[vmkit-commits] [vmkit] r83866 - in /vmkit/trunk: include/mvm/VirtualMachine.h lib/JnJVM/VMCore/Jnjvm.h lib/Mvm/CommonThread/ctthread.cpp lib/Mvm/GCMmap2/MvmGC.h lib/Mvm/GCMmap2/gcinit.cpp lib/Mvm/GCMmap2/gcthread.cpp lib/Mvm/GCMmap2/gcthread.h
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Mon Oct 12 11:21:06 PDT 2009
Author: geoffray
Date: Mon Oct 12 13:21:05 2009
New Revision: 83866
URL: http://llvm.org/viewvc/llvm-project?rev=83866&view=rev
Log:
Move the list of threads from GCThread to VirtualMachine.
Modified:
vmkit/trunk/include/mvm/VirtualMachine.h
vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h
vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cpp
vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cpp
vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h
Modified: vmkit/trunk/include/mvm/VirtualMachine.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=83866&r1=83865&r2=83866&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/VirtualMachine.h (original)
+++ vmkit/trunk/include/mvm/VirtualMachine.h Mon Oct 12 13:21:05 2009
@@ -127,11 +127,60 @@
ToEnqueue = new gc*[INITIAL_QUEUE_SIZE];
ToEnqueueLength = INITIAL_QUEUE_SIZE;
ToEnqueueIndex = 0;
+
+ mainThread = 0;
+ NumberOfThreads = 0;
}
public:
+ /// allocator - Bump pointer allocator to allocate permanent memory
+ /// related to this VM.
+ ///
mvm::BumpPtrAllocator& allocator;
+ /// 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;
+
+ /// 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--;
+ th->remove();
+ if (!NumberOfThreads) mainThread = 0;
+ ThreadLock.unlock();
+ }
+
+
virtual void tracer() {}
virtual ~VirtualMachine() {}
Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=83866&r1=83865&r2=83866&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Mon Oct 12 13:21:05 2009
@@ -109,10 +109,6 @@
private:
- /// mainThread - The initial thread of this JVM.
- ///
- JavaThread* mainThread;
-
/// finalizerThread - The thread that finalizes Java objects.
///
JavaThread* finalizerThread;
@@ -294,14 +290,6 @@
///
ArrayUInt16* asciizToArray(const char* asciiz);
- /// setMainThread - Set the main thread of this VM.
- ///
- void setMainThread(JavaThread* th) { mainThread = th; }
-
- /// getMainThread - Get the main thread of this VM.
- ///
- JavaThread* getMainThread() const { return mainThread; }
-
/// setFinalizerThread - Set the finalizer thread of this VM.
///
void setFinalizerThread(JavaThread* th) { finalizerThread = th; }
Modified: vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp?rev=83866&r1=83865&r2=83866&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/ctthread.cpp Mon Oct 12 13:21:05 2009
@@ -173,13 +173,13 @@
sa.sa_sigaction = sigsegvHandler;
sigaction(SIGSEGV, &sa, NULL);
-#ifdef ISOLATE
assert(th->MyVM && "VM not set in a thread");
+#ifdef ISOLATE
th->IsolateID = th->MyVM->IsolateID;
#endif
- Collector::inject_my_thread(th);
+ th->MyVM->addThread(th);
th->routine(th);
- Collector::remove_my_thread(th);
+ th->MyVM->removeThread(th);
}
Modified: vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h?rev=83866&r1=83865&r2=83866&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h Mon Oct 12 13:21:05 2009
@@ -92,11 +92,6 @@
siggc_handler(0);
}
- static void inject_my_thread(mvm::Thread* th);
- static inline void remove_my_thread(mvm::Thread* th) {
- threads->remove(th);
- }
-
static inline void *allocate_unprotected(size_t sz) {
return allocator->alloc(sz);
}
Modified: vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cpp?rev=83866&r1=83865&r2=83866&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cpp (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gcinit.cpp Mon Oct 12 13:21:05 2009
@@ -65,7 +65,3 @@
allocator = 0;
}
-void Collector::inject_my_thread(mvm::Thread* th) {
- threads->inject(th);
-}
-
Modified: vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cpp?rev=83866&r1=83865&r2=83866&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cpp (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gcthread.cpp Mon Oct 12 13:21:05 2009
@@ -13,17 +13,22 @@
using namespace mvm;
void GCThread::waitStacks() {
+ mvm::Thread* self = mvm::Thread::get();
_stackLock.lock();
- while(_nb_collected < _nb_threads)
+ while(_nb_collected < self->MyVM->NumberOfThreads)
_stackCond.wait(&_stackLock);
_stackLock.unlock();
}
void GCThread::synchronize() {
-
+
+ mvm::Thread* self = mvm::Thread::get();
+ assert(self && "No thread local data for this thread");
+
+ // Lock thread lock, so that we can traverse the thread list safely.
+ self->MyVM->ThreadLock.lock();
+
if (cooperative) {
- mvm::Thread* self = mvm::Thread::get();
- assert(self && "No thread local data for this thread");
current_collector = self;
_nb_collected = 0;
@@ -74,4 +79,6 @@
waitStacks();
}
+
+ self->MyVM->ThreadLock.unlock();
}
Modified: vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h?rev=83866&r1=83865&r2=83866&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h Mon Oct 12 13:21:05 2009
@@ -29,9 +29,6 @@
/// _collectionCond - Condition for unblocking the collector.
Cond _collectionCond;
- /// _nb_threads - Number of active threads.
- unsigned int _nb_threads;
-
/// _nb_collected - Number of threads collected.
unsigned int _nb_collected;
@@ -41,7 +38,6 @@
public:
- mvm::Thread* base;
bool cooperative;
mvm::Thread* getCurrentCollector() {
@@ -49,10 +45,8 @@
}
GCThread() {
- _nb_threads = 0;
_nb_collected = 0;
current_collector = 0;
- base = 0;
#ifdef WITH_LLVM_GCC
cooperative = true;
#else
@@ -60,9 +54,6 @@
#endif
}
- inline unsigned int get_nb_threads() {
- return _nb_threads;
- }
inline void lock() { _globalLock.lock(); }
inline void unlock() { _globalLock.unlock(); }
@@ -92,46 +83,10 @@
inline void collectorGo() { _stackCond.broadcast(); }
- inline void cancel() {
- // all stacks have been collected
- _nb_collected = _nb_threads;
- // unblock all threads in stack collection
- collectorGo();
- // unblock mutators
- collectionFinished();
- }
-
inline void another_mark() { _nb_collected++; }
void synchronize();
- inline void remove(mvm::Thread* th) {
- lock();
- th->remove();
- _nb_threads--;
- if (!_nb_threads) base = 0;
-#ifdef SERVICE
- th->MyVM->numThreads--;
-#endif
- unlock();
- }
-
- inline void inject(mvm::Thread* th) {
- lock();
-#ifdef SERVICE
- if (th->MyVM->numThreads + 1 > th->MyVM->threadLimit) {
- unlock();
- th->MyVM->stopService();
- }
- th->MyVM->numThreads++;
-#endif
- if (base)
- th->append(base);
- else
- base = th;
- _nb_threads++;
- unlock();
- }
};
}
More information about the vmkit-commits
mailing list