* src/vm/array.c: Changed copyright.
[cacao.git] / src / vm / exceptions.c
index e2bd111a81c4e5856b1a583d1fdbc8c46ba3d01b..b231276c032f5c10ffec7468a0a53ed90c10f50a 100644 (file)
@@ -89,7 +89,7 @@ java_object_t *_no_threads_exceptionptr = NULL;
 
 *******************************************************************************/
 
-bool exceptions_init(void)
+void exceptions_init(void)
 {
 #if !(defined(__ARM__) && defined(__LINUX__))
        /* On arm-linux the first memory page can't be mmap'ed, as it
@@ -109,15 +109,6 @@ bool exceptions_init(void)
 
        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 */
-
-       if (!(class_java_lang_Throwable =
-                 load_class_bootstrap(utf_java_lang_Throwable)) ||
-               !link_class(class_java_lang_Throwable))
-               return false;
-
-       return true;
 }
 
 
@@ -655,13 +646,13 @@ static java_handle_t *exceptions_new_error(utf *message)
 
 java_object_t *exceptions_asm_new_abstractmethoderror(u1 *sp, u1 *ra)
 {
-       stackframeinfo  sfi;
-       java_handle_t  *e;
-       java_object_t  *o;
+       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 */
 
@@ -671,9 +662,9 @@ java_object_t *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);
 
        /* unwrap the exception */
        /* ATTENTION: do the this _after_ the stackframeinfo was removed */
@@ -994,10 +985,9 @@ void exceptions_throw_internalerror(const char *message, ...)
 
 void exceptions_throw_linkageerror(const char *message, classinfo *c)
 {
-       java_handle_t *o;
-       utf           *u;
-       char          *msg;
-       int            len;
+       utf  *u;
+       char *msg;
+       int   len;
 
        /* calculate exception message length */
 
@@ -1019,16 +1009,11 @@ void exceptions_throw_linkageerror(const char *message, classinfo *c)
 
        u = utf_new_char(msg);
 
-       o = exceptions_new_utf_utf(utf_java_lang_LinkageError, u);
-
        /* free memory */
 
        MFREE(msg, char, len);
 
-       if (o == NULL)
-               return;
-
-       exceptions_set_exception(o);
+       exceptions_throw_utf_utf(utf_java_lang_LinkageError, u);
 }
 
 
@@ -1724,20 +1709,19 @@ java_handle_t *exceptions_fillinstacktrace(void)
 #if defined(ENABLE_JIT)
 u1 *exceptions_handle_exception(java_object_t *xptro, u1 *xpc, u1 *pv, u1 *sp)
 {
-       stackframeinfo         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;
+       stackframeinfo_t        sfi;
+       java_handle_t          *xptr;
+       methodinfo             *m;
+       codeinfo               *code;
+       exceptiontable_t       *et;
+       exceptiontable_entry_t *ete;
+       s4                      i;
+       classref_or_classinfo   cr;
+       classinfo              *c;
 #if defined(ENABLE_THREADS)
-       java_object_t         *o;
+       java_object_t          *o;
 #endif
-       u1                    *result;
+       u1                     *result;
 
 #ifdef __S390__
        /* Addresses are 31 bit integers */
@@ -1749,23 +1733,26 @@ u1 *exceptions_handle_exception(java_object_t *xptro, u1 *xpc, u1 *pv, u1 *sp)
        xptr = LLNI_WRAP(xptro);
        xpc  = ADDR_MASK(xpc);
 
-       /* create the stackframeinfo (XPC is equal to RA) */
+       /* Fill and add a stackframeinfo (XPC is equal to RA). */
 
-       stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, xpc, xpc);
+       stacktrace_stackframeinfo_add(&sfi, pv, sp, xpc, xpc);
 
        result = NULL;
 
-       /* get info from the method header */
+       /* Get the codeinfo for the current method. */
 
-       code                 = *((codeinfo **)            (pv + CodeinfoPointer));
-       issync               = *((s4 *)                   (pv + IsSync));
-       ex                   =   (dseg_exception_entry *) (pv + ExTableStart);
-       exceptiontablelength = *((s4 *)                   (pv + ExTableSize));
+       code = code_get_codeinfo_for_pv(pv);
 
        /* Get the methodinfo pointer from the codeinfo pointer. For
-          asm_vm_call_method the codeinfo pointer is NULL. */
+          asm_vm_call_method the codeinfo pointer is NULL and we simply
+          can return the proper exception handler. */
+
+       if (code == NULL) {
+               result = (u1 *) (uintptr_t) &asm_vm_call_method_exception_handler;
+               goto exceptions_handle_exception_return;
+       }
 
-       m = (code == NULL) ? NULL : code->m;
+       m = code->m;
 
 #if !defined(NDEBUG)
        /* print exception trace */
@@ -1778,25 +1765,20 @@ u1 *exceptions_handle_exception(java_object_t *xptro, u1 *xpc, u1 *pv, u1 *sp)
 # endif
 #endif
 
