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 GCIdleTimeHeapState DefaultHeapState() { | 22 GCIdleTimeHeapState DefaultHeapState() { |
23 GCIdleTimeHeapState result; | 23 GCIdleTimeHeapState 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; | |
28 return result; | 27 return result; |
29 } | 28 } |
30 | 29 |
31 static const size_t kSizeOfObjects = 100 * MB; | 30 static const size_t kSizeOfObjects = 100 * MB; |
32 static const size_t kMarkCompactSpeed = 200 * KB; | 31 static const size_t kMarkCompactSpeed = 200 * KB; |
33 static const size_t kMarkingSpeed = 200 * KB; | 32 static const size_t kMarkingSpeed = 200 * KB; |
34 static const int kMaxNotifications = 100; | 33 static const int kMaxNotifications = 100; |
35 | 34 |
36 private: | 35 private: |
37 GCIdleTimeHandler handler_; | 36 GCIdleTimeHandler handler_; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 156 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
158 EXPECT_EQ(DO_FULL_GC, action.type); | 157 EXPECT_EQ(DO_FULL_GC, action.type); |
159 } | 158 } |
160 | 159 |
161 | 160 |
162 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) { | 161 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) { |
163 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 162 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
164 heap_state.contexts_disposed = 1; | 163 heap_state.contexts_disposed = 1; |
165 heap_state.contexts_disposal_rate = | 164 heap_state.contexts_disposal_rate = |
166 GCIdleTimeHandler::kHighContextDisposalRate; | 165 GCIdleTimeHandler::kHighContextDisposalRate; |
167 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 166 size_t speed = kMarkCompactSpeed; |
168 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); | 167 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); |
169 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 168 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
170 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); | 169 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); |
171 } | 170 } |
172 | 171 |
173 | 172 |
174 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) { | 173 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) { |
175 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 174 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
176 heap_state.contexts_disposed = 1; | 175 heap_state.contexts_disposed = 1; |
177 heap_state.contexts_disposal_rate = | 176 heap_state.contexts_disposal_rate = |
178 GCIdleTimeHandler::kHighContextDisposalRate; | 177 GCIdleTimeHandler::kHighContextDisposalRate; |
179 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 178 size_t speed = kMarkCompactSpeed; |
180 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); | 179 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); |
181 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 180 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
182 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); | 181 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); |
183 } | 182 } |
184 | 183 |
185 | 184 |
186 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) { | 185 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) { |
187 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 186 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
188 double idle_time_ms = 10; | 187 double idle_time_ms = 10; |
189 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 188 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
190 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); | 189 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); |
191 } | 190 } |
192 | 191 |
193 | 192 |
194 TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) { | 193 TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) { |
195 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 194 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
196 heap_state.incremental_marking_stopped = true; | 195 heap_state.incremental_marking_stopped = true; |
197 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 196 size_t speed = kMarkCompactSpeed; |
198 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); | 197 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); |
199 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 198 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
200 EXPECT_EQ(DONE, action.type); | 199 EXPECT_EQ(DONE, action.type); |
201 } | 200 } |
202 | 201 |
203 | 202 |
204 TEST_F(GCIdleTimeHandlerTest, DoNotStartIncrementalMarking) { | 203 TEST_F(GCIdleTimeHandlerTest, DoNotStartIncrementalMarking) { |
205 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 204 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
206 heap_state.incremental_marking_stopped = true; | 205 heap_state.incremental_marking_stopped = true; |
207 double idle_time_ms = 10.0; | 206 double idle_time_ms = 10.0; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 // Simulate incremental marking stopped and not eligible to start. | 247 // Simulate incremental marking stopped and not eligible to start. |
249 heap_state.incremental_marking_stopped = true; | 248 heap_state.incremental_marking_stopped = true; |
250 double idle_time_ms = 10.0; | 249 double idle_time_ms = 10.0; |
251 // We should return DONE if we cannot start incremental marking. | 250 // We should return DONE if we cannot start incremental marking. |
252 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 251 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
253 EXPECT_EQ(DONE, action.type); | 252 EXPECT_EQ(DONE, action.type); |
254 } | 253 } |
255 | 254 |
256 } // namespace internal | 255 } // namespace internal |
257 } // namespace v8 | 256 } // namespace v8 |
OLD | NEW |