* Removed all Id tags.
[cacao.git] / src / vm / jit / s390 / codegen.c
index 02af44c6324501a11ffb2e2415fbd1e5195c98b4..c9b4cfbad66c06c2f300337c72fa86741c59ee43 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: codegen.c 8268 2007-08-07 13:24:43Z twisti $
-
 */
 
 
@@ -34,6 +32,7 @@
 #include <stdio.h>
 
 #include "native/jni.h"
+#include "native/localref.h"
 #include "native/native.h"
 
 #include "mm/memory.h"
 #include "vm/stringlocal.h"
 #include "vm/vm.h"
 
-#define OOPS() assert(0);
-#define SUPPORT_HERCULES 1
+/* DO__LOG generates a call to do__log. No registers are destroyed,
+ * so you may use it anywhere. regs is an array containing all general
+ * purpose registers.
+ */
 
-void panic() { }
+static void do__log(u4 *regs) {
+       /* insert stuff here */
+}
+
+#define DO__LOG \
+       N_AHI(REG_SP, -200); \
+       N_STM(R0, R15, 96, REG_SP); \
+       M_ALD_DSEG(R14, dseg_add_address(cd, &do__log)); \
+       N_LA(R2, 96, RN, REG_SP); \
+       N_BASR(R14, R14); \
+       N_LM(R0, R15, 96, REG_SP); \
+       N_AHI(REG_SP, 200);
+
+#define SUPPORT_HERCULES 1
 
 /* codegen *********************************************************************
 
@@ -83,6 +97,30 @@ void panic() { }
 
 *******************************************************************************/
 
+/*
+
+Layout of stackframe:
+
+Meaning                                Offset
+===============================================================================
+return_address                         (stackframesize - 1) * 8 
+saved_int_reg[INT_SAV_CNT - 1]         (stackframseize - 2) * 8
+...
+saved_int_reg[rd->savintreguse]  
+saved_flt_reg[FLT_SAV_CNT - 1]
+...
+saved_flt_reg[rd->savfltreguse]        (stackframesize - 1 - savedregs_num) * 8
+
+return_value_tmp                       (rd->memuse + 1) * 8
+monitorenter_argument                  (rd->memuse) * 8 
+???
+local[rd->memuse - 1]                  (rd->memuse - 1) * 8
+....
+local[2]                               2 * 8
+local[1]                               1 * 8
+local[0]                               0 * 8
+
+*/
 
 bool codegen_emit(jitdata *jd)
 {
@@ -134,7 +172,7 @@ bool codegen_emit(jitdata *jd)
        /* space to save used callee saved registers */
 
        savedregs_num += (INT_SAV_CNT - rd->savintreguse);
-       savedregs_num += (FLT_SAV_CNT - rd->savfltreguse) * 2;
+       savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);
 
        cd->stackframesize = rd->memuse + savedregs_num + 1  /* space to save RA */;
 
@@ -149,12 +187,9 @@ bool codegen_emit(jitdata *jd)
           since both values reside in R2. */
 
        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
-               /* reserve 2 slots for long/double return values for monitorexit */
-
-               if (IS_2_WORD_TYPE(m->parseddesc->returntype.type))
-                       cd->stackframesize += 3;
-               else
-                       cd->stackframesize += 2;
+               /* 1 slot space to save argument of monitor_enter */
+               /* 1 slot to temporary store return value before monitor_exit */
+               cd->stackframesize += 2;
        }
 #endif
 
@@ -164,12 +199,12 @@ bool codegen_emit(jitdata *jd)
 
        if (!jd->isleafmethod || opt_verbosecall )
                /* TODO really 16 bytes ? */
-               cd->stackframesize = (cd->stackframesize + 3) & ~3;
+               cd->stackframesize = (cd->stackframesize + 2) & ~2;
 
        /* create method header */
 
        (void) dseg_add_unique_address(cd, code);              /* CodeinfoPointer */
