| 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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 } | 433 } |
| 434 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 434 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 435 // Emulate mutator work. | 435 // Emulate mutator work. |
| 436 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { | 436 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { |
| 437 handler()->NotifyScavenge(); | 437 handler()->NotifyScavenge(); |
| 438 } | 438 } |
| 439 action = handler()->Compute(0, heap_state); | 439 action = handler()->Compute(0, heap_state); |
| 440 EXPECT_EQ(DO_NOTHING, action.type); | 440 EXPECT_EQ(DO_NOTHING, action.type); |
| 441 } | 441 } |
| 442 | 442 |
| 443 |
| 444 TEST_F(GCIdleTimeHandlerTest, KeepDoingDoNothingWithZeroIdleTime) { |
| 445 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 446 for (int i = 0; i < GCIdleTimeHandler::kMaxNoProgressIdleTimesPerIdleRound; |
| 447 i++) { |
| 448 GCIdleTimeAction action = handler()->Compute(0, heap_state); |
| 449 EXPECT_EQ(DO_NOTHING, action.type); |
| 450 } |
| 451 // Should still return DO_NOTHING if we have been given 0 deadline yet. |
| 452 GCIdleTimeAction action = handler()->Compute(0, heap_state); |
| 453 EXPECT_EQ(DO_NOTHING, action.type); |
| 454 } |
| 455 |
| 456 |
| 457 TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnSweeping) { |
| 458 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 459 |
| 460 // Simulate sweeping being in-progress but not complete. |
| 461 heap_state.incremental_marking_stopped = true; |
| 462 heap_state.can_start_incremental_marking = false; |
| 463 heap_state.sweeping_in_progress = true; |
| 464 double idle_time_ms = 10.0; |
| 465 for (int i = 0; i < GCIdleTimeHandler::kMaxNoProgressIdleTimesPerIdleRound; |
| 466 i++) { |
| 467 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 468 EXPECT_EQ(DO_NOTHING, action.type); |
| 469 } |
| 470 // We should return DONE after not making progress for some time. |
| 471 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 472 EXPECT_EQ(DONE, action.type); |
| 473 } |
| 474 |
| 475 |
| 476 TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnIncrementalMarking) { |
| 477 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 478 |
| 479 // Simulate incremental marking stopped and not eligible to start. |
| 480 heap_state.incremental_marking_stopped = true; |
| 481 heap_state.can_start_incremental_marking = false; |
| 482 double idle_time_ms = 10.0; |
| 483 for (int i = 0; i < GCIdleTimeHandler::kMaxNoProgressIdleTimesPerIdleRound; |
| 484 i++) { |
| 485 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 486 EXPECT_EQ(DO_NOTHING, action.type); |
| 487 } |
| 488 // We should return DONE after not making progress for some time. |
| 489 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 490 EXPECT_EQ(DONE, action.type); |
| 491 } |
| 492 |
| 443 } // namespace internal | 493 } // namespace internal |
| 444 } // namespace v8 | 494 } // namespace v8 |
| OLD | NEW |