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
impl GenerationalCollector
pub fn new() -> Self
Sourcepub fn with_promotion_threshold(threshold: u8) -> Self
pub fn with_promotion_threshold(threshold: u8) -> Self
Create a generational collector with a custom promotion threshold.
Sourcepub fn add_young_region(&mut self, region: Region)
pub fn add_young_region(&mut self, region: Region)
Add a region to the young generation.
Sourcepub fn add_old_region(&mut self, region: Region)
pub fn add_old_region(&mut self, region: Region)
Add a region to the old generation.
Sourcepub fn young_regions(&self) -> &[Region]
pub fn young_regions(&self) -> &[Region]
Get a reference to young regions.
Sourcepub fn young_regions_mut(&mut self) -> &mut Vec<Region>
pub fn young_regions_mut(&mut self) -> &mut Vec<Region>
Get a mutable reference to young regions.
Sourcepub fn old_regions(&self) -> &[Region]
pub fn old_regions(&self) -> &[Region]
Get a reference to old regions.
Sourcepub fn old_regions_mut(&mut self) -> &mut Vec<Region>
pub fn old_regions_mut(&mut self) -> &mut Vec<Region>
Get a mutable reference to old regions.
Sourcepub fn young_used_bytes(&self) -> usize
pub fn young_used_bytes(&self) -> usize
Total bytes used in young gen.
Sourcepub fn young_capacity_bytes(&self) -> usize
pub fn young_capacity_bytes(&self) -> usize
Total capacity in young gen (all young regions).
Sourcepub fn old_used_bytes(&self) -> usize
pub fn old_used_bytes(&self) -> usize
Total bytes used in old gen.
Sourcepub fn old_capacity_bytes(&self) -> usize
pub fn old_capacity_bytes(&self) -> usize
Total capacity in old gen (all old regions).
Sourcepub fn young_utilization(&self) -> f64
pub fn young_utilization(&self) -> f64
Young gen utilization (0.0 to 1.0). Returns 0.0 if no young regions exist.
Sourcepub fn old_free_bytes(&self) -> usize
pub fn old_free_bytes(&self) -> usize
Old gen free bytes.
Sourcepub fn is_young_ptr(&self, ptr: *const u8) -> bool
pub fn is_young_ptr(&self, ptr: *const u8) -> bool
Check if a pointer falls within any young-gen region.
Sourcepub fn is_old_ptr(&self, ptr: *const u8) -> bool
pub fn is_old_ptr(&self, ptr: *const u8) -> bool
Check if a pointer falls within any old-gen region.
Sourcepub fn collect_young(
&mut self,
marker: &mut Marker,
roots: &[*mut u8],
) -> SweepStats
pub fn collect_young( &mut self, marker: &mut Marker, roots: &[*mut u8], ) -> SweepStats
Collect the young generation.
- Mark roots that point into young gen
- Scan dirty cards for old-to-young references
- Complete marking (only young-gen objects)
- Promote survivors that have survived enough cycles
- Sweep dead young-gen objects
- Clear dirty cards
Sourcepub fn collect_old(
&mut self,
marker: &mut Marker,
roots: &[*mut u8],
) -> SweepStats
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.
Sourcepub fn survival_count(&self, obj_ptr: *const u8) -> u8
pub fn survival_count(&self, obj_ptr: *const u8) -> u8
Get the survival count for a specific object.
Sourcepub fn total_promoted(&self) -> u64
pub fn total_promoted(&self) -> u64
Get the total number of objects promoted over all collections.
Sourcepub fn record_young_gc(&mut self)
pub fn record_young_gc(&mut self)
Record a young collection.
Sourcepub fn record_old_gc(&mut self)
pub fn record_old_gc(&mut self)
Record an old (full) collection.
Sourcepub fn should_promote(&self, survival_count: u8) -> bool
pub fn should_promote(&self, survival_count: u8) -> bool
Check if an object should be promoted based on survival count.
Sourcepub fn card_table(&self) -> Option<&CardTable>
pub fn card_table(&self) -> Option<&CardTable>
Get the card table, if initialized.
Sourcepub fn card_table_mut(&mut self) -> Option<&mut CardTable>
pub fn card_table_mut(&mut self) -> Option<&mut CardTable>
Get a mutable reference to the card table.
Sourcepub fn init_card_table(&mut self, base: usize, size: usize)
pub fn init_card_table(&mut self, base: usize, size: usize)
Initialize the card table for a given memory range.
Sourcepub fn young_gc_count(&self) -> u64
pub fn young_gc_count(&self) -> u64
Statistics.
pub fn old_gc_count(&self) -> u64
Sourcepub fn promotion_threshold(&self) -> u8
pub fn promotion_threshold(&self) -> u8
Promotion threshold value.