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.size_of_objects = kSizeOfObjects; | 26 result.size_of_objects = kSizeOfObjects; |
27 result.incremental_marking_stopped = false; | 27 result.incremental_marking_stopped = false; |
28 result.can_start_incremental_marking = true; | 28 result.can_start_incremental_marking = true; |
29 result.sweeping_in_progress = false; | 29 result.sweeping_in_progress = false; |
| 30 result.sweeping_completed = false; |
30 result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed; | 31 result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed; |
31 result.incremental_marking_speed_in_bytes_per_ms = kMarkingSpeed; | 32 result.incremental_marking_speed_in_bytes_per_ms = kMarkingSpeed; |
32 result.scavenge_speed_in_bytes_per_ms = kScavengeSpeed; | 33 result.scavenge_speed_in_bytes_per_ms = kScavengeSpeed; |
33 result.used_new_space_size = 0; | 34 result.used_new_space_size = 0; |
34 result.new_space_capacity = kNewSpaceCapacity; | 35 result.new_space_capacity = kNewSpaceCapacity; |
35 result.new_space_allocation_throughput_in_bytes_per_ms = | 36 result.new_space_allocation_throughput_in_bytes_per_ms = |
36 kNewSpaceAllocationThroughput; | 37 kNewSpaceAllocationThroughput; |
37 return result; | 38 return result; |
38 } | 39 } |
39 | 40 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 heap_state.incremental_marking_stopped = true; | 297 heap_state.incremental_marking_stopped = true; |
297 heap_state.can_start_incremental_marking = false; | 298 heap_state.can_start_incremental_marking = false; |
298 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 299 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; |
299 double idle_time_ms = | 300 double idle_time_ms = |
300 static_cast<double>(heap_state.size_of_objects / speed - 1); | 301 static_cast<double>(heap_state.size_of_objects / speed - 1); |
301 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 302 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
302 EXPECT_EQ(DO_NOTHING, action.type); | 303 EXPECT_EQ(DO_NOTHING, action.type); |
303 } | 304 } |
304 | 305 |
305 | 306 |
| 307 TEST_F(GCIdleTimeHandlerTest, FinalizeSweeping) { |
| 308 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 309 heap_state.incremental_marking_stopped = true; |
| 310 heap_state.can_start_incremental_marking = false; |
| 311 heap_state.sweeping_in_progress = true; |
| 312 heap_state.sweeping_completed = true; |
| 313 double idle_time_ms = 10.0; |
| 314 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 315 EXPECT_EQ(DO_FINALIZE_SWEEPING, action.type); |
| 316 } |
| 317 |
| 318 |
| 319 TEST_F(GCIdleTimeHandlerTest, CannotFinalizeSweeping) { |
| 320 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 321 heap_state.incremental_marking_stopped = true; |
| 322 heap_state.can_start_incremental_marking = false; |
| 323 heap_state.sweeping_in_progress = true; |
| 324 heap_state.sweeping_completed = false; |
| 325 double idle_time_ms = 10.0; |
| 326 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 327 EXPECT_EQ(DO_NOTHING, action.type); |
| 328 } |
| 329 |
| 330 |
306 TEST_F(GCIdleTimeHandlerTest, StopEventually1) { | 331 TEST_F(GCIdleTimeHandlerTest, StopEventually1) { |
307 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 332 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
308 heap_state.incremental_marking_stopped = true; | 333 heap_state.incremental_marking_stopped = true; |
309 heap_state.can_start_incremental_marking = false; | 334 heap_state.can_start_incremental_marking = false; |
310 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 335 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; |
311 double idle_time_ms = | 336 double idle_time_ms = |
312 static_cast<double>(heap_state.size_of_objects / speed + 1); | 337 static_cast<double>(heap_state.size_of_objects / speed + 1); |
313 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) { | 338 for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) { |
314 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 339 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
315 EXPECT_EQ(DO_FULL_GC, action.type); | 340 EXPECT_EQ(DO_FULL_GC, action.type); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 // Emulate mutator work. | 460 // Emulate mutator work. |
436 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { | 461 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { |
437 handler()->NotifyScavenge(); | 462 handler()->NotifyScavenge(); |
438 } | 463 } |
439 action = handler()->Compute(0, heap_state); | 464 action = handler()->Compute(0, heap_state); |
440 EXPECT_EQ(DO_NOTHING, action.type); | 465 EXPECT_EQ(DO_NOTHING, action.type); |
441 } | 466 } |
442 | 467 |
443 } // namespace internal | 468 } // namespace internal |
444 } // namespace v8 | 469 } // namespace v8 |
OLD | NEW |