- replace proto_ exceptions with dynamic ones
authortwisti <none@none>
Sun, 7 Mar 2004 22:12:28 +0000 (22:12 +0000)
committertwisti <none@none>
Sun, 7 Mar 2004 22:12:28 +0000 (22:12 +0000)
jit/alpha/asmpart.S
jit/alpha/codegen.c
src/vm/jit/alpha/asmpart.S
src/vm/jit/alpha/codegen.c

index 236652ba539ed9e14d3dcfd4161915f5670ac72a..c377bc333f70b23ff9fde45f7457e9a9a4396719 100644 (file)
@@ -28,7 +28,7 @@
    Authors: Andreas Krall
             Reinhard Grafl
 
-   $Id: asmpart.S 901 2004-01-22 19:06:00Z twisti $
+   $Id: asmpart.S 948 2004-03-07 22:12:28Z twisti $
 
 */
 
@@ -157,8 +157,8 @@ has_no_x_instr_set:
 /********************* function synchronize_caches ****************************/
 
        .ent    synchronize_caches
-synchronize_caches:
 
+synchronize_caches:
        call_pal PAL_imb                  /* synchronise instruction cache        */
        jmp     zero,(ra)                 /* return                               */
 
@@ -826,14 +826,21 @@ L_is_initialized:
 
        .ent    asm_builtin_monitorenter
 asm_builtin_monitorenter:
-
        ldgp    gp,0(pv)
        lda     pv,builtin_monitorenter
        beq     a0,nb_monitorenter        /* if (null) throw exception            */
        jmp     zero,(pv)                 /* else call builtin_monitorenter       */
 
 nb_monitorenter:
-       ldq     xptr,proto_java_lang_NullPointerException
+       subq    sp,8,sp
+    stq     ra,0(sp)
+       ldq     a0,string_java_lang_NullPointerException
+    jsr     ra,new_exception_message
+    ldgp    gp,0(ra)
+       mov     v0,xptr
+    ldq     ra,0(sp)
+       addq    sp,8,sp
+       
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
        .end    asm_builtin_monitorenter
@@ -847,14 +854,21 @@ nb_monitorenter:
 
        .ent    asm_builtin_monitorexit
 asm_builtin_monitorexit:
-
        ldgp    gp,0(pv)
        lda     pv,builtin_monitorexit
        beq     a0,nb_monitorexit         /* if (null) throw exception            */
        jmp     zero,(pv)                 /* else call builtin_monitorexit        */
 
 nb_monitorexit:
-       ldq     xptr,proto_java_lang_NullPointerException
+       subq    sp,8,sp
+    stq     ra,0(sp)
+       ldq     a0,string_java_lang_NullPointerException
+    jsr     ra,new_exception_message
+    ldgp    gp,0(ra)
+       mov     v0,xptr
+    ldq     ra,0(sp)
+       addq    sp,8,sp
+       
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
        .end    asm_builtin_monitorexit
@@ -867,17 +881,27 @@ nb_monitorexit:
 *******************************************************************************/
 
        .ent    asm_builtin_idiv
-asm_builtin_idiv:
 
+asm_builtin_idiv:
        ldgp    gp,0(pv)
        lda     pv,builtin_idiv
        beq     a1,nb_idiv                /* if (null) throw exception            */
        jmp     zero,(pv)                 /* else call builtin_idiv               */
 
 nb_idiv:
-       ldq     xptr,proto_java_lang_ArithmeticException
+       subq    sp,8,sp
+       stq     ra,0(sp)
+       ldq     a0,string_java_lang_ArithmeticException
+       ldq     a1,string_java_lang_ArithmeticException_message
+       jsr     ra,new_exception_message
+       ldgp    gp,0(ra)
+       mov     v0,xptr
+       ldq     ra,0(sp)
+       addq    sp,8,sp
+       
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
+
        .end    asm_builtin_idiv
 
 
@@ -888,17 +912,27 @@ nb_idiv:
 *******************************************************************************/
 
        .ent    asm_builtin_ldiv
-asm_builtin_ldiv:
 
+asm_builtin_ldiv:
        ldgp    gp,0(pv)
        lda     pv,builtin_ldiv
        beq     a1,nb_ldiv                /* if (null) throw exception            */
        jmp     zero,(pv)                 /* else call builtin_ldiv               */
 
 nb_ldiv:
-       ldq     xptr,proto_java_lang_ArithmeticException
+       subq    sp,8,sp
+       stq     ra,0(sp)
+       ldq     a0,string_java_lang_ArithmeticException
+       ldq     a1,string_java_lang_ArithmeticException_message
+       jsr     ra,new_exception_message
+       ldgp    gp,0(ra)
+       mov     v0,xptr
+       ldq     ra,0(sp)
+       addq    sp,8,sp
+
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
+
        .end    asm_builtin_ldiv
 
 
@@ -909,17 +943,27 @@ nb_ldiv:
 *******************************************************************************/
 
        .ent    asm_builtin_irem
-asm_builtin_irem:
 
+asm_builtin_irem:
        ldgp    gp,0(pv)
        lda     pv,builtin_irem
        beq     a1,nb_irem                /* if (null) throw exception            */
        jmp     zero,(pv)                 /* else call builtin_irem               */
 
 nb_irem:
-       ldq     xptr,proto_java_lang_ArithmeticException
+       subq    sp,8,sp
+       stq     ra,0(sp)
+       ldq     a0,string_java_lang_ArithmeticException
+       ldq     a1,string_java_lang_ArithmeticException_message
+       jsr     ra,new_exception_message
+       ldgp    gp,0(ra)
+       mov     v0,xptr
+       ldq     ra,0(sp)
+       addq    sp,8,sp
+
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
+
        .end    asm_builtin_irem
 
 
@@ -930,17 +974,27 @@ nb_irem:
 *******************************************************************************/
 
        .ent    asm_builtin_lrem
-asm_builtin_lrem:
 
+asm_builtin_lrem:
        ldgp    gp,0(pv)
        lda     pv,builtin_lrem
        beq     a1,nb_lrem                /* if (null) throw exception            */
        jmp     zero,(pv)                 /* else call builtin_lrem               */
 
 nb_lrem:
-       ldq     xptr,proto_java_lang_ArithmeticException
+       subq    sp,8,sp
+       stq     ra,0(sp)
+       ldq     a0,string_java_lang_ArithmeticException
+       ldq     a1,string_java_lang_ArithmeticException_message
+       jsr     ra,new_exception_message
+       ldgp    gp,0(ra)
+       mov     v0,xptr
+       ldq     ra,0(sp)
+       addq    sp,8,sp
+
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
+
        .end    asm_builtin_lrem
 
 
