Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/heap/mark-compact.h" | 5 #include "src/heap/mark-compact.h" |
| 6 | 6 |
| 7 #include "src/base/atomicops.h" | 7 #include "src/base/atomicops.h" |
| 8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/base/sys-info.h" | 9 #include "src/base/sys-info.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 int area_size = space->AreaSize(); | 676 int area_size = space->AreaSize(); |
| 677 | 677 |
| 678 // Pairs of (live_bytes_in_page, page). | 678 // Pairs of (live_bytes_in_page, page). |
| 679 typedef std::pair<int, Page*> LiveBytesPagePair; | 679 typedef std::pair<int, Page*> LiveBytesPagePair; |
| 680 std::vector<LiveBytesPagePair> pages; | 680 std::vector<LiveBytesPagePair> pages; |
| 681 pages.reserve(number_of_pages); | 681 pages.reserve(number_of_pages); |
| 682 | 682 |
| 683 PageIterator it(space); | 683 PageIterator it(space); |
| 684 while (it.has_next()) { | 684 while (it.has_next()) { |
| 685 Page* p = it.next(); | 685 Page* p = it.next(); |
| 686 // Invariant: No page should be marked as aborted after a GC. | |
| 687 DCHECK(!p->IsFlagSet(Page::COMPACTION_WAS_ABORTED)); | |
| 686 if (p->NeverEvacuate()) continue; | 688 if (p->NeverEvacuate()) continue; |
| 687 if (p->IsFlagSet(Page::POPULAR_PAGE)) { | 689 if (p->IsFlagSet(Page::POPULAR_PAGE)) { |
| 688 // This page had slots buffer overflow on previous GC, skip it. | 690 // This page had slots buffer overflow on previous GC, skip it. |
| 689 p->ClearFlag(Page::POPULAR_PAGE); | 691 p->ClearFlag(Page::POPULAR_PAGE); |
| 690 continue; | 692 continue; |
| 691 } | 693 } |
| 692 // Invariant: Evacuation candidates are just created when marking is | 694 // Invariant: Evacuation candidates are just created when marking is |
| 693 // started. At the end of a GC all evacuation candidates are cleared and | 695 // started. At the end of a GC all evacuation candidates are cleared and |
| 694 // their slot buffers are released. | 696 // their slot buffers are released. |
| 695 CHECK(!p->IsEvacuationCandidate()); | 697 CHECK(!p->IsEvacuationCandidate()); |
| (...skipping 2575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3271 // moved, others are still in place. | 3273 // moved, others are still in place. |
| 3272 // We need to: | 3274 // We need to: |
| 3273 // - Leave the evacuation candidate flag for later processing of | 3275 // - Leave the evacuation candidate flag for later processing of |
| 3274 // slots buffer entries. | 3276 // slots buffer entries. |
| 3275 // - Leave the slots buffer there for processing of entries added by | 3277 // - Leave the slots buffer there for processing of entries added by |
| 3276 // the write barrier. | 3278 // the write barrier. |
| 3277 // - Rescan the page as slot recording in the migration buffer only | 3279 // - Rescan the page as slot recording in the migration buffer only |
| 3278 // happens upon moving (which we potentially didn't do). | 3280 // happens upon moving (which we potentially didn't do). |
| 3279 // - Leave the page in the list of pages of a space since we could not | 3281 // - Leave the page in the list of pages of a space since we could not |
| 3280 // fully evacuate it. | 3282 // fully evacuate it. |
| 3283 // - Mark them for rescanning for store buffer entries as we otherwise | |
| 3284 // might have stale store buffer entries that become "valid" again | |
| 3285 // after reusing the memory. Note that all existing store buffer | |
| 3286 // entries of such pages are filtered before rescanning. | |
| 3281 DCHECK(p->IsEvacuationCandidate()); | 3287 DCHECK(p->IsEvacuationCandidate()); |
| 3282 p->SetFlag(Page::COMPACTION_WAS_ABORTED); | 3288 p->SetFlag(Page::COMPACTION_WAS_ABORTED); |
| 3289 p->set_scan_on_scavenge(true); | |
| 3283 abandoned_pages++; | 3290 abandoned_pages++; |
| 3284 break; | 3291 break; |
| 3285 case MemoryChunk::kCompactingFinalize: | 3292 case MemoryChunk::kCompactingFinalize: |
| 3286 DCHECK(p->IsEvacuationCandidate()); | 3293 DCHECK(p->IsEvacuationCandidate()); |
| 3287 p->SetWasSwept(); | 3294 p->SetWasSwept(); |
| 3288 p->Unlink(); | 3295 p->Unlink(); |
| 3289 break; | 3296 break; |
| 3290 case MemoryChunk::kCompactingDone: | 3297 case MemoryChunk::kCompactingDone: |
| 3291 DCHECK(p->IsFlagSet(Page::POPULAR_PAGE)); | 3298 DCHECK(p->IsFlagSet(Page::POPULAR_PAGE)); |
| 3292 DCHECK(p->IsFlagSet(Page::RESCAN_ON_EVACUATION)); | 3299 DCHECK(p->IsFlagSet(Page::RESCAN_ON_EVACUATION)); |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3651 } | 3658 } |
| 3652 } | 3659 } |
| 3653 | 3660 |
| 3654 { | 3661 { |
| 3655 GCTracer::Scope gc_scope(heap()->tracer(), | 3662 GCTracer::Scope gc_scope(heap()->tracer(), |
| 3656 GCTracer::Scope::MC_UPDATE_ROOT_TO_NEW_POINTERS); | 3663 GCTracer::Scope::MC_UPDATE_ROOT_TO_NEW_POINTERS); |
| 3657 // Update roots. | 3664 // Update roots. |
| 3658 heap_->IterateRoots(&updating_visitor, VISIT_ALL_IN_SWEEP_NEWSPACE); | 3665 heap_->IterateRoots(&updating_visitor, VISIT_ALL_IN_SWEEP_NEWSPACE); |
| 3659 } | 3666 } |
| 3660 | 3667 |
| 3661 { | |
| 3662 GCTracer::Scope gc_scope(heap()->tracer(), | |
| 3663 GCTracer::Scope::MC_UPDATE_OLD_TO_NEW_POINTERS); | |
| 3664 StoreBufferRebuildScope scope(heap_, heap_->store_buffer(), | |
| 3665 &Heap::ScavengeStoreBufferCallback); | |
| 3666 heap_->store_buffer()->IteratePointersToNewSpace(&UpdatePointer); | |
| 3667 } | |
| 3668 | |
| 3669 int npages = evacuation_candidates_.length(); | 3668 int npages = evacuation_candidates_.length(); |
| 3670 { | 3669 { |
| 3671 GCTracer::Scope gc_scope( | 3670 GCTracer::Scope gc_scope( |
| 3672 heap()->tracer(), | 3671 heap()->tracer(), |
| 3673 GCTracer::Scope::MC_UPDATE_POINTERS_BETWEEN_EVACUATED); | 3672 GCTracer::Scope::MC_UPDATE_POINTERS_BETWEEN_EVACUATED); |
| 3674 for (int i = 0; i < npages; i++) { | 3673 for (int i = 0; i < npages; i++) { |
| 3675 Page* p = evacuation_candidates_[i]; | 3674 Page* p = evacuation_candidates_[i]; |
| 3676 DCHECK(p->IsEvacuationCandidate() || | 3675 DCHECK(p->IsEvacuationCandidate() || |
| 3677 p->IsFlagSet(Page::RESCAN_ON_EVACUATION)); | 3676 p->IsFlagSet(Page::RESCAN_ON_EVACUATION)); |
| 3678 | 3677 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3727 break; | 3726 break; |
| 3728 default: | 3727 default: |
| 3729 UNREACHABLE(); | 3728 UNREACHABLE(); |
| 3730 break; | 3729 break; |
| 3731 } | 3730 } |
| 3732 } | 3731 } |
| 3733 } | 3732 } |
| 3734 } | 3733 } |
| 3735 | 3734 |
| 3736 { | 3735 { |
| 3736 // Note that this phase needs to happen after making aborted pages iterable | |
| 3737 // in the previous (sweeping) phase. | |
| 3738 GCTracer::Scope gc_scope(heap()->tracer(), | |
| 3739 GCTracer::Scope::MC_UPDATE_OLD_TO_NEW_POINTERS); | |
| 3740 StoreBufferRebuildScope scope(heap_, heap_->store_buffer(), | |
| 3741 &Heap::ScavengeStoreBufferCallback); | |
| 3742 heap_->store_buffer()->IteratePointersToNewSpace(&UpdatePointer); | |
| 3743 } | |
| 3744 | |
| 3745 { | |
| 3737 GCTracer::Scope gc_scope(heap()->tracer(), | 3746 GCTracer::Scope gc_scope(heap()->tracer(), |
| 3738 GCTracer::Scope::MC_UPDATE_MISC_POINTERS); | 3747 GCTracer::Scope::MC_UPDATE_MISC_POINTERS); |
| 3739 heap_->string_table()->Iterate(&updating_visitor); | 3748 heap_->string_table()->Iterate(&updating_visitor); |
| 3740 | 3749 |
| 3741 // Update pointers from external string table. | 3750 // Update pointers from external string table. |
| 3742 heap_->UpdateReferencesInExternalStringTable( | 3751 heap_->UpdateReferencesInExternalStringTable( |
| 3743 &UpdateReferenceInExternalStringTableEntry); | 3752 &UpdateReferenceInExternalStringTableEntry); |
| 3744 | 3753 |
| 3745 EvacuationWeakObjectRetainer evacuation_object_retainer; | 3754 EvacuationWeakObjectRetainer evacuation_object_retainer; |
| 3746 heap()->ProcessAllWeakReferences(&evacuation_object_retainer); | 3755 heap()->ProcessAllWeakReferences(&evacuation_object_retainer); |
| 3747 } | 3756 } |
| 3748 | 3757 |
| 3749 { | 3758 { |
| 3750 GCTracer::Scope gc_scope(heap()->tracer(), | 3759 GCTracer::Scope gc_scope(heap()->tracer(), |
| 3751 GCTracer::Scope::MC_SWEEP_ABORTED); | 3760 GCTracer::Scope::MC_SWEEP_ABORTED); |
| 3752 // After updating all pointers, we can finally sweep the aborted pages, | 3761 // After updating all pointers, we can finally sweep the aborted pages, |
| 3753 // effectively overriding any forward pointers. | 3762 // effectively overriding any forward pointers. |
| 3754 SweepAbortedPages(); | 3763 SweepAbortedPages(); |
| 3755 } | 3764 } |
| 3756 | 3765 |
|
Hannes Payer (out of office)
2015/12/02 12:45:18
The store buffer processing should go here, after
Michael Lippautz
2015/12/02 13:04:19
Done.
| |
| 3757 heap_->isolate()->inner_pointer_to_code_cache()->Flush(); | 3766 heap_->isolate()->inner_pointer_to_code_cache()->Flush(); |
| 3758 | 3767 |
| 3759 // The hashing of weak_object_to_code_table is no longer valid. | 3768 // The hashing of weak_object_to_code_table is no longer valid. |
| 3760 heap()->weak_object_to_code_table()->Rehash( | 3769 heap()->weak_object_to_code_table()->Rehash( |
| 3761 heap()->isolate()->factory()->undefined_value()); | 3770 heap()->isolate()->factory()->undefined_value()); |
| 3762 } | 3771 } |
| 3763 | 3772 |
| 3764 | 3773 |
| 3765 void MarkCompactCollector::MoveEvacuationCandidatesToEndOfPagesList() { | 3774 void MarkCompactCollector::MoveEvacuationCandidatesToEndOfPagesList() { |
| 3766 int npages = evacuation_candidates_.length(); | 3775 int npages = evacuation_candidates_.length(); |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4125 MarkBit mark_bit = Marking::MarkBitFrom(host); | 4134 MarkBit mark_bit = Marking::MarkBitFrom(host); |
| 4126 if (Marking::IsBlack(mark_bit)) { | 4135 if (Marking::IsBlack(mark_bit)) { |
| 4127 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); | 4136 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); |
| 4128 RecordRelocSlot(&rinfo, target); | 4137 RecordRelocSlot(&rinfo, target); |
| 4129 } | 4138 } |
| 4130 } | 4139 } |
| 4131 } | 4140 } |
| 4132 | 4141 |
| 4133 } // namespace internal | 4142 } // namespace internal |
| 4134 } // namespace v8 | 4143 } // namespace v8 |
| OLD | NEW |