Skip to main content

GcRuntime

Struct GcRuntime 

Source
pub struct GcRuntime { /* private fields */ }
Expand description

QuickJS-style runtime heap: reference counting + three-phase cycle removal.

Implementations§

Source§

impl GcRuntime

Source

pub fn new() -> Self

Source

pub fn malloc_state(&self) -> &MallocState

Source

pub fn malloc_state_mut(&mut self) -> &mut MallocState

Source

pub fn gc_threshold(&self) -> usize

Source

pub fn set_gc_threshold(&mut self, threshold: usize)

threshold == usize::MAX disables automatic GC, matching JS_SetGCThreshold(rt, -1).

Source

pub fn gc_phase(&self) -> GcPhase

Source

pub fn gc_object_count(&self) -> usize

Source

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.

Source

pub fn dup_gc(&mut self, id: GcId) -> GcId

Increment refcount. Matches QuickJS js_dup for GC objects.

Source

pub fn free_gc(&mut self, id: GcId)

Decrement refcount and free when it reaches zero. Matches QuickJS JS_FreeValueRT for GC objects.

Source

pub fn add_ref_counted<F>(&mut self, on_free: F) -> RefCountId
where F: FnOnce(&mut GcRuntime) + 'static,

Allocate a simple refcounted payload (strings, etc.). Not cycle-collected.

Source

pub fn dup_ref_counted(&mut self, id: RefCountId) -> RefCountId

Source

pub fn free_ref_counted(&mut self, id: RefCountId)

Source

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.

Source

pub fn mark_children(&mut self, id: GcId, mark_func: MarkFunc)

Traverse children of a GC object. Matches QuickJS mark_children.

Source

pub fn trigger_gc(&mut self, alloc_size: usize)

Maybe run GC when tracked malloc exceeds threshold. Matches js_trigger_gc.

Source

pub fn run_gc(&mut self)

Run the three-phase cycle collector. Matches JS_RunGC.

Source

pub fn is_live_object(&self, id: GcId) -> bool

Return false if the object has been freed during cycle collection. Matches JS_IsLiveObject.

Source

pub fn ref_count(&self, id: GcId) -> i32

Source

pub fn object_exists(&self, id: GcId) -> bool

Source

pub fn object_downcast<T: GcObject>(&self, id: GcId) -> Option<&T>

Source

pub fn object_downcast_mut<T: GcObject>(&mut self, id: GcId) -> Option<&mut T>

Trait Implementations§

Source§

impl Default for GcRuntime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.