GNU header update.
[cacao.git] / src / vm / jit / alpha / codegen.c
index 6e512d6cef7c49f1a7ad93fb17158e2a0d97b415..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 1279 2004-07-05 18:48:45Z stefan $
+   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,129 +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 */
-
-
-/* parameter allocation mode */
-
-int nreg_parammode = PARAMMODE_NUMBERED;  
-
-   /* parameter-registers will be allocated by assigning the
-      1. parameter:   int/float-reg 16
-      2. parameter:   int/float-reg 17  
-      3. parameter:   int/float-reg 18 ....
-   */
-
 
-/* stackframe-infos ***********************************************************/
+/* Include independent code generation stuff -- include after register        */
+/* descriptions to avoid extern definitions.                                  */
 
-int parentargs_base; /* offset in stackframe for the parameter from the caller*/
-
-/* -> see file 'calling.doc' */
-
-
-/* additional functions and macros to generate code ***************************/
-
-/* #define BlockPtrOfPC(pc)        block+block_index[pc] */
-#define BlockPtrOfPC(pc)  ((basicblock *) iptr->target)
-
-
-#ifdef STATISTICS
-#define COUNT_SPILLS count_spills++
-#else
-#define COUNT_SPILLS
+#include "vm/jit/codegen.inc"
+#include "vm/jit/reg.inc"
+#ifdef LSRA
+#include "vm/jit/lsra.inc"
 #endif
 
 
-/* gen_nullptr_check(objreg) */
-
-#define gen_nullptr_check(objreg) \
-    if (checknull) { \
-        M_BEQZ((objreg), 0); \
-        codegen_addxnullrefs(mcodeptr); \
-    }
-
-
-/* MCODECHECK(icnt) */
-
-#define MCODECHECK(icnt) \
-       if((mcodeptr + (icnt)) > mcodeend) mcodeptr = codegen_increase((u1*) mcodeptr)
-
-/* M_INTMOVE:
-     generates an integer-move from register a to b.
-     if a and b are the same int-register, no code will be generated.
-*/ 
-
-#define M_INTMOVE(a,b) if (a != b) { M_MOV(a, b); }
-
-
-/* M_FLTMOVE:
-    generates a floating-point-move from register a to b.
-    if a and b are the same float-register, no code will be generated
-*/ 
-
-#define M_FLTMOVE(a,b) if (a != b) { M_FMOV(a, b); }
-
-
-/* var_to_reg_xxx:
-    this function generates code to fetch data from a pseudo-register
-    into a real register. 
-    If the pseudo-register has actually been assigned to a real 
-    register, no code will be emitted, since following operations
-    can use this register directly.
-    
-    v: pseudoregister to be fetched from
-    tempregnum: temporary register to be used if v is actually spilled to ram
-
-    return: the register number, where the operand can be found after 
-            fetching (this wil be either tempregnum or the register
-            number allready given to v)
-*/
-
-#define var_to_reg_int(regnr,v,tempnr) { \
-       if ((v)->flags & INMEMORY) \
-               {COUNT_SPILLS;M_LLD(tempnr,REG_SP,8*(v)->regoff);regnr=tempnr;} \
-       else regnr=(v)->regoff; \
-}
-
-
-#define var_to_reg_flt(regnr,v,tempnr) { \
-       if ((v)->flags & INMEMORY) \
-               {COUNT_SPILLS;M_DLD(tempnr,REG_SP,8*(v)->regoff);regnr=tempnr;} \
-       else regnr=(v)->regoff; \
-}
-
-
-/* store_reg_to_var_xxx:
-    This function generates the code to store the result of an operation
-    back into a spilled pseudo-variable.
-    If the pseudo-variable has not been spilled in the first place, this 
-    function will generate nothing.
-    
-    v ............ Pseudovariable
-    tempregnum ... Number of the temporary registers as returned by
-                   reg_of_var.
-*/     
-
-#define store_reg_to_var_int(sptr, tempregnum) {       \
-       if ((sptr)->flags & INMEMORY) {                    \
-               COUNT_SPILLS;                                  \
-               M_LST(tempregnum, REG_SP, 8 * (sptr)->regoff); \
-               }                                              \
-       }
-
-#define store_reg_to_var_flt(sptr, tempregnum) {       \
-       if ((sptr)->flags & INMEMORY) {                    \
-               COUNT_SPILLS;                                  \
-               M_DST(tempregnum, REG_SP, 8 * (sptr)->regoff); \
-               }                                              \
-       }
-
-
 /* 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               */
@@ -278,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 {
@@ -330,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
        }
 }
@@ -346,33 +240,30 @@ 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;
+       s4 len, s1, s2, s3, d;
+       s4 a;
+       s4 parentargs_base;
        s4             *mcodeptr;
        stackptr        src;
        varinfo        *var;
        basicblock     *bptr;
        instruction    *iptr;
        exceptiontable *ex;
