Check pending exception result in AllocObjectWithAllocator.
Possible previous bug:
Allocation fails due to OOM and the collector transitions.
This caused us to incorrectly retry the allocation with a pending
exception. We now return null if there is a pending exception.
Bug: 17164348
Change-Id: I22eab472afb2fdea6e800963ccb35ec0755ba0e6
diff --git a/runtime/gc/heap-inl.h b/runtime/gc/heap-inl.h
index 7d3fd2d..d1fb600 100644
--- a/runtime/gc/heap-inl.h
+++ b/runtime/gc/heap-inl.h
@@ -84,7 +84,9 @@
&klass);
if (obj == nullptr) {
bool after_is_current_allocator = allocator == GetCurrentAllocator();
- if (is_current_allocator && !after_is_current_allocator) {
+ // If there is a pending exception, fail the allocation right away since the next one
+ // could cause OOM and abort the runtime.
+ if (!self->IsExceptionPending() && is_current_allocator && !after_is_current_allocator) {
// If the allocator changed, we need to restart the allocation.
return AllocObject<kInstrumented>(self, klass, byte_count, pre_fence_visitor);
}