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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include "src/heap/gc-idle-time-handler.h" | 7 #include "src/heap/gc-idle-time-handler.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 class GCIdleTimeHandlerTest : public ::testing::Test { | 15 class GCIdleTimeHandlerTest : public ::testing::Test { |
16 public: | 16 public: |
17 GCIdleTimeHandlerTest() {} | 17 GCIdleTimeHandlerTest() {} |
18 virtual ~GCIdleTimeHandlerTest() {} | 18 virtual ~GCIdleTimeHandlerTest() {} |
19 | 19 |
20 GCIdleTimeHandler* handler() { return &handler_; } | 20 GCIdleTimeHandler* handler() { return &handler_; } |
21 | 21 |
22 GCIdleTimeHandler::HeapState DefaultHeapState() { | 22 GCIdleTimeHandler::HeapState DefaultHeapState() { |
23 GCIdleTimeHandler::HeapState result; | 23 GCIdleTimeHandler::HeapState result; |
24 result.contexts_disposed = 0; | 24 result.contexts_disposed = 0; |
25 result.contexts_disposal_rate = GCIdleTimeHandler::kHighContextDisposalRate; | 25 result.contexts_disposal_rate = GCIdleTimeHandler::kHighContextDisposalRate; |
26 result.incremental_marking_stopped = false; | 26 result.incremental_marking_stopped = false; |
27 result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed; | 27 result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed; |
28 result.scavenge_speed_in_bytes_per_ms = kScavengeSpeed; | |
29 result.used_new_space_size = 0; | |
30 result.new_space_capacity = kNewSpaceCapacity; | |
31 result.new_space_allocation_throughput_in_bytes_per_ms = | |
32 kNewSpaceAllocationThroughput; | |
33 return result; | 28 return result; |
34 } | 29 } |
35 | 30 |
36 static const size_t kSizeOfObjects = 100 * MB; | 31 static const size_t kSizeOfObjects = 100 * MB; |
37 static const size_t kMarkCompactSpeed = 200 * KB; | 32 static const size_t kMarkCompactSpeed = 200 * KB; |
38 static const size_t kMarkingSpeed = 200 * KB; | 33 static const size_t kMarkingSpeed = 200 * KB; |
39 static const size_t kScavengeSpeed = 100 * KB; | |
40 static const size_t kNewSpaceCapacity = 1 * MB; | |
41 static const size_t kNewSpaceAllocationThroughput = 10 * KB; | |
42 static const int kMaxNotifications = 100; | 34 static const int kMaxNotifications = 100; |
43 | 35 |
44 private: | 36 private: |
45 GCIdleTimeHandler handler_; | 37 GCIdleTimeHandler handler_; |
46 }; | 38 }; |
47 | 39 |
48 } // namespace | 40 } // namespace |
49 | 41 |
50 | 42 |
51 TEST(GCIdleTimeHandler, EstimateMarkingStepSizeInitial) { | 43 TEST(GCIdleTimeHandler, EstimateMarkingStepSizeInitial) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 92 |
101 | 93 |
102 TEST(GCIdleTimeHandler, EstimateMarkCompactTimeMax) { | 94 TEST(GCIdleTimeHandler, EstimateMarkCompactTimeMax) { |
103 size_t size = std::numeric_limits<size_t>::max(); | 95 size_t size = std::numeric_limits<size_t>::max(); |
104 size_t speed = 1; | 96 size_t speed = 1; |
105 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); | 97 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); |
106 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); | 98 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); |
107 } | 99 } |
108 | 100 |
109 | 101 |
110 TEST_F(GCIdleTimeHandlerTest, DoScavengeEmptyNewSpace) { | |
111 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
112 int idle_time_ms = 16; | |
113 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( | |
114 idle_time_ms, heap_state.new_space_capacity, | |
115 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | |
116 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | |
117 } | |
118 | |
119 | |
120 TEST_F(GCIdleTimeHandlerTest, DoScavengeFullNewSpace) { | |
121 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
122 heap_state.used_new_space_size = kNewSpaceCapacity; | |
123 int idle_time_ms = 16; | |
124 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoScavenge( | |
125 idle_time_ms, heap_state.new_space_capacity, | |
126 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | |
127 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | |
128 } | |
129 | |
130 | |
131 TEST_F(GCIdleTimeHandlerTest, DoScavengeUnknownScavengeSpeed) { | |
132 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
133 heap_state.used_new_space_size = kNewSpaceCapacity; | |
134 heap_state.scavenge_speed_in_bytes_per_ms = 0; | |
135 int idle_time_ms = 8; | |
136 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( | |
137 idle_time_ms, heap_state.new_space_capacity, | |
138 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | |
139 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | |
140 } | |
141 | |
142 | |
143 TEST_F(GCIdleTimeHandlerTest, DoScavengeLowScavengeSpeed) { | |
144 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
145 heap_state.used_new_space_size = kNewSpaceCapacity; | |
146 heap_state.scavenge_speed_in_bytes_per_ms = 1 * KB; | |
147 int idle_time_ms = 16; | |
148 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( | |
149 idle_time_ms, heap_state.new_space_capacity, | |
150 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | |
151 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | |
152 } | |
153 | |
154 | |
155 TEST_F(GCIdleTimeHandlerTest, DoScavengeLowAllocationRate) { | |
156 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
157 heap_state.used_new_space_size = kNewSpaceCapacity; | |
158 heap_state.new_space_allocation_throughput_in_bytes_per_ms = | |
159 GCIdleTimeHandler::kLowAllocationThroughput - 1; | |
160 int idle_time_ms = 16; | |
161 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoScavenge( | |
162 idle_time_ms, heap_state.new_space_capacity, | |
163 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | |
164 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | |
165 } | |
166 | |
167 | |
168 TEST_F(GCIdleTimeHandlerTest, DoScavengeHighScavengeSpeed) { | |
169 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
170 heap_state.used_new_space_size = kNewSpaceCapacity; | |
171 heap_state.scavenge_speed_in_bytes_per_ms = kNewSpaceCapacity; | |
172 int idle_time_ms = 16; | |
173 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoScavenge( | |
174 idle_time_ms, heap_state.new_space_capacity, | |
175 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | |
176 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | |
177 } | |
178 | |
179 | |
180 TEST_F(GCIdleTimeHandlerTest, DoNotScavengeSmallNewSpaceSize) { | |
181 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
182 heap_state.used_new_space_size = (MB / 2) - 1; | |
183 heap_state.scavenge_speed_in_bytes_per_ms = kNewSpaceCapacity; | |
184 int idle_time_ms = 16; | |
185 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( | |
186 idle_time_ms, heap_state.new_space_capacity, | |
187 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | |
188 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | |
189 } | |
190 | |
191 | |
192 TEST_F(GCIdleTimeHandlerTest, ShouldDoMarkCompact) { | 102 TEST_F(GCIdleTimeHandlerTest, ShouldDoMarkCompact) { |
193 size_t idle_time_ms = GCIdleTimeHandler::kMaxScheduledIdleTime; | 103 size_t idle_time_ms = GCIdleTimeHandler::kMaxScheduledIdleTime; |
194 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoMarkCompact(idle_time_ms, 0, 0)); | 104 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoMarkCompact(idle_time_ms, 0, 0)); |
195 } | 105 } |
196 | 106 |
197 | 107 |
198 TEST_F(GCIdleTimeHandlerTest, DontDoMarkCompact) { | 108 TEST_F(GCIdleTimeHandlerTest, DontDoMarkCompact) { |
199 size_t idle_time_ms = 1; | 109 size_t idle_time_ms = 1; |
200 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoMarkCompact( | 110 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoMarkCompact( |
201 idle_time_ms, kSizeOfObjects, kMarkingSpeed)); | 111 idle_time_ms, kSizeOfObjects, kMarkingSpeed)); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) { | 194 TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) { |
285 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 195 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
286 heap_state.incremental_marking_stopped = true; | 196 heap_state.incremental_marking_stopped = true; |
287 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 197 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; |
288 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); | 198 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); |
289 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 199 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
290 EXPECT_EQ(DONE, action.type); | 200 EXPECT_EQ(DONE, action.type); |
291 } | 201 } |
292 | 202 |
293 | 203 |
294 TEST_F(GCIdleTimeHandlerTest, Scavenge) { | |
295 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
296 int idle_time_ms = 10; | |
297 heap_state.used_new_space_size = | |
298 heap_state.new_space_capacity - | |
299 (kNewSpaceAllocationThroughput * idle_time_ms); | |
300 GCIdleTimeAction action = | |
301 handler()->Compute(static_cast<double>(idle_time_ms), heap_state); | |
302 EXPECT_EQ(DO_SCAVENGE, action.type); | |
303 heap_state.used_new_space_size = 0; | |
304 } | |
305 | |
306 | |
307 TEST_F(GCIdleTimeHandlerTest, ScavengeAndDone) { | |
308 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | |
309 int idle_time_ms = 10; | |
310 heap_state.incremental_marking_stopped = true; | |
311 heap_state.used_new_space_size = | |
312 heap_state.new_space_capacity - | |
313 (kNewSpaceAllocationThroughput * idle_time_ms); | |
314 GCIdleTimeAction action = | |
315 handler()->Compute(static_cast<double>(idle_time_ms), heap_state); | |
316 EXPECT_EQ(DO_SCAVENGE, action.type); | |
317 heap_state.used_new_space_size = 0; | |
318 action = handler()->Compute(static_cast<double>(idle_time_ms), heap_state); | |
319 EXPECT_EQ(DONE, action.type); | |
320 } | |
321 | |
322 | |
323 TEST_F(GCIdleTimeHandlerTest, DoNotStartIncrementalMarking) { | 204 TEST_F(GCIdleTimeHandlerTest, DoNotStartIncrementalMarking) { |
324 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 205 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
325 heap_state.incremental_marking_stopped = true; | 206 heap_state.incremental_marking_stopped = true; |
326 double idle_time_ms = 10.0; | 207 double idle_time_ms = 10.0; |
327 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 208 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
328 EXPECT_EQ(DONE, action.type); | 209 EXPECT_EQ(DONE, action.type); |
329 } | 210 } |
330 | 211 |
331 | 212 |
332 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop) { | 213 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // Simulate incremental marking stopped and not eligible to start. | 248 // Simulate incremental marking stopped and not eligible to start. |
368 heap_state.incremental_marking_stopped = true; | 249 heap_state.incremental_marking_stopped = true; |
369 double idle_time_ms = 10.0; | 250 double idle_time_ms = 10.0; |
370 // We should return DONE if we cannot start incremental marking. | 251 // We should return DONE if we cannot start incremental marking. |
371 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 252 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
372 EXPECT_EQ(DONE, action.type); | 253 EXPECT_EQ(DONE, action.type); |
373 } | 254 } |
374 | 255 |
375 } // namespace internal | 256 } // namespace internal |
376 } // namespace v8 | 257 } // namespace v8 |
OLD | NEW |