| Index: runtime/vm/heap.cc
|
| diff --git a/runtime/vm/heap.cc b/runtime/vm/heap.cc
|
| index fd22740abb4cf19fd94ec30ba3dd59720b629247..c3353d276231028b1ad6b2c3730b12b01c241163 100644
|
| --- a/runtime/vm/heap.cc
|
| +++ b/runtime/vm/heap.cc
|
| @@ -89,18 +89,18 @@ uword Heap::AllocateOld(intptr_t size, HeapPage::PageType type) {
|
| // If we are in the process of running a sweep, wait for the sweeper to free
|
| // memory.
|
| Thread* thread = Thread::Current();
|
| - {
|
| - MonitorLocker ml(old_space_.tasks_lock());
|
| - addr = old_space_.TryAllocate(size, type);
|
| - while ((addr == 0) && (old_space_.tasks() > 0)) {
|
| - ml.WaitWithSafepointCheck(thread);
|
| + if (thread->CanCollectGarbage()) {
|
| + {
|
| + MonitorLocker ml(old_space_.tasks_lock());
|
| addr = old_space_.TryAllocate(size, type);
|
| + while ((addr == 0) && (old_space_.tasks() > 0)) {
|
| + ml.WaitWithSafepointCheck(thread);
|
| + addr = old_space_.TryAllocate(size, type);
|
| + }
|
| + }
|
| + if (addr != 0) {
|
| + return addr;
|
| }
|
| - }
|
| - if (addr != 0) {
|
| - return addr;
|
| - }
|
| - if (thread->CanCollectGarbage()) {
|
| // All GC tasks finished without allocating successfully. Run a full GC.
|
| CollectAllGarbage();
|
| addr = old_space_.TryAllocate(size, type);
|
|
|