| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 size_of_objects / final_incremental_mark_compact_speed_in_bytes_per_ms; | 110 size_of_objects / final_incremental_mark_compact_speed_in_bytes_per_ms; |
| 111 return Min(result, kMaxFinalIncrementalMarkCompactTimeInMs); | 111 return Min(result, kMaxFinalIncrementalMarkCompactTimeInMs); |
| 112 } | 112 } |
| 113 | 113 |
| 114 | 114 |
| 115 bool GCIdleTimeHandler::ShouldDoScavenge( | 115 bool GCIdleTimeHandler::ShouldDoScavenge( |
| 116 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, | 116 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, |
| 117 size_t scavenge_speed_in_bytes_per_ms, | 117 size_t scavenge_speed_in_bytes_per_ms, |
| 118 size_t new_space_allocation_throughput_in_bytes_per_ms) { | 118 size_t new_space_allocation_throughput_in_bytes_per_ms) { |
| 119 size_t new_space_allocation_limit = | 119 size_t new_space_allocation_limit = |
| 120 kMaxFrameRenderingIdleTime * scavenge_speed_in_bytes_per_ms; | 120 kMaxScheduledIdleTime * scavenge_speed_in_bytes_per_ms; |
| 121 | 121 |
| 122 // If the limit is larger than the new space size, then scavenging used to be | 122 // If the limit is larger than the new space size, then scavenging used to be |
| 123 // really fast. We can take advantage of the whole new space. | 123 // really fast. We can take advantage of the whole new space. |
| 124 if (new_space_allocation_limit > new_space_size) { | 124 if (new_space_allocation_limit > new_space_size) { |
| 125 new_space_allocation_limit = new_space_size; | 125 new_space_allocation_limit = new_space_size; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // We do not know the allocation throughput before the first Scavenge. | 128 // We do not know the allocation throughput before the first Scavenge. |
| 129 // TODO(hpayer): Estimate allocation throughput before the first Scavenge. | 129 // TODO(hpayer): Estimate allocation throughput before the first Scavenge. |
| 130 if (new_space_allocation_throughput_in_bytes_per_ms == 0) { | 130 if (new_space_allocation_throughput_in_bytes_per_ms == 0) { |
| 131 new_space_allocation_limit = | 131 new_space_allocation_limit = |
| 132 static_cast<size_t>(new_space_size * kConservativeTimeRatio); | 132 static_cast<size_t>(new_space_size * kConservativeTimeRatio); |
| 133 } else { | 133 } else { |
| 134 // We have to trigger scavenge before we reach the end of new space. | 134 // We have to trigger scavenge before we reach the end of new space. |
| 135 new_space_allocation_limit -= | 135 new_space_allocation_limit -= |
| 136 new_space_allocation_throughput_in_bytes_per_ms * | 136 new_space_allocation_throughput_in_bytes_per_ms * kMaxScheduledIdleTime; |
| 137 kMaxFrameRenderingIdleTime; | |
| 138 } | 137 } |
| 139 | 138 |
| 140 if (scavenge_speed_in_bytes_per_ms == 0) { | 139 if (scavenge_speed_in_bytes_per_ms == 0) { |
| 141 scavenge_speed_in_bytes_per_ms = kInitialConservativeScavengeSpeed; | 140 scavenge_speed_in_bytes_per_ms = kInitialConservativeScavengeSpeed; |
| 142 } | 141 } |
| 143 | 142 |
| 144 if (new_space_allocation_limit <= used_new_space_size) { | 143 if (new_space_allocation_limit <= used_new_space_size) { |
| 145 if (used_new_space_size / scavenge_speed_in_bytes_per_ms <= | 144 if (used_new_space_size / scavenge_speed_in_bytes_per_ms <= |
| 146 idle_time_in_ms) { | 145 idle_time_in_ms) { |
| 147 return true; | 146 return true; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 if (ShouldDoMarkCompact(static_cast<size_t>(idle_time_in_ms), | 236 if (ShouldDoMarkCompact(static_cast<size_t>(idle_time_in_ms), |
| 238 heap_state.size_of_objects, | 237 heap_state.size_of_objects, |
| 239 heap_state.mark_compact_speed_in_bytes_per_ms)) { | 238 heap_state.mark_compact_speed_in_bytes_per_ms)) { |
| 240 // If there are no more than two GCs left in this idle round and we are | 239 // If there are no more than two GCs left in this idle round and we are |
| 241 // allowed to do a full GC, then make those GCs full in order to compact | 240 // allowed to do a full GC, then make those GCs full in order to compact |
| 242 // the code space. | 241 // the code space. |
| 243 // TODO(ulan): Once we enable code compaction for incremental marking, we | 242 // TODO(ulan): Once we enable code compaction for incremental marking, we |
| 244 // can get rid of this special case and always start incremental marking. | 243 // can get rid of this special case and always start incremental marking. |
| 245 int remaining_mark_sweeps = | 244 int remaining_mark_sweeps = |
| 246 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; | 245 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; |
| 247 if (static_cast<size_t>(idle_time_in_ms) > kMaxFrameRenderingIdleTime && | 246 if (static_cast<size_t>(idle_time_in_ms) > kMaxScheduledIdleTime && |
| 248 (remaining_mark_sweeps <= 2 || | 247 (remaining_mark_sweeps <= 2 || |
| 249 !heap_state.can_start_incremental_marking)) { | 248 !heap_state.can_start_incremental_marking)) { |
| 250 return GCIdleTimeAction::FullGC(); | 249 return GCIdleTimeAction::FullGC(); |
| 251 } | 250 } |
| 252 } | 251 } |
| 253 if (!heap_state.can_start_incremental_marking) { | 252 if (!heap_state.can_start_incremental_marking) { |
| 254 return GCIdleTimeAction::Nothing(); | 253 return GCIdleTimeAction::Nothing(); |
| 255 } | 254 } |
| 256 } | 255 } |
| 257 // TODO(hpayer): Estimate finalize sweeping time. | 256 // TODO(hpayer): Estimate finalize sweeping time. |
| 258 if (heap_state.sweeping_in_progress && | 257 if (heap_state.sweeping_in_progress && |
| 259 static_cast<size_t>(idle_time_in_ms) >= kMinTimeForFinalizeSweeping) { | 258 static_cast<size_t>(idle_time_in_ms) >= kMinTimeForFinalizeSweeping) { |
| 260 return GCIdleTimeAction::FinalizeSweeping(); | 259 return GCIdleTimeAction::FinalizeSweeping(); |
| 261 } | 260 } |
| 262 | 261 |
| 263 if (heap_state.incremental_marking_stopped && | 262 if (heap_state.incremental_marking_stopped && |
| 264 !heap_state.can_start_incremental_marking) { | 263 !heap_state.can_start_incremental_marking) { |
| 265 return GCIdleTimeAction::Nothing(); | 264 return GCIdleTimeAction::Nothing(); |
| 266 } | 265 } |
| 267 size_t step_size = EstimateMarkingStepSize( | 266 size_t step_size = EstimateMarkingStepSize( |
| 268 static_cast<size_t>(kIncrementalMarkingStepTimeInMs), | 267 static_cast<size_t>(kIncrementalMarkingStepTimeInMs), |
| 269 heap_state.incremental_marking_speed_in_bytes_per_ms); | 268 heap_state.incremental_marking_speed_in_bytes_per_ms); |
| 270 return GCIdleTimeAction::IncrementalMarking(step_size); | 269 return GCIdleTimeAction::IncrementalMarking(step_size); |
| 271 } | 270 } |
| 272 } | 271 } |
| 273 } | 272 } |
| OLD | NEW |