Skip to content

Commit e79e94e

Browse files
authored
Use to_address for SFT access (#1122)
Changed convenient methods in `ObjectReference` so that if they use SFT, we use `self.to_address()` to get the address instead of `self.0` which returns the raw address. Also removed `ObjectReference::value()` to force users to use the more explicit `ObjectReference::to_raw_address()`.
1 parent 1bfd558 commit e79e94e

File tree

6 files changed

+24
-29
lines changed

6 files changed

+24
-29
lines changed

src/memory_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@ pub fn handle_user_collection_request<VM: VMBinding>(mmtk: &MMTK<VM>, tls: VMMut
557557
///
558558
/// Arguments:
559559
/// * `object`: The object reference to query.
560-
pub fn is_live_object(object: ObjectReference) -> bool {
561-
object.is_live()
560+
pub fn is_live_object<VM: VMBinding>(object: ObjectReference) -> bool {
561+
object.is_live::<VM>()
562562
}
563563

564564
/// Check if `addr` is the address of an object reference to an MMTk object.

src/policy/immix/immixspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ impl<VM: VMBinding> ImmixSpace<VM> {
650650
);
651651

652652
queue.enqueue(new_object);
653-
debug_assert!(new_object.is_live());
653+
debug_assert!(new_object.is_live::<VM>());
654654
self.unlog_object_if_needed(new_object);
655655
new_object
656656
}

src/util/address.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -546,49 +546,44 @@ impl ObjectReference {
546546
self.0 == 0
547547
}
548548

549-
/// returns the ObjectReference
550-
pub fn value(self) -> usize {
551-
self.0
552-
}
553-
554549
/// Is the object reachable, determined by the policy?
555550
/// Note: Objects in ImmortalSpace may have `is_live = true` but are actually unreachable.
556-
pub fn is_reachable(self) -> bool {
551+
pub fn is_reachable<VM: VMBinding>(self) -> bool {
557552
if self.is_null() {
558553
false
559554
} else {
560-
unsafe { SFT_MAP.get_unchecked(Address(self.0)) }.is_reachable(self)
555+
unsafe { SFT_MAP.get_unchecked(self.to_address::<VM>()) }.is_reachable(self)
561556
}
562557
}
563558

564559
/// Is the object live, determined by the policy?
565-
pub fn is_live(self) -> bool {
560+
pub fn is_live<VM: VMBinding>(self) -> bool {
566561
if self.0 == 0 {
567562
false
568563
} else {
569-
unsafe { SFT_MAP.get_unchecked(Address(self.0)) }.is_live(self)
564+
unsafe { SFT_MAP.get_unchecked(self.to_address::<VM>()) }.is_live(self)
570565
}
571566
}
572567

573568
/// Can the object be moved?
574-
pub fn is_movable(self) -> bool {
575-
unsafe { SFT_MAP.get_unchecked(Address(self.0)) }.is_movable()
569+
pub fn is_movable<VM: VMBinding>(self) -> bool {
570+
unsafe { SFT_MAP.get_unchecked(self.to_address::<VM>()) }.is_movable()
576571
}
577572

578573
/// Get forwarding pointer if the object is forwarded.
579-
pub fn get_forwarded_object(self) -> Option<Self> {
580-
unsafe { SFT_MAP.get_unchecked(Address(self.0)) }.get_forwarded_object(self)
574+
pub fn get_forwarded_object<VM: VMBinding>(self) -> Option<Self> {
575+
unsafe { SFT_MAP.get_unchecked(self.to_address::<VM>()) }.get_forwarded_object(self)
581576
}
582577

583578
/// Is the object in any MMTk spaces?
584-
pub fn is_in_any_space(self) -> bool {
585-
unsafe { SFT_MAP.get_unchecked(Address(self.0)) }.is_in_space(self)
579+
pub fn is_in_any_space<VM: VMBinding>(self) -> bool {
580+
unsafe { SFT_MAP.get_unchecked(self.to_address::<VM>()) }.is_in_space(self)
586581
}
587582

588583
/// Is the object sane?
589584
#[cfg(feature = "sanity")]
590-
pub fn is_sane(self) -> bool {
591-
unsafe { SFT_MAP.get_unchecked(Address(self.0)) }.is_sane()
585+
pub fn is_sane<VM: VMBinding>(self) -> bool {
586+
unsafe { SFT_MAP.get_unchecked(self.to_address::<VM>()) }.is_sane()
592587
}
593588
}
594589

src/util/finalizable_processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<F: Finalizable> FinalizableProcessor<F> {
5353
for mut f in self.candidates.drain(start..).collect::<Vec<F>>() {
5454
let reff = f.get_reference();
5555
trace!("Pop {:?} for finalization", reff);
56-
if reff.is_live() {
56+
if reff.is_live::<E::VM>() {
5757
FinalizableProcessor::<F>::forward_finalizable_reference(e, &mut f);
5858
trace!("{:?} is live, push {:?} back to candidates", reff, f);
5959
self.candidates.push(f);

src/util/reference_processor.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ impl ReferenceProcessor {
246246
// For references in the table, the reference needs to be valid, and if the referent is not null, it should be valid as well
247247
sync.references.iter().for_each(|reff| {
248248
debug_assert!(!reff.is_null());
249-
debug_assert!(reff.is_in_any_space());
249+
debug_assert!(reff.is_in_any_space::<VM>());
250250
let referent = VM::VMReferenceGlue::get_referent(*reff);
251251
if !VM::VMReferenceGlue::is_referent_cleared(referent) {
252252
debug_assert!(
253-
referent.is_in_any_space(),
253+
referent.is_in_any_space::<VM>(),
254254
"Referent {:?} (of reference {:?}) is not in any space",
255255
referent,
256256
reff
@@ -260,7 +260,7 @@ impl ReferenceProcessor {
260260
// For references that will be enqueue'd, the referent needs to be valid, and the referent needs to be null.
261261
sync.enqueued_references.iter().for_each(|reff| {
262262
debug_assert!(!reff.is_null());
263-
debug_assert!(reff.is_in_any_space());
263+
debug_assert!(reff.is_in_any_space::<VM>());
264264
let referent = VM::VMReferenceGlue::get_referent(*reff);
265265
debug_assert!(VM::VMReferenceGlue::is_referent_cleared(referent));
266266
});
@@ -397,7 +397,7 @@ impl ReferenceProcessor {
397397

398398
trace!("Processing reference: {:?}", reference);
399399

400-
if !reference.is_live() {
400+
if !reference.is_live::<E::VM>() {
401401
// Reference is currently unreachable but may get reachable by the
402402
// following trace. We postpone the decision.
403403
continue;
@@ -433,7 +433,7 @@ impl ReferenceProcessor {
433433

434434
// If the reference is dead, we're done with it. Let it (and
435435
// possibly its referent) be garbage-collected.
436-
if !reference.is_live() {
436+
if !reference.is_live::<E::VM>() {
437437
<E::VM as VMBinding>::VMReferenceGlue::clear_referent(reference);
438438
trace!(" UNREACHABLE reference: {}", reference);
439439
trace!(" (unreachable)");
@@ -456,11 +456,11 @@ impl ReferenceProcessor {
456456

457457
trace!(" => {}", new_reference);
458458

459-
if old_referent.is_live() {
459+
if old_referent.is_live::<E::VM>() {
460460
// Referent is still reachable in a way that is as strong as
461461
// or stronger than the current reference level.
462462
let new_referent = Self::get_forwarded_referent(trace, old_referent);
463-
debug_assert!(new_referent.is_live());
463+
debug_assert!(new_referent.is_live::<E::VM>());
464464
trace!(" ~> {}", new_referent);
465465

466466
// The reference object stays on the waiting list, and the

src/util/sanity/sanity_checker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<VM: VMBinding> ProcessEdgesWork for SanityGCProcessEdges<VM> {
195195
let mut sanity_checker = self.mmtk().sanity_checker.lock().unwrap();
196196
if !sanity_checker.refs.contains(&object) {
197197
// FIXME steveb consider VM-specific integrity check on reference.
198-
assert!(object.is_sane(), "Invalid reference {:?}", object);
198+
assert!(object.is_sane::<VM>(), "Invalid reference {:?}", object);
199199

200200
// Let plan check object
201201
assert!(

0 commit comments

Comments
 (0)