-       registerdata   *r;
-
+       u2 currentline=0;
        {
        s4 i, p, pa, t, l;
        s4 savedregs_num;
 
-       /* keep code size smaller */
-       r = m->registerdata;
-
        savedregs_num = (m->isleafmethod) ? 0 : 1;        /* space to save the RA */
 
        /* 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 */
 
@@ -383,8 +274,8 @@ void codegen(methodinfo *m)
 
        /* create method header */
 
-       (void) dseg_addaddress(m);                              /* MethodPointer  */
-       (void) dseg_adds4(parentargs_base * 8);                 /* FrameSize      */
+       (void) dseg_addaddress(cd, m);                          /* MethodPointer  */
+       (void) dseg_adds4(cd, parentargs_base * 8);             /* FrameSize      */
 
 #if defined(USE_THREADS)
 
@@ -395,40 +286,40 @@ void codegen(methodinfo *m)
        */
 
        if (checksync && (m->flags & ACC_SYNCHRONIZED))
-               (void) dseg_adds4((r->maxmemuse + 1) * 8);          /* IsSync         */
+               (void) dseg_adds4(cd, (rd->maxmemuse + 1) * 8);     /* IsSync         */
        else
 
 #endif
 
-       (void) dseg_adds4(0);                                   /* IsSync         */
+       (void) dseg_adds4(cd, 0);                               /* IsSync         */
                                               
-       (void) dseg_adds4(m->isleafmethod);                     /* IsLeaf         */
-       (void) dseg_adds4(r->savintregcnt - r->maxsavintreguse);/* IntSave        */
-       (void) dseg_adds4(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();
+       dseg_addlinenumbertablesize(cd);
 
-       (void) dseg_adds4(m->exceptiontablelength);             /* ExTableSize    */
+       (void) dseg_adds4(cd, cd->exceptiontablelength);        /* ExTableSize    */
 
        /* create exception table */
 
-       for (ex = m->exceptiontable; ex != NULL; ex = ex->down) {
-               dseg_addtarget(ex->start);
-               dseg_addtarget(ex->end);
-               dseg_addtarget(ex->handler);
-               (void) dseg_addaddress(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 */
        
-       mcodeptr = (s4*) mcodebase;
-       mcodeend = (s4*) (mcodebase + mcodesize);
+       mcodeptr = (s4 *) cd->mcodebase;
+       cd->mcodeend = (s4 *) (cd->mcodebase + cd->mcodesize);
        MCODECHECK(128 + m->paramcount);
 
        /* 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 */
@@ -437,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 */
@@ -449,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->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
@@ -470,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 */
@@ -479,31 +370,31 @@ 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);
+               p = dseg_addaddress(cd, m);
                M_ALD(REG_ITMP1, REG_PV, p);
                M_AST(REG_ITMP1, REG_SP, 0 * 8);
-               p = dseg_addaddress((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 - mcodebase);
+               disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
                M_LDA(REG_PV, REG_RA, disp);
                M_ALD(REG_RA, REG_SP, 1 * 8);
 
                for (p = 0; /* p < 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++) {
@@ -511,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);
                        }
                }
 
@@ -529,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++;
@@ -538,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       */
@@ -557,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       */
@@ -583,11 +474,11 @@ void codegen(methodinfo *m)
                s4 disp;
                s8 func_enter = (m->flags & ACC_STATIC) ?
                        (s8) builtin_staticmonitorenter : (s8) builtin_monitorenter;
-               p = dseg_addaddress((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 - mcodebase);
+               disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
                M_LDA(REG_PV, REG_RA, disp);
        }                       
 #endif
@@ -598,7 +489,7 @@ void codegen(methodinfo *m)
        /* walk through all basic blocks */
        for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
 
-               bptr->mpc = (s4) ((u1 *) mcodeptr - mcodebase);
+               bptr->mpc = (s4) ((u1 *) mcodeptr - cd->mcodebase);
 
                if (bptr->flags >= BBREACHED) {
 
@@ -607,7 +498,7 @@ void codegen(methodinfo *m)
                {
                branchref *brefs;
                for (brefs = bptr->branchrefs; brefs != NULL; brefs = brefs->next) {
-                       gen_resolvebranch((u1*) mcodebase + brefs->branchpos, 
+                       gen_resolvebranch((u1*) cd->mcodebase + brefs->branchpos, 
                                          brefs->branchpos, bptr->mpc);
                        }
                }
@@ -617,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);
                                                }
@@ -652,6 +560,9 @@ void codegen(methodinfo *m)
                                }
                        src = src->prev;
                        }
+#ifdef LSRA
+               }
+#endif
 
                /* walk through all instructions */
                
@@ -661,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) {
 
@@ -671,21 +587,15 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_BEQZ(s1, 0);
-                       codegen_addxnullrefs(mcodeptr);
+                       codegen_addxnullrefs(cd, mcodeptr);
                        break;
 
                /* constant operations ************************************************/
 
-#define ICONST(r,c) if(((c)>=-32768)&&((c)<= 32767)){M_LDA(r,REG_ZERO,c);} \
-                    else{a=dseg_adds4(c);M_ILD(r,REG_PV,a);}
-
-#define LCONST(r,c) if(((c)>=-32768)&&((c)<= 32767)){M_LDA(r,REG_ZERO,c);} \
-                    else{a=dseg_adds8(c);M_LLD(r,REG_PV,a);}
-
                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;
@@ -693,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;
@@ -701,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(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;
@@ -710,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(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;
@@ -719,14 +629,13 @@ 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 (iptr->val.a);
+                               a = dseg_addaddress(cd, iptr->val.a);
                                M_ALD(d, REG_PV, a);
-                               }
-                       else {
+                       } else {
                                M_INTMOVE(REG_ZERO, d);
-                               }
+                       }
                        store_reg_to_var_int(iptr->dst, d);
                        break;
 
@@ -737,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
@@ -752,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
@@ -772,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);
@@ -789,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);
@@ -809,29 +718,24 @@ void codegen(methodinfo *m)
                case ICMD_POP2:       /* ..., value, value  ==> ...                   */
                        break;
 
-#define M_COPY(from,to) \
-                       d = reg_of_var(m, to, REG_IFTMP); \
-                       if ((from->regoff != to->regoff) || \
-                           ((from->flags ^ to->flags) & INMEMORY)) { \
-                               if (IS_FLT_DBL_TYPE(from->type)) { \
-                                       var_to_reg_flt(s1, from, d); \
-                                       M_FLTMOVE(s1,d); \
-                                       store_reg_to_var_flt(to, d); \
-                                       }\
-                               else { \
-                                       var_to_reg_int(s1, from, d); \
-                                       M_INTMOVE(s1,d); \
-                                       store_reg_to_var_int(to, d); \
-                                       }\
-                               }
-
                case ICMD_DUP:        /* ..., a ==> ..., a, a                         */
                        M_COPY(src, iptr->dst);
                        break;
 
                case ICMD_DUP_X1:     /* ..., a, b ==> ..., b, a, b                   */
 
