[vmkit-commits] [vmkit] r86283 - in /vmkit/trunk: include/mvm/Threads/CollectionRV.h include/mvm/Threads/Thread.h lib/Mvm/CommonThread/CollectionRV.cpp mmtk/mmtk-j3/Collection.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Fri Nov 6 12:30:45 PST 2009


Author: geoffray
Date: Fri Nov  6 14:30:44 2009
New Revision: 86283

URL: http://llvm.org/viewvc/llvm-project?rev=86283&view=rev
Log:
Really protect thread list when collecting.


Modified:
    vmkit/trunk/include/mvm/Threads/CollectionRV.h
    vmkit/trunk/include/mvm/Threads/Thread.h
    vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp
    vmkit/trunk/mmtk/mmtk-j3/Collection.cpp

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

==============================================================================
--- vmkit/trunk/include/mvm/Threads/CollectionRV.h (original)
+++ vmkit/trunk/include/mvm/Threads/CollectionRV.h Fri Nov  6 14:30:44 2009
@@ -60,24 +60,13 @@
     mvm::Thread::get()->inRV = true;
     lockRV();
   }
- 
-  void finishRV() {
-    
-    if (cooperative) {
-      mvm::Thread* initiator = mvm::Thread::get();
-      mvm::Thread* cur = initiator;
-      do {
-        cur->doYield = false;
-        cur = (mvm::Thread*)cur->next();
-      } while (cur != initiator);
-    }
-
-    nbJoined = 0;
-    rendezvousNb++;
-    condEndRV.broadcast();
+
+  void cancelRV() {
     mvm::Thread::get()->inRV = false;
     unlockRV();
   }
+ 
+  void finishRV();
   
   void collectorGo() { condInitiator.broadcast(); }
 

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

==============================================================================
--- vmkit/trunk/include/mvm/Threads/Thread.h (original)
+++ vmkit/trunk/include/mvm/Threads/Thread.h Fri Nov  6 14:30:44 2009
@@ -32,6 +32,10 @@
   ///
 	CircularBase	*_prev;
 public:
+  
+  /// ~CircularBase - Give the class a home.
+  ///
+  virtual ~CircularBase() {}
 
   /// next - Get the next object in the list.
   ///
@@ -59,7 +63,7 @@
 
   /// remove - Remove the object from its list.
   ///
-	inline void remove() { 
+	inline void remove() {
 		_prev->_next = _next; 
 		_next->_prev = _prev;
 		alone();
@@ -77,6 +81,16 @@
   /// alone - Set the object as being part of a new empty list.
   ///
 	inline void alone() { _prev = _next = this; }
+
+  /// print - Print the list for debug purposes.
+  void print() {
+    CircularBase* temp = this;
+    do {
+      fprintf(stderr, "%p -> ", (void*)temp);
+      temp = temp->next();
+    } while (temp != this);
+    fprintf(stderr, "\n");
+  }
 };
 
 
@@ -188,10 +202,6 @@
 
 public:
  
-  /// ~Thread - Give the class a home.
-  ///
-  virtual ~Thread() {}
-
   /// tracer - Does nothing. Used for child classes which may defined
   /// a tracer.
   ///

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

==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp Fri Nov  6 14:30:44 2009
@@ -38,8 +38,9 @@
   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.
+  
+  // Lock thread lock, so that we can traverse the thread list safely. This will
+  // be released on finishRV.
   self->MyVM->ThreadLock.lock();
 
   if (cooperative) {
@@ -75,8 +76,6 @@
   
   // And wait for other threads to finish.
   waitRV();
- 
-  self->MyVM->ThreadLock.unlock();
 }
 
 void CollectionRV::join() {
@@ -129,3 +128,24 @@
   th->MyVM->rendezvous.join();
   th->endNative();
 }
+
+void CollectionRV::finishRV() {
+    
+  mvm::Thread* self = mvm::Thread::get();
+  if (cooperative) {
+    mvm::Thread* initiator = mvm::Thread::get();
+    mvm::Thread* cur = initiator;
+    do {
+      cur->doYield = false;
+      cur = (mvm::Thread*)cur->next();
+    } while (cur != initiator);
+  }
+
+  nbJoined = 0;
+  rendezvousNb++;
+  condEndRV.broadcast();
+  self->inRV = false;
+  self->MyVM->ThreadLock.unlock();
+  
+  unlockRV();
+}

Modified: vmkit/trunk/mmtk/mmtk-j3/Collection.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-j3/Collection.cpp?rev=86283&r1=86282&r2=86283&view=diff

==============================================================================
--- vmkit/trunk/mmtk/mmtk-j3/Collection.cpp (original)
+++ vmkit/trunk/mmtk/mmtk-j3/Collection.cpp Fri Nov  6 14:30:44 2009
@@ -41,7 +41,7 @@
   // Verify that another collection is not happening.
   th->MyVM->rendezvous.startRV();
   if (th->doYield) {
-    th->MyVM->rendezvous.unlockRV();
+    th->MyVM->rendezvous.cancelRV();
     th->MyVM->rendezvous.join();
     return;
   } else {
@@ -76,7 +76,6 @@
     th->MyVM->endCollection();
   }
 
-
 }
 
 extern "C" void Java_org_j3_mmtk_Collection_joinCollection__ (JavaObject* C) {





More information about the vmkit-commits mailing list