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 30 matching lines...) Expand all Loading... |
41 void TransitionToReduceMemoryMode( | 41 void TransitionToReduceMemoryMode( |
42 const GCIdleTimeHandler::HeapState& heap_state) { | 42 const GCIdleTimeHandler::HeapState& heap_state) { |
43 handler()->NotifyScavenge(); | 43 handler()->NotifyScavenge(); |
44 EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode()); | 44 EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode()); |
45 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime; | 45 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime; |
46 int limit = GCIdleTimeHandler::kLongIdleNotificationsBeforeMutatorIsIdle; | 46 int limit = GCIdleTimeHandler::kLongIdleNotificationsBeforeMutatorIsIdle; |
47 bool incremental = !heap_state.incremental_marking_stopped || | 47 bool incremental = !heap_state.incremental_marking_stopped || |
48 heap_state.can_start_incremental_marking; | 48 heap_state.can_start_incremental_marking; |
49 for (int i = 0; i < limit; i++) { | 49 for (int i = 0; i < limit; i++) { |
50 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 50 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
51 EXPECT_EQ(incremental ? DO_INCREMENTAL_MARKING : DO_NOTHING, action.type); | 51 if (incremental) { |
| 52 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); |
| 53 } else { |
| 54 EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type); |
| 55 } |
52 } | 56 } |
53 handler()->Compute(idle_time_ms, heap_state); | 57 handler()->Compute(idle_time_ms, heap_state); |
54 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode()); | 58 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode()); |
55 } | 59 } |
56 | 60 |
57 void TransitionToDoneMode(const GCIdleTimeHandler::HeapState& heap_state, | 61 void TransitionToDoneMode(const GCIdleTimeHandler::HeapState& heap_state, |
58 double idle_time_ms, | 62 double idle_time_ms, |
59 GCIdleTimeActionType expected) { | 63 GCIdleTimeActionType expected) { |
60 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode()); | 64 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode()); |
61 int limit = GCIdleTimeHandler::kMaxIdleMarkCompacts; | 65 int limit = GCIdleTimeHandler::kMaxIdleMarkCompacts; |
62 for (int i = 0; i < limit; i++) { | 66 for (int i = 0; i < limit; i++) { |
63 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 67 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
64 EXPECT_EQ(expected, action.type); | 68 EXPECT_EQ(expected, action.type); |
65 EXPECT_TRUE(action.reduce_memory); | 69 EXPECT_TRUE(action.reduce_memory); |
66 handler()->NotifyMarkCompact(); | 70 handler()->NotifyMarkCompact(); |
67 handler()->NotifyIdleMarkCompact(); | 71 handler()->NotifyIdleMarkCompact(); |
68 } | 72 } |
69 handler()->Compute(idle_time_ms, heap_state); | 73 handler()->Compute(idle_time_ms, heap_state); |
70 EXPECT_EQ(GCIdleTimeHandler::kDone, handler()->mode()); | 74 EXPECT_EQ(GCIdleTimeHandler::kDone, handler()->mode()); |
71 } | 75 } |
72 | 76 |
73 void TransitionToReduceLatencyMode( | 77 void TransitionToReduceLatencyMode( |
74 const GCIdleTimeHandler::HeapState& heap_state) { | 78 const GCIdleTimeHandler::HeapState& heap_state) { |
75 EXPECT_EQ(GCIdleTimeHandler::kDone, handler()->mode()); | 79 EXPECT_EQ(GCIdleTimeHandler::kDone, handler()->mode()); |
76 int limit = GCIdleTimeHandler::kGCsBeforeMutatorIsActive; | 80 int limit = GCIdleTimeHandler::kMarkCompactsBeforeMutatorIsActive; |
77 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime; | 81 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime; |
78 for (int i = 0; i < limit; i++) { | 82 for (int i = 0; i < limit; i++) { |
79 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 83 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
80 EXPECT_EQ(DONE, action.type); | 84 EXPECT_EQ(DONE, action.type); |
81 if (i % 2 == 0) { | 85 handler()->NotifyMarkCompact(); |
82 handler()->NotifyScavenge(); | |
83 } else { | |
84 handler()->NotifyMarkCompact(); | |
85 } | |
86 } | 86 } |
87 handler()->Compute(idle_time_ms, heap_state); | 87 handler()->Compute(idle_time_ms, heap_state); |
88 EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode()); | 88 EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode()); |
89 } | 89 } |
90 | 90 |
91 static const size_t kSizeOfObjects = 100 * MB; | 91 static const size_t kSizeOfObjects = 100 * MB; |
92 static const size_t kMarkCompactSpeed = 200 * KB; | 92 static const size_t kMarkCompactSpeed = 200 * KB; |
93 static const size_t kMarkingSpeed = 200 * KB; | 93 static const size_t kMarkingSpeed = 200 * KB; |
94 static const size_t kScavengeSpeed = 100 * KB; | 94 static const size_t kScavengeSpeed = 100 * KB; |
95 static const size_t kNewSpaceCapacity = 1 * MB; | 95 static const size_t kNewSpaceCapacity = 1 * MB; |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 } | 543 } |
544 } | 544 } |
545 | 545 |
546 | 546 |
547 TEST_F(GCIdleTimeHandlerTest, SmallIdleTimeNothingToDo) { | 547 TEST_F(GCIdleTimeHandlerTest, SmallIdleTimeNothingToDo) { |
548 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 548 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
549 heap_state.incremental_marking_stopped = true; | 549 heap_state.incremental_marking_stopped = true; |
550 heap_state.can_start_incremental_marking = false; | 550 heap_state.can_start_incremental_marking = false; |
551 for (int i = 0; i < kMaxNotifications; i++) { | 551 for (int i = 0; i < kMaxNotifications; i++) { |
552 GCIdleTimeAction action = handler()->Compute(10, heap_state); | 552 GCIdleTimeAction action = handler()->Compute(10, heap_state); |
553 EXPECT_EQ(DO_NOTHING, action.type); | 553 EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type); |
554 } | 554 } |
555 } | 555 } |
556 | 556 |
557 | 557 |
558 TEST_F(GCIdleTimeHandlerTest, StayInReduceLatencyModeBecauseOfScavenges) { | 558 TEST_F(GCIdleTimeHandlerTest, StayInReduceLatencyModeBecauseOfScavenges) { |
559 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 559 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
560 heap_state.incremental_marking_stopped = true; | 560 heap_state.incremental_marking_stopped = true; |
561 heap_state.can_start_incremental_marking = false; | 561 heap_state.can_start_incremental_marking = false; |
562 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime; | 562 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime; |
563 int limit = GCIdleTimeHandler::kLongIdleNotificationsBeforeMutatorIsIdle; | 563 int limit = GCIdleTimeHandler::kLongIdleNotificationsBeforeMutatorIsIdle; |
564 for (int i = 0; i < kMaxNotifications; i++) { | 564 for (int i = 0; i < kMaxNotifications; i++) { |
565 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 565 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
566 EXPECT_EQ(DO_NOTHING, action.type); | 566 EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type); |
567 if ((i + 1) % limit == 0) handler()->NotifyScavenge(); | 567 if ((i + 1) % limit == 0) handler()->NotifyScavenge(); |
568 EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode()); | 568 EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode()); |
569 } | 569 } |
570 } | 570 } |
571 | 571 |
572 | 572 |
573 TEST_F(GCIdleTimeHandlerTest, StayInReduceLatencyModeBecauseOfMarkCompacts) { | 573 TEST_F(GCIdleTimeHandlerTest, StayInReduceLatencyModeBecauseOfMarkCompacts) { |
574 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 574 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
575 heap_state.incremental_marking_stopped = true; | 575 heap_state.incremental_marking_stopped = true; |
576 heap_state.can_start_incremental_marking = false; | 576 heap_state.can_start_incremental_marking = false; |
577 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime; | 577 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime; |
578 int limit = GCIdleTimeHandler::kLongIdleNotificationsBeforeMutatorIsIdle; | 578 int limit = GCIdleTimeHandler::kLongIdleNotificationsBeforeMutatorIsIdle; |
579 for (int i = 0; i < kMaxNotifications; i++) { | 579 for (int i = 0; i < kMaxNotifications; i++) { |
580 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 580 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
581 EXPECT_EQ(DO_NOTHING, action.type); | 581 EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type); |
582 if ((i + 1) % limit == 0) handler()->NotifyMarkCompact(); | 582 if ((i + 1) % limit == 0) handler()->NotifyMarkCompact(); |
583 EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode()); | 583 EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode()); |
584 } | 584 } |
585 } | 585 } |
586 | 586 |
587 | 587 |
588 TEST_F(GCIdleTimeHandlerTest, ReduceMemoryToReduceLatency) { | 588 TEST_F(GCIdleTimeHandlerTest, ReduceMemoryToReduceLatency) { |
589 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 589 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
590 heap_state.incremental_marking_stopped = true; | 590 heap_state.incremental_marking_stopped = true; |
591 heap_state.can_start_incremental_marking = false; | 591 heap_state.can_start_incremental_marking = false; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 handler()->NotifyScavenge(); | 636 handler()->NotifyScavenge(); |
637 // Notify idle GC. | 637 // Notify idle GC. |
638 handler()->NotifyMarkCompact(); | 638 handler()->NotifyMarkCompact(); |
639 handler()->NotifyIdleMarkCompact(); | 639 handler()->NotifyIdleMarkCompact(); |
640 } | 640 } |
641 action = handler()->Compute(idle_time_ms, heap_state); | 641 action = handler()->Compute(idle_time_ms, heap_state); |
642 EXPECT_EQ(DONE, action.type); | 642 EXPECT_EQ(DONE, action.type); |
643 } | 643 } |
644 | 644 |
645 | 645 |
| 646 TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnSweeping) { |
| 647 // Regression test for crbug.com/489323. |
| 648 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 649 |
| 650 // Simulate sweeping being in-progress but not complete. |
| 651 heap_state.incremental_marking_stopped = true; |
| 652 heap_state.can_start_incremental_marking = false; |
| 653 heap_state.sweeping_in_progress = true; |
| 654 heap_state.sweeping_completed = false; |
| 655 double idle_time_ms = 10.0; |
| 656 for (int i = 0; i < GCIdleTimeHandler::kMaxNoProgressIdleTimesPerMode; i++) { |
| 657 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 658 EXPECT_EQ(DO_NOTHING, action.type); |
| 659 } |
| 660 // We should return DONE after not making progress for some time. |
| 661 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 662 EXPECT_EQ(DONE, action.type); |
| 663 } |
| 664 |
| 665 |
| 666 TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnIncrementalMarking) { |
| 667 // Regression test for crbug.com/489323. |
| 668 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 669 |
| 670 // Simulate incremental marking stopped and not eligible to start. |
| 671 heap_state.incremental_marking_stopped = true; |
| 672 heap_state.can_start_incremental_marking = false; |
| 673 double idle_time_ms = 10.0; |
| 674 for (int i = 0; i < GCIdleTimeHandler::kMaxNoProgressIdleTimesPerMode; i++) { |
| 675 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 676 EXPECT_EQ(DO_NOTHING, action.type); |
| 677 } |
| 678 // We should return DONE after not making progress for some time. |
| 679 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 680 EXPECT_EQ(DONE, action.type); |
| 681 } |
| 682 |
| 683 |
| 684 TEST_F(GCIdleTimeHandlerTest, BackgroundReduceLatencyToReduceMemory) { |
| 685 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
| 686 heap_state.incremental_marking_stopped = false; |
| 687 heap_state.can_start_incremental_marking = true; |
| 688 double idle_time_ms = GCIdleTimeHandler::kMinBackgroundIdleTime; |
| 689 handler()->NotifyScavenge(); |
| 690 EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode()); |
| 691 int limit = |
| 692 GCIdleTimeHandler::kBackgroundIdleNotificationsBeforeMutatorIsIdle; |
| 693 for (int i = 0; i < limit; i++) { |
| 694 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 695 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); |
| 696 } |
| 697 handler()->Compute(idle_time_ms, heap_state); |
| 698 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode()); |
| 699 } |
| 700 |
646 } // namespace internal | 701 } // namespace internal |
647 } // namespace v8 | 702 } // namespace v8 |
OLD | NEW |