Reviewers: Michael Starzinger,

Description:
Last active parallel sweeper thread releases evacuation candidates.

BUG=


Please review this at https://chromiumcodereview.appspot.com/12082101/

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

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


Index: src/mark-compact.cc
diff --git a/src/mark-compact.cc b/src/mark-compact.cc
index 4dc4a95c8de2ab9b830c365a4b498fffb06e7d38..10e591e9b9587d225c34a460eadb3c38cbceb9f7 100644
--- a/src/mark-compact.cc
+++ b/src/mark-compact.cc
@@ -505,7 +505,7 @@ void MarkCompactCollector::ClearMarkbits() {


 void MarkCompactCollector::StartSweeperThreads() {
-  SweeperThread::set_sweeping_pending(true);
+  SweeperThread::Prepare();
   for (int i = 0; i < FLAG_sweeper_threads; i++) {
     heap()->isolate()->sweeper_threads()[i]->StartSweeping();
   }
@@ -517,7 +517,7 @@ void MarkCompactCollector::WaitUntilSweepingCompleted() {
     for (int i = 0; i < FLAG_sweeper_threads; i++) {
       heap()->isolate()->sweeper_threads()[i]->WaitForSweeperThread();
     }
-    SweeperThread::set_sweeping_pending(false);
+    SweeperThread::Finalize();
     StealMemoryFromSweeperThreads(heap()->paged_space(OLD_DATA_SPACE));
     StealMemoryFromSweeperThreads(heap()->paged_space(OLD_POINTER_SPACE));
     heap()->FreeQueuedChunks();
@@ -3241,6 +3241,14 @@ void MarkCompactCollector::EvacuateNewSpaceAndCandidates() {

   slots_buffer_allocator_.DeallocateChain(&migration_slots_buffer_);
   ASSERT(migration_slots_buffer_ == NULL);
+  if (!AreSweeperThreadsActivated()) {
+    ReleaseEvacuationCandidates();
+  }
+}
+
+
+void MarkCompactCollector::ReleaseEvacuationCandidates() {
+  int npages = evacuation_candidates_.length();
   for (int i = 0; i < npages; i++) {
     Page* p = evacuation_candidates_[i];
     if (!p->IsEvacuationCandidate()) continue;
Index: src/mark-compact.h
diff --git a/src/mark-compact.h b/src/mark-compact.h
index 0c98016fd2b2246470752fa30d857e3525aac7eb..2b0d7e072e0ef0ff2bcb6c6d567546c8a799c9b3 100644
--- a/src/mark-compact.h
+++ b/src/mark-compact.h
@@ -690,6 +690,8 @@ class MarkCompactCollector {

   bool AreSweeperThreadsActivated();

+  void ReleaseEvacuationCandidates();
+
  private:
   MarkCompactCollector();
   ~MarkCompactCollector();
Index: src/sweeper-thread.cc
diff --git a/src/sweeper-thread.cc b/src/sweeper-thread.cc
index 7e31e6cb56da937def85328f31ee7ce6d45f5a3e..73880760f911ad9e020d398a7193d7b77ffc5d58 100644
--- a/src/sweeper-thread.cc
+++ b/src/sweeper-thread.cc
@@ -55,6 +55,9 @@ SweeperThread::SweeperThread(Isolate* isolate)
 bool SweeperThread::sweeping_pending_ = false;


+volatile AtomicWord SweeperThread::active_threads_ = 0;
+
+
 void SweeperThread::Run() {
   Isolate::SetIsolateThreadLocals(isolate_, NULL);
   while (true) {
@@ -71,6 +74,11 @@ void SweeperThread::Run() {
     collector_->SweepInParallel(heap_->old_pointer_space(),
                                 &private_free_list_old_pointer_space_,
                                 &free_list_old_pointer_space_);
+
+    if (NoBarrier_AtomicIncrement(&active_threads_, -1) == 0) {
+      collector_->ReleaseEvacuationCandidates();
+    }
+
     end_sweeping_semaphore_->Signal();
   }
 }
Index: src/sweeper-thread.h
diff --git a/src/sweeper-thread.h b/src/sweeper-thread.h
index ba793c2043bd2724132bb7ab4dbaafcd55044468..4b98a43af6537fd30c185a86a20f1d42d2e17db5 100644
--- a/src/sweeper-thread.h
+++ b/src/sweeper-thread.h
@@ -50,11 +50,18 @@ class SweeperThread : public Thread {
   void WaitForSweeperThread();
   intptr_t StealMemory(PagedSpace* space);

-  static bool sweeping_pending() { return sweeping_pending_; }
-  static void set_sweeping_pending(bool sweeping_pending) {
-    sweeping_pending_ = sweeping_pending;
+  static void Prepare() {
+    sweeping_pending_ = true;
+    NoBarrier_Store(&active_threads_,
+                    static_cast<AtomicWord>(FLAG_sweeper_threads));
+  }
+
+  static void Finalize() {
+    sweeping_pending_ = false;
   }

+  static bool sweeping_pending() { return sweeping_pending_; }
+
   ~SweeperThread() {
     delete start_sweeping_semaphore_;
     delete end_sweeping_semaphore_;
@@ -74,6 +81,7 @@ class SweeperThread : public Thread {
   FreeList private_free_list_old_pointer_space_;
   volatile AtomicWord stop_thread_;
   static bool sweeping_pending_;
+  volatile static AtomicWord active_threads_;
 };

 } }  // namespace v8::internal


--
--
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