feat: protect existing objects during read-only calls and track reads

This commit is contained in:
2026-10-21 14:17:38 +08:00
parent 44a02c9fd6
commit ff49f266a2
11 changed files with 249 additions and 6 deletions
+13
View File
@@ -13,6 +13,18 @@ pub struct ObjectStore {
}
impl ObjectStore {
/// Existing objects are immutable; fresh result graphs may be constructed.
/// Scopes must end in LIFO order. Read handles are borrowed, never GC roots.
pub fn begin_read_only(&mut self) -> usize {
self.heap.begin_read_only()
}
pub fn end_read_only(&mut self, scope: usize) -> Result<Vec<ObjectRef>, VmError> {
self.heap.end_read_only(scope)
}
pub fn is_read_only(&self) -> bool {
self.heap.is_read_only()
}
pub fn downgrade(&self, reference: ObjectRef) -> Result<WeakObjectRef, VmError> {
self.object(reference)?;
Ok(WeakObjectRef(reference))
@@ -107,6 +119,7 @@ impl ObjectStore {
}
pub fn object(&self, reference: ObjectRef) -> Result<&EndorObject, VmError> {
self.heap.record_read(reference);
self.heap.get(reference)
}