* src/vm/jit/parse.cpp,
[cacao.git] / src / vm / jit / powerpc64 / codegen.c
index 9f04d1c238f1af2ffb68b921f611591a7841564f..6de89aaf0b6c5c16d65127a5f882d02e4e68a968 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/powerpc64/codegen.c - machine code generator for 64-bit PowerPC
 
-   Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
-   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-   J. Wenninger, Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: codegen.c 7701 2007-04-15 00:38:00Z michi $
-
 */
 
 
 #include "config.h"
 
 #include <assert.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <signal.h>
 
 
 #include "mm/memory.h"
 
-#include "native/native.h"
+#include "native/localref.hpp"
+#include "native/native.hpp"
+
+#include "threads/lock.hpp"
 
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
+#include "vm/jit/builtin.hpp"
+#include "vm/exceptions.hpp"
 #include "vm/global.h"
-#include "vm/stringlocal.h"
-#include "vm/vm.h"
+#include "vm/loader.hpp"
+#include "vm/options.h"
+#include "vm/vm.hpp"
 
+#include "vm/jit/abi.h"
 #include "vm/jit/abi-asm.h"
-#include "vm/jit/md.h"
 #include "vm/jit/asmpart.h"
-#include "vm/jit/codegen-common.h"
+#include "vm/jit/codegen-common.hpp"
 #include "vm/jit/dseg.h"
-#include "vm/jit/emit-common.h"
-#include "vm/jit/jit.h"
-#include "vm/jit/parse.h"
-#include "vm/jit/patcher.h"
+#include "vm/jit/emit-common.hpp"
+#include "vm/jit/jit.hpp"
+#include "vm/jit/linenumbertable.hpp"
+#include "vm/jit/parse.hpp"
+#include "vm/jit/patcher-common.hpp"
 #include "vm/jit/reg.h"
-#include "vm/jit/replace.h"
-#include "vm/jit/stacktrace.h"
-
-#include "vmcore/loader.h"
-#include "vmcore/options.h"
+#include "vm/jit/replace.hpp"
+#include "vm/jit/stacktrace.hpp"
+#include "vm/jit/trap.h"
 
 #if defined(ENABLE_LSRA)
 # include "vm/jit/allocator/lsra.h"
 #endif
 
-#if defined(ENABLE_THREADS)
-# include "threads/native/lock.h"
-#endif
-
 
 /* codegen_emit ****************************************************************
 
@@ -92,7 +88,6 @@ bool codegen_emit(jitdata *jd)
        varinfo            *var;
        basicblock         *bptr;
        instruction        *iptr;
-       exception_entry    *ex;
        u2                  currentline;
        methodinfo         *lm;             /* local methodinfo for ICMD_INVOKE*  */
        unresolved_method  *um;
@@ -112,9 +107,11 @@ bool codegen_emit(jitdata *jd)
 
        /* prevent compiler warnings */
 
-       d = 0;
-       lm = NULL;
+       d   = 0;
+       lm  = NULL;
+       um  = NULL;
        bte = NULL;
+       uf  = NULL;
 
        {
        s4 i, p, t, l;
@@ -134,7 +131,7 @@ bool codegen_emit(jitdata *jd)
     /* monitor_exit. The stack position for the argument can not be shared  */
        /* with place to save the return register on PPC64, since both values     */
        /* reside in R3 */
-       if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
+       if (checksync && code_is_synchronized(code)) {
                /* reserve 2 slots for long/double return values for monitorexit */
                cd->stackframesize += 2;
        }
@@ -155,39 +152,21 @@ bool codegen_emit(jitdata *jd)
        (void) dseg_add_unique_address(cd, code);                      /* CodeinfoPointer */
        (void) dseg_add_unique_s4(cd, cd->stackframesize * 8);             /* FrameSize       */
 
-#if defined(ENABLE_THREADS)
-       /* IsSync contains the offset relative to the stack pointer for the
-          argument of monitor_exit used in the exception handler. Since the
-          offset could be zero and give a wrong meaning of the flag it is
-          offset by one.
-       */
-
-       if (checksync && (m->flags & ACC_SYNCHRONIZED))
-               (void) dseg_add_unique_s4(cd, (rd->memuse + 1) * 8);       /* IsSync          */
-       else
-#endif
-               (void) dseg_add_unique_s4(cd, 0);                          /* IsSync          */
-                                              
-       (void) dseg_add_unique_s4(cd, jd->isleafmethod);                /* IsLeaf          */
-       (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave         */
-       (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave         */
+       code->synchronizedoffset = rd->memuse * 8;
 
-       dseg_addlinenumbertablesize(cd);
+       /* REMOVEME: We still need it for exception handling in assembler. */
 
-       (void) dseg_add_unique_s4(cd, jd->exceptiontablelength);       /* ExTableSize     */
+       if (code_is_leafmethod(code))
+               (void) dseg_add_unique_s4(cd, 1);
+       else
+               (void) dseg_add_unique_s4(cd, 0);
 
-       /* create exception table */
+       (void) dseg_add_unique_s4(cd, INT_SAV_CNT - rd->savintreguse); /* IntSave         */
+       (void) dseg_add_unique_s4(cd, FLT_SAV_CNT - rd->savfltreguse); /* FltSave         */
 
-       for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
-               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.any);
-       }
-       
        /* create stack frame (if necessary) */
 
-       if (!jd->isleafmethod) {
+       if (!code_is_leafmethod(code)) {
                M_MFLR(REG_ZERO);
                M_AST(REG_ZERO, REG_SP, LA_LR_OFFSET);
        }
@@ -217,70 +196,68 @@ bool codegen_emit(jitdata *jd)
                        l++;
                if (varindex == UNUSED)
                        continue;
+
                var = VAR(varindex);
-               s1 = md->params[p].regoff;
-               if (IS_INT_LNG_TYPE(t)) {                    /* integer args          */
-                       if (!md->params[p].inmemory) {           /* register arguments    */
-                               s2 = rd->argintregs[s1];
-                               if (!IS_INMEMORY(var->flags))   {
-                                       M_INTMOVE(s2, var->vv.regoff);
-                               } else {                             /* reg arg -> spilled    */
-                                       M_LST(s2, REG_SP, var->vv.regoff * 8);
-                               } 
-                       } else {                                 /* stack arguments       */
-                               if (!IS_INMEMORY(var->flags)) {      /* stack arg -> register */
-                                       M_LLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 8);
-
-                               } else {                             /* stack arg -> spilled  */
-                                       var->vv.regoff = cd->stackframesize + s1;
-                               }
-                       }
+               s1  = md->params[p].regoff;
 
-               } else {                                     /* floating args         */
-                       if (!md->params[p].inmemory) {           /* register arguments    */
-                               s2 = rd->argfltregs[s1];
-                               if (!IS_INMEMORY(var->flags)) {      /* reg arg -> register   */
-                                       M_FLTMOVE(s2, var->vv.regoff);
-                               } else {                                         /* reg arg -> spilled    */
-                                       M_DST(s2, REG_SP, var->vv.regoff * 8);
+               if (IS_INT_LNG_TYPE(t)) {
+                       if (!md->params[p].inmemory) {
+                               if (!IS_INMEMORY(var->flags))
+                                       M_INTMOVE(s1, var->vv.regoff);
+                               else
+                                       M_LST(s1, REG_SP, var->vv.regoff);
+                       }
+                       else {
+                               if (!IS_INMEMORY(var->flags))
+                                       M_LLD(var->vv.regoff, REG_SP, cd->stackframesize * 8 + s1);
+                               else
+                                       var->vv.regoff = cd->stackframesize * 8 + s1;
+                       }
+               }
+               else {
+                       if (!md->params[p].inmemory) {
+                               if (!IS_INMEMORY(var->flags))
+                                       M_FLTMOVE(s1, var->vv.regoff);
+                               else
+                                       M_DST(s1, REG_SP, var->vv.regoff);
+                       }
+                       else {
+                               if (!(var->flags & INMEMORY)) {
+                                       if (IS_2_WORD_TYPE(t))
+                                               M_DLD(var->vv.regoff, REG_SP, cd->stackframesize * 8 + s1);
+                                       else
+                                               M_DLD(var->vv.regoff, REG_SP, cd->stackframesize * 8 + s1);
                                }
-
-                       } else {                                 /* stack arguments       */
-                               if (!(var->flags & INMEMORY)) {      /* stack-arg -> register */
-                                       if (IS_2_WORD_TYPE(t)) {
-                                               M_DLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 8);
-                                       } else {
-                                               M_DLD(var->vv.regoff, REG_SP, (cd->stackframesize + s1) * 8);
-                                       }
-                               } else {                             /* stack-arg -> spilled  */
-                                       var->vv.regoff = cd->stackframesize + s1;
-                               }
+                               else
+                                       var->vv.regoff = cd->stackframesize * 8 + s1;
                        }
                }
-       } /* end for */
+       }
 
        /* save monitorenter argument */
 
 #if defined(ENABLE_THREADS)
 
-       if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
+       if (checksync && code_is_synchronized(code)) {
 
                /* stackoffset for argument used for LOCK_monitor_exit */
                s1 = rd->memuse;
+
 #if !defined (NDEBUG)
                if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
                        M_AADD_IMM(REG_SP, -((LA_SIZE_IN_POINTERS + PA_SIZE_IN_POINTERS + ARG_CNT) * 8), REG_SP);
 
                        for (p = 0; p < INT_ARG_CNT; p++)
-                               M_LST(rd->argintregs[p], REG_SP, LA_SIZE + PA_SIZE + p * 8);
+                               M_LST(abi_registers_integer_argument[p], REG_SP, LA_SIZE + PA_SIZE + p * 8);
 
                        for (p = 0; p < FLT_ARG_CNT; p++)
-                               M_DST(rd->argfltregs[p], REG_SP, LA_SIZE + PA_SIZE + (INT_ARG_CNT + p) * 8);
+                               M_DST(abi_registers_float_argument[p], REG_SP, LA_SIZE + PA_SIZE + (INT_ARG_CNT + p) * 8);
 
                        /* used for LOCK_monitor_exit, adopt size because we created another stackframe */
                        s1 += (LA_SIZE_IN_POINTERS + PA_SIZE_IN_POINTERS + ARG_CNT);
                }
 #endif
+
                p = dseg_add_functionptr(cd, LOCK_monitor_enter);
                M_ALD(REG_ITMP3, REG_PV, p);
                M_ALD(REG_ITMP3, REG_ITMP3, 0); /* TOC */
@@ -289,24 +266,25 @@ bool codegen_emit(jitdata *jd)
                /* get or test the lock object */
 
                if (m->flags & ACC_STATIC) {
-                       p = dseg_add_address(cd, &m->class->object.header);
-                       M_ALD(rd->argintregs[0], REG_PV, p);
+                       p = dseg_add_address(cd, &m->clazz->object.header);
+                       M_ALD(REG_A0, REG_PV, p);
                }
                else {
-                       M_TST(rd->argintregs[0]);
+                       M_TST(REG_A0);
                        M_BNE(1);
-                       M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_NULLPOINTER);
+                       M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_NullPointerException);
                }
 
