Struct mmtk::util::address::Address

source ·
#[repr(transparent)]
pub struct Address(usize);
Expand description

Address represents an arbitrary address. This is designed to represent address and do address arithmetic mostly in a safe way, and to allow mark some operations as unsafe. This type needs to be zero overhead (memory wise and time wise). The idea is from the paper High-level Low-level Programming (VEE09) and JikesRVM.

Tuple Fields§

§0: usize

Implementations§

source§

impl Address

source

pub const ZERO: Self = _

The lowest possible address.

source

pub const MAX: Self = _

The highest possible address.

source

pub fn from_ptr<T>(ptr: *const T) -> Address

creates Address from a pointer

source

pub fn from_ref<T>(r: &T) -> Address

creates Address from a Rust reference

source

pub fn from_mut_ptr<T>(ptr: *mut T) -> Address

creates Address from a mutable pointer

source

pub const unsafe fn zero() -> Address

creates a null Address (0)

§Safety

It is unsafe and the user needs to be aware that they are creating an invalid address. The zero address should only be used as unininitialized or sentinel values in performance critical code (where you dont want to use Option<Address>).

source

pub unsafe fn max() -> Address

creates an Address of (usize::MAX)

§Safety

It is unsafe and the user needs to be aware that they are creating an invalid address. The max address should only be used as unininitialized or sentinel values in performance critical code (where you dont want to use Option<Address>).

source

pub const unsafe fn from_usize(raw: usize) -> Address

creates an arbitrary Address

§Safety

It is unsafe and the user needs to be aware that they may create an invalid address. This creates arbitrary addresses which may not be valid. This should only be used for hard-coded addresses. Any other uses of this function could be replaced with more proper alternatives.

source

pub fn shift<T>(self, offset: isize) -> Self

shifts the address by N T-typed objects (returns addr + N * size_of(T))

source

pub const fn get_extent(self, other: Address) -> ByteSize

Get the number of bytes between two addresses. The current address needs to be higher than the other address.

source

pub const fn get_offset(self, other: Address) -> ByteOffset

Get the offset from other to self. The result is negative is self is lower than other.

source

pub const fn add(self, size: usize) -> Address

Add an offset to the address.

source

pub const fn sub(self, size: usize) -> Address

Subtract an offset from the address.

source

pub const fn and(self, mask: usize) -> usize

Bitwise ‘and’ with a mask.

source

pub const fn saturating_sub(self, size: usize) -> Address

Perform a saturating subtract on the Address

source

pub unsafe fn load<T: Copy>(self) -> T

loads a value of type T from the address

§Safety

This could throw a segment fault if the address is invalid

source

pub unsafe fn store<T>(self, value: T)

stores a value of type T to the address

§Safety

This could throw a segment fault if the address is invalid

source

pub unsafe fn atomic_load<T: Atomic>(self, order: Ordering) -> T::Type

atomic operation: load

§Safety

This could throw a segment fault if the address is invalid

source

pub unsafe fn atomic_store<T: Atomic>(self, val: T::Type, order: Ordering)

atomic operation: store

§Safety

This could throw a segment fault if the address is invalid

source

pub unsafe fn compare_exchange<T: Atomic>( self, old: T::Type, new: T::Type, success: Ordering, failure: Ordering ) -> Result<T::Type, T::Type>

atomic operation: compare and exchange usize

§Safety

This could throw a segment fault if the address is invalid

source

pub fn is_zero(self) -> bool

is this address zero?

source

pub const fn align_up(self, align: ByteSize) -> Address

aligns up the address to the given alignment

source

pub const fn align_down(self, align: ByteSize) -> Address

aligns down the address to the given alignment

source

pub const fn is_aligned_to(self, align: usize) -> bool

is this address aligned to the given alignment

source

pub fn to_ptr<T>(self) -> *const T

converts the Address to a pointer

source

pub fn to_mut_ptr<T>(self) -> *mut T

converts the Address to a mutable pointer

source

pub unsafe fn as_ref<'a, T>(self) -> &'a T

converts the Address to a Rust reference

§Safety

The caller must guarantee the address actually points to a Rust object.

source

pub unsafe fn as_mut_ref<'a, T>(self) -> &'a mut T

converts the Address to a mutable Rust reference

§Safety

The caller must guarantee the address actually points to a Rust object.

source

pub const fn as_usize(self) -> usize

converts the Address to a pointer-sized integer

source

pub fn chunk_index(self) -> usize

returns the chunk index for this address

source

pub fn is_mapped(self) -> bool

return true if the referenced memory is mapped

source

