Chromium Code Reviews| Index: src/heap/mark-compact.cc |
| diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc |
| index 0b331e33f30e59fb7b29e3d178fb049c0dc0d401..21423d8de1159830dd7f849ba84f93d5a60d0e13 100644 |
| --- a/src/heap/mark-compact.cc |
| +++ b/src/heap/mark-compact.cc |
| @@ -3303,7 +3303,6 @@ void MarkCompactCollector::EvacuatePages( |
| intptr_t live_bytes = p->LiveBytes(); |
| AlwaysAllocateScope always_allocate(isolate()); |
| if (VisitLiveObjects(p, &visitor, kClearMarkbits)) { |
| - p->ResetLiveBytes(); |
| p->parallel_compaction_state().SetValue( |
| MemoryChunk::kCompactingFinalize); |
| compaction_spaces->ReportCompactionProgress( |
| @@ -3792,19 +3791,22 @@ void MarkCompactCollector::ReleaseEvacuationCandidates() { |
| int MarkCompactCollector::SweepInParallel(PagedSpace* space, |
| - int required_freed_bytes) { |
| + int required_freed_bytes, |
| + int max_pages) { |
| int max_freed = 0; |
| int max_freed_overall = 0; |
| - PageIterator it(space); |
| - while (it.has_next()) { |
| - Page* p = it.next(); |
| + int page_count = 0; |
| + for (Page* p : sweeping_list(space)) { |
|
Hannes Payer (out of office)
2016/01/20 09:25:03
Since we have now a separate data structure, why d
Michael Lippautz
2016/01/20 11:11:16
Because removing items from a std::vector can be q
Hannes Payer (out of office)
2016/01/20 12:08:19
Why don't we use a priority_queue?
|
| max_freed = SweepInParallel(p, space); |
| DCHECK(max_freed >= 0); |
| if (required_freed_bytes > 0 && max_freed >= required_freed_bytes) { |
| return max_freed; |
| } |
| max_freed_overall = Max(max_freed, max_freed_overall); |
| - if (p == space->end_of_unswept_pages()) break; |
| + page_count++; |
| + if (max_pages > 0 && page_count >= max_pages) { |
| + break; |
| + } |
| } |
| return max_freed_overall; |
| } |
| @@ -3848,15 +3850,10 @@ int MarkCompactCollector::SweepInParallel(Page* page, PagedSpace* space) { |
| void MarkCompactCollector::StartSweepSpace(PagedSpace* space) { |
| space->ClearStats(); |
| - // We defensively initialize end_of_unswept_pages_ here with the first page |
| - // of the pages list. |
| - space->set_end_of_unswept_pages(space->FirstPage()); |
| - |
| PageIterator it(space); |
| - int pages_swept = 0; |
| + int will_be_swept = 0; |
| bool unused_page_present = false; |
| - bool parallel_sweeping_active = false; |
| while (it.has_next()) { |
| Page* p = it.next(); |
| @@ -3894,39 +3891,19 @@ void MarkCompactCollector::StartSweepSpace(PagedSpace* space) { |
| unused_page_present = true; |
| } |
| - if (!parallel_sweeping_active) { |
| - if (FLAG_gc_verbose) { |
| - PrintIsolate(isolate(), "sweeping: %p", p); |
| - } |
| - if (space->identity() == CODE_SPACE) { |
| - if (FLAG_zap_code_space) { |
| - Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST, |
| - ZAP_FREE_SPACE>(space, NULL, p, NULL); |
| - } else { |
| - Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST, |
| - IGNORE_FREE_SPACE>(space, NULL, p, NULL); |
| - } |
| - } else { |
| - Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, IGNORE_SKIP_LIST, |
| - IGNORE_FREE_SPACE>(space, NULL, p, NULL); |
| - } |
| - pages_swept++; |
| - parallel_sweeping_active = true; |
| - } else { |
| - if (FLAG_gc_verbose) { |
| - PrintIsolate(isolate(), "sweeping: initialized for parallel: %p", p); |
| - } |
| - p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingPending); |
| - int to_sweep = p->area_size() - p->LiveBytes(); |
| - space->accounting_stats_.ShrinkSpace(to_sweep); |
| - } |
| - space->set_end_of_unswept_pages(p); |
| + sweeping_list(space).push_back(p); |
| + p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingPending); |
| + int to_sweep = p->area_size() - p->LiveBytes(); |
| + space->accounting_stats_.ShrinkSpace(to_sweep); |
| + will_be_swept++; |
| } |
| if (FLAG_gc_verbose) { |
| - PrintIsolate(isolate(), "sweeping: space=%s pages_swept=%d", |
| - AllocationSpaceName(space->identity()), pages_swept); |
| + PrintIsolate(isolate(), "sweeping: space=%s initialized_for_sweeping=%d", |
| + AllocationSpaceName(space->identity()), will_be_swept); |
| } |
| + std::sort(sweeping_list(space).begin(), sweeping_list(space).end(), |
| + [](Page* a, Page* b) { return a->LiveBytes() < b->LiveBytes(); }); |
| } |
| @@ -3980,9 +3957,7 @@ void MarkCompactCollector::SweepSpaces() { |
| void MarkCompactCollector::ParallelSweepSpaceComplete(PagedSpace* space) { |
| - PageIterator it(space); |
| - while (it.has_next()) { |
| - Page* p = it.next(); |
| + for (Page* p : sweeping_list(space)) { |
| if (p->parallel_sweeping_state().Value() == |
| MemoryChunk::kSweepingFinalize) { |
| p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingDone); |
| @@ -3997,6 +3972,9 @@ void MarkCompactCollector::ParallelSweepSpacesComplete() { |
| ParallelSweepSpaceComplete(heap()->old_space()); |
| ParallelSweepSpaceComplete(heap()->code_space()); |
| ParallelSweepSpaceComplete(heap()->map_space()); |
| + sweeping_list(heap()->old_space()).clear(); |
| + sweeping_list(heap()->code_space()).clear(); |
| + sweeping_list(heap()->map_space()).clear(); |
| } |