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

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

    // Provided methods
    fn clear_referent(new_reference: ObjectReference) { ... }
    fn is_referent_cleared(referent: ObjectReference) -> bool { ... }
}
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§

source

type FinalizableType: Finalizable

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

Required Methods§

source

fn get_referent(object: ObjectReference) -> ObjectReference

Get the referent from a weak reference object.

Arguments:

  • object: The object reference.
source

fn set_referent(reff: ObjectReference, referent: ObjectReference)

Set the referent in a weak reference object.

Arguments:

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

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.

Provided Methods§

source

fn clear_referent(new_reference: ObjectReference)

Weak and soft references always clear the referent before enqueueing.

Arguments:

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

fn is_referent_cleared(referent: ObjectReference) -> bool

Check if the referent has been cleared.

Arguments:

  • referent: The referent object reference.

Implementors§