From 488849c584337a1aae8413a1d1e0fad8043bf672 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Thu, 21 Apr 2016 10:23:16 -0700 Subject: [PATCH] Fix heap check. 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 | 9 ++------- patchoat/patchoat.h | 1 - 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc index a1b3c9e12..93e40afea 100644 --- a/patchoat/patchoat.cc +++ b/patchoat/patchoat.cc @@ -650,12 +650,6 @@ bool PatchOat::PatchImage(bool primary_image) { return true; } -bool PatchOat::InHeap(mirror::Object* o) { - uintptr_t begin = reinterpret_cast(heap_->Begin()); - uintptr_t end = reinterpret_cast(heap_->End()); - uintptr_t obj = reinterpret_cast(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(off, moved_object); } diff --git a/patchoat/patchoat.h b/patchoat/patchoat.h index a6a8feeb3..510ff1e5b 100644 --- a/patchoat/patchoat.h +++ b/patchoat/patchoat.h @@ -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(); -- 2.11.0