Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/heap/incremental-marking.cc

Issue 1404523002: [heap] inline allocation steps refactor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Use virtual functions instead of callbacks Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "src/heap/gc-tracer.h" 11 #include "src/heap/gc-tracer.h"
12 #include "src/heap/mark-compact-inl.h" 12 #include "src/heap/mark-compact-inl.h"
13 #include "src/heap/objects-visiting.h" 13 #include "src/heap/objects-visiting.h"
14 #include "src/heap/objects-visiting-inl.h" 14 #include "src/heap/objects-visiting-inl.h"
15 #include "src/v8.h" 15 #include "src/v8.h"
16 16
17 namespace v8 { 17 namespace v8 {
18 namespace internal { 18 namespace internal {
19 19
20 class IncrementalMarkingObserver : public InlineAllocationObserver {
21 public:
22 IncrementalMarkingObserver(IncrementalMarking& incremental_marking,
23 intptr_t step_size)
24 : InlineAllocationObserver(step_size),
25 incremental_marking_(incremental_marking) {}
26
27 virtual void Step(int bytes_allocated) {
28 incremental_marking_.Step(bytes_allocated,
29 IncrementalMarking::GC_VIA_STACK_GUARD);
30 }
31
32 private:
33 IncrementalMarking& incremental_marking_;
34 };
35
20 36
21 IncrementalMarking::StepActions IncrementalMarking::IdleStepActions() { 37 IncrementalMarking::StepActions IncrementalMarking::IdleStepActions() {
22 return StepActions(IncrementalMarking::NO_GC_VIA_STACK_GUARD, 38 return StepActions(IncrementalMarking::NO_GC_VIA_STACK_GUARD,
23 IncrementalMarking::FORCE_MARKING, 39 IncrementalMarking::FORCE_MARKING,
24 IncrementalMarking::DO_NOT_FORCE_COMPLETION); 40 IncrementalMarking::DO_NOT_FORCE_COMPLETION);
25 } 41 }
26 42
27 43
28 IncrementalMarking::IncrementalMarking(Heap* heap) 44 IncrementalMarking::IncrementalMarking(Heap* heap)
29 : heap_(heap), 45 : heap_(heap),
46 observer_(nullptr),
30 state_(STOPPED), 47 state_(STOPPED),
31 is_compacting_(false), 48 is_compacting_(false),
32 steps_count_(0), 49 steps_count_(0),
33 old_generation_space_available_at_start_of_incremental_(0), 50 old_generation_space_available_at_start_of_incremental_(0),
34 old_generation_space_used_at_start_of_incremental_(0), 51 old_generation_space_used_at_start_of_incremental_(0),
35 bytes_rescanned_(0), 52 bytes_rescanned_(0),
36 should_hurry_(false), 53 should_hurry_(false),
37 marking_speed_(0), 54 marking_speed_(0),
38 bytes_scanned_(0), 55 bytes_scanned_(0),
39 allocated_(0), 56 allocated_(0),
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 579
563 if (!heap_->mark_compact_collector()->sweeping_in_progress()) { 580 if (!heap_->mark_compact_collector()->sweeping_in_progress()) {
564 StartMarking(); 581 StartMarking();
565 } else { 582 } else {
566 if (FLAG_trace_incremental_marking) { 583 if (FLAG_trace_incremental_marking) {
567 PrintF("[IncrementalMarking] Start sweeping.\n"); 584 PrintF("[IncrementalMarking] Start sweeping.\n");
568 } 585 }
569 state_ = SWEEPING; 586 state_ = SWEEPING;
570 } 587 }
571 588
572 heap_->LowerInlineAllocationLimit(kAllocatedThreshold); 589 observer_ = new IncrementalMarkingObserver(*this, kAllocatedThreshold);
ulan 2015/10/22 09:02:22 I think we can bind the lifetime of the observer t
ofrobots 2015/10/26 21:55:01 Done.
590 heap_->new_space()->AddInlineAllocationObserver(observer_);
591
573 incremental_marking_job()->Start(heap_); 592 incremental_marking_job()->Start(heap_);
574 } 593 }
575 594
576 595
577 void IncrementalMarking::StartMarking() { 596 void IncrementalMarking::StartMarking() {
578 if (FLAG_trace_incremental_marking) { 597 if (FLAG_trace_incremental_marking) {
579 PrintF("[IncrementalMarking] Start marking\n"); 598 PrintF("[IncrementalMarking] Start marking\n");
580 } 599 }
581 600
582 is_compacting_ = !FLAG_never_compact && 601 is_compacting_ = !FLAG_never_compact &&
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK); 833 context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK);
815 } 834 }
816 } 835 }
817 836
818 837
819 void IncrementalMarking::Stop() { 838 void IncrementalMarking::Stop() {
820 if (IsStopped()) return; 839 if (IsStopped()) return;
821 if (FLAG_trace_incremental_marking) { 840 if (FLAG_trace_incremental_marking) {
822 PrintF("[IncrementalMarking] Stopping.\n"); 841 PrintF("[IncrementalMarking] Stopping.\n");
823 } 842 }
824 heap_->ResetInlineAllocationLimit(); 843
844 if (observer_) {
845 heap_->new_space()->RemoveInlineAllocationObserver(observer_);
846 delete observer_;
Hannes Payer (out of office) 2015/10/22 09:14:14 Let's allocate/delete the observer at heap setup/s
ofrobots 2015/10/26 21:55:01 Done as per Ulan's suggestion above.
847 observer_ = nullptr;
848 }
849
825 IncrementalMarking::set_should_hurry(false); 850 IncrementalMarking::set_should_hurry(false);
826 ResetStepCounters(); 851 ResetStepCounters();
827 if (IsMarking()) { 852 if (IsMarking()) {
828 PatchIncrementalMarkingRecordWriteStubs(heap_, 853 PatchIncrementalMarkingRecordWriteStubs(heap_,
829 RecordWriteStub::STORE_BUFFER_ONLY); 854 RecordWriteStub::STORE_BUFFER_ONLY);
830 DeactivateIncrementalWriteBarrier(); 855 DeactivateIncrementalWriteBarrier();
831 856
832 if (is_compacting_) { 857 if (is_compacting_) {
833 LargeObjectIterator it(heap_->lo_space()); 858 LargeObjectIterator it(heap_->lo_space());
834 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { 859 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) {
835 Page* p = Page::FromAddress(obj->address()); 860 Page* p = Page::FromAddress(obj->address());
836 if (p->IsFlagSet(Page::RESCAN_ON_EVACUATION)) { 861 if (p->IsFlagSet(Page::RESCAN_ON_EVACUATION)) {
837 p->ClearFlag(Page::RESCAN_ON_EVACUATION); 862 p->ClearFlag(Page::RESCAN_ON_EVACUATION);
838 } 863 }
839 } 864 }
840 } 865 }
841 } 866 }
842 heap_->isolate()->stack_guard()->ClearGC(); 867 heap_->isolate()->stack_guard()->ClearGC();
843 state_ = STOPPED; 868 state_ = STOPPED;
844 is_compacting_ = false; 869 is_compacting_ = false;
845 } 870 }
846 871
847 872
848 void IncrementalMarking::Finalize() { 873 void IncrementalMarking::Finalize() {
849 Hurry(); 874 Hurry();
850 state_ = STOPPED; 875 state_ = STOPPED;
851 is_compacting_ = false; 876 is_compacting_ = false;
852 heap_->ResetInlineAllocationLimit(); 877
878 if (observer_) {
879 heap_->new_space()->RemoveInlineAllocationObserver(observer_);
880 delete observer_;
881 observer_ = nullptr;
882 }
853 IncrementalMarking::set_should_hurry(false); 883 IncrementalMarking::set_should_hurry(false);
854 ResetStepCounters(); 884 ResetStepCounters();
855 PatchIncrementalMarkingRecordWriteStubs(heap_, 885 PatchIncrementalMarkingRecordWriteStubs(heap_,
856 RecordWriteStub::STORE_BUFFER_ONLY); 886 RecordWriteStub::STORE_BUFFER_ONLY);
857 DeactivateIncrementalWriteBarrier(); 887 DeactivateIncrementalWriteBarrier();
858 DCHECK(heap_->mark_compact_collector()->marking_deque()->IsEmpty()); 888 DCHECK(heap_->mark_compact_collector()->marking_deque()->IsEmpty());
859 heap_->isolate()->stack_guard()->ClearGC(); 889 heap_->isolate()->stack_guard()->ClearGC();
860 } 890 }
861 891
862 892
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 void IncrementalMarking::IncrementIdleMarkingDelayCounter() { 1157 void IncrementalMarking::IncrementIdleMarkingDelayCounter() {
1128 idle_marking_delay_counter_++; 1158 idle_marking_delay_counter_++;
1129 } 1159 }
1130 1160
1131 1161
1132 void IncrementalMarking::ClearIdleMarkingDelayCounter() { 1162 void IncrementalMarking::ClearIdleMarkingDelayCounter() {
1133 idle_marking_delay_counter_ = 0; 1163 idle_marking_delay_counter_ = 0;
1134 } 1164 }
1135 } // namespace internal 1165 } // namespace internal
1136 } // namespace v8 1166 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698