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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/heap/incremental-marking.h" | 7 #include "src/heap/incremental-marking.h" |
8 | 8 |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/compilation-cache.h" | 10 #include "src/compilation-cache.h" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 Object* obj = *p; | 244 Object* obj = *p; |
245 if (obj->IsHeapObject()) { | 245 if (obj->IsHeapObject()) { |
246 heap->mark_compact_collector()->RecordSlot(anchor, p, obj); | 246 heap->mark_compact_collector()->RecordSlot(anchor, p, obj); |
247 MarkObject(heap, obj); | 247 MarkObject(heap, obj); |
248 } | 248 } |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
252 // Marks the object grey and pushes it on the marking stack. | 252 // Marks the object grey and pushes it on the marking stack. |
253 INLINE(static void MarkObject(Heap* heap, Object* obj)) { | 253 INLINE(static void MarkObject(Heap* heap, Object* obj)) { |
254 IncrementalMarking::MarkObject(heap, obj); | 254 IncrementalMarking::MarkObject(heap, HeapObject::cast(obj)); |
255 } | 255 } |
256 | 256 |
257 // Marks the object black without pushing it on the marking stack. | 257 // Marks the object black without pushing it on the marking stack. |
258 // Returns true if object needed marking and false otherwise. | 258 // Returns true if object needed marking and false otherwise. |
259 INLINE(static bool MarkObjectWithoutPush(Heap* heap, Object* obj)) { | 259 INLINE(static bool MarkObjectWithoutPush(Heap* heap, Object* obj)) { |
260 HeapObject* heap_object = HeapObject::cast(obj); | 260 HeapObject* heap_object = HeapObject::cast(obj); |
261 MarkBit mark_bit = Marking::MarkBitFrom(heap_object); | 261 MarkBit mark_bit = Marking::MarkBitFrom(heap_object); |
262 if (Marking::IsWhite(mark_bit)) { | 262 if (Marking::IsWhite(mark_bit)) { |
263 mark_bit.Set(); | 263 mark_bit.Set(); |
264 MemoryChunk::IncrementLiveBytesFromGC(heap_object->address(), | 264 MemoryChunk::IncrementLiveBytesFromGC(heap_object->address(), |
(...skipping 15 matching lines...) Expand all Loading... |
280 | 280 |
281 void VisitPointers(Object** start, Object** end) { | 281 void VisitPointers(Object** start, Object** end) { |
282 for (Object** p = start; p < end; p++) MarkObjectByPointer(p); | 282 for (Object** p = start; p < end; p++) MarkObjectByPointer(p); |
283 } | 283 } |
284 | 284 |
285 private: | 285 private: |
286 void MarkObjectByPointer(Object** p) { | 286 void MarkObjectByPointer(Object** p) { |
287 Object* obj = *p; | 287 Object* obj = *p; |
288 if (!obj->IsHeapObject()) return; | 288 if (!obj->IsHeapObject()) return; |
289 | 289 |
290 IncrementalMarking::MarkObject(heap_, obj); | 290 IncrementalMarking::MarkObject(heap_, HeapObject::cast(obj)); |
291 } | 291 } |
292 | 292 |
293 Heap* heap_; | 293 Heap* heap_; |
294 }; | 294 }; |
295 | 295 |
296 | 296 |
297 void IncrementalMarking::Initialize() { | 297 void IncrementalMarking::Initialize() { |
298 IncrementalMarkingMarkingVisitor::Initialize(); | 298 IncrementalMarkingMarkingVisitor::Initialize(); |
299 } | 299 } |
300 | 300 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 IncrementalMarkingRootMarkingVisitor visitor(this); | 538 IncrementalMarkingRootMarkingVisitor visitor(this); |
539 heap_->IterateStrongRoots(&visitor, VISIT_ONLY_STRONG); | 539 heap_->IterateStrongRoots(&visitor, VISIT_ONLY_STRONG); |
540 | 540 |
541 // Ready to start incremental marking. | 541 // Ready to start incremental marking. |
542 if (FLAG_trace_incremental_marking) { | 542 if (FLAG_trace_incremental_marking) { |
543 PrintF("[IncrementalMarking] Running\n"); | 543 PrintF("[IncrementalMarking] Running\n"); |
544 } | 544 } |
545 } | 545 } |
546 | 546 |
547 | 547 |
| 548 void IncrementalMarking::MarkObjectGroups() { |
| 549 DCHECK(FLAG_overapproximate_weak_closure); |
| 550 DCHECK(!weak_closure_was_overapproximated_); |
| 551 |
| 552 GCTracer::Scope gc_scope(heap_->tracer(), |
| 553 GCTracer::Scope::MC_INCREMENTAL_WEAKCLOSURE); |
| 554 |
| 555 heap_->mark_compact_collector()->MarkImplicitRefGroups(&MarkObject); |
| 556 |
| 557 IncrementalMarkingRootMarkingVisitor visitor(this); |
| 558 heap_->isolate()->global_handles()->IterateObjectGroups( |
| 559 &visitor, &MarkCompactCollector::IsUnmarkedHeapObjectWithHeap); |
| 560 |
| 561 heap_->isolate()->global_handles()->RemoveImplicitRefGroups(); |
| 562 heap_->isolate()->global_handles()->RemoveObjectGroups(); |
| 563 |
| 564 weak_closure_was_overapproximated_ = true; |
| 565 } |
| 566 |
| 567 |
548 void IncrementalMarking::PrepareForScavenge() { | 568 void IncrementalMarking::PrepareForScavenge() { |
549 if (!IsMarking()) return; | 569 if (!IsMarking()) return; |
550 NewSpacePageIterator it(heap_->new_space()->FromSpaceStart(), | 570 NewSpacePageIterator it(heap_->new_space()->FromSpaceStart(), |
551 heap_->new_space()->FromSpaceEnd()); | 571 heap_->new_space()->FromSpaceEnd()); |
552 while (it.has_next()) { | 572 while (it.has_next()) { |
553 Bitmap::Clear(it.next()); | 573 Bitmap::Clear(it.next()); |
554 } | 574 } |
555 } | 575 } |
556 | 576 |
557 | 577 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); | 638 MemoryChunk* chunk = MemoryChunk::FromAddress(obj->address()); |
619 SLOW_DCHECK(Marking::IsGrey(mark_bit) || | 639 SLOW_DCHECK(Marking::IsGrey(mark_bit) || |
620 (obj->IsFiller() && Marking::IsWhite(mark_bit)) || | 640 (obj->IsFiller() && Marking::IsWhite(mark_bit)) || |
621 (chunk->IsFlagSet(MemoryChunk::HAS_PROGRESS_BAR) && | 641 (chunk->IsFlagSet(MemoryChunk::HAS_PROGRESS_BAR) && |
622 Marking::IsBlack(mark_bit))); | 642 Marking::IsBlack(mark_bit))); |
623 #endif | 643 #endif |
624 MarkBlackOrKeepBlack(obj, mark_bit, size); | 644 MarkBlackOrKeepBlack(obj, mark_bit, size); |
625 } | 645 } |
626 | 646 |
627 | 647 |
628 void IncrementalMarking::MarkObject(Heap* heap, Object* obj) { | 648 void IncrementalMarking::MarkObject(Heap* heap, HeapObject* obj) { |
629 HeapObject* heap_object = HeapObject::cast(obj); | 649 MarkBit mark_bit = Marking::MarkBitFrom(obj); |
630 MarkBit mark_bit = Marking::MarkBitFrom(heap_object); | |
631 if (mark_bit.data_only()) { | 650 if (mark_bit.data_only()) { |
632 MarkBlackOrKeepGrey(heap_object, mark_bit, heap_object->Size()); | 651 MarkBlackOrKeepGrey(obj, mark_bit, obj->Size()); |
633 } else if (Marking::IsWhite(mark_bit)) { | 652 } else if (Marking::IsWhite(mark_bit)) { |
634 heap->incremental_marking()->WhiteToGreyAndPush(heap_object, mark_bit); | 653 heap->incremental_marking()->WhiteToGreyAndPush(obj, mark_bit); |
635 } | 654 } |
636 } | 655 } |
637 | 656 |
638 | 657 |
639 intptr_t IncrementalMarking::ProcessMarkingDeque(intptr_t bytes_to_process) { | 658 intptr_t IncrementalMarking::ProcessMarkingDeque(intptr_t bytes_to_process) { |
640 intptr_t bytes_processed = 0; | 659 intptr_t bytes_processed = 0; |
641 Map* filler_map = heap_->one_pointer_filler_map(); | 660 Map* filler_map = heap_->one_pointer_filler_map(); |
642 MarkingDeque* marking_deque = | 661 MarkingDeque* marking_deque = |
643 heap_->mark_compact_collector()->marking_deque(); | 662 heap_->mark_compact_collector()->marking_deque(); |
644 while (!marking_deque->IsEmpty() && bytes_processed < bytes_to_process) { | 663 while (!marking_deque->IsEmpty() && bytes_processed < bytes_to_process) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 heap_->isolate()->stack_guard()->ClearGC(); | 786 heap_->isolate()->stack_guard()->ClearGC(); |
768 } | 787 } |
769 | 788 |
770 | 789 |
771 void IncrementalMarking::OverApproximateWeakClosure() { | 790 void IncrementalMarking::OverApproximateWeakClosure() { |
772 DCHECK(FLAG_overapproximate_weak_closure); | 791 DCHECK(FLAG_overapproximate_weak_closure); |
773 DCHECK(!weak_closure_was_overapproximated_); | 792 DCHECK(!weak_closure_was_overapproximated_); |
774 if (FLAG_trace_incremental_marking) { | 793 if (FLAG_trace_incremental_marking) { |
775 PrintF("[IncrementalMarking] requesting weak closure overapproximation.\n"); | 794 PrintF("[IncrementalMarking] requesting weak closure overapproximation.\n"); |
776 } | 795 } |
777 set_should_hurry(true); | |
778 request_type_ = OVERAPPROXIMATION; | 796 request_type_ = OVERAPPROXIMATION; |
779 heap_->isolate()->stack_guard()->RequestGC(); | 797 heap_->isolate()->stack_guard()->RequestGC(); |
780 } | 798 } |
781 | 799 |
782 | 800 |
783 void IncrementalMarking::MarkingComplete(CompletionAction action) { | 801 void IncrementalMarking::MarkingComplete(CompletionAction action) { |
784 state_ = COMPLETE; | 802 state_ = COMPLETE; |
785 // We will set the stack guard to request a GC now. This will mean the rest | 803 // We will set the stack guard to request a GC now. This will mean the rest |
786 // of the GC gets performed as soon as possible (we can't do a GC here in a | 804 // of the GC gets performed as soon as possible (we can't do a GC here in a |
787 // record-write context). If a few things get allocated between now and then | 805 // record-write context). If a few things get allocated between now and then |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 void IncrementalMarking::IncrementIdleMarkingDelayCounter() { | 1018 void IncrementalMarking::IncrementIdleMarkingDelayCounter() { |
1001 idle_marking_delay_counter_++; | 1019 idle_marking_delay_counter_++; |
1002 } | 1020 } |
1003 | 1021 |
1004 | 1022 |
1005 void IncrementalMarking::ClearIdleMarkingDelayCounter() { | 1023 void IncrementalMarking::ClearIdleMarkingDelayCounter() { |
1006 idle_marking_delay_counter_ = 0; | 1024 idle_marking_delay_counter_ = 0; |
1007 } | 1025 } |
1008 } | 1026 } |
1009 } // namespace v8::internal | 1027 } // namespace v8::internal |
OLD | NEW |