-       (void) dseg_add_unique_s4(cd, cd->stackframesize * 4); /* FrameSize       */
+       (void) dseg_add_unique_s4(cd, cd->stackframesize * 8); /* FrameSize       */
 
 #if defined(ENABLE_THREADS)
        /* IsSync contains the offset relative to the stack pointer for the
@@ -179,10 +214,9 @@ bool codegen_emit(jitdata *jd)
        */
 
        if (checksync && (m->flags & ACC_SYNCHRONIZED))
-               (void) dseg_add_unique_s4(cd, (rd->memuse + 1) * 4); /* IsSync        */
+               (void) dseg_add_unique_s4(cd, (rd->memuse + 1) * 8); /* IsSync        */
        else
 #endif
-
                (void) dseg_add_unique_s4(cd, 0);                    /* IsSync          */
 
        (void) dseg_add_unique_s4(cd, jd->isleafmethod);               /* IsLeaf  */
@@ -223,18 +257,18 @@ bool codegen_emit(jitdata *jd)
        /* create stack frame (if necessary) */
 
        if (cd->stackframesize)
-               M_ASUB_IMM(cd->stackframesize * 4, REG_SP);
+               M_ASUB_IMM(cd->stackframesize * 8, REG_SP);
 
        /* save used callee saved registers and return address */
 
        p = cd->stackframesize;
-       p--; M_AST(REG_RA, REG_SP, p * 4);
+       p--; M_AST(REG_RA, REG_SP, p * 8);
 
        for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
-               p--; M_IST(rd->savintregs[i], REG_SP, p * 4);
+               p--; M_IST(rd->savintregs[i], REG_SP, p * 8);
        }
        for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
-               p -= 2; M_DST(rd->savfltregs[i], REG_SP, p * 4);
+               p--; M_DST(rd->savfltregs[i], REG_SP, p * 8);
        }
 
        /* take arguments out of register or stack frame */
@@ -246,8 +280,9 @@ bool codegen_emit(jitdata *jd)
                varindex = jd->local_map[l * 5 + t];
 
                l++;
-               if (IS_2_WORD_TYPE(t))    /* increment local counter for 2 word types */
-                       l++;
+
+               if (IS_2_WORD_TYPE(t))
+                       l++;
 
                if (varindex == UNUSED)
                        continue;
@@ -255,6 +290,7 @@ bool codegen_emit(jitdata *jd)
                var = VAR(varindex);
 
                s1 = md->params[p].regoff;
