Skip to main content

Region

Struct Region 

Source
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

Source

pub fn new() -> Self

Allocate a new 2MB region via mmap.

Source

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.

Source

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

Check if a pointer falls within this region.

Source

pub fn base(&self) -> *mut u8

Get the base address of this region.

Source

pub fn used_bytes(&self) -> usize

Get the current used bytes.

Source

pub fn remaining(&self) -> usize

Get the remaining capacity.

Source

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.

Source

pub fn reset(&mut self)

Reset the cursor (after relocation has moved all live objects out).

Source

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.

Source

pub fn for_each_object_mut(&mut self, f: impl FnMut(&mut GcHeader, *mut u8))

Iterate over all allocated objects mutably.

Source

pub fn protect(&self)

Protect this region’s pages (PROT_NONE) — used after relocation.

Source

pub fn unprotect(&self)

Unprotect this region’s pages (PROT_READ|PROT_WRITE) — used after fixup.

Source

pub fn live_bytes(&self) -> usize

Get/set live_bytes tracking.

Source

pub fn set_live_bytes(&mut self, bytes: usize)

Trait Implementations§

Source§

impl Drop for Region

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Region

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.