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 "test/heap-unittests/heap-unittest.h" | |
6 | |
5 #include <limits> | 7 #include <limits> |
6 | 8 |
7 #include "src/heap/gc-idle-time-handler.h" | |
8 | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 | 9 |
11 namespace v8 { | 10 namespace v8 { |
12 namespace internal { | 11 namespace internal { |
13 | 12 |
14 TEST(EstimateMarkingStepSizeTest, EstimateMarkingStepSizeInitial) { | 13 TEST(EstimateMarkingStepSizeTest, EstimateMarkingStepSizeInitial) { |
15 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(1, 0); | 14 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(1, 0); |
16 EXPECT_EQ( | 15 EXPECT_EQ( |
17 static_cast<size_t>(GCIdleTimeHandler::kInitialConservativeMarkingSpeed * | 16 static_cast<size_t>(GCIdleTimeHandler::kInitialConservativeMarkingSpeed * |
18 GCIdleTimeHandler::kConservativeTimeRatio), | 17 GCIdleTimeHandler::kConservativeTimeRatio), |
19 step_size); | 18 step_size); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 } | 61 } |
63 | 62 |
64 | 63 |
65 TEST(EstimateMarkCompactTimeTest, EstimateMarkCompactTimeMax) { | 64 TEST(EstimateMarkCompactTimeTest, EstimateMarkCompactTimeMax) { |
66 size_t size = std::numeric_limits<size_t>::max(); | 65 size_t size = std::numeric_limits<size_t>::max(); |
67 size_t speed = 1; | 66 size_t speed = 1; |
68 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); | 67 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); |
69 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); | 68 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); |
70 } | 69 } |
71 | 70 |
71 | |
72 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) { | |
73 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
74 heap_state.contexts_disposed = 1; | |
75 heap_state.incremental_marking_stopped = true; | |
76 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | |
77 int idle_time_ms = (heap_state.size_of_objects + speed - 1) / speed; | |
78 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
79 EXPECT_EQ(DO_FULL_GC, action.type); | |
80 } | |
81 | |
82 | |
83 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) { | |
84 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
85 heap_state.contexts_disposed = 1; | |
86 heap_state.incremental_marking_stopped = true; | |
87 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | |
88 int idle_time_ms = heap_state.size_of_objects / speed - 1; | |
89 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
90 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | |
91 } | |
92 | |
93 | |
94 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) { | |
95 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
96 heap_state.contexts_disposed = 1; | |
97 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | |
98 int idle_time_ms = heap_state.size_of_objects / speed - 1; | |
99 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
100 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | |
101 } | |
102 | |
103 | |
104 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) { | |
105 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
106 size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms; | |
107 int idle_time_ms = 10; | |
108 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
109 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | |
110 EXPECT_GT(speed * idle_time_ms, action.parameter); | |
111 EXPECT_LT(0, action.parameter); | |
112 } | |
113 | |
114 | |
115 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking2) { | |
116 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
117 heap_state.incremental_marking_stopped = true; | |
118 size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms; | |
119 int idle_time_ms = 10; | |
120 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
121 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | |
122 EXPECT_GT(speed * idle_time_ms, action.parameter); | |
123 EXPECT_LT(0, action.parameter); | |
124 } | |
125 | |
126 | |
127 TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) { | |
128 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
129 heap_state.incremental_marking_stopped = true; | |
130 heap_state.can_start_incremental_marking = false; | |
131 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | |
132 int idle_time_ms = heap_state.size_of_objects / speed - 1; | |
133 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
134 EXPECT_EQ(DO_NOTHING, action.type); | |
135 } | |
136 | |
137 | |
138 TEST_F(GCIdleTimeHandlerTest, StopEventually1) { | |
139 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
140 heap_state.incremental_marking_stopped = true; | |
141 heap_state.can_start_incremental_marking = false; | |
142 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | |
143 int idle_time_ms = heap_state.size_of_objects / speed + 1; | |
144 for (int i = 0; i < 100; i++) { | |
Hannes Payer (out of office)
2014/08/22 12:54:59
Instead of 100, can we use the expected value to t
| |
145 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
146 if (action.type == DO_NOTHING) break; | |
147 EXPECT_EQ(DO_FULL_GC, action.type); | |
148 handler()->NotifyIdleMarkCompact(); | |
149 } | |
150 for (int i = 0; i < 100; i++) { | |
151 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
152 EXPECT_EQ(DO_NOTHING, action.type); | |
153 } | |
154 } | |
155 | |
156 | |
157 TEST_F(GCIdleTimeHandlerTest, StopEventually2) { | |
158 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
159 int idle_time_ms = 10; | |
160 for (int i = 0; i < 100; i++) { | |
161 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
162 if (action.type == DO_NOTHING) break; | |
163 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | |
164 handler()->NotifyIdleMarkCompact(); | |
165 } | |
166 for (int i = 0; i < 100; i++) { | |
167 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
168 EXPECT_EQ(DO_NOTHING, action.type); | |
169 } | |
170 } | |
171 | |
172 | |
173 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop1) { | |
174 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
175 heap_state.incremental_marking_stopped = true; | |
176 heap_state.can_start_incremental_marking = false; | |
177 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | |
178 int idle_time_ms = heap_state.size_of_objects / speed + 1; | |
179 for (int i = 0; i < 100; i++) { | |
180 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
181 if (action.type == DO_NOTHING) break; | |
182 EXPECT_EQ(DO_FULL_GC, action.type); | |
183 handler()->NotifyIdleMarkCompact(); | |
184 } | |
185 for (int i = 0; i < 100; i++) { | |
186 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
187 EXPECT_EQ(DO_NOTHING, action.type); | |
188 } | |
189 // Emulate mutator work. | |
190 for (int i = 0; i < 100; i++) { | |
191 handler()->NotifyScavenge(); | |
192 } | |
193 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
194 EXPECT_EQ(DO_FULL_GC, action.type); | |
195 } | |
196 | |
197 | |
198 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop2) { | |
199 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
200 int idle_time_ms = 10; | |
201 for (int i = 0; i < 100; i++) { | |
202 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
203 if (action.type == DO_NOTHING) break; | |
204 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | |
205 handler()->NotifyIdleMarkCompact(); | |
206 } | |
207 for (int i = 0; i < 100; i++) { | |
208 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
209 EXPECT_EQ(DO_NOTHING, action.type); | |
210 } | |
211 // Emulate mutator work. | |
212 for (int i = 0; i < 100; i++) { | |
213 handler()->NotifyScavenge(); | |
214 } | |
215 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | |
216 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | |
217 } | |
218 | |
219 | |
72 } // namespace internal | 220 } // namespace internal |
73 } // namespace v8 | 221 } // namespace v8 |
OLD | NEW |