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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 bool GCIdleTimeHandler::ShouldDoMarkCompact( | 116 bool GCIdleTimeHandler::ShouldDoMarkCompact( |
117 size_t idle_time_in_ms, size_t size_of_objects, | 117 size_t idle_time_in_ms, size_t size_of_objects, |
118 size_t mark_compact_speed_in_bytes_per_ms) { | 118 size_t mark_compact_speed_in_bytes_per_ms) { |
119 return idle_time_in_ms >= | 119 return idle_time_in_ms >= |
120 EstimateMarkCompactTime(size_of_objects, | 120 EstimateMarkCompactTime(size_of_objects, |
121 mark_compact_speed_in_bytes_per_ms); | 121 mark_compact_speed_in_bytes_per_ms); |
122 } | 122 } |
123 | 123 |
124 | 124 |
125 // The following logic is implemented by the controller: | 125 // The following logic is implemented by the controller: |
126 // (1) If the new space is almost full and we can affort a Scavenge or if the | 126 // (1) If we don't have any idle time, do nothing, unless a context was |
| 127 // disposed, incremental marking is stopped, and the heap is small. Then do |
| 128 // a full GC. |
| 129 // (2) If the new space is almost full and we can affort a Scavenge or if the |
127 // next Scavenge will very likely take long, then a Scavenge is performed. | 130 // next Scavenge will very likely take long, then a Scavenge is performed. |
128 // (2) If there is currently no MarkCompact idle round going on, we start a | 131 // (3) If there is currently no MarkCompact idle round going on, we start a |
129 // new idle round if enough garbage was created or we received a context | 132 // new idle round if enough garbage was created or we received a context |
130 // disposal event. Otherwise we do not perform garbage collection to keep | 133 // disposal event. Otherwise we do not perform garbage collection to keep |
131 // system utilization low. | 134 // system utilization low. |
132 // (3) If incremental marking is done, we perform a full garbage collection | 135 // (4) If incremental marking is done, we perform a full garbage collection |
133 // if context was disposed or if we are allowed to still do full garbage | 136 // if context was disposed or if we are allowed to still do full garbage |
134 // collections during this idle round or if we are not allowed to start | 137 // collections during this idle round or if we are not allowed to start |
135 // incremental marking. Otherwise we do not perform garbage collection to | 138 // incremental marking. Otherwise we do not perform garbage collection to |
136 // keep system utilization low. | 139 // keep system utilization low. |
137 // (4) If sweeping is in progress and we received a large enough idle time | 140 // (5) If sweeping is in progress and we received a large enough idle time |
138 // request, we finalize sweeping here. | 141 // request, we finalize sweeping here. |
139 // (5) If incremental marking is in progress, we perform a marking step. Note, | 142 // (6) If incremental marking is in progress, we perform a marking step. Note, |
140 // that this currently may trigger a full garbage collection. | 143 // that this currently may trigger a full garbage collection. |
141 GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms, | 144 GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms, |
142 HeapState heap_state) { | 145 HeapState heap_state) { |
| 146 if (idle_time_in_ms == 0) { |
| 147 if (heap_state.incremental_marking_stopped) { |
| 148 if (heap_state.size_of_objects < kSmallHeapSize && |
| 149 heap_state.contexts_disposed > 0) { |
| 150 return GCIdleTimeAction::FullGC(); |
| 151 } |
| 152 } |
| 153 return GCIdleTimeAction::Nothing(); |
| 154 } |
| 155 |
143 if (ShouldDoScavenge( | 156 if (ShouldDoScavenge( |
144 idle_time_in_ms, heap_state.new_space_capacity, | 157 idle_time_in_ms, heap_state.new_space_capacity, |
145 heap_state.used_new_space_size, | 158 heap_state.used_new_space_size, |
146 heap_state.scavenge_speed_in_bytes_per_ms, | 159 heap_state.scavenge_speed_in_bytes_per_ms, |
147 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) { | 160 heap_state.new_space_allocation_throughput_in_bytes_per_ms)) { |
148 return GCIdleTimeAction::Scavenge(); | 161 return GCIdleTimeAction::Scavenge(); |
149 } | 162 } |
150 | 163 |
151 if (IsMarkCompactIdleRoundFinished()) { | 164 if (IsMarkCompactIdleRoundFinished()) { |
152 if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) { | 165 if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) { |
153 StartIdleRound(); | 166 StartIdleRound(); |
154 } else { | 167 } else { |
155 return GCIdleTimeAction::Done(); | 168 return GCIdleTimeAction::Done(); |
156 } | 169 } |
157 } | 170 } |
158 | 171 |
159 if (idle_time_in_ms == 0) { | |
160 return GCIdleTimeAction::Nothing(); | |
161 } | |
162 | |
163 if (heap_state.incremental_marking_stopped) { | 172 if (heap_state.incremental_marking_stopped) { |
| 173 // TODO(jochen): Remove context disposal dependant logic. |
164 if (ShouldDoMarkCompact(idle_time_in_ms, heap_state.size_of_objects, | 174 if (ShouldDoMarkCompact(idle_time_in_ms, heap_state.size_of_objects, |
165 heap_state.mark_compact_speed_in_bytes_per_ms) || | 175 heap_state.mark_compact_speed_in_bytes_per_ms) || |
166 (heap_state.size_of_objects < kSmallHeapSize && | 176 (heap_state.size_of_objects < kSmallHeapSize && |
167 heap_state.contexts_disposed > 0)) { | 177 heap_state.contexts_disposed > 0)) { |
168 // If there are no more than two GCs left in this idle round and we are | 178 // If there are no more than two GCs left in this idle round and we are |
169 // allowed to do a full GC, then make those GCs full in order to compact | 179 // allowed to do a full GC, then make those GCs full in order to compact |
170 // the code space. | 180 // the code space. |
171 // TODO(ulan): Once we enable code compaction for incremental marking, we | 181 // TODO(ulan): Once we enable code compaction for incremental marking, we |
172 // can get rid of this special case and always start incremental marking. | 182 // can get rid of this special case and always start incremental marking. |
173 int remaining_mark_sweeps = | 183 int remaining_mark_sweeps = |
(...skipping 18 matching lines...) Expand all Loading... |
192 if (heap_state.incremental_marking_stopped && | 202 if (heap_state.incremental_marking_stopped && |
193 !heap_state.can_start_incremental_marking) { | 203 !heap_state.can_start_incremental_marking) { |
194 return GCIdleTimeAction::Nothing(); | 204 return GCIdleTimeAction::Nothing(); |
195 } | 205 } |
196 size_t step_size = EstimateMarkingStepSize( | 206 size_t step_size = EstimateMarkingStepSize( |
197 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); | 207 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); |
198 return GCIdleTimeAction::IncrementalMarking(step_size); | 208 return GCIdleTimeAction::IncrementalMarking(step_size); |
199 } | 209 } |
200 } | 210 } |
201 } | 211 } |
OLD | NEW |