Trait mmtk::vm::edge_shape::Edge

source ·
pub trait Edge: Copy + Send + Debug + PartialEq + Eq + Hash {
    // Required methods
    fn load(&self) -> ObjectReference;
    fn store(&self, object: ObjectReference);

    // Provided methods
    fn prefetch_load(&self) { ... }
    fn prefetch_store(&self) { ... }
}
Expand description

An abstract edge. An edge holds an object reference. When we load from it, we get an ObjectReference; we can also store an ObjectReference into it.

This intends to abstract out the differences of reference field representation among different VMs. If the VM represent a reference field as a word that holds the pointer to the object, it can use the default SimpleEdge we provide. In some cases, the VM need to implement its own Edge instances.

For example:

  • The VM uses compressed pointer (Compressed OOP in OpenJDK’s terminology), where the heap size is limited, and a 64-bit pointer is stored in a 32-bit slot.
  • The VM uses tagged pointer, where some bits of a word are used as metadata while the rest are used as pointer.
  • A field holds a pointer to the middle of an object (an object field, or an array element, or some arbitrary offset) for some reasons.

When loading, Edge::load shall decode its internal representation to a “regular” ObjectReference. The implementation can do this with any appropriate operations, usually shifting and masking bits or subtracting offset from the address. By doing this conversion, MMTk can implement GC algorithms in a VM-neutral way, knowing only ObjectReference.

When GC moves object, Edge::store shall convert the updated ObjectReference back to the edge-specific representation. Compressed pointers remain compressed; tagged pointers preserve their tag bits; and offsetted pointers keep their offsets.

The methods of this trait are called on hot paths. Please ensure they have high performance. Use inlining when appropriate.

Note: this trait only concerns the representation (i.e. the shape) of the edge, not its semantics, such as whether it holds strong or weak references. If a VM holds a weak reference in a word as a pointer, it can also use SimpleEdge for weak reference fields.

Required Methods§

source

fn load(&self) -> ObjectReference

Load object reference from the edge.

source

fn store(&self, object: ObjectReference)

Store the object reference object into the edge.

Provided Methods§

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.

Implementors§

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§

impl Edge for SimpleEdge