| 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/flags.h" | 5 #include "src/flags.h" |
| 6 #include "src/heap/gc-idle-time-handler.h" | 6 #include "src/heap/gc-idle-time-handler.h" |
| 7 #include "src/heap/gc-tracer.h" | 7 #include "src/heap/gc-tracer.h" |
| 8 #include "src/utils.h" | 8 #include "src/utils.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 size_t result = | 107 size_t result = |
| 108 size_of_objects / final_incremental_mark_compact_speed_in_bytes_per_ms; | 108 size_of_objects / final_incremental_mark_compact_speed_in_bytes_per_ms; |
| 109 return Min(result, kMaxFinalIncrementalMarkCompactTimeInMs); | 109 return Min(result, kMaxFinalIncrementalMarkCompactTimeInMs); |
| 110 } | 110 } |
| 111 | 111 |
| 112 | 112 |
| 113 bool GCIdleTimeHandler::ShouldDoScavenge( | 113 bool GCIdleTimeHandler::ShouldDoScavenge( |
| 114 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, | 114 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, |
| 115 size_t scavenge_speed_in_bytes_per_ms, | 115 size_t scavenge_speed_in_bytes_per_ms, |
| 116 size_t new_space_allocation_throughput_in_bytes_per_ms) { | 116 size_t new_space_allocation_throughput_in_bytes_per_ms) { |
| 117 if (idle_time_in_ms >= kMinBackgroundIdleTime) { |
| 118 // It is better to do full GC for the background tab. |
| 119 return false; |
| 120 } |
| 117 size_t new_space_allocation_limit = | 121 size_t new_space_allocation_limit = |
| 118 kMaxScheduledIdleTime * scavenge_speed_in_bytes_per_ms; | 122 kMaxScheduledIdleTime * scavenge_speed_in_bytes_per_ms; |
| 119 | 123 |
| 120 // If the limit is larger than the new space size, then scavenging used to be | 124 // If the limit is larger than the new space size, then scavenging used to be |
| 121 // really fast. We can take advantage of the whole new space. | 125 // really fast. We can take advantage of the whole new space. |
| 122 if (new_space_allocation_limit > new_space_size) { | 126 if (new_space_allocation_limit > new_space_size) { |
| 123 new_space_allocation_limit = new_space_size; | 127 new_space_allocation_limit = new_space_size; |
| 124 } | 128 } |
| 125 | 129 |
| 126 // We do not know the allocation throughput before the first scavenge. | 130 // We do not know the allocation throughput before the first scavenge. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 } | 190 } |
| 187 | 191 |
| 188 | 192 |
| 189 bool GCIdleTimeHandler::ShouldDoOverApproximateWeakClosure( | 193 bool GCIdleTimeHandler::ShouldDoOverApproximateWeakClosure( |
| 190 size_t idle_time_in_ms) { | 194 size_t idle_time_in_ms) { |
| 191 // TODO(jochen): Estimate the time it will take to build the object groups. | 195 // TODO(jochen): Estimate the time it will take to build the object groups. |
| 192 return idle_time_in_ms >= kMinTimeForOverApproximatingWeakClosureInMs; | 196 return idle_time_in_ms >= kMinTimeForOverApproximatingWeakClosureInMs; |
| 193 } | 197 } |
| 194 | 198 |
| 195 | 199 |
| 196 GCIdleTimeAction GCIdleTimeHandler::NothingOrDone() { | 200 GCIdleTimeAction GCIdleTimeHandler::NothingOrDone(double idle_time_in_ms) { |
| 201 if (idle_time_in_ms >= kMinBackgroundIdleTime) { |
| 202 return GCIdleTimeAction::Nothing(); |
| 203 } |
| 197 if (idle_times_which_made_no_progress_ >= kMaxNoProgressIdleTimes) { | 204 if (idle_times_which_made_no_progress_ >= kMaxNoProgressIdleTimes) { |
| 198 return GCIdleTimeAction::Done(); | 205 return GCIdleTimeAction::Done(); |
| 199 } else { | 206 } else { |
| 200 idle_times_which_made_no_progress_++; | 207 idle_times_which_made_no_progress_++; |
| 201 return GCIdleTimeAction::Nothing(); | 208 return GCIdleTimeAction::Nothing(); |
| 202 } | 209 } |
| 203 } | 210 } |
| 204 | 211 |
| 205 | 212 |
| 206 // The following logic is implemented by the controller: | 213 // The following logic is implemented by the controller: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 225 return GCIdleTimeAction::FullGC(); | 232 return GCIdleTimeAction::FullGC(); |
| 226 } | 233 } |
| 227 } | 234 } |
| 228 return GCIdleTimeAction::Nothing(); | 235 return GCIdleTimeAction::Nothing(); |
| 229 } | 236 } |
| 230 | 237 |
| 231 // We are in a context disposal GC scenario. Don't do anything if we do not | 238 // We are in a context disposal GC scenario. Don't do anything if we do not |
| 232 // get the right idle signal. | 239 // get the right idle signal. |
| 233 if (ShouldDoContextDisposalMarkCompact(heap_state.contexts_disposed, | 240 if (ShouldDoContextDisposalMarkCompact(heap_state.contexts_disposed, |
| 234 heap_state.contexts_disposal_rate)) { | 241 heap_state.contexts_disposal_rate)) { |
| 235 return NothingOrDone(); | 242 return NothingOrDone(idle_time_in_ms); |
| 236 } | 243 } |
| 237 | 244 |
| 238 if (ShouldDoScavenge( | 245 if (ShouldDoScavenge( |
| 239 static_cast<size_t>(idle_time_in_ms), heap_state.new_space_capacity, | 246 static_cast<size_t>(idle_time_in_ms), heap_state.new_space_capacity, |
| 240 heap_state.used_new_space_size, | 247 heap_state.used_new_space_size, |
| 241 heap_state.scavenge_speed_in_bytes_per_ms, | 248 heap_state.scavenge_speed_in_bytes_per_ms, |
| 242 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) { | 249 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) { |
| 243 return GCIdleTimeAction::Scavenge(); | 250 return GCIdleTimeAction::Scavenge(); |
| 244 } | 251 } |
| 245 | 252 |
| 246 if (heap_state.sweeping_in_progress) { | 253 if (heap_state.sweeping_in_progress) { |
| 247 if (heap_state.sweeping_completed) { | 254 if (heap_state.sweeping_completed) { |
| 248 return GCIdleTimeAction::FinalizeSweeping(); | 255 return GCIdleTimeAction::FinalizeSweeping(); |
| 249 } else { | 256 } else { |
| 250 return NothingOrDone(); | 257 return NothingOrDone(idle_time_in_ms); |
| 251 } | 258 } |
| 252 } | 259 } |
| 253 | 260 |
| 254 if (!FLAG_incremental_marking || heap_state.incremental_marking_stopped) { | 261 if (!FLAG_incremental_marking || heap_state.incremental_marking_stopped) { |
| 255 return GCIdleTimeAction::Done(); | 262 return GCIdleTimeAction::Done(); |
| 256 } | 263 } |
| 257 | 264 |
| 258 size_t step_size = EstimateMarkingStepSize( | 265 size_t step_size = EstimateMarkingStepSize( |
| 259 static_cast<size_t>(kIncrementalMarkingStepTimeInMs), | 266 static_cast<size_t>(kIncrementalMarkingStepTimeInMs), |
| 260 heap_state.incremental_marking_speed_in_bytes_per_ms); | 267 heap_state.incremental_marking_speed_in_bytes_per_ms); |
| 261 return GCIdleTimeAction::IncrementalMarking(step_size); | 268 return GCIdleTimeAction::IncrementalMarking(step_size); |
| 262 } | 269 } |
| 263 | 270 |
| 264 | 271 |
| 265 } | 272 } |
| 266 } | 273 } |
| OLD | NEW |