Merged changes from trunk.
[cacao.git] / src / vm / jit / powerpc / codegen.c
index 57f99fdd29f9191caac0ef4d6fa8b8bac85b7eef..38118d9b80012b69f1919736919ce3984298f9b9 100644 (file)
@@ -31,7 +31,7 @@
             Christian Ullrich
             Edwin Steiner
 
-   $Id: codegen.c 4937 2006-05-18 14:33:32Z edwin $
+   $Id: codegen.c 5323 2006-09-05 16:45:24Z edwin $
 
 */
 
 
 #include "mm/memory.h"
 #include "native/native.h"
+
+#if defined(ENABLE_THREADS)
+# include "threads/native/lock.h"
+#endif
+
 #include "vm/builtin.h"
 #include "vm/exceptions.h"
 #include "vm/global.h"
 #include "vm/options.h"
 #include "vm/stringlocal.h"
 #include "vm/vm.h"
+#include "vm/jit/abi-asm.h"
 #include "vm/jit/asmpart.h"
 #include "vm/jit/codegen-common.h"
 #include "vm/jit/dseg.h"
 #include "vm/jit/emit.h"
 #include "vm/jit/jit.h"
+#include "vm/jit/methodheader.h"
 #include "vm/jit/parse.h"
 #include "vm/jit/patcher.h"
 #include "vm/jit/reg.h"
@@ -73,8 +80,6 @@
 #endif
 
 
-void codegen_trace_args(jitdata *jd, s4 stackframesize, bool nativestub);
-
 /* codegen *********************************************************************
 
    Generates machine code.
@@ -84,11 +89,11 @@ void codegen_trace_args(jitdata *jd, s4 stackframesize, bool nativestub);
 bool codegen(jitdata *jd)
 {
        methodinfo         *m;
+       codeinfo           *code;
        codegendata        *cd;
        registerdata       *rd;
        s4                  len, s1, s2, s3, d, disp;
        ptrint              a;
-       s4                  stackframesize;
        stackptr            src;
        varinfo            *var;
        basicblock         *bptr;
@@ -102,9 +107,10 @@ bool codegen(jitdata *jd)
 
        /* get required compiler data */
 
-       m  = jd->m;
-       cd = jd->cd;
-       rd = jd->rd;
+       m    = jd->m;
+       code = jd->code;
+       cd   = jd->cd;
+       rd   = jd->rd;
 
        /* prevent compiler warnings */
 
@@ -121,32 +127,39 @@ bool codegen(jitdata *jd)
        /* space to save used callee saved registers */
 
        savedregs_num += (INT_SAV_CNT - rd->savintreguse);
-       savedregs_num += 2 * (FLT_SAV_CNT - rd->savfltreguse);
+       savedregs_num += (FLT_SAV_CNT - rd->savfltreguse) * 2;
 
-       stackframesize = rd->memuse + savedregs_num;
+       cd->stackframesize = rd->memuse + savedregs_num;
 
 #if defined(ENABLE_THREADS)
-       /* space to save argument of monitor_enter and Return Values to survive */
-    /* monitor_exit. The stack position for the argument can not be shared  */
-       /* with place to save the return register on PPC, since both values     */
-       /* reside in R3 */
+       /* Space to save argument of monitor_enter and Return Values to
+          survive monitor_exit. The stack position for the argument can
+          not be shared with place to save the return register on PPC,
+          since both values reside in R3. */
+
        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))
-                       stackframesize += 3;
+                       cd->stackframesize += 3;
                else
-                       stackframesize += 2;
+                       cd->stackframesize += 2;
        }
 
 #endif
 
        /* create method header */
 
-       stackframesize = (stackframesize + 3) & ~3;    /* align stack to 16-bytes */
+       /* align stack to 16-bytes */
+
+       if (!jd->isleafmethod || JITDATA_HAS_FLAG_VERBOSECALL(jd))
+               cd->stackframesize = (cd->stackframesize + 3) & ~3;
 
-       (void) dseg_addaddress(cd, m);                          /* MethodPointer  */
-       (void) dseg_adds4(cd, stackframesize * 4);              /* FrameSize      */
+       else if (jd->isleafmethod && (cd->stackframesize == LA_SIZE_IN_POINTERS))
+               cd->stackframesize = 0;
+
+       (void) dseg_add_unique_address(cd, code);              /* CodeinfoPointer */
+       (void) dseg_add_unique_s4(cd, cd->stackframesize * 4); /* FrameSize       */
 
 #if defined(ENABLE_THREADS)
        /* IsSync contains the offset relative to the stack pointer for the
@@ -156,41 +169,54 @@ bool codegen(jitdata *jd)
        */
 
        if (checksync && (m->flags & ACC_SYNCHRONIZED))
-               (void) dseg_adds4(cd, (rd->memuse + 1) * 4);        /* IsSync         */
+               (void) dseg_add_unique_s4(cd, (rd->memuse + 1) * 4);/* IsSync         */
        else
 #endif
-               (void) dseg_adds4(cd, 0);                           /* IsSync         */
+               (void) dseg_add_unique_s4(cd, 0);                  /* IsSync          */
                                               
-       (void) dseg_adds4(cd, m->isleafmethod);                 /* IsLeaf         */
-       (void) dseg_adds4(cd, INT_SAV_CNT - rd->savintreguse);  /* IntSave        */
-       (void) dseg_adds4(cd, FLT_SAV_CNT - rd->savfltreguse);  /* FltSave        */
+       (void) dseg_add_unique_s4(cd, jd->isleafmethod);       /* IsLeaf          */
+       (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave */
+       (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave */
 
        dseg_addlinenumbertablesize(cd);
 
-       (void) dseg_adds4(cd, cd->exceptiontablelength);        /* ExTableSize    */
+       (void) dseg_add_unique_s4(cd, cd->exceptiontablelength); /* ExTableSize   */
 
        /* create exception table */
 
        for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
-               dseg_addtarget(cd, ex->start);
-               dseg_addtarget(cd, ex->end);
-               dseg_addtarget(cd, ex->handler);
-               (void) dseg_addaddress(cd, ex->catchtype.cls);
+               dseg_add_target(cd, ex->start);
+               dseg_add_target(cd, ex->end);
+               dseg_add_target(cd, ex->handler);
+               (void) dseg_add_unique_address(cd, ex->catchtype.cls);
        }
        
+       /* generate method profiling code */
+
+       if (JITDATA_HAS_FLAG_INSTRUMENT(jd)) {
+               /* count frequency */
+
+               M_ALD(REG_ITMP1, REG_PV, CodeinfoPointer);
+               M_ALD(REG_ITMP2, REG_ITMP1, OFFSET(codeinfo, frequency));
+               M_IADD_IMM(REG_ITMP2, 1, REG_ITMP2);
+               M_AST(REG_ITMP2, REG_ITMP1, OFFSET(codeinfo, frequency));
+
+/*             PROFILE_CYCLE_START; */
+       }
+
        /* create stack frame (if necessary) */
 
-       if (!m->isleafmethod) {
+       if (!jd->isleafmethod) {
                M_MFLR(REG_ZERO);
                M_AST(REG_ZERO, REG_SP, LA_LR_OFFSET);
        }
 
-       if (stackframesize)
-               M_STWU(REG_SP, REG_SP, -stackframesize * 4);
+       if (cd->stackframesize)
+               M_STWU(REG_SP, REG_SP, -(cd->stackframesize * 4));
 
        /* save return address and used callee saved registers */
 
-       p = stackframesize;
+       p = cd->stackframesize;
        for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
                p--; M_IST(rd->savintregs[i], REG_SP, p * 4);
        }
@@ -234,21 +260,21 @@ bool codegen(jitdata *jd)
                        } else {                                 /* stack arguments       */
                                if (!(var->flags & INMEMORY)) {      /* stack arg -> register */
                                        if (IS_2_WORD_TYPE(t))
-                                               M_LLD(var->regoff, REG_SP, (stackframesize + s1) * 4);
+                                               M_LLD(var->regoff, REG_SP, (cd->stackframesize + s1) * 4);
                                        else
-                                               M_ILD(var->regoff, REG_SP, (stackframesize + s1) * 4);
+                                               M_ILD(var->regoff, REG_SP, (cd->stackframesize + s1) * 4);
 
                                } else {                             /* stack arg -> spilled  */
 #if 1
-                                       M_ILD(REG_ITMP1, REG_SP, (stackframesize + s1) * 4);
+                                       M_ILD(REG_ITMP1, REG_SP, (cd->stackframesize + s1) * 4);
                                        M_IST(REG_ITMP1, REG_SP, var->regoff * 4);
                                        if (IS_2_WORD_TYPE(t)) {
-                                               M_ILD(REG_ITMP1, REG_SP, (stackframesize + s1) * 4 +4);
+                                               M_ILD(REG_ITMP1, REG_SP, (cd->stackframesize + s1) * 4 +4);
                                                M_IST(REG_ITMP1, REG_SP, var->regoff * 4 + 4);
                                        }
 #else
                                        /* Reuse Memory Position on Caller Stack */
-                                       var->regoff = stackframesize + s1;
+                                       var->regoff = cd->stackframesize + s1;
 #endif
                                }
                        }
@@ -269,101 +295,101 @@ bool codegen(jitdata *jd)
                        } else {                                 /* stack arguments       */
                                if (!(var->flags & INMEMORY)) {      /* stack-arg -> register */
                                        if (IS_2_WORD_TYPE(t))
-                                               M_DLD(var->regoff, REG_SP, (stackframesize + s1) * 4);
+                                               M_DLD(var->regoff, REG_SP, (cd->stackframesize + s1) * 4);
 
                                        else
-                                               M_FLD(var->regoff, REG_SP, (stackframesize + s1) * 4);
+                                               M_FLD(var->regoff, REG_SP, (cd->stackframesize + s1) * 4);
 
                                } else {                             /* stack-arg -> spilled  */
 #if 1
                                        if (IS_2_WORD_TYPE(t)) {
-                                               M_DLD(REG_FTMP1, REG_SP, (stackframesize + s1) * 4);
+                                               M_DLD(REG_FTMP1, REG_SP, (cd->stackframesize + s1) * 4);
                                                M_DST(REG_FTMP1, REG_SP, var->regoff * 4);
-                                               var->regoff = stackframesize + s1;
+                                               var->regoff = cd->stackframesize + s1;
 
                                        } else {
-                                               M_FLD(REG_FTMP1, REG_SP, (stackframesize + s1) * 4);
+                                               M_FLD(REG_FTMP1, REG_SP, (cd->stackframesize + s1) * 4);
                                                M_FST(REG_FTMP1, REG_SP, var->regoff * 4);
                                        }
 #else
                                        /* Reuse Memory Position on Caller Stack */
-                                       var->regoff = stackframesize + s1;
+                                       var->regoff = cd->stackframesize + s1;
 #endif
                                }
                        }
                }
        } /* end for */
 
-       /* save monitorenter argument */
-
 #if defined(ENABLE_THREADS)
+       /* call monitorenter function */
+
        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
                /* stack offset for monitor argument */
 
                s1 = rd->memuse;
 
-#if 0
-               if (opt_verbosecall) {
-                       M_LDA(REG_SP, REG_SP, -(INT_ARG_CNT * 4 + FLT_ARG_CNT * 8));
+# if !defined(NDEBUG)
+               if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
+                       M_AADD_IMM(REG_SP, -((LA_SIZE_IN_POINTERS + ARG_CNT) * 8), REG_SP);
 
                        for (p = 0; p < INT_ARG_CNT; p++)
-                               M_IST(rd->argintregs[p], REG_SP, p * 4);
+                               M_IST(rd->argintregs[p], REG_SP, LA_SIZE + p * 8);
+
+                       for (p = 0; p < FLT_ARG_CNT; p++)
+                               M_DST(rd->argfltregs[p], REG_SP, LA_SIZE + (INT_ARG_CNT + p) * 8);
 
-                       for (p = 0; p < FLT_ARG_CNT * 2; p += 2)
-                               M_DST(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 4);
+                       /* ATTENTION: We multiply here with 2, because we use * 8
+                          above for simplicity and below * 4! */
 
-                       s1 += INT_ARG_CNT + FLT_ARG_CNT;
+                       s1 += (LA_SIZE_IN_POINTERS + ARG_CNT) * 2;
                }