+
                if (IS_INT_LNG_TYPE(t)) {                    /* integer args          */
                        if (IS_2_WORD_TYPE(t)) {
                                s2 = PACK_REGS(
@@ -266,31 +302,28 @@ bool codegen_emit(jitdata *jd)
                        }
                        if (!md->params[p].inmemory) {           /* register arguments    */
                                if (!IS_INMEMORY(var->flags)) {      /* reg arg -> register   */
-                                       if (IS_2_WORD_TYPE(t))
+                                       if (IS_2_WORD_TYPE(t)) {
                                                M_LNGMOVE(s2, var->vv.regoff);
-                                       else
+                                       } else {
                                                M_INTMOVE(s2, var->vv.regoff);
-
+                                       }
                                } else {                             /* reg arg -> spilled    */
-                                       if (IS_2_WORD_TYPE(t))
+                                       if (IS_2_WORD_TYPE(t)) {
                                                M_LST(s2, REG_SP, var->vv.regoff);
-                                       else
+                                       } else {
                                                M_IST(s2, REG_SP, var->vv.regoff);
+                                       }
                                }
 
                        } else {                                 /* stack arguments       */
                                if (!IS_INMEMORY(var->flags)) {      /* stack arg -> register */
-                                       if (IS_2_WORD_TYPE(t))
-                                               M_LLD(var->vv.regoff, REG_SP, cd->stackframesize * 4 + s1);
-                                       else
-                                               M_ILD(var->vv.regoff, REG_SP, cd->stackframesize * 4 + s1);
-
-                               } else {                             /* stack arg -> spilled  */
                                        if (IS_2_WORD_TYPE(t)) {
-                                               N_MVC(var->vv.regoff, 8, REG_SP, cd->stackframesize * 4 + s1, REG_SP);
+                                               M_LLD(var->vv.regoff, REG_SP, cd->stackframesize * 8 + s1);
                                        } else {
-                                               N_MVC(var->vv.regoff, 4, REG_SP, cd->stackframesize * 4 + s1, REG_SP);
+                                               M_ILD(var->vv.regoff, REG_SP, cd->stackframesize * 8 + s1);
                                        }
+                               } else {                             /* stack arg -> spilled  */
+                                       N_MVC(var->vv.regoff, 8, REG_SP, cd->stackframesize * 8 + s1, REG_SP);
                                }
                        }
 
@@ -310,19 +343,14 @@ bool codegen_emit(jitdata *jd)
                        } else {                                 /* stack arguments       */
                                if (!IS_INMEMORY(var->flags)) {      /* stack-arg -> register */
                                        if (IS_2_WORD_TYPE(t))
-                                               M_DLD(var->vv.regoff, REG_SP, cd->stackframesize * 4 + s1);
+                                               M_DLD(var->vv.regoff, REG_SP, cd->stackframesize * 8 + s1);
 
                                        else
-                                               M_FLD(var->vv.regoff, REG_SP, cd->stackframesize * 4 + s1);
+                                               M_FLD(var->vv.regoff, REG_SP, cd->stackframesize * 8 + s1);
 
                                } else {                             /* stack-arg -> spilled  */
-                                       if (IS_2_WORD_TYPE(t)) {
-                                               N_MVC(var->vv.regoff, 8, REG_SP, cd->stackframesize * 4 + s1, REG_SP);
-                                               var->vv.regoff = cd->stackframesize * 4 + s1;
-
-                                       } else {
-                                               N_MVC(var->vv.regoff, 4, REG_SP, cd->stackframesize * 4 + s1, REG_SP);
-                                       }
+                                       N_MVC(var->vv.regoff, 8, REG_SP, cd->stackframesize * 8 + s1, REG_SP);
+                                       var->vv.regoff = cd->stackframesize * 8 + s1;
                                }
                        }
                }
@@ -344,9 +372,9 @@ bool codegen_emit(jitdata *jd)
                                M_IST(abi_registers_integer_argument[p], REG_SP, p * 8);
 
                        for (p = 0; p < FLT_ARG_CNT; p++)
-                               M_FST(abi_registers_float_argument[p], REG_SP, (INT_ARG_CNT + p) * 8);
+                               M_DST(abi_registers_float_argument[p], REG_SP, (INT_ARG_CNT + p) * 8);
 
-                       s1 += ((INT_ARG_CNT + FLT_ARG_CNT) * 2);
+                       s1 += ((INT_ARG_CNT + FLT_ARG_CNT));
                }
 #endif
 
@@ -365,7 +393,7 @@ bool codegen_emit(jitdata *jd)
                disp = dseg_add_functionptr(cd, LOCK_monitor_enter);
                M_ALD_DSEG(REG_ITMP3, disp);
 
-               M_AST(REG_A0, REG_SP, s1 * 4);
+               M_AST(REG_A0, REG_SP, s1 * 8);
 
                M_ASUB_IMM(96, REG_SP); 
                M_CALL(REG_ITMP3);
@@ -377,7 +405,7 @@ bool codegen_emit(jitdata *jd)
                                M_ILD(abi_registers_integer_argument[p], REG_SP, p * 8);
 
                        for (p = 0; p < FLT_ARG_CNT; p++)
-                               M_FLD(abi_registers_float_argument[p], REG_SP, (INT_ARG_CNT + p) * 8);
+                               M_DLD(abi_registers_float_argument[p], REG_SP, (INT_ARG_CNT + p) * 8);
 
                        M_AADD_IMM((INT_ARG_CNT + FLT_ARG_CNT) * 8, REG_SP);
                }
