| 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" | 5 #include "test/heap-unittests/heap-unittest.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); | 67 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); |
| 68 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); | 68 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); |
| 69 } | 69 } |
| 70 | 70 |
| 71 | 71 |
| 72 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) { | 72 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) { |
| 73 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 73 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 74 heap_state.contexts_disposed = 1; | 74 heap_state.contexts_disposed = 1; |
| 75 heap_state.incremental_marking_stopped = true; | 75 heap_state.incremental_marking_stopped = true; |
| 76 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 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; | 77 int idle_time_ms = |
| 78 static_cast<int>((heap_state.size_of_objects + speed - 1) / speed); |
| 78 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 79 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 79 EXPECT_EQ(DO_FULL_GC, action.type); | 80 EXPECT_EQ(DO_FULL_GC, action.type); |
| 80 } | 81 } |
| 81 | 82 |
| 82 | 83 |
| 83 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) { | 84 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) { |
| 84 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 85 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 85 heap_state.contexts_disposed = 1; | 86 heap_state.contexts_disposed = 1; |
| 86 heap_state.incremental_marking_stopped = true; | 87 heap_state.incremental_marking_stopped = true; |
| 87 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 88 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 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed - 1); |
| 89 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 90 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 90 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | 91 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); |
| 91 } | 92 } |
| 92 | 93 |
| 93 | 94 |
| 94 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) { | 95 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) { |
| 95 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 96 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 96 heap_state.contexts_disposed = 1; | 97 heap_state.contexts_disposed = 1; |
| 97 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 98 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 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed - 1); |
| 99 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 100 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 100 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | 101 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); |
| 101 } | 102 } |
| 102 | 103 |
| 103 | 104 |
| 104 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) { | 105 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) { |
| 105 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 106 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 106 size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms; | 107 size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms; |
| 107 int idle_time_ms = 10; | 108 int idle_time_ms = 10; |
| 108 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 109 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 124 static_cast<size_t>(action.parameter)); | 125 static_cast<size_t>(action.parameter)); |
| 125 EXPECT_LT(0, action.parameter); | 126 EXPECT_LT(0, action.parameter); |
| 126 } | 127 } |
| 127 | 128 |
| 128 | 129 |
| 129 TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) { | 130 TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) { |
| 130 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 131 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 131 heap_state.incremental_marking_stopped = true; | 132 heap_state.incremental_marking_stopped = true; |
| 132 heap_state.can_start_incremental_marking = false; | 133 heap_state.can_start_incremental_marking = false; |
| 133 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 134 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; |
| 134 int idle_time_ms = heap_state.size_of_objects / speed - 1; | 135 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed - 1); |
| 135 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 136 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 136 EXPECT_EQ(DO_NOTHING, action.type); | 137 EXPECT_EQ(DO_NOTHING, action.type); |
| 137 } | 138 } |
| 138 | 139 |
| 139 | 140 |
| 140 TEST_F(GCIdleTimeHandlerTest, StopEventually1) { | 141 TEST_F(GCIdleTimeHandlerTest, StopEventually1) { |
| 141 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 142 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 142 heap_state.incremental_marking_stopped = true; | 143 heap_state.incremental_marking_stopped = true; |
| 143 heap_state.can_start_incremental_marking = false; | 144 heap_state.can_start_incremental_marking = false; |
| 144 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 145 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; |
| 145 int idle_time_ms = heap_state.size_of_objects / speed + 1; | 146 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed + 1); |
| 146 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) { | 147 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) { |
| 147 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 148 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 148 EXPECT_EQ(DO_FULL_GC, action.type); | 149 EXPECT_EQ(DO_FULL_GC, action.type); |
| 149 handler()->NotifyIdleMarkCompact(); | 150 handler()->NotifyIdleMarkCompact(); |
| 150 } | 151 } |
| 151 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 152 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 152 EXPECT_EQ(DO_NOTHING, action.type); | 153 EXPECT_EQ(DO_NOTHING, action.type); |
| 153 } | 154 } |
| 154 | 155 |
| 155 | 156 |
| 156 TEST_F(GCIdleTimeHandlerTest, StopEventually2) { | 157 TEST_F(GCIdleTimeHandlerTest, StopEventually2) { |
| 157 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 158 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 158 int idle_time_ms = 10; | 159 int idle_time_ms = 10; |
| 159 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) { | 160 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) { |
| 160 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 161 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 161 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | 162 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); |
| 162 handler()->NotifyIdleMarkCompact(); | 163 handler()->NotifyIdleMarkCompact(); |
| 163 } | 164 } |
| 164 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 165 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 165 EXPECT_EQ(DO_NOTHING, action.type); | 166 EXPECT_EQ(DO_NOTHING, action.type); |
| 166 } | 167 } |
| 167 | 168 |
| 168 | 169 |
| 169 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop1) { | 170 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop1) { |
| 170 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 171 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 171 heap_state.incremental_marking_stopped = true; | 172 heap_state.incremental_marking_stopped = true; |
| 172 heap_state.can_start_incremental_marking = false; | 173 heap_state.can_start_incremental_marking = false; |
| 173 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 174 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; |
| 174 int idle_time_ms = heap_state.size_of_objects / speed + 1; | 175 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed + 1); |
| 175 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) { | 176 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) { |
| 176 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 177 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 177 EXPECT_EQ(DO_FULL_GC, action.type); | 178 EXPECT_EQ(DO_FULL_GC, action.type); |
| 178 handler()->NotifyIdleMarkCompact(); | 179 handler()->NotifyIdleMarkCompact(); |
| 179 } | 180 } |
| 180 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 181 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 181 EXPECT_EQ(DO_NOTHING, action.type); | 182 EXPECT_EQ(DO_NOTHING, action.type); |
| 182 // Emulate mutator work. | 183 // Emulate mutator work. |
| 183 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { | 184 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { |
| 184 handler()->NotifyScavenge(); | 185 handler()->NotifyScavenge(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 203 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { | 204 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { |
| 204 handler()->NotifyScavenge(); | 205 handler()->NotifyScavenge(); |
| 205 } | 206 } |
| 206 action = handler()->Compute(idle_time_ms, heap_state); | 207 action = handler()->Compute(idle_time_ms, heap_state); |
| 207 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | 208 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); |
| 208 } | 209 } |
| 209 | 210 |
| 210 | 211 |
| 211 } // namespace internal | 212 } // namespace internal |
| 212 } // namespace v8 | 213 } // namespace v8 |
| OLD | NEW |