* src/vm/jit/powerpc/md.c (md_patch_replacement_point): Added.
[cacao.git] / src / vm / jit / alpha / codegen.c
index 198a8ea7fd54450517e2dc52b27b48bff7aab1a7..5ac5add885f650580b394e4fe8dae0fce8df3d86 100644 (file)
@@ -1,9 +1,9 @@
 /* src/vm/jit/alpha/codegen.c - machine code generator for Alpha
 
-   Copyright (C) 1996-2005 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 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
 
    This file is part of CACAO.
 
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
+   Contact: cacao@cacaojvm.org
 
    Authors: Andreas Krall
             Reinhard Grafl
 
    Changes: Joseph Wenninger
             Christian Thalinger
+            Christian Ullrich
+            Edwin Steiner
 
-   $Id: codegen.c 2389 2005-04-26 16:16:05Z twisti $
+   $Id: codegen.c 4653 2006-03-18 04:14:17Z edwin $
 
 */
 
 
+#include "config.h"
+
+#include <assert.h>
 #include <stdio.h>
-#include <signal.h>
 
-#include "config.h"
-#include "cacao/cacao.h"
+#include "vm/types.h"
+
+#include "md.h"
+#include "md-abi.h"
+
+#include "vm/jit/alpha/arch.h"
+#include "vm/jit/alpha/codegen.h"
+
+#include "native/jni.h"
 #include "native/native.h"
 #include "vm/builtin.h"
+#include "vm/exceptions.h"
 #include "vm/global.h"
 #include "vm/loader.h"
-#include "vm/tables.h"
+#include "vm/options.h"
+#include "vm/stringlocal.h"
+#include "vm/vm.h"
 #include "vm/jit/asmpart.h"
+#include "vm/jit/codegen-common.h"
+#include "vm/jit/dseg.h"
 #include "vm/jit/jit.h"
-#ifdef LSRA
-#include "vm/jit/lsra.h"
-#endif
 #include "vm/jit/parse.h"
 #include "vm/jit/patcher.h"
 #include "vm/jit/reg.h"
-#include "vm/jit/alpha/arch.h"
-#include "vm/jit/alpha/codegen.h"
-#include "vm/jit/alpha/types.h"
-#include "vm/jit/alpha/asmoffsets.h"
-
-
-/* *****************************************************************************
-
-Datatypes and Register Allocations:
------------------------------------ 
-
-On 64-bit-machines (like the Alpha) all operands are stored in the
-registers in a 64-bit form, even when the correspondig JavaVM  operands
-only need 32 bits. This is done by a canonical representation:
-
-32-bit integers are allways stored as sign-extended 64-bit values (this
-approach is directly supported by the Alpha architecture and is very easy
-to implement).
-
-32-bit-floats are stored in a 64-bit doubleprecision register by simply
-expanding the exponent and mantissa with zeroes. (also supported by the
-architecture)
-
-
-Stackframes:
-
-The calling conventions and the layout of the stack is  explained in detail
-in the documention file: calling.doc
-
-*******************************************************************************/
-
-
-/* register descripton - array ************************************************/
-
-/* #define REG_RES   0         reserved register for OS or code generator     */
-/* #define REG_RET   1         return value register                          */
-/* #define REG_EXC   2         exception value register (only old jit)        */
-/* #define REG_SAV   3         (callee) saved register                        */
-/* #define REG_TMP   4         scratch temporary register (caller saved)      */
-/* #define REG_ARG   5         argument register (caller saved)               */
-
-/* #define REG_END   -1        last entry in tables */
-int nregdescint[] = {
-       REG_RET, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, 
-       REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, 
-       REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
-       REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES, REG_RES,
-       REG_END };
-
-/* for use of reserved registers, see comment above */
-       
-int nregdescfloat[] = {
-       REG_RET, REG_TMP, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV, REG_SAV,
-       REG_SAV, REG_SAV, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_TMP, 
-       REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_ARG, REG_TMP, REG_TMP,
-       REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES,
-       REG_END };
-
-
-/* Include independent code generation stuff -- include after register        */
-/* descriptions to avoid extern definitions.                                  */
-
-#include "vm/jit/codegen.inc"
-#include "vm/jit/reg.inc"
-#ifdef LSRA
-#include "vm/jit/lsra.inc"
-#endif
-
-
-/* NullPointerException handlers and exception handling initialisation        */
-
-typedef struct sigctx_struct {
-       long          sc_onstack;           /* sigstack state to restore          */
-       long          sc_mask;              /* signal mask to restore             */
-       long          sc_pc;                /* pc at time of signal               */
-       long          sc_ps;                /* psl to retore                      */
-       long          sc_regs[32];          /* processor regs 0 to 31             */
-       long          sc_ownedfp;           /* fp has been used                   */
-       long          sc_fpregs[32];        /* fp regs 0 to 31                    */
-       unsigned long sc_fpcr;              /* floating point control register    */
-       unsigned long sc_fp_control;        /* software fpcr                      */
-                                           /* rest is unused                     */
-       unsigned long sc_reserved1, sc_reserved2;
-       unsigned long sc_ssize;
-       char          *sc_sbase;
-       unsigned long sc_traparg_a0;
-       unsigned long sc_traparg_a1;
-       unsigned long sc_traparg_a2;
-       unsigned long sc_fp_trap_pc;
-       unsigned long sc_fp_trigger_sum;
-       unsigned long sc_fp_trigger_inst;
-       unsigned long sc_retcode[2];
-} sigctx_struct;
-
-
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-void thread_restartcriticalsection(ucontext_t *uc)
-{
-       void *critical;
-       if ((critical = thread_checkcritical((void*) uc->uc_mcontext.sc_pc)) != NULL)
-               uc->uc_mcontext.sc_pc = (u8) critical;
-}
-#endif
-
-
-/* NullPointerException signal handler for hardware null pointer check */
-
-void catch_NullPointerException(int sig, siginfo_t *siginfo, void *_p)
-{
-       struct sigaction act;
-       sigset_t         nsig;
-       int              instr;
-       long             faultaddr;
-
-       ucontext_t *_uc = (ucontext_t *) _p;
-       mcontext_t *sigctx = &_uc->uc_mcontext;
-
-       instr = *((s4 *) (sigctx->sc_pc));
-       faultaddr = sigctx->sc_regs[(instr >> 16) & 0x1f];
-
-       if (faultaddr == 0) {
-               /* Reset signal handler - necessary for SysV, does no harm for BSD */
-               act.sa_sigaction = catch_NullPointerException;
-               act.sa_flags = SA_SIGINFO;
-               sigaction(sig, &act, NULL);
-
-               sigemptyset(&nsig);
-               sigaddset(&nsig, sig);
-               sigprocmask(SIG_UNBLOCK, &nsig, NULL);           /* unblock signal    */
-
-               sigctx->sc_regs[REG_ITMP1_XPTR] = (u8) string_java_lang_NullPointerException;
-               sigctx->sc_regs[REG_ITMP2_XPC] = sigctx->sc_pc;
-               sigctx->sc_pc = (u8) asm_throw_and_handle_exception;
-               return;
-
-       } else {
-               faultaddr += (long) ((instr << 16) >> 16);
-               fprintf(stderr, "faulting address: 0x%016lx\n", faultaddr);
-               panic("Stack overflow");
-       }
-}
-
-
-#ifdef __osf__
-
-void init_exceptions(void)
-{
-
-#else /* Linux */
-
-/* Linux on Digital Alpha needs an initialisation of the ieee floating point
-       control for IEEE compliant arithmetic (option -mieee of GCC). Under
-       Digital Unix this is done automatically.
-*/
-
-#include <asm/fpu.h>
-
-extern unsigned long ieee_get_fp_control();
-extern void ieee_set_fp_control(unsigned long fp_control);
-
-void init_exceptions(void)
-{
-       struct sigaction act;
-
-       /* initialize floating point control */
-
-       ieee_set_fp_control(ieee_get_fp_control()
-                                               & ~IEEE_TRAP_ENABLE_INV
-                                               & ~IEEE_TRAP_ENABLE_DZE
-/*                                             & ~IEEE_TRAP_ENABLE_UNF   we dont want underflow */
-                                               & ~IEEE_TRAP_ENABLE_OVF);
-#endif
-
-       /* install signal handlers we need to convert to exceptions */
-
-       if (!checknull) {
-               act.sa_sigaction = catch_NullPointerException;
-               act.sa_flags = SA_SIGINFO;
-
-#if defined(SIGSEGV)
-               sigaction(SIGSEGV, &act, NULL);
-#endif
+#include "vm/jit/replace.h"
 
-#if defined(SIGBUS)
-               sigaction(SIGBUS, &act, NULL);
+#if defined(ENABLE_LSRA)
+# include "vm/jit/allocator/lsra.h"
 #endif
-       }
-}
 
 
-/* function gen_mcode **********************************************************
+/* codegen *********************************************************************
 
-       generates machine code
+   Generates machine code.
 
 *******************************************************************************/
 
-void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
+bool codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 {
-       s4     len, s1, s2, s3, d;
-       ptrint a;
-       s4 parentargs_base;
-       s4             *mcodeptr;
-       stackptr        src;
-       varinfo        *var;
-       basicblock     *bptr;
-       instruction    *iptr;
-       exceptiontable *ex;
-       u2 currentline=0;
+       s4                  len, s1, s2, s3, d, disp;
+       s4                  parentargs_base;
+       s4                 *mcodeptr;
+       stackptr            src;
+       varinfo            *var;
+       basicblock         *bptr;
+       instruction        *iptr;
+       exceptiontable     *ex;
+       u2                  currentline;
+       methodinfo         *lm;             /* local methodinfo for ICMD_INVOKE*  */
+       builtintable_entry *bte;
+       methoddesc         *md;
+       rplpoint           *replacementpoint;
+
+       /* prevent compiler warnings */
+
+       d = 0;
+       currentline = 0;
+       lm = NULL;
+       bte = NULL;
+
        {
-       s4 i, p, pa, t, l;
+       s4 i, p, t, l;
        s4 savedregs_num;
 
        savedregs_num = (m->isleafmethod) ? 0 : 1;        /* space to save the RA */
 
        /* space to save used callee saved registers */
 
-       savedregs_num += (rd->savintregcnt - rd->maxsavintreguse);
-       savedregs_num += (rd->savfltregcnt - rd->maxsavfltreguse);
+       savedregs_num += (INT_SAV_CNT - rd->savintreguse);
+       savedregs_num += (FLT_SAV_CNT - rd->savfltreguse);
 
-       parentargs_base = rd->maxmemuse + savedregs_num;
+       parentargs_base = rd->memuse + savedregs_num;
 
 #if defined(USE_THREADS)           /* space to save argument of monitor_enter */
-
        if (checksync && (m->flags & ACC_SYNCHRONIZED))
                parentargs_base++;
-
 #endif
 
        /* create method header */
@@ -288,7 +126,6 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
        (void) dseg_adds4(cd, parentargs_base * 8);             /* FrameSize      */
 
 #if defined(USE_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
@@ -296,16 +133,14 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
        */
 
        if (checksync && (m->flags & ACC_SYNCHRONIZED))
-               (void) dseg_adds4(cd, (rd->maxmemuse + 1) * 8);     /* IsSync         */
+               (void) dseg_adds4(cd, (rd->memuse + 1) * 8);        /* IsSync         */
        else
-
 #endif
-
-       (void) dseg_adds4(cd, 0);                               /* IsSync         */
+               (void) dseg_adds4(cd, 0);                           /* IsSync         */
                                               
        (void) dseg_adds4(cd, m->isleafmethod);                 /* IsLeaf         */
-       (void) dseg_adds4(cd, rd->savintregcnt - rd->maxsavintreguse);/* IntSave  */
-       (void) dseg_adds4(cd, rd->savfltregcnt - rd->maxsavfltreguse);/* FltSave  */
+       (void) dseg_adds4(cd, INT_SAV_CNT - rd->savintreguse);  /* IntSave        */
+       (void) dseg_adds4(cd, FLT_SAV_CNT - rd->savfltreguse);  /* FltSave        */
 
        dseg_addlinenumbertablesize(cd);
 
@@ -322,15 +157,12 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
        
        /* initialize mcode variables */
        
-       mcodeptr = (s4 *) cd->mcodebase;
-       cd->mcodeend = (s4 *) (cd->mcodebase + cd->mcodesize);
-       MCODECHECK(128 + m->paramcount);
+       mcodeptr = (s4 *) cd->mcodeptr;
 
        /* create stack frame (if necessary) */
 
-       if (parentargs_base) {
+       if (parentargs_base)
                M_LDA(REG_SP, REG_SP, -parentargs_base * 8);
-       }
 
        /* save return address and used callee saved registers */
 
@@ -338,127 +170,61 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
        if (!m->isleafmethod) {
                p--; M_AST(REG_RA, REG_SP, p * 8);
        }
-       for (i = rd->savintregcnt - 1; i >= rd->maxsavintreguse; i--) {
+       for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
                p--; M_LST(rd->savintregs[i], REG_SP, p * 8);
        }
-       for (i = rd->savfltregcnt - 1; i >= rd->maxsavfltreguse; i--) {
+       for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
                p--; M_DST(rd->savfltregs[i], REG_SP, p * 8);
        }
 
-       /* copy argument registers to stack and call trace function with pointer
-          to arguments on stack.
-       */
-
-       if (runverbose) {
-               s4 disp;
-               M_LDA(REG_SP, REG_SP, -((INT_ARG_CNT + FLT_ARG_CNT + 2) * 8));
-               M_AST(REG_RA, REG_SP, 1 * 8);
-
-               /* save integer argument registers */
-               for (p = 0; p < m->paramcount && p < INT_ARG_CNT; p++) {
-                       M_LST(rd->argintregs[p], REG_SP,  (2 + p) * 8);
-               }
-
-               /* save and copy float arguments into integer registers */
-               for (p = 0; p < m->paramcount && p < FLT_ARG_CNT; p++) {
-                       t = m->paramtypes[p];
-
-                       if (IS_FLT_DBL_TYPE(t)) {
-                               if (IS_2_WORD_TYPE(t)) {
-                                       M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-
-                               } else {
-                                       M_FST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-                               }
-
-                               M_LLD(rd->argintregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-                               
-                       } else {
-                               M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-                       }
-               }
-
-               p = dseg_addaddress(cd, m);
-               M_ALD(REG_ITMP1, REG_PV, p);
-               M_AST(REG_ITMP1, REG_SP, 0 * 8);
-               p = dseg_addaddress(cd, (void *) builtin_trace_args);
-               M_ALD(REG_PV, REG_PV, p);
-               M_JSR(REG_RA, REG_PV);
-               disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
-               M_LDA(REG_PV, REG_RA, disp);
-               M_ALD(REG_RA, REG_SP, 1 * 8);
-
-               for (p = 0; p < m->paramcount && p < INT_ARG_CNT; p++) {
-                       M_LLD(rd->argintregs[p], REG_SP,  (2 + p) * 8);
-               }
-
-               for (p = 0; p < m->paramcount && p < FLT_ARG_CNT; p++) {
-                       t = m->paramtypes[p];
-
-                       if (IS_FLT_DBL_TYPE(t)) {
-                               if (IS_2_WORD_TYPE(t)) {
-                                       M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-
-                               } else {
-                                       M_FLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-                               }
-
-                       } else {
-                               M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-                       }
-               }
-
-               M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT + 2) * 8);
-       }
-
        /* take arguments out of register or stack frame */
 
-       for (p = 0, l = 0; p < m->paramcount; p++) {
-               t = m->paramtypes[p];
+       md = m->parseddesc;
+
+       for (p = 0, l = 0; p < md->paramcount; p++) {
+               t = md->paramtypes[p].type;
                var = &(rd->locals[l][t]);
                l++;
                if (IS_2_WORD_TYPE(t))    /* increment local counter for 2 word types */
                        l++;
                if (var->type < 0)
                        continue;
+               s1 = md->params[p].regoff;
                if (IS_INT_LNG_TYPE(t)) {                    /* integer args          */
-                       if (p < INT_ARG_CNT) {                   /* register arguments    */
+                       if (!md->params[p].inmemory) {           /* register arguments    */
+                               s2 = rd->argintregs[s1];
                                if (!(var->flags & INMEMORY)) {      /* reg arg -> register   */
-                                       M_INTMOVE(rd->argintregs[p], var->regoff);
+                                       M_INTMOVE(s2, var->regoff);
+
                                } else {                             /* reg arg -> spilled    */
-                                       M_LST(rd->argintregs[p], REG_SP, 8 * var->regoff);
+                                       M_LST(s2, REG_SP, var->regoff * 8);
                                }
 
                        } else {                                 /* stack arguments       */
-                               pa = p - INT_ARG_CNT;
                                if (!(var->flags & INMEMORY)) {      /* stack arg -> register */
-                                       M_LLD(var->regoff, REG_SP, 8 * (parentargs_base + pa));
+                                       M_LLD(var->regoff, REG_SP, (parentargs_base + s1) * 8);
 
                                } else {                             /* stack arg -> spilled  */
-/*                                     M_LLD(REG_ITMP1, REG_SP, 8 * (parentargs_base + pa)); */
-/*                                     M_LST(REG_ITMP1, REG_SP, 8 * var->regoff); */
-                                       var->regoff = parentargs_base + pa;
+                                       var->regoff = parentargs_base + s1;
                                }
                        }
 
                } else {                                     /* floating args         */
-                       if (p < FLT_ARG_CNT) {                   /* register arguments    */
+                       if (!md->params[p].inmemory) {           /* register arguments    */
+                               s2 = rd->argfltregs[s1];
                                if (!(var->flags & INMEMORY)) {      /* reg arg -> register   */
-                                       M_FLTMOVE(rd->argfltregs[p], var->regoff);
+                                       M_FLTMOVE(s2, var->regoff);
 
                                } else {                                         /* reg arg -> spilled    */
-                                       M_DST(rd->argfltregs[p], REG_SP, 8 * var->regoff);
+                                       M_DST(s2, REG_SP, var->regoff * 8);
                                }
 
                        } else {                                 /* stack arguments       */
-                               pa = p - FLT_ARG_CNT;
                                if (!(var->flags & INMEMORY)) {      /* stack-arg -> register */
-                                       M_DLD(var->regoff, REG_SP, 8 * (parentargs_base + pa) );
+                                       M_DLD(var->regoff, REG_SP, (parentargs_base + s1) * 8);
 
                                } else {                             /* stack-arg -> spilled  */
-/*                                     M_DLD(REG_FTMP1, REG_SP, 8 * (parentargs_base + pa)); */
-/*                                     M_DST(REG_FTMP1, REG_SP, 8 * var->regoff); */
-                                       var->regoff = parentargs_base + pa;
+                                       var->regoff = parentargs_base + s1;
                                }
                        }
                }
@@ -468,37 +234,132 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
 #if defined(USE_THREADS)
        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
-               s4 disp;
+               /* stack offset for monitor argument */
+
+               s1 = rd->memuse;
+
+               if (opt_verbosecall) {
+                       M_LDA(REG_SP, REG_SP, -(INT_ARG_CNT + FLT_ARG_CNT) * 8);
+
+                       for (p = 0; p < INT_ARG_CNT; p++)
+                               M_LST(rd->argintregs[p], REG_SP, p * 8);
+
+                       for (p = 0; p < FLT_ARG_CNT; p++)
+                               M_DST(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 8);
+
+                       s1 += INT_ARG_CNT + FLT_ARG_CNT;
+               }
+
+               /* decide which monitor enter function to call */
 
                if (m->flags & ACC_STATIC) {
-                       p = dseg_addaddress(cd, m->class);
-                       M_ALD(REG_ITMP1, REG_PV, p);
-                       M_AST(REG_ITMP1, REG_SP, rd->maxmemuse * 8);
-                       M_INTMOVE(REG_ITMP1, rd->argintregs[0]);
-                       p = dseg_addaddress(cd, BUILTIN_staticmonitorenter);
-                       M_ALD(REG_PV, REG_PV, p);
+                       disp = dseg_addaddress(cd, m->class);
+                       M_ALD(rd->argintregs[0], REG_PV, disp);
+                       M_AST(rd->argintregs[0], REG_SP, s1 * 8);
+                       disp = dseg_addaddress(cd, BUILTIN_staticmonitorenter);
+                       M_ALD(REG_PV, REG_PV, disp);
                        M_JSR(REG_RA, REG_PV);
                        disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
                        M_LDA(REG_PV, REG_RA, disp);
 
                } else {
                        M_BEQZ(rd->argintregs[0], 0);
-                       codegen_addxnullrefs(cd, mcodeptr);
-                       M_AST(rd->argintregs[0], REG_SP, rd->maxmemuse * 8);
-                       p = dseg_addaddress(cd, BUILTIN_monitorenter);
-                       M_ALD(REG_PV, REG_PV, p);
+                       codegen_add_nullpointerexception_ref(cd, mcodeptr);
+                       M_AST(rd->argintregs[0], REG_SP, s1 * 8);
+                       disp = dseg_addaddress(cd, BUILTIN_monitorenter);
+                       M_ALD(REG_PV, REG_PV, disp);
                        M_JSR(REG_RA, REG_PV);
                        disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
                        M_LDA(REG_PV, REG_RA, disp);
                }
+
+               if (opt_verbosecall) {
+                       for (p = 0; p < INT_ARG_CNT; p++)
+                               M_LLD(rd->argintregs[p], REG_SP, p * 8);
+
+                       for (p = 0; p < FLT_ARG_CNT; p++)
+                               M_DLD(rd->argfltregs[p], REG_SP, (INT_ARG_CNT + p) * 8);
+
+                       M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT) * 8);
+               }
        }                       
 #endif
 
+       /* call trace function */
+
+       if (opt_verbosecall) {
+               M_LDA(REG_SP, REG_SP, -((INT_ARG_CNT + FLT_ARG_CNT + 2) * 8));
+               M_AST(REG_RA, REG_SP, 1 * 8);
+
+               /* save integer argument registers */
+
+               for (p = 0; p < md->paramcount && p < INT_ARG_CNT; p++)
+                       M_LST(rd->argintregs[p], REG_SP, (2 + p) * 8);
+
+               /* save and copy float arguments into integer registers */
+
+               for (p = 0; p < md->paramcount && p < FLT_ARG_CNT; p++) {
+                       t = md->paramtypes[p].type;
+
+                       if (IS_FLT_DBL_TYPE(t)) {
+                               if (IS_2_WORD_TYPE(t)) {
+                                       M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+
+                               } else {
+                                       M_FST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                               }
+
+                               M_LLD(rd->argintregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                               
+                       } else {
+                               M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                       }
+               }
+
+               disp = dseg_addaddress(cd, m);
+               M_ALD(REG_ITMP1, REG_PV, disp);
+               M_AST(REG_ITMP1, REG_SP, 0 * 8);
+               disp = dseg_addaddress(cd, (void *) builtin_trace_args);
+               M_ALD(REG_PV, REG_PV, disp);
+               M_JSR(REG_RA, REG_PV);
+               disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
+               M_LDA(REG_PV, REG_RA, disp);
+               M_ALD(REG_RA, REG_SP, 1 * 8);
+
+               /* restore integer argument registers */
+
+               for (p = 0; p < md->paramcount && p < INT_ARG_CNT; p++)
+                       M_LLD(rd->argintregs[p], REG_SP, (2 + p) * 8);
+
+               /* restore float argument registers */
+
+               for (p = 0; p < md->paramcount && p < FLT_ARG_CNT; p++) {
+                       t = md->paramtypes[p].type;
+
+                       if (IS_FLT_DBL_TYPE(t)) {
+                               if (IS_2_WORD_TYPE(t)) {
+                                       M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+
+                               } else {
+                                       M_FLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                               }
+
+                       } else {
+                               M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                       }
+               }
+
+               M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT + 2) * 8);
+       }
+
        }
 
        /* end of header generation */
 
+       replacementpoint = cd->code->rplpoints;
+
        /* walk through all basic blocks */
+
        for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
 
                bptr->mpc = (s4) ((u1 *) mcodeptr - cd->mcodebase);
@@ -515,21 +376,29 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        }
                }
 
