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