OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_GC_IDLE_TIME_HANDLER_H_ | 5 #ifndef V8_HEAP_GC_IDLE_TIME_HANDLER_H_ |
6 #define V8_HEAP_GC_IDLE_TIME_HANDLER_H_ | 6 #define V8_HEAP_GC_IDLE_TIME_HANDLER_H_ |
7 | 7 |
8 #include "src/globals.h" | 8 #include "src/globals.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 enum GCIdleTimeActionType { | 13 enum GCIdleTimeActionType { |
14 DONE, | 14 DONE, |
15 DO_NOTHING, | 15 DO_NOTHING, |
16 DO_INCREMENTAL_MARKING, | 16 DO_INCREMENTAL_MARKING, |
17 DO_SCAVENGE, | 17 DO_SCAVENGE, |
18 DO_FULL_GC, | 18 DO_FULL_GC, |
19 DO_FINALIZE_SWEEPING | 19 DO_FINALIZE_SWEEPING |
20 }; | 20 }; |
21 | 21 |
22 | 22 |
23 class GCIdleTimeAction { | 23 class GCIdleTimeAction { |
24 public: | 24 public: |
25 static GCIdleTimeAction Done() { | 25 static GCIdleTimeAction Done() { |
26 GCIdleTimeAction result; | 26 GCIdleTimeAction result; |
27 result.type = DONE; | 27 result.type = DONE; |
28 result.parameter = 0; | 28 result.parameter = 0; |
29 result.additional_work = false; | 29 result.additional_work = false; |
30 result.reduce_memory = false; | |
30 return result; | 31 return result; |
31 } | 32 } |
32 | 33 |
33 static GCIdleTimeAction Nothing() { | 34 static GCIdleTimeAction Nothing() { |
34 GCIdleTimeAction result; | 35 GCIdleTimeAction result; |
35 result.type = DO_NOTHING; | 36 result.type = DO_NOTHING; |
36 result.parameter = 0; | 37 result.parameter = 0; |
37 result.additional_work = false; | 38 result.additional_work = false; |
39 result.reduce_memory = false; | |
38 return result; | 40 return result; |
39 } | 41 } |
40 | 42 |
41 static GCIdleTimeAction IncrementalMarking(intptr_t step_size) { | 43 static GCIdleTimeAction IncrementalMarking(intptr_t step_size, |
44 bool reduce_memory) { | |
42 GCIdleTimeAction result; | 45 GCIdleTimeAction result; |
43 result.type = DO_INCREMENTAL_MARKING; | 46 result.type = DO_INCREMENTAL_MARKING; |
44 result.parameter = step_size; | 47 result.parameter = step_size; |
45 result.additional_work = false; | 48 result.additional_work = false; |
49 result.reduce_memory = reduce_memory; | |
46 return result; | 50 return result; |
47 } | 51 } |
48 | 52 |
49 static GCIdleTimeAction Scavenge() { | 53 static GCIdleTimeAction Scavenge() { |
Hannes Payer (out of office)
2015/05/04 11:20:37
scavenge could also respect the reduce_memory flag
ulan
2015/05/05 12:10:13
Done.
| |
50 GCIdleTimeAction result; | 54 GCIdleTimeAction result; |
51 result.type = DO_SCAVENGE; | 55 result.type = DO_SCAVENGE; |
52 result.parameter = 0; | 56 result.parameter = 0; |
53 result.additional_work = false; | 57 result.additional_work = false; |
58 result.reduce_memory = false; | |
54 return result; | 59 return result; |
55 } | 60 } |
56 | 61 |
57 static GCIdleTimeAction FullGC() { | 62 static GCIdleTimeAction FullGC(bool reduce_memory) { |
58 GCIdleTimeAction result; | 63 GCIdleTimeAction result; |
59 result.type = DO_FULL_GC; | 64 result.type = DO_FULL_GC; |
60 result.parameter = 0; | 65 result.parameter = 0; |
61 result.additional_work = false; | 66 result.additional_work = false; |
67 result.reduce_memory = reduce_memory; | |
62 return result; | 68 return result; |
63 } | 69 } |
64 | 70 |
65 static GCIdleTimeAction FinalizeSweeping() { | 71 static GCIdleTimeAction FinalizeSweeping() { |
66 GCIdleTimeAction result; | 72 GCIdleTimeAction result; |
67 result.type = DO_FINALIZE_SWEEPING; | 73 result.type = DO_FINALIZE_SWEEPING; |
68 result.parameter = 0; | 74 result.parameter = 0; |
69 result.additional_work = false; | 75 result.additional_work = false; |
76 result.reduce_memory = false; | |
70 return result; | 77 return result; |
71 } | 78 } |
72 | 79 |
73 void Print(); | 80 void Print(); |
74 | 81 |
75 GCIdleTimeActionType type; | 82 GCIdleTimeActionType type; |
76 intptr_t parameter; | 83 intptr_t parameter; |
77 bool additional_work; | 84 bool additional_work; |
85 bool reduce_memory; | |
78 }; | 86 }; |
79 | 87 |
80 | 88 |
81 class GCTracer; | 89 class GCTracer; |
82 | 90 |
83 // The idle time handler makes decisions about which garbage collection | 91 // The idle time handler makes decisions about which garbage collection |
84 // operations are executing during IdleNotification. | 92 // operations are executing during IdleNotification. |
85 class GCIdleTimeHandler { | 93 class GCIdleTimeHandler { |
86 public: | 94 public: |
87 // If we haven't recorded any incremental marking events yet, we carefully | 95 // If we haven't recorded any incremental marking events yet, we carefully |
(...skipping 16 matching lines...) Expand all Loading... | |
104 static const size_t kInitialConservativeFinalIncrementalMarkCompactSpeed = | 112 static const size_t kInitialConservativeFinalIncrementalMarkCompactSpeed = |
105 2 * MB; | 113 2 * MB; |
106 | 114 |
107 // Maximum mark-compact time returned by EstimateMarkCompactTime. | 115 // Maximum mark-compact time returned by EstimateMarkCompactTime. |
108 static const size_t kMaxMarkCompactTimeInMs; | 116 static const size_t kMaxMarkCompactTimeInMs; |
109 | 117 |
110 // Maximum final incremental mark-compact time returned by | 118 // Maximum final incremental mark-compact time returned by |
111 // EstimateFinalIncrementalMarkCompactTime. | 119 // EstimateFinalIncrementalMarkCompactTime. |
112 static const size_t kMaxFinalIncrementalMarkCompactTimeInMs; | 120 static const size_t kMaxFinalIncrementalMarkCompactTimeInMs; |
113 | 121 |
114 // Number of idle mark-compact events, after which idle handler will finish | |
115 // idle round. | |
116 static const int kMaxMarkCompactsInIdleRound; | |
117 | |
118 // Number of scavenges that will trigger start of new idle round. | |
119 static const int kIdleScavengeThreshold; | |
120 | |
121 // This is the maximum scheduled idle time. Note that it can be more than | 122 // This is the maximum scheduled idle time. Note that it can be more than |
122 // 16.66 ms when there is currently no rendering going on. | 123 // 16.66 ms when there is currently no rendering going on. |
123 static const size_t kMaxScheduledIdleTime = 50; | 124 static const size_t kMaxScheduledIdleTime = 50; |
124 | 125 |
125 // The maximum idle time when frames are rendered is 16.66ms. | 126 // The maximum idle time when frames are rendered is 16.66ms. |
126 static const size_t kMaxFrameRenderingIdleTime = 17; | 127 static const size_t kMaxFrameRenderingIdleTime = 17; |
127 | 128 |
128 // We conservatively assume that in the next kTimeUntilNextIdleEvent ms | 129 // We conservatively assume that in the next kTimeUntilNextIdleEvent ms |
129 // no idle notification happens. | 130 // no idle notification happens. |
130 static const size_t kTimeUntilNextIdleEvent = 100; | 131 static const size_t kTimeUntilNextIdleEvent = 100; |
131 | 132 |
132 // If we haven't recorded any scavenger events yet, we use a conservative | 133 // If we haven't recorded any scavenger events yet, we use a conservative |
133 // lower bound for the scavenger speed. | 134 // lower bound for the scavenger speed. |
134 static const size_t kInitialConservativeScavengeSpeed = 100 * KB; | 135 static const size_t kInitialConservativeScavengeSpeed = 100 * KB; |
135 | 136 |
136 // If contexts are disposed at a higher rate a full gc is triggered. | 137 // If contexts are disposed at a higher rate a full gc is triggered. |
137 static const double kHighContextDisposalRate; | 138 static const double kHighContextDisposalRate; |
138 | 139 |
139 // Incremental marking step time. | 140 // Incremental marking step time. |
140 static const size_t kIncrementalMarkingStepTimeInMs = 1; | 141 static const size_t kIncrementalMarkingStepTimeInMs = 1; |
141 | 142 |
142 static const size_t kMinTimeForOverApproximatingWeakClosureInMs; | 143 static const size_t kMinTimeForOverApproximatingWeakClosureInMs; |
143 | 144 |
144 // Number of times we will return a Nothing action per Idle round despite | 145 // The number of idle MarkCompact GCs to perform before transitioning to |
145 // having idle time available before we returning a Done action to ensure we | 146 // the kDone mode. |
146 // don't keep scheduling idle tasks and making no progress. | 147 static const int kMaxIdleMarkCompacts = 3; |
147 static const int kMaxNoProgressIdleTimesPerIdleRound = 10; | 148 |
149 // The number of mutator GCs before transitioning from the kDone mode. | |
Hannes Payer (out of office)
2015/05/04 11:20:36
to kReduceLatency
ulan
2015/05/05 12:10:13
Done.
| |
150 static const int kGCsBeforeMutatorIsActive = 7; | |
151 | |
152 // Mutator is considered idle if | |
153 // 1) there is an idle notification with time >= kMaxLongIdleTime, | |
154 // 2) or there are kLongIdleNotificationsBeforeMutatorIsIdle idle | |
155 // notifications | |
156 // with time >= kMinLongIdleTime and without any mutator GC in between. | |
157 static const int kMinLongIdleTime = kMaxFrameRenderingIdleTime + 1; | |
158 static const int kMaxLongIdleTime = 1000; | |
159 static const int kLongIdleNotificationsBeforeMutatorIsIdle = 20; | |
160 | |
148 | 161 |
149 class HeapState { | 162 class HeapState { |
150 public: | 163 public: |
151 void Print(); | 164 void Print(); |
152 | 165 |
153 int contexts_disposed; | 166 int contexts_disposed; |
154 double contexts_disposal_rate; | 167 double contexts_disposal_rate; |
155 size_t size_of_objects; | 168 size_t size_of_objects; |
156 bool incremental_marking_stopped; | 169 bool incremental_marking_stopped; |
157 bool can_start_incremental_marking; | 170 bool can_start_incremental_marking; |
158 bool sweeping_in_progress; | 171 bool sweeping_in_progress; |
159 bool sweeping_completed; | 172 bool sweeping_completed; |
160 size_t mark_compact_speed_in_bytes_per_ms; | 173 size_t mark_compact_speed_in_bytes_per_ms; |
161 size_t incremental_marking_speed_in_bytes_per_ms; | 174 size_t incremental_marking_speed_in_bytes_per_ms; |
162 size_t final_incremental_mark_compact_speed_in_bytes_per_ms; | 175 size_t final_incremental_mark_compact_speed_in_bytes_per_ms; |
163 size_t scavenge_speed_in_bytes_per_ms; | 176 size_t scavenge_speed_in_bytes_per_ms; |
164 size_t used_new_space_size; | 177 size_t used_new_space_size; |
165 size_t new_space_capacity; | 178 size_t new_space_capacity; |
166 size_t new_space_allocation_throughput_in_bytes_per_ms; | 179 size_t new_space_allocation_throughput_in_bytes_per_ms; |
167 }; | 180 }; |
168 | 181 |
169 GCIdleTimeHandler() | 182 GCIdleTimeHandler() |
170 : mark_compacts_since_idle_round_started_(0), | 183 : idle_mark_compacts_(0), |
171 scavenges_since_last_idle_round_(0), | 184 mark_compacts_(0), |
172 idle_times_which_made_no_progress_since_last_idle_round_(0) {} | 185 scavenges_(0), |
186 long_idle_notifications_(0), | |
187 mode_(kReduceLatency) {} | |
173 | 188 |
174 GCIdleTimeAction Compute(double idle_time_in_ms, HeapState heap_state); | 189 GCIdleTimeAction Compute(double idle_time_in_ms, HeapState heap_state); |
175 | 190 |
176 void NotifyIdleMarkCompact() { | 191 void NotifyIdleMarkCompact() { ++idle_mark_compacts_; } |
177 if (mark_compacts_since_idle_round_started_ < kMaxMarkCompactsInIdleRound) { | |
178 ++mark_compacts_since_idle_round_started_; | |
179 if (mark_compacts_since_idle_round_started_ == | |
180 kMaxMarkCompactsInIdleRound) { | |
181 scavenges_since_last_idle_round_ = 0; | |
182 } | |
183 } | |
184 } | |
185 | 192 |
186 void NotifyScavenge() { ++scavenges_since_last_idle_round_; } | 193 void NotifyMarkCompact() { ++mark_compacts_; } |
194 | |
195 void NotifyScavenge() { ++scavenges_; } | |
187 | 196 |
188 static size_t EstimateMarkingStepSize(size_t idle_time_in_ms, | 197 static size_t EstimateMarkingStepSize(size_t idle_time_in_ms, |
189 size_t marking_speed_in_bytes_per_ms); | 198 size_t marking_speed_in_bytes_per_ms); |
190 | 199 |
191 static size_t EstimateMarkCompactTime( | 200 static size_t EstimateMarkCompactTime( |
192 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms); | 201 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms); |
193 | 202 |
194 static size_t EstimateFinalIncrementalMarkCompactTime( | 203 static size_t EstimateFinalIncrementalMarkCompactTime( |
195 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms); | 204 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms); |
196 | 205 |
197 static bool ShouldDoMarkCompact(size_t idle_time_in_ms, | 206 static bool ShouldDoMarkCompact(size_t idle_time_in_ms, |
198 size_t size_of_objects, | 207 size_t size_of_objects, |
199 size_t mark_compact_speed_in_bytes_per_ms); | 208 size_t mark_compact_speed_in_bytes_per_ms); |
200 | 209 |
201 static bool ShouldDoContextDisposalMarkCompact(int context_disposed, | 210 static bool ShouldDoContextDisposalMarkCompact(int context_disposed, |
202 double contexts_disposal_rate); | 211 double contexts_disposal_rate); |
203 | 212 |
204 static bool ShouldDoFinalIncrementalMarkCompact( | 213 static bool ShouldDoFinalIncrementalMarkCompact( |
205 size_t idle_time_in_ms, size_t size_of_objects, | 214 size_t idle_time_in_ms, size_t size_of_objects, |
206 size_t final_incremental_mark_compact_speed_in_bytes_per_ms); | 215 size_t final_incremental_mark_compact_speed_in_bytes_per_ms); |
207 | 216 |
208 static bool ShouldDoOverApproximateWeakClosure(size_t idle_time_in_ms); | 217 static bool ShouldDoOverApproximateWeakClosure(size_t idle_time_in_ms); |
209 | 218 |
210 static bool ShouldDoScavenge( | 219 static bool ShouldDoScavenge( |
211 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, | 220 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, |
212 size_t scavenger_speed_in_bytes_per_ms, | 221 size_t scavenger_speed_in_bytes_per_ms, |
213 size_t new_space_allocation_throughput_in_bytes_per_ms); | 222 size_t new_space_allocation_throughput_in_bytes_per_ms); |
214 | 223 |
215 private: | 224 private: |
216 GCIdleTimeAction NothingOrDone(); | 225 enum Mode { kReduceLatency, kReduceMemory, kDone }; |
217 | 226 |
218 void StartIdleRound() { | 227 bool IsMutatorActive(int contexts_disposed, int gcs); |
219 mark_compacts_since_idle_round_started_ = 0; | 228 bool IsMutatorIdle(int long_idle_notifications, int gcs); |
220 idle_times_which_made_no_progress_since_last_idle_round_ = 0; | 229 void UpdateCounters(double idle_time_in_ms); |
221 } | 230 void ResetCounters(); |
222 bool IsMarkCompactIdleRoundFinished() { | 231 Mode NextMode(const HeapState& heap_state); |
223 return mark_compacts_since_idle_round_started_ == | 232 GCIdleTimeAction Step(double idle_time_in_ms, const HeapState& heap_state, |
224 kMaxMarkCompactsInIdleRound; | 233 bool reduce_memory); |
225 } | |
226 bool EnoughGarbageSinceLastIdleRound() { | |
227 return scavenges_since_last_idle_round_ >= kIdleScavengeThreshold; | |
228 } | |
229 | 234 |
230 int mark_compacts_since_idle_round_started_; | 235 int idle_mark_compacts_; |
231 int scavenges_since_last_idle_round_; | 236 int mark_compacts_; |
232 int idle_times_which_made_no_progress_since_last_idle_round_; | 237 int scavenges_; |
238 int long_idle_notifications_; | |
239 | |
240 Mode mode_; | |
233 | 241 |
234 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler); | 242 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler); |
235 }; | 243 }; |
236 | 244 |
237 } // namespace internal | 245 } // namespace internal |
238 } // namespace v8 | 246 } // namespace v8 |
239 | 247 |
240 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ | 248 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ |
OLD | NEW |