Struct mmtk::util::address::Address[][src]

#[repr(transparent)]pub struct Address(_);

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.

Implementations

impl Address[src]

pub const ZERO: Self[src]

pub const MAX: Self[src]

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

creates Address from a pointer

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

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

creates Address from a mutable pointer

pub const unsafe fn zero() -> Address[src]

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

).

pub unsafe fn max() -> Address[src]

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

).

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

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.

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

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

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

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

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

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

loads a value of type T from the address

Safety

This could throw a segment fault if the address is invalid

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

stores a value of type T to the address

Safety

This could throw a segment fault if the address is invalid

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

atomic operation: load

Safety

This could throw a segment fault if the address is invalid

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

atomic operation: store

Safety

This could throw a segment fault if the address is invalid

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

atomic operation: compare and exchange usize

Safety

This could throw a segment fault if the address is invalid

pub fn is_zero(self) -> bool[src]

is this address zero?

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

aligns up the address to the given alignment

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

aligns down the address to the given alignment

pub fn is_aligned_to(self, align: usize) -> bool[src]

is this address aligned to the given alignment

pub unsafe fn to_object_reference(self) -> ObjectReference[src]

converts the Address into an ObjectReference

Safety

We would expect ObjectReferences point to valid objects, but an arbitrary Address may not reside an object. This conversion is unsafe, and it is the user’s responsibility to ensure the safety.

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

converts the Address to a pointer

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

converts the Address to a mutable pointer

pub const fn as_usize(self) -> usize[src]

converts the Address to a pointer-sized integer

pub fn chunk_index(self) -> usize[src]

returns the chunk index for this address

pub fn is_mapped(self) -> bool[src]

return true if the referenced memory is mapped

Trait Implementations

impl Add<isize> for Address[src]

Address + ByteOffset (positive or negative)

type Output = Address

The resulting type after applying the + operator.

impl Add<usize> for Address[src]

Address + ByteSize (positive)

type Output = Address

The resulting type after applying the + operator.

impl AddAssign<isize> for Address[src]

Address += ByteOffset (positive or negative)

impl AddAssign<usize> for Address[src]

Address += ByteSize (positive)

impl BitAnd<u8> for Address[src]

type Output = u8

The resulting type after applying the & operator.

impl BitAnd<usize> for Address[src]

Address & mask

type Output = usize

The resulting type after applying the & operator.

impl BitOr<u8> for Address[src]

type Output = usize

The resulting type after applying the | operator.

impl BitOr<usize> for Address[src]

Address | mask

type Output = usize

The resulting type after applying the | operator.

impl Clone for Address[src]

impl Copy for Address[src]

impl Debug for Address[src]

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

impl Display for Address[src]

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

impl Eq for Address[src]

impl Hash for Address[src]

impl LowerHex for Address[src]

allows print Address as lower-case hex value

impl PartialEq<Address> for Address[src]

impl PartialOrd<Address> for Address[src]

impl Shl<usize> for Address[src]

Address << shift (get an index)

type Output = usize

The resulting type after applying the << operator.

impl Shr<usize> for Address[src]

Address >> shift (get an index)

type Output = usize

The resulting type after applying the >> operator.

impl StructuralEq for Address[src]

impl StructuralPartialEq for Address[src]

impl Sub<Address> for Address[src]

Address - Address (the first address must be higher)

type Output = ByteSize

The resulting type after applying the - operator.

impl Sub<usize> for Address[src]

Address - ByteSize (positive)

type Output = Address

The resulting type after applying the - operator.

impl SubAssign<usize> for Address[src]

Address -= ByteSize (positive)

impl UpperHex for Address[src]

allows print Address as upper-case hex value

Auto Trait Implementations

impl RefUnwindSafe for Address

impl Send for Address

impl Sync for Address

impl Unpin for Address

impl UnwindSafe for Address

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Downcast for T where
    T: Any
[src]

impl<T> DowncastSync for T where
    T: Any + Send + Sync
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.