Skip to main content

Heap

Struct Heap 

Source
pub struct Heap { /* private fields */ }

Implementations§

Source§

impl Heap

Source

pub fn new() -> Self

Source

pub fn unpause(&self)

Enable collection. Until this is called, step is a no-op (so the runtime can bootstrap without prematurely freeing objects).

Source

pub fn is_paused(&self) -> bool

Source

pub fn allocate<T: Trace + 'static>(&self, value: T) -> Gc<T>

Allocate a new GcBox<T> and prepend it to the allgc chain.

Source

pub fn bytes_used(&self) -> usize

Bytes currently retained by GC-tracked objects (rough estimate).

Source

pub fn threshold_bytes(&self) -> usize

Current collection threshold in bytes. When bytes_used() >= threshold_bytes(), the next step() will run a full collection (unless paused). Used by callers that want to short-circuit expensive prep work (e.g. snapshotting weak tables / pending finalizers) when no collection will actually fire.

Source

pub fn would_collect(&self) -> bool

Cheap predicate: would a step() actually do work? Equivalent to !paused && bytes_used() >= threshold_bytes(). Callers that build snapshot state before invoking the heap should gate on this.

Source

pub fn collections(&self) -> usize

Source

pub fn barrier<P, C>(&self, parent: Gc<P>, child: Gc<C>)
where P: Trace + 'static, C: Trace + 'static,

Forward write barrier: invoked when parent (already-traced black object) gains a new reference to child. To preserve the tri-color invariant (“no black points to white”), we mark the child gray immediately. Cheap: one branch + maybe one queue push.

During incremental mode this prevents the marking phase from missing the new edge. In current stop-the-world mode it’s still correct (a no-op when the collection is idle), so call sites can be wired now and the incremental upgrade is mechanical later.

Source

pub fn step(&self, roots: &dyn Trace)

Possibly run a collection. Trigger: bytes_used > threshold. Caller passes the root set (the runtime — typically GlobalState implementing Trace).

Source

pub fn step_with_post_mark<F: FnMut(&mut Marker)>( &self, roots: &dyn Trace, post_mark: F, )

Like [step] but invokes a post_mark hook when a collection actually fires (threshold reached). Hook is a no-op on the short-circuit path. The runtime uses this to bridge weak-table pruning into implicit GC steps fired from inside the VM loop.

Source

pub fn full_collect(&self, roots: &dyn Trace)

Stop-the-world full collect. Marks every reachable object from roots, then sweeps white (unreachable) boxes from the allgc chain.

Source

pub fn mark_only_with_post_mark<F: FnMut(&mut Marker)>( &self, roots: &dyn Trace, post_mark: F, )

Run only the mark/atomic hook portion of a collection, without sweeping.

This is used by runtimes that need an atomic reachability snapshot for weak-table cleanup while they are deliberately avoiding object freeing.

Source

pub fn full_collect_with_post_mark<F: FnMut(&mut Marker)>( &self, roots: &dyn Trace, post_mark: F, )

Stop-the-world full collect with a post-mark hook.

Internally drives the incremental state machine to completion with an unbounded budget — equivalent to repeatedly calling [incremental_step_with_post_mark] until it returns Paused. The post-mark hook is invoked exactly once, during the atomic transition.

Source

pub fn incremental_step_with_post_mark<F: FnMut(&mut Marker)>( &self, roots: &dyn Trace, budget: StepBudget, post_mark: F, ) -> StepOutcome

Run one budgeted step of the incremental collector.

The state machine advances Pause → Propagate → Atomic → Sweep → Finalize → Pause. Each phase consumes budget; the call returns when the budget runs out or the cycle reaches Pause. The post_mark hook is invoked exactly once per cycle, during the Atomic transition (after the initial gray-queue drain, before sweep starts).

Returns:

Source

pub fn gc_state(&self) -> GcState

Returns the current state of the incremental collector.

Source

pub fn allgc_count(&self) -> usize

Approximate number of live GC boxes, computed by walking the allgc chain. Linear in heap size; used for cycle-cost estimation and tests.

Source

pub fn drop_all(&self)

Drop every allocation, ignoring reachability. Called at shutdown. After this returns, every outstanding Gc<T> is dangling — callers must ensure no Gc<T> outlives the Heap.

Trait Implementations§

Source§

impl Default for Heap

Source§

fn default() -> Self

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

impl Drop for Heap

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !Freeze for Heap

§

impl !RefUnwindSafe for Heap

§

impl !Send for Heap

§

impl !Sync for Heap

§

impl Unpin for Heap

§

impl UnsafeUnpin for Heap

§

impl !UnwindSafe for Heap

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.