-#endif
+# endif
 
-               /* decide which monitor enter function to call */
+               p = dseg_add_functionptr(cd, LOCK_monitor_enter);
+               M_ALD(REG_ITMP3, REG_PV, p);
+               M_MTCTR(REG_ITMP3);
+
+               /* get or test the lock object */
 
                if (m->flags & ACC_STATIC) {
-                       p = dseg_addaddress(cd, BUILTIN_staticmonitorenter);
-                       M_ALD(REG_ITMP3, REG_PV, p);
-                       M_MTCTR(REG_ITMP3);
-                       p = dseg_addaddress(cd, m->class);
+                       p = dseg_add_address(cd, &m->class->object.header);
                        M_ALD(rd->argintregs[0], REG_PV, p);
-                       M_AST(rd->argintregs[0], REG_SP, s1 * 4);
-                       M_JSR;
-
-               } else {
-                       p = dseg_addaddress(cd, BUILTIN_monitorenter);
-                       M_ALD(REG_ITMP3, REG_PV, p);
-                       M_MTCTR(REG_ITMP3);
+               }
+               else {
                        M_TST(rd->argintregs[0]);
                        M_BEQ(0);
                        codegen_add_nullpointerexception_ref(cd);
-                       M_AST(rd->argintregs[0], REG_SP, s1 * 4);
-                       M_JSR;
                }
 
-#if 0
-               if (opt_verbosecall) {
+               M_AST(rd->argintregs[0], REG_SP, s1 * 4);
+               M_JSR;
+
+# if !defined(NDEBUG)
+               if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
                        for (p = 0; p < INT_ARG_CNT; p++)
-                               M_ILD(rd->argintregs[p], REG_SP, p * 4);
+                               M_ILD(rd->argintregs[p], REG_SP, LA_SIZE + p * 8);
 
                        for (p = 0; p < FLT_ARG_CNT; p++)
-                               M_DLD(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 4);
+                               M_DLD(rd->argfltregs[p], REG_SP, LA_SIZE + (INT_ARG_CNT + p) * 8);
 
-
-                       M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT) * 8);
+                       M_AADD_IMM(REG_SP, (LA_SIZE_IN_POINTERS + ARG_CNT) * 8, REG_SP);
                }
-#endif
+# endif
        }
-#endif
+#endif /* defined(ENABLE_THREADS) */
 
        /* call trace function */
 
-       if (opt_verbosecall)
-               codegen_trace_args(jd, stackframesize, false);
+       if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
+               emit_verbosecall_enter(jd);
        }
 
        /* end of header generation */
 
-       replacementpoint = jd->code->rplpoints;
+       replacementpoint = code->rplpoints;
 
        /* walk through all basic blocks */
+
        for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
 
                bptr->mpc = (s4) (cd->mcodeptr - cd->mcodebase);
@@ -389,6 +415,23 @@ bool codegen(jitdata *jd)
                        replacementpoint++;
                }
 
+               /* generate basicblock profiling code */
+
+               if (JITDATA_HAS_FLAG_INSTRUMENT(jd)) {
+                       /* count frequency */
+
+                       disp = dseg_add_address(cd, code->bbfrequency);
+                       M_ALD(REG_ITMP2, REG_PV, disp);
+                       M_ALD(REG_ITMP3, REG_ITMP2, bptr->nr * 4);
+                       M_IADD_IMM(REG_ITMP3, 1, REG_ITMP3);
+                       M_AST(REG_ITMP3, REG_ITMP2, bptr->nr * 4);
+
+                       /* if this is an exception handler, start profiling again */
+
+/*                     if (bptr->type == BBTYPE_EXH) */
+/*                             PROFILE_CYCLE_START; */
+               }
+
                /* copy interface registers to their destination */
 
                src = bptr->instack;
@@ -418,9 +461,10 @@ bool codegen(jitdata *jd)
                                d = codegen_reg_of_var(rd, 0, src, REG_ITMP1);
                                M_INTMOVE(REG_ITMP1, d);
                                emit_store(jd, NULL, src, d);
-                       } else {
+                       }
+                       else {
                                if (src->type == TYPE_LNG)
-                                       d = codegen_reg_of_var(rd, 0, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                                       d = codegen_reg_of_var(rd, 0, src, REG_ITMP12_PACKED);
                                else
                                        d = codegen_reg_of_var(rd, 0, src, REG_IFTMP);
                                if ((src->varkind != STACKVAR)) {
@@ -429,26 +473,28 @@ bool codegen(jitdata *jd)
                                                if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
                                                        s1 = rd->interfaces[len][s2].regoff;
                                                        M_FLTMOVE(s1, d);
-                                               } else {
+                                               }
+                                               else {
                                                        if (IS_2_WORD_TYPE(s2)) {
                                                                M_DLD(d, REG_SP,
                                                                          rd->interfaces[len][s2].regoff * 4);
-                                                       } else {
+                                                       }
+                                                       else {
                                                                M_FLD(d, REG_SP,
                                                                          rd->interfaces[len][s2].regoff * 4);
                                                        }       
                                                }
-
                                                emit_store(jd, NULL, src, d);
-
-                                       else {
+                                       }
+                                       else {
                                                if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
                                                        s1 = rd->interfaces[len][s2].regoff;
                                                        if (IS_2_WORD_TYPE(s2))
                                                                M_LNGMOVE(s1, d);
                                                        else
                                                                M_INTMOVE(s1, d);
-                                               } else {
+                                               } 
+                                               else {
                                                        if (IS_2_WORD_TYPE(s2))
                                                                M_LLD(d, REG_SP,
                                                                          rd->interfaces[len][s2].regoff * 4);
@@ -456,7 +502,6 @@ bool codegen(jitdata *jd)
                                                                M_ILD(d, REG_SP,
                                                                          rd->interfaces[len][s2].regoff * 4);
                                                }
-
                                                emit_store(jd, NULL, src, d);
                                        }
                                }
@@ -508,7 +553,7 @@ bool codegen(jitdata *jd)
                case ICMD_LCONST:     /* ...  ==> ..., constant                       */
                                      /* op1 = 0, val.l = constant                    */
 
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        LCONST(d, iptr->val.l);
                        emit_store(jd, iptr, iptr->dst, d);
                        break;
@@ -517,7 +562,7 @@ bool codegen(jitdata *jd)
                                      /* op1 = 0, val.f = constant                    */
 
                        d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_FTMP1);
-                       a = dseg_addfloat(cd, iptr->val.f);
+                       a = dseg_add_float(cd, iptr->val.f);
                        M_FLD(d, REG_PV, a);
                        emit_store(jd, iptr, iptr->dst, d);
                        break;
@@ -526,7 +571,7 @@ bool codegen(jitdata *jd)
                                      /* op1 = 0, val.d = constant                    */
 
                        d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_FTMP1);
-                       a = dseg_adddouble(cd, iptr->val.d);
+                       a = dseg_add_double(cd, iptr->val.d);
                        M_DLD(d, REG_PV, a);
                        emit_store(jd, iptr, iptr->dst, d);
                        break;
@@ -535,16 +580,20 @@ bool codegen(jitdata *jd)
                                      /* op1 = 0, val.a = constant                    */
 
                        d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP1);
-                       disp = dseg_addaddress(cd, iptr->val.a);
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               codegen_addpatchref(cd, PATCHER_aconst,
-                                                                       ICMD_ACONST_UNRESOLVED_CLASSREF(iptr),
-                                                                   disp);
+                               constant_classref *cr = ICMD_ACONST_UNRESOLVED_CLASSREF(iptr);;
+
+                               disp = dseg_add_unique_address(cd, cr);
+
+                               codegen_addpatchref(cd, PATCHER_resolve_classref_to_classinfo,
+                                                                       cr, disp);
 
                                if (opt_showdisassemble)
                                        M_NOP;
                        }
+                       else
+                               disp = dseg_add_address(cd, iptr->val.a);
 
                        M_ALD(d, REG_PV, disp);
                        emit_store(jd, iptr, iptr->dst, d);
@@ -572,7 +621,7 @@ bool codegen(jitdata *jd)
                                      /* op1 = local variable                         */
 
                        var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        if ((iptr->dst->varkind == LOCALVAR) &&
                                (iptr->dst->varnum == iptr->op1))
                                break;
