pub struct HeaderMetadataSpec {
    pub bit_offset: isize,
    pub num_of_bits: usize,
}
Expand description

This struct stores the specification of a header metadata bit-set. It supports either bits metadata of 1-7 bits in the same byte, or u8/u16/u32/u64 at an offset of their natural alignment.

For performance reasons, objects of this struct should be constants.

Fields§

§bit_offset: isize

bit_offset is the index of the starting bit from which the data should be read or written. It is counted from the right (least significant bit) of the byte. Positive values refer to the bit positions within the current byte, starting with 0 for the least significant bit (rightmost) up to 7 for the most significant bit (leftmost). Negative values are used to refer to bit positions in the previous bytes, where -1 indicates the most significant bit (leftmost) of the byte immediately before the current one.

§num_of_bits: usize

num_of_bits specifies the number of consecutive bits to be read or written starting from the bit_offset. This value is used to define the size of the data field in bits. For instance, if num_of_bits is set to 1, only a single bit is considered, whereas a value of 8 would indicate a full byte. This field must be a positive integer and typically should not exceed the size of the data type that will hold the extracted value (for example, 8 bits for a u8, 16 bits for a u16, etc.). The num_of_bits together with the bit_offset enables the extraction of bit fields of arbitrary length and position, facilitating bit-level data manipulation.

Implementations§

source§

impl HeaderMetadataSpec

source

fn assert_mask<T: MetadataValue>(&self, mask: Option<T>)

We only allow mask for u8/u16/u32/u64/usize. If a mask is used with a spec that does not allow it, this method will panic.

We allow using mask for certain operations. The reason for mask is that for header metadata, we may have overlapping metadata specs. For example, a forwarding pointer is pointer-size, but its last 2 bits could be used as forwarding bits. In that case, all accesses to the forwarding pointer spec should be used with a mask to make sure that we exclude the forwarding bits.

source

fn assert_spec<T: MetadataValue>(&self)

Assert if this is a valid spec.

source

fn byte_offset(&self) -> isize

source

fn meta_addr(&self, header: Address) -> Address

source

fn get_shift_and_mask_for_bits(&self) -> (isize, u8)

Get the bit shift (the bit distance from the lowest bit to the bits location defined in the spec), and the mask (used to extract value for the bits defined in the spec).

source

fn get_bits_from_u8(&self, raw_byte: u8) -> u8

Extract bits from a raw byte, and put it to the lowest bits.

source

fn set_bits_to_u8(&self, raw_byte: u8, set_val: u8) -> u8

Set bits to a raw byte. set_val has the valid value in its lowest bits.

source

fn truncate_bits_in_u8(&self, val: u8) -> u8

Truncate a value based on the spec.

source

pub unsafe fn load<T: MetadataValue>( &self, header: Address, optional_mask: Option<T> ) -> T

This function provides a default implementation for the load_metadata method from the ObjectModel trait.

§Safety

This is a non-atomic load, thus not thread-safe.

source

pub fn load_atomic<T: MetadataValue>( &self, header: Address, optional_mask: Option<T>, ordering: Ordering ) -> T

This function provides a default implementation for the load_metadata_atomic method from the ObjectModel trait.

source

fn load_inner<T: MetadataValue>( &self, header: Address, optional_mask: Option<T>, atomic_ordering: Option<Ordering> ) -> T

source

pub unsafe fn store<T: MetadataValue>( &self, header: Address, val: T, optional_mask: Option<T> )

This function provides a default implementation for the store_metadata method from the ObjectModel trait.

Note: this function does compare-and-swap in a busy loop. So, unlike compare_exchange_metadata, this operation will always success.

§Safety

This is a non-atomic store, thus not thread-safe.

source

pub fn store_atomic<T: MetadataValue>( &self, header: Address, val: T, optional_mask: Option<T>, ordering: Ordering )

This function provides a default implementation for the store_metadata_atomic method from the ObjectModel trait.

Note: this function does compare-and-swap in a busy loop. So, unlike compare_exchange_metadata, this operation will always success.

source

fn store_inner<T: MetadataValue>( &self, header: Address, val: T, optional_mask: Option<T>, atomic_ordering: Option<Ordering> )

source

pub fn compare_exchange<T: MetadataValue>( &self, header: Address, old_metadata: T, new_metadata: T, optional_mask: Option<T>, success_order: Ordering, failure_order: Ordering ) -> Result<T, T>

This function provides a default implementation for the compare_exchange_metadata method from the ObjectModel trait.

Note: this function only does fetch and exclusive store once, without any busy waiting in a loop.

source

fn fetch_ops_on_bits<F: Fn(u8) -> u8>( &self, header: Address, set_order: Ordering, fetch_order: Ordering, update: F ) -> u8

Inner method for fetch_add/sub on bits. For fetch_and/or, we don’t necessarily need this method. We could directly do fetch_and/or on the u8.

source

pub fn fetch_add<T: MetadataValue>( &self, header: Address, val: T, order: Ordering ) -> T

This function provides a default implementation for the fetch_add method from the ObjectModel trait.

source

pub fn fetch_sub<T: MetadataValue>( &self, header: Address, val: T, order: Ordering ) -> T

This function provides a default implementation for the fetch_sub method from the ObjectModel trait.

source

pub fn fetch_and<T: MetadataValue>( &self, header: Address, val: T, order: Ordering ) -> T

This function provides a default implementation for the fetch_and method from the ObjectModel trait.

source

pub fn fetch_or<T: MetadataValue>( &self, header: Address, val: T, order: Ordering ) -> T

This function provides a default implementation for the fetch_or method from the ObjectModel trait.

source

pub fn fetch_update<T: MetadataValue, F: FnMut(T) -> Option<T> + Copy>( &self, header: Address, set_order: Ordering, fetch_order: Ordering, f: F ) -> Result<T, T>

This function provides a default implementation for the fetch_update method from the ObjectModel trait. The semantics is the same as Rust’s fetch_update on atomic types.

Trait Implementations§

source§

impl Clone for HeaderMetadataSpec

source§

fn clone(&self) -> HeaderMetadataSpec

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for HeaderMetadataSpec

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for HeaderMetadataSpec

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for HeaderMetadataSpec

source§

fn eq(&self, other: &HeaderMetadataSpec) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for HeaderMetadataSpec

source§

impl Eq for HeaderMetadataSpec

source§

impl StructuralPartialEq for HeaderMetadataSpec

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.