| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // Number of scavenges that will trigger start of new idle round. | 106 // Number of scavenges that will trigger start of new idle round. |
| 107 static const int kIdleScavengeThreshold; | 107 static const int kIdleScavengeThreshold; |
| 108 | 108 |
| 109 // Heap size threshold below which we prefer mark-compact over incremental | 109 // Heap size threshold below which we prefer mark-compact over incremental |
| 110 // step. | 110 // step. |
| 111 static const size_t kSmallHeapSize = 2 * kPointerSize * MB; | 111 static const size_t kSmallHeapSize = 2 * kPointerSize * MB; |
| 112 | 112 |
| 113 // That is the maximum idle time we will have during frame rendering. | 113 // That is the maximum idle time we will have during frame rendering. |
| 114 static const size_t kMaxFrameRenderingIdleTime = 16; | 114 static const size_t kMaxFrameRenderingIdleTime = 16; |
| 115 | 115 |
| 116 // If less than that much memory is left in the new space, we consider it | |
| 117 // as almost full and force a new space collection earlier in the idle time. | |
| 118 static const size_t kNewSpaceAlmostFullTreshold = 100 * KB; | |
| 119 | |
| 120 // If we haven't recorded any scavenger events yet, we use a conservative | 116 // If we haven't recorded any scavenger events yet, we use a conservative |
| 121 // lower bound for the scavenger speed. | 117 // lower bound for the scavenger speed. |
| 122 static const size_t kInitialConservativeScavengeSpeed = 100 * KB; | 118 static const size_t kInitialConservativeScavengeSpeed = 100 * KB; |
| 123 | 119 |
| 124 struct HeapState { | 120 struct HeapState { |
| 125 int contexts_disposed; | 121 int contexts_disposed; |
| 126 size_t size_of_objects; | 122 size_t size_of_objects; |
| 127 bool incremental_marking_stopped; | 123 bool incremental_marking_stopped; |
| 128 bool can_start_incremental_marking; | 124 bool can_start_incremental_marking; |
| 129 bool sweeping_in_progress; | 125 bool sweeping_in_progress; |
| 130 size_t mark_compact_speed_in_bytes_per_ms; | 126 size_t mark_compact_speed_in_bytes_per_ms; |
| 131 size_t incremental_marking_speed_in_bytes_per_ms; | 127 size_t incremental_marking_speed_in_bytes_per_ms; |
| 132 size_t scavenge_speed_in_bytes_per_ms; | 128 size_t scavenge_speed_in_bytes_per_ms; |
| 133 size_t available_new_space_memory; | 129 size_t used_new_space_size; |
| 134 size_t new_space_capacity; | 130 size_t new_space_capacity; |
| 135 size_t new_space_allocation_throughput_in_bytes_per_ms; | 131 size_t new_space_allocation_throughput_in_bytes_per_ms; |
| 136 }; | 132 }; |
| 137 | 133 |
| 138 GCIdleTimeHandler() | 134 GCIdleTimeHandler() |
| 139 : mark_compacts_since_idle_round_started_(0), | 135 : mark_compacts_since_idle_round_started_(0), |
| 140 scavenges_since_last_idle_round_(0) {} | 136 scavenges_since_last_idle_round_(0) {} |
| 141 | 137 |
| 142 GCIdleTimeAction Compute(size_t idle_time_in_ms, HeapState heap_state); | 138 GCIdleTimeAction Compute(size_t idle_time_in_ms, HeapState heap_state); |
| 143 | 139 |
| 144 void NotifyIdleMarkCompact() { | 140 void NotifyIdleMarkCompact() { |
| 145 if (mark_compacts_since_idle_round_started_ < kMaxMarkCompactsInIdleRound) { | 141 if (mark_compacts_since_idle_round_started_ < kMaxMarkCompactsInIdleRound) { |
| 146 ++mark_compacts_since_idle_round_started_; | 142 ++mark_compacts_since_idle_round_started_; |
| 147 if (mark_compacts_since_idle_round_started_ == | 143 if (mark_compacts_since_idle_round_started_ == |
| 148 kMaxMarkCompactsInIdleRound) { | 144 kMaxMarkCompactsInIdleRound) { |
| 149 scavenges_since_last_idle_round_ = 0; | 145 scavenges_since_last_idle_round_ = 0; |
| 150 } | 146 } |
| 151 } | 147 } |
| 152 } | 148 } |
| 153 | 149 |
| 154 void NotifyScavenge() { ++scavenges_since_last_idle_round_; } | 150 void NotifyScavenge() { ++scavenges_since_last_idle_round_; } |
| 155 | 151 |
| 156 static size_t EstimateMarkingStepSize(size_t idle_time_in_ms, | 152 static size_t EstimateMarkingStepSize(size_t idle_time_in_ms, |
| 157 size_t marking_speed_in_bytes_per_ms); | 153 size_t marking_speed_in_bytes_per_ms); |
| 158 | 154 |
| 159 static size_t EstimateMarkCompactTime( | 155 static size_t EstimateMarkCompactTime( |
| 160 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms); | 156 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms); |
| 161 | 157 |
| 162 static size_t EstimateScavengeTime(size_t new_space_size, | 158 static bool DoScavenge( |
| 163 size_t scavenger_speed_in_bytes_per_ms); | 159 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, |
| 164 | 160 size_t scavenger_speed_in_bytes_per_ms, |
| 165 static bool ScavangeMayHappenSoon( | |
| 166 size_t available_new_space_memory, | |
| 167 size_t new_space_allocation_throughput_in_bytes_per_ms); | 161 size_t new_space_allocation_throughput_in_bytes_per_ms); |
| 168 | 162 |
| 169 private: | 163 private: |
| 170 void StartIdleRound() { mark_compacts_since_idle_round_started_ = 0; } | 164 void StartIdleRound() { mark_compacts_since_idle_round_started_ = 0; } |
| 171 bool IsMarkCompactIdleRoundFinished() { | 165 bool IsMarkCompactIdleRoundFinished() { |
| 172 return mark_compacts_since_idle_round_started_ == | 166 return mark_compacts_since_idle_round_started_ == |
| 173 kMaxMarkCompactsInIdleRound; | 167 kMaxMarkCompactsInIdleRound; |
| 174 } | 168 } |
| 175 bool EnoughGarbageSinceLastIdleRound() { | 169 bool EnoughGarbageSinceLastIdleRound() { |
| 176 return scavenges_since_last_idle_round_ >= kIdleScavengeThreshold; | 170 return scavenges_since_last_idle_round_ >= kIdleScavengeThreshold; |
| 177 } | 171 } |
| 178 | 172 |
| 179 int mark_compacts_since_idle_round_started_; | 173 int mark_compacts_since_idle_round_started_; |
| 180 int scavenges_since_last_idle_round_; | 174 int scavenges_since_last_idle_round_; |
| 181 | 175 |
| 182 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler); | 176 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler); |
| 183 }; | 177 }; |
| 184 | 178 |
| 185 } // namespace internal | 179 } // namespace internal |
| 186 } // namespace v8 | 180 } // namespace v8 |
| 187 | 181 |
| 188 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ | 182 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ |
| OLD | NEW |