[vmkit-commits] [vmkit] r85398 - in /vmkit/trunk: include/mvm/Threads/CollectionRV.h include/mvm/Threads/Thread.h lib/Mvm/CommonThread/CollectionRV.cpp lib/Mvm/CommonThread/ctthread.cpp lib/Mvm/GCMmap2/gccollector.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Wed Oct 28 09:22:38 PDT 2009


Author: geoffray
Date: Wed Oct 28 11:22:37 2009
New Revision: 85398

URL: http://llvm.org/viewvc/llvm-project?rev=85398&view=rev
Log:
Rename functions and fields to consistent names of what they actually
do or represent.


Modified:
    vmkit/trunk/include/mvm/Threads/CollectionRV.h
    vmkit/trunk/include/mvm/Threads/Thread.h
    vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp
    vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
    vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp

Modified: vmkit/trunk/include/mvm/Threads/CollectionRV.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/CollectionRV.h?rev=85398&r1=85397&r2=85398&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/Threads/CollectionRV.h (original)
+++ vmkit/trunk/include/mvm/Threads/CollectionRV.h Wed Oct 28 11:22:37 2009
@@ -18,40 +18,37 @@
 
 class CollectionRV {
   
-  /// stackLock - Stack lock for synchronization.
-  LockNormal _stackLock;         
+  /// _lockRV - Lock for synchronization.
+  LockNormal _lockRV;         
   
-  /// stackCond - Condition for unlocking other tasks (write protect).
-  Cond stackCond;
+  /// condEndRV - Condition for unlocking other tasks (write protect).
+  Cond condEndRV;
 
-  /// collectionCond - Condition for unblocking the collector.
-  Cond collectionCond;
+  /// collectionCond - Condition for unblocking the initator.
+  Cond condInitiator;
 
-  /// nbCollected - Number of threads collected.
-  unsigned nbCollected;
+  /// nbJoined - Number of threads that joined the rendezvous.
+  unsigned nbJoined;
   
-  /// currentCollector - The initiating thread for collection. Don't
-  /// synchonize this one.
-  mvm::Thread* currentCollector;  
+  /// initiator - The initiating thread for rendezvous.
+  mvm::Thread* initiator;
   
   /// cooperative - Is the rendez-vous cooperative?
   bool cooperative;
 
-
   /// rendezvousNb - The identifier of the rendez-vous.
-  ///
   unsigned rendezvousNb;
   
 public:
  
-  mvm::Thread* getCurrentCollector() {
-    return currentCollector;
+  mvm::Thread* getInitiator() {
+    return initiator;
   }
 
   CollectionRV() {
     rendezvousNb = 0;
-    nbCollected = 0;
-    currentCollector = 0;
+    nbJoined = 0;
+    initiator = 0;
 #ifdef WITH_LLVM_GCC
     cooperative = true;
 #else
@@ -61,35 +58,35 @@
  
   bool isCooperative() { return cooperative; }
 
-  void stackLock() { _stackLock.lock(); }
-  void stackUnlock() { _stackLock.unlock(); }
+  void lockRV() { _lockRV.lock(); }
+  void unlockRV() { _lockRV.unlock(); }
 
-  void waitStacks();
-  void waitCollection();
+  void waitEndOfRV();
+  void waitRV();
  
-  void collectionFinished() {
+  void finishRV() {
     if (cooperative) {
       // We lock here to make sure no threads previously blocked in native
       // will join the collection and never go back to running code.
-      stackLock();
-      mvm::Thread* cur = currentCollector;
+      lockRV();
+      mvm::Thread* cur = initiator;
       do {
         cur->doYield = false;
         cur = (mvm::Thread*)cur->next();
-      } while (cur != currentCollector);
+      } while (cur != initiator);
       rendezvousNb++;
-      collectionCond.broadcast();
-      stackUnlock();
+      condEndRV.broadcast();
+      unlockRV();
     } else {
       rendezvousNb++;
-      collectionCond.broadcast();
+      condEndRV.broadcast();
     }
-    currentCollector->inGC = false;
+    initiator->inRV = false;
   }
   
-  void collectorGo() { stackCond.broadcast(); }
+  void collectorGo() { condInitiator.broadcast(); }
 
-  void another_mark() { nbCollected++; }
+  void another_mark() { nbJoined++; }
 
   void synchronize();
 

Modified: vmkit/trunk/include/mvm/Threads/Thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=85398&r1=85397&r2=85398&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/Threads/Thread.h (original)
+++ vmkit/trunk/include/mvm/Threads/Thread.h Wed Oct 28 11:22:37 2009
@@ -147,14 +147,13 @@
   ///
   bool doYield;
 
-  /// inGC - Flag to tell that the thread is being part of a GC.
+  /// inRV - Flag to tell that the thread is being part of a rendezvous.
   ///
-  bool inGC;
+  bool inRV;
 
-  /// stackScanned - Flag to tell that the thread's stack has already
-  /// been analyzed.
+  /// joinedRV - Flag to tell that the thread has joined a rendezvous.
   ///
-  bool stackScanned;
+  bool joinedRV;
 
   /// get - Get the thread specific data of the current thread.
   ///
@@ -183,9 +182,9 @@
   ///
   virtual void internalClearException() {}
 
-  /// joinCollection - Join a collection.
+  /// joinRV - Join a rendezvous.
   ///
-  void joinCollection();
+  void joinRV();
 
 public:
  
@@ -203,13 +202,13 @@
 
   void enterUncooperativeCode(unsigned level = 0) __attribute__ ((noinline)) {
     if (isMvmThread()) {
-      if (!inGC) {
+      if (!inRV) {
         assert(!lastSP && "SP already set when entering uncooperative code");
         ++level;
         void* temp = __builtin_frame_address(0);
         while (level--) temp = ((void**)temp)[0];
         lastSP = temp;
-        if (doYield) joinCollection();
+        if (doYield) joinRV();
         assert(lastSP && "No last SP when entering uncooperative code");
       }
     }
@@ -217,10 +216,10 @@
   
   void enterUncooperativeCode(void* SP) {
     if (isMvmThread()) {
-      if (!inGC) {
+      if (!inRV) {
         assert(!lastSP && "SP already set when entering uncooperative code");
         lastSP = SP;
-        if (doYield) joinCollection();
+        if (doYield) joinRV();
         assert(lastSP && "No last SP when entering uncooperative code");
       }
     }
@@ -228,11 +227,11 @@
 
   void leaveUncooperativeCode() {
     if (isMvmThread()) {
-      if (!inGC) {
+      if (!inRV) {
         assert(lastSP && "No last SP when leaving uncooperative code");
-        if (doYield) joinCollection();
+        if (doYield) joinRV();
         lastSP = 0;
-        if (doYield) joinCollection();
+        if (doYield) joinRV();
         assert(!lastSP && "SP has a value after leaving uncooperative code");
       }
     }

Modified: vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp?rev=85398&r1=85397&r2=85398&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp Wed Oct 28 11:22:37 2009
@@ -12,79 +12,81 @@
 
 using namespace mvm;
 
-void CollectionRV::waitCollection() {
+void CollectionRV::waitEndOfRV() {
   mvm::Thread* th = mvm::Thread::get();
   unsigned cm = rendezvousNb;
 
-  if (nbCollected == th->MyVM->NumberOfThreads) collectorGo();
+  if (nbJoined == th->MyVM->NumberOfThreads) collectorGo();
   
   while (rendezvousNb == cm) {
-    collectionCond.wait(&_stackLock);
+    condEndRV.wait(&_lockRV);
   }
 }
 
-void CollectionRV::waitStacks() {
+void CollectionRV::waitRV() {
   mvm::Thread* self = mvm::Thread::get();
-  stackLock();
+  lockRV();
   
-  while (nbCollected < self->MyVM->NumberOfThreads)
-    stackCond.wait(&_stackLock);
+  while (nbJoined < self->MyVM->NumberOfThreads)
+    condInitiator.wait(&_lockRV);
   
-  stackUnlock();
+  unlockRV();
 }
 
 void CollectionRV::synchronize() {
   
   mvm::Thread* self = mvm::Thread::get();
   assert(self && "No thread local data for this thread");
+  self->inRV = true;
 
   // Lock thread lock, so that we can traverse the thread list safely.
   self->MyVM->ThreadLock.lock();
 
   if (cooperative) {
-    currentCollector = self;
-    nbCollected = 0;
+    initiator = self;
+    nbJoined = 0;
  	 
-    // Lock stacks. Changes on the doYield flag of threads must be
-    // protected, as threads may wake up after being blocked in native code
-    // and join the collection.
-    stackLock();
+    // Lock. Changes on the doYield flag of threads must be protected, as
+    // threads may wake up after being blocked in native code and join the
+    // rendezvous.
+    lockRV();
 
     mvm::Thread* cur = self;
     do {
-      cur->stackScanned = false;
+      cur->joinedRV = false;
       cur->doYield = true;
       cur = (mvm::Thread*)cur->next();
     } while (cur != self);
     
-    // Unlock now. Each running thread will scan its stack.
-    stackUnlock();
+    // Unlock now. Each running thread will join the rendezvous.
+    unlockRV();
 
-    // Scan the stacks of currently blocked threads.
+    // Lookup currently blocked threads.
     for (mvm::Thread* cur = (mvm::Thread*)self->next(); cur != self; 
          cur = (mvm::Thread*)cur->next()) {
       void* val = cur->getLastSP();
       // If val is null, this means that the thread woke up, and is
-      // joining the collection. We are sure the thread will scan its stack.
+      // joining the rendezvous. We are sure the thread will join the
+      // rendezvous.
       if (val) addForeignThread(cur);
     }
 
     // Add myself.
     another_mark();
 
-    // And wait for other threads to finish.
-    waitStacks();
+    // And wait for other threads to join.
+    waitRV();
 
   } else {
     mvm::Thread* self = mvm::Thread::get();
-    self->stackScanned = false;
+    self->joinedRV = false;
     assert(self && "No thread local data for this thread");
-    currentCollector = self;
-    nbCollected = 0;
+    initiator = self;
+    nbJoined = 0;
 
     for (mvm::Thread* cur = (mvm::Thread*)self->next(); cur != self; 
          cur = (mvm::Thread*)cur->next()) {
-      cur->stackScanned = false;
+      cur->joinedRV = false;
       cur->killForRendezvous();
     }
     
@@ -92,7 +94,7 @@
     another_mark();
 
     // And wait for other threads to finish.
-    waitStacks();
+    waitRV();
   }
  
   self->MyVM->ThreadLock.unlock();
@@ -100,47 +102,47 @@
 
 void CollectionRV::join() {
   mvm::Thread* th = mvm::Thread::get();
-  th->inGC = true;
+  th->inRV = true;
   bool changed = false;
  
-  stackLock();
+  lockRV();
 
   if (isCooperative() && !th->doYield) {
     // I was previously blocked, and I'm running late: someone else collected
     // my stack, and the GC has finished already. Just unlock and return.
-    stackUnlock();
-    th->inGC = false;
+    unlockRV();
+    th->inRV = false;
     return;
   }
  
   // I woke up while a GC was happening, and no-one has listed me yet.
-  if (!th->stackScanned) {
+  if (!th->joinedRV) {
     another_mark();
-    th->stackScanned = true;
+    th->joinedRV = true;
     if (!th->getLastSP()) {
       changed = true;
       th->setLastSP(FRAME_PTR());
     }
   }
 
-  // Wait for the collection to finish.
-  waitCollection();
-  stackUnlock();
+  // Wait for the rendezvous to finish.
+  waitEndOfRV();
+  unlockRV();
   
-  // The collection is finished. Set inGC to false.
-  th->inGC = false;
+  // The rendezvous is finished. Set inRV to false.
+  th->inRV = false;
   if (changed) th->setLastSP(0);
 }
 
 void CollectionRV::addForeignThread(mvm::Thread* th) {
-  stackLock();
+  lockRV();
 
   // The thread may have waken up during this GC. In this case, it may have
   // put itself into the waiting list.
-  if (!th->stackScanned) {
+  if (!th->joinedRV) {
     another_mark();
-    th->stackScanned = true;
+    th->joinedRV = true;
   }
 
-  stackUnlock();
+  unlockRV();
 }

Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=85398&r1=85397&r2=85398&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Wed Oct 28 11:22:37 2009
@@ -39,12 +39,12 @@
 void Thread::yield(void) {
   Thread* th = mvm::Thread::get();
   if (th->isMvmThread()) {
-    if (th->doYield && !th->inGC) th->joinCollection();
+    if (th->doYield && !th->inRV) th->joinRV();
   }
   sched_yield();
 }
 
-void Thread::joinCollection() {
+void Thread::joinRV() {
   MyVM->rendezvous.join(); 
 }
 

Modified: vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp?rev=85398&r1=85397&r2=85398&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp Wed Oct 28 11:22:37 2009
@@ -44,7 +44,6 @@
   mvm::Thread* th = mvm::Thread::get();
   mvm::StackScanner* sc = th->MyVM->getScanner();
   th->MyVM->startCollection();
-  th->inGC = true;
 
   th->MyVM->rendezvous.synchronize();
 
@@ -93,7 +92,7 @@
   
   // Wake up all threads.
   th->MyVM->endCollection();
-  th->MyVM->rendezvous.collectionFinished();
+  th->MyVM->rendezvous.finishRV();
   th->MyVM->wakeUpFinalizers();
   th->MyVM->wakeUpEnqueue();
   
@@ -103,8 +102,7 @@
     next = cur->next();
     allocator->reject_chunk(cur);
   }
-  th->inGC = false;
-
+  
 }
 
 void Collector::collect_unprotect() {





More information about the vmkit-commits mailing list