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 #include "src/heap/gc-idle-time-handler.h" | 5 #include "src/heap/gc-idle-time-handler.h" |
6 #include "src/heap/gc-tracer.h" | 6 #include "src/heap/gc-tracer.h" |
7 #include "src/utils.h" | 7 #include "src/utils.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // new idle round if enough garbage was created. Otherwise we do not perform | 182 // new idle round if enough garbage was created. Otherwise we do not perform |
183 // garbage collection to keep system utilization low. | 183 // garbage collection to keep system utilization low. |
184 // (4) If incremental marking is done, we perform a full garbage collection | 184 // (4) If incremental marking is done, we perform a full garbage collection |
185 // if we are allowed to still do full garbage collections during this idle | 185 // if we are allowed to still do full garbage collections during this idle |
186 // round or if we are not allowed to start incremental marking. Otherwise we | 186 // round or if we are not allowed to start incremental marking. Otherwise we |
187 // do not perform garbage collection to keep system utilization low. | 187 // do not perform garbage collection to keep system utilization low. |
188 // (5) If sweeping is in progress and we received a large enough idle time | 188 // (5) If sweeping is in progress and we received a large enough idle time |
189 // request, we finalize sweeping here. | 189 // request, we finalize sweeping here. |
190 // (6) If incremental marking is in progress, we perform a marking step. Note, | 190 // (6) If incremental marking is in progress, we perform a marking step. Note, |
191 // that this currently may trigger a full garbage collection. | 191 // that this currently may trigger a full garbage collection. |
192 GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms, | 192 GCIdleTimeAction GCIdleTimeHandler::Compute(double idle_time_in_ms, |
193 HeapState heap_state) { | 193 HeapState heap_state) { |
194 if (idle_time_in_ms == 0) { | 194 if (idle_time_in_ms <= 0.0) { |
195 if (heap_state.incremental_marking_stopped) { | 195 if (heap_state.incremental_marking_stopped) { |
196 if (ShouldDoContextDisposalMarkCompact( | 196 if (ShouldDoContextDisposalMarkCompact( |
197 heap_state.contexts_disposed, | 197 heap_state.contexts_disposed, |
198 heap_state.contexts_disposal_rate)) { | 198 heap_state.contexts_disposal_rate)) { |
199 return GCIdleTimeAction::FullGC(); | 199 return GCIdleTimeAction::FullGC(); |
200 } | 200 } |
201 } | 201 } |
202 return GCIdleTimeAction::Nothing(); | 202 return GCIdleTimeAction::Nothing(); |
203 } | 203 } |
204 | 204 |
205 if (ShouldDoScavenge( | 205 if (ShouldDoScavenge( |
206 idle_time_in_ms, heap_state.new_space_capacity, | 206 static_cast<size_t>(idle_time_in_ms), heap_state.new_space_capacity, |
207 heap_state.used_new_space_size, | 207 heap_state.used_new_space_size, |
208 heap_state.scavenge_speed_in_bytes_per_ms, | 208 heap_state.scavenge_speed_in_bytes_per_ms, |
209 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) { | 209 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) { |
210 return GCIdleTimeAction::Scavenge(); | 210 return GCIdleTimeAction::Scavenge(); |
211 } | 211 } |
212 | 212 |
213 if (IsMarkCompactIdleRoundFinished()) { | 213 if (IsMarkCompactIdleRoundFinished()) { |
214 if (EnoughGarbageSinceLastIdleRound()) { | 214 if (EnoughGarbageSinceLastIdleRound()) { |
215 StartIdleRound(); | 215 StartIdleRound(); |
216 } else { | 216 } else { |
217 return GCIdleTimeAction::Done(); | 217 return GCIdleTimeAction::Done(); |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 if (heap_state.incremental_marking_stopped) { | 221 if (heap_state.incremental_marking_stopped) { |
222 if (ShouldDoMarkCompact(idle_time_in_ms, heap_state.size_of_objects, | 222 if (ShouldDoMarkCompact(static_cast<size_t>(idle_time_in_ms), |
| 223 heap_state.size_of_objects, |
223 heap_state.mark_compact_speed_in_bytes_per_ms)) { | 224 heap_state.mark_compact_speed_in_bytes_per_ms)) { |
224 // If there are no more than two GCs left in this idle round and we are | 225 // If there are no more than two GCs left in this idle round and we are |
225 // allowed to do a full GC, then make those GCs full in order to compact | 226 // allowed to do a full GC, then make those GCs full in order to compact |
226 // the code space. | 227 // the code space. |
227 // TODO(ulan): Once we enable code compaction for incremental marking, we | 228 // TODO(ulan): Once we enable code compaction for incremental marking, we |
228 // can get rid of this special case and always start incremental marking. | 229 // can get rid of this special case and always start incremental marking. |
229 int remaining_mark_sweeps = | 230 int remaining_mark_sweeps = |
230 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; | 231 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; |
231 if (idle_time_in_ms > kMaxFrameRenderingIdleTime && | 232 if (static_cast<size_t>(idle_time_in_ms) > kMaxFrameRenderingIdleTime && |
232 (remaining_mark_sweeps <= 2 || | 233 (remaining_mark_sweeps <= 2 || |
233 !heap_state.can_start_incremental_marking)) { | 234 !heap_state.can_start_incremental_marking)) { |
234 return GCIdleTimeAction::FullGC(); | 235 return GCIdleTimeAction::FullGC(); |
235 } | 236 } |
236 } | 237 } |
237 if (!heap_state.can_start_incremental_marking) { | 238 if (!heap_state.can_start_incremental_marking) { |
238 return GCIdleTimeAction::Nothing(); | 239 return GCIdleTimeAction::Nothing(); |
239 } | 240 } |
240 } | 241 } |
241 // TODO(hpayer): Estimate finalize sweeping time. | 242 // TODO(hpayer): Estimate finalize sweeping time. |
242 if (heap_state.sweeping_in_progress && | 243 if (heap_state.sweeping_in_progress && |
243 idle_time_in_ms >= kMinTimeForFinalizeSweeping) { | 244 static_cast<size_t>(idle_time_in_ms) >= kMinTimeForFinalizeSweeping) { |
244 return GCIdleTimeAction::FinalizeSweeping(); | 245 return GCIdleTimeAction::FinalizeSweeping(); |
245 } | 246 } |
246 | 247 |
247 if (heap_state.incremental_marking_stopped && | 248 if (heap_state.incremental_marking_stopped && |
248 !heap_state.can_start_incremental_marking) { | 249 !heap_state.can_start_incremental_marking) { |
249 return GCIdleTimeAction::Nothing(); | 250 return GCIdleTimeAction::Nothing(); |
250 } | 251 } |
251 size_t step_size = EstimateMarkingStepSize( | 252 size_t step_size = EstimateMarkingStepSize( |
252 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); | 253 static_cast<size_t>(idle_time_in_ms), |
| 254 heap_state.incremental_marking_speed_in_bytes_per_ms); |
253 return GCIdleTimeAction::IncrementalMarking(step_size); | 255 return GCIdleTimeAction::IncrementalMarking(step_size); |
254 } | 256 } |
255 } | 257 } |
256 } | 258 } |
OLD | NEW |