pub fn range_intersection( r1: &Range<Address>, r2: &Range<Address> ) -> Range<Address>

Returns the intersection of the two address ranges. The returned range could be empty if there is no intersection between the ranges.

Trait Implementations§

source§

impl Add<isize> for Address

Address + ByteOffset (positive or negative)

§

type Output = Address

The resulting type after applying the + operator.
source§

fn add(self, offset: ByteOffset) -> Address

Performs the + operation. Read more
source§

impl Add<usize> for Address

Address + ByteSize (positive)

§

type Output = Address

The resulting type after applying the + operator.
source§

fn add(self, offset: ByteSize) -> Address

Performs the + operation. Read more
source§

impl AddAssign<isize> for Address

Address += ByteOffset (positive or negative)

source§

fn add_assign(&mut self, offset: ByteOffset)

Performs the += operation. Read more
source§

impl AddAssign<usize> for Address

Address += ByteSize (positive)

source§

fn add_assign(&mut self, offset: ByteSize)

Performs the += operation. Read more
source§

impl BitAnd<u8> for Address

§

type Output = u8

The resulting type after applying the & operator.
source§

fn bitand(self, other: u8) -> u8

Performs the & operation. Read more
source§

impl BitAnd<usize> for Address

Address & mask

§

type Output = usize

The resulting type after applying the & operator.
source§

fn bitand(self, other: usize) -> usize

Performs the & operation. Read more
source§

impl BitOr<u8> for Address

§

type Output = usize

The resulting type after applying the | operator.
source§

fn bitor(self, other: u8) -> usize

Performs the | operation. Read more
source§

impl BitOr<usize> for Address

Address | mask

§

type Output = usize

The resulting type after applying the | operator.
source§

fn bitor(self, other: usize) -> usize

Performs the | operation. Read more
source§

impl Clone for Address

source§

fn clone(&self) -> Address

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 Address

allows Debug format the Address (as upper-case hex value with 0x prefix)

source§

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

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

impl Display for Address

allows Display format the Address (as upper-case hex value with 0x prefix)

source§

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

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

impl Edge for Address

For backword compatibility, we let Address implement Edge so that existing bindings that use Address to represent an edge can continue to work.

However, we should use SimpleEdge directly instead of using Address. The purpose of the Address type is to represent an address in memory. It is not directly related to fields that hold references to other objects. Calling load() and store() on an Address does not indicate how many bytes to load or store, or how to interpret those bytes. On the other hand, SimpleEdge is all about how to access a field that holds a reference represented simply as an ObjectReference. The intention and the semantics are clearer with SimpleEdge.

source§

fn load(&self) -> Option<ObjectReference>

Load object reference from the slot. Read more
source§

fn store(&self, object: ObjectReference)

Store the object reference object into the slot. Read more
source§

fn prefetch_load(&self)

Prefetch the edge so that a subsequent load will be faster.
source§

fn prefetch_store(&self)

Prefetch the edge so that a subsequent store will be faster.
source§

impl FromStr for Address

§

type Err = ParseIntError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for Address

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 LowerHex for Address

allows print Address as lower-case hex value

source§

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

Formats the value using the given formatter.
source§

impl Ord for Address

source§

fn cmp(&self, other: &Address) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Address

source§

fn eq(&self, other: &Address) -> 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 PartialOrd for Address

source§

fn partial_cmp(&self, other: &Address) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Shl<usize> for Address

Address << shift (get an index)

§

type Output = usize

The resulting type after applying the << operator.
source§

fn shl(self, shift: usize) -> usize

Performs the << operation. Read more
source§

impl Shr<usize> for Address

Address >> shift (get an index)

§

type Output = usize

The resulting type after applying the >> operator.
source§

fn shr(self, shift: usize) -> usize

Performs the >> operation. Read more
source§

impl Sub<usize> for Address

Address - ByteSize (positive)

§

type Output = Address

The resulting type after applying the - operator.
source§

fn sub(self, offset: ByteSize) -> Address

Performs the - operation. Read more
source§

impl Sub for Address

Address - Address (the first address must be higher)

§

type Output = usize

The resulting type after applying the - operator.
source§

fn sub(self, other: Address) -> ByteSize

Performs the - operation. Read more
source§

impl SubAssign<usize> for Address

Address -= ByteSize (positive)

source§

fn sub_assign(&mut self, offset: ByteSize)

Performs the -= operation. Read more
source§

impl UpperHex for Address

allows print Address as upper-case hex value

source§

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

Formats the value using the given formatter.
source§

impl Copy for Address

source§

impl Eq for Address

source§

impl NoUninit for Address

source§

impl StructuralPartialEq for Address

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.