Skip to content

Commit

Permalink
Checking if the referent has been cleared (#698)
Browse files Browse the repository at this point in the history
Some runtimes clear reference to a different value other than null. This PR adds a method to the ReferenceGlue trait to check if a reference is cleared and replac the checks in mmtk-core to call this method instead. Therefore, bindings can overwrite the method `is_referent_cleared` to do the check properly.
  • Loading branch information
udesou authored Nov 15, 2022
1 parent c453a1c commit 9648aed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/util/reference_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl ReferenceProcessor {
debug_assert!(!reff.is_null());
debug_assert!(reff.is_in_any_space());
let referent = VM::VMReferenceGlue::get_referent(*reff);
if !referent.is_null() {
if !VM::VMReferenceGlue::is_referent_cleared(referent) {
debug_assert!(
referent.is_in_any_space(),
"Referent {:?} (of reference {:?}) is not in any space",
Expand All @@ -264,7 +264,7 @@ impl ReferenceProcessor {
debug_assert!(!reff.is_null());
debug_assert!(reff.is_in_any_space());
let referent = VM::VMReferenceGlue::get_referent(*reff);
debug_assert!(referent.is_null());
debug_assert!(VM::VMReferenceGlue::is_referent_cleared(referent));
});
}

Expand Down Expand Up @@ -402,7 +402,7 @@ impl ReferenceProcessor {

// Reference is definitely reachable. Retain the referent.
let referent = <E::VM as VMBinding>::VMReferenceGlue::get_referent(*reference);
if !referent.is_null() {
if !<E::VM as VMBinding>::VMReferenceGlue::is_referent_cleared(referent) {
Self::keep_referent_alive(trace, referent);
}
trace!(" ~> {:?} (retained)", referent.to_address());
Expand Down Expand Up @@ -446,8 +446,8 @@ impl ReferenceProcessor {
// this does not cause the Reference object to be enqueued. We
// simply allow the Reference object to fall out of our
// waiting list.
if old_referent.is_null() {
trace!(" (null referent) ");
if <E::VM as VMBinding>::VMReferenceGlue::is_referent_cleared(old_referent) {
trace!(" (cleared referent) ");
return None;
}

Expand Down
8 changes: 8 additions & 0 deletions src/vm/reference_glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ pub trait ReferenceGlue<VM: VMBinding> {
/// * `referent`: The referent object reference.
fn set_referent(reff: ObjectReference, referent: ObjectReference);

/// Check if the referent has been cleared.
///
/// Arguments:
/// * `referent`: The referent object reference.
fn is_referent_cleared(referent: ObjectReference) -> bool {
referent.is_null()
}

/// 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
Expand Down

0 comments on commit 9648aed

Please sign in to comment.