Reviewers: Michael Starzinger,

Description:
Wait for sweeper threads in EnsureSweeperProgress() only if the main thread
finished its sweeping phase.

BUG=


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

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/mark-compact.h
  M src/mark-compact.cc
  M src/spaces.h
  M src/spaces.cc


Index: src/mark-compact.cc
diff --git a/src/mark-compact.cc b/src/mark-compact.cc
index ea797a5866a63fb26dd46b76baeadb85effeccc6..88d9de1813b4621e0570682c7f0c995832ad9a3e 100644
--- a/src/mark-compact.cc
+++ b/src/mark-compact.cc
@@ -67,6 +67,7 @@ MarkCompactCollector::MarkCompactCollector() :  // NOLINT
       compacting_(false),
       was_marked_incrementally_(false),
       sweeping_pending_(false),
+      sequential_sweeping_(false),
       tracer_(NULL),
       migration_slots_buffer_(NULL),
       heap_(NULL),
@@ -3895,37 +3896,38 @@ void MarkCompactCollector::SweepSpaces() {
   // the map space last because freeing non-live maps overwrites them and
   // the other spaces rely on possibly non-live maps to get the sizes for
   // non-live objects.
+  { SweepingScope scope(this);
+    SweepSpace(heap()->old_pointer_space(), how_to_sweep);
+    SweepSpace(heap()->old_data_space(), how_to_sweep);
+
+    if (how_to_sweep == PARALLEL_CONSERVATIVE ||
+        how_to_sweep == CONCURRENT_CONSERVATIVE) {
+      // TODO(hpayer): fix race with concurrent sweeper
+      StartSweeperThreads();
+    }

-  SweepSpace(heap()->old_pointer_space(), how_to_sweep);
-  SweepSpace(heap()->old_data_space(), how_to_sweep);
-
-  if (how_to_sweep == PARALLEL_CONSERVATIVE ||
-      how_to_sweep == CONCURRENT_CONSERVATIVE) {
-    // TODO(hpayer): fix race with concurrent sweeper
-    StartSweeperThreads();
-  }
-
-  if (how_to_sweep == PARALLEL_CONSERVATIVE) {
-    WaitUntilSweepingCompleted();
-  }
+    if (how_to_sweep == PARALLEL_CONSERVATIVE) {
+      WaitUntilSweepingCompleted();
+    }

-  RemoveDeadInvalidatedCode();
-  SweepSpace(heap()->code_space(), PRECISE);
+    RemoveDeadInvalidatedCode();
+    SweepSpace(heap()->code_space(), PRECISE);

-  SweepSpace(heap()->cell_space(), PRECISE);
+    SweepSpace(heap()->cell_space(), PRECISE);

-  EvacuateNewSpaceAndCandidates();
+    EvacuateNewSpaceAndCandidates();

-  // ClearNonLiveTransitions depends on precise sweeping of map space to
-  // detect whether unmarked map became dead in this collection or in one
-  // of the previous ones.
-  SweepSpace(heap()->map_space(), PRECISE);
+    // ClearNonLiveTransitions depends on precise sweeping of map space to
+    // detect whether unmarked map became dead in this collection or in one
+    // of the previous ones.
+    SweepSpace(heap()->map_space(), PRECISE);

-  // Deallocate unmarked objects and clear marked bits for marked objects.
-  heap_->lo_space()->FreeUnmarkedObjects();
+ // Deallocate unmarked objects and clear marked bits for marked objects.
+    heap_->lo_space()->FreeUnmarkedObjects();

-  if (how_to_sweep != CONCURRENT_CONSERVATIVE) {
-    FinalizeSweeping();
+    if (how_to_sweep != CONCURRENT_CONSERVATIVE) {
+      FinalizeSweeping();
+    }
   }
 }

Index: src/mark-compact.h
diff --git a/src/mark-compact.h b/src/mark-compact.h
index b5d60fd41e80f81f5395dff0ee0f665dc161c8d2..f349bb3d7ac61fc1e7aa55f3e2b2ebca04b7c3d8 100644
--- a/src/mark-compact.h
+++ b/src/mark-compact.h
@@ -698,6 +698,14 @@ class MarkCompactCollector {

   void FinalizeSweeping();

+  void set_sequential_sweeping(bool sequential_sweeping) {
+    sequential_sweeping_ = sequential_sweeping;
+  }
+
+  bool sequential_sweeping() const {
+    return sequential_sweeping_;
+  }
+
   // Parallel marking support.
   void MarkInParallel();

@@ -749,6 +757,8 @@ class MarkCompactCollector {
   // True if concurrent or parallel sweeping is currently in progress.
   bool sweeping_pending_;

+  bool sequential_sweeping_;
+
// A pointer to the current stack-allocated GC tracer object during a full
   // collection (NULL before and after).
   GCTracer* tracer_;
@@ -904,6 +914,22 @@ class MarkCompactCollector {
 };


+class SweepingScope BASE_EMBEDDED {
+ public:
+  explicit SweepingScope(MarkCompactCollector *collector) :
+    collector_(collector) {
+    collector_->set_sequential_sweeping(true);
+  }
+
+  ~SweepingScope() {
+    collector_->set_sequential_sweeping(false);
+  }
+
+ private:
+  MarkCompactCollector* collector_;
+};
+
+
 const char* AllocationSpaceName(AllocationSpace space);

 } }  // namespace v8::internal
Index: src/spaces.cc
diff --git a/src/spaces.cc b/src/spaces.cc
index 0af587d2052263e6168b65cb1573ceb5a99203c4..1861c5340391d50db9d7c2ac3e51ce6dd6f2d0da 100644
--- a/src/spaces.cc
+++ b/src/spaces.cc
@@ -2553,9 +2553,11 @@ bool PagedSpace::EnsureSweeperProgress(intptr_t size_in_bytes) {
   if (collector->AreSweeperThreadsActivated()) {
     if (collector->IsConcurrentSweepingInProgress()) {
       if (collector->StealMemoryFromSweeperThreads(this) < size_in_bytes) {
-        collector->WaitUntilSweepingCompleted();
-        collector->FinalizeSweeping();
-        return true;
+        if (!collector->sequential_sweeping()) {
+          collector->WaitUntilSweepingCompleted();
+          collector->FinalizeSweeping();
+          return true;
+        }
       }
       return false;
     }
Index: src/spaces.h
diff --git a/src/spaces.h b/src/spaces.h
index fe22341308f029dd8dd15128f0c7682056b8630e..6ff3ee3694dccd769a61bbc35342b66a317342f7 100644
--- a/src/spaces.h
+++ b/src/spaces.h
@@ -1765,9 +1765,9 @@ class PagedSpace : public Space {

   bool AdvanceSweeper(intptr_t bytes_to_sweep);

-  // When parallel sweeper threads are active this function waits
-  // for them to complete, otherwise AdvanceSweeper with size_in_bytes
-  // is called.
+  // When parallel sweeper threads are active and the main thread finished
+ // its sweeping phase, this function waits for them to complete, otherwise
+  // AdvanceSweeper with size_in_bytes is called.
   bool EnsureSweeperProgress(intptr_t size_in_bytes);

   bool IsLazySweepingComplete() {


--
--
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/groups/opt_out.


Reply via email to