[vmkit-commits] [vmkit] r118833 - in /vmkit/branches/precise: include/mvm/Threads/CollectionRV.h include/mvm/Threads/Thread.h lib/J3/Classpath/ClasspathVMThread.inc lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/Compiler/JavaJIT.cpp lib/J3/VMCore/JavaRuntimeJIT.cpp lib/J3/VMCore/JavaThread.cpp lib/J3/VMCore/JavaThread.h lib/J3/VMCore/Jnjvm.cpp lib/J3/VMCore/ReferenceQueue.cpp lib/J3/VMCore/ReferenceQueue.h lib/J3/VMCore/VirtualTables.cpp lib/Mvm/CommonThread/CollectionRV.cpp lib/Mvm/CommonThread/ctthread.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Thu Nov 11 12:43:26 PST 2010
Author: geoffray
Date: Thu Nov 11 14:43:26 2010
New Revision: 118833
URL: http://llvm.org/viewvc/llvm-project?rev=118833&view=rev
Log:
Some more GC fixes.
Modified:
vmkit/branches/precise/include/mvm/Threads/CollectionRV.h
vmkit/branches/precise/include/mvm/Threads/Thread.h
vmkit/branches/precise/lib/J3/Classpath/ClasspathVMThread.inc
vmkit/branches/precise/lib/J3/Compiler/JavaAOTCompiler.cpp
vmkit/branches/precise/lib/J3/Compiler/JavaJIT.cpp
vmkit/branches/precise/lib/J3/VMCore/JavaRuntimeJIT.cpp
vmkit/branches/precise/lib/J3/VMCore/JavaThread.cpp
vmkit/branches/precise/lib/J3/VMCore/JavaThread.h
vmkit/branches/precise/lib/J3/VMCore/Jnjvm.cpp
vmkit/branches/precise/lib/J3/VMCore/ReferenceQueue.cpp
vmkit/branches/precise/lib/J3/VMCore/ReferenceQueue.h
vmkit/branches/precise/lib/J3/VMCore/VirtualTables.cpp
vmkit/branches/precise/lib/Mvm/CommonThread/CollectionRV.cpp
vmkit/branches/precise/lib/Mvm/CommonThread/ctthread.cpp
Modified: vmkit/branches/precise/include/mvm/Threads/CollectionRV.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/include/mvm/Threads/CollectionRV.h?rev=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/include/mvm/Threads/CollectionRV.h (original)
+++ vmkit/branches/precise/include/mvm/Threads/CollectionRV.h Thu Nov 11 14:43:26 2010
@@ -34,7 +34,7 @@
CollectionRV() {
nbJoined = 0;
}
-
+
void lockRV() { _lockRV.lock(); }
void unlockRV() { _lockRV.unlock(); }
@@ -59,6 +59,8 @@
virtual void join() = 0;
virtual void joinAfterUncooperative(void* SP) = 0;
virtual void joinBeforeUncooperative() = 0;
+
+ virtual void addThread(Thread* th) = 0;
};
class CooperativeCollectionRV : public CollectionRV {
@@ -69,6 +71,7 @@
void join();
void joinAfterUncooperative(void* SP);
void joinBeforeUncooperative();
+ void addThread(Thread* th);
};
class UncooperativeCollectionRV : public CollectionRV {
@@ -79,6 +82,7 @@
void join();
void joinAfterUncooperative(void* SP);
void joinBeforeUncooperative();
+ void addThread(Thread* th);
};
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=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/include/mvm/Threads/Thread.h (original)
+++ vmkit/branches/precise/include/mvm/Threads/Thread.h Thu Nov 11 14:43:26 2010
@@ -165,10 +165,6 @@
///
int kill(int signo);
- /// killForRendezvous - Kill the given thread for a rendezvous.
- ///
- void killForRendezvous();
-
/// exit - Exit the current thread.
///
static void exit(int value);
Modified: vmkit/branches/precise/lib/J3/Classpath/ClasspathVMThread.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/Classpath/ClasspathVMThread.inc?rev=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/Classpath/ClasspathVMThread.inc (original)
+++ vmkit/branches/precise/lib/J3/Classpath/ClasspathVMThread.inc Thu Nov 11 14:43:26 2010
@@ -45,6 +45,7 @@
// which is the JavaThread object.
vmThread = (JavaObjectVMThread*)thread->vmThread;
assert(vmThread && "Didn't fix the vmThread of a j3 thread");
+ assert(vmThread->getVirtualTable());
JavaObjectVMThread::setVmdata(vmThread, thread);
UserClass* vmthClass = (UserClass*)JavaObject::getClass(vmThread);
@@ -58,7 +59,9 @@
if (!isDaemon) {
vm->threadSystem.enter();
}
-
+
+ assert(vmThread->getVirtualTable());
+ assert(javaThread->getVirtualTable());
// Run the VMThread::run function
vm->upcalls->runVMThread->invokeIntSpecial(vm, vmthClass, vmThread);
@@ -86,7 +89,8 @@
javaThread = vm->upcalls->assocThread->getInstanceObjectField(vmThread);
assert(javaThread && "VMThread with no Java equivalent");
- JavaThread* th = new JavaThread(javaThread, vmThread, vm);
+ JavaThread* th = new JavaThread(vm);
+ th->initialise(javaThread, vmThread);
if (!th) vm->outOfMemoryError();
th->start((void (*)(mvm::Thread*))start);
Modified: vmkit/branches/precise/lib/J3/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/branches/precise/lib/J3/Compiler/JavaAOTCompiler.cpp Thu Nov 11 14:43:26 2010
@@ -2132,7 +2132,7 @@
void JavaAOTCompiler::compileFile(Jnjvm* vm, const char* n) {
name = n;
- JavaThread* th = new JavaThread(0, 0, vm);
+ JavaThread* th = new JavaThread(vm);
vm->setMainThread(th);
th->start((void (*)(mvm::Thread*))mainCompilerStart);
vm->waitForExit();
Modified: vmkit/branches/precise/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/Compiler/JavaJIT.cpp?rev=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/branches/precise/lib/J3/Compiler/JavaJIT.cpp Thu Nov 11 14:43:26 2010
@@ -1905,14 +1905,15 @@
intrinsics->AllocateUnresolvedFunction,
Size, VT, "", currentBlock);
+ addHighLevelType(val, cl ? cl : upcalls->OfObject);
+ Instruction* res = new BitCastInst(val, intrinsics->JavaObjectType, "", currentBlock);
+ push(res, false, cl ? cl : upcalls->OfObject);
+
+ // Make sure to add the object to the finalization list after it has been
+ // pushed.
if (cl && cl->virtualVT->destructor) {
CallInst::Create(intrinsics->AddFinalizationCandidate, val, "", currentBlock);
}
-
-
- addHighLevelType(val, cl ? cl : upcalls->OfObject);
- val = new BitCastInst(val, intrinsics->JavaObjectType, "", currentBlock);
- push(val, false, cl ? cl : upcalls->OfObject);
}
Value* JavaJIT::ldResolved(uint16 index, bool stat, Value* object,
Modified: vmkit/branches/precise/lib/J3/VMCore/JavaRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/branches/precise/lib/J3/VMCore/JavaRuntimeJIT.cpp Thu Nov 11 14:43:26 2010
@@ -758,7 +758,7 @@
while (table[i] != (uintptr_t)meth) { i += 2; }
result = table[i + 1];
}
- assert((result != NULL) && "Bad IMT");
+ assert((result != 0) && "Bad IMT");
return (void*)result;
}
Modified: vmkit/branches/precise/lib/J3/VMCore/JavaThread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/VMCore/JavaThread.cpp?rev=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/VMCore/JavaThread.cpp (original)
+++ vmkit/branches/precise/lib/J3/VMCore/JavaThread.cpp Thu Nov 11 14:43:26 2010
@@ -19,18 +19,14 @@
using namespace j3;
-JavaThread::JavaThread(JavaObject* thread, JavaObject* vmth, Jnjvm* isolate)
- : MutatorThread() {
- llvm_gcroot(thread, 0);
- llvm_gcroot(vmth, 0);
-
- javaThread = thread;
- vmThread = vmth;
+JavaThread::JavaThread(Jnjvm* isolate) : MutatorThread() {
MyVM = isolate;
- pendingException = 0;
+ pendingException = NULL;
jniEnv = isolate->jniEnv;
localJNIRefs = new JNILocalReferences();
- currentAddedReferences = 0;
+ currentAddedReferences = NULL;
+ javaThread = NULL;
+ vmThread = NULL;
#ifdef SERVICE
eipIndex = 0;
@@ -41,6 +37,13 @@
#endif
}
+void JavaThread::initialise(JavaObject* thread, JavaObject* vmth) {
+ llvm_gcroot(thread, 0);
+ llvm_gcroot(vmth, 0);
+ javaThread = thread;
+ vmThread = vmth;
+}
+
JavaThread::~JavaThread() {
delete localJNIRefs;
#ifdef SERVICE
Modified: vmkit/branches/precise/lib/J3/VMCore/JavaThread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/VMCore/JavaThread.h?rev=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/VMCore/JavaThread.h (original)
+++ vmkit/branches/precise/lib/J3/VMCore/JavaThread.h Thu Nov 11 14:43:26 2010
@@ -123,15 +123,17 @@
/// JavaThread - Creates a Java thread.
///
- JavaThread(JavaObject* thread, JavaObject* vmThread, Jnjvm* isolate);
+ JavaThread(Jnjvm* isolate);
- /// get - Get the current thread as a JnJVM object.
+ void initialise(JavaObject* thread, JavaObject* vmth);
+
+ /// get - Get the current thread as a J3 object.
///
static JavaThread* get() {
return (JavaThread*)mvm::Thread::get();
}
- /// getJVM - Get the JnJVM in which this thread executes.
+ /// getJVM - Get the Java VM in which this thread executes.
///
Jnjvm* getJVM() {
return (Jnjvm*)MyVM;
Modified: vmkit/branches/precise/lib/J3/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/VMCore/Jnjvm.cpp?rev=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/VMCore/Jnjvm.cpp (original)
+++ vmkit/branches/precise/lib/J3/VMCore/Jnjvm.cpp Thu Nov 11 14:43:26 2010
@@ -1328,7 +1328,7 @@
void Jnjvm::runApplication(int argc, char** argv) {
argumentsInfo.argc = argc;
argumentsInfo.argv = argv;
- mainThread = new JavaThread(0, 0, this);
+ mainThread = new JavaThread(this);
mainThread->start((void (*)(mvm::Thread*))mainJavaStart);
}
Modified: vmkit/branches/precise/lib/J3/VMCore/ReferenceQueue.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/VMCore/ReferenceQueue.cpp?rev=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/VMCore/ReferenceQueue.cpp (original)
+++ vmkit/branches/precise/lib/J3/VMCore/ReferenceQueue.cpp Thu Nov 11 14:43:26 2010
@@ -15,7 +15,7 @@
using namespace j3;
-ReferenceThread::ReferenceThread(Jnjvm* vm) : JavaThread(NULL, NULL, vm),
+ReferenceThread::ReferenceThread(Jnjvm* vm) : JavaThread(vm),
WeakReferencesQueue(ReferenceQueue::WEAK),
SoftReferencesQueue(ReferenceQueue::SOFT),
PhantomReferencesQueue(ReferenceQueue::PHANTOM) {
@@ -155,7 +155,7 @@
}
-FinalizerThread::FinalizerThread(Jnjvm* vm) : JavaThread(NULL, NULL, vm) {
+FinalizerThread::FinalizerThread(Jnjvm* vm) : JavaThread(vm) {
FinalizationQueue = new gc*[INITIAL_QUEUE_SIZE];
QueueLength = INITIAL_QUEUE_SIZE;
CurrentIndex = 0;
@@ -197,6 +197,7 @@
void FinalizerThread::addFinalizationCandidate(gc* obj) {
+ llvm_gcroot(obj, 0);
FinalizationQueueLock.acquire();
if (CurrentIndex >= QueueLength) {
Modified: vmkit/branches/precise/lib/J3/VMCore/ReferenceQueue.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/VMCore/ReferenceQueue.h?rev=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/VMCore/ReferenceQueue.h (original)
+++ vmkit/branches/precise/lib/J3/VMCore/ReferenceQueue.h Thu Nov 11 14:43:26 2010
@@ -51,6 +51,7 @@
}
void addReference(gc* ref) {
+ llvm_gcroot(ref, 0);
QueueLock.acquire();
if (CurrentIndex >= QueueLength) {
uint32 newLength = QueueLength * GROW_FACTOR;
@@ -110,18 +111,21 @@
/// addWeakReference - Add a weak reference to the queue.
///
void addWeakReference(gc* ref) {
+ llvm_gcroot(ref, 0);
WeakReferencesQueue.addReference(ref);
}
/// addSoftReference - Add a weak reference to the queue.
///
void addSoftReference(gc* ref) {
+ llvm_gcroot(ref, 0);
SoftReferencesQueue.addReference(ref);
}
/// addPhantomReference - Add a weak reference to the queue.
///
void addPhantomReference(gc* ref) {
+ llvm_gcroot(ref, 0);
PhantomReferencesQueue.addReference(ref);
}
Modified: vmkit/branches/precise/lib/J3/VMCore/VirtualTables.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/J3/VMCore/VirtualTables.cpp?rev=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/lib/J3/VMCore/VirtualTables.cpp (original)
+++ vmkit/branches/precise/lib/J3/VMCore/VirtualTables.cpp Thu Nov 11 14:43:26 2010
@@ -321,9 +321,7 @@
}
void JavaThread::tracer(uintptr_t closure) {
- if (pendingException != NULL) {
- mvm::Collector::markAndTraceRoot(&pendingException, closure);
- }
+ mvm::Collector::markAndTraceRoot(&pendingException, closure);
mvm::Collector::markAndTraceRoot(&javaThread, closure);
mvm::Collector::markAndTraceRoot(&vmThread, closure);
#ifdef SERVICE
Modified: vmkit/branches/precise/lib/Mvm/CommonThread/CollectionRV.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/precise/lib/Mvm/CommonThread/CollectionRV.cpp?rev=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/lib/Mvm/CommonThread/CollectionRV.cpp (original)
+++ vmkit/branches/precise/lib/Mvm/CommonThread/CollectionRV.cpp Thu Nov 11 14:43:26 2010
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include <cassert>
+#include <signal.h>
#include "MvmGC.h"
#include "mvm/VirtualMachine.h"
#include "mvm/Threads/CollectionRV.h"
@@ -80,6 +81,13 @@
unlockRV();
}
+
+#if defined(__MACH__)
+# define SIGGC SIGXCPU
+#else
+# define SIGGC SIGPWR
+#endif
+
void UncooperativeCollectionRV::synchronize() {
assert(nbJoined == 0);
mvm::Thread* self = mvm::Thread::get();
@@ -89,7 +97,8 @@
for (mvm::Thread* cur = (mvm::Thread*)self->next(); cur != self;
cur = (mvm::Thread*)cur->next()) {
- cur->killForRendezvous();
+ int res = cur->kill(SIGGC);
+ assert(!res && "Error on kill");
}
// And wait for other threads to finish.
@@ -220,3 +229,29 @@
void UncooperativeCollectionRV::joinBeforeUncooperative() {
UNREACHABLE();
}
+
+void CooperativeCollectionRV::addThread(Thread* th) {
+ // Nothing to do.
+}
+
+static void siggcHandler(int) {
+ mvm::Thread* th = mvm::Thread::get();
+ th->MyVM->rendezvous.join();
+}
+
+void UncooperativeCollectionRV::addThread(Thread* th) {
+ // Set the SIGGC handler for uncooperative rendezvous.
+ struct sigaction sa;
+ sigset_t mask;
+ sigaction(SIGGC, 0, &sa);
+ sigfillset(&mask);
+ sa.sa_mask = mask;
+ sa.sa_handler = siggcHandler;
+ sa.sa_flags |= SA_RESTART;
+ sigaction(SIGGC, &sa, NULL);
+
+ if (nbJoined != 0) {
+ // In uncooperative mode, we may have missed a signal.
+ join();
+ }
+}
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=118833&r1=118832&r2=118833&view=diff
==============================================================================
--- vmkit/branches/precise/lib/Mvm/CommonThread/ctthread.cpp (original)
+++ vmkit/branches/precise/lib/Mvm/CommonThread/ctthread.cpp Thu Nov 11 14:43:26 2010
@@ -305,18 +305,6 @@
extern void sigsegvHandler(int, siginfo_t*, void*);
-
-#if defined(__MACH__)
-# define SIGGC SIGXCPU
-#else
-# define SIGGC SIGPWR
-#endif
-
-static void siggcHandler(int) {
- mvm::Thread* th = mvm::Thread::get();
- th->MyVM->rendezvous.join();
-}
-
/// internalThreadStart - The initial function called by a thread. Sets some
/// thread specific data, registers the thread to the GC and calls the
/// given routine of th.
@@ -333,19 +321,12 @@
sa.sa_sigaction = sigsegvHandler;
sigaction(SIGSEGV, &sa, NULL);
- // Set the SIGGC handler for uncooperative rendezvous.
- sigaction(SIGGC, 0, &sa);
- sigfillset(&mask);
- sa.sa_mask = mask;
- sa.sa_handler = siggcHandler;
- sa.sa_flags |= SA_RESTART;
- sigaction(SIGGC, &sa, NULL);
+ th->MyVM->rendezvous.addThread(th);
assert(th->MyVM && "VM not set in a thread");
#ifdef ISOLATE
th->IsolateID = th->MyVM->IsolateID;
#endif
- th->MyVM->addThread(th);
th->routine(th);
th->MyVM->removeThread(th);
delete th;
@@ -361,6 +342,7 @@
pthread_attr_init(&attributs);
pthread_attr_setstack(&attributs, this, STACK_SIZE);
routine = fct;
+ MyVM->addThread(this);
int res = pthread_create((pthread_t*)(void*)(&internalThreadID), &attributs,
(void* (*)(void *))internalThreadStart, this);
pthread_detach((pthread_t)internalThreadID);
@@ -395,12 +377,6 @@
TheStackManager.used[index] = 0;
}
-void Thread::killForRendezvous() {
- int res = kill(SIGGC);
- assert(!res && "Error on kill");
-}
-
-
#ifdef WITH_LLVM_GCC
void Thread::scanStack(uintptr_t closure) {
StackWalker Walker(this);
More information about the vmkit-commits
mailing list