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 28 matching lines...) Expand all Loading... | |
135 | 148 |
136 bool GCIdleTimeHandler::ShouldDoMarkCompact( | 149 bool GCIdleTimeHandler::ShouldDoMarkCompact( |
137 size_t idle_time_in_ms, size_t size_of_objects, | 150 size_t idle_time_in_ms, size_t size_of_objects, |
138 size_t mark_compact_speed_in_bytes_per_ms) { | 151 size_t mark_compact_speed_in_bytes_per_ms) { |
139 return idle_time_in_ms >= | 152 return idle_time_in_ms >= |
140 EstimateMarkCompactTime(size_of_objects, | 153 EstimateMarkCompactTime(size_of_objects, |
141 mark_compact_speed_in_bytes_per_ms); | 154 mark_compact_speed_in_bytes_per_ms); |
142 } | 155 } |
143 | 156 |
144 | 157 |
158 bool GCIdleTimeHandler::ShouldDoFinalIncrementalMarkCompact( | |
159 size_t idle_time_in_ms, size_t size_of_objects, | |
160 size_t final_incremental_mark_compact_speed_in_bytes_per_ms) { | |
161 return idle_time_in_ms >= | |
162 EstimateMarkCompactTime( | |
ulan
2014/11/24 16:02:28
EstimateFinalIncrementalMarkCompactTime?
Hannes Payer (out of office)
2014/11/24 19:05:09
Done.
| |
163 size_of_objects, | |
164 final_incremental_mark_compact_speed_in_bytes_per_ms); | |
165 } | |
166 | |
167 | |
145 // The following logic is implemented by the controller: | 168 // The following logic is implemented by the controller: |
146 // (1) If we don't have any idle time, do nothing, unless a context was | 169 // (1) If we don't have any idle time, do nothing, unless a context was |
147 // disposed, incremental marking is stopped, and the heap is small. Then do | 170 // disposed, incremental marking is stopped, and the heap is small. Then do |
148 // a full GC. | 171 // a full GC. |
149 // (2) If the new space is almost full and we can affort a Scavenge or if the | 172 // (2) If the new space is almost full and we can affort a Scavenge or if the |
150 // next Scavenge will very likely take long, then a Scavenge is performed. | 173 // next Scavenge will very likely take long, then a Scavenge is performed. |
151 // (3) If there is currently no MarkCompact idle round going on, we start a | 174 // (3) If there is currently no MarkCompact idle round going on, we start a |
152 // new idle round if enough garbage was created. Otherwise we do not perform | 175 // new idle round if enough garbage was created. Otherwise we do not perform |
153 // garbage collection to keep system utilization low. | 176 // garbage collection to keep system utilization low. |
154 // (4) If incremental marking is done, we perform a full garbage collection | 177 // (4) If incremental marking is done, we perform a full garbage collection |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 if (heap_state.incremental_marking_stopped && | 239 if (heap_state.incremental_marking_stopped && |
217 !heap_state.can_start_incremental_marking) { | 240 !heap_state.can_start_incremental_marking) { |
218 return GCIdleTimeAction::Nothing(); | 241 return GCIdleTimeAction::Nothing(); |
219 } | 242 } |
220 size_t step_size = EstimateMarkingStepSize( | 243 size_t step_size = EstimateMarkingStepSize( |
221 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); | 244 idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms); |
222 return GCIdleTimeAction::IncrementalMarking(step_size); | 245 return GCIdleTimeAction::IncrementalMarking(step_size); |
223 } | 246 } |
224 } | 247 } |
225 } | 248 } |
OLD | NEW |