Reviewers: ulan, rmcilroy,

Description:
Finalize sweeping in idle notification when all pages are swept.

A follow-up CL will implement incremental sweeping during idle time.

BUG=

Please review this at https://codereview.chromium.org/1038283003/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+52, -8 lines):
  M src/heap/gc-idle-time-handler.h
  M src/heap/gc-idle-time-handler.cc
  M src/heap/heap.cc
  M src/heap/mark-compact.h
  M src/heap/mark-compact.cc
  M src/heap/spaces.h
  M src/heap/spaces.cc
  M test/unittests/heap/gc-idle-time-handler-unittest.cc


Index: src/heap/gc-idle-time-handler.cc
diff --git a/src/heap/gc-idle-time-handler.cc b/src/heap/gc-idle-time-handler.cc index 80417a7f25dcf81c20ebf6b8916f3855a82f5278..92c7a1c41ea95f7d2d018490aa840555f0bc8b8a 100644
--- a/src/heap/gc-idle-time-handler.cc
+++ b/src/heap/gc-idle-time-handler.cc
@@ -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.unswept_pages_left) {
     return GCIdleTimeAction::FinalizeSweeping();
   }

Index: src/heap/gc-idle-time-handler.h
diff --git a/src/heap/gc-idle-time-handler.h b/src/heap/gc-idle-time-handler.h index 6a39b78aaa2fcc24fd5210236f177bf0f9fffc14..9e02d89408b1cb408ed861531d986f6b4d4d56c8 100644
--- a/src/heap/gc-idle-time-handler.h
+++ b/src/heap/gc-idle-time-handler.h
@@ -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 unswept_pages_left;
     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: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 5af21e18c0df762e7efb97e2778e6e708ad8f066..103ba1d86f5f7246b3c33b4b02161b60a0bf5e5b 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -4616,6 +4616,7 @@ 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.unswept_pages_left = mark_compact_collector()->UnsweptPagesLeft();
   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: src/heap/mark-compact.cc
diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc
index 3d93c7ccc6dcb7d9175cfca258587a14b7a4847f..10af856b6d630761a829fb191efbac180cb52137 100644
--- a/src/heap/mark-compact.cc
+++ b/src/heap/mark-compact.cc
@@ -4210,6 +4210,12 @@ static inline int MarkWordToObjectStarts(uint32_t mark_bits, int* starts) {
 }


+bool MarkCompactCollector::UnsweptPagesLeft() {
+  return heap_->old_data_space()->UnsweptPagesLeft() ||
+         heap_->old_pointer_space()->UnsweptPagesLeft();
+}
+
+
 int MarkCompactCollector::SweepInParallel(PagedSpace* space,
                                           int required_freed_bytes) {
   int max_freed = 0;
Index: src/heap/mark-compact.h
diff --git a/src/heap/mark-compact.h b/src/heap/mark-compact.h
index ddb993f5a2f676491e732da2a1a39cae26c48b59..b3163e4ae973c58cc50bcc94c60cc7b935aca99e 100644
--- a/src/heap/mark-compact.h
+++ b/src/heap/mark-compact.h
@@ -633,6 +633,10 @@ class MarkCompactCollector {

   MarkingParity marking_parity() { return marking_parity_; }

+  // Returns true if one of the concurrently swept spaces has unswept pages
+  // left.
+  bool UnsweptPagesLeft();
+
// Concurrent and parallel sweeping support. If required_freed_bytes was set // to a value larger than 0, then sweeping returns after a block of at least // required_freed_bytes was freed. If required_freed_bytes was set to zero
Index: src/heap/spaces.cc
diff --git a/src/heap/spaces.cc b/src/heap/spaces.cc
index 6c2b58b17e5795995911aa6a992226ce8050ef18..fe28ef2317a507b9e3c4c195f835a3f61fb28d0c 100644
--- a/src/heap/spaces.cc
+++ b/src/heap/spaces.cc
@@ -2645,6 +2645,17 @@ HeapObject* PagedSpace::SlowAllocateRaw(int size_in_bytes) {
 }


+bool PagedSpace::UnsweptPagesLeft() {
+  PageIterator it(this);
+  while (it.has_next()) {
+    Page* p = it.next();
+    if (p->parallel_sweeping() >= Page::SWEEPING_FINALIZE) return true;
+    if (p == end_of_unswept_pages()) break;
+  }
+  return false;
+}
+
+
 #ifdef DEBUG
 void PagedSpace::ReportCodeStatistics(Isolate* isolate) {
   CommentStatistic* comments_statistics =
Index: src/heap/spaces.h
diff --git a/src/heap/spaces.h b/src/heap/spaces.h
index ec8821d7d8725b674ea4147c173690eb56ae717d..10f672a33d364a280b6b60addecaccf15440b26b 100644
--- a/src/heap/spaces.h
+++ b/src/heap/spaces.h
@@ -1928,6 +1928,9 @@ class PagedSpace : public Space {
   // Slow path of AllocateRaw.  This function is space-dependent.
   MUST_USE_RESULT HeapObject* SlowAllocateRaw(int size_in_bytes);

+  // Returns true if the space contains unswept pages.
+  bool UnsweptPagesLeft();
+
   friend class PageIterator;
   friend class MarkCompactCollector;
 };
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 b5f59bd5108f1792c24a70ece5499d97f3954c8d..777f73253257e8c7cfd8184446cbc4432e0d0b10 100644
--- a/test/unittests/heap/gc-idle-time-handler-unittest.cc
+++ b/test/unittests/heap/gc-idle-time-handler-unittest.cc
@@ -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.unswept_pages_left = 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.unswept_pages_left = false;
+  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.unswept_pages_left = true;
+  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;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to