-               M_AST(rd->argintregs[0], REG_SP, s1 * 8);       /* rd->memuse * 8 */
+               M_AST(REG_A0, REG_SP, s1 * 8);                      /* rd->memuse * 8 */
                M_JSR;
-#if !defined (NDEBUG)
+
+#if !defined(NDEBUG)
                if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
                        for (p = 0; p < INT_ARG_CNT; p++)
-                               M_LLD(rd->argintregs[p], REG_SP, LA_SIZE + PA_SIZE + p * 8);
+                               M_LLD(abi_registers_integer_argument[p], REG_SP, LA_SIZE + PA_SIZE + p * 8);
 
                        for (p = 0; p < FLT_ARG_CNT; p++)
-                               M_DLD(rd->argfltregs[p], REG_SP, LA_SIZE + PA_SIZE + (INT_ARG_CNT + p) * 8);
+                               M_DLD(abi_registers_float_argument[p], REG_SP, LA_SIZE + PA_SIZE + (INT_ARG_CNT + p) * 8);
 
                        M_AADD_IMM(REG_SP, (LA_SIZE_IN_POINTERS + PA_SIZE_IN_POINTERS + ARG_CNT) * 8, REG_SP);
                }
@@ -318,9 +296,9 @@ bool codegen_emit(jitdata *jd)
 #if !defined (NDEBUG)
        if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
                emit_verbosecall_enter(jd);
+#endif
 
        }
-#endif
 
        /* end of header generation */
 
@@ -346,7 +324,7 @@ bool codegen_emit(jitdata *jd)
                /* copy interface registers to their destination */
 
                len = bptr->indepth;