@@ -951,8 +1005,8 @@ nb_lrem:
 *******************************************************************************/
 
     .ent    asm_builtin_checkcast
-asm_builtin_checkcast:
 
+asm_builtin_checkcast:
     ldgp    gp,0(pv)
     lda     sp,-16(sp)                  # allocate stack space
     stq     ra,0(sp)                    # save return address
@@ -966,11 +1020,16 @@ asm_builtin_checkcast:
     jmp     zero,(ra)
 
 nb_ccast_throw:
-    ldq     xptr,proto_java_lang_ClassCastException
+       ldq     a0,string_java_lang_ClassCastException
+       jsr     ra,new_exception
+       ldgp    gp,0(ra)
+       mov     v0,xptr
+
     ldq     ra,0(sp)                    # restore return address
     lda     sp,16(sp)                   # free stack space
     lda     xpc,-4(ra)                  # faulting address is return adress - 4
     br      asm_handle_nat_exception
+
     .end    asm_builtin_checkcast
 
                
@@ -981,8 +1040,8 @@ nb_ccast_throw:
 *******************************************************************************/
 
        .ent    asm_builtin_checkarraycast
-asm_builtin_checkarraycast:
 
+asm_builtin_checkarraycast:
        ldgp    gp,0(pv)
        lda     sp,-16(sp)                /* allocate stack space                 */
        stq     ra,0(sp)                  /* save return address                  */
@@ -996,11 +1055,16 @@ asm_builtin_checkarraycast:
        jmp     zero,(ra)
 
 nb_carray_throw:
-       ldq     xptr,proto_java_lang_ClassCastException
+       ldq     a0,string_java_lang_ClassCastException
+    jsr     ra,new_exception
+    ldgp    gp,0(ra)
+       mov     v0,xptr
+
        ldq     ra,0(sp)                  /* restore return address               */
        lda     sp,16(sp)                 /* free stack space                     */
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
+
        .end    asm_builtin_checkarraycast
 
 
@@ -1011,8 +1075,8 @@ nb_carray_throw:
 *******************************************************************************/
 
        .ent    asm_builtin_aastore
-asm_builtin_aastore:
 
+asm_builtin_aastore:
        ldgp    gp,0(pv)
        beq     a0,nb_aastore_null        /* if null pointer throw exception      */
        ldl     t0,offarraysize(a0)       /* load size                            */
@@ -1034,19 +1098,40 @@ asm_builtin_aastore:
        stq     a1,offobjarrdata(a0)      /* store objectptr in array             */
        jmp     zero,(ra)
 
-nb_aastore_null:
-       ldq     xptr,proto_java_lang_NullPointerException
+nb_aastore_null:       
+       subq    sp,8,sp                   /* allocate stack space                 */
+       stq     ra,0(sp)                  /* save return address                  */
+       ldq     a0,string_java_lang_NullPointerException
+    jsr     ra,new_exception
+    ldgp    gp,0(ra)
+       mov     v0,xptr
+       ldq     ra,0(sp)
+       addq    sp,8,sp
+
        mov     ra,xpc                    /* faulting address is return adress    */
        br      asm_handle_nat_exception
 
 nb_aastore_bound:
-       ldq     xptr,proto_java_lang_ArrayIndexOutOfBoundsException
+       ldq     a0,string_java_lang_ArrayIndexOutOfBoundsException
+    jsr     ra,new_exception_int      /* a1 already contains the index        */
+    ldgp    gp,0(ra)
+       mov     v0,xptr
+
+       ldq     ra,0(sp)                  /* restore return address               */
        lda     sp,24(sp)                 /* free stack space                     */
        mov     ra,xpc                    /* faulting address is return adress    */
        br      asm_handle_nat_exception
 
 nb_aastore_throw:
-       ldq     xptr,proto_java_lang_ArrayStoreException
+       subq    sp,8,sp                   /* allocate stack space                 */
+       stq     ra,0(sp)                  /* save return address                  */
+       ldq     a0,string_java_lang_ArrayStoreException
+    jsr     ra,new_exception
+    ldgp    gp,0(ra)
+       mov     v0,xptr
+       ldq     ra,0(sp)
+       addq    sp,8,sp
+
        mov     ra,xpc                    /* faulting address is return adress    */
        br      asm_handle_nat_exception
 
@@ -1060,8 +1145,8 @@ nb_aastore_throw:
 *******************************************************************************/
 
        .ent    asm_initialize_thread_stack
-asm_initialize_thread_stack:
 
+asm_initialize_thread_stack:
        lda     a1,-128(a1)
        stq     zero, 0(a1)
        stq     zero, 8(a1)
@@ -1081,6 +1166,7 @@ asm_initialize_thread_stack:
        stq     a0, 120(a1)
        mov     a1, v0
        jmp     zero,(ra)
+
        .end    asm_initialize_thread_stack
 
 
@@ -1093,8 +1179,8 @@ asm_initialize_thread_stack:
 *******************************************************************************/
 
        .ent    asm_perform_threadswitch
-asm_perform_threadswitch:
 
+asm_perform_threadswitch:
        subq    sp,128,sp
        stq     s0, 0(sp)
        stq     s1, 8(sp)
@@ -1134,6 +1220,7 @@ asm_perform_threadswitch:
        mov     ra, pv
        addq    sp, 128, sp
        jmp     zero,(ra)
+
        .end    asm_perform_threadswitch
 
 
@@ -1152,6 +1239,7 @@ asm_perform_threadswitch:
 
 
        .ent    asm_switchstackandcall
+
 asm_switchstackandcall:
        lda     a0,-2*8(a0)     /* allocate new stack                                 */
        stq     ra,0(a0)        /* save return address on new stack                   */
@@ -1185,8 +1273,8 @@ asm_switchstackandcall:
 
 
        .ent    asm_getcallingmethod
-asm_getcallingmethod:
 
+asm_getcallingmethod:
        ldq             t3,16(sp)             /* load return address of native function   */
        addq    sp,24,t2                          /* skip frames of C-Function and nativestub */
                
@@ -1227,9 +1315,8 @@ pv_ok1:
 
 pv_ok2:                
        ldq     v0,MethodPointer(t4)  /*                                                                                  */
-
                                                                                
