| 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.size_of_objects = kSizeOfObjects; | 26 result.size_of_objects = kSizeOfObjects; |
| 26 result.incremental_marking_stopped = false; | 27 result.incremental_marking_stopped = false; |
| 27 result.can_start_incremental_marking = true; | 28 result.can_start_incremental_marking = true; |
| 28 result.sweeping_in_progress = false; | 29 result.sweeping_in_progress = false; |
| 29 result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed; | 30 result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed; |
| 30 result.incremental_marking_speed_in_bytes_per_ms = kMarkingSpeed; | 31 result.incremental_marking_speed_in_bytes_per_ms = kMarkingSpeed; |
| 31 result.scavenge_speed_in_bytes_per_ms = kScavengeSpeed; | 32 result.scavenge_speed_in_bytes_per_ms = kScavengeSpeed; |
| 32 result.used_new_space_size = 0; | 33 result.used_new_space_size = 0; |
| 33 result.new_space_capacity = kNewSpaceCapacity; | 34 result.new_space_capacity = kNewSpaceCapacity; |
| 34 result.new_space_allocation_throughput_in_bytes_per_ms = | 35 result.new_space_allocation_throughput_in_bytes_per_ms = |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 173 } |
| 173 | 174 |
| 174 | 175 |
| 175 TEST_F(GCIdleTimeHandlerTest, DontDoMarkCompact) { | 176 TEST_F(GCIdleTimeHandlerTest, DontDoMarkCompact) { |
| 176 size_t idle_time_in_ms = 1; | 177 size_t idle_time_in_ms = 1; |
| 177 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoMarkCompact( | 178 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoMarkCompact( |
| 178 idle_time_in_ms, kSizeOfObjects, kMarkingSpeed)); | 179 idle_time_in_ms, kSizeOfObjects, kMarkingSpeed)); |
| 179 } | 180 } |
| 180 | 181 |
| 181 | 182 |
| 183 TEST_F(GCIdleTimeHandlerTest, ContextDisposeLowRate) { |
| 184 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 185 heap_state.contexts_disposed = 1; |
| 186 heap_state.incremental_marking_stopped = true; |
| 187 int idle_time_ms = 0; |
| 188 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 189 EXPECT_EQ(DO_NOTHING, action.type); |
| 190 } |
| 191 |
| 192 |
| 193 TEST_F(GCIdleTimeHandlerTest, ContextDisposeHighRate) { |
| 194 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 195 heap_state.contexts_disposed = 1; |
| 196 heap_state.contexts_disposal_rate = |
| 197 GCIdleTimeHandler::kHighContextDisposalRate - 1; |
| 198 heap_state.incremental_marking_stopped = true; |
| 199 int idle_time_ms = 0; |
| 200 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 201 EXPECT_EQ(DO_NOTHING, action.type); |
| 202 } |
| 203 |
| 204 |
| 182 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) { | 205 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) { |
| 183 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 206 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 184 heap_state.contexts_disposed = 1; | 207 heap_state.contexts_disposed = 1; |
| 208 heap_state.contexts_disposal_rate = 1.0; |
| 185 heap_state.incremental_marking_stopped = true; | 209 heap_state.incremental_marking_stopped = true; |
| 210 heap_state.can_start_incremental_marking = false; |
| 186 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 211 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; |
| 187 int idle_time_ms = | 212 int idle_time_ms = |
| 188 static_cast<int>((heap_state.size_of_objects + speed - 1) / speed); | 213 static_cast<int>((heap_state.size_of_objects + speed - 1) / speed); |
| 189 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 214 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 190 EXPECT_EQ(DO_FULL_GC, action.type); | 215 EXPECT_EQ(DO_FULL_GC, action.type); |
| 191 } | 216 } |
| 192 | 217 |
| 193 | 218 |
| 194 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeZeroIdleTime) { | 219 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeZeroIdleTime) { |
| 195 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 220 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 196 heap_state.contexts_disposed = 1; | 221 heap_state.contexts_disposed = 1; |
| 222 heap_state.contexts_disposal_rate = 1.0; |
| 197 heap_state.incremental_marking_stopped = true; | 223 heap_state.incremental_marking_stopped = true; |
| 198 heap_state.size_of_objects = GCIdleTimeHandler::kSmallHeapSize / 2; | 224 heap_state.size_of_objects = GCIdleTimeHandler::kSmallHeapSize / 2; |
| 199 int idle_time_ms = 0; | 225 int idle_time_ms = 0; |
| 200 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 226 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 201 EXPECT_EQ(DO_FULL_GC, action.type); | 227 EXPECT_EQ(DO_FULL_GC, action.type); |
| 202 } | 228 } |
| 203 | 229 |
| 204 | 230 |
| 205 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) { | 231 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) { |
| 206 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 232 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 207 heap_state.contexts_disposed = 1; | 233 heap_state.contexts_disposed = 1; |
| 234 heap_state.contexts_disposal_rate = 1.0; |
| 208 heap_state.incremental_marking_stopped = true; | 235 heap_state.incremental_marking_stopped = true; |
| 209 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 236 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; |
| 210 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed - 1); | 237 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed - 1); |
| 211 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 238 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 212 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | 239 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); |
| 213 } | 240 } |
| 214 | 241 |
| 215 | 242 |
| 216 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) { | 243 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) { |
| 217 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 244 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 218 heap_state.contexts_disposed = 1; | 245 heap_state.contexts_disposed = 1; |
| 246 heap_state.contexts_disposal_rate = 1.0; |
| 219 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 247 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; |
| 220 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed - 1); | 248 int idle_time_ms = static_cast<int>(heap_state.size_of_objects / speed - 1); |
| 221 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 249 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 222 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); | 250 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); |
| 223 } | 251 } |
| 224 | 252 |
| 225 | 253 |
| 226 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) { | 254 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) { |
| 227 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 255 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 228 size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms; | 256 size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 // Emulate mutator work. | 415 // Emulate mutator work. |
| 388 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { | 416 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { |
| 389 handler()->NotifyScavenge(); | 417 handler()->NotifyScavenge(); |
| 390 } | 418 } |
| 391 action = handler()->Compute(0, heap_state); | 419 action = handler()->Compute(0, heap_state); |
| 392 EXPECT_EQ(DO_NOTHING, action.type); | 420 EXPECT_EQ(DO_NOTHING, action.type); |
| 393 } | 421 } |
| 394 | 422 |
| 395 } // namespace internal | 423 } // namespace internal |
| 396 } // namespace v8 | 424 } // namespace v8 |
| OLD | NEW |