Finalize sweeping in idle notification when all pages are swept.
authorhpayer <hpayer@chromium.org>
Mon, 30 Mar 2015 10:05:25 +0000 (03:05 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 30 Mar 2015 10:05:35 +0000 (10:05 +0000)
A follow-up CL will implement incremental sweeping during idle time.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#27513}

src/heap/gc-idle-time-handler.cc
src/heap/gc-idle-time-handler.h
src/heap/heap.cc
test/unittests/heap/gc-idle-time-handler-unittest.cc

index 80417a7..449429c 100644 (file)
@@ -12,7 +12,6 @@ namespace internal {
 const double GCIdleTimeHandler::kConservativeTimeRatio = 0.9;
 const size_t GCIdleTimeHandler::kMaxMarkCompactTimeInMs = 1000;
 const size_t GCIdleTimeHandler::kMaxFinalIncrementalMarkCompactTimeInMs = 1000;
-const size_t GCIdleTimeHandler::kMinTimeForFinalizeSweeping = 100;
 const int GCIdleTimeHandler::kMaxMarkCompactsInIdleRound = 2;
 const int GCIdleTimeHandler::kIdleScavengeThreshold = 5;
 const double GCIdleTimeHandler::kHighContextDisposalRate = 100;
@@ -241,9 +240,7 @@ GCIdleTimeAction GCIdleTimeHandler::Compute(double idle_time_in_ms,
     }
   }
 
-  // TODO(hpayer): Estimate finalize sweeping time.
-  if (heap_state.sweeping_in_progress &&
-      static_cast<size_t>(idle_time_in_ms) >= kMinTimeForFinalizeSweeping) {
+  if (heap_state.sweeping_in_progress && heap_state.sweeping_completed) {
     return GCIdleTimeAction::FinalizeSweeping();
   }
 
index 6a39b78..94e1e03 100644 (file)
@@ -111,10 +111,6 @@ class GCIdleTimeHandler {
   // EstimateFinalIncrementalMarkCompactTime.
   static const size_t kMaxFinalIncrementalMarkCompactTimeInMs;
 
-  // Minimum time to finalize sweeping phase. The main thread may wait for
-  // sweeper threads.
-  static const size_t kMinTimeForFinalizeSweeping;
-
   // Number of idle mark-compact events, after which idle handler will finish
   // idle round.
   static const int kMaxMarkCompactsInIdleRound;
@@ -148,6 +144,7 @@ class GCIdleTimeHandler {
     bool incremental_marking_stopped;
     bool can_start_incremental_marking;
     bool sweeping_in_progress;
+    bool sweeping_completed;
     size_t mark_compact_speed_in_bytes_per_ms;
     size_t incremental_marking_speed_in_bytes_per_ms;
     size_t final_incremental_mark_compact_speed_in_bytes_per_ms;
index edea473..e89aafa 100644 (file)
@@ -4629,6 +4629,8 @@ bool Heap::IdleNotification(double deadline_in_seconds) {
       !mark_compact_collector()->sweeping_in_progress();
   heap_state.sweeping_in_progress =
       mark_compact_collector()->sweeping_in_progress();
+  heap_state.sweeping_completed =
+      mark_compact_collector()->IsSweepingCompleted();
   heap_state.mark_compact_speed_in_bytes_per_ms =
       static_cast<size_t>(tracer()->MarkCompactSpeedInBytesPerMillisecond());
   heap_state.incremental_marking_speed_in_bytes_per_ms = static_cast<size_t>(
index b5f59bd..7642462 100644 (file)
@@ -27,6 +27,7 @@ class GCIdleTimeHandlerTest : public ::testing::Test {
     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;
     result.incremental_marking_speed_in_bytes_per_ms = kMarkingSpeed;
     result.scavenge_speed_in_bytes_per_ms = kScavengeSpeed;
@@ -303,6 +304,30 @@ TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) {
 }
 
 
+TEST_F(GCIdleTimeHandlerTest, FinalizeSweeping) {
+  GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
+  heap_state.incremental_marking_stopped = true;
+  heap_state.can_start_incremental_marking = false;
+  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;
+  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, StopEventually1) {
   GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
   heap_state.incremental_marking_stopped = true;