From 6724d8649ab73e4fb86c8014bda51b13bddf2f3f Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Mon, 18 Aug 2014 15:02:59 -0700 Subject: [PATCH] Fix heap corruption and verification. There was a faulty assumption that space End() was always aligned to card boundaries. This was true for all spaces other than the image and resulted in heap corruption when the last object of the image space contained a reference to an object in another space. Also fixed an error where we called the pre GC verification post GC. Bug: 17080623 Change-Id: I041ee564518f53b79c6e8dc2ad782a3152577a4e --- runtime/gc/accounting/card_table-inl.h | 2 +- runtime/gc/heap.cc | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/gc/accounting/card_table-inl.h b/runtime/gc/accounting/card_table-inl.h index 217360f21..3b06f74d7 100644 --- a/runtime/gc/accounting/card_table-inl.h +++ b/runtime/gc/accounting/card_table-inl.h @@ -55,7 +55,7 @@ inline size_t CardTable::Scan(ContinuousSpaceBitmap* bitmap, byte* scan_begin, b // scan_end is the byte after the last byte we scan. DCHECK_LE(scan_end, reinterpret_cast(bitmap->HeapLimit())); byte* card_cur = CardFromAddr(scan_begin); - byte* card_end = CardFromAddr(scan_end); + byte* card_end = CardFromAddr(AlignUp(scan_end, kCardSize)); CheckCardValid(card_cur); CheckCardValid(card_end); size_t cards_scanned = 0; diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index ef60e8118..8d74f10eb 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -2503,7 +2503,6 @@ class VerifyLiveStackReferences { bool Heap::VerifyMissingCardMarks() { Thread* self = Thread::Current(); Locks::mutator_lock_->AssertExclusiveHeld(self); - // We need to sort the live stack since we binary search it. live_stack_->Sort(); // Since we sorted the allocation stack content, need to revoke all @@ -2511,7 +2510,6 @@ bool Heap::VerifyMissingCardMarks() { RevokeAllThreadLocalAllocationStacks(self); VerifyLiveStackReferences visitor(this); GetLiveBitmap()->Visit(visitor); - // We can verify objects in the live stack since none of these should reference dead objects. for (mirror::Object** it = live_stack_->Begin(); it != live_stack_->End(); ++it) { if (!kUseThreadLocalAllocationStack || *it != nullptr) { @@ -2698,7 +2696,7 @@ void Heap::PostGcVerificationPaused(collector::GarbageCollector* gc) { void Heap::PostGcVerification(collector::GarbageCollector* gc) { if (verify_system_weaks_ || verify_post_gc_rosalloc_ || verify_post_gc_heap_) { collector::GarbageCollector::ScopedPause pause(gc); - PreGcVerificationPaused(gc); + PostGcVerificationPaused(gc); } } -- 2.11.0