Revision: 13569
Author:   [email protected]
Date:     Thu Jan 31 06:23:36 2013
Log:      Added parallel marking threads.

BUG=

Review URL: https://codereview.chromium.org/12047044
http://code.google.com/p/v8/source/detail?r=13569

Added:
 /branches/bleeding_edge/src/marking-thread.cc
 /branches/bleeding_edge/src/marking-thread.h
Modified:
 /branches/bleeding_edge/src/flag-definitions.h
 /branches/bleeding_edge/src/isolate.cc
 /branches/bleeding_edge/src/isolate.h
 /branches/bleeding_edge/src/mark-compact.cc
 /branches/bleeding_edge/src/mark-compact.h
 /branches/bleeding_edge/tools/gyp/v8.gyp

=======================================
--- /dev/null
+++ /branches/bleeding_edge/src/marking-thread.cc       Thu Jan 31 06:23:36 2013
@@ -0,0 +1,85 @@
+// Copyright 2013 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "marking-thread.h"
+
+#include "v8.h"
+
+#include "isolate.h"
+#include "v8threads.h"
+
+namespace v8 {
+namespace internal {
+
+MarkingThread::MarkingThread(Isolate* isolate)
+     : Thread("MarkingThread"),
+       isolate_(isolate),
+       heap_(isolate->heap()),
+       start_marking_semaphore_(OS::CreateSemaphore(0)),
+       end_marking_semaphore_(OS::CreateSemaphore(0)),
+       stop_semaphore_(OS::CreateSemaphore(0)) {
+  NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(false));
+  id_ = NoBarrier_AtomicIncrement(&id_counter_, 1);
+}
+
+
+Atomic32 MarkingThread::id_counter_ = -1;
+
+
+void MarkingThread::Run() {
+  Isolate::SetIsolateThreadLocals(isolate_, NULL);
+
+  while (true) {
+    start_marking_semaphore_->Wait();
+
+    if (Acquire_Load(&stop_thread_)) {
+      stop_semaphore_->Signal();
+      return;
+    }
+
+    end_marking_semaphore_->Signal();
+  }
+}
+
+
+void MarkingThread::Stop() {
+  Release_Store(&stop_thread_, static_cast<AtomicWord>(true));
+  start_marking_semaphore_->Signal();
+  stop_semaphore_->Wait();
+}
+
+
+void MarkingThread::StartMarking() {
+  start_marking_semaphore_->Signal();
+}
+
+
+void MarkingThread::WaitForMarkingThread() {
+  end_marking_semaphore_->Wait();
+}
+
+} }  // namespace v8::internal
=======================================
--- /dev/null
+++ /branches/bleeding_edge/src/marking-thread.h        Thu Jan 31 06:23:36 2013
@@ -0,0 +1,71 @@
+// Copyright 2013 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef V8_MARKING_THREAD_H_
+#define V8_MARKING_THREAD_H_
+
+#include "atomicops.h"
+#include "flags.h"
+#include "platform.h"
+#include "v8utils.h"
+
+#include "spaces.h"
+
+#include "heap.h"
+
+namespace v8 {
+namespace internal {
+
+class MarkingThread : public Thread {
+ public:
+  explicit MarkingThread(Isolate* isolate);
+
+  void Run();
+  void Stop();
+  void StartMarking();
+  void WaitForMarkingThread();
+
+  ~MarkingThread() {
+    delete start_marking_semaphore_;
+    delete end_marking_semaphore_;
+    delete stop_semaphore_;
+  }
+
+ private:
+  Isolate* isolate_;
+  Heap* heap_;
+  Semaphore* start_marking_semaphore_;
+  Semaphore* end_marking_semaphore_;
+  Semaphore* stop_semaphore_;
+  volatile AtomicWord stop_thread_;
+  int id_;
+  static Atomic32 id_counter_;
+};
+
+} }  // namespace v8::internal
+
+#endif  // V8_MARKING_THREAD_H_
=======================================
--- /branches/bleeding_edge/src/flag-definitions.h      Wed Jan 30 04:19:32 2013
+++ /branches/bleeding_edge/src/flag-definitions.h      Thu Jan 31 06:23:36 2013
@@ -421,6 +421,8 @@
 DEFINE_bool(concurrent_sweeping, false, "enable concurrent sweeping")
 DEFINE_int(sweeper_threads, 1,
            "number of parallel and concurrent sweeping threads")
+DEFINE_bool(parallel_marking, false, "enable parallel marking")
+DEFINE_int(marking_threads, 1, "number of parallel marking threads")
 #ifdef VERIFY_HEAP
 DEFINE_bool(verify_heap, false, "verify heap pointers before and after GC")
 #endif
=======================================
--- /branches/bleeding_edge/src/isolate.cc      Wed Jan 30 07:50:09 2013
+++ /branches/bleeding_edge/src/isolate.cc      Thu Jan 31 06:23:36 2013
@@ -40,6 +40,7 @@
 #include "isolate.h"
 #include "lithium-allocator.h"
 #include "log.h"
+#include "marking-thread.h"
 #include "messages.h"
 #include "platform.h"
 #include "regexp-stack.h"
@@ -1653,6 +1654,7 @@
       context_exit_happened_(false),
       deferred_handles_head_(NULL),
       optimizing_compiler_thread_(this),