@@ -568,6 +596,16 @@ bool codegen_emit(jitdata *jd)
                                } else {
                                        disp = dseg_add_unique_address(cd, iptr->sx.val.anyptr);
                                        M_ALD_DSEG(d, disp);
+                                       /*
+                                       if (((u4)(iptr->sx.val.anyptr) & 0x00008000) == 0) {
+                                               N_LHI(d, ((u4)(iptr->sx.val.anyptr) >> 16) & 0xFFFF);
+                                               M_SLL_IMM(16, d);
+                                               N_AHI(d, (u4)(iptr->sx.val.anyptr) & 0xFFFF);
+                                       } else {
+                                               disp = dseg_add_unique_address(cd, iptr->sx.val.anyptr);
+                                               M_ALD_DSEG(d, disp);
+                                       }
+                                       */
                                }
                        }
                        emit_store_dst(jd, iptr, d);
@@ -1683,7 +1721,7 @@ bool codegen_emit(jitdata *jd)
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
                        /* TODO softnull */
                        /* implicit null-pointer check */
-                       M_ILD(d, s1, OFFSET(java_arrayheader, size));
+                       M_ILD(d, s1, OFFSET(java_array_t, size));
                        emit_store_dst(jd, iptr, d);
 
                        break;
@@ -1696,7 +1734,7 @@ bool codegen_emit(jitdata *jd)
                        /* implicit null-pointer check */
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
 
-                       N_IC(d, OFFSET(java_bytearray, data[0]), s2, s1);
+                       N_IC(d, OFFSET(java_bytearray_t, data[0]), s2, s1);
 
                        M_SLL_IMM(24, d);
                        M_SRA_IMM(24, d);
@@ -1716,7 +1754,7 @@ bool codegen_emit(jitdata *jd)
                        M_INTMOVE(s2, REG_ITMP2);
                        M_SLL_IMM(1, REG_ITMP2);
 
-                       N_LH(d, OFFSET(java_chararray, data[0]), REG_ITMP2, s1);
+                       N_LH(d, OFFSET(java_chararray_t, data[0]), REG_ITMP2, s1);
 
                        /* N_LH does sign extends, undo ! */
 
@@ -1737,7 +1775,7 @@ bool codegen_emit(jitdata *jd)
                        M_INTMOVE(s2, REG_ITMP2);
                        M_SLL_IMM(1, REG_ITMP2);
 
-                       N_LH(d, OFFSET(java_shortarray, data[0]), REG_ITMP2, s1);
+                       N_LH(d, OFFSET(java_shortarray_t, data[0]), REG_ITMP2, s1);
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1751,7 +1789,7 @@ bool codegen_emit(jitdata *jd)
                        
                        M_INTMOVE(s2, REG_ITMP2);
                        M_SLL_IMM(2, REG_ITMP2); /* scale index by 4 */
-                       N_L(d, OFFSET(java_intarray, data[0]), REG_ITMP2, s1);
+                       N_L(d, OFFSET(java_intarray_t, data[0]), REG_ITMP2, s1);
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1775,8 +1813,8 @@ bool codegen_emit(jitdata *jd)
                                s1 = REG_ITMP3;
                        }
 
-                       N_L(GET_HIGH_REG(d) /* evntl. itmp1 */, OFFSET(java_intarray, data[0]), REG_ITMP2, s1);
-                       N_L(GET_LOW_REG(d) /* evntl. itmp2 */, OFFSET(java_intarray, data[0]) + 4, REG_ITMP2, s1);
+                       N_L(GET_HIGH_REG(d) /* evntl. itmp1 */, OFFSET(java_intarray_t, data[0]), REG_ITMP2, s1);
+                       N_L(GET_LOW_REG(d) /* evntl. itmp2 */, OFFSET(java_intarray_t, data[0]) + 4, REG_ITMP2, s1);
                        emit_store_dst(jd, iptr, d);
 
                        break;
@@ -1793,7 +1831,7 @@ bool codegen_emit(jitdata *jd)
                        M_INTMOVE(s2, REG_ITMP2);
                        M_SLL_IMM(2, REG_ITMP2); /* scale index by 4 */
        
-                       N_LE(d, OFFSET(java_floatarray, data[0]), REG_ITMP2, s1);
+                       N_LE(d, OFFSET(java_floatarray_t, data[0]), REG_ITMP2, s1);
 
                        emit_store_dst(jd, iptr, d);
                        break;
@@ -1809,7 +1847,7 @@ bool codegen_emit(jitdata *jd)
                        M_INTMOVE(s2, REG_ITMP2);
                        M_SLL_IMM(3, REG_ITMP2); /* scale index by 8 */
        