-       jmp     zero,(ra)                                 /* return                                   */
+       jmp     zero,(ra)             /* return                                   */
 
        .end    asm_getcallingmethod
 
index cf5f81f03fc938fa521066336abdb4a45d0a7a61..92f01d1d95c2e3679f88a87db3e7c57cd44addcb 100644 (file)
@@ -28,7 +28,7 @@
    Authors: Andreas Krall
             Reinhard Grafl
 
-   $Id: codegen.c 901 2004-01-22 19:06:00Z twisti $
+   $Id: codegen.c 948 2004-03-07 22:12:28Z twisti $
 
 */
 
@@ -143,15 +143,11 @@ int parentargs_base; /* offset in stackframe for the parameter from the caller*/
 
 /* gen_nullptr_check(objreg) */
 
-#ifdef SOFTNULLPTRCHECK
 #define gen_nullptr_check(objreg) \
-       if (checknull) {\
-           M_BEQZ((objreg), 0);\
-           codegen_addxnullrefs(mcodeptr);\
-       }
-#else
-#define gen_nullptr_check(objreg)
-#endif
+    if (checknull) { \
+        M_BEQZ((objreg), 0); \
+        codegen_addxnullrefs(mcodeptr); \
+    }
 
 
 /* MCODECHECK(icnt) */
@@ -164,7 +160,7 @@ int parentargs_base; /* offset in stackframe for the parameter from the caller*/
      if a and b are the same int-register, no code will be generated.
 */ 
 
-#define M_INTMOVE(a,b) if(a!=b){M_MOV(a,b);}
+#define M_INTMOVE(a,b) if (a != b) { M_MOV(a, b); }
 
 
 /* M_FLTMOVE:
@@ -172,7 +168,7 @@ int parentargs_base; /* offset in stackframe for the parameter from the caller*/
     if a and b are the same float-register, no code will be generated
 */ 
 
-#define M_FLTMOVE(a,b) if(a!=b){M_FMOV(a,b);}
+#define M_FLTMOVE(a,b) if (a != b) { M_FMOV(a, b); }
 
 
 /* var_to_reg_xxx:
@@ -326,17 +322,23 @@ void catch_NullPointerException(int sig, int code, sigctx_struct *sigctx)
                sigemptyset(&nsig);
                sigaddset(&nsig, sig);
                sigprocmask(SIG_UNBLOCK, &nsig, NULL);           /* unblock signal    */
+
+               if (!proto_java_lang_NullPointerException) {
+                       proto_java_lang_NullPointerException =
+                               new_exception(string_java_lang_NullPointerException);
+               }
+
                sigctx->sc_regs[REG_ITMP1_XPTR] =
                                            (long) proto_java_lang_NullPointerException;
                sigctx->sc_regs[REG_ITMP2_XPC] = sigctx->sc_pc;
                sigctx->sc_pc = (long) asm_handle_exception;
                return;
-               }
-       else {
+
+       else {
                faultaddr += (long) ((instr << 16) >> 16);
                fprintf(stderr, "faulting address: 0x%16lx\n", faultaddr);
                panic("Stack overflow");
-               }
+       }
 }
 
 
@@ -371,7 +373,6 @@ ieee_set_fp_control(ieee_get_fp_control()
        /* install signal handlers we need to convert to exceptions */
 
        if (!checknull) {
-
 #if defined(SIGSEGV)
                signal(SIGSEGV, (void*) catch_NullPointerException);
 #endif
@@ -379,7 +380,7 @@ ieee_set_fp_control(ieee_get_fp_control()
 #if defined(SIGBUS)
                signal(SIGBUS, (void*) catch_NullPointerException);
 #endif
-               }
+       }
 }
 
 
@@ -389,21 +390,6 @@ ieee_set_fp_control(ieee_get_fp_control()
 
 *******************************************************************************/
 
-#define        MethodPointer   -8
-#define        FrameSize       -12
-#define     IsSync          -16
-#define     IsLeaf          -20
-#define     IntSave         -24
-#define     FltSave         -28
-#define     ExTableSize     -32
-#define     ExTableStart    -32
-
-#define     ExEntrySize     -32
-#define     ExStartPC       -8
-#define     ExEndPC         -16
-#define     ExHandlerPC     -24
-#define     ExCatchType     -32
-
 void codegen()
 {
        int  len, s1, s2, s3, d;
@@ -1987,12 +1973,12 @@ void codegen()
                        */
 
 #define gen_bound_check \
-            if (checkbounds) { \
-                               M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
-                               M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\
-                               M_BEQZ(REG_ITMP3, 0);\
-                               codegen_addxboundrefs(mcodeptr); \
-                }
+    if (checkbounds) { \
+        M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
+        M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\
+        M_BEQZ(REG_ITMP3, 0);\
+        codegen_addxboundrefs(mcodeptr, s2); \
+    }
 
                case ICMD_ARRAYLENGTH: /* ..., arrayref  ==> ..., length              */
 
@@ -3680,9 +3666,9 @@ makeactualcall:
        for (; xboundrefs != NULL; xboundrefs = xboundrefs->next) {
                if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
                        gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos, 
-                               xboundrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
+                               xboundrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - (4 + 4));
                        continue;
-                       }
+               }
 
 
                gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos, 
@@ -3690,24 +3676,47 @@ makeactualcall:
 
                MCODECHECK(8);
 
+               M_MOV(xboundrefs->reg, REG_ITMP1);
                M_LDA(REG_ITMP2_XPC, REG_PV, xboundrefs->branchpos - 4);
 
                if (xcodeptr != NULL) {
-                       int disp = (xcodeptr-mcodeptr)-1;
-                       M_BR(disp);
-                       }
-               else {
+                       M_BR(xcodeptr - mcodeptr - 1);
+
+               } else {
                        xcodeptr = mcodeptr;
 
-                       a = dseg_addaddress(proto_java_lang_ArrayIndexOutOfBoundsException);
-                       M_ALD(REG_ITMP1_XPTR, REG_PV, a);
+                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
+                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+
+                       a = dseg_addaddress(string_java_lang_ArrayIndexOutOfBoundsException);
+                       M_ALD(argintregs[0], REG_PV, a);
+                       M_MOV(REG_ITMP1, argintregs[1]);
+
+                       a = dseg_addaddress(new_exception_int);
+                       M_ALD(REG_PV, REG_PV, a);
+                       M_JSR(REG_RA, REG_PV);
+
+                       /* recompute pv */
+                       s1 = (s4) ((u1 *) mcodeptr - mcodebase);
+                       if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
+                       else {
+                               s4 ml = -s1, mh = 0;
+                               while (ml < -32768) { ml += 65536; mh--; }
+                               M_LDA(REG_PV, REG_RA, ml);
+                               M_LDAH(REG_PV, REG_PV, mh);
+                       }
+
+                       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+
+                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
 
                        a = dseg_addaddress(asm_handle_exception);
                        M_ALD(REG_ITMP3, REG_PV, a);
 
                        M_JMP(REG_ZERO, REG_ITMP3);
-                       }
                }
