OSDN Git Service

Fix heap check.
authorMathieu Chartier <mathieuc@google.com>
Thu, 21 Apr 2016 17:23:16 +0000 (10:23 -0700)
committerMathieu Chartier <mathieuc@google.com>
Thu, 21 Apr 2016 17:38:53 +0000 (10:38 -0700)
Previously, we only checked the image we were patching. This did not
work if the referent was in another image. Fixed the DCHECK to check
all the boot images.

Bug: 28286961
Change-Id: I7195314e531d0a950d495296d1e2f953e7b66659

patchoat/patchoat.cc
patchoat/patchoat.h

index a1b3c9e..93e40af 100644 (file)
@@ -650,12 +650,6 @@ bool PatchOat::PatchImage(bool primary_image) {
   return true;
 }
 
-bool PatchOat::InHeap(mirror::Object* o) {
-  uintptr_t begin = reinterpret_cast<uintptr_t>(heap_->Begin());
-  uintptr_t end = reinterpret_cast<uintptr_t>(heap_->End());
-  uintptr_t obj = reinterpret_cast<uintptr_t>(o);
-  return o == nullptr || (begin <= obj && obj < end);
-}
 
 void PatchOat::PatchVisitor::operator() (mirror::Object* obj, MemberOffset off,
                                          bool is_static_unused ATTRIBUTE_UNUSED) const {
@@ -668,7 +662,8 @@ void PatchOat::PatchVisitor::operator() (mirror::Class* cls ATTRIBUTE_UNUSED,
                                          mirror::Reference* ref) const {
   MemberOffset off = mirror::Reference::ReferentOffset();
   mirror::Object* referent = ref->GetReferent();
-  DCHECK(patcher_->InHeap(referent)) << "Referent is not in the heap.";
+  DCHECK(referent == nullptr ||
+         Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(referent)) << referent;
   mirror::Object* moved_object = patcher_->RelocatedAddressOfPointer(referent);
   copy_->SetFieldObjectWithoutWriteBarrier<false, true, kVerifyNone>(off, moved_object);
 }
index a6a8fee..510ff1e 100644 (file)
@@ -106,7 +106,6 @@ class PatchOat {
       SHARED_REQUIRES(Locks::mutator_lock_);
   void FixupMethod(ArtMethod* object, ArtMethod* copy)
       SHARED_REQUIRES(Locks::mutator_lock_);
-  bool InHeap(mirror::Object*);
 
   // Patches oat in place, modifying the oat_file given to the constructor.
   bool PatchElf();