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 { |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 } | 458 } |
459 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 459 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
460 // Emulate mutator work. | 460 // Emulate mutator work. |
461 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { | 461 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { |
462 handler()->NotifyScavenge(); | 462 handler()->NotifyScavenge(); |
463 } | 463 } |
464 action = handler()->Compute(0, heap_state); | 464 action = handler()->Compute(0, heap_state); |
465 EXPECT_EQ(DO_NOTHING, action.type); | 465 EXPECT_EQ(DO_NOTHING, action.type); |
466 } | 466 } |
467 | 467 |
| 468 |
| 469 TEST_F(GCIdleTimeHandlerTest, KeepDoingDoNothingWithZeroIdleTime) { |
| 470 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 471 for (int i = 0; i < GCIdleTimeHandler::kMaxNoProgressIdleTimesPerIdleRound; |
| 472 i++) { |
| 473 GCIdleTimeAction action = handler()->Compute(0, heap_state); |
| 474 EXPECT_EQ(DO_NOTHING, action.type); |
| 475 } |
| 476 // Should still return DO_NOTHING if we have been given 0 deadline yet. |
| 477 GCIdleTimeAction action = handler()->Compute(0, heap_state); |
| 478 EXPECT_EQ(DO_NOTHING, action.type); |
| 479 } |
| 480 |
| 481 |
| 482 TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnSweeping) { |
| 483 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 484 |
| 485 // Simulate sweeping being in-progress but not complete. |
| 486 heap_state.incremental_marking_stopped = true; |
| 487 heap_state.can_start_incremental_marking = false; |
| 488 heap_state.sweeping_in_progress = true; |
| 489 heap_state.sweeping_completed = false; |
| 490 double idle_time_ms = 10.0; |
| 491 for (int i = 0; i < GCIdleTimeHandler::kMaxNoProgressIdleTimesPerIdleRound; |
| 492 i++) { |
| 493 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 494 EXPECT_EQ(DO_NOTHING, action.type); |
| 495 } |
| 496 // We should return DONE after not making progress for some time. |
| 497 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 498 EXPECT_EQ(DONE, action.type); |
| 499 } |
| 500 |
| 501 |
| 502 TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnIncrementalMarking) { |
| 503 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 504 |
| 505 // Simulate incremental marking stopped and not eligible to start. |
| 506 heap_state.incremental_marking_stopped = true; |
| 507 heap_state.can_start_incremental_marking = false; |
| 508 double idle_time_ms = 10.0; |
| 509 for (int i = 0; i < GCIdleTimeHandler::kMaxNoProgressIdleTimesPerIdleRound; |
| 510 i++) { |
| 511 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 512 EXPECT_EQ(DO_NOTHING, action.type); |
| 513 } |
| 514 // We should return DONE after not making progress for some time. |
| 515 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 516 EXPECT_EQ(DONE, action.type); |
| 517 } |
| 518 |
468 } // namespace internal | 519 } // namespace internal |
469 } // namespace v8 | 520 } // namespace v8 |
OLD | NEW |