OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 MarkBit obj_bit = Marking::MarkBitFrom(obj); | 168 MarkBit obj_bit = Marking::MarkBitFrom(obj); |
169 if (Marking::IsBlack(obj_bit)) { | 169 if (Marking::IsBlack(obj_bit)) { |
170 // Object is not going to be rescanned. We need to record the slot. | 170 // Object is not going to be rescanned. We need to record the slot. |
171 heap_->mark_compact_collector()->RecordRelocSlot(rinfo, | 171 heap_->mark_compact_collector()->RecordRelocSlot(rinfo, |
172 Code::cast(value)); | 172 Code::cast(value)); |
173 } | 173 } |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 | 177 |
178 static void MarkObjectGreyDoNotEnqueue(Object* obj) { | |
179 if (obj->IsHeapObject()) { | |
180 HeapObject* heap_obj = HeapObject::cast(obj); | |
181 MarkBit mark_bit = Marking::MarkBitFrom(HeapObject::cast(obj)); | |
182 if (Marking::IsBlack(mark_bit)) { | |
183 MemoryChunk::IncrementLiveBytesFromGC(heap_obj->address(), | |
184 -heap_obj->Size()); | |
185 } | |
186 Marking::AnyToGrey(mark_bit); | |
187 } | |
188 } | |
189 | |
190 | |
178 class IncrementalMarkingMarkingVisitor | 191 class IncrementalMarkingMarkingVisitor |
179 : public StaticMarkingVisitor<IncrementalMarkingMarkingVisitor> { | 192 : public StaticMarkingVisitor<IncrementalMarkingMarkingVisitor> { |
180 public: | 193 public: |
181 static void Initialize() { | 194 static void Initialize() { |
182 StaticMarkingVisitor<IncrementalMarkingMarkingVisitor>::Initialize(); | 195 StaticMarkingVisitor<IncrementalMarkingMarkingVisitor>::Initialize(); |
183 | 196 |
197 table_.Register(kVisitNativeContext, &VisitNativeContextIncremental); | |
184 table_.Register(kVisitJSRegExp, &VisitJSRegExp); | 198 table_.Register(kVisitJSRegExp, &VisitJSRegExp); |
185 } | 199 } |
186 | 200 |
201 static void VisitNativeContextIncremental(Map* map, HeapObject* object) { | |
202 Context* context = Context::cast(object); | |
203 | |
204 // We will mark cache black with a separate pass | |
205 // when we finish marking. | |
206 MarkObjectGreyDoNotEnqueue(context->normalized_map_cache()); | |
207 IncrementalMarkingMarkingVisitor::VisitNativeContext(map, context); | |
Michael Starzinger
2012/11/08 11:10:39
This method is actually in the StaticMarkingVisito
payer
2012/11/08 12:12:10
Done.
| |
208 } | |
209 | |
187 static void VisitJSWeakMap(Map* map, HeapObject* object) { | 210 static void VisitJSWeakMap(Map* map, HeapObject* object) { |
188 Heap* heap = map->GetHeap(); | 211 Heap* heap = map->GetHeap(); |
189 VisitPointers(heap, | 212 VisitPointers(heap, |
190 HeapObject::RawField(object, JSWeakMap::kPropertiesOffset), | 213 HeapObject::RawField(object, JSWeakMap::kPropertiesOffset), |
191 HeapObject::RawField(object, JSWeakMap::kSize)); | 214 HeapObject::RawField(object, JSWeakMap::kSize)); |
192 } | 215 } |
193 | 216 |
194 static void BeforeVisitingSharedFunctionInfo(HeapObject* object) {} | 217 static void BeforeVisitingSharedFunctionInfo(HeapObject* object) {} |
195 | 218 |
196 INLINE(static void VisitPointer(Heap* heap, Object** p)) { | 219 INLINE(static void VisitPointer(Heap* heap, Object** p)) { |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 if (FLAG_trace_incremental_marking) { | 510 if (FLAG_trace_incremental_marking) { |
488 PrintF("[IncrementalMarking] Start sweeping.\n"); | 511 PrintF("[IncrementalMarking] Start sweeping.\n"); |
489 } | 512 } |
490 state_ = SWEEPING; | 513 state_ = SWEEPING; |
491 } | 514 } |
492 | 515 |
493 heap_->new_space()->LowerInlineAllocationLimit(kAllocatedThreshold); | 516 heap_->new_space()->LowerInlineAllocationLimit(kAllocatedThreshold); |
494 } | 517 } |
495 | 518 |
496 | 519 |
497 static void MarkObjectGreyDoNotEnqueue(Object* obj) { | |
498 if (obj->IsHeapObject()) { | |
499 HeapObject* heap_obj = HeapObject::cast(obj); | |
500 MarkBit mark_bit = Marking::MarkBitFrom(HeapObject::cast(obj)); | |
501 if (Marking::IsBlack(mark_bit)) { | |
502 MemoryChunk::IncrementLiveBytesFromGC(heap_obj->address(), | |
503 -heap_obj->Size()); | |
504 } | |
505 Marking::AnyToGrey(mark_bit); | |
506 } | |
507 } | |
508 | |
509 | |
510 void IncrementalMarking::StartMarking(CompactionFlag flag) { | 520 void IncrementalMarking::StartMarking(CompactionFlag flag) { |
511 if (FLAG_trace_incremental_marking) { | 521 if (FLAG_trace_incremental_marking) { |
512 PrintF("[IncrementalMarking] Start marking\n"); | 522 PrintF("[IncrementalMarking] Start marking\n"); |
513 } | 523 } |
514 | 524 |
515 is_compacting_ = !FLAG_never_compact && (flag == ALLOW_COMPACTION) && | 525 is_compacting_ = !FLAG_never_compact && (flag == ALLOW_COMPACTION) && |
516 heap_->mark_compact_collector()->StartCompaction( | 526 heap_->mark_compact_collector()->StartCompaction( |
517 MarkCompactCollector::INCREMENTAL_COMPACTION); | 527 MarkCompactCollector::INCREMENTAL_COMPACTION); |
518 | 528 |
519 state_ = MARKING; | 529 state_ = MARKING; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 } | 622 } |
613 } | 623 } |
614 marking_deque_.set_top(new_top); | 624 marking_deque_.set_top(new_top); |
615 | 625 |
616 steps_took_since_last_gc_ = 0; | 626 steps_took_since_last_gc_ = 0; |
617 steps_count_since_last_gc_ = 0; | 627 steps_count_since_last_gc_ = 0; |
618 longest_step_ = 0.0; | 628 longest_step_ = 0.0; |
619 } | 629 } |
620 | 630 |
621 | 631 |
632 void IncrementalMarking::MarkObject(Map* map, HeapObject* obj) { | |
Michael Starzinger
2012/11/08 11:10:39
This should actually be called "ProcessObject" or
payer
2012/11/08 12:12:10
I added a size parameter to the VisitObject method
| |
633 MarkBit map_mark_bit = Marking::MarkBitFrom(map); | |
634 if (Marking::IsWhite(map_mark_bit)) { | |
635 WhiteToGreyAndPush(map, map_mark_bit); | |
636 } | |
637 | |
638 IncrementalMarkingMarkingVisitor::IterateBody(map, obj); | |
639 | |
640 MarkBit obj_mark_bit = Marking::MarkBitFrom(obj); | |
641 SLOW_ASSERT(Marking::IsGrey(obj_mark_bit) || | |
642 (obj->IsFiller() && Marking::IsWhite(obj_mark_bit))); | |
643 Marking::MarkBlack(obj_mark_bit); | |
644 MemoryChunk::IncrementLiveBytesFromGC(obj->address(), obj->SizeFromMap(map)); | |
645 } | |
646 | |
647 | |
648 void IncrementalMarking::ProcessMarking(intptr_t bytes_to_process) { | |
Michael Starzinger
2012/11/08 11:10:39
Let's rename that to ProcessMarkingDeque, that's m
payer
2012/11/08 12:12:10
Done.
| |
649 Map* filler_map = heap_->one_pointer_filler_map(); | |
650 while (!marking_deque_.IsEmpty() && bytes_to_process > 0) { | |
651 HeapObject* obj = marking_deque_.Pop(); | |
652 | |
653 // Explicitly skip one word fillers. Incremental markbit patterns are | |
654 // correct only for objects that occupy at least two words. | |
655 Map* map = obj->map(); | |
656 if (map == filler_map) continue; | |
657 | |
658 int size = obj->SizeFromMap(map); | |
659 bytes_to_process -= size; | |
660 MarkObject(map, obj); | |
661 } | |
662 } | |
663 | |
664 | |
665 void IncrementalMarking::ProcessMarking() { | |
Michael Starzinger
2012/11/08 11:10:39
Likewise.
payer
2012/11/08 12:12:10
Done.
| |
666 Map* filler_map = heap_->one_pointer_filler_map(); | |
667 while (!marking_deque_.IsEmpty()) { | |
668 HeapObject* obj = marking_deque_.Pop(); | |
669 | |
670 // Explicitly skip one word fillers. Incremental markbit patterns are | |
671 // correct only for objects that occupy at least two words. | |
672 Map* map = obj->map(); | |
673 if (map == filler_map) continue; | |
674 | |
675 MarkObject(map, obj); | |
676 } | |
677 } | |
678 | |
622 void IncrementalMarking::Hurry() { | 679 void IncrementalMarking::Hurry() { |
623 if (state() == MARKING) { | 680 if (state() == MARKING) { |
624 double start = 0.0; | 681 double start = 0.0; |
625 if (FLAG_trace_incremental_marking) { | 682 if (FLAG_trace_incremental_marking) { |
626 PrintF("[IncrementalMarking] Hurry\n"); | 683 PrintF("[IncrementalMarking] Hurry\n"); |
627 start = OS::TimeCurrentMillis(); | 684 start = OS::TimeCurrentMillis(); |
628 } | 685 } |
629 // TODO(gc) hurry can mark objects it encounters black as mutator | 686 // TODO(gc) hurry can mark objects it encounters black as mutator |
630 // was stopped. | 687 // was stopped. |
631 Map* filler_map = heap_->one_pointer_filler_map(); | 688 ProcessMarking(); |
632 Map* native_context_map = heap_->native_context_map(); | |
633 while (!marking_deque_.IsEmpty()) { | |
634 HeapObject* obj = marking_deque_.Pop(); | |
635 | |
636 // Explicitly skip one word fillers. Incremental markbit patterns are | |
637 // correct only for objects that occupy at least two words. | |
638 Map* map = obj->map(); | |
639 if (map == filler_map) { | |
640 continue; | |
641 } else if (map == native_context_map) { | |
642 // Native contexts have weak fields. | |
643 IncrementalMarkingMarkingVisitor::VisitNativeContext(map, obj); | |
644 } else { | |
645 MarkBit map_mark_bit = Marking::MarkBitFrom(map); | |
646 if (Marking::IsWhite(map_mark_bit)) { | |
647 WhiteToGreyAndPush(map, map_mark_bit); | |
648 } | |
649 IncrementalMarkingMarkingVisitor::IterateBody(map, obj); | |
650 } | |
651 | |
652 MarkBit mark_bit = Marking::MarkBitFrom(obj); | |
653 ASSERT(!Marking::IsBlack(mark_bit)); | |
654 Marking::MarkBlack(mark_bit); | |
655 MemoryChunk::IncrementLiveBytesFromGC(obj->address(), obj->Size()); | |
656 } | |
657 state_ = COMPLETE; | 689 state_ = COMPLETE; |
658 if (FLAG_trace_incremental_marking) { | 690 if (FLAG_trace_incremental_marking) { |
659 double end = OS::TimeCurrentMillis(); | 691 double end = OS::TimeCurrentMillis(); |
660 PrintF("[IncrementalMarking] Complete (hurry), spent %d ms.\n", | 692 PrintF("[IncrementalMarking] Complete (hurry), spent %d ms.\n", |
661 static_cast<int>(end - start)); | 693 static_cast<int>(end - start)); |
662 } | 694 } |
663 } | 695 } |
664 | 696 |
665 if (FLAG_cleanup_code_caches_at_gc) { | 697 if (FLAG_cleanup_code_caches_at_gc) { |
666 PolymorphicCodeCache* poly_cache = heap_->polymorphic_code_cache(); | 698 PolymorphicCodeCache* poly_cache = heap_->polymorphic_code_cache(); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
785 if (FLAG_trace_incremental_marking || FLAG_trace_gc) { | 817 if (FLAG_trace_incremental_marking || FLAG_trace_gc) { |
786 start = OS::TimeCurrentMillis(); | 818 start = OS::TimeCurrentMillis(); |
787 } | 819 } |
788 | 820 |
789 if (state_ == SWEEPING) { | 821 if (state_ == SWEEPING) { |
790 if (heap_->AdvanceSweepers(static_cast<int>(bytes_to_process))) { | 822 if (heap_->AdvanceSweepers(static_cast<int>(bytes_to_process))) { |
791 bytes_scanned_ = 0; | 823 bytes_scanned_ = 0; |
792 StartMarking(PREVENT_COMPACTION); | 824 StartMarking(PREVENT_COMPACTION); |
793 } | 825 } |
794 } else if (state_ == MARKING) { | 826 } else if (state_ == MARKING) { |
795 Map* filler_map = heap_->one_pointer_filler_map(); | 827 ProcessMarking(bytes_to_process); |
796 Map* native_context_map = heap_->native_context_map(); | |
797 while (!marking_deque_.IsEmpty() && bytes_to_process > 0) { | |
798 HeapObject* obj = marking_deque_.Pop(); | |
799 | |
800 // Explicitly skip one word fillers. Incremental markbit patterns are | |
801 // correct only for objects that occupy at least two words. | |
802 Map* map = obj->map(); | |
803 if (map == filler_map) continue; | |
804 | |
805 int size = obj->SizeFromMap(map); | |
806 bytes_to_process -= size; | |
807 MarkBit map_mark_bit = Marking::MarkBitFrom(map); | |
808 if (Marking::IsWhite(map_mark_bit)) { | |
809 WhiteToGreyAndPush(map, map_mark_bit); | |
810 } | |
811 | |
812 // TODO(gc) switch to static visitor instead of normal visitor. | |
813 if (map == native_context_map) { | |
814 // Native contexts have weak fields. | |
815 Context* ctx = Context::cast(obj); | |
816 | |
817 // We will mark cache black with a separate pass | |
818 // when we finish marking. | |
819 MarkObjectGreyDoNotEnqueue(ctx->normalized_map_cache()); | |
820 | |
821 IncrementalMarkingMarkingVisitor::VisitNativeContext(map, ctx); | |
822 } else { | |
823 IncrementalMarkingMarkingVisitor::IterateBody(map, obj); | |
824 } | |
825 | |
826 MarkBit obj_mark_bit = Marking::MarkBitFrom(obj); | |
827 SLOW_ASSERT(Marking::IsGrey(obj_mark_bit) || | |
828 (obj->IsFiller() && Marking::IsWhite(obj_mark_bit))); | |
829 Marking::MarkBlack(obj_mark_bit); | |
830 MemoryChunk::IncrementLiveBytesFromGC(obj->address(), size); | |
831 } | |
832 if (marking_deque_.IsEmpty()) MarkingComplete(action); | 828 if (marking_deque_.IsEmpty()) MarkingComplete(action); |
833 } | 829 } |
834 | 830 |
835 steps_count_++; | 831 steps_count_++; |
836 steps_count_since_last_gc_++; | 832 steps_count_since_last_gc_++; |
837 | 833 |
838 bool speed_up = false; | 834 bool speed_up = false; |
839 | 835 |
840 if ((steps_count_ % kMarkingSpeedAccellerationInterval) == 0) { | 836 if ((steps_count_ % kMarkingSpeedAccellerationInterval) == 0) { |
841 if (FLAG_trace_gc) { | 837 if (FLAG_trace_gc) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
923 bytes_scanned_ = 0; | 919 bytes_scanned_ = 0; |
924 write_barriers_invoked_since_last_step_ = 0; | 920 write_barriers_invoked_since_last_step_ = 0; |
925 } | 921 } |
926 | 922 |
927 | 923 |
928 int64_t IncrementalMarking::SpaceLeftInOldSpace() { | 924 int64_t IncrementalMarking::SpaceLeftInOldSpace() { |
929 return heap_->MaxOldGenerationSize() - heap_->PromotedSpaceSizeOfObjects(); | 925 return heap_->MaxOldGenerationSize() - heap_->PromotedSpaceSizeOfObjects(); |
930 } | 926 } |
931 | 927 |
932 } } // namespace v8::internal | 928 } } // namespace v8::internal |
OLD | NEW |