| 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 |
| 650 void IncrementalMarking::FinalizeIncrementally() { | 688 void IncrementalMarking::FinalizeIncrementally() { |
| 651 DCHECK(FLAG_finalize_marking_incrementally); | 689 DCHECK(FLAG_finalize_marking_incrementally); |
| 652 DCHECK(!finalize_marking_completed_); | 690 DCHECK(!finalize_marking_completed_); |
| 653 DCHECK(IsMarking()); | 691 DCHECK(IsMarking()); |
| 654 | 692 |
| 655 int old_marking_deque_top = | 693 int old_marking_deque_top = |
| 656 heap_->mark_compact_collector()->marking_deque()->top(); | 694 heap_->mark_compact_collector()->marking_deque()->top(); |
| 657 | 695 |
| 658 // After finishing incremental marking, we try to discover all unmarked | 696 // After finishing incremental marking, we try to discover all unmarked |
| 659 // objects to reduce the marking load in the final pause. | 697 // objects to reduce the marking load in the final pause. |
| 660 // 1) We scan and mark the roots again to find all changes to the root set. | 698 // 1) We scan and mark the roots again to find all changes to the root set. |
| 661 // 2) We mark the object groups. | 699 // 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. |
| 662 MarkRoots(); | 702 MarkRoots(); |
| 663 MarkObjectGroups(); | 703 MarkObjectGroups(); |
| 704 ProcessWeakCells(); |
| 664 | 705 |
| 665 int marking_progress = | 706 int marking_progress = |
| 666 abs(old_marking_deque_top - | 707 abs(old_marking_deque_top - |
| 667 heap_->mark_compact_collector()->marking_deque()->top()); | 708 heap_->mark_compact_collector()->marking_deque()->top()); |
| 668 | 709 |
| 669 ++incremental_marking_finalization_rounds_; | 710 ++incremental_marking_finalization_rounds_; |
| 670 if ((incremental_marking_finalization_rounds_ >= | 711 if ((incremental_marking_finalization_rounds_ >= |
| 671 FLAG_max_incremental_marking_finalization_rounds) || | 712 FLAG_max_incremental_marking_finalization_rounds) || |
| 672 (marking_progress < | 713 (marking_progress < |
| 673 FLAG_min_progress_during_incremental_marking_finalization)) { | 714 FLAG_min_progress_during_incremental_marking_finalization)) { |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 void IncrementalMarking::IncrementIdleMarkingDelayCounter() { | 1195 void IncrementalMarking::IncrementIdleMarkingDelayCounter() { |
| 1155 idle_marking_delay_counter_++; | 1196 idle_marking_delay_counter_++; |
| 1156 } | 1197 } |
| 1157 | 1198 |
| 1158 | 1199 |
| 1159 void IncrementalMarking::ClearIdleMarkingDelayCounter() { | 1200 void IncrementalMarking::ClearIdleMarkingDelayCounter() { |
| 1160 idle_marking_delay_counter_ = 0; | 1201 idle_marking_delay_counter_ = 0; |
| 1161 } | 1202 } |
| 1162 } // namespace internal | 1203 } // namespace internal |
| 1163 } // namespace v8 | 1204 } // namespace v8 |
| OLD | NEW |