* src/vm/exceptions.c (exceptions_handle_exception) [__ARM__]: Added
[cacao.git] / src / vm / exceptions.c
index e138c229cfad7294b6e2aea3b6e93ab67e6a0680..bab903ce08366a49115c1e3bd5739a906f6578a9 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: exceptions.c 7942 2007-05-23 12:40:31Z twisti $
-
 */
 
 
@@ -33,6 +31,8 @@
 #include <string.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <sys/mman.h>
 
 #include "vm/types.h"
 
 #include "mm/memory.h"
 
 #include "native/jni.h"
+#include "native/llni.h"
 #include "native/native.h"
+
 #include "native/include/java_lang_String.h"
 #include "native/include/java_lang_Throwable.h"
 
 #include "threads/lock-common.h"
 #include "threads/threads-common.h"
 
-#include "toolbox/logging.h"
 #include "toolbox/util.h"
 
 #include "vm/builtin.h"
 #include "vm/vm.h"
 
 #include "vm/jit/asmpart.h"
-#include "vm/jit/disass.h"
 #include "vm/jit/jit.h"
 #include "vm/jit/methodheader.h"
+#include "vm/jit/patcher-common.h"
+#include "vm/jit/show.h"
 #include "vm/jit/stacktrace.h"
+#include "vm/jit/trace.h"
 
 #include "vmcore/class.h"
 #include "vmcore/loader.h"
+#include "vmcore/method.h"
 #include "vmcore/options.h"
 
 #if defined(ENABLE_VMLOG)
 /* for raising exceptions from native methods *********************************/
 
 #if !defined(ENABLE_THREADS)
-java_objectheader *_no_threads_exceptionptr = NULL;
+java_object_t *_no_threads_exceptionptr = NULL;
 #endif
 
 
-/* init_system_exceptions ******************************************************
+/* exceptions_init *************************************************************
 
-   Load and link exceptions used in the system.
+   Initialize the exceptions subsystem.
 
 *******************************************************************************/
 
-bool exceptions_init(void)
+void exceptions_init(void)
 {
-       /* java/lang/Throwable */
+#if !(defined(__ARM__) && defined(__LINUX__))
+       /* On arm-linux the first memory page can't be mmap'ed, as it
+          contains the exception vectors. */
 
-       if (!(class_java_lang_Throwable =
-                 load_class_bootstrap(utf_java_lang_Throwable)) ||
-               !link_class(class_java_lang_Throwable))
-               return false;
+       int pagesize;
 
-       /* java/lang/Error */
+       /* mmap a memory page at address 0x0, so our hardware-exceptions
+          work. */
 
-       if (!(class_java_lang_Error = load_class_bootstrap(utf_java_lang_Error)) ||
-               !link_class(class_java_lang_Error))
-               return false;
+       pagesize = getpagesize();
 
-#if defined(ENABLE_JAVASE)
-       /* java/lang/LinkageError */
+       (void) memory_mmap_anon(NULL, pagesize, PROT_NONE, MAP_PRIVATE | MAP_FIXED);
+#endif
+
+       /* check if we get into trouble with our hardware-exceptions */
+
+       if (OFFSET(java_bytearray_t, data) <= EXCEPTION_HARDWARE_LARGEST)
+               vm_abort("signal_init: array-data offset is less or equal the maximum hardware-exception displacement: %d <= %d", OFFSET(java_bytearray_t, data), EXCEPTION_HARDWARE_LARGEST);
+}
+
+
+/* exceptions_get_exception ****************************************************
+
+   Returns the current exception pointer of the current thread.
 
-       if (!(class_java_lang_LinkageError =
-                 load_class_bootstrap(utf_java_lang_LinkageError)) ||
-               !link_class(class_java_lang_LinkageError))
-               return false;
+*******************************************************************************/
+
+java_handle_t *exceptions_get_exception(void)
+{
+       java_object_t *o;
+       java_handle_t *e;
+#if defined(ENABLE_THREADS)
+       threadobject  *t;
+
+       t = THREADOBJECT;
 #endif
 
-       /* java/lang/NoClassDefFoundError */
+       /* Get the exception. */
 
-       if (!(class_java_lang_NoClassDefFoundError =
-                 load_class_bootstrap(utf_java_lang_NoClassDefFoundError)) ||
-               !link_class(class_java_lang_NoClassDefFoundError))
-               return false;
+       LLNI_CRITICAL_START;
 
-       /* java/lang/OutOfMemoryError */
+#if defined(ENABLE_THREADS)
+       o = t->_exceptionptr;
+#else
+       o = _no_threads_exceptionptr;
+#endif
 
-       if (!(class_java_lang_OutOfMemoryError =
-                 load_class_bootstrap(utf_java_lang_OutOfMemoryError)) ||
-               !link_class(class_java_lang_OutOfMemoryError))
-               return false;
+       e = LLNI_WRAP(o);
 
-       /* java/lang/VirtualMachineError */
+       LLNI_CRITICAL_END;
 
-       if (!(class_java_lang_VirtualMachineError =
-                 load_class_bootstrap(utf_java_lang_VirtualMachineError)) ||
-               !link_class(class_java_lang_VirtualMachineError))
-               return false;
+       /* Return the exception. */
 
+       return e;
+}
 
-       /* java/lang/Exception */
 
-       if (!(class_java_lang_Exception =
-                 load_class_bootstrap(utf_java_lang_Exception)) ||
-               !link_class(class_java_lang_Exception))
-               return false;
+/* exceptions_set_exception ****************************************************
 
-       /* java/lang/ClassCastException */
+   Sets the exception pointer of the current thread.
 
-       if (!(class_java_lang_ClassCastException =
-                 load_class_bootstrap(utf_java_lang_ClassCastException)) ||
-               !link_class(class_java_lang_ClassCastException))
-               return false;
+*******************************************************************************/
 
