Chromium Code Reviews| Index: src/spaces.cc |
| diff --git a/src/spaces.cc b/src/spaces.cc |
| index 194f75dfbfa56e0c3498cb83f63ade07df0596eb..66a2a074cb19f7b1bfe7738486ffd343aa09da24 100644 |
| --- a/src/spaces.cc |
| +++ b/src/spaces.cc |
| @@ -2577,6 +2577,22 @@ void PagedSpace::EvictEvacuationCandidatesFromFreeLists() { |
| } |
| +HeapObject* PagedSpace::WaitForSweeperThreadsAndRetryAllocation( |
| + int size_in_bytes) { |
| + MarkCompactCollector* collector = heap()->mark_compact_collector(); |
| + |
| + // If sweeper threads are still running, wait for them. |
| + if (collector->IsConcurrentSweepingInProgress()) { |
| + collector->WaitUntilSweepingCompleted(); |
| + |
| + // After waiting for the sweeper threads, there may be new free-list |
| + // entries. |
| + return free_list_.Allocate(size_in_bytes); |
| + } |
| + return NULL; |
| +} |
| + |
| + |
| HeapObject* PagedSpace::SlowAllocateRaw(int size_in_bytes) { |
| // Allocation in this space has failed. |
| @@ -2587,25 +2603,20 @@ HeapObject* PagedSpace::SlowAllocateRaw(int size_in_bytes) { |
| // Retry the free list allocation. |
| HeapObject* object = free_list_.Allocate(size_in_bytes); |
| - if (object != NULL) return object; |
| + if (object != NULL) |
| + return object; |
| } |
| // Free list allocation failed and there is no next page. Fail if we have |
| // hit the old generation size limit that should cause a garbage |
| // collection. |
| - if (!heap()->always_allocate() && |
| - heap()->OldGenerationAllocationLimitReached()) { |
| - // If sweeper threads are active, wait for them at that point. |
| - if (collector->IsConcurrentSweepingInProgress()) { |
| - collector->WaitUntilSweepingCompleted(); |
| - |
| - // After waiting for the sweeper threads, there may be new free-list |
| - // entries. |
| - HeapObject* object = free_list_.Allocate(size_in_bytes); |
| - if (object != NULL) return object; |
| - } |
| - |
| - return NULL; |
| + if (!heap()->always_allocate() |
| + && heap()->OldGenerationAllocationLimitReached()) { |
| + // If sweeper threads are active, wait for them at that point and steal |
| + // elements form their free-lists. |
| + HeapObject* object = WaitForSweeperThreadsAndRetryAllocation(size_in_bytes); |
| + if (object != NULL) |
|
ulan
2014/06/30 09:32:47
Nit: it should be either a single line or use {}
Hannes Payer (out of office)
2014/06/30 12:38:25
Done.
|
| + return object; |
| } |
| // Try to expand the space and allocate in the new next page. |
| @@ -2614,8 +2625,10 @@ HeapObject* PagedSpace::SlowAllocateRaw(int size_in_bytes) { |
| return free_list_.Allocate(size_in_bytes); |
| } |
| - // Finally, fail. |
| - return NULL; |
| + // If sweeper threads are active, wait for them at that point and steal |
| + // elements form their free-lists. Allocation may still fail their which |
| + // would indicate that there is not enough memory for the given allocation. |
| + return WaitForSweeperThreadsAndRetryAllocation(size_in_bytes); |
| } |