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