diff --git a/src/util/reference_processor.rs b/src/util/reference_processor.rs index 7998a7bba9..cc8b2ae8d4 100644 --- a/src/util/reference_processor.rs +++ b/src/util/reference_processor.rs @@ -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", @@ -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)); }); } @@ -402,7 +402,7 @@ impl ReferenceProcessor { // Reference is definitely reachable. Retain the referent. let referent = ::VMReferenceGlue::get_referent(*reference); - if !referent.is_null() { + if !::VMReferenceGlue::is_referent_cleared(referent) { Self::keep_referent_alive(trace, referent); } trace!(" ~> {:?} (retained)", referent.to_address()); @@ -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 ::VMReferenceGlue::is_referent_cleared(old_referent) { + trace!(" (cleared referent) "); return None; } diff --git a/src/vm/reference_glue.rs b/src/vm/reference_glue.rs index 299c7a6010..b36d720e90 100644 --- a/src/vm/reference_glue.rs +++ b/src/vm/reference_glue.rs @@ -43,6 +43,14 @@ pub trait ReferenceGlue { /// * `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