-                       M_COPY(src,       iptr->dst->prev->prev);
+                       M_COPY(src,       iptr->dst);
+                       M_COPY(src->prev, iptr->dst->prev);
+                       M_COPY(iptr->dst, iptr->dst->prev->prev);
+                       break;
+
+               case ICMD_DUP_X2:     /* ..., a, b, c ==> ..., c, a, b, c             */
+
+                       M_COPY(src,             iptr->dst);
+                       M_COPY(src->prev,       iptr->dst->prev);
+                       M_COPY(src->prev->prev, iptr->dst->prev->prev);
+                       M_COPY(iptr->dst,       iptr->dst->prev->prev->prev);
+                       break;
 
                case ICMD_DUP2:       /* ..., a, b ==> ..., a, b, a, b                */
 
@@ -841,14 +745,11 @@ void codegen(methodinfo *m)
 
                case ICMD_DUP2_X1:    /* ..., a, b, c ==> ..., b, c, a, b, c          */
 
-                       M_COPY(src->prev,       iptr->dst->prev->prev->prev);
-
-               case ICMD_DUP_X2:     /* ..., a, b, c ==> ..., c, a, b, c             */
-
                        M_COPY(src,             iptr->dst);
                        M_COPY(src->prev,       iptr->dst->prev);
                        M_COPY(src->prev->prev, iptr->dst->prev->prev);
-                       M_COPY(src, iptr->dst->prev->prev->prev);
+                       M_COPY(iptr->dst,       iptr->dst->prev->prev->prev);
+                       M_COPY(iptr->dst->prev, iptr->dst->prev->prev->prev->prev);
                        break;
 
                case ICMD_DUP2_X2:    /* ..., a, b, c, d ==> ..., c, d, a, b, c, d    */
@@ -857,13 +758,13 @@ void codegen(methodinfo *m)
                        M_COPY(src->prev,             iptr->dst->prev);
                        M_COPY(src->prev->prev,       iptr->dst->prev->prev);
                        M_COPY(src->prev->prev->prev, iptr->dst->prev->prev->prev);
-                       M_COPY(src,       iptr->dst->prev->prev->prev->prev);
-                       M_COPY(src->prev, iptr->dst->prev->prev->prev->prev->prev);
+                       M_COPY(iptr->dst,             iptr->dst->prev->prev->prev->prev);
+                       M_COPY(iptr->dst->prev,       iptr->dst->prev->prev->prev->prev->prev);
                        break;
 
                case ICMD_SWAP:       /* ..., a, b ==> ..., b, a                      */
 
-                       M_COPY(src, iptr->dst->prev);
+                       M_COPY(src,       iptr->dst->prev);
                        M_COPY(src->prev, iptr->dst);
                        break;
 
@@ -873,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;
@@ -881,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;
@@ -889,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;
@@ -897,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;
@@ -905,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);
                                }
@@ -919,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;
@@ -927,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);
                                }
@@ -943,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;
@@ -952,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);
                                }
@@ -967,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;
@@ -976,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);
                                }
@@ -991,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;
@@ -1000,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);
                                }
@@ -1015,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;
@@ -1024,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);
                                }
@@ -1039,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;
@@ -1048,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);
                                }
@@ -1063,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;
@@ -1072,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);
                                }
@@ -1087,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);
@@ -1105,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);
@@ -1116,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);
@@ -1126,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);
@@ -1136,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;
@@ -1145,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);
@@ -1157,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);
@@ -1168,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;
@@ -1177,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;
@@ -1186,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;
@@ -1195,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;
@@ -1204,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;
@@ -1213,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;
@@ -1223,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;
@@ -1232,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);
                                }
@@ -1253,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;
@@ -1291,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);
                                }
@@ -1324,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;
@@ -1387,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;
@@ -1396,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);
                                }
@@ -1411,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);
                                }
@@ -1427,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;
@@ -1436,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);
                                }
@@ -1451,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);
                                }
@@ -1467,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);
@@ -1478,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);
@@ -1505,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;
@@ -1513,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;
@@ -1522,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);
                                }
@@ -1544,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);
                                }
@@ -1566,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);
                                }
@@ -1588,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);
                                }
@@ -1610,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);
                                }
@@ -1632,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);
                                }
@@ -1654,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);
                                }
@@ -1676,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);
                                }
@@ -1697,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(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);
@@ -1708,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(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);
@@ -1719,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(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);
@@ -1731,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(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);
@@ -1742,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);
@@ -1751,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);
                                }
@@ -1766,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);
@@ -1794,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);
@@ -1821,18 +1722,10 @@ void codegen(methodinfo *m)
 
                /* memory operations **************************************************/
 
-#define gen_bound_check \
-    if (checkbounds) { \
-        M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
-        M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\
-        M_BEQZ(REG_ITMP3, 0);\
-        codegen_addxboundrefs(mcodeptr, s2); \
-    }
-
                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);
