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

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

Issue 1226703002: Revert of Replace reduce-memory mode in idle notification with delayed clean-up GC. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/unittests/heap/memory-reducer-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/heap/gc-idle-time-handler-unittest.cc
diff --git a/test/unittests/heap/gc-idle-time-handler-unittest.cc b/test/unittests/heap/gc-idle-time-handler-unittest.cc
index c75fde492e5822fbc5d77fb3d5cfa0db9cd2a000..d4833b34d2710877a42bdca257fbb30bfa85df61 100644
--- a/test/unittests/heap/gc-idle-time-handler-unittest.cc
+++ b/test/unittests/heap/gc-idle-time-handler-unittest.cc
@@ -25,6 +25,7 @@
result.contexts_disposal_rate = GCIdleTimeHandler::kHighContextDisposalRate;
result.size_of_objects = kSizeOfObjects;
result.incremental_marking_stopped = false;
+ result.can_start_incremental_marking = true;
result.sweeping_in_progress = false;
result.sweeping_completed = false;
result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed;
@@ -37,13 +38,63 @@
return result;
}
+ void TransitionToReduceMemoryMode(
+ const GCIdleTimeHandler::HeapState& heap_state) {
+ handler()->NotifyScavenge();
+ EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode());
+ double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime;
+ int limit = GCIdleTimeHandler::kLongIdleNotificationsBeforeMutatorIsIdle;
+ bool incremental = !heap_state.incremental_marking_stopped ||
+ heap_state.can_start_incremental_marking;
+ for (int i = 0; i < limit; i++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ if (incremental) {
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ } else {
+ EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type);
+ }
+ }
+ handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode());
+ }
+
+ void TransitionToDoneMode(const GCIdleTimeHandler::HeapState& heap_state,
+ double idle_time_ms,
+ GCIdleTimeActionType expected) {
+ EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode());
+ int limit = GCIdleTimeHandler::kMaxIdleMarkCompacts;
+ for (int i = 0; i < limit; i++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(expected, action.type);
+ EXPECT_TRUE(action.reduce_memory);
+ handler()->NotifyMarkCompact(true);
+ handler()->NotifyIdleMarkCompact();
+ }
+ handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(GCIdleTimeHandler::kDone, handler()->mode());
+ }
+
+ void TransitionToReduceLatencyMode(
+ const GCIdleTimeHandler::HeapState& heap_state) {
+ EXPECT_EQ(GCIdleTimeHandler::kDone, handler()->mode());
+ int limit = GCIdleTimeHandler::kMarkCompactsBeforeMutatorIsActive;
+ double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime;
+ for (int i = 0; i < limit; i++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DONE, action.type);
+ handler()->NotifyMarkCompact(true);
+ }
+ handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode());
+ }
+
static const size_t kSizeOfObjects = 100 * MB;
static const size_t kMarkCompactSpeed = 200 * KB;
static const size_t kMarkingSpeed = 200 * KB;
static const size_t kScavengeSpeed = 100 * KB;
static const size_t kNewSpaceCapacity = 1 * MB;
static const size_t kNewSpaceAllocationThroughput = 10 * KB;
- static const int kMaxNotifications = 100;
+ static const int kMaxNotifications = 1000;
private:
GCIdleTimeHandler handler_;
@@ -212,8 +263,11 @@
heap_state.contexts_disposed = 1;
heap_state.incremental_marking_stopped = true;
double idle_time_ms = 0;
- GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
- EXPECT_EQ(DO_NOTHING, action.type);
+ for (int mode = 0; mode < 1; mode++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_NOTHING, action.type);
+ TransitionToReduceMemoryMode(heap_state);
+ }
}
@@ -224,8 +278,12 @@
GCIdleTimeHandler::kHighContextDisposalRate - 1;
heap_state.incremental_marking_stopped = true;
double idle_time_ms = 0;
- GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
- EXPECT_EQ(DO_FULL_GC, action.type);
+ for (int mode = 0; mode < 1; mode++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_FULL_GC, action.type);
+ heap_state.contexts_disposal_rate = 0.0;
+ TransitionToReduceMemoryMode(heap_state);
+ }
}
@@ -235,12 +293,34 @@
heap_state.contexts_disposal_rate = 1.0;
heap_state.incremental_marking_stopped = true;
double idle_time_ms = 0;
- GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
- EXPECT_EQ(DO_FULL_GC, action.type);
+ for (int mode = 0; mode < 1; mode++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_FULL_GC, action.type);
+ heap_state.contexts_disposal_rate = 0.0;
+ TransitionToReduceMemoryMode(heap_state);
+ }
}
TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.contexts_disposed = 1;
+ heap_state.contexts_disposal_rate =
+ GCIdleTimeHandler::kHighContextDisposalRate;
+ heap_state.incremental_marking_stopped = true;
+ size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
+ double idle_time_ms =
+ static_cast<double>(heap_state.size_of_objects / speed - 1);
+ for (int mode = 0; mode < 1; mode++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ heap_state.contexts_disposal_rate = 0.0;
+ TransitionToReduceMemoryMode(heap_state);
+ }
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) {
GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
heap_state.contexts_disposed = 1;
heap_state.contexts_disposal_rate =
@@ -248,160 +328,332 @@
size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
double idle_time_ms =
static_cast<double>(heap_state.size_of_objects / speed - 1);
- GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
- EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
-}
-
-
-TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) {
- GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
- heap_state.contexts_disposed = 1;
- heap_state.contexts_disposal_rate =
- GCIdleTimeHandler::kHighContextDisposalRate;
+ for (int mode = 0; mode < 1; mode++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ heap_state.contexts_disposal_rate = 0.0;
+ TransitionToReduceMemoryMode(heap_state);
+ }
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms;
+ double idle_time_ms = 10;
+ for (int mode = 0; mode < 1; mode++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ EXPECT_GT(speed * static_cast<size_t>(idle_time_ms),
+ static_cast<size_t>(action.parameter));
+ EXPECT_LT(0, action.parameter);
+ TransitionToReduceMemoryMode(heap_state);
+ }
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, IncrementalMarking2) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms;
+ double idle_time_ms = 10;
+ for (int mode = 0; mode < 1; mode++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ EXPECT_GT(speed * static_cast<size_t>(idle_time_ms),
+ static_cast<size_t>(action.parameter));
+ EXPECT_LT(0, action.parameter);
+ TransitionToReduceMemoryMode(heap_state);
+ }
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
double idle_time_ms =
static_cast<double>(heap_state.size_of_objects / speed - 1);
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_NOTHING, action.type);
+ TransitionToReduceMemoryMode(heap_state);
+ action = handler()->Compute(idle_time_ms, heap_state);
EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
}
-TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) {
- GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
- size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms;
- double idle_time_ms = 10;
- GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
- EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
- EXPECT_GT(speed * static_cast<size_t>(idle_time_ms),
- static_cast<size_t>(action.parameter));
- EXPECT_LT(0, action.parameter);
-}
-
-
-TEST_F(GCIdleTimeHandlerTest, IncrementalMarking2) {
- GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
- size_t speed = heap_state.incremental_marking_speed_in_bytes_per_ms;
- double idle_time_ms = 10;
- GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
- EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
- EXPECT_GT(speed * static_cast<size_t>(idle_time_ms),
- static_cast<size_t>(action.parameter));
- EXPECT_LT(0, action.parameter);
-}
-
-
-TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) {
- GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
- heap_state.incremental_marking_stopped = true;
+TEST_F(GCIdleTimeHandlerTest, FinalizeSweeping) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ for (int mode = 0; mode < 1; mode++) {
+ heap_state.sweeping_in_progress = true;
+ heap_state.sweeping_completed = true;
+ double idle_time_ms = 10.0;
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_FINALIZE_SWEEPING, action.type);
+ heap_state.sweeping_in_progress = false;
+ heap_state.sweeping_completed = false;
+ TransitionToReduceMemoryMode(heap_state);
+ }
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, CannotFinalizeSweeping) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ for (int mode = 0; mode < 1; mode++) {
+ heap_state.sweeping_in_progress = true;
+ heap_state.sweeping_completed = false;
+ double idle_time_ms = 10.0;
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_NOTHING, action.type);
+ heap_state.sweeping_in_progress = false;
+ heap_state.sweeping_completed = false;
+ TransitionToReduceMemoryMode(heap_state);
+ }
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, Scavenge) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ int idle_time_ms = 10;
+ for (int mode = 0; mode < 1; mode++) {
+ heap_state.used_new_space_size =
+ heap_state.new_space_capacity -
+ (kNewSpaceAllocationThroughput * idle_time_ms);
+ GCIdleTimeAction action =
+ handler()->Compute(static_cast<double>(idle_time_ms), heap_state);
+ EXPECT_EQ(DO_SCAVENGE, action.type);
+ heap_state.used_new_space_size = 0;
+ TransitionToReduceMemoryMode(heap_state);
+ }
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, ScavengeAndDone) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ int idle_time_ms = 10;
+ heap_state.can_start_incremental_marking = false;
+ heap_state.incremental_marking_stopped = true;
+ for (int mode = 0; mode < 1; mode++) {
+ heap_state.used_new_space_size =
+ heap_state.new_space_capacity -
+ (kNewSpaceAllocationThroughput * idle_time_ms);
+ GCIdleTimeAction action =
+ handler()->Compute(static_cast<double>(idle_time_ms), heap_state);
+ EXPECT_EQ(DO_SCAVENGE, action.type);
+ heap_state.used_new_space_size = 0;
+ action = handler()->Compute(static_cast<double>(idle_time_ms), heap_state);
+ EXPECT_EQ(DO_NOTHING, action.type);
+ TransitionToReduceMemoryMode(heap_state);
+ }
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, StopEventually1) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime;
+ bool stopped = false;
+ for (int i = 0; i < kMaxNotifications && !stopped; i++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ if (action.type == DO_INCREMENTAL_MARKING || action.type == DO_FULL_GC) {
+ handler()->NotifyMarkCompact(true);
+ handler()->NotifyIdleMarkCompact();
+ }
+ if (action.type == DONE) stopped = true;
+ }
+ EXPECT_TRUE(stopped);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, StopEventually2) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
double idle_time_ms =
- static_cast<double>(heap_state.size_of_objects / speed - 1);
+ static_cast<double>(heap_state.size_of_objects / speed + 1);
+ TransitionToReduceMemoryMode(heap_state);
+ TransitionToDoneMode(heap_state, idle_time_ms, DO_FULL_GC);
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
EXPECT_EQ(DONE, action.type);
}
-TEST_F(GCIdleTimeHandlerTest, FinalizeSweeping) {
- GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
- heap_state.incremental_marking_stopped = true;
- heap_state.sweeping_in_progress = true;
- heap_state.sweeping_completed = true;
- double idle_time_ms = 10.0;
- GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
- EXPECT_EQ(DO_FINALIZE_SWEEPING, action.type);
-}
-
-
-TEST_F(GCIdleTimeHandlerTest, CannotFinalizeSweeping) {
- GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
- heap_state.incremental_marking_stopped = true;
+TEST_F(GCIdleTimeHandlerTest, StopEventually3) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ double idle_time_ms = 10;
+ TransitionToReduceMemoryMode(heap_state);
+ TransitionToDoneMode(heap_state, idle_time_ms, DO_INCREMENTAL_MARKING);
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DONE, action.type);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop1) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
+ double idle_time_ms =
+ static_cast<double>(heap_state.size_of_objects / speed + 1);
+ TransitionToReduceMemoryMode(heap_state);
+ TransitionToDoneMode(heap_state, idle_time_ms, DO_FULL_GC);
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DONE, action.type);
+ TransitionToReduceLatencyMode(heap_state);
+ heap_state.can_start_incremental_marking = true;
+ action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ EXPECT_FALSE(action.reduce_memory);
+ EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode());
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop2) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ double idle_time_ms = 10;
+ TransitionToReduceMemoryMode(heap_state);
+ TransitionToDoneMode(heap_state, idle_time_ms, DO_INCREMENTAL_MARKING);
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DONE, action.type);
+ TransitionToReduceLatencyMode(heap_state);
+ heap_state.can_start_incremental_marking = true;
+ action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ EXPECT_FALSE(action.reduce_memory);
+ EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode());
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeNothingToDo) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ for (int i = 0; i < kMaxNotifications; i++) {
+ GCIdleTimeAction action = handler()->Compute(0, heap_state);
+ EXPECT_EQ(DO_NOTHING, action.type);
+ }
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, SmallIdleTimeNothingToDo) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ for (int i = 0; i < kMaxNotifications; i++) {
+ GCIdleTimeAction action = handler()->Compute(10, heap_state);
+ EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type);
+ }
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, StayInReduceLatencyModeBecauseOfScavenges) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime;
+ int limit = GCIdleTimeHandler::kLongIdleNotificationsBeforeMutatorIsIdle;
+ for (int i = 0; i < kMaxNotifications; i++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type);
+ if ((i + 1) % limit == 0) handler()->NotifyScavenge();
+ EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode());
+ }
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, StayInReduceLatencyModeBecauseOfMarkCompacts) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime;
+ int limit = GCIdleTimeHandler::kLongIdleNotificationsBeforeMutatorIsIdle;
+ for (int i = 0; i < kMaxNotifications; i++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type);
+ if ((i + 1) % limit == 0) handler()->NotifyMarkCompact(true);
+ EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode());
+ }
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, ReduceMemoryToReduceLatency) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime;
+ int limit = GCIdleTimeHandler::kMaxIdleMarkCompacts;
+ for (int idle_gc = 0; idle_gc < limit; idle_gc++) {
+ TransitionToReduceMemoryMode(heap_state);
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ EXPECT_TRUE(action.reduce_memory);
+ EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode());
+ for (int i = 0; i < idle_gc; i++) {
+ action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ EXPECT_TRUE(action.reduce_memory);
+ // ReduceMemory mode should tolerate one mutator GC per idle GC.
+ handler()->NotifyScavenge();
+ // Notify idle GC.
+ handler()->NotifyMarkCompact(true);
+ handler()->NotifyIdleMarkCompact();
+ }
+ // Transition to ReduceLatency mode after doing |idle_gc| idle GCs.
+ handler()->NotifyScavenge();
+ action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_NOTHING, action.type);
+ EXPECT_FALSE(action.reduce_memory);
+ EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode());
+ }
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, ReduceMemoryToDone) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
+ double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime;
+ int limit = GCIdleTimeHandler::kMaxIdleMarkCompacts;
+ TransitionToReduceMemoryMode(heap_state);
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ EXPECT_TRUE(action.reduce_memory);
+ for (int i = 0; i < limit; i++) {
+ action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ EXPECT_TRUE(action.reduce_memory);
+ EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode());
+ // ReduceMemory mode should tolerate one mutator GC per idle GC.
+ handler()->NotifyScavenge();
+ // Notify idle GC.
+ handler()->NotifyMarkCompact(true);
+ handler()->NotifyIdleMarkCompact();
+ }
+ action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DONE, action.type);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnSweeping) {
+ // Regression test for crbug.com/489323.
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+
+ // Simulate sweeping being in-progress but not complete.
+ heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
heap_state.sweeping_in_progress = true;
heap_state.sweeping_completed = false;
double idle_time_ms = 10.0;
- GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
- EXPECT_EQ(DO_NOTHING, action.type);
-}
-
-
-TEST_F(GCIdleTimeHandlerTest, Scavenge) {
- GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
- int idle_time_ms = 10;
- heap_state.used_new_space_size =
- heap_state.new_space_capacity -
- (kNewSpaceAllocationThroughput * idle_time_ms);
- GCIdleTimeAction action =
- handler()->Compute(static_cast<double>(idle_time_ms), heap_state);
- EXPECT_EQ(DO_SCAVENGE, action.type);
- heap_state.used_new_space_size = 0;
-}
-
-
-TEST_F(GCIdleTimeHandlerTest, ScavengeAndDone) {
- GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
- int idle_time_ms = 10;
- heap_state.incremental_marking_stopped = true;
- heap_state.used_new_space_size =
- heap_state.new_space_capacity -
- (kNewSpaceAllocationThroughput * idle_time_ms);
- GCIdleTimeAction action =
- handler()->Compute(static_cast<double>(idle_time_ms), heap_state);
- EXPECT_EQ(DO_SCAVENGE, action.type);
- heap_state.used_new_space_size = 0;
- action = handler()->Compute(static_cast<double>(idle_time_ms), heap_state);
- EXPECT_EQ(DONE, action.type);
-}
-
-
-TEST_F(GCIdleTimeHandlerTest, DoNotStartIncrementalMarking) {
- GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
- heap_state.incremental_marking_stopped = true;
- double idle_time_ms = 10.0;
- GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
- EXPECT_EQ(DONE, action.type);
-}
-
-
-TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop) {
- GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
- heap_state.incremental_marking_stopped = true;
- double idle_time_ms = 10.0;
- GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
- EXPECT_EQ(DONE, action.type);
- heap_state.incremental_marking_stopped = false;
- action = handler()->Compute(idle_time_ms, heap_state);
- EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
-}
-
-
-TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeNothingToDo) {
- GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
- for (int i = 0; i < kMaxNotifications; i++) {
- GCIdleTimeAction action = handler()->Compute(0, heap_state);
- EXPECT_EQ(DO_NOTHING, action.type);
- }
-}
-
-
-TEST_F(GCIdleTimeHandlerTest, SmallIdleTimeNothingToDo) {
- GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
- heap_state.incremental_marking_stopped = true;
- for (int i = 0; i < kMaxNotifications; i++) {
- GCIdleTimeAction action = handler()->Compute(10, heap_state);
- EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type);
- }
-}
-
-
-TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnSweeping) {
- // Regression test for crbug.com/489323.
- GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
-
- // Simulate sweeping being in-progress but not complete.
- heap_state.incremental_marking_stopped = true;
- heap_state.sweeping_in_progress = true;
- heap_state.sweeping_completed = false;
- double idle_time_ms = 10.0;
- for (int i = 0; i < GCIdleTimeHandler::kMaxNoProgressIdleTimes; i++) {
+ for (int i = 0; i < GCIdleTimeHandler::kMaxNoProgressIdleTimesPerMode; i++) {
GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
EXPECT_EQ(DO_NOTHING, action.type);
}
@@ -417,9 +669,48 @@
// Simulate incremental marking stopped and not eligible to start.
heap_state.incremental_marking_stopped = true;
+ heap_state.can_start_incremental_marking = false;
double idle_time_ms = 10.0;
- // We should return DONE if we cannot start incremental marking.
- GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ for (int i = 0; i < GCIdleTimeHandler::kMaxNoProgressIdleTimesPerMode; i++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_NOTHING, action.type);
+ }
+ // We should return DONE after not making progress for some time.
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DONE, action.type);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, BackgroundReduceLatencyToReduceMemory) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = false;
+ heap_state.can_start_incremental_marking = true;
+ double idle_time_ms = GCIdleTimeHandler::kMinBackgroundIdleTime;
+ handler()->NotifyScavenge();
+ EXPECT_EQ(GCIdleTimeHandler::kReduceLatency, handler()->mode());
+ int limit =
+ GCIdleTimeHandler::kBackgroundIdleNotificationsBeforeMutatorIsIdle;
+ for (int i = 0; i < limit; i++) {
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ }
+ handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode());
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, SkipUselessGCs) {
+ GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+ heap_state.incremental_marking_stopped = false;
+ heap_state.can_start_incremental_marking = true;
+ TransitionToReduceMemoryMode(heap_state);
+ EXPECT_EQ(GCIdleTimeHandler::kReduceMemory, handler()->mode());
+ double idle_time_ms = GCIdleTimeHandler::kMinLongIdleTime;
+ GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+ EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+ handler()->NotifyMarkCompact(false);
+ handler()->NotifyIdleMarkCompact();
+ action = handler()->Compute(idle_time_ms, heap_state);
EXPECT_EQ(DONE, action.type);
}
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/unittests/heap/memory-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698