* Removed all Id tags.
[cacao.git] / src / vm / exceptions.c
index 79dca438c8ca953ade9307b6a5c90e75786e8f3b..6a340702f6d46ebf34ac87cd05c95b3faad9f2ee 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: exceptions.c 8056 2007-06-10 14:49:57Z michi $
-
 */
 
 
 #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/stacktrace.h"
 
 #include "vmcore/class.h"
 #include "vmcore/loader.h"
+#include "vmcore/method.h"
 #include "vmcore/options.h"
 
 #if defined(ENABLE_VMLOG)
@@ -77,7 +77,7 @@
 /* for raising exceptions from native methods *********************************/
 
 #if !defined(ENABLE_THREADS)
-java_objectheader *_no_threads_exceptionptr = NULL;
+java_object_t *_no_threads_exceptionptr = NULL;
 #endif
 
 
@@ -89,6 +89,10 @@ java_objectheader *_no_threads_exceptionptr = NULL;
 
 bool exceptions_init(void)
 {
+#if !(defined(__ARM__) && defined(__LINUX__))
+       /* On arm-linux the first memory page can't be mmap'ed, as it
+          contains the exception vectors. */
+
        int pagesize;
 
        /* mmap a memory page at address 0x0, so our hardware-exceptions
@@ -97,11 +101,12 @@ bool exceptions_init(void)
        pagesize = getpagesize();
 
        (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, data) <= EXCEPTION_HARDWARE_PATCHER)
-               vm_abort("signal_init: array-data offset is less or equal the maximum hardware-exception displacement: %d <= %d", OFFSET(java_bytearray, data), EXCEPTION_HARDWARE_PATCHER);
+       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);
 
        /* java/lang/Throwable */
 
@@ -189,6 +194,71 @@ bool exceptions_init(void)
 }
 
 
+/* exceptions_get_exception ****************************************************
+
+   Returns the current exception pointer of the current thread.
+
+*******************************************************************************/
+
+java_handle_t *exceptions_get_exception(void)
+{
+       /* return the exception */
+
+       return *exceptionptr;
+}
+
+
+/* exceptions_set_exception ****************************************************
+
+   Sets the exception pointer of the current thread.
+
+*******************************************************************************/
+
+void exceptions_set_exception(java_handle_t *o)
+{
+       /* set the exception */
+
+       *exceptionptr = o;
+}
+
+
+/* exceptions_clear_exception **************************************************
+
+   Clears the current exception pointer of the current thread.
+
+*******************************************************************************/
+
+void exceptions_clear_exception(void)
+{
+       exceptions_set_exception(NULL);
+}
+
+
+/* exceptions_get_and_clear_exception ******************************************
+
+   Gets the exception pointer of the current thread and clears it.
+   This function may return NULL.
+
+*******************************************************************************/
+
+java_handle_t *exceptions_get_and_clear_exception(void)
+{
+       java_handle_t *o;
+
+       /* get the exception */
+
+       o = exceptions_get_exception();
+
+       /* and clear the exception */
+
+       exceptions_clear_exception();
+
+       /* return the exception */
+
+       return o;
+}
+
+
 /* exceptions_new_class ********************************************************
 
    Creates an exception object from the given class and initalizes it.
@@ -198,14 +268,14 @@ bool exceptions_init(void)
 
 *******************************************************************************/
 
-static java_objectheader *exceptions_new_class(classinfo *c)
+static java_handle_t *exceptions_new_class(classinfo *c)
 {
-       java_objectheader *o;
+       java_handle_t *o;
 
        o = native_new_and_init(c);
 
        if (o == NULL)
-               return *exceptionptr;
+               return exceptions_get_exception();
 
        return o;
 }
@@ -220,15 +290,15 @@ static java_objectheader *exceptions_new_class(classinfo *c)
 
 *******************************************************************************/
 
-static java_objectheader *exceptions_new_utf(utf *classname)
+static java_handle_t *exceptions_new_utf(utf *classname)
 {
-       classinfo         *c;
-       java_objectheader *o;
+       classinfo     *c;
+       java_handle_t *o;
 
        c = load_class_bootstrap(classname);
 
        if (c == NULL)
-               return *exceptionptr;
+               return exceptions_get_exception();
 
        o = exceptions_new_class(c);
 
@@ -248,14 +318,14 @@ static java_objectheader *exceptions_new_utf(utf *classname)
 
 static void exceptions_throw_class(classinfo *c)
 {
-       java_objectheader *o;
+       java_handle_t *o;
 
        o = exceptions_new_class(c);
 
        if (o == NULL)
                return;
 
-       *exceptionptr = o;
+       exceptions_set_exception(o);
 }
 
 
@@ -294,22 +364,41 @@ 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;
+
+       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);
 }
 
 