@@ -636,7 +685,7 @@ bool codegen(jitdata *jd)
                                break;
                        var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
                        if (var->flags & INMEMORY) {
-                               s1 = emit_load_s1(jd, iptr, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                               s1 = emit_load_s1(jd, iptr, src, REG_ITMP12_PACKED);
                                M_LST(s1, REG_SP, var->regoff * 4);
                        } else {
                                s1 = emit_load_s1(jd, iptr, src, var->regoff);
@@ -746,8 +795,8 @@ bool codegen(jitdata *jd)
 
                case ICMD_LNEG:       /* ..., value  ==> ..., - value                 */
 
-                       s1 = emit_load_s1(jd, iptr, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       s1 = emit_load_s1(jd, iptr, src, REG_ITMP12_PACKED);
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        M_SUBFIC(GET_LOW_REG(s1), 0, GET_LOW_REG(d));
                        M_SUBFZE(GET_HIGH_REG(s1), GET_HIGH_REG(d));
                        emit_store(jd, iptr, iptr->dst, d);
@@ -756,7 +805,7 @@ bool codegen(jitdata *jd)
                case ICMD_I2L:        /* ..., value  ==> ..., value                   */
 
                        s1 = emit_load_s1(jd, iptr, src, REG_ITMP2);
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        M_INTMOVE(s1, GET_LOW_REG(d));
                        M_SRA_IMM(GET_LOW_REG(d), 31, GET_HIGH_REG(d));
                        emit_store(jd, iptr, iptr->dst, d);
@@ -822,7 +871,7 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1_low(jd, iptr, src->prev, REG_ITMP1);
                        s2 = emit_load_s2_low(jd, iptr, src, REG_ITMP2);
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        M_ADDC(s1, s2, GET_LOW_REG(d));
                        s1 = emit_load_s1_high(jd, iptr, src->prev, REG_ITMP1);
                        s2 = emit_load_s2_high(jd, iptr, src, REG_ITMP3);   /* don't use REG_ITMP2 */
@@ -835,7 +884,7 @@ bool codegen(jitdata *jd)
 
                        s3 = iptr->val.l & 0xffffffff;
                        s1 = emit_load_s1_low(jd, iptr, src, REG_ITMP1);
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        if ((s3 >= -32768) && (s3 <= 32767)) {
                                M_ADDIC(s1, s3, GET_LOW_REG(d));
                        } else {
@@ -882,7 +931,7 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1_low(jd, iptr, src->prev, REG_ITMP1);
                        s2 = emit_load_s2_low(jd, iptr, src, REG_ITMP2);
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        M_SUBC(s1, s2, GET_LOW_REG(d));
                        s1 = emit_load_s1_high(jd, iptr, src->prev, REG_ITMP1);
                        s2 = emit_load_s2_high(jd, iptr, src, REG_ITMP3);   /* don't use REG_ITMP2 */
@@ -895,7 +944,7 @@ bool codegen(jitdata *jd)
 
                        s3 = (-iptr->val.l) & 0xffffffff;
                        s1 = emit_load_s1_low(jd, iptr, src, REG_ITMP1);
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        if ((s3 >= -32768) && (s3 <= 32767)) {
                                M_ADDIC(s1, s3, GET_LOW_REG(d));
                        } else {
@@ -961,12 +1010,12 @@ bool codegen(jitdata *jd)
                        bte = iptr->val.a;
                        md = bte->md;
 
-                       s2 = emit_load_s2(jd, iptr, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       s2 = emit_load_s2(jd, iptr, src, REG_ITMP12_PACKED);
                        M_OR_TST(GET_HIGH_REG(s2), GET_LOW_REG(s2), REG_ITMP3);
                        M_BEQ(0);
                        codegen_add_arithmeticexception_ref(cd);
 
-                       disp = dseg_addaddress(cd, bte->fp);
+                       disp = dseg_add_functionptr(cd, bte->fp);
                        M_ALD(REG_ITMP3, REG_PV, disp);
                        M_MTCTR(REG_ITMP3);
 
@@ -974,15 +1023,15 @@ bool codegen(jitdata *jd)
                                                   rd->argintregs[GET_HIGH_REG(md->params[1].regoff)]);
                        M_LNGMOVE(s2, s3);
 
-                       s1 = emit_load_s1(jd, iptr, src->prev, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       s1 = emit_load_s1(jd, iptr, src->prev, REG_ITMP12_PACKED);
                        s3 = PACK_REGS(rd->argintregs[GET_LOW_REG(md->params[0].regoff)],
                                                   rd->argintregs[GET_HIGH_REG(md->params[0].regoff)]);
                        M_LNGMOVE(s1, s3);
 
                        M_JSR;
 
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_RESULT2, REG_RESULT));
-                       M_LNGMOVE(PACK_REGS(REG_RESULT2, REG_RESULT), d);
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_RESULT_PACKED);
+                       M_LNGMOVE(REG_RESULT_PACKED, d);
                        emit_store(jd, iptr, iptr->dst, d);
                        break;
 
@@ -1112,7 +1161,7 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1_low(jd, iptr, src->prev, REG_ITMP1);
                        s2 = emit_load_s2_low(jd, iptr, src, REG_ITMP2);
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        M_AND(s1, s2, GET_LOW_REG(d));
                        s1 = emit_load_s1_high(jd, iptr, src->prev, REG_ITMP1);
                        s2 = emit_load_s2_high(jd, iptr, src, REG_ITMP3);   /* don't use REG_ITMP2 */
@@ -1125,7 +1174,7 @@ bool codegen(jitdata *jd)
 
                        s3 = iptr->val.l & 0xffffffff;
                        s1 = emit_load_s1_low(jd, iptr, src, REG_ITMP1);
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        if ((s3 >= 0) && (s3 <= 65535)) {
                                M_AND_IMM(s1, s3, GET_LOW_REG(d));
                        } else {
@@ -1195,7 +1244,7 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1_low(jd, iptr, src->prev, REG_ITMP1);
                        s2 = emit_load_s2_low(jd, iptr, src, REG_ITMP2);
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        M_OR(s1, s2, GET_LOW_REG(d));
                        s1 = emit_load_s1_high(jd, iptr, src->prev, REG_ITMP1);
                        s2 = emit_load_s2_high(jd, iptr, src, REG_ITMP3);   /* don't use REG_ITMP2 */
@@ -1208,7 +1257,7 @@ bool codegen(jitdata *jd)
 
                        s3 = iptr->val.l & 0xffffffff;
                        s1 = emit_load_s1_low(jd, iptr, src, REG_ITMP1);
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        if ((s3 >= 0) && (s3 <= 65535)) {
                                M_OR_IMM(s1, s3, GET_LOW_REG(d));
                        } else {
@@ -1253,7 +1302,7 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1_low(jd, iptr, src->prev, REG_ITMP1);
                        s2 = emit_load_s2_low(jd, iptr, src, REG_ITMP2);
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        M_XOR(s1, s2, GET_LOW_REG(d));
                        s1 = emit_load_s1_high(jd, iptr, src->prev, REG_ITMP1);
                        s2 = emit_load_s2_high(jd, iptr, src, REG_ITMP3);   /* don't use REG_ITMP2 */
@@ -1266,7 +1315,7 @@ bool codegen(jitdata *jd)
 
                        s3 = iptr->val.l & 0xffffffff;
                        s1 = emit_load_s1_low(jd, iptr, src, REG_ITMP1);
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        if ((s3 >= 0) && (s3 <= 65535)) {
                                M_XOR_IMM(s1, s3, GET_LOW_REG(d));
                        } else {
@@ -1448,11 +1497,11 @@ bool codegen(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, src, REG_FTMP1);
                        d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP2);
                        M_CLR(d);
-                       disp = dseg_addfloat(cd, 0.0);
+                       disp = dseg_add_float(cd, 0.0);
                        M_FLD(REG_FTMP2, REG_PV, disp);
                        M_FCMPU(s1, REG_FTMP2);
                        M_BNAN(4);
-                       disp = dseg_adds4(cd, 0);
+                       disp = dseg_add_unique_s4(cd, 0);
                        M_CVTDL_C(s1, REG_FTMP1);
                        M_LDA(REG_ITMP1, REG_PV, disp);
                        M_STFIWX(REG_FTMP1, 0, REG_ITMP1);
@@ -1701,7 +1750,7 @@ bool codegen(jitdata *jd)
 
                        s1 = emit_load_s1(jd, iptr, src->prev, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, src, REG_ITMP2);
-                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                       d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
@@ -1868,7 +1917,7 @@ bool codegen(jitdata *jd)
                        }
                        s3 = emit_load_s3(jd, iptr, src, rd->argintregs[1]);
 
-                       disp = dseg_addaddress(cd, BUILTIN_canstore);
+                       disp = dseg_add_functionptr(cd, BUILTIN_canstore);
                        M_ALD(REG_ITMP3, REG_PV, disp);
                        M_MTCTR(REG_ITMP3);
 
@@ -1893,21 +1942,23 @@ bool codegen(jitdata *jd)
                                      /* op1 = type, val.a = field address            */
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               disp = dseg_addaddress(cd, NULL);
+                               unresolved_field *uf = INSTRUCTION_UNRESOLVED_FIELD(iptr);
 
-                               codegen_addpatchref(cd, PATCHER_get_putstatic,
-                                                                       INSTRUCTION_UNRESOLVED_FIELD(iptr), disp);
+                               disp = dseg_add_unique_address(cd, uf);
+
+                               codegen_addpatchref(cd, PATCHER_get_putstatic, uf, disp);
 
                                if (opt_showdisassemble)
                                        M_NOP;
-
-                       else {
+                       }
+                       else {
                                fieldinfo *fi = INSTRUCTION_RESOLVED_FIELDINFO(iptr);
 
-                               disp = dseg_addaddress(cd, &(fi->value));
+                               disp = dseg_add_address(cd, &(fi->value));
 
                                if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
-                                       codegen_addpatchref(cd, PATCHER_clinit, fi->class, disp);
+                                       codegen_addpatchref(cd, PATCHER_initialize_class,
+                                                                               fi->class, disp);
 
                                        if (opt_showdisassemble)
                                                M_NOP;
@@ -1921,7 +1972,7 @@ bool codegen(jitdata *jd)
                                M_ILD_INTERN(d, REG_ITMP1, 0);
                                break;
                        case TYPE_LNG:
-                               d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                               d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                                M_ILD_INTERN(GET_LOW_REG(d), REG_ITMP1, 4);/* keep this order */
                                M_ILD_INTERN(GET_HIGH_REG(d), REG_ITMP1, 0);/*keep this order */
                                break;
@@ -1944,23 +1995,24 @@ bool codegen(jitdata *jd)
                case ICMD_PUTSTATIC:  /* ..., value  ==> ...                          */
                                      /* op1 = type, val.a = field address            */
 
-
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               disp = dseg_addaddress(cd, NULL);
+                               unresolved_field *uf = INSTRUCTION_UNRESOLVED_FIELD(iptr);
+
+                               disp = dseg_add_unique_address(cd, uf);
 
-                               codegen_addpatchref(cd, PATCHER_get_putstatic,
-                                                                       INSTRUCTION_UNRESOLVED_FIELD(iptr), disp);
+                               codegen_addpatchref(cd, PATCHER_get_putstatic, uf, disp);
 
                                if (opt_showdisassemble)
                                        M_NOP;
-
-                       else {
+                       }
+                       else {
                                fieldinfo *fi = INSTRUCTION_RESOLVED_FIELDINFO(iptr);
 
-                               disp = dseg_addaddress(cd, &(fi->value));
+                               disp = dseg_add_address(cd, &(fi->value));
 
                                if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
-                                       codegen_addpatchref(cd, PATCHER_clinit, fi->class, disp);
+                                       codegen_addpatchref(cd, PATCHER_initialize_class,
+                                                                               fi->class, disp);
 
                                        if (opt_showdisassemble)
                                                M_NOP;
@@ -1970,24 +2022,24 @@ bool codegen(jitdata *jd)
                        M_ALD(REG_ITMP1, REG_PV, disp);
                        switch (iptr->op1) {
                        case TYPE_INT:
-                               s2 = emit_load_s2(jd, iptr, src, REG_ITMP2);
-                               M_IST_INTERN(s2, REG_ITMP1, 0);
+                               s1 = emit_load_s1(jd, iptr, src, REG_ITMP2);
+                               M_IST_INTERN(s1, REG_ITMP1, 0);
                                break;
                        case TYPE_LNG:
-                               s2 = emit_load_s2(jd, iptr, src, PACK_REGS(REG_ITMP2, REG_ITMP3));
-                               M_LST_INTERN(s2, REG_ITMP1, 0);
+                               s1 = emit_load_s1(jd, iptr, src, REG_ITMP23_PACKED);
+                               M_LST_INTERN(s1, REG_ITMP1, 0);
                                break;
                        case TYPE_ADR:
-                               s2 = emit_load_s2(jd, iptr, src, REG_ITMP2);
-                               M_AST_INTERN(s2, REG_ITMP1, 0);
+                               s1 = emit_load_s1(jd, iptr, src, REG_ITMP2);
+                               M_AST_INTERN(s1, REG_ITMP1, 0);
                                break;
                        case TYPE_FLT:
-                               s2 = emit_load_s2(jd, iptr, src, REG_FTMP2);
-                               M_FST_INTERN(s2, REG_ITMP1, 0);
+                               s1 = emit_load_s1(jd, iptr, src, REG_FTMP2);
+                               M_FST_INTERN(s1, REG_ITMP1, 0);
                                break;
                        case TYPE_DBL:
-                               s2 = emit_load_s2(jd, iptr, src, REG_FTMP2);
-                               M_DST_INTERN(s2, REG_ITMP1, 0);
+                               s1 = emit_load_s1(jd, iptr, src, REG_FTMP2);
+                               M_DST_INTERN(s1, REG_ITMP1, 0);
                                break;
                        }
                        break;
@@ -2000,16 +2052,18 @@ bool codegen(jitdata *jd)
                        gen_nullptr_check(s1);
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               codegen_addpatchref(cd, PATCHER_get_putfield,
-                                                                       INSTRUCTION_UNRESOLVED_FIELD(iptr), 0);
+                               unresolved_field *uf = INSTRUCTION_UNRESOLVED_FIELD(iptr);
+
+                               codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
 
                                if (opt_showdisassemble)
                                        M_NOP;
 
                                disp = 0;
-
-                       } else {
-                               disp = INSTRUCTION_RESOLVED_FIELDINFO(iptr)->offset;
+                       }
+                       else {
+                               fieldinfo *fi = INSTRUCTION_RESOLVED_FIELDINFO(iptr);
+                               disp = fi->offset;
                        }
 
                        switch (iptr->op1) {
@@ -2018,11 +2072,12 @@ bool codegen(jitdata *jd)
                                M_ILD(d, s1, disp);
                                break;
                        case TYPE_LNG:
-                               d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                               d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_ITMP12_PACKED);
                                if (GET_HIGH_REG(d) == s1) {
                                        M_ILD(GET_LOW_REG(d), s1, disp + 4);
                                        M_ILD(GET_HIGH_REG(d), s1, disp);
-                               } else {
+                               }
+                               else {
                                        M_ILD(GET_HIGH_REG(d), s1, disp);
                                        M_ILD(GET_LOW_REG(d), s1, disp + 4);
                                }
@@ -2050,26 +2105,27 @@ bool codegen(jitdata *jd)
                        gen_nullptr_check(s1);
 
                        if (!IS_FLT_DBL_TYPE(iptr->op1)) {
-                               if (IS_2_WORD_TYPE(iptr->op1)) {
-                                       s2 = emit_load_s2(jd, iptr, src, PACK_REGS(REG_ITMP2, REG_ITMP3));
-                               } else {
+                               if (IS_2_WORD_TYPE(iptr->op1))
+                                       s2 = emit_load_s2(jd, iptr, src, REG_ITMP23_PACKED);
+                               else
                                        s2 = emit_load_s2(jd, iptr, src, REG_ITMP2);
-                               }
-                       } else {
-                               s2 = emit_load_s2(jd, iptr, src, REG_FTMP2);
                        }
+                       else
+                               s2 = emit_load_s2(jd, iptr, src, REG_FTMP2);
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               codegen_addpatchref(cd, PATCHER_get_putfield,
-                                                                       INSTRUCTION_UNRESOLVED_FIELD(iptr), 0);
+                               unresolved_field *uf = INSTRUCTION_UNRESOLVED_FIELD(iptr);
+
+                               codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
 
                                if (opt_showdisassemble)
                                        M_NOP;
 
                                disp = 0;
-
-                       } else {
-                               disp = INSTRUCTION_RESOLVED_FIELDINFO(iptr)->offset;
+                       }
+                       else {
+                               fieldinfo *fi = INSTRUCTION_RESOLVED_FIELDINFO(iptr);
+                               disp = fi->offset;
                        }
 
                        switch (iptr->op1) {
@@ -2102,24 +2158,29 @@ bool codegen(jitdata *jd)
 
 #ifdef ENABLE_VERIFIER
                        if (iptr->val.a) {
-                               codegen_addpatchref(cd, PATCHER_athrow_areturn,
-                                                                       (unresolved_class *) iptr->val.a, 0);
+                               unresolved_class *uc = INSTRUCTION_UNRESOLVED_CLASS(iptr);
+
+                               codegen_addpatchref(cd, PATCHER_resolve_class, uc, 0);
 
                                if (opt_showdisassemble)
                                        M_NOP;
                        }
 #endif /* ENABLE_VERIFIER */
 
-                       disp = dseg_addaddress(cd, asm_handle_exception);
+                       disp = dseg_add_functionptr(cd, asm_handle_exception);
                        M_ALD(REG_ITMP2, REG_PV, disp);
                        M_MTCTR(REG_ITMP2);
 
-                       if (m->isleafmethod) M_MFLR(REG_ITMP3);         /* save LR        */
+                       if (jd->isleafmethod)
+                               M_MFLR(REG_ITMP3);                          /* save LR        */
+
                        M_BL(0);                                        /* get current PC */
                        M_MFLR(REG_ITMP2_XPC);
-                       if (m->isleafmethod) M_MTLR(REG_ITMP3);         /* restore LR     */
-                       M_RTS;                                          /* jump to CTR    */
 
+                       if (jd->isleafmethod)
+                               M_MTLR(REG_ITMP3);                          /* restore LR     */
+
+                       M_RTS;                                          /* jump to CTR    */
                        ALIGNCODENOP;
                        break;
 
@@ -2133,13 +2194,16 @@ bool codegen(jitdata *jd)
                case ICMD_JSR:          /* ... ==> ...                                */
                                        /* op1 = target JavaVM pc                     */
 
-                       if (m->isleafmethod)
+                       if (jd->isleafmethod)
                                M_MFLR(REG_ITMP2);
+
                        M_BL(0);
                        M_MFLR(REG_ITMP1);
-                       M_IADD_IMM(REG_ITMP1, m->isleafmethod ? 4*4 : 3*4, REG_ITMP1);
-                       if (m->isleafmethod)
+                       M_IADD_IMM(REG_ITMP1, jd->isleafmethod ? 4*4 : 3*4, REG_ITMP1);
+
+                       if (jd->isleafmethod)
                                M_MTLR(REG_ITMP2);
+
                        M_BR(0);
                        codegen_addreference(cd, (basicblock *) iptr->target);
                        break;
@@ -2541,8 +2605,9 @@ bool codegen(jitdata *jd)
 
 #ifdef ENABLE_VERIFIER
                        if (iptr->val.a) {
-                               codegen_addpatchref(cd, PATCHER_athrow_areturn,
-                                                                       (unresolved_class *) iptr->val.a, 0);
+                               unresolved_class *uc = INSTRUCTION_UNRESOLVED_CLASS(iptr);
+
+                               codegen_addpatchref(cd, PATCHER_resolve_class, uc, 0);
 
                                if (opt_showdisassemble)
                                        M_NOP;
@@ -2552,8 +2617,8 @@ bool codegen(jitdata *jd)
 
                case ICMD_LRETURN:      /* ..., retvalue ==> ...                      */
 
-                       s1 = emit_load_s1(jd, iptr, src, PACK_REGS(REG_RESULT2, REG_RESULT));
-                       M_LNGMOVE(s1, PACK_REGS(REG_RESULT2, REG_RESULT));
+                       s1 = emit_load_s1(jd, iptr, src, REG_RESULT_PACKED);
+                       M_LNGMOVE(s1, REG_RESULT_PACKED);
                        goto nowperformreturn;
 
                case ICMD_FRETURN:      /* ..., retvalue ==> ...                      */
@@ -2569,63 +2634,16 @@ nowperformreturn:
                        {
                        s4 i, p;
                        
-                       p = stackframesize;
+                       p = cd->stackframesize;
 
                        /* call trace function */
 
-                       if (opt_verbosecall) {
-                               M_MFLR(REG_ZERO);
-                               M_LDA(REG_SP, REG_SP, -10 * 8);
-                               M_DST(REG_FRESULT, REG_SP, 48+0);
-                               M_IST(REG_RESULT, REG_SP, 48+8);
-                               M_AST(REG_ZERO, REG_SP, 48+12);
-                               M_IST(REG_RESULT2, REG_SP, 48+16);
-
-                               /* keep this order */
-                               switch (iptr->opc) {
-                               case ICMD_IRETURN:
-                               case ICMD_ARETURN:
-#if defined(__DARWIN__)
-                                       M_MOV(REG_RESULT, rd->argintregs[2]);
-                                       M_CLR(rd->argintregs[1]);
-#else
-                                       M_MOV(REG_RESULT, rd->argintregs[3]);
-                                       M_CLR(rd->argintregs[2]);
-#endif
-                                       break;
-
-                               case ICMD_LRETURN:
-#if defined(__DARWIN__)
-                                       M_MOV(REG_RESULT2, rd->argintregs[2]);
-                                       M_MOV(REG_RESULT, rd->argintregs[1]);
-#else
-                                       M_MOV(REG_RESULT2, rd->argintregs[3]);
-                                       M_MOV(REG_RESULT, rd->argintregs[2]);
-#endif
-                                       break;
-                               }
-
-                               disp = dseg_addaddress(cd, m);
-                               M_ALD(rd->argintregs[0], REG_PV, disp);
+                       if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
+                               emit_verbosecall_exit(jd);
 
-                               M_FLTMOVE(REG_FRESULT, rd->argfltregs[0]);
-                               M_FLTMOVE(REG_FRESULT, rd->argfltregs[1]);
-                               disp = dseg_addaddress(cd, builtin_displaymethodstop);
-                               M_ALD(REG_ITMP2, REG_PV, disp);
-                               M_MTCTR(REG_ITMP2);
-                               M_JSR;
-
-                               M_DLD(REG_FRESULT, REG_SP, 48+0);
-                               M_ILD(REG_RESULT, REG_SP, 48+8);
-                               M_ALD(REG_ZERO, REG_SP, 48+12);
-                               M_ILD(REG_RESULT2, REG_SP, 48+16);
-                               M_LDA(REG_SP, REG_SP, 10 * 8);
-                               M_MTLR(REG_ZERO);
-                       }
-                       
 #if defined(ENABLE_THREADS)
                        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
-                               disp = dseg_addaddress(cd, BUILTIN_monitorexit);
+                               disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
                                M_ALD(REG_ITMP3, REG_PV, disp);
                                M_MTCTR(REG_ITMP3);
 
@@ -2672,7 +2690,7 @@ nowperformreturn:
 
                        /* restore return address                                         */
 
-                       if (!m->isleafmethod) {
+                       if (!jd->isleafmethod) {
                                /* ATTENTION: Don't use REG_ZERO (r0) here, as M_ALD
                                   may have a displacement overflow. */
 
@@ -2691,8 +2709,8 @@ nowperformreturn:
 
                        /* deallocate stack                                               */
 
-                       if (stackframesize)
-                               M_LDA(REG_SP, REG_SP, stackframesize * 4);
+                       if (cd->stackframesize)
+                               M_LDA(REG_SP, REG_SP, cd->stackframesize * 4);
 
                        M_RET;
                        ALIGNCODENOP;
@@ -2734,12 +2752,12 @@ nowperformreturn:
                        tptr += i;
 
                        while (--i >= 0) {
-                               dseg_addtarget(cd, (basicblock *) tptr[0]); 
+                               dseg_add_target(cd, (basicblock *) tptr[0]); 
                                --tptr;
                        }
                        }
 
-                       /* length of dataseg after last dseg_addtarget is used by load */
+                       /* length of dataseg after last dseg_add_target is used by load */
 
                        M_SLL_IMM(REG_ITMP1, 2, REG_ITMP1);
                        M_IADD(REG_ITMP1, REG_PV, REG_ITMP2);
@@ -2770,8 +2788,9 @@ nowperformreturn:
                                val = s4ptr[0];
                                if ((val >= -32768) && (val <= 32767)) {
                                        M_CMPI(s1, val);
-                               } else {
-                                       a = dseg_adds4(cd, val);
+                               }
+                               else {
+                                       a = dseg_add_s4(cd, val);
                                        M_ILD(REG_ITMP2, REG_PV, a);
                                        M_CMP(s1, REG_ITMP2);
                                }
@@ -2829,29 +2848,31 @@ gen_method:
                                                   rd->argintregs[GET_HIGH_REG(md->params[s3].regoff)]);
                                                        d = emit_load_s1(jd, iptr, src, s1);
                                                        M_LNGMOVE(d, s1);
-                                               } else {
+                                               }
+                                               else {
                                                        s1 = rd->argintregs[md->params[s3].regoff];
                                                        d = emit_load_s1(jd, iptr, src, s1);
                                                        M_INTMOVE(d, s1);
                                                }
-
-                                       else {
+                                       }
+                                       else {
                                                if (IS_2_WORD_TYPE(src->type)) {
-                                                       d = emit_load_s1(jd, iptr, src, PACK_REGS(REG_ITMP2, REG_ITMP1));
+                                                       d = emit_load_s1(jd, iptr, src, REG_ITMP12_PACKED);
                                                        M_LST(d, REG_SP, md->params[s3].regoff * 4);
-                                               } else {
+                                               }
+                                               else {
                                                        d = emit_load_s1(jd, iptr, src, REG_ITMP1);
                                                        M_IST(d, REG_SP, md->params[s3].regoff * 4);
                                                }
                                        }
-                                               
-                               else {
+                               }
+                               else {
                                        if (!md->params[s3].inmemory) {
                                                s1 = rd->argfltregs[md->params[s3].regoff];
                                                d = emit_load_s1(jd, iptr, src, s1);
                                                M_FLTMOVE(d, s1);
-
-                                       else {
+                                       }
+                                       else {
                                                d = emit_load_s1(jd, iptr, src, REG_FTMP1);
                                                if (IS_2_WORD_TYPE(src->type))
                                                        M_DST(d, REG_SP, md->params[s3].regoff * 4);
@@ -2863,7 +2884,7 @@ gen_method:
 
                        switch (iptr->opc) {
                        case ICMD_BUILTIN:
-                               disp = dseg_addaddress(cd, bte->fp);
+                               disp = dseg_add_functionptr(cd, bte->fp);
                                d = md->returntype.type;
 
                                M_ALD(REG_PV, REG_PV, disp);  /* pointer to built-in-function */
@@ -2891,7 +2912,7 @@ gen_method:
                                if (lm == NULL) {
                                        unresolved_method *um = INSTRUCTION_UNRESOLVED_METHOD(iptr);
 
-                                       disp = dseg_addaddress(cd, NULL);
+                                       disp = dseg_add_unique_address(cd, um);
 
                                        codegen_addpatchref(cd, PATCHER_invokestatic_special,
                                                                                um, disp);
@@ -2900,9 +2921,9 @@ gen_method:
                                                M_NOP;
 
                                        d = md->returntype.type;
-
-                               else {
-                                       disp = dseg_addaddress(cd, lm->stubroutine);
+                               }
+                               else {
+                                       disp = dseg_add_address(cd, lm->stubroutine);
                                        d = md->returntype.type;
                                }
 
@@ -2927,8 +2948,8 @@ gen_method:
 
                                        s1 = 0;
                                        d = md->returntype.type;
-
-                               else {
+                               }
+                               else {
                                        s1 = OFFSET(vftbl_t, table[0]) +
                                                sizeof(methodptr) * lm->vftblindex;
                                        d = md->returntype.type;
@@ -2958,8 +2979,8 @@ gen_method:
                                        s1 = 0;
                                        s2 = 0;
                                        d = md->returntype.type;
-
-                               else {
+                               }
+                               else {
                                        s1 = OFFSET(vftbl_t, interfacetable[0]) -
                                                sizeof(methodptr*) * lm->class->index;
 
@@ -2985,14 +3006,15 @@ gen_method:
                        if (d != TYPE_VOID) {
                                if (IS_INT_LNG_TYPE(iptr->dst->type)) {
                                        if (IS_2_WORD_TYPE(iptr->dst->type)) {
-                                               s1 = codegen_reg_of_var(rd, iptr->opc, iptr->dst,
-                                                                               PACK_REGS(REG_RESULT2, REG_RESULT));
-                                               M_LNGMOVE(PACK_REGS(REG_RESULT2, REG_RESULT), s1);
-                                       else {
+                                               s1 = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_RESULT_PACKED);
+                                               M_LNGMOVE(REG_RESULT_PACKED, s1);
+                                       }
+                                       else {
                                                s1 = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_RESULT);
                                                M_INTMOVE(REG_RESULT, s1);
                                        }
-                               } else {
+                               }
+                               else {
                                        s1 = codegen_reg_of_var(rd, iptr->opc, iptr->dst, REG_FRESULT);
                                        M_FLTMOVE(REG_FRESULT, s1);
                                }
@@ -3022,19 +3044,14 @@ gen_method:
                                /* object type cast-check */
 
                                classinfo *super;
-                               vftbl_t   *supervftbl;
                                s4         superindex;
 
                                super = (classinfo *) iptr->val.a;
 
-                               if (!super) {
+                               if (super == NULL)
                                        superindex = 0;
-                                       supervftbl = NULL;
-
-                               } else {
+                               else
                                        superindex = super->index;
-                                       supervftbl = super->vftbl;
-                               }
                        
 #if defined(ENABLE_THREADS)
                                codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
@@ -3055,14 +3072,14 @@ gen_method:
 
                                /* if class is not resolved, check which code to call */
 
-                               if (!super) {
+                               if (super == NULL) {
                                        M_TST(s1);
                                        M_BEQ(3 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
 
-                                       disp = dseg_adds4(cd, 0);                     /* super->flags */
+                                       disp = dseg_add_unique_s4(cd, 0);         /* super->flags */
 
                                        codegen_addpatchref(cd,
-                                                                               PATCHER_checkcast_instanceof_flags,
+                                                                               PATCHER_resolve_classref_to_flags,
                                                                                (constant_classref *) iptr->target,
                                                                                disp);
 
@@ -3076,12 +3093,8 @@ gen_method:
 
                                /* interface checkcast code */
 
-                               if (!super || (super->flags & ACC_INTERFACE)) {
-                                       if (super) {
-                                               M_TST(s1);
-                                               M_BEQ(s2);
-
-                                       } else {
+                               if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
+                                       if (super == NULL) {
                                                codegen_addpatchref(cd,
                                                                                        PATCHER_checkcast_instanceof_interface,
                                                                                        (constant_classref *) iptr->target,
@@ -3090,40 +3103,46 @@ gen_method:
                                                if (opt_showdisassemble)
                                                        M_NOP;
                                        }
+                                       else {
+                                               M_TST(s1);
+                                               M_BEQ(s2);
+                                       }
 
                                        M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
                                        M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
                                        M_LDATST(REG_ITMP3, REG_ITMP3, -superindex);
                                        M_BLE(0);
-                                       codegen_add_classcastexception_ref(cd);
+                                       codegen_add_classcastexception_ref(cd, s1);
                                        M_ALD(REG_ITMP3, REG_ITMP2,
                                                  OFFSET(vftbl_t, interfacetable[0]) -
                                                  superindex * sizeof(methodptr*));
                                        M_TST(REG_ITMP3);
                                        M_BEQ(0);
-                                       codegen_add_classcastexception_ref(cd);
+                                       codegen_add_classcastexception_ref(cd, s1);
 
-                                       if (!super)
+                                       if (super == NULL)
                                                M_BR(s3);
                                }
 
                                /* class checkcast code */
 
-                               if (!super || !(super->flags & ACC_INTERFACE)) {
-                                       disp = dseg_addaddress(cd, supervftbl);
-
-                                       if (super) {
-                                               M_TST(s1);
-                                               M_BEQ(s3);
+                               if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
+                                       if (super == NULL) {
+                                               disp = dseg_add_unique_address(cd, NULL);
 
-                                       } else {
-                                               codegen_addpatchref(cd, PATCHER_checkcast_class,
+                                               codegen_addpatchref(cd, PATCHER_resolve_classref_to_vftbl,
                                                                                        (constant_classref *) iptr->target,
                                                                                        disp);
 
                                                if (opt_showdisassemble)
                                                        M_NOP;
                                        }
+                                       else {
+                                               disp = dseg_add_address(cd, super->vftbl);
+
+                                               M_TST(s1);
+                                               M_BEQ(s3);
+                                       }
 
                                        M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
 #if defined(ENABLE_THREADS)
@@ -3149,35 +3168,37 @@ gen_method:
                                        }
                                        M_CMPU(REG_ITMP3, REG_ITMP2);
                                        M_BGT(0);
-                                       codegen_add_classcastexception_ref(cd);
+                                       codegen_add_classcastexception_ref(cd, s1);
                                }
                                d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, s1);
-
-                       else {
+                       }
+                       else {
                                /* array type cast-check */
 
                                s1 = emit_load_s1(jd, iptr, src, rd->argintregs[0]);
                                M_INTMOVE(s1, rd->argintregs[0]);
 
-                               disp = dseg_addaddress(cd, iptr->val.a);
-
                                if (iptr->val.a == NULL) {
-                                       codegen_addpatchref(cd, PATCHER_builtin_arraycheckcast,
+                                       disp = dseg_add_unique_address(cd, NULL);
+
+                                       codegen_addpatchref(cd, PATCHER_resolve_classref_to_classinfo,
                                                                                (constant_classref *) iptr->target,
                                                                                disp);
 
                                        if (opt_showdisassemble)
                                                M_NOP;
                                }
+                               else
+                                       disp = dseg_add_address(cd, iptr->val.a);
 
                                M_ALD(rd->argintregs[1], REG_PV, disp);
-                               disp = dseg_addaddress(cd, BUILTIN_arraycheckcast);
+                               disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
                                M_ALD(REG_ITMP2, REG_PV, disp);
                                M_MTCTR(REG_ITMP2);
                                M_JSR;
                                M_TST(REG_RESULT);
                                M_BEQ(0);
-                               codegen_add_classcastexception_ref(cd);
+                               codegen_add_classcastexception_ref(cd, s1);
 
                                s1 = emit_load_s1(jd, iptr, src, REG_ITMP1);
                                d = codegen_reg_of_var(rd, iptr->opc, iptr->dst, s1);
@@ -3204,19 +3225,14 @@ gen_method:
 
                        {
                        classinfo *super;
-                       vftbl_t   *supervftbl;
                        s4         superindex;
 
                        super = (classinfo *) iptr->val.a;
 
-                       if (!super) {
+                       if (super == NULL)
                                superindex = 0;
-                               supervftbl = NULL;
-
-                       } else {
+                       else
                                superindex = super->index;
-                               supervftbl = super->vftbl;
-                       }
                        
 #if defined(ENABLE_THREADS)
             codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
@@ -3244,13 +3260,13 @@ gen_method:
 
                        /* if class is not resolved, check which code to call */
 
-                       if (!super) {
+                       if (super == NULL) {
                                M_TST(s1);
                                M_BEQ(3 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
 
-                               disp = dseg_adds4(cd, 0);                     /* super->flags */
+                               disp = dseg_add_unique_s4(cd, 0);             /* super->flags */
 
-                               codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
+                               codegen_addpatchref(cd, PATCHER_resolve_classref_to_flags,
                                                                        (constant_classref *) iptr->target, disp);
 
                                if (opt_showdisassemble)
@@ -3263,12 +3279,8 @@ gen_method:
 
                        /* interface instanceof code */
 
-                       if (!super || (super->flags & ACC_INTERFACE)) {
-                               if (super) {
-                                       M_TST(s1);
-                                       M_BEQ(s2);
-
-                               } else {
+                       if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
+                               if (super == NULL) {
                                        codegen_addpatchref(cd,
                                                                                PATCHER_checkcast_instanceof_interface,
                                                                                (constant_classref *) iptr->target, 0);
@@ -3276,6 +3288,10 @@ gen_method:
                                        if (opt_showdisassemble)
                                                M_NOP;
                                }
+                               else {
+                                       M_TST(s1);
+                                       M_BEQ(s2);
+                               }
 
                                M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
                                M_ILD(REG_ITMP3, REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
@@ -3288,27 +3304,28 @@ gen_method:
                                M_BEQ(1);
                                M_IADD_IMM(REG_ZERO, 1, d);
 
-                               if (!super)
+                               if (super == NULL)
                                        M_BR(s3);
                        }
 
                        /* class instanceof code */
 
-                       if (!super || !(super->flags & ACC_INTERFACE)) {
-                               disp = dseg_addaddress(cd, supervftbl);
-
-                               if (super) {
-                                       M_TST(s1);
-                                       M_BEQ(s3);
+                       if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
+                               if (super == NULL) {
+                                       disp = dseg_add_unique_address(cd, NULL);
 
-                               } else {
-                                       codegen_addpatchref(cd, PATCHER_instanceof_class,
+                                       codegen_addpatchref(cd, PATCHER_resolve_classref_to_vftbl,
                                                                                (constant_classref *) iptr->target,
                                                                                disp);
 
-                                       if (opt_showdisassemble) {
+                                       if (opt_showdisassemble)
                                                M_NOP;
-                                       }
+                               }
+                               else {
+                                       disp = dseg_add_address(cd, super->vftbl);
+
+                                       M_TST(s1);
+                                       M_BEQ(s3);
                                }
 
                                M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
@@ -3359,17 +3376,16 @@ gen_method:
                        /* is patcher function set? */
 
                        if (iptr->val.a == NULL) {
-                               disp = dseg_addaddress(cd, NULL);
+                               disp = dseg_add_unique_address(cd, NULL);
 
-                               codegen_addpatchref(cd, PATCHER_builtin_multianewarray,
+                               codegen_addpatchref(cd, PATCHER_resolve_classref_to_classinfo,
                                                                        (constant_classref *) iptr->target, disp);
 
                                if (opt_showdisassemble)
                                        M_NOP;
-
-                       } else {
-                               disp = dseg_addaddress(cd, iptr->val.a);
                        }
+                       else
+                               disp = dseg_add_address(cd, iptr->val.a);
 
                        /* a1 = arraydescriptor */
 
@@ -3383,7 +3399,7 @@ gen_method:
                        M_LDA(rd->argintregs[2], REG_SP, LA_SIZE + 3 * 4);
 #endif
 
-                       disp = dseg_addaddress(cd, BUILTIN_multianewarray);
+                       disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
                        M_ALD(REG_ITMP3, REG_PV, disp);
                        M_MTCTR(REG_ITMP3);
                        M_JSR;
@@ -3450,216 +3466,11 @@ gen_method:
 
        dseg_createlinenumbertable(cd);
 
+       /* generate stubs */
 
-       /* generate exception and patcher stubs */
-
-       {
-               exceptionref *eref;
-               patchref     *pref;
-               u4            mcode;
-               u1           *savedmcodeptr;
-               u1           *tmpmcodeptr;
-
-               savedmcodeptr = NULL;
-
-               /* generate exception stubs */
-
-               for (eref = cd->exceptionrefs; eref != NULL; eref = eref->next) {
-                       gen_resolvebranch(cd->mcodebase + eref->branchpos, 
-                                                         eref->branchpos, cd->mcodeptr - cd->mcodebase);
-
-                       MCODECHECK(100);
-
-                       /* Check if the exception is an
-                          ArrayIndexOutOfBoundsException.  If so, move index register
-                          into REG_ITMP1. */
-
-                       if (eref->reg != -1)
-                               M_MOV(eref->reg, REG_ITMP1);
-
-                       /* calcuate exception address */
-
-                       M_LDA(REG_ITMP2_XPC, REG_PV, eref->branchpos - 4);
-
-                       /* move function to call into REG_ITMP3 */
-
-                       disp = dseg_addaddress(cd, eref->function);
-                       M_ALD(REG_ITMP3, REG_PV, disp);
-
-                       if (savedmcodeptr != NULL) {
-                               disp = ((u4 *) savedmcodeptr) - (((u4 *) cd->mcodeptr) + 1);
-                               M_BR(disp);
-
-                       } else {
-                               savedmcodeptr = cd->mcodeptr;
-
-                               if (m->isleafmethod) {
-                                       M_MFLR(REG_ZERO);
-                                       M_AST(REG_ZERO, REG_SP, stackframesize * 4 + LA_LR_OFFSET);
-                               }
-
-                               M_MOV(REG_PV, rd->argintregs[0]);
-                               M_MOV(REG_SP, rd->argintregs[1]);
-
-                               if (m->isleafmethod)
-                                       M_MOV(REG_ZERO, rd->argintregs[2]);
-                               else
-                                       M_ALD(rd->argintregs[2],
-                                                 REG_SP, stackframesize * 4 + LA_LR_OFFSET);
-
-                               M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
-                               M_MOV(REG_ITMP1, rd->argintregs[4]);
-
-                               M_STWU(REG_SP, REG_SP, -(LA_SIZE + 6 * 4));
-                               M_AST(REG_ITMP2_XPC, REG_SP, LA_SIZE + 5 * 4);
-
-                               M_MTCTR(REG_ITMP3);
-                               M_JSR;
-                               M_MOV(REG_RESULT, REG_ITMP1_XPTR);
-
-                               M_ALD(REG_ITMP2_XPC, REG_SP, LA_SIZE + 5 * 4);
-                               M_IADD_IMM(REG_SP, LA_SIZE + 6 * 4, REG_SP);
-
-                               if (m->isleafmethod) {
-                                       /* XXX FIXME: REG_ZERO can cause problems here! */
-                                       assert(stackframesize * 4 <= 32767);
-
-                                       M_ALD(REG_ZERO, REG_SP, stackframesize * 4 + LA_LR_OFFSET);
-                                       M_MTLR(REG_ZERO);
-                               }
-
-                               disp = dseg_addaddress(cd, asm_handle_exception);
-                               M_ALD(REG_ITMP3, REG_PV, disp);
-                               M_MTCTR(REG_ITMP3);
-                               M_RTS;
-                       }
-               }
-
-
-               /* generate code patching stub call code */
-
-               for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
-                       /* check code segment size */
-
-                       MCODECHECK(16);
-
-                       /* Get machine code which is patched back in later. The
-                          call is 1 instruction word long. */
-
-                       tmpmcodeptr = (u1 *) (cd->mcodebase + pref->branchpos);
-
-                       mcode = *((u4 *) tmpmcodeptr);
-
-                       /* Patch in the call to call the following code (done at
-                          compile time). */
-
-                       savedmcodeptr = cd->mcodeptr;   /* save current mcodeptr          */
-                       cd->mcodeptr  = tmpmcodeptr;    /* set mcodeptr to patch position */
-
-                       disp = ((u4 *) savedmcodeptr) - (((u4 *) tmpmcodeptr) + 1);
-                       M_BR(disp);
-
-                       cd->mcodeptr = savedmcodeptr;   /* restore the current mcodeptr   */
-
-                       /* create stack frame - keep stack 16-byte aligned */
-
-                       M_AADD_IMM(REG_SP, -8 * 4, REG_SP);
-
-                       /* calculate return address and move it onto the stack */
-
-                       M_LDA(REG_ITMP3, REG_PV, pref->branchpos);
-                       M_AST_INTERN(REG_ITMP3, REG_SP, 5 * 4);
-
-                       /* move pointer to java_objectheader onto stack */
-
-#if defined(ENABLE_THREADS)
-                       /* order reversed because of data segment layout */
-
-                       (void) dseg_addaddress(cd, NULL);                         /* flcword    */
-                       (void) dseg_addaddress(cd, lock_get_initial_lock_word()); /* monitorPtr */
-                       disp = dseg_addaddress(cd, NULL);                         /* vftbl      */
-
-                       M_LDA(REG_ITMP3, REG_PV, disp);
-                       M_AST_INTERN(REG_ITMP3, REG_SP, 4 * 4);
-#else
-                       /* do nothing */
-#endif
-
-                       /* move machine code onto stack */
-
-                       disp = dseg_adds4(cd, mcode);
-                       M_ILD(REG_ITMP3, REG_PV, disp);
-                       M_IST_INTERN(REG_ITMP3, REG_SP, 3 * 4);
-
-                       /* move class/method/field reference onto stack */
-
-                       disp = dseg_addaddress(cd, pref->ref);
-                       M_ALD(REG_ITMP3, REG_PV, disp);
-                       M_AST_INTERN(REG_ITMP3, REG_SP, 2 * 4);
-
-                       /* move data segment displacement onto stack */
-
-                       disp = dseg_addaddress(cd, pref->disp);
-                       M_ILD(REG_ITMP3, REG_PV, disp);
-                       M_IST_INTERN(REG_ITMP3, REG_SP, 1 * 4);
-
-                       /* move patcher function pointer onto stack */
-
-                       disp = dseg_addaddress(cd, pref->patcher);
-                       M_ALD(REG_ITMP3, REG_PV, disp);
-                       M_AST_INTERN(REG_ITMP3, REG_SP, 0 * 4);
-
-                       disp = dseg_addaddress(cd, asm_wrapper_patcher);
-                       M_ALD(REG_ITMP3, REG_PV, disp);
-                       M_MTCTR(REG_ITMP3);
-                       M_RTS;
-               }
-
-               /* generate replacement-out stubs */
-
-               {
-                       int i;
-
-                       replacementpoint = jd->code->rplpoints;
-
-                       for (i = 0; i < jd->code->rplpointcount; ++i, ++replacementpoint) {
-                               /* check code segment size */
-
-                               MCODECHECK(100);
-
-                               /* note start of stub code */
-
-                               replacementpoint->outcode = (u1 *) (cd->mcodeptr - cd->mcodebase);
-
-                               /* make machine code for patching */
-
-                               tmpmcodeptr  = cd->mcodeptr;
-                               cd->mcodeptr = (u1 *) &(replacementpoint->mcode) + 1 /* big-endian */;
-
-                               disp = (ptrint)((s4*)replacementpoint->outcode - (s4*)replacementpoint->pc) - 1;
-                               M_BR(disp);
-
-                               cd->mcodeptr = tmpmcodeptr;
-
-                               /* create stack frame - keep 16-byte aligned */
-
-                               M_AADD_IMM(REG_SP, -4 * 4, REG_SP);
-
-                               /* push address of `rplpoint` struct */
-
-                               disp = dseg_addaddress(cd, replacementpoint);
-                               M_ALD(REG_ITMP3, REG_PV, disp);
-                               M_AST_INTERN(REG_ITMP3, REG_SP, 0 * 4);
-
-                               /* jump to replacement function */
-
-                               disp = dseg_addaddress(cd, asm_replacement_out);
-                               M_ALD(REG_ITMP3, REG_PV, disp);
-                               M_MTCTR(REG_ITMP3);
-                               M_RTS;
-                       }
-               }
-       }
+       emit_exception_stubs(jd);
+       emit_patcher_stubs(jd);
+       emit_replacement_stubs(jd);
 
        codegen_finish(jd);
 
@@ -3675,7 +3486,7 @@ gen_method:
        
 *******************************************************************************/
 
-#define COMPILERSTUB_DATASIZE    2 * SIZEOF_VOID_P
+#define COMPILERSTUB_DATASIZE    3 * SIZEOF_VOID_P
 #define COMPILERSTUB_CODESIZE    4 * 4
 
 #define COMPILERSTUB_SIZE        COMPILERSTUB_DATASIZE + COMPILERSTUB_CODESIZE
@@ -3685,6 +3496,7 @@ u1 *createcompilerstub(methodinfo *m)
 {
        u1          *s;                     /* memory to hold the stub            */
        ptrint      *d;
+       codeinfo    *code;
        codegendata *cd;
        s4           dumpsize;
 
@@ -3702,14 +3514,17 @@ u1 *createcompilerstub(methodinfo *m)
        cd = DNEW(codegendata);
        cd->mcodeptr = s;
 
-       /* Store the methodinfo* in the same place as in the methodheader
-          for compiled methods. */
+       /* Store the codeinfo pointer in the same place as in the
+          methodheader for compiled methods. */
+
+       code = code_codeinfo_new(m);
 
        d[0] = (ptrint) asm_call_jit_compiler;
        d[1] = (ptrint) m;
+       d[2] = (ptrint) code;
 
-       M_ALD_INTERN(REG_ITMP1, REG_PV, -1 * SIZEOF_VOID_P);
-       M_ALD_INTERN(REG_PV, REG_PV, -2 * SIZEOF_VOID_P);
+       M_ALD_INTERN(REG_ITMP1, REG_PV, -2 * SIZEOF_VOID_P);
+       M_ALD_INTERN(REG_PV, REG_PV, -3 * SIZEOF_VOID_P);
        M_MTCTR(REG_PV);
        M_RTS;
 
@@ -3737,9 +3552,9 @@ u1 *createcompilerstub(methodinfo *m)
 u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
 {
        methodinfo   *m;
+       codeinfo     *code;
        codegendata  *cd;
        registerdata *rd;
-       s4            stackframesize;       /* size of stackframe if needed       */
        methoddesc   *md;
        s4            nativeparams;
        s4            i, j;                 /* count variables                    */
@@ -3749,9 +3564,10 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
 
        /* get required compiler data */
 
-       m  = jd->m;
-       cd = jd->cd;
-       rd = jd->rd;
+       m    = jd->m;
+       code = jd->code;
+       cd   = jd->cd;
+       rd   = jd->rd;
 
        /* set some variables */
 
@@ -3760,43 +3576,44 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
 
        /* calculate stackframe size */
 
-       stackframesize =
+       cd->stackframesize =
                sizeof(stackframeinfo) / SIZEOF_VOID_P +
                sizeof(localref_table) / SIZEOF_VOID_P +
                4 +                             /* 4 stackframeinfo arguments (darwin)*/
                nmd->paramcount * 2 +           /* assume all arguments are doubles   */
                nmd->memuse;
 
-       stackframesize = (stackframesize + 3) & ~3; /* keep stack 16-byte aligned */
+       /* keep stack 16-byte aligned */
+
+       cd->stackframesize = (cd->stackframesize + 3) & ~3;
 
        /* create method header */
 
-       (void) dseg_addaddress(cd, m);                          /* MethodPointer  */
-       (void) dseg_adds4(cd, stackframesize * 4);              /* FrameSize      */
-       (void) dseg_adds4(cd, 0);                               /* IsSync         */
-       (void) dseg_adds4(cd, 0);                               /* IsLeaf         */
-       (void) dseg_adds4(cd, 0);                               /* IntSave        */
-       (void) dseg_adds4(cd, 0);                               /* FltSave        */
+       (void) dseg_add_unique_address(cd, code);              /* CodeinfoPointer */
+       (void) dseg_add_unique_s4(cd, cd->stackframesize * 4); /* 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         */
+       (void) dseg_add_unique_s4(cd, 0);                      /* FltSave         */
        (void) dseg_addlinenumbertablesize(cd);
-       (void) dseg_adds4(cd, 0);                               /* ExTableSize    */
+       (void) dseg_add_unique_s4(cd, 0);                      /* ExTableSize     */
 
        /* generate code */
 
        M_MFLR(REG_ZERO);
        M_AST_INTERN(REG_ZERO, REG_SP, LA_LR_OFFSET);
-       M_STWU(REG_SP, REG_SP, -(stackframesize * 4));
+       M_STWU(REG_SP, REG_SP, -(cd->stackframesize * 4));
 
-       if (opt_verbosecall)
-               /* parent_argbase == stackframesize * 4 */
-               codegen_trace_args(jd, stackframesize * 4 , true);
+       if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
+               emit_verbosecall_enter(jd);
 
        /* get function address (this must happen before the stackframeinfo) */
 
-       funcdisp = dseg_addaddress(cd, f);
+       funcdisp = dseg_add_functionptr(cd, f);
 
 #if !defined(WITH_STATIC_CLASSPATH)
        if (f == NULL) {
-               codegen_addpatchref(cd, PATCHER_resolve_native, m, funcdisp);
+               codegen_addpatchref(cd, PATCHER_resolve_native_function, m, funcdisp);
 
                if (opt_showdisassemble)
                        M_NOP;
@@ -3837,11 +3654,11 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
 
        /* create native stack info */
 
-       M_AADD_IMM(REG_SP, stackframesize * 4, rd->argintregs[0]);
+       M_AADD_IMM(REG_SP, cd->stackframesize * 4, rd->argintregs[0]);
        M_MOV(REG_PV, rd->argintregs[1]);
-       M_AADD_IMM(REG_SP, stackframesize * 4, rd->argintregs[2]);
-       M_ALD(rd->argintregs[3], REG_SP, stackframesize * 4 + LA_LR_OFFSET);
-       disp = dseg_addaddress(cd, codegen_start_native_call);
+       M_AADD_IMM(REG_SP, cd->stackframesize * 4, rd->argintregs[2]);
+       M_ALD(rd->argintregs[3], REG_SP, cd->stackframesize * 4 + LA_LR_OFFSET);
+       disp = dseg_add_functionptr(cd, codegen_start_native_call);
        M_ALD(REG_ITMP1, REG_PV, disp);
        M_MTCTR(REG_ITMP1);
        M_JSR;
@@ -3913,7 +3730,7 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
                                }
 
                        } else {
-                               s1 = md->params[i].regoff + stackframesize;
+                               s1 = md->params[i].regoff + cd->stackframesize;
                                s2 = nmd->params[j].regoff;
 
                                M_ILD(REG_ITMP1, REG_SP, s1 * 4);
@@ -3930,7 +3747,7 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
                           argument registers keep unchanged. */
 
                        if (md->params[i].inmemory) {
-                               s1 = md->params[i].regoff + stackframesize;
+                               s1 = md->params[i].regoff + cd->stackframesize;
                                s2 = nmd->params[j].regoff;
 
                                if (IS_2_WORD_TYPE(t)) {
@@ -3948,13 +3765,13 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
        /* put class into second argument register */
 
        if (m->flags & ACC_STATIC) {
-               disp = dseg_addaddress(cd, m->class);
+               disp = dseg_add_address(cd, m->class);
                M_ALD(rd->argintregs[1], REG_PV, disp);
        }
 
        /* put env into first argument register */
 
-       disp = dseg_addaddress(cd, _Jv_env);
+       disp = dseg_add_address(cd, _Jv_env);
        M_ALD(rd->argintregs[0], REG_PV, disp);
 
        /* generate the actual native call */
@@ -3963,6 +3780,11 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
        M_MTCTR(REG_ITMP3);
        M_JSR;
 
+       /* print call trace */
+
+       if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
+               emit_verbosecall_exit(jd);
+
        /* save return value */
 
        if (md->returntype.type != TYPE_VOID) {
@@ -3970,7 +3792,8 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
                        if (IS_2_WORD_TYPE(md->returntype.type))
                                M_IST(REG_RESULT2, REG_SP, LA_SIZE + 2 * 4);
                        M_IST(REG_RESULT, REG_SP, LA_SIZE + 1 * 4);
-               } else {
+               }
+               else {
                        if (IS_2_WORD_TYPE(md->returntype.type))
                                M_DST(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
                        else
@@ -3980,82 +3803,12 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
 
        /* remove native stackframe info */
 
-       M_AADD_IMM(REG_SP, stackframesize * 4, rd->argintregs[0]);
-       disp = dseg_addaddress(cd, codegen_finish_native_call);
+       M_AADD_IMM(REG_SP, cd->stackframesize * 4, rd->argintregs[0]);
+       disp = dseg_add_functionptr(cd, codegen_finish_native_call);
        M_ALD(REG_ITMP1, REG_PV, disp);
        M_MTCTR(REG_ITMP1);
        M_JSR;
-
-       /* print call trace */
-
-       if (opt_verbosecall) {
-                /* just restore the value we need, don't care about the other */
-
-               if (md->returntype.type != TYPE_VOID) {
-                       if (IS_INT_LNG_TYPE(md->returntype.type)) {
-                               if (IS_2_WORD_TYPE(md->returntype.type))
-                                       M_ILD(REG_RESULT2, REG_SP, LA_SIZE + 2 * 4);
-                               M_ILD(REG_RESULT, REG_SP, LA_SIZE + 1 * 4);
-                       } else {
-                               if (IS_2_WORD_TYPE(md->returntype.type))
-                                       M_DLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
-                               else
-                                       M_FLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
-                       }
-               }
-
-               M_LDA(REG_SP, REG_SP, -(LA_SIZE + (1 + 2 + 2 + 1) * 4));
-
-               /* keep this order */
-               switch (md->returntype.type) {
-               case TYPE_INT:
-               case TYPE_ADR:
-#if defined(__DARWIN__)
-                       M_MOV(REG_RESULT, rd->argintregs[2]);
-                       M_CLR(rd->argintregs[1]);
-#else
-                       M_MOV(REG_RESULT, rd->argintregs[3]);
-                       M_CLR(rd->argintregs[2]);
-#endif
-                       break;
-
-               case TYPE_LNG:
-#if defined(__DARWIN__)
-                       M_MOV(REG_RESULT2, rd->argintregs[2]);
-                       M_MOV(REG_RESULT, rd->argintregs[1]);
-#else
-                       M_MOV(REG_RESULT2, rd->argintregs[3]);
-                       M_MOV(REG_RESULT, rd->argintregs[2]);
-#endif
-                       break;
-               }
-
-               M_FLTMOVE(REG_FRESULT, rd->argfltregs[0]);
-               M_FLTMOVE(REG_FRESULT, rd->argfltregs[1]);
-               disp = dseg_addaddress(cd, m);
-               M_ALD(rd->argintregs[0], REG_PV, disp);
-
-               disp = dseg_addaddress(cd, builtin_displaymethodstop);
-               M_ALD(REG_ITMP2, REG_PV, disp);
-               M_MTCTR(REG_ITMP2);
-               M_JSR;
-
-               M_LDA(REG_SP, REG_SP, LA_SIZE + (1 + 2 + 2 + 1) * 4);
-       }
-
-       /* check for exception */
-
-#if defined(ENABLE_THREADS)
-       disp = dseg_addaddress(cd, builtin_get_exceptionptrptr);
-       M_ALD(REG_ITMP1, REG_PV, disp);
-       M_MTCTR(REG_ITMP1);
-       M_JSR;
-       M_MOV(REG_RESULT, REG_ITMP2);
-#else
-       disp = dseg_addaddress(cd, &_no_threads_exceptionptr);
-       M_ALD(REG_ITMP2, REG_PV, disp);
-#endif
-       M_ALD(REG_ITMP1_XPTR, REG_ITMP2, 0);/* load exception into reg. itmp1     */
+       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
 
        /* restore return value */
 
@@ -4064,7 +3817,8 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
                        if (IS_2_WORD_TYPE(md->returntype.type))
                                M_ILD(REG_RESULT2, REG_SP, LA_SIZE + 2 * 4);
                        M_ILD(REG_RESULT, REG_SP, LA_SIZE + 1 * 4);
-               } else {
+               }
+               else {
                        if (IS_2_WORD_TYPE(md->returntype.type))
                                M_DLD(REG_FRESULT, REG_SP, LA_SIZE + 1 * 4);
                        else
@@ -4072,322 +3826,33 @@ u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd)
                }
        }
 
+       M_ALD(REG_ITMP2_XPC, REG_SP, cd->stackframesize * 4 + LA_LR_OFFSET);
+       M_MTLR(REG_ITMP2_XPC);
+       M_LDA(REG_SP, REG_SP, cd->stackframesize * 4); /* remove stackframe       */
+
+       /* check for exception */
+
        M_TST(REG_ITMP1_XPTR);
-       M_BNE(4);                           /* if no exception then return        */
+       M_BNE(1);                           /* if no exception then return        */
 
-       M_ALD(REG_ZERO, REG_SP, stackframesize * 4 + LA_LR_OFFSET); /* load ra   */
-       M_MTLR(REG_ZERO);
-       M_LDA(REG_SP, REG_SP, stackframesize * 4); /* remove stackframe           */
        M_RET;
 
        /* handle exception */
 
-       M_CLR(REG_ITMP3);
-       M_AST(REG_ITMP3, REG_ITMP2, 0);     /* store NULL into exceptionptr       */
+       M_IADD_IMM(REG_ITMP2_XPC, -4, REG_ITMP2_XPC);  /* exception address       */
 
-       M_ALD(REG_ITMP2, REG_SP, stackframesize * 4 + LA_LR_OFFSET); /* load ra   */
-       M_MTLR(REG_ITMP2);
-
-       M_LDA(REG_SP, REG_SP, stackframesize * 4); /* remove stackframe           */
-
-       M_IADD_IMM(REG_ITMP2, -4, REG_ITMP2_XPC);  /* fault address               */
-
-       disp = dseg_addaddress(cd, asm_handle_nat_exception);
+       disp = dseg_add_functionptr(cd, asm_handle_nat_exception);
        M_ALD(REG_ITMP3, REG_PV, disp);
        M_MTCTR(REG_ITMP3);
        M_RTS;
 
-       /* generate patcher stub call code */
-
-       {
-               patchref *pref;
-               u4        mcode;
-               u1       *savedmcodeptr;
-               u1       *tmpmcodeptr;
-
-               for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
-                       /* Get machine code which is patched back in later. The
-                          call is 1 instruction word long. */
-
-                       tmpmcodeptr = cd->mcodebase + pref->branchpos;
-
-                       mcode = *((u4 *) tmpmcodeptr);
-
-                       /* Patch in the call to call the following code (done at
-                          compile time). */
-
-                       savedmcodeptr = cd->mcodeptr;   /* save current mcodeptr          */
-                       cd->mcodeptr  = tmpmcodeptr;    /* set mcodeptr to patch position */
-
-                       disp = ((u4 *) savedmcodeptr) - (((u4 *) tmpmcodeptr) + 1);
-                       M_BL(disp);
-
-                       cd->mcodeptr = savedmcodeptr;   /* restore the current mcodeptr   */
-
-                       /* create stack frame - keep stack 16-byte aligned */
-
-                       M_AADD_IMM(REG_SP, -8 * 4, REG_SP);
-
-                       /* move return address onto stack */
-
-                       M_MFLR(REG_ZERO);
-                       M_AST(REG_ZERO, REG_SP, 5 * 4);
-
-                       /* move pointer to java_objectheader onto stack */
-
-#if defined(ENABLE_THREADS)
-                       /* order reversed because of data segment layout */
-
-                       (void) dseg_addaddress(cd, NULL);                         /* flcword    */
-                       (void) dseg_addaddress(cd, lock_get_initial_lock_word()); /* monitorPtr */
-                       disp = dseg_addaddress(cd, NULL);                         /* vftbl      */
-
-                       M_LDA(REG_ITMP3, REG_PV, disp);
-                       M_AST(REG_ITMP3, REG_SP, 4 * 4);
-#else
-                       /* do nothing */
-#endif
-
-                       /* move machine code onto stack */
-
-                       disp = dseg_adds4(cd, mcode);
-                       M_ILD(REG_ITMP3, REG_PV, disp);
-                       M_IST(REG_ITMP3, REG_SP, 3 * 4);
-
-                       /* move class/method/field reference onto stack */
-
-                       disp = dseg_addaddress(cd, pref->ref);
-                       M_ALD(REG_ITMP3, REG_PV, disp);
-                       M_AST(REG_ITMP3, REG_SP, 2 * 4);
-
-                       /* move data segment displacement onto stack */
-
-                       disp = dseg_addaddress(cd, pref->disp);
-                       M_ILD(REG_ITMP3, REG_PV, disp);
-                       M_IST(REG_ITMP3, REG_SP, 1 * 4);
+       /* generate patcher stubs */
 
-                       /* move patcher function pointer onto stack */
-
-                       disp = dseg_addaddress(cd, pref->patcher);
-                       M_ALD(REG_ITMP3, REG_PV, disp);
-                       M_AST(REG_ITMP3, REG_SP, 0 * 4);
-
-                       disp = dseg_addaddress(cd, asm_wrapper_patcher);
-                       M_ALD(REG_ITMP3, REG_PV, disp);
-                       M_MTCTR(REG_ITMP3);
-                       M_RTS;
-               }
-       }
+       emit_patcher_stubs(jd);
 
        codegen_finish(jd);
 
-       return jd->code->entrypoint;
-}
-
-
-void codegen_trace_args(jitdata *jd, s4 stackframesize, bool nativestub)
-{
-       methodinfo   *m;
-       codegendata  *cd;
-       registerdata *rd;
-       s4 s1, p, t, d;
-       int stack_off;
-       int stack_size;
-       methoddesc *md;
-
-       /* get required compiler data */
-
-       m  = jd->m;
-       cd = jd->cd;
-       rd = jd->rd;
-
-       md = m->parseddesc;
-       
-       if (!nativestub)
-               M_MFLR(REG_ITMP3);
-       /* Build up Stackframe for builtin_trace_args call (a multiple of 16) */
-       /* For Darwin:                                                        */
-       /* LA + TRACE_ARGS_NUM u8 args + methodinfo + LR                      */
-       /* LA_SIZE(=6*4) + 8*8         + 4          + 4  + 0(Padding)         */
-       /* 6 * 4 + 8 * 8 + 2 * 4 = 12 * 8 = 6 * 16                            */
-       /* For Linux:                                                         */
-       /* LA + (TRACE_ARGS_NUM - INT_ARG_CNT/2) u8 args + methodinfo         */
-       /* + INT_ARG_CNT * 4 ( save integer registers) + LR + 8 + 8 (Padding) */
-       /* LA_SIZE(=2*4) + 4 * 8 + 4 + 8 * 4 + 4 + 8                          */
-       /* 2 * 4 + 4 * 8 + 10 * 4 + 1 * 8 + 8= 12 * 8 = 6 * 16                */
-       
-       /* in nativestubs no Place to save the LR (Link Register) would be needed */
-       /* but since the stack frame has to be aligned the 4 Bytes would have to  */
-       /* be padded again */
-
-#if defined(__DARWIN__)
-       stack_size = LA_SIZE + (TRACE_ARGS_NUM + 1) * 8;
-#else
-       stack_size = 6 * 16;
-#endif
-       M_LDA(REG_SP, REG_SP, -stack_size);
-
-       /* Save LR */
-       if (!nativestub)
-               M_IST(REG_ITMP3, REG_SP, LA_SIZE + TRACE_ARGS_NUM * 8 + 1 * 4);
-
-       M_CLR(REG_ITMP1);    /* clear help register */
-
-       /* save up to TRACE_ARGS_NUM arguments into the reserved stack space */
-#if defined(__DARWIN__)
-       /* Copy Params starting from first to Stack                          */
-       /* since TRACE_ARGS == INT_ARG_CNT all used integer argument regs    */ 
-       /* are saved                                                         */
-       p = 0;
-#else
-       /* Copy Params starting from fifth to Stack (INT_ARG_CNT/2) are in   */
-       /* integer argument regs                                             */
-       /* all integer argument registers have to be saved                   */
-       for (p = 0; p < 8; p++) {
-               d = rd->argintregs[p];
-               /* save integer argument registers */
-               M_IST(d, REG_SP, LA_SIZE + 4 * 8 + 4 + p * 4);
-       }
-       p = 4;
-#endif
-       stack_off = LA_SIZE;
-       for (; p < md->paramcount && p < TRACE_ARGS_NUM; p++, stack_off += 8) {
-               t = md->paramtypes[p].type;
-               if (IS_INT_LNG_TYPE(t)) {
-                       if (!md->params[p].inmemory) { /* Param in Arg Reg */
-                               if (IS_2_WORD_TYPE(t)) {
-                                       M_IST(rd->argintregs[GET_HIGH_REG(md->params[p].regoff)]
-                                                 , REG_SP, stack_off);
-                                       M_IST(rd->argintregs[GET_LOW_REG(md->params[p].regoff)]
-                                                 , REG_SP, stack_off + 4);
-                               } else {
-                                       M_IST(REG_ITMP1, REG_SP, stack_off);
-                                       M_IST(rd->argintregs[md->params[p].regoff]
-                                                 , REG_SP, stack_off + 4);
-                               }
-                       } else { /* Param on Stack */
-                               s1 = (md->params[p].regoff + stackframesize) * 4 
-                                       + stack_size;
-                               if (IS_2_WORD_TYPE(t)) {
-                                       M_ILD(REG_ITMP2, REG_SP, s1);
-                                       M_IST(REG_ITMP2, REG_SP, stack_off);
-                                       M_ILD(REG_ITMP2, REG_SP, s1 + 4);
-                                       M_IST(REG_ITMP2, REG_SP, stack_off + 4);
-                               } else {
-                                       M_IST(REG_ITMP1, REG_SP, stack_off);
-                                       M_ILD(REG_ITMP2, REG_SP, s1);
-                                       M_IST(REG_ITMP2, REG_SP, stack_off + 4);
-                               }
-                       }
-               } else { /* IS_FLT_DBL_TYPE(t) */
-                       if (!md->params[p].inmemory) { /* in Arg Reg */
-                               s1 = rd->argfltregs[md->params[p].regoff];
-                               if (!IS_2_WORD_TYPE(t)) {
-                                       M_IST(REG_ITMP1, REG_SP, stack_off);
-                                       M_FST(s1, REG_SP, stack_off + 4);
-                               } else {
-                                       M_DST(s1, REG_SP, stack_off);
-                               }
-                       } else { /* on Stack */
-                               /* this should not happen */
-                       }
-               }
-       }
-
-       /* load first 4 (==INT_ARG_CNT/2) arguments into integer registers */
-#if defined(__DARWIN__)
-       for (p = 0; p < 8; p++) {
-               d = rd->argintregs[p];
-               M_ILD(d, REG_SP, LA_SIZE + p * 4);
-       }
-#else
-       /* LINUX */
-       /* Set integer and float argument registers vor trace_args call */
-       /* offset to saved integer argument registers                   */
-       stack_off = LA_SIZE + 4 * 8 + 4;
-       for (p = 0; (p < 4) && (p < md->paramcount); p++) {
-               t = md->paramtypes[p].type;
-               if (IS_INT_LNG_TYPE(t)) {
-                       /* "stretch" int types */
-                       if (!IS_2_WORD_TYPE(t)) {
-                               M_CLR(rd->argintregs[2 * p]);
-                               M_ILD(rd->argintregs[2 * p + 1], REG_SP,stack_off);
-                               stack_off += 4;
-                       } else {
-                               M_ILD(rd->argintregs[2 * p + 1], REG_SP,stack_off + 4);
-                               M_ILD(rd->argintregs[2 * p], REG_SP,stack_off);
-                               stack_off += 8;
-                       }
-               } else { /* Float/Dbl */
-                       if (!md->params[p].inmemory) { /* Param in Arg Reg */
-                               /* use reserved Place on Stack (sp + 5 * 16) to copy  */
-                               /* float/double arg reg to int reg                    */
-                               s1 = rd->argfltregs[md->params[p].regoff];
-                               if (!IS_2_WORD_TYPE(t)) {
-                                       M_FST(s1, REG_SP, 5 * 16);
-                                       M_ILD(rd->argintregs[2 * p + 1], REG_SP, 5 * 16);
-                                       M_CLR(rd->argintregs[2 * p]);
-                               } else {
-                                       M_DST(s1, REG_SP, 5 * 16);
-                                       M_ILD(rd->argintregs[2 * p + 1], REG_SP,  5 * 16 + 4);
-                                       M_ILD(rd->argintregs[2 * p], REG_SP, 5 * 16);
-                               }
-                       }
-               }
-       }
-#endif
-
-       /* put methodinfo pointer on Stackframe */
-       p = dseg_addaddress(cd, m);
-       M_ALD(REG_ITMP1, REG_PV, p);
-#if defined(__DARWIN__)
-       M_AST(REG_ITMP1, REG_SP, LA_SIZE + TRACE_ARGS_NUM * 8); 
-#else
-       M_AST(REG_ITMP1, REG_SP, LA_SIZE + 4 * 8);
-#endif
-       p = dseg_addaddress(cd, builtin_trace_args);
-       M_ALD(REG_ITMP2, REG_PV, p);
-       M_MTCTR(REG_ITMP2);
-       M_JSR;
-
-#if defined(__DARWIN__)
-       /* restore integer argument registers from the reserved stack space */
-
-       stack_off = LA_SIZE;
-       for (p = 0; p < md->paramcount && p < TRACE_ARGS_NUM; 
-                p++, stack_off += 8) {
-               t = md->paramtypes[p].type;
-
-               if (IS_INT_LNG_TYPE(t)) {
-                       if (!md->params[p].inmemory) {
-                               if (IS_2_WORD_TYPE(t)) {
-                                       M_ILD(rd->argintregs[GET_HIGH_REG(md->params[p].regoff)]
-                                                 , REG_SP, stack_off);
-                                       M_ILD(rd->argintregs[GET_LOW_REG(md->params[p].regoff)]
-                                                 , REG_SP, stack_off + 4);
-                               } else {
-                                       M_ILD(rd->argintregs[md->params[p].regoff]
-                                                 , REG_SP, stack_off + 4);
-                               }
-                       }
-               }
-       }
-#else
-       /* LINUX */
-       for (p = 0; p < 8; p++) {
-               d = rd->argintregs[p];
-               /* save integer argument registers */
-               M_ILD(d, REG_SP, LA_SIZE + 4 * 8 + 4 + p * 4);
-       }
-#endif
-
-       if (!nativestub)
-               M_ILD(REG_ITMP3, REG_SP, LA_SIZE + TRACE_ARGS_NUM * 8 + 1 * 4);
-
-       M_LDA(REG_SP, REG_SP, stack_size);
-
-       if (!nativestub)
-               M_MTLR(REG_ITMP3);
+       return code->entrypoint;
 }