* ICMD_CHECKASIZE, ICMD_CHECKEXCEPTION: Removed.
[cacao.git] / src / vm / jit / alpha / codegen.c
index a2c8c371043282e580b81065ebc1a71c636cfaca..ebd3e527627e76ccb6d1ce5f753d9baebb321922 100644 (file)
@@ -29,8 +29,9 @@
 
    Changes: Joseph Wenninger
             Christian Thalinger
+            Christian Ullrich
 
-   $Id: codegen.c 2736 2005-06-18 09:20:34Z twisti $
+   $Id: codegen.c 3345 2005-10-04 22:14:53Z twisti $
 
 */
 
@@ -38,6 +39,7 @@
 #include <stdio.h>
 
 #include "config.h"
+#include "vm/types.h"
 
 #include "md.h"
 #include "md-abi.h"
@@ -45,8 +47,6 @@
 
 #include "vm/jit/alpha/arch.h"
 #include "vm/jit/alpha/codegen.h"
-#include "vm/jit/alpha/types.h"
-#include "vm/jit/alpha/asmoffsets.h"
 
 #include "cacao/cacao.h"
 #include "native/native.h"
@@ -78,7 +78,7 @@
 
 void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 {
-       s4                  len, s1, s2, s3, d;
+       s4                  len, s1, s2, s3, d, disp;
        ptrint              a;
        s4                  parentargs_base;
        s4                 *mcodeptr;
@@ -92,6 +92,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
        builtintable_entry *bte;
        methoddesc         *md;
 
+       /* prevent compiler warnings */
+
+       d = 0;
+       currentline = 0;
+       lm = NULL;
+       bte = NULL;
+
        {
        s4 i, p, t, l;
        s4 savedregs_num;
@@ -100,10 +107,10 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
        /* space to save used callee saved registers */
 
-       savedregs_num += (rd->savintregcnt - rd->maxsavintreguse);
-       savedregs_num += (rd->savfltregcnt - rd->maxsavfltreguse);
+       savedregs_num += (INT_SAV_CNT - rd->savintreguse);
+       savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);
 
-       parentargs_base = rd->maxmemuse + savedregs_num;
+       parentargs_base = rd->memuse + savedregs_num;
 
 #if defined(USE_THREADS)           /* space to save argument of monitor_enter */
 
@@ -126,7 +133,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
        */
 
        if (checksync && (m->flags & ACC_SYNCHRONIZED))
-               (void) dseg_adds4(cd, (rd->maxmemuse + 1) * 8);     /* IsSync         */
+               (void) dseg_adds4(cd, (rd->memuse + 1) * 8);     /* IsSync         */
        else
 
 #endif
@@ -134,8 +141,8 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
        (void) dseg_adds4(cd, 0);                               /* IsSync         */
                                               
        (void) dseg_adds4(cd, m->isleafmethod);                 /* IsLeaf         */
-       (void) dseg_adds4(cd, rd->savintregcnt - rd->maxsavintreguse);/* IntSave  */
-       (void) dseg_adds4(cd, rd->savfltregcnt - rd->maxsavfltreguse);/* FltSave  */
+       (void) dseg_adds4(cd, INT_SAV_CNT - rd->savintreguse);/* IntSave  */
+       (void) dseg_adds4(cd, FLT_SAV_CNT - rd->savfltreguse);/* FltSave  */
 
        dseg_addlinenumbertablesize(cd);
 
@@ -168,10 +175,10 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
        if (!m->isleafmethod) {
                p--; M_AST(REG_RA, REG_SP, p * 8);
        }
-       for (i = rd->savintregcnt - 1; i >= rd->maxsavintreguse; i--) {
+       for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
                p--; M_LST(rd->savintregs[i], REG_SP, p * 8);
        }
-       for (i = rd->savfltregcnt - 1; i >= rd->maxsavfltreguse; i--) {
+       for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
                p--; M_DST(rd->savfltregs[i], REG_SP, p * 8);
        }
 
@@ -234,7 +241,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
                /* stack offset for monitor argument */
 
-               s1 = rd->maxmemuse;
+               s1 = rd->memuse;
 
                if (runverbose) {
                        M_LDA(REG_SP, REG_SP, -(INT_ARG_CNT + FLT_ARG_CNT) * 8);
@@ -251,25 +258,25 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                /* decide which monitor enter function to call */
 
                if (m->flags & ACC_STATIC) {
-                       p = dseg_addaddress(cd, m->class);
-                       M_ALD(REG_ITMP1, REG_PV, p);
+                       disp = dseg_addaddress(cd, m->class);
+                       M_ALD(REG_ITMP1, REG_PV, disp);
                        M_AST(REG_ITMP1, REG_SP, s1 * 8);
                        M_INTMOVE(REG_ITMP1, rd->argintregs[0]);
-                       p = dseg_addaddress(cd, BUILTIN_staticmonitorenter);
-                       M_ALD(REG_PV, REG_PV, p);
+                       disp = dseg_addaddress(cd, BUILTIN_staticmonitorenter);
+                       M_ALD(REG_PV, REG_PV, disp);
                        M_JSR(REG_RA, REG_PV);
-                       d = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
-                       M_LDA(REG_PV, REG_RA, d);
+                       disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, disp);
 
                } else {
                        M_BEQZ(rd->argintregs[0], 0);
                        codegen_addxnullrefs(cd, mcodeptr);
                        M_AST(rd->argintregs[0], REG_SP, s1 * 8);
-                       p = dseg_addaddress(cd, BUILTIN_monitorenter);
-                       M_ALD(REG_PV, REG_PV, p);
+                       disp = dseg_addaddress(cd, BUILTIN_monitorenter);
+                       M_ALD(REG_PV, REG_PV, disp);
                        M_JSR(REG_RA, REG_PV);
-                       d = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
-                       M_LDA(REG_PV, REG_RA, d);
+                       disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, disp);
                }
 
                if (runverbose) {
@@ -315,14 +322,14 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        }
                }
 
-               p = dseg_addaddress(cd, m);
-               M_ALD(REG_ITMP1, REG_PV, p);
+               disp = dseg_addaddress(cd, m);
+               M_ALD(REG_ITMP1, REG_PV, disp);
                M_AST(REG_ITMP1, REG_SP, 0 * 8);
-               p = dseg_addaddress(cd, (void *) builtin_trace_args);
-               M_ALD(REG_PV, REG_PV, p);
+               disp = dseg_addaddress(cd, (void *) builtin_trace_args);
+               M_ALD(REG_PV, REG_PV, disp);
                M_JSR(REG_RA, REG_PV);
-               d = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
-               M_LDA(REG_PV, REG_RA, d);
+               disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
+               M_LDA(REG_PV, REG_RA, disp);
                M_ALD(REG_RA, REG_SP, 1 * 8);
 
                /* restore integer argument registers */
@@ -385,9 +392,9 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        if ((len == 0) && (bptr->type != BBTYPE_STD)) {
                                        /*                              d = reg_of_var(m, src, REG_ITMP1); */
                                        if (!(src->flags & INMEMORY))
-                                               d= src->regoff;
+                                               d = src->regoff;
                                        else
-                                               d=REG_ITMP1;
+                                               d = REG_ITMP1;
                                        M_INTMOVE(REG_ITMP1, d);
                                        store_reg_to_var_int(src, d);
                                }
@@ -398,37 +405,34 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        while (src != NULL) {
                                len--;
                                if ((len == 0) && (bptr->type != BBTYPE_STD)) {
-                               d = reg_of_var(rd, src, REG_ITMP1);
-                               M_INTMOVE(REG_ITMP1, d);
-                               store_reg_to_var_int(src, d);
-                               }
-                       else {
-                               d = reg_of_var(rd, src, REG_IFTMP);
-                               if ((src->varkind != STACKVAR)) {
-                                       s2 = src->type;
-                                       if (IS_FLT_DBL_TYPE(s2)) {
-                                               if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
-                                                       s1 = rd->interfaces[len][s2].regoff;
-                                                       M_FLTMOVE(s1,d);
-                                                       }
-                                               else {
-                                                       M_DLD(d, REG_SP, 8 * rd->interfaces[len][s2].regoff);
+                                       d = reg_of_var(rd, src, REG_ITMP1);
+                                       M_INTMOVE(REG_ITMP1, d);
+                                       store_reg_to_var_int(src, d);
+                               } else {
+                                       d = reg_of_var(rd, src, REG_IFTMP);
+                                       if ((src->varkind != STACKVAR)) {
+                                               s2 = src->type;
+                                               if (IS_FLT_DBL_TYPE(s2)) {
+                                                       if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
+                                                               s1 = rd->interfaces[len][s2].regoff;
+                                                               M_FLTMOVE(s1, d);
+                                                       } else {
+                                                               M_DLD(d, REG_SP, rd->interfaces[len][s2].regoff * 8);
                                                        }
-                                               store_reg_to_var_flt(src, d);
+                                                       store_reg_to_var_flt(src, d);
                                                }
-                                       else {
-                                               if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
-                                                       s1 = rd->interfaces[len][s2].regoff;
-                                                       M_INTMOVE(s1,d);
-                                                       }
                                                else {
-                                                       M_LLD(d, REG_SP, 8 * rd->interfaces[len][s2].regoff);
+                                                       if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
+                                                               s1 = rd->interfaces[len][s2].regoff;
+                                                               M_INTMOVE(s1, d);
+                                                       } else {
+                                                               M_LLD(d, REG_SP, rd->interfaces[len][s2].regoff * 8);
                                                        }
-                                               store_reg_to_var_int(src, d);
+                                                       store_reg_to_var_int(src, d);
                                                }
                                        }
                                }
-                       src = src->prev;
+                               src = src->prev;
                        }
 #ifdef LSRA
                }
@@ -441,7 +445,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                for (iptr = bptr->iinstr; len > 0; src = iptr->dst, len--, iptr++) {
                        if (iptr->line != currentline) {
-                               dseg_addlinenumber(cd, iptr->line, mcodeptr);
+                               dseg_addlinenumber(cd, iptr->line, (u1 *) mcodeptr);
                                currentline = iptr->line;
                        }
 
@@ -484,8 +488,8 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* op1 = 0, val.f = constant                    */
 
                        d = reg_of_var(rd, iptr->dst, REG_FTMP1);
-                       a = dseg_addfloat(cd, iptr->val.f);
-                       M_FLD(d, REG_PV, a);
+                       disp = dseg_addfloat(cd, iptr->val.f);
+                       M_FLD(d, REG_PV, disp);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
                        
@@ -493,8 +497,8 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* op1 = 0, val.d = constant                    */
 
                        d = reg_of_var(rd, iptr->dst, REG_FTMP1);
-                       a = dseg_adddouble(cd, iptr->val.d);
-                       M_DLD(d, REG_PV, a);
+                       disp = dseg_adddouble(cd, iptr->val.d);
+                       M_DLD(d, REG_PV, disp);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -503,8 +507,8 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        d = reg_of_var(rd, iptr->dst, REG_ITMP1);
                        if (iptr->val.a) {
-                               a = dseg_addaddress(cd, iptr->val.a);
-                               M_ALD(d, REG_PV, a);
+                               disp = dseg_addaddress(cd, iptr->val.a);
+                               M_ALD(d, REG_PV, disp);
                        } else {
                                M_INTMOVE(REG_ZERO, d);
                        }
@@ -523,10 +527,11 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                            (iptr->dst->varnum == iptr->op1))
                                break;
                        var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
-                       if (var->flags & INMEMORY)
-                               M_LLD(d, REG_SP, 8 * var->regoff);
-                       else
-                               {M_INTMOVE(var->regoff,d);}
+                       if (var->flags & INMEMORY) {
+                               M_LLD(d, REG_SP, var->regoff * 8);
+                       } else {
+                               M_INTMOVE(var->regoff, d);
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -538,10 +543,11 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                            (iptr->dst->varnum == iptr->op1))
                                break;
                        var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
-                       if (var->flags & INMEMORY)
-                               M_DLD(d, REG_SP, 8 * var->regoff);
-                       else
-                               {M_FLTMOVE(var->regoff,d);}
+                       if (var->flags & INMEMORY) {
+                               M_DLD(d, REG_SP, var->regoff * 8);
+                       } else {
+                               M_FLTMOVE(var->regoff, d);
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -556,12 +562,11 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
                        if (var->flags & INMEMORY) {
                                var_to_reg_int(s1, src, REG_ITMP1);
-                               M_LST(s1, REG_SP, 8 * var->regoff);
-                               }
-                       else {
+                               M_LST(s1, REG_SP, var->regoff * 8);
+                       } else {
                                var_to_reg_int(s1, src, var->regoff);
                                M_INTMOVE(s1, var->regoff);
-                               }
+                       }
                        break;
 
                case ICMD_FSTORE:     /* ..., value  ==> ...                          */
@@ -573,12 +578,11 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
                        if (var->flags & INMEMORY) {
                                var_to_reg_flt(s1, src, REG_FTMP1);
-                               M_DST(s1, REG_SP, 8 * var->regoff);
-                               }
-                       else {
+                               M_DST(s1, REG_SP, var->regoff * 8);
+                       } else {
                                var_to_reg_flt(s1, src, var->regoff);
                                M_FLTMOVE(s1, var->regoff);
-                               }
+                       }
                        break;
 
 
