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 #ifndef V8_HEAP_GC_IDLE_TIME_HANDLER_H_ | 5 #ifndef V8_HEAP_GC_IDLE_TIME_HANDLER_H_ |
6 #define V8_HEAP_GC_IDLE_TIME_HANDLER_H_ | 6 #define V8_HEAP_GC_IDLE_TIME_HANDLER_H_ |
7 | 7 |
8 #include "src/globals.h" | 8 #include "src/globals.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 enum GCIdleTimeActionType { | 13 enum GCIdleTimeActionType { |
14 DONE, | 14 DONE, |
15 DO_NOTHING, | 15 DO_NOTHING, |
16 DO_INCREMENTAL_STEP, | 16 DO_INCREMENTAL_STEP, |
17 DO_SCAVENGE, | |
18 DO_FULL_GC, | 17 DO_FULL_GC, |
19 }; | 18 }; |
20 | 19 |
21 | 20 |
22 class GCIdleTimeAction { | 21 class GCIdleTimeAction { |
23 public: | 22 public: |
24 static GCIdleTimeAction Done() { | 23 static GCIdleTimeAction Done() { |
25 GCIdleTimeAction result; | 24 GCIdleTimeAction result; |
26 result.type = DONE; | 25 result.type = DONE; |
27 result.additional_work = false; | 26 result.additional_work = false; |
28 return result; | 27 return result; |
29 } | 28 } |
30 | 29 |
31 static GCIdleTimeAction Nothing() { | 30 static GCIdleTimeAction Nothing() { |
32 GCIdleTimeAction result; | 31 GCIdleTimeAction result; |
33 result.type = DO_NOTHING; | 32 result.type = DO_NOTHING; |
34 result.additional_work = false; | 33 result.additional_work = false; |
35 return result; | 34 return result; |
36 } | 35 } |
37 | 36 |
38 static GCIdleTimeAction IncrementalStep() { | 37 static GCIdleTimeAction IncrementalStep() { |
39 GCIdleTimeAction result; | 38 GCIdleTimeAction result; |
40 result.type = DO_INCREMENTAL_STEP; | 39 result.type = DO_INCREMENTAL_STEP; |
41 result.additional_work = false; | 40 result.additional_work = false; |
42 return result; | 41 return result; |
43 } | 42 } |
44 | 43 |
45 static GCIdleTimeAction Scavenge() { | |
46 GCIdleTimeAction result; | |
47 result.type = DO_SCAVENGE; | |
48 result.additional_work = false; | |
49 return result; | |
50 } | |
51 | |
52 static GCIdleTimeAction FullGC() { | 44 static GCIdleTimeAction FullGC() { |
53 GCIdleTimeAction result; | 45 GCIdleTimeAction result; |
54 result.type = DO_FULL_GC; | 46 result.type = DO_FULL_GC; |
55 result.additional_work = false; | 47 result.additional_work = false; |
56 return result; | 48 return result; |
57 } | 49 } |
58 | 50 |
59 void Print(); | 51 void Print(); |
60 | 52 |
61 GCIdleTimeActionType type; | 53 GCIdleTimeActionType type; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 90 |
99 // This is the maximum scheduled idle time. Note that it can be more than | 91 // This is the maximum scheduled idle time. Note that it can be more than |
100 // 16.66 ms when there is currently no rendering going on. | 92 // 16.66 ms when there is currently no rendering going on. |
101 static const size_t kMaxScheduledIdleTime = 50; | 93 static const size_t kMaxScheduledIdleTime = 50; |
102 | 94 |
103 // The maximum idle time when frames are rendered is 16.66ms. | 95 // The maximum idle time when frames are rendered is 16.66ms. |
104 static const size_t kMaxFrameRenderingIdleTime = 17; | 96 static const size_t kMaxFrameRenderingIdleTime = 17; |
105 | 97 |
106 static const int kMinBackgroundIdleTime = 900; | 98 static const int kMinBackgroundIdleTime = 900; |
107 | 99 |
108 // We conservatively assume that in the next kTimeUntilNextIdleEvent ms | |
109 // no idle notification happens. | |
110 static const size_t kTimeUntilNextIdleEvent = 100; | |
111 | |
112 // An allocation throughput below kLowAllocationThroughput bytes/ms is | 100 // An allocation throughput below kLowAllocationThroughput bytes/ms is |
113 // considered low | 101 // considered low |
114 static const size_t kLowAllocationThroughput = 1000; | 102 static const size_t kLowAllocationThroughput = 1000; |
115 | 103 |
116 // If we haven't recorded any scavenger events yet, we use a conservative | |
117 // lower bound for the scavenger speed. | |
118 static const size_t kInitialConservativeScavengeSpeed = 100 * KB; | |
119 | |
120 // The minimum size of allocated new space objects to trigger a scavenge. | |
121 static const size_t kMinimumNewSpaceSizeToPerformScavenge = MB / 2; | |
122 | |
123 // If contexts are disposed at a higher rate a full gc is triggered. | 104 // If contexts are disposed at a higher rate a full gc is triggered. |
124 static const double kHighContextDisposalRate; | 105 static const double kHighContextDisposalRate; |
125 | 106 |
126 // Incremental marking step time. | 107 // Incremental marking step time. |
127 static const size_t kIncrementalMarkingStepTimeInMs = 1; | 108 static const size_t kIncrementalMarkingStepTimeInMs = 1; |
128 | 109 |
129 static const size_t kMinTimeForOverApproximatingWeakClosureInMs; | 110 static const size_t kMinTimeForOverApproximatingWeakClosureInMs; |
130 | 111 |
131 // Number of times we will return a Nothing action in the current mode | 112 // Number of times we will return a Nothing action in the current mode |
132 // despite having idle time available before we returning a Done action to | 113 // despite having idle time available before we returning a Done action to |
133 // ensure we don't keep scheduling idle tasks and making no progress. | 114 // ensure we don't keep scheduling idle tasks and making no progress. |
134 static const int kMaxNoProgressIdleTimes = 10; | 115 static const int kMaxNoProgressIdleTimes = 10; |
135 | 116 |
136 class HeapState { | 117 class HeapState { |
137 public: | 118 public: |
138 void Print(); | 119 void Print(); |
139 | 120 |
140 int contexts_disposed; | 121 int contexts_disposed; |
141 double contexts_disposal_rate; | 122 double contexts_disposal_rate; |
142 size_t size_of_objects; | 123 size_t size_of_objects; |
143 bool incremental_marking_stopped; | 124 bool incremental_marking_stopped; |
144 bool sweeping_in_progress; | 125 bool sweeping_in_progress; |
145 bool sweeping_completed; | 126 bool sweeping_completed; |
146 bool has_low_allocation_rate; | 127 bool has_low_allocation_rate; |
147 size_t mark_compact_speed_in_bytes_per_ms; | 128 size_t mark_compact_speed_in_bytes_per_ms; |
148 size_t incremental_marking_speed_in_bytes_per_ms; | 129 size_t incremental_marking_speed_in_bytes_per_ms; |
149 size_t final_incremental_mark_compact_speed_in_bytes_per_ms; | 130 size_t final_incremental_mark_compact_speed_in_bytes_per_ms; |
150 size_t scavenge_speed_in_bytes_per_ms; | |
151 size_t used_new_space_size; | |
152 size_t new_space_capacity; | |
153 size_t new_space_allocation_throughput_in_bytes_per_ms; | |
154 }; | 131 }; |
155 | 132 |
156 GCIdleTimeHandler() : idle_times_which_made_no_progress_(0) {} | 133 GCIdleTimeHandler() : idle_times_which_made_no_progress_(0) {} |
157 | 134 |
158 GCIdleTimeAction Compute(double idle_time_in_ms, HeapState heap_state); | 135 GCIdleTimeAction Compute(double idle_time_in_ms, HeapState heap_state); |
159 | 136 |
160 void ResetNoProgressCounter() { idle_times_which_made_no_progress_ = 0; } | 137 void ResetNoProgressCounter() { idle_times_which_made_no_progress_ = 0; } |
161 | 138 |
162 static size_t EstimateMarkingStepSize(size_t idle_time_in_ms, | 139 static size_t EstimateMarkingStepSize(size_t idle_time_in_ms, |
163 size_t marking_speed_in_bytes_per_ms); | 140 size_t marking_speed_in_bytes_per_ms); |
(...skipping 10 matching lines...) Expand all Loading... |
174 | 151 |
175 static bool ShouldDoContextDisposalMarkCompact(int context_disposed, | 152 static bool ShouldDoContextDisposalMarkCompact(int context_disposed, |
176 double contexts_disposal_rate); | 153 double contexts_disposal_rate); |
177 | 154 |
178 static bool ShouldDoFinalIncrementalMarkCompact( | 155 static bool ShouldDoFinalIncrementalMarkCompact( |
179 size_t idle_time_in_ms, size_t size_of_objects, | 156 size_t idle_time_in_ms, size_t size_of_objects, |
180 size_t final_incremental_mark_compact_speed_in_bytes_per_ms); | 157 size_t final_incremental_mark_compact_speed_in_bytes_per_ms); |
181 | 158 |
182 static bool ShouldDoOverApproximateWeakClosure(size_t idle_time_in_ms); | 159 static bool ShouldDoOverApproximateWeakClosure(size_t idle_time_in_ms); |
183 | 160 |
184 static bool ShouldDoScavenge( | |
185 size_t idle_time_in_ms, size_t new_space_size, size_t used_new_space_size, | |
186 size_t scavenger_speed_in_bytes_per_ms, | |
187 size_t new_space_allocation_throughput_in_bytes_per_ms); | |
188 | |
189 private: | 161 private: |
190 GCIdleTimeAction NothingOrDone(double idle_time_in_ms); | 162 GCIdleTimeAction NothingOrDone(double idle_time_in_ms); |
191 | 163 |
192 // Idle notifications with no progress. | 164 // Idle notifications with no progress. |
193 int idle_times_which_made_no_progress_; | 165 int idle_times_which_made_no_progress_; |
194 | 166 |
195 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler); | 167 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler); |
196 }; | 168 }; |
197 | 169 |
198 } // namespace internal | 170 } // namespace internal |
199 } // namespace v8 | 171 } // namespace v8 |
200 | 172 |
201 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ | 173 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ |
OLD | NEW |