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 | 6 |
7 #include "src/flags.h" | 7 #include "src/flags.h" |
8 #include "src/heap/gc-tracer.h" | 8 #include "src/heap/gc-tracer.h" |
9 #include "src/utils.h" | 9 #include "src/utils.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
14 const double GCIdleTimeHandler::kConservativeTimeRatio = 0.9; | 14 const double GCIdleTimeHandler::kConservativeTimeRatio = 0.9; |
15 const size_t GCIdleTimeHandler::kMaxMarkCompactTimeInMs = 1000; | |
16 const size_t GCIdleTimeHandler::kMaxFinalIncrementalMarkCompactTimeInMs = 1000; | 15 const size_t GCIdleTimeHandler::kMaxFinalIncrementalMarkCompactTimeInMs = 1000; |
17 const double GCIdleTimeHandler::kHighContextDisposalRate = 100; | 16 const double GCIdleTimeHandler::kHighContextDisposalRate = 100; |
18 const size_t GCIdleTimeHandler::kMinTimeForOverApproximatingWeakClosureInMs = 1; | 17 const size_t GCIdleTimeHandler::kMinTimeForOverApproximatingWeakClosureInMs = 1; |
19 | 18 |
20 | 19 |
21 void GCIdleTimeAction::Print() { | 20 void GCIdleTimeAction::Print() { |
22 switch (type) { | 21 switch (type) { |
23 case DONE: | 22 case DONE: |
24 PrintF("done"); | 23 PrintF("done"); |
25 break; | 24 break; |
(...skipping 14 matching lines...) Expand all Loading... |
40 | 39 |
41 | 40 |
42 void GCIdleTimeHeapState::Print() { | 41 void GCIdleTimeHeapState::Print() { |
43 PrintF("contexts_disposed=%d ", contexts_disposed); | 42 PrintF("contexts_disposed=%d ", contexts_disposed); |
44 PrintF("contexts_disposal_rate=%f ", contexts_disposal_rate); | 43 PrintF("contexts_disposal_rate=%f ", contexts_disposal_rate); |
45 PrintF("size_of_objects=%" V8_SIZET_PREFIX V8_PTR_PREFIX "d ", | 44 PrintF("size_of_objects=%" V8_SIZET_PREFIX V8_PTR_PREFIX "d ", |
46 size_of_objects); | 45 size_of_objects); |
47 PrintF("incremental_marking_stopped=%d ", incremental_marking_stopped); | 46 PrintF("incremental_marking_stopped=%d ", incremental_marking_stopped); |
48 } | 47 } |
49 | 48 |
50 | |
51 size_t GCIdleTimeHandler::EstimateMarkingStepSize( | 49 size_t GCIdleTimeHandler::EstimateMarkingStepSize( |
52 size_t idle_time_in_ms, size_t marking_speed_in_bytes_per_ms) { | 50 double idle_time_in_ms, double marking_speed_in_bytes_per_ms) { |
53 DCHECK(idle_time_in_ms > 0); | 51 DCHECK(idle_time_in_ms > 0); |
54 | 52 |
55 if (marking_speed_in_bytes_per_ms == 0) { | 53 if (marking_speed_in_bytes_per_ms == 0) { |
56 marking_speed_in_bytes_per_ms = kInitialConservativeMarkingSpeed; | 54 marking_speed_in_bytes_per_ms = kInitialConservativeMarkingSpeed; |
57 } | 55 } |
58 | 56 |
59 size_t marking_step_size = marking_speed_in_bytes_per_ms * idle_time_in_ms; | 57 double marking_step_size = marking_speed_in_bytes_per_ms * idle_time_in_ms; |
60 if (marking_step_size / marking_speed_in_bytes_per_ms != idle_time_in_ms) { | 58 if (marking_step_size >= kMaximumMarkingStepSize) { |
61 // In the case of an overflow we return maximum marking step size. | |
62 return kMaximumMarkingStepSize; | 59 return kMaximumMarkingStepSize; |
63 } | 60 } |
64 | |
65 if (marking_step_size > kMaximumMarkingStepSize) | |
66 return kMaximumMarkingStepSize; | |
67 | |
68 return static_cast<size_t>(marking_step_size * kConservativeTimeRatio); | 61 return static_cast<size_t>(marking_step_size * kConservativeTimeRatio); |
69 } | 62 } |
70 | 63 |
71 | 64 double GCIdleTimeHandler::EstimateFinalIncrementalMarkCompactTime( |
72 size_t GCIdleTimeHandler::EstimateMarkCompactTime( | |
73 size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms) { | |
74 // TODO(hpayer): Be more precise about the type of mark-compact event. It | |
75 // makes a huge difference if compaction is happening. | |
76 if (mark_compact_speed_in_bytes_per_ms == 0) { | |
77 mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed; | |
78 } | |
79 size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms; | |
80 return Min(result, kMaxMarkCompactTimeInMs); | |
81 } | |
82 | |
83 | |
84 size_t GCIdleTimeHandler::EstimateFinalIncrementalMarkCompactTime( | |
85 size_t size_of_objects, | 65 size_t size_of_objects, |
86 size_t final_incremental_mark_compact_speed_in_bytes_per_ms) { | 66 double final_incremental_mark_compact_speed_in_bytes_per_ms) { |
87 if (final_incremental_mark_compact_speed_in_bytes_per_ms == 0) { | 67 if (final_incremental_mark_compact_speed_in_bytes_per_ms == 0) { |
88 final_incremental_mark_compact_speed_in_bytes_per_ms = | 68 final_incremental_mark_compact_speed_in_bytes_per_ms = |
89 kInitialConservativeFinalIncrementalMarkCompactSpeed; | 69 kInitialConservativeFinalIncrementalMarkCompactSpeed; |
90 } | 70 } |
91 size_t result = | 71 double result = |
92 size_of_objects / final_incremental_mark_compact_speed_in_bytes_per_ms; | 72 size_of_objects / final_incremental_mark_compact_speed_in_bytes_per_ms; |
93 return Min(result, kMaxFinalIncrementalMarkCompactTimeInMs); | 73 return Min<double>(result, kMaxFinalIncrementalMarkCompactTimeInMs); |
94 } | 74 } |
95 | 75 |
96 | |
97 bool GCIdleTimeHandler::ShouldDoMarkCompact( | |
98 size_t idle_time_in_ms, size_t size_of_objects, | |
99 size_t mark_compact_speed_in_bytes_per_ms) { | |
100 return idle_time_in_ms >= kMaxScheduledIdleTime && | |
101 idle_time_in_ms >= | |
102 EstimateMarkCompactTime(size_of_objects, | |
103 mark_compact_speed_in_bytes_per_ms); | |
104 } | |
105 | |
106 | |
107 bool GCIdleTimeHandler::ShouldDoContextDisposalMarkCompact( | 76 bool GCIdleTimeHandler::ShouldDoContextDisposalMarkCompact( |
108 int contexts_disposed, double contexts_disposal_rate) { | 77 int contexts_disposed, double contexts_disposal_rate) { |
109 return contexts_disposed > 0 && contexts_disposal_rate > 0 && | 78 return contexts_disposed > 0 && contexts_disposal_rate > 0 && |
110 contexts_disposal_rate < kHighContextDisposalRate; | 79 contexts_disposal_rate < kHighContextDisposalRate; |
111 } | 80 } |
112 | 81 |
113 | |
114 bool GCIdleTimeHandler::ShouldDoFinalIncrementalMarkCompact( | 82 bool GCIdleTimeHandler::ShouldDoFinalIncrementalMarkCompact( |
115 size_t idle_time_in_ms, size_t size_of_objects, | 83 double idle_time_in_ms, size_t size_of_objects, |
116 size_t final_incremental_mark_compact_speed_in_bytes_per_ms) { | 84 double final_incremental_mark_compact_speed_in_bytes_per_ms) { |
117 return idle_time_in_ms >= | 85 return idle_time_in_ms >= |
118 EstimateFinalIncrementalMarkCompactTime( | 86 EstimateFinalIncrementalMarkCompactTime( |
119 size_of_objects, | 87 size_of_objects, |
120 final_incremental_mark_compact_speed_in_bytes_per_ms); | 88 final_incremental_mark_compact_speed_in_bytes_per_ms); |
121 } | 89 } |
122 | 90 |
123 | |
124 bool GCIdleTimeHandler::ShouldDoOverApproximateWeakClosure( | 91 bool GCIdleTimeHandler::ShouldDoOverApproximateWeakClosure( |
125 size_t idle_time_in_ms) { | 92 double idle_time_in_ms) { |
126 // TODO(jochen): Estimate the time it will take to build the object groups. | 93 // TODO(jochen): Estimate the time it will take to build the object groups. |
127 return idle_time_in_ms >= kMinTimeForOverApproximatingWeakClosureInMs; | 94 return idle_time_in_ms >= kMinTimeForOverApproximatingWeakClosureInMs; |
128 } | 95 } |
129 | 96 |
130 | 97 |
131 GCIdleTimeAction GCIdleTimeHandler::NothingOrDone(double idle_time_in_ms) { | 98 GCIdleTimeAction GCIdleTimeHandler::NothingOrDone(double idle_time_in_ms) { |
132 if (idle_time_in_ms >= kMinBackgroundIdleTime) { | 99 if (idle_time_in_ms >= kMinBackgroundIdleTime) { |
133 return GCIdleTimeAction::Nothing(); | 100 return GCIdleTimeAction::Nothing(); |
134 } | 101 } |
135 if (idle_times_which_made_no_progress_ >= kMaxNoProgressIdleTimes) { | 102 if (idle_times_which_made_no_progress_ >= kMaxNoProgressIdleTimes) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 if (!FLAG_incremental_marking || heap_state.incremental_marking_stopped) { | 143 if (!FLAG_incremental_marking || heap_state.incremental_marking_stopped) { |
177 return GCIdleTimeAction::Done(); | 144 return GCIdleTimeAction::Done(); |
178 } | 145 } |
179 | 146 |
180 return GCIdleTimeAction::IncrementalStep(); | 147 return GCIdleTimeAction::IncrementalStep(); |
181 } | 148 } |
182 | 149 |
183 | 150 |
184 } // namespace internal | 151 } // namespace internal |
185 } // namespace v8 | 152 } // namespace v8 |
OLD | NEW |