pub struct GcRuntime { /* private fields */ }Expand description
QuickJS-style runtime heap: reference counting + three-phase cycle removal.
Implementations§
Source§impl GcRuntime
impl GcRuntime
pub fn new() -> Self
pub fn malloc_state(&self) -> &MallocState
pub fn malloc_state_mut(&mut self) -> &mut MallocState
pub fn gc_threshold(&self) -> usize
Sourcepub fn set_gc_threshold(&mut self, threshold: usize)
pub fn set_gc_threshold(&mut self, threshold: usize)
threshold == usize::MAX disables automatic GC, matching JS_SetGCThreshold(rt, -1).
pub fn gc_phase(&self) -> GcPhase
pub fn gc_object_count(&self) -> usize
Sourcepub fn add_gc_object(
&mut self,
object: Box<dyn GcObject>,
gc_obj_type: GcObjectType,
) -> GcId
pub fn add_gc_object( &mut self, object: Box<dyn GcObject>, gc_obj_type: GcObjectType, ) -> GcId
Register a new GC object with ref_count = 1 on gc_obj_list.
Matches QuickJS add_gc_object.
Sourcepub fn dup_gc(&mut self, id: GcId) -> GcId
pub fn dup_gc(&mut self, id: GcId) -> GcId
Increment refcount. Matches QuickJS js_dup for GC objects.
Sourcepub fn free_gc(&mut self, id: GcId)
pub fn free_gc(&mut self, id: GcId)
Decrement refcount and free when it reaches zero.
Matches QuickJS JS_FreeValueRT for GC objects.
Sourcepub fn add_ref_counted<F>(&mut self, on_free: F) -> RefCountId
pub fn add_ref_counted<F>(&mut self, on_free: F) -> RefCountId
Allocate a simple refcounted payload (strings, etc.). Not cycle-collected.
pub fn dup_ref_counted(&mut self, id: RefCountId) -> RefCountId
pub fn free_ref_counted(&mut self, id: RefCountId)
Sourcepub fn mark_gc_header(&mut self, id: GcId, mark_func: MarkFunc)
pub fn mark_gc_header(&mut self, id: GcId, mark_func: MarkFunc)
Mark a GC object header during traversal. Matches JS_MarkValue for object tags.
Sourcepub fn mark_children(&mut self, id: GcId, mark_func: MarkFunc)
pub fn mark_children(&mut self, id: GcId, mark_func: MarkFunc)
Traverse children of a GC object. Matches QuickJS mark_children.
Sourcepub fn trigger_gc(&mut self, alloc_size: usize)
pub fn trigger_gc(&mut self, alloc_size: usize)
Maybe run GC when tracked malloc exceeds threshold. Matches js_trigger_gc.
Sourcepub fn is_live_object(&self, id: GcId) -> bool
pub fn is_live_object(&self, id: GcId) -> bool
Return false if the object has been freed during cycle collection.
Matches JS_IsLiveObject.