GNU header update.
[cacao.git] / src / vm / jit / alpha / codegen.c
index b39647a9daff4d3d883e6674d7f9251bea8b7fa4..ccec552f6e5746ae8746091d001e75e8bbac8bb1 100644 (file)
@@ -1,10 +1,9 @@
-/* jit/alpha/codegen.c - machine code generator for alpha
+/* vm/jit/alpha/codegen.c - machine code generator for alpha
 
-   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
-   Institut f. Computersprachen, TU Wien
-   R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
-   S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
-   J. Wenninger
+   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
 
    This file is part of CACAO.
 
    Authors: Andreas Krall
             Reinhard Grafl
 
-   $Id: codegen.c 1347 2004-07-21 23:29:39Z twisti $
+   Changes: Joseph Wenninger
+
+   $Id: codegen.c 1735 2004-12-07 14:33:27Z twisti $
 
 */
 
 
-#include "global.h"
 #include <stdio.h>
 #include <signal.h>
-#include "types.h"
-#include "main.h"
-#include "jit/alpha/codegen.h"
-#include "jit/jit.h"
-#include "jit/parse.h"
-#include "jit/reg.h"
-#include "builtin.h"
-#include "asmpart.h"
-#include "jni.h"
-#include "loader.h"
-#include "tables.h"
-#include "native.h"
-#include "main.h"
-
-/* include independent code generation stuff */
-#include "jit/codegen.inc"
-#include "jit/reg.inc"
+
+#include "vm/jit/alpha/arch.h"
+#include "native/native.h"
+#include "vm/builtin.h"
+#include "vm/global.h"
+#include "vm/loader.h"
+#include "vm/tables.h"
+#include "vm/jit/asmpart.h"
+#include "vm/jit/jit.h"
+#ifdef LSRA
+#include "vm/jit/lsra.h"
+#endif
+#include "vm/jit/parse.h"
+#include "vm/jit/reg.h"
+#include "vm/jit/alpha/codegen.h"
+#include "vm/jit/alpha/types.h"
+#include "vm/jit/alpha/asmoffsets.h"
 
 
 /* *****************************************************************************
@@ -108,13 +108,20 @@ int nregdescfloat[] = {
        REG_TMP, REG_TMP, REG_TMP, REG_TMP, REG_RES, REG_RES, REG_RES, REG_RES,
        REG_END };
 
-/* for use of reserved registers, see comment above */
+
+/* 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               */
@@ -162,16 +169,19 @@ void catch_NullPointerException(int sig, int code, sigctx_struct *sigctx)
        faultaddr = sigctx->sc_regs[(instr >> 16) & 0x1f];
 
        if (faultaddr == 0) {
-               signal(sig, (void*) catch_NullPointerException); /* reinstall handler */
+               /* reinstall handler */
+               signal(sig, (functionptr) catch_NullPointerException);
                sigemptyset(&nsig);
                sigaddset(&nsig, sig);
                sigprocmask(SIG_UNBLOCK, &nsig, NULL);           /* unblock signal    */
 
-               xptr = new_exception(string_java_lang_NullPointerException);
+               /*xptr = new_nullpointerexception();
+               sigctx->sc_regs[REG_ITMP1_XPTR] = (u8) xptr;*/
 
-               sigctx->sc_regs[REG_ITMP1_XPTR] = (u8) xptr;
+               sigctx->sc_regs[REG_ITMP1_XPTR]=string_java_lang_NullPointerException;
                sigctx->sc_regs[REG_ITMP2_XPC] = sigctx->sc_pc;
-               sigctx->sc_pc = (u8) asm_handle_exception;
+               /*sigctx->sc_pc = (u8) asm_handle_exception;*/
+               sigctx->sc_pc = (u8) asm_throw_and_handle_exception;
                return;
 
        } else {
@@ -214,11 +224,11 @@ ieee_set_fp_control(ieee_get_fp_control()
 
        if (!checknull) {
 #if defined(SIGSEGV)
-               signal(SIGSEGV, (void*) catch_NullPointerException);
+               signal(SIGSEGV, (functionptr) catch_NullPointerException);
 #endif
 
 #if defined(SIGBUS)
-               signal(SIGBUS, (void*) catch_NullPointerException);
+               signal(SIGBUS, (functionptr) catch_NullPointerException);
 #endif
        }
 }
@@ -230,7 +240,7 @@ ieee_set_fp_control(ieee_get_fp_control()
 
 *******************************************************************************/
 
-void codegen(methodinfo *m)
+void codegen(methodinfo *m, codegendata *cd, registerdata *rd)
 {
        s4 len, s1, s2, s3, d;
        s4 a;
@@ -241,13 +251,7 @@ void codegen(methodinfo *m)
        basicblock     *bptr;
        instruction    *iptr;
        exceptiontable *ex;
-       registerdata   *r;
-       codegendata    *cd;
-
-       /* keep code size smaller */
-       r = m->registerdata;
-       cd = m->codegendata;
-
+       u2 currentline=0;
        {
        s4 i, p, pa, t, l;
        s4 savedregs_num;
@@ -256,10 +260,10 @@ void codegen(methodinfo *m)
 
        /* space to save used callee saved registers */
 
-       savedregs_num += (r->savintregcnt - r->maxsavintreguse);
-       savedregs_num += (r->savfltregcnt - r->maxsavfltreguse);
+       savedregs_num += (rd->savintregcnt - rd->maxsavintreguse);
+       savedregs_num += (rd->savfltregcnt - rd->maxsavfltreguse);
 
-       parentargs_base = r->maxmemuse + savedregs_num;
+       parentargs_base = rd->maxmemuse + savedregs_num;
 
 #if defined(USE_THREADS)           /* space to save argument of monitor_enter */
 
@@ -270,8 +274,8 @@ void codegen(methodinfo *m)
 
        /* create method header */
 
-       (void) dseg_addaddress(m, m);                           /* MethodPointer  */
-       (void) dseg_adds4(m, parentargs_base * 8);                 /* FrameSize      */
+       (void) dseg_addaddress(cd, m);                          /* MethodPointer  */
+       (void) dseg_adds4(cd, parentargs_base * 8);             /* FrameSize      */
 
 #if defined(USE_THREADS)
 
@@ -282,28 +286,28 @@ void codegen(methodinfo *m)
        */
 
        if (checksync && (m->flags & ACC_SYNCHRONIZED))
-               (void) dseg_adds4(m, (r->maxmemuse + 1) * 8);       /* IsSync         */
+               (void) dseg_adds4(cd, (rd->maxmemuse + 1) * 8);     /* IsSync         */
        else
 
 #endif
 
-       (void) dseg_adds4(m, 0);                                /* IsSync         */
+       (void) dseg_adds4(cd, 0);                               /* IsSync         */
                                               
-       (void) dseg_adds4(m, m->isleafmethod);                  /* IsLeaf         */
-       (void) dseg_adds4(m, r->savintregcnt - r->maxsavintreguse);/* IntSave     */
-       (void) dseg_adds4(m, r->savfltregcnt - r->maxsavfltreguse);/* FltSave     */
+       (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  */
 
-       dseg_addlinenumbertablesize(m);
+       dseg_addlinenumbertablesize(cd);
 
-       (void) dseg_adds4(m, m->exceptiontablelength);          /* ExTableSize    */
+       (void) dseg_adds4(cd, cd->exceptiontablelength);        /* ExTableSize    */
 
        /* create exception table */
 
-       for (ex = m->exceptiontable; ex != NULL; ex = ex->down) {
-               dseg_addtarget(m, ex->start);
-               dseg_addtarget(m, ex->end);
-               dseg_addtarget(m, ex->handler);
-               (void) dseg_addaddress(m, ex->catchtype);
+       for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
+               dseg_addtarget(cd, ex->start);
+               dseg_addtarget(cd, ex->end);
+               dseg_addtarget(cd, ex->handler);
+               (void) dseg_addaddress(cd, ex->catchtype);
        }
        
        /* initialize mcode variables */
@@ -315,7 +319,7 @@ void codegen(methodinfo *m)
        /* create stack frame (if necessary) */
 
        if (parentargs_base) {
-               M_LDA (REG_SP, REG_SP, -parentargs_base * 8);
+               M_LDA(REG_SP, REG_SP, -parentargs_base * 8);
        }
 
        /* save return address and used callee saved registers */
@@ -324,11 +328,11 @@ void codegen(methodinfo *m)
        if (!m->isleafmethod) {
                p--; M_AST(REG_RA, REG_SP, p * 8);
        }
-       for (i = r->savintregcnt - 1; i >= r->maxsavintreguse; i--) {
-               p--; M_LST(r->savintregs[i], REG_SP, p * 8);
+       for (i = rd->savintregcnt - 1; i >= rd->maxsavintreguse; i--) {
+               p--; M_LST(rd->savintregs[i], REG_SP, p * 8);
        }
-       for (i = r->savfltregcnt - 1; i >= r->maxsavfltreguse; i--) {
-               p--; M_DST(r->savfltregs[i], REG_SP, p * 8);
+       for (i = rd->savfltregcnt - 1; i >= rd->maxsavfltreguse; i--) {
+               p--; M_DST(rd->savfltregs[i], REG_SP, p * 8);
        }
 
        /* save monitorenter argument */
@@ -336,12 +340,12 @@ void codegen(methodinfo *m)
 #if defined(USE_THREADS)
        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
                if (m->flags & ACC_STATIC) {
-                       p = dseg_addaddress(m, m->class);
+                       p = dseg_addaddress(cd, m->class);
                        M_ALD(REG_ITMP1, REG_PV, p);
-                       M_AST(REG_ITMP1, REG_SP, r->maxmemuse * 8);
+                       M_AST(REG_ITMP1, REG_SP, rd->maxmemuse * 8);
 
                } else {
-                       M_AST(r->argintregs[0], REG_SP, r->maxmemuse * 8);
+                       M_AST(rd->argintregs[0], REG_SP, rd->maxmemuse * 8);
                }
        }                       
 #endif
@@ -357,7 +361,7 @@ void codegen(methodinfo *m)
 
                /* save integer argument registers */
                for (p = 0; /* p < m->paramcount && */ p < INT_ARG_CNT; p++) {
-                       M_LST(r->argintregs[p], REG_SP,  (2 + p) * 8);
+                       M_LST(rd->argintregs[p], REG_SP,  (2 + p) * 8);
                }
 
                /* save and copy float arguments into integer registers */
@@ -366,23 +370,23 @@ void codegen(methodinfo *m)
 
                        if (IS_FLT_DBL_TYPE(t)) {
                                if (IS_2_WORD_TYPE(t)) {
-                                       M_DST(r->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                                       M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
 
                                } else {
-                                       M_FST(r->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                                       M_FST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
                                }
 
-                               M_LLD(r->argintregs[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(r->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                               M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
                        }
                }
 
-               p = dseg_addaddress(m, m);
+               p = dseg_addaddress(cd, m);
                M_ALD(REG_ITMP1, REG_PV, p);
                M_AST(REG_ITMP1, REG_SP, 0 * 8);
-               p = dseg_addaddress(m, (void *) builtin_trace_args);
+               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);
@@ -390,7 +394,7 @@ void codegen(methodinfo *m)
                M_ALD(REG_RA, REG_SP, 1 * 8);
 
                for (p = 0; /* p < mparamcount && */ p < INT_ARG_CNT; p++) {
-                       M_LLD(r->argintregs[p], REG_SP,  (2 + p) * 8);
+                       M_LLD(rd->argintregs[p], REG_SP,  (2 + p) * 8);
                }
 
                for (p = 0; /* p < mparamcount && */ p < FLT_ARG_CNT; p++) {
@@ -398,14 +402,14 @@ void codegen(methodinfo *m)
 
                        if (IS_FLT_DBL_TYPE(t)) {
                                if (IS_2_WORD_TYPE(t)) {
-                                       M_DLD(r->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                                       M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
 
                                } else {
-                                       M_FLD(r->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                                       M_FLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
                                }
 
                        } else {
-                               M_DLD(r->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                               M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
                        }
                }
 
@@ -416,7 +420,7 @@ void codegen(methodinfo *m)
 
        for (p = 0, l = 0; p < m->paramcount; p++) {
                t = m->paramtypes[p];
-               var = &(r->locals[l][t]);
+               var = &(rd->locals[l][t]);
                l++;
                if (IS_2_WORD_TYPE(t))    /* increment local counter for 2 word types */
                        l++;
@@ -425,9 +429,9 @@ void codegen(methodinfo *m)
                if (IS_INT_LNG_TYPE(t)) {                    /* integer args          */
                        if (p < INT_ARG_CNT) {                   /* register arguments    */
                                if (!(var->flags & INMEMORY)) {      /* reg arg -> register   */
-                                       M_INTMOVE(r->argintregs[p], var->regoff);
+                                       M_INTMOVE(rd->argintregs[p], var->regoff);
                                } else {                             /* reg arg -> spilled    */
-                                       M_LST(r->argintregs[p], REG_SP, 8 * var->regoff);
+                                       M_LST(rd->argintregs[p], REG_SP, 8 * var->regoff);
                                }
 
                        } else {                                 /* stack arguments       */
@@ -444,10 +448,10 @@ void codegen(methodinfo *m)
                } else {                                     /* floating args         */
                        if (p < FLT_ARG_CNT) {                   /* register arguments    */
                                if (!(var->flags & INMEMORY)) {      /* reg arg -> register   */
-                                       M_FLTMOVE(r->argfltregs[p], var->regoff);
+                                       M_FLTMOVE(rd->argfltregs[p], var->regoff);
 
                                } else {                                         /* reg arg -> spilled    */
-                                       M_DST(r->argfltregs[p], REG_SP, 8 * var->regoff);
+                                       M_DST(rd->argfltregs[p], REG_SP, 8 * var->regoff);
                                }
 
                        } else {                                 /* stack arguments       */
@@ -470,9 +474,9 @@ void codegen(methodinfo *m)
                s4 disp;
                s8 func_enter = (m->flags & ACC_STATIC) ?
                        (s8) builtin_staticmonitorenter : (s8) builtin_monitorenter;
-               p = dseg_addaddress(m, (void*) func_enter);
+               p = dseg_addaddress(cd, (void*) func_enter);
                M_ALD(REG_PV, REG_PV, p);
-               M_ALD(r->argintregs[0], REG_SP, r->maxmemuse * 8);
+               M_ALD(rd->argintregs[0], REG_SP, rd->maxmemuse * 8);
                M_JSR(REG_RA, REG_PV);
                disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
                M_LDA(REG_PV, REG_RA, disp);
@@ -504,34 +508,51 @@ void codegen(methodinfo *m)
                src = bptr->instack;
                len = bptr->indepth;
                MCODECHECK(64+len);
+#ifdef LSRA
+               if (opt_lsra) {
                while (src != NULL) {
                        len--;
                        if ((len == 0) && (bptr->type != BBTYPE_STD)) {
-                               d = reg_of_var(m, src, REG_ITMP1);
+                                       /*                              d = reg_of_var(m, src, REG_ITMP1); */
+                                       if (!(src->flags & INMEMORY))
+                                               d= src->regoff;
+                                       else
+                                               d=REG_ITMP1;
+                                       M_INTMOVE(REG_ITMP1, d);
+                                       store_reg_to_var_int(src, d);
+                               }
+                               src = src->prev;
+                       }
+               } else {
+#endif
+                       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(m, src, REG_IFTMP);
+                               d = reg_of_var(rd, src, REG_IFTMP);
                                if ((src->varkind != STACKVAR)) {
                                        s2 = src->type;
                                        if (IS_FLT_DBL_TYPE(s2)) {
-                                               if (!(r->interfaces[len][s2].flags & INMEMORY)) {
-                                                       s1 = r->interfaces[len][s2].regoff;
+                                               if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
+                                                       s1 = rd->interfaces[len][s2].regoff;
                                                        M_FLTMOVE(s1,d);
                                                        }
                                                else {
-                                                       M_DLD(d, REG_SP, 8 * r->interfaces[len][s2].regoff);
+                                                       M_DLD(d, REG_SP, 8 * rd->interfaces[len][s2].regoff);
                                                        }
                                                store_reg_to_var_flt(src, d);
                                                }
                                        else {
-                                               if (!(r->interfaces[len][s2].flags & INMEMORY)) {
-                                                       s1 = r->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, 8 * r->interfaces[len][s2].regoff);
+                                                       M_LLD(d, REG_SP, 8 * rd->interfaces[len][s2].regoff);
                                                        }
                                                store_reg_to_var_int(src, d);
                                                }
@@ -539,6 +560,9 @@ void codegen(methodinfo *m)
                                }
                        src = src->prev;
                        }
+#ifdef LSRA
+               }
+#endif
 
                /* walk through all instructions */
                
@@ -548,6 +572,11 @@ void codegen(methodinfo *m)
                    len > 0;
                    src = iptr->dst, len--, iptr++) {
 
+               if (iptr->line!=currentline) {
+                       dseg_addlinenumber(cd,iptr->line,mcodeptr);
+                       currentline=iptr->line;
+               }
+
        MCODECHECK(64);           /* an instruction usually needs < 64 words      */
        switch (iptr->opc) {
 
@@ -558,7 +587,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_BEQZ(s1, 0);
-                       codegen_addxnullrefs(m, mcodeptr);
+                       codegen_addxnullrefs(cd, mcodeptr);
                        break;
 
                /* constant operations ************************************************/
@@ -566,7 +595,7 @@ void codegen(methodinfo *m)
                case ICMD_ICONST:     /* ...  ==> ..., constant                       */
                                      /* op1 = 0, val.i = constant                    */
 
-                       d = reg_of_var(m, iptr->dst, REG_ITMP1);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP1);
                        ICONST(d, iptr->val.i);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -574,7 +603,7 @@ void codegen(methodinfo *m)
                case ICMD_LCONST:     /* ...  ==> ..., constant                       */
                                      /* op1 = 0, val.l = constant                    */
 
-                       d = reg_of_var(m, iptr->dst, REG_ITMP1);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP1);
                        LCONST(d, iptr->val.l);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -582,8 +611,8 @@ void codegen(methodinfo *m)
                case ICMD_FCONST:     /* ...  ==> ..., constant                       */
                                      /* op1 = 0, val.f = constant                    */
 
-                       d = reg_of_var(m, iptr->dst, REG_FTMP1);
-                       a = dseg_addfloat(m, iptr->val.f);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP1);
+                       a = dseg_addfloat(cd, iptr->val.f);
                        M_FLD(d, REG_PV, a);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
@@ -591,8 +620,8 @@ void codegen(methodinfo *m)
                case ICMD_DCONST:     /* ...  ==> ..., constant                       */
                                      /* op1 = 0, val.d = constant                    */
 
-                       d = reg_of_var(m, iptr->dst, REG_FTMP1);
-                       a = dseg_adddouble(m, iptr->val.d);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP1);
+                       a = dseg_adddouble(cd, iptr->val.d);
                        M_DLD(d, REG_PV, a);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
@@ -600,9 +629,9 @@ void codegen(methodinfo *m)
                case ICMD_ACONST:     /* ...  ==> ..., constant                       */
                                      /* op1 = 0, val.a = constant                    */
 
-                       d = reg_of_var(m, iptr->dst, REG_ITMP1);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP1);
                        if (iptr->val.a) {
-                               a = dseg_addaddress(m, iptr->val.a);
+                               a = dseg_addaddress(cd, iptr->val.a);
                                M_ALD(d, REG_PV, a);
                        } else {
                                M_INTMOVE(REG_ZERO, d);
@@ -617,11 +646,11 @@ void codegen(methodinfo *m)
                case ICMD_LLOAD:      /* op1 = local variable                         */
                case ICMD_ALOAD:
 
-                       d = reg_of_var(m, iptr->dst, REG_ITMP1);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP1);
                        if ((iptr->dst->varkind == LOCALVAR) &&
                            (iptr->dst->varnum == iptr->op1))
                                break;
-                       var = &(r->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
+                       var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
                        if (var->flags & INMEMORY)
                                M_LLD(d, REG_SP, 8 * var->regoff);
                        else
@@ -632,11 +661,11 @@ void codegen(methodinfo *m)
                case ICMD_FLOAD:      /* ...  ==> ..., content of local variable      */
                case ICMD_DLOAD:      /* op1 = local variable                         */
 
-                       d = reg_of_var(m, iptr->dst, REG_FTMP1);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP1);
                        if ((iptr->dst->varkind == LOCALVAR) &&
                            (iptr->dst->varnum == iptr->op1))
                                break;
-                       var = &(r->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
+                       var = &(rd->locals[iptr->op1][iptr->opc - ICMD_ILOAD]);
                        if (var->flags & INMEMORY)
                                M_DLD(d, REG_SP, 8 * var->regoff);
                        else
@@ -652,7 +681,7 @@ void codegen(methodinfo *m)
                        if ((src->varkind == LOCALVAR) &&
                            (src->varnum == iptr->op1))
                                break;
-                       var = &(r->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
+                       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);
@@ -669,7 +698,7 @@ void codegen(methodinfo *m)
                        if ((src->varkind == LOCALVAR) &&
                            (src->varnum == iptr->op1))
                                break;
-                       var = &(r->locals[iptr->op1][iptr->opc - ICMD_ISTORE]);
+                       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);
@@ -745,7 +774,7 @@ void codegen(methodinfo *m)
                case ICMD_INEG:       /* ..., value  ==> ..., - value                 */
 
                        var_to_reg_int(s1, src, REG_ITMP1); 
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_ISUB(REG_ZERO, s1, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -753,7 +782,7 @@ void codegen(methodinfo *m)
                case ICMD_LNEG:       /* ..., value  ==> ..., - value                 */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_LSUB(REG_ZERO, s1, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -761,7 +790,7 @@ void codegen(methodinfo *m)
                case ICMD_I2L:        /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_INTMOVE(s1, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -769,7 +798,7 @@ void codegen(methodinfo *m)
                case ICMD_L2I:        /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_IADD(s1, REG_ZERO, d );
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -777,7 +806,7 @@ void codegen(methodinfo *m)
                case ICMD_INT2BYTE:   /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (has_ext_instr_set) {
                                M_BSEXT(s1, d);
                                }
@@ -791,7 +820,7 @@ void codegen(methodinfo *m)
                case ICMD_INT2CHAR:   /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
             M_CZEXT(s1, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -799,7 +828,7 @@ void codegen(methodinfo *m)
                case ICMD_INT2SHORT:  /* ..., value  ==> ..., value                   */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (has_ext_instr_set) {
                                M_SSEXT(s1, d);
                                }
@@ -815,7 +844,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_IADD(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -824,7 +853,7 @@ void codegen(methodinfo *m)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_IADD_IMM(s1, iptr->val.i, d);
                                }
@@ -839,7 +868,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_LADD(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -848,7 +877,7 @@ void codegen(methodinfo *m)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_LADD_IMM(s1, iptr->val.l, d);
                                }
@@ -863,7 +892,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_ISUB(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -872,7 +901,7 @@ void codegen(methodinfo *m)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_ISUB_IMM(s1, iptr->val.i, d);
                                }
@@ -887,7 +916,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_LSUB(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -896,7 +925,7 @@ void codegen(methodinfo *m)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_LSUB_IMM(s1, iptr->val.l, d);
                                }
@@ -911,7 +940,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_IMUL(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -920,7 +949,7 @@ void codegen(methodinfo *m)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_IMUL_IMM(s1, iptr->val.i, d);
                                }
@@ -935,7 +964,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_LMUL (s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -944,7 +973,7 @@ void codegen(methodinfo *m)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_LMUL_IMM(s1, iptr->val.l, d);
                                }
@@ -959,7 +988,7 @@ void codegen(methodinfo *m)
                case ICMD_LDIVPOW2:   /* val.i = constant                             */
                                      
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (iptr->val.i <= 15) {
                                M_LDA(REG_ITMP2, s1, (1 << iptr->val.i) -1);
                                M_CMOVGE(s1, s1, REG_ITMP2);
@@ -977,7 +1006,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_AND_IMM(s2, 0x1f, REG_ITMP3);
                        M_SLL(s1, REG_ITMP3, d);
                        M_IADD(d, REG_ZERO, d);
@@ -988,7 +1017,7 @@ void codegen(methodinfo *m)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_SLL_IMM(s1, iptr->val.i & 0x1f, d);
                        M_IADD(d, REG_ZERO, d);
                        store_reg_to_var_int(iptr->dst, d);
@@ -998,7 +1027,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_AND_IMM(s2, 0x1f, REG_ITMP3);
                        M_SRA(s1, REG_ITMP3, d);
                        store_reg_to_var_int(iptr->dst, d);
@@ -1008,7 +1037,7 @@ void codegen(methodinfo *m)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_SRA_IMM(s1, iptr->val.i & 0x1f, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1017,7 +1046,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_AND_IMM(s2, 0x1f, REG_ITMP2);
             M_IZEXT(s1, d);
                        M_SRL(d, REG_ITMP2, d);
@@ -1029,7 +1058,7 @@ void codegen(methodinfo *m)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
             M_IZEXT(s1, d);
                        M_SRL_IMM(d, iptr->val.i & 0x1f, d);
                        M_IADD(d, REG_ZERO, d);
@@ -1040,7 +1069,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_SLL(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1049,7 +1078,7 @@ void codegen(methodinfo *m)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_SLL_IMM(s1, iptr->val.i & 0x3f, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1058,7 +1087,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_SRA(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1067,7 +1096,7 @@ void codegen(methodinfo *m)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_SRA_IMM(s1, iptr->val.i & 0x3f, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1076,7 +1105,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_SRL(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1085,7 +1114,7 @@ void codegen(methodinfo *m)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_SRL_IMM(s1, iptr->val.i & 0x3f, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1095,7 +1124,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_AND(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1104,7 +1133,7 @@ void codegen(methodinfo *m)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_AND_IMM(s1, iptr->val.i, d);
                                }
@@ -1125,7 +1154,7 @@ void codegen(methodinfo *m)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (s1 == d) {
                                M_MOV(s1, REG_ITMP1);
                                s1 = REG_ITMP1;
@@ -1163,7 +1192,7 @@ void codegen(methodinfo *m)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_AND_IMM(s1, iptr->val.l, d);
                                }
@@ -1196,7 +1225,7 @@ void codegen(methodinfo *m)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (s1 == d) {
                                M_MOV(s1, REG_ITMP1);
                                s1 = REG_ITMP1;
@@ -1259,7 +1288,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_OR( s1,s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1268,7 +1297,7 @@ void codegen(methodinfo *m)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_OR_IMM(s1, iptr->val.i, d);
                                }
@@ -1283,7 +1312,7 @@ void codegen(methodinfo *m)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_OR_IMM(s1, iptr->val.l, d);
                                }
@@ -1299,7 +1328,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_XOR(s1, s2, d);
                        store_reg_to_var_int(iptr->dst, d);
                        break;
@@ -1308,7 +1337,7 @@ void codegen(methodinfo *m)
                                      /* val.i = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if ((iptr->val.i >= 0) && (iptr->val.i <= 255)) {
                                M_XOR_IMM(s1, iptr->val.i, d);
                                }
@@ -1323,7 +1352,7 @@ void codegen(methodinfo *m)
                                      /* val.l = constant                             */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if ((iptr->val.l >= 0) && (iptr->val.l <= 255)) {
                                M_XOR_IMM(s1, iptr->val.l, d);
                                }
@@ -1339,7 +1368,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        M_CMPLT(s1, s2, REG_ITMP3);
                        M_CMPLT(s2, s1, REG_ITMP1);
                        M_LSUB (REG_ITMP1, REG_ITMP3, d);
@@ -1350,7 +1379,7 @@ void codegen(methodinfo *m)
                case ICMD_IINC:       /* ..., value  ==> ..., value + constant        */
                                      /* op1 = variable, val.i = constant             */
 
-                       var = &(r->locals[iptr->op1][TYPE_INT]);
+                       var = &(rd->locals[iptr->op1][TYPE_INT]);
                        if (var->flags & INMEMORY) {
                                s1 = REG_ITMP1;
                                M_LLD(s1, REG_SP, 8 * var->regoff);
@@ -1377,7 +1406,7 @@ void codegen(methodinfo *m)
                case ICMD_FNEG:       /* ..., value  ==> ..., - value                 */
 
                        var_to_reg_flt(s1, src, REG_FTMP1);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        M_FMOVN(s1, d);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
@@ -1385,7 +1414,7 @@ void codegen(methodinfo *m)
                case ICMD_DNEG:       /* ..., value  ==> ..., - value                 */
 
                        var_to_reg_flt(s1, src, REG_FTMP1);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        M_FMOVN(s1, d);
                        store_reg_to_var_flt(iptr->dst, d);
                        break;
@@ -1394,7 +1423,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_flt(s1, src->prev, REG_FTMP1);
                        var_to_reg_flt(s2, src, REG_FTMP2);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_FADD(s1, s2, d);
                                }
@@ -1416,7 +1445,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_flt(s1, src->prev, REG_FTMP1);
                        var_to_reg_flt(s2, src, REG_FTMP2);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_DADD(s1, s2, d);
                                }
@@ -1438,7 +1467,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_flt(s1, src->prev, REG_FTMP1);
                        var_to_reg_flt(s2, src, REG_FTMP2);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_FSUB(s1, s2, d);
                                }
@@ -1460,7 +1489,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_flt(s1, src->prev, REG_FTMP1);
                        var_to_reg_flt(s2, src, REG_FTMP2);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_DSUB(s1, s2, d);
                                }
@@ -1482,7 +1511,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_flt(s1, src->prev, REG_FTMP1);
                        var_to_reg_flt(s2, src, REG_FTMP2);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_FMUL(s1, s2, d);
                                }
@@ -1504,7 +1533,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_flt(s1, src->prev, REG_FTMP1);
                        var_to_reg_flt(s2, src, REG_FTMP2);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_DMUL(s1, s2, d);
                                }
@@ -1526,7 +1555,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_flt(s1, src->prev, REG_FTMP1);
                        var_to_reg_flt(s2, src, REG_FTMP2);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_FDIV(s1, s2, d);
                                }
@@ -1548,7 +1577,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_flt(s1, src->prev, REG_FTMP1);
                        var_to_reg_flt(s2, src, REG_FTMP2);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_DDIV(s1, s2, d);
                                }
@@ -1569,8 +1598,8 @@ void codegen(methodinfo *m)
                case ICMD_I2F:       /* ..., value  ==> ..., (float) value            */
                case ICMD_L2F:
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
-                       a = dseg_adddouble(m, 0.0);
+                       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);
                        M_CVTLF(d, d);
@@ -1580,8 +1609,8 @@ void codegen(methodinfo *m)
                case ICMD_I2D:       /* ..., value  ==> ..., (double) value           */
                case ICMD_L2D:
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
-                       a = dseg_adddouble(m, 0.0);
+                       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);
                        M_CVTLD(d, d);
@@ -1591,8 +1620,8 @@ void codegen(methodinfo *m)
                case ICMD_F2I:       /* ..., value  ==> ..., (int) value              */
                case ICMD_D2I:
                        var_to_reg_flt(s1, src, REG_FTMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
-                       a = dseg_adddouble(m, 0.0);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       a = dseg_adddouble(cd, 0.0);
                        M_CVTDL_C(s1, REG_FTMP2);
                        M_CVTLI(REG_FTMP2, REG_FTMP3);
                        M_DST (REG_FTMP3, REG_PV, a);
@@ -1603,8 +1632,8 @@ void codegen(methodinfo *m)
                case ICMD_F2L:       /* ..., value  ==> ..., (long) value             */
                case ICMD_D2L:
                        var_to_reg_flt(s1, src, REG_FTMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
-                       a = dseg_adddouble(m, 0.0);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
+                       a = dseg_adddouble(cd, 0.0);
                        M_CVTDL_C(s1, REG_FTMP2);
                        M_DST (REG_FTMP2, REG_PV, a);
                        M_LLD (d, REG_PV, a);
@@ -1614,7 +1643,7 @@ void codegen(methodinfo *m)
                case ICMD_F2D:       /* ..., value  ==> ..., (double) value           */
 
                        var_to_reg_flt(s1, src, REG_FTMP1);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        M_CVTFDS(s1, d);
                        M_TRAPB;
                        store_reg_to_var_flt(iptr->dst, d);
@@ -1623,7 +1652,7 @@ void codegen(methodinfo *m)
                case ICMD_D2F:       /* ..., value  ==> ..., (float) value            */
 
                        var_to_reg_flt(s1, src, REG_FTMP1);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (opt_noieee) {
                                M_CVTDF(s1, d);
                                }
@@ -1638,7 +1667,7 @@ void codegen(methodinfo *m)
                case ICMD_DCMPL:
                        var_to_reg_flt(s1, src->prev, REG_FTMP1);
                        var_to_reg_flt(s2, src, REG_FTMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (opt_noieee) {
                                M_LSUB_IMM(REG_ZERO, 1, d);
                                M_FCMPEQ(s1, s2, REG_FTMP3);
@@ -1666,7 +1695,7 @@ void codegen(methodinfo *m)
                case ICMD_DCMPG:
                        var_to_reg_flt(s1, src->prev, REG_FTMP1);
                        var_to_reg_flt(s2, src, REG_FTMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (opt_noieee) {
                                M_LADD_IMM(REG_ZERO, 1, d);
                                M_FCMPEQ(s1, s2, REG_FTMP3);
@@ -1696,7 +1725,7 @@ void codegen(methodinfo *m)
                case ICMD_ARRAYLENGTH: /* ..., arrayref  ==> ..., length              */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        gen_nullptr_check(s1);
                        M_ILD(d, s1, OFFSET(java_arrayheader, size));
                        store_reg_to_var_int(iptr->dst, d);
@@ -1706,7 +1735,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
@@ -1720,7 +1749,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
@@ -1734,7 +1763,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
@@ -1749,7 +1778,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
@@ -1763,7 +1792,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_FTMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_FTMP3);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
@@ -1777,7 +1806,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
@@ -1801,7 +1830,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
@@ -1827,7 +1856,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src->prev, REG_ITMP1);
                        var_to_reg_int(s2, src, REG_ITMP2);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (iptr->op1 == 0) {
                                gen_nullptr_check(s1);
                                gen_bound_check;
@@ -2104,30 +2133,20 @@ void codegen(methodinfo *m)
                case ICMD_PUTSTATIC:  /* ..., value  ==> ...                          */
                                      /* op1 = type, val.a = field address            */
 
-                       /* if class isn't yet initialized, do it */
+                       /* If the static fields' class is not yet initialized, we do it   */
+                       /* now. The call code is generated later.                         */
                        if (!((fieldinfo *) iptr->val.a)->class->initialized) {
-                               /* call helper function which patches this code */
-                               a = dseg_addaddress(m, ((fieldinfo *) iptr->val.a)->class);
-                               M_ALD(REG_ITMP1, REG_PV, a);
-                               a = dseg_addaddress(m, asm_check_clinit);
-                               M_ALD(REG_PV, REG_PV, a);
-                               M_JSR(REG_RA, REG_PV);
+                               codegen_addclinitref(cd, mcodeptr, ((fieldinfo *) iptr->val.a)->class);
 
-                               /* recompute pv */
-                               s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
-                               if (s1 <= 32768) {
-                                       M_LDA(REG_PV, REG_RA, -s1);
+                               /* This is just for debugging purposes. Is very difficult to  */
+                               /* read patched code. Here we patch the following 2 nop's     */
+                               /* so that the real code keeps untouched.                     */
+                               if (showdisassemble) {
                                        M_NOP;
-
-                               } 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);
                                }
                        }
                        
-                       a = dseg_addaddress(m, &(((fieldinfo *)(iptr->val.a))->value));
+                       a = dseg_addaddress(cd, &(((fieldinfo *)(iptr->val.a))->value));
                        M_ALD(REG_ITMP1, REG_PV, a);
                        switch (iptr->op1) {
                                case TYPE_INT:
@@ -2159,52 +2178,41 @@ void codegen(methodinfo *m)
 
                        /* if class isn't yet initialized, do it */
                        if (!((fieldinfo *) iptr->val.a)->class->initialized) {
-                               /* call helper function which patches this code */
-                               a = dseg_addaddress(m, ((fieldinfo *) iptr->val.a)->class);
-                               M_ALD(REG_ITMP1, REG_PV, a);
-                               a = dseg_addaddress(m, asm_check_clinit);
-                               M_ALD(REG_PV, REG_PV, a);
-                               M_JSR(REG_RA, REG_PV);
+                               codegen_addclinitref(cd, mcodeptr, ((fieldinfo *) iptr->val.a)->class);
 
-                               /* recompute pv */
-                               s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
-                               if (s1 <= 32768) {
-                                       M_LDA(REG_PV, REG_RA, -s1);
+                               /* This is just for debugging purposes. Is very difficult to  */
+                               /* read patched code. Here we patch the following 2 nop's     */
+                               /* so that the real code keeps untouched.                     */
+                               if (showdisassemble) {
                                        M_NOP;
-
-                               } 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);
                                }
                        }
                        
-                       a = dseg_addaddress(m, &(((fieldinfo *) iptr->val.a)->value));
+                       a = dseg_addaddress(cd, &(((fieldinfo *) iptr->val.a)->value));
                        M_ALD(REG_ITMP1, REG_PV, a);
                        switch (iptr->op1) {
                                case TYPE_INT:
-                                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                                        M_ILD(d, REG_ITMP1, 0);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
                                case TYPE_LNG:
-                                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                                        M_LLD(d, REG_ITMP1, 0);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
                                case TYPE_ADR:
-                                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                                        M_ALD(d, REG_ITMP1, 0);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
                                case TYPE_FLT:
-                                       d = reg_of_var(m, iptr->dst, REG_FTMP1);
+                                       d = reg_of_var(rd, iptr->dst, REG_FTMP1);
                                        M_FLD(d, REG_ITMP1, 0);
                                        store_reg_to_var_flt(iptr->dst, d);
                                        break;
                                case TYPE_DBL:                          
-                                       d = reg_of_var(m, iptr->dst, REG_FTMP1);
+                                       d = reg_of_var(rd, iptr->dst, REG_FTMP1);
                                        M_DLD(d, REG_ITMP1, 0);
                                        store_reg_to_var_flt(iptr->dst, d);
                                        break;
@@ -2259,35 +2267,35 @@ void codegen(methodinfo *m)
                        switch (iptr->op1) {
                                case TYPE_INT:
                                        var_to_reg_int(s1, src, REG_ITMP1);
-                                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                                        gen_nullptr_check(s1);
                                        M_ILD(d, s1, a);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
                                case TYPE_LNG:
                                        var_to_reg_int(s1, src, REG_ITMP1);
-                                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                                        gen_nullptr_check(s1);
                                        M_LLD(d, s1, a);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
                                case TYPE_ADR:
                                        var_to_reg_int(s1, src, REG_ITMP1);
-                                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                                        gen_nullptr_check(s1);
                                        M_ALD(d, s1, a);
                                        store_reg_to_var_int(iptr->dst, d);
                                        break;
                                case TYPE_FLT:
                                        var_to_reg_int(s1, src, REG_ITMP1);
-                                       d = reg_of_var(m, iptr->dst, REG_FTMP1);
+                                       d = reg_of_var(rd, iptr->dst, REG_FTMP1);
                                        gen_nullptr_check(s1);
                                        M_FLD(d, s1, a);
                                        store_reg_to_var_flt(iptr->dst, d);
                                        break;
                                case TYPE_DBL:                          
                                        var_to_reg_int(s1, src, REG_ITMP1);
-                                       d = reg_of_var(m, iptr->dst, REG_FTMP1);
+                                       d = reg_of_var(rd, iptr->dst, REG_FTMP1);
                                        gen_nullptr_check(s1);
                                        M_DLD(d, s1, a);
                                        store_reg_to_var_flt(iptr->dst, d);
@@ -2305,7 +2313,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_INTMOVE(s1, REG_ITMP1_XPTR);
-                       a = dseg_addaddress(m, asm_handle_exception);
+                       a = dseg_addaddress(cd, asm_handle_exception);
                        M_ALD(REG_ITMP2, REG_PV, a);
                        M_JMP(REG_ITMP2_XPC, REG_ITMP2);
                        M_NOP;              /* nop ensures that XPC is less than the end */
@@ -2316,7 +2324,7 @@ void codegen(methodinfo *m)
                case ICMD_GOTO:         /* ... ==> ...                                */
                                        /* op1 = target JavaVM pc                     */
                        M_BR(0);
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        ALIGNCODENOP;
                        break;
 
@@ -2324,13 +2332,13 @@ void codegen(methodinfo *m)
                                        /* op1 = target JavaVM pc                     */
 
                        M_BSR(REG_ITMP1, 0);
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
                        
                case ICMD_RET:          /* ... ==> ...                                */
                                        /* op1 = local variable                       */
 
-                       var = &(r->locals[iptr->op1][TYPE_ADR]);
+                       var = &(rd->locals[iptr->op1][TYPE_ADR]);
                        if (var->flags & INMEMORY) {
                                M_ALD(REG_ITMP1, REG_SP, 8 * var->regoff);
                                M_RET(REG_ZERO, REG_ITMP1);
@@ -2345,7 +2353,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_BEQZ(s1, 0);
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFNONNULL:    /* ..., value ==> ...                         */
@@ -2353,7 +2361,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_BNEZ(s1, 0);
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFEQ:         /* ..., value ==> ...                         */
@@ -2373,7 +2381,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFLT:         /* ..., value ==> ...                         */
@@ -2393,7 +2401,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFLE:         /* ..., value ==> ...                         */
@@ -2413,7 +2421,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFNE:         /* ..., value ==> ...                         */
@@ -2433,7 +2441,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFGT:         /* ..., value ==> ...                         */
@@ -2453,7 +2461,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFGE:         /* ..., value ==> ...                         */
@@ -2473,7 +2481,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_LEQ:       /* ..., value ==> ...                         */
@@ -2493,7 +2501,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_LLT:       /* ..., value ==> ...                         */
@@ -2513,7 +2521,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_LLE:       /* ..., value ==> ...                         */
@@ -2533,7 +2541,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_LNE:       /* ..., value ==> ...                         */
@@ -2553,7 +2561,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_LGT:       /* ..., value ==> ...                         */
@@ -2573,7 +2581,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_LGE:       /* ..., value ==> ...                         */
@@ -2593,7 +2601,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_ICMPEQ:    /* ..., value, value ==> ...                  */
@@ -2604,7 +2612,7 @@ void codegen(methodinfo *m)
                        var_to_reg_int(s2, src, REG_ITMP2);
                        M_CMPEQ(s1, s2, REG_ITMP1);
                        M_BNEZ(REG_ITMP1, 0);
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_ICMPNE:    /* ..., value, value ==> ...                  */
@@ -2615,7 +2623,7 @@ void codegen(methodinfo *m)
                        var_to_reg_int(s2, src, REG_ITMP2);
                        M_CMPEQ(s1, s2, REG_ITMP1);
                        M_BEQZ(REG_ITMP1, 0);
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_ICMPLT:    /* ..., value, value ==> ...                  */
@@ -2625,7 +2633,7 @@ void codegen(methodinfo *m)
                        var_to_reg_int(s2, src, REG_ITMP2);
                        M_CMPLT(s1, s2, REG_ITMP1);
                        M_BNEZ(REG_ITMP1, 0);
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_ICMPGT:    /* ..., value, value ==> ...                  */
@@ -2635,7 +2643,7 @@ void codegen(methodinfo *m)
                        var_to_reg_int(s2, src, REG_ITMP2);
                        M_CMPLE(s1, s2, REG_ITMP1);
                        M_BEQZ(REG_ITMP1, 0);
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_ICMPLE:    /* ..., value, value ==> ...                  */
@@ -2645,7 +2653,7 @@ void codegen(methodinfo *m)
                        var_to_reg_int(s2, src, REG_ITMP2);
                        M_CMPLE(s1, s2, REG_ITMP1);
                        M_BNEZ(REG_ITMP1, 0);
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_ICMPGE:    /* ..., value, value ==> ...                  */
@@ -2655,7 +2663,7 @@ void codegen(methodinfo *m)
                        var_to_reg_int(s2, src, REG_ITMP2);
                        M_CMPLT(s1, s2, REG_ITMP1);
                        M_BEQZ(REG_ITMP1, 0);
-                       codegen_addreference(m, BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                /* (value xx 0) ? IFxx_ICONST : ELSE_ICONST                           */
@@ -2667,7 +2675,7 @@ void codegen(methodinfo *m)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        s3 = iptr->val.i;
                        if (iptr[1].opc == ICMD_ELSE_ICONST) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
@@ -2701,7 +2709,7 @@ void codegen(methodinfo *m)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        s3 = iptr->val.i;
                        if (iptr[1].opc == ICMD_ELSE_ICONST) {
                                if ((s3 == 0) && (iptr[1].val.i == 1)) {
@@ -2735,7 +2743,7 @@ void codegen(methodinfo *m)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
@@ -2768,7 +2776,7 @@ void codegen(methodinfo *m)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
@@ -2801,7 +2809,7 @@ void codegen(methodinfo *m)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
@@ -2834,7 +2842,7 @@ void codegen(methodinfo *m)
                                        /* val.i = constant                           */
 
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        s3 = iptr->val.i;
                        if ((iptr[1].opc == ICMD_ELSE_ICONST)) {
                                if ((s3 == 1) && (iptr[1].val.i == 0)) {
@@ -2874,14 +2882,14 @@ void codegen(methodinfo *m)
 #if defined(USE_THREADS)
                        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
                                s4 disp;
-                               a = dseg_addaddress(m, (void *) (builtin_monitorexit));
+                               a = dseg_addaddress(cd, (void *) (builtin_monitorexit));
                                M_ALD(REG_PV, REG_PV, a);
-                               M_ALD(r->argintregs[0], REG_SP, r->maxmemuse * 8);
-                               M_LST(REG_RESULT, REG_SP, r->maxmemuse * 8);
+                               M_ALD(rd->argintregs[0], REG_SP, rd->maxmemuse * 8);
+                               M_LST(REG_RESULT, REG_SP, rd->maxmemuse * 8);
                                M_JSR(REG_RA, REG_PV);
                                disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
                                M_LDA(REG_PV, REG_RA, disp);
-                               M_LLD(REG_RESULT, REG_SP, r->maxmemuse * 8);
+                               M_LLD(REG_RESULT, REG_SP, rd->maxmemuse * 8);
                        }
 #endif
 
@@ -2896,14 +2904,14 @@ void codegen(methodinfo *m)
 #if defined(USE_THREADS)
                        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
                                s4 disp;
-                               a = dseg_addaddress(m, (void *) (builtin_monitorexit));
+                               a = dseg_addaddress(cd, (void *) (builtin_monitorexit));
                                M_ALD(REG_PV, REG_PV, a);
-                               M_ALD(r->argintregs[0], REG_SP, r->maxmemuse * 8);
-                               M_DST(REG_FRESULT, REG_SP, r->maxmemuse * 8);
+                               M_ALD(rd->argintregs[0], REG_SP, rd->maxmemuse * 8);
+                               M_DST(REG_FRESULT, REG_SP, rd->maxmemuse * 8);
                                M_JSR(REG_RA, REG_PV);
                                disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
                                M_LDA(REG_PV, REG_RA, disp);
-                               M_DLD(REG_FRESULT, REG_SP, r->maxmemuse * 8);
+                               M_DLD(REG_FRESULT, REG_SP, rd->maxmemuse * 8);
                        }
 #endif
 
@@ -2914,9 +2922,9 @@ void codegen(methodinfo *m)
 #if defined(USE_THREADS)
                        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
                                s4 disp;
-                               a = dseg_addaddress(m, (void *) (builtin_monitorexit));
+                               a = dseg_addaddress(cd, (void *) (builtin_monitorexit));
                                M_ALD(REG_PV, REG_PV, a);
-                               M_ALD(r->argintregs[0], REG_SP, r->maxmemuse * 8);
+                               M_ALD(rd->argintregs[0], REG_SP, rd->maxmemuse * 8);
                                M_JSR(REG_RA, REG_PV);
                                disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
                                M_LDA(REG_PV, REG_RA, disp);
@@ -2937,11 +2945,11 @@ nowperformreturn:
 
                        /* restore saved registers                                        */
 
-                       for (i = r->savintregcnt - 1; i >= r->maxsavintreguse; i--) {
-                               p--; M_LLD(r->savintregs[i], REG_SP, p * 8);
+                       for (i = rd->savintregcnt - 1; i >= rd->maxsavintreguse; i--) {
+                               p--; M_LLD(rd->savintregs[i], REG_SP, p * 8);
                        }
-                       for (i = r->savfltregcnt - 1; i >= r->maxsavfltreguse; i--) {
-                               p--; M_DLD(r->savfltregs[i], REG_SP, p * 8);
+                       for (i = rd->savfltregcnt - 1; i >= rd->maxsavfltreguse; i--) {
+                               p--; M_DLD(rd->savfltregs[i], REG_SP, p * 8);
                        }
 
                        /* deallocate stack                                               */
@@ -2957,12 +2965,12 @@ nowperformreturn:
                                M_AST(REG_RA, REG_SP, 0 * 8);
                                M_LST(REG_RESULT, REG_SP, 1 * 8);
                                M_DST(REG_FRESULT, REG_SP, 2 * 8);
-                               a = dseg_addaddress(m, m);
-                               M_ALD(r->argintregs[0], REG_PV, a);
-                               M_MOV(REG_RESULT, r->argintregs[1]);
-                               M_FLTMOVE(REG_FRESULT, r->argfltregs[2]);
-                               M_FLTMOVE(REG_FRESULT, r->argfltregs[3]);
-                               a = dseg_addaddress(m, (void *) builtin_displaymethodstop);
+                               a = dseg_addaddress(cd, m);
+                               M_ALD(rd->argintregs[0], REG_PV, a);
+                               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);
                                M_JSR(REG_RA, REG_PV);
                                s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
@@ -3019,8 +3027,8 @@ nowperformreturn:
                        M_BEQZ(REG_ITMP2, 0);
 
 
-                       /* codegen_addreference(m, BlockPtrOfPC(s4ptr[0]), mcodeptr); */
-                       codegen_addreference(m, (basicblock *) tptr[0], mcodeptr);
+                       /* 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 */
 
@@ -3028,8 +3036,8 @@ nowperformreturn:
                        tptr += i;
 
                        while (--i >= 0) {
-                               /* dseg_addtarget(m, BlockPtrOfPC(*--s4ptr)); */
-                               dseg_addtarget(m, (basicblock *) tptr[0]); 
+                               /* dseg_addtarget(cd, BlockPtrOfPC(*--s4ptr)); */
+                               dseg_addtarget(cd, (basicblock *) tptr[0]); 
                                --tptr;
                                }
                        }
@@ -3069,21 +3077,21 @@ nowperformreturn:
                                                M_LDA(REG_ITMP2, REG_ZERO, val);
                                                } 
                                        else {
-                                               a = dseg_adds4(m, val);
+                                               a = dseg_adds4(cd, val);
                                                M_ILD(REG_ITMP2, REG_PV, a);
                                                }
                                        M_CMPEQ(s1, REG_ITMP2, REG_ITMP2);
                                        }
                                M_BNEZ(REG_ITMP2, 0);
-                               /* codegen_addreference(m, BlockPtrOfPC(s4ptr[1]), mcodeptr); */
-                               codegen_addreference(m, (basicblock *) tptr[0], mcodeptr); 
+                               /* codegen_addreference(cd, BlockPtrOfPC(s4ptr[1]), mcodeptr); */
+                               codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr); 
                                }
 
                        M_BR(0);
-                       /* codegen_addreference(m, BlockPtrOfPC(l), mcodeptr); */
+                       /* codegen_addreference(cd, BlockPtrOfPC(l), mcodeptr); */
                        
                        tptr = (void **) iptr->target;
-                       codegen_addreference(m, (basicblock *) tptr[0], mcodeptr);
+                       codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
 
                        ALIGNCODENOP;
                        break;
@@ -3131,7 +3139,7 @@ gen_method: {
                                        continue;
                                if (IS_INT_LNG_TYPE(src->type)) {
                                        if (s3 < INT_ARG_CNT) {
-                                               s1 = r->argintregs[s3];
+                                               s1 = rd->argintregs[s3];
                                                var_to_reg_int(d, src, s1);
                                                M_INTMOVE(d, s1);
 
@@ -3142,7 +3150,7 @@ gen_method: {
 
                                } else {
                                        if (s3 < FLT_ARG_CNT) {
-                                               s1 = r->argfltregs[s3];
+                                               s1 = rd->argfltregs[s3];
                                                var_to_reg_flt(d, src, s1);
                                                M_FLTMOVE(d, s1);
 
@@ -3158,7 +3166,7 @@ gen_method: {
                        case ICMD_BUILTIN3:
                        case ICMD_BUILTIN2:
                        case ICMD_BUILTIN1:
-                               a = dseg_addaddress(m, (void *) lm);
+                               a = dseg_addaddress(cd, (void *) lm);
                                d = iptr->op1;
 
                                M_ALD(REG_PV, REG_PV, a);     /* Pointer to built-in-function */
@@ -3166,7 +3174,7 @@ gen_method: {
 
                        case ICMD_INVOKESTATIC:
                        case ICMD_INVOKESPECIAL:
-                               a = dseg_addaddress(m, lm->stubroutine);
+                               a = dseg_addaddress(cd, lm->stubroutine);
                                d = lm->returntype;
 
                                M_ALD(REG_PV, REG_PV, a);            /* method pointer in r27 */
@@ -3175,8 +3183,8 @@ gen_method: {
                        case ICMD_INVOKEVIRTUAL:
                                d = lm->returntype;
 
-                               gen_nullptr_check(r->argintregs[0]);
-                               M_ALD(REG_METHODPTR, r->argintregs[0],
+                               gen_nullptr_check(rd->argintregs[0]);
+                               M_ALD(REG_METHODPTR, rd->argintregs[0],
                                          OFFSET(java_objectheader, vftbl));
                                M_ALD(REG_PV, REG_METHODPTR, OFFSET(vftbl_t, table[0]) +
                                          sizeof(methodptr) * lm->vftblindex);
@@ -3185,8 +3193,8 @@ gen_method: {
                        case ICMD_INVOKEINTERFACE:
                                d = lm->returntype;
                                        
-                               gen_nullptr_check(r->argintregs[0]);
-                               M_ALD(REG_METHODPTR, r->argintregs[0],
+                               gen_nullptr_check(rd->argintregs[0]);
+                               M_ALD(REG_METHODPTR, rd->argintregs[0],
                                          OFFSET(java_objectheader, vftbl));    
                                M_ALD(REG_METHODPTR, REG_METHODPTR,
                                          OFFSET(vftbl_t, interfacetable[0]) -
@@ -3213,12 +3221,12 @@ gen_method: {
 
                        if (d != TYPE_VOID) {
                                if (IS_INT_LNG_TYPE(iptr->dst->type)) {
-                                       s1 = reg_of_var(m, iptr->dst, REG_RESULT);
+                                       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(m, iptr->dst, REG_FRESULT);
+                                       s1 = reg_of_var(rd, iptr->dst, REG_FRESULT);
                                        M_FLTMOVE(REG_FRESULT, s1);
                                        store_reg_to_var_flt(iptr->dst, s1);
                                }
@@ -3249,10 +3257,10 @@ gen_method: {
                        classinfo *super = (classinfo*) iptr->val.a;
                        
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                       codegen_threadcritrestart(m, (u1 *) mcodeptr - cd->mcodebase);
+                       codegen_threadcritrestart(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
                        var_to_reg_int(s1, src, REG_ITMP1);
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        if (s1 == d) {
                                M_MOV(s1, REG_ITMP1);
                                s1 = REG_ITMP1;
@@ -3286,16 +3294,16 @@ gen_method: {
 */
                                        M_BEQZ(s1, 7);
                                        M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
-                                       a = dseg_addaddress(m, (void*) super->vftbl);
+                                       a = dseg_addaddress(cd, (void*) super->vftbl);
                                        M_ALD(REG_ITMP2, REG_PV, a);
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                                       codegen_threadcritstart(m, (u1 *) mcodeptr - cd->mcodebase);
+                                       codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
                                        M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
                                        M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
                                        M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                                       codegen_threadcritstop(m, (u1 *) mcodeptr - cd->mcodebase);
+                                       codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
                                        M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
                                        M_CMPULE(REG_ITMP1, REG_ITMP2, d);
@@ -3329,9 +3337,9 @@ gen_method: {
                        classinfo *super = (classinfo *) iptr->val.a;
                        
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                       codegen_threadcritrestart(m, (u1 *) mcodeptr - cd->mcodebase);
+                       codegen_threadcritrestart(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
-                       d = reg_of_var(m, iptr->dst, REG_ITMP3);
+                       d = reg_of_var(rd, iptr->dst, REG_ITMP3);
                        var_to_reg_int(s1, src, d);
                        if (iptr->op1) {                               /* class/interface */
                                if (super->flags & ACC_INTERFACE) {        /* interface       */
@@ -3340,12 +3348,12 @@ gen_method: {
                                        M_ILD(REG_ITMP2, REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
                                        M_LDA(REG_ITMP2, REG_ITMP2, - super->index);
                                        M_BLEZ(REG_ITMP2, 0);
-                                       codegen_addxcastrefs(m, mcodeptr);
+                                       codegen_addxcastrefs(cd, mcodeptr);
                                        M_ALD(REG_ITMP2, REG_ITMP1,
                                              OFFSET(vftbl_t, interfacetable[0]) -
                                              super->index * sizeof(methodptr*));
                                        M_BEQZ(REG_ITMP2, 0);
-                                       codegen_addxcastrefs(m, mcodeptr);
+                                       codegen_addxcastrefs(cd, mcodeptr);
                                        }
                                else {                                     /* class           */
 /*
@@ -3369,17 +3377,17 @@ gen_method: {
 */
                                        M_BEQZ(s1, 8 + (d == REG_ITMP3));
                                        M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
-                                       a = dseg_addaddress(m, (void *) super->vftbl);
+                                       a = dseg_addaddress(cd, (void *) super->vftbl);
                                        M_ALD(REG_ITMP2, REG_PV, a);
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                                       codegen_threadcritstart(m, (u1 *) mcodeptr - cd->mcodebase);
+                                       codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
                                        M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
                                        if (d != REG_ITMP3) {
                                                M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl_t, baseval));
                                                M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                                               codegen_threadcritstop(m, (u1 *) mcodeptr - cd->mcodebase);
+                                               codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
                                                M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
                                                }
@@ -3389,12 +3397,12 @@ gen_method: {
                                                M_ALD(REG_ITMP2, REG_PV, a);
                                                M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                                               codegen_threadcritstop(m, (u1 *) mcodeptr - cd->mcodebase);
+                                               codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
                                                }
                                        M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2);
                                        M_BEQZ(REG_ITMP2, 0);
-                                       codegen_addxcastrefs(m, mcodeptr);
+                                       codegen_addxcastrefs(cd, mcodeptr);
                                        }
                                }
                        else
@@ -3408,13 +3416,13 @@ gen_method: {
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_BLTZ(s1, 0);
-                       codegen_addxcheckarefs(m, mcodeptr);
+                       codegen_addxcheckarefs(cd, mcodeptr);
                        break;
 
                case ICMD_CHECKEXCEPTION:    /* ... ==> ...                           */
 
                        M_BEQZ(REG_RESULT, 0);
-                       codegen_addxexceptionrefs(m, mcodeptr);
+                       codegen_addxexceptionrefs(cd, mcodeptr);
                        break;
 
                case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref  */
@@ -3427,7 +3435,7 @@ gen_method: {
                        for (s1 = iptr->op1; --s1 >= 0; src = src->prev) {
                                var_to_reg_int(s2, src, REG_ITMP1);
                                M_BLTZ(s2, 0);
-                               codegen_addxcheckarefs(m, mcodeptr);
+                               codegen_addxcheckarefs(cd, mcodeptr);
 
                                /* copy sizes to stack (argument numbers >= INT_ARG_CNT)      */
 
@@ -3438,18 +3446,18 @@ gen_method: {
 
                        /* a0 = dimension count */
 
-                       ICONST(r->argintregs[0], iptr->op1);
+                       ICONST(rd->argintregs[0], iptr->op1);
 
                        /* a1 = arraydescriptor */
 
-                       a = dseg_addaddress(m, iptr->val.a);
-                       M_ALD(r->argintregs[1], REG_PV, a);
+                       a = dseg_addaddress(cd, iptr->val.a);
+                       M_ALD(rd->argintregs[1], REG_PV, a);
 
                        /* a2 = pointer to dimensions = stack pointer */
 
-                       M_INTMOVE(REG_SP, r->argintregs[2]);
+                       M_INTMOVE(REG_SP, rd->argintregs[2]);
 
-                       a = dseg_addaddress(m, (void *) builtin_nmultianewarray);
+                       a = dseg_addaddress(cd, (void *) builtin_nmultianewarray);
                        M_ALD(REG_PV, REG_PV, a);
                        M_JSR(REG_RA, REG_PV);
                        s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
@@ -3461,11 +3469,14 @@ gen_method: {
                                M_LDA(REG_PV, REG_RA, ml);
                                M_LDAH(REG_PV, REG_PV, mh);
                        }
-                       s1 = reg_of_var(m, iptr->dst, REG_RESULT);
+                       s1 = reg_of_var(rd, iptr->dst, REG_RESULT);
                        M_INTMOVE(REG_RESULT, s1);
                        store_reg_to_var_int(iptr->dst, s1);
                        break;
 
+                case ICMD_INLINE_START:
+                case ICMD_INLINE_END:
+                        break;
 
                default: error ("Unknown pseudo command: %d", iptr->opc);
        
@@ -3480,26 +3491,29 @@ gen_method: {
        src = bptr->outstack;
        len = bptr->outdepth;
        MCODECHECK(64+len);
+#ifdef LSRA
+       if (!opt_lsra) 
+#endif
        while (src) {
                len--;
                if ((src->varkind != STACKVAR)) {
                        s2 = src->type;
                        if (IS_FLT_DBL_TYPE(s2)) {
                                var_to_reg_flt(s1, src, REG_FTMP1);
-                               if (!(r->interfaces[len][s2].flags & INMEMORY)) {
-                                       M_FLTMOVE(s1,r->interfaces[len][s2].regoff);
+                               if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
+                                       M_FLTMOVE(s1,rd->interfaces[len][s2].regoff);
                                        }
                                else {
-                                       M_DST(s1, REG_SP, 8 * r->interfaces[len][s2].regoff);
+                                       M_DST(s1, REG_SP, 8 * rd->interfaces[len][s2].regoff);
                                        }
                                }
                        else {
                                var_to_reg_int(s1, src, REG_ITMP1);
-                               if (!(r->interfaces[len][s2].flags & INMEMORY)) {
-                                       M_INTMOVE(s1,r->interfaces[len][s2].regoff);
+                               if (!(rd->interfaces[len][s2].flags & INMEMORY)) {
+                                       M_INTMOVE(s1,rd->interfaces[len][s2].regoff);
                                        }
                                else {
-                                       M_LST(s1, REG_SP, 8 * r->interfaces[len][s2].regoff);
+                                       M_LST(s1, REG_SP, 8 * rd->interfaces[len][s2].regoff);
                                        }
                                }
                        }
@@ -3508,6 +3522,8 @@ gen_method: {
        } /* if (bptr -> flags >= BBREACHED) */
        } /* for basic block */
 
+       codegen_createlinenumbertable(cd);
+
        {
        /* generate bound check stubs */
 
@@ -3531,36 +3547,20 @@ gen_method: {
                } else {
                        xcodeptr = mcodeptr;
 
-                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
-                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
-
-                       a = dseg_addaddress(m, string_java_lang_ArrayIndexOutOfBoundsException);
-                       M_ALD(r->argintregs[0], REG_PV, a);
-                       M_MOV(REG_ITMP1, r->argintregs[1]);
+                        a = dseg_addaddress(cd, asm_throw_and_handle_arrayindexoutofbounds_exception);
+                        M_ALD(REG_PV, REG_PV, a);
 
-                       a = dseg_addaddress(m, new_exception_int);
-                       M_ALD(REG_PV, REG_PV, a);
-                       M_JSR(REG_RA, REG_PV);
+                        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_RESULT, REG_ITMP1_XPTR);
-
-                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
-                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
-
-                       a = dseg_addaddress(m, asm_handle_exception);
-                       M_ALD(REG_ITMP3, REG_PV, a);
-
-                       M_JMP(REG_ZERO, REG_ITMP3);
+                        /* 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);
+                        }
                }
        }
 
@@ -3569,7 +3569,7 @@ gen_method: {
        xcodeptr = NULL;
        
        for (bref = cd->xcheckarefs; bref != NULL; bref = bref->next) {
-               if ((m->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
                        gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
                                                          bref->branchpos,
                                                          (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
@@ -3590,16 +3590,15 @@ gen_method: {
                } else {
                        xcodeptr = mcodeptr;
 
-                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
-                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
-
-                       a = dseg_addaddress(m, string_java_lang_NegativeArraySizeException);
-                       M_ALD(r->argintregs[0], REG_PV, a);
+                       
+                       a = dseg_addaddress(cd, string_java_lang_NegativeArraySizeException);
+                       M_ALD(REG_ITMP1_XPTR,REG_PV,a);
 
-                       a = dseg_addaddress(m, new_exception);
+                       a = dseg_addaddress(cd, asm_throw_and_handle_nat_exception);
                        M_ALD(REG_PV, REG_PV, a);
-                       M_JSR(REG_RA, REG_PV);
 
+                       M_JSR(REG_RA, REG_PV);
+               
                        /* recompute pv */
                        s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
                        if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
@@ -3610,15 +3609,7 @@ gen_method: {
                                M_LDAH(REG_PV, REG_PV, mh);
                        }
 
-                       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
 
-                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
-                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
-
-                       a = dseg_addaddress(m, asm_handle_exception);
-                       M_ALD(REG_ITMP3, REG_PV, a);
-
-                       M_JMP(REG_ZERO, REG_ITMP3);
                }
        }
 
@@ -3627,7 +3618,7 @@ gen_method: {
        xcodeptr = NULL;
        
        for (bref = cd->xcastrefs; bref != NULL; bref = bref->next) {
-               if ((m->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
                        gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
                                                          bref->branchpos,
                                                          (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
@@ -3648,35 +3639,24 @@ gen_method: {
                } else {
                        xcodeptr = mcodeptr;
 
-                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
-                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       a = dseg_addaddress(cd, string_java_lang_ClassCastException);
+                        M_ALD(REG_ITMP1_XPTR,REG_PV,a);
 
-                       a = dseg_addaddress(m, string_java_lang_ClassCastException);
-                       M_ALD(r->argintregs[0], REG_PV, a);
+                        a = dseg_addaddress(cd, asm_throw_and_handle_nat_exception);
+                        M_ALD(REG_PV, REG_PV, a);
 
-                       a = dseg_addaddress(m, new_exception);
-                       M_ALD(REG_PV, REG_PV, a);
-                       M_JSR(REG_RA, REG_PV);
+                        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);
-                       }
+                        /* recompute pv */
+                        s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                        if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
+                        else {
+                                s4 ml = -s1, mh = 0;
+                                while (ml < -32768) { ml += 65536; mh--; }
+                                M_LDA(REG_PV, REG_RA, ml);
+                                M_LDAH(REG_PV, REG_PV, mh);
+                        }
 
-                       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
-
-                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
-                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
-
-                       a = dseg_addaddress(m, asm_handle_exception);
-                       M_ALD(REG_ITMP3, REG_PV, a);
-
-                       M_JMP(REG_ZERO, REG_ITMP3);
                }
        }
 
@@ -3685,7 +3665,7 @@ gen_method: {
        xcodeptr = NULL;
 
        for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) {
-               if ((m->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
                        gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
                                                          bref->branchpos,
                                                          (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
@@ -3710,7 +3690,7 @@ gen_method: {
                        M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
                        M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
 
-                       a = dseg_addaddress(m, &builtin_get_exceptionptrptr);
+                       a = dseg_addaddress(cd, &builtin_get_exceptionptrptr);
                        M_ALD(REG_PV, REG_PV, a);
                        M_JSR(REG_RA, REG_PV);
 
@@ -3730,16 +3710,27 @@ gen_method: {
                        M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
                        M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
 #else
-                       a = dseg_addaddress(m, &_exceptionptr);
+                       a = dseg_addaddress(cd, &_exceptionptr);
                        M_ALD(REG_ITMP3, REG_PV, a);
                        M_ALD(REG_ITMP1_XPTR, REG_ITMP3, 0);
                        M_AST(REG_ZERO, REG_ITMP3, 0);
 #endif
 
-                       a = dseg_addaddress(m, asm_handle_exception);
-                       M_ALD(REG_ITMP3, REG_PV, a);
+                       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);
+                       }
 
-                       M_JMP(REG_ZERO, REG_ITMP3);
                }
        }
 
@@ -3748,7 +3739,7 @@ gen_method: {
        xcodeptr = NULL;
 
        for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) {
-               if ((m->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
                        gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
                                                          bref->branchpos,
                                                          (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
@@ -3769,40 +3760,70 @@ gen_method: {
                } else {
                        xcodeptr = mcodeptr;
 
-                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
-                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
+                       a = dseg_addaddress(cd, string_java_lang_NullPointerException);
+                        M_ALD(REG_ITMP1_XPTR,REG_PV,a);
 
-                       a = dseg_addaddress(m, string_java_lang_NullPointerException);
-                       M_ALD(r->argintregs[0], REG_PV, a);
+                        a = dseg_addaddress(cd, asm_throw_and_handle_nat_exception);
+                        M_ALD(REG_PV, REG_PV, a);
 
-                       a = dseg_addaddress(m, new_exception);
-                       M_ALD(REG_PV, REG_PV, a);
-                       M_JSR(REG_RA, REG_PV);
+                        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);
-                       }
+                        /* recompute pv */
+                        s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
+                        if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
+                        else {
+                                s4 ml = -s1, mh = 0;
+                                while (ml < -32768) { ml += 65536; mh--; }
+                                M_LDA(REG_PV, REG_RA, ml);
+                                M_LDAH(REG_PV, REG_PV, mh);
+                        }
 
-                       M_MOV(REG_RESULT, REG_ITMP1_XPTR);
+               }
+       }
 
-                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
-                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
+       /* generate put/getstatic stub call code */
 
-                       a = dseg_addaddress(m, asm_handle_exception);
-                       M_ALD(REG_ITMP3, REG_PV, a);
+       {
+               clinitref   *cref;
+               u4           mcode;
+               s4          *tmpmcodeptr;
+
+               for (cref = cd->clinitrefs; cref != NULL; cref = cref->next) {
+                       /* Get machine code which is patched back in later. The call is   */
+                       /* 1 instruction word long.                                       */
+                       xcodeptr = (s4 *) (cd->mcodebase + cref->branchpos);
+                       mcode = *xcodeptr;
+
+                       /* 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 */
 
-                       M_JMP(REG_ZERO, REG_ITMP3);
+                       M_BSR(REG_RA, tmpmcodeptr - (xcodeptr + 1));
+
+                       mcodeptr = tmpmcodeptr;         /* restore the current mcodeptr   */
+
+                       MCODECHECK(6);
+
+                       /* move class pointer into REG_ITMP2                              */
+                       a = dseg_addaddress(cd, cref->class);
+                       M_ALD(REG_ITMP1, REG_PV, a);
+
+                       /* move machine code onto stack                                   */
+                       a = dseg_adds4(cd, mcode);
+                       M_ILD(REG_ITMP3, REG_PV, a);
+                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
+                       M_IST(REG_ITMP3, REG_SP, 0);
+
+                       a = dseg_addaddress(cd, asm_check_clinit);
+                       M_ALD(REG_ITMP2, REG_PV, a);
+                       M_JMP(REG_ZERO, REG_ITMP2);
                }
        }
        }
 
-       codegen_finish(m, (s4) ((u1 *) mcodeptr - cd->mcodebase));
+       codegen_finish(m, cd, (s4) ((u1 *) mcodeptr - cd->mcodebase));
 }
 
 
@@ -3853,18 +3874,36 @@ void removecompilerstub(u1 *stub)
 
 *******************************************************************************/
 
+
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-#define NATIVESTUBSTACK          2
-#define NATIVESTUBTHREADEXTRA    6
+#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 NATIVESTUBSTACK          1
-#define NATIVESTUBTHREADEXTRA    1
+#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 NATIVESTUBSIZE           (44 + NATIVESTUBTHREADEXTRA - 1)
-#define NATIVESTATICSIZE         5
-#define NATIVEVERBOSESIZE        (39 + 13)
-#define NATIVESTUBOFFSET         9
+#define NATIVESTUB_SIZE           (44 + NATIVESTUB_THREAD_EXTRA - 1)
+#define NATIVESTUB_STATIC_SIZE         5
+#define NATIVESTUB_VERBOSE_SIZE        (39 + 13)
+#define NATIVESTUB_OFFSET         11
+
+#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
+
+#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)
 {
@@ -3874,59 +3913,74 @@ u1 *createnativestub(functionptr f, methodinfo *m)
        s4 stackframesize = 0;              /* size of stackframe if needed       */
        s4 disp;
        s4 stubsize;
-       registerdata *r;
+       codegendata  *cd;
+       registerdata *rd;
+       t_inlining_globals *id;
+       s4 dumpsize;
 
-       /* keep code size smaller */
-       reg_init(m);
-       r = m->registerdata;
+       /* mark start of dump memory area */
+
+       dumpsize = dump_size();
+
+       /* setup registers before using it */
+
+       cd = DNEW(codegendata);
+       rd = DNEW(registerdata);
+       id = DNEW(t_inlining_globals);
+
+       inlining_setup(m, id);
+       reg_setup(m, rd, id);
 
        descriptor2types(m);                /* set paramcount and paramtypes      */
 
-       stubsize = NATIVESTUBSIZE;          /* calculate nativestub size          */
+       stubsize = NATIVESTUB_SIZE;         /* calculate nativestub size          */
+
        if ((m->flags & ACC_STATIC) && !m->class->initialized)
-               stubsize += NATIVESTATICSIZE;
+               stubsize += NATIVESTUB_STATIC_SIZE;
 
        if (runverbose)
-               stubsize += NATIVEVERBOSESIZE;
+               stubsize += NATIVESTUB_VERBOSE_SIZE;
 
        s = CNEW(u8, stubsize);             /* memory to hold the stub            */
-       cs = s + NATIVESTUBOFFSET;
-       mcodeptr = (s4 *) (cs);             /* code generation pointer            */
+       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->clinitrefs = NULL;
 
-       *(cs-1) = (u8) f;                   /* address of native method           */
+       *(cs-1)  = (u8) f;                  /* address of native method           */
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-       *(cs-2) = (u8) &builtin_get_exceptionptrptr;
+       *(cs-2)  = (u8) &builtin_get_exceptionptrptr;
 #else
-       *(cs-2) = (u8) (&_exceptionptr);    /* address of exceptionptr            */
+       *(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_check_clinit;
-
-       M_LDA(REG_SP, REG_SP, -NATIVESTUBSTACK * 8);      /* build up stackframe  */
+       *(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_check_clinit;
+       *(cs-10) = (u8) &builtin_asm_get_stackframeinfo;
+       *(cs-11) = (u8) NULL;               /* filled with machine code           */
+
+       M_LDA(REG_SP, REG_SP, -NATIVESTUB_STACK * 8);     /* build up stackframe  */
        M_AST(REG_RA, REG_SP, 0 * 8);       /* store return address               */
 
+       M_AST(REG_RA, REG_SP, (6+NATIVESTUB_STACKTRACE_OFFSET) * 8);       /* store return address  in stackinfo helper*/
+
        /* if function is static, check for initialized */
 
        if (m->flags & ACC_STATIC) {
        /* if class isn't yet initialized, do it */
                if (!m->class->initialized) {
-                       /* call helper function which patches this code */
-                       M_ALD(REG_ITMP1, REG_PV, -8 * 8);     /* class                    */
-                       M_ALD(REG_PV, REG_PV, -9 * 8);        /* asm_check_clinit         */
-                       M_JSR(REG_RA, REG_PV);
-                       disp = -(s4) (mcodeptr - (s4 *) cs) * 4;
-                       M_LDA(REG_PV, REG_RA, disp);
-                       M_NOP;                  /* this is essential for code patching    */
+                       codegen_addclinitref(cd, mcodeptr, m->class);
                }
        }
 
-       /* max. 39 instructions */
-       if (runverbose) {
+       /* max. 39 +9 instructions */
+       {
                s4 p;
                s4 t;
                M_LDA(REG_SP, REG_SP, -((INT_ARG_CNT + FLT_ARG_CNT + 2) * 8));
@@ -3934,7 +3988,7 @@ u1 *createnativestub(functionptr f, methodinfo *m)
 
                /* save integer argument registers */
                for (p = 0; p < m->paramcount && p < INT_ARG_CNT; p++) {
-                       M_LST(r->argintregs[p], REG_SP, (2 + p) * 8);
+                       M_LST(rd->argintregs[p], REG_SP, (2 + p) * 8);
                }
 
                /* save and copy float arguments into integer registers */
@@ -3943,28 +3997,54 @@ u1 *createnativestub(functionptr f, methodinfo *m)
 
                        if (IS_FLT_DBL_TYPE(t)) {
                                if (IS_2_WORD_TYPE(t)) {
-                                       M_DST(r->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-                                       M_LLD(r->argintregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                                       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);
 
                                } else {
-                                       M_FST(r->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
-                                       M_ILD(r->argintregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                                       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);
                                }
                                
                        } else {
-                               M_DST(r->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                               M_DST(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
                        }
                }
 
-               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);
+               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);
+               }
+
+
+/*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 0
+                M_MOV(REG_RESULT,REG_ITMP3);
+                M_LST(REG_RESULT,REG_ITMP3,0);
+#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(r->argintregs[p], REG_SP, (2 + p) * 8);
+                       M_LLD(rd->argintregs[p], REG_SP, (2 + p) * 8);
                }
 
                for (p = 0; p < m->paramcount && p < FLT_ARG_CNT; p++) {
@@ -3972,14 +4052,14 @@ u1 *createnativestub(functionptr f, methodinfo *m)
 
                        if (IS_FLT_DBL_TYPE(t)) {
                                if (IS_2_WORD_TYPE(t)) {
-                                       M_DLD(r->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                                       M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
 
                                } else {
-                                       M_FLD(r->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                                       M_FLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
                                }
 
                        } else {
-                               M_DLD(r->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
+                               M_DLD(rd->argfltregs[p], REG_SP, (2 + INT_ARG_CNT + p) * 8);
                        }
                }
 
@@ -4005,54 +4085,54 @@ u1 *createnativestub(functionptr f, methodinfo *m)
 
                if (m->flags & ACC_STATIC) {
                        if (IS_FLT_DBL_TYPE(m->paramtypes[5])) {
-                               M_DST(r->argfltregs[5], REG_SP, 1 * 8);
+                               M_DST(rd->argfltregs[5], REG_SP, 1 * 8);
                        } else {
-                               M_LST(r->argintregs[5], REG_SP, 1 * 8);
+                               M_LST(rd->argintregs[5], REG_SP, 1 * 8);
                        }
 
                        if (IS_FLT_DBL_TYPE(m->paramtypes[4])) {
-                               M_DST(r->argfltregs[4], REG_SP, 0 * 8);
+                               M_DST(rd->argfltregs[4], REG_SP, 0 * 8);
                        } else {
-                               M_LST(r->argintregs[4], REG_SP, 0 * 8);
+                               M_LST(rd->argintregs[4], REG_SP, 0 * 8);
                        }
 
                } else {
                        if (IS_FLT_DBL_TYPE(m->paramtypes[5])) {
-                               M_DST(r->argfltregs[5], REG_SP, 0 * 8);
+                               M_DST(rd->argfltregs[5], REG_SP, 0 * 8);
                        } else {
-                               M_LST(r->argintregs[5], REG_SP, 0 * 8);
+                               M_LST(rd->argintregs[5], REG_SP, 0 * 8);
                        }
                }
        }
 
        if (m->flags & ACC_STATIC) {
-               M_MOV(r->argintregs[3], r->argintregs[5]);
-               M_MOV(r->argintregs[2], r->argintregs[4]);
-               M_MOV(r->argintregs[1], r->argintregs[3]);
-               M_MOV(r->argintregs[0], r->argintregs[2]);
-               M_FMOV(r->argfltregs[3], r->argfltregs[5]);
-               M_FMOV(r->argfltregs[2], r->argfltregs[4]);
-               M_FMOV(r->argfltregs[1], r->argfltregs[3]);
-               M_FMOV(r->argfltregs[0], r->argfltregs[2]);
+               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(r->argintregs[1], REG_PV, -8 * 8);
+               M_ALD(rd->argintregs[1], REG_PV, -8 * 8);
 
        } else {
-               M_MOV(r->argintregs[4], r->argintregs[5]);
-               M_MOV(r->argintregs[3], r->argintregs[4]);
-               M_MOV(r->argintregs[2], r->argintregs[3]);
-               M_MOV(r->argintregs[1], r->argintregs[2]);
-               M_MOV(r->argintregs[0], r->argintregs[1]);
-               M_FMOV(r->argfltregs[4], r->argfltregs[5]);
-               M_FMOV(r->argfltregs[3], r->argfltregs[4]);
-               M_FMOV(r->argfltregs[2], r->argfltregs[3]);
-               M_FMOV(r->argfltregs[1], r->argfltregs[2]);
-               M_FMOV(r->argfltregs[0], r->argfltregs[1]);
+               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]);
        }
 
        /* put env into first argument register */
-       M_ALD(r->argintregs[0], REG_PV, -4 * 8);
+       M_ALD(rd->argintregs[0], REG_PV, -4 * 8);
 
        M_ALD(REG_PV, REG_PV, -1 * 8);      /* load adress of native method       */
        M_JSR(REG_RA, REG_PV);              /* call native method                 */
@@ -4067,12 +4147,12 @@ u1 *createnativestub(functionptr f, methodinfo *m)
        /* 13 instructions */
        if (runverbose) {
                M_LDA(REG_SP, REG_SP, -2 * 8);
-               M_ALD(r->argintregs[0], REG_PV, -6 * 8); /* load method adress        */
+               M_ALD(rd->argintregs[0], REG_PV, -6 * 8); /* load method adress       */
                M_LST(REG_RESULT, REG_SP, 0 * 8);
                M_DST(REG_FRESULT, REG_SP, 1 * 8);
-               M_MOV(REG_RESULT, r->argintregs[1]);
-               M_FMOV(REG_FRESULT, r->argfltregs[2]);
-               M_FMOV(REG_FRESULT, r->argfltregs[3]);
+               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          */
                M_JSR(REG_RA, REG_PV);
                disp = -(s4) (mcodeptr - (s4 *) cs) * 4;
@@ -4082,6 +4162,10 @@ u1 *createnativestub(functionptr f, methodinfo *m)
                M_LDA(REG_SP, REG_SP, 2 * 8);
        }
 
+        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*/
+
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
        if (IS_FLT_DBL_TYPE(m->returntype))
                M_DST(REG_FRESULT, REG_SP, 1 * 8);
@@ -4103,27 +4187,70 @@ u1 *createnativestub(functionptr f, methodinfo *m)
        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, NATIVESTUBSTACK * 8); /* remove stackframe          */
+       M_LDA(REG_SP, REG_SP, NATIVESTUB_STACK * 8); /* remove stackframe         */
        M_RET(REG_ZERO, REG_RA);            /* return to caller                   */
 
        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, NATIVESTUBSTACK * 8); /* remove stackframe          */
+       M_LDA(REG_SP, REG_SP, NATIVESTUB_STACK * 8); /* remove stackframe         */
        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_JMP(REG_ZERO, REG_ITMP3);         /* jump to asm exception handler      */
        
+       /* generate put/getstatic stub call code */
+
+       {
+               s4          *xcodeptr;
+               clinitref   *cref;
+               s4          *tmpmcodeptr;
+
+               /* there can only be one clinit ref entry                             */
+               cref = cd->clinitrefs;
+
+               if (cref) {
+                       /* Get machine code which is patched back in later. The call is   */
+                       /* 1 instruction word long.                                       */
+                       xcodeptr = (s4 *) (cd->mcodebase + cref->branchpos);
+                       *(cs-11) = (u4) *xcodeptr;
+
+                       /* 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 */
+
+                       M_BSR(REG_RA, tmpmcodeptr - (xcodeptr + 1));
+
+                       mcodeptr = tmpmcodeptr;         /* restore the current mcodeptr   */
+
+                       /* move class pointer into REG_ITMP2                              */
+                       M_ALD(REG_ITMP1, REG_PV, -8 * 8);     /* class                    */
+
+                       /* move machine code into REG_ITMP3                               */
+                       M_ILD(REG_ITMP3, REG_PV, -11 * 8);    /* machine code             */
+                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
+                       M_IST(REG_ITMP3, REG_SP, 0);
+
+                       M_ALD(REG_ITMP2, REG_PV, -9 * 8);     /* asm_check_clinit         */
+                       M_JMP(REG_ZERO, REG_ITMP2);
+               }
+       }
+
 #if 0
        dolog_plain("stubsize: %d (for %d params)\n", (int) (mcodeptr - (s4*) s), m->paramcount);
 #endif
 
 #if defined(STATISTICS)
        if (opt_stat)
-               count_nstub_len += NATIVESTUBSIZE * 8;
+               count_nstub_len += NATIVESTUB_SIZE * 8;
 #endif
 
-       return (u1 *) (s + NATIVESTUBOFFSET);
+       /* release dump area */
+
+       dump_release(dumpsize);
+
+       return (u1 *) (s + NATIVESTUB_OFFSET);
 }