* src/vm/jit/parse.c, src/vm/jit/parse.h (Changes): Merged with
[cacao.git] / src / vm / exceptions.c
index d26a789e8354a34009f69d1607125c239095203e..fdf447892942ebe0a280282ed9dd7715bcf35d57 100644 (file)
@@ -28,7 +28,7 @@
 
    Changes: Edwin Steiner
 
-   $Id: exceptions.c 5088 2006-07-08 20:16:05Z twisti $
+   $Id: exceptions.c 5935 2006-11-08 20:27:37Z twisti $
 
 */
 
@@ -984,7 +984,7 @@ java_objectheader *new_unsupportedclassversionerror(classinfo *c, const char *me
 }
 
 
-/* new_verifyerror *************************************************************
+/* exceptions_new_verifyerror **************************************************
 
    Generates a java.lang.VerifyError for the JIT compiler.
 
@@ -998,7 +998,8 @@ java_objectheader *new_unsupportedclassversionerror(classinfo *c, const char *me
 
 *******************************************************************************/
 
-java_objectheader *new_verifyerror(methodinfo *m, const char *message, ...)
+java_objectheader *exceptions_new_verifyerror(methodinfo *m,
+                                                                                         const char *message, ...)
 {
        java_objectheader *o;
        va_list            ap;
@@ -1053,6 +1054,18 @@ java_objectheader *new_verifyerror(methodinfo *m, const char *message, ...)
 }
 
 
+/* exceptions_throw_verifyerror ************************************************
+
+   Throws a java.lang.VerifyError for the VM system.
+
+*******************************************************************************/
+
+void exceptions_throw_verifyerror(methodinfo *m, const char *message, ...)
+{
+       *exceptionptr = exceptions_new_verifyerror(m, message);
+}
+
+
 /* exceptions_throw_verifyerror_for_stack **************************************
 
    throws a java.lang.VerifyError for an invalid stack slot type
@@ -1111,6 +1124,7 @@ void exceptions_throw_verifyerror_for_stack(methodinfo *m,int type)
                case TYPE_FLT: typename = "float"; break;
                case TYPE_DBL: typename = "double"; break;
                case TYPE_ADR: typename = "object/array"; break;
+               case TYPE_RET: typename = "returnAddress"; break;
                default:       typename = "<INVALID>"; assert(0); break;
        }
        strcat(msg, typename);
@@ -1210,13 +1224,13 @@ void exceptions_throw_arrayindexoutofboundsexception(void)
 }
 
 
-/* new_arraystoreexception *****************************************************
+/* exceptions_new_arraystoreexception ******************************************
 
-   generates a java.lang.ArrayStoreException for the jit compiler
+   Generates a java.lang.ArrayStoreException for the VM compiler.
 
 *******************************************************************************/
 
-java_objectheader *new_arraystoreexception(void)
+java_objectheader *exceptions_new_arraystoreexception(void)
 {
        java_objectheader *e;
 
@@ -1230,6 +1244,19 @@ java_objectheader *new_arraystoreexception(void)
 }
 
 
+/* exceptions_throw_arraystoreexception ****************************************
+
+   Generates a java.lang.ArrayStoreException for the VM system and
+   throw it in the VM system.
+
+*******************************************************************************/
+
+void exceptions_throw_arraystoreexception(void)
+{
+       *exceptionptr = exceptions_new_arraystoreexception();
+}
+
+
 /* exceptions_new_classcastexception *******************************************
 
    Generates a java.lang.ClassCastException for the JIT compiler.
@@ -1287,26 +1314,39 @@ void exceptions_throw_illegalargumentexception(void)
 }
 
 
-/* new_illegalmonitorstateexception ********************************************
+/* exceptions_new_illegalmonitorstateexception *********************************
 
    Generates a java.lang.IllegalMonitorStateException for the VM
    thread system.
 
 *******************************************************************************/
 
-java_objectheader *new_illegalmonitorstateexception(void)
+java_objectheader *exceptions_new_illegalmonitorstateexception(void)
 {
        java_objectheader *e;
 
        e = native_new_and_init(class_java_lang_IllegalMonitorStateException);
 
-       if (!e)
+       if (e == NULL)
                return *exceptionptr;
 
        return e;
 }
 
 