+       }
 
        /* generate negative array size check stubs */
 
@@ -3718,7 +3727,7 @@ makeactualcall:
                        gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos, 
                                xcheckarefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
                        continue;
-                       }
+               }
 
                gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos, 
                                  xcheckarefs->branchpos, (u1*) mcodeptr - mcodebase);
@@ -3728,21 +3737,42 @@ makeactualcall:
                M_LDA(REG_ITMP2_XPC, REG_PV, xcheckarefs->branchpos - 4);
 
                if (xcodeptr != NULL) {
-                       int disp = (xcodeptr-mcodeptr)-1;
-                       M_BR(disp);
-                       }
-               else {
+                       M_BR(xcodeptr - mcodeptr - 1);
+
+               } else {
                        xcodeptr = mcodeptr;
 
-                       a = dseg_addaddress(proto_java_lang_NegativeArraySizeException);
-                       M_ALD(REG_ITMP1_XPTR, REG_PV, a);
+                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
+                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+
+                       a = dseg_addaddress(string_java_lang_NegativeArraySizeException);
+                       M_ALD(argintregs[0], REG_PV, a);
+
+                       a = dseg_addaddress(new_exception);
+                       M_ALD(REG_PV, REG_PV, a);
+                       M_JSR(REG_RA, REG_PV);
+
+                       /* recompute pv */
+                       s1 = (s4) ((u1 *) mcodeptr - mcodebase);
+                       if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
+                       else {
+                               s4 ml = -s1, mh = 0;
+                               while (ml < -32768) { ml += 65536; mh--; }
+                               M_LDA(REG_PV, REG_RA, ml);
+                               M_LDAH(REG_PV, REG_PV, mh);
+                       }
+
+                       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+
+                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
 
                        a = dseg_addaddress(asm_handle_exception);
                        M_ALD(REG_ITMP3, REG_PV, a);
 
                        M_JMP(REG_ZERO, REG_ITMP3);
-                       }
                }
+       }
 
        /* generate cast check stubs */
 
@@ -3753,7 +3783,7 @@ makeactualcall:
                        gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos, 
                                xcastrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
                        continue;
-                       }
+               }
 
                gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos, 
                                  xcastrefs->branchpos, (u1*) mcodeptr - mcodebase);
@@ -3763,24 +3793,42 @@ makeactualcall:
                M_LDA(REG_ITMP2_XPC, REG_PV, xcastrefs->branchpos - 4);
 
                if (xcodeptr != NULL) {
-                       int disp = (xcodeptr-mcodeptr)-1;
-                       M_BR(disp);
-                       }
-               else {
+                       M_BR(xcodeptr - mcodeptr - 1);
+
+               } else {
                        xcodeptr = mcodeptr;
 
-                       a = dseg_addaddress(proto_java_lang_ClassCastException);
-                       M_ALD(REG_ITMP1_XPTR, REG_PV, a);
+                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
+                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+
+                       a = dseg_addaddress(string_java_lang_ClassCastException);
+                       M_ALD(argintregs[0], REG_PV, a);
+
+                       a = dseg_addaddress(new_exception);
+                       M_ALD(REG_PV, REG_PV, a);
+                       M_JSR(REG_RA, REG_PV);
+
+                       /* recompute pv */
+                       s1 = (s4) ((u1 *) mcodeptr - mcodebase);
+                       if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
+                       else {
+                               s4 ml = -s1, mh = 0;
+                               while (ml < -32768) { ml += 65536; mh--; }
+                               M_LDA(REG_PV, REG_RA, ml);
+                               M_LDAH(REG_PV, REG_PV, mh);
+                       }
+
+                       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+
+                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
 
                        a = dseg_addaddress(asm_handle_exception);
                        M_ALD(REG_ITMP3, REG_PV, a);
 
                        M_JMP(REG_ZERO, REG_ITMP3);
-                       }
                }
-
-
-#ifdef SOFTNULLPTRCHECK
+       }
 
        /* generate null pointer check stubs */
 
@@ -3791,7 +3839,7 @@ makeactualcall:
                        gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos, 
                                xnullrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
                        continue;
-                       }
+               }
 
                gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos, 
                                  xnullrefs->branchpos, (u1*) mcodeptr - mcodebase);
@@ -3801,23 +3849,42 @@ makeactualcall:
                M_LDA(REG_ITMP2_XPC, REG_PV, xnullrefs->branchpos - 4);
 
                if (xcodeptr != NULL) {
-                       int disp = (xcodeptr-mcodeptr)-1;
-                       M_BR(disp);
-                       }
-               else {
+                       M_BR(xcodeptr - mcodeptr - 1);
+
+               } else {
                        xcodeptr = mcodeptr;
 
-                       a = dseg_addaddress(proto_java_lang_NullPointerException);
-                       M_ALD(REG_ITMP1_XPTR, REG_PV, a);
+                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
+                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+
+                       a = dseg_addaddress(string_java_lang_NullPointerException);
+                       M_ALD(argintregs[0], REG_PV, a);
+
+                       a = dseg_addaddress(new_exception);
+                       M_ALD(REG_PV, REG_PV, a);
+                       M_JSR(REG_RA, REG_PV);
+
+                       /* recompute pv */
+                       s1 = (s4) ((u1 *) mcodeptr - mcodebase);
+                       if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
+                       else {
+                               s4 ml = -s1, mh = 0;
+                               while (ml < -32768) { ml += 65536; mh--; }
+                               M_LDA(REG_PV, REG_RA, ml);
+                               M_LDAH(REG_PV, REG_PV, mh);
+                       }
+
+                       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+
+                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
 
                        a = dseg_addaddress(asm_handle_exception);
                        M_ALD(REG_ITMP3, REG_PV, a);
 
                        M_JMP(REG_ZERO, REG_ITMP3);
-                       }
                }
