Squashed commit of the following: (#41)

commit 6603c2f5ab68db30f265073138e75e0ff4542b57
Merge: 0347a6da4 cc128aa4f
Author: Joel Dice <joel.dice@gmail.com>
Date:   Tue Sep 12 10:20:45 2017 -0600

    Merge pull request #550 from corda/chrisr3-exceptions-vmrun

    Refactor handling of uncaught exceptions with OpenJDK to use runRaw().

commit cc128aa4f93d4deadd3368fb68397c52ee88fe86
Author: Chris Rankin <chris.rankin@r3.com>
Date:   Mon Sep 11 23:41:57 2017 +0100

    Refactor handling of uncaught exception with OpenJDK to use runRaw().
This commit is contained in:
Chris Rankin 2017-09-13 10:09:17 +01:00 committed by GitHub
parent 4d46239c68
commit 35c2da7030

View File

@ -296,9 +296,7 @@ object makeJconstructor(Thread* t, GcMethod* vmMethod, int index = -1);
object makeJfield(Thread* t, GcField* vmField, int index = -1);
void uncaughtException(Thread *t, GcThrowable *e);
void disposeThread(Thread *t);
static uint64_t uncaughtExceptionHandler(Thread*, uintptr_t*);
#ifdef AVIAN_OPENJDK_SRC
void interceptFileOperations(Thread*, bool);
@ -594,13 +592,25 @@ class MyClasspath : public Classpath {
THREAD_RESOURCE0(t, {
GcThrowable* e = t->exception;
if (e != NULL) {
PROTECT(t, e);
t->exception = NULL;
uncaughtException(t, e);
// Prevent any exceptions thrown from the uncaught
// exception handler from unwinding the stack past
// this point. This allows us to continue cleaning
// up this resource.
uintptr_t argument = reinterpret_cast<uintptr_t>(e);
runRaw(t, uncaughtExceptionHandler, &argument);
}
disposeThread(t);
vm::acquire(t, t->javaThread);
t->clearFlag(Thread::ActiveFlag);
vm::notifyAll(t, t->javaThread);
vm::release(t, t->javaThread);
t->m->processor->invoke(t,
cast<GcMethod>(t, roots(t)->threadTerminated()),
t->javaThread->group(),
t->javaThread);
});
GcMethod* method = resolveMethod(
@ -969,37 +979,20 @@ class EmbeddedFile {
unsigned pathLength;
};
void uncaughtException(Thread *t, GcThrowable *e)
static uint64_t uncaughtExceptionHandler(Thread* t, uintptr_t* arguments)
{
GcThrowable* exception = cast<GcThrowable>(t, reinterpret_cast<object>(arguments[0]));
PROTECT(t, exception);
GcMethod* dispatch = resolveMethod(t,
roots(t)->bootLoader(),
"java/lang/Thread",
"dispatchUncaughtException",
"(Ljava/lang/Throwable;)V");
if (dispatch != NULL) {
THREAD_RESOURCE0(t, {
if (t->exception != NULL) {
// The stack will be unwound when this resource is
// released, which means that uncaughtException()
// will not return. So repeat the thread clean-up here.
disposeThread(t);
}
});
t->m->processor->invoke(t, dispatch, t->javaThread, e);
t->m->processor->invoke(t, dispatch, t->javaThread, exception);
}
}
void disposeThread(Thread *t) {
vm::acquire(t, t->javaThread);
t->clearFlag(Thread::ActiveFlag);
vm::notifyAll(t, t->javaThread);
vm::release(t, t->javaThread);
t->m->processor->invoke(t,
cast<GcMethod>(t, roots(t)->threadTerminated()),
t->javaThread->group(),
t->javaThread);
return 0;
}
#ifdef AVIAN_OPENJDK_SRC