-                       N_LD(d, OFFSET(java_floatarray, data[0]), REG_ITMP2, s1);
+                       N_LD(d, OFFSET(java_floatarray_t, data[0]), REG_ITMP2, s1);
 
                        emit_store_dst(jd, iptr, d);
                        break;
@@ -1824,7 +1862,7 @@ bool codegen_emit(jitdata *jd)
                        
                        M_INTMOVE(s2, REG_ITMP2);
                        M_SLL_IMM(2, REG_ITMP2); /* scale index by 4 */
-                       N_L(d, OFFSET(java_objectarray, data[0]), REG_ITMP2, s1);
+                       N_L(d, OFFSET(java_objectarray_t, data[0]), REG_ITMP2, s1);
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1835,7 +1873,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
 
-                       N_STC(s3, OFFSET(java_bytearray, data[0]), s2, s1);
+                       N_STC(s3, OFFSET(java_bytearray_t, data[0]), s2, s1);
                        break;
 
                case ICMD_CASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1849,7 +1887,7 @@ bool codegen_emit(jitdata *jd)
                        M_INTMOVE(s2, REG_ITMP2);
                        M_SLL_IMM(1, REG_ITMP2);
 
-                       N_STH(s3, OFFSET(java_chararray, data[0]), REG_ITMP2, s1);
+                       N_STH(s3, OFFSET(java_chararray_t, data[0]), REG_ITMP2, s1);
 
                        break;
 
@@ -1863,7 +1901,7 @@ bool codegen_emit(jitdata *jd)
                        M_INTMOVE(s2, REG_ITMP2);
                        M_SLL_IMM(1, REG_ITMP2);
 
-                       N_STH(s3, OFFSET(java_shortarray, data[0]), REG_ITMP2, s1);
+                       N_STH(s3, OFFSET(java_shortarray_t, data[0]), REG_ITMP2, s1);
                        break;
 
                case ICMD_IASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1878,7 +1916,7 @@ bool codegen_emit(jitdata *jd)
                        M_INTMOVE(s2, REG_ITMP2);
                        M_SLL_IMM(2, REG_ITMP2);
 
-                       N_ST(s3, OFFSET(java_intarray, data[0]), REG_ITMP2, s1);
+                       N_ST(s3, OFFSET(java_intarray_t, data[0]), REG_ITMP2, s1);
                        break;
 
                case ICMD_LASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1892,9 +1930,9 @@ bool codegen_emit(jitdata *jd)
                        M_SLL_IMM(3, REG_ITMP2);
 
                        s3 = emit_load_s3_high(jd, iptr, REG_ITMP3);
-                       N_ST(s3, OFFSET(java_intarray, data[0]), REG_ITMP2, s1);
+                       N_ST(s3, OFFSET(java_intarray_t, data[0]), REG_ITMP2, s1);
                        s3 = emit_load_s3_low(jd, iptr, REG_ITMP3);
-                       N_ST(s3, OFFSET(java_intarray, data[0]) + 4, REG_ITMP2, s1);
+                       N_ST(s3, OFFSET(java_intarray_t, data[0]) + 4, REG_ITMP2, s1);
                        break;
 
                case ICMD_FASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1907,7 +1945,7 @@ bool codegen_emit(jitdata *jd)
                        M_INTMOVE(s2, REG_ITMP2);
                        M_SLL_IMM(2, REG_ITMP2);
 
-                       N_STE(s3, OFFSET(java_floatarray, data[0]), REG_ITMP2, s1);
+                       N_STE(s3, OFFSET(java_floatarray_t, data[0]), REG_ITMP2, s1);
                        break;
 
                case ICMD_DASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1920,7 +1958,7 @@ bool codegen_emit(jitdata *jd)
                        M_INTMOVE(s2, REG_ITMP2);
                        M_SLL_IMM(3, REG_ITMP2);
 
