#[repr(transparent)]
pub struct ObjectReference(NonZeroUsize);
Expand description

ObjectReference represents address for an object. Compared with Address, operations allowed on ObjectReference are very limited. No address arithmetics are allowed for ObjectReference. The idea is from the paper High-level Low-level Programming (VEE09) and JikesRVM.

A runtime may define its “object references” differently. It may define an object reference as the address of an object, a handle that points to an indirection table entry where a pointer to the object is held, or anything else. Regardless, MMTk expects each object reference to have a pointer to the object (an address) in each object reference, and that address should be used for this ObjectReference type.

We currently do not allow an opaque ObjectReference type for which a binding can define their layout. We now only allow a binding to define their semantics through a set of methods in crate::vm::ObjectModel. Major refactoring is needed in MMTk to allow the opaque ObjectReference type, and we haven’t seen a use case for now.

Note that ObjectReference cannot be null. For the cases where a non-null object reference may or may not exist, (such as the result of crate::vm::slot::Slot::load) Option<ObjectReference> should be used. ObjectReference is backed by NonZeroUsize which cannot be zero, and it has the #[repr(transparent)] attribute. Thanks to null pointer optimization (NPO), Option<ObjectReference> has the same size as NonZeroUsize and usize. For the convenience of passing Option<ObjectReference> to and from native (C/C++) programs, mmtk-core provides crate::util::api_util::NullableObjectReference.

Tuple Fields§

§0: NonZeroUsize

Implementations§

source§

impl ObjectReference

source

pub fn to_raw_address(self) -> Address

Cast the object reference to its raw address. This method is mostly for the convinience of a binding.

MMTk should not make any assumption on the actual location of the address with the object reference. MMTk should not assume the address returned by this method is in our allocation. For the purposes of setting object metadata, MMTk should use crate::vm::ObjectModel::ref_to_address() or crate::vm::ObjectModel::ref_to_header().

source

pub fn from_raw_address(addr: Address) -> Option<ObjectReference>

Cast a raw address to an object reference. This method is mostly for the convinience of a binding. This is how a binding creates ObjectReference instances.

If addr is 0, the result is None.

MMTk should not assume an arbitrary address can be turned into an object reference. MMTk can use crate::vm::ObjectModel::address_to_ref() to turn addresses that are from crate::vm::ObjectModel::ref_to_address() back to object.

source

pub unsafe fn from_raw_address_unchecked(addr: Address) -> ObjectReference

Like from_raw_address, but assume addr is not zero. This can be used to elide a check against zero for performance-critical code.

§Safety

This method assumes addr is not zero. It should only be used in cases where we know at compile time that the input cannot be zero. For example, if we compute the address by adding a positive offset to a non-zero address, we know the result must not be zero.

source

pub fn to_address<VM: VMBinding>(self) -> Address

Get the in-heap address from an object reference. This method is used by MMTk to get an in-heap address for an object reference. This method is syntactic sugar for crate::vm::ObjectModel::ref_to_address. See the comments on crate::vm::ObjectModel::ref_to_address.

source

pub fn to_header<VM: VMBinding>(self) -> Address

Get the header base address from an object reference. This method is used by MMTk to get a base address for the object header, and access the object header. This method is syntactic sugar for crate::vm::ObjectModel::ref_to_header. See the comments on crate::vm::ObjectModel::ref_to_header.

source

pub fn to_object_start<VM: VMBinding>(self) -> Address

Get the start of the allocation address for the object. This method is used by MMTk to get the start of the allocation address originally returned from crate::memory_manager::alloc for the object. This method is syntactic sugar for crate::vm::ObjectModel::ref_to_object_start. See comments on crate::vm::ObjectModel::ref_to_object_start.

source

pub fn from_address<VM: VMBinding>(addr: Address) -> ObjectReference

Get the object reference from an address that is returned from crate::util::address::ObjectReference::to_address or crate::vm::ObjectModel::ref_to_address. This method is syntactic sugar for crate::vm::ObjectModel::address_to_ref. See the comments on crate::vm::ObjectModel::address_to_ref.

source

pub fn is_reachable<VM: VMBinding>(self) -> bool

Is the object reachable, determined by the policy? Note: Objects in ImmortalSpace may have is_live = true but are actually unreachable.

source

pub fn is_live<VM: VMBinding>(self) -> bool

Is the object live, determined by the policy?

source

pub fn is_movable<VM: VMBinding>(self) -> bool

Can the object be moved?

source

pub fn get_forwarded_object<VM: VMBinding>(self) -> Option<Self>

Get forwarding pointer if the object is forwarded.

source

pub fn is_in_any_space<VM: VMBinding>(self) -> bool

Is the object in any MMTk spaces?

source

pub fn is_sane<VM: VMBinding>(self) -> bool

Is the object sane?

Trait Implementations§

source§

impl Clone for ObjectReference

source§

fn clone(&self) -> ObjectReference

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 ObjectReference

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 ObjectReference

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 Finalizable for ObjectReference

This provides an implementation of Finalizable for ObjectReference. Most bindings should be able to use ObjectReference as ReferenceGlue::FinalizableType.

source§

fn get_reference(&self) -> ObjectReference

Load the object reference.
source§

fn set_reference(&mut self, object: ObjectReference)

Store the object reference.
source§

fn keep_alive<E: ProcessEdgesWork>(&mut self, trace: &mut E)

Keep the heap references in the finalizable object alive. For example, the reference itself needs to be traced. However, if the finalizable object includes other heap references, the implementation should trace them as well. Note that trace_object() may move objects so we need to write the new reference in case that it is moved.
source§

impl Hash for ObjectReference

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 ObjectReference

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 ObjectReference

source§

fn cmp(&self, other: &ObjectReference) -> 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 ObjectReference

source§

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

source§

fn partial_cmp(&self, other: &ObjectReference) -> 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 UpperHex for ObjectReference

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 ObjectReference

source§

impl Eq for ObjectReference

source§

impl NoUninit for ObjectReference

source§

impl StructuralPartialEq for ObjectReference

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.