Compare rounded sizes in CheckPreconditionsForAllocObject
Fixes a bug where the retrying the allocation for switching from
non instrumented -> instrumented would cause DCHECK failure because
it was comparing a rounded size to an unrounded size.
Bug: 37885600
Test: test-art-host
Change-Id: I2bffff6ae4e3c20b2e830a407a0688ba4cad51a1
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 6377c89..10fa4d2 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -3856,14 +3856,16 @@
void Heap::CheckPreconditionsForAllocObject(ObjPtr<mirror::Class> c, size_t byte_count) {
CHECK(c == nullptr || (c->IsClassClass() && byte_count >= sizeof(mirror::Class)) ||
- (c->IsVariableSize() || c->GetObjectSize() == byte_count))
+ (c->IsVariableSize() ||
+ RoundUp(c->GetObjectSize(), kObjectAlignment) ==
+ RoundUp(byte_count, kObjectAlignment)))
<< "ClassFlags=" << c->GetClassFlags()
<< " IsClassClass=" << c->IsClassClass()
<< " byte_count=" << byte_count
<< " IsVariableSize=" << c->IsVariableSize()
<< " ObjectSize=" << c->GetObjectSize()
<< " sizeof(Class)=" << sizeof(mirror::Class)
- << verification_->DumpObjectInfo(c.Ptr(), /*tag*/ "klass");
+ << " " << verification_->DumpObjectInfo(c.Ptr(), /*tag*/ "klass");
CHECK_GE(byte_count, sizeof(mirror::Object));
}