| 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; | |
| 15 const size_t GCIdleTimeHandler::kMinTimeForFinalizeSweeping = 100; | 14 const size_t GCIdleTimeHandler::kMinTimeForFinalizeSweeping = 100; |
| 16 const int GCIdleTimeHandler::kMaxMarkCompactsInIdleRound = 7; | 15 const int GCIdleTimeHandler::kMaxMarkCompactsInIdleRound = 7; |
| 17 const int GCIdleTimeHandler::kIdleScavengeThreshold = 5; | 16 const int GCIdleTimeHandler::kIdleScavengeThreshold = 5; |
| 18 const double GCIdleTimeHandler::kHighContextDisposalRate = 100; | 17 const double GCIdleTimeHandler::kHighContextDisposalRate = 100; |
| 19 | 18 |
| 20 | 19 |
| 21 void GCIdleTimeAction::Print() { | 20 void GCIdleTimeAction::Print() { |
| 22 switch (type) { | 21 switch (type) { |
| 23 case DONE: | 22 case DONE: |
| 24 PrintF("done"); | 23 PrintF("done"); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 if (marking_step_size > kMaximumMarkingStepSize) | 77 if (marking_step_size > kMaximumMarkingStepSize) |
| 79 return kMaximumMarkingStepSize; | 78 return kMaximumMarkingStepSize; |
| 80 | 79 |
| 81 return static_cast<size_t>(marking_step_size * kConservativeTimeRatio); | 80 return static_cast<size_t>(marking_step_size * kConservativeTimeRatio); |
| 82 } | 81 } |
| 83 | 82 |
| 84 | 83 |
| 85 size_t GCIdleTimeHandler::EstimateMarkCompactTime( | 84 size_t GCIdleTimeHandler::EstimateMarkCompactTime( |
| 86 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms) { | 85 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms) { |
| 87 // TODO(hpayer): Be more precise about the type of mark-compact event. It | 86 // TODO(hpayer): Be more precise about the type of mark-compact event. It |
| 88 // makes a huge difference if compaction is happening. | 87 // makes a huge difference if it is incremental or non-incremental and if |
| 88 // compaction is happening. |
| 89 if (mark_compact_speed_in_bytes_per_ms == 0) { | 89 if (mark_compact_speed_in_bytes_per_ms == 0) { |
| 90 mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed; | 90 mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed; |
| 91 } | 91 } |
| 92 size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms; | 92 size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms; |
| 93 return Min(result, kMaxMarkCompactTimeInMs); | 93 return Min(result, kMaxMarkCompactTimeInMs); |
| 94 } | 94 } |
| 95 | 95 |
| 96 | 96 |
| 97 size_t GCIdleTimeHandler::EstimateFinalIncrementalMarkCompactTime( | |
| 98 size_t size_of_objects, | |
| 99 size_t final_incremental_mark_compact_speed_in_bytes_per_ms) { | |
| 100 if (final_incremental_mark_compact_speed_in_bytes_per_ms == 0) { | |
| 101 final_incremental_mark_compact_speed_in_bytes_per_ms = | |
| 102 kInitialConservativeFinalIncrementalMarkCompactSpeed; | |
| 103 } | |
| 104 size_t result = | |
| 105 size_of_objects / final_incremental_mark_compact_speed_in_bytes_per_ms; | |
| 106 return Min(result, kMaxFinalIncrementalMarkCompactTimeInMs); | |
| 107 } | |
| 108 | |
| 109 | |
| 110 bool GCIdleTimeHandler::ShouldDoScavenge( | 97 bool GCIdleTimeHandler::ShouldDoScavenge( |
| 111 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, | 98 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, |
| 112 size_t scavenge_speed_in_bytes_per_ms, | 99 size_t scavenge_speed_in_bytes_per_ms, |
| 113 size_t new_space_allocation_throughput_in_bytes_per_ms) { | 100 size_t new_space_allocation_throughput_in_bytes_per_ms) { |
| 114 size_t new_space_allocation_limit = | 101 size_t new_space_allocation_limit = |
| 115 kMaxFrameRenderingIdleTime * scavenge_speed_in_bytes_per_ms; | 102 kMaxFrameRenderingIdleTime * scavenge_speed_in_bytes_per_ms; |
| 116 | 103 |
| 117 // If the limit is larger than the new space size, then scavenging used to be | 104 // If the limit is larger than the new space size, then scavenging used to be |
| 118 // really fast. We can take advantage of the whole new space. | 105 // really fast. We can take advantage of the whole new space. |
| 119 if (new_space_allocation_limit > new_space_size) { | 106 if (new_space_allocation_limit > new_space_size) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } | 142 } |
| 156 | 143 |
| 157 | 144 |
| 158 bool GCIdleTimeHandler::ShouldDoContextDisposalMarkCompact( | 145 bool GCIdleTimeHandler::ShouldDoContextDisposalMarkCompact( |
| 159 bool context_disposed, double contexts_disposal_rate) { | 146 bool context_disposed, double contexts_disposal_rate) { |
| 160 return context_disposed && contexts_disposal_rate > 0 && | 147 return context_disposed && contexts_disposal_rate > 0 && |
| 161 contexts_disposal_rate < kHighContextDisposalRate; | 148 contexts_disposal_rate < kHighContextDisposalRate; |
| 162 } | 149 } |
| 163 | 150 |
| 164 | 151 |
| 165 bool GCIdleTimeHandler::ShouldDoFinalIncrementalMarkCompact( | |
| 166 size_t idle_time_in_ms, size_t size_of_objects, | |
| 167 size_t final_incremental_mark_compact_speed_in_bytes_per_ms) { | |
| 168 return idle_time_in_ms >= | |
| 169 EstimateFinalIncrementalMarkCompactTime( | |
| 170 size_of_objects, | |
| 171 final_incremental_mark_compact_speed_in_bytes_per_ms); | |
| 172 } | |
| 173 | |
| 174 | |
| 175 // The following logic is implemented by the controller: | 152 // The following logic is implemented by the controller: |
| 176 // (1) If we don't have any idle time, do nothing, unless a context was | 153 // (1) If we don't have any idle time, do nothing, unless a context was |
| 177 // disposed, incremental marking is stopped, and the heap is small. Then do | 154 // disposed, incremental marking is stopped, and the heap is small. Then do |
| 178 // a full GC. | 155 // a full GC. |
| 179 // (2) If the new space is almost full and we can affort a Scavenge or if the | 156 // (2) If the new space is almost full and we can affort a Scavenge or if the |
| 180 // next Scavenge will very likely take long, then a Scavenge is performed. | 157 // next Scavenge will very likely take long, then a Scavenge is performed. |
| 181 // (3) If there is currently no MarkCompact idle round going on, we start a | 158 // (3) If there is currently no MarkCompact idle round going on, we start a |
| 182 // new idle round if enough garbage was created. Otherwise we do not perform | 159 // new idle round if enough garbage was created. Otherwise we do not perform |
| 183 // garbage collection to keep system utilization low. | 160 // garbage collection to keep system utilization low. |
| 184 // (4) If incremental marking is done, we perform a full garbage collection | 161 // (4) If incremental marking is done, we perform a full garbage collection |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 if (heap_state.incremental_marking_stopped && | 224 if (heap_state.incremental_marking_stopped && |
| 248 !heap_state.can_start_incremental_marking) { | 225 !heap_state.can_start_incremental_marking) { |
| 249 return GCIdleTimeAction::Nothing(); | 226 return GCIdleTimeAction::Nothing(); |
| 250 } | 227 } |
| 251 size_t step_size = EstimateMarkingStepSize( | 228 size_t step_size = EstimateMarkingStepSize( |
| 252 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); | 229 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); |
| 253 return GCIdleTimeAction::IncrementalMarking(step_size); | 230 return GCIdleTimeAction::IncrementalMarking(step_size); |
| 254 } | 231 } |
| 255 } | 232 } |
| 256 } | 233 } |
| OLD | NEW |