-                       N_STD(s3, OFFSET(java_doublearray, data[0]), REG_ITMP2, s1);
+                       N_STD(s3, OFFSET(java_doublearray_t, data[0]), REG_ITMP2, s1);
                        break;
 
                case ICMD_AASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1948,7 +1986,7 @@ bool codegen_emit(jitdata *jd)
 
                        M_INTMOVE(s2, REG_ITMP2);
                        M_SLL_IMM(2, REG_ITMP2);
-                       N_ST(s3, OFFSET(java_objectarray, data[0]), REG_ITMP2, s1);
+                       N_ST(s3, OFFSET(java_objectarray_t, data[0]), REG_ITMP2, s1);
 
                        /*
                        M_SAADDQ(s2, s1, REG_ITMP1); itmp1 := 4 * s2 + s1
@@ -2559,26 +2597,25 @@ nowperformreturn:
 
 #if defined(ENABLE_THREADS)
                        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
-
                                /* we need to save the proper return value */
 
                                switch (iptr->opc) {
                                case ICMD_LRETURN:
-                                       M_IST(REG_RESULT2, REG_SP, rd->memuse * 4 + 8);
+                                       M_IST(REG_RESULT2, REG_SP, ((rd->memuse + 1) * 8) + 4);
                                        /* fall through */
                                case ICMD_IRETURN:
                                case ICMD_ARETURN:
-                                       M_IST(REG_RESULT , REG_SP, rd->memuse * 4 + 4);
+                                       M_IST(REG_RESULT , REG_SP, (rd->memuse + 1) * 8);
                                        break;
                                case ICMD_FRETURN:
-                                       M_FST(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
+                                       M_FST(REG_FRESULT, REG_SP, (rd->memuse + 1) * 8);
                                        break;
                                case ICMD_DRETURN:
-                                       M_DST(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
+                                       M_DST(REG_FRESULT, REG_SP, (rd->memuse + 1) * 8);
                                        break;
                                }
 
-                               M_ALD(REG_A0, REG_SP, rd->memuse * 4);
+                               M_ALD(REG_A0, REG_SP, rd->memuse * 8);
 
                                disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
                                M_ALD_DSEG(REG_ITMP3, disp);
@@ -2591,17 +2628,17 @@ nowperformreturn:
 
                                switch (iptr->opc) {
                                case ICMD_LRETURN:
-                                       M_ILD(REG_RESULT2, REG_SP, rd->memuse * 4 + 8);
+                                       M_ILD(REG_RESULT2, REG_SP, ((rd->memuse + 1) * 8) + 4);
                                        /* fall through */
                                case ICMD_IRETURN:
                                case ICMD_ARETURN:
-                                       M_ILD(REG_RESULT , REG_SP, rd->memuse * 4 + 4);
+                                       M_ILD(REG_RESULT , REG_SP, (rd->memuse + 1) * 8);
                                        break;
                                case ICMD_FRETURN:
-                                       M_FLD(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
+                                       M_FLD(REG_FRESULT, REG_SP, (rd->memuse + 1) * 8);
                                        break;
                                case ICMD_DRETURN:
-                                       M_DLD(REG_FRESULT, REG_SP, rd->memuse * 4 + 4);
+                                       M_DLD(REG_FRESULT, REG_SP, (rd->memuse + 1) * 8);
                                        break;
                                }
                        }
@@ -2609,27 +2646,27 @@ nowperformreturn:
 
                        /* restore return address                                         */
 
-                       p--; M_ALD(REG_RA, REG_SP, p * 4);
+                       p--; M_ALD(REG_RA, REG_SP, p * 8);
 
                        /* restore saved registers                                        */
 
                        for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
-                               p--; M_ILD(rd->savintregs[i], REG_SP, p * 4);
+                               p--; M_ILD(rd->savintregs[i], REG_SP, p * 8);
                        }
                        for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
-                               p -= 2; M_DLD(rd->savfltregs[i], REG_SP, p * 4);
+                               p--; M_DLD(rd->savfltregs[i], REG_SP, p * 8);
                        }
 
                        /* deallocate stack                                               */
 
                        if (cd->stackframesize)
-                               M_AADD_IMM(cd->stackframesize * 4, REG_SP);
+                               M_AADD_IMM(cd->stackframesize * 8, REG_SP);
 
                        /* generate method profiling code */
 
                        PROFILE_CYCLE_STOP;