-       /* java/lang/ClassNotFoundException */
+void exceptions_set_exception(java_handle_t *e)
+{
+       threadobject  *t;
+       java_object_t *o;
 
-       if (!(class_java_lang_ClassNotFoundException =
-                 load_class_bootstrap(utf_java_lang_ClassNotFoundException)) ||
-               !link_class(class_java_lang_ClassNotFoundException))
-               return false;
+#if defined(ENABLE_THREADS)
+       t = THREADOBJECT;
+#else
+       t = NULL;
+#endif
 
-       /* java/lang/NullPointerException */
+       /* Set the exception. */
 
-       if (!(class_java_lang_NullPointerException =
-                 load_class_bootstrap(utf_java_lang_NullPointerException)) ||
-               !link_class(class_java_lang_NullPointerException))
-               return false;
+       LLNI_CRITICAL_START;
 
+       o = LLNI_UNWRAP(e);
 
-#if defined(WITH_CLASSPATH_GNU)
-       /* java/lang/VMThrowable */
+#if !defined(NDEBUG)
+       if (opt_DebugExceptions) {
+               printf("[exceptions_set_exception  : t=%p, o=%p, class=",
+                          (void *) t, (void *) o);
+               class_print(o->vftbl->class);
+               printf("]\n");
+       }
+#endif
 
-       if (!(class_java_lang_VMThrowable =
-                 load_class_bootstrap(utf_java_lang_VMThrowable)) ||
-               !link_class(class_java_lang_VMThrowable))
-               return false;
+#if defined(ENABLE_THREADS)
+       t->_exceptionptr = o;
+#else
+       _no_threads_exceptionptr = o;
 #endif
 
-       return true;
+       LLNI_CRITICAL_END;
 }
 
 
-/* exceptions_new_class ********************************************************
+/* exceptions_clear_exception **************************************************
 
-   Creates an exception object from the given class and initalizes it.
+   Clears the current exception pointer of the current thread.
 
-   IN:
-      class....class pointer
+*******************************************************************************/
+
+void exceptions_clear_exception(void)
+{
+       threadobject *t;
+
+#if defined(ENABLE_THREADS)
+       t = THREADOBJECT;
+#else
+       t = NULL;
+#endif
+
+       /* Set the exception. */
+
+#if !defined(NDEBUG)
+       if (opt_DebugExceptions) {
+               printf("[exceptions_clear_exception: t=%p]\n", (void *) t);
+       }
+#endif
+
+#if defined(ENABLE_THREADS)
+       t->_exceptionptr = NULL;
+#else
+       _no_threads_exceptionptr = NULL;
+#endif
+}
+
+
+/* exceptions_get_and_clear_exception ******************************************
+
+   Gets the exception pointer of the current thread and clears it.
+   This function may return NULL.
 
 *******************************************************************************/
 
-static java_objectheader *exceptions_new_class(classinfo *c)
+java_handle_t *exceptions_get_and_clear_exception(void)
 {
-       java_objectheader *o;
+       java_handle_t *o;
 
-       o = native_new_and_init(c);
+       /* Get the exception... */
 
-       if (o == NULL)
-               return *exceptionptr;
+       o = exceptions_get_exception();
+
+       /* ...and clear the exception if it is set. */
+
+       if (o != NULL)
+               exceptions_clear_exception();
+
+       /* return the exception */
 
        return o;
 }
 
 
-/* exceptions_new_utf **********************************************************
+/* exceptions_abort ************************************************************
 
-   Creates an exception object with the given name and initalizes it.
+   Prints exception to be thrown and aborts.
 
    IN:
-      classname....class name in UTF-8
+      classname....class name
+      message......exception message
 
 *******************************************************************************/
 
-static java_objectheader *exceptions_new_utf(utf *classname)
+static void exceptions_abort(utf *classname, utf *message)
 {
-       classinfo         *c;
-       java_objectheader *o;
+       log_println("exception thrown while VM is initializing: ");
 
-       c = load_class_bootstrap(classname);
+       log_start();
+       utf_display_printable_ascii_classname(classname);
 
-       if (c == NULL)
-               return *exceptionptr;
+       if (message != NULL) {
+               log_print(": ");
+               utf_display_printable_ascii_classname(message);
+       }
 
-       o = exceptions_new_class(c);
+       log_finish();
 
-       return o;
+       vm_abort("Aborting...");
 }
 
 
-/* exceptions_throw_class ******************************************************
+/* exceptions_new_utf **********************************************************
 
-   Creates an exception object from the given class, initalizes and
-   throws it.
+   Creates an exception object with the given name and initalizes it.
 
    IN:
-      class....class pointer
+      classname....class name in UTF-8
 
 *******************************************************************************/
 
-static void exceptions_throw_class(classinfo *c)
+static java_handle_t *exceptions_new_utf(utf *classname)
 {
-       java_objectheader *o;
+       classinfo     *c;
+       java_handle_t *o;
 
-       o = exceptions_new_class(c);
+       if (vm_initializing)
+               exceptions_abort(classname, NULL);
+
+       c = load_class_bootstrap(classname);
+
+       if (c == NULL)
+               return exceptions_get_exception();
+
+       o = native_new_and_init(c);
 
        if (o == NULL)
-               return;
+               return exceptions_get_exception();
 
-       *exceptionptr = o;
+       return o;
 }
 
 
@@ -255,14 +319,14 @@ static void exceptions_throw_class(classinfo *c)
 
 static void exceptions_throw_utf(utf *classname)
 {
-       classinfo *c;
+       java_handle_t *o;
 
-       c = load_class_bootstrap(classname);
+       o = exceptions_new_utf(classname);
 
-       if (c == NULL)
+       if (o == NULL)
                return;
 
-       exceptions_throw_class(c);
+       exceptions_set_exception(o);
 }
 
 
@@ -278,97 +342,173 @@ static void exceptions_throw_utf(utf *classname)
 *******************************************************************************/
 
 static void exceptions_throw_utf_throwable(utf *classname,
-                                                                                  java_objectheader *cause)
+                                                                                  java_handle_t *cause)
 {
-       java_objectheader *o;
-       classinfo         *c;
-   
+       classinfo           *c;
+       java_handle_t       *o;
+       methodinfo          *m;
+       java_lang_Throwable *object;
+
+       if (vm_initializing)
+               exceptions_abort(classname, NULL);
+
+       object = (java_lang_Throwable *) cause;
+
        c = load_class_bootstrap(classname);
 
        if (c == NULL)
                return;
 
-       o = native_new_and_init_throwable(c, cause);
+       /* create object */
 
+       o = builtin_new(c);
+       
        if (o == NULL)
                return;
 
-       *exceptionptr = o;
+       /* call initializer */
+
+       m = class_resolveclassmethod(c,
+                                                                utf_init,
+                                                                utf_java_lang_Throwable__void,
+                                                                NULL,
+                                                                true);
+                                                     
+       if (m == NULL)
+               return;
+
+       (void) vm_call_method(m, o, cause);
+
+       exceptions_set_exception(o);
 }
 
 