@@ -1842,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;
@@ -1856,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;
@@ -1870,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;
@@ -1885,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;
@@ -1899,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;
@@ -1913,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;
@@ -1937,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;
@@ -1963,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;
@@ -2240,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(((fieldinfo *) iptr->val.a)->class);
-                               M_ALD(REG_ITMP1, REG_PV, a);
-                               a = dseg_addaddress(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 = (int) ((u1*) mcodeptr - 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(&(((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:
@@ -2295,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(((fieldinfo *) iptr->val.a)->class);
-                               M_ALD(REG_ITMP1, REG_PV, a);
-                               a = dseg_addaddress(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 = (int) ((u1*) mcodeptr - 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 (&(((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;
@@ -2352,7 +2224,7 @@ void codegen(methodinfo *m)
                case ICMD_PUTFIELD:   /* ..., value  ==> ...                          */
                                      /* op1 = type, val.i = field offset             */
 
-                       a = ((fieldinfo *)(iptr->val.a))->offset;
+                       a = ((fieldinfo *) iptr->val.a)->offset;
                        switch (iptr->op1) {
                                case TYPE_INT:
                                        var_to_reg_int(s1, src->prev, REG_ITMP1);
@@ -2395,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);
@@ -2441,7 +2313,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_INTMOVE(s1, REG_ITMP1_XPTR);
-                       a = dseg_addaddress(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 */
@@ -2452,7 +2324,7 @@ void codegen(methodinfo *m)
                case ICMD_GOTO:         /* ... ==> ...                                */
                                        /* op1 = target JavaVM pc                     */
                        M_BR(0);
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        ALIGNCODENOP;
                        break;
 
@@ -2460,13 +2332,13 @@ void codegen(methodinfo *m)
                                        /* op1 = target JavaVM pc                     */
 
                        M_BSR(REG_ITMP1, 0);
-                       codegen_addreference(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);
@@ -2481,7 +2353,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_BEQZ(s1, 0);
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFNONNULL:    /* ..., value ==> ...                         */
@@ -2489,7 +2361,7 @@ void codegen(methodinfo *m)
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_BNEZ(s1, 0);
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFEQ:         /* ..., value ==> ...                         */
@@ -2509,7 +2381,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFLT:         /* ..., value ==> ...                         */
@@ -2529,7 +2401,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFLE:         /* ..., value ==> ...                         */
@@ -2549,7 +2421,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFNE:         /* ..., value ==> ...                         */
@@ -2569,7 +2441,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFGT:         /* ..., value ==> ...                         */
@@ -2589,7 +2461,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IFGE:         /* ..., value ==> ...                         */
@@ -2609,7 +2481,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_LEQ:       /* ..., value ==> ...                         */
@@ -2629,7 +2501,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_LLT:       /* ..., value ==> ...                         */
@@ -2649,7 +2521,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_LLE:       /* ..., value ==> ...                         */
@@ -2669,7 +2541,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BNEZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_LNE:       /* ..., value ==> ...                         */
@@ -2689,7 +2561,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_LGT:       /* ..., value ==> ...                         */
@@ -2709,7 +2581,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_LGE:       /* ..., value ==> ...                         */
@@ -2729,7 +2601,7 @@ void codegen(methodinfo *m)
                                        }
                                M_BEQZ(REG_ITMP1, 0);
                                }
-                       codegen_addreference(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_ICMPEQ:    /* ..., value, value ==> ...                  */
@@ -2740,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(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_ICMPNE:    /* ..., value, value ==> ...                  */
@@ -2751,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(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_ICMPLT:    /* ..., value, value ==> ...                  */
@@ -2761,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(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_ICMPGT:    /* ..., value, value ==> ...                  */
@@ -2771,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(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_ICMPLE:    /* ..., value, value ==> ...                  */
@@ -2781,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(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                case ICMD_IF_ICMPGE:    /* ..., value, value ==> ...                  */
@@ -2791,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(BlockPtrOfPC(iptr->op1), mcodeptr);
+                       codegen_addreference(cd, BlockPtrOfPC(iptr->op1), mcodeptr);
                        break;
 
                /* (value xx 0) ? IFxx_ICONST : ELSE_ICONST                           */
@@ -2803,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)) {
@@ -2837,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)) {
@@ -2871,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)) {
@@ -2904,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)) {
@@ -2937,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)) {
@@ -2970,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)) {
@@ -3010,14 +2882,14 @@ void codegen(methodinfo *m)
 #if defined(USE_THREADS)
                        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
                                s4 disp;
-                               a = dseg_addaddress((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 - mcodebase);
+                               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
 
@@ -3032,14 +2904,14 @@ void codegen(methodinfo *m)
 #if defined(USE_THREADS)
                        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
                                s4 disp;
-                               a = dseg_addaddress((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 - mcodebase);
+                               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
 
@@ -3050,11 +2922,11 @@ void codegen(methodinfo *m)
 #if defined(USE_THREADS)
                        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
                                s4 disp;
-                               a = dseg_addaddress((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 - mcodebase);
+                               disp = -(s4) ((u1 *) mcodeptr - cd->mcodebase);
                                M_LDA(REG_PV, REG_RA, disp);
                        }
 #endif
@@ -3073,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                                               */
@@ -3093,15 +2965,15 @@ 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_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((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 - mcodebase);
+                               s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
                                if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
                                else {
                                        s4 ml = -s1, mh = 0;
@@ -3155,8 +3027,8 @@ nowperformreturn:
                        M_BEQZ(REG_ITMP2, 0);
 
 
-                       /* codegen_addreference(BlockPtrOfPC(s4ptr[0]), mcodeptr); */
-                       codegen_addreference((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 */
 
@@ -3164,8 +3036,8 @@ nowperformreturn:
                        tptr += i;
 
                        while (--i >= 0) {
-                               /* dseg_addtarget(BlockPtrOfPC(*--s4ptr)); */
-                               dseg_addtarget((basicblock *) tptr[0]); 
+                               /* dseg_addtarget(cd, BlockPtrOfPC(*--s4ptr)); */
+                               dseg_addtarget(cd, (basicblock *) tptr[0]); 
                                --tptr;
                                }
                        }
@@ -3173,7 +3045,7 @@ nowperformreturn:
                        /* length of dataseg after last dseg_addtarget is used by load */
 
                        M_SAADDQ(REG_ITMP1, REG_PV, REG_ITMP2);
-                       M_ALD(REG_ITMP2, REG_ITMP2, -dseglen);
+                       M_ALD(REG_ITMP2, REG_ITMP2, -(cd->dseglen));
                        M_JMP(REG_ZERO, REG_ITMP2);
                        ALIGNCODENOP;
                        break;
@@ -3205,21 +3077,21 @@ nowperformreturn:
                                                M_LDA(REG_ITMP2, REG_ZERO, val);
                                                } 
                                        else {
-                                               a = dseg_adds4 (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(BlockPtrOfPC(s4ptr[1]), mcodeptr); */
-                               codegen_addreference((basicblock *) tptr[0], mcodeptr); 
+                               /* codegen_addreference(cd, BlockPtrOfPC(s4ptr[1]), mcodeptr); */
+                               codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr); 
                                }
 
                        M_BR(0);
-                       /* codegen_addreference(BlockPtrOfPC(l), mcodeptr); */
+                       /* codegen_addreference(cd, BlockPtrOfPC(l), mcodeptr); */
                        
                        tptr = (void **) iptr->target;
-                       codegen_addreference((basicblock *) tptr[0], mcodeptr);
+                       codegen_addreference(cd, (basicblock *) tptr[0], mcodeptr);
 
                        ALIGNCODENOP;
                        break;
@@ -3257,7 +3129,6 @@ nowperformreturn:
 
 gen_method: {
                        methodinfo *lm;
-                       classinfo  *ci;
 
                        MCODECHECK((s3 << 1) + 64);
 
@@ -3268,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);
 
@@ -3279,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);
 
@@ -3292,62 +3163,52 @@ gen_method: {
 
                        lm = iptr->val.a;
                        switch (iptr->opc) {
-                               case ICMD_BUILTIN3:
-                               case ICMD_BUILTIN2:
-                               case ICMD_BUILTIN1:
-                                       a = dseg_addaddress((void *) lm);
-
-                                       M_ALD(REG_PV, REG_PV, a); /* Pointer to built-in-function */
-                                       d = iptr->op1;
-                                       goto makeactualcall;
+                       case ICMD_BUILTIN3:
+                       case ICMD_BUILTIN2:
+                       case ICMD_BUILTIN1:
+                               a = dseg_addaddress(cd, (void *) lm);
+                               d = iptr->op1;
 
-                               case ICMD_INVOKESTATIC:
-                               case ICMD_INVOKESPECIAL:
-                                       a = dseg_addaddress(lm->stubroutine);
-
-                                       M_ALD(REG_PV, REG_PV, a);        /* method pointer in r27 */
+                               M_ALD(REG_PV, REG_PV, a);     /* Pointer to built-in-function */
+                               break;
 
-                                       d = lm->returntype;
-                                       goto makeactualcall;
+                       case ICMD_INVOKESTATIC:
+                       case ICMD_INVOKESPECIAL:
+                               a = dseg_addaddress(cd, lm->stubroutine);
+                               d = lm->returntype;
 
-                               case ICMD_INVOKEVIRTUAL:
+                               M_ALD(REG_PV, REG_PV, a);            /* method pointer in r27 */
+                               break;
 
-                                       gen_nullptr_check(r->argintregs[0]);
-                                       M_ALD(REG_METHODPTR, r->argintregs[0],
-                                                 OFFSET(java_objectheader, vftbl));
-                                       M_ALD(REG_PV, REG_METHODPTR, OFFSET(vftbl, table[0]) +
-                                                 sizeof(methodptr) * lm->vftblindex);
+                       case ICMD_INVOKEVIRTUAL:
+                               d = lm->returntype;
 
-                                       d = lm->returntype;
-                                       goto makeactualcall;
+                               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);
+                               break;
 
-                               case ICMD_INVOKEINTERFACE:
-                                       ci = lm->class;
+                       case ICMD_INVOKEINTERFACE:
+                               d = lm->returntype;
                                        
-                                       gen_nullptr_check(r->argintregs[0]);
-                                       M_ALD(REG_METHODPTR, r->argintregs[0],
-                                                 OFFSET(java_objectheader, vftbl));    
-                                       M_ALD(REG_METHODPTR, REG_METHODPTR,
-                                             OFFSET(vftbl, interfacetable[0]) -
-                                             sizeof(methodptr*) * ci->index);
-                                       M_ALD(REG_PV, REG_METHODPTR,
-                                                 sizeof(methodptr) * (lm - ci->methods));
-
-                                       d = lm->returntype;
-                                       goto makeactualcall;
-
-                               default:
-                                       d = 0;
-                                       error ("Unkown ICMD-Command: %d", iptr->opc);
-                               }
-
-makeactualcall:
+                               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]) -
+                                         sizeof(methodptr*) * lm->class->index);
+                               M_ALD(REG_PV, REG_METHODPTR,
+                                         sizeof(methodptr) * (lm - lm->class->methods));
+                               break;
+                       }
 
                        M_JSR(REG_RA, REG_PV);
 
                        /* recompute pv */
 
-                       s1 = (s4) ((u1 *) mcodeptr - mcodebase);
+                       s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
                        if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
                        else {
                                s4 ml = -s1, mh = 0;
@@ -3360,12 +3221,12 @@ makeactualcall:
 
                        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);
                                }
@@ -3396,10 +3257,10 @@ makeactualcall:
                        classinfo *super = (classinfo*) iptr->val.a;
                        
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                       codegen_threadcritrestart((u1*) mcodeptr - 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;
@@ -3409,11 +3270,11 @@ makeactualcall:
                                if (super->flags & ACC_INTERFACE) {        /* interface       */
                                        M_BEQZ(s1, 6);
                                        M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
-                                       M_ILD(REG_ITMP2, REG_ITMP1, OFFSET(vftbl, interfacetablelength));
+                                       M_ILD(REG_ITMP2, REG_ITMP1, OFFSET(vftbl_t, interfacetablelength));
                                        M_LDA(REG_ITMP2, REG_ITMP2, - super->index);
                                        M_BLEZ(REG_ITMP2, 2);
                                        M_ALD(REG_ITMP1, REG_ITMP1,
-                                             OFFSET(vftbl, interfacetable[0]) -
+                                             OFFSET(vftbl_t, interfacetable[0]) -
                                              super->index * sizeof(methodptr*));
                                        M_CMPULT(REG_ZERO, REG_ITMP1, d);      /* REG_ITMP1 != 0  */
                                        }
@@ -3422,7 +3283,7 @@ makeactualcall:
                                        s2 = super->vftbl->diffval;
                                        M_BEQZ(s1, 4 + (s2 > 255));
                                        M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
-                                       M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
+                                       M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
                                        M_LDA(REG_ITMP1, REG_ITMP1, - super->vftbl->baseval);
                                        if (s2 <= 255)
                                                M_CMPULE_IMM(REG_ITMP1, s2, d);
@@ -3433,16 +3294,16 @@ makeactualcall:
 */
                                        M_BEQZ(s1, 7);
                                        M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
-                                       a = dseg_addaddress ((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((u1*) mcodeptr - mcodebase);
+                                       codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
-                                       M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
-                                       M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl, baseval));
-                                       M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval));
+                                       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((u1*) mcodeptr - mcodebase);
+                                       codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
                                        M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
                                        M_CMPULE(REG_ITMP1, REG_ITMP2, d);
@@ -3473,33 +3334,33 @@ makeactualcall:
  */
 
                        {
-                       classinfo *super = (classinfo*) iptr->val.a;
+                       classinfo *super = (classinfo *) iptr->val.a;
                        
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                       codegen_threadcritrestart((u1*) mcodeptr - 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       */
                                        M_BEQZ(s1, 6);
                                        M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
-                                       M_ILD(REG_ITMP2, REG_ITMP1, OFFSET(vftbl, interfacetablelength));
+                                       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(mcodeptr);
+                                       codegen_addxcastrefs(cd, mcodeptr);
                                        M_ALD(REG_ITMP2, REG_ITMP1,
-                                             OFFSET(vftbl, interfacetable[0]) -
+                                             OFFSET(vftbl_t, interfacetable[0]) -
                                              super->index * sizeof(methodptr*));
                                        M_BEQZ(REG_ITMP2, 0);
-                                       codegen_addxcastrefs(mcodeptr);
+                                       codegen_addxcastrefs(cd, mcodeptr);
                                        }
                                else {                                     /* class           */
 /*
                                        s2 = super->vftbl->diffval;
                                        M_BEQZ(s1, 4 + (s2 != 0) + (s2 > 255));
                                        M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
-                                       M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
+                                       M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
                                        M_LDA(REG_ITMP1, REG_ITMP1, - super->vftbl->baseval);
                                        if (s2 == 0) {
                                                M_BNEZ(REG_ITMP1, 0);
@@ -3516,32 +3377,32 @@ makeactualcall:
 */
                                        M_BEQZ(s1, 8 + (d == REG_ITMP3));
                                        M_ALD(REG_ITMP1, s1, OFFSET(java_objectheader, vftbl));
-                                       a = dseg_addaddress ((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((u1*) mcodeptr - mcodebase);
+                                       codegen_threadcritstart(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
-                                       M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl, baseval));
+                                       M_ILD(REG_ITMP1, REG_ITMP1, OFFSET(vftbl_t, baseval));
                                        if (d != REG_ITMP3) {
-                                               M_ILD(REG_ITMP3, REG_ITMP2, OFFSET(vftbl, baseval));
-                                               M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval));
+                                               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((u1*) mcodeptr - mcodebase);
+                                               codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
                                                M_ISUB(REG_ITMP1, REG_ITMP3, REG_ITMP1);
                                                }
                                        else {
-                                               M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, baseval));
+                                               M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, baseval));
                                                M_ISUB(REG_ITMP1, REG_ITMP2, REG_ITMP1);
                                                M_ALD(REG_ITMP2, REG_PV, a);
-                                               M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl, diffval));
+                                               M_ILD(REG_ITMP2, REG_ITMP2, OFFSET(vftbl_t, diffval));
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-                                               codegen_threadcritstop((u1*) mcodeptr - mcodebase);
+                                               codegen_threadcritstop(cd, (u1 *) mcodeptr - cd->mcodebase);
 #endif
                                                }
                                        M_CMPULE(REG_ITMP1, REG_ITMP2, REG_ITMP2);
                                        M_BEQZ(REG_ITMP2, 0);
-                                       codegen_addxcastrefs(mcodeptr);
+                                       codegen_addxcastrefs(cd, mcodeptr);
                                        }
                                }
                        else
@@ -3555,13 +3416,13 @@ makeactualcall:
 
                        var_to_reg_int(s1, src, REG_ITMP1);
                        M_BLTZ(s1, 0);
-                       codegen_addxcheckarefs(mcodeptr);
+                       codegen_addxcheckarefs(cd, mcodeptr);
                        break;
 
                case ICMD_CHECKEXCEPTION:    /* ... ==> ...                           */
 
                        M_BEQZ(REG_RESULT, 0);
-                       codegen_addxexceptionrefs(mcodeptr);
+                       codegen_addxexceptionrefs(cd, mcodeptr);
                        break;
 
                case ICMD_MULTIANEWARRAY:/* ..., cnt1, [cnt2, ...] ==> ..., arrayref  */
@@ -3574,32 +3435,32 @@ makeactualcall:
                        for (s1 = iptr->op1; --s1 >= 0; src = src->prev) {
                                var_to_reg_int(s2, src, REG_ITMP1);
                                M_BLTZ(s2, 0);
-                               codegen_addxcheckarefs(mcodeptr);
+                               codegen_addxcheckarefs(cd, mcodeptr);
 
                                /* copy sizes to stack (argument numbers >= INT_ARG_CNT)      */
 
                                if (src->varkind != ARGVAR) {
                                        M_LST(s2, REG_SP, 8 * (s1 + INT_ARG_CNT));
-                                       }
                                }
+                       }
 
                        /* a0 = dimension count */
 
