When retrying a failed alloc use the new size if class was redefined
When jvmti redefines the class it can potentially change the size of the
object. If there are any allocations in progress on suspended threads
(for ex: the thread got suspended because of a GC while in the middle of
allocation) we restart the allocations. When restarting an allocation,
we should use the updated size of the class. This wasn't a correctness
issue since when we restart the allocation we call PreObjectAllocated
listeners if any redefinition has happened and that would update the
size. This was only causing failures with the Check that was using the
old size. It is cleaner if we just call the new alloc with the new size.
Bug:207842562
Test:testrunner.py --dex2oat-jobs 4 --jit --no-relocate --forcecopy --64
--host -t 2005-pause-all-redefine-multithreaded
Change-Id: I6e5bf1b5439a1a20f7b1a333b1eda4aa4effa290
diff --git a/runtime/gc/heap-inl.h b/runtime/gc/heap-inl.h
index 9017f30..9e1524e 100644
--- a/runtime/gc/heap-inl.h
+++ b/runtime/gc/heap-inl.h
@@ -160,11 +160,14 @@
if (!self->IsExceptionPending()) {
// Since we are restarting, allow thread suspension.
ScopedAllowThreadSuspension ats;
+ // Get the new class size in case class redefinition changed the class size since alloc
+ // started.
+ int new_byte_count = klass->IsVariableSize()? byte_count : klass->GetObjectSize();
// AllocObject will pick up the new allocator type, and instrumented as true is the safe
// default.
return AllocObjectWithAllocator</*kInstrumented=*/true>(self,
klass,
- byte_count,
+ new_byte_count,
GetUpdatedAllocator(allocator),
pre_fence_visitor);
}