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 #ifndef V8_HEAP_INCREMENTAL_MARKING_H_ | 5 #ifndef V8_HEAP_INCREMENTAL_MARKING_H_ |
6 #define V8_HEAP_INCREMENTAL_MARKING_H_ | 6 #define V8_HEAP_INCREMENTAL_MARKING_H_ |
7 | 7 |
8 #include "src/cancelable-task.h" | 8 #include "src/cancelable-task.h" |
9 #include "src/execution.h" | 9 #include "src/execution.h" |
10 #include "src/heap/heap.h" | 10 #include "src/heap/heap.h" |
11 #include "src/heap/incremental-marking-job.h" | 11 #include "src/heap/incremental-marking-job.h" |
12 #include "src/heap/mark-compact.h" | 12 #include "src/heap/mark-compact.h" |
13 #include "src/heap/spaces.h" | 13 #include "src/heap/spaces.h" |
14 #include "src/objects.h" | 14 #include "src/objects.h" |
15 | 15 |
16 namespace v8 { | 16 namespace v8 { |
17 namespace internal { | 17 namespace internal { |
18 | 18 |
19 // Forward declarations. | 19 // Forward declarations. |
20 class MarkBit; | 20 class MarkBit; |
21 class PagedSpace; | 21 class PagedSpace; |
22 | 22 |
23 class IncrementalMarking { | 23 class IncrementalMarking { |
24 public: | 24 public: |
25 enum State { STOPPED, SWEEPING, MARKING, COMPLETE }; | 25 enum State { STOPPED, SWEEPING, MARKING, COMPLETE }; |
26 | 26 |
27 enum CompletionAction { GC_VIA_STACK_GUARD, NO_GC_VIA_STACK_GUARD }; | 27 enum CompletionAction { GC_VIA_STACK_GUARD, NO_GC_VIA_STACK_GUARD }; |
28 | 28 |
29 enum ForceMarkingAction { FORCE_MARKING, DO_NOT_FORCE_MARKING }; | |
30 | |
31 enum ForceCompletionAction { FORCE_COMPLETION, DO_NOT_FORCE_COMPLETION }; | 29 enum ForceCompletionAction { FORCE_COMPLETION, DO_NOT_FORCE_COMPLETION }; |
32 | 30 |
33 enum GCRequestType { NONE, COMPLETE_MARKING, FINALIZATION }; | 31 enum GCRequestType { NONE, COMPLETE_MARKING, FINALIZATION }; |
34 | 32 |
35 struct StepActions { | |
36 StepActions(CompletionAction complete_action_, | |
37 ForceMarkingAction force_marking_, | |
38 ForceCompletionAction force_completion_) | |
39 : completion_action(complete_action_), | |
40 force_marking(force_marking_), | |
41 force_completion(force_completion_) {} | |
42 | |
43 CompletionAction completion_action; | |
44 ForceMarkingAction force_marking; | |
45 ForceCompletionAction force_completion; | |
46 }; | |
47 | |
48 static StepActions IdleStepActions(); | |
49 | |
50 explicit IncrementalMarking(Heap* heap); | 33 explicit IncrementalMarking(Heap* heap); |
51 | 34 |
52 static void Initialize(); | 35 static void Initialize(); |
53 | 36 |
54 State state() { | 37 State state() { |
55 DCHECK(state_ == STOPPED || FLAG_incremental_marking); | 38 DCHECK(state_ == STOPPED || FLAG_incremental_marking); |
56 return state_; | 39 return state_; |
57 } | 40 } |
58 | 41 |
59 bool should_hurry() { return should_hurry_; } | 42 bool should_hurry() { return should_hurry_; } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 void FinalizeMarking(CompletionAction action); | 89 void FinalizeMarking(CompletionAction action); |
107 | 90 |
108 void MarkingComplete(CompletionAction action); | 91 void MarkingComplete(CompletionAction action); |
109 | 92 |
110 void Epilogue(); | 93 void Epilogue(); |
111 | 94 |
112 // Performs incremental marking steps until deadline_in_ms is reached. It | 95 // Performs incremental marking steps until deadline_in_ms is reached. It |
113 // returns the remaining time that cannot be used for incremental marking | 96 // returns the remaining time that cannot be used for incremental marking |
114 // anymore because a single step would exceed the deadline. | 97 // anymore because a single step would exceed the deadline. |
115 double AdvanceIncrementalMarking(double deadline_in_ms, | 98 double AdvanceIncrementalMarking(double deadline_in_ms, |
116 StepActions step_actions); | 99 CompletionAction completion_action, |
| 100 ForceCompletionAction force_completion); |
117 | 101 |
118 // It's hard to know how much work the incremental marker should do to make | 102 // It's hard to know how much work the incremental marker should do to make |
119 // progress in the face of the mutator creating new work for it. We start | 103 // progress in the face of the mutator creating new work for it. We start |
120 // of at a moderate rate of work and gradually increase the speed of the | 104 // of at a moderate rate of work and gradually increase the speed of the |
121 // incremental marker until it completes. | 105 // incremental marker until it completes. |
122 // Do some marking every time this much memory has been allocated or that many | 106 // Do some marking every time this much memory has been allocated or that many |
123 // heavy (color-checking) write barriers have been invoked. | 107 // heavy (color-checking) write barriers have been invoked. |
124 static const intptr_t kAllocatedThreshold = 65536; | 108 static const intptr_t kAllocatedThreshold = 65536; |
125 static const intptr_t kWriteBarriersInvokedThreshold = 32768; | 109 static const intptr_t kWriteBarriersInvokedThreshold = 32768; |
126 // Start off by marking this many times more memory than has been allocated. | 110 // Start off by marking this many times more memory than has been allocated. |
127 static const intptr_t kInitialMarkingSpeed = 1; | 111 static const intptr_t kInitialMarkingSpeed = 1; |
128 // But if we are promoting a lot of data we need to mark faster to keep up | 112 // But if we are promoting a lot of data we need to mark faster to keep up |
129 // with the data that is entering the old space through promotion. | 113 // with the data that is entering the old space through promotion. |
130 static const intptr_t kFastMarking = 3; | 114 static const intptr_t kFastMarking = 3; |
131 // After this many steps we increase the marking/allocating factor. | 115 // After this many steps we increase the marking/allocating factor. |
132 static const intptr_t kMarkingSpeedAccellerationInterval = 1024; | 116 static const intptr_t kMarkingSpeedAccellerationInterval = 1024; |
133 // This is how much we increase the marking/allocating factor by. | 117 // This is how much we increase the marking/allocating factor by. |
134 static const intptr_t kMarkingSpeedAccelleration = 2; | 118 static const intptr_t kMarkingSpeedAccelleration = 2; |
135 static const intptr_t kMaxMarkingSpeed = 1000; | 119 static const intptr_t kMaxMarkingSpeed = 1000; |
136 | 120 |
| 121 static const intptr_t kStepSizeInMs = 1; |
| 122 |
137 // This is the upper bound for how many times we allow finalization of | 123 // This is the upper bound for how many times we allow finalization of |
138 // incremental marking to be postponed. | 124 // incremental marking to be postponed. |
139 static const size_t kMaxIdleMarkingDelayCounter = 3; | 125 static const size_t kMaxIdleMarkingDelayCounter = 3; |
140 | 126 |
141 void FinalizeSweeping(); | 127 void FinalizeSweeping(); |
142 | 128 |
143 void OldSpaceStep(intptr_t allocated); | 129 void NotifyAllocatedBytes(intptr_t allocated_bytes); |
144 | 130 |
145 intptr_t Step(intptr_t allocated, CompletionAction action, | 131 void Step(intptr_t bytes_to_process, CompletionAction action, |
146 ForceMarkingAction marking = DO_NOT_FORCE_MARKING, | 132 ForceCompletionAction completion); |
147 ForceCompletionAction completion = FORCE_COMPLETION); | |
148 | 133 |
149 inline void RestartIfNotMarking(); | 134 inline void RestartIfNotMarking(); |
150 | 135 |
151 static void RecordWriteFromCode(HeapObject* obj, Object** slot, | 136 static void RecordWriteFromCode(HeapObject* obj, Object** slot, |
152 Isolate* isolate); | 137 Isolate* isolate); |
153 | 138 |
154 static void RecordWriteOfCodeEntryFromCode(JSFunction* host, Object** slot, | 139 static void RecordWriteOfCodeEntryFromCode(JSFunction* host, Object** slot, |
155 Isolate* isolate); | 140 Isolate* isolate); |
156 | 141 |
157 // Record a slot for compaction. Returns false for objects that are | 142 // Record a slot for compaction. Returns false for objects that are |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 void StartBlackAllocationForTesting() { StartBlackAllocation(); } | 223 void StartBlackAllocationForTesting() { StartBlackAllocation(); } |
239 | 224 |
240 private: | 225 private: |
241 class Observer : public AllocationObserver { | 226 class Observer : public AllocationObserver { |
242 public: | 227 public: |
243 Observer(IncrementalMarking& incremental_marking, intptr_t step_size) | 228 Observer(IncrementalMarking& incremental_marking, intptr_t step_size) |
244 : AllocationObserver(step_size), | 229 : AllocationObserver(step_size), |
245 incremental_marking_(incremental_marking) {} | 230 incremental_marking_(incremental_marking) {} |
246 | 231 |
247 void Step(int bytes_allocated, Address, size_t) override { | 232 void Step(int bytes_allocated, Address, size_t) override { |
248 incremental_marking_.Step(bytes_allocated, | 233 incremental_marking_.NotifyAllocatedBytes(bytes_allocated); |
249 IncrementalMarking::GC_VIA_STACK_GUARD); | |
250 } | 234 } |
251 | 235 |
252 private: | 236 private: |
253 IncrementalMarking& incremental_marking_; | 237 IncrementalMarking& incremental_marking_; |
254 }; | 238 }; |
255 | 239 |
256 int64_t SpaceLeftInOldSpace(); | 240 int64_t SpaceLeftInOldSpace(); |
257 | 241 |
258 void SpeedUp(); | 242 void SpeedUp(); |
259 | 243 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 GCRequestType request_type_; | 309 GCRequestType request_type_; |
326 | 310 |
327 IncrementalMarkingJob incremental_marking_job_; | 311 IncrementalMarkingJob incremental_marking_job_; |
328 | 312 |
329 DISALLOW_IMPLICIT_CONSTRUCTORS(IncrementalMarking); | 313 DISALLOW_IMPLICIT_CONSTRUCTORS(IncrementalMarking); |
330 }; | 314 }; |
331 } // namespace internal | 315 } // namespace internal |
332 } // namespace v8 | 316 } // namespace v8 |
333 | 317 |
334 #endif // V8_HEAP_INCREMENTAL_MARKING_H_ | 318 #endif // V8_HEAP_INCREMENTAL_MARKING_H_ |
OLD | NEW |