Permalink
Browse files

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

Refactor handling of uncaught exceptions with OpenJDK to use runRaw().
  • Loading branch information...
2 parents 0347a6d + cc128aa commit 6603c2f5ab68db30f265073138e75e0ff4542b57 @dicej dicej committed on GitHub Sep 12, 2017
Showing with 23 additions and 30 deletions.
  1. +23 −30 src/classpath-openjdk.cpp
View
@@ -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);
@@ -597,13 +595,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(
@@ -972,37 +982,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

0 comments on commit 6603c2f

Please sign in to comment.