Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking if the referent has been cleared #698

Merged
merged 2 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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