From d82e89ece0887e32e7630400db159ed01284f210 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Wed, 5 Aug 2015 10:10:07 -0700 Subject: [PATCH] Fix mod-union logic for native roots Bug: 22949217 Change-Id: I9e4631870160d5a9412df1eec2a7b79c65668542 --- runtime/gc/accounting/mod_union_table.cc | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/runtime/gc/accounting/mod_union_table.cc b/runtime/gc/accounting/mod_union_table.cc index 157f60931..b9e89253f 100644 --- a/runtime/gc/accounting/mod_union_table.cc +++ b/runtime/gc/accounting/mod_union_table.cc @@ -101,28 +101,34 @@ class ModUnionUpdateObjectReferencesVisitor { // Extra parameters are required since we use this same visitor signature for checking objects. void operator()(Object* obj, MemberOffset offset, bool is_static ATTRIBUTE_UNUSED) const SHARED_REQUIRES(Locks::mutator_lock_) { - // Only add the reference if it is non null and fits our criteria. - mirror::HeapReference* const obj_ptr = obj->GetFieldObjectReferenceAddr(offset); - mirror::Object* ref = obj_ptr->AsMirrorPtr(); - if (ref != nullptr && !from_space_->HasAddress(ref) && !immune_space_->HasAddress(ref)) { - *contains_reference_to_other_space_ = true; - visitor_->MarkHeapReference(obj_ptr); - } + MarkReference(obj->GetFieldObjectReferenceAddr(offset)); } void VisitRootIfNonNull(mirror::CompressedReference* root) const SHARED_REQUIRES(Locks::mutator_lock_) { - if (kIsDebugBuild && !root->IsNull()) { - VisitRoot(root); - } + VisitRoot(root); } void VisitRoot(mirror::CompressedReference* root) const SHARED_REQUIRES(Locks::mutator_lock_) { - DCHECK(from_space_->HasAddress(root->AsMirrorPtr())); + MarkReference(root); } private: + template + void MarkReference(mirror::ObjectReference* obj_ptr) const + SHARED_REQUIRES(Locks::mutator_lock_) { + // Only add the reference if it is non null and fits our criteria. + mirror::Object* ref = obj_ptr->AsMirrorPtr(); + if (ref != nullptr && !from_space_->HasAddress(ref) && !immune_space_->HasAddress(ref)) { + *contains_reference_to_other_space_ = true; + mirror::Object* new_object = visitor_->MarkObject(ref); + if (ref != new_object) { + obj_ptr->Assign(new_object); + } + } + } + MarkObjectVisitor* const visitor_; // Space which we are scanning space::ContinuousSpace* const from_space_; -- 2.11.0