-                       ICONST(r->argintregs[0], iptr->op1);
+                       ICONST(rd->argintregs[0], iptr->op1);
 
                        /* a1 = arraydescriptor */
 
-                       a = dseg_addaddress(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((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 - mcodebase);
+                       s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
                        if (s1 <= 32768)
                                M_LDA(REG_PV, REG_RA, -s1);
                        else {
@@ -3608,11 +3469,14 @@ makeactualcall:
                                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);
        
@@ -3627,26 +3491,29 @@ makeactualcall:
        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);
                                        }
                                }
                        }
@@ -3655,23 +3522,24 @@ makeactualcall:
        } /* if (bptr -> flags >= BBREACHED) */
        } /* for basic block */
 
-       /* bptr -> mpc = (int)((u1*) mcodeptr - mcodebase); */
+       codegen_createlinenumbertable(cd);
 
        {
        /* generate bound check stubs */
 
        s4 *xcodeptr = NULL;
-       
-       for (; xboundrefs != NULL; xboundrefs = xboundrefs->next) {
-               gen_resolvebranch((u1*) mcodebase + xboundrefs->branchpos, 
-                                 xboundrefs->branchpos,
-                                                 (u1*) mcodeptr - mcodebase);
+       branchref *bref;
+
+       for (bref = cd->xboundrefs; bref != NULL; bref = bref->next) {
+               gen_resolvebranch((u1*) cd->mcodebase + bref->branchpos, 
+                                 bref->branchpos,
+                                                 (u1*) mcodeptr - cd->mcodebase);
 
                MCODECHECK(8);
 
                /* move index register into REG_ITMP1 */
-               M_MOV(xboundrefs->reg, REG_ITMP1);
-               M_LDA(REG_ITMP2_XPC, REG_PV, xboundrefs->branchpos - 4);
+               M_MOV(bref->reg, REG_ITMP1);
+               M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
 
                if (xcodeptr != NULL) {
                        M_BR(xcodeptr - mcodeptr - 1);
@@ -3679,36 +3547,20 @@ makeactualcall:
                } else {
                        xcodeptr = mcodeptr;
 
-                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
-                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
-
-                       a = dseg_addaddress(string_java_lang_ArrayIndexOutOfBoundsException);
-                       M_ALD(r->argintregs[0], REG_PV, a);
-                       M_MOV(REG_ITMP1, r->argintregs[1]);
-
-                       a = dseg_addaddress(new_exception_int);
-                       M_ALD(REG_PV, REG_PV, a);
-                       M_JSR(REG_RA, REG_PV);
-
-                       /* recompute pv */
-                       s1 = (s4) ((u1 *) mcodeptr - 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(cd, asm_throw_and_handle_arrayindexoutofbounds_exception);
+                        M_ALD(REG_PV, REG_PV, a);
 
-                       a = dseg_addaddress(asm_handle_exception);
-                       M_ALD(REG_ITMP3, REG_PV, a);
+                        M_JSR(REG_RA, REG_PV);
 
-                       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);
+                        }
                }
        }
 
@@ -3716,21 +3568,21 @@ makeactualcall:
 
        xcodeptr = NULL;
        
-       for (; xcheckarefs != NULL; xcheckarefs = xcheckarefs->next) {
-               if ((m->exceptiontablelength == 0) && (xcodeptr != NULL)) {
-                       gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos, 
-                                                         xcheckarefs->branchpos,
-                                                         (u1*) xcodeptr - (u1*) mcodebase - 4);
+       for (bref = cd->xcheckarefs; bref != NULL; bref = bref->next) {
+               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+                       gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
+                                                         bref->branchpos,
+                                                         (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
                        continue;
                }
 
-               gen_resolvebranch((u1*) mcodebase + xcheckarefs->branchpos, 
-                                 xcheckarefs->branchpos,
-                                                 (u1*) mcodeptr - mcodebase);
+               gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
+                                 bref->branchpos,
+                                                 (u1 *) mcodeptr - cd->mcodebase);
 
                MCODECHECK(8);
 
-               M_LDA(REG_ITMP2_XPC, REG_PV, xcheckarefs->branchpos - 4);
+               M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
 
                if (xcodeptr != NULL) {
                        M_BR(xcodeptr - mcodeptr - 1);
@@ -3738,18 +3590,17 @@ makeactualcall:
                } else {
                        xcodeptr = mcodeptr;
 
-                       M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
-                       M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
-
-                       a = dseg_addaddress(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(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 - mcodebase);
+                       s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
                        if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
                        else {
                                s4 ml = -s1, mh = 0;
@@ -3758,15 +3609,7 @@ makeactualcall:
                                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(asm_handle_exception);
-                       M_ALD(REG_ITMP3, REG_PV, a);
-
-                       M_JMP(REG_ZERO, REG_ITMP3);
                }
        }
 
@@ -3774,21 +3617,21 @@ makeactualcall:
 
        xcodeptr = NULL;
        
-       for (; xcastrefs != NULL; xcastrefs = xcastrefs->next) {
-               if ((m->exceptiontablelength == 0) && (xcodeptr != NULL)) {
-                       gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos, 
-                                                         xcastrefs->branchpos,
-                                                         (u1*) xcodeptr - (u1*) mcodebase - 4);
+       for (bref = cd->xcastrefs; bref != NULL; bref = bref->next) {
+               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+                       gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
+                                                         bref->branchpos,
+                                                         (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
                        continue;
                }
 
-               gen_resolvebranch((u1*) mcodebase + xcastrefs->branchpos, 
-                                 xcastrefs->branchpos,
-                                                 (u1*) mcodeptr - mcodebase);
+               gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
+                                 bref->branchpos,
+                                                 (u1 *) mcodeptr - cd->mcodebase);
 
                MCODECHECK(8);
 
-               M_LDA(REG_ITMP2_XPC, REG_PV, xcastrefs->branchpos - 4);
+               M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
 
                if (xcodeptr != NULL) {
                        M_BR(xcodeptr - mcodeptr - 1);
@@ -3796,35 +3639,24 @@ makeactualcall:
                } 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(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(new_exception);
-                       M_ALD(REG_PV, REG_PV, a);
-                       M_JSR(REG_RA, REG_PV);
-
-                       /* recompute pv */
-                       s1 = (s4) ((u1 *) mcodeptr - 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);
+                        M_JSR(REG_RA, REG_PV);
 
-                       a = dseg_addaddress(asm_handle_exception);
-                       M_ALD(REG_ITMP3, REG_PV, a);
+                        /* 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);
                }
        }
 
@@ -3832,21 +3664,21 @@ makeactualcall:
 
        xcodeptr = NULL;
 
-       for (; xexceptionrefs != NULL; xexceptionrefs = xexceptionrefs->next) {
-               if ((m->exceptiontablelength == 0) && (xcodeptr != NULL)) {
-                       gen_resolvebranch((u1*) mcodebase + xexceptionrefs->branchpos,
-                                                         xexceptionrefs->branchpos,
-                                                         (u1*) xcodeptr - (u1*) mcodebase - 4);
+       for (bref = cd->xexceptionrefs; bref != NULL; bref = bref->next) {
+               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+                       gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos,
+                                                         bref->branchpos,
+                                                         (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
                        continue;
                }
 
-               gen_resolvebranch((u1*) mcodebase + xexceptionrefs->branchpos, 
-                                 xexceptionrefs->branchpos,
-                                                 (u1*) mcodeptr - mcodebase);
+               gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
+                                 bref->branchpos,
+                                                 (u1 *) mcodeptr - cd->mcodebase);
 
                MCODECHECK(8);
 
-               M_LDA(REG_ITMP2_XPC, REG_PV, xexceptionrefs->branchpos - 4);
+               M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
 
                if (xcodeptr != NULL) {
                        M_BR(xcodeptr - mcodeptr - 1);
@@ -3858,12 +3690,12 @@ makeactualcall:
                        M_LSUB_IMM(REG_SP, 1 * 8, REG_SP);
                        M_LST(REG_ITMP2_XPC, REG_SP, 0 * 8);
 
-                       a = dseg_addaddress(&builtin_get_exceptionptrptr);
+                       a = dseg_addaddress(cd, &builtin_get_exceptionptrptr);
                        M_ALD(REG_PV, REG_PV, a);
                        M_JSR(REG_RA, REG_PV);
 
                        /* recompute pv */
-                       s1 = (s4) ((u1 *) mcodeptr - mcodebase);
+                       s1 = (s4) ((u1 *) mcodeptr - cd->mcodebase);
                        if (s1 <= 32768) M_LDA(REG_PV, REG_RA, -s1);
                        else {
                                s4 ml = -s1, mh = 0;
@@ -3878,16 +3710,27 @@ makeactualcall:
                        M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
                        M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
 #else
-                       a = dseg_addaddress(&_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(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);
                }
        }
 
@@ -3895,21 +3738,21 @@ makeactualcall:
 
        xcodeptr = NULL;
 
-       for (; xnullrefs != NULL; xnullrefs = xnullrefs->next) {
-               if ((m->exceptiontablelength == 0) && (xcodeptr != NULL)) {
-                       gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos, 
-                                                         xnullrefs->branchpos,
-                                                         (u1*) xcodeptr - (u1*) mcodebase - 4);
+       for (bref = cd->xnullrefs; bref != NULL; bref = bref->next) {
+               if ((cd->exceptiontablelength == 0) && (xcodeptr != NULL)) {
+                       gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
+                                                         bref->branchpos,
+                                                         (u1 *) xcodeptr - (u1 *) cd->mcodebase - 4);
                        continue;
                }
 
-               gen_resolvebranch((u1*) mcodebase + xnullrefs->branchpos, 
-                                 xnullrefs->branchpos,
-                                                 (u1*) mcodeptr - mcodebase);
+               gen_resolvebranch((u1 *) cd->mcodebase + bref->branchpos, 
+                                 bref->branchpos,
+                                                 (u1 *) mcodeptr - cd->mcodebase);
 
                MCODECHECK(8);
 
-               M_LDA(REG_ITMP2_XPC, REG_PV, xnullrefs->branchpos - 4);
+               M_LDA(REG_ITMP2_XPC, REG_PV, bref->branchpos - 4);
 
                if (xcodeptr != NULL) {
                        M_BR(xcodeptr - mcodeptr - 1);
@@ -3917,40 +3760,70 @@ makeactualcall:
                } 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(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(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 - 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);
+       /* generate put/getstatic stub call code */
 
-                       M_LLD(REG_ITMP2_XPC, REG_SP, 0 * 8);
-                       M_LADD_IMM(REG_SP, 1 * 8, REG_SP);
+       {
+               clinitref   *cref;
+               u4           mcode;
+               s4          *tmpmcodeptr;
 
-                       a = dseg_addaddress(asm_handle_exception);
-                       M_ALD(REG_ITMP3, REG_PV, a);
+               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 - mcodebase));
+       codegen_finish(m, cd, (s4) ((u1 *) mcodeptr - cd->mcodebase));
 }
 
 
@@ -4001,18 +3874,36 @@ void removecompilerstub(u1 *stub)
 
 *******************************************************************************/
 
+
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+#define NATIVESTUB_STACK          8/*ra,native result, oldThreadspecificHeadValue, addressOfThreadspecificHead, method, 0,0,ra*/
+#define NATIVESTUB_THREAD_EXTRA    (6 + 20) /*20 for additional frame creation*/
+#define NATIVESTUB_STACKTRACE_OFFSET   1
+#else
+#define NATIVESTUB_STACK          7/*ra,oldThreadspecificHeadValue, addressOfThreadspecificHead, method, 0,0,ra*/
+#define NATIVESTUB_THREAD_EXTRA    (1 + 20) /*20 for additional frame creation*/
+#define NATIVESTUB_STACKTRACE_OFFSET   0
+#endif
+
+#define NATIVESTUB_SIZE           (44 + NATIVESTUB_THREAD_EXTRA - 1)
+#define NATIVESTUB_STATIC_SIZE         5
+#define NATIVESTUB_VERBOSE_SIZE        (39 + 13)
+#define NATIVESTUB_OFFSET         11
+
+#if 0
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-#define NATIVESTUBSTACK          2
-#define NATIVESTUBTHREADEXTRA    6
+#define NATIVESTUB_STACK           2
+#define NATIVESTUB_THREAD_EXTRA    6
 #else
-#define NATIVESTUBSTACK          1
-#define NATIVESTUBTHREADEXTRA    1
+#define NATIVESTUB_STACK           1
+#define NATIVESTUB_THREAD_EXTRA    1
 #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     4
+#define NATIVESTUB_VERBOSE_SIZE    (39 + 13)
+#define NATIVESTUB_OFFSET          10
+#endif
 
 u1 *createnativestub(functionptr f, methodinfo *m)
 {
@@ -4022,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;
+
+       /* mark start of dump memory area */
+
+       dumpsize = dump_size();
+
+       /* setup registers before using it */
 
-       /* keep code size smaller */
-       reg_init(m);
-       r = m->registerdata;
+       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            */
 
-       *(cs-1) = (u8) f;                   /* address of native method           */
+       /* 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           */
 #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));
@@ -4082,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 */
@@ -4091,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++) {
@@ -4120,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);
                        }
                }
 
@@ -4153,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                 */
@@ -4215,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;
@@ -4230,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);
@@ -4251,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);
 }