+
                        M_RET;
-                       ALIGNCODENOP;
                        }
                        break;
 
@@ -2851,7 +2888,7 @@ gen_method:
 
                                /* implicit null-pointer check */
 
-                               M_ALD(REG_METHODPTR, REG_A0, OFFSET(java_objectheader, vftbl));
+                               M_ALD(REG_METHODPTR, REG_A0, OFFSET(java_object_t, vftbl));
                                M_ALD(REG_PV, REG_METHODPTR, s1);
                                break;
 
@@ -2876,7 +2913,7 @@ gen_method:
                                }
 
                                /* Implicit null-pointer check */
-                               M_ALD(REG_METHODPTR, REG_A0, OFFSET(java_objectheader, vftbl));
+                               M_ALD(REG_METHODPTR, REG_A0, OFFSET(java_object_t, vftbl));
                                N_LHI(REG_ITMP1, s1);
                                N_L(REG_METHODPTR, 0, REG_ITMP1, REG_METHODPTR);
                                M_ALD(REG_PV, REG_METHODPTR, s2);
@@ -3011,7 +3048,7 @@ gen_method:
                                                emit_label_beq(cd, LABEL_EXIT_INTERFACE_NULL);
                                        }
 
-                                       M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
+                                       M_ALD(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
                                        M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
                                        M_ISUB_IMM(superindex, REG_ITMP3);
                                        emit_classcast_check(cd, iptr, BRANCH_LE, RN, s1);
@@ -3049,7 +3086,7 @@ gen_method:
                                                emit_label_beq(cd, LABEL_EXIT_CLASS_NULL);
                                        }
 
-                                       M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
+                                       M_ALD(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
                                        M_ALD_DSEG(REG_ITMP3, disp);
 
                                        CODEGEN_CRITICAL_SECTION_START;
@@ -3217,7 +3254,7 @@ gen_method:
                                        emit_label_beq(cd, LABEL_EXIT_INTERFACE_NULL);
                                }
 
