[vmkit-commits] [vmkit] r120169 - in /vmkit/branches/precise: include/mvm/Threads/Thread.h lib/J3/Classpath/ClasspathReflect.h lib/Mvm/CommonThread/ctthread.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Thu Nov 25 22:45:48 PST 2010


Author: geoffray
Date: Fri Nov 26 00:45:48 2010
New Revision: 120169

URL: http://llvm.org/viewvc/llvm-project?rev=120169&view=rev
Log:
Make sure the thread is dead before re-using its stack!


Modified:
    vmkit/branches/precise/include/mvm/Threads/Thread.h
    vmkit/branches/precise/lib/J3/Classpath/ClasspathReflect.h
    vmkit/branches/precise/lib/Mvm/CommonThread/ctthread.cpp

Modified: vmkit/branches/precise/include/mvm/Threads/Thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/include/mvm/Threads/Thread.h?rev=120169&r1=120168&r2=120169&view=diff
==============================================================================
--- vmkit/branches/precise/include/mvm/Threads/Thread.h (original)
+++ vmkit/branches/precise/include/mvm/Threads/Thread.h Fri Nov 26 00:45:48 2010
@@ -14,6 +14,7 @@
 #include <cstdio>
 #include <stdlib.h>
 
+#include "debug.h"
 #include "types.h"
 
 #ifdef RUNTIME_DWARF_EXCEPTIONS
@@ -292,11 +293,11 @@
   /// Thread. The thread object is inlined in the stack.
   ///
   void* operator new(size_t sz);
-  void operator delete(void* th) {}
+  void operator delete(void* th) { UNREACHABLE(); }
   
   /// releaseThread - Free the stack so that another thread can use it.
   ///
-  static void releaseThread(void* th);
+  static void releaseThread(mvm::Thread* th);
 
   /// routine - The function to invoke when the thread starts.
   ///

Modified: vmkit/branches/precise/lib/J3/Classpath/ClasspathReflect.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/Classpath/ClasspathReflect.h?rev=120169&r1=120168&r2=120169&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/Classpath/ClasspathReflect.h (original)
+++ vmkit/branches/precise/lib/J3/Classpath/ClasspathReflect.h Fri Nov 26 00:45:48 2010
@@ -14,6 +14,7 @@
 
 #include <JavaClass.h>
 #include <JavaObject.h>
+#include <JavaThread.h>
 
 extern "C" j3::JavaObject* internalFillInStackTrace(j3::JavaObject*);
 

Modified: vmkit/branches/precise/lib/Mvm/CommonThread/ctthread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/Mvm/CommonThread/ctthread.cpp?rev=120169&r1=120168&r2=120169&view=diff
==============================================================================
--- vmkit/branches/precise/lib/Mvm/CommonThread/ctthread.cpp (original)
+++ vmkit/branches/precise/lib/Mvm/CommonThread/ctthread.cpp Fri Nov 26 00:45:48 2010
@@ -417,7 +417,6 @@
   th->MyVM->rendezvous.addThread(th);
   th->routine(th);
   th->MyVM->removeThread(th);
-  delete th;
 }
 
 
@@ -456,12 +455,22 @@
       res = (void*)TheStackManager.allocate();
     }
   }
+  // Make sure the thread information is cleared.
+  memset(res, 0, sz);
   return res;
 }
 
 /// releaseThread - Remove the stack of the thread from the list of stacks
 /// in use.
-void Thread::releaseThread(void* th) {
+void Thread::releaseThread(mvm::Thread* th) {
+  // It seems like the pthread implementation in Linux is clearing with NULL
+  // the stack of the thread. So we have to get the thread id before
+  // calling pthread_join.
+  void* thread_id = th->internalThreadID;
+  if (thread_id != NULL) {
+    // Wait for the thread to die.
+    pthread_join((pthread_t)thread_id, NULL);
+  }
   uintptr_t index = ((uintptr_t)th & Thread::IDMask);
   index = (index & ~TheStackManager.baseAddr) >> 20;
   TheStackManager.used[index] = 0;





More information about the vmkit-commits mailing list