[vmkit-commits] [vmkit] r120579 - in /vmkit/branches/multi-vm: include/mvm/Threads/CollectionRV.h include/mvm/VirtualMachine.h lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/VMCore/Jnjvm.cpp lib/Mvm/CommonThread/CollectionRV.cpp lib/Mvm/CommonThread/ctthread.cpp mmtk/mmtk-j3/ActivePlan.cpp

Gael Thomas gael.thomas at lip6.fr
Wed Dec 1 08:50:10 PST 2010


Author: gthomas
Date: Wed Dec  1 10:50:10 2010
New Revision: 120579

URL: http://llvm.org/viewvc/llvm-project?rev=120579&view=rev
Log:
move the linked list of threads in CollectionRV

Modified:
    vmkit/branches/multi-vm/include/mvm/Threads/CollectionRV.h
    vmkit/branches/multi-vm/include/mvm/VirtualMachine.h
    vmkit/branches/multi-vm/lib/J3/Compiler/JavaAOTCompiler.cpp
    vmkit/branches/multi-vm/lib/J3/VMCore/Jnjvm.cpp
    vmkit/branches/multi-vm/lib/Mvm/CommonThread/CollectionRV.cpp
    vmkit/branches/multi-vm/lib/Mvm/CommonThread/ctthread.cpp
    vmkit/branches/multi-vm/mmtk/mmtk-j3/ActivePlan.cpp

Modified: vmkit/branches/multi-vm/include/mvm/Threads/CollectionRV.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/include/mvm/Threads/CollectionRV.h?rev=120579&r1=120578&r2=120579&view=diff
==============================================================================
--- vmkit/branches/multi-vm/include/mvm/Threads/CollectionRV.h (original)
+++ vmkit/branches/multi-vm/include/mvm/Threads/CollectionRV.h Wed Dec  1 10:50:10 2010
@@ -17,7 +17,17 @@
 namespace mvm {
 
 class CollectionRV {
+public:
+  /// oneThread - The main thread of this VM.
+  mvm::Thread* oneThread;
+
 protected: 
+  /// numberOfThreads - The number of threads that currently run under this VM.
+  uint32_t numberOfThreads;
+
+  /// threadLock - Lock to create or destroy a new thread.
+  mvm::SpinLock threadLock;
+
   /// _lockRV - Lock for synchronization.
   LockNormal _lockRV;         
   
@@ -33,6 +43,8 @@
 public: 
   CollectionRV() {
     nbJoined = 0;
+    oneThread = 0;
+    numberOfThreads = 0;
   }
 
   void lockRV() { _lockRV.lock(); }
@@ -60,7 +72,14 @@
   virtual void joinAfterUncooperative(void* SP) = 0;
   virtual void joinBeforeUncooperative() = 0;
 
-  virtual void addThread(Thread* th) = 0;
+  /// addThread - Add a new thread to the list of threads.
+  void addThread(mvm::Thread* th);
+  
+  /// removeThread - Remove the thread from the list of threads.
+  void removeThread(mvm::Thread* th);
+
+  /// prepareForJoin - for uncooperative gc, prepare the SIGGC handler
+	virtual void prepareForJoin() = 0;
 };
 
 class CooperativeCollectionRV : public CollectionRV {
@@ -71,7 +90,7 @@
   void join();
   void joinAfterUncooperative(void* SP);
   void joinBeforeUncooperative();
-  void addThread(Thread* th);
+	void prepareForJoin();
 };
 
 class UncooperativeCollectionRV : public CollectionRV {
@@ -82,7 +101,7 @@
   void join();
   void joinAfterUncooperative(void* SP);
   void joinBeforeUncooperative();
-  void addThread(Thread* th);
+  void prepareForJoin();
 };
 
 

Modified: vmkit/branches/multi-vm/include/mvm/VirtualMachine.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/include/mvm/VirtualMachine.h?rev=120579&r1=120578&r2=120579&view=diff
==============================================================================
--- vmkit/branches/multi-vm/include/mvm/VirtualMachine.h (original)
+++ vmkit/branches/multi-vm/include/mvm/VirtualMachine.h Wed Dec  1 10:50:10 2010
@@ -56,8 +56,6 @@
 protected:
   VirtualMachine(mvm::BumpPtrAllocator &Alloc, mvm::VMKit* vmk) :
 		  allocator(Alloc) {
-    mainThread = 0;
-    NumberOfThreads = 0;
 		vmkit = vmk;
   }
 
@@ -71,55 +69,13 @@
   ///
   mvm::BumpPtrAllocator& allocator;
 
-//===----------------------------------------------------------------------===//
-// (1) Thread-related methods.
-//===----------------------------------------------------------------------===//
-
-  /// mainThread - The main thread of this VM.
-  ///
-  mvm::Thread* mainThread;
-
-  /// NumberOfThreads - The number of threads that currently run under this VM.
-  ///
-  uint32_t NumberOfThreads;
-
-  /// ThreadLock - Lock to create or destroy a new thread.
-  ///
-  mvm::SpinLock ThreadLock;
-
 	/// vmkit - a pointer to vmkit that contains information on all the vms
+	///
 	mvm::VMKit* vmkit;
-  
-  /// setMainThread - Set the main thread of this VM.
-  ///
-  void setMainThread(mvm::Thread* th) { mainThread = th; }
-  
-  /// getMainThread - Get the main thread of this VM.
-  ///
-  mvm::Thread* getMainThread() const { return mainThread; }
 
-  /// addThread - Add a new thread to the list of threads.
-  ///
-  void addThread(mvm::Thread* th) {
-    ThreadLock.lock();
-    NumberOfThreads++;
-    if (th != mainThread) {
-      if (mainThread) th->append(mainThread);
-      else mainThread = th;
-    }
-    ThreadLock.unlock();
-  }
-  
-  /// removeThread - Remove the thread from the list of threads.
-  ///
-  void removeThread(mvm::Thread* th) {
-    ThreadLock.lock();
-    NumberOfThreads--;
-    if (mainThread == th) mainThread = (Thread*)th->next();
-    th->remove();
-    if (!NumberOfThreads) mainThread = 0;
-    ThreadLock.unlock();
-  }
+//===----------------------------------------------------------------------===//
+// (1) Thread-related methods.
+//===----------------------------------------------------------------------===//
 
 //===----------------------------------------------------------------------===//
 // (2) GC-related methods.

Modified: vmkit/branches/multi-vm/lib/J3/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=120579&r1=120578&r2=120579&view=diff
==============================================================================
--- vmkit/branches/multi-vm/lib/J3/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/branches/multi-vm/lib/J3/Compiler/JavaAOTCompiler.cpp Wed Dec  1 10:50:10 2010
@@ -2134,7 +2134,6 @@
 void JavaAOTCompiler::compileFile(Jnjvm* vm, const char* n) {
   name = n;
 	vm->javaMainThread = JavaThread::create(vm);
-  vm->mainThread = vm->javaMainThread->mut;
   vm->javaMainThread->mut->start(mainCompilerStart);
   vm->waitForExit();
 }

Modified: vmkit/branches/multi-vm/lib/J3/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/lib/J3/VMCore/Jnjvm.cpp?rev=120579&r1=120578&r2=120579&view=diff
==============================================================================
--- vmkit/branches/multi-vm/lib/J3/VMCore/Jnjvm.cpp (original)
+++ vmkit/branches/multi-vm/lib/J3/VMCore/Jnjvm.cpp Wed Dec  1 10:50:10 2010
@@ -1342,8 +1342,7 @@
   argumentsInfo.argc = argc;
   argumentsInfo.argv = argv;
   javaMainThread = JavaThread::create(this);
-	mainThread = javaMainThread->mut;
-  mainThread->start((void (*)(mvm::Thread*))mainJavaStart);
+  javaMainThread->mut->start((void (*)(mvm::Thread*))mainJavaStart);
 }
 
 Jnjvm::Jnjvm(mvm::BumpPtrAllocator& Alloc, mvm::VMKit* vmkit, JnjvmBootstrapLoader* loader) : 

