pub trait ReferenceGlue<VM: VMBinding> {
    type FinalizableType: Finalizable;

    // Required methods
    fn clear_referent(new_reference: ObjectReference);
    fn get_referent(object: ObjectReference) -> Option<ObjectReference>;
    fn set_referent(reff: ObjectReference, referent: ObjectReference);
    fn enqueue_references(references: &[ObjectReference], tls: VMWorkerThread);
Expand description

VM-specific methods for reference processing, including weak references, and finalizers. We handle weak references and finalizers differently:

  • for weak references, we assume they are implemented as normal reference objects (also known as weak objects) with a referent that is actually weakly reachable. This trait provides a few methods to access the referent of such an reference object.
  • for finalizers, we provide a Finalizable trait, and require bindings to specify a type that implements Finalizable. When the binding registers or pops a finalizable object from MMTk, the specified type is used for the finalizable objects. For most languages, they can just use ObjectReference for the finalizable type, meaning that they are registering and popping a normal object reference as finalizable objects.

Required Associated Types§


type FinalizableType: Finalizable

The type of finalizable objects. This type is used when the binding registers and pops finalizable objects.

Required Methods§


fn clear_referent(new_reference: ObjectReference)

Weak and soft references always clear the referent before enqueueing.


  • new_reference: The reference whose referent is to be cleared.

fn get_referent(object: ObjectReference) -> Option<ObjectReference>

Get the referent from a weak reference object.


  • object: Reference to the referent. `None`` if the object currently does not point to a referent. This may happen if the reference has been cleared.

fn set_referent(reff: ObjectReference, referent: ObjectReference)

Set the referent in a weak reference object.


  • reff: The object reference for the reference.
  • referent: The referent object reference.

fn enqueue_references(references: &[ObjectReference], tls: VMWorkerThread)

For weak reference types, if the referent is cleared during GC, the reference will be added to a queue, and MMTk will call this method to inform the VM about the changes for those references. This method is used to implement Java’s ReferenceQueue. Note that this method is called for each type of weak references during GC, and the references slice will be cleared after this call is returned. That means MMTk will no longer keep these references alive once this method is returned.

Object Safety§

This trait is not object safe.