feat(vm): integrate metered strings and native retention for PLN-0176 step 19
This commit is contained in:
@@ -213,3 +213,48 @@ fn late_work_refusal_releases_all_new_owners() {
|
||||
assert_eq!(b.used(Q::ConstantStringBytes), 0);
|
||||
assert_eq!(b.used(Q::PbxBytes), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn constant_strings_share_image_domain_across_sessions_and_native_snapshots() {
|
||||
use crate::resource_budget::{RuntimeLimits, RuntimeResource};
|
||||
use crate::{HostContext, HostReturn, NativeInterface, VirtualMachine};
|
||||
struct Native;
|
||||
impl NativeInterface for Native {
|
||||
fn syscall(
|
||||
&mut self,
|
||||
_id: u32,
|
||||
_args: &[Value],
|
||||
_ret: &mut HostReturn,
|
||||
_ctx: &mut HostContext,
|
||||
) -> Result<(), prometeu_hal::vm_fault::VmFault> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
let mut code = (Op::PushConst as u16).to_le_bytes().to_vec();
|
||||
code.extend_from_slice(&0u32.to_le_bytes());
|
||||
code.extend_from_slice(&(Op::Halt as u16).to_le_bytes());
|
||||
let bytes = fixture(&code, 1, &[K::String("shared".into())], None, &[]);
|
||||
let image = ValidatedProgramImage::load(&bytes, &mut budget(), caps::NONE).unwrap();
|
||||
let lease = image.lease_constant(0).unwrap();
|
||||
let limits = RuntimeLimits::default().lowered(RuntimeResource::StringBytes, 0).unwrap();
|
||||
let mut first = VirtualMachine::from_image(image.clone(), limits.clone());
|
||||
let mut second = VirtualMachine::from_image(image.clone(), limits);
|
||||
first.prepare_boot_call().unwrap();
|
||||
second.prepare_boot_call().unwrap();
|
||||
for vm in [&mut first, &mut second] {
|
||||
vm.step(&mut Native, &mut HostContext::new(None)).unwrap();
|
||||
}
|
||||
let snapshot = first.operand_stack_top(1);
|
||||
let other = second.operand_stack_top(1);
|
||||
let (Value::String(left), Value::String(right)) = (&snapshot[0], &other[0]) else { panic!() };
|
||||
assert!(Arc::ptr_eq(left, right));
|
||||
assert_eq!(snapshot.retained_domains(), 1);
|
||||
drop(image);
|
||||
drop(first);
|
||||
drop(second);
|
||||
drop(other);
|
||||
assert_eq!(lease.retained_content(), (6, 1));
|
||||
drop(lease);
|
||||
let Value::String(text) = &snapshot[0] else { panic!() };
|
||||
assert_eq!(text.as_ref(), "shared");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user