-
-#endif
+       }
        }
 
        codegen_finish((int)((u1*) mcodeptr - mcodebase));
index 236652ba539ed9e14d3dcfd4161915f5670ac72a..c377bc333f70b23ff9fde45f7457e9a9a4396719 100644 (file)
@@ -28,7 +28,7 @@
    Authors: Andreas Krall
             Reinhard Grafl
 
-   $Id: asmpart.S 901 2004-01-22 19:06:00Z twisti $
+   $Id: asmpart.S 948 2004-03-07 22:12:28Z twisti $
 
 */
 
@@ -157,8 +157,8 @@ has_no_x_instr_set:
 /********************* function synchronize_caches ****************************/
 
        .ent    synchronize_caches
-synchronize_caches:
 
+synchronize_caches:
        call_pal PAL_imb                  /* synchronise instruction cache        */
        jmp     zero,(ra)                 /* return                               */
 
@@ -826,14 +826,21 @@ L_is_initialized:
 
        .ent    asm_builtin_monitorenter
 asm_builtin_monitorenter:
-
        ldgp    gp,0(pv)
        lda     pv,builtin_monitorenter
        beq     a0,nb_monitorenter        /* if (null) throw exception            */
        jmp     zero,(pv)                 /* else call builtin_monitorenter       */
 
 nb_monitorenter:
-       ldq     xptr,proto_java_lang_NullPointerException
+       subq    sp,8,sp
+    stq     ra,0(sp)
+       ldq     a0,string_java_lang_NullPointerException
+    jsr     ra,new_exception_message
+    ldgp    gp,0(ra)
+       mov     v0,xptr
+    ldq     ra,0(sp)
+       addq    sp,8,sp
+       
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
        .end    asm_builtin_monitorenter
@@ -847,14 +854,21 @@ nb_monitorenter:
 
        .ent    asm_builtin_monitorexit
 asm_builtin_monitorexit:
-
        ldgp    gp,0(pv)
        lda     pv,builtin_monitorexit
        beq     a0,nb_monitorexit         /* if (null) throw exception            */
        jmp     zero,(pv)                 /* else call builtin_monitorexit        */
 
 nb_monitorexit:
-       ldq     xptr,proto_java_lang_NullPointerException
+       subq    sp,8,sp
+    stq     ra,0(sp)
+       ldq     a0,string_java_lang_NullPointerException
+    jsr     ra,new_exception_message
+    ldgp    gp,0(ra)
+       mov     v0,xptr
+    ldq     ra,0(sp)
+       addq    sp,8,sp
+       
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
        .end    asm_builtin_monitorexit
@@ -867,17 +881,27 @@ nb_monitorexit:
 *******************************************************************************/
 
        .ent    asm_builtin_idiv
-asm_builtin_idiv:
 
+asm_builtin_idiv:
        ldgp    gp,0(pv)
        lda     pv,builtin_idiv
        beq     a1,nb_idiv                /* if (null) throw exception            */
        jmp     zero,(pv)                 /* else call builtin_idiv               */
 
 nb_idiv:
-       ldq     xptr,proto_java_lang_ArithmeticException
+       subq    sp,8,sp
+       stq     ra,0(sp)
+       ldq     a0,string_java_lang_ArithmeticException
+       ldq     a1,string_java_lang_ArithmeticException_message
+       jsr     ra,new_exception_message
+       ldgp    gp,0(ra)
+       mov     v0,xptr
+       ldq     ra,0(sp)
+       addq    sp,8,sp
+       
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
+
        .end    asm_builtin_idiv
 
 
@@ -888,17 +912,27 @@ nb_idiv:
 *******************************************************************************/
 
        .ent    asm_builtin_ldiv
-asm_builtin_ldiv:
 
+asm_builtin_ldiv:
        ldgp    gp,0(pv)
        lda     pv,builtin_ldiv
        beq     a1,nb_ldiv                /* if (null) throw exception            */
        jmp     zero,(pv)                 /* else call builtin_ldiv               */
 
 nb_ldiv:
-       ldq     xptr,proto_java_lang_ArithmeticException
+       subq    sp,8,sp
+       stq     ra,0(sp)
+       ldq     a0,string_java_lang_ArithmeticException
+       ldq     a1,string_java_lang_ArithmeticException_message
+       jsr     ra,new_exception_message
+       ldgp    gp,0(ra)
+       mov     v0,xptr
+       ldq     ra,0(sp)
+       addq    sp,8,sp
+
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
+
        .end    asm_builtin_ldiv
 
 
@@ -909,17 +943,27 @@ nb_ldiv:
 *******************************************************************************/
 
        .ent    asm_builtin_irem
-asm_builtin_irem:
 
+asm_builtin_irem:
        ldgp    gp,0(pv)
        lda     pv,builtin_irem
        beq     a1,nb_irem                /* if (null) throw exception            */
        jmp     zero,(pv)                 /* else call builtin_irem               */
 
 nb_irem:
-       ldq     xptr,proto_java_lang_ArithmeticException
+       subq    sp,8,sp
+       stq     ra,0(sp)
+       ldq     a0,string_java_lang_ArithmeticException
+       ldq     a1,string_java_lang_ArithmeticException_message
+       jsr     ra,new_exception_message
+       ldgp    gp,0(ra)
+       mov     v0,xptr
+       ldq     ra,0(sp)
+       addq    sp,8,sp
+
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
+
        .end    asm_builtin_irem
 
 
@@ -930,17 +974,27 @@ nb_irem:
 *******************************************************************************/
 
        .ent    asm_builtin_lrem
-asm_builtin_lrem:
 
+asm_builtin_lrem:
        ldgp    gp,0(pv)
        lda     pv,builtin_lrem
        beq     a1,nb_lrem                /* if (null) throw exception            */
        jmp     zero,(pv)                 /* else call builtin_lrem               */
 
 nb_lrem:
-       ldq     xptr,proto_java_lang_ArithmeticException
+       subq    sp,8,sp
+       stq     ra,0(sp)
+       ldq     a0,string_java_lang_ArithmeticException
+       ldq     a1,string_java_lang_ArithmeticException_message
+       jsr     ra,new_exception_message
+       ldgp    gp,0(ra)
+       mov     v0,xptr
+       ldq     ra,0(sp)
+       addq    sp,8,sp
+
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
+
        .end    asm_builtin_lrem
 
 
@@ -951,8 +1005,8 @@ nb_lrem:
 *******************************************************************************/
 
     .ent    asm_builtin_checkcast