+               /* handle replacement points */
+
+               if (bptr->bitflags & BBFLAG_REPLACEMENT) {
+                       replacementpoint->pc = (u1*)(ptrint)bptr->mpc; /* will be resolved later */
+                       
+                       replacementpoint++;
+               }
+
                /* copy interface registers to their destination */
 
                src = bptr->instack;
                len = bptr->indepth;
                MCODECHECK(64+len);
-#ifdef LSRA
+#if defined(ENABLE_LSRA)
                if (opt_lsra) {
                while (src != NULL) {
                        len--;
                        if ((len == 0) && (bptr->type != BBTYPE_STD)) {
                                        /*                              d = reg_of_var(m, src, REG_ITMP1); */
                                        if (!(src->flags & INMEMORY))
-                                               d= src->regoff;
+                                               d = src->regoff;
                                        else
-                                               d=REG_ITMP1;
+                                               d = REG_ITMP1;
                                        M_INTMOVE(REG_ITMP1, d);
                                        store_reg_to_var_int(src, d);
                                }
@@ -540,39 +409,36 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        while (src != NULL) {
                                len--;
                                if ((len == 0) && (bptr->type != BBTYPE_STD)) {
-                               d = reg_of_var(rd, src, REG_ITMP1);
-                               M_INTMOVE(REG_ITMP1, d);
-                               store_reg_to_var_int(src, d);
-                               }
-                       else {
-                               d = reg_of_var(rd, src, REG_IFTMP);
-                               if ((src->varkind != STACKVAR)) {
-                                       s2 = src->type;
-                                       if (IS_FLT_DBL_TYPE(s2)) {
-                                               if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
-                                                       s1 = rd->interfaces[len][s2].regoff;
-                                                       M_FLTMOVE(s1,d);
-                                                       }
-                                               else {
-                                                       M_DLD(d, REG_SP, 8 * rd->interfaces[len][s2].regoff);
+                                       d = reg_of_var(rd, src, REG_ITMP1);
+                                       M_INTMOVE(REG_ITMP1, d);
+                                       store_reg_to_var_int(src, d);
+                               } else {
+                                       d = reg_of_var(rd, src, REG_IFTMP);
+                                       if ((src->varkind != STACKVAR)) {
+                                               s2 = src->type;
+                                               if (IS_FLT_DBL_TYPE(s2)) {
+                                                       if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
+                                                               s1 = rd->interfaces[len][s2].regoff;
+                                                               M_FLTMOVE(s1, d);
+                                                       } else {
+                                                               M_DLD(d, REG_SP, rd->interfaces[len][s2].regoff * 8);
                                                        }
-                                               store_reg_to_var_flt(src, d);
+                                                       store_reg_to_var_flt(src, d);
                                                }
-                                       else {
-                                               if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
-                                                       s1 = rd->interfaces[len][s2].regoff;
-                                                       M_INTMOVE(s1,d);
-                                                       }
                                                else {
-                                                       M_LLD(d, REG_SP, 8 * rd->interfaces[len][s2].regoff);
+                                                       if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
+                                                               s1 = rd->interfaces[len][s2].regoff;
+                                                               M_INTMOVE(s1, d);
+                                                       } else {
+                                                               M_LLD(d, REG_SP, rd->interfaces[len][s2].regoff * 8);
                                                        }
-                                               store_reg_to_var_int(src, d);
+                                                       store_reg_to_var_int(src, d);
                                                }
                                        }
                                }
-                       src = src->prev;
+                               src = src->prev;
                        }
-#ifdef LSRA
+#if defined(ENABLE_LSRA)
                }
 #endif
 
@@ -583,7 +449,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                for (iptr = bptr->iinstr; len > 0; src = iptr->dst, len--, iptr++) {
                        if (iptr->line != currentline) {
-                               dseg_addlinenumber(cd, iptr->line, mcodeptr);
+                               dseg_addlinenumber(cd, iptr->line, (u1 *) mcodeptr);
                                currentline = iptr->line;
                        }
 
@@ -601,7 +467,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_BEQZ(s1, 0);
-                       codegen_addxnullrefs(cd, mcodeptr);
+                       codegen_add_nullpointerexception_ref(cd, mcodeptr);
                        break;
 
                /* constant operations ************************************************/
@@ -626,8 +492,8 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* op1 = 0, val.f = constant                    */
 
                        d = reg_of_var(rd, iptr->dst, REG_FTMP1);
-                       a = dseg_addfloat(cd, iptr->val.f);
-                       M_FLD(d, REG_PV, a);
+                       disp = dseg_addfloat(cd, iptr->val.f);
+                       M_FLD(d, REG_PV, disp);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
                        
@@ -635,8 +501,8 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* op1 = 0, val.d = constant                    */
 
                        d = reg_of_var(rd, iptr->dst, REG_FTMP1);
-                       a = dseg_adddouble(cd, iptr->val.d);
-                       M_DLD(d, REG_PV, a);
+                       disp = dseg_adddouble(cd, iptr->val.d);
+                       M_DLD(d, REG_PV, disp);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -644,11 +510,26 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* op1 = 0, val.a = constant                    */
 
                        d = reg_of_var(rd, iptr->dst, REG_ITMP1);
-                       if (iptr->val.a) {
-                               a = dseg_addaddress(cd, iptr->val.a);
-                               M_ALD(d, REG_PV, a);
+
+                       if ((iptr->target != NULL) && (iptr->val.a == NULL)) {
+                               disp = dseg_addaddress(cd, iptr->val.a);
+
+                               codegen_addpatchref(cd, mcodeptr,
+                                                                       PATCHER_aconst,
+                                                                       (unresolved_class *) iptr->target, disp);
+
+                               if (opt_showdisassemble)
+                                       M_NOP;
+
+                               M_ALD(d, REG_PV, disp);
+
                        } else {
-                               M_INTMOVE(REG_ZERO, d);
+                               if (iptr->val.a == NULL) {
+                                       M_INTMOVE(REG_ZERO, d);
+                               } else {
+                                       disp = dseg_addaddress(cd, iptr->val.a);
+                                       M_ALD(d, REG_PV, disp);
+                               }
                        }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -665,10 +546,11 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                            (iptr->dst->varnum == iptr->op1))
                                break;
                        var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
-                       if (var->flags & INMEMORY)
-                               M_LLD(d, REG_SP, 8 * var->regoff);
-                       else
-                               {M_INTMOVE(var->regoff,d);}
+                       if (var->flags & INMEMORY) {
+                               M_LLD(d, REG_SP, var->regoff * 8);
+                       } else {
+                               M_INTMOVE(var->regoff, d);
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -680,10 +562,11 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                            (iptr->dst->varnum == iptr->op1))
                                break;
                        var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
-                       if (var->flags & INMEMORY)
-                               M_DLD(d, REG_SP, 8 * var->regoff);
-                       else
-                               {M_FLTMOVE(var->regoff,d);}
+                       if (var->flags & INMEMORY) {
+                               M_DLD(d, REG_SP, var->regoff * 8);
+                       } else {
+                               M_FLTMOVE(var->regoff, d);
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -698,12 +581,11 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
                        if (var->flags & INMEMORY) {
                                var_to_reg_int(s1, src, REG_ITMP1);
-                               M_LST(s1, REG_SP, 8 * var->regoff);
-                               }
-                       else {
+                               M_LST(s1, REG_SP, var->regoff * 8);
+                       } else {
                                var_to_reg_int(s1, src, var->regoff);
                                M_INTMOVE(s1, var->regoff);
-                               }
+                       }
                        break;
 
                case ICMD_FSTORE:     /* ..., value  ==> ...                          */
@@ -715,12 +597,11 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
                        if (var->flags & INMEMORY) {
                                var_to_reg_flt(s1, src, REG_FTMP1);
-                               M_DST(s1, REG_SP, 8 * var->regoff);
-                               }
-                       else {
+                               M_DST(s1, REG_SP, var->regoff * 8);
+                       } else {
                                var_to_reg_flt(s1, src, var->regoff);
                                M_FLTMOVE(s1, var->regoff);
-                               }
+                       }
                        break;
 
 
@@ -788,7 +669,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_INEG:       /* ..., value  ==> ..., - value                 */
 
                        var_to_reg_int(s1, src, REG_ITMP1); 
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_ISUB(REG_ZERO, s1, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -796,7 +677,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_LNEG:       /* ..., value  ==> ..., - value                 */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_LSUB(REG_ZERO, s1, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -804,7 +685,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_I2L:        /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_INTMOVE(s1, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -812,29 +693,28 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_L2I:        /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                       M_IADD(s1, REG_ZERO, d );
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                       M_IADD(s1, REG_ZERO, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
                case ICMD_INT2BYTE:   /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (has_ext_instr_set) {
                                M_BSEXT(s1, d);
-                               }
-                       else {
+                       } else {
                                M_SLL_IMM(s1, 56, d);
                                M_SRA_IMM( d, 56, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
                case ICMD_INT2CHAR:   /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
             M_CZEXT(s1, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -842,14 +722,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_INT2SHORT:  /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (has_ext_instr_set) {
                                M_SSEXT(s1, d);
-                               }
-                       else {
+                       } else {
                                M_SLL_IMM(s1, 48, d);
                                M_SRA_IMM( d, 48, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -858,7 +737,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_IADD(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -867,14 +746,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_IADD_IMM(s1, iptr->val.i, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_IADD(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -882,7 +760,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_LADD(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -891,14 +769,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_LADD_IMM(s1, iptr->val.l, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_LADD(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -906,7 +783,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_ISUB(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -915,14 +792,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_ISUB_IMM(s1, iptr->val.i, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_ISUB(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -930,7 +806,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_LSUB(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -939,14 +815,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_LSUB_IMM(s1, iptr->val.l, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_LSUB(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -954,7 +829,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_IMUL(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -963,14 +838,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_IMUL_IMM(s1, iptr->val.i, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_IMUL(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -978,8 +852,8 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                       M_LMUL (s1, s2, d);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                       M_LMUL(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -987,14 +861,57 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_LMUL_IMM(s1, iptr->val.l, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_LMUL(s1, REG_ITMP2, d);
-                               }
+                       }
+                       store_reg_to_var_int(iptr->dst, d);
+                       break;
+
+               case ICMD_IDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
+               case ICMD_IREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
+
+                       var_to_reg_int(s1, src->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src, REG_ITMP2);
+                       d = reg_of_var(rd, iptr->dst, REG_RESULT);
+                       M_BEQZ(s2, 0);
+                       codegen_add_arithmeticexception_ref(cd, mcodeptr);
+
+                       M_MOV(s1, rd->argintregs[0]);
+                       M_MOV(s2, rd->argintregs[1]);
+                       bte = iptr->val.a;
+                       disp = dseg_addaddress(cd, bte->fp);
+                       M_ALD(REG_PV, REG_PV, disp);
+                       M_JSR(REG_RA, REG_PV);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
+
+                       M_IADD(REG_RESULT, REG_ZERO, d); /* sign extend (bugfix for gcc -O2) */
+                       store_reg_to_var_int(iptr->dst, d);
+                       break;
+
+               case ICMD_LDIV:       /* ..., val1, val2  ==> ..., val1 / val2        */
+               case ICMD_LREM:       /* ..., val1, val2  ==> ..., val1 % val2        */
+
+                       var_to_reg_int(s1, src->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src, REG_ITMP2);
+                       d = reg_of_var(rd, iptr->dst, REG_RESULT);
+                       M_BEQZ(s2, 0);
+                       codegen_add_arithmeticexception_ref(cd, mcodeptr);
+
+                       M_MOV(s1, rd->argintregs[0]);
+                       M_MOV(s2, rd->argintregs[1]);
+                       bte = iptr->val.a;
+                       disp = dseg_addaddress(cd, bte->fp);
+                       M_ALD(REG_PV, REG_PV, disp);
+                       M_JSR(REG_RA, REG_PV);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
+
+                       M_INTMOVE(REG_RESULT, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1002,16 +919,15 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_LDIVPOW2:   /* val.i = constant                             */
                                      
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (iptr->val.i <= 15) {
                                M_LDA(REG_ITMP2, s1, (1 << iptr->val.i) -1);
                                M_CMOVGE(s1, s1, REG_ITMP2);
-                               }
-                       else {
+                       } else {
                                M_SRA_IMM(s1, 63, REG_ITMP2);
                                M_SRL_IMM(REG_ITMP2, 64 - iptr->val.i, REG_ITMP2);
                                M_LADD(s1, REG_ITMP2, REG_ITMP2);
-                               }
+                       }
                        M_SRA_IMM(REG_ITMP2, iptr->val.i, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1020,7 +936,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_AND_IMM(s2, 0x1f, REG_ITMP3);
                        M_SLL(s1, REG_ITMP3, d);
                        M_IADD(d, REG_ZERO, d);
@@ -1031,7 +947,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SLL_IMM(s1, iptr->val.i & 0x1f, d);
                        M_IADD(d, REG_ZERO, d);
                        store_reg_to_var_int(iptr->dst, d);
@@ -1041,7 +957,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_AND_IMM(s2, 0x1f, REG_ITMP3);
                        M_SRA(s1, REG_ITMP3, d);
                        store_reg_to_var_int(iptr->dst, d);
@@ -1051,7 +967,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SRA_IMM(s1, iptr->val.i & 0x1f, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1060,7 +976,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_AND_IMM(s2, 0x1f, REG_ITMP2);
             M_IZEXT(s1, d);
                        M_SRL(d, REG_ITMP2, d);
@@ -1072,7 +988,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
             M_IZEXT(s1, d);
                        M_SRL_IMM(d, iptr->val.i & 0x1f, d);
                        M_IADD(d, REG_ZERO, d);
@@ -1083,7 +999,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SLL(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1092,7 +1008,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SLL_IMM(s1, iptr->val.i & 0x3f, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1101,7 +1017,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SRA(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1110,7 +1026,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SRA_IMM(s1, iptr->val.i & 0x3f, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1119,7 +1035,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SRL(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1128,7 +1044,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_SRL_IMM(s1, iptr->val.i & 0x3f, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1138,7 +1054,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_AND(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1147,20 +1063,17 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_AND_IMM(s1, iptr->val.i, d);
-                               }
-                       else if (iptr->val.i == 0xffff) {
+                       } else if (iptr->val.i == 0xffff) {
                                M_CZEXT(s1, d);
-                               }
-                       else if (iptr->val.i == 0xffffff) {
+                       } else if (iptr->val.i == 0xffffff) {
                                M_ZAPNOT_IMM(s1, 0x07, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_AND(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1168,36 +1081,33 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (s1 == d) {
                                M_MOV(s1, REG_ITMP1);
                                s1 = REG_ITMP1;
-                               }
+                       }
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_AND_IMM(s1, iptr->val.i, d);
                                M_BGEZ(s1, 3);
                                M_ISUB(REG_ZERO, s1, d);
                                M_AND_IMM(d, iptr->val.i, d);
-                               }
-                       else if (iptr->val.i == 0xffff) {
+                       } else if (iptr->val.i == 0xffff) {
                                M_CZEXT(s1, d);
                                M_BGEZ(s1, 3);
                                M_ISUB(REG_ZERO, s1, d);
                                M_CZEXT(d, d);
-                               }
-                       else if (iptr->val.i == 0xffffff) {
+                       } else if (iptr->val.i == 0xffffff) {
                                M_ZAPNOT_IMM(s1, 0x07, d);
                                M_BGEZ(s1, 3);
                                M_ISUB(REG_ZERO, s1, d);
                                M_ZAPNOT_IMM(d, 0x07, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_AND(s1, REG_ITMP2, d);
                                M_BGEZ(s1, 3);
                                M_ISUB(REG_ZERO, s1, d);
                                M_AND(d, REG_ITMP2, d);
-                               }
+                       }
                        M_ISUB(REG_ZERO, d, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1206,32 +1116,25 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_AND_IMM(s1, iptr->val.l, d);
-                               }
-                       else if (iptr->val.l == 0xffffL) {
+                       } else if (iptr->val.l == 0xffffL) {
                                M_CZEXT(s1, d);
-                               }
-                       else if (iptr->val.l == 0xffffffL) {
+                       } else if (iptr->val.l == 0xffffffL) {
                                M_ZAPNOT_IMM(s1, 0x07, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffL) {
                                M_IZEXT(s1, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffffL) {
                                M_ZAPNOT_IMM(s1, 0x1f, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffffffL) {
                                M_ZAPNOT_IMM(s1, 0x3f, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffffffffL) {
                                M_ZAPNOT_IMM(s1, 0x7f, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_AND(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1239,60 +1142,53 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (s1 == d) {
                                M_MOV(s1, REG_ITMP1);
                                s1 = REG_ITMP1;
-                               }
+                       }
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_AND_IMM(s1, iptr->val.l, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_AND_IMM(d, iptr->val.l, d);
-                               }
-                       else if (iptr->val.l == 0xffffL) {
+                       } else if (iptr->val.l == 0xffffL) {
                                M_CZEXT(s1, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_CZEXT(d, d);
-                               }
-                       else if (iptr->val.l == 0xffffffL) {
+                       } else if (iptr->val.l == 0xffffffL) {
                                M_ZAPNOT_IMM(s1, 0x07, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_ZAPNOT_IMM(d, 0x07, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffL) {
                                M_IZEXT(s1, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_IZEXT(d, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffffL) {
                                M_ZAPNOT_IMM(s1, 0x1f, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_ZAPNOT_IMM(d, 0x1f, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffffffL) {
                                M_ZAPNOT_IMM(s1, 0x3f, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_ZAPNOT_IMM(d, 0x3f, d);
-                               }
-                       else if (iptr->val.l == 0xffffffffffffffL) {
+                       } else if (iptr->val.l == 0xffffffffffffffL) {
                                M_ZAPNOT_IMM(s1, 0x7f, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_ZAPNOT_IMM(d, 0x7f, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_AND(s1, REG_ITMP2, d);
                                M_BGEZ(s1, 3);
                                M_LSUB(REG_ZERO, s1, d);
                                M_AND(d, REG_ITMP2, d);
-                               }
+                       }
                        M_LSUB(REG_ZERO, d, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1302,7 +1198,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_OR( s1,s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1311,14 +1207,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_OR_IMM(s1, iptr->val.i, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_OR(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1326,14 +1221,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_OR_IMM(s1, iptr->val.l, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_OR(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1342,7 +1236,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_XOR(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1351,14 +1245,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_XOR_IMM(s1, iptr->val.i, d);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, iptr->val.i);
                                M_XOR(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1366,14 +1259,13 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_XOR_IMM(s1, iptr->val.l, d);
-                               }
-                       else {
+                       } else {
                                LCONST(REG_ITMP2, iptr->val.l);
                                M_XOR(s1, REG_ITMP2, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1382,10 +1274,10 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        M_CMPLT(s1, s2, REG_ITMP3);
                        M_CMPLT(s2, s1, REG_ITMP1);
-                       M_LSUB (REG_ITMP1, REG_ITMP3, d);
+                       M_LSUB(REG_ITMP1, REG_ITMP3, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1396,22 +1288,19 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        var = &(rd->locals[iptr->op1][TYPE_INT]);
                        if (var->flags & INMEMORY) {
                                s1 = REG_ITMP1;
-                               M_LLD(s1, REG_SP, 8 * var->regoff);
-                               }
-                       else
+                               M_LLD(s1, REG_SP, var->regoff * 8);
+                       } else
                                s1 = var->regoff;
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_IADD_IMM(s1, iptr->val.i, s1);
-                               }
-                       else if ((iptr->val.i > -256) && (iptr->val.i < 0)) {
+                       } else if ((iptr->val.i > -256) && (iptr->val.i < 0)) {
                                M_ISUB_IMM(s1, (-iptr->val.i), s1);
-                               }
-                       else {
+                       } else {
                                M_LDA (s1, s1, iptr->val.i);
                                M_IADD(s1, REG_ZERO, s1);
-                               }
+                       }
                        if (var->flags & INMEMORY)
-                               M_LST(s1, REG_SP, 8 * var->regoff);
+                               M_LST(s1, REG_SP, var->regoff * 8);
                        break;
 
 
@@ -1420,7 +1309,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_FNEG:       /* ..., value  ==> ..., - value                 */
 
                        var_to_reg_flt(s1, src, REG_FTMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP2);
                        M_FMOVN(s1, d);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
@@ -1428,7 +1317,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_DNEG:       /* ..., value  ==> ..., - value                 */
 
                        var_to_reg_flt(s1, src, REG_FTMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP2);
                        M_FMOVN(s1, d);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
@@ -1440,18 +1329,16 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_FADD(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_FADDS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_FADDS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -1462,18 +1349,16 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_DADD(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_DADDS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_DADDS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -1484,18 +1369,16 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_FSUB(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_FSUBS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_FSUBS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -1506,18 +1389,16 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_DSUB(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_DSUBS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_DSUBS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -1528,40 +1409,36 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_FMUL(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_FMULS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_FMULS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
-               case ICMD_DMUL:       /* ..., val1, val2  ==> ..., val1 *** val2        */
+               case ICMD_DMUL:       /* ..., val1, val2  ==> ..., val1 *** val2      */
 
                        var_to_reg_flt(s1, src->prev, REG_FTMP1);
                        var_to_reg_flt(s2, src, REG_FTMP2);
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_DMUL(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_DMULS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_DMULS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -1572,18 +1449,16 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_FDIV(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_FDIVS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_FDIVS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
@@ -1594,18 +1469,16 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_DDIV(s1, s2, d);
-                               }
-                       else {
+                       } else {
                                if (d == s1 || d == s2) {
                                        M_DDIVS(s1, s2, REG_FTMP3);
                                        M_TRAPB;
                                        M_FMOV(REG_FTMP3, d);
-                                       }
-                               else {
+                               } else {
                                        M_DDIVS(s1, s2, d);
                                        M_TRAPB;
-                                       }
                                }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
                
@@ -1613,9 +1486,9 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_L2F:
                        var_to_reg_int(s1, src, REG_ITMP1);
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
-                       a = dseg_adddouble(cd, 0.0);
-                       M_LST (s1, REG_PV, a);
-                       M_DLD (d, REG_PV, a);
+                       disp = dseg_adddouble(cd, 0.0);
+                       M_LST(s1, REG_PV, disp);
+                       M_DLD(d, REG_PV, disp);
                        M_CVTLF(d, d);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
@@ -1624,9 +1497,9 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_L2D:
                        var_to_reg_int(s1, src, REG_ITMP1);
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
-                       a = dseg_adddouble(cd, 0.0);
-                       M_LST (s1, REG_PV, a);
-                       M_DLD (d, REG_PV, a);
+                       disp = dseg_adddouble(cd, 0.0);
+                       M_LST(s1, REG_PV, disp);
+                       M_DLD(d, REG_PV, disp);
                        M_CVTLD(d, d);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
@@ -1635,11 +1508,11 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_D2I:
                        var_to_reg_flt(s1, src, REG_FTMP1);
                        d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                       a = dseg_adddouble(cd, 0.0);
+                       disp = dseg_adddouble(cd, 0.0);
                        M_CVTDL_C(s1, REG_FTMP2);
                        M_CVTLI(REG_FTMP2, REG_FTMP3);
-                       M_DST (REG_FTMP3, REG_PV, a);
-                       M_ILD (d, REG_PV, a);
+                       M_DST(REG_FTMP3, REG_PV, disp);
+                       M_ILD(d, REG_PV, disp);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
                
@@ -1647,10 +1520,10 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_D2L:
                        var_to_reg_flt(s1, src, REG_FTMP1);
                        d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                       a = dseg_adddouble(cd, 0.0);
+                       disp = dseg_adddouble(cd, 0.0);
                        M_CVTDL_C(s1, REG_FTMP2);
-                       M_DST (REG_FTMP2, REG_PV, a);
-                       M_LLD (d, REG_PV, a);
+                       M_DST(REG_FTMP2, REG_PV, disp);
+                       M_LLD(d, REG_PV, disp);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1669,11 +1542,10 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_CVTDF(s1, d);
-                               }
-                       else {
+                       } else {
                                M_CVTDFS(s1, d);
                                M_TRAPB;
-                               }
+                       }
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
                
@@ -1690,8 +1562,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                M_FCMPLT(s2, s1, REG_FTMP3);
                                M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
                                M_LADD_IMM(REG_ZERO, 1, d);
-                               }
-                       else {
+                       } else {
                                M_LSUB_IMM(REG_ZERO, 1, d);
                                M_FCMPEQS(s1, s2, REG_FTMP3);
                                M_TRAPB;
@@ -1701,7 +1572,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                M_TRAPB;
                                M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
                                M_LADD_IMM(REG_ZERO, 1, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
                        
@@ -1718,8 +1589,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                M_FCMPLT(s1, s2, REG_FTMP3);
                                M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
                                M_LSUB_IMM(REG_ZERO, 1, d);
-                               }
-                       else {
+                       } else {
                                M_LADD_IMM(REG_ZERO, 1, d);
                                M_FCMPEQS(s1, s2, REG_FTMP3);
                                M_TRAPB;
@@ -1729,7 +1599,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                M_TRAPB;
                                M_FBEQZ (REG_FTMP3, 1);        /* jump over next instruction  */
                                M_LSUB_IMM(REG_ZERO, 1, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1739,37 +1609,80 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_ARRAYLENGTH: /* ..., arrayref  ==> ..., length              */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        gen_nullptr_check(s1);
                        M_ILD(d, s1, OFFSET(java_arrayheader, size));
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
-               case ICMD_AALOAD:     /* ..., arrayref, index  ==> ..., value         */
+               case ICMD_BALOAD:     /* ..., arrayref, index  ==> ..., value         */
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
-                       M_SAADDQ(s2, s1, REG_ITMP1);
-                       M_ALD( d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
+                       }
+                       if (has_ext_instr_set) {
+                               M_LADD   (s2, s1, REG_ITMP1);
+                               M_BLDU   (d, REG_ITMP1, OFFSET (java_bytearray, data[0]));
+                               M_BSEXT  (d, d);
+                       } else {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0])+1);
+                               M_EXTQH(REG_ITMP2, REG_ITMP1, d);
+                               M_SRA_IMM(d, 56, d);
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
-               case ICMD_LALOAD:     /* ..., arrayref, index  ==> ..., value         */
+               case ICMD_CALOAD:     /* ..., arrayref, index  ==> ..., value         */
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
-                       M_S8ADDQ(s2, s1, REG_ITMP1);
-                       M_LLD(d, REG_ITMP1, OFFSET(java_longarray, data[0]));
+                       }
+                       if (has_ext_instr_set) {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_SLDU(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                       } else {
+                               M_LADD (s2, s1, REG_ITMP1);
+                               M_LADD (s2, REG_ITMP1, REG_ITMP1);
+                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                               M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                               M_EXTWL(REG_ITMP2, REG_ITMP1, d);
+                       }
+                       store_reg_to_var_int(iptr->dst, d);
+                       break;                  
+
+               case ICMD_SALOAD:     /* ..., arrayref, index  ==> ..., value         */
+
+                       var_to_reg_int(s1, src->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src, REG_ITMP2);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                       }
+                       if (has_ext_instr_set) {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_SLDU( d, REG_ITMP1, OFFSET (java_shortarray, data[0]));
+                               M_SSEXT(d, d);
+                       } else {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0])+2);
+                               M_EXTQH(REG_ITMP2, REG_ITMP1, d);
+                               M_SRA_IMM(d, 48, d);
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -1777,26 +1690,39 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
-                 
+                       }
                        M_S4ADDQ(s2, s1, REG_ITMP1);
                        M_ILD(d, REG_ITMP1, OFFSET(java_intarray, data[0]));
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
+               case ICMD_LALOAD:     /* ..., arrayref, index  ==> ..., value         */
+
+                       var_to_reg_int(s1, src->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src, REG_ITMP2);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                       if (iptr->op1 == 0) {
+                               gen_nullptr_check(s1);
+                               gen_bound_check;
+                       }
+                       M_S8ADDQ(s2, s1, REG_ITMP1);
+                       M_LLD(d, REG_ITMP1, OFFSET(java_longarray, data[0]));
+                       store_reg_to_var_int(iptr->dst, d);
+                       break;
+
                case ICMD_FALOAD:     /* ..., arrayref, index  ==> ..., value         */
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
                        M_S4ADDQ(s2, s1, REG_ITMP1);
                        M_FLD(d, REG_ITMP1, OFFSET(java_floatarray, data[0]));
                        store_reg_to_var_flt(iptr->dst, d);
@@ -1806,129 +1732,128 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
                        M_S8ADDQ(s2, s1, REG_ITMP1);
                        M_DLD(d, REG_ITMP1, OFFSET(java_doublearray, data[0]));
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
 
-               case ICMD_CALOAD:     /* ..., arrayref, index  ==> ..., value         */
+               case ICMD_AALOAD:     /* ..., arrayref, index  ==> ..., value         */
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
-                       if (has_ext_instr_set) {
-                               M_LADD(s2, s1, REG_ITMP1);
-                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
-                               M_SLDU(d, REG_ITMP1, OFFSET(java_chararray, data[0]));
-                               }
-                       else {
-                               M_LADD (s2, s1, REG_ITMP1);
-                               M_LADD (s2, REG_ITMP1, REG_ITMP1);
-                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
-                               M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
-                               M_EXTWL(REG_ITMP2, REG_ITMP1, d);
-                               }
+                       }
+                       M_SAADDQ(s2, s1, REG_ITMP1);
+                       M_ALD(d, REG_ITMP1, OFFSET(java_objectarray, data[0]));
                        store_reg_to_var_int(iptr->dst, d);
-                       break;                  
+                       break;
 
-               case ICMD_SALOAD:     /* ..., arrayref, index  ==> ..., value         */
 
-                       var_to_reg_int(s1, src->prev, REG_ITMP1);
-                       var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+               case ICMD_BASTORE:    /* ..., arrayref, index, value  ==> ...         */
+
+                       var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src->prev, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
+                       var_to_reg_int(s3, src, REG_ITMP3);
                        if (has_ext_instr_set) {
                                M_LADD(s2, s1, REG_ITMP1);
-                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
-                               M_SLDU( d, REG_ITMP1, OFFSET (java_shortarray, data[0]));
-                               M_SSEXT(d, d);
-                               }
-                       else {
+                               M_BST(s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+                       } else {
                                M_LADD(s2, s1, REG_ITMP1);
-                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
-                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
-                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0])+2);
-                               M_EXTQH(REG_ITMP2, REG_ITMP1, d);
-                               M_SRA_IMM(d, 48, d);
-                               }
-                       store_reg_to_var_int(iptr->dst, d);
+                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0]));
+                               M_INSBL(s3, REG_ITMP1, REG_ITMP3);
+                               M_MSKBL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
+                               M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2);
+                               M_LST_U(REG_ITMP2, REG_ITMP1, 0);
+                       }
                        break;
 
-               case ICMD_BALOAD:     /* ..., arrayref, index  ==> ..., value         */
+               case ICMD_CASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
-                       var_to_reg_int(s1, src->prev, REG_ITMP1);
-                       var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
+                       var_to_reg_int(s2, src->prev, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
+                       var_to_reg_int(s3, src, REG_ITMP3);
                        if (has_ext_instr_set) {
-                               M_LADD   (s2, s1, REG_ITMP1);
-                               M_BLDU   (d, REG_ITMP1, OFFSET (java_bytearray, data[0]));
-                               M_BSEXT  (d, d);
-                               }
-                       else {
                                M_LADD(s2, s1, REG_ITMP1);
-                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
-                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0])+1);
-                               M_EXTQH(REG_ITMP2, REG_ITMP1, d);
-                               M_SRA_IMM(d, 56, d);
-                               }
-                       store_reg_to_var_int(iptr->dst, d);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_SST(s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                       } else {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
+                               M_INSWL(s3, REG_ITMP1, REG_ITMP3);
+                               M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
+                               M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2);
+                               M_LST_U(REG_ITMP2, REG_ITMP1, 0);
+                       }
                        break;
 
-
-               case ICMD_AASTORE:    /* ..., arrayref, index, value  ==> ...         */
+               case ICMD_SASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
                        var_to_reg_int(s3, src, REG_ITMP3);
-                       M_SAADDQ(s2, s1, REG_ITMP1);
-                       M_AST   (s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
+                       if (has_ext_instr_set) {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_SST(s3, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+                       } else {
+                               M_LADD(s2, s1, REG_ITMP1);
+                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
+                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+                               M_LDA(REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0]));
+                               M_INSWL(s3, REG_ITMP1, REG_ITMP3);
+                               M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
+                               M_OR(REG_ITMP2, REG_ITMP3, REG_ITMP2);
+                               M_LST_U(REG_ITMP2, REG_ITMP1, 0);
+                       }
                        break;
 
-               case ICMD_LASTORE:    /* ..., arrayref, index, value  ==> ...         */
+               case ICMD_IASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
                        var_to_reg_int(s3, src, REG_ITMP3);
-                       M_S8ADDQ(s2, s1, REG_ITMP1);
-                       M_LST   (s3, REG_ITMP1, OFFSET(java_longarray, data[0]));
+                       M_S4ADDQ(s2, s1, REG_ITMP1);
+                       M_IST(s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
                        break;
 
-               case ICMD_IASTORE:    /* ..., arrayref, index, value  ==> ...         */
+               case ICMD_LASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
-
+                       }
                        var_to_reg_int(s3, src, REG_ITMP3);
-                       M_S4ADDQ(s2, s1, REG_ITMP1);
-                       M_IST   (s3, REG_ITMP1, OFFSET(java_intarray, data[0]));
+                       M_S8ADDQ(s2, s1, REG_ITMP1);
+                       M_LST(s3, REG_ITMP1, OFFSET(java_longarray, data[0]));
                        break;
 
                case ICMD_FASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1938,10 +1863,10 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
                        var_to_reg_flt(s3, src, REG_FTMP3);
                        M_S4ADDQ(s2, s1, REG_ITMP1);
-                       M_FST   (s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
+                       M_FST(s3, REG_ITMP1, OFFSET(java_floatarray, data[0]));
                        break;
 
                case ICMD_DASTORE:    /* ..., arrayref, index, value  ==> ...         */
@@ -1951,86 +1876,38 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
                        var_to_reg_flt(s3, src, REG_FTMP3);
                        M_S8ADDQ(s2, s1, REG_ITMP1);
-                       M_DST   (s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
+                       M_DST(s3, REG_ITMP1, OFFSET(java_doublearray, data[0]));
                        break;
 
-               case ICMD_CASTORE:    /* ..., arrayref, index, value  ==> ...         */
+               case ICMD_AASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
-                               }
+                       }
                        var_to_reg_int(s3, src, REG_ITMP3);
-                       if (has_ext_instr_set) {
-                               M_LADD(s2, s1, REG_ITMP1);
-                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
-                               M_SST (s3, REG_ITMP1, OFFSET(java_chararray, data[0]));
-                               }
-                       else {
-                               M_LADD (s2, s1, REG_ITMP1);
-                               M_LADD (s2, REG_ITMP1, REG_ITMP1);
-                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_chararray, data[0]));
-                               M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_chararray, data[0]));
-                               M_INSWL(s3, REG_ITMP1, REG_ITMP3);
-                               M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
-                               M_OR   (REG_ITMP2, REG_ITMP3, REG_ITMP2);
-                               M_LST_U(REG_ITMP2, REG_ITMP1, 0);
-                               }
-                       break;
-
-               case ICMD_SASTORE:    /* ..., arrayref, index, value  ==> ...         */
 
-                       var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
-                       var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       if (iptr->op1 == 0) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                               }
-                       var_to_reg_int(s3, src, REG_ITMP3);
-                       if (has_ext_instr_set) {
-                               M_LADD(s2, s1, REG_ITMP1);
-                               M_LADD(s2, REG_ITMP1, REG_ITMP1);
-                               M_SST (s3, REG_ITMP1, OFFSET(java_shortarray, data[0]));
-                               }
-                       else {
-                               M_LADD (s2, s1, REG_ITMP1);
-                               M_LADD (s2, REG_ITMP1, REG_ITMP1);
-                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_shortarray, data[0]));
-                               M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_shortarray, data[0]));
-                               M_INSWL(s3, REG_ITMP1, REG_ITMP3);
-                               M_MSKWL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
-                               M_OR   (REG_ITMP2, REG_ITMP3, REG_ITMP2);
-                               M_LST_U(REG_ITMP2, REG_ITMP1, 0);
-                               }
-                       break;
+                       M_MOV(s1, rd->argintregs[0]);
+                       M_MOV(s3, rd->argintregs[1]);
+                       disp = dseg_addaddress(cd, BUILTIN_canstore);
+                       M_ALD(REG_PV, REG_PV, disp);
+                       M_JSR(REG_RA, REG_PV);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
 
-               case ICMD_BASTORE:    /* ..., arrayref, index, value  ==> ...         */
+                       M_BEQZ(REG_RESULT, 0);
+                       codegen_add_arraystoreexception_ref(cd, mcodeptr);
 
                        var_to_reg_int(s1, src->prev->prev, REG_ITMP1);
                        var_to_reg_int(s2, src->prev, REG_ITMP2);
-                       if (iptr->op1 == 0) {
-                               gen_nullptr_check(s1);
-                               gen_bound_check;
-                               }
                        var_to_reg_int(s3, src, REG_ITMP3);
-                       if (has_ext_instr_set) {
-                               M_LADD(s2, s1, REG_ITMP1);
-                               M_BST (s3, REG_ITMP1, OFFSET(java_bytearray, data[0]));
-                               }
-                       else {
-                               M_LADD (s2, s1, REG_ITMP1);
-                               M_LLD_U(REG_ITMP2, REG_ITMP1, OFFSET(java_bytearray, data[0]));
-                               M_LDA  (REG_ITMP1, REG_ITMP1, OFFSET(java_bytearray, data[0]));
-                               M_INSBL(s3, REG_ITMP1, REG_ITMP3);
-                               M_MSKBL(REG_ITMP2, REG_ITMP1, REG_ITMP2);
-                               M_OR   (REG_ITMP2, REG_ITMP3, REG_ITMP2);
-                               M_LST_U(REG_ITMP2, REG_ITMP1, 0);
-                               }
+                       M_SAADDQ(s2, s1, REG_ITMP1);
+                       M_AST(s3, REG_ITMP1, OFFSET(java_objectarray, data[0]));
                        break;
 
 
@@ -2147,45 +2024,45 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_GETSTATIC:  /* ...  ==> ..., value                          */
                                      /* op1 = type, val.a = field address            */
 
-                       if (!iptr->val.a) {
+                       if (iptr->val.a == NULL) {
+                               disp = dseg_addaddress(cd, 0);
+
                                codegen_addpatchref(cd, mcodeptr,
                                                                        PATCHER_get_putstatic,
-                                                                       (unresolved_field *) iptr->target);
+                                                                       (unresolved_field *) iptr->target, disp);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = 0;
 
                        } else {
                                fieldinfo *fi = iptr->val.a;
 
-                               if (!fi->class->initialized) {
+                               disp = dseg_addaddress(cd, &(fi->value));
+
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
                                        codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_clinit, fi->class);
+                                                                               PATCHER_clinit, fi->class, 0);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
                                }
-
-                               a = (ptrint) &(fi->value);
                        }
 
-                       a = dseg_addaddress(cd, a);
-                       M_ALD(REG_ITMP1, REG_PV, a);
+                       M_ALD(REG_ITMP1, REG_PV, disp);
                        switch (iptr->op1) {
                        case TYPE_INT:
-                               d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                               d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                                M_ILD(d, REG_ITMP1, 0);
                                store_reg_to_var_int(iptr->dst, d);
                                break;
                        case TYPE_LNG:
-                               d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                               d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                                M_LLD(d, REG_ITMP1, 0);
                                store_reg_to_var_int(iptr->dst, d);
                                break;
                        case TYPE_ADR:
-                               d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                               d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                                M_ALD(d, REG_ITMP1, 0);
                                store_reg_to_var_int(iptr->dst, d);
                                break;
@@ -2205,32 +2082,31 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_PUTSTATIC:  /* ..., value  ==> ...                          */
                                      /* op1 = type, val.a = field address            */
 
-                       if (!iptr->val.a) {
+                       if (iptr->val.a == NULL) {
+                               disp = dseg_addaddress(cd, 0);
+
                                codegen_addpatchref(cd, mcodeptr,
                                                                        PATCHER_get_putstatic,
-                                                                       (unresolved_field *) iptr->target);
+                                                                       (unresolved_field *) iptr->target, disp);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = 0;
-
                        } else {
                                fieldinfo *fi = iptr->val.a;
 
-                               if (!fi->class->initialized) {
+                               disp = dseg_addaddress(cd, &(fi->value));
+
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
                                        codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_clinit, fi->class);
+                                                                               PATCHER_clinit, fi->class, 0);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
                                }
-
-                               a = (ptrint) &(fi->value);
                        }
 
-                       a = dseg_addaddress(cd, a);
-                       M_ALD(REG_ITMP1, REG_PV, a);
+                       M_ALD(REG_ITMP1, REG_PV, disp);
                        switch (iptr->op1) {
                        case TYPE_INT:
                                var_to_reg_int(s2, src, REG_ITMP2);
@@ -2260,32 +2136,31 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                          /* op1 = type, val.a = field address (in    */
                                          /* following NOP)                           */
 
-                       if (!iptr[1].val.a) {
+                       if (iptr[1].val.a == NULL) {
+                               disp = dseg_addaddress(cd, 0);
+
                                codegen_addpatchref(cd, mcodeptr,
                                                                        PATCHER_get_putstatic,
-                                                                       (unresolved_field *) iptr[1].target);
+                                                                       (unresolved_field *) iptr[1].target, disp);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = 0;
-
                        } else {
                                fieldinfo *fi = iptr[1].val.a;
+       
+                               disp = dseg_addaddress(cd, &(fi->value));
 
-                               if (!fi->class->initialized) {
+                               if (!CLASS_IS_OR_ALMOST_INITIALIZED(fi->class)) {
                                        codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_clinit, fi->class);
+                                                                               PATCHER_clinit, fi->class, 0);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
                                }
-
-                               a = (ptrint) &(fi->value);
                        }
                        
-                       a = dseg_addaddress(cd, a);
-                       M_ALD(REG_ITMP1, REG_PV, a);
+                       M_ALD(REG_ITMP1, REG_PV, disp);
                        switch (iptr->op1) {
                        case TYPE_INT:
                                M_IST(REG_ZERO, REG_ITMP1, 0);
@@ -2306,94 +2181,137 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        break;
 
 
-               case ICMD_PUTFIELD:   /* ..., objectref, value  ==> ...               */
-                                     /* op1 = type, val.a = field address            */
+               case ICMD_GETFIELD:   /* ...  ==> ..., value                          */
+                                     /* op1 = type, val.i = field offset             */
 
-                       a = ((fieldinfo *) iptr->val.a)->offset;
-                       var_to_reg_int(s1, src->prev, REG_ITMP1);
+                       var_to_reg_int(s1, src, REG_ITMP1);
                        gen_nullptr_check(s1);
+
+                       if (iptr->val.a == NULL) {
+                               codegen_addpatchref(cd, mcodeptr,
+                                                                       PATCHER_get_putfield,
+                                                                       (unresolved_field *) iptr->target, 0);
+
+                               if (opt_showdisassemble)
+                                       M_NOP;
+
+                               disp = 0;
+
+                       } else {
+                               disp = ((fieldinfo *) (iptr->val.a))->offset;
+                       }
+
                        switch (iptr->op1) {
                        case TYPE_INT:
-                               var_to_reg_int(s2, src, REG_ITMP2);
-                               M_IST(s2, s1, a);
+                               d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                               M_ILD(d, s1, disp);
+                               store_reg_to_var_int(iptr->dst, d);
                                break;
                        case TYPE_LNG:
-                               var_to_reg_int(s2, src, REG_ITMP2);
-                               M_LST(s2, s1, a);
+                               d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                               M_LLD(d, s1, disp);
+                               store_reg_to_var_int(iptr->dst, d);
                                break;
                        case TYPE_ADR:
-                               var_to_reg_int(s2, src, REG_ITMP2);
-                               M_AST(s2, s1, a);
+                               d = reg_of_var(rd, iptr->dst, REG_ITMP2);
+                               M_ALD(d, s1, disp);
+                               store_reg_to_var_int(iptr->dst, d);
                                break;
                        case TYPE_FLT:
-                               var_to_reg_flt(s2, src, REG_FTMP2);
-                               M_FST(s2, s1, a);
+                               d = reg_of_var(rd, iptr->dst, REG_FTMP1);
+                               M_FLD(d, s1, disp);
+                               store_reg_to_var_flt(iptr->dst, d);
                                break;
-                       case TYPE_DBL:
-                               var_to_reg_flt(s2, src, REG_FTMP2);
-                               M_DST(s2, s1, a);
+                       case TYPE_DBL:                          
+                               d = reg_of_var(rd, iptr->dst, REG_FTMP1);
+                               M_DLD(d, s1, disp);
+                               store_reg_to_var_flt(iptr->dst, d);
                                break;
                        }
                        break;
 
-               case ICMD_PUTFIELDCONST:  /* ..., objectref  ==> ...                  */
-                                         /* val = value (in current instruction)     */
-                                         /* op1 = type, val.a = field address (in    */
-                                         /* following NOP)                           */
+               case ICMD_PUTFIELD:   /* ..., objectref, value  ==> ...               */
+                                     /* op1 = type, val.a = field address            */
 
-                       a = ((fieldinfo *) iptr[1].val.a)->offset;
-                       var_to_reg_int(s1, src, REG_ITMP1);
+                       var_to_reg_int(s1, src->prev, REG_ITMP1);
                        gen_nullptr_check(s1);
-                       switch (iptr[1].op1) {
+
+                       if (!IS_FLT_DBL_TYPE(iptr->op1)) {
+                               var_to_reg_int(s2, src, REG_ITMP2);
+                       } else {
+                               var_to_reg_flt(s2, src, REG_FTMP2);
+                       }
+
+                       if (iptr->val.a == NULL) {
+                               codegen_addpatchref(cd, mcodeptr,
+                                                                       PATCHER_get_putfield,
+                                                                       (unresolved_field *) iptr->target, 0);
+
+                               if (opt_showdisassemble)
+                                       M_NOP;
+
+                               disp = 0;
+
+                       } else {
+                               disp = ((fieldinfo *) (iptr->val.a))->offset;
+                       }
+
+                       switch (iptr->op1) {
                        case TYPE_INT:
-                               M_IST(REG_ZERO, s1, a);
+                               M_IST(s2, s1, disp);
                                break;
                        case TYPE_LNG:
-                               M_LST(REG_ZERO, s1, a);
+                               M_LST(s2, s1, disp);
                                break;
                        case TYPE_ADR:
-                               M_AST(REG_ZERO, s1, a);
+                               M_AST(s2, s1, disp);
                                break;
                        case TYPE_FLT:
-                               M_FST(REG_ZERO, s1, a);
+                               M_FST(s2, s1, disp);
                                break;
                        case TYPE_DBL:
-                               M_DST(REG_ZERO, s1, a);
+                               M_DST(s2, s1, disp);
                                break;
                        }
                        break;
 
-               case ICMD_GETFIELD:   /* ...  ==> ..., value                          */
-                                     /* op1 = type, val.i = field offset             */
+               case ICMD_PUTFIELDCONST:  /* ..., objectref  ==> ...                  */
+                                         /* val = value (in current instruction)     */
+                                         /* op1 = type, val.a = field address (in    */
+                                         /* following NOP)                           */
 
-                       a = ((fieldinfo *)(iptr->val.a))->offset;
                        var_to_reg_int(s1, src, REG_ITMP1);
                        gen_nullptr_check(s1);
-                       switch (iptr->op1) {
+
+                       if (iptr[1].val.a == NULL) {
+                               codegen_addpatchref(cd, mcodeptr,
+                                                                       PATCHER_get_putfield,
+                                                                       (unresolved_field *) iptr[1].target, 0);
+
+                               if (opt_showdisassemble)
+                                       M_NOP;
+
+                               disp = 0;
+
+                       } else {
+                               disp = ((fieldinfo *) (iptr[1].val.a))->offset;
+                       }
+
+                       switch (iptr[1].op1) {
                        case TYPE_INT:
-                               d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                               M_ILD(d, s1, a);
-                               store_reg_to_var_int(iptr->dst, d);
+                               M_IST(REG_ZERO, s1, disp);
                                break;
                        case TYPE_LNG:
-                               d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                               M_LLD(d, s1, a);
-                               store_reg_to_var_int(iptr->dst, d);
+                               M_LST(REG_ZERO, s1, disp);
                                break;
                        case TYPE_ADR:
-                               d = reg_of_var(rd, iptr->dst, REG_ITMP3);
-                               M_ALD(d, s1, a);
-                               store_reg_to_var_int(iptr->dst, d);
+                               M_AST(REG_ZERO, s1, disp);
                                break;
                        case TYPE_FLT:
-                               d = reg_of_var(rd, iptr->dst, REG_FTMP1);
-                               M_FLD(d, s1, a);
-                               store_reg_to_var_flt(iptr->dst, d);
+                               M_FST(REG_ZERO, s1, disp);
                                break;
-                       case TYPE_DBL:                          
-                               d = reg_of_var(rd, iptr->dst, REG_FTMP1);
-                               M_DLD(d, s1, a);
-                               store_reg_to_var_flt(iptr->dst, d);
+                       case TYPE_DBL:
+                               M_DST(REG_ZERO, s1, disp);
                                break;
                        }
                        break;
@@ -2401,14 +2319,24 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                /* branch operations **************************************************/
 
-#define ALIGNCODENOP {if((int)((long)mcodeptr&7)){M_NOP;}}
+               case ICMD_ATHROW:       /* ..., objectref ==> ... (, objectref)       */
+
+                       var_to_reg_int(s1, src, REG_ITMP1);
+                       M_INTMOVE(s1, REG_ITMP1_XPTR);
+
+#ifdef ENABLE_VERIFIER
+                       if (iptr->val.a) {
+                               codegen_addpatchref(cd, mcodeptr,
+                                                                       PATCHER_athrow_areturn,
+                                                                       (unresolved_class *) iptr->val.a, 0);
 
-               case ICMD_ATHROW:       /* ..., objectref ==> ... (, objectref)       */
+                               if (opt_showdisassemble)
+                                       M_NOP;
+                       }
+#endif /* ENABLE_VERIFIER */
 
-                       var_to_reg_int(s1, src, REG_ITMP1);
-                       M_INTMOVE(s1, REG_ITMP1_XPTR);
-                       a = dseg_addaddress(cd, asm_handle_exception);
-                       M_ALD(REG_ITMP2, REG_PV, a);
+                       disp = dseg_addaddress(cd, asm_handle_exception);
+                       M_ALD(REG_ITMP2, REG_PV, disp);
                        M_JMP(REG_ITMP2_XPC, REG_ITMP2);
                        M_NOP;              /* nop ensures that XPC is less than the end */
                                            /* of basic block                            */
@@ -2418,7 +2346,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                case ICMD_GOTO:         /* ... ==> ...                                */
                                        /* op1 = target JavaVM pc                     */
                        M_BR(0);
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        ALIGNCODENOP;
                        break;
 
@@ -2426,7 +2354,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* op1 = target JavaVM pc                     */
 
                        M_BSR(REG_ITMP1, 0);
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
                        
                case ICMD_RET:          /* ... ==> ...                                */
@@ -2447,7 +2375,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_BEQZ(s1, 0);
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IFNONNULL:    /* ..., value ==> ...                         */
@@ -2455,7 +2383,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_BNEZ(s1, 0);
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IFEQ:         /* ..., value ==> ...                         */
@@ -2475,7 +2403,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IFLT:         /* ..., value ==> ...                         */
@@ -2495,7 +2423,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IFLE:         /* ..., value ==> ...                         */
@@ -2515,7 +2443,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IFNE:         /* ..., value ==> ...                         */
@@ -2535,7 +2463,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IFGT:         /* ..., value ==> ...                         */
@@ -2555,7 +2483,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IFGE:         /* ..., value ==> ...                         */
@@ -2575,7 +2503,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IF_LEQ:       /* ..., value ==> ...                         */
@@ -2595,7 +2523,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IF_LLT:       /* ..., value ==> ...                         */
@@ -2615,7 +2543,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IF_LLE:       /* ..., value ==> ...                         */
@@ -2635,7 +2563,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IF_LNE:       /* ..., value ==> ...                         */
@@ -2655,7 +2583,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IF_LGT:       /* ..., value ==> ...                         */
@@ -2675,7 +2603,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IF_LGE:       /* ..., value ==> ...                         */
@@ -2695,7 +2623,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IF_ICMPEQ:    /* ..., value, value ==> ...                  */
@@ -2706,7 +2634,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        var_to_reg_int(s2, src, REG_ITMP2);
                        M_CMPEQ(s1, s2, REG_ITMP1);
                        M_BNEZ(REG_ITMP1, 0);
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IF_ICMPNE:    /* ..., value, value ==> ...                  */
@@ -2717,7 +2645,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        var_to_reg_int(s2, src, REG_ITMP2);
                        M_CMPEQ(s1, s2, REG_ITMP1);
                        M_BEQZ(REG_ITMP1, 0);
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IF_ICMPLT:    /* ..., value, value ==> ...                  */
@@ -2727,7 +2655,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        var_to_reg_int(s2, src, REG_ITMP2);
                        M_CMPLT(s1, s2, REG_ITMP1);
                        M_BNEZ(REG_ITMP1, 0);
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IF_ICMPGT:    /* ..., value, value ==> ...                  */
@@ -2737,7 +2665,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        var_to_reg_int(s2, src, REG_ITMP2);
                        M_CMPLE(s1, s2, REG_ITMP1);
                        M_BEQZ(REG_ITMP1, 0);
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IF_ICMPLE:    /* ..., value, value ==> ...                  */
@@ -2747,7 +2675,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        var_to_reg_int(s2, src, REG_ITMP2);
                        M_CMPLE(s1, s2, REG_ITMP1);
                        M_BNEZ(REG_ITMP1, 0);
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                case ICMD_IF_ICMPGE:    /* ..., value, value ==> ...                  */
@@ -2757,7 +2685,7 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                        var_to_reg_int(s2, src, REG_ITMP2);
                        M_CMPLT(s1, s2, REG_ITMP1);
                        M_BEQZ(REG_ITMP1, 0);
-                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, (basicblock *) iptr->target, mcodeptr);
                        break;
 
                /* (value xx 0) ? IFxx_ICONST : ELSE_ICONST                           */
@@ -2769,33 +2697,32 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        s3 = iptr->val.i;
                        if (iptr[1].opc == ICMD_ELSE_ICONST) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPEQ(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPEQ(s1, REG_ZERO, d);
                                        M_XOR_IMM(d, 1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if (s1 == d) {
                                        M_MOV(s1, REG_ITMP1);
                                        s1 = REG_ITMP1;
-                                       }
-                               ICONST(d, iptr[1].val.i);
                                }
+                               ICONST(d, iptr[1].val.i);
+                       }
                        if ((s3 >= 0) && (s3 <= 255)) {
                                M_CMOVEQ_IMM(s1, s3, d);
-                               }
-                       else {
-                               ICONST(REG_ITMP2, s3);
-                               M_CMOVEQ(s1, REG_ITMP2, d);
-                               }
+                       } else {
+                               ICONST(REG_ITMP3, s3);
+                               M_CMOVEQ(s1, REG_ITMP3, d);
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -2803,33 +2730,32 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        s3 = iptr->val.i;
                        if (iptr[1].opc == ICMD_ELSE_ICONST) {
                                if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPEQ(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPEQ(s1, REG_ZERO, d);
                                        M_XOR_IMM(d, 1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if (s1 == d) {
                                        M_MOV(s1, REG_ITMP1);
                                        s1 = REG_ITMP1;
-                                       }
-                               ICONST(d, iptr[1].val.i);
                                }
+                               ICONST(d, iptr[1].val.i);
+                       }
                        if ((s3 >= 0) && (s3 <= 255)) {
                                M_CMOVNE_IMM(s1, s3, d);
-                               }
-                       else {
-                               ICONST(REG_ITMP2, s3);
-                               M_CMOVNE(s1, REG_ITMP2, d);
-                               }
+                       } else {
+                               ICONST(REG_ITMP3, s3);
+                               M_CMOVNE(s1, REG_ITMP3, d);
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -2837,32 +2763,31 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPLT(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPLE(REG_ZERO, s1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if (s1 == d) {
                                        M_MOV(s1, REG_ITMP1);
                                        s1 = REG_ITMP1;
-                                       }
-                               ICONST(d, iptr[1].val.i);
                                }
+                               ICONST(d, iptr[1].val.i);
+                       }
                        if ((s3 >= 0) && (s3 <= 255)) {
                                M_CMOVLT_IMM(s1, s3, d);
-                               }
-                       else {
-                               ICONST(REG_ITMP2, s3);
-                               M_CMOVLT(s1, REG_ITMP2, d);
-                               }
+                       } else {
+                               ICONST(REG_ITMP3, s3);
+                               M_CMOVLT(s1, REG_ITMP3, d);
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -2870,32 +2795,31 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPLE(REG_ZERO, s1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPLT(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if (s1 == d) {
                                        M_MOV(s1, REG_ITMP1);
                                        s1 = REG_ITMP1;
-                                       }
-                               ICONST(d, iptr[1].val.i);
                                }
+                               ICONST(d, iptr[1].val.i);
+                       }
                        if ((s3 >= 0) && (s3 <= 255)) {
                                M_CMOVGE_IMM(s1, s3, d);
-                               }
-                       else {
-                               ICONST(REG_ITMP2, s3);
-                               M_CMOVGE(s1, REG_ITMP2, d);
-                               }
+                       } else {
+                               ICONST(REG_ITMP3, s3);
+                               M_CMOVGE(s1, REG_ITMP3, d);
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -2903,32 +2827,31 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPLT(REG_ZERO, s1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPLE(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if (s1 == d) {
                                        M_MOV(s1, REG_ITMP1);
                                        s1 = REG_ITMP1;
-                                       }
-                               ICONST(d, iptr[1].val.i);
                                }
+                               ICONST(d, iptr[1].val.i);
+                       }
                        if ((s3 >= 0) && (s3 <= 255)) {
                                M_CMOVGT_IMM(s1, s3, d);
-                               }
-                       else {
-                               ICONST(REG_ITMP2, s3);
-                               M_CMOVGT(s1, REG_ITMP2, d);
-                               }
+                       } else {
+                               ICONST(REG_ITMP3, s3);
+                               M_CMOVGT(s1, REG_ITMP3, d);
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -2936,43 +2859,57 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP2);
                        s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
                                        M_CMPLE(s1, REG_ZERO, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if ((s3 == 0) && (iptr[1].val.i == 1)) {
                                        M_CMPLT(REG_ZERO, s1, d);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
-                                       }
+                               }
                                if (s1 == d) {
                                        M_MOV(s1, REG_ITMP1);
                                        s1 = REG_ITMP1;
-                                       }
-                               ICONST(d, iptr[1].val.i);
                                }
+                               ICONST(d, iptr[1].val.i);
+                       }
                        if ((s3 >= 0) && (s3 <= 255)) {
                                M_CMOVLE_IMM(s1, s3, d);
-                               }
-                       else {
-                               ICONST(REG_ITMP2, s3);
-                               M_CMOVLE(s1, REG_ITMP2, d);
-                               }
+                       } else {
+                               ICONST(REG_ITMP3, s3);
+                               M_CMOVLE(s1, REG_ITMP3, d);
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
 
                case ICMD_IRETURN:      /* ..., retvalue ==> ...                      */
                case ICMD_LRETURN:
-               case ICMD_ARETURN:
+
+                       var_to_reg_int(s1, src, REG_RESULT);
+                       M_INTMOVE(s1, REG_RESULT);
+                       goto nowperformreturn;
+
+               case ICMD_ARETURN:      /* ..., retvalue ==> ...                      */
 
                        var_to_reg_int(s1, src, REG_RESULT);
                        M_INTMOVE(s1, REG_RESULT);
 
+#ifdef ENABLE_VERIFIER
+                       if (iptr->val.a) {
+                               codegen_addpatchref(cd, mcodeptr,
+                                                                       PATCHER_athrow_areturn,
+                                                                       (unresolved_class *) iptr->val.a, 0);
+
+                               if (opt_showdisassemble)
+                                       M_NOP;
+                       }
+#endif /* ENABLE_VERIFIER */
                        goto nowperformreturn;
 
                case ICMD_FRETURN:      /* ..., retvalue ==> ...                      */
@@ -2980,7 +2917,6 @@ void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 
                        var_to_reg_flt(s1, src, REG_FRESULT);
                        M_FLTMOVE(s1, REG_FRESULT);
-
                        goto nowperformreturn;
 
                case ICMD_RETURN:       /* ...  ==> ...                               */
@@ -2993,27 +2929,24 @@ nowperformreturn:
                        
                        /* call trace function */
 
-                       if (runverbose) {
+                       if (opt_verbosecall) {
                                M_LDA(REG_SP, REG_SP, -3 * 8);
                                M_AST(REG_RA, REG_SP, 0 * 8);
                                M_LST(REG_RESULT, REG_SP, 1 * 8);
                                M_DST(REG_FRESULT, REG_SP, 2 * 8);
-                               a = dseg_addaddress(cd, m);
-                               M_ALD(rd->argintregs[0], REG_PV, a);
+
+                               disp = dseg_addaddress(cd, m);
+                               M_ALD(rd->argintregs[0], REG_PV, disp);
                                M_MOV(REG_RESULT, rd->argintregs[1]);
                                M_FLTMOVE(REG_FRESULT, rd->argfltregs[2]);
                                M_FLTMOVE(REG_FRESULT, rd->argfltregs[3]);
-                               a = dseg_addaddress(cd, (void *) builtin_displaymethodstop);
-                               M_ALD(REG_PV, REG_PV, a);
+
+                               disp = dseg_addaddress(cd, (void *) builtin_displaymethodstop);
+                               M_ALD(REG_PV, REG_PV, disp);
                                M_JSR(REG_RA, REG_PV);
-                               s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
-                               if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
-                               else {
-                                       s4 ml = -s1, mh = 0;
-                                       while (ml < -32768) { ml += 65536; mh--; }
-                                       M_LDA(REG_PV, REG_RA, ml);
-                                       M_LDAH(REG_PV, REG_PV, mh);
-                               }
+                               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                               M_LDA(REG_PV, REG_RA, -disp);
+
                                M_DLD(REG_FRESULT, REG_SP, 2 * 8);
                                M_LLD(REG_RESULT, REG_SP, 1 * 8);
                                M_ALD(REG_RA, REG_SP, 0 * 8);
@@ -3022,24 +2955,22 @@ nowperformreturn:
 
 #if defined(USE_THREADS)
                        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
-                               s4 disp;
-
-                               M_ALD(rd->argintregs[0], REG_SP, rd->maxmemuse * 8);
+                               M_ALD(rd->argintregs[0], REG_SP, rd->memuse * 8);
 
                                switch (iptr->opc) {
                                case ICMD_IRETURN:
                                case ICMD_LRETURN:
                                case ICMD_ARETURN:
-                                       M_LST(REG_RESULT, REG_SP, rd->maxmemuse * 8);
+                                       M_LST(REG_RESULT, REG_SP, rd->memuse * 8);
                                        break;
                                case ICMD_FRETURN:
                                case ICMD_DRETURN:
-                                       M_DST(REG_FRESULT, REG_SP, rd->maxmemuse * 8);
+                                       M_DST(REG_FRESULT, REG_SP, rd->memuse * 8);
                                        break;
                                }
 
-                               a = dseg_addaddress(cd, BUILTIN_monitorexit);
-                               M_ALD(REG_PV, REG_PV, a);
+                               disp = dseg_addaddress(cd, BUILTIN_monitorexit);
+                               M_ALD(REG_PV, REG_PV, disp);
                                M_JSR(REG_RA, REG_PV);
                                disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
                                M_LDA(REG_PV, REG_RA, disp);
@@ -3048,11 +2979,11 @@ nowperformreturn:
                                case ICMD_IRETURN:
                                case ICMD_LRETURN:
                                case ICMD_ARETURN:
-                                       M_LLD(REG_RESULT, REG_SP, rd->maxmemuse * 8);
+                                       M_LLD(REG_RESULT, REG_SP, rd->memuse * 8);
                                        break;
                                case ICMD_FRETURN:
                                case ICMD_DRETURN:
-                                       M_DLD(REG_FRESULT, REG_SP, rd->maxmemuse * 8);
+                                       M_DLD(REG_FRESULT, REG_SP, rd->memuse * 8);
                                        break;
                                }
                        }
@@ -3066,10 +2997,10 @@ nowperformreturn:
 
                        /* restore saved registers                                        */
 
-                       for (i = rd->savintregcnt - 1; i >= rd->maxsavintreguse; i--) {
+                       for (i = INT_SAV_CNT - 1; i >= rd->savintreguse; i--) {
                                p--; M_LLD(rd->savintregs[i], REG_SP, p * 8);
                        }
-                       for (i = rd->savfltregcnt - 1; i >= rd->maxsavfltreguse; i--) {
+                       for (i = FLT_SAV_CNT - 1; i >= rd->savfltreguse; i--) {
                                p--; M_DLD(rd->savfltregs[i], REG_SP, p * 8);
                        }
 
@@ -3097,15 +3028,14 @@ nowperformreturn:
                        i = s4ptr[2];                          /* high    */
                        
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       if (l == 0)
-                               {M_INTMOVE(s1, REG_ITMP1);}
-                       else if (l <= 32768) {
+                       if (l == 0) {
+                               M_INTMOVE(s1, REG_ITMP1);
+                       else if (l <= 32768) {
                                M_LDA(REG_ITMP1, s1, -l);
-                               }
-                       else {
+                       } else {
                                ICONST(REG_ITMP2, l);
                                M_ISUB(s1, REG_ITMP2, REG_ITMP1);
-                               }
+                       }
                        i = i - l + 1;
 
                        /* range check */
@@ -3115,11 +3045,8 @@ nowperformreturn:
                        else {
                                M_LDA(REG_ITMP2, REG_ZERO, i - 1);
                                M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2);
-                               }
+                       }
                        M_BEQZ(REG_ITMP2, 0);
-
-
-                       /* codegen_addreference(cd, BlockPtrOfPC(s4ptr[0]), mcodeptr); */
                        codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
 
                        /* build jump table top down and use address of lowest entry */
@@ -3128,10 +3055,9 @@ nowperformreturn:
                        tptr += i;
 
                        while (--i >= 0) {
-                               /* dseg_addtarget(cd, BlockPtrOfPC(*--s4ptr)); */
                                dseg_addtarget(cd, (basicblock *) tptr[0]); 
                                --tptr;
-                               }
+                       }
                        }
 
                        /* length of dataseg after last dseg_addtarget is used by load */
@@ -3163,24 +3089,20 @@ nowperformreturn:
                                val = s4ptr[0];
                                if ((val >= 0) && (val <= 255)) {
                                        M_CMPEQ_IMM(s1, val, REG_ITMP2);
-                                       }
-                               else {
+                               } else {
                                        if ((val >= -32768) && (val <= 32767)) {
                                                M_LDA(REG_ITMP2, REG_ZERO, val);
-                                               } 
-                                       else {
-                                               a = dseg_adds4(cd, val);
-                                               M_ILD(REG_ITMP2, REG_PV, a);
-                                               }
-                                       M_CMPEQ(s1, REG_ITMP2, REG_ITMP2);
+                                       } else {
+                                               disp = dseg_adds4(cd, val);
+                                               M_ILD(REG_ITMP2, REG_PV, disp);
                                        }
+                                       M_CMPEQ(s1, REG_ITMP2, REG_ITMP2);
+                               }
                                M_BNEZ(REG_ITMP2, 0);
-                               /* codegen_addreference(cd, BlockPtrOfPC(s4ptr[1]), mcodeptr); */
                                codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr); 
-                               }
+                       }
 
                        M_BR(0);
-                       /* codegen_addreference(cd, BlockPtrOfPC(l), mcodeptr); */
                        
                        tptr = (void **) iptr->target;
                        codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
@@ -3190,118 +3112,107 @@ nowperformreturn:
                        }
 
 
-               case ICMD_BUILTIN3:     /* ..., arg1, arg2, arg3 ==> ...              */
-                                       /* op1 = return type, val.a = function pointer*/
-                       s3 = 3;
-                       goto gen_method;
-
-               case ICMD_BUILTIN2:     /* ..., arg1, arg2 ==> ...                    */
-                                       /* op1 = return type, val.a = function pointer*/
-                       s3 = 2;
-                       goto gen_method;
+               case ICMD_BUILTIN:      /* ..., arg1, arg2, arg3 ==> ...              */
+                                       /* op1 = arg count val.a = builtintable entry */
 
-               case ICMD_BUILTIN1:     /* ..., arg1 ==> ...                          */
-                                       /* op1 = return type, val.a = function pointer*/
-                       s3 = 1;
+                       bte = iptr->val.a;
+                       md = bte->md;
                        goto gen_method;
 
                case ICMD_INVOKESTATIC: /* ..., [arg1, [arg2 ...]] ==> ...            */
                                        /* op1 = arg count, val.a = method pointer    */
 
                case ICMD_INVOKESPECIAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
-                                       /* op1 = arg count, val.a = method pointer    */
-
-               case ICMD_INVOKEVIRTUAL:/* ..., objectref, [arg1, [arg2 ...]] ==> ... */
-                                       /* op1 = arg count, val.a = method pointer    */
+               case ICMD_INVOKEVIRTUAL:/* op1 = arg count, val.a = method pointer    */
+               case ICMD_INVOKEINTERFACE:
 
-               case ICMD_INVOKEINTERFACE:/*.., objectref, [arg1, [arg2 ...]] ==> ... */
-                                       /* op1 = arg count, val.a = method pointer    */
+                       lm = iptr->val.a;
 
-                       s3 = iptr->op1;
+                       if (lm == NULL) {
+                               unresolved_method *um = iptr->target;
+                               md = um->methodref->parseddesc.md;
+                       } else {
+                               md = lm->parseddesc;
+                       }
 
-gen_method: {
-                       methodinfo *lm;
+gen_method:
+                       s3 = md->paramcount;
 
                        MCODECHECK((s3 << 1) + 64);
 
                        /* copy arguments to registers or stack location                  */
 
-                       for (; --s3 >= 0; src = src->prev) {
+                       for (s3 = s3 - 1; s3 >= 0; s3--, src = src->prev) {
                                if (src->varkind == ARGVAR)
                                        continue;
                                if (IS_INT_LNG_TYPE(src->type)) {
-                                       if (s3 < INT_ARG_CNT) {
-                                               s1 = rd->argintregs[s3];
+                                       if (!md->params[s3].inmemory) {
+                                               s1 = rd->argintregs[md->params[s3].regoff];
                                                var_to_reg_int(d, src, s1);
                                                M_INTMOVE(d, s1);
-
                                        } else {
                                                var_to_reg_int(d, src, REG_ITMP1);
-                                               M_LST(d, REG_SP, 8 * (s3 - INT_ARG_CNT));
+                                               M_LST(d, REG_SP, md->params[s3].regoff * 8);
                                        }
 
                                } else {
-                                       if (s3 < FLT_ARG_CNT) {
-                                               s1 = rd->argfltregs[s3];
+                                       if (!md->params[s3].inmemory) {
+                                               s1 = rd->argfltregs[md->params[s3].regoff];
                                                var_to_reg_flt(d, src, s1);
                                                M_FLTMOVE(d, s1);
-
                                        } else {
                                                var_to_reg_flt(d, src, REG_FTMP1);
-                                               M_DST(d, REG_SP, 8 * (s3 - FLT_ARG_CNT));
+                                               M_DST(d, REG_SP, md->params[s3].regoff * 8);
                                        }
                                }
-                       } /* end of for */
+                       }
 
-                       lm = iptr->val.a;
                        switch (iptr->opc) {
-                       case ICMD_BUILTIN3:
-                       case ICMD_BUILTIN2:
-                       case ICMD_BUILTIN1:
-                               if (iptr->target) {
-                                       codegen_addpatchref(cd, mcodeptr,
-                                                                               (functionptr) lm, iptr->target);
+                       case ICMD_BUILTIN:
+                               disp = dseg_addaddress(cd, bte->fp);
+                               d = md->returntype.type;
 
-                                       if (showdisassemble)
-                                               M_NOP;
+                               M_ALD(REG_PV, REG_PV, disp);  /* Pointer to built-in-function */
+                               M_JSR(REG_RA, REG_PV);
+                               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                               M_LDA(REG_PV, REG_RA, -disp);
 
-                                       a = 0;
+                               /* if op1 == true, we need to check for an exception */
 
-                               } else {
-                                       a = (ptrint) lm;
+                               if (iptr->op1 == true) {
+                                       M_BEQZ(REG_RESULT, 0);
+                                       codegen_add_fillinstacktrace_ref(cd, mcodeptr);
                                }
-
-                               a = dseg_addaddress(cd, a);
-                               d = iptr->op1;
-
-                               M_ALD(REG_PV, REG_PV, a);     /* Pointer to built-in-function */
                                break;
 
                        case ICMD_INVOKESPECIAL:
-                               gen_nullptr_check(rd->argintregs[0]);
-                               M_ILD(REG_ITMP1, rd->argintregs[0], 0); /* hardware nullptr   */
+                               M_BEQZ(rd->argintregs[0], 0);
+                               codegen_add_nullpointerexception_ref(cd, mcodeptr);
                                /* fall through */
 
                        case ICMD_INVOKESTATIC:
                                if (!lm) {
                                        unresolved_method *um = iptr->target;
 
+                                       disp = dseg_addaddress(cd, NULL);
+
                                        codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_invokestatic_special, um);
+                                                                               PATCHER_invokestatic_special, um, disp);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
 
-                                       a = 0;
                                        d = um->methodref->parseddesc.md->returntype.type;
 
                                } else {
-                                       a = (ptrint) lm->stubroutine;
+                                       disp = dseg_addaddress(cd, lm->stubroutine);
                                        d = lm->parseddesc->returntype.type;
                                }
 
-                               a = dseg_addaddress(cd, a);
-                               M_ALD(REG_PV, REG_PV, a);            /* method pointer in r27 */
+                               M_ALD(REG_PV, REG_PV, disp);         /* method pointer in r27 */
+                               M_JSR(REG_RA, REG_PV);
+                               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                               M_LDA(REG_PV, REG_RA, -disp);
                                break;
 
                        case ICMD_INVOKEVIRTUAL:
@@ -3311,9 +3222,9 @@ gen_method: {
                                        unresolved_method *um = iptr->target;
 
                                        codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_invokevirtual, um);
+                                                                               PATCHER_invokevirtual, um, 0);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
 
                                        s1 = 0;
@@ -3328,6 +3239,9 @@ gen_method: {
                                M_ALD(REG_METHODPTR, rd->argintregs[0],
                                          OFFSET(java_objectheader, vftbl));
                                M_ALD(REG_PV, REG_METHODPTR, s1);
+                               M_JSR(REG_RA, REG_PV);
+                               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                               M_LDA(REG_PV, REG_RA, -disp);
                                break;
 
                        case ICMD_INVOKEINTERFACE:
@@ -3337,9 +3251,9 @@ gen_method: {
                                        unresolved_method *um = iptr->target;
 
                                        codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_invokeinterface, um);
+                                                                               PATCHER_invokeinterface, um, 0);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
 
                                        s1 = 0;
@@ -3359,22 +3273,12 @@ gen_method: {
                                          OFFSET(java_objectheader, vftbl));    
                                M_ALD(REG_METHODPTR, REG_METHODPTR, s1);
                                M_ALD(REG_PV, REG_METHODPTR, s2);
+                               M_JSR(REG_RA, REG_PV);
+                               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                               M_LDA(REG_PV, REG_RA, -disp);
                                break;
                        }
 
-                       M_JSR(REG_RA, REG_PV);
-
-                       /* recompute pv */
-
-                       s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
-                       if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
-                       else {
-                               s4 ml = -s1, mh = 0;
-                               while (ml < -32768) { ml += 65536; mh--; }
-                               M_LDA(REG_PV, REG_RA, ml);
-                               M_LDAH(REG_PV, REG_PV, mh);
-                       }
-
                        /* d contains return type */
 
                        if (d != TYPE_VOID) {
@@ -3382,14 +3286,12 @@ gen_method: {
                                        s1 = reg_of_var(rd, iptr->dst, REG_RESULT);
                                        M_INTMOVE(REG_RESULT, s1);
                                        store_reg_to_var_int(iptr->dst, s1);
-
                                } else {
                                        s1 = reg_of_var(rd, iptr->dst, REG_FRESULT);
                                        M_FLTMOVE(REG_FRESULT, s1);
                                        store_reg_to_var_flt(iptr->dst, s1);
                                }
                        }
-                       }
                        break;
 
 
@@ -3411,136 +3313,175 @@ gen_method: {
                         *         super->vftbl->diffval));
                         */
 
-                       {
-                       classinfo *super;
-                       vftbl_t   *supervftbl;
-                       s4         superindex;
+                       if (iptr->op1 == 1) {
+                               /* object type cast-check */
 
-                       super = (classinfo *) iptr->val.a;
+                               classinfo *super;
+                               vftbl_t   *supervftbl;
+                               s4         superindex;
 
-                       if (!super) {
-                               superindex = 0;
-                               supervftbl = NULL;
+                               super = (classinfo *) iptr->val.a;
 
-                       } else {
-                               superindex = super->index;
-                               supervftbl = super->vftbl;
-                       }
+                               if (!super) {
+                                       superindex = 0;
+                                       supervftbl = NULL;
+
+                               } else {
+                                       superindex = super->index;
+                                       supervftbl = super->vftbl;
+                               }
                        
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                       codegen_threadcritrestart(cd, (u1 *) mcodeptr - cd->mcodebase);
+                               codegen_threadcritrestart(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
-                       var_to_reg_int(s1, src, REG_ITMP1);
-
-                       /* calculate interface checkcast code size */
-
-                       s2 = 6;
-                       if (!super)
-                               s2 += showdisassemble ? 1 : 0;
-
-                       /* calculate class checkcast code size */
-
-                       s3 = 9 /* 8 + (s1 == REG_ITMP1) */;
-                       if (!super)
-                               s3 += showdisassemble ? 1 : 0;
+                               var_to_reg_int(s1, src, REG_ITMP1);
 
-                       /* if class is not resolved, check which code to call */
+                               /* calculate interface checkcast code size */
 
-                       if (!super) {
-                               M_BEQZ(s1, 4 + (showdisassemble ? 1 : 0) + s2 + 1 + s3);
+                               s2 = 6;
+                               if (!super)
+                                       s2 += opt_showdisassemble ? 1 : 0;
 
-                               codegen_addpatchref(cd, mcodeptr,
-                                                                       PATCHER_checkcast_instanceof_flags,
-                                                                       (constant_classref *) iptr->target);
+                               /* calculate class checkcast code size */
 
-                               if (showdisassemble)
-                                       M_NOP;
+                               s3 = 9 /* 8 + (s1 == REG_ITMP1) */;
+                               if (!super)
+                                       s3 += opt_showdisassemble ? 1 : 0;
 
-                               a = dseg_adds4(cd, 0); /* super->flags */
-                               M_ILD(REG_ITMP2, REG_PV, a);
-                               a = dseg_adds4(cd, ACC_INTERFACE);
-                               M_ILD(REG_ITMP3, REG_PV, a);
-                               M_AND(REG_ITMP2, REG_ITMP3, REG_ITMP2);
-                               M_BEQZ(REG_ITMP2, s2 + 1);
-                       }
+                               /* if class is not resolved, check which code to call */
 
-                       /* interface checkcast code */
+                               if (!super) {
+                                       M_BEQZ(s1, 4 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
 
-                       if (!super || (super->flags & ACC_INTERFACE)) {
-                               if (super) {
-                                       M_BEQZ(s1, s2);
+                                       disp = dseg_adds4(cd, 0);                 /* super->flags */
 
-                               } else {
                                        codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_checkcast_instanceof_interface,
-                                                                               (constant_classref *) iptr->target);
+                                                                               PATCHER_checkcast_instanceof_flags,
+                                                                               (constant_classref *) iptr->target,
+                                                                               disp);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
+
+                                       M_ILD(REG_ITMP2, REG_PV, disp);
+                                       disp = dseg_adds4(cd, ACC_INTERFACE);
+                                       M_ILD(REG_ITMP3, REG_PV, disp);
+                                       M_AND(REG_ITMP2, REG_ITMP3, REG_ITMP2);
+                                       M_BEQZ(REG_ITMP2, s2 + 1);
                                }
 
-                               M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
-                               M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, interfacetablelength));
-                               M_LDA(REG_ITMP3, REG_ITMP3, -superindex);
-                               M_BLEZ(REG_ITMP3, 0);
-                               codegen_addxcastrefs(cd, mcodeptr);
-                               M_ALD(REG_ITMP3, REG_ITMP2,
-                                         OFFSET(vftbl_t, interfacetable[0]) -
-                                         superindex * sizeof(methodptr*));
-                               M_BEQZ(REG_ITMP3, 0);
-                               codegen_addxcastrefs(cd, mcodeptr);
+                               /* interface checkcast code */
 
-                               if (!super)
-                                       M_BR(s3);
-                       }
+                               if (!super || (super->flags & ACC_INTERFACE)) {
+                                       if (super) {
+                                               M_BEQZ(s1, s2);
 
-                       /* class checkcast code */
+                                       } else {
+                                               codegen_addpatchref(cd, mcodeptr,
+                                                                                       PATCHER_checkcast_instanceof_interface,
+                                                                                       (constant_classref *) iptr->target,
+                                                                                       0);
 
-                       if (!super || !(super->flags & ACC_INTERFACE)) {
-                               if (super) {
-                                       M_BEQZ(s1, s3);
+                                               if (opt_showdisassemble)
+                                                       M_NOP;
+                                       }
 
-                               } else {
-                                       codegen_addpatchref(cd, mcodeptr,
-                                                                               PATCHER_checkcast_instanceof_class,
-                                                                               (constant_classref *) iptr->target);
+                                       M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
+                                       M_ILD(REG_ITMP3, REG_ITMP2,
+                                                 OFFSET(vftbl_t, interfacetablelength));
+                                       M_LDA(REG_ITMP3, REG_ITMP3, -superindex);
+                                       M_BLEZ(REG_ITMP3, 0);
+                                       codegen_add_classcastexception_ref(cd, mcodeptr);
+                                       M_ALD(REG_ITMP3, REG_ITMP2,
+                                                 (s4) (OFFSET(vftbl_t, interfacetable[0]) -
+                                                               superindex * sizeof(methodptr*)));
+                                       M_BEQZ(REG_ITMP3, 0);
+                                       codegen_add_classcastexception_ref(cd, mcodeptr);
 
-                                       if (showdisassemble)
-                                               M_NOP;
+                                       if (!super)
+                                               M_BR(s3);
                                }
 
-                               M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
-                               a = dseg_addaddress(cd, supervftbl);
-                               M_ALD(REG_ITMP3, REG_PV, a);
+                               /* class checkcast code */
+
+                               if (!super || !(super->flags & ACC_INTERFACE)) {
+                                       disp = dseg_addaddress(cd, supervftbl);
+
+                                       if (super) {
+                                               M_BEQZ(s1, s3);
+
+                                       } else {
+                                               codegen_addpatchref(cd, mcodeptr,
+                                                                                       PATCHER_checkcast_instanceof_class,
+                                                                                       (constant_classref *) iptr->target,
+                                                                                       disp);
+
+                                               if (opt_showdisassemble)
+                                                       M_NOP;
+                                       }
+
+                                       M_ALD(REG_ITMP2, s1, OFFSET(java_objectheader, vftbl));
+                                       M_ALD(REG_ITMP3, REG_PV, disp);
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                               codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
+                                       codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
-                               M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
-/*                             if (s1 != REG_ITMP1) { */
-/*                                     M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, baseval)); */
-/*                                     M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval)); */
-/*  #if defined(USE_THREADS) && defined(NATIVE_THREADS) */
-/*                                     codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase); */
-/*  #endif */
-/*                                     M_ISUB(REG_ITMP2, REG_ITMP1, REG_ITMP2); */
-
-/*                             } else { */
+                                       M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
+                                       /*                              if (s1 != REG_ITMP1) { */
+                                       /*                                      M_ILD(REG_ITMP1, REG_ITMP3, OFFSET(vftbl_t, baseval)); */
+                                       /*                                      M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval)); */
+                                       /*  #if defined(USE_THREADS) && defined(NATIVE_THREADS) */
+                                       /*                                      codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase); */
+                                       /*  #endif */
+                                       /*                                      M_ISUB(REG_ITMP2, REG_ITMP1, REG_ITMP2); */
+
+                                       /*                              } else { */
                                        M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, baseval));
                                        M_ISUB(REG_ITMP2, REG_ITMP3, REG_ITMP2);
-                                       M_ALD(REG_ITMP3, REG_PV, a);
+                                       M_ALD(REG_ITMP3, REG_PV, disp);
                                        M_ILD(REG_ITMP3, REG_ITMP3, OFFSET(vftbl_t, diffval));
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
                                        codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
-/*                             } */
-                               M_CMPULE(REG_ITMP2, REG_ITMP3, REG_ITMP3);
-                               M_BEQZ(REG_ITMP3, 0);
-                               codegen_addxcastrefs(cd, mcodeptr);
+                                       /*                              } */
+                                       M_CMPULE(REG_ITMP2, REG_ITMP3, REG_ITMP3);
+                                       M_BEQZ(REG_ITMP3, 0);
+                                       codegen_add_classcastexception_ref(cd, mcodeptr);
+                               }
+                               d = reg_of_var(rd, iptr->dst, s1);
+
+                       } else {
+                               /* array type cast-check */
+
+                               var_to_reg_int(s1, src, rd->argintregs[0]);
+                               M_INTMOVE(s1, rd->argintregs[0]);
+
+                               disp = dseg_addaddress(cd, iptr->val.a);
+
+                               if (iptr->val.a == NULL) {
+                                       codegen_addpatchref(cd, mcodeptr,
+                                                                               PATCHER_builtin_arraycheckcast,
+                                                                               (constant_classref *) iptr->target,
+                                                                               disp);
+
+                                       if (opt_showdisassemble)
+                                               M_NOP;
+                               }
+
+                               M_ALD(rd->argintregs[1], REG_PV, disp);
+                               disp = dseg_addaddress(cd, BUILTIN_arraycheckcast);
+                               M_ALD(REG_PV, REG_PV, disp);
+                               M_JSR(REG_RA, REG_PV);
+                               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                               M_LDA(REG_PV, REG_RA, -disp);
+
+                               M_BEQZ(REG_RESULT, 0);
+                               codegen_add_classcastexception_ref(cd, mcodeptr);
+
+                               var_to_reg_int(s1, src, REG_ITMP1);
+                               d = reg_of_var(rd, iptr->dst, s1);
                        }
-                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_INTMOVE(s1, d);
                        store_reg_to_var_int(iptr->dst, d);
-                       }
                        break;
 
                case ICMD_INSTANCEOF: /* ..., objectref ==> ..., intresult            */
@@ -3591,31 +3532,33 @@ gen_method: {
 
                        s2 = 6;
                        if (!super)
-                               s2 += (d == REG_ITMP2 ? 1 : 0) + (showdisassemble ? 1 : 0);
+                               s2 += (d == REG_ITMP2 ? 1 : 0) + (opt_showdisassemble ? 1 : 0);
 
                        /* calculate class instanceof code size */
 
                        s3 = 7;
                        if (!super)
-                               s3 += (showdisassemble ? 1 : 0);
+                               s3 += (opt_showdisassemble ? 1 : 0);
 
                        /* if class is not resolved, check which code to call */
 
                        if (!super) {
                                M_CLR(d);
-                               M_BEQZ(s1, 4 + (showdisassemble ? 1 : 0) + s2 + 1 + s3);
+                               M_BEQZ(s1, 4 + (opt_showdisassemble ? 1 : 0) + s2 + 1 + s3);
+
+                               disp = dseg_adds4(cd, 0);                     /* super->flags */
 
                                codegen_addpatchref(cd, mcodeptr,
                                                                        PATCHER_checkcast_instanceof_flags,
-                                                                       (constant_classref *) iptr->target);
+                                                                       (constant_classref *) iptr->target, disp);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = dseg_adds4(cd, 0); /* super->flags */
-                               M_ILD(REG_ITMP3, REG_PV, a);
-                               a = dseg_adds4(cd, ACC_INTERFACE);
-                               M_ILD(REG_ITMP2, REG_PV, a);
+                               M_ILD(REG_ITMP3, REG_PV, disp);
+
+                               disp = dseg_adds4(cd, ACC_INTERFACE);
+                               M_ILD(REG_ITMP2, REG_PV, disp);
                                M_AND(REG_ITMP3, REG_ITMP2, REG_ITMP3);
                                M_BEQZ(REG_ITMP3, s2 + 1);
                        }
@@ -3635,9 +3578,9 @@ gen_method: {
 
                                        codegen_addpatchref(cd, mcodeptr,
                                                                                PATCHER_checkcast_instanceof_interface,
-                                                                               (constant_classref *) iptr->target);
+                                                                               (constant_classref *) iptr->target, 0);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
                                }
 
@@ -3646,8 +3589,8 @@ gen_method: {
                                M_LDA(REG_ITMP3, REG_ITMP3, -superindex);
                                M_BLEZ(REG_ITMP3, 2);
                                M_ALD(REG_ITMP1, REG_ITMP1,
-                                         OFFSET(vftbl_t, interfacetable[0]) -
-                                         superindex * sizeof(methodptr*));
+                                         (s4) (OFFSET(vftbl_t, interfacetable[0]) -
+                                                       superindex * sizeof(methodptr*)));
                                M_CMPULT(REG_ZERO, REG_ITMP1, d);      /* REG_ITMP1 != 0  */
 
                                if (!super)
@@ -3657,6 +3600,8 @@ gen_method: {
                        /* class instanceof code */
 
                        if (!super || !(super->flags & ACC_INTERFACE)) {
+                               disp = dseg_addaddress(cd, supervftbl);
+
                                if (super) {
                                        M_CLR(d);
                                        M_BEQZ(s1, s3);
@@ -3664,15 +3609,15 @@ gen_method: {
                                } else {
                                        codegen_addpatchref(cd, mcodeptr,
                                                                                PATCHER_checkcast_instanceof_class,
-                                                                               (constant_classref *) iptr->target);
+                                                                               (constant_classref *) iptr->target,
+                                                                               disp);
 
-                                       if (showdisassemble)
+                                       if (opt_showdisassemble)
                                                M_NOP;
                                }
 
                                M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
-                               a = dseg_addaddress(cd, supervftbl);
-                               M_ALD(REG_ITMP2, REG_PV, a);
+                               M_ALD(REG_ITMP2, REG_PV, disp);
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
                                codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
@@ -3686,90 +3631,74 @@ gen_method: {
                                M_CMPULE(REG_ITMP1, REG_ITMP2, d);
                        }
                        store_reg_to_var_int(iptr->dst, d);
-                       }
-                       break;
-
-
-               case ICMD_CHECKASIZE:  /* ..., size ==> ..., size                     */
-
-                       var_to_reg_int(s1, src, REG_ITMP1);
-                       M_BLTZ(s1, 0);
-                       codegen_addxcheckarefs(cd, mcodeptr);
-                       break;
-
-               case ICMD_CHECKEXCEPTION:    /* ... ==> ...                           */
-
-                       M_BEQZ(REG_RESULT, 0);
-                       codegen_addxexceptionrefs(cd, mcodeptr);
+                       }
                        break;
 
                case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref  */
-                                     /* op1 = dimension, val.a = array descriptor    */
+                                     /* op1 = dimension, val.a = class               */
 
                        /* check for negative sizes and copy sizes to stack if necessary  */
 
                        MCODECHECK((iptr->op1 << 1) + 64);
 
                        for (s1 = iptr->op1; --s1 >= 0; src = src->prev) {
-                               var_to_reg_int(s2, src, REG_ITMP1);
-                               M_BLTZ(s2, 0);
-                               codegen_addxcheckarefs(cd, mcodeptr);
-
                                /* copy SAVEDVAR sizes to stack */
 
                                if (src->varkind != ARGVAR) {
+                                       var_to_reg_int(s2, src, REG_ITMP1);
                                        M_LST(s2, REG_SP, s1 * 8);
                                }
                        }
 
+                       /* a0 = dimension count */
+
+                       ICONST(rd->argintregs[0], iptr->op1);
+
                        /* is patcher function set? */
 
-                       if (iptr->target) {
+                       if (iptr->val.a == NULL) {
+                               disp = dseg_addaddress(cd, 0);
+
                                codegen_addpatchref(cd, mcodeptr,
-                                                                       (functionptr) iptr->target, iptr->val.a);
+                                                                       PATCHER_builtin_multianewarray,
+                                                                       (constant_classref *) iptr->target,
+                                                                       disp);
 
-                               if (showdisassemble)
+                               if (opt_showdisassemble)
                                        M_NOP;
 
-                               a = 0;
-
                        } else {
-                               a = (ptrint) iptr->val.a;
+                               disp = dseg_addaddress(cd, iptr->val.a);
                        }
 
-                       /* a0 = dimension count */
-
-                       ICONST(rd->argintregs[0], iptr->op1);
-
                        /* a1 = arraydescriptor */
 
-                       a = dseg_addaddress(cd, a);
-                       M_ALD(rd->argintregs[1], REG_PV, a);
+                       M_ALD(rd->argintregs[1], REG_PV, disp);
 
                        /* a2 = pointer to dimensions = stack pointer */
 
                        M_INTMOVE(REG_SP, rd->argintregs[2]);
 
-                       a = dseg_addaddress(cd, (void *) BUILTIN_multianewarray);
-                       M_ALD(REG_PV, REG_PV, a);
+                       disp = dseg_addaddress(cd, BUILTIN_multianewarray);
+                       M_ALD(REG_PV, REG_PV, disp);
                        M_JSR(REG_RA, REG_PV);
-                       s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
-                       if (s1 <= 32768)
-                               M_LDA(REG_PV, REG_RA, -s1);
-                       else {
-                               s4 ml = -s1, mh = 0;
-                               while (ml < -32768) { ml += 65536; mh--; }
-                               M_LDA(REG_PV, REG_RA, ml);
-                               M_LDAH(REG_PV, REG_PV, mh);
-                       }
-                       s1 = reg_of_var(rd, iptr->dst, REG_RESULT);
-                       M_INTMOVE(REG_RESULT, s1);
-                       store_reg_to_var_int(iptr->dst, s1);
+                       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                       M_LDA(REG_PV, REG_RA, -disp);
+
+                       /* check for exception before result assignment */
+
+                       M_BEQZ(REG_RESULT, 0);
+                       codegen_add_fillinstacktrace_ref(cd, mcodeptr);
+
+                       d = reg_of_var(rd, iptr->dst, REG_RESULT);
+                       M_INTMOVE(REG_RESULT, d);
+                       store_reg_to_var_int(iptr->dst, d);
                        break;
 
                default:
-                       throw_cacao_exception_exit(string_java_lang_InternalError,
-                                                                          "Unknown ICMD %d", iptr->opc);
+                       *exceptionptr =
+                               new_internalerror("Unknown ICMD %d", iptr->opc);
+                       return false;
        } /* switch */
                
        } /* for instruction */
@@ -3779,7 +3708,7 @@ gen_method: {
        src = bptr->outstack;
        len = bptr->outdepth;
        MCODECHECK(64+len);
-#ifdef LSRA
+#if defined(ENABLE_LSRA)
        if (!opt_lsra) 
 #endif
        while (src) {
@@ -3810,800 +3739,678 @@ gen_method: {
        } /* if (bptr -> flags >= BBREACHED) */
        } /* for basic block */
 
-       codegen_createlinenumbertable(cd);
+       dseg_createlinenumbertable(cd);
 
-       {
-       /* generate bound check stubs */
 
-       s4 *xcodeptr = NULL;
-       branchref *bref;
+       /* generate exception and patcher stubs */
 
-       for (bref = cd->xboundrefs; bref != NULL; bref = bref->next) {
-               gen_resolvebranch((u1*) cd->mcodebase + bref->branchpos, 
-                                 bref->branchpos,
-                                                 (u1*) mcodeptr - cd->mcodebase);
+       {
+               exceptionref *eref;
+               patchref     *pref;
+               u4            mcode;
+               s4           *savedmcodeptr;
+               s4           *tmpmcodeptr;
 
-               MCODECHECK(8);
+               savedmcodeptr = NULL;
 
-               /* move index register into REG_ITMP1 */
-               M_MOV(bref->reg, REG_ITMP1);
-               M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
+               /* generate exception stubs */
 
-               if (xcodeptr != NULL) {
-                       M_BR(xcodeptr - mcodeptr - 1);
+               for (eref = cd->exceptionrefs; eref != NULL; eref = eref->next) {
+                       gen_resolvebranch((u1 *) cd->mcodebase + eref->branchpos, 
+                                                         eref->branchpos,
+                                                         (u1 *) mcodeptr - cd->mcodebase);
 
-               } else {
-                       xcodeptr = mcodeptr;
-
-                        a = dseg_addaddress(cd, asm_throw_and_handle_arrayindexoutofbounds_exception);
-                        M_ALD(REG_PV, REG_PV, a);
-
-                        M_JSR(REG_RA, REG_PV);
-
-                        /* recompute pv */
-                        s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
-                        if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
-                        else {
-                                s4 ml = -s1, mh = 0;
-                                while (ml < -32768) { ml += 65536; mh--; }
-                                M_LDA(REG_PV, REG_RA, ml);
-                                M_LDAH(REG_PV, REG_PV, mh);
-                        }
-               }
-       }
+                       MCODECHECK(100);
 
-       /* generate negative array size check stubs */
+                       /* move index register into REG_ITMP1 */
 
-       xcodeptr = NULL;
-       
-       for (bref = cd->xcheckarefs; bref != NULL; bref = bref->next) {
-               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
-                       gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
-                                                         bref->branchpos,
-                                                         (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
-                       continue;
-               }
+                       /* Check if the exception is an
+                          ArrayIndexOutOfBoundsException.  If so, move index register
+                          into REG_ITMP1. */
 
-               gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
-                                 bref->branchpos,
-                                                 (u1 *) mcodeptr - cd->mcodebase);
+                       if (eref->reg != -1)
+                               M_MOV(eref->reg, REG_ITMP1);
 
-               MCODECHECK(8);
+                       /* calcuate exception address */
 
-               M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
+                       M_LDA(REG_ITMP2_XPC, REG_PV, eref->branchpos - 4);
 
-               if (xcodeptr != NULL) {
-                       M_BR(xcodeptr - mcodeptr - 1);
+                       /* move function to call into REG_ITMP3 */
 
-               } else {
-                       xcodeptr = mcodeptr;
+                       disp = dseg_addaddress(cd, eref->function);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
 
-                       
-                       a = dseg_addaddress(cd, string_java_lang_NegativeArraySizeException);
-                       M_ALD(REG_ITMP1_XPTR,REG_PV,a);
+                       if (savedmcodeptr != NULL) {
+                               disp = savedmcodeptr - mcodeptr - 1;
+                               M_BR(disp);
 
-                       a = dseg_addaddress(cd, asm_throw_and_handle_nat_exception);
-                       M_ALD(REG_PV, REG_PV, a);
+                       } else {
+                               savedmcodeptr = mcodeptr;
 
-                       M_JSR(REG_RA, REG_PV);
-               
-                       /* recompute pv */
-                       s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
-                       if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
-                       else {
-                               s4 ml = -s1, mh = 0;
-                               while (ml < -32768) { ml += 65536; mh--; }
-                               M_LDA(REG_PV, REG_RA, ml);
-                               M_LDAH(REG_PV, REG_PV, mh);
-                       }
+                               M_MOV(REG_PV, rd->argintregs[0]);
+                               M_MOV(REG_SP, rd->argintregs[1]);
 
+                               if (m->isleafmethod)
+                                       M_MOV(REG_RA, rd->argintregs[2]);
+                               else
+                                       M_ALD(rd->argintregs[2],
+                                                 REG_SP, parentargs_base * 8 - SIZEOF_VOID_P);
 
-               }
-       }
+                               M_MOV(REG_ITMP2_XPC, rd->argintregs[3]);
+                               M_MOV(REG_ITMP1, rd->argintregs[4]);
 
-       /* generate cast check stubs */
+                               M_LDA(REG_SP, REG_SP, -2 * 8);
+                               M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
 
-       xcodeptr = NULL;
-       
-       for (bref = cd->xcastrefs; bref != NULL; bref = bref->next) {
-               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
-                       gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
-                                                         bref->branchpos,
-                                                         (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
-                       continue;
-               }
+                               if (m->isleafmethod)
+                                       M_AST(REG_RA, REG_SP, 1 * 8);
 
-               gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
-                                 bref->branchpos,
-                                                 (u1 *) mcodeptr - cd->mcodebase);
+                               M_MOV(REG_ITMP3, REG_PV);
+                               M_JSR(REG_RA, REG_PV);
+                               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                               M_LDA(REG_PV, REG_RA, -disp);
 
-               MCODECHECK(8);
+                               M_MOV(REG_RESULT, REG_ITMP1_XPTR);
 
-               M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
+                               if (m->isleafmethod)
+                                       M_ALD(REG_RA, REG_SP, 1 * 8);
 
-               if (xcodeptr != NULL) {
-                       M_BR(xcodeptr - mcodeptr - 1);
+                               M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                               M_LDA(REG_SP, REG_SP, 2 * 8);
 
-               } else {
-                       xcodeptr = mcodeptr;
+                               disp = dseg_addaddress(cd, asm_handle_exception);
+                               M_ALD(REG_ITMP3, REG_PV, disp);
+                               M_JMP(REG_ZERO, REG_ITMP3);
+                       }
+               }
 
-                       a = dseg_addaddress(cd, string_java_lang_ClassCastException);
-                        M_ALD(REG_ITMP1_XPTR,REG_PV,a);
 
-                        a = dseg_addaddress(cd, asm_throw_and_handle_nat_exception);
-                        M_ALD(REG_PV, REG_PV, a);
+               /* generate code patching stub call code */
 
-                        M_JSR(REG_RA, REG_PV);
+               for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
+                       /* check code segment size */
 
-                        /* recompute pv */
-                        s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
-                        if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
-                        else {
-                                s4 ml = -s1, mh = 0;
-                                while (ml < -32768) { ml += 65536; mh--; }
-                                M_LDA(REG_PV, REG_RA, ml);
-                                M_LDAH(REG_PV, REG_PV, mh);
-                        }
+                       MCODECHECK(100);
 
-               }
-       }
+                       /* Get machine code which is patched back in later. The
+                          call is 1 instruction word long. */
 
-       /* generate exception check stubs */
+                       savedmcodeptr = (s4 *) (cd->mcodebase + pref->branchpos);
+                       mcode = *savedmcodeptr;
 
-       xcodeptr = NULL;
+                       /* Patch in the call to call the following code (done at
+                          compile time). */
 
-       for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) {
-               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
-                       gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
-                                                         bref->branchpos,
-                                                         (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
-                       continue;
-               }
+                       tmpmcodeptr = mcodeptr;         /* save current mcodeptr          */
+                       mcodeptr    = savedmcodeptr;    /* set mcodeptr to patch position */
 
-               gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
-                                 bref->branchpos,
-                                                 (u1 *) mcodeptr - cd->mcodebase);
+                       M_BSR(REG_ITMP3, tmpmcodeptr - (savedmcodeptr + 1));
 
-               MCODECHECK(8);
+                       mcodeptr = tmpmcodeptr;         /* restore the current mcodeptr   */
 
-               M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
+                       /* create stack frame */
 
-               if (xcodeptr != NULL) {
-                       M_BR(xcodeptr - mcodeptr - 1);
+                       M_LSUB_IMM(REG_SP, 6 * 8, REG_SP);
 
-               } else {
-                       xcodeptr = mcodeptr;
+                       /* move return address onto stack */
 
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
-                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       M_AST(REG_ITMP3, REG_SP, 5 * 8);
 
-                       a = dseg_addaddress(cd, &builtin_get_exceptionptrptr);
-                       M_ALD(REG_PV, REG_PV, a);
-                       M_JSR(REG_RA, REG_PV);
+                       /* move pointer to java_objectheader onto stack */
 
-                       /* recompute pv */
-                       s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
-                       if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
-                       else {
-                               s4 ml = -s1, mh = 0;
-                               while (ml < -32768) { ml += 65536; mh--; }
-                               M_LDA(REG_PV, REG_RA, ml);
-                               M_LDAH(REG_PV, REG_PV, mh);
-                       }
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+                       /* create a virtual java_objectheader */
 
-                       M_ALD(REG_ITMP1_XPTR, REG_RESULT, 0);
-                       M_AST(REG_ZERO, REG_RESULT, 0);
+                       (void) dseg_addaddress(cd, get_dummyLR());          /* monitorPtr */
+                       disp = dseg_addaddress(cd, NULL);                   /* vftbl      */
 
-                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
-                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
+                       M_LDA(REG_ITMP3, REG_PV, disp);
+                       M_AST(REG_ITMP3, REG_SP, 4 * 8);
 #else
-                       a = dseg_addaddress(cd, &_exceptionptr);
-                       M_ALD(REG_ITMP3, REG_PV, a);
-                       M_ALD(REG_ITMP1_XPTR, REG_ITMP3, 0);
-                       M_AST(REG_ZERO, REG_ITMP3, 0);
+                       /* do nothing */
 #endif
 
-                       a = dseg_addaddress(cd, asm_refillin_and_handle_exception);
-                       M_ALD(REG_PV, REG_PV, a);
-
-                       M_JMP(REG_RA, REG_PV);
-               
-                       /* recompute pv */
-                       s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
-                       if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
-                       else {
-                               s4 ml = -s1, mh = 0;
-                               while (ml < -32768) { ml += 65536; mh--; }
-                               M_LDA(REG_PV, REG_RA, ml);
-                               M_LDAH(REG_PV, REG_PV, mh);
-                       }
-
-               }
-       }
-
-       /* generate null pointer check stubs */
-
-       xcodeptr = NULL;
-
-       for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) {
-               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
-                       gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
-                                                         bref->branchpos,
-                                                         (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
-                       continue;
-               }
-
-               gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
-                                 bref->branchpos,
-                                                 (u1 *) mcodeptr - cd->mcodebase);
-
-               MCODECHECK(8);
+                       /* move machine code onto stack */
 
-               M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
+                       disp = dseg_adds4(cd, mcode);
+                       M_ILD(REG_ITMP3, REG_PV, disp);
+                       M_IST(REG_ITMP3, REG_SP, 3 * 8);
 
-               if (xcodeptr != NULL) {
-                       M_BR(xcodeptr - mcodeptr - 1);
+                       /* move class/method/field reference onto stack */
 
-               } else {
-                       xcodeptr = mcodeptr;
+                       disp = dseg_addaddress(cd, pref->ref);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_AST(REG_ITMP3, REG_SP, 2 * 8);
 
-                       a = dseg_addaddress(cd, string_java_lang_NullPointerException);
-                        M_ALD(REG_ITMP1_XPTR,REG_PV,a);
+                       /* move data segment displacement onto stack */
 
-                        a = dseg_addaddress(cd, asm_throw_and_handle_nat_exception);
-                        M_ALD(REG_PV, REG_PV, a);
+                       disp = dseg_adds4(cd, pref->disp);
+                       M_ILD(REG_ITMP3, REG_PV, disp);
+                       M_IST(REG_ITMP3, REG_SP, 1 * 8);
 
-                        M_JSR(REG_RA, REG_PV);
+                       /* move patcher function pointer onto stack */
 
-                        /* recompute pv */
-                        s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
-                        if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
-                        else {
-                                s4 ml = -s1, mh = 0;
-                                while (ml < -32768) { ml += 65536; mh--; }
-                                M_LDA(REG_PV, REG_RA, ml);
-                                M_LDAH(REG_PV, REG_PV, mh);
-                        }
+                       disp = dseg_addaddress(cd, pref->patcher);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_AST(REG_ITMP3, REG_SP, 0 * 8);
 
+                       disp = dseg_addaddress(cd, asm_wrapper_patcher);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_JMP(REG_ZERO, REG_ITMP3);
                }
-       }
-
-       /* generate put/getstatic stub call code */
 
-       {
-               patchref *pref;
-               u4        mcode;
-               s4       *tmpmcodeptr;
+               /* generate replacement-out stubs */
 
-               for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
-                       /* check code segment size */
-                       MCODECHECK(9);
+               {
+                       int i;
 
-                       /* Get machine code which is patched back in later. The call is   */
-                       /* 1 instruction word long.                                       */
-                       xcodeptr = (s4 *) (cd->mcodebase + pref->branchpos);
-                       mcode = *xcodeptr;
+                       replacementpoint = cd->code->rplpoints;
+                       for (i=0; i<cd->code->rplpointcount; ++i, ++replacementpoint) {
+                               /* check code segment size */
 
-                       /* patch in the call to call the following code (done at compile  */
-                       /* time)                                                          */
+                               MCODECHECK(100);
 
-                       tmpmcodeptr = mcodeptr;         /* save current mcodeptr          */
-                       mcodeptr = xcodeptr;            /* set mcodeptr to patch position */
+                               /* note start of stub code */
 
-                       M_BSR(REG_RA, tmpmcodeptr - (xcodeptr + 1));
+                               replacementpoint->outcode = (u1*) (ptrint)((u1*)mcodeptr - cd->mcodebase);
 
-                       mcodeptr = tmpmcodeptr;         /* restore the current mcodeptr   */
+                               /* make machine code for patching */
 
-                       /* create stack frame */
+                               tmpmcodeptr = mcodeptr;
+                               mcodeptr = (s4*) &(replacementpoint->mcode);
 
-                       M_LSUB_IMM(REG_SP, 3 * 8, REG_SP);
+                               disp = (ptrint)((s4*)replacementpoint->outcode - (s4*)replacementpoint->pc) - 1;
+                               M_BR(disp);
 
-                       /* move machine code onto stack */
+                               mcodeptr = tmpmcodeptr;
 
-                       a = dseg_adds4(cd, mcode);
-                       M_ILD(REG_ITMP3, REG_PV, a);
-                       M_IST(REG_ITMP3, REG_SP, 2 * 8);
+                               /* create stack frame */
 
-                       /* move class/method/field reference onto stack */
+                               M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
 
-                       a = dseg_addaddress(cd, pref->ref);
-                       M_ALD(REG_ITMP3, REG_PV, a);
-                       M_AST(REG_ITMP3, REG_SP, 1 * 8);
+                               /* push address of `rplpoint` struct */
 
-                       /* move patcher function pointer onto stack */
+                               disp = dseg_addaddress(cd, replacementpoint);
+                               M_ALD(REG_ITMP3, REG_PV, disp);
+                               M_AST(REG_ITMP3, REG_SP, 0 * 8);
 
-                       a = dseg_addaddress(cd, pref->patcher);
-                       M_ALD(REG_ITMP3, REG_PV, a);
-                       M_AST(REG_ITMP3, REG_SP, 0 * 8);
+                               /* jump to replacement function */
 
-                       a = dseg_addaddress(cd, asm_wrapper_patcher);
-                       M_ALD(REG_ITMP3, REG_PV, a);
-                       M_JMP(REG_ZERO, REG_ITMP3);
+                               disp = dseg_addaddress(cd, asm_replacement_out);
+                               M_ALD(REG_ITMP3, REG_PV, disp);
+                               M_JMP(REG_ZERO, REG_ITMP3);
+                       }
                }
        }
-       }
 
        codegen_finish(m, cd, (s4) ((u1 *) mcodeptr - cd->mcodebase));
+
+       /* everything's ok */
+
+       return true;
 }
 
 
-/* function createcompilerstub *************************************************
+/* createcompilerstub **********************************************************
 
-       creates a stub routine which calls the compiler
+   Creates a stub routine which calls the compiler.
        
 *******************************************************************************/
 
-#define COMPSTUBSIZE    3
+#define COMPILERSTUB_DATASIZE    2 * SIZEOF_VOID_P
+#define COMPILERSTUB_CODESIZE    3 * 4
+
+#define COMPILERSTUB_SIZE        COMPILERSTUB_DATASIZE + COMPILERSTUB_CODESIZE
+
 
 u1 *createcompilerstub(methodinfo *m)
 {
-       u8 *s = CNEW(u8, COMPSTUBSIZE);     /* memory to hold the stub            */
-       s4 *mcodeptr = (s4 *) s;            /* code generation pointer            */
-       
-                                           /* code for the stub                  */
-       M_ALD(REG_PV, REG_PV, 16);          /* load pointer to the compiler       */
-       M_JMP(0, REG_PV);                   /* jump to the compiler, return address
-                                              in reg 0 is used as method pointer */
-       s[1] = (u8) m;                      /* literals to be adressed            */  
-       s[2] = (u8) asm_call_jit_compiler;  /* jump directly via PV from above    */
-
-#if defined(STATISTICS)
-       if (opt_stat)
-               count_cstub_len += COMPSTUBSIZE * 8;
-#endif
+       u1     *s;                          /* memory to hold the stub            */
+       ptrint *d;
+       s4     *mcodeptr;                   /* code generation pointer            */
 
-       return (u1 *) s;
-}
+       s = CNEW(u1, COMPILERSTUB_SIZE);
+
+       /* set data pointer and code pointer */
 
+       d = (ptrint *) s;
+       s = s + COMPILERSTUB_DATASIZE;
 
-/* function removecompilerstub *************************************************
+       mcodeptr = (s4 *) s;
+       
+       /* Store the methodinfo* in the same place as in the methodheader
+          for compiled methods. */
 
-     deletes a compilerstub from memory  (simply by freeing it)
+       d[0] = (ptrint) asm_call_jit_compiler;
+       d[1] = (ptrint) m;
 
-*******************************************************************************/
+       /* code for the stub */
 
-void removecompilerstub(u1 *stub)
-{
-       CFREE(stub, COMPSTUBSIZE * 8);
+       M_ALD(REG_ITMP1, REG_PV, -1 * 8);   /* load methodinfo pointer            */
+       M_ALD(REG_PV, REG_PV, -2 * 8);      /* load pointer to the compiler       */
+       M_JMP(REG_ZERO, REG_PV);            /* jump to the compiler               */
+
+#if defined(ENABLE_STATISTICS)
+       if (opt_stat)
+               count_cstub_len += COMPILERSTUB_SIZE;
+#endif
+
+       return s;
 }
 
 
-/* function: createnativestub **************************************************
+/* createnativestub ************************************************************
 
-       creates a stub routine which calls a native method
+   Creates a stub routine which calls a native method.
 
 *******************************************************************************/
 
+u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
+                                        registerdata *rd, methoddesc *nmd)
+{
+       s4         *mcodeptr;               /* code generation pointer            */
+       s4          stackframesize;         /* size of stackframe if needed       */
+       methoddesc *md;
+       s4          nativeparams;
+       s4          i, j;                   /* count variables                    */
+       s4          t;
+       s4          s1, s2, disp;
+       s4          funcdisp;               /* displacement of the function       */
 
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-#define NATIVESTUB_STACK          8/*ra,native result, oldThreadspecificHeadValue, addressOfThreadspecificHead, method, 0,0,ra*/
-#define NATIVESTUB_THREAD_EXTRA    (6 + 20) /*20 for additional frame creation*/
-#define NATIVESTUB_STACKTRACE_OFFSET   1
-#else
-#define NATIVESTUB_STACK          7/*ra,oldThreadspecificHeadValue, addressOfThreadspecificHead, method, 0,0,ra*/
-#define NATIVESTUB_THREAD_EXTRA    (1 + 20) /*20 for additional frame creation*/
-#define NATIVESTUB_STACKTRACE_OFFSET   0
-#endif
-
-#define NATIVESTUB_SIZE            (44 + NATIVESTUB_THREAD_EXTRA - 1)
-#define NATIVESTUB_STATIC_SIZE     5
-#define NATIVESTUB_VERBOSE_SIZE    (39 + 13)
-#define NATIVESTUB_OFFSET          12
+       /* initialize variables */
 
-#if 0
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-#define NATIVESTUB_STACK           2
-#define NATIVESTUB_THREAD_EXTRA    6
-#else
-#define NATIVESTUB_STACK           1
-#define NATIVESTUB_THREAD_EXTRA    1
-#endif
+       md = m->parseddesc;
+       nativeparams = (m->flags & ACC_STATIC) ? 2 : 1;
 
-#define NATIVESTUB_SIZE            (44 + NATIVESTUB_THREAD_EXTRA - 1)
-#define NATIVESTUB_STATIC_SIZE     4
-#define NATIVESTUB_VERBOSE_SIZE    (39 + 13)
-#define NATIVESTUB_OFFSET          10
-#endif
 
-u1 *createnativestub(functionptr f, methodinfo *m)
-{
-       u8 *s;                              /* memory pointer to hold the stub    */
-       u8 *cs;
-       s4 *mcodeptr;                       /* code generation pointer            */
-       s4 stackframesize = 0;              /* size of stackframe if needed       */
-       s4 disp;
-       s4 stubsize;
-       codegendata  *cd;
-       registerdata *rd;
-       t_inlining_globals *id;
-       s4 dumpsize;
+       /* calculate stack frame size */
 
-       /* mark start of dump memory area */
+       stackframesize =
+               1 +                             /* return address                     */
+               sizeof(stackframeinfo) / SIZEOF_VOID_P +
+               sizeof(localref_table) / SIZEOF_VOID_P +
+               1 +                             /* methodinfo for call trace          */
+               (md->paramcount > INT_ARG_CNT ? INT_ARG_CNT : md->paramcount) +
+               nmd->memuse;
 
-       dumpsize = dump_size();
 
-       /* setup registers before using it */
+       /* create method header */
 
-       cd = DNEW(codegendata);
-       rd = DNEW(registerdata);
-       id = DNEW(t_inlining_globals);
+       (void) dseg_addaddress(cd, m);                          /* MethodPointer  */
+       (void) dseg_adds4(cd, stackframesize * 8);              /* FrameSize      */
+       (void) dseg_adds4(cd, 0);                               /* IsSync         */
+       (void) dseg_adds4(cd, 0);                               /* IsLeaf         */
+       (void) dseg_adds4(cd, 0);                               /* IntSave        */
+       (void) dseg_adds4(cd, 0);                               /* FltSave        */
+       (void) dseg_addlinenumbertablesize(cd);
+       (void) dseg_adds4(cd, 0);                               /* ExTableSize    */
 
-       inlining_setup(m, id);
-       reg_setup(m, rd, id);
 
-       method_descriptor2types(m);                /* set paramcount and paramtypes      */
+       /* initialize mcode variables */
+       
+       mcodeptr = (s4 *) cd->mcodeptr;
 
-       stubsize = NATIVESTUB_SIZE;         /* calculate nativestub size          */
 
-       if ((m->flags & ACC_STATIC) && !m->class->initialized)
-               stubsize += NATIVESTUB_STATIC_SIZE;
+       /* generate stub code */
 
-       if (runverbose)
-               stubsize += NATIVESTUB_VERBOSE_SIZE;
+       M_LDA(REG_SP, REG_SP, -stackframesize * 8);
+       M_AST(REG_RA, REG_SP, stackframesize * 8 - SIZEOF_VOID_P);
 
-       s = CNEW(u8, stubsize);             /* memory to hold the stub            */
-       cs = s + NATIVESTUB_OFFSET;
-       mcodeptr = (s4 *) cs;               /* code generation pointer            */
 
-       /* set some required varibles which are normally set by codegen_setup     */
-       cd->mcodebase = (u1 *) mcodeptr;
-       cd->patchrefs = NULL;
+       /* call trace function */
 
-       *(cs-1)  = (u8) f;                  /* address of native method           */
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-       *(cs-2)  = (u8) &builtin_get_exceptionptrptr;
-#else
-       *(cs-2)  = (u8) (&_exceptionptr);   /* address of exceptionptr            */
-#endif
-       *(cs-3)  = (u8) asm_handle_nat_exception; /* addr of asm exception handler*/
-       *(cs-4)  = (u8) (&env);             /* addr of jni_environement           */
-       *(cs-5)  = (u8) builtin_trace_args;
-       *(cs-6)  = (u8) m;
-       *(cs-7)  = (u8) builtin_displaymethodstop;
-       *(cs-8)  = (u8) m->class;
-       *(cs-9)  = (u8) asm_wrapper_patcher;
-       *(cs-10) = (u8) &builtin_asm_get_stackframeinfo;
-       *(cs-11) = (u8) NULL;               /* filled with machine code           */
-       *(cs-12) = (u8) PATCHER_clinit;
+       if (opt_verbosecall) {
+               /* save integer argument registers */
 
-       M_LDA(REG_SP, REG_SP, -NATIVESTUB_STACK * 8);     /* build up stackframe  */
-       M_AST(REG_RA, REG_SP, 0 * 8);       /* store return address               */
+               for (i = 0, j = 1; i < md->paramcount && i < INT_ARG_CNT; i++) {
+                       if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
+                               M_LST(rd->argintregs[i], REG_SP, j * 8);
+                               j++;
+                       }
+               }
 
-       M_AST(REG_RA, REG_SP, (6+NATIVESTUB_STACKTRACE_OFFSET) * 8);       /* store return address  in stackinfo helper*/
+               /* save and copy float arguments into integer registers */
 
-       /* if function is static, check for initialized */
+               for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
+                       t = md->paramtypes[i].type;
 
-       if (m->flags & ACC_STATIC) {
-       /* if class isn't yet initialized, do it */
-               if (!m->class->initialized) {
-                       codegen_addpatchref(cd, mcodeptr, NULL, NULL);
+                       if (IS_FLT_DBL_TYPE(t)) {
+                               if (IS_2_WORD_TYPE(t)) {
+                                       M_DST(rd->argfltregs[i], REG_SP, j * 8);
+                                       M_LLD(rd->argintregs[i], REG_SP, j * 8);
+                               } else {
+                                       M_FST(rd->argfltregs[i], REG_SP, j * 8);
+                                       M_ILD(rd->argintregs[i], REG_SP, j * 8);
+                               }
+                               j++;
+                       }
                }
-       }
 
-       /* max. 39 +9 instructions */
-       {
-               s4 p;
-               s4 t;
-               M_LDA(REG_SP, REG_SP, -((INT_ARG_CNT + FLT_ARG_CNT + 2) * 8));
-               M_AST(REG_RA, REG_SP, 1 * 8);
+               disp = dseg_addaddress(cd, m);
+               M_ALD(REG_ITMP1, REG_PV, disp);
+               M_AST(REG_ITMP1, REG_SP, 0 * 8);
+               disp = dseg_addaddress(cd, builtin_trace_args);
+               M_ALD(REG_PV, REG_PV, disp);
+               M_JSR(REG_RA, REG_PV);
+               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+               M_LDA(REG_PV, REG_RA, -disp);
 
-               /* save integer argument registers */
-               for (p = 0; p < m->paramcount && p < INT_ARG_CNT; p++) {
-                       M_LST(rd->argintregs[p], REG_SP, (2 + p) * 8);
+               for (i = 0, j = 1; i < md->paramcount && i < INT_ARG_CNT; i++) {
+                       if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
+                               M_LLD(rd->argintregs[i], REG_SP, j * 8);
+                               j++;
+                       }
                }
 
-               /* save and copy float arguments into integer registers */
-               for (p = 0; p < m->paramcount && p < FLT_ARG_CNT; p++) {
-                       t = m->paramtypes[p];
+               for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
+                       t = md->paramtypes[i].type;
 
                        if (IS_FLT_DBL_TYPE(t)) {
                                if (IS_2_WORD_TYPE(t)) {
-                                       M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-                                       M_LLD(rd->argintregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-
+                                       M_DLD(rd->argfltregs[i], REG_SP, j * 8);
                                } else {
-                                       M_FST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-                                       M_ILD(rd->argintregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                                       M_FLD(rd->argfltregs[i], REG_SP, j * 8);
                                }
-                               
-                       } else {
-                               M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                               j++;
                        }
                }
+       }
 
-               if (runverbose) {
-                       M_ALD(REG_ITMP1, REG_PV, -6 * 8);
-                       M_AST(REG_ITMP1, REG_SP, 0 * 8);
-                       M_ALD(REG_PV, REG_PV, -5 * 8);
-                       M_JSR(REG_RA, REG_PV);
-                       disp = -(s4) (mcodeptr - (s4 *) cs) * 4;
-                       M_LDA(REG_PV, REG_RA, disp);
-               }
+       /* get function address (this must happen before the stackframeinfo) */
 
+       funcdisp = dseg_addaddress(cd, f);
 
-/*stack info */
-                M_ALD(REG_PV, REG_PV, -10 * 8);      /* builtin_asm_get_stackframeinfo        */
-                M_JSR(REG_RA, REG_PV);
-                disp = -(s4) (mcodeptr - (s4 *) cs) * 4;
-                M_LDA(REG_PV, REG_RA, disp);
+#if !defined(WITH_STATIC_CLASSPATH)
+       if (f == NULL) {
+               codegen_addpatchref(cd, mcodeptr, PATCHER_resolve_native, m, funcdisp);
 
-#if 0
-                M_MOV(REG_RESULT,REG_ITMP3);
-                M_LST(REG_RESULT,REG_ITMP3,0);
+               if (opt_showdisassemble)
+                       M_NOP;
+       }
 #endif
-                M_LST(REG_RESULT,REG_SP, ((INT_ARG_CNT + FLT_ARG_CNT + 2) * 8)+(2+NATIVESTUB_STACKTRACE_OFFSET)*8);/*save adress of pointer*/
-                M_LLD(REG_ITMP3,REG_RESULT,0); /* get pointer*/
-                M_LST(REG_ITMP3,REG_SP,(1+NATIVESTUB_STACKTRACE_OFFSET)*8+((INT_ARG_CNT + FLT_ARG_CNT + 2) * 8)); /*save old value*/
-                M_LDA(REG_ITMP3,REG_SP,(1+NATIVESTUB_STACKTRACE_OFFSET)*8+((INT_ARG_CNT + FLT_ARG_CNT + 2) * 8)); /*calculate new value*/
-                M_LLD(REG_ITMP2,REG_ITMP3,8);
-                M_LST(REG_ITMP3,REG_ITMP2,0); /*store new value*/
-                M_LLD(REG_ITMP2,REG_PV,-6*8);
-                M_LST(REG_ITMP2,REG_SP,(3+NATIVESTUB_STACKTRACE_OFFSET)*8+((INT_ARG_CNT + FLT_ARG_CNT + 2) * 8));
-                M_LST(REG_ZERO,REG_SP,(4+NATIVESTUB_STACKTRACE_OFFSET)*8+((INT_ARG_CNT + FLT_ARG_CNT + 2) * 8));
-                M_LST(REG_ZERO,REG_SP,(5+NATIVESTUB_STACKTRACE_OFFSET)*8+((INT_ARG_CNT + FLT_ARG_CNT + 2) * 8));
-/*stack info -end */
-
-
-               for (p = 0; p < m->paramcount && p < INT_ARG_CNT; p++) {
-                       M_LLD(rd->argintregs[p], REG_SP, (2 + p) * 8);
+
+       /* save integer and float argument registers */
+
+       for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++) {
+               if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
+                       M_LST(rd->argintregs[i], REG_SP, j * 8);
+                       j++;
                }
+       }
 
-               for (p = 0; p < m->paramcount && p < FLT_ARG_CNT; p++) {
-                       t = m->paramtypes[p];
+       for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
+               if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
+                       M_DST(rd->argfltregs[i], REG_SP, j * 8);
+                       j++;
+               }
+       }
 
-                       if (IS_FLT_DBL_TYPE(t)) {
-                               if (IS_2_WORD_TYPE(t)) {
-                                       M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+       /* prepare data structures for native function call */
 
-                               } else {
-                                       M_FLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-                               }
+       M_LDA(rd->argintregs[0], REG_SP, stackframesize * 8 - SIZEOF_VOID_P);
+       M_MOV(REG_PV, rd->argintregs[1]);
+       M_LDA(rd->argintregs[2], REG_SP, stackframesize * 8);
+       M_ALD(rd->argintregs[3], REG_SP, stackframesize * 8 - SIZEOF_VOID_P);
+       disp = dseg_addaddress(cd, codegen_start_native_call);
+       M_ALD(REG_PV, REG_PV, disp);
+       M_JSR(REG_RA, REG_PV);
+       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+       M_LDA(REG_PV, REG_RA, -disp);
 
-                       } else {
-                               M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-                       }
+       /* restore integer and float argument registers */
+
+       for (i = 0, j = 0; i < md->paramcount && i < INT_ARG_CNT; i++) {
+               if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
+                       M_LLD(rd->argintregs[i], REG_SP, j * 8);
+                       j++;
                }
+       }
 
-               M_ALD(REG_RA, REG_SP, 1 * 8);
-               M_LDA(REG_SP, REG_SP, (INT_ARG_CNT + FLT_ARG_CNT + 2) * 8);
+       for (i = 0; i < md->paramcount && i < FLT_ARG_CNT; i++) {
+               if (IS_FLT_DBL_TYPE(md->paramtypes[i].type)) {
+                       M_DLD(rd->argfltregs[i], REG_SP, j * 8);
+                       j++;
+               }
        }
 
-       /* save argument registers on stack -- if we have to */
-       if ((m->flags & ACC_STATIC && m->paramcount > (INT_ARG_CNT - 2)) || m->paramcount > (INT_ARG_CNT - 1)) {
-               s4 i;
-               s4 paramshiftcnt = (m->flags & ACC_STATIC) ? 2 : 1;
-               s4 stackparamcnt = (m->paramcount > INT_ARG_CNT) ? m->paramcount - INT_ARG_CNT : 0;
+       /* copy or spill arguments to new locations */
 
-               stackframesize = stackparamcnt + paramshiftcnt;
+       for (i = md->paramcount - 1, j = i + nativeparams; i >= 0; i--, j--) {
+               t = md->paramtypes[i].type;
 
-               M_LDA(REG_SP, REG_SP, -stackframesize * 8);
+               if (IS_INT_LNG_TYPE(t)) {
+                       if (!md->params[i].inmemory) {
+                               s1 = rd->argintregs[md->params[i].regoff];
 
-               /* copy stack arguments into new stack frame -- if any */
-               for (i = 0; i < stackparamcnt; i++) {
-                       M_LLD(REG_ITMP1, REG_SP, (stackparamcnt + 1 + i) * 8);
-                       M_LST(REG_ITMP1, REG_SP, (paramshiftcnt + i) * 8);
-               }
+                               if (!nmd->params[j].inmemory) {
+                                       s2 = rd->argintregs[nmd->params[j].regoff];
+                                       M_INTMOVE(s1, s2);
 
-               if (m->flags & ACC_STATIC) {
-                       if (IS_FLT_DBL_TYPE(m->paramtypes[5])) {
-                               M_DST(rd->argfltregs[5], REG_SP, 1 * 8);
-                       } else {
-                               M_LST(rd->argintregs[5], REG_SP, 1 * 8);
-                       }
+                               } else {
+                                       s2 = nmd->params[j].regoff;
+                                       M_LST(s1, REG_SP, s2 * 8);
+                               }
 
-                       if (IS_FLT_DBL_TYPE(m->paramtypes[4])) {
-                               M_DST(rd->argfltregs[4], REG_SP, 0 * 8);
                        } else {
-                               M_LST(rd->argintregs[4], REG_SP, 0 * 8);
+                               s1 = md->params[i].regoff + stackframesize;
+                               s2 = nmd->params[j].regoff;
+                               M_LLD(REG_ITMP1, REG_SP, s1 * 8);
+                               M_LST(REG_ITMP1, REG_SP, s2 * 8);
                        }
 
                } else {
-                       if (IS_FLT_DBL_TYPE(m->paramtypes[5])) {
-                               M_DST(rd->argfltregs[5], REG_SP, 0 * 8);
-                       } else {
-                               M_LST(rd->argintregs[5], REG_SP, 0 * 8);
-                       }
-               }
-       }
-#if 1
-       {
-               s4 i;
+                       if (!md->params[i].inmemory) {
+                               s1 = rd->argfltregs[md->params[i].regoff];
 
-               if (m->flags & ACC_STATIC) {
-                       /* shift iargs count if less than INT_ARG_CNT, or all */
-                       for (i = (m->paramcount < (INT_ARG_CNT - 2)) ? m->paramcount : (INT_ARG_CNT - 2); i >= 0; i--) {
-                               M_MOV(rd->argintregs[i], rd->argintregs[i + 2]);
-                               M_FMOV(rd->argfltregs[i], rd->argfltregs[i + 2]);
-                       }
+                               if (!nmd->params[j].inmemory) {
+                                       s2 = rd->argfltregs[nmd->params[j].regoff];
+                                       M_FLTMOVE(s1, s2);
 
-                       /* put class into second argument register */
-                       M_ALD(rd->argintregs[1], REG_PV, -8 * 8);
+                               } else {
+                                       s2 = nmd->params[j].regoff;
+                                       if (IS_2_WORD_TYPE(t))
+                                               M_DST(s1, REG_SP, s2 * 8);
+                                       else
+                                               M_FST(s1, REG_SP, s2 * 8);
+                               }
 
-               } else {
-                       /* shift iargs count if less than INT_ARG_CNT, or all */
-                       for (i = (m->paramcount < (INT_ARG_CNT - 1)) ? m->paramcount : (INT_ARG_CNT - 1); i >= 0; i--) {
-                               M_MOV(rd->argintregs[i], rd->argintregs[i + 1]);
-                               M_FMOV(rd->argfltregs[i], rd->argfltregs[i + 1]);
+                       } else {
+                               s1 = md->params[i].regoff + stackframesize;
+                               s2 = nmd->params[j].regoff;
+                               M_DLD(REG_FTMP1, REG_SP, s1 * 8);
+                               if (IS_2_WORD_TYPE(t))
+                                       M_DST(REG_FTMP1, REG_SP, s2 * 8);
+                               else
+                                       M_FST(REG_FTMP1, REG_SP, s2 * 8);
                        }
                }
        }
-#else
+
+       /* put class into second argument register */
+
        if (m->flags & ACC_STATIC) {
-               M_MOV(rd->argintregs[3], rd->argintregs[5]);
-               M_MOV(rd->argintregs[2], rd->argintregs[4]);
-               M_MOV(rd->argintregs[1], rd->argintregs[3]);
-               M_MOV(rd->argintregs[0], rd->argintregs[2]);
-               M_FMOV(rd->argfltregs[3], rd->argfltregs[5]);
-               M_FMOV(rd->argfltregs[2], rd->argfltregs[4]);
-               M_FMOV(rd->argfltregs[1], rd->argfltregs[3]);
-               M_FMOV(rd->argfltregs[0], rd->argfltregs[2]);
-
-               /* put class into second argument register */
-               M_ALD(rd->argintregs[1], REG_PV, -8 * 8);
-
-       } else {
-               M_MOV(rd->argintregs[4], rd->argintregs[5]);
-               M_MOV(rd->argintregs[3], rd->argintregs[4]);
-               M_MOV(rd->argintregs[2], rd->argintregs[3]);
-               M_MOV(rd->argintregs[1], rd->argintregs[2]);
-               M_MOV(rd->argintregs[0], rd->argintregs[1]);
-               M_FMOV(rd->argfltregs[4], rd->argfltregs[5]);
-               M_FMOV(rd->argfltregs[3], rd->argfltregs[4]);
-               M_FMOV(rd->argfltregs[2], rd->argfltregs[3]);
-               M_FMOV(rd->argfltregs[1], rd->argfltregs[2]);
-               M_FMOV(rd->argfltregs[0], rd->argfltregs[1]);
+               disp = dseg_addaddress(cd, m->class);
+               M_ALD(rd->argintregs[1], REG_PV, disp);
        }
-#endif
 
        /* put env into first argument register */
-       M_ALD(rd->argintregs[0], REG_PV, -4 * 8);
 
-       M_ALD(REG_PV, REG_PV, -1 * 8);      /* load adress of native method       */
+       disp = dseg_addaddress(cd, _Jv_env);
+       M_ALD(rd->argintregs[0], REG_PV, disp);
+
+       /* do the native function call */
+
+       M_ALD(REG_PV, REG_PV, funcdisp);
        M_JSR(REG_RA, REG_PV);              /* call native method                 */
-       disp = -(s4) (mcodeptr - (s4 *) cs) * 4;
-       M_LDA(REG_PV, REG_RA, disp);        /* recompute pv from ra               */
+       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+       M_LDA(REG_PV, REG_RA, -disp);       /* recompute pv from ra               */
 
-       /* remove stackframe if there is one */
-       if (stackframesize) {
-               M_LDA(REG_SP, REG_SP, stackframesize * 8);
-       }
+       /* save return value */
 
-       /* 13 instructions */
-       if (runverbose) {
-               M_LDA(REG_SP, REG_SP, -2 * 8);
-               M_ALD(rd->argintregs[0], REG_PV, -6 * 8); /* load method adress       */
+       if (IS_INT_LNG_TYPE(md->returntype.type))
                M_LST(REG_RESULT, REG_SP, 0 * 8);
-               M_DST(REG_FRESULT, REG_SP, 1 * 8);
+       else
+               M_DST(REG_FRESULT, REG_SP, 0 * 8);
+
+       /* remove native stackframe info */
+
+       M_LDA(rd->argintregs[0], REG_SP, stackframesize * 8 - SIZEOF_VOID_P);
+       disp = dseg_addaddress(cd, codegen_finish_native_call);
+       M_ALD(REG_PV, REG_PV, disp);
+       M_JSR(REG_RA, REG_PV);
+       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+       M_LDA(REG_PV, REG_RA, -disp);
+
+       /* call finished trace */
+
+       if (opt_verbosecall) {
+               /* just restore the value we need, don't care about the other */
+
+               if (IS_INT_LNG_TYPE(md->returntype.type))
+                       M_LLD(REG_RESULT, REG_SP, 0 * 8);
+               else
+                       M_DLD(REG_FRESULT, REG_SP, 0 * 8);
+
+               disp = dseg_addaddress(cd, m);
+               M_ALD(rd->argintregs[0], REG_PV, disp);
+
                M_MOV(REG_RESULT, rd->argintregs[1]);
                M_FMOV(REG_FRESULT, rd->argfltregs[2]);
                M_FMOV(REG_FRESULT, rd->argfltregs[3]);
-               M_ALD(REG_PV, REG_PV, -7 * 8);  /* builtin_displaymethodstop          */
+
+               disp = dseg_addaddress(cd, builtin_displaymethodstop);
+               M_ALD(REG_PV, REG_PV, disp);
                M_JSR(REG_RA, REG_PV);
-               disp = -(s4) (mcodeptr - (s4 *) cs) * 4;
-               M_LDA(REG_PV, REG_RA, disp);
-               M_LLD(REG_RESULT, REG_SP, 0 * 8);
-               M_DLD(REG_FRESULT, REG_SP, 1 * 8);
-               M_LDA(REG_SP, REG_SP, 2 * 8);
+               disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+               M_LDA(REG_PV, REG_RA, -disp);
        }
 
-        M_LLD(REG_ITMP3,REG_SP,(2+NATIVESTUB_STACKTRACE_OFFSET)*8); /*get address of stacktrace helper pointer*/
-        M_LLD(REG_ITMP1,REG_SP,(1+NATIVESTUB_STACKTRACE_OFFSET)*8); /*get old value*/
-        M_LST(REG_ITMP1,REG_ITMP3,0); /*set old value*/
+       /* check for exception */
 
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-       if (IS_FLT_DBL_TYPE(m->returntype))
-               M_DST(REG_FRESULT, REG_SP, 1 * 8);
-       else
-               M_AST(REG_RESULT, REG_SP, 1 * 8);
-       M_ALD(REG_PV, REG_PV, -2 * 8);      /* builtin_get_exceptionptrptr        */
+       disp = dseg_addaddress(cd, builtin_get_exceptionptrptr);
+       M_ALD(REG_PV, REG_PV, disp);
        M_JSR(REG_RA, REG_PV);
-       disp = -(s4) (mcodeptr - (s4 *) cs) * 4;
-       M_LDA(REG_PV, REG_RA, disp);
+       disp = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+       M_LDA(REG_PV, REG_RA, -disp);
        M_MOV(REG_RESULT, REG_ITMP3);
-       if (IS_FLT_DBL_TYPE(m->returntype))
-               M_DLD(REG_FRESULT, REG_SP, 1 * 8);
-       else
-               M_ALD(REG_RESULT, REG_SP, 1 * 8);
 #else
-       M_ALD(REG_ITMP3, REG_PV, -2 * 8);   /* get address of exceptionptr        */
+       disp = dseg_addaddress(cd, &_exceptionptr);
+       M_ALD(REG_RESULT, REG_PV, disp);    /* get address of exceptionptr        */
 #endif
        M_ALD(REG_ITMP1, REG_ITMP3, 0);     /* load exception into reg. itmp1     */
+
+       /* restore return value */
+
+       if (IS_INT_LNG_TYPE(md->returntype.type))
+               M_LLD(REG_RESULT, REG_SP, 0 * 8);
+       else
+               M_DLD(REG_FRESULT, REG_SP, 0 * 8);
+
        M_BNEZ(REG_ITMP1, 3);               /* if no exception then return        */
 
-       M_ALD(REG_RA, REG_SP, 0 * 8);       /* load return address                */
-       M_LDA(REG_SP, REG_SP, NATIVESTUB_STACK * 8); /* remove stackframe         */
+       M_ALD(REG_RA, REG_SP, (stackframesize - 1) * 8); /* load return address   */
+       M_LDA(REG_SP, REG_SP, stackframesize * 8);
        M_RET(REG_ZERO, REG_RA);            /* return to caller                   */
 
+       /* handle exception */
+
        M_AST(REG_ZERO, REG_ITMP3, 0);      /* store NULL into exceptionptr       */
 
-       M_ALD(REG_RA, REG_SP, 0 * 8);       /* load return address                */
-       M_LDA(REG_SP, REG_SP, NATIVESTUB_STACK * 8); /* remove stackframe         */
+       M_ALD(REG_RA, REG_SP, (stackframesize - 1) * 8); /* load return address   */
        M_LDA(REG_ITMP2, REG_RA, -4);       /* move fault address into reg. itmp2 */
-       M_ALD(REG_ITMP3, REG_PV, -3 * 8);   /* load asm exception handler address */
+
+       M_LDA(REG_SP, REG_SP, stackframesize * 8);
+
+       disp = dseg_addaddress(cd, asm_handle_nat_exception);
+       M_ALD(REG_ITMP3, REG_PV, disp);     /* load asm exception handler address */
        M_JMP(REG_ZERO, REG_ITMP3);         /* jump to asm exception handler      */
        
-       /* generate put/getstatic stub call code */
+
+       /* process patcher calls **************************************************/
 
        {
                patchref *pref;
-               s4       *xcodeptr;
+               u4        mcode;
+               s4       *savedmcodeptr;
                s4       *tmpmcodeptr;
 
-               /* there can only be one <clinit> ref entry                           */
+               /* there can only be one <clinit> ref entry */
+
                pref = cd->patchrefs;
 
-               if (pref) {
-                       /* Get machine code which is patched back in later. The call is   */
-                       /* 1 instruction word long.                                       */
-                       xcodeptr = (s4 *) (cd->mcodebase + pref->branchpos);
-                       *(cs-11) = (u4) *xcodeptr;
+               for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
+                       /* Get machine code which is patched back in later. The
+                          call is 1 instruction word long. */
+
+                       savedmcodeptr = (s4 *) (cd->mcodebase + pref->branchpos);
+                       mcode = (u4) *savedmcodeptr;
 
                        /* patch in the call to call the following code (done at compile  */
                        /* time)                                                          */
 
                        tmpmcodeptr = mcodeptr;         /* save current mcodeptr          */
-                       mcodeptr = xcodeptr;            /* set mcodeptr to patch position */
+                       mcodeptr    = savedmcodeptr;    /* set mcodeptr to patch position */
 
-                       M_BSR(REG_RA, tmpmcodeptr - (xcodeptr + 1));
+                       M_BSR(REG_ITMP3, tmpmcodeptr - (savedmcodeptr + 1));
 
                        mcodeptr = tmpmcodeptr;         /* restore the current mcodeptr   */
 
-                       /* create stack frame                                             */
+                       /* create stack frame */
 
-                       M_LSUB_IMM(REG_SP, 3 * 8, REG_SP);
+                       M_LSUB_IMM(REG_SP, 6 * 8, REG_SP);
 
-                       /* move machine code onto stack                                   */
+                       /* move return address onto stack */
 
-                       M_ILD(REG_ITMP3, REG_PV, -11 * 8);    /* machine code             */
-                       M_IST(REG_ITMP3, REG_SP, 2 * 8);
+                       M_AST(REG_ITMP3, REG_SP, 5 * 8);
 
-                       /* move class reference onto stack                                */
+                       /* move pointer to java_objectheader onto stack */
 
-                       M_ALD(REG_ITMP3, REG_PV, -8 * 8);     /* class                    */
-                       M_AST(REG_ITMP3, REG_SP, 1 * 8);
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+                       /* create a virtual java_objectheader */
 
-                       /* move patcher function pointer onto stack                       */
+                       (void) dseg_addaddress(cd, get_dummyLR());          /* monitorPtr */
+                       disp = dseg_addaddress(cd, NULL);                   /* vftbl      */
 
-                       M_ALD(REG_ITMP3, REG_PV, -12 * 8);    /* patcher function         */
-                       M_AST(REG_ITMP3, REG_SP, 0 * 8);
+                       M_LDA(REG_ITMP3, REG_PV, disp);
+                       M_AST(REG_ITMP3, REG_SP, 4 * 8);
+#else
+                       M_AST(REG_ZERO, REG_SP, 4 * 8);
+#endif
 
-                       M_ALD(REG_ITMP3, REG_PV, -9 * 8);     /* asm_wrapper_patcher      */
-                       M_JMP(REG_ZERO, REG_ITMP3);
-               }
-       }
+                       /* move machine code onto stack */
 
-       /* Check if the stub size is big enough to hold the whole stub generated. */
-       /* If not, this can lead into unpredictable crashes, because of heap      */
-       /* corruption.                                                            */
-       if ((s4) ((ptrint) mcodeptr - (ptrint) s) > stubsize * sizeof(u8)) {
-               throw_cacao_exception_exit(string_java_lang_InternalError,
-                                                                  "Native stub size %d is to small for current stub size %d",
-                                                                  stubsize, (s4) ((ptrint) mcodeptr - (ptrint) s));
-       }
+                       disp = dseg_adds4(cd, mcode);
+                       M_ILD(REG_ITMP3, REG_PV, disp);
+                       M_IST(REG_ITMP3, REG_SP, 3 * 8);
 
-#if defined(STATISTICS)
-       if (opt_stat)
-               count_nstub_len += NATIVESTUB_SIZE * 8;
-#endif
+                       /* move class/method/field reference onto stack */
 
-       /* release dump area */
+                       disp = dseg_addaddress(cd, pref->ref);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_AST(REG_ITMP3, REG_SP, 2 * 8);
 
-       dump_release(dumpsize);
+                       /* move data segment displacement onto stack */
 
-       return (u1 *) (s + NATIVESTUB_OFFSET);
-}
+                       disp = dseg_adds4(cd, pref->disp);
+                       M_ILD(REG_ITMP3, REG_PV, disp);
+                       M_IST(REG_ITMP3, REG_SP, 1 * 8);
+
+                       /* move patcher function pointer onto stack */
 
+                       disp = dseg_addaddress(cd, pref->patcher);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_AST(REG_ITMP3, REG_SP, 0 * 8);
 
-/* function: removenativestub **************************************************
+                       disp = dseg_addaddress(cd, asm_wrapper_patcher);
+                       M_ALD(REG_ITMP3, REG_PV, disp);
+                       M_JMP(REG_ZERO, REG_ITMP3);
+               }
+       }
 
-    removes a previously created native-stub from memory
-    
-*******************************************************************************/
+       codegen_finish(m, cd, (s4) ((u1 *) mcodeptr - cd->mcodebase));
 
-void removenativestub(u1 *stub)
-{
-       CFREE((u8 *) stub - NATIVESTUBOFFSET, NATIVESTUBSIZE * 8);
+       return cd->code->entrypoint;
 }
 
 
@@ -4618,4 +4425,5 @@ void removenativestub(u1 *stub)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */