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 DO_NOTHING, | 14 DO_NOTHING, |
15 DO_INCREMENTAL_MARKING, | 15 DO_INCREMENTAL_MARKING, |
16 DO_SCAVENGE, | 16 DO_SCAVENGE, |
17 DO_FULL_GC, | 17 DO_FULL_GC |
18 DO_FINALIZE_SWEEPING | |
19 }; | 18 }; |
20 | 19 |
21 | 20 |
22 class GCIdleTimeAction { | 21 class GCIdleTimeAction { |
23 public: | 22 public: |
24 static GCIdleTimeAction Nothing() { | 23 static GCIdleTimeAction Nothing() { |
25 GCIdleTimeAction result; | 24 GCIdleTimeAction result; |
26 result.type = DO_NOTHING; | 25 result.type = DO_NOTHING; |
27 result.parameter = 0; | 26 result.parameter = 0; |
28 return result; | 27 return result; |
29 } | 28 } |
30 | |
31 static GCIdleTimeAction IncrementalMarking(intptr_t step_size) { | 29 static GCIdleTimeAction IncrementalMarking(intptr_t step_size) { |
32 GCIdleTimeAction result; | 30 GCIdleTimeAction result; |
33 result.type = DO_INCREMENTAL_MARKING; | 31 result.type = DO_INCREMENTAL_MARKING; |
34 result.parameter = step_size; | 32 result.parameter = step_size; |
35 return result; | 33 return result; |
36 } | 34 } |
37 | |
38 static GCIdleTimeAction Scavenge() { | 35 static GCIdleTimeAction Scavenge() { |
39 GCIdleTimeAction result; | 36 GCIdleTimeAction result; |
40 result.type = DO_SCAVENGE; | 37 result.type = DO_SCAVENGE; |
41 result.parameter = 0; | 38 result.parameter = 0; |
42 return result; | 39 return result; |
43 } | 40 } |
44 | |
45 static GCIdleTimeAction FullGC() { | 41 static GCIdleTimeAction FullGC() { |
46 GCIdleTimeAction result; | 42 GCIdleTimeAction result; |
47 result.type = DO_FULL_GC; | 43 result.type = DO_FULL_GC; |
48 result.parameter = 0; | 44 result.parameter = 0; |
49 return result; | 45 return result; |
50 } | 46 } |
51 | 47 |
52 static GCIdleTimeAction FinalizeSweeping() { | |
53 GCIdleTimeAction result; | |
54 result.type = DO_FINALIZE_SWEEPING; | |
55 result.parameter = 0; | |
56 return result; | |
57 } | |
58 | |
59 GCIdleTimeActionType type; | 48 GCIdleTimeActionType type; |
60 intptr_t parameter; | 49 intptr_t parameter; |
61 }; | 50 }; |
62 | 51 |
63 | 52 |
64 class GCTracer; | 53 class GCTracer; |
65 | 54 |
66 // The idle time handler makes decisions about which garbage collection | 55 // The idle time handler makes decisions about which garbage collection |
67 // operations are executing during IdleNotification. | 56 // operations are executing during IdleNotification. |
68 class GCIdleTimeHandler { | 57 class GCIdleTimeHandler { |
69 public: | 58 public: |
70 // If we haven't recorded any incremental marking events yet, we carefully | 59 // If we haven't recorded any incremental marking events yet, we carefully |
71 // mark with a conservative lower bound for the marking speed. | 60 // mark with a conservative lower bound for the marking speed. |
72 static const size_t kInitialConservativeMarkingSpeed = 100 * KB; | 61 static const size_t kInitialConservativeMarkingSpeed = 100 * KB; |
73 | 62 |
74 // Maximum marking step size returned by EstimateMarkingStepSize. | 63 // Maximum marking step size returned by EstimateMarkingStepSize. |
75 static const size_t kMaximumMarkingStepSize = 700 * MB; | 64 static const size_t kMaximumMarkingStepSize = 700 * MB; |
76 | 65 |
77 // We have to make sure that we finish the IdleNotification before | 66 // We have to make sure that we finish the IdleNotification before |
78 // idle_time_in_ms. Hence, we conservatively prune our workload estimate. | 67 // idle_time_in_ms. Hence, we conservatively prune our workload estimate. |
79 static const double kConservativeTimeRatio; | 68 static const double kConservativeTimeRatio; |
80 | 69 |
81 // If we haven't recorded any mark-compact events yet, we use | 70 // If we haven't recorded any mark-compact events yet, we use |
82 // conservative lower bound for the mark-compact speed. | 71 // conservative lower bound for the mark-compact speed. |
83 static const size_t kInitialConservativeMarkCompactSpeed = 2 * MB; | 72 static const size_t kInitialConservativeMarkCompactSpeed = 2 * MB; |
84 | 73 |
85 // Maximum mark-compact time returned by EstimateMarkCompactTime. | 74 // Maximum mark-compact time returned by EstimateMarkCompactTime. |
86 static const size_t kMaxMarkCompactTimeInMs = 1000000; | 75 static const size_t kMaxMarkCompactTimeInMs; |
87 | |
88 // Minimum time to finalize sweeping phase. The main thread may wait for | |
89 // sweeper threads. | |
90 static const size_t kMinTimeForFinalizeSweeping = 100; | |
91 | 76 |
92 struct HeapState { | 77 struct HeapState { |
93 int contexts_disposed; | 78 int contexts_disposed; |
94 size_t size_of_objects; | 79 size_t size_of_objects; |
95 bool incremental_marking_stopped; | 80 bool incremental_marking_stopped; |
96 bool can_start_incremental_marking; | 81 bool can_start_incremental_marking; |
97 bool sweeping_in_progress; | |
98 }; | 82 }; |
99 | 83 |
100 GCIdleTimeHandler() | 84 GCIdleTimeHandler() |
101 : mark_compacts_since_idle_round_started_(0), | 85 : mark_compacts_since_idle_round_started_(0), |
102 scavenges_since_last_idle_round_(0) {} | 86 scavenges_since_last_idle_round_(0) {} |
103 | 87 |
104 GCIdleTimeAction Compute(size_t idle_time_in_ms, HeapState heap_state, | 88 GCIdleTimeAction Compute(int idle_time_in_ms, HeapState heap_state, |
105 GCTracer* gc_tracer); | 89 GCTracer* gc_tracer); |
106 | 90 |
107 void NotifyIdleMarkCompact() { | 91 void NotifyIdleMarkCompact() { |
108 if (mark_compacts_since_idle_round_started_ < kMaxMarkCompactsInIdleRound) { | 92 if (mark_compacts_since_idle_round_started_ < kMaxMarkCompactsInIdleRound) { |
109 ++mark_compacts_since_idle_round_started_; | 93 ++mark_compacts_since_idle_round_started_; |
110 if (mark_compacts_since_idle_round_started_ == | 94 if (mark_compacts_since_idle_round_started_ == |
111 kMaxMarkCompactsInIdleRound) { | 95 kMaxMarkCompactsInIdleRound) { |
112 scavenges_since_last_idle_round_ = 0; | 96 scavenges_since_last_idle_round_ = 0; |
113 } | 97 } |
114 } | 98 } |
(...skipping 22 matching lines...) Expand all Loading... |
137 int mark_compacts_since_idle_round_started_; | 121 int mark_compacts_since_idle_round_started_; |
138 int scavenges_since_last_idle_round_; | 122 int scavenges_since_last_idle_round_; |
139 | 123 |
140 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler); | 124 DISALLOW_COPY_AND_ASSIGN(GCIdleTimeHandler); |
141 }; | 125 }; |
142 | 126 |
143 } // namespace internal | 127 } // namespace internal |
144 } // namespace v8 | 128 } // namespace v8 |
145 | 129 |
146 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ | 130 #endif // V8_HEAP_GC_IDLE_TIME_HANDLER_H_ |
OLD | NEW |