Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: test/unittests/heap/gc-idle-time-handler-unittest.cc

Issue 1145103002: Take freed handles into account when scheduling idle GCs. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/heap/heap.cc ('K') | « src/heap/heap.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 void TransitionToDoneMode(const GCIdleTimeHandler::HeapState& heap_state, 61 void TransitionToDoneMode(const GCIdleTimeHandler::HeapState& heap_state,
62 double idle_time_ms, 62 double idle_time_ms,
63 GCIdleTimeActionType expected) { 63 GCIdleTimeActionType expected) {
64 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode()); 64 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode());
65 int limit = GCIdleTimeHandler::kMaxIdleMarkCompacts; 65 int limit = GCIdleTimeHandler::kMaxIdleMarkCompacts;
66 for (int i = 0; i < limit; i++) { 66 for (int i = 0; i < limit; i++) {
67 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); 67 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
68 EXPECT_EQ(expected, action.type); 68 EXPECT_EQ(expected, action.type);
69 EXPECT_TRUE(action.reduce_memory); 69 EXPECT_TRUE(action.reduce_memory);
70 handler()->NotifyMarkCompact(); 70 handler()->NotifyMarkCompact(true);
71 handler()->NotifyIdleMarkCompact(); 71 handler()->NotifyIdleMarkCompact();
72 } 72 }
73 handler()->Compute(idle_time_ms, heap_state); 73 handler()->Compute(idle_time_ms, heap_state);
74 EXPECT_EQ(GCIdleTimeHandler::kDone, handler()->mode()); 74 EXPECT_EQ(GCIdleTimeHandler::kDone, handler()->mode());
75 } 75 }
76 76
77 void TransitionToReduceLatencyMode( 77 void TransitionToReduceLatencyMode(
78 const GCIdleTimeHandler::HeapState& heap_state) { 78 const GCIdleTimeHandler::HeapState& heap_state) {
79 EXPECT_EQ(GCIdleTimeHandler::kDone, handler()->mode()); 79 EXPECT_EQ(GCIdleTimeHandler::kDone, handler()->mode());
80 int limit = GCIdleTimeHandler::kMarkCompactsBeforeMutatorIsActive; 80 int limit = GCIdleTimeHandler::kMarkCompactsBeforeMutatorIsActive;
81 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime; 81 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime;
82 for (int i = 0; i < limit; i++) { 82 for (int i = 0; i < limit; i++) {
83 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); 83 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
84 EXPECT_EQ(DONE, action.type); 84 EXPECT_EQ(DONE, action.type);
85 handler()->NotifyMarkCompact(); 85 handler()->NotifyMarkCompact(true);
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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 455
456 TEST_F(GCIdleTimeHandlerTest, StopEventually1) { 456 TEST_F(GCIdleTimeHandlerTest, StopEventually1) {
457 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); 457 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
458 heap_state.incremental_marking_stopped = true; 458 heap_state.incremental_marking_stopped = true;
459 heap_state.can_start_incremental_marking = false; 459 heap_state.can_start_incremental_marking = false;
460 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime; 460 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime;
461 bool stopped = false; 461 bool stopped = false;
462 for (int i = 0; i < kMaxNotifications && !stopped; i++) { 462 for (int i = 0; i < kMaxNotifications && !stopped; i++) {
463 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); 463 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
464 if (action.type == DO_INCREMENTAL_MARKING || action.type == DO_FULL_GC) { 464 if (action.type == DO_INCREMENTAL_MARKING || action.type == DO_FULL_GC) {
465 handler()->NotifyMarkCompact(); 465 handler()->NotifyMarkCompact(true);
466 handler()->NotifyIdleMarkCompact(); 466 handler()->NotifyIdleMarkCompact();
467 } 467 }
468 if (action.type == DONE) stopped = true; 468 if (action.type == DONE) stopped = true;
469 } 469 }
470 EXPECT_TRUE(stopped); 470 EXPECT_TRUE(stopped);
471 } 471 }
472 472
473 473
474 TEST_F(GCIdleTimeHandlerTest, StopEventually2) { 474 TEST_F(GCIdleTimeHandlerTest, StopEventually2) {
475 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); 475 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_TRUE(DO_NOTHING == action.type || DONE == 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(true);
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;
592 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime; 592 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime;
593 int limit = GCIdleTimeHandler::kMaxIdleMarkCompacts; 593 int limit = GCIdleTimeHandler::kMaxIdleMarkCompacts;
594 for (int idle_gc = 0; idle_gc < limit; idle_gc++) { 594 for (int idle_gc = 0; idle_gc < limit; idle_gc++) {
595 TransitionToReduceMemoryMode(heap_state); 595 TransitionToReduceMemoryMode(heap_state);
596 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); 596 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
597 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); 597 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
598 EXPECT_TRUE(action.reduce_memory); 598 EXPECT_TRUE(action.reduce_memory);
599 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode()); 599 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode());
600 for (int i = 0; i < idle_gc; i++) { 600 for (int i = 0; i < idle_gc; i++) {
601 action = handler()->Compute(idle_time_ms, heap_state); 601 action = handler()->Compute(idle_time_ms, heap_state);
602 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); 602 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
603 EXPECT_TRUE(action.reduce_memory); 603 EXPECT_TRUE(action.reduce_memory);
604 // ReduceMemory mode should tolerate one mutator GC per idle GC. 604 // ReduceMemory mode should tolerate one mutator GC per idle GC.
605 handler()->NotifyScavenge(); 605 handler()->NotifyScavenge();
606 // Notify idle GC. 606 // Notify idle GC.
607 handler()->NotifyMarkCompact(); 607 handler()->NotifyMarkCompact(true);
608 handler()->NotifyIdleMarkCompact(); 608 handler()->NotifyIdleMarkCompact();
609 } 609 }
610 // Transition to ReduceLatency mode after doing |idle_gc| idle GCs. 610 // Transition to ReduceLatency mode after doing |idle_gc| idle GCs.
611 handler()->NotifyScavenge(); 611 handler()->NotifyScavenge();
612 action = handler()->Compute(idle_time_ms, heap_state); 612 action = handler()->Compute(idle_time_ms, heap_state);
613 EXPECT_EQ(DO_NOTHING, action.type); 613 EXPECT_EQ(DO_NOTHING, action.type);
614 EXPECT_FALSE(action.reduce_memory); 614 EXPECT_FALSE(action.reduce_memory);
615 EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode()); 615 EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode());
616 } 616 }
617 } 617 }
(...skipping 10 matching lines...) Expand all
628 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); 628 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
629 EXPECT_TRUE(action.reduce_memory); 629 EXPECT_TRUE(action.reduce_memory);
630 for (int i = 0; i < limit; i++) { 630 for (int i = 0; i < limit; i++) {
631 action = handler()->Compute(idle_time_ms, heap_state); 631 action = handler()->Compute(idle_time_ms, heap_state);
632 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); 632 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
633 EXPECT_TRUE(action.reduce_memory); 633 EXPECT_TRUE(action.reduce_memory);
634 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode()); 634 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode());
635 // ReduceMemory mode should tolerate one mutator GC per idle GC. 635 // ReduceMemory mode should tolerate one mutator GC per idle GC.
636 handler()->NotifyScavenge(); 636 handler()->NotifyScavenge();
637 // Notify idle GC. 637 // Notify idle GC.
638 handler()->NotifyMarkCompact(); 638 handler()->NotifyMarkCompact(true);
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) { 646 TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnSweeping) {
647 // Regression test for crbug.com/489323. 647 // Regression test for crbug.com/489323.
648 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); 648 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 int limit = 691 int limit =
692 GCIdleTimeHandler::kBackgroundIdleNotificationsBeforeMutatorIsIdle; 692 GCIdleTimeHandler::kBackgroundIdleNotificationsBeforeMutatorIsIdle;
693 for (int i = 0; i < limit; i++) { 693 for (int i = 0; i < limit; i++) {
694 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); 694 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
695 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); 695 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
696 } 696 }
697 handler()->Compute(idle_time_ms, heap_state); 697 handler()->Compute(idle_time_ms, heap_state);
698 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode()); 698 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode());
699 } 699 }
700 700
701
702 TEST_F(GCIdleTimeHandlerTest, SkipUselessGCs) {
703 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
704 heap_state.incremental_marking_stopped = false;
705 heap_state.can_start_incremental_marking = true;
706 TransitionToReduceMemoryMode(heap_state);
707 EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode());
708 double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime;
709 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
710 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
711 handler()->NotifyMarkCompact(false);
712 handler()->NotifyIdleMarkCompact();
713 action = handler()->Compute(idle_time_ms, heap_state);
714 EXPECT_EQ(DONE, action.type);
715 }
716
701 } // namespace internal 717 } // namespace internal
702 } // namespace v8 718 } // namespace v8
OLDNEW
« src/heap/heap.cc ('K') | « src/heap/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698