Avoid idle times smaller than 1ms.
authorhpayer@chromium.org <hpayer@chromium.org>
Thu, 18 Sep 2014 13:37:36 +0000 (13:37 +0000)
committerhpayer@chromium.org <hpayer@chromium.org>
Thu, 18 Sep 2014 13:37:36 +0000 (13:37 +0000)
BUG=
R=ulan@chromium.org

Review URL: https://codereview.chromium.org/580083002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24044 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/heap/gc-idle-time-handler-unittest.cc
src/heap/gc-idle-time-handler.cc

index 195a88d..b4f2f74 100644 (file)
@@ -315,5 +315,34 @@ TEST_F(GCIdleTimeHandlerTest, ScavengeAndDone) {
   EXPECT_EQ(DO_NOTHING, action.type);
 }
 
+
+TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeNothingToDo) {
+  GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+  int idle_time_ms = 0;
+  GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+  EXPECT_EQ(DO_NOTHING, action.type);
+}
+
+
+TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeDoNothingButStartIdleRound) {
+  GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+  int idle_time_ms = 10;
+  for (int i = 0; i < GCIdleTimeHandler::kMaxMarkCompactsInIdleRound; i++) {
+    GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+    if (action.type == DONE) break;
+    EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
+    // In this case we try to emulate incremental marking steps the finish with
+    // a full gc.
+    handler()->NotifyIdleMarkCompact();
+  }
+  GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
+  // Emulate mutator work.
+  for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) {
+    handler()->NotifyScavenge();
+  }
+  action = handler()->Compute(0, heap_state);
+  EXPECT_EQ(DO_NOTHING, action.type);
+}
+
 }  // namespace internal
 }  // namespace v8
index 8cce929..7c74dcb 100644 (file)
@@ -126,6 +126,10 @@ GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms,
     }
   }
 
+  if (idle_time_in_ms == 0) {
+    return GCIdleTimeAction::Nothing();
+  }
+
   if (heap_state.incremental_marking_stopped) {
     size_t estimated_time_in_ms =
         EstimateMarkCompactTime(heap_state.size_of_objects,