-asm_builtin_checkcast:
 
+asm_builtin_checkcast:
     ldgp    gp,0(pv)
     lda     sp,-16(sp)                  # allocate stack space
     stq     ra,0(sp)                    # save return address
@@ -966,11 +1020,16 @@ asm_builtin_checkcast:
     jmp     zero,(ra)
 
 nb_ccast_throw:
-    ldq     xptr,proto_java_lang_ClassCastException
+       ldq     a0,string_java_lang_ClassCastException
+       jsr     ra,new_exception
+       ldgp    gp,0(ra)
+       mov     v0,xptr
+
     ldq     ra,0(sp)                    # restore return address
     lda     sp,16(sp)                   # free stack space
     lda     xpc,-4(ra)                  # faulting address is return adress - 4
     br      asm_handle_nat_exception
+
     .end    asm_builtin_checkcast
 
                
@@ -981,8 +1040,8 @@ nb_ccast_throw:
 *******************************************************************************/
 
        .ent    asm_builtin_checkarraycast
-asm_builtin_checkarraycast:
 
+asm_builtin_checkarraycast:
        ldgp    gp,0(pv)
        lda     sp,-16(sp)                /* allocate stack space                 */
        stq     ra,0(sp)                  /* save return address                  */
@@ -996,11 +1055,16 @@ asm_builtin_checkarraycast:
        jmp     zero,(ra)
 
 nb_carray_throw:
-       ldq     xptr,proto_java_lang_ClassCastException
+       ldq     a0,string_java_lang_ClassCastException
+    jsr     ra,new_exception
+    ldgp    gp,0(ra)
+       mov     v0,xptr
+
        ldq     ra,0(sp)                  /* restore return address               */
        lda     sp,16(sp)                 /* free stack space                     */
        lda     xpc,-4(ra)                /* faulting address is return adress - 4*/
        br      asm_handle_nat_exception
+
        .end    asm_builtin_checkarraycast
 
 
@@ -1011,8 +1075,8 @@ nb_carray_throw:
 *******************************************************************************/
 
        .ent    asm_builtin_aastore
-asm_builtin_aastore:
 
+asm_builtin_aastore:
        ldgp    gp,0(pv)
        beq     a0,nb_aastore_null        /* if null pointer throw exception      */
        ldl     t0,offarraysize(a0)       /* load size                            */
@@ -1034,19 +1098,40 @@ asm_builtin_aastore:
        stq     a1,offobjarrdata(a0)      /* store objectptr in array             */
        jmp     zero,(ra)
 
-nb_aastore_null:
-       ldq     xptr,proto_java_lang_NullPointerException
+nb_aastore_null:       
+       subq    sp,8,sp                   /* allocate stack space                 */
+       stq     ra,0(sp)                  /* save return address                  */
+       ldq     a0,string_java_lang_NullPointerException
+    jsr     ra,new_exception
+    ldgp    gp,0(ra)
+       mov     v0,xptr
+       ldq     ra,0(sp)
+       addq    sp,8,sp
+
        mov     ra,xpc                    /* faulting address is return adress    */
        br      asm_handle_nat_exception
 
 nb_aastore_bound:
-       ldq     xptr,proto_java_lang_ArrayIndexOutOfBoundsException
+       ldq     a0,string_java_lang_ArrayIndexOutOfBoundsException
+    jsr     ra,new_exception_int      /* a1 already contains the index        */
+    ldgp    gp,0(ra)
+       mov     v0,xptr
+
+       ldq     ra,0(sp)                  /* restore return address               */
        lda     sp,24(sp)                 /* free stack space                     */
        mov     ra,xpc                    /* faulting address is return adress    */
        br      asm_handle_nat_exception
 
 nb_aastore_throw:
-       ldq     xptr,proto_java_lang_ArrayStoreException
+       subq    sp,8,sp                   /* allocate stack space                 */
+       stq     ra,0(sp)                  /* save return address                  */
+       ldq     a0,string_java_lang_ArrayStoreException
+    jsr     ra,new_exception
+    ldgp    gp,0(ra)
+       mov     v0,xptr
+       ldq     ra,0(sp)
+       addq    sp,8,sp
+
        mov     ra,xpc                    /* faulting address is return adress    */
        br      asm_handle_nat_exception
 
@@ -1060,8 +1145,8 @@ nb_aastore_throw:
 *******************************************************************************/
 
        .ent    asm_initialize_thread_stack
-asm_initialize_thread_stack:
 
+asm_initialize_thread_stack:
        lda     a1,-128(a1)
        stq     zero, 0(a1)
        stq     zero, 8(a1)
@@ -1081,6 +1166,7 @@ asm_initialize_thread_stack:
        stq     a0, 120(a1)
        mov     a1, v0
        jmp     zero,(ra)
+
        .end    asm_initialize_thread_stack
 
 
@@ -1093,8 +1179,8 @@ asm_initialize_thread_stack:
 *******************************************************************************/
 
        .ent    asm_perform_threadswitch
-asm_perform_threadswitch:
 
+asm_perform_threadswitch:
        subq    sp,128,sp
        stq     s0, 0(sp)
        stq     s1, 8(sp)
@@ -1134,6 +1220,7 @@ asm_perform_threadswitch:
        mov     ra, pv
        addq    sp, 128, sp
        jmp     zero,(ra)
+
        .end    asm_perform_threadswitch
 
 
@@ -1152,6 +1239,7 @@ asm_perform_threadswitch:
 
 
        .ent    asm_switchstackandcall
+
 asm_switchstackandcall:
        lda     a0,-2*8(a0)     /* allocate new stack                                 */
        stq     ra,0(a0)        /* save return address on new stack                   */
@@ -1185,8 +1273,8 @@ asm_switchstackandcall:
 
 
        .ent    asm_getcallingmethod
-asm_getcallingmethod:
 
+asm_getcallingmethod:
        ldq             t3,16(sp)             /* load return address of native function   */
        addq    sp,24,t2                          /* skip frames of C-Function and nativestub */
                
@@ -1227,9 +1315,8 @@ pv_ok1:
 
 pv_ok2:                
        ldq     v0,MethodPointer(t4)  /*                                                                                  */
-
                                                                                
-       jmp     zero,(ra)                                 /* return                                   */
+       jmp     zero,(ra)             /* return                                   */
 
        .end    asm_getcallingmethod
 