@@ -325,22 +414,103 @@ static void exceptions_throw_utf_throwable(utf *classname,
 *******************************************************************************/
 
 static void exceptions_throw_utf_exception(utf *classname,
-                                                                                  java_objectheader *exception)
+                                                                                  java_handle_t *exception)
 {
-       java_objectheader *o;
-       classinfo         *c;
-   
+       classinfo     *c;
+       java_handle_t *o;
+       methodinfo    *m;
+
        c = load_class_bootstrap(classname);
 
        if (c == NULL)
                return;
 
-       o = native_new_and_init_exception(c, exception);
+       /* create object */
 
+       o = builtin_new(c);
+       
        if (o == NULL)
                return;
 
-       *exceptionptr = 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_throw_utf_cause **************************************************
+
+   Creates an exception object with the given name and initalizes it
+   with the given java/lang/Throwable exception with initCause.
+
+   IN:
+      classname....class name in UTF-8
+         cause........the given Throwable
+
+*******************************************************************************/
+
+static void exceptions_throw_utf_cause(utf *classname, java_handle_t *cause)
+{
+       classinfo           *c;
+       java_handle_t       *o;
+       methodinfo          *m;
+       java_lang_String    *s;
+       java_lang_Throwable *object;
+
+       object = (java_lang_Throwable *) cause;
+
+       c = load_class_bootstrap(classname);
+
+       if (c == NULL)
+               return;
+
+       /* create object */
+
+       o = builtin_new(c);
+       
+       if (o == NULL)
+               return;
+
+       /* 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);
 }
 
 
@@ -359,21 +529,21 @@ static void exceptions_throw_utf_exception(utf *classname,
 
 *******************************************************************************/
 
-static java_objectheader *exceptions_new_utf_javastring(utf *classname,
-                                                                                                               java_objectheader *message)
+static java_handle_t *exceptions_new_utf_javastring(utf *classname,
+                                                                                                       java_handle_t *message)
 {
-       java_objectheader *o;
-       classinfo         *c;
+       java_handle_t *o;
+       classinfo     *c;
    
        c = load_class_bootstrap(classname);
 
        if (c == NULL)
-               return *exceptionptr;
+               return exceptions_get_exception();
 
        o = native_new_and_init_string(c, message);
 
        if (o == NULL)
-               return *exceptionptr;
+               return exceptions_get_exception();
 
        return o;
 }
@@ -389,20 +559,20 @@ static java_objectheader *exceptions_new_utf_javastring(utf *classname,
 
 *******************************************************************************/
 
-static java_objectheader *exceptions_new_class_utf(classinfo *c, utf *message)
+static java_handle_t *exceptions_new_class_utf(classinfo *c, utf *message)
 {
-       java_objectheader *o;
-       java_objectheader *s;
+       java_handle_t *o;
+       java_handle_t *s;
 
        s = javastring_new(message);
 
        if (s == NULL)
-               return *exceptionptr;
+               return exceptions_get_exception();
 
        o = native_new_and_init_string(c, s);
 
        if (o == NULL)
-               return *exceptionptr;
+               return exceptions_get_exception();
 
        return o;
 }
@@ -423,15 +593,15 @@ 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_utf(utf *classname, utf *message)
 {
-       classinfo         *c;
-       java_objectheader *o;
+       classinfo     *c;
+       java_handle_t *o;
 
        c = load_class_bootstrap(classname);
 
        if (c == NULL)
-               return *exceptionptr;
+               return exceptions_get_exception();
 
        o = exceptions_new_class_utf(c, message);
 
@@ -452,7 +622,11 @@ static java_objectheader *exceptions_new_utf_utf(utf *classname, utf *message)
 
 static void exceptions_throw_class_utf(classinfo *c, utf *message)
 {
-       *exceptionptr = exceptions_new_class_utf(c, message);
+       java_handle_t *o;
+
+       o = exceptions_new_class_utf(c, message);
+
+       exceptions_set_exception(o);
 }
 
 
@@ -469,7 +643,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);
 }
 
 
@@ -479,9 +657,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);
 
@@ -496,9 +674,9 @@ 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);
 
@@ -514,10 +692,10 @@ 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  sfi;
+       java_handle_t  *e;
 
        /* create the stackframeinfo (XPC is equal to RA) */
 
@@ -545,9 +723,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);
 
@@ -682,13 +860,24 @@ void exceptions_throw_noclassdeffounderror(utf *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);
+}
+
+
 /* exceptions_throw_noclassdeffounderror_wrong_name ****************************
 
    Generates and throws a java.lang.NoClassDefFoundError with a
    specific message:
 
-
-
    IN:
       name.........name of the class not found as a utf *
 
@@ -718,51 +907,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
@@ -773,7 +917,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);
@@ -888,9 +1032,9 @@ void exceptions_throw_internalerror(const char *message, ...)
 
 void exceptions_throw_linkageerror(const char *message, classinfo *c)
 {
-       java_objectheader *o;
-       char              *msg;
-       s4                 msglen;
+       java_handle_t *o;
+       char          *msg;
+       s4             msglen;
 
        /* calculate exception message length */
 
@@ -920,7 +1064,7 @@ void exceptions_throw_linkageerror(const char *message, classinfo *c)
        if (o == NULL)
                return;
 
