[vmkit-commits] [vmkit] r85751 - in /vmkit/trunk: include/mvm/Threads/Thread.h lib/Mvm/Runtime/Object.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sun Nov 1 14:13:30 PST 2009


Author: geoffray
Date: Sun Nov  1 16:13:30 2009
New Revision: 85751

URL: http://llvm.org/viewvc/llvm-project?rev=85751&view=rev
Log:
Call waitOn on a Thread's lastSP in case of race conditions and the
thread clears lastSP in a rendezvous.


Modified:
    vmkit/trunk/include/mvm/Threads/Thread.h
    vmkit/trunk/lib/Mvm/Runtime/Object.cpp

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

==============================================================================
--- vmkit/trunk/include/mvm/Threads/Thread.h (original)
+++ vmkit/trunk/include/mvm/Threads/Thread.h Sun Nov  1 16:13:30 2009
@@ -229,14 +229,36 @@
     if (isMvmThread()) {
       if (!inRV) {
         assert(lastSP && "No last SP when leaving uncooperative code");
+        // Check to see if a rendezvous has been set while being in native code.
         if (doYield) joinRV();
+        // Clear lastSP. If a rendezvous happens there, the thread will join it
+        // in the next iteration and set lastSP.
         lastSP = 0;
+        // A rendezvous has just been initiated, join it.
         if (doYield) joinRV();
         assert(!lastSP && "SP has a value after leaving uncooperative code");
       }
     }
   }
 
+  void* waitOnSP() {
+    // First see if we can get lastSP directly.
+    void* sp = lastSP;
+    if (sp) return sp;
+    
+    // Then loop a fixed number of iterations to get lastSP.
+    for (uint32 count = 0; count < 1000; ++count) {
+      sp = lastSP;
+      if (sp) return sp;
+    }
+    
+    // Finally, yield until lastSP is not set.
+    while ((sp = lastSP) == NULL) mvm::Thread::yield();
+
+    assert(sp != NULL && "Still no sp");
+    return sp;
+  }
+
 
   /// clearException - Clear any pending exception of the current thread.
   void clearException() {

Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=85751&r1=85750&r2=85751&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original)
+++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Sun Nov  1 16:13:30 2009
@@ -266,7 +266,8 @@
 void CamlStackScanner::scanStack(mvm::Thread* th) {
   std::vector<void*>::iterator it = th->addresses.end();
 
-  void** addr = mvm::Thread::get() == th ? (void**)FRAME_PTR() : (void**)th->getLastSP();
+  void** addr = mvm::Thread::get() == th ? (void**)FRAME_PTR() :
+                                           (void**)th->waitOnSP();
   void** oldAddr = addr;
 
   // Loop until we cross the first Java frame.
@@ -349,7 +350,7 @@
 void UnpreciseStackScanner::scanStack(mvm::Thread* th) {
   register unsigned int  **max = (unsigned int**)(void*)th->baseSP;
   if (mvm::Thread::get() != th) {
-    register unsigned int  **cur = (unsigned int**)th->getLastSP();
+    register unsigned int  **cur = (unsigned int**)th->waitOnSP();
     for(; cur<max; cur++) Collector::scanObject((void**)cur);
   } else {
     jmp_buf buf;





More information about the vmkit-commits mailing list