| 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 } else { | 236 } else { |
| 237 return Action(idle_time_in_ms, heap_state, mode_ == kReduceMemory); | 237 return Action(idle_time_in_ms, heap_state, mode_ == kReduceMemory); |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 | 240 |
| 241 | 241 |
| 242 // The following logic is implemented by the controller: | 242 // The following logic is implemented by the controller: |
| 243 // (1) If we don't have any idle time, do nothing, unless a context was | 243 // (1) If we don't have any idle time, do nothing, unless a context was |
| 244 // disposed, incremental marking is stopped, and the heap is small. Then do | 244 // disposed, incremental marking is stopped, and the heap is small. Then do |
| 245 // a full GC. | 245 // a full GC. |
| 246 // (2) If the new space is almost full and we can afford a Scavenge or if the | 246 // (2) If the context disposal rate is high and we cannot perform a full GC, |
| 247 // we do nothing until the context disposal rate becomes lower. |
| 248 // (3) If the new space is almost full and we can affort a Scavenge or if the |
| 247 // next Scavenge will very likely take long, then a Scavenge is performed. | 249 // next Scavenge will very likely take long, then a Scavenge is performed. |
| 248 // (3) If incremental marking is done, we perform a full garbage collection | 250 // (4) If there is currently no MarkCompact idle round going on, we start a |
| 251 // new idle round if enough garbage was created. Otherwise we do not perform |
| 252 // garbage collection to keep system utilization low. |
| 253 // (5) If incremental marking is done, we perform a full garbage collection |
| 249 // if we are allowed to still do full garbage collections during this idle | 254 // if we are allowed to still do full garbage collections during this idle |
| 250 // round or if we are not allowed to start incremental marking. Otherwise we | 255 // round or if we are not allowed to start incremental marking. Otherwise we |
| 251 // do not perform garbage collection to keep system utilization low. | 256 // do not perform garbage collection to keep system utilization low. |
| 252 // (4) If sweeping is in progress and we received a large enough idle time | 257 // (6) If sweeping is in progress and we received a large enough idle time |
| 253 // request, we finalize sweeping here. | 258 // request, we finalize sweeping here. |
| 254 // (5) If incremental marking is in progress, we perform a marking step. Note, | 259 // (7) If incremental marking is in progress, we perform a marking step. Note, |
| 255 // that this currently may trigger a full garbage collection. | 260 // that this currently may trigger a full garbage collection. |
| 256 GCIdleTimeAction GCIdleTimeHandler::Action(double idle_time_in_ms, | 261 GCIdleTimeAction GCIdleTimeHandler::Action(double idle_time_in_ms, |
| 257 const HeapState& heap_state, | 262 const HeapState& heap_state, |
| 258 bool reduce_memory) { | 263 bool reduce_memory) { |
| 259 if (static_cast<int>(idle_time_in_ms) <= 0) { | 264 if (static_cast<int>(idle_time_in_ms) <= 0) { |
| 260 if (heap_state.incremental_marking_stopped) { | 265 if (heap_state.incremental_marking_stopped) { |
| 261 if (ShouldDoContextDisposalMarkCompact( | 266 if (ShouldDoContextDisposalMarkCompact( |
| 262 heap_state.contexts_disposed, | 267 heap_state.contexts_disposed, |
| 263 heap_state.contexts_disposal_rate)) { | 268 heap_state.contexts_disposal_rate)) { |
| 264 return GCIdleTimeAction::FullGC(false); | 269 return GCIdleTimeAction::FullGC(false); |
| 265 } | 270 } |
| 266 } | 271 } |
| 267 return GCIdleTimeAction::Nothing(); | 272 return GCIdleTimeAction::Nothing(); |
| 268 } | 273 } |
| 269 | 274 |
| 275 // We are in a context disposal GC scenario. Don't do anything if we do not |
| 276 // get the right idle signal. |
| 277 if (ShouldDoContextDisposalMarkCompact(heap_state.contexts_disposed, |
| 278 heap_state.contexts_disposal_rate)) { |
| 279 return GCIdleTimeAction::Nothing(); |
| 280 } |
| 281 |
| 270 if (ShouldDoScavenge( | 282 if (ShouldDoScavenge( |
| 271 static_cast<size_t>(idle_time_in_ms), heap_state.new_space_capacity, | 283 static_cast<size_t>(idle_time_in_ms), heap_state.new_space_capacity, |
| 272 heap_state.used_new_space_size, | 284 heap_state.used_new_space_size, |
| 273 heap_state.scavenge_speed_in_bytes_per_ms, | 285 heap_state.scavenge_speed_in_bytes_per_ms, |
| 274 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) { | 286 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) { |
| 275 return GCIdleTimeAction::Scavenge(); | 287 return GCIdleTimeAction::Scavenge(); |
| 276 } | 288 } |
| 277 | 289 |
| 278 if (heap_state.incremental_marking_stopped && reduce_memory) { | 290 if (heap_state.incremental_marking_stopped && reduce_memory) { |
| 279 if (ShouldDoMarkCompact(static_cast<size_t>(idle_time_in_ms), | 291 if (ShouldDoMarkCompact(static_cast<size_t>(idle_time_in_ms), |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 } | 376 } |
| 365 if (mutator_gcs > idle_mark_compacts_) { | 377 if (mutator_gcs > idle_mark_compacts_) { |
| 366 return kReduceLatency; | 378 return kReduceLatency; |
| 367 } | 379 } |
| 368 break; | 380 break; |
| 369 } | 381 } |
| 370 return mode_; | 382 return mode_; |
| 371 } | 383 } |
| 372 } | 384 } |
| 373 } | 385 } |
| OLD | NEW |