pub struct Region { /* private fields */ }Expand description
A contiguous 2MB memory region allocated via mmap.
Objects are bump-allocated within the region. Each object is preceded by a GcHeader (8 bytes) and is 8-byte aligned.
Implementations§
Source§impl Region
impl Region
Sourcepub fn try_alloc(&mut self, layout: Layout) -> Option<*mut u8>
pub fn try_alloc(&mut self, layout: Layout) -> Option<*mut u8>
Try to bump-allocate within this region.
Returns a pointer to the object data (after the GcHeader) or None if the region is exhausted.
total_size includes the GcHeader (8 bytes) + the object layout size,
already aligned to 8 bytes.
Sourcepub fn used_bytes(&self) -> usize
pub fn used_bytes(&self) -> usize
Get the current used bytes.
Sourcepub fn set_cursor(&mut self, cursor: usize)
pub fn set_cursor(&mut self, cursor: usize)
Set the cursor to a specific offset. Used by TLAB flush to sync the TLAB’s allocation cursor back into the region before sweep.
Sourcepub fn for_each_object(&self, f: impl FnMut(&GcHeader, *mut u8))
pub fn for_each_object(&self, f: impl FnMut(&GcHeader, *mut u8))
Iterate over all allocated objects in this region.
Calls f(header, obj_ptr) for each object.
Sourcepub fn for_each_object_mut(&mut self, f: impl FnMut(&mut GcHeader, *mut u8))
pub fn for_each_object_mut(&mut self, f: impl FnMut(&mut GcHeader, *mut u8))
Iterate over all allocated objects mutably.
Sourcepub fn unprotect(&self)
pub fn unprotect(&self)
Unprotect this region’s pages (PROT_READ|PROT_WRITE) — used after fixup.
Sourcepub fn live_bytes(&self) -> usize
pub fn live_bytes(&self) -> usize
Get/set live_bytes tracking.