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 | |
191 class IncrementalMarkingMarkingVisitor | 178 class IncrementalMarkingMarkingVisitor |
192 : public StaticMarkingVisitor<IncrementalMarkingMarkingVisitor> { | 179 : public StaticMarkingVisitor<IncrementalMarkingMarkingVisitor> { |
193 public: | 180 public: |
194 static void Initialize() { | 181 static void Initialize() { |
195 StaticMarkingVisitor<IncrementalMarkingMarkingVisitor>::Initialize(); | 182 StaticMarkingVisitor<IncrementalMarkingMarkingVisitor>::Initialize(); |
196 | 183 |
197 table_.Register(kVisitNativeContext, &VisitNativeContextIncremental); | |
198 table_.Register(kVisitJSRegExp, &VisitJSRegExp); | 184 table_.Register(kVisitJSRegExp, &VisitJSRegExp); |
199 } | 185 } |
200 | 186 |
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 VisitNativeContext(map, context); | |
208 } | |
209 | |
210 static void VisitJSWeakMap(Map* map, HeapObject* object) { | 187 static void VisitJSWeakMap(Map* map, HeapObject* object) { |
211 Heap* heap = map->GetHeap(); | 188 Heap* heap = map->GetHeap(); |
212 VisitPointers(heap, | 189 VisitPointers(heap, |
213 HeapObject::RawField(object, JSWeakMap::kPropertiesOffset), | 190 HeapObject::RawField(object, JSWeakMap::kPropertiesOffset), |
214 HeapObject::RawField(object, JSWeakMap::kSize)); | 191 HeapObject::RawField(object, JSWeakMap::kSize)); |
215 } | 192 } |
216 | 193 |
217 static void BeforeVisitingSharedFunctionInfo(HeapObject* object) {} | 194 static void BeforeVisitingSharedFunctionInfo(HeapObject* object) {} |
218 | 195 |
219 INLINE(static void VisitPointer(Heap* heap, Object** p)) { | 196 INLINE(static void VisitPointer(Heap* heap, Object** p)) { |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 if (FLAG_trace_incremental_marking) { | 487 if (FLAG_trace_incremental_marking) { |
511 PrintF("[IncrementalMarking] Start sweeping.\n"); | 488 PrintF("[IncrementalMarking] Start sweeping.\n"); |
512 } | 489 } |
513 state_ = SWEEPING; | 490 state_ = SWEEPING; |
514 } | 491 } |
515 | 492 |
516 heap_->new_space()->LowerInlineAllocationLimit(kAllocatedThreshold); | 493 heap_->new_space()->LowerInlineAllocationLimit(kAllocatedThreshold); |
517 } | 494 } |
518 | 495 |
519 | 496 |
| 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 |
520 void IncrementalMarking::StartMarking(CompactionFlag flag) { | 510 void IncrementalMarking::StartMarking(CompactionFlag flag) { |
521 if (FLAG_trace_incremental_marking) { | 511 if (FLAG_trace_incremental_marking) { |
522 PrintF("[IncrementalMarking] Start marking\n"); | 512 PrintF("[IncrementalMarking] Start marking\n"); |
523 } | 513 } |
524 | 514 |
525 is_compacting_ = !FLAG_never_compact && (flag == ALLOW_COMPACTION) && | 515 is_compacting_ = !FLAG_never_compact && (flag == ALLOW_COMPACTION) && |
526 heap_->mark_compact_collector()->StartCompaction( | 516 heap_->mark_compact_collector()->StartCompaction( |
527 MarkCompactCollector::INCREMENTAL_COMPACTION); | 517 MarkCompactCollector::INCREMENTAL_COMPACTION); |
528 | 518 |
529 state_ = MARKING; | 519 state_ = MARKING; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 } | 612 } |
623 } | 613 } |
624 marking_deque_.set_top(new_top); | 614 marking_deque_.set_top(new_top); |
625 | 615 |
626 steps_took_since_last_gc_ = 0; | 616 steps_took_since_last_gc_ = 0; |
627 steps_count_since_last_gc_ = 0; | 617 steps_count_since_last_gc_ = 0; |
628 longest_step_ = 0.0; | 618 longest_step_ = 0.0; |
629 } | 619 } |
630 | 620 |
631 | 621 |
632 void IncrementalMarking::VisitObject(Map* map, HeapObject* obj, int size) { | |
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(), size); | |
645 } | |
646 | |
647 | |
648 void IncrementalMarking::ProcessMarkingDeque(intptr_t bytes_to_process) { | |
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 VisitObject(map, obj, size); | |
661 } | |
662 } | |
663 | |
664 | |
665 void IncrementalMarking::ProcessMarkingDeque() { | |
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 VisitObject(map, obj, obj->SizeFromMap(map)); | |
676 } | |
677 } | |
678 | |
679 | |
680 void IncrementalMarking::Hurry() { | 622 void IncrementalMarking::Hurry() { |
681 if (state() == MARKING) { | 623 if (state() == MARKING) { |
682 double start = 0.0; | 624 double start = 0.0; |
683 if (FLAG_trace_incremental_marking) { | 625 if (FLAG_trace_incremental_marking) { |
684 PrintF("[IncrementalMarking] Hurry\n"); | 626 PrintF("[IncrementalMarking] Hurry\n"); |
685 start = OS::TimeCurrentMillis(); | 627 start = OS::TimeCurrentMillis(); |
686 } | 628 } |
687 // TODO(gc) hurry can mark objects it encounters black as mutator | 629 // TODO(gc) hurry can mark objects it encounters black as mutator |
688 // was stopped. | 630 // was stopped. |
689 ProcessMarkingDeque(); | 631 Map* filler_map = heap_->one_pointer_filler_map(); |
| 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 } |
690 state_ = COMPLETE; | 657 state_ = COMPLETE; |
691 if (FLAG_trace_incremental_marking) { | 658 if (FLAG_trace_incremental_marking) { |
692 double end = OS::TimeCurrentMillis(); | 659 double end = OS::TimeCurrentMillis(); |
693 PrintF("[IncrementalMarking] Complete (hurry), spent %d ms.\n", | 660 PrintF("[IncrementalMarking] Complete (hurry), spent %d ms.\n", |
694 static_cast<int>(end - start)); | 661 static_cast<int>(end - start)); |
695 } | 662 } |
696 } | 663 } |
697 | 664 |
698 if (FLAG_cleanup_code_caches_at_gc) { | 665 if (FLAG_cleanup_code_caches_at_gc) { |
699 PolymorphicCodeCache* poly_cache = heap_->polymorphic_code_cache(); | 666 PolymorphicCodeCache* poly_cache = heap_->polymorphic_code_cache(); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 if (FLAG_trace_incremental_marking || FLAG_trace_gc) { | 785 if (FLAG_trace_incremental_marking || FLAG_trace_gc) { |
819 start = OS::TimeCurrentMillis(); | 786 start = OS::TimeCurrentMillis(); |
820 } | 787 } |
821 | 788 |
822 if (state_ == SWEEPING) { | 789 if (state_ == SWEEPING) { |
823 if (heap_->AdvanceSweepers(static_cast<int>(bytes_to_process))) { | 790 if (heap_->AdvanceSweepers(static_cast<int>(bytes_to_process))) { |
824 bytes_scanned_ = 0; | 791 bytes_scanned_ = 0; |
825 StartMarking(PREVENT_COMPACTION); | 792 StartMarking(PREVENT_COMPACTION); |
826 } | 793 } |
827 } else if (state_ == MARKING) { | 794 } else if (state_ == MARKING) { |
828 ProcessMarkingDeque(bytes_to_process); | 795 Map* filler_map = heap_->one_pointer_filler_map(); |
| 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 } |
829 if (marking_deque_.IsEmpty()) MarkingComplete(action); | 832 if (marking_deque_.IsEmpty()) MarkingComplete(action); |
830 } | 833 } |
831 | 834 |
832 steps_count_++; | 835 steps_count_++; |
833 steps_count_since_last_gc_++; | 836 steps_count_since_last_gc_++; |
834 | 837 |
835 bool speed_up = false; | 838 bool speed_up = false; |
836 | 839 |
837 if ((steps_count_ % kMarkingSpeedAccellerationInterval) == 0) { | 840 if ((steps_count_ % kMarkingSpeedAccellerationInterval) == 0) { |
838 if (FLAG_trace_gc) { | 841 if (FLAG_trace_gc) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 bytes_scanned_ = 0; | 923 bytes_scanned_ = 0; |
921 write_barriers_invoked_since_last_step_ = 0; | 924 write_barriers_invoked_since_last_step_ = 0; |
922 } | 925 } |
923 | 926 |
924 | 927 |
925 int64_t IncrementalMarking::SpaceLeftInOldSpace() { | 928 int64_t IncrementalMarking::SpaceLeftInOldSpace() { |
926 return heap_->MaxOldGenerationSize() - heap_->PromotedSpaceSizeOfObjects(); | 929 return heap_->MaxOldGenerationSize() - heap_->PromotedSpaceSizeOfObjects(); |
927 } | 930 } |
928 | 931 |
929 } } // namespace v8::internal | 932 } } // namespace v8::internal |
OLD | NEW |