Chromium Code Reviews| 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 { |
| 11 | 11 |
| 12 const double GCIdleTimeHandler::kConservativeTimeRatio = 0.9; | 12 const double GCIdleTimeHandler::kConservativeTimeRatio = 0.9; |
| 13 const size_t GCIdleTimeHandler::kMaxMarkCompactTimeInMs = 1000; | 13 const size_t GCIdleTimeHandler::kMaxMarkCompactTimeInMs = 1000; |
| 14 const size_t GCIdleTimeHandler::kMaxFinalIncrementalMarkCompactTimeInMs = 1000; | 14 const size_t GCIdleTimeHandler::kMaxFinalIncrementalMarkCompactTimeInMs = 1000; |
| 15 const size_t GCIdleTimeHandler::kMinTimeForFinalizeSweeping = 100; | 15 const size_t GCIdleTimeHandler::kMinTimeForFinalizeSweeping = 100; |
| 16 const int GCIdleTimeHandler::kMaxMarkCompactsInIdleRound = 7; | 16 const int GCIdleTimeHandler::kMaxMarkCompactsInIdleRound = 7; |
| 17 const int GCIdleTimeHandler::kIdleScavengeThreshold = 5; | 17 const int GCIdleTimeHandler::kIdleScavengeThreshold = 5; |
| 18 const double GCIdleTimeHandler::kHighContextDisposalRate = 100; | 18 const double GCIdleTimeHandler::kHighContextDisposalRate = 100; |
| 19 const size_t GCIdleTimeHandler::kMinTimeForOverApproximatingWeakClosureInMs = 1; | 19 const size_t GCIdleTimeHandler::kMinTimeForOverApproximatingWeakClosureInMs = 1; |
| 20 const double GCIdleTimeHandler::kMinMillisecondsInBetweenMarkCompact = 1000; | |
| 20 | 21 |
| 21 | 22 |
| 22 void GCIdleTimeAction::Print() { | 23 void GCIdleTimeAction::Print() { |
| 23 switch (type) { | 24 switch (type) { |
| 24 case DONE: | 25 case DONE: |
| 25 PrintF("done"); | 26 PrintF("done"); |
| 26 break; | 27 break; |
| 27 case DO_NOTHING: | 28 case DO_NOTHING: |
| 28 PrintF("no action"); | 29 PrintF("no action"); |
| 29 break; | 30 break; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 idle_time_in_ms) { | 146 idle_time_in_ms) { |
| 146 return true; | 147 return true; |
| 147 } | 148 } |
| 148 } | 149 } |
| 149 return false; | 150 return false; |
| 150 } | 151 } |
| 151 | 152 |
| 152 | 153 |
| 153 bool GCIdleTimeHandler::ShouldDoMarkCompact( | 154 bool GCIdleTimeHandler::ShouldDoMarkCompact( |
| 154 size_t idle_time_in_ms, size_t size_of_objects, | 155 size_t idle_time_in_ms, size_t size_of_objects, |
| 155 size_t mark_compact_speed_in_bytes_per_ms) { | 156 size_t mark_compact_speed_in_bytes_per_ms, double last_mark_compact_time, |
| 156 return idle_time_in_ms >= | 157 double current_time) { |
| 157 EstimateMarkCompactTime(size_of_objects, | 158 bool mark_compact_rate_high = |
| 158 mark_compact_speed_in_bytes_per_ms); | 159 current_time < |
| 160 last_mark_compact_time + kMinMillisecondsInBetweenMarkCompact; | |
|
jochen (gone - plz use gerrit)
2015/03/20 12:41:52
you're adding seconds + milliseconds here as far a
Hannes Payer (out of office)
2015/03/20 14:20:39
yeah, found it when I run the experiment. already
| |
| 161 return !mark_compact_rate_high && | |
| 162 idle_time_in_ms >= | |
| 163 EstimateMarkCompactTime(size_of_objects, | |
| 164 mark_compact_speed_in_bytes_per_ms); | |
| 159 } | 165 } |
| 160 | 166 |
| 161 | 167 |
| 162 bool GCIdleTimeHandler::ShouldDoContextDisposalMarkCompact( | 168 bool GCIdleTimeHandler::ShouldDoContextDisposalMarkCompact( |
| 163 int contexts_disposed, double contexts_disposal_rate) { | 169 int contexts_disposed, double contexts_disposal_rate) { |
| 164 return contexts_disposed > 0 && contexts_disposal_rate > 0 && | 170 return contexts_disposed > 0 && contexts_disposal_rate > 0 && |
| 165 contexts_disposal_rate < kHighContextDisposalRate; | 171 contexts_disposal_rate < kHighContextDisposalRate; |
| 166 } | 172 } |
| 167 | 173 |
| 168 | 174 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 197 // round or if we are not allowed to start incremental marking. Otherwise we | 203 // round or if we are not allowed to start incremental marking. Otherwise we |
| 198 // do not perform garbage collection to keep system utilization low. | 204 // do not perform garbage collection to keep system utilization low. |
| 199 // (5) If sweeping is in progress and we received a large enough idle time | 205 // (5) If sweeping is in progress and we received a large enough idle time |
| 200 // request, we finalize sweeping here. | 206 // request, we finalize sweeping here. |
| 201 // (6) If incremental marking is in progress, we perform a marking step. Note, | 207 // (6) If incremental marking is in progress, we perform a marking step. Note, |
| 202 // that this currently may trigger a full garbage collection. | 208 // that this currently may trigger a full garbage collection. |
| 203 GCIdleTimeAction GCIdleTimeHandler::Compute(double idle_time_in_ms, | 209 GCIdleTimeAction GCIdleTimeHandler::Compute(double idle_time_in_ms, |
| 204 HeapState heap_state) { | 210 HeapState heap_state) { |
| 205 if (static_cast<int>(idle_time_in_ms) <= 0) { | 211 if (static_cast<int>(idle_time_in_ms) <= 0) { |
| 206 if (heap_state.contexts_disposed > 0) { | 212 if (heap_state.contexts_disposed > 0) { |
| 213 printf("start idle round, contexts disposed\n"); | |
|
jochen (gone - plz use gerrit)
2015/03/20 12:41:52
debug code?
Hannes Payer (out of office)
2015/03/20 14:20:39
Done.
| |
| 207 StartIdleRound(); | 214 StartIdleRound(); |
| 208 } | 215 } |
| 209 if (heap_state.incremental_marking_stopped) { | 216 if (heap_state.incremental_marking_stopped) { |
| 210 if (ShouldDoContextDisposalMarkCompact( | 217 if (ShouldDoContextDisposalMarkCompact( |
| 211 heap_state.contexts_disposed, | 218 heap_state.contexts_disposed, |
| 212 heap_state.contexts_disposal_rate)) { | 219 heap_state.contexts_disposal_rate)) { |
| 213 return GCIdleTimeAction::FullGC(); | 220 return GCIdleTimeAction::FullGC(); |
| 214 } | 221 } |
| 215 } | 222 } |
| 216 return GCIdleTimeAction::Nothing(); | 223 return GCIdleTimeAction::Nothing(); |
| 217 } | 224 } |
| 218 | 225 |
| 219 if (ShouldDoScavenge( | 226 if (ShouldDoScavenge( |
| 220 static_cast<size_t>(idle_time_in_ms), heap_state.new_space_capacity, | 227 static_cast<size_t>(idle_time_in_ms), heap_state.new_space_capacity, |
| 221 heap_state.used_new_space_size, | 228 heap_state.used_new_space_size, |
| 222 heap_state.scavenge_speed_in_bytes_per_ms, | 229 heap_state.scavenge_speed_in_bytes_per_ms, |
| 223 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) { | 230 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) { |
| 224 return GCIdleTimeAction::Scavenge(); | 231 return GCIdleTimeAction::Scavenge(); |
| 225 } | 232 } |
| 226 | 233 |
| 227 if (IsMarkCompactIdleRoundFinished()) { | 234 if (IsMarkCompactIdleRoundFinished()) { |
| 228 if (EnoughGarbageSinceLastIdleRound()) { | 235 if (EnoughGarbageSinceLastIdleRound()) { |
| 236 printf("start idle round, enough garbage\n"); | |
| 229 StartIdleRound(); | 237 StartIdleRound(); |
| 230 } else { | 238 } else { |
| 231 return GCIdleTimeAction::Done(); | 239 return GCIdleTimeAction::Done(); |
| 232 } | 240 } |
| 233 } | 241 } |
| 234 | 242 |
| 235 if (heap_state.incremental_marking_stopped) { | 243 if (heap_state.incremental_marking_stopped) { |
| 236 if (ShouldDoMarkCompact(static_cast<size_t>(idle_time_in_ms), | 244 if (ShouldDoMarkCompact( |
| 237 heap_state.size_of_objects, | 245 static_cast<size_t>(idle_time_in_ms), heap_state.size_of_objects, |
| 238 heap_state.mark_compact_speed_in_bytes_per_ms)) { | 246 heap_state.mark_compact_speed_in_bytes_per_ms, |
| 247 heap_state.last_mark_compact_time, heap_state.current_time)) { | |
| 239 // If there are no more than two GCs left in this idle round and we are | 248 // If there are no more than two GCs left in this idle round and we are |
| 240 // allowed to do a full GC, then make those GCs full in order to compact | 249 // allowed to do a full GC, then make those GCs full in order to compact |
| 241 // the code space. | 250 // the code space. |
| 242 // TODO(ulan): Once we enable code compaction for incremental marking, we | 251 // TODO(ulan): Once we enable code compaction for incremental marking, we |
| 243 // can get rid of this special case and always start incremental marking. | 252 // can get rid of this special case and always start incremental marking. |
| 244 int remaining_mark_sweeps = | 253 int remaining_mark_sweeps = |
| 245 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; | 254 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; |
| 246 if (static_cast<size_t>(idle_time_in_ms) > kMaxScheduledIdleTime && | 255 if (static_cast<size_t>(idle_time_in_ms) > kMaxScheduledIdleTime && |
| 247 (remaining_mark_sweeps <= 2 || | 256 (remaining_mark_sweeps <= 2 || |
| 248 !heap_state.can_start_incremental_marking)) { | 257 !heap_state.can_start_incremental_marking)) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 263 !heap_state.can_start_incremental_marking) { | 272 !heap_state.can_start_incremental_marking) { |
| 264 return GCIdleTimeAction::Nothing(); | 273 return GCIdleTimeAction::Nothing(); |
| 265 } | 274 } |
| 266 size_t step_size = EstimateMarkingStepSize( | 275 size_t step_size = EstimateMarkingStepSize( |
| 267 static_cast<size_t>(kIncrementalMarkingStepTimeInMs), | 276 static_cast<size_t>(kIncrementalMarkingStepTimeInMs), |
| 268 heap_state.incremental_marking_speed_in_bytes_per_ms); | 277 heap_state.incremental_marking_speed_in_bytes_per_ms); |
| 269 return GCIdleTimeAction::IncrementalMarking(step_size); | 278 return GCIdleTimeAction::IncrementalMarking(step_size); |
| 270 } | 279 } |
| 271 } | 280 } |
| 272 } | 281 } |
| OLD | NEW |