* src/vm/jit/intrp/codegen.c (nativecall): Store return valud of
[cacao.git] / src / vm / jit / intrp / asmpart.c
index f0a02126eea6081d74a99c06a306f709bfda8a5f..288fa7c3a96673bbf9b590a34c3cf6da826c227e 100644 (file)
@@ -29,7 +29,7 @@
 
    Changes:
 
-   $Id: asmpart.c 5233 2006-08-14 10:59:39Z twisti $
+   $Id: asmpart.c 5668 2006-10-04 16:01:53Z edwin $
 
 */
 
@@ -175,11 +175,12 @@ double intrp_asm_vm_call_method_double(methodinfo *m, s4 vmargscount,
 
 Inst *intrp_asm_handle_exception(Inst *ip, java_objectheader *o, Cell *fp, Cell **new_spp, Cell **new_fpp)
 {
-       classinfo      *c;
-       s4              framesize;
-       exceptionentry *ex;
-       s4              exceptiontablelength;
-       s4              i;
+       classinfo            *c;
+       classref_or_classinfo cr;
+       s4                    framesize;
+       exceptionentry       *ex;
+       s4                    exceptiontablelength;
+       s4                    i;
 
   /* for a description of the stack see IRETURN in java.vmg */
 
@@ -191,9 +192,9 @@ Inst *intrp_asm_handle_exception(Inst *ip, java_objectheader *o, Cell *fp, Cell
          codeinfo *code = *((codeinfo **) ((u1 *)f + CodeinfoPointer));
          methodinfo *m = code->m;
 
-         framesize = (*((s4 *) (((u1 *) f) + FrameSize)));
-         ex = (exceptionentry *) (((u1 *) f) + ExTableStart);
-         exceptiontablelength = *((s4 *) (((u1 *) f) + ExTableSize));
+         framesize            = *((s4 *)             (((u1 *) f) + FrameSize));
+         ex                   =   (exceptionentry *) (((u1 *) f) + ExTableStart);
+         exceptiontablelength = *((s4 *)             (((u1 *) f) + ExTableSize));
 
 #if !defined(NDEBUG)
          if (opt_verbose || opt_verbosecall || opt_verboseexception)
@@ -202,17 +203,42 @@ Inst *intrp_asm_handle_exception(Inst *ip, java_objectheader *o, Cell *fp, Cell
 
          for (i = 0; i < exceptiontablelength; i++) {
                  ex--;
-                 c = ex->catchtype.cls;
 
-                 if (c != NULL) {
-                         if (!(c->state & CLASS_LOADED))
-                                 /* XXX fix me! */
-                                 if (!load_class_bootstrap(c->name))
-                                         assert(0);
+                 cr = ex->catchtype;
+
+                 if (cr.any != NULL) {
+                         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->state & CLASS_LINKED))
-                                 if (!link_class(c))
+                                 if (c == NULL) {
+                                         /* Exception resolving the exception class, argh! */
+                                         /* XXX how to report that error? */
                                          assert(0);
+                                 }
+
+                                 /* 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;
+                               
+                                 /* If the class is not linked, the exception object cannot */
+                                 /* be an instance of it.                                   */
+                                 if (!(c->state & CLASS_LINKED))
+                                         continue;
+                         }
                  }
 
                  if (ip-1 >= (Inst *) ex->startpc && ip-1 < (Inst *) ex->endpc &&