OSDN Git Service

Check pending exception result in AllocObjectWithAllocator.
authorMathieu Chartier <mathieuc@google.com>
Thu, 21 Aug 2014 01:19:23 +0000 (18:19 -0700)
committerMathieu Chartier <mathieuc@google.com>
Thu, 21 Aug 2014 01:45:40 +0000 (18:45 -0700)
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

runtime/gc/heap-inl.h

index 7d3fd2d..d1fb600 100644 (file)
@@ -84,7 +84,9 @@ inline mirror::Object* Heap::AllocObjectWithAllocator(Thread* self, mirror::Clas
                                    &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);
         }