-               MCODECHECK(64+len);
+               MCODECHECK(128+len);
 
 #if defined(ENABLE_LSRA)
                if (opt_lsra) {
@@ -387,13 +365,12 @@ bool codegen_emit(jitdata *jd)
                currentline = 0;
                        
                for (iptr = bptr->iinstr; len > 0; len--, iptr++) {
-                       bool sign_ext = false;
                        if (iptr->line != currentline) {
-                               dseg_addlinenumber(cd, iptr->line);
+                               linenumbertable_list_entry_add(cd, iptr->line);
                                currentline = iptr->line;
                        }
 
-                       MCODECHECK(64);   /* an instruction usually needs < 64 words      */
+                       MCODECHECK(128);   /* an instruction usually needs < 64 words      */
 
                switch (iptr->opc) {
                case ICMD_NOP:        /* ...  ==> ...                                 */
@@ -409,14 +386,14 @@ bool codegen_emit(jitdata *jd)
                case ICMD_INLINE_BODY:
         
                        REPLACEMENT_POINT_INLINE_BODY(cd, iptr);
-                       dseg_addlinenumber_inline_start(cd, iptr);
-                       dseg_addlinenumber(cd, iptr->line);
+                       linenumbertable_list_entry_add_inline_start(cd, iptr);
+                       linenumbertable_list_entry_add(cd, iptr->line);
                        break;
 
                case ICMD_INLINE_END:
 
-                       dseg_addlinenumber_inline_end(cd, iptr);
-                       dseg_addlinenumber(cd, iptr->line);
+                       linenumbertable_list_entry_add_inline_end(cd, iptr);
+                       linenumbertable_list_entry_add(cd, iptr->line);
                        break;
 
                case ICMD_CHECKNULL:  /* ..., objectref  ==> ..., objectref           */
@@ -465,7 +442,7 @@ bool codegen_emit(jitdata *jd)
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
                                disp = dseg_add_unique_address(cd, iptr->sx.val.c.ref);
-                               codegen_addpatchref(cd, PATCHER_aconst,
+                               patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
                                                                        iptr->sx.val.c.ref,
                                                                    disp);
                        } else  {
@@ -481,33 +458,38 @@ bool codegen_emit(jitdata *jd)
                case ICMD_ILOAD:      /* ...  ==> ..., content of local variable      */
                case ICMD_ALOAD:      /* s1.localindex = local variable               */
                case ICMD_LLOAD:
-               case ICMD_FLOAD:      /* ...  ==> ..., content of local variable      */
-               case ICMD_DLOAD:      /* ...  ==> ..., content of local variable      */
+               case ICMD_FLOAD:
+               case ICMD_DLOAD:
                case ICMD_ISTORE:     /* ..., value  ==> ...                          */
                case ICMD_LSTORE:
-               case ICMD_FSTORE:     /* ..., value  ==> ...                          */
-               case ICMD_DSTORE:     /* ..., value  ==> ...                          */
+               case ICMD_FSTORE:
+               case ICMD_DSTORE:
                case ICMD_COPY:
                case ICMD_MOVE:
 
-                       emit_copy(jd, iptr, VAROP(iptr->s1), VAROP(iptr->dst));
+                       emit_copy(jd, iptr);
                        break;
 
                case ICMD_ASTORE:
                        if (!(iptr->flags.bits & INS_FLAG_RETADDR))
-                               emit_copy(jd, iptr, VAROP(iptr->s1), VAROP(iptr->dst));
+                               emit_copy(jd, iptr);
                        break;
 
 
                /* integer operations *************************************************/
 
                case ICMD_INEG:       /* ..., value  ==> ..., - value                 */
-                       sign_ext = true;
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP1); 
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
+                       M_NEG(s1, d);
+                       M_EXTSW(d, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
                case ICMD_LNEG:    
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1); 
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        M_NEG(s1, d);
-                       if (sign_ext) M_EXTSW(d, d);
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -652,7 +634,16 @@ bool codegen_emit(jitdata *jd)
                        break;
 
                case ICMD_IDIV:
-                       sign_ext = true;
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2(jd, iptr, REG_ITMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
+                       emit_arithmetic_check(cd, iptr, s2);
+
+                       M_DIV(s1, s2, d);
+                       M_EXTSW(d, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
                case ICMD_LDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
@@ -663,18 +654,28 @@ bool codegen_emit(jitdata *jd)
                        M_DIV(s1, s2, d);
                        /* we need to test if divident was 0x8000000000000, bit OV is set in XER in this case */
                        /* we only need to check this if we did a LDIV, not for IDIV */
-                       if (!sign_ext)  {
-                               M_MFXER(REG_ITMP2);
-                               M_ANDIS(REG_ITMP2, 0x4000, REG_ITMP2);  /* test OV */
-                               M_BLE(1);
-                               M_MOV(s1, d);                           /* java specs says result == dividend */
-                       }
-                       if (sign_ext) M_EXTSW(d, d);
+                       M_MFXER(REG_ITMP2);
+                       M_ANDIS(REG_ITMP2, 0x4000, REG_ITMP2);  /* test OV */
+                       M_BLE(1);
+                       M_MOV(s1, d);                           /* java specs says result == dividend */
                        emit_store_dst(jd, iptr, d);
                        break;
 
                case ICMD_IREM:
-                       sign_ext = true;
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2(jd, iptr, REG_ITMP2);
+                       emit_arithmetic_check(cd, iptr, s2);
+
+                       M_DIV(s1, s2,  REG_ITMP3);      
+                       M_MUL(REG_ITMP3, s2, REG_ITMP2);
+                       M_SUB(s1, REG_ITMP2,  REG_ITMP3);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
+
+                       M_MOV(REG_ITMP3, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
+
                case ICMD_LREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
@@ -683,30 +684,34 @@ bool codegen_emit(jitdata *jd)
                        M_DIV(s1, s2,  REG_ITMP3);      
                        /* we need to test if divident was 0x8000000000000, bit OV is set in XER in this case */
                        /* we only need to check this if we did a LDIV, not for IDIV */
-                       if (!sign_ext)  {
-                               M_MFXER(REG_ITMP2);
-                               M_ANDIS(REG_ITMP2, 0x4000, REG_ITMP2);  /* test OV */
-                               M_BLE(2); 
-                               LCONST(REG_ITMP3, 0);                   /* result == 0 in this case */
-                               M_BR(2);
-                       }
+                       M_MFXER(REG_ITMP2);
+                       M_ANDIS(REG_ITMP2, 0x4000, REG_ITMP2);  /* test OV */
+                       M_BLE(2); 
+                       LCONST(REG_ITMP3, 0);                   /* result == 0 in this case */
+                       M_BR(2);
                        M_MUL(REG_ITMP3, s2, REG_ITMP2);
                        M_SUB(s1, REG_ITMP2,  REG_ITMP3);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
 
                        M_MOV(REG_ITMP3, d);
-                       emit_store_dst(jd, iptr, REG_ITMP1);
+                       emit_store_dst(jd, iptr, d);
                        break;
 
                
                case ICMD_IMUL:       /* ..., val1, val2  ==> ..., val1 * val2        */
-                       sign_ext = true;
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2(jd, iptr, REG_ITMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
+                       M_MUL(s1, s2, d);
+                       M_EXTSW(d, d);
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
                case ICMD_LMUL:
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        M_MUL(s1, s2, d);
-                       if (sign_ext) M_EXTSW(d, d);
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -742,6 +747,7 @@ bool codegen_emit(jitdata *jd)
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
                        M_SRA_IMM(s1, iptr->sx.val.i, d);
                        M_ADDZE(d, d);
+                       M_EXTSW(d, d);
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -794,6 +800,7 @@ bool codegen_emit(jitdata *jd)
                        M_MOV(s1, REG_ITMP1);
                        M_CLR_HIGH(REG_ITMP1);
                        M_SRL(REG_ITMP1, REG_ITMP2, d);
+                       M_EXTSW(d,d);   /* for the case it was shift 0 bits */
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -856,8 +863,15 @@ bool codegen_emit(jitdata *jd)
                        break;
 
                case ICMD_IAND:       /* ..., val1, val2  ==> ..., val1 & val2        */
-               case ICMD_LAND:
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2(jd, iptr, REG_ITMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
+                       M_AND(s1, s2, d);
+/*                     M_EXTSW(d, d);*/
+                       emit_store_dst(jd, iptr, d);
+                       break;
 
+               case ICMD_LAND:
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
@@ -921,9 +935,10 @@ bool codegen_emit(jitdata *jd)
                        
                        M_MOV(s1, REG_ITMP2);
                        M_CMPI(s1, 0);
-                       M_BGE(1 + 2*(iptr->sx.val.i >= 32768));
+                       M_BGE(1 + 3*(iptr->sx.val.i >= 32768));
                        if (iptr->sx.val.i >= 32768) {
                                M_ADDIS(REG_ZERO, iptr->sx.val.i >> 16, REG_ITMP2);
+                               M_EXTSW(REG_ITMP2, REG_ITMP2);
                                M_OR_IMM(REG_ITMP2, iptr->sx.val.i, REG_ITMP2);
                                M_IADD(s1, REG_ITMP2, REG_ITMP2);
                        } else {
@@ -942,6 +957,14 @@ bool codegen_emit(jitdata *jd)
 #endif
 
                case ICMD_IOR:        /* ..., val1, val2  ==> ..., val1 | val2        */
+                       s1 = emit_load_s1(jd, iptr, REG_ITMP1);
+                       s2 = emit_load_s2(jd, iptr, REG_ITMP2);
+                       d = codegen_reg_of_dst(jd, iptr, REG_ITMP3);
+                       M_OR(s1, s2, d);
+/*                     M_EXTSW(d,d);*/
+                       emit_store_dst(jd, iptr, d);
+                       break;
+
                case ICMD_LOR:
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
@@ -1157,7 +1180,6 @@ bool codegen_emit(jitdata *jd)
                case ICMD_FCMPL:      /* ..., val1, val2  ==> ..., val1 fcmpg val2    */
                case ICMD_DCMPL:      /* == => 0, < => 1, > => -1                     */
 
-
                        s1 = emit_load_s1(jd, iptr, REG_FTMP1);
                        s2 = emit_load_s2(jd, iptr, REG_FTMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP1);
@@ -1186,109 +1208,8 @@ bool codegen_emit(jitdata *jd)
                        M_IADD_IMM(REG_ZERO, -1, d);
                        emit_store_dst(jd, iptr, d);
                        break;
-                       
-               case ICMD_IF_FCMPEQ:    /* ..., value, value ==> ...                  */
-               case ICMD_IF_DCMPEQ:
-
-                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
-                       s2 = emit_load_s2(jd, iptr, REG_FTMP2);
-                       M_FCMPU(s1, s2);
-                       M_BNAN(1);
-                       emit_beq(cd, iptr->dst.block);
-                       break;
-
-               case ICMD_IF_FCMPNE:    /* ..., value, value ==> ...                  */
-               case ICMD_IF_DCMPNE:
-
-                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
-                       s2 = emit_load_s2(jd, iptr, REG_FTMP2);
-                       M_FCMPU(s1, s2);
-                       emit_bnan(cd, iptr->dst.block);
-                       emit_bne(cd, iptr->dst.block);
-                       break;
-
-
-               case ICMD_IF_FCMPL_LT:  /* ..., value, value ==> ...                  */
-               case ICMD_IF_DCMPL_LT:
-
-                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
-                       s2 = emit_load_s2(jd, iptr, REG_FTMP2);
-                       M_FCMPU(s1, s2);
-                       emit_bnan(cd, iptr->dst.block);
-                       emit_blt(cd, iptr->dst.block);
-                       break;
-
-               case ICMD_IF_FCMPL_GT:  /* ..., value, value ==> ...                  */
-               case ICMD_IF_DCMPL_GT:
-
-                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
-                       s2 = emit_load_s2(jd, iptr, REG_FTMP2);
-                       M_FCMPU(s1, s2);
-                       M_BNAN(1);
-                       emit_bgt(cd, iptr->dst.block);
-                       break;
-
-               case ICMD_IF_FCMPL_LE:  /* ..., value, value ==> ...                  */
-               case ICMD_IF_DCMPL_LE:
-
-                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
-                       s2 = emit_load_s2(jd, iptr, REG_FTMP2);
-                       M_FCMPU(s1, s2);
-                       emit_bnan(cd, iptr->dst.block);
-                       emit_ble(cd, iptr->dst.block);
-                       break;
-
-               case ICMD_IF_FCMPL_GE:  /* ..., value, value ==> ...                  */
-               case ICMD_IF_DCMPL_GE:
-
-                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
-                       s2 = emit_load_s2(jd, iptr, REG_FTMP2);
-                       M_FCMPU(s1, s2);
-                       M_BNAN(1);
-                       emit_bge(cd, iptr->dst.block);
-                       break;
-
-               case ICMD_IF_FCMPG_LT:  /* ..., value, value ==> ...                  */
-               case ICMD_IF_DCMPG_LT:
-
-                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
-                       s2 = emit_load_s2(jd, iptr, REG_FTMP2);
-                       M_FCMPU(s1, s2);
-                       M_BNAN(1);
-                       emit_blt(cd, iptr->dst.block);
-                       break;
-
-               case ICMD_IF_FCMPG_GT:  /* ..., value, value ==> ...                  */
-               case ICMD_IF_DCMPG_GT:
-
-                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
-                       s2 = emit_load_s2(jd, iptr, REG_FTMP2);
-                       M_FCMPU(s1, s2);
-                       emit_bnan(cd, iptr->dst.block);
-                       emit_bgt(cd, iptr->dst.block);
-                       break;
-
-               case ICMD_IF_FCMPG_LE:  /* ..., value, value ==> ...                  */
-               case ICMD_IF_DCMPG_LE:
-
-                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
-                       s2 = emit_load_s2(jd, iptr, REG_FTMP2);
-                       M_FCMPU(s1, s2);
-                       M_BNAN(1);
-                       emit_ble(cd, iptr->dst.block);
-                       break;
-
-               case ICMD_IF_FCMPG_GE:  /* ..., value, value ==> ...                  */
-               case ICMD_IF_DCMPG_GE:
-
-                       s1 = emit_load_s1(jd, iptr, REG_FTMP1);
-                       s2 = emit_load_s2(jd, iptr, REG_FTMP2);
-                       M_FCMPU(s1, s2);
-                       emit_bnan(cd, iptr->dst.block);
-                       emit_bge(cd, iptr->dst.block);
-                       break;
-
 
+                       
                /* memory operations **************************************************/
 
                case ICMD_ARRAYLENGTH: /* ..., arrayref  ==> ..., length              */
@@ -1296,7 +1217,7 @@ bool codegen_emit(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        emit_nullpointer_check(cd, iptr, s1);
-                       M_ILD(d, s1, OFFSET(java_arrayheader, size));
+                       M_ILD(d, s1, OFFSET(java_array_t, size));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1306,7 +1227,7 @@ bool codegen_emit(jitdata *jd)
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
-                       M_IADD_IMM(s2, OFFSET(java_bytearray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(s2, OFFSET(java_bytearray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_LBZX(d, s1, REG_ITMP2);
                        M_BSEXT(d, d);
@@ -1320,7 +1241,7 @@ bool codegen_emit(jitdata *jd)
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_SLL_IMM(s2, 1, REG_ITMP2);
-                       M_IADD_IMM(REG_ITMP2, OFFSET(java_chararray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(REG_ITMP2, OFFSET(java_chararray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_LHZX(d, s1, REG_ITMP2);
                        emit_store_dst(jd, iptr, d);
@@ -1333,7 +1254,7 @@ bool codegen_emit(jitdata *jd)
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_SLL_IMM(s2, 1, REG_ITMP2);
-                       M_IADD_IMM(REG_ITMP2, OFFSET(java_shortarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(REG_ITMP2, OFFSET(java_shortarray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_LHAX(d, s1, REG_ITMP2);
                        emit_store_dst(jd, iptr, d);
@@ -1346,7 +1267,7 @@ bool codegen_emit(jitdata *jd)
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_SLL_IMM(s2, 2, REG_ITMP2);
-                       M_IADD_IMM(REG_ITMP2, OFFSET(java_intarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(REG_ITMP2, OFFSET(java_intarray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_LWAX(d, s1, REG_ITMP2);
                        emit_store_dst(jd, iptr, d);
@@ -1361,7 +1282,7 @@ bool codegen_emit(jitdata *jd)
                        M_SLL_IMM(s2, 3, REG_ITMP2);
                        M_IADD(s1, REG_ITMP2, REG_ITMP2);
                        /* implicit null-pointer check */
-                       M_LLD_INTERN(d, REG_ITMP2, OFFSET(java_longarray, data[0]));
+                       M_LLD_INTERN(d, REG_ITMP2, OFFSET(java_longarray_t, data[0]));
                        emit_store_dst(jd, iptr, d);
                        break;
 
@@ -1372,7 +1293,7 @@ bool codegen_emit(jitdata *jd)
                        d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_SLL_IMM(s2, 2, REG_ITMP2);
-                       M_IADD_IMM(REG_ITMP2, OFFSET(java_floatarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(REG_ITMP2, OFFSET(java_floatarray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_LFSX(d, s1, REG_ITMP2);
                        emit_store_dst(jd, iptr, d);
@@ -1385,7 +1306,7 @@ bool codegen_emit(jitdata *jd)
                        d = codegen_reg_of_dst(jd, iptr, REG_FTMP1);
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_SLL_IMM(s2, 3, REG_ITMP2);
-                       M_IADD_IMM(REG_ITMP2, OFFSET(java_doublearray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(REG_ITMP2, OFFSET(java_doublearray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_LFDX(d, s1, REG_ITMP2);
                        emit_store_dst(jd, iptr, d);
@@ -1398,7 +1319,7 @@ bool codegen_emit(jitdata *jd)
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        M_SLL_IMM(s2, 3, REG_ITMP2);
-                       M_IADD_IMM(REG_ITMP2, OFFSET(java_objectarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(REG_ITMP2, OFFSET(java_objectarray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_ALDX(d, s1, REG_ITMP2);
                        emit_store_dst(jd, iptr, d);
@@ -1411,7 +1332,7 @@ bool codegen_emit(jitdata *jd)
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
-                       M_IADD_IMM(s2, OFFSET(java_bytearray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(s2, OFFSET(java_bytearray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_STBX(s3, s1, REG_ITMP2);
                        break;
@@ -1423,7 +1344,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
                        M_SLL_IMM(s2, 1, REG_ITMP2);
-                       M_IADD_IMM(REG_ITMP2, OFFSET(java_chararray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(REG_ITMP2, OFFSET(java_chararray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_STHX(s3, s1, REG_ITMP2);
                        break;
@@ -1435,7 +1356,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
                        M_SLL_IMM(s2, 1, REG_ITMP2);
-                       M_IADD_IMM(REG_ITMP2, OFFSET(java_shortarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(REG_ITMP2, OFFSET(java_shortarray_t, data[0]), REG_ITMP2);
                        M_STHX(s3, s1, REG_ITMP2);
                        break;
 
@@ -1446,7 +1367,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
                        M_SLL_IMM(s2, 2, REG_ITMP2);
-                       M_IADD_IMM(REG_ITMP2, OFFSET(java_intarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(REG_ITMP2, OFFSET(java_intarray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_STWX(s3, s1, REG_ITMP2);
                        break;
@@ -1458,7 +1379,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
                        M_SLL_IMM(s2, 3, REG_ITMP2);
-                       M_IADD_IMM(REG_ITMP2, OFFSET(java_longarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(REG_ITMP2, OFFSET(java_longarray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_LSTX(s3, s1, REG_ITMP2);
                        break;
@@ -1470,7 +1391,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        s3 = emit_load_s3(jd, iptr, REG_FTMP3);
                        M_SLL_IMM(s2, 2, REG_ITMP2);
-                       M_IADD_IMM(REG_ITMP2, OFFSET(java_floatarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(REG_ITMP2, OFFSET(java_floatarray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_STFSX(s3, s1, REG_ITMP2);
                        break;
@@ -1482,7 +1403,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        s3 = emit_load_s3(jd, iptr, REG_FTMP3);
                        M_SLL_IMM(s2, 3, REG_ITMP2);
-                       M_IADD_IMM(REG_ITMP2, OFFSET(java_doublearray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(REG_ITMP2, OFFSET(java_doublearray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_STFDX(s3, s1, REG_ITMP2);
                        break;
@@ -1494,7 +1415,7 @@ bool codegen_emit(jitdata *jd)
                        emit_arrayindexoutofbounds_check(cd, iptr, s1, s2);
                        s3 = emit_load_s3(jd, iptr, REG_A1);
 
-                       disp = dseg_add_functionptr(cd, BUILTIN_canstore);
+                       disp = dseg_add_functionptr(cd, BUILTIN_FAST_canstore);
                        M_ALD(REG_ITMP3, REG_PV, disp);
                        M_ALD(REG_ITMP3, REG_ITMP3, 0); /* TOC */
                        M_MTCTR(REG_ITMP3);
@@ -1503,13 +1424,13 @@ bool codegen_emit(jitdata *jd)
                        M_INTMOVE(s3, REG_A1);
 
                        M_JSR;
-                       emit_exception_check(cd, iptr);
+                       emit_arraystore_check(cd, iptr);
 
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        s2 = emit_load_s2(jd, iptr, REG_ITMP2);
                        s3 = emit_load_s3(jd, iptr, REG_ITMP3);
                        M_SLL_IMM(s2, 3, REG_ITMP2);
-                       M_IADD_IMM(REG_ITMP2, OFFSET(java_objectarray, data[0]), REG_ITMP2);
+                       M_IADD_IMM(REG_ITMP2, OFFSET(java_objectarray_t, data[0]), REG_ITMP2);
                        /* implicit null-pointer check */
                        M_ASTX(s3, s1, REG_ITMP2);
                        break;
@@ -1518,22 +1439,21 @@ bool codegen_emit(jitdata *jd)
                case ICMD_GETSTATIC:  /* ...  ==> ..., value                          */
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               uf = iptr->sx.s23.s3.uf;
-
+                               uf        = iptr->sx.s23.s3.uf;
                                fieldtype = uf->fieldref->parseddesc.fd->type;
-                               disp = dseg_add_unique_address(cd, NULL);
+                               disp      = dseg_add_unique_address(cd, NULL);
 
-                               codegen_addpatchref(cd, PATCHER_get_putstatic,
+                               patcher_add_patch_ref(jd, PATCHER_get_putstatic,
                                                                        iptr->sx.s23.s3.uf, disp);
 
-                       } else {
-                               fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
-
+                       }
+                       else {
+                               fi        = iptr->sx.s23.s3.fmiref->p.field;
                                fieldtype = fi->type;
-                               disp = dseg_add_address(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);
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) {
+                                       patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->clazz, disp);
                                }
                        }
 
@@ -1567,21 +1487,20 @@ bool codegen_emit(jitdata *jd)
 
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               uf = iptr->sx.s23.s3.uf;
-
+                               uf        = iptr->sx.s23.s3.uf;
                                fieldtype = uf->fieldref->parseddesc.fd->type;
-                               disp = dseg_add_unique_address(cd, NULL);
+                               disp      = dseg_add_unique_address(cd, NULL);
 
-                               codegen_addpatchref(cd, PATCHER_get_putstatic,
+                               patcher_add_patch_ref(jd, PATCHER_get_putstatic,
                                                                        iptr->sx.s23.s3.uf, disp);
-                       } else {
-                               fieldinfo *fi = iptr->sx.s23.s3.fmiref->p.field;
-
+                       }
+                       else {
+                               fi        = iptr->sx.s23.s3.fmiref->p.field;
                                fieldtype = fi->type;
-                               disp = dseg_add_address(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);
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->clazz)) {
+                                       patcher_add_patch_ref(jd, PATCHER_initialize_class, fi->clazz, disp);
                                }
                        }
 
@@ -1616,15 +1535,16 @@ bool codegen_emit(jitdata *jd)
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               uf = iptr->sx.s23.s3.uf;
+                               uf        = iptr->sx.s23.s3.uf;
                                fieldtype = uf->fieldref->parseddesc.fd->type;
-                               disp = 0;
+                               disp      = 0;
 
-                               codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
-                       } else {
-                               fi = iptr->sx.s23.s3.fmiref->p.field;
+                               patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
+                       }
+                       else {
+                               fi        = iptr->sx.s23.s3.fmiref->p.field;
                                fieldtype = fi->type;
-                               disp = fi->offset;
+                               disp      = fi->offset;
                        }
 
                        /* implicit null-pointer check */
@@ -1675,7 +1595,7 @@ bool codegen_emit(jitdata *jd)
                                s2 = emit_load_s2(jd, iptr, REG_FTMP2);
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               codegen_addpatchref(cd, PATCHER_get_putfield, uf, 0);
+                               patcher_add_patch_ref(jd, PATCHER_get_putfield, uf, 0);
                        }
 
 
@@ -1709,7 +1629,7 @@ bool codegen_emit(jitdata *jd)
 
 #ifdef ENABLE_VERIFIER
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               codegen_addpatchref(cd, PATCHER_athrow_areturn,
+                               patcher_add_patch_ref(jd, PATCHER_resolve_class,
                                                                        iptr->sx.s23.s2.uc, 0);
                        }
 #endif /* ENABLE_VERIFIER */
@@ -1718,12 +1638,16 @@ bool codegen_emit(jitdata *jd)
                        M_ALD(REG_ITMP2, REG_PV, disp);
                        M_MTCTR(REG_ITMP2);
 
-                       if (jd->isleafmethod) M_MFLR(REG_ITMP3);         /* save LR        */
+                       if (code_is_leafmethod(code))
+                               M_MFLR(REG_ITMP3);                          /* save LR        */
+
                        M_BL(0);                                        /* get current PC */
                        M_MFLR(REG_ITMP2_XPC);
-                       if (jd->isleafmethod) M_MTLR(REG_ITMP3);         /* restore LR     */
-                       M_RTS;                                          /* jump to CTR    */
 
+                       if (code_is_leafmethod(code))
+                               M_MTLR(REG_ITMP3);                          /* restore LR     */
+
+                       M_RTS;                                          /* jump to CTR    */
                        ALIGNCODENOP;
                        break;
 
@@ -1882,7 +1806,7 @@ bool codegen_emit(jitdata *jd)
 
 #ifdef ENABLE_VERIFIER
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               codegen_addpatchref(cd, PATCHER_athrow_areturn,
+                               patcher_add_patch_ref(jd, PATCHER_resolve_class,
                                                                        iptr->sx.s23.s2.uc, 0);
                        }
 #endif /* ENABLE_VERIFIER */
@@ -1910,13 +1834,12 @@ nowperformreturn:
                        /* call trace function */
 
 #if !defined(NDEBUG)
-                       if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
+                       if (JITDATA_HAS_FLAG_VERBOSECALL(jd))
                                emit_verbosecall_exit(jd);
-                       }
 #endif         
 
 #if defined(ENABLE_THREADS)
-                       if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
+                       if (checksync && code_is_synchronized(code)) {
                                disp = dseg_add_functionptr(cd, LOCK_monitor_exit);
                                M_ALD(REG_ITMP3, REG_PV, disp);
                                M_ALD(REG_ITMP3, REG_ITMP3, 0); /* TOC */
@@ -1939,7 +1862,7 @@ nowperformreturn:
                                        break;
                                }
 
-                               M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 8);
+                               M_ALD(REG_A0, REG_SP, rd->memuse * 8);
                                M_JSR;
 
                                /* and now restore the proper return value */
@@ -1963,7 +1886,7 @@ nowperformreturn:
 
                        /* restore return address                                         */
 
-                       if (!jd->isleafmethod) {
+                       if (!code_is_leafmethod(code)) {
                                /* ATTENTION: Don't use REG_ZERO (r0) here, as M_ALD
                                   may have a displacement overflow. */
 
@@ -2049,7 +1972,7 @@ nowperformreturn:
 
                        i = iptr->sx.s23.s2.lookupcount;
                        
-                       MCODECHECK((i<<2)+8);
+                       MCODECHECK((i<<3)+8);
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        while (--i >= 0) {
                                val = lookup->value;
@@ -2099,56 +2022,60 @@ nowperformreturn:
 gen_method:
                        s3 = md->paramcount;
 
-                       MCODECHECK((s3 << 1) + 64);
+                       MCODECHECK((s3 << 2) + 128);
 
                        /* copy arguments to registers or stack location */
 
                        for (s3 = s3 - 1; s3 >= 0; s3--) {
                                var = VAR(iptr->sx.s23.s2.args[s3]);
+                               d   = md->params[s3].regoff;
 
                                if (var->flags & PREALLOC)
                                        continue;
 
                                if (IS_INT_LNG_TYPE(var->type)) {
                                        if (!md->params[s3].inmemory) {
-                                               s1 = rd->argintregs[md->params[s3].regoff];
-                                               d = emit_load(jd, iptr, var, s1);
-                                               M_LNGMOVE(d, s1);
-                                       } else {
-                                               d = emit_load(jd, iptr, var, REG_ITMP1);
-                                               M_LST(d, REG_SP, md->params[s3].regoff * 8);
+                                               s1 = emit_load(jd, iptr, var, d);
+                                               M_LNGMOVE(s1, d);
                                        }
-                               } else {
+                                       else {
+                                               s1 = emit_load(jd, iptr, var, REG_ITMP1);
+                                               M_LST(s1, REG_SP, d);
+                                       }
+                               }
+                               else {
                                        if (!md->params[s3].inmemory) {
-                                               s1 = rd->argfltregs[md->params[s3].regoff];
-                                               d = emit_load(jd, iptr, var, s1);
-                                               M_FLTMOVE(d, s1);
-                                       else {
-                                               d = emit_load(jd, iptr, var, REG_FTMP1);
-                                               M_DST(d, REG_SP, md->params[s3].regoff * 8);
+                                               s1 = emit_load(jd, iptr, var, d);
+                                               M_FLTMOVE(s1, d);
+                                       }
+                                       else {
+                                               s1 = emit_load(jd, iptr, var, REG_FTMP1);
+                                               M_DST(s1, REG_SP, d);
                                        }
                                }
-                       } /* end of for */
+                       }
 
                        switch (iptr->opc) {
                        case ICMD_BUILTIN:
-                               disp = dseg_add_functionptr(cd, bte->fp);
-                               M_ALD(REG_PV, REG_PV, disp);
-                               M_ALD(REG_PV, REG_PV, 0);       /* TOC */
+                               if (bte->stub == NULL) {
+                                       disp = dseg_add_functionptr(cd, bte->fp);
+                                       M_ALD(REG_PV, REG_PV, disp);
+                                       M_ALD(REG_PV, REG_PV, 0);       /* TOC */
+                               }
+                               else {
+                                       disp = dseg_add_functionptr(cd, bte->stub);
+                                       M_ALD(REG_PV, REG_PV, disp);
+                               }
 
                                /* generate the actual call */
-                               REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
                                M_MTCTR(REG_PV);
                                M_JSR;
                                REPLACEMENT_POINT_INVOKE_RETURN(cd, iptr);
                                disp = (s4) (cd->mcodeptr - cd->mcodebase);
                                M_MFLR(REG_ITMP1);
                                M_LDA(REG_PV, REG_ITMP1, -disp);
-
-                               emit_exception_check(cd, iptr);
                                break;
 
-
                        case ICMD_INVOKESPECIAL:
                                emit_nullpointer_check(cd, iptr, REG_A0);
                                /* fall through */
@@ -2157,7 +2084,7 @@ gen_method:
                                if (lm == NULL) {
                                        disp = dseg_add_unique_address(cd, um);
 
-                                       codegen_addpatchref(cd, PATCHER_invokestatic_special,
+                                       patcher_add_patch_ref(jd, PATCHER_invokestatic_special,
                                                                                um, disp);
                                } else {
                                        disp = dseg_add_address(cd, lm->stubroutine);
@@ -2172,11 +2099,11 @@ gen_method:
                                disp = (s4) (cd->mcodeptr - cd->mcodebase);
                                M_MFLR(REG_ITMP1);
                                M_LDA(REG_PV, REG_ITMP1, -disp);
-
                                break;
+
                        case ICMD_INVOKEVIRTUAL:
                                if (lm == NULL) {
-                                       codegen_addpatchref(cd, PATCHER_invokevirtual, um, 0);
+                                       patcher_add_patch_ref(jd, PATCHER_invokevirtual, um, 0);
                                        s1 = 0;
                                } else {
                                        s1 = OFFSET(vftbl_t, table[0]) +
@@ -2184,7 +2111,7 @@ gen_method:
                                }
 
                                /* implicit null-pointer check */
-                               M_ALD(REG_METHODPTR, REG_A0, OFFSET(java_objectheader, vftbl));
+                               M_ALD(REG_METHODPTR, REG_A0, OFFSET(java_object_t, vftbl));
                                M_ALD(REG_PV, REG_METHODPTR, s1);
 
                                /* generate the actual call */
@@ -2199,20 +2126,20 @@ gen_method:
 
                        case ICMD_INVOKEINTERFACE:
                                if (lm == NULL) {
-                                       codegen_addpatchref(cd, PATCHER_invokeinterface, um, 0);
+                                       patcher_add_patch_ref(jd, PATCHER_invokeinterface, um, 0);
 
                                        s1 = 0;
                                        s2 = 0;
 
                                } else {
                                        s1 = OFFSET(vftbl_t, interfacetable[0]) -
-                                               sizeof(methodptr*) * lm->class->index;
+                                               sizeof(methodptr*) * lm->clazz->index;
 
-                                       s2 = sizeof(methodptr) * (lm - lm->class->methods);
+                                       s2 = sizeof(methodptr) * (lm - lm->clazz->methods);
                                }
 
                                /* implicit null-pointer check */
-                               M_ALD(REG_METHODPTR, REG_A0, OFFSET(java_objectheader, vftbl));    
+                               M_ALD(REG_METHODPTR, REG_A0, OFFSET(java_object_t, vftbl));    
                                M_ALD(REG_METHODPTR, REG_METHODPTR, s1);
                                M_ALD(REG_PV, REG_METHODPTR, s2);
 
@@ -2267,68 +2194,48 @@ gen_method:
                                s4         superindex;
 
                                if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                                       super = NULL;
+                                       super      = NULL;
                                        superindex = 0;
-                               } else {
-                                       super = iptr->sx.s23.s3.c.cls;
+                               }
+                               else {
+                                       super      = iptr->sx.s23.s3.c.cls;
                                        superindex = super->index;
                                }
-                       
-#if defined(ENABLE_THREADS)
-                               codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
-#endif
+               
                                s1 = emit_load_s1(jd, iptr, REG_ITMP1);
 
-                               /* calculate interface checkcast code size */
-
-                               s2 = 9;
-#if defined(SOFTEX)
-                               s2 += CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd) ? 2 : 0;
-#endif
-                               if (super == NULL)
-                                       s2 += (opt_shownops ? 1 : 0);
-
-                               /* calculate class checkcast code size */
-
-                               s3 = 10 + (s1 == REG_ITMP1);
-#if defined(SOFTEX)
-                               s3 += CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd) ? 1 : 0;
-#endif
-                               if (super == NULL)
-                                       s3 += (opt_shownops ? 1 : 0);
-
                                /* if class is not resolved, check which code to call */
 
                                if (super == NULL) {
                                        M_TST(s1);
-                                       M_BEQ(3 + (opt_shownops ? 1 : 0) + s2 + 1 + s3);
-
+                                       emit_label_beq(cd, BRANCH_LABEL_1);
                                        disp = dseg_add_unique_s4(cd, 0);                     /* super->flags */
 
-                                       codegen_addpatchref(cd,
-                                                                               PATCHER_checkcast_instanceof_flags,
+                                       patcher_add_patch_ref(jd,
+                                                                               PATCHER_resolve_classref_to_flags,
                                                                                iptr->sx.s23.s3.c.ref,
                                                                                disp);
 
                                        M_ILD(REG_ITMP2, REG_PV, disp);
                                        M_AND_IMM(REG_ITMP2, ACC_INTERFACE, REG_ITMP2);
-                                       M_BEQ(s2 + 1);
+
+                                       emit_label_beq(cd, BRANCH_LABEL_2);
                                }
 
                                /* interface checkcast code */
 
                                if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
                                        if (super == NULL) {
-                                               codegen_addpatchref(cd,
+                                               patcher_add_patch_ref(jd,
                                                                                        PATCHER_checkcast_interface,
                                                                                        iptr->sx.s23.s3.c.ref,
                                                                                        0);
                                        } else {
                                                M_TST(s1);
-                                               M_BEQ(s2);
+                                               emit_label_beq(cd, BRANCH_LABEL_3);
                                        }
 
-                                       M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
+                                       M_ALD(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
                                        M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
                                        M_LDATST(REG_ITMP3, REG_ITMP3, -superindex);
                                        emit_classcast_check(cd, iptr, BRANCH_LE, REG_ITMP3, s1);
@@ -2338,36 +2245,37 @@ gen_method:
                                        M_TST(REG_ITMP3);
                                        emit_classcast_check(cd, iptr, BRANCH_EQ, REG_ITMP3, s1);
 
-                                       if (!super)
-                                               M_BR(s3);
+                                       if (super == NULL)      {
+                                               emit_label_br(cd, BRANCH_LABEL_4);
+                                       } else  {
+                                               emit_label(cd, BRANCH_LABEL_3);
+                                       }
                                }
 
                                /* class checkcast code */
 
                                if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
                                        if (super == NULL) {
+                                               emit_label(cd, BRANCH_LABEL_2);
+
                                                disp = dseg_add_unique_address(cd, NULL);
-                                               codegen_addpatchref(cd, PATCHER_checkcast_class,
+                                               patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
                                                                                        iptr->sx.s23.s3.c.ref,
                                                                                        disp);
                                        } else {
                                                disp = dseg_add_address(cd, super->vftbl);
                                                M_TST(s1);
-                                               M_BEQ(s3);
+                                               emit_label_beq(cd, BRANCH_LABEL_5);
                                        }
 
-                                       M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
-#if defined(ENABLE_THREADS)
-                                       codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
-#endif
+                                       M_ALD(REG_ITMP2, s1, OFFSET(java_object_t, vftbl));
+
                                        M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
                                        M_ALD(REG_ITMP2, REG_PV, disp);
                                        if (s1 != REG_ITMP1) {
                                                M_ILD(REG_ITMP1, REG_ITMP2, OFFSET(vftbl_t, baseval));
                                                M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
-#if defined(ENABLE_THREADS)
-                                               codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
-#endif
+
                                                M_SUB(REG_ITMP3, REG_ITMP1, REG_ITMP3);
                                                M_EXTSW(REG_ITMP3, REG_ITMP3);
                                        } else {
@@ -2376,32 +2284,37 @@ gen_method:
                                                M_EXTSW(REG_ITMP3, REG_ITMP3);
                                                M_ALD(REG_ITMP2, REG_PV, disp);
                                                M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
-#if defined(ENABLE_THREADS)
-                                               codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
-#endif
                                        }
                                        M_CMPU(REG_ITMP3, REG_ITMP2);
                                        emit_classcast_check(cd, iptr, BRANCH_GT, REG_ITMP3, s1);
+                                       
+                                       if (super != NULL)
+                                               emit_label(cd, BRANCH_LABEL_5);
+                               }
+
+                               if (super == NULL) {
+                                       emit_label(cd, BRANCH_LABEL_1);
+                                       emit_label(cd, BRANCH_LABEL_4);
                                }
                                d = codegen_reg_of_dst(jd, iptr, s1);
 
                        } else {
                                /* array type cast-check */
 
-                               s1 = emit_load_s1(jd, iptr, rd->argintregs[0]);
-                               M_INTMOVE(s1, rd->argintregs[0]);
+                               s1 = emit_load_s1(jd, iptr, REG_A0);
+                               M_INTMOVE(s1, REG_A0);
 
 
                                if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
                                        disp = dseg_add_unique_address(cd, NULL);
-                                       codegen_addpatchref(cd, PATCHER_builtin_arraycheckcast,
+                                       patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
                                                                                iptr->sx.s23.s3.c.ref,
                                                                                disp);
                                } else {
                                        disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
                                }
 
-                               M_ALD(rd->argintregs[1], REG_PV, disp);
+                               M_ALD(REG_A1, REG_PV, disp);
                                disp = dseg_add_functionptr(cd, BUILTIN_arraycheckcast);
                                M_ALD(REG_ITMP2, REG_PV, disp);
                                M_ALD(REG_ITMP2, REG_ITMP2, 0); /* TOC */
@@ -2436,23 +2349,17 @@ gen_method:
 
                        {
                        classinfo *super;
-                       vftbl_t   *supervftbl;
                        s4         superindex;
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
-                               super = NULL;
+                               super      = NULL;
                                superindex = 0;
-                               supervftbl = NULL;
                        }
                        else {
-                               super = iptr->sx.s23.s3.c.cls;
+                               super      = iptr->sx.s23.s3.c.cls;
                                superindex = super->index;
-                               supervftbl = super->vftbl;
                        }
                        
-#if defined(ENABLE_THREADS)
-            codegen_threadcritrestart(cd, cd->mcodeptr - cd->mcodebase);
-#endif
                        s1 = emit_load_s1(jd, iptr, REG_ITMP1);
                        d = codegen_reg_of_dst(jd, iptr, REG_ITMP2);
                        if (s1 == d) {
@@ -2460,50 +2367,37 @@ gen_method:
                                s1 = REG_ITMP1;
                        }
 
-                       /* calculate interface instanceof code size */
-
-                       s2 = 8;
-                       if (!super)
-                               s2 += (opt_shownops ? 1 : 0);
-
-                       /* calculate class instanceof code size */
-
-                       s3 = 11;
-                       if (super == NULL)
-                               s3 += (opt_shownops ? 1 : 0);
-
                        M_CLR(d);
 
                        /* if class is not resolved, check which code to call */
 
                        if (super == NULL) {
                                M_TST(s1);
-                               M_BEQ(3 + (opt_shownops ? 1 : 0) + s2 + 1 + s3);
-
+                               emit_label_beq(cd, BRANCH_LABEL_1);
                                disp = dseg_add_unique_s4(cd, 0);                     /* super->flags */
 
-                               codegen_addpatchref(cd, PATCHER_checkcast_instanceof_flags,
+                               patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_flags,
                                                                        iptr->sx.s23.s3.c.ref, disp);
 
                                M_ILD(REG_ITMP3, REG_PV, disp);
                                M_AND_IMM(REG_ITMP3, ACC_INTERFACE, REG_ITMP3);
-                               M_BEQ(s2 + 1);
+                               emit_label_beq(cd, BRANCH_LABEL_2);
                        }
 
                        /* interface instanceof code */
 
-                       if (!super || (super->flags & ACC_INTERFACE)) {
-                               if (super) {
-                                       M_TST(s1);
-                                       M_BEQ(s2);
-
-                               } else {
-                                       codegen_addpatchref(cd,
+                       if ((super == NULL) || (super->flags & ACC_INTERFACE)) {
+                               if (super == NULL) {
+                                       patcher_add_patch_ref(jd,
                                                                                PATCHER_instanceof_interface,
                                                                                iptr->sx.s23.s3.c.ref, 0);
+
+                               } else {
+                                       M_TST(s1);
+                                       emit_label_beq(cd, BRANCH_LABEL_3);
                                }
 
-                               M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
+                               M_ALD(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
                                M_ILD(REG_ITMP3, REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
                                M_LDATST(REG_ITMP3, REG_ITMP3, -superindex);
                                M_BLE(4);
@@ -2514,44 +2408,54 @@ gen_method:
                                M_BEQ(1);
                                M_IADD_IMM(REG_ZERO, 1, d);
 
-                               if (super == NULL)
-                                       M_BR(s3);
+                               if (super == NULL)      {
+                                       emit_label_br(cd, BRANCH_LABEL_4);
+                               } else  {
+                                       emit_label(cd, BRANCH_LABEL_3);
+                               }
                        }
 
                        /* class instanceof code */
 
                        if ((super == NULL) || !(super->flags & ACC_INTERFACE)) {
 
-                               if (super) {
-                                       disp = dseg_add_address(cd, supervftbl);
-                                       M_TST(s1);
-                                       M_BEQ(s3);
+                               if (super == NULL) {
+                                       emit_label(cd, BRANCH_LABEL_2);
 
-                               } else {
                                        disp = dseg_add_unique_address(cd, NULL);
-                                       codegen_addpatchref(cd, PATCHER_instanceof_class,
+                                       patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_vftbl,
                                                                                iptr->sx.s23.s3.c.ref,
                                                                                disp);
+
+                               } else {
+                                       disp = dseg_add_address(cd, super->vftbl);
+                                       M_TST(s1);
+                                       emit_label_beq(cd, BRANCH_LABEL_5);
                                }
 
-                               M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
+                               M_ALD(REG_ITMP1, s1, OFFSET(java_object_t, vftbl));
                                M_ALD(REG_ITMP2, REG_PV, disp);
-#if defined(ENABLE_THREADS)
-                               codegen_threadcritstart(cd, cd->mcodeptr - cd->mcodebase);
-#endif
+
                                M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
                                M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
                                M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
-#if defined(ENABLE_THREADS)
-                               codegen_threadcritstop(cd, cd->mcodeptr - cd->mcodebase);
-#endif
+
                                M_SUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
                                M_EXTSW(REG_ITMP1, REG_ITMP1);
                                M_CMPU(REG_ITMP1, REG_ITMP2);
                                M_CLR(d);
                                M_BGT(1);
                                M_IADD_IMM(REG_ZERO, 1, d);
+
+                               if (super != NULL)
+                                       emit_label(cd, BRANCH_LABEL_5);
+                       }
+
+                       if (super == NULL) {
+                               emit_label(cd, BRANCH_LABEL_1);
+                               emit_label(cd, BRANCH_LABEL_4);
                        }
+
                        emit_store_dst(jd, iptr, d);
                        }
                        break;
@@ -2560,7 +2464,7 @@ gen_method:
 
                        /* check for negative sizes and copy sizes to stack if necessary  */
 
-                       MCODECHECK((iptr->s1.argcount << 1) + 64);
+                       MCODECHECK((iptr->s1.argcount << 2) + 128);
 
                        for (s1 = iptr->s1.argcount; --s1 >= 0; ) {
 
@@ -2580,14 +2484,14 @@ gen_method:
 
                        /* a0 = dimension count */
 
-                       ICONST(rd->argintregs[0], iptr->s1.argcount);
+                       ICONST(REG_A0, iptr->s1.argcount);
 
                        /* is patcher function set? */
 
                        if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
                                disp = dseg_add_unique_address(cd, NULL);
 
-                               codegen_addpatchref(cd, PATCHER_builtin_multianewarray,
+                               patcher_add_patch_ref(jd, PATCHER_resolve_classref_to_classinfo,
                                                                        iptr->sx.s23.s3.c.ref, disp);
                        } else {
                                disp = dseg_add_address(cd, iptr->sx.s23.s3.c.cls);
@@ -2595,14 +2499,14 @@ gen_method:
 
                        /* a1 = arraydescriptor */
 
-                       M_ALD(rd->argintregs[1], REG_PV, disp);
+                       M_ALD(REG_A1, REG_PV, disp);
 
                        /* a2 = pointer to dimensions = stack pointer */
 
 #if defined(__DARWIN__)
-                       M_LDA(rd->argintregs[2], REG_SP, LA_SIZE + INT_ARG_CNT * 8);
+                       M_LDA(REG_A2, REG_SP, LA_SIZE + INT_ARG_CNT * 8);
 #else
-                       M_LDA(rd->argintregs[2], REG_SP, LA_SIZE + 3 * 8);
+                       M_LDA(REG_A2, REG_SP, LA_SIZE + 3 * 8);
 #endif
 
                        disp = dseg_add_functionptr(cd, BUILTIN_multianewarray);
@@ -2630,12 +2534,9 @@ gen_method:
        } /* if (bptr -> flags >= BBREACHED) */
        } /* for basic block */
 
-       dseg_createlinenumbertable(cd);
-
-       /* generate stubs */
+       /* generate traps */
 
-       emit_patcher_stubs(jd);
-       REPLACEMENT_EMIT_STUBS(jd);
+       emit_patcher_traps(jd);
 
        /* everything's ok */
 
@@ -2643,66 +2544,41 @@ gen_method:
 }
 
 
-/* codegen_emit_stub_compiler **************************************************
-
-   Emits a stub routine which calls the compiler.
-       
-*******************************************************************************/
-
-void codegen_emit_stub_compiler(jitdata *jd)
-{
-       methodinfo  *m;
-       codegendata *cd;
-
-       /* get required compiler data */
-
-       m  = jd->m;
-       cd = jd->cd;
-
-       /* code for the stub */
-
-       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;
-}
-
-
 /* codegen_emit_stub_native ****************************************************
 
    Emits a stub routine which calls a native method.
 
 *******************************************************************************/
 
-void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
+void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f, int skipparams)
 {
-       methodinfo   *m;
-       codeinfo     *code;
-       codegendata  *cd;
-       registerdata *rd;
-       methoddesc   *md;
-       s4            nativeparams;
-       s4            i, j;                 /* count variables                    */
-       s4            t;
-       s4            s1, s2, disp;
-       s4            funcdisp;
+       methodinfo  *m;
+       codeinfo    *code;
+       codegendata *cd;
+       methoddesc  *md;
+       s4           i, j;
+       s4           t;
+       int          s1, s2;
+       int          disp;
 
        /* get required compiler data */
 
        m    = jd->m;
        code = jd->code;
        cd   = jd->cd;
-       rd   = jd->rd;
+
+       /* Sanity check. */
+
+       assert(!code_is_leafmethod(code));
 
        /* set some variables */
 
        md = m->parseddesc;
-       nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
 
        /* calculate stackframe size */
 
        cd->stackframesize =
-               sizeof(stackframeinfo) / SIZEOF_VOID_P +
+               sizeof(stackframeinfo_t) / SIZEOF_VOID_P +
                sizeof(localref_table) / SIZEOF_VOID_P +
                4 +                            /* 4 stackframeinfo arguments (darwin)*/
                nmd->paramcount  + 
@@ -2712,14 +2588,11 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        /* create method header */
 
-       (void) dseg_add_unique_address(cd, code);                      /* CodeinfoPointer */
-       (void) dseg_add_unique_s4(cd, cd->stackframesize * 8);             /* FrameSize       */
-       (void) dseg_add_unique_s4(cd, 0);                              /* IsSync          */
-       (void) dseg_add_unique_s4(cd, 0);                              /* IsLeaf          */
-       (void) dseg_add_unique_s4(cd, 0);                              /* IntSave         */
-       (void) dseg_add_unique_s4(cd, 0);                              /* FltSave         */
-       (void) dseg_addlinenumbertablesize(cd);
-       (void) dseg_add_unique_s4(cd, 0);                              /* ExTableSize     */
+       (void) dseg_add_unique_address(cd, code);              /* CodeinfoPointer */
+       (void) dseg_add_unique_s4(cd, cd->stackframesize * 8); /* FrameSize       */
+       (void) dseg_add_unique_s4(cd, 0);                      /* IsLeaf          */
+       (void) dseg_add_unique_s4(cd, 0);                      /* IntSave         */
+       (void) dseg_add_unique_s4(cd, 0);                      /* FltSave         */
 
        /* generate code */
 
@@ -2727,147 +2600,122 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
        M_AST_INTERN(REG_ZERO, REG_SP, LA_LR_OFFSET);
        M_STDU(REG_SP, REG_SP, -(cd->stackframesize * 8));
 
-#if !defined(NDEBUG)
-       if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
-               emit_verbosecall_enter(jd);
-       }
-#endif
-       /* get function address (this must happen before the stackframeinfo) */
-
-       funcdisp = dseg_add_functionptr(cd, f);
-
-#if !defined(WITH_STATIC_CLASSPATH)
-       if (f == NULL) {
-               codegen_addpatchref(cd, PATCHER_resolve_native, m, funcdisp);
-       }
-#endif
-
        /* save integer and float argument registers */
 
-       j = 0;
-
        for (i = 0; i < md->paramcount; i++) {
-               t = md->paramtypes[i].type;
-
-               if (IS_INT_LNG_TYPE(t)) {
-                       if (!md->params[i].inmemory) {
-                               s1 = md->params[i].regoff;
-                               M_LST(rd->argintregs[s1], REG_SP, LA_SIZE + PA_SIZE + 4*8 + j * 8);
-                               j++;
-                       }
-               }
-       }
+               if (!md->params[i].inmemory) {
+                       s1 = md->params[i].regoff;
 
-       for (i = 0; i < md->paramcount; i++) {
-               if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
-                       if (!md->params[i].inmemory) {
-                               s1 = md->params[i].regoff;
-                               M_DST(rd->argfltregs[s1], REG_SP, LA_SIZE + PA_SIZE + 4*8 + j * 8);
-                               j++;
+                       switch (md->paramtypes[i].type) {
+                       case TYPE_INT:
+                       case TYPE_LNG:
+                       case TYPE_ADR:
+                               M_LST(s1, REG_SP, LA_SIZE + PA_SIZE + 4 * 8 + i * 8);
+                               break;
+                       case TYPE_FLT:
+                       case TYPE_DBL:
+                               M_DST(s1, REG_SP, LA_SIZE + PA_SIZE + 4 * 8 + i * 8);
+                               break;
                        }
                }
        }
 
        /* create native stack info */
 
-       M_AADD_IMM(REG_SP, cd->stackframesize * 8, rd->argintregs[0]);
-       M_MOV(REG_PV, rd->argintregs[1]);
-       M_AADD_IMM(REG_SP, cd->stackframesize * 8, rd->argintregs[2]);
-       M_ALD(rd->argintregs[3], REG_SP, cd->stackframesize * 8 + LA_LR_OFFSET);
+       M_MOV(REG_SP, REG_A0);
+       M_MOV(REG_PV, REG_A1);
        disp = dseg_add_functionptr(cd, codegen_start_native_call);
-
        M_ALD(REG_ITMP1, REG_PV, disp);
        M_ALD(REG_ITMP1, REG_ITMP1, 0);         /* TOC */
        M_MTCTR(REG_ITMP1);
        M_JSR;
 
-       /* restore integer and float argument registers */
-
-       j = 0;
+       /* remember class argument */
 
-       for (i = 0; i < md->paramcount; i++) {
-               t = md->paramtypes[i].type;
+       if (m->flags & ACC_STATIC)
+               M_MOV(REG_RESULT, REG_ITMP3);
 
-               if (IS_INT_LNG_TYPE(t)) {
-                       if (!md->params[i].inmemory) {
-                               s1 = md->params[i].regoff;
-                               M_LLD(rd->argintregs[s1], REG_SP, LA_SIZE + PA_SIZE + 4 * 8 + j * 8);
-                               j++;
-                       }
-               }
-       }
+       /* restore integer and float argument registers */
 
        for (i = 0; i < md->paramcount; i++) {
-               if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
-                       if (!md->params[i].inmemory) {
-                               s1 = md->params[i].regoff;
-                               M_DLD(rd->argfltregs[s1], REG_SP, LA_SIZE + PA_SIZE + 4 * 8 + j * 8);
-                               j++;
+               if (!md->params[i].inmemory) {
+                       s1 = md->params[i].regoff;
+
+                       switch (md->paramtypes[i].type) {
+                       case TYPE_INT:
+                       case TYPE_LNG:
+                       case TYPE_ADR:
+                               M_LLD(s1, REG_SP, LA_SIZE + PA_SIZE + 4 * 8 + i * 8);
+                               break;
+                       case TYPE_FLT:
+                       case TYPE_DBL:
+                               M_DLD(s1, REG_SP, LA_SIZE + PA_SIZE + 4 * 8 + i * 8);
+                               break;
                        }
                }
        }
        
        /* copy or spill arguments to new locations */
 
-       for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
+       for (i = md->paramcount - 1, j = i + skipparams; i >= 0; i--, j--) {
                t = md->paramtypes[i].type;
 
                if (IS_INT_LNG_TYPE(t)) {
                        if (!md->params[i].inmemory) {
-                               s1 = rd->argintregs[md->params[i].regoff];
+                               s1 = md->params[i].regoff;
+                               s2 = nmd->params[j].regoff;
 
-                               if (!nmd->params[j].inmemory) {
-                                       s2 = rd->argintregs[nmd->params[j].regoff];
+                               if (!nmd->params[j].inmemory)
                                        M_INTMOVE(s1, s2);
-                               } else {
-                                       s2 = nmd->params[j].regoff;
-                                       M_LST(s1, REG_SP, s2 * 8);
-                               }
-
-                       } else {
-                               s1 = md->params[i].regoff + cd->stackframesize;
+                               else
+                                       M_LST(s1, REG_SP, s2);
+                       }
+                       else {
+                               s1 = md->params[i].regoff + cd->stackframesize * 8;
                                s2 = nmd->params[j].regoff;
 
-                               M_LLD(REG_ITMP1, REG_SP, s1 * 8);
-                               M_LST(REG_ITMP1, REG_SP, s2 * 8);
+                               M_LLD(REG_ITMP1, REG_SP, s1);
+                               M_LST(REG_ITMP1, REG_SP, s2);
                        }
-
-               else {
+               }
+               else {
                        /* We only copy spilled float arguments, as the float
                           argument registers keep unchanged. */
 
                        if (md->params[i].inmemory) {
-                               s1 = md->params[i].regoff + cd->stackframesize;
+                               s1 = md->params[i].regoff + cd->stackframesize * 8;
                                s2 = nmd->params[j].regoff;
 
-                               M_DLD(REG_FTMP1, REG_SP, s1 * 8);
+                               M_DLD(REG_FTMP1, REG_SP, s1);
 
-                               if (IS_2_WORD_TYPE(t)) {        
-                                       M_DST(REG_FTMP1, REG_SP, s2 * 8);
-                               } else {
-                                       M_FST(REG_FTMP1, REG_SP, s2 * 8 + 4);
-                               }
+                               if (IS_2_WORD_TYPE(t))
+                                       M_DST(REG_FTMP1, REG_SP, s2);
+                               else
+                                       M_FST(REG_FTMP1, REG_SP, s2 + 4);
                        }
                }
        }
 
-       /* put class into second argument register */
+       /* Handle native Java methods. */
 
-       if (m->flags & ACC_STATIC) {
-               disp = dseg_add_unique_address(cd, m->class);
-               M_ALD(rd->argintregs[1], REG_PV, disp);
-       }
+       if (m->flags & ACC_NATIVE) {
+               /* put class into second argument register */
 
-       /* put env into first argument register */
+               if (m->flags & ACC_STATIC)
+                       M_MOV(REG_ITMP3, REG_A1);
 
-       disp = dseg_add_unique_address(cd, _Jv_env);
-       M_ALD(rd->argintregs[0], REG_PV, disp);
+               /* put env into first argument register */
 
-       /* generate the actual native call */
+               disp = dseg_add_unique_address(cd, VM_get_jnienv());
+               M_ALD(REG_A0, REG_PV, disp);
+       }
+
+       /* Call the native function. */
        /* native functions have a different TOC for sure */
 
        M_AST(REG_TOC, REG_SP, 40);     /* save old TOC */
-       M_ALD(REG_ITMP3, REG_PV, funcdisp);
+       disp = dseg_add_functionptr(cd, f);
+       M_ALD(REG_ITMP3, REG_PV, disp);
        M_ALD(REG_TOC, REG_ITMP3, 8);   /* load TOC from func. descriptor */
        M_ALD(REG_ITMP3, REG_ITMP3, 0);         
        M_MTCTR(REG_ITMP3);
@@ -2878,22 +2726,17 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        if (md->returntype.type != TYPE_VOID) {
                if (IS_INT_LNG_TYPE(md->returntype.type)) {
-                       M_LST(REG_RESULT, REG_SP, LA_SIZE + PA_SIZE + 1 * 8);
+                       M_LST(REG_RESULT, REG_SP, LA_SIZE + PA_SIZE + 2 * 8);
                }
                else {
-                       M_DST(REG_FRESULT, REG_SP, LA_SIZE + PA_SIZE + 1 * 8);
+                       M_DST(REG_FRESULT, REG_SP, LA_SIZE + PA_SIZE + 2 * 8);
                }
        }
 
-       /* print call trace */
-#if ! defined(NDEBGUU)
-       if (JITDATA_HAS_FLAG_VERBOSECALL(jd)) {
-               emit_verbosecall_exit(jd);
-       }
-#endif
        /* remove native stackframe info */
 
-       M_AADD_IMM(REG_SP, cd->stackframesize * 8, rd->argintregs[0]);
+       M_MOV(REG_SP, REG_A0);
+       M_MOV(REG_PV, REG_A1);
        disp = dseg_add_functionptr(cd, codegen_finish_native_call);
        M_ALD(REG_ITMP1, REG_PV, disp);
        M_ALD(REG_ITMP1, REG_ITMP1, 0); /* XXX what about TOC? */
@@ -2905,14 +2748,10 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
 
        if (md->returntype.type != TYPE_VOID) {
                if (IS_INT_LNG_TYPE(md->returntype.type)) {
-                       M_LLD(REG_RESULT, REG_SP, LA_SIZE + PA_SIZE + 1 * 8);
+                       M_LLD(REG_RESULT, REG_SP, LA_SIZE + PA_SIZE + 2 * 8);
                }
                else {
-/*                     if (IS_2_WORD_TYPE(md->returntype.type)) */
-                               M_DLD(REG_FRESULT, REG_SP, LA_SIZE + PA_SIZE + 1 * 8);
-/*                     else
-                               M_FLD(REG_FRESULT, REG_SP, LA_SIZE + PA_SIZE + 1 * 8); F XXX
-                               */
+                       M_DLD(REG_FRESULT, REG_SP, LA_SIZE + PA_SIZE + 2 * 8);
                }
        }
 
@@ -2935,19 +2774,9 @@ void codegen_emit_stub_native(jitdata *jd, methoddesc *nmd, functionptr f)
        M_ALD(REG_ITMP3, REG_PV, disp);
        M_MTCTR(REG_ITMP3);
        M_RTS;
-
-       /* generate patcher stub call code */
-
-       emit_patcher_stubs(jd);
-
-       codegen_finish(jd);
-
-       return code->entrypoint;
 }
 
 
-
-
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where