| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 177 } |
| 178 | 178 |
| 179 | 179 |
| 180 bool GCIdleTimeHandler::ShouldDoOverApproximateWeakClosure( | 180 bool GCIdleTimeHandler::ShouldDoOverApproximateWeakClosure( |
| 181 size_t idle_time_in_ms) { | 181 size_t idle_time_in_ms) { |
| 182 // TODO(jochen): Estimate the time it will take to build the object groups. | 182 // TODO(jochen): Estimate the time it will take to build the object groups. |
| 183 return idle_time_in_ms >= kMinTimeForOverApproximatingWeakClosureInMs; | 183 return idle_time_in_ms >= kMinTimeForOverApproximatingWeakClosureInMs; |
| 184 } | 184 } |
| 185 | 185 |
| 186 | 186 |
| 187 GCIdleTimeAction GCIdleTimeHandler::NothingOrDone() { |
| 188 if (idle_times_which_made_no_progress_since_last_idle_round_ >= |
| 189 kMaxNoProgressIdleTimesPerIdleRound) { |
| 190 return GCIdleTimeAction::Done(); |
| 191 } else { |
| 192 idle_times_which_made_no_progress_since_last_idle_round_++; |
| 193 return GCIdleTimeAction::Nothing(); |
| 194 } |
| 195 } |
| 196 |
| 197 |
| 187 // The following logic is implemented by the controller: | 198 // The following logic is implemented by the controller: |
| 188 // (1) If we don't have any idle time, do nothing, unless a context was | 199 // (1) If we don't have any idle time, do nothing, unless a context was |
| 189 // disposed, incremental marking is stopped, and the heap is small. Then do | 200 // disposed, incremental marking is stopped, and the heap is small. Then do |
| 190 // a full GC. | 201 // a full GC. |
| 191 // (2) If the new space is almost full and we can affort a Scavenge or if the | 202 // (2) If the new space is almost full and we can afford a Scavenge or if the |
| 192 // next Scavenge will very likely take long, then a Scavenge is performed. | 203 // next Scavenge will very likely take long, then a Scavenge is performed. |
| 193 // (3) If there is currently no MarkCompact idle round going on, we start a | 204 // (3) If there is currently no MarkCompact idle round going on, we start a |
| 194 // new idle round if enough garbage was created. Otherwise we do not perform | 205 // new idle round if enough garbage was created. Otherwise we do not perform |
| 195 // garbage collection to keep system utilization low. | 206 // garbage collection to keep system utilization low. |
| 196 // (4) If incremental marking is done, we perform a full garbage collection | 207 // (4) If incremental marking is done, we perform a full garbage collection |
| 197 // if we are allowed to still do full garbage collections during this idle | 208 // if we are allowed to still do full garbage collections during this idle |
| 198 // round or if we are not allowed to start incremental marking. Otherwise we | 209 // round or if we are not allowed to start incremental marking. Otherwise we |
| 199 // do not perform garbage collection to keep system utilization low. | 210 // do not perform garbage collection to keep system utilization low. |
| 200 // (5) If sweeping is in progress and we received a large enough idle time | 211 // (5) If sweeping is in progress and we received a large enough idle time |
| 201 // request, we finalize sweeping here. | 212 // request, we finalize sweeping here. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 } | 253 } |
| 243 | 254 |
| 244 // TODO(hpayer): Estimate finalize sweeping time. | 255 // TODO(hpayer): Estimate finalize sweeping time. |
| 245 if (heap_state.sweeping_in_progress && | 256 if (heap_state.sweeping_in_progress && |
| 246 static_cast<size_t>(idle_time_in_ms) >= kMinTimeForFinalizeSweeping) { | 257 static_cast<size_t>(idle_time_in_ms) >= kMinTimeForFinalizeSweeping) { |
| 247 return GCIdleTimeAction::FinalizeSweeping(); | 258 return GCIdleTimeAction::FinalizeSweeping(); |
| 248 } | 259 } |
| 249 | 260 |
| 250 if (heap_state.incremental_marking_stopped && | 261 if (heap_state.incremental_marking_stopped && |
| 251 !heap_state.can_start_incremental_marking) { | 262 !heap_state.can_start_incremental_marking) { |
| 252 return GCIdleTimeAction::Nothing(); | 263 return NothingOrDone(); |
| 253 } | 264 } |
| 265 |
| 254 size_t step_size = EstimateMarkingStepSize( | 266 size_t step_size = EstimateMarkingStepSize( |
| 255 static_cast<size_t>(kIncrementalMarkingStepTimeInMs), | 267 static_cast<size_t>(kIncrementalMarkingStepTimeInMs), |
| 256 heap_state.incremental_marking_speed_in_bytes_per_ms); | 268 heap_state.incremental_marking_speed_in_bytes_per_ms); |
| 257 return GCIdleTimeAction::IncrementalMarking(step_size); | 269 return GCIdleTimeAction::IncrementalMarking(step_size); |
| 258 } | 270 } |
| 259 } | 271 } |
| 260 } | 272 } |
| OLD | NEW |