-/* exceptions_new_utf_javastring ***********************************************
+/* exceptions_throw_utf_exception **********************************************
 
    Creates an exception object with the given name and initalizes it
-   with the given java/lang/String message.
+   with the given java/lang/Exception exception.
 
    IN:
       classname....class name in UTF-8
-         message......the message as a java.lang.String
-
-   RETURN VALUE:
-      an exception pointer (in any case -- either it is the newly created
-         exception, or an exception thrown while trying to create it).
+         exception....the given Exception
 
 *******************************************************************************/
 
-static java_objectheader *exceptions_new_utf_javastring(utf *classname,
-                                                                                                               java_objectheader *message)
+static void exceptions_throw_utf_exception(utf *classname,
+                                                                                  java_handle_t *exception)
 {
-       java_objectheader *o;
-       classinfo         *c;
-   
+       classinfo     *c;
+       java_handle_t *o;
+       methodinfo    *m;
+
+       if (vm_initializing)
+               exceptions_abort(classname, NULL);
+
        c = load_class_bootstrap(classname);
 
        if (c == NULL)
-               return *exceptionptr;
+               return;
 
-       o = native_new_and_init_string(c, message);
+       /* create object */
 
+       o = builtin_new(c);
+       
        if (o == NULL)
-               return *exceptionptr;
+               return;
 
-       return o;
+       /* call initializer */
+
+       m = class_resolveclassmethod(c,
+                                                                utf_init,
+                                                                utf_java_lang_Exception__V,
+                                                                NULL,
+                                                                true);
+                                                     
+       if (m == NULL)
+               return;
+
+       (void) vm_call_method(m, o, exception);
+
+       exceptions_set_exception(o);
 }
 
 
-/* exceptions_new_class_utf ****************************************************
+/* exceptions_throw_utf_cause **************************************************
 
-   Creates an exception object of the given class and initalizes it.
+   Creates an exception object with the given name and initalizes it
+   with the given java/lang/Throwable exception with initCause.
 
    IN:
-      c..........class pointer
-      message....the message as UTF-8 string
+      classname....class name in UTF-8
+         cause........the given Throwable
 
 *******************************************************************************/
 
-static java_objectheader *exceptions_new_class_utf(classinfo *c, utf *message)
+static void exceptions_throw_utf_cause(utf *classname, java_handle_t *cause)
 {
-       java_objectheader *o;
-       java_objectheader *s;
+       classinfo           *c;
+       java_handle_t       *o;
+       methodinfo          *m;
+       java_lang_String    *s;
+       java_lang_Throwable *object;
 
-       s = javastring_new(message);
+       if (vm_initializing)
+               exceptions_abort(classname, NULL);
 
-       if (s == NULL)
-               return *exceptionptr;
+       object = (java_lang_Throwable *) cause;
 
-       o = native_new_and_init_string(c, s);
+       c = load_class_bootstrap(classname);
 
+       if (c == NULL)
+               return;
+
+       /* create object */
+
+       o = builtin_new(c);
+       
        if (o == NULL)
-               return *exceptionptr;
+               return;
 
-       return o;
+       /* call initializer */
+
+       m = class_resolveclassmethod(c,
+                                                                utf_init,
+                                                                utf_java_lang_String__void,
+                                                                NULL,
+                                                                true);
+                                                     
+       if (m == NULL)
+               return;
+
+       LLNI_field_get_ref(object, detailMessage, s);
+
+       (void) vm_call_method(m, o, s);
+
+       /* call initCause */
+
+       m = class_resolveclassmethod(c,
+                                                                utf_initCause,
+                                                                utf_java_lang_Throwable__java_lang_Throwable,
+                                                                NULL,
+                                                                true);
+
+       if (m == NULL)
+               return;
+
+       (void) vm_call_method(m, o, cause);
+
+       exceptions_set_exception(o);
 }
 
 
-/* exceptions_new_utf_utf ******************************************************
+/* exceptions_new_utf_javastring ***********************************************
 
    Creates an exception object with the given name and initalizes it
-   with the given utf message.
+   with the given java/lang/String message.
 
    IN:
       classname....class name in UTF-8
-         message......the message as an utf *
+         message......the message as a java.lang.String
 
    RETURN VALUE:
       an exception pointer (in any case -- either it is the newly created
@@ -376,36 +516,69 @@ static java_objectheader *exceptions_new_class_utf(classinfo *c, utf *message)
 
 *******************************************************************************/
 
-static java_objectheader *exceptions_new_utf_utf(utf *classname, utf *message)
+static java_handle_t *exceptions_new_utf_javastring(utf *classname,
+                                                                                                       java_handle_t *message)
 {
-       classinfo         *c;
-       java_objectheader *o;
+       java_handle_t *o;
+       classinfo     *c;
+   
+       if (vm_initializing)
+               exceptions_abort(classname, NULL);
 
        c = load_class_bootstrap(classname);
 
        if (c == NULL)
-               return *exceptionptr;
+               return exceptions_get_exception();
+
+       o = native_new_and_init_string(c, message);
 
-       o = exceptions_new_class_utf(c, message);
+       if (o == NULL)
+               return exceptions_get_exception();
 
        return o;
 }
 
 
-/* exceptions_throw_class_utf **************************************************
+/* exceptions_new_utf_utf ******************************************************
 
-   Creates an exception object of the given class, initalizes and
-   throws it with the given utf message.
+   Creates an exception object with the given name and initalizes it
+   with the given utf message.
 
    IN:
-      c..........class pointer
-         message....the message as an UTF-8
+      classname....class name in UTF-8
+         message......the message as an utf *
+
+   RETURN VALUE:
+      an exception pointer (in any case -- either it is the newly created
+         exception, or an exception thrown while trying to create it).
 
 *******************************************************************************/
 
-static void exceptions_throw_class_utf(classinfo *c, utf *message)
+static java_handle_t *exceptions_new_utf_utf(utf *classname, utf *message)
 {
-       *exceptionptr = exceptions_new_class_utf(c, message);
+       classinfo     *c;
+       java_handle_t *s;
+       java_handle_t *o;
+
+       if (vm_initializing)
+               exceptions_abort(classname, message);
+
+       c = load_class_bootstrap(classname);
+
+       if (c == NULL)
+               return exceptions_get_exception();
+
+       s = javastring_new(message);
+
+       if (s == NULL)
+               return exceptions_get_exception();
+
+       o = native_new_and_init_string(c, s);
+
+       if (o == NULL)
+               return exceptions_get_exception();
+
+       return o;
 }
 
 
