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/incremental-marking.h" | 5 #include "src/heap/incremental-marking.h" |
6 | 6 |
7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
8 #include "src/compilation-cache.h" | 8 #include "src/compilation-cache.h" |
9 #include "src/conversions.h" | 9 #include "src/conversions.h" |
10 #include "src/heap/gc-idle-time-handler.h" | 10 #include "src/heap/gc-idle-time-handler.h" |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 | 640 |
641 IncrementalMarkingRootMarkingVisitor visitor(this); | 641 IncrementalMarkingRootMarkingVisitor visitor(this); |
642 heap_->mark_compact_collector()->MarkImplicitRefGroups(&MarkObject); | 642 heap_->mark_compact_collector()->MarkImplicitRefGroups(&MarkObject); |
643 heap_->isolate()->global_handles()->IterateObjectGroups( | 643 heap_->isolate()->global_handles()->IterateObjectGroups( |
644 &visitor, &MarkCompactCollector::IsUnmarkedHeapObjectWithHeap); | 644 &visitor, &MarkCompactCollector::IsUnmarkedHeapObjectWithHeap); |
645 heap_->isolate()->global_handles()->RemoveImplicitRefGroups(); | 645 heap_->isolate()->global_handles()->RemoveImplicitRefGroups(); |
646 heap_->isolate()->global_handles()->RemoveObjectGroups(); | 646 heap_->isolate()->global_handles()->RemoveObjectGroups(); |
647 } | 647 } |
648 | 648 |
649 | 649 |
650 void IncrementalMarking::ProcessWeakCells() { | |
651 DCHECK(FLAG_finalize_marking_incrementally); | |
652 DCHECK(!finalize_marking_completed_); | |
653 DCHECK(IsMarking()); | |
654 | |
655 Object* weak_cell_obj = heap()->encountered_weak_cells(); | |
656 Object* weak_cell_head = Smi::FromInt(0); | |
657 WeakCell* prev_weak_cell_obj = NULL; | |
658 while (weak_cell_obj != Smi::FromInt(0)) { | |
659 WeakCell* weak_cell = reinterpret_cast<WeakCell*>(weak_cell_obj); | |
660 // We do not insert cleared weak cells into the list, so the value | |
661 // cannot be a Smi here. | |
662 HeapObject* value = HeapObject::cast(weak_cell->value()); | |
663 // Remove weak cells with live objects from the list, they do not need | |
664 // clearing. | |
665 if (MarkCompactCollector::IsMarked(value)) { | |
666 // Record slot, if value is pointing to an evacuation candidate. | |
667 Object** slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset); | |
668 heap_->mark_compact_collector()->RecordSlot(weak_cell, slot, *slot); | |
669 // Remove entry somewhere after top. | |
670 if (prev_weak_cell_obj != NULL) { | |
671 prev_weak_cell_obj->set_next(weak_cell->next()); | |
672 } | |
673 weak_cell_obj = weak_cell->next(); | |
674 weak_cell->clear_next(heap()); | |
675 } else { | |
676 if (weak_cell_head == Smi::FromInt(0)) { | |
677 weak_cell_head = weak_cell; | |
678 } | |
679 prev_weak_cell_obj = weak_cell; | |
680 weak_cell_obj = weak_cell->next(); | |
681 } | |
682 } | |
683 // Top may have changed. | |
684 heap()->set_encountered_weak_cells(weak_cell_head); | |
685 } | |
686 | |
687 | |
688 void IncrementalMarking::FinalizeIncrementally() { | 650 void IncrementalMarking::FinalizeIncrementally() { |
689 DCHECK(FLAG_finalize_marking_incrementally); | 651 DCHECK(FLAG_finalize_marking_incrementally); |
690 DCHECK(!finalize_marking_completed_); | 652 DCHECK(!finalize_marking_completed_); |
691 DCHECK(IsMarking()); | 653 DCHECK(IsMarking()); |
692 | 654 |
693 int old_marking_deque_top = | 655 int old_marking_deque_top = |
694 heap_->mark_compact_collector()->marking_deque()->top(); | 656 heap_->mark_compact_collector()->marking_deque()->top(); |
695 | 657 |
696 // After finishing incremental marking, we try to discover all unmarked | 658 // After finishing incremental marking, we try to discover all unmarked |
697 // objects to reduce the marking load in the final pause. | 659 // objects to reduce the marking load in the final pause. |
698 // 1) We scan and mark the roots again to find all changes to the root set. | 660 // 1) We scan and mark the roots again to find all changes to the root set. |
699 // 2) We mark the object groups. | 661 // 2) We mark the object groups. |
700 // 3) Remove weak cell with live values from the list of weak cells, they | |
701 // do not need processing during GC. | |
702 MarkRoots(); | 662 MarkRoots(); |
703 MarkObjectGroups(); | 663 MarkObjectGroups(); |
704 ProcessWeakCells(); | |
705 | 664 |
706 int marking_progress = | 665 int marking_progress = |
707 abs(old_marking_deque_top - | 666 abs(old_marking_deque_top - |
708 heap_->mark_compact_collector()->marking_deque()->top()); | 667 heap_->mark_compact_collector()->marking_deque()->top()); |
709 | 668 |
710 ++incremental_marking_finalization_rounds_; | 669 ++incremental_marking_finalization_rounds_; |
711 if ((incremental_marking_finalization_rounds_ >= | 670 if ((incremental_marking_finalization_rounds_ >= |
712 FLAG_max_incremental_marking_finalization_rounds) || | 671 FLAG_max_incremental_marking_finalization_rounds) || |
713 (marking_progress < | 672 (marking_progress < |
714 FLAG_min_progress_during_incremental_marking_finalization)) { | 673 FLAG_min_progress_during_incremental_marking_finalization)) { |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 void IncrementalMarking::IncrementIdleMarkingDelayCounter() { | 1154 void IncrementalMarking::IncrementIdleMarkingDelayCounter() { |
1196 idle_marking_delay_counter_++; | 1155 idle_marking_delay_counter_++; |
1197 } | 1156 } |
1198 | 1157 |
1199 | 1158 |
1200 void IncrementalMarking::ClearIdleMarkingDelayCounter() { | 1159 void IncrementalMarking::ClearIdleMarkingDelayCounter() { |
1201 idle_marking_delay_counter_ = 0; | 1160 idle_marking_delay_counter_ = 0; |
1202 } | 1161 } |
1203 } // namespace internal | 1162 } // namespace internal |
1204 } // namespace v8 | 1163 } // namespace v8 |
OLD | NEW |