| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 if (marking_step_size > kMaximumMarkingStepSize) | 57 if (marking_step_size > kMaximumMarkingStepSize) |
| 58 return kMaximumMarkingStepSize; | 58 return kMaximumMarkingStepSize; |
| 59 | 59 |
| 60 return static_cast<size_t>(marking_step_size * kConservativeTimeRatio); | 60 return static_cast<size_t>(marking_step_size * kConservativeTimeRatio); |
| 61 } | 61 } |
| 62 | 62 |
| 63 | 63 |
| 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 // TODO(hpayer): Be more precise about the type of mark-compact event. It |
| 67 // makes a huge difference if it is incremental or non-incremental and if |
| 68 // compaction is happening. |
| 66 if (mark_compact_speed_in_bytes_per_ms == 0) { | 69 if (mark_compact_speed_in_bytes_per_ms == 0) { |
| 67 mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed; | 70 mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed; |
| 68 } | 71 } |
| 69 size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms; | 72 size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms; |
| 70 return Min(result, kMaxMarkCompactTimeInMs); | 73 return Min(result, kMaxMarkCompactTimeInMs); |
| 71 } | 74 } |
| 72 | 75 |
| 73 | 76 |
| 74 bool GCIdleTimeHandler::DoScavenge( | 77 bool GCIdleTimeHandler::DoScavenge( |
| 75 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, | 78 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 103 if (new_space_allocation_limit <= used_new_space_size) { | 106 if (new_space_allocation_limit <= used_new_space_size) { |
| 104 if (used_new_space_size / scavenge_speed_in_bytes_per_ms <= | 107 if (used_new_space_size / scavenge_speed_in_bytes_per_ms <= |
| 105 idle_time_in_ms) { | 108 idle_time_in_ms) { |
| 106 return true; | 109 return true; |
| 107 } | 110 } |
| 108 } | 111 } |
| 109 return false; | 112 return false; |
| 110 } | 113 } |
| 111 | 114 |
| 112 | 115 |
| 116 bool GCIdleTimeHandler::DoMarkCompact( |
| 117 size_t idle_time_in_ms, size_t size_of_objects, |
| 118 size_t mark_compact_speed_in_bytes_per_ms) { |
| 119 return idle_time_in_ms >= |
| 120 EstimateMarkCompactTime(size_of_objects, |
| 121 mark_compact_speed_in_bytes_per_ms); |
| 122 } |
| 123 |
| 124 |
| 113 // The following logic is implemented by the controller: | 125 // The following logic is implemented by the controller: |
| 114 // (1) If the new space is almost full and we can affort a Scavenge or if the | 126 // (1) If the new space is almost full and we can affort a Scavenge or if the |
| 115 // next Scavenge will very likely take long, then a Scavenge is performed. | 127 // next Scavenge will very likely take long, then a Scavenge is performed. |
| 116 // (2) If there is currently no MarkCompact idle round going on, we start a | 128 // (2) If there is currently no MarkCompact idle round going on, we start a |
| 117 // new idle round if enough garbage was created or we received a context | 129 // new idle round if enough garbage was created or we received a context |
| 118 // disposal event. Otherwise we do not perform garbage collection to keep | 130 // disposal event. Otherwise we do not perform garbage collection to keep |
| 119 // system utilization low. | 131 // system utilization low. |
| 120 // (3) If incremental marking is done, we perform a full garbage collection | 132 // (3) If incremental marking is done, we perform a full garbage collection |
| 121 // if context was disposed or if we are allowed to still do full garbage | 133 // if context was disposed or if we are allowed to still do full garbage |
| 122 // collections during this idle round or if we are not allowed to start | 134 // collections during this idle round or if we are not allowed to start |
| (...skipping 18 matching lines...) Expand all Loading... |
| 141 } else { | 153 } else { |
| 142 return GCIdleTimeAction::Done(); | 154 return GCIdleTimeAction::Done(); |
| 143 } | 155 } |
| 144 } | 156 } |
| 145 | 157 |
| 146 if (idle_time_in_ms == 0) { | 158 if (idle_time_in_ms == 0) { |
| 147 return GCIdleTimeAction::Nothing(); | 159 return GCIdleTimeAction::Nothing(); |
| 148 } | 160 } |
| 149 | 161 |
| 150 if (heap_state.incremental_marking_stopped) { | 162 if (heap_state.incremental_marking_stopped) { |
| 151 size_t estimated_time_in_ms = | 163 if (DoMarkCompact(idle_time_in_ms, heap_state.size_of_objects, |
| 152 EstimateMarkCompactTime(heap_state.size_of_objects, | 164 heap_state.mark_compact_speed_in_bytes_per_ms) || |
| 153 heap_state.mark_compact_speed_in_bytes_per_ms); | |
| 154 if (idle_time_in_ms >= estimated_time_in_ms || | |
| 155 (heap_state.size_of_objects < kSmallHeapSize && | 165 (heap_state.size_of_objects < kSmallHeapSize && |
| 156 heap_state.contexts_disposed > 0)) { | 166 heap_state.contexts_disposed > 0)) { |
| 157 // If there are no more than two GCs left in this idle round and we are | 167 // If there are no more than two GCs left in this idle round and we are |
| 158 // allowed to do a full GC, then make those GCs full in order to compact | 168 // allowed to do a full GC, then make those GCs full in order to compact |
| 159 // the code space. | 169 // the code space. |
| 160 // TODO(ulan): Once we enable code compaction for incremental marking, we | 170 // TODO(ulan): Once we enable code compaction for incremental marking, we |
| 161 // can get rid of this special case and always start incremental marking. | 171 // can get rid of this special case and always start incremental marking. |
| 162 int remaining_mark_sweeps = | 172 int remaining_mark_sweeps = |
| 163 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; | 173 kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; |
| 164 if (heap_state.contexts_disposed > 0 || | 174 if (heap_state.contexts_disposed > 0 || |
| (...skipping 16 matching lines...) Expand all Loading... |
| 181 if (heap_state.incremental_marking_stopped && | 191 if (heap_state.incremental_marking_stopped && |
| 182 !heap_state.can_start_incremental_marking) { | 192 !heap_state.can_start_incremental_marking) { |
| 183 return GCIdleTimeAction::Nothing(); | 193 return GCIdleTimeAction::Nothing(); |
| 184 } | 194 } |
| 185 size_t step_size = EstimateMarkingStepSize( | 195 size_t step_size = EstimateMarkingStepSize( |
| 186 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); | 196 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); |
| 187 return GCIdleTimeAction::IncrementalMarking(step_size); | 197 return GCIdleTimeAction::IncrementalMarking(step_size); |
| 188 } | 198 } |
| 189 } | 199 } |
| 190 } | 200 } |
| OLD | NEW |