@@ -422,7 +595,11 @@ static void exceptions_throw_class_utf(classinfo *c, utf *message)
 
 static void exceptions_throw_utf_utf(utf *classname, utf *message)
 {
-       *exceptionptr = exceptions_new_utf_utf(classname, message);
+       java_handle_t *o;
+
+       o = exceptions_new_utf_utf(classname, message);
+
+       exceptions_set_exception(o);
 }
 
 
@@ -432,9 +609,9 @@ static void exceptions_throw_utf_utf(utf *classname, utf *message)
 
 *******************************************************************************/
 
-java_objectheader *exceptions_new_abstractmethoderror(void)
+java_handle_t *exceptions_new_abstractmethoderror(void)
 {
-       java_objectheader *o;
+       java_handle_t *o;
 
        o = exceptions_new_utf(utf_java_lang_AbstractMethodError);
 
@@ -449,11 +626,11 @@ java_objectheader *exceptions_new_abstractmethoderror(void)
 *******************************************************************************/
 
 #if defined(ENABLE_JAVAME_CLDC1_1)
-static java_objectheader *exceptions_new_error(utf *message)
+static java_handle_t *exceptions_new_error(utf *message)
 {
-       java_objectheader *o;
+       java_handle_t *o;
 
-       o = exceptions_new_class_utf(class_java_lang_Error, message);
+       o = exceptions_new_utf_utf(utf_java_lang_Error, message);
 
        return o;
 }
@@ -467,14 +644,15 @@ static java_objectheader *exceptions_new_error(utf *message)
 
 *******************************************************************************/
 
-java_objectheader *exceptions_asm_new_abstractmethoderror(u1 *sp, u1 *ra)
+java_object_t *exceptions_asm_new_abstractmethoderror(u1 *sp, u1 *ra)
 {
-       stackframeinfo     sfi;
-       java_objectheader *e;
+       stackframeinfo_t  sfi;
+       java_handle_t    *e;
+       java_object_t    *o;
 
-       /* create the stackframeinfo (XPC is equal to RA) */
+       /* Fill and add a stackframeinfo (XPC is equal to RA). */
 
-       stacktrace_create_extern_stackframeinfo(&sfi, NULL, sp, ra, ra);
+       stacktrace_stackframeinfo_add(&sfi, NULL, sp, ra, ra);
 
        /* create the exception */
 
@@ -484,11 +662,16 @@ java_objectheader *exceptions_asm_new_abstractmethoderror(u1 *sp, u1 *ra)
        e = exceptions_new_error(utf_java_lang_AbstractMethodError);
 #endif
 
-       /* remove the stackframeinfo */
+       /* Remove the stackframeinfo. */
 
-       stacktrace_remove_stackframeinfo(&sfi);
+       stacktrace_stackframeinfo_remove(&sfi);
 
-       return e;
+       /* unwrap the exception */
+       /* ATTENTION: do the this _after_ the stackframeinfo was removed */
+
+       o = LLNI_UNWRAP(e);
+
+       return o;
 }
 
 
@@ -498,9 +681,9 @@ java_objectheader *exceptions_asm_new_abstractmethoderror(u1 *sp, u1 *ra)
 
 *******************************************************************************/
 
-java_objectheader *exceptions_new_arraystoreexception(void)
+java_handle_t *exceptions_new_arraystoreexception(void)
 {
-       java_objectheader *o;
+       java_handle_t *o;
 
        o = exceptions_new_utf(utf_java_lang_ArrayStoreException);
 
@@ -610,10 +793,8 @@ void exceptions_throw_classformaterror(classinfo *c, const char *message, ...)
 *******************************************************************************/
 
 void exceptions_throw_classnotfoundexception(utf *name)
-{
-       /* we use class here, as this one is rather frequent */
-
-       exceptions_throw_class_utf(class_java_lang_ClassNotFoundException, name);
+{      
+       exceptions_throw_utf_utf(utf_java_lang_ClassNotFoundException, name);
 }
 
 
@@ -628,10 +809,20 @@ void exceptions_throw_classnotfoundexception(utf *name)
 
 void exceptions_throw_noclassdeffounderror(utf *name)
 {
-       if (vm_initializing)
-               vm_abort("java.lang.NoClassDefFoundError: %s", name->text);
+       exceptions_throw_utf_utf(utf_java_lang_NoClassDefFoundError, name);
+}
+
 
-       exceptions_throw_class_utf(class_java_lang_NoClassDefFoundError, name);
+/* exceptions_throw_noclassdeffounderror_cause *********************************
+
+   Generates and throws a java.lang.NoClassDefFoundError with the
+   given cause.
+
+*******************************************************************************/
+
+void exceptions_throw_noclassdeffounderror_cause(java_handle_t *cause)
+{
+       exceptions_throw_utf_cause(utf_java_lang_NoClassDefFoundError, cause);
 }
 
 
@@ -640,8 +831,6 @@ void exceptions_throw_noclassdeffounderror(utf *name)
    Generates and throws a java.lang.NoClassDefFoundError with a
    specific message:
 
-
-
    IN:
       name.........name of the class not found as a utf *
 
@@ -671,51 +860,6 @@ void exceptions_throw_noclassdeffounderror_wrong_name(classinfo *c, utf *name)
 }
 
 
-/* classnotfoundexception_to_noclassdeffounderror ******************************
-
-   Check the *exceptionptr for a ClassNotFoundException. If it is one,
-   convert it to a NoClassDefFoundError.
-
-*******************************************************************************/
-
-void classnotfoundexception_to_noclassdeffounderror(void)
-{
-       java_objectheader   *xptr;
-       java_objectheader   *cause;
-       java_lang_Throwable *t;
-       java_objectheader   *s;
-
-       /* get the cause */
-
-       cause = *exceptionptr;
-
-       /* convert ClassNotFoundException's to NoClassDefFoundError's */
-
-       if (builtin_instanceof(cause, class_java_lang_ClassNotFoundException)) {
-               /* clear exception, because we are calling jit code again */
-
-               *exceptionptr = NULL;
-
-               /* create new error */
-
-               t = (java_lang_Throwable *) cause;
-               s = (java_objectheader *) t->detailMessage;
-
-               xptr = exceptions_new_utf_javastring(utf_java_lang_NoClassDefFoundError,
-                                                                                        s);
-
-               /* we had an exception while creating the error */
-
-               if (*exceptionptr)
-                       return;
-
-               /* set new exception */
-
-               *exceptionptr = xptr;
-       }
-}
-
-
 /* exceptions_throw_exceptionininitializererror ********************************
 
    Generates and throws a java.lang.ExceptionInInitializerError for
@@ -726,7 +870,7 @@ void classnotfoundexception_to_noclassdeffounderror(void)
 
 *******************************************************************************/
 
-void exceptions_throw_exceptionininitializererror(java_objectheader *cause)
+void exceptions_throw_exceptionininitializererror(java_handle_t *cause)
 {
        exceptions_throw_utf_throwable(utf_java_lang_ExceptionInInitializerError,
                                                                   cause);
@@ -841,39 +985,35 @@ void exceptions_throw_internalerror(const char *message, ...)
 
 void exceptions_throw_linkageerror(const char *message, classinfo *c)
 {
-       java_objectheader *o;
-       char              *msg;
-       s4                 msglen;
+       utf  *u;
+       char *msg;
+       int   len;
 
        /* calculate exception message length */
 
-       msglen = strlen(message) + 1;
+       len = strlen(message) + 1;
 
        if (c != NULL)
-               msglen += utf_bytes(c->name);
+               len += utf_bytes(c->name);
                
        /* allocate memory */
 
-       msg = MNEW(char, msglen);
+       msg = MNEW(char, len);
 
        /* generate message */
 
-       strcpy(msg,message);
+       strcpy(msg, message);
 
        if (c != NULL)
                utf_cat_classname(msg, c->name);
 
-       o = native_new_and_init_string(class_java_lang_LinkageError,
-                                                                  javastring_new_from_utf_string(msg));
+       u = utf_new_char(msg);
 
        /* free memory */
 
-       MFREE(msg, char, msglen);
+       MFREE(msg, char, len);
 
-       if (o == NULL)
-               return;
-
-       *exceptionptr = o;
+       exceptions_throw_utf_utf(utf_java_lang_LinkageError, u);
 }
 
 
@@ -961,7 +1101,7 @@ void exceptions_throw_nosuchmethoderror(classinfo *c, utf *name, utf *desc)
 #if defined(ENABLE_JAVASE)
        exceptions_throw_utf_utf(utf_java_lang_NoSuchMethodError, u);
 #else
-       exceptions_throw_class_utf(class_java_lang_Error, u);
+       exceptions_throw_utf_utf(utf_java_lang_Error, u);
 #endif
 }
 
@@ -974,7 +1114,7 @@ void exceptions_throw_nosuchmethoderror(classinfo *c, utf *name, utf *desc)
 
 void exceptions_throw_outofmemoryerror(void)
 {
-       exceptions_throw_class(class_java_lang_OutOfMemoryError);
+       exceptions_throw_utf(utf_java_lang_OutOfMemoryError);
 }
 
 
@@ -993,7 +1133,7 @@ void exceptions_throw_unsatisfiedlinkerror(utf *name)
 #if defined(ENABLE_JAVASE)
        exceptions_throw_utf_utf(utf_java_lang_UnsatisfiedLinkError, name);
 #else
-       exceptions_throw_class_utf(class_java_lang_Error, name);
+       exceptions_throw_utf_utf(utf_java_lang_Error, name);
 #endif
 }
 
@@ -1192,9 +1332,9 @@ void exceptions_throw_verifyerror_for_stack(methodinfo *m, int type)
 
 *******************************************************************************/
 
-java_objectheader *exceptions_new_arithmeticexception(void)
+java_handle_t *exceptions_new_arithmeticexception(void)
 {
-       java_objectheader *o;
+       java_handle_t *o;
 
        o = exceptions_new_utf_utf(utf_java_lang_ArithmeticException,
                                                           utf_division_by_zero);
@@ -1210,11 +1350,11 @@ java_objectheader *exceptions_new_arithmeticexception(void)
 
 *******************************************************************************/
 
-java_objectheader *exceptions_new_arrayindexoutofboundsexception(s4 index)
+java_handle_t *exceptions_new_arrayindexoutofboundsexception(s4 index)
 {
-       java_objectheader *o;
-       methodinfo        *m;
-       java_objectheader *s;
+       java_handle_t *o;
+       methodinfo    *m;
+       java_handle_t *s;
 
        /* convert the index into a String, like Sun does */
 
@@ -1225,18 +1365,18 @@ java_objectheader *exceptions_new_arrayindexoutofboundsexception(s4 index)
                                                                 true);
 
        if (m == NULL)
-               return *exceptionptr;
+               return exceptions_get_exception();
 
        s = vm_call_method(m, NULL, index);
 
        if (s == NULL)
-               return *exceptionptr;
+               return exceptions_get_exception();
 
        o = exceptions_new_utf_javastring(utf_java_lang_ArrayIndexOutOfBoundsException,
                                                                          s);
 
        if (o == NULL)
-               return *exceptionptr;
+               return exceptions_get_exception();
 
        return o;
 }
@@ -1264,7 +1404,6 @@ void exceptions_throw_arrayindexoutofboundsexception(void)
 void exceptions_throw_arraystoreexception(void)
 {
        exceptions_throw_utf(utf_java_lang_ArrayStoreException);
-/*     e = native_new_and_init(class_java_lang_ArrayStoreException); */
 }
 
 
@@ -1274,14 +1413,17 @@ void exceptions_throw_arraystoreexception(void)
 
 *******************************************************************************/
 
-java_objectheader *exceptions_new_classcastexception(java_objectheader *o)
+java_handle_t *exceptions_new_classcastexception(java_handle_t *o)
 {
-       java_objectheader *e;
-       utf               *classname;
+       java_handle_t *e;
+       classinfo     *c;
+       utf           *classname;
+
+       LLNI_class_get(o, c);
 
-       classname = o->vftbl->class->name;
+       classname = c->name;
 
-       e = exceptions_new_class_utf(class_java_lang_ClassCastException, classname);
+       e = exceptions_new_utf_utf(utf_java_lang_ClassCastException, classname);
 
        return e;
 }
@@ -1306,11 +1448,9 @@ void exceptions_throw_clonenotsupportedexception(void)
 
 *******************************************************************************/
 
-void exceptions_throw_illegalaccessexception(classinfo *c)
+void exceptions_throw_illegalaccessexception(utf *message)
 {
-       /* XXX handle argument */
-
-       exceptions_throw_utf(utf_java_lang_IllegalAccessException);
+       exceptions_throw_utf_utf(utf_java_lang_IllegalAccessException, message);
 }
 
 
@@ -1374,7 +1514,7 @@ void exceptions_throw_interruptedexception(void)
 
 *******************************************************************************/
 
-void exceptions_throw_invocationtargetexception(java_objectheader *cause)
+void exceptions_throw_invocationtargetexception(java_handle_t *cause)
 {
        exceptions_throw_utf_throwable(utf_java_lang_reflect_InvocationTargetException,
                                                                   cause);
@@ -1400,11 +1540,11 @@ void exceptions_throw_negativearraysizeexception(void)
 
 *******************************************************************************/
 
-java_objectheader *exceptions_new_nullpointerexception(void)
+java_handle_t *exceptions_new_nullpointerexception(void)
 {
-       java_objectheader *o;
+       java_handle_t *o;
 
-       o = exceptions_new_class(class_java_lang_NullPointerException);
+       o = exceptions_new_utf(utf_java_lang_NullPointerException);
 
        return o;
 }
@@ -1419,7 +1559,20 @@ java_objectheader *exceptions_new_nullpointerexception(void)
 
 void exceptions_throw_nullpointerexception(void)
 {
-       exceptions_throw_class(class_java_lang_NullPointerException);
+       exceptions_throw_utf(utf_java_lang_NullPointerException);
+}
+
+
+/* exceptions_throw_privilegedactionexception **********************************
+
+   Generates and throws a java.security.PrivilegedActionException.
+
+*******************************************************************************/
+
+void exceptions_throw_privilegedactionexception(java_handle_t *exception)
+{
+       exceptions_throw_utf_exception(utf_java_security_PrivilegedActionException,
+                                                                  exception);
 }
 
 
@@ -1436,45 +1589,57 @@ void exceptions_throw_stringindexoutofboundsexception(void)
 }
 
 
-/* exceptions_get_exception ****************************************************
+/* exceptions_classnotfoundexception_to_noclassdeffounderror *******************
 
-   Returns the current exception pointer of the current thread.
+   Check the exception for a ClassNotFoundException. If it is one,
+   convert it to a NoClassDefFoundError.
 
 *******************************************************************************/
 
-java_objectheader *exceptions_get_exception(void)
+void exceptions_classnotfoundexception_to_noclassdeffounderror(void)
 {
-       /* return the exception */
+       classinfo           *c;
+       java_handle_t       *o;
+       java_handle_t       *cause;
+       java_lang_Throwable *object;
+       java_lang_String    *s;
 
-       return *exceptionptr;
-}
+       /* Load java/lang/ClassNotFoundException for the instanceof
+          check. */
 
+       c = load_class_bootstrap(utf_java_lang_ClassNotFoundException);
 
-/* exceptions_set_exception ****************************************************
+       if (c == NULL)
+               return;
 
-   Sets the exception pointer of the current thread.
+       /* Get the cause. */
 
-*******************************************************************************/
+       cause = exceptions_get_exception();
 
-void exceptions_set_exception(java_objectheader *o)
-{
-       /* set the exception */
+       /* Convert ClassNotFoundException's to NoClassDefFoundError's. */
 
-       *exceptionptr = o;
-}
+       if (builtin_instanceof(cause, c)) {
+               /* clear exception, because we are calling jit code again */
 
+               exceptions_clear_exception();
 
-/* exceptions_clear_exception **************************************************
+               /* create new error */
 
-   Clears the current exception pointer of the current thread.
+               object = (java_lang_Throwable *) cause;
+               LLNI_field_get_ref(object, detailMessage, s);
 
-*******************************************************************************/
+               o = exceptions_new_utf_javastring(utf_java_lang_NoClassDefFoundError,
+                                                                                 (java_handle_t *) s);
 
-void exceptions_clear_exception(void)
-{
-       /* and clear the exception */
+               /* we had an exception while creating the error */
+
+               if (exceptions_get_exception())
+                       return;
 
-       *exceptionptr = NULL;
+               /* set new exception */
+
+               exceptions_set_exception(o);
+       }
 }
 
 
@@ -1485,28 +1650,28 @@ void exceptions_clear_exception(void)
 
 *******************************************************************************/
 
-java_objectheader *exceptions_fillinstacktrace(void)
+java_handle_t *exceptions_fillinstacktrace(void)
 {
-       java_objectheader *o;
-       methodinfo        *m;
+       java_handle_t *o;
+       classinfo     *c;
+       methodinfo    *m;
 
        /* get exception */
 
-       o = *exceptionptr;
-       assert(o);
-
-       /* clear exception */
+       o = exceptions_get_and_clear_exception();
 
-       *exceptionptr = NULL;
+       assert(o);
 
        /* resolve methodinfo pointer from exception object */
 
+       LLNI_class_get(o, c);
+
 #if defined(ENABLE_JAVASE)
-       m = class_resolvemethod(o->vftbl->class,
+       m = class_resolvemethod(c,
                                                        utf_fillInStackTrace,
                                                        utf_void__java_lang_Throwable);
 #elif defined(ENABLE_JAVAME_CLDC1_1)
-       m = class_resolvemethod(o->vftbl->class,
+       m = class_resolvemethod(c,
                                                        utf_fillInStackTrace,
                                                        utf_void__void);
 #else
@@ -1523,110 +1688,6 @@ java_objectheader *exceptions_fillinstacktrace(void)
 }
 
 
-/* exceptions_get_and_clear_exception ******************************************
-
-   Gets the exception pointer of the current thread and clears it.
-   This function may return NULL.
-
-*******************************************************************************/
-
-java_objectheader *exceptions_get_and_clear_exception(void)
-{
-       java_objectheader **p;
-       java_objectheader  *e;
-
-       /* get the pointer of the exception pointer */
-
-       p = exceptionptr;
-
-       /* get the exception */
-
-       e = *p;
-
-       /* and clear the exception */
-
-       *p = NULL;
-
-       /* return the exception */
-
-       return e;
-}
-
-
-/* exceptions_new_hardware_exception *******************************************
-
-   Creates the correct exception for a hardware-exception thrown and
-   caught by a signal handler.
-
-*******************************************************************************/
-
-java_objectheader *exceptions_new_hardware_exception(u1 *pv, u1 *sp, u1 *ra, u1 *xpc, s4 type, ptrint val)
-{
-       stackframeinfo     sfi;
-       java_objectheader *e;
-       java_objectheader *o;
-       s4                 index;
-
-       /* create stackframeinfo */
-
-       stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
-
-       switch (type) {
-       case EXCEPTION_HARDWARE_NULLPOINTER:
-               e = exceptions_new_nullpointerexception();
-               break;
-
-       case EXCEPTION_HARDWARE_ARITHMETIC:
-               e = exceptions_new_arithmeticexception();
-               break;
-
-       case EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS:
-               index = (s4) val;
-               e = exceptions_new_arrayindexoutofboundsexception(index);
-               break;
-
-       case EXCEPTION_HARDWARE_CLASSCAST:
-               o = (java_objectheader *) val;
-               e = exceptions_new_classcastexception(o);
-               break;
-
-       case EXCEPTION_HARDWARE_EXCEPTION:
-               e = exceptions_fillinstacktrace();
-               break;
-
-       default:
-               /* let's try to get a backtrace */
-
-               codegen_get_pv_from_pc(xpc);
-
-               /* if that does not work, print more debug info */
-
-               log_println("exceptions_new_hardware_exception: unknown exception type %d", type);
-
-#if SIZEOF_VOID_P == 8
-               log_println("PC=0x%016lx", xpc);
-#else
-               log_println("PC=0x%08x", xpc);
-#endif
-
-#if defined(ENABLE_DISASSEMBLER)
-               log_println("machine instruction at PC:");
-               disassinstr(xpc);
-#endif
-
-               vm_abort("Exiting...");
-       }
-
-       /* remove stackframeinfo */
-
-       stacktrace_remove_stackframeinfo(&sfi);
-
-       /* return the exception object */
-
-       return e;
-}
-
-
 /* exceptions_handle_exception *************************************************
 
    Try to find an exception handler for the given exception and return it.
@@ -1646,19 +1707,21 @@ java_objectheader *exceptions_new_hardware_exception(u1 *pv, u1 *sp, u1 *ra, u1
 *******************************************************************************/
 
 #if defined(ENABLE_JIT)
-u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp)
+u1 *exceptions_handle_exception(java_object_t *xptro, u1 *xpc, u1 *pv, u1 *sp)
 {
+       stackframeinfo_t       sfi;
+       java_handle_t         *xptr;
        methodinfo            *m;
        codeinfo              *code;
-       s4                     issync;
        dseg_exception_entry  *ex;
        s4                     exceptiontablelength;
        s4                     i;
        classref_or_classinfo  cr;
        classinfo             *c;
 #if defined(ENABLE_THREADS)
-       java_objectheader     *o;
+       java_object_t         *o;
 #endif
+       u1                    *result;
 
 #ifdef __S390__
        /* Addresses are 31 bit integers */
@@ -1667,12 +1730,19 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
 #      define ADDR_MASK(x) (x)
 #endif
 
-       xpc = ADDR_MASK(xpc);
+       xptr = LLNI_WRAP(xptro);
+       xpc  = ADDR_MASK(xpc);
+
+       /* Fill and add a stackframeinfo (XPC is equal to RA). */
+
+       stacktrace_stackframeinfo_add(&sfi, pv, sp, xpc, xpc);
+
+       result = NULL;
+
+       /* Get the codeinfo for the current method. */
 
-       /* get info from the method header */
+       code = code_get_codeinfo_for_pv(pv);
 
-       code                 = *((codeinfo **)            (pv + CodeinfoPointer));
-       issync               = *((s4 *)                   (pv + IsSync));
        ex                   =   (dseg_exception_entry *) (pv + ExTableStart);
        exceptiontablelength = *((s4 *)                   (pv + ExTableSize));
 
@@ -1684,12 +1754,12 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
 #if !defined(NDEBUG)
        /* print exception trace */
 
-       if (opt_verbose || opt_verbosecall || opt_verboseexception)
-               builtin_trace_exception(xptr, m, xpc, 1);
-#endif
+       if (opt_TraceExceptions)
+               trace_exception(LLNI_DIRECT(xptr), m, xpc);
 
-#if defined(ENABLE_VMLOG)
+# if defined(ENABLE_VMLOG)
        vmlog_cacao_throw(xptr);
+# endif
 #endif
 
        for (i = 0; i < exceptiontablelength; i++) {
@@ -1702,8 +1772,10 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
                   special case of asm_vm_call_method.  So, just return the
                   proper exception handler. */
 
-               if ((ex->startpc == NULL) && (ex->endpc == NULL))
-                       return (u1 *) (ptrint) &asm_vm_call_method_exception_handler;
+               if ((ex->startpc == NULL) && (ex->endpc == NULL)) {
+                       result = (u1 *) (ptrint) &asm_vm_call_method_exception_handler;
+                       goto exceptions_handle_exception_return;
+               }
 
                /* is the xpc is the current catch range */
 
@@ -1716,17 +1788,18 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
 #if !defined(NDEBUG)
                                /* Print stacktrace of exception when caught. */
 
-#if defined(ENABLE_VMLOG)
+# if defined(ENABLE_VMLOG)
                                vmlog_cacao_catch(xptr);
-#endif
+# endif
 
-                               if (opt_verboseexception) {
+                               if (opt_TraceExceptions) {
                                        exceptions_print_exception(xptr);
                                        stacktrace_print_trace(xptr);
                                }
 #endif
 
-                               return ex->handlerpc;
+                               result = ex->handlerpc;
+                               goto exceptions_handle_exception_return;
                        }
 
                        /* resolve or load/link the exception class */
@@ -1745,7 +1818,7 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
 
                                if (c == NULL) {
                                        /* Exception resolving the exception class, argh! */
-                                       return NULL;
+                                       goto exceptions_handle_exception_return;
                                }
 
                                /* Ok, we resolved it. Enter it in the table, so we don't */
@@ -1761,14 +1834,14 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
                                        /* use the methods' classloader */
                                        if (!load_class_from_classloader(c->name,
                                                                                                         m->class->classloader))
-                                               return NULL;
+                                               goto exceptions_handle_exception_return;
 
                                /* XXX I think, if it is not linked, we can be sure that     */
                                /* the exception object is no (indirect) instance of it, no? */
                                /* -Edwin                                                    */
                                if (!(c->state & CLASS_LINKED))
                                        if (!link_class(c))
-                                               return NULL;
+                                               goto exceptions_handle_exception_return;
                        }
 
                        /* is the thrown exception an instance of the catch class? */
@@ -1777,33 +1850,34 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
 #if !defined(NDEBUG)
                                /* Print stacktrace of exception when caught. */
 
-#if defined(ENABLE_VMLOG)
+# if defined(ENABLE_VMLOG)
                                vmlog_cacao_catch(xptr);
-#endif
+# endif
 
-                               if (opt_verboseexception) {
+                               if (opt_TraceExceptions) {
                                        exceptions_print_exception(xptr);
                                        stacktrace_print_trace(xptr);
                                }
 #endif
 
-                               return ex->handlerpc;
+                               result = ex->handlerpc;
+                               goto exceptions_handle_exception_return;
                        }
                }
        }
 
 #if defined(ENABLE_THREADS)
-       /* is this method synchronized? */
+       /* Is this method realization synchronized? */
 
-       if (issync) {
-               /* get synchronization object */
+       if (code_is_synchronized(code)) {
+               /* Get synchronization object. */
 
-# if defined(__MIPS__) && (SIZEOF_VOID_P == 4)
+# if defined(__ARM__) || (defined(__MIPS__) && (SIZEOF_VOID_P == 4)) || defined(__I386__) || defined(__S390__) || defined(__POWERPC__)
                /* XXX change this if we ever want to use 4-byte stackslots */
-               o = *((java_objectheader **) (sp + issync - 8));
+               o = *((java_object_t **) (sp + code->synchronizedoffset - 8));
 # else
-               o = *((java_objectheader **) (sp + issync - SIZEOF_VOID_P));
-#endif
+               o = *((java_object_t **) (sp + code->synchronizedoffset - SIZEOF_VOID_P));
+# endif
 
                assert(o != NULL);
 
@@ -1813,11 +1887,38 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
 
        /* none of the exceptions catch this one */
 
-#if defined(ENABLE_VMLOG)
+#if !defined(NDEBUG)
+# if defined(ENABLE_VMLOG)
        vmlog_cacao_unwnd_method(m);
-#endif
+# endif
+
+# if defined(ENABLE_DEBUG_FILTER)
+       if (show_filters_test_verbosecall_exit(m)) {
+# endif
+
+       /* outdent the log message */
+
+       if (opt_verbosecall) {
+               if (TRACEJAVACALLINDENT)
+                       TRACEJAVACALLINDENT--;
+               else
+                       log_text("exceptions_handle_exception: WARNING: unmatched unindent");
+       }
+
+# if defined(ENABLE_DEBUG_FILTER)
+       }
+# endif
+#endif /* !defined(NDEBUG) */
+
+       result = NULL;
+
+exceptions_handle_exception_return:
 
-       return NULL;
+       /* Remove the stackframeinfo. */
+
+       stacktrace_stackframeinfo_remove(&sfi);
+
+       return result;
 }
 #endif /* defined(ENABLE_JIT) */
 
@@ -1829,12 +1930,14 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
 
 *******************************************************************************/
 
-void exceptions_print_exception(java_objectheader *xptr)
+void exceptions_print_exception(java_handle_t *xptr)
 {
        java_lang_Throwable   *t;
 #if defined(ENABLE_JAVASE)
        java_lang_Throwable   *cause;
 #endif
+       java_lang_String      *s;
+       classinfo             *c;
        utf                   *u;
 
        t = (java_lang_Throwable *) xptr;
@@ -1845,15 +1948,18 @@ void exceptions_print_exception(java_objectheader *xptr)
        }
 
 #if defined(ENABLE_JAVASE)
-       cause = t->cause;
+       LLNI_field_get_ref(t, cause, cause);
 #endif
 
        /* print the root exception */
 
-       utf_display_printable_ascii_classname(t->header.vftbl->class->name);
+       LLNI_class_get(t, c);
+       utf_display_printable_ascii_classname(c->name);
 
-       if (t->detailMessage != NULL) {
-               u = javastring_toutf((java_objectheader *) t->detailMessage, false);
+       LLNI_field_get_ref(t, detailMessage, s);
+
+       if (s != NULL) {
+               u = javastring_toutf((java_handle_t *) s, false);
 
                printf(": ");
                utf_display_printable_ascii(u);
@@ -1866,11 +1972,14 @@ void exceptions_print_exception(java_objectheader *xptr)
 
        if ((cause != NULL) && (cause != t)) {
                printf("Caused by: ");
-               utf_display_printable_ascii_classname(cause->header.vftbl->class->name);
+               
+               LLNI_class_get(cause, c);
+               utf_display_printable_ascii_classname(c->name);
 
-               if (cause->detailMessage != NULL) {
-                       u = javastring_toutf((java_objectheader *) cause->detailMessage,
-                                                                false);
+               LLNI_field_get_ref(cause, detailMessage, s);
+
+               if (s != NULL) {
+                       u = javastring_toutf((java_handle_t *) s, false);
 
                        printf(": ");
                        utf_display_printable_ascii(u);
@@ -1891,11 +2000,11 @@ void exceptions_print_exception(java_objectheader *xptr)
 
 void exceptions_print_current_exception(void)
 {
-       java_objectheader *xptr;
+       java_handle_t *o;
 
-       xptr = *exceptionptr;
+       o = exceptions_get_exception();
 
-       exceptions_print_exception(xptr);
+       exceptions_print_exception(o);
 }
 
 
@@ -1911,23 +2020,21 @@ void exceptions_print_current_exception(void)
 
 void exceptions_print_stacktrace(void)
 {
-       java_objectheader *oxptr;
-       java_objectheader *xptr;
-       classinfo         *c;
-       methodinfo        *m;
+       java_handle_t *oxptr;
+       java_handle_t *xptr;
+       classinfo     *c;
+       methodinfo    *m;
 
        /* get original exception */
 
-       oxptr = *exceptionptr;
+       oxptr = exceptions_get_and_clear_exception();
 
        if (oxptr == NULL)
                vm_abort("exceptions_print_stacktrace: no exception thrown");
 
        /* clear exception, because we are calling jit code again */
 
-       *exceptionptr = NULL;
-
-       c = oxptr->vftbl->class;
+       LLNI_class_get(oxptr, c);
 
        /* find the printStackTrace() method */
 
@@ -1952,7 +2059,7 @@ void exceptions_print_stacktrace(void)
           have a serious problem while printStackTrace. But may
           be another exception, so print it. */
 
-       xptr = *exceptionptr;
+       xptr = exceptions_get_exception();
 
        if (xptr != NULL) {
                fprintf(stderr, "Exception while printStackTrace(): ");