| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // sweeper threads. | 91 // sweeper threads. |
| 92 static const size_t kMinTimeForFinalizeSweeping; | 92 static const size_t kMinTimeForFinalizeSweeping; |
| 93 | 93 |
| 94 // Number of idle mark-compact events, after which idle handler will finish | 94 // Number of idle mark-compact events, after which idle handler will finish |
| 95 // idle round. | 95 // idle round. |
| 96 static const int kMaxMarkCompactsInIdleRound; | 96 static const int kMaxMarkCompactsInIdleRound; |
| 97 | 97 |
| 98 // Number of scavenges that will trigger start of new idle round. | 98 // Number of scavenges that will trigger start of new idle round. |
| 99 static const int kIdleScavengeThreshold; | 99 static const int kIdleScavengeThreshold; |
| 100 | 100 |
| 101 // If less than that much memory is left in the new space, we consider it |
| 102 // as almost full and force a new space collection earlier in the idle time. |
| 103 static const size_t kNewSpaceAlmostFullTreshold = 100 * KB; |
| 104 |
| 105 // If we haven't recorded any scavenger events yet, we use a conservative |
| 106 // lower bound for the scavenger speed. |
| 107 static const size_t kInitialConservativeScavengeSpeed = 100 * KB; |
| 108 |
| 101 struct HeapState { | 109 struct HeapState { |
| 102 int contexts_disposed; | 110 int contexts_disposed; |
| 103 size_t size_of_objects; | 111 size_t size_of_objects; |
| 104 bool incremental_marking_stopped; | 112 bool incremental_marking_stopped; |
| 105 bool can_start_incremental_marking; | 113 bool can_start_incremental_marking; |
| 106 bool sweeping_in_progress; | 114 bool sweeping_in_progress; |
| 107 size_t mark_compact_speed_in_bytes_per_ms; | 115 size_t mark_compact_speed_in_bytes_per_ms; |
| 108 size_t incremental_marking_speed_in_bytes_per_ms; | 116 size_t incremental_marking_speed_in_bytes_per_ms; |
| 117 size_t scavenge_speed_in_bytes_per_ms; |
| 118 size_t available_new_space_memory; |
| 119 size_t new_space_capacity; |
| 109 }; | 120 }; |
| 110 | 121 |
| 111 GCIdleTimeHandler() | 122 GCIdleTimeHandler() |
| 112 : mark_compacts_since_idle_round_started_(0), | 123 : mark_compacts_since_idle_round_started_(0), |
| 113 scavenges_since_last_idle_round_(0) {} | 124 scavenges_since_last_idle_round_(0) {} |
| 114 | 125 |
| 115 GCIdleTimeAction Compute(size_t idle_time_in_ms, HeapState heap_state); | 126 GCIdleTimeAction Compute(size_t idle_time_in_ms, HeapState heap_state); |
| 116 | 127 |
| 117 void NotifyIdleMarkCompact() { | 128 void NotifyIdleMarkCompact() { |
| 118 if (mark_compacts_since_idle_round_started_ < kMaxMarkCompactsInIdleRound) { | 129 if (mark_compacts_since_idle_round_started_ < kMaxMarkCompactsInIdleRound) { |
| 119 ++mark_compacts_since_idle_round_started_; | 130 ++mark_compacts_since_idle_round_started_; |
| 120 if (mark_compacts_since_idle_round_started_ == | 131 if (mark_compacts_since_idle_round_started_ == |
| 121 kMaxMarkCompactsInIdleRound) { | 132 kMaxMarkCompactsInIdleRound) { |
| 122 scavenges_since_last_idle_round_ = 0; | 133 scavenges_since_last_idle_round_ = 0; |
| 123 } | 134 } |
| 124 } | 135 } |
| 125 } | 136 } |
| 126 | 137 |
| 127 void NotifyScavenge() { ++scavenges_since_last_idle_round_; } | 138 void NotifyScavenge() { ++scavenges_since_last_idle_round_; } |
| 128 | 139 |
| 129 static size_t EstimateMarkingStepSize(size_t idle_time_in_ms, | 140 static size_t EstimateMarkingStepSize(size_t idle_time_in_ms, |
| 130 size_t marking_speed_in_bytes_per_ms); | 141 size_t marking_speed_in_bytes_per_ms); |
| 131 | 142 |
| 132 static size_t EstimateMarkCompactTime( | 143 static size_t EstimateMarkCompactTime( |
| 133 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms); | 144 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms); |
| 134 | 145 |
| 146 static size_t EstimateScavengeTime(size_t new_space_size, |
| 147 size_t scavenger_speed_in_bytes_per_ms); |
| 148 |
| 135 private: | 149 private: |
| 136 void StartIdleRound() { mark_compacts_since_idle_round_started_ = 0; } | 150 void StartIdleRound() { mark_compacts_since_idle_round_started_ = 0; } |
| 137 bool IsIdleRoundFinished() { | 151 bool IsMarkCompactIdleRoundFinished() { |
| 138 return mark_compacts_since_idle_round_started_ == | 152 return mark_compacts_since_idle_round_started_ == |
| 139 kMaxMarkCompactsInIdleRound; | 153 kMaxMarkCompactsInIdleRound; |
| 140 } | 154 } |
| 141 bool EnoughGarbageSinceLastIdleRound() { | 155 bool EnoughGarbageSinceLastIdleRound() { |
| 142 return scavenges_since_last_idle_round_ >= kIdleScavengeThreshold; | 156 return scavenges_since_last_idle_round_ >= kIdleScavengeThreshold; |
| 143 } | 157 } |
| 144 | 158 |
| 145 int mark_compacts_since_idle_round_started_; | 159 int mark_compacts_since_idle_round_started_; |
| 146 int scavenges_since_last_idle_round_; | 160 int scavenges_since_last_idle_round_; |
| 147 | 161 |
| 148 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler); | 162 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler); |
| 149 }; | 163 }; |
| 150 | 164 |
| 151 } // namespace internal | 165 } // namespace internal |
| 152 } // namespace v8 | 166 } // namespace v8 |
| 153 | 167 |
| 154 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ | 168 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ |
| OLD | NEW |