| 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 { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 size_t GCIdleTimeHandler::EstimateMarkCompactTime( | 64 size_t GCIdleTimeHandler::EstimateMarkCompactTime( |
| 65 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms) { | 65 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms) { |
| 66 if (mark_compact_speed_in_bytes_per_ms == 0) { | 66 if (mark_compact_speed_in_bytes_per_ms == 0) { |
| 67 mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed; | 67 mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed; |
| 68 } | 68 } |
| 69 size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms; | 69 size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms; |
| 70 return Min(result, kMaxMarkCompactTimeInMs); | 70 return Min(result, kMaxMarkCompactTimeInMs); |
| 71 } | 71 } |
| 72 | 72 |
| 73 | 73 |
| 74 size_t GCIdleTimeHandler::EstimateScavengeTime( | 74 bool GCIdleTimeHandler::DoScavenge( |
| 75 size_t new_space_size, size_t scavenge_speed_in_bytes_per_ms) { | 75 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, |
| 76 size_t scavenge_speed_in_bytes_per_ms, |
| 77 size_t new_space_allocation_throughput_in_bytes_per_ms) { |
| 78 size_t new_space_allocation_limit = |
| 79 kMaxFrameRenderingIdleTime * scavenge_speed_in_bytes_per_ms; |
| 80 |
| 81 // If the limit is larger than the new space size, then scavenging used to be |
| 82 // really fast. We can take advantage of the whole new space. |
| 83 if (new_space_allocation_limit > new_space_size) { |
| 84 new_space_allocation_limit = new_space_size; |
| 85 } |
| 86 |
| 87 // We do not know the allocation throughput before the first Scavenge. |
| 88 // TODO(hpayer): Estimate allocation throughput before the first Scavenge. |
| 89 if (new_space_allocation_throughput_in_bytes_per_ms == 0) { |
| 90 new_space_allocation_limit = new_space_size * kConservativeTimeRatio; |
| 91 } else { |
| 92 // We have to trigger scavenge before we reach the end of new space. |
| 93 new_space_allocation_limit -= |
| 94 new_space_allocation_throughput_in_bytes_per_ms * |
| 95 kMaxFrameRenderingIdleTime; |
| 96 } |
| 97 |
| 76 if (scavenge_speed_in_bytes_per_ms == 0) { | 98 if (scavenge_speed_in_bytes_per_ms == 0) { |
| 77 scavenge_speed_in_bytes_per_ms = kInitialConservativeScavengeSpeed; | 99 scavenge_speed_in_bytes_per_ms = kInitialConservativeScavengeSpeed; |
| 78 } | 100 } |
| 79 return new_space_size / scavenge_speed_in_bytes_per_ms; | |
| 80 } | |
| 81 | 101 |
| 82 | 102 if (new_space_allocation_limit <= used_new_space_size) { |
| 83 bool GCIdleTimeHandler::ScavangeMayHappenSoon( | 103 if (used_new_space_size / scavenge_speed_in_bytes_per_ms <= |
| 84 size_t available_new_space_memory, | 104 idle_time_in_ms) { |
| 85 size_t new_space_allocation_throughput_in_bytes_per_ms) { | 105 return true; |
| 86 if (available_new_space_memory <= | 106 } |
| 87 new_space_allocation_throughput_in_bytes_per_ms * | |
| 88 kMaxFrameRenderingIdleTime) { | |
| 89 return true; | |
| 90 } | 107 } |
| 91 return false; | 108 return false; |
| 92 } | 109 } |
| 93 | 110 |
| 94 | 111 |
| 95 // The following logic is implemented by the controller: | 112 // The following logic is implemented by the controller: |
| 96 // (1) If the new space is almost full and we can effort a Scavenge, then a | 113 // (1) If the new space is almost full and we can effort a Scavenge or if the |
| 97 // Scavenge is performed. | 114 // next Scavenge will very likely take long, then a Scavenge is performed. |
| 98 // (2) If there is currently no MarkCompact idle round going on, we start a | 115 // (2) If there is currently no MarkCompact idle round going on, we start a |
| 99 // new idle round if enough garbage was created or we received a context | 116 // new idle round if enough garbage was created or we received a context |
| 100 // disposal event. Otherwise we do not perform garbage collection to keep | 117 // disposal event. Otherwise we do not perform garbage collection to keep |
| 101 // system utilization low. | 118 // system utilization low. |
| 102 // (3) If incremental marking is done, we perform a full garbage collection | 119 // (3) If incremental marking is done, we perform a full garbage collection |
| 103 // if context was disposed or if we are allowed to still do full garbage | 120 // if context was disposed or if we are allowed to still do full garbage |
| 104 // collections during this idle round or if we are not allowed to start | 121 // collections during this idle round or if we are not allowed to start |
| 105 // incremental marking. Otherwise we do not perform garbage collection to | 122 // incremental marking. Otherwise we do not perform garbage collection to |
| 106 // keep system utilization low. | 123 // keep system utilization low. |
| 107 // (4) If sweeping is in progress and we received a large enough idle time | 124 // (4) If sweeping is in progress and we received a large enough idle time |
| 108 // request, we finalize sweeping here. | 125 // request, we finalize sweeping here. |
| 109 // (5) If incremental marking is in progress, we perform a marking step. Note, | 126 // (5) If incremental marking is in progress, we perform a marking step. Note, |
| 110 // that this currently may trigger a full garbage collection. | 127 // that this currently may trigger a full garbage collection. |
| 111 GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms, | 128 GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms, |
| 112 HeapState heap_state) { | 129 HeapState heap_state) { |
| 113 if (ScavangeMayHappenSoon( | 130 if (DoScavenge(idle_time_in_ms, heap_state.new_space_capacity, |
| 114 heap_state.available_new_space_memory, | 131 heap_state.used_new_space_size, |
| 115 heap_state.new_space_allocation_throughput_in_bytes_per_ms) && | 132 heap_state.scavenge_speed_in_bytes_per_ms, |
| 116 idle_time_in_ms >= | 133 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) { |
| 117 EstimateScavengeTime(heap_state.new_space_capacity, | |
| 118 heap_state.scavenge_speed_in_bytes_per_ms)) { | |
| 119 return GCIdleTimeAction::Scavenge(); | 134 return GCIdleTimeAction::Scavenge(); |
| 120 } | 135 } |
| 136 |
| 121 if (IsMarkCompactIdleRoundFinished()) { | 137 if (IsMarkCompactIdleRoundFinished()) { |
| 122 if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) { | 138 if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) { |
| 123 StartIdleRound(); | 139 StartIdleRound(); |
| 124 } else { | 140 } else { |
| 125 return GCIdleTimeAction::Done(); | 141 return GCIdleTimeAction::Done(); |
| 126 } | 142 } |
| 127 } | 143 } |
| 128 | 144 |
| 129 if (idle_time_in_ms == 0) { | 145 if (idle_time_in_ms == 0) { |
| 130 return GCIdleTimeAction::Nothing(); | 146 return GCIdleTimeAction::Nothing(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 if (heap_state.incremental_marking_stopped && | 180 if (heap_state.incremental_marking_stopped && |
| 165 !heap_state.can_start_incremental_marking) { | 181 !heap_state.can_start_incremental_marking) { |
| 166 return GCIdleTimeAction::Nothing(); | 182 return GCIdleTimeAction::Nothing(); |
| 167 } | 183 } |
| 168 size_t step_size = EstimateMarkingStepSize( | 184 size_t step_size = EstimateMarkingStepSize( |
| 169 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); | 185 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); |
| 170 return GCIdleTimeAction::IncrementalMarking(step_size); | 186 return GCIdleTimeAction::IncrementalMarking(step_size); |
| 171 } | 187 } |
| 172 } | 188 } |
| 173 } | 189 } |
| OLD | NEW |