+      marking_thread_(NULL),
       sweeper_thread_(NULL) {
   TRACE_ISOLATE(constructor);

@@ -1744,6 +1746,14 @@
       }
       delete[] sweeper_thread_;
     }
+
+    if (FLAG_parallel_marking) {
+      for (int i = 0; i < FLAG_marking_threads; i++) {
+        marking_thread_[i]->Stop();
+        delete marking_thread_[i];
+      }
+      delete[] marking_thread_;
+    }

     if (FLAG_parallel_recompilation) optimizing_compiler_thread_.Stop();

@@ -2115,6 +2125,17 @@

   if (FLAG_parallel_recompilation) optimizing_compiler_thread_.Start();

+  if (FLAG_parallel_marking) {
+    if (FLAG_marking_threads < 1) {
+      FLAG_marking_threads = 1;
+    }
+    marking_thread_ = new MarkingThread*[FLAG_marking_threads];
+    for (int i = 0; i < FLAG_marking_threads; i++) {
+      marking_thread_[i] = new MarkingThread(this);
+      marking_thread_[i]->Start();
+    }
+  }
+
   if (FLAG_parallel_sweeping || FLAG_concurrent_sweeping) {
     if (FLAG_sweeper_threads < 1) {
       FLAG_sweeper_threads = 1;
=======================================
--- /branches/bleeding_edge/src/isolate.h       Wed Jan 30 07:07:58 2013
+++ /branches/bleeding_edge/src/isolate.h       Thu Jan 31 06:23:36 2013
@@ -71,6 +71,7 @@
 class InlineRuntimeFunctionsTable;
 class NoAllocationStringAllocator;
 class InnerPointerToCodeCache;
+class MarkingThread;
 class PreallocatedMemoryThread;
 class RegExpStack;
 class SaveContext;
@@ -1074,6 +1075,10 @@
   // TODO(svenpanne) This method is on death row...
   static v8::Isolate* GetDefaultIsolateForLocking();

+  MarkingThread** marking_threads() {
+    return marking_thread_;
+  }
+
   SweeperThread** sweeper_threads() {
     return sweeper_thread_;
   }
@@ -1301,11 +1306,13 @@

   DeferredHandles* deferred_handles_head_;
   OptimizingCompilerThread optimizing_compiler_thread_;
+  MarkingThread** marking_thread_;
   SweeperThread** sweeper_thread_;

   friend class ExecutionAccess;
   friend class HandleScopeImplementer;
   friend class IsolateInitializer;
+  friend class MarkingThread;
   friend class OptimizingCompilerThread;
   friend class SweeperThread;
   friend class ThreadManager;
=======================================
--- /branches/bleeding_edge/src/mark-compact.cc Wed Jan 30 05:13:04 2013
+++ /branches/bleeding_edge/src/mark-compact.cc Thu Jan 31 06:23:36 2013
@@ -37,6 +37,7 @@
 #include "ic-inl.h"
 #include "incremental-marking.h"
 #include "mark-compact.h"
+#include "marking-thread.h"
 #include "objects-visiting.h"
 #include "objects-visiting-inl.h"
 #include "stub-cache.h"
@@ -538,6 +539,20 @@
 bool MarkCompactCollector::AreSweeperThreadsActivated() {
   return heap()->isolate()->sweeper_threads() != NULL;
 }
+
+
+void MarkCompactCollector::MarkInParallel() {
+  for (int i = 0; i < FLAG_marking_threads; i++) {
+    heap()->isolate()->marking_threads()[i]->StartMarking();
+  }
+}
+
+
+void MarkCompactCollector::WaitUntilMarkingCompleted() {
+  for (int i = 0; i < FLAG_marking_threads; i++) {
+    heap()->isolate()->marking_threads()[i]->WaitForMarkingThread();
+  }
+}


 bool Marking::TransferMark(Address old_start, Address new_start) {
=======================================
--- /branches/bleeding_edge/src/mark-compact.h  Wed Jan 30 04:19:32 2013
+++ /branches/bleeding_edge/src/mark-compact.h  Thu Jan 31 06:23:36 2013
@@ -680,6 +680,7 @@

   MarkingParity marking_parity() { return marking_parity_; }

+  // Concurrent and parallel sweeping support.
   void SweepInParallel(PagedSpace* space,
                        FreeList* private_free_list,
                        FreeList* free_list);
@@ -690,6 +691,11 @@

   bool AreSweeperThreadsActivated();

+  // Parallel marking support.
+  void MarkInParallel();
+
+  void WaitUntilMarkingCompleted();
+
  private:
   MarkCompactCollector();
   ~MarkCompactCollector();
=======================================
--- /branches/bleeding_edge/tools/gyp/v8.gyp    Wed Jan 30 04:19:32 2013
+++ /branches/bleeding_edge/tools/gyp/v8.gyp    Thu Jan 31 06:23:36 2013
@@ -382,6 +382,8 @@
             '../../src/macro-assembler.h',
             '../../src/mark-compact.cc',
             '../../src/mark-compact.h',
+            '../../src/marking-thread.h',
+            '../../src/marking-thread.cc',
             '../../src/messages.cc',
             '../../src/messages.h',
             '../../src/natives.h',

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