Skip to main content

GenerationalCollector

Struct GenerationalCollector 

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

Generational collector state.

Manages young and old generation regions, promotion tracking, and card table write barriers. Young-gen collection scans only young regions + dirty cards, while old-gen collection does a full mark-sweep.

Implementations§

Source§

impl GenerationalCollector

Source

pub fn new() -> Self

Source

pub fn with_promotion_threshold(threshold: u8) -> Self

Create a generational collector with a custom promotion threshold.

Source

pub fn add_young_region(&mut self, region: Region)

Add a region to the young generation.

Source

pub fn add_old_region(&mut self, region: Region)

Add a region to the old generation.

Source

pub fn young_regions(&self) -> &[Region]

Get a reference to young regions.

Source

pub fn young_regions_mut(&mut self) -> &mut Vec<Region>

Get a mutable reference to young regions.

Source

pub fn old_regions(&self) -> &[Region]

Get a reference to old regions.

Source

pub fn old_regions_mut(&mut self) -> &mut Vec<Region>

Get a mutable reference to old regions.

Source

pub fn young_used_bytes(&self) -> usize

Total bytes used in young gen.

Source

pub fn young_capacity_bytes(&self) -> usize

Total capacity in young gen (all young regions).

Source

pub fn old_used_bytes(&self) -> usize

Total bytes used in old gen.

Source

pub fn old_capacity_bytes(&self) -> usize

Total capacity in old gen (all old regions).

Source

pub fn young_utilization(&self) -> f64

Young gen utilization (0.0 to 1.0). Returns 0.0 if no young regions exist.

Source

pub fn old_free_bytes(&self) -> usize

Old gen free bytes.

Source

pub fn is_young_ptr(&self, ptr: *const u8) -> bool

Check if a pointer falls within any young-gen region.

Source

pub fn is_old_ptr(&self, ptr: *const u8) -> bool

Check if a pointer falls within any old-gen region.

Source

pub fn collect_young( &mut self, marker: &mut Marker, roots: &[*mut u8], ) -> SweepStats

Collect the young generation.

  1. Mark roots that point into young gen
  2. Scan dirty cards for old-to-young references
  3. Complete marking (only young-gen objects)
  4. Promote survivors that have survived enough cycles
  5. Sweep dead young-gen objects
  6. Clear dirty cards
Source

pub fn collect_old( &mut self, marker: &mut Marker, roots: &[*mut u8], ) -> SweepStats

Collect the old generation (full mark-sweep).

This marks from roots across ALL regions (young + old) and sweeps only old-gen regions. Called less frequently than young GC.

Source

pub fn survival_count(&self, obj_ptr: *const u8) -> u8

Get the survival count for a specific object.

Source

pub fn total_promoted(&self) -> u64

Get the total number of objects promoted over all collections.

Source

pub fn record_young_gc(&mut self)

Record a young collection.

Source

pub fn record_old_gc(&mut self)

Record an old (full) collection.

Source

pub fn should_promote(&self, survival_count: u8) -> bool

Check if an object should be promoted based on survival count.

Source

pub fn card_table(&self) -> Option<&CardTable>

Get the card table, if initialized.

Source

pub fn card_table_mut(&mut self) -> Option<&mut CardTable>

Get a mutable reference to the card table.

Source

pub fn init_card_table(&mut self, base: usize, size: usize)

Initialize the card table for a given memory range.

Source

pub fn young_gc_count(&self) -> u64

Statistics.

Source

pub fn old_gc_count(&self) -> u64

Source

pub fn promotion_threshold(&self) -> u8

Promotion threshold value.

Trait Implementations§

Source§

impl Default for GenerationalCollector

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.