+/* exceptions_throw_illegalmonitorstateexception *******************************
+
+   Generates a java.lang.IllegalMonitorStateException for the VM
+   system and throw it in the VM system.
+
+*******************************************************************************/
+
+void exceptions_throw_illegalmonitorstateexception(void)
+{
+       *exceptionptr = exceptions_new_illegalmonitorstateexception();
+}
+
+
 /* exceptions_new_negativearraysizeexception ***********************************
 
    Generates a java.lang.NegativeArraySizeException for the VM system.
@@ -1338,19 +1378,19 @@ void exceptions_throw_negativearraysizeexception(void)
 }
 
 
-/* new_nullpointerexception ****************************************************
+/* exceptions_new_nullpointerexception *****************************************
 
-   generates a java.lang.NullPointerException for the jit compiler
+   Generates a java.lang.NullPointerException for the VM system.
 
 *******************************************************************************/
 
-java_objectheader *new_nullpointerexception(void)
+java_objectheader *exceptions_new_nullpointerexception(void)
 {
        java_objectheader *e;
 
        e = native_new_and_init(class_java_lang_NullPointerException);
 
-       if (!e)
+       if (e == NULL)
                return *exceptionptr;
 
        return e;
@@ -1366,7 +1406,7 @@ java_objectheader *new_nullpointerexception(void)
 
 void exceptions_throw_nullpointerexception(void)
 {
-       *exceptionptr = new_nullpointerexception();
+       *exceptionptr = exceptions_new_nullpointerexception();
 }
 
 
@@ -1451,13 +1491,13 @@ java_objectheader *exceptions_get_and_clear_exception(void)
 
 *******************************************************************************/
 
+#if defined(ENABLE_JIT)
 u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp)
 {
        methodinfo            *m;
        codeinfo              *code;
-       s4                     framesize;
        s4                     issync;
-       exceptionentry        *ex;
+       dseg_exception_entry  *ex;
        s4                     exceptiontablelength;
        s4                     i;
        classref_or_classinfo  cr;
@@ -1468,11 +1508,10 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
 
        /* get info from the method header */
 
-       code                 = *((codeinfo **)      (pv + CodeinfoPointer));
-       framesize            = *((s4 *)             (pv + FrameSize));
-       issync               = *((s4 *)             (pv + IsSync));
-       ex                   =   (exceptionentry *) (pv + ExTableStart);
-       exceptiontablelength = *((s4 *)             (pv + ExTableSize));
+       code                 = *((codeinfo **)            (pv + CodeinfoPointer));
+       issync               = *((s4 *)                   (pv + IsSync));
+       ex                   =   (dseg_exception_entry *) (pv + ExTableStart);
+       exceptiontablelength = *((s4 *)                   (pv + ExTableSize));
 
        /* Get the methodinfo pointer from the codeinfo pointer. For
           asm_vm_call_method the codeinfo pointer is NULL. */
@@ -1522,17 +1561,40 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
                        /* resolve or load/link the exception class */
 
                        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.                              */
+
                                c = resolve_classref_eager(cr.ref);
 
+                               if (c == NULL) {
+                                       /* Exception resolving the exception class, argh! */
+                                       return NULL;
+                               }
+
+                               /* 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 {
                                c = cr.cls;
 
+                               /* XXX I don't think this case can ever happen. -Edwin */
                                if (!(c->state & CLASS_LOADED))
                                        /* use the methods' classloader */
                                        if (!load_class_from_classloader(c->name,
                                                                                                         m->class->classloader))
                                                return NULL;
 
+                               /* 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;
@@ -1570,7 +1632,7 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
 
                assert(o != NULL);
 
-               builtin_monitorexit(o);
+               lock_monitor_exit(o);
        }
 #endif
 
@@ -1578,6 +1640,7 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
 
        return NULL;
 }
+#endif /* defined(ENABLE_JIT) */
 
 
 /* exceptions_print_exception **************************************************
@@ -1587,7 +1650,6 @@ u1 *exceptions_handle_exception(java_objectheader *xptr, u1 *xpc, u1 *pv, u1 *sp
 
 *******************************************************************************/
 
-#if !defined(NDEBUG)
 void exceptions_print_exception(java_objectheader *xptr)
 {
        java_lang_Throwable   *t;
@@ -1618,7 +1680,7 @@ void exceptions_print_exception(java_objectheader *xptr)
 
        /* print the cause if available */
 
-       if (cause && (cause != t)) {
+       if ((cause != NULL) && (cause != t)) {
                printf("Caused by: ");
                utf_display_printable_ascii_classname(cause->header.vftbl->class->name);
 
@@ -1632,7 +1694,6 @@ void exceptions_print_exception(java_objectheader *xptr)
                putc('\n', stdout);
        }
 }
-#endif /* !defined(NDEBUG) */
 
 
 /*