Trait mmtk::vm::reference_glue::ReferenceGlue
source · 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 implementsFinalizable
. 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 useObjectReference
for the finalizable type, meaning that they are registering and popping a normal object reference as finalizable objects.
Required Associated Types§
sourcetype FinalizableType: Finalizable
type FinalizableType: Finalizable
The type of finalizable objects. This type is used when the binding registers and pops finalizable objects.
Required Methods§
sourcefn clear_referent(new_reference: ObjectReference)
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.
sourcefn get_referent(object: ObjectReference) -> Option<ObjectReference>
fn get_referent(object: ObjectReference) -> Option<ObjectReference>
Get the referent from a weak reference object.
Arguments:
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.
sourcefn set_referent(reff: ObjectReference, referent: ObjectReference)
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.
sourcefn enqueue_references(references: &[ObjectReference], tls: VMWorkerThread)
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.