index cf5f81f03fc938fa521066336abdb4a45d0a7a61..92f01d1d95c2e3679f88a87db3e7c57cd44addcb 100644 (file)
@@ -28,7 +28,7 @@
    Authors: Andreas Krall
             Reinhard Grafl
 
-   $Id: codegen.c 901 2004-01-22 19:06:00Z twisti $
+   $Id: codegen.c 948 2004-03-07 22:12:28Z twisti $
 
 */
 
@@ -143,15 +143,11 @@ int parentargs_base; /* offset in stackframe for the parameter from the caller*/
 
 /* gen_nullptr_check(objreg) */
 
-#ifdef SOFTNULLPTRCHECK
 #define gen_nullptr_check(objreg) \
-       if (checknull) {\
-           M_BEQZ((objreg), 0);\
-           codegen_addxnullrefs(mcodeptr);\
-       }
-#else
-#define gen_nullptr_check(objreg)
-#endif
+    if (checknull) { \
+        M_BEQZ((objreg), 0); \
+        codegen_addxnullrefs(mcodeptr); \
+    }
 
 
 /* MCODECHECK(icnt) */
@@ -164,7 +160,7 @@ int parentargs_base; /* offset in stackframe for the parameter from the caller*/
      if a and b are the same int-register, no code will be generated.
 */ 
 
-#define M_INTMOVE(a,b) if(a!=b){M_MOV(a,b);}
+#define M_INTMOVE(a,b) if (a != b) { M_MOV(a, b); }
 
 
 /* M_FLTMOVE:
@@ -172,7 +168,7 @@ int parentargs_base; /* offset in stackframe for the parameter from the caller*/
     if a and b are the same float-register, no code will be generated
 */ 
 
-#define M_FLTMOVE(a,b) if(a!=b){M_FMOV(a,b);}
+#define M_FLTMOVE(a,b) if (a != b) { M_FMOV(a, b); }
 
 
 /* var_to_reg_xxx:
@@ -326,17 +322,23 @@ void catch_NullPointerException(int sig, int code, sigctx_struct *sigctx)
                sigemptyset(&nsig);
                sigaddset(&nsig, sig);
                sigprocmask(SIG_UNBLOCK, &nsig, NULL);           /* unblock signal    */
+
+               if (!proto_java_lang_NullPointerException) {
+                       proto_java_lang_NullPointerException =
+                               new_exception(string_java_lang_NullPointerException);
+               }
+
                sigctx->sc_regs[REG_ITMP1_XPTR] =
                                            (long) proto_java_lang_NullPointerException;
                sigctx->sc_regs[REG_ITMP2_XPC] = sigctx->sc_pc;
                sigctx->sc_pc = (long) asm_handle_exception;
                return;
-               }
-       else {
+
+       else {
                faultaddr += (long) ((instr << 16) >> 16);
                fprintf(stderr, "faulting address: 0x%16lx\n", faultaddr);
                panic("Stack overflow");
-               }
+       }
 }
 
 
@@ -371,7 +373,6 @@ ieee_set_fp_control(ieee_get_fp_control()
        /* install signal handlers we need to convert to exceptions */
 
        if (!checknull) {
-
 #if defined(SIGSEGV)
                signal(SIGSEGV, (void*) catch_NullPointerException);
 #endif
@@ -379,7 +380,7 @@ ieee_set_fp_control(ieee_get_fp_control()
 #if defined(SIGBUS)
                signal(SIGBUS, (void*) catch_NullPointerException);
 #endif
-               }
+       }
 }
 
 
@@ -389,21 +390,6 @@ ieee_set_fp_control(ieee_get_fp_control()
 
 *******************************************************************************/
 
-#define        MethodPointer   -8
-#define        FrameSize       -12
-#define     IsSync          -16
-#define     IsLeaf          -20
-#define     IntSave         -24
-#define     FltSave         -28
-#define     ExTableSize     -32
-#define     ExTableStart    -32
-
-#define     ExEntrySize     -32
-#define     ExStartPC       -8
-#define     ExEndPC         -16
-#define     ExHandlerPC     -24
-#define     ExCatchType     -32
-
 void codegen()
 {
        int  len, s1, s2, s3, d;
@@ -1987,12 +1973,12 @@ void codegen()
                        */
 
 #define gen_bound_check \
-            if (checkbounds) { \
-                               M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
-                               M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\
-                               M_BEQZ(REG_ITMP3, 0);\
-                               codegen_addxboundrefs(mcodeptr); \
-                }
+    if (checkbounds) { \
+        M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
+        M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\
+        M_BEQZ(REG_ITMP3, 0);\
+        codegen_addxboundrefs(mcodeptr, s2); \
+    }
 
                case ICMD_ARRAYLENGTH: /* ..., arrayref  ==> ..., length              */
 
@@ -3680,9 +3666,9 @@ makeactualcall:
        for (; xboundrefs != NULL; xboundrefs = xboundrefs->next) {
                if ((exceptiontablelength == 0) && (xcodeptr != NULL)) {
                        gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos, 
-                               xboundrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
+                               xboundrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - (4 + 4));
                        continue;
-                       }
+               }
 
 
                gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos, 
@@ -3690,24 +3676,47 @@ makeactualcall:
 
                MCODECHECK(8);
 
+               M_MOV(xboundrefs->reg, REG_ITMP1);
                M_LDA(REG_ITMP2_XPC, REG_PV, xboundrefs->branchpos - 4);
 
                if (xcodeptr != NULL) {
-                       int disp = (xcodeptr-mcodeptr)-1;
-                       M_BR(disp);
-                       }
-               else {
+                       M_BR(xcodeptr - mcodeptr - 1);
+
+               } else {
                        xcodeptr = mcodeptr;
 
-                       a = dseg_addaddress(proto_java_lang_ArrayIndexOutOfBoundsException);
-                       M_ALD(REG_ITMP1_XPTR, REG_PV, a);
+                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
+                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+
+                       a = dseg_addaddress(string_java_lang_ArrayIndexOutOfBoundsException);
+                       M_ALD(argintregs[0], REG_PV, a);
+                       M_MOV(REG_ITMP1, argintregs[1]);
+
+                       a = dseg_addaddress(new_exception_int);
+                       M_ALD(REG_PV, REG_PV, a);
+                       M_JSR(REG_RA, REG_PV);
+
+                       /* recompute pv */
+                       s1 = (s4) ((u1 *) mcodeptr - mcodebase);
+                       if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
+                       else {
+                               s4 ml = -s1, mh = 0;
+                               while (ml < -32768) { ml += 65536; mh--; }
+                               M_LDA(REG_PV, REG_RA, ml);
+                               M_LDAH(REG_PV, REG_PV, mh);
+                       }
+
+                       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+
+                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
 
                        a = dseg_addaddress(asm_handle_exception);
                        M_ALD(REG_ITMP3, REG_PV, a);
 
                        M_JMP(REG_ZERO, REG_ITMP3);
-                       }
                }
