test(vm): prove Dynamic box roots across safepoint GC for PLN-0176 step 20
This commit is contained in:
@@ -203,6 +203,50 @@ fn decoded_dynamic_box_roundtrip_and_identity_never_nest_boxes() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn decoded_trait_box_is_the_only_receiver_root_across_frame_sync_gc() {
|
||||||
|
let mut code = vec![];
|
||||||
|
arg(&mut code, OpCode::GetGlobal, 0);
|
||||||
|
arg(&mut code, OpCode::GetGlobal, 1);
|
||||||
|
arg(&mut code, OpCode::DynPack, 11);
|
||||||
|
op(&mut code, OpCode::FrameSync);
|
||||||
|
arg(&mut code, OpCode::DynUnpack, 11);
|
||||||
|
op(&mut code, OpCode::Pop);
|
||||||
|
op(&mut code, OpCode::Pop);
|
||||||
|
op(&mut code, OpCode::FrameSync);
|
||||||
|
op(&mut code, OpCode::Halt);
|
||||||
|
let image = image(&code, vec![function(0, code.len(), &[], &[], 0, 2)]);
|
||||||
|
let registry = image.registry().clone();
|
||||||
|
let mut vm = VirtualMachine::from_image(image, RuntimeLimits::default());
|
||||||
|
vm.prepare_boot_call().unwrap();
|
||||||
|
let receiver = vm.heap.allocate_typed_struct(registry, TypeId(9)).unwrap();
|
||||||
|
load_globals_and_step(&mut vm, &[Value::HeapRef(receiver), Value::Int64(0)]).unwrap();
|
||||||
|
let Value::HeapRef(box_handle) = vm.operand_stack[1] else { panic!("box handle") };
|
||||||
|
vm.globals.clear();
|
||||||
|
vm.gc_alloc_threshold = 1;
|
||||||
|
vm.last_gc_live_count = 0;
|
||||||
|
assert!(matches!(
|
||||||
|
vm.step(&mut Native, &mut HostContext::new(None)),
|
||||||
|
Err(LogicalFrameEndingReason::FrameSync)
|
||||||
|
));
|
||||||
|
assert!(vm.heap.is_valid(receiver));
|
||||||
|
assert!(vm.heap.is_valid(box_handle));
|
||||||
|
assert_eq!(vm.heap.len(), 3); // Coroutine, immutable box and its receiver.
|
||||||
|
vm.step(&mut Native, &mut HostContext::new(None)).unwrap();
|
||||||
|
assert_eq!(vm.operand_stack.as_slice(), &[Value::HeapRef(receiver), Value::Int64(0)]);
|
||||||
|
vm.step(&mut Native, &mut HostContext::new(None)).unwrap();
|
||||||
|
vm.step(&mut Native, &mut HostContext::new(None)).unwrap();
|
||||||
|
// Force the next permitted GC even though no allocation occurred between safepoints.
|
||||||
|
vm.last_gc_live_count = 0;
|
||||||
|
assert!(matches!(
|
||||||
|
vm.step(&mut Native, &mut HostContext::new(None)),
|
||||||
|
Err(LogicalFrameEndingReason::FrameSync)
|
||||||
|
));
|
||||||
|
assert!(!vm.heap.is_valid(receiver));
|
||||||
|
assert!(!vm.heap.is_valid(box_handle));
|
||||||
|
assert_eq!(vm.heap.len(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decoded_dynamic_malformed_pairs_trap_once_without_consuming_source() {
|
fn decoded_dynamic_malformed_pairs_trap_once_without_consuming_source() {
|
||||||
for operation in [OpCode::DynUnpack, OpCode::DynCanUnpack] {
|
for operation in [OpCode::DynUnpack, OpCode::DynCanUnpack] {
|
||||||
|
|||||||
Reference in New Issue
Block a user