Modified: vmkit/branches/multi-vm/lib/Mvm/CommonThread/CollectionRV.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/lib/Mvm/CommonThread/CollectionRV.cpp?rev=120579&r1=120578&r2=120579&view=diff
==============================================================================
--- vmkit/branches/multi-vm/lib/Mvm/CommonThread/CollectionRV.cpp (original)
+++ vmkit/branches/multi-vm/lib/Mvm/CommonThread/CollectionRV.cpp Wed Dec  1 10:50:10 2010
@@ -17,12 +17,30 @@
 
 using namespace mvm;
 
+void CollectionRV::addThread(mvm::Thread* th) {
+	threadLock.lock();
+	numberOfThreads++;
+	if (th != oneThread) {
+		if (oneThread) th->append(oneThread);
+		else oneThread = th;
+	}
+	threadLock.unlock();
+}
+  
+void CollectionRV::removeThread(mvm::Thread* th) {
+	threadLock.lock();
+	numberOfThreads--;
+	if (oneThread == th) oneThread = (Thread*)th->next();
+	th->remove();
+	if (!numberOfThreads) oneThread = 0;
+	threadLock.unlock();
+}
+
 void CollectionRV::another_mark() {
-  mvm::Thread* th = mvm::Thread::get();
   assert(th->getLastSP() != NULL);
   assert(nbJoined < th->MyVM->NumberOfThreads);
   nbJoined++;
-  if (nbJoined == th->MyVM->NumberOfThreads) {
+  if (nbJoined == numberOfThreads) {
     condInitiator.broadcast();
   }
 }
@@ -37,11 +55,10 @@
 }
 
 void CollectionRV::waitRV() {
-  mvm::Thread* self = mvm::Thread::get(); 
   // Add myself.
   nbJoined++;
 
-  while (nbJoined != self->MyVM->NumberOfThreads) {
+  while (nbJoined != numberOfThreads) {
     condInitiator.wait(&_lockRV);
   } 
 }
@@ -51,7 +68,7 @@
   mvm::Thread* self = mvm::Thread::get();
   // Lock thread lock, so that we can traverse the thread list safely. This will
   // be released on finishRV.
-  self->MyVM->ThreadLock.lock();
+ threadLock.lock();
 
   mvm::Thread* cur = self;
   do {
@@ -93,7 +110,7 @@
   mvm::Thread* self = mvm::Thread::get();
   // Lock thread lock, so that we can traverse the thread list safely. This will
   // be released on finishRV.
-  self->MyVM->ThreadLock.lock();
+  threadLock.lock();
   
   for (mvm::Thread* cur = (mvm::Thread*)self->next(); cur != self; 
        cur = (mvm::Thread*)cur->next()) {
@@ -205,18 +222,22 @@
 
   assert(nbJoined == initiator->MyVM->NumberOfThreads && "Inconsistent state");
   nbJoined = 0;
-  initiator->MyVM->ThreadLock.unlock();
+  threadLock.unlock();
   condEndRV.broadcast();
   unlockRV();
   initiator->inRV = false;
 }
 
+void CooperativeCollectionRV::prepareForJoin() {
+	/// nothing to do
+}
+
 void UncooperativeCollectionRV::finishRV() {
   lockRV();
   mvm::Thread* initiator = mvm::Thread::get();
   assert(nbJoined == initiator->MyVM->NumberOfThreads && "Inconsistent state");
   nbJoined = 0;
-  initiator->MyVM->ThreadLock.unlock();
+  threadLock.unlock();
   condEndRV.broadcast();
   unlockRV();
   initiator->inRV = false;
@@ -230,16 +251,12 @@
   UNREACHABLE();
 }
 
-void CooperativeCollectionRV::addThread(Thread* th) {
-  // Nothing to do.
-}
-
 static void siggcHandler(int) {
   mvm::Thread* th = mvm::Thread::get();
   th->MyVM->rendezvous.join();
 }
 
-void UncooperativeCollectionRV::addThread(Thread* th) {
+void UncooperativeCollectionRV::prepareForJoin() {
   // Set the SIGGC handler for uncooperative rendezvous.
   struct sigaction sa;
   sigset_t mask;

Modified: vmkit/branches/multi-vm/lib/Mvm/CommonThread/ctthread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/lib/Mvm/CommonThread/ctthread.cpp?rev=120579&r1=120578&r2=120579&view=diff
==============================================================================
--- vmkit/branches/multi-vm/lib/Mvm/CommonThread/ctthread.cpp (original)
+++ vmkit/branches/multi-vm/lib/Mvm/CommonThread/ctthread.cpp Wed Dec  1 10:50:10 2010
@@ -428,9 +428,9 @@
 #ifdef ISOLATE
   th->IsolateID = th->MyVM->IsolateID;
 #endif
-  th->MyVM->rendezvous.addThread(th);
+  th->MyVM->rendezvous.prepareForJoin();
   th->routine(th);
-  th->MyVM->removeThread(th);
+  th->MyVM->rendezvous.removeThread(th);
 }
 
 
@@ -445,7 +445,7 @@
   routine = fct;
   // Make sure to add it in the list of threads before leaving this function:
   // the garbage collector wants to trace this thread.
-  MyVM->addThread(this);
+  MyVM->rendezvous.addThread(this);
   int res = pthread_create((pthread_t*)(void*)(&internalThreadID), &attributs,
                            (void* (*)(void *))internalThreadStart, this);
   pthread_detach((pthread_t)internalThreadID);

Modified: vmkit/branches/multi-vm/mmtk/mmtk-j3/ActivePlan.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/mmtk/mmtk-j3/ActivePlan.cpp?rev=120579&r1=120578&r2=120579&view=diff
==============================================================================
--- vmkit/branches/multi-vm/mmtk/mmtk-j3/ActivePlan.cpp (original)
+++ vmkit/branches/multi-vm/mmtk/mmtk-j3/ActivePlan.cpp Wed Dec  1 10:50:10 2010
@@ -18,8 +18,8 @@
   assert(A && "No active plan");
   
   if (A->current == NULL) {
-    A->current = (mvm::MutatorThread*)mvm::Thread::get()->MyVM->mainThread;
-  } else if (A->current->next() == mvm::Thread::get()->MyVM->mainThread) {
+    A->current = (mvm::MutatorThread*)mvm::Thread::get()->MyVM->rendezvous.oneThread;
+  } else if (A->current->next() == mvm::Thread::get()->MyVM->rendezvous.oneThread) {
     A->current = NULL;
     return NULL;
   } else {





More information about the vmkit-commits mailing list