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 | |
7 #include <limits> | 5 #include <limits> |
8 | 6 |
| 7 #include "src/heap/gc-idle-time-handler.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 TEST(EstimateMarkingStepSizeTest, EstimateMarkingStepSizeInitial) { | 13 namespace { |
| 14 |
| 15 class GCIdleTimeHandlerTest : public ::testing::Test { |
| 16 public: |
| 17 GCIdleTimeHandlerTest() {} |
| 18 virtual ~GCIdleTimeHandlerTest() {} |
| 19 |
| 20 GCIdleTimeHandler* handler() { return &handler_; } |
| 21 |
| 22 GCIdleTimeHandler::HeapState DefaultHeapState() { |
| 23 GCIdleTimeHandler::HeapState result; |
| 24 result.contexts_disposed = 0; |
| 25 result.size_of_objects = kSizeOfObjects; |
| 26 result.incremental_marking_stopped = false; |
| 27 result.can_start_incremental_marking = true; |
| 28 result.sweeping_in_progress = false; |
| 29 result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed; |
| 30 result.incremental_marking_speed_in_bytes_per_ms = kMarkingSpeed; |
| 31 return result; |
| 32 } |
| 33 |
| 34 static const size_t kSizeOfObjects = 100 * MB; |
| 35 static const size_t kMarkCompactSpeed = 100 * KB; |
| 36 static const size_t kMarkingSpeed = 100 * KB; |
| 37 |
| 38 private: |
| 39 GCIdleTimeHandler handler_; |
| 40 }; |
| 41 |
| 42 } // namespace |
| 43 |
| 44 |
| 45 TEST(GCIdleTimeHandler, EstimateMarkingStepSizeInitial) { |
14 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(1, 0); | 46 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize(1, 0); |
15 EXPECT_EQ( | 47 EXPECT_EQ( |
16 static_cast<size_t>(GCIdleTimeHandler::kInitialConservativeMarkingSpeed * | 48 static_cast<size_t>(GCIdleTimeHandler::kInitialConservativeMarkingSpeed * |
17 GCIdleTimeHandler::kConservativeTimeRatio), | 49 GCIdleTimeHandler::kConservativeTimeRatio), |
18 step_size); | 50 step_size); |
19 } | 51 } |
20 | 52 |
21 | 53 |
22 TEST(EstimateMarkingStepSizeTest, EstimateMarkingStepSizeNonZero) { | 54 TEST(GCIdleTimeHandler, EstimateMarkingStepSizeNonZero) { |
23 size_t marking_speed_in_bytes_per_millisecond = 100; | 55 size_t marking_speed_in_bytes_per_millisecond = 100; |
24 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize( | 56 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize( |
25 1, marking_speed_in_bytes_per_millisecond); | 57 1, marking_speed_in_bytes_per_millisecond); |
26 EXPECT_EQ(static_cast<size_t>(marking_speed_in_bytes_per_millisecond * | 58 EXPECT_EQ(static_cast<size_t>(marking_speed_in_bytes_per_millisecond * |
27 GCIdleTimeHandler::kConservativeTimeRatio), | 59 GCIdleTimeHandler::kConservativeTimeRatio), |
28 step_size); | 60 step_size); |
29 } | 61 } |
30 | 62 |
31 | 63 |
32 TEST(EstimateMarkingStepSizeTest, EstimateMarkingStepSizeOverflow1) { | 64 TEST(GCIdleTimeHandler, EstimateMarkingStepSizeOverflow1) { |
33 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize( | 65 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize( |
34 10, std::numeric_limits<size_t>::max()); | 66 10, std::numeric_limits<size_t>::max()); |
35 EXPECT_EQ(static_cast<size_t>(GCIdleTimeHandler::kMaximumMarkingStepSize), | 67 EXPECT_EQ(static_cast<size_t>(GCIdleTimeHandler::kMaximumMarkingStepSize), |
36 step_size); | 68 step_size); |
37 } | 69 } |
38 | 70 |
39 | 71 |
40 TEST(EstimateMarkingStepSizeTest, EstimateMarkingStepSizeOverflow2) { | 72 TEST(GCIdleTimeHandler, EstimateMarkingStepSizeOverflow2) { |
41 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize( | 73 size_t step_size = GCIdleTimeHandler::EstimateMarkingStepSize( |
42 std::numeric_limits<size_t>::max(), 10); | 74 std::numeric_limits<size_t>::max(), 10); |
43 EXPECT_EQ(static_cast<size_t>(GCIdleTimeHandler::kMaximumMarkingStepSize), | 75 EXPECT_EQ(static_cast<size_t>(GCIdleTimeHandler::kMaximumMarkingStepSize), |
44 step_size); | 76 step_size); |
45 } | 77 } |
46 | 78 |
47 | 79 |
48 TEST(EstimateMarkCompactTimeTest, EstimateMarkCompactTimeInitial) { | 80 TEST(GCIdleTimeHandler, EstimateMarkCompactTimeInitial) { |
49 size_t size = 100 * MB; | 81 size_t size = 100 * MB; |
50 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, 0); | 82 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, 0); |
51 EXPECT_EQ(size / GCIdleTimeHandler::kInitialConservativeMarkCompactSpeed, | 83 EXPECT_EQ(size / GCIdleTimeHandler::kInitialConservativeMarkCompactSpeed, |
52 time); | 84 time); |
53 } | 85 } |
54 | 86 |
55 | 87 |
56 TEST(EstimateMarkCompactTimeTest, EstimateMarkCompactTimeNonZero) { | 88 TEST(GCIdleTimeHandler, EstimateMarkCompactTimeNonZero) { |
57 size_t size = 100 * MB; | 89 size_t size = 100 * MB; |
58 size_t speed = 10 * KB; | 90 size_t speed = 10 * KB; |
59 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); | 91 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); |
60 EXPECT_EQ(size / speed, time); | 92 EXPECT_EQ(size / speed, time); |
61 } | 93 } |
62 | 94 |
63 | 95 |
64 TEST(EstimateMarkCompactTimeTest, EstimateMarkCompactTimeMax) { | 96 TEST(GCIdleTimeHandler, EstimateMarkCompactTimeMax) { |
65 size_t size = std::numeric_limits<size_t>::max(); | 97 size_t size = std::numeric_limits<size_t>::max(); |
66 size_t speed = 1; | 98 size_t speed = 1; |
67 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); | 99 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); |
68 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); | 100 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); |
69 } | 101 } |
70 | 102 |
71 | 103 |
72 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) { | 104 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) { |
73 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 105 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
74 heap_state.contexts_disposed = 1; | 106 heap_state.contexts_disposed = 1; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 233 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
202 EXPECT_EQ(DO_NOTHING, action.type); | 234 EXPECT_EQ(DO_NOTHING, action.type); |
203 // Emulate mutator work. | 235 // Emulate mutator work. |
204 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { | 236 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { |
205 handler()->NotifyScavenge(); | 237 handler()->NotifyScavenge(); |
206 } | 238 } |
207 action = handler()->Compute(idle_time_ms, heap_state); | 239 action = handler()->Compute(idle_time_ms, heap_state); |
208 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | 240 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); |
209 } | 241 } |
210 | 242 |
211 | |
212 } // namespace internal | 243 } // namespace internal |
213 } // namespace v8 | 244 } // namespace v8 |
OLD | NEW |