[vmkit-commits] [vmkit] r146105 - /vmkit/trunk/lib/j3/ClassLib/OpenJDK/OpenJDK.inc

Will Dietz wdietz2 at illinois.edu
Wed Dec 7 15:34:37 PST 2011


Author: wdietz2
Date: Wed Dec  7 17:34:37 2011
New Revision: 146105

URL: http://llvm.org/viewvc/llvm-project?rev=146105&view=rev
Log:
OpenJDK: Handle exceptions thrown from newly spawned threads

Modified:
    vmkit/trunk/lib/j3/ClassLib/OpenJDK/OpenJDK.inc

Modified: vmkit/trunk/lib/j3/ClassLib/OpenJDK/OpenJDK.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/ClassLib/OpenJDK/OpenJDK.inc?rev=146105&r1=146104&r2=146105&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/ClassLib/OpenJDK/OpenJDK.inc (original)
+++ vmkit/trunk/lib/j3/ClassLib/OpenJDK/OpenJDK.inc Wed Dec  7 17:34:37 2011
@@ -513,7 +513,11 @@
 void start(JavaThread* thread) {
 
   JavaObject* javaThread = NULL;
+  JavaObject* handler = NULL;
+  JavaObject* exc = NULL;
   llvm_gcroot(javaThread, 0);
+  llvm_gcroot(exc, 0);
+  llvm_gcroot(handler, 0);
 
   Jnjvm* vm = thread->getJVM();
 
@@ -546,9 +550,30 @@
   JavaMethod * meth = thClass->lookupMethodDontThrow(runName, runType, false, true, 0);
   assert(meth);
 
+  // Sanity check
+  assert(JavaThread::get() == thread);
+
   // Run the thread...
-  // TODO: What happens if the thread throws an exception?
-  meth->invokeIntSpecial(vm, thClass, javaThread);
+  TRY {
+    meth->invokeIntSpecial(vm, thClass, javaThread);
+  } CATCH {
+    exc = thread->pendingException;
+  } END_CATCH;
+
+  // Sanity check
+  assert(JavaThread::get() == thread);
+
+  if (exc != NULL) {
+    thread->clearException();
+    TRY {
+      handler = vm->upcalls->getUncaughtExceptionHandler->invokeJavaObjectVirtual(vm, thClass, javaThread);
+      verifyNull(handler);
+      vm->upcalls->uncaughtException->invokeIntVirtual(vm, vm->upcalls->uncaughtException->classDef, handler, &javaThread, &exc);
+    } CATCH {
+      fprintf(stderr, "Exception in thread \"(unknown)\": "
+                      "Can not print stack trace.\n");
+    } END_CATCH;
+  }
 
   // Indicate that the thread is done by clearing the eetop field.
   // and notify all waiting threads.





More information about the vmkit-commits mailing list