-       for (i = 0; i < exceptiontablelength; i++) {
-               /* ATTENTION: keep this here, as we need to decrement the
-           pointer before the loop executes! */
+       /* Get the exception table. */
 
-               ex--;
+       et = code->exceptiontable;
 
-               /* If the start and end PC is NULL, this means we have the
-                  special case of asm_vm_call_method.  So, just return the
-                  proper exception handler. */
+       if (et != NULL) {
+       /* Iterate over all exception table entries. */
 
-               if ((ex->startpc == NULL) && (ex->endpc == NULL)) {
-                       result = (u1 *) (ptrint) &asm_vm_call_method_exception_handler;
-                       goto exceptions_handle_exception_return;
-               }
+       ete = et->entries;
 
+       for (i = 0; i < et->length; i++, ete++) {
                /* is the xpc is the current catch range */
 
-               if ((ADDR_MASK(ex->startpc) <= xpc) && (xpc < ADDR_MASK(ex->endpc))) {
-                       cr = ex->catchtype;
+               if ((ADDR_MASK(ete->startpc) <= xpc) && (xpc < ADDR_MASK(ete->endpc))) {
+                       cr = ete->catchtype;
 
                        /* NULL catches everything */
 
@@ -1814,7 +1796,7 @@ u1 *exceptions_handle_exception(java_object_t *xptro, u1 *xpc, u1 *pv, u1 *sp)
                                }
 #endif
 
-                               result = ex->handlerpc;
+                               result = ete->handlerpc;
                                goto exceptions_handle_exception_return;
                        }
 
@@ -1822,13 +1804,14 @@ u1 *exceptions_handle_exception(java_object_t *xptro, u1 *xpc, u1 *pv, u1 *sp)
 
                        if (IS_CLASSREF(cr)) {
                                /* The exception class reference is unresolved. */
-                               /* We have to do _eager_ resolving here. While the class of */
-                               /* the exception object is guaranteed to be loaded, it may  */
-                               /* well have been loaded by a different loader than the     */
-                               /* defining loader of m's class, which is the one we must   */
-                               /* use to resolve the catch class. Thus lazy resolving      */
-                               /* might fail, even if the result of the resolution would   */
-                               /* be an already loaded class.                              */
+                               /* We have to do _eager_ resolving here. While the
+                                  class of the exception object is guaranteed to be
+                                  loaded, it may well have been loaded by a different
+                                  loader than the defining loader of m's class, which
+                                  is the one we must use to resolve the catch
+                                  class. Thus lazy resolving might fail, even if the
+                                  result of the resolution would be an already loaded
+                                  class. */
 
                                c = resolve_classref_eager(cr.ref);
 
@@ -1837,12 +1820,13 @@ u1 *exceptions_handle_exception(java_object_t *xptro, u1 *xpc, u1 *pv, u1 *sp)
                                        goto exceptions_handle_exception_return;
                                }
 
-                               /* Ok, we resolved it. Enter it in the table, so we don't */
-                               /* have to do this again.                                 */
-                               /* XXX this write should be atomic. Is it?                */
+                               /* Ok, we resolved it. Enter it in the table, so we
+                                  don't have to do this again. */
+                               /* XXX this write should be atomic. Is it? */
 
-                               ex->catchtype.cls = c;
-                       } else {
+                               ete->catchtype.cls = c;
+                       }
+                       else {
                                c = cr.cls;
 
                                /* XXX I don't think this case can ever happen. -Edwin */
@@ -1852,9 +1836,9 @@ u1 *exceptions_handle_exception(java_object_t *xptro, u1 *xpc, u1 *pv, u1 *sp)
                                                                                                         m->class->classloader))
                                                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                                                    */
+                               /* 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))
                                                goto exceptions_handle_exception_return;
@@ -1876,28 +1860,24 @@ u1 *exceptions_handle_exception(java_object_t *xptro, u1 *xpc, u1 *pv, u1 *sp)
                                }
 #endif
 
-                               result = ex->handlerpc;
+                               result = ete->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)) || defined(__I386__) || defined(__S390__) || defined(__POWERPC__)
-               /* XXX change this if we ever want to use 4-byte stackslots */
-               o = *((java_object_t **) (sp + issync - 8));
-# else
-               o = *((java_object_t **) (sp + issync - SIZEOF_VOID_P));
-# endif
+               o = *((java_object_t **) (sp + code->synchronizedoffset));
 
                assert(o != NULL);
 
-               lock_monitor_exit(o);
+               lock_monitor_exit(LLNI_QUICKWRAP(o));
        }
 #endif
 
@@ -1930,9 +1910,9 @@ u1 *exceptions_handle_exception(java_object_t *xptro, u1 *xpc, u1 *pv, u1 *sp)
 
 exceptions_handle_exception_return:
 
-       /* remove the stackframeinfo */
+       /* Remove the stackframeinfo. */
 
-       stacktrace_remove_stackframeinfo(&sfi);
+       stacktrace_stackframeinfo_remove(&sfi);
 
        return result;
 }