+       }
 
        /* generate negative array size check stubs */
 
@@ -3718,7 +3727,7 @@ makeactualcall:
                        gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos, 
                                xcheckarefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
                        continue;
-                       }
+               }
 
                gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos, 
                                  xcheckarefs->branchpos, (u1*) mcodeptr - mcodebase);
@@ -3728,21 +3737,42 @@ makeactualcall:
                M_LDA(REG_ITMP2_XPC, REG_PV, xcheckarefs->branchpos - 4);
 
                if (xcodeptr != NULL) {
-                       int disp = (xcodeptr-mcodeptr)-1;
-                       M_BR(disp);
-                       }
-               else {
+                       M_BR(xcodeptr - mcodeptr - 1);
+
+               } else {
                        xcodeptr = mcodeptr;
 
-                       a = dseg_addaddress(proto_java_lang_NegativeArraySizeException);
-                       M_ALD(REG_ITMP1_XPTR, REG_PV, a);
+                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
+                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+
+                       a = dseg_addaddress(string_java_lang_NegativeArraySizeException);
+                       M_ALD(argintregs[0], REG_PV, a);
+
+                       a = dseg_addaddress(new_exception);
+                       M_ALD(REG_PV, REG_PV, a);
+                       M_JSR(REG_RA, REG_PV);
+
+                       /* recompute pv */
+                       s1 = (s4) ((u1 *) mcodeptr - mcodebase);
+                       if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
+                       else {
+                               s4 ml = -s1, mh = 0;
+                               while (ml < -32768) { ml += 65536; mh--; }
+                               M_LDA(REG_PV, REG_RA, ml);
+                               M_LDAH(REG_PV, REG_PV, mh);
+                       }
+
+                       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+
+                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
 
                        a = dseg_addaddress(asm_handle_exception);
                        M_ALD(REG_ITMP3, REG_PV, a);
 
                        M_JMP(REG_ZERO, REG_ITMP3);
-                       }
                }
+       }
 
        /* generate cast check stubs */
 
@@ -3753,7 +3783,7 @@ makeactualcall:
                        gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos, 
                                xcastrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
                        continue;
-                       }
+               }
 
                gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos, 
                                  xcastrefs->branchpos, (u1*) mcodeptr - mcodebase);
@@ -3763,24 +3793,42 @@ makeactualcall:
                M_LDA(REG_ITMP2_XPC, REG_PV, xcastrefs->branchpos - 4);
 
                if (xcodeptr != NULL) {
-                       int disp = (xcodeptr-mcodeptr)-1;
-                       M_BR(disp);
-                       }
-               else {
+                       M_BR(xcodeptr - mcodeptr - 1);
+
+               } else {
                        xcodeptr = mcodeptr;
 
-                       a = dseg_addaddress(proto_java_lang_ClassCastException);
-                       M_ALD(REG_ITMP1_XPTR, REG_PV, a);
+                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
+                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+
+                       a = dseg_addaddress(string_java_lang_ClassCastException);
+                       M_ALD(argintregs[0], REG_PV, a);
+
+                       a = dseg_addaddress(new_exception);
+                       M_ALD(REG_PV, REG_PV, a);
+                       M_JSR(REG_RA, REG_PV);
+
+                       /* recompute pv */
+                       s1 = (s4) ((u1 *) mcodeptr - mcodebase);
+                       if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
+                       else {
+                               s4 ml = -s1, mh = 0;
+                               while (ml < -32768) { ml += 65536; mh--; }
+                               M_LDA(REG_PV, REG_RA, ml);
+                               M_LDAH(REG_PV, REG_PV, mh);
+                       }
+
+                       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+
+                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
 
                        a = dseg_addaddress(asm_handle_exception);
                        M_ALD(REG_ITMP3, REG_PV, a);
 
                        M_JMP(REG_ZERO, REG_ITMP3);
-                       }
                }
-
-
-#ifdef SOFTNULLPTRCHECK
+       }
 
        /* generate null pointer check stubs */
 
@@ -3791,7 +3839,7 @@ makeactualcall:
                        gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos, 
                                xnullrefs->branchpos, (u1*) xcodeptr - (u1*) mcodebase - 4);
                        continue;
-                       }
+               }
 
                gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos, 
                                  xnullrefs->branchpos, (u1*) mcodeptr - mcodebase);
@@ -3801,23 +3849,42 @@ makeactualcall:
                M_LDA(REG_ITMP2_XPC, REG_PV, xnullrefs->branchpos - 4);
 
                if (xcodeptr != NULL) {
-                       int disp = (xcodeptr-mcodeptr)-1;
-                       M_BR(disp);
-                       }
-               else {
+                       M_BR(xcodeptr - mcodeptr - 1);
+
+               } else {
                        xcodeptr = mcodeptr;
 
-                       a = dseg_addaddress(proto_java_lang_NullPointerException);
-                       M_ALD(REG_ITMP1_XPTR, REG_PV, a);
+                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
+                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+
+                       a = dseg_addaddress(string_java_lang_NullPointerException);
+                       M_ALD(argintregs[0], REG_PV, a);
+
+                       a = dseg_addaddress(new_exception);
+                       M_ALD(REG_PV, REG_PV, a);
+                       M_JSR(REG_RA, REG_PV);
+
+                       /* recompute pv */
+                       s1 = (s4) ((u1 *) mcodeptr - mcodebase);
+                       if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
+                       else {
+                               s4 ml = -s1, mh = 0;
+                               while (ml < -32768) { ml += 65536; mh--; }
+                               M_LDA(REG_PV, REG_RA, ml);
+                               M_LDAH(REG_PV, REG_PV, mh);
+                       }
+
+                       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+
+                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
 
                        a = dseg_addaddress(asm_handle_exception);
                        M_ALD(REG_ITMP3, REG_PV, a);
 
                        M_JMP(REG_ZERO, REG_ITMP3);
-                       }
                }
-
-#endif
+       }
        }
 
        codegen_finish((int)((u1*) mcodeptr - mcodebase));