| 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 #ifndef V8_HEAP_GC_IDLE_TIME_HANDLER_H_ | 5 #ifndef V8_HEAP_GC_IDLE_TIME_HANDLER_H_ |
| 6 #define V8_HEAP_GC_IDLE_TIME_HANDLER_H_ | 6 #define V8_HEAP_GC_IDLE_TIME_HANDLER_H_ |
| 7 | 7 |
| 8 #include "src/globals.h" | 8 #include "src/globals.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 static const size_t kInitialConservativeScavengeSpeed = 100 * KB; | 131 static const size_t kInitialConservativeScavengeSpeed = 100 * KB; |
| 132 | 132 |
| 133 // If contexts are disposed at a higher rate a full gc is triggered. | 133 // If contexts are disposed at a higher rate a full gc is triggered. |
| 134 static const double kHighContextDisposalRate; | 134 static const double kHighContextDisposalRate; |
| 135 | 135 |
| 136 // Incremental marking step time. | 136 // Incremental marking step time. |
| 137 static const size_t kIncrementalMarkingStepTimeInMs = 1; | 137 static const size_t kIncrementalMarkingStepTimeInMs = 1; |
| 138 | 138 |
| 139 static const size_t kMinTimeForOverApproximatingWeakClosureInMs; | 139 static const size_t kMinTimeForOverApproximatingWeakClosureInMs; |
| 140 | 140 |
| 141 // Number of times we will return a Nothing action per Idle round despite |
| 142 // having idle time available before we returning a Done action to ensure we |
| 143 // don't keep scheduling idle tasks and making no progress. |
| 144 static const int kMaxNoProgressIdleTimesPerIdleRound = 10; |
| 145 |
| 141 class HeapState { | 146 class HeapState { |
| 142 public: | 147 public: |
| 143 void Print(); | 148 void Print(); |
| 144 | 149 |
| 145 int contexts_disposed; | 150 int contexts_disposed; |
| 146 double contexts_disposal_rate; | 151 double contexts_disposal_rate; |
| 147 size_t size_of_objects; | 152 size_t size_of_objects; |
| 148 bool incremental_marking_stopped; | 153 bool incremental_marking_stopped; |
| 149 bool can_start_incremental_marking; | 154 bool can_start_incremental_marking; |
| 150 bool sweeping_in_progress; | 155 bool sweeping_in_progress; |
| 151 size_t mark_compact_speed_in_bytes_per_ms; | 156 size_t mark_compact_speed_in_bytes_per_ms; |
| 152 size_t incremental_marking_speed_in_bytes_per_ms; | 157 size_t incremental_marking_speed_in_bytes_per_ms; |
| 153 size_t final_incremental_mark_compact_speed_in_bytes_per_ms; | 158 size_t final_incremental_mark_compact_speed_in_bytes_per_ms; |
| 154 size_t scavenge_speed_in_bytes_per_ms; | 159 size_t scavenge_speed_in_bytes_per_ms; |
| 155 size_t used_new_space_size; | 160 size_t used_new_space_size; |
| 156 size_t new_space_capacity; | 161 size_t new_space_capacity; |
| 157 size_t new_space_allocation_throughput_in_bytes_per_ms; | 162 size_t new_space_allocation_throughput_in_bytes_per_ms; |
| 158 }; | 163 }; |
| 159 | 164 |
| 160 GCIdleTimeHandler() | 165 GCIdleTimeHandler() |
| 161 : mark_compacts_since_idle_round_started_(0), | 166 : mark_compacts_since_idle_round_started_(0), |
| 162 scavenges_since_last_idle_round_(0) {} | 167 scavenges_since_last_idle_round_(0), |
| 168 idle_times_which_made_no_progress_since_last_idle_round_(0) {} |
| 163 | 169 |
| 164 GCIdleTimeAction Compute(double idle_time_in_ms, HeapState heap_state); | 170 GCIdleTimeAction Compute(double idle_time_in_ms, HeapState heap_state); |
| 165 | 171 |
| 166 void NotifyIdleMarkCompact() { | 172 void NotifyIdleMarkCompact() { |
| 167 if (mark_compacts_since_idle_round_started_ < kMaxMarkCompactsInIdleRound) { | 173 if (mark_compacts_since_idle_round_started_ < kMaxMarkCompactsInIdleRound) { |
| 168 ++mark_compacts_since_idle_round_started_; | 174 ++mark_compacts_since_idle_round_started_; |
| 169 if (mark_compacts_since_idle_round_started_ == | 175 if (mark_compacts_since_idle_round_started_ == |
| 170 kMaxMarkCompactsInIdleRound) { | 176 kMaxMarkCompactsInIdleRound) { |
| 171 scavenges_since_last_idle_round_ = 0; | 177 scavenges_since_last_idle_round_ = 0; |
| 172 } | 178 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 196 size_t final_incremental_mark_compact_speed_in_bytes_per_ms); | 202 size_t final_incremental_mark_compact_speed_in_bytes_per_ms); |
| 197 | 203 |
| 198 static bool ShouldDoOverApproximateWeakClosure(size_t idle_time_in_ms); | 204 static bool ShouldDoOverApproximateWeakClosure(size_t idle_time_in_ms); |
| 199 | 205 |
| 200 static bool ShouldDoScavenge( | 206 static bool ShouldDoScavenge( |
| 201 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, | 207 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, |
| 202 size_t scavenger_speed_in_bytes_per_ms, | 208 size_t scavenger_speed_in_bytes_per_ms, |
| 203 size_t new_space_allocation_throughput_in_bytes_per_ms); | 209 size_t new_space_allocation_throughput_in_bytes_per_ms); |
| 204 | 210 |
| 205 private: | 211 private: |
| 206 void StartIdleRound() { mark_compacts_since_idle_round_started_ = 0; } | 212 GCIdleTimeAction NothingOrDone(); |
| 213 |
| 214 void StartIdleRound() { |
| 215 mark_compacts_since_idle_round_started_ = 0; |
| 216 idle_times_which_made_no_progress_since_last_idle_round_ = 0; |
| 217 } |
| 207 bool IsMarkCompactIdleRoundFinished() { | 218 bool IsMarkCompactIdleRoundFinished() { |
| 208 return mark_compacts_since_idle_round_started_ == | 219 return mark_compacts_since_idle_round_started_ == |
| 209 kMaxMarkCompactsInIdleRound; | 220 kMaxMarkCompactsInIdleRound; |
| 210 } | 221 } |
| 211 bool EnoughGarbageSinceLastIdleRound() { | 222 bool EnoughGarbageSinceLastIdleRound() { |
| 212 return scavenges_since_last_idle_round_ >= kIdleScavengeThreshold; | 223 return scavenges_since_last_idle_round_ >= kIdleScavengeThreshold; |
| 213 } | 224 } |
| 214 | 225 |
| 215 int mark_compacts_since_idle_round_started_; | 226 int mark_compacts_since_idle_round_started_; |
| 216 int scavenges_since_last_idle_round_; | 227 int scavenges_since_last_idle_round_; |
| 228 int idle_times_which_made_no_progress_since_last_idle_round_; |
| 217 | 229 |
| 218 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler); | 230 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler); |
| 219 }; | 231 }; |
| 220 | 232 |
| 221 } // namespace internal | 233 } // namespace internal |
| 222 } // namespace v8 | 234 } // namespace v8 |
| 223 | 235 |
| 224 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ | 236 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ |
| OLD | NEW |