@@ -646,7 +650,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_INEG:       /* ..., value  ==> ..., - value                 */
 
                        var_to_reg_int(s1, src, REG_ITMP1); 
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_ISUB(REG_ZERO, s1, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -654,7 +658,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_LNEG:       /* ..., value  ==> ..., - value                 */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_LSUB(REG_ZERO, s1, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -662,7 +666,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_I2L:        /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_INTMOVE(s1, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -670,29 +674,28 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_L2I:        /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                       M_IADD(s1, REG_ZERO, d );
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                       M_IADD(s1, REG_ZERO, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
                case ICMD_INT2BYTE:   /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (has_ext_instr_set) {
                                M_BSEXT(s1, d);
-                               }
-                       else {
+                       } else {
                                M_SLL_IMM(s1, 56, d);
                                M_SRA_IMM( d, 56, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
                case ICMD_INT2CHAR:   /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
             M_CZEXT(s1, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -700,14 +703,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_INT2SHORT:  /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (has_ext_instr_set) {
                                M_SSEXT(s1, d);
-                               }
-                       else {
+                       } else {
                                M_SLL_IMM(s1, 48, d);
                                M_SRA_IMM( d, 48, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -716,7 +718,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_IADD(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -725,14 +727,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_IADD_IMM(s1, iptr->val.i, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_IADD(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -740,7 +741,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_LADD(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -749,14 +750,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_LADD_IMM(s1, iptr->val.l, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_LADD(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -764,7 +764,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_ISUB(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -773,14 +773,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_ISUB_IMM(s1, iptr->val.i, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_ISUB(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -788,7 +787,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_LSUB(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -797,14 +796,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_LSUB_IMM(s1, iptr->val.l, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_LSUB(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -812,7 +810,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_IMUL(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -821,14 +819,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_IMUL_IMM(s1, iptr->val.i, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_IMUL(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -836,8 +833,8 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                       M_LMUL (s1, s2, d);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                       M_LMUL(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -845,14 +842,57 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_LMUL_IMM(s1, iptr->val.l, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_LMUL(s1, REG_ITMP2, d);
-                               }
+                       }
+                       store_reg_to_var_int(iptr->dst, d);
+                       break;
+
+               case ICMD_IDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
+               case ICMD_IREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
+
+                       var_to_reg_int(s1, src->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src, REG_ITMP2);
+                       d = reg_of_var(rd, iptr->dst, REG_RESULT);
+                       M_BEQZ(s2, 0);
+                       codegen_addxdivrefs(cd, mcodeptr);
+
+                       M_MOV(s1, rd->argintregs[0]);
+                       M_MOV(s2, rd->argintregs[1]);
+                       bte = iptr->val.a;
+                       disp = dseg_addaddress(cd, bte->fp);
+                       M_ALD(REG_PV, REG_PV, disp);
+                       M_JSR(REG_RA, REG_PV);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
+
+                       M_IADD(REG_RESULT, REG_ZERO, d); /* sign extend (bugfix for gcc -O2) */
+                       store_reg_to_var_int(iptr->dst, d);
+                       break;
+
+               case ICMD_LDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
+               case ICMD_LREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
+
+                       var_to_reg_int(s1, src->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src, REG_ITMP2);
+                       d = reg_of_var(rd, iptr->dst, REG_RESULT);
+                       M_BEQZ(s2, 0);
+                       codegen_addxdivrefs(cd, mcodeptr);
+
+                       M_MOV(s1, rd->argintregs[0]);
+                       M_MOV(s2, rd->argintregs[1]);
+                       bte = iptr->val.a;
+                       disp = dseg_addaddress(cd, bte->fp);
+                       M_ALD(REG_PV, REG_PV, disp);
+                       M_JSR(REG_RA, REG_PV);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
+
+                       M_INTMOVE(REG_RESULT, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -860,16 +900,15 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_LDIVPOW2:   /* val.i = constant                             */
                                      
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (iptr->val.i <= 15) {
                                M_LDA(REG_ITMP2, s1, (1 << iptr->val.i) -1);
                                M_CMOVGE(s1, s1, REG_ITMP2);
-                               }
-                       else {
+                       } else {
                                M_SRA_IMM(s1, 63, REG_ITMP2);
                                M_SRL_IMM(REG_ITMP2, 64 - iptr->val.i, REG_ITMP2);
                                M_LADD(s1, REG_ITMP2, REG_ITMP2);
-                               }
+                       }
                        M_SRA_IMM(REG_ITMP2, iptr->val.i, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -878,7 +917,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_AND_IMM(s2, 0x1f, REG_ITMP3);
                        M_SLL(s1, REG_ITMP3, d);
                        M_IADD(d, REG_ZERO, d);
@@ -889,7 +928,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SLL_IMM(s1, iptr->val.i & 0x1f, d);
                        M_IADD(d, REG_ZERO, d);
                        store_reg_to_var_int(iptr->dst, d);
@@ -899,7 +938,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_AND_IMM(s2, 0x1f, REG_ITMP3);
                        M_SRA(s1, REG_ITMP3, d);
                        store_reg_to_var_int(iptr->dst, d);
@@ -909,7 +948,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SRA_IMM(s1, iptr->val.i & 0x1f, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -918,7 +957,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_AND_IMM(s2, 0x1f, REG_ITMP2);
             M_IZEXT(s1, d);
                        M_SRL(d, REG_ITMP2, d);
@@ -930,7 +969,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
             M_IZEXT(s1, d);
                        M_SRL_IMM(d, iptr->val.i & 0x1f, d);
                        M_IADD(d, REG_ZERO, d);
@@ -941,7 +980,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SLL(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -950,7 +989,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SLL_IMM(s1, iptr->val.i & 0x3f, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -959,7 +998,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SRA(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -968,7 +1007,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SRA_IMM(s1, iptr->val.i & 0x3f, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -977,7 +1016,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SRL(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -986,7 +1025,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SRL_IMM(s1, iptr->val.i & 0x3f, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -996,7 +1035,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_AND(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1005,20 +1044,17 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_AND_IMM(s1, iptr->val.i, d);
-                               }
-                       else if (iptr->val.i == 0xffff) {
+                       } else if (iptr->val.i == 0xffff) {
                                M_CZEXT(s1, d);
-                               }
-                       else if (iptr->val.i == 0xffffff) {
+                       } else if (iptr->val.i == 0xffffff) {
                                M_ZAPNOT_IMM(s1, 0x07, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_AND(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1026,36 +1062,33 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (s1 == d) {
                                M_MOV(s1, REG_ITMP1);
                                s1 = REG_ITMP1;
-                               }
+                       }
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_AND_IMM(s1, iptr->val.i, d);
                                M_BGEZ(s1, 3);
                                M_ISUB(REG_ZERO, s1, d);
                                M_AND_IMM(d, iptr->val.i, d);
-                               }
-                       else if (iptr->val.i == 0xffff) {
+                       } else if (iptr->val.i == 0xffff) {
                                M_CZEXT(s1, d);
                                M_BGEZ(s1, 3);
                                M_ISUB(REG_ZERO, s1, d);
                                M_CZEXT(d, d);
-                               }
-                       else if (iptr->val.i == 0xffffff) {
+                       } else if (iptr->val.i == 0xffffff) {
                                M_ZAPNOT_IMM(s1, 0x07, d);
                                M_BGEZ(s1, 3);
                                M_ISUB(REG_ZERO, s1, d);
                                M_ZAPNOT_IMM(d, 0x07, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_AND(s1, REG_ITMP2, d);
                                M_BGEZ(s1, 3);
                                M_ISUB(REG_ZERO, s1, d);
                                M_AND(d, REG_ITMP2, d);
-                               }
+                       }
                        M_ISUB(REG_ZERO, d, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1064,32 +1097,25 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_AND_IMM(s1, iptr->val.l, d);
-                               }
-                       else if (iptr->val.l == 0xffffL) {
+                       } else if (iptr->val.l == 0xffffL) {
                                M_CZEXT(s1, d);
-                               }
-                       else if (iptr->val.l == 0xffffffL) {
+                       } else if (iptr->val.l == 0xffffffL) {
                                M_ZAPNOT_IMM(s1, 0x07, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffL) {
                                M_IZEXT(s1, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffffL) {
                                M_ZAPNOT_IMM(s1, 0x1f, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffffffL) {
                                M_ZAPNOT_IMM(s1, 0x3f, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffffffffL) {
                                M_ZAPNOT_IMM(s1, 0x7f, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_AND(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1097,60 +1123,53 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (s1 == d) {
                                M_MOV(s1, REG_ITMP1);
                                s1 = REG_ITMP1;
-                               }
+                       }
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_AND_IMM(s1, iptr->val.l, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_AND_IMM(d, iptr->val.l, d);
-                               }
-                       else if (iptr->val.l == 0xffffL) {
+                       } else if (iptr->val.l == 0xffffL) {
                                M_CZEXT(s1, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_CZEXT(d, d);
-                               }
-                       else if (iptr->val.l == 0xffffffL) {
+                       } else if (iptr->val.l == 0xffffffL) {
                                M_ZAPNOT_IMM(s1, 0x07, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_ZAPNOT_IMM(d, 0x07, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffL) {
                                M_IZEXT(s1, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_IZEXT(d, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffffL) {
                                M_ZAPNOT_IMM(s1, 0x1f, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_ZAPNOT_IMM(d, 0x1f, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffffffL) {
                                M_ZAPNOT_IMM(s1, 0x3f, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_ZAPNOT_IMM(d, 0x3f, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffffffffL) {
                                M_ZAPNOT_IMM(s1, 0x7f, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_ZAPNOT_IMM(d, 0x7f, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_AND(s1, REG_ITMP2, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_AND(d, REG_ITMP2, d);
-                               }
+                       }
                        M_LSUB(REG_ZERO, d, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1160,7 +1179,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_OR( s1,s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1169,14 +1188,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_OR_IMM(s1, iptr->val.i, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_OR(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1184,14 +1202,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_OR_IMM(s1, iptr->val.l, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_OR(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1200,7 +1217,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_XOR(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1209,14 +1226,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_XOR_IMM(s1, iptr->val.i, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_XOR(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1224,14 +1240,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_XOR_IMM(s1, iptr->val.l, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_XOR(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1240,10 +1255,10 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_CMPLT(s1, s2, REG_ITMP3);
                        M_CMPLT(s2, s1, REG_ITMP1);
-                       M_LSUB (REG_ITMP1, REG_ITMP3, d);
+                       M_LSUB(REG_ITMP1, REG_ITMP3, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1254,22 +1269,19 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        var = &(rd->locals[iptr->op1][TYPE_INT]);
                        if (var->flags & INMEMORY) {
                                s1 = REG_ITMP1;
-                               M_LLD(s1, REG_SP, 8 * var->regoff);
-                               }
-                       else
+                               M_LLD(s1, REG_SP, var->regoff * 8);
+                       } else
                                s1 = var->regoff;
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_IADD_IMM(s1, iptr->val.i, s1);
-                               }
-                       else if ((iptr->val.i > -256) && (iptr->val.i < 0)) {
+                       } else if ((iptr->val.i > -256) && (iptr->val.i < 0)) {
                                M_ISUB_IMM(s1, (-iptr->val.i), s1);
-                               }
-                       else {
+                       } else {
                                M_LDA (s1, s1, iptr->val.i);
                                M_IADD(s1, REG_ZERO, s1);
-                               }
+                       }
                        if (var->flags & INMEMORY)
-                               M_LST(s1, REG_SP, 8 * var->regoff);
+                               M_LST(s1, REG_SP, var->regoff * 8);
                        break;
 
 
@@ -1278,7 +1290,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_FNEG:       /* ..., value  ==> ..., - value                 */
 
                        var_to_reg_flt(s1, src, REG_FTMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP2);
                        M_FMOVN(s1, d);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
@@ -1286,7 +1298,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_DNEG:       /* ..., value  ==> ..., - value                 */
 
                        var_to_reg_flt(s1, src, REG_FTMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP2);
                        M_FMOVN(s1, d);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
@@ -1298,18 +1310,16 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_FADD(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_FADDS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_FADDS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -1320,18 +1330,16 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_DADD(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_DADDS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_DADDS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -1342,18 +1350,16 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_FSUB(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_FSUBS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_FSUBS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -1364,18 +1370,16 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_DSUB(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_DSUBS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_DSUBS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -1386,40 +1390,36 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_FMUL(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_FMULS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_FMULS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
-               case ICMD_DMUL:       /* ..., val1, val2  ==> ..., val1 *** val2        */
+               case ICMD_DMUL:       /* ..., val1, val2  ==> ..., val1 *** val2      */
 
                        var_to_reg_flt(s1, src->prev, REG_FTMP1);
                        var_to_reg_flt(s2, src, REG_FTMP2);
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_DMUL(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_DMULS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_DMULS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -1430,18 +1430,16 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_FDIV(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_FDIVS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_FDIVS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -1452,18 +1450,16 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_DDIV(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_DDIVS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_DDIVS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
                
@@ -1471,9 +1467,9 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_L2F:
                        var_to_reg_int(s1, src, REG_ITMP1);
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
-                       a = dseg_adddouble(cd, 0.0);
-                       M_LST (s1, REG_PV, a);
-                       M_DLD (d, REG_PV, a);
+                       disp = dseg_adddouble(cd, 0.0);
+                       M_LST(s1, REG_PV, disp);
+                       M_DLD(d, REG_PV, disp);
                        M_CVTLF(d, d);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
@@ -1482,9 +1478,9 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_L2D:
                        var_to_reg_int(s1, src, REG_ITMP1);
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
-                       a = dseg_adddouble(cd, 0.0);
-                       M_LST (s1, REG_PV, a);
-                       M_DLD (d, REG_PV, a);
+                       disp = dseg_adddouble(cd, 0.0);
+                       M_LST(s1, REG_PV, disp);
+                       M_DLD(d, REG_PV, disp);
                        M_CVTLD(d, d);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
@@ -1493,11 +1489,11 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_D2I:
                        var_to_reg_flt(s1, src, REG_FTMP1);
                        d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                       a = dseg_adddouble(cd, 0.0);
+                       disp = dseg_adddouble(cd, 0.0);
                        M_CVTDL_C(s1, REG_FTMP2);
                        M_CVTLI(REG_FTMP2, REG_FTMP3);
-                       M_DST (REG_FTMP3, REG_PV, a);
-                       M_ILD (d, REG_PV, a);
+                       M_DST(REG_FTMP3, REG_PV, disp);
+                       M_ILD(d, REG_PV, disp);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
                
@@ -1505,10 +1501,10 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_D2L:
                        var_to_reg_flt(s1, src, REG_FTMP1);
                        d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                       a = dseg_adddouble(cd, 0.0);
+                       disp = dseg_adddouble(cd, 0.0);
                        M_CVTDL_C(s1, REG_FTMP2);
-                       M_DST (REG_FTMP2, REG_PV, a);
-                       M_LLD (d, REG_PV, a);
+                       M_DST(REG_FTMP2, REG_PV, disp);
+                       M_LLD(d, REG_PV, disp);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1527,11 +1523,10 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_CVTDF(s1, d);
-                               }
-                       else {
+                       } else {
                                M_CVTDFS(s1, d);
                                M_TRAPB;
-                               }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
                
@@ -1548,8 +1543,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                M_FCMPLT(s2, s1, REG_FTMP3);
                                M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
                                M_LADD_IMM(REG_ZERO, 1, d);
-                               }
-                       else {
+                       } else {
                                M_LSUB_IMM(REG_ZERO, 1, d);
                                M_FCMPEQS(s1, s2, REG_FTMP3);
                                M_TRAPB;
@@ -1559,7 +1553,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                M_TRAPB;
                                M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
                                M_LADD_IMM(REG_ZERO, 1, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
                        
@@ -1576,8 +1570,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                M_FCMPLT(s1, s2, REG_FTMP3);
                                M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
                                M_LSUB_IMM(REG_ZERO, 1, d);
-                               }
-                       else {
+                       } else {
                                M_LADD_IMM(REG_ZERO, 1, d);
                                M_FCMPEQS(s1, s2, REG_FTMP3);
                                M_TRAPB;
@@ -1587,7 +1580,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                M_TRAPB;
                                M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
                                M_LSUB_IMM(REG_ZERO, 1, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1597,37 +1590,80 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_ARRAYLENGTH: /* ..., arrayref  ==> ..., length              */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        gen_nullptr_check(s1);
                        M_ILD(d, s1, OFFSET(java_arrayheader, size));
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
-               case ICMD_AALOAD:     /* ..., arrayref, index  ==> ..., value         */
+               case ICMD_BALOAD:     /* ..., arrayref, index  ==> ..., value         */
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
-                       M_SAADDQ(s2, s1, REG_ITMP1);
-                       M_ALD( d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
+                       }
+                       if (has_ext_instr_set) {
+                               M_LADD   (s2, s1, REG_ITMP1);
+                               M_BLDU   (d, REG_ITMP1, OFFSET (java_bytearray, data[0]));
+                               M_BSEXT  (d, d);
+                       } else {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0])+1);
+                               M_EXTQH(REG_ITMP2, REG_ITMP1, d);
+                               M_SRA_IMM(d, 56, d);
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
-               case ICMD_LALOAD:     /* ..., arrayref, index  ==> ..., value         */
+               case ICMD_CALOAD:     /* ..., arrayref, index  ==> ..., value         */
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
-                       M_S8ADDQ(s2, s1, REG_ITMP1);
-                       M_LLD(d, REG_ITMP1, OFFSET(java_longarray, data[0]));
+                       }
+                       if (has_ext_instr_set) {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_SLDU(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                       } else {
+                               M_LADD (s2, s1, REG_ITMP1);
+                               M_LADD (s2, REG_ITMP1, REG_ITMP1);
+                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                               M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                               M_EXTWL(REG_ITMP2, REG_ITMP1, d);
+                       }
+                       store_reg_to_var_int(iptr->dst, d);
+                       break;                  
+
+               case ICMD_SALOAD:     /* ..., arrayref, index  ==> ..., value         */
+
+                       var_to_reg_int(s1, src->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src, REG_ITMP2);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                       }
+                       if (has_ext_instr_set) {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_SLDU( d, REG_ITMP1, OFFSET (java_shortarray, data[0]));
+                               M_SSEXT(d, d);
+                       } else {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0])+2);
+                               M_EXTQH(REG_ITMP2, REG_ITMP1, d);
+                               M_SRA_IMM(d, 48, d);
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1635,26 +1671,39 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
-                 
+                       }
                        M_S4ADDQ(s2, s1, REG_ITMP1);
                        M_ILD(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
+               case ICMD_LALOAD:     /* ..., arrayref, index  ==> ..., value         */
+
+                       var_to_reg_int(s1, src->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src, REG_ITMP2);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                       }
+                       M_S8ADDQ(s2, s1, REG_ITMP1);
+                       M_LLD(d, REG_ITMP1, OFFSET(java_longarray, data[0]));
+                       store_reg_to_var_int(iptr->dst, d);
+                       break;
+
                case ICMD_FALOAD:     /* ..., arrayref, index  ==> ..., value         */
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
                        M_S4ADDQ(s2, s1, REG_ITMP1);
                        M_FLD(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
                        store_reg_to_var_flt(iptr->dst, d);
@@ -1664,129 +1713,128 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
                        M_S8ADDQ(s2, s1, REG_ITMP1);
                        M_DLD(d, REG_ITMP1, OFFSET(java_doublearray, data[0]));
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
-               case ICMD_CALOAD:     /* ..., arrayref, index  ==> ..., value         */
+               case ICMD_AALOAD:     /* ..., arrayref, index  ==> ..., value         */
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
-                       if (has_ext_instr_set) {
-                               M_LADD(s2, s1, REG_ITMP1);
-                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
-                               M_SLDU(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
-                               }
-                       else {
-                               M_LADD (s2, s1, REG_ITMP1);
-                               M_LADD (s2, REG_ITMP1, REG_ITMP1);
-                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
-                               M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
-                               M_EXTWL(REG_ITMP2, REG_ITMP1, d);
-                               }
+                       }
+                       M_SAADDQ(s2, s1, REG_ITMP1);
+                       M_ALD(d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
                        store_reg_to_var_int(iptr->dst, d);
-                       break;                  
+                       break;
 
-               case ICMD_SALOAD:     /* ..., arrayref, index  ==> ..., value         */
 
-                       var_to_reg_int(s1, src->prev, REG_ITMP1);
-                       var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+               case ICMD_BASTORE:    /* ..., arrayref, index, value  ==> ...         */
+
+                       var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src->prev, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
+                       var_to_reg_int(s3, src, REG_ITMP3);
                        if (has_ext_instr_set) {
                                M_LADD(s2, s1, REG_ITMP1);
-                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
-                               M_SLDU( d, REG_ITMP1, OFFSET (java_shortarray, data[0]));
-                               M_SSEXT(d, d);
-                               }
-                       else {
+                               M_BST(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+                       } else {
                                M_LADD(s2, s1, REG_ITMP1);
-                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
-                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
-                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0])+2);
-                               M_EXTQH(REG_ITMP2, REG_ITMP1, d);
-                               M_SRA_IMM(d, 48, d);
-                               }
-                       store_reg_to_var_int(iptr->dst, d);
+                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+                               M_INSBL(s3, REG_ITMP1, REG_ITMP3);
+                               M_MSKBL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
+                               M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2);
+                               M_LST_U(REG_ITMP2, REG_ITMP1, 0);
+                       }
                        break;
 
-               case ICMD_BALOAD:     /* ..., arrayref, index  ==> ..., value         */
+               case ICMD_CASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
-                       var_to_reg_int(s1, src->prev, REG_ITMP1);
-                       var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src->prev, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
+                       var_to_reg_int(s3, src, REG_ITMP3);
                        if (has_ext_instr_set) {
-                               M_LADD   (s2, s1, REG_ITMP1);
-                               M_BLDU   (d, REG_ITMP1, OFFSET (java_bytearray, data[0]));
-                               M_BSEXT  (d, d);
-                               }
-                       else {
                                M_LADD(s2, s1, REG_ITMP1);
-                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
-                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0])+1);
-                               M_EXTQH(REG_ITMP2, REG_ITMP1, d);
-                               M_SRA_IMM(d, 56, d);
-                               }
-                       store_reg_to_var_int(iptr->dst, d);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_SST(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                       } else {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                               M_INSWL(s3, REG_ITMP1, REG_ITMP3);
+                               M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
+                               M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2);
+                               M_LST_U(REG_ITMP2, REG_ITMP1, 0);
+                       }
                        break;
 
-
-               case ICMD_AASTORE:    /* ..., arrayref, index, value  ==> ...         */
+               case ICMD_SASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
                        var_to_reg_int(s3, src, REG_ITMP3);
-                       M_SAADDQ(s2, s1, REG_ITMP1);
-                       M_AST   (s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
+                       if (has_ext_instr_set) {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_SST(s3, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+                       } else {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+                               M_INSWL(s3, REG_ITMP1, REG_ITMP3);
+                               M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
+                               M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2);
+                               M_LST_U(REG_ITMP2, REG_ITMP1, 0);
+                       }
                        break;
 
-               case ICMD_LASTORE:    /* ..., arrayref, index, value  ==> ...         */
+               case ICMD_IASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
                        var_to_reg_int(s3, src, REG_ITMP3);
-                       M_S8ADDQ(s2, s1, REG_ITMP1);
-                       M_LST   (s3, REG_ITMP1, OFFSET(java_longarray, data[0]));
+                       M_S4ADDQ(s2, s1, REG_ITMP1);
+                       M_IST(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
                        break;
 
-               case ICMD_IASTORE:    /* ..., arrayref, index, value  ==> ...         */
+               case ICMD_LASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
-
+                       }
                        var_to_reg_int(s3, src, REG_ITMP3);
-                       M_S4ADDQ(s2, s1, REG_ITMP1);
-                       M_IST   (s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
+                       M_S8ADDQ(s2, s1, REG_ITMP1);
+                       M_LST(s3, REG_ITMP1, OFFSET(java_longarray, data[0]));
                        break;
 
                case ICMD_FASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1796,10 +1844,10 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
                        var_to_reg_flt(s3, src, REG_FTMP3);
                        M_S4ADDQ(s2, s1, REG_ITMP1);
-                       M_FST   (s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
+                       M_FST(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
                        break;
 
                case ICMD_DASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1809,86 +1857,39 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
                        var_to_reg_flt(s3, src, REG_FTMP3);
                        M_S8ADDQ(s2, s1, REG_ITMP1);
-                       M_DST   (s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
+                       M_DST(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
                        break;
 
-               case ICMD_CASTORE:    /* ..., arrayref, index, value  ==> ...         */
+               case ICMD_AASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       if (iptr->op1 == 0) {
+/*                     if (iptr->op1 == 0) { */
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+/*                     } */
                        var_to_reg_int(s3, src, REG_ITMP3);
-                       if (has_ext_instr_set) {
-                               M_LADD(s2, s1, REG_ITMP1);
-                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
-                               M_SST (s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
-                               }
-                       else {
-                               M_LADD (s2, s1, REG_ITMP1);
-                               M_LADD (s2, REG_ITMP1, REG_ITMP1);
-                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
-                               M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
-                               M_INSWL(s3, REG_ITMP1, REG_ITMP3);
-                               M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
-                               M_OR   (REG_ITMP2, REG_ITMP3, REG_ITMP2);
-                               M_LST_U(REG_ITMP2, REG_ITMP1, 0);
-                               }
-                       break;
-
-               case ICMD_SASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
-                       var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
-                       var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       if (iptr->op1 == 0) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                               }
-                       var_to_reg_int(s3, src, REG_ITMP3);
-                       if (has_ext_instr_set) {
-                               M_LADD(s2, s1, REG_ITMP1);
-                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
-                               M_SST (s3, REG_ITMP1, OFFSET(java_shortarray, data[0]));
-                               }
-                       else {
-                               M_LADD (s2, s1, REG_ITMP1);
-                               M_LADD (s2, REG_ITMP1, REG_ITMP1);
-                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
-                               M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0]));
-                               M_INSWL(s3, REG_ITMP1, REG_ITMP3);
-                               M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
-                               M_OR   (REG_ITMP2, REG_ITMP3, REG_ITMP2);
-                               M_LST_U(REG_ITMP2, REG_ITMP1, 0);
-                               }
-                       break;
+                       M_MOV(s1, rd->argintregs[0]);
+                       M_MOV(s3, rd->argintregs[1]);
+                       bte = iptr->val.a;
+                       disp = dseg_addaddress(cd, bte->fp);
+                       M_ALD(REG_PV, REG_PV, disp);
+                       M_JSR(REG_RA, REG_PV);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
 
-               case ICMD_BASTORE:    /* ..., arrayref, index, value  ==> ...         */
+                       M_BEQZ(REG_RESULT, 0);
+                       codegen_addxstorerefs(cd, mcodeptr);
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       if (iptr->op1 == 0) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                               }
                        var_to_reg_int(s3, src, REG_ITMP3);
-                       if (has_ext_instr_set) {
-                               M_LADD(s2, s1, REG_ITMP1);
-                               M_BST (s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
-                               }
-                       else {
-                               M_LADD (s2, s1, REG_ITMP1);
-                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
-                               M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0]));
-                               M_INSBL(s3, REG_ITMP1, REG_ITMP3);
-                               M_MSKBL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
-                               M_OR   (REG_ITMP2, REG_ITMP3, REG_ITMP2);
-                               M_LST_U(REG_ITMP2, REG_ITMP1, 0);
-                               }
+                       M_SAADDQ(s2, s1, REG_ITMP1);
+                       M_AST(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
                        break;
 
 
@@ -2006,44 +2007,44 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* op1 = type, val.a = field address            */
 
                        if (!iptr->val.a) {
+                               disp = dseg_addaddress(cd, 0);
+
                                codegen_addpatchref(cd, mcodeptr,
                                                                        PATCHER_get_putstatic,
-                                                                       (unresolved_field *) iptr->target);
+                                                                       (unresolved_field *) iptr->target, disp);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = 0;
 
                        } else {
                                fieldinfo *fi = iptr->val.a;
 
+                               disp = dseg_addaddress(cd, &(fi->value));
+
                                if (!fi->class->initialized) {
                                        codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_clinit, fi->class);
+                                                                               PATCHER_clinit, fi->class, 0);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
                                }
-
-                               a = (ptrint) &(fi->value);
                        }
 
-                       a = dseg_addaddress(cd, a);
-                       M_ALD(REG_ITMP1, REG_PV, a);
+                       M_ALD(REG_ITMP1, REG_PV, disp);
                        switch (iptr->op1) {
                        case TYPE_INT:
-                               d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                               d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                                M_ILD(d, REG_ITMP1, 0);
                                store_reg_to_var_int(iptr->dst, d);
                                break;
                        case TYPE_LNG:
-                               d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                               d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                                M_LLD(d, REG_ITMP1, 0);
                                store_reg_to_var_int(iptr->dst, d);
                                break;
                        case TYPE_ADR:
-                               d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                               d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                                M_ALD(d, REG_ITMP1, 0);
                                store_reg_to_var_int(iptr->dst, d);
                                break;
@@ -2064,31 +2065,30 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* op1 = type, val.a = field address            */
 
                        if (!iptr->val.a) {
+                               disp = dseg_addaddress(cd, 0);
+
                                codegen_addpatchref(cd, mcodeptr,
                                                                        PATCHER_get_putstatic,
-                                                                       (unresolved_field *) iptr->target);
+                                                                       (unresolved_field *) iptr->target, disp);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = 0;
-
                        } else {
                                fieldinfo *fi = iptr->val.a;
 
+                               disp = dseg_addaddress(cd, &(fi->value));
+
                                if (!fi->class->initialized) {
                                        codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_clinit, fi->class);
+                                                                               PATCHER_clinit, fi->class, 0);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
                                }
-
-                               a = (ptrint) &(fi->value);
                        }
 
-                       a = dseg_addaddress(cd, a);
-                       M_ALD(REG_ITMP1, REG_PV, a);
+                       M_ALD(REG_ITMP1, REG_PV, disp);
                        switch (iptr->op1) {
                        case TYPE_INT:
                                var_to_reg_int(s2, src, REG_ITMP2);
@@ -2119,31 +2119,30 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                          /* following NOP)                           */
 
                        if (!iptr[1].val.a) {
+                               disp = dseg_addaddress(cd, 0);
+
                                codegen_addpatchref(cd, mcodeptr,
                                                                        PATCHER_get_putstatic,
-                                                                       (unresolved_field *) iptr[1].target);
+                                                                       (unresolved_field *) iptr[1].target, disp);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = 0;
-
                        } else {
                                fieldinfo *fi = iptr[1].val.a;
+       
+                               disp = dseg_addaddress(cd, &(fi->value));
 
                                if (!fi->class->initialized) {
                                        codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_clinit, fi->class);
+                                                                               PATCHER_clinit, fi->class, 0);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
                                }
-
-                               a = (ptrint) &(fi->value);
                        }
                        
-                       a = dseg_addaddress(cd, a);
-                       M_ALD(REG_ITMP1, REG_PV, a);
+                       M_ALD(REG_ITMP1, REG_PV, disp);
                        switch (iptr->op1) {
                        case TYPE_INT:
                                M_IST(REG_ZERO, REG_ITMP1, 0);
@@ -2173,41 +2172,41 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        if (!iptr->val.a) {
                                codegen_addpatchref(cd, mcodeptr,
                                                                        PATCHER_get_putfield,
-                                                                       (unresolved_field *) iptr->target);
+                                                                       (unresolved_field *) iptr->target, 0);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = 0;
+                               disp = 0;
 
                        } else {
-                               a = ((fieldinfo *) (iptr->val.a))->offset;
+                               disp = ((fieldinfo *) (iptr->val.a))->offset;
                        }
 
                        switch (iptr->op1) {
                        case TYPE_INT:
-                               d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                               M_ILD(d, s1, a);
+                               d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                               M_ILD(d, s1, disp);
                                store_reg_to_var_int(iptr->dst, d);
                                break;
                        case TYPE_LNG:
-                               d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                               M_LLD(d, s1, a);
+                               d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                               M_LLD(d, s1, disp);
                                store_reg_to_var_int(iptr->dst, d);
                                break;
                        case TYPE_ADR:
-                               d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                               M_ALD(d, s1, a);
+                               d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                               M_ALD(d, s1, disp);
                                store_reg_to_var_int(iptr->dst, d);
                                break;
                        case TYPE_FLT:
-                               d = reg_of_var(rd, iptr->dst, REG_FTMP3);
-                               M_FLD(d, s1, a);
+                               d = reg_of_var(rd, iptr->dst, REG_FTMP1);
+                               M_FLD(d, s1, disp);
                                store_reg_to_var_flt(iptr->dst, d);
                                break;
                        case TYPE_DBL:                          
-                               d = reg_of_var(rd, iptr->dst, REG_FTMP3);
-                               M_DLD(d, s1, a);
+                               d = reg_of_var(rd, iptr->dst, REG_FTMP1);
+                               M_DLD(d, s1, disp);
                                store_reg_to_var_flt(iptr->dst, d);
                                break;
                        }
@@ -2228,32 +2227,32 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        if (!iptr->val.a) {
                                codegen_addpatchref(cd, mcodeptr,
                                                                        PATCHER_get_putfield,
-                                                                       (unresolved_field *) iptr->target);
+                                                                       (unresolved_field *) iptr->target, 0);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = 0;
+                               disp = 0;
 
                        } else {
-                               a = ((fieldinfo *) (iptr->val.a))->offset;
+                               disp = ((fieldinfo *) (iptr->val.a))->offset;
                        }
 
                        switch (iptr->op1) {
                        case TYPE_INT:
-                               M_IST(s2, s1, a);
+                               M_IST(s2, s1, disp);
                                break;
                        case TYPE_LNG:
-                               M_LST(s2, s1, a);
+                               M_LST(s2, s1, disp);
                                break;
                        case TYPE_ADR:
-                               M_AST(s2, s1, a);
+                               M_AST(s2, s1, disp);
                                break;
                        case TYPE_FLT:
-                               M_FST(s2, s1, a);
+                               M_FST(s2, s1, disp);
                                break;
                        case TYPE_DBL:
-                               M_DST(s2, s1, a);
+                               M_DST(s2, s1, disp);
                                break;
                        }
                        break;
@@ -2269,32 +2268,32 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        if (!iptr[1].val.a) {
                                codegen_addpatchref(cd, mcodeptr,
                                                                        PATCHER_get_putfield,
-                                                                       (unresolved_field *) iptr[1].target);
+                                                                       (unresolved_field *) iptr[1].target, 0);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = 0;
+                               disp = 0;
 
                        } else {
-                               a = ((fieldinfo *) (iptr[1].val.a))->offset;
+                               disp = ((fieldinfo *) (iptr[1].val.a))->offset;
                        }
 
                        switch (iptr[1].op1) {
                        case TYPE_INT:
-                               M_IST(REG_ZERO, s1, a);
+                               M_IST(REG_ZERO, s1, disp);
                                break;
                        case TYPE_LNG:
-                               M_LST(REG_ZERO, s1, a);
+                               M_LST(REG_ZERO, s1, disp);
                                break;
                        case TYPE_ADR:
-                               M_AST(REG_ZERO, s1, a);
+                               M_AST(REG_ZERO, s1, disp);
                                break;
                        case TYPE_FLT:
-                               M_FST(REG_ZERO, s1, a);
+                               M_FST(REG_ZERO, s1, disp);
                                break;
                        case TYPE_DBL:
-                               M_DST(REG_ZERO, s1, a);
+                               M_DST(REG_ZERO, s1, disp);
                                break;
                        }
                        break;
@@ -2306,8 +2305,8 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_INTMOVE(s1, REG_ITMP1_XPTR);
-                       a = dseg_addaddress(cd, asm_handle_exception);
-                       M_ALD(REG_ITMP2, REG_PV, a);
+                       disp = dseg_addaddress(cd, asm_handle_exception);
+                       M_ALD(REG_ITMP2, REG_PV, disp);
                        M_JMP(REG_ITMP2_XPC, REG_ITMP2);
                        M_NOP;              /* nop ensures that XPC is less than the end */
                                            /* of basic block                            */
@@ -2668,33 +2667,32 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        s3 = iptr->val.i;
                        if (iptr[1].opc == ICMD_ELSE_ICONST) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPEQ(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPEQ(s1, REG_ZERO, d);
                                        M_XOR_IMM(d, 1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if (s1 == d) {
                                        M_MOV(s1, REG_ITMP1);
                                        s1 = REG_ITMP1;
-                                       }
-                               ICONST(d, iptr[1].val.i);
                                }
+                               ICONST(d, iptr[1].val.i);
+                       }
                        if ((s3 >= 0) && (s3 <= 255)) {
                                M_CMOVEQ_IMM(s1, s3, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, s3);
                                M_CMOVEQ(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -2702,33 +2700,32 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        s3 = iptr->val.i;
                        if (iptr[1].opc == ICMD_ELSE_ICONST) {
                                if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPEQ(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPEQ(s1, REG_ZERO, d);
                                        M_XOR_IMM(d, 1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if (s1 == d) {
                                        M_MOV(s1, REG_ITMP1);
                                        s1 = REG_ITMP1;
-                                       }
-                               ICONST(d, iptr[1].val.i);
                                }
+                               ICONST(d, iptr[1].val.i);
+                       }
                        if ((s3 >= 0) && (s3 <= 255)) {
                                M_CMOVNE_IMM(s1, s3, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, s3);
                                M_CMOVNE(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -2736,32 +2733,31 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPLT(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPLE(REG_ZERO, s1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if (s1 == d) {
                                        M_MOV(s1, REG_ITMP1);
                                        s1 = REG_ITMP1;
-                                       }
-                               ICONST(d, iptr[1].val.i);
                                }
+                               ICONST(d, iptr[1].val.i);
+                       }
                        if ((s3 >= 0) && (s3 <= 255)) {
                                M_CMOVLT_IMM(s1, s3, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, s3);
                                M_CMOVLT(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -2769,32 +2765,31 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPLE(REG_ZERO, s1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPLT(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if (s1 == d) {
                                        M_MOV(s1, REG_ITMP1);
                                        s1 = REG_ITMP1;
-                                       }
-                               ICONST(d, iptr[1].val.i);
                                }
+                               ICONST(d, iptr[1].val.i);
+                       }
                        if ((s3 >= 0) && (s3 <= 255)) {
                                M_CMOVGE_IMM(s1, s3, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, s3);
                                M_CMOVGE(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -2802,32 +2797,31 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPLT(REG_ZERO, s1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPLE(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if (s1 == d) {
                                        M_MOV(s1, REG_ITMP1);
                                        s1 = REG_ITMP1;
-                                       }
-                               ICONST(d, iptr[1].val.i);
                                }
+                               ICONST(d, iptr[1].val.i);
+                       }
                        if ((s3 >= 0) && (s3 <= 255)) {
                                M_CMOVGT_IMM(s1, s3, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, s3);
                                M_CMOVGT(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -2835,32 +2829,31 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPLE(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPLT(REG_ZERO, s1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if (s1 == d) {
                                        M_MOV(s1, REG_ITMP1);
                                        s1 = REG_ITMP1;
-                                       }
-                               ICONST(d, iptr[1].val.i);
                                }
+                               ICONST(d, iptr[1].val.i);
+                       }
                        if ((s3 >= 0) && (s3 <= 255)) {
                                M_CMOVLE_IMM(s1, s3, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, s3);
                                M_CMOVLE(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -2897,22 +2890,19 @@ nowperformreturn:
                                M_AST(REG_RA, REG_SP, 0 * 8);
                                M_LST(REG_RESULT, REG_SP, 1 * 8);
                                M_DST(REG_FRESULT, REG_SP, 2 * 8);
-                               a = dseg_addaddress(cd, m);
-                               M_ALD(rd->argintregs[0], REG_PV, a);
+
+                               disp = dseg_addaddress(cd, m);
+                               M_ALD(rd->argintregs[0], REG_PV, disp);
                                M_MOV(REG_RESULT, rd->argintregs[1]);
                                M_FLTMOVE(REG_FRESULT, rd->argfltregs[2]);
                                M_FLTMOVE(REG_FRESULT, rd->argfltregs[3]);
-                               a = dseg_addaddress(cd, (void *) builtin_displaymethodstop);
-                               M_ALD(REG_PV, REG_PV, a);
+
+                               disp = dseg_addaddress(cd, (void *) builtin_displaymethodstop);
+                               M_ALD(REG_PV, REG_PV, disp);
                                M_JSR(REG_RA, REG_PV);
-                               s1 = (s4) ((u1 *) mcodeptr - cd->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);
-                               }
+                               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                               M_LDA(REG_PV, REG_RA, -disp);
+
                                M_DLD(REG_FRESULT, REG_SP, 2 * 8);
                                M_LLD(REG_RESULT, REG_SP, 1 * 8);
                                M_ALD(REG_RA, REG_SP, 0 * 8);
@@ -2923,22 +2913,22 @@ nowperformreturn:
                        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
                                s4 disp;
 
-                               M_ALD(rd->argintregs[0], REG_SP, rd->maxmemuse * 8);
+                               M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 8);
 
                                switch (iptr->opc) {
                                case ICMD_IRETURN:
                                case ICMD_LRETURN:
                                case ICMD_ARETURN:
-                                       M_LST(REG_RESULT, REG_SP, rd->maxmemuse * 8);
+                                       M_LST(REG_RESULT, REG_SP, rd->memuse * 8);
                                        break;
                                case ICMD_FRETURN:
                                case ICMD_DRETURN:
-                                       M_DST(REG_FRESULT, REG_SP, rd->maxmemuse * 8);
+                                       M_DST(REG_FRESULT, REG_SP, rd->memuse * 8);
                                        break;
                                }
 
-                               a = dseg_addaddress(cd, BUILTIN_monitorexit);
-                               M_ALD(REG_PV, REG_PV, a);
+                               disp = dseg_addaddress(cd, BUILTIN_monitorexit);
+                               M_ALD(REG_PV, REG_PV, disp);
                                M_JSR(REG_RA, REG_PV);
                                disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
                                M_LDA(REG_PV, REG_RA, disp);
@@ -2947,11 +2937,11 @@ nowperformreturn:
                                case ICMD_IRETURN:
                                case ICMD_LRETURN:
                                case ICMD_ARETURN:
-                                       M_LLD(REG_RESULT, REG_SP, rd->maxmemuse * 8);
+                                       M_LLD(REG_RESULT, REG_SP, rd->memuse * 8);
                                        break;
                                case ICMD_FRETURN:
                                case ICMD_DRETURN:
-                                       M_DLD(REG_FRESULT, REG_SP, rd->maxmemuse * 8);
+                                       M_DLD(REG_FRESULT, REG_SP, rd->memuse * 8);
                                        break;
                                }
                        }
@@ -2965,10 +2955,10 @@ nowperformreturn:
 
                        /* restore saved registers                                        */
 
-                       for (i = rd->savintregcnt - 1; i >= rd->maxsavintreguse; i--) {
+                       for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
                                p--; M_LLD(rd->savintregs[i], REG_SP, p * 8);
                        }
-                       for (i = rd->savfltregcnt - 1; i >= rd->maxsavfltreguse; i--) {
+                       for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
                                p--; M_DLD(rd->savfltregs[i], REG_SP, p * 8);
                        }
 
@@ -2996,15 +2986,14 @@ nowperformreturn:
                        i = s4ptr[2];                          /* high    */
                        
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       if (l == 0)
-                               {M_INTMOVE(s1, REG_ITMP1);}
-                       else if (l <= 32768) {
+                       if (l == 0) {
+                               M_INTMOVE(s1, REG_ITMP1);
+                       else if (l <= 32768) {
                                M_LDA(REG_ITMP1, s1, -l);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, l);
                                M_ISUB(s1, REG_ITMP2, REG_ITMP1);
-                               }
+                       }
                        i = i - l + 1;
 
                        /* range check */
@@ -3014,11 +3003,8 @@ nowperformreturn:
                        else {
                                M_LDA(REG_ITMP2, REG_ZERO, i - 1);
                                M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2);
-                               }
+                       }
                        M_BEQZ(REG_ITMP2, 0);
-
-
-                       /* codegen_addreference(cd, BlockPtrOfPC(s4ptr[0]), mcodeptr); */
                        codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
 
                        /* build jump table top down and use address of lowest entry */
@@ -3027,10 +3013,9 @@ nowperformreturn:
                        tptr += i;
 
                        while (--i >= 0) {
-                               /* dseg_addtarget(cd, BlockPtrOfPC(*--s4ptr)); */
                                dseg_addtarget(cd, (basicblock *) tptr[0]); 
                                --tptr;
-                               }
+                       }
                        }
 
                        /* length of dataseg after last dseg_addtarget is used by load */
@@ -3062,24 +3047,20 @@ nowperformreturn:
                                val = s4ptr[0];
                                if ((val >= 0) && (val <= 255)) {
                                        M_CMPEQ_IMM(s1, val, REG_ITMP2);
-                                       }
-                               else {
+                               } else {
                                        if ((val >= -32768) && (val <= 32767)) {
                                                M_LDA(REG_ITMP2, REG_ZERO, val);
-                                               } 
-                                       else {
-                                               a = dseg_adds4(cd, val);
-                                               M_ILD(REG_ITMP2, REG_PV, a);
-                                               }
-                                       M_CMPEQ(s1, REG_ITMP2, REG_ITMP2);
+                                       } else {
+                                               disp = dseg_adds4(cd, val);
+                                               M_ILD(REG_ITMP2, REG_PV, disp);
                                        }
+                                       M_CMPEQ(s1, REG_ITMP2, REG_ITMP2);
+                               }
                                M_BNEZ(REG_ITMP2, 0);
-                               /* codegen_addreference(cd, BlockPtrOfPC(s4ptr[1]), mcodeptr); */
                                codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr); 
-                               }
+                       }
 
                        M_BR(0);
-                       /* codegen_addreference(cd, BlockPtrOfPC(l), mcodeptr); */
                        
                        tptr = (void **) iptr->target;
                        codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
@@ -3113,7 +3094,7 @@ nowperformreturn:
                        }
 
 gen_method:
-                       s3 = iptr->op1;
+                       s3 = md->paramcount;
 
                        MCODECHECK((s3 << 1) + 64);
 
@@ -3147,48 +3128,61 @@ gen_method:
                        switch (iptr->opc) {
                        case ICMD_BUILTIN:
                                if (iptr->target) {
-                                       codegen_addpatchref(cd, mcodeptr, bte->fp, iptr->target);
+                                       disp = dseg_addaddress(cd, NULL);
 
-                                       if (showdisassemble)
-                                               M_NOP;
+                                       codegen_addpatchref(cd, mcodeptr, bte->fp, iptr->target,
+                                                                               disp);
 
-                                       a = 0;
+                                       if (opt_showdisassemble)
+                                               M_NOP;
 
                                } else {
-                                       a = (ptrint) bte->fp;
+                                       disp = dseg_addaddress(cd, bte->fp);
                                }
 
-                               a = dseg_addaddress(cd, a);
                                d = md->returntype.type;
 
-                               M_ALD(REG_PV, REG_PV, a);     /* Pointer to built-in-function */
+                               M_ALD(REG_PV, REG_PV, disp);  /* Pointer to built-in-function */
+                               M_JSR(REG_RA, REG_PV);
+                               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                               M_LDA(REG_PV, REG_RA, -disp);
+
+                               /* if op1 == true, we need to check for an exception */
+
+                               if (iptr->op1 == true) {
+                                       M_BEQZ(REG_RESULT, 0);
+                                       codegen_addxexceptionrefs(cd, mcodeptr);
+                               }
                                break;
 
                        case ICMD_INVOKESPECIAL:
-                               gen_nullptr_check(rd->argintregs[0]);
-                               M_ILD(REG_ITMP1, rd->argintregs[0], 0); /* hardware nullptr   */
+                               M_BEQZ(rd->argintregs[0], 0);
+                               codegen_addxnullrefs(cd, mcodeptr);
                                /* fall through */
 
                        case ICMD_INVOKESTATIC:
                                if (!lm) {
                                        unresolved_method *um = iptr->target;
 
+                                       disp = dseg_addaddress(cd, NULL);
+
                                        codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_invokestatic_special, um);
+                                                                               PATCHER_invokestatic_special, um, disp);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
 
-                                       a = 0;
                                        d = um->methodref->parseddesc.md->returntype.type;
 
                                } else {
-                                       a = (ptrint) lm->stubroutine;
+                                       disp = dseg_addaddress(cd, lm->stubroutine);
                                        d = lm->parseddesc->returntype.type;
                                }
 
-                               a = dseg_addaddress(cd, a);
-                               M_ALD(REG_PV, REG_PV, a);            /* method pointer in r27 */
+                               M_ALD(REG_PV, REG_PV, disp);         /* method pointer in r27 */
+                               M_JSR(REG_RA, REG_PV);
+                               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                               M_LDA(REG_PV, REG_RA, -disp);
                                break;
 
                        case ICMD_INVOKEVIRTUAL:
@@ -3198,9 +3192,9 @@ gen_method:
                                        unresolved_method *um = iptr->target;
 
                                        codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_invokevirtual, um);
+                                                                               PATCHER_invokevirtual, um, 0);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
 
                                        s1 = 0;
@@ -3215,6 +3209,9 @@ gen_method:
                                M_ALD(REG_METHODPTR, rd->argintregs[0],
                                          OFFSET(java_objectheader, vftbl));
                                M_ALD(REG_PV, REG_METHODPTR, s1);
+                               M_JSR(REG_RA, REG_PV);
+                               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                               M_LDA(REG_PV, REG_RA, -disp);
                                break;
 
                        case ICMD_INVOKEINTERFACE:
@@ -3224,9 +3221,9 @@ gen_method:
                                        unresolved_method *um = iptr->target;
 
                                        codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_invokeinterface, um);
+                                                                               PATCHER_invokeinterface, um, 0);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
 
                                        s1 = 0;
@@ -3246,22 +3243,12 @@ gen_method:
                                          OFFSET(java_objectheader, vftbl));    
                                M_ALD(REG_METHODPTR, REG_METHODPTR, s1);
                                M_ALD(REG_PV, REG_METHODPTR, s2);
+                               M_JSR(REG_RA, REG_PV);
+                               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                               M_LDA(REG_PV, REG_RA, -disp);
                                break;
                        }
 
-                       M_JSR(REG_RA, REG_PV);
-
-                       /* recompute pv */
-
-                       s1 = (s4) ((u1 *) mcodeptr - cd->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);
-                       }
-
                        /* d contains return type */
 
                        if (d != TYPE_VOID) {
@@ -3321,30 +3308,31 @@ gen_method:
 
                        s2 = 6;
                        if (!super)
-                               s2 += showdisassemble ? 1 : 0;
+                               s2 += opt_showdisassemble ? 1 : 0;
 
                        /* calculate class checkcast code size */
 
                        s3 = 9 /* 8 + (s1 == REG_ITMP1) */;
                        if (!super)
-                               s3 += showdisassemble ? 1 : 0;
+                               s3 += opt_showdisassemble ? 1 : 0;
 
                        /* if class is not resolved, check which code to call */
 
                        if (!super) {
-                               M_BEQZ(s1, 4 + (showdisassemble ? 1 : 0) + s2 + 1 + s3);
+                               M_BEQZ(s1, 4 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
+
+                               disp = dseg_adds4(cd, 0);                     /* super->flags */
 
                                codegen_addpatchref(cd, mcodeptr,
                                                                        PATCHER_checkcast_instanceof_flags,
-                                                                       (constant_classref *) iptr->target);
+                                                                       (constant_classref *) iptr->target, disp);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = dseg_adds4(cd, 0); /* super->flags */
-                               M_ILD(REG_ITMP2, REG_PV, a);
-                               a = dseg_adds4(cd, ACC_INTERFACE);
-                               M_ILD(REG_ITMP3, REG_PV, a);
+                               M_ILD(REG_ITMP2, REG_PV, disp);
+                               disp = dseg_adds4(cd, ACC_INTERFACE);
+                               M_ILD(REG_ITMP3, REG_PV, disp);
                                M_AND(REG_ITMP2, REG_ITMP3, REG_ITMP2);
                                M_BEQZ(REG_ITMP2, s2 + 1);
                        }
@@ -3358,9 +3346,9 @@ gen_method:
                                } else {
                                        codegen_addpatchref(cd, mcodeptr,
                                                                                PATCHER_checkcast_instanceof_interface,
-                                                                               (constant_classref *) iptr->target);
+                                                                               (constant_classref *) iptr->target, 0);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
                                }
 
@@ -3370,8 +3358,8 @@ gen_method:
                                M_BLEZ(REG_ITMP3, 0);
                                codegen_addxcastrefs(cd, mcodeptr);
                                M_ALD(REG_ITMP3, REG_ITMP2,
-                                         OFFSET(vftbl_t, interfacetable[0]) -
-                                         superindex * sizeof(methodptr*));
+                                         (s4) (OFFSET(vftbl_t, interfacetable[0]) -
+                                                       superindex * sizeof(methodptr*)));
                                M_BEQZ(REG_ITMP3, 0);
                                codegen_addxcastrefs(cd, mcodeptr);
 
@@ -3382,21 +3370,23 @@ gen_method:
                        /* class checkcast code */
 
                        if (!super || !(super->flags & ACC_INTERFACE)) {
+                               disp = dseg_addaddress(cd, supervftbl);
+
                                if (super) {
                                        M_BEQZ(s1, s3);
 
                                } else {
                                        codegen_addpatchref(cd, mcodeptr,
                                                                                PATCHER_checkcast_instanceof_class,
-                                                                               (constant_classref *) iptr->target);
+                                                                               (constant_classref *) iptr->target,
+                                                                               disp);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
                                }
 
                                M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
-                               a = dseg_addaddress(cd, supervftbl);
-                               M_ALD(REG_ITMP3, REG_PV, a);
+                               M_ALD(REG_ITMP3, REG_PV, disp);
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
                                codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
@@ -3412,7 +3402,7 @@ gen_method:
 /*                             } else { */
                                        M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
                                        M_ISUB(REG_ITMP2, REG_ITMP3, REG_ITMP2);
-                                       M_ALD(REG_ITMP3, REG_PV, a);
+                                       M_ALD(REG_ITMP3, REG_PV, disp);
                                        M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
                                        codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
@@ -3422,12 +3412,51 @@ gen_method:
                                M_BEQZ(REG_ITMP3, 0);
                                codegen_addxcastrefs(cd, mcodeptr);
                        }
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, s1);
                        M_INTMOVE(s1, d);
                        store_reg_to_var_int(iptr->dst, d);
                        }
                        break;
 
+               case ICMD_ARRAYCHECKCAST: /* ..., objectref ==> ..., objectref        */
+                                         /* op1: 1... resolved, 0... not resolved    */
+
+                       var_to_reg_int(s1, src, rd->argintregs[0]);
+                       M_INTMOVE(s1, rd->argintregs[0]);
+
+                       bte = iptr->val.a;
+
+                       disp = dseg_addaddress(cd, iptr->target);
+
+                       if (!iptr->op1) {
+                               codegen_addpatchref(cd, mcodeptr, bte->fp, iptr->target, disp);
+
+                               if (opt_showdisassemble)
+                                       M_NOP;
+
+                               a = 0;
+
+                       } else {
+                               a = (ptrint) bte->fp;
+                       }
+
+                       M_ALD(rd->argintregs[1], REG_PV, disp);
+
+                       disp = dseg_addaddress(cd, a);
+                       M_ALD(REG_PV, REG_PV, disp);
+                       M_JSR(REG_RA, REG_PV);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
+
+                       M_BEQZ(REG_RESULT, 0);
+                       codegen_addxcastrefs(cd, mcodeptr);
+
+                       var_to_reg_int(s1, src, REG_ITMP1);
+                       d = reg_of_var(rd, iptr->dst, s1);
+                       M_INTMOVE(s1, d);
+                       store_reg_to_var_int(iptr->dst, d);
+                       break;
+
                case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult            */
 
                                      /* op1:   0 == array, 1 == class                */
@@ -3476,31 +3505,33 @@ gen_method:
 
                        s2 = 6;
                        if (!super)
-                               s2 += (d == REG_ITMP2 ? 1 : 0) + (showdisassemble ? 1 : 0);
+                               s2 += (d == REG_ITMP2 ? 1 : 0) + (opt_showdisassemble ? 1 : 0);
 
                        /* calculate class instanceof code size */
 
                        s3 = 7;
                        if (!super)
-                               s3 += (showdisassemble ? 1 : 0);
+                               s3 += (opt_showdisassemble ? 1 : 0);
 
                        /* if class is not resolved, check which code to call */
 
                        if (!super) {
                                M_CLR(d);
-                               M_BEQZ(s1, 4 + (showdisassemble ? 1 : 0) + s2 + 1 + s3);
+                               M_BEQZ(s1, 4 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
+
+                               disp = dseg_adds4(cd, 0);                     /* super->flags */
 
                                codegen_addpatchref(cd, mcodeptr,
                                                                        PATCHER_checkcast_instanceof_flags,
-                                                                       (constant_classref *) iptr->target);
+                                                                       (constant_classref *) iptr->target, disp);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = dseg_adds4(cd, 0); /* super->flags */
-                               M_ILD(REG_ITMP3, REG_PV, a);
-                               a = dseg_adds4(cd, ACC_INTERFACE);
-                               M_ILD(REG_ITMP2, REG_PV, a);
+                               M_ILD(REG_ITMP3, REG_PV, disp);
+
+                               disp = dseg_adds4(cd, ACC_INTERFACE);
+                               M_ILD(REG_ITMP2, REG_PV, disp);
                                M_AND(REG_ITMP3, REG_ITMP2, REG_ITMP3);
                                M_BEQZ(REG_ITMP3, s2 + 1);
                        }
@@ -3520,9 +3551,9 @@ gen_method:
 
                                        codegen_addpatchref(cd, mcodeptr,
                                                                                PATCHER_checkcast_instanceof_interface,
-                                                                               (constant_classref *) iptr->target);
+                                                                               (constant_classref *) iptr->target, 0);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
                                }
 
@@ -3531,8 +3562,8 @@ gen_method:
                                M_LDA(REG_ITMP3, REG_ITMP3, -superindex);
                                M_BLEZ(REG_ITMP3, 2);
                                M_ALD(REG_ITMP1, REG_ITMP1,
-                                         OFFSET(vftbl_t, interfacetable[0]) -
-                                         superindex * sizeof(methodptr*));
+                                         (s4) (OFFSET(vftbl_t, interfacetable[0]) -
+                                                       superindex * sizeof(methodptr*)));
                                M_CMPULT(REG_ZERO, REG_ITMP1, d);      /* REG_ITMP1 != 0  */
 
                                if (!super)
@@ -3542,6 +3573,8 @@ gen_method:
                        /* class instanceof code */
 
                        if (!super || !(super->flags & ACC_INTERFACE)) {
+                               disp = dseg_addaddress(cd, supervftbl);
+
                                if (super) {
                                        M_CLR(d);
                                        M_BEQZ(s1, s3);
@@ -3549,15 +3582,15 @@ gen_method:
                                } else {
                                        codegen_addpatchref(cd, mcodeptr,
                                                                                PATCHER_checkcast_instanceof_class,
-                                                                               (constant_classref *) iptr->target);
+                                                                               (constant_classref *) iptr->target,
+                                                                               disp);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
                                }
 
                                M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
-                               a = dseg_addaddress(cd, supervftbl);
-                               M_ALD(REG_ITMP2, REG_PV, a);
+                               M_ALD(REG_ITMP2, REG_PV, disp);
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
                                codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
@@ -3574,20 +3607,6 @@ gen_method:
                        }
                        break;
 
-
-               case ICMD_CHECKASIZE:  /* ..., size ==> ..., size                     */
-
-                       var_to_reg_int(s1, src, REG_ITMP1);
-                       M_BLTZ(s1, 0);
-                       codegen_addxcheckarefs(cd, mcodeptr);
-                       break;
-
-               case ICMD_CHECKEXCEPTION:    /* ... ==> ...                           */
-
-                       M_BEQZ(REG_RESULT, 0);
-                       codegen_addxexceptionrefs(cd, mcodeptr);
-                       break;
-
                case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref  */
                                      /* op1 = dimension, val.a = array descriptor    */
 
@@ -3596,60 +3615,56 @@ gen_method:
                        MCODECHECK((iptr->op1 << 1) + 64);
 
                        for (s1 = iptr->op1; --s1 >= 0; src = src->prev) {
-                               var_to_reg_int(s2, src, REG_ITMP1);
-                               M_BLTZ(s2, 0);
-                               codegen_addxcheckarefs(cd, mcodeptr);
-
                                /* copy SAVEDVAR sizes to stack */
 
                                if (src->varkind != ARGVAR) {
+                                       var_to_reg_int(s2, src, REG_ITMP1);
                                        M_LST(s2, REG_SP, s1 * 8);
                                }
                        }
 
+                       /* a0 = dimension count */
+
+                       ICONST(rd->argintregs[0], iptr->op1);
+
                        /* is patcher function set? */
 
                        if (iptr->target) {
+                               disp = dseg_addaddress(cd, 0);
+
                                codegen_addpatchref(cd, mcodeptr,
-                                                                       (functionptr) iptr->target, iptr->val.a);
+                                                                       (functionptr) iptr->target, iptr->val.a,
+                                                                       disp);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = 0;
-
                        } else {
-                               a = (ptrint) iptr->val.a;
+                               disp = dseg_addaddress(cd, iptr->val.a);
                        }
 
-                       /* a0 = dimension count */
-
-                       ICONST(rd->argintregs[0], iptr->op1);
-
                        /* a1 = arraydescriptor */
 
-                       a = dseg_addaddress(cd, a);
-                       M_ALD(rd->argintregs[1], REG_PV, a);
+                       M_ALD(rd->argintregs[1], REG_PV, disp);
 
                        /* a2 = pointer to dimensions = stack pointer */
 
                        M_INTMOVE(REG_SP, rd->argintregs[2]);
 
-                       a = dseg_addaddress(cd, (void *) BUILTIN_multianewarray);
-                       M_ALD(REG_PV, REG_PV, a);
+                       disp = dseg_addaddress(cd, (void *) BUILTIN_multianewarray);
+                       M_ALD(REG_PV, REG_PV, disp);
                        M_JSR(REG_RA, REG_PV);
-                       s1 = (s4) ((u1 *) mcodeptr - cd->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);
-                       }
-                       s1 = reg_of_var(rd, iptr->dst, REG_RESULT);
-                       M_INTMOVE(REG_RESULT, s1);
-                       store_reg_to_var_int(iptr->dst, s1);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
+
+                       /* check for exception before result assignment */
+
+                       M_BEQZ(REG_RESULT, 0);
+                       codegen_addxexceptionrefs(cd, mcodeptr);
+
+                       d = reg_of_var(rd, iptr->dst, REG_RESULT);
+                       M_INTMOVE(REG_RESULT, d);
+                       store_reg_to_var_int(iptr->dst, d);
                        break;
 
                default:
@@ -3698,50 +3713,127 @@ gen_method:
        codegen_createlinenumbertable(cd);
 
        {
-       /* generate bound check stubs */
 
        s4 *xcodeptr = NULL;
        branchref *bref;
 
+       /* generate ArithmeticException stubs */
+
+       for (bref = cd->xdivrefs; bref != NULL; bref = bref->next) {
+               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+                       gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
+                                                         bref->branchpos,
+                                                         (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
+                       continue;
+               }
+
+               gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
+                                 bref->branchpos,
+                                                 (u1 *) mcodeptr - cd->mcodebase);
+
+               MCODECHECK(16);
+
+               M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
+
+               if (xcodeptr != NULL) {
+                       disp = xcodeptr - mcodeptr - 1;
+                       M_BR(disp);
+
+               } else {
+                       xcodeptr = mcodeptr;
+
+                       M_MOV(REG_PV, rd->argintregs[0]);
+                       M_MOV(REG_SP, rd->argintregs[1]);
+                       M_ALD(rd->argintregs[2],
+                                 REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
+                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+
+                       M_LDA(REG_SP, REG_SP, -1 * 8);
+                       M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+
+                       disp = dseg_addaddress(cd, stacktrace_inline_arithmeticexception);
+                       M_ALD(REG_PV, REG_PV, disp);
+                       M_JSR(REG_RA, REG_PV);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
+
+                       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+
+                       M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LDA(REG_SP, REG_SP, 1 * 8);
+
+                       disp = dseg_addaddress(cd, asm_handle_exception);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_JMP(REG_ZERO, REG_ITMP3);
+               }
+       }
+
+       /* generate ArrayIndexOutOfBoundsException stubs */
+
+       xcodeptr = NULL;
+
        for (bref = cd->xboundrefs; bref != NULL; bref = bref->next) {
                gen_resolvebranch((u1*) cd->mcodebase + bref->branchpos, 
                                  bref->branchpos,
                                                  (u1*) mcodeptr - cd->mcodebase);
 
-               MCODECHECK(8);
+               MCODECHECK(18);
 
                /* move index register into REG_ITMP1 */
+
                M_MOV(bref->reg, REG_ITMP1);
                M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
 
                if (xcodeptr != NULL) {
-                       M_BR(xcodeptr - mcodeptr - 1);
+                       disp = xcodeptr - mcodeptr - 1;
+                       M_BR(disp);
 
                } else {
                        xcodeptr = mcodeptr;
 
-                       a = dseg_addaddress(cd, asm_throw_and_handle_arrayindexoutofbounds_exception);
-                       M_ALD(REG_PV, REG_PV, a);
+                       M_MOV(REG_PV, rd->argintregs[0]);
+                       M_MOV(REG_SP, rd->argintregs[1]);
+
+                       if (m->isleafmethod)
+                               M_MOV(REG_RA, rd->argintregs[2]);
+                       else
+                               M_ALD(rd->argintregs[2],
+                                         REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
+
+                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+                       M_MOV(REG_ITMP1, rd->argintregs[4]);
+
+                       M_LDA(REG_SP, REG_SP, -2 * 8);
+                       M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
 
+                       if (m->isleafmethod)
+                               M_AST(REG_RA, REG_SP, 1 * 8);
+
+                       disp = dseg_addaddress(cd, stacktrace_inline_arrayindexoutofboundsexception);
+                       M_ALD(REG_PV, REG_PV, disp);
                        M_JSR(REG_RA, REG_PV);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
 
-                       /* recompute pv */
-                       s1 = (s4) ((u1 *) mcodeptr - cd->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);
+
+                       if (m->isleafmethod)
+                               M_ALD(REG_RA, REG_SP, 1 * 8);
+
+                       M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LDA(REG_SP, REG_SP, 2 * 8);
+
+                       disp = dseg_addaddress(cd, asm_handle_exception);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_JMP(REG_ZERO, REG_ITMP3);
                }
        }
 
-       /* generate negative array size check stubs */
+       /* generate ArrayStoreException stubs */
 
        xcodeptr = NULL;
        
-       for (bref = cd->xcheckarefs; bref != NULL; bref = bref->next) {
+       for (bref = cd->xstorerefs; bref != NULL; bref = bref->next) {
                if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
                        gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
                                                          bref->branchpos,
@@ -3753,37 +3845,44 @@ gen_method:
                                  bref->branchpos,
                                                  (u1 *) mcodeptr - cd->mcodebase);
 
-               MCODECHECK(8);
+               MCODECHECK(16);
 
                M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
 
                if (xcodeptr != NULL) {
-                       M_BR(xcodeptr - mcodeptr - 1);
+                       disp = xcodeptr - mcodeptr - 1;
+                       M_BR(disp);
 
                } else {
                        xcodeptr = mcodeptr;
 
-                       a = dseg_addaddress(cd, string_java_lang_NegativeArraySizeException);
-                       M_ALD(REG_ITMP1_XPTR,REG_PV,a);
+                       M_MOV(REG_PV, rd->argintregs[0]);
+                       M_MOV(REG_SP, rd->argintregs[1]);
+                       M_ALD(rd->argintregs[2],
+                                 REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
+                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
 
-                       a = dseg_addaddress(cd, asm_throw_and_handle_nat_exception);
-                       M_ALD(REG_PV, REG_PV, a);
+                       M_LDA(REG_SP, REG_SP, -1 * 8);
+                       M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
 
+                       disp = dseg_addaddress(cd, stacktrace_inline_arraystoreexception);
+                       M_ALD(REG_PV, REG_PV, disp);
                        M_JSR(REG_RA, REG_PV);
-               
-                       /* recompute pv */
-                       s1 = (s4) ((u1 *) mcodeptr - cd->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);
-                       }
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
+
+                       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+
+                       M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LDA(REG_SP, REG_SP, 1 * 8);
+
+                       disp = dseg_addaddress(cd, asm_handle_exception);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_JMP(REG_ZERO, REG_ITMP3);
                }
        }
 
-       /* generate cast check stubs */
+       /* generate ClassCastException stubs */
 
        xcodeptr = NULL;
        
@@ -3799,43 +3898,61 @@ gen_method:
                                  bref->branchpos,
                                                  (u1 *) mcodeptr - cd->mcodebase);
 
-               MCODECHECK(8);
+               MCODECHECK(18);
 
                M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
 
                if (xcodeptr != NULL) {
-                       M_BR(xcodeptr - mcodeptr - 1);
+                       disp = xcodeptr - mcodeptr - 1;
+                       M_BR(disp);
 
                } else {
                        xcodeptr = mcodeptr;
 
-                       a = dseg_addaddress(cd, string_java_lang_ClassCastException);
-                       M_ALD(REG_ITMP1_XPTR,REG_PV,a);
+                       M_MOV(REG_PV, rd->argintregs[0]);
+                       M_MOV(REG_SP, rd->argintregs[1]);
+
+                       if (m->isleafmethod)
+                               M_MOV(REG_RA, rd->argintregs[2]);
+                       else
+                               M_ALD(rd->argintregs[2],
+                                         REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
+
+                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+
+                       M_LDA(REG_SP, REG_SP, -2 * 8);
+                       M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
 
-                       a = dseg_addaddress(cd, asm_throw_and_handle_nat_exception);
-                       M_ALD(REG_PV, REG_PV, a);
+                       if (m->isleafmethod)
+                               M_AST(REG_RA, REG_SP, 1 * 8);
 
+                       disp = dseg_addaddress(cd, stacktrace_inline_classcastexception);
+                       M_ALD(REG_PV, REG_PV, disp);
                        M_JSR(REG_RA, REG_PV);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
 
-                       /* recompute pv */
-                       s1 = (s4) ((u1 *) mcodeptr - cd->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);
+
+                       if (m->isleafmethod)
+                               M_ALD(REG_RA, REG_SP, 1 * 8);
+
+                       M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LDA(REG_SP, REG_SP, 2 * 8);
+
+                       disp = dseg_addaddress(cd, asm_handle_exception);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_JMP(REG_ZERO, REG_ITMP3);
                }
        }
 
-       /* generate exception check stubs */
+       /* generate NullPointerException stubs */
 
        xcodeptr = NULL;
 
-       for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) {
+       for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) {
                if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
-                       gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
+                       gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
                                                          bref->branchpos,
                                                          (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
                        continue;
@@ -3845,71 +3962,61 @@ gen_method:
                                  bref->branchpos,
                                                  (u1 *) mcodeptr - cd->mcodebase);
 
-               MCODECHECK(8);
+               MCODECHECK(18);
 
                M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
 
                if (xcodeptr != NULL) {
-                       M_BR(xcodeptr - mcodeptr - 1);
+                       disp = xcodeptr - mcodeptr - 1;
+                       M_BR(disp);
 
                } else {
                        xcodeptr = mcodeptr;
 
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
-                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_MOV(REG_PV, rd->argintregs[0]);
+                       M_MOV(REG_SP, rd->argintregs[1]);
 
-                       a = dseg_addaddress(cd, &builtin_get_exceptionptrptr);
-                       M_ALD(REG_PV, REG_PV, a);
-                       M_JSR(REG_RA, REG_PV);
+                       if (m->isleafmethod)
+                               M_MOV(REG_RA, rd->argintregs[2]);
+                       else
+                               M_ALD(rd->argintregs[2],
+                                         REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
 
-                       /* recompute pv */
-                       s1 = (s4) ((u1 *) mcodeptr - cd->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_ITMP2_XPC, rd->argintregs[3]);
 
-                       M_ALD(REG_ITMP1_XPTR, REG_RESULT, 0);
-                       M_AST(REG_ZERO, REG_RESULT, 0);
+                       M_LDA(REG_SP, REG_SP, -2 * 8);
+                       M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
 
-                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
-                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
-#else
-                       a = dseg_addaddress(cd, &_exceptionptr);
-                       M_ALD(REG_ITMP3, REG_PV, a);
-                       M_ALD(REG_ITMP1_XPTR, REG_ITMP3, 0);
-                       M_AST(REG_ZERO, REG_ITMP3, 0);
-#endif
+                       if (m->isleafmethod)
+                               M_AST(REG_RA, REG_SP, 1 * 8);
 
-                       a = dseg_addaddress(cd, asm_refillin_and_handle_exception);
-                       M_ALD(REG_PV, REG_PV, a);
+                       disp = dseg_addaddress(cd, stacktrace_inline_nullpointerexception);
+                       M_ALD(REG_PV, REG_PV, disp);
+                       M_JSR(REG_RA, REG_PV);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
 
-                       M_JMP(REG_RA, REG_PV);
-               
-                       /* recompute pv */
-                       s1 = (s4) ((u1 *) mcodeptr - cd->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);
 
+                       if (m->isleafmethod)
+                               M_ALD(REG_RA, REG_SP, 1 * 8);
+
+                       M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LDA(REG_SP, REG_SP, 2 * 8);
+
+                       disp = dseg_addaddress(cd, asm_handle_exception);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_JMP(REG_ZERO, REG_ITMP3);
                }
        }
 
-       /* generate null pointer check stubs */
+       /* generate exception check stubs */
 
        xcodeptr = NULL;
 
-       for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) {
+       for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) {
                if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
-                       gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
+                       gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
                                                          bref->branchpos,
                                                          (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
                        continue;
@@ -3919,37 +4026,44 @@ gen_method:
                                  bref->branchpos,
                                                  (u1 *) mcodeptr - cd->mcodebase);
 
-               MCODECHECK(8);
+               MCODECHECK(16);
 
                M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
 
                if (xcodeptr != NULL) {
-                       M_BR(xcodeptr - mcodeptr - 1);
+                       disp = xcodeptr - mcodeptr - 1;
+                       M_BR(disp);
 
                } else {
                        xcodeptr = mcodeptr;
 
-                       a = dseg_addaddress(cd, string_java_lang_NullPointerException);
-                       M_ALD(REG_ITMP1_XPTR,REG_PV,a);
+                       M_MOV(REG_PV, rd->argintregs[0]);
+                       M_MOV(REG_SP, rd->argintregs[1]);
+                       M_ALD(rd->argintregs[2],
+                                 REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
+                       M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
 
-                       a = dseg_addaddress(cd, asm_throw_and_handle_nat_exception);
-                       M_ALD(REG_PV, REG_PV, a);
+                       M_LDA(REG_SP, REG_SP, -1 * 8);
+                       M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
 
+                       disp = dseg_addaddress(cd, stacktrace_inline_fillInStackTrace);
+                       M_ALD(REG_PV, REG_PV, disp);
                        M_JSR(REG_RA, REG_PV);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
 
-                       /* recompute pv */
-                       s1 = (s4) ((u1 *) mcodeptr - cd->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_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_LDA(REG_SP, REG_SP, 1 * 8);
+
+                       disp = dseg_addaddress(cd, asm_handle_exception);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_JMP(REG_ZERO, REG_ITMP3);
                }
        }
 
-       /* generate put/getstatic stub call code */
+       /* generate patcher stub call code */
 
        {
                patchref *pref;
@@ -3959,7 +4073,7 @@ gen_method:
                for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
                        /* check code segment size */
 
-                       MCODECHECK(13 + 4 + 1);
+                       MCODECHECK(30);
 
                        /* Get machine code which is patched back in later. The call is   */
                        /* 1 instruction word long.                                       */
@@ -3979,11 +4093,11 @@ gen_method:
 
                        /* create stack frame */
 
-                       M_LSUB_IMM(REG_SP, 5 * 8, REG_SP);
+                       M_LSUB_IMM(REG_SP, 6 * 8, REG_SP);
 
                        /* move return address onto stack */
 
-                       M_AST(REG_ITMP3, REG_SP, 4 * 8);
+                       M_AST(REG_ITMP3, REG_SP, 5 * 8);
 
                        /* move pointer to java_objectheader onto stack */
 
@@ -3991,59 +4105,40 @@ gen_method:
                        /* create a virtual java_objectheader */
 
                        (void) dseg_addaddress(cd, get_dummyLR());          /* monitorPtr */
-                       a = dseg_addaddress(cd, NULL);                      /* vftbl      */
+                       disp = dseg_addaddress(cd, NULL);                   /* vftbl      */
 
-                       if (a >= -32768) {
-                               M_LDA(REG_ITMP3, REG_PV, a);
-                       } else {
-                               M_LDAH(REG_ITMP3, REG_PV, (a >> 16) & 0x0000ffff);
-                               M_LDA(REG_ITMP3, REG_ITMP3, a & 0x0000ffff);
-                       }
-                       M_AST(REG_ITMP3, REG_SP, 3 * 8);
+                       M_LDA(REG_ITMP3, REG_PV, disp);
+                       M_AST(REG_ITMP3, REG_SP, 4 * 8);
 #else
-                       M_AST(REG_ZERO, REG_SP, 3 * 8);
+                       M_AST(REG_ZERO, REG_SP, 4 * 8);
 #endif
 
                        /* move machine code onto stack */
 
-                       a = dseg_adds4(cd, mcode);
-                       if (a >= -32768) {
-                               M_ILD(REG_ITMP3, REG_PV, a);
-                       } else {
-                               M_LDAH(REG_ITMP3, REG_PV, (a >> 16) & 0x0000ffff);
-                               M_ILD(REG_ITMP3, REG_ITMP3, a & 0x0000ffff);
-                       }
-                       M_IST(REG_ITMP3, REG_SP, 2 * 8);
+                       disp = dseg_adds4(cd, mcode);
+                       M_ILD(REG_ITMP3, REG_PV, disp);
+                       M_IST(REG_ITMP3, REG_SP, 3 * 8);
 
                        /* move class/method/field reference onto stack */
 
-                       a = dseg_addaddress(cd, pref->ref);
-                       if (a >= -32768) {
-                               M_ALD(REG_ITMP3, REG_PV, a);
-                       } else {
-                               M_LDAH(REG_ITMP3, REG_PV, (a >> 16) & 0x0000ffff);
-                               M_ALD(REG_ITMP3, REG_ITMP3, a & 0x0000ffff);
-                       }
-                       M_AST(REG_ITMP3, REG_SP, 1 * 8);
+                       disp = dseg_addaddress(cd, pref->ref);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_AST(REG_ITMP3, REG_SP, 2 * 8);
+
+                       /* move data segment displacement onto stack */
+
+                       disp = dseg_adds4(cd, pref->disp);
+                       M_ILD(REG_ITMP3, REG_PV, disp);
+                       M_IST(REG_ITMP3, REG_SP, 1 * 8);
 
                        /* move patcher function pointer onto stack */
 
-                       a = dseg_addaddress(cd, pref->patcher);
-                       if (a >= -32768) {
-                               M_ALD(REG_ITMP3, REG_PV, a);
-                       } else {
-                               M_LDAH(REG_ITMP3, REG_PV, (a >> 16) & 0x0000ffff);
-                               M_ALD(REG_ITMP3, REG_ITMP3, a & 0x0000ffff);
-                       }
+                       disp = dseg_addaddress(cd, pref->patcher);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
                        M_AST(REG_ITMP3, REG_SP, 0 * 8);
 
-                       a = dseg_addaddress(cd, asm_wrapper_patcher);
-                       if (a >= -32768) {
-                               M_ALD(REG_ITMP3, REG_PV, a);
-                       } else {
-                               M_LDAH(REG_ITMP3, REG_PV, (a >> 16) & 0x0000ffff);
-                               M_ALD(REG_ITMP3, REG_ITMP3, a & 0x0000ffff);
-                       }
+                       disp = dseg_addaddress(cd, asm_wrapper_patcher);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
                        M_JMP(REG_ZERO, REG_ITMP3);
                }
        }
@@ -4089,51 +4184,28 @@ functionptr createcompilerstub(methodinfo *m)
 *******************************************************************************/
 
 functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
-                                                        registerdata *rd)
+                                                        registerdata *rd, methoddesc *nmd)
 {
        s4         *mcodeptr;               /* code generation pointer            */
        s4          stackframesize;         /* size of stackframe if needed       */
-       s4          disp;
        methoddesc *md;
-       methoddesc *nmd;
        s4          nativeparams;
        s4          i, j;                   /* count variables                    */
        s4          t;
-       s4          s1, s2, off;
+       s4          s1, s2, disp;
+       s4          funcdisp;               /* displacement of the function       */
 
        /* initialize variables */
 
-       nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
-
-
-       /* create new method descriptor with additional native parameters */
-
        md = m->parseddesc;
-       
-       nmd = (methoddesc *) DMNEW(u1, sizeof(methoddesc) - sizeof(typedesc) +
-                                                          md->paramcount * sizeof(typedesc) +
-                                                          nativeparams * sizeof(typedesc));
-
-       nmd->paramcount = md->paramcount + nativeparams;
-
-       nmd->params = DMNEW(paramdesc, nmd->paramcount);
-
-       nmd->paramtypes[0].type = TYPE_ADR; /* add environment pointer            */
-
-       if (m->flags & ACC_STATIC)
-               nmd->paramtypes[1].type = TYPE_ADR; /* add class pointer              */
-
-       MCOPY(nmd->paramtypes + nativeparams, md->paramtypes, typedesc,
-                 md->paramcount);
-
-       md_param_alloc(nmd);
+       nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
 
 
        /* calculate stack frame size */
 
        stackframesize =
                1 +                             /* return address                     */
-               6 +                             /* dynamic stack info                 */
+               sizeof(stackframeinfo) / SIZEOF_VOID_P +
                1 +                             /* methodinfo for call trace          */
                (md->paramcount > INT_ARG_CNT ? INT_ARG_CNT : md->paramcount) +
                nmd->memuse;
@@ -4160,26 +4232,20 @@ functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
        /* generate stub code */
 
        M_LDA(REG_SP, REG_SP, -stackframesize * 8);
-       M_AST(REG_RA, REG_SP, (stackframesize - 1) * 8);
-
+       M_AST(REG_RA, REG_SP, stackframesize * 8 - SIZEOF_VOID_P);
 
-       /* if function is static, check for initialized */
-
-       if ((m->flags & ACC_STATIC) && !m->class->initialized) {
-               codegen_addpatchref(cd, mcodeptr, PATCHER_clinit, m->class);
-
-               if (showdisassemble)
-                       M_NOP;
-       }
 
        /* call trace function */
 
        if (runverbose) {
                /* save integer argument registers */
 
-               for (i = 0, j = 1; i < md->paramcount && i < INT_ARG_CNT; i++)
-                       if (IS_INT_LNG_TYPE(md->paramtypes[i].type))
-                               M_LST(rd->argintregs[i], REG_SP, j++ * 8);
+               for (i = 0, j = 1; i < md->paramcount && i < INT_ARG_CNT; i++) {
+                       if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
+                               M_LST(rd->argintregs[i], REG_SP, j * 8);
+                               j++;
+                       }
+               }
 
                /* save and copy float arguments into integer registers */
 
@@ -4198,18 +4264,21 @@ functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
                        }
                }
 
-               off = dseg_addaddress(cd, m);
-               M_ALD(REG_ITMP1, REG_PV, off);
+               disp = dseg_addaddress(cd, m);
+               M_ALD(REG_ITMP1, REG_PV, disp);
                M_AST(REG_ITMP1, REG_SP, 0 * 8);
-               off = dseg_addaddress(cd, builtin_trace_args);
-               M_ALD(REG_PV, REG_PV, off);
+               disp = dseg_addaddress(cd, builtin_trace_args);
+               M_ALD(REG_PV, REG_PV, disp);
                M_JSR(REG_RA, REG_PV);
                disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
                M_LDA(REG_PV, REG_RA, -disp);
 
-               for (i = 0, j = 1; i < md->paramcount && i < INT_ARG_CNT; i++)
-                       if (IS_INT_LNG_TYPE(md->paramtypes[i].type))
-                               M_LLD(rd->argintregs[i], REG_SP, j++ * 8);
+               for (i = 0, j = 1; i < md->paramcount && i < INT_ARG_CNT; i++) {
+                       if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
+                               M_LLD(rd->argintregs[i], REG_SP, j * 8);
+                               j++;
+                       }
+               }
 
                for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
                        t = md->paramtypes[i].type;
@@ -4225,45 +4294,65 @@ functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
                }
        }
 
+       /* get function address (this must happen before the stackframeinfo) */
+
+       funcdisp = dseg_addaddress(cd, f);
+
+#if !defined(ENABLE_STATICVM)
+       if (f == NULL) {
+               codegen_addpatchref(cd, mcodeptr, PATCHER_resolve_native, m, funcdisp);
+
+               if (opt_showdisassemble)
+                       M_NOP;
+       }
+#endif
+
 
        /* save integer and float argument registers */
 
-       for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++)
-               if (IS_INT_LNG_TYPE(md->paramtypes[i].type))
-                       M_LST(rd->argintregs[i], REG_SP, j++ * 8);
+       for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++) {
+               if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
+                       M_LST(rd->argintregs[i], REG_SP, j * 8);
+                       j++;
+               }
+       }
 
-       for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++)
-               if (IS_FLT_DBL_TYPE(md->paramtypes[i].type))
-                       M_DST(rd->argfltregs[i], REG_SP, j++ * 8);
+       for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
+               if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
+                       M_DST(rd->argfltregs[i], REG_SP, j * 8);
+                       j++;
+               }
+       }
 
-       /* create native stack info */
+       /* create native stackframe info */
 
-       off = dseg_addaddress(cd, builtin_asm_get_stackframeinfo);
-       M_ALD(REG_PV, REG_PV, off);
+       M_AADD_IMM(REG_SP,
+                          stackframesize * 8 - SIZEOF_VOID_P - sizeof(stackframeinfo),
+                          rd->argintregs[0]);
+       M_MOV(REG_PV, rd->argintregs[1]);
+       M_AADD_IMM(REG_SP, stackframesize * 8, rd->argintregs[2]);
+       M_ALD(rd->argintregs[3], REG_SP, stackframesize * 8 - SIZEOF_VOID_P);
+       disp = dseg_addaddress(cd, stacktrace_create_native_stackframeinfo);
+       M_ALD(REG_PV, REG_PV, disp);
        M_JSR(REG_RA, REG_PV);
        disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
        M_LDA(REG_PV, REG_RA, -disp);
 
-       M_LST(REG_RESULT, REG_SP, (stackframesize - 5) * 8); /* save adress of pointer */
-       M_LLD(REG_ITMP2, REG_RESULT, 0); /* get pointer */
-       M_LST(REG_ITMP2, REG_SP, (stackframesize - 6) * 8); /* save old value */
-       M_LDA(REG_ITMP3, REG_SP, (stackframesize - 6) * 8); /* calculate new value */
-       M_LST(REG_ITMP3, REG_RESULT, 0); /* store new value */
-       off = dseg_addaddress(cd, m);
-       M_LLD(REG_ITMP2, REG_PV, off);
-       M_LST(REG_ITMP2, REG_SP, (stackframesize - 4) * 8);
-       M_LST(REG_ZERO, REG_SP, (stackframesize - 3) * 8);
-       M_LST(REG_ZERO, REG_SP, (stackframesize - 2) * 8);
-
        /* restore integer and float argument registers */
 
-       for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++)
-               if (IS_INT_LNG_TYPE(md->paramtypes[i].type))
-                       M_LLD(rd->argintregs[i], REG_SP, j++ * 8);
+       for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++) {
+               if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
+                       M_LLD(rd->argintregs[i], REG_SP, j * 8);
+                       j++;
+               }
+       }
 
-       for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++)
-               if (IS_FLT_DBL_TYPE(md->paramtypes[i].type))
-                       M_DLD(rd->argfltregs[i], REG_SP, j++ * 8);
+       for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
+               if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
+                       M_DLD(rd->argfltregs[i], REG_SP, j * 8);
+                       j++;
+               }
+       }
 
 
        /* copy or spill arguments to new locations */
@@ -4301,14 +4390,20 @@ functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
 
                                } else {
                                        s2 = nmd->params[j].regoff;
-                                       M_DST(s1, REG_SP, s2 * 8);
+                                       if (IS_2_WORD_TYPE(t))
+                                               M_DST(s1, REG_SP, s2 * 8);
+                                       else
+                                               M_FST(s1, REG_SP, s2 * 8);
                                }
 
                        } else {
                                s1 = md->params[i].regoff + stackframesize;
                                s2 = nmd->params[j].regoff;
                                M_DLD(REG_FTMP1, REG_SP, s1 * 8);
-                               M_DST(REG_FTMP1, REG_SP, s2 * 8);
+                               if (IS_2_WORD_TYPE(t))
+                                       M_DST(REG_FTMP1, REG_SP, s2 * 8);
+                               else
+                                       M_FST(REG_FTMP1, REG_SP, s2 * 8);
                        }
                }
        }
@@ -4316,95 +4411,83 @@ functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
        /* put class into second argument register */
 
        if (m->flags & ACC_STATIC) {
-               off = dseg_addaddress(cd, m->class);
-               M_ALD(rd->argintregs[1], REG_PV, off);
+               disp = dseg_addaddress(cd, m->class);
+               M_ALD(rd->argintregs[1], REG_PV, disp);
        }
 
        /* put env into first argument register */
 
-       off = dseg_addaddress(cd, &env);
-       M_ALD(rd->argintregs[0], REG_PV, off);
+       disp = dseg_addaddress(cd, &env);
+       M_ALD(rd->argintregs[0], REG_PV, disp);
 
        /* do the native function call */
 
-#if !defined(STATIC_CLASSPATH)
-       if (f == NULL) {
-               codegen_addpatchref(cd, mcodeptr, PATCHER_resolve_native, m);
-
-               if (showdisassemble)
-                       M_NOP;
-       }
-#endif
-
-       off = dseg_addaddress(cd, f);
-       M_ALD(REG_PV, REG_PV, off);         /* load adress of native method       */
+       M_ALD(REG_PV, REG_PV, funcdisp);
        M_JSR(REG_RA, REG_PV);              /* call native method                 */
        disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
        M_LDA(REG_PV, REG_RA, -disp);       /* recompute pv from ra               */
 
+       /* save return value */
 
-       /* remove native stack info */
+       if (IS_INT_LNG_TYPE(md->returntype.type))
+               M_LST(REG_RESULT, REG_SP, 0 * 8);
+       else
+               M_DST(REG_FRESULT, REG_SP, 0 * 8);
 
-       M_LLD(REG_ITMP3, REG_SP, (stackframesize - 5) * 8); /* get address of stacktrace helper pointer */
-       M_LLD(REG_ITMP1, REG_SP, (stackframesize - 6) * 8); /* get old value */
-       M_LST(REG_ITMP1, REG_ITMP3, 0); /* set old value */
+       /* remove native stackframe info */
 
+       M_AADD_IMM(REG_SP,
+                          stackframesize * 8 - SIZEOF_VOID_P - sizeof(stackframeinfo),
+                          rd->argintregs[0]);
+       disp = dseg_addaddress(cd, stacktrace_remove_stackframeinfo);
+       M_ALD(REG_PV, REG_PV, disp);
+       M_JSR(REG_RA, REG_PV);
+       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+       M_LDA(REG_PV, REG_RA, -disp);
 
        /* call finished trace */
 
        if (runverbose) {
-               M_LST(REG_RESULT, REG_SP, 0 * 8);
-               M_DST(REG_FRESULT, REG_SP, 1 * 8);
-
-               off = dseg_addaddress(cd, m);
-               M_ALD(rd->argintregs[0], REG_PV, off);
+               disp = dseg_addaddress(cd, m);
+               M_ALD(rd->argintregs[0], REG_PV, disp);
 
                M_MOV(REG_RESULT, rd->argintregs[1]);
                M_FMOV(REG_FRESULT, rd->argfltregs[2]);
                M_FMOV(REG_FRESULT, rd->argfltregs[3]);
 
-               off = dseg_addaddress(cd, builtin_displaymethodstop);
-               M_ALD(REG_PV, REG_PV, off);
+               disp = dseg_addaddress(cd, builtin_displaymethodstop);
+               M_ALD(REG_PV, REG_PV, disp);
                M_JSR(REG_RA, REG_PV);
                disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
                M_LDA(REG_PV, REG_RA, -disp);
-
-               M_LLD(REG_RESULT, REG_SP, 0 * 8);
-               M_DLD(REG_FRESULT, REG_SP, 1 * 8);
        }
 
-
        /* check for exception */
 
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-       if (IS_FLT_DBL_TYPE(md->returntype.type))
-               M_DST(REG_FRESULT, REG_SP, 0 * 8);
-       else
-               M_AST(REG_RESULT, REG_SP, 0 * 8);
-
-       off = dseg_addaddress(cd, builtin_get_exceptionptrptr);
-       M_ALD(REG_PV, REG_PV, off);
+       disp = dseg_addaddress(cd, builtin_get_exceptionptrptr);
+       M_ALD(REG_PV, REG_PV, disp);
        M_JSR(REG_RA, REG_PV);
        disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
        M_LDA(REG_PV, REG_RA, -disp);
        M_MOV(REG_RESULT, REG_ITMP3);
-
-       if (IS_FLT_DBL_TYPE(md->returntype.type))
-               M_DLD(REG_FRESULT, REG_SP, 0 * 8);
-       else
-               M_ALD(REG_RESULT, REG_SP, 0 * 8);
 #else
-       off = dseg_addaddress(cd, &_exceptionptr);
-       M_ALD(REG_ITMP3, REG_PV, off);      /* get address of exceptionptr        */
+       disp = dseg_addaddress(cd, &_exceptionptr);
+       M_ALD(REG_RESULT, REG_PV, disp);    /* get address of exceptionptr        */
 #endif
-
        M_ALD(REG_ITMP1, REG_ITMP3, 0);     /* load exception into reg. itmp1     */
+
+       /* restore return value */
+
+       if (IS_INT_LNG_TYPE(md->returntype.type))
+               M_LLD(REG_RESULT, REG_SP, 0 * 8);
+       else
+               M_DLD(REG_FRESULT, REG_SP, 0 * 8);
+
        M_BNEZ(REG_ITMP1, 3);               /* if no exception then return        */
 
        M_ALD(REG_RA, REG_SP, (stackframesize - 1) * 8); /* load return address   */
-
        M_LDA(REG_SP, REG_SP, stackframesize * 8);
-
        M_RET(REG_ZERO, REG_RA);            /* return to caller                   */
 
        /* handle exception */
@@ -4416,8 +4499,8 @@ functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
 
        M_LDA(REG_SP, REG_SP, stackframesize * 8);
 
-       off = dseg_addaddress(cd, asm_handle_nat_exception);
-       M_ALD(REG_ITMP3, REG_PV, off);      /* load asm exception handler address */
+       disp = dseg_addaddress(cd, asm_handle_nat_exception);
+       M_ALD(REG_ITMP3, REG_PV, disp);     /* load asm exception handler address */
        M_JMP(REG_ZERO, REG_ITMP3);         /* jump to asm exception handler      */
        
 
@@ -4451,11 +4534,11 @@ functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
 
                        /* create stack frame                                             */
 
-                       M_LSUB_IMM(REG_SP, 5 * 8, REG_SP);
+                       M_LSUB_IMM(REG_SP, 6 * 8, REG_SP);
 
                        /* move return address onto stack */
 
-                       M_AST(REG_ITMP3, REG_SP, 4 * 8);
+                       M_AST(REG_ITMP3, REG_SP, 5 * 8);
 
                        /* move pointer to java_objectheader onto stack */
 
@@ -4463,34 +4546,40 @@ functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
                        /* create a virtual java_objectheader */
 
                        (void) dseg_addaddress(cd, get_dummyLR());          /* monitorPtr */
-                       off = dseg_addaddress(cd, NULL);                    /* vftbl      */
+                       disp = dseg_addaddress(cd, NULL);                   /* vftbl      */
 
-                       M_LDA(REG_ITMP3, REG_PV, off);
-                       M_AST(REG_ITMP3, REG_SP, 3 * 8);
+                       M_LDA(REG_ITMP3, REG_PV, disp);
+                       M_AST(REG_ITMP3, REG_SP, 4 * 8);
 #else
-                       M_AST(REG_ZERO, REG_SP, 3 * 8);
+                       M_AST(REG_ZERO, REG_SP, 4 * 8);
 #endif
 
                        /* move machine code onto stack */
 
-                       off = dseg_adds4(cd, mcode);
-                       M_ILD(REG_ITMP3, REG_PV, off);
-                       M_IST(REG_ITMP3, REG_SP, 2 * 8);
+                       disp = dseg_adds4(cd, mcode);
+                       M_ILD(REG_ITMP3, REG_PV, disp);
+                       M_IST(REG_ITMP3, REG_SP, 3 * 8);
 
                        /* move class/method/field reference onto stack */
 
-                       off = dseg_addaddress(cd, pref->ref);
-                       M_ALD(REG_ITMP3, REG_PV, off);
-                       M_AST(REG_ITMP3, REG_SP, 1 * 8);
+                       disp = dseg_addaddress(cd, pref->ref);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_AST(REG_ITMP3, REG_SP, 2 * 8);
+
+                       /* move data segment displacement onto stack */
+
+                       disp = dseg_adds4(cd, pref->disp);
+                       M_ILD(REG_ITMP3, REG_PV, disp);
+                       M_IST(REG_ITMP3, REG_SP, 1 * 8);
 
                        /* move patcher function pointer onto stack */
 
-                       off = dseg_addaddress(cd, pref->patcher);
-                       M_ALD(REG_ITMP3, REG_PV, off);
+                       disp = dseg_addaddress(cd, pref->patcher);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
                        M_AST(REG_ITMP3, REG_SP, 0 * 8);
 
-                       off = dseg_addaddress(cd, asm_wrapper_patcher);
-                       M_ALD(REG_ITMP3, REG_PV, off);
+                       disp = dseg_addaddress(cd, asm_wrapper_patcher);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
                        M_JMP(REG_ZERO, REG_ITMP3);
                }
        }