-       *exceptionptr = o;
+       exceptions_set_exception(o);
 }
 
 
@@ -1239,9 +1383,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);
@@ -1257,11 +1401,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 */
 
@@ -1272,18 +1416,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;
 }
@@ -1321,10 +1465,10 @@ 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;
+       utf           *classname;
 
        classname = o->vftbl->class->name;
 
@@ -1419,7 +1563,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);
@@ -1445,9 +1589,9 @@ 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);
 
@@ -1474,7 +1618,7 @@ void exceptions_throw_nullpointerexception(void)
 
 *******************************************************************************/
 
-void exceptions_throw_privilegedactionexception(java_objectheader *exception)
+void exceptions_throw_privilegedactionexception(java_handle_t *exception)
 {
        exceptions_throw_utf_exception(utf_java_security_PrivilegedActionException,
                                                                   exception);
@@ -1494,45 +1638,48 @@ 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 */
+       java_handle_t       *o;
+       java_handle_t       *cause;
+       java_lang_Throwable *object;
+       java_lang_String    *s;
 
-       return *exceptionptr;
-}
+       /* get the cause */
 
+       cause = exceptions_get_exception();
 
-/* exceptions_set_exception ****************************************************
+       /* convert ClassNotFoundException's to NoClassDefFoundError's */
 
-   Sets the exception pointer of the current thread.
+       if (builtin_instanceof(cause, class_java_lang_ClassNotFoundException)) {
+               /* clear exception, because we are calling jit code again */
 
-*******************************************************************************/
+               exceptions_clear_exception();
 
-void exceptions_set_exception(java_objectheader *o)
-{
-       /* set the exception */
-
-       *exceptionptr = o;
-}
+               /* create new error */
 
+               object = (java_lang_Throwable *) cause;
+               LLNI_field_get_ref(object, detailMessage, s);
 
-/* exceptions_clear_exception **************************************************
+               o = exceptions_new_utf_javastring(utf_java_lang_NoClassDefFoundError,
+                                                                                 (java_handle_t *) s);
 
-   Clears the current exception pointer of the current thread.
+               /* we had an exception while creating the error */
 
-*******************************************************************************/
+               if (exceptions_get_exception())
+                       return;
 
-void exceptions_clear_exception(void)
-{
-       /* and clear the exception */
+               /* set new exception */
 
-       *exceptionptr = NULL;
+               exceptions_set_exception(o);
+       }
 }
 
 
@@ -1543,19 +1690,16 @@ 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;
+       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 */
 
@@ -1581,114 +1725,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...");
-
-               /* keep compiler happy */
-
-               e = NULL;
-       }
-
-       /* 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.
@@ -1708,7 +1744,7 @@ 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 *xptr, u1 *xpc, u1 *pv, u1 *sp)
 {
        methodinfo            *m;
        codeinfo              *code;
@@ -1719,7 +1755,7 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
        classref_or_classinfo  cr;
        classinfo             *c;
 #if defined(ENABLE_THREADS)
-       java_objectheader     *o;
+       java_object_t         *o;
 #endif
 
 #ifdef __S390__
@@ -1746,7 +1782,7 @@ 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)
+       if (opt_verbose || opt_verbosecall || opt_TraceExceptions)
                builtin_trace_exception(xptr, m, xpc, 1);
 #endif
 
@@ -1782,7 +1818,7 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
                                vmlog_cacao_catch(xptr);
 #endif
 
-                               if (opt_verboseexception) {
+                               if (opt_TraceExceptions) {
                                        exceptions_print_exception(xptr);
                                        stacktrace_print_trace(xptr);
                                }
@@ -1843,7 +1879,7 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
                                vmlog_cacao_catch(xptr);
 #endif
 
-                               if (opt_verboseexception) {
+                               if (opt_TraceExceptions) {
                                        exceptions_print_exception(xptr);
                                        stacktrace_print_trace(xptr);
                                }
@@ -1860,12 +1896,12 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
        if (issync) {
                /* get synchronization object */
 
-# if defined(__MIPS__) && (SIZEOF_VOID_P == 4)
+# if (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 + issync - 8));
 # else
-               o = *((java_objectheader **) (sp + issync - SIZEOF_VOID_P));
-#endif
+               o = *((java_object_t **) (sp + issync - SIZEOF_VOID_P));
+# endif
 
                assert(o != NULL);
 
@@ -1891,12 +1927,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;
@@ -1907,15 +1945,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);
+
+       LLNI_field_get_ref(t, detailMessage, s);
 
-       if (t->detailMessage != NULL) {
-               u = javastring_toutf((java_objectheader *) t->detailMessage, false);
+       if (s != NULL) {
+               u = javastring_toutf((java_handle_t *) s, false);
 
                printf(": ");
                utf_display_printable_ascii(u);
@@ -1928,11 +1969,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);
@@ -1953,11 +1997,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);
 }
 
 
@@ -1973,22 +2017,20 @@ 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;
 
        /* find the printStackTrace() method */
@@ -2014,7 +2056,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(): ");