-                               M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
+                               M_ALD(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
                                M_ILD(REG_ITMP3, REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
                                M_ISUB_IMM(superindex, REG_ITMP3);
 
@@ -3264,7 +3301,7 @@ gen_method:
                                        emit_label_beq(cd, LABEL_EXIT_CLASS_NULL);
                                }
 
-                               M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
+                               M_ALD(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
                                M_ALD_DSEG(REG_ITMP2, disp);
 
                                CODEGEN_CRITICAL_SECTION_START;
@@ -3394,9 +3431,6 @@ gen_method:
        /* generate stubs */
 
        emit_patcher_traps(jd);
-#if defined(ENABLE_REPLACEMENT)
-       REPLACEMENT_EMIT_STUBS(jd);
-#endif
 
        /* everything's ok */
 
@@ -3488,20 +3522,17 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        cd->stackframesize = 
                1 + /* r14 - return address */ +
-               sizeof(stackframeinfo) / SIZEOF_VOID_P +
-               sizeof(localref_table) / SIZEOF_VOID_P +
+               ((sizeof(stackframeinfo) + 7) / 8) +
+               ((sizeof(localref_table) + 7) / 8)  +
                1 + /* itmp3 */
-               (INT_ARG_CNT + FLT_ARG_CNT) * 2 +
+               (INT_ARG_CNT + FLT_ARG_CNT) +
                nmd->memuse + /* parameter passing */
-               96 / SIZEOF_VOID_P /* required by ABI */;
-
-       cd->stackframesize |= 0x1;                  /* keep stack 8-byte aligned */
-
+               (96 / 8)  /* required by ABI */;
 
        /* create method header */
 
        (void) dseg_add_unique_address(cd, code);              /* CodeinfoPointer */
-       (void) dseg_add_unique_s4(cd, cd->stackframesize * 4); /* FrameSize       */
+       (void) dseg_add_unique_s4(cd, cd->stackframesize * 8); /* FrameSize       */
        (void) dseg_add_unique_s4(cd, 0);                      /* IsSync          */
        (void) dseg_add_unique_s4(cd, 0);                      /* IsLeaf          */
        (void) dseg_add_unique_s4(cd, 0);                      /* IntSave         */
@@ -3511,7 +3542,7 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        /* generate stub code */
 
-       N_AHI(REG_SP, -(cd->stackframesize * SIZEOF_VOID_P));
+       N_AHI(REG_SP, -(cd->stackframesize * 8));
        N_AHI(REG_PV, N_PV_OFFSET);
 
        /* generate native method profiling code */
@@ -3528,7 +3559,7 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        /* save return address */
 
-       N_ST(R14, (cd->stackframesize - 1) * SIZEOF_VOID_P, RN, REG_SP);
+       N_ST(R14, (cd->stackframesize - 1) * 8, RN, REG_SP);
 
 #if !defined(NDEBUG)
        if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
@@ -3546,7 +3577,7 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        M_ILD_DSEG(REG_ITMP1, disp);
 
-       j = 96 + (nmd->memuse * 4);
+       j = 96 + (nmd->memuse * 8);
 
        /* todo some arg registers are not volatile in C-abi terms */
 
@@ -3581,10 +3612,10 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        /* create dynamic stack info */
 
-       N_LAE(REG_A0, (cd->stackframesize - 1) * 4, RN, REG_SP); /* datasp */
+       N_LAE(REG_A0, (cd->stackframesize - 1) * , RN, REG_SP); /* datasp */
        N_LA(REG_A1, -N_PV_OFFSET, RN, REG_PV); /* pv */
-       N_LAE(REG_A2, cd->stackframesize * 4, RN, REG_SP); /* old SP */
-       N_L(REG_A3, (cd->stackframesize - 1) * 4, RN, REG_SP); /* return address */
+       N_LAE(REG_A2, cd->stackframesize * 8, RN, REG_SP); /* old SP */
+       N_L(REG_A3, (cd->stackframesize - 1) * 8, RN, REG_SP); /* return address */
 
        disp = dseg_add_functionptr(cd, codegen_start_native_call);
        M_ILD_DSEG(REG_ITMP1, disp);
@@ -3593,7 +3624,7 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        /* restore integer and float argument registers */
 
-       j = 96 + (nmd->memuse * 4);
+       j = 96 + (nmd->memuse * 8);
 
        for (i = 0; i < md->paramcount; i++) {
                if (! md->params[i].inmemory) {
@@ -3667,7 +3698,7 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
                                }
 
                        } else {
-                               s1 = cd->stackframesize * 4 + md->params[i].regoff;
+                               s1 = cd->stackframesize * 8 + md->params[i].regoff;
                                s2 = nmd->params[j].regoff;
                                
                                if (IS_2_WORD_TYPE(t)) {
@@ -3682,7 +3713,7 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
                        /* registers keep unchanged.                                      */
 
                        if (md->params[i].inmemory) {
-                               s1 = cd->stackframesize * 4 + md->params[i].regoff;
+                               s1 = cd->stackframesize * 8 + md->params[i].regoff;
                                s2 = nmd->params[j].regoff;
 
                                if (IS_2_WORD_TYPE(t)) {
@@ -3737,7 +3768,7 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        /* remove native stackframe info */
 
-       N_LAE(REG_A0, (cd->stackframesize - 1) * 4, RN, REG_SP); /* datasp */
+       N_LAE(REG_A0, (cd->stackframesize - 1) * 8, RN, REG_SP); /* datasp */
        disp = dseg_add_functionptr(cd, codegen_finish_native_call);
        M_ALD_DSEG(REG_ITMP1, disp);
        M_CALL(REG_ITMP1);
@@ -3763,11 +3794,11 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        /* load return address */
        
-       N_L(REG_ITMP2, (cd->stackframesize - 1) * 4, RN, REG_SP);
+       N_L(REG_ITMP2, (cd->stackframesize - 1) * 8, RN, REG_SP);
 
        /* remove stackframe */
 
-       N_AHI(REG_SP, cd->stackframesize * 4);
+       N_AHI(REG_SP, cd->stackframesize * 8);
 
        /* test for exception */