* src/mm/memory.cpp,
[cacao.git] / src / vm / jit / allocator / simplereg.c
index b6a2d245be75fa465117a3b5e6777a1d1498a0e2..f3390ba045c9e96125824b126f2ad9b2ab5b3900 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/allocator/simplereg.c - register allocator
 
-   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
-   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
-   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
-   Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
-
-   Authors: Andreas Krall
-
-   Changes: Stefan Ring
-            Christian Thalinger
-            Christian Ullrich
-            Michael Starzinger
-            Edwin Steiner
-
-   $Id: simplereg.c 5789 2006-10-16 09:02:40Z twisti $
-
 */
 
 
 #include "config.h"
-#include "vm/types.h"
 
 #include <assert.h>
+#include <stdint.h>
+
+#include "vm/types.h"
 
 #include "arch.h"
 #include "md-abi.h"
 
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "mm/memory.h"
-#include "vm/method.h"
+#include "mm/memory.hpp"
+
+#include "vm/jit/builtin.hpp"
+#include "vm/exceptions.hpp"
+#include "vm/method.hpp"
 #include "vm/options.h"
-#include "vm/resolve.h"
-#include "vm/stringlocal.h"
+#include "vm/resolve.hpp"
+#include "vm/string.hpp"
+
+#include "vm/jit/abi.h"
 #include "vm/jit/reg.h"
+#include "vm/jit/show.hpp"
 #include "vm/jit/allocator/simplereg.h"
-#include "vm/jit/show.h"
 
 
 #if 0
@@ -71,6 +62,11 @@ static void simplereg_allocate_locals(jitdata *jd);
 static void simplereg_allocate_temporaries(jitdata *jd);
 
 
+/* size of a stackslot used by the internal ABI */
+
+#define SIZE_OF_STACKSLOT 8
+
+
 /* total number of registers */
 
 #if defined(HAS_ADDRESS_REGISTER_FILE)
@@ -165,7 +161,7 @@ static void simplereg_allocate_temporaries(jitdata *jd);
 #define AVAIL_FREE_TMP_INT  AVAIL_BACK_INT(rd->freetmpinttop)
 #define AVAIL_FREE_SAV_INT  AVAIL_BACK_INT(rd->freesavinttop)
 
-#define TAKE_ARG_FLT(r)  POP_FRONT(rd->argfltregs, rd->argfltreguse, r)
+#define TAKE_ARG_FLT(r)  POP_FRONT(abi_registers_float_argument, rd->argfltreguse, r)
 #define TAKE_TMP_FLT(r)  POP_BACK(rd->tmpfltregs, rd->tmpfltreguse, r)
 #define TAKE_SAV_FLT(r)  POP_BACK(rd->savfltregs, rd->savfltreguse, r)
 
@@ -173,7 +169,7 @@ static void simplereg_allocate_temporaries(jitdata *jd);
 #define TAKE_TMP_ADR(r)  POP_BACK(rd->tmpadrregs, rd->tmpadrreguse, r)
 #define TAKE_SAV_ADR(r)  POP_BACK(rd->savadrregs, rd->savadrreguse, r)
 
-#define TAKE_ARG_INT(r)  POP_FRONT_INT(rd->argintregs, rd->argintreguse, r)
+#define TAKE_ARG_INT(r)  POP_FRONT_INT(abi_registers_integer_argument, rd->argintreguse, r)
 #define TAKE_TMP_INT(r)  POP_BACK_INT(rd->tmpintregs, rd->tmpintreguse, r)
 #define TAKE_SAV_INT(r)  POP_BACK_INT(rd->savintregs, rd->savintreguse, r)
 
@@ -206,45 +202,13 @@ static void simplereg_allocate_temporaries(jitdata *jd);
 
 #define NEW_MEM_SLOT(r)                                              \
     do {                                                             \
-        (r) = rd->memuse;                                            \
-        rd->memuse += memneeded + 1;                                 \
-    } while (0)
-
-#define NEW_MEM_SLOT_ALIGNED(r)                                      \
-    do {                                                             \
-        if ( (memneeded) && (rd->memuse & 1))                        \
-            rd->memuse++;                                            \
-        (r) = rd->memuse;                                            \
-        rd->memuse += memneeded + 1;                                 \
-    } while (0)
-
-#define NEW_MEM_SLOT_ALIGNED_REUSE_PADDING(r)                        \
-    do {                                                             \
-        if ( (memneeded) && (rd->memuse & 1)) {                      \
-                       PUSH_BACK(rd->freemem, rd->freememtop, rd->memuse);      \
-            rd->memuse++;                                            \
-               }                                                            \
-        (r) = rd->memuse;                                            \
-        rd->memuse += memneeded + 1;                                 \
+        (r) = rd->memuse * SIZE_OF_STACKSLOT;                        \
+        rd->memuse += 1;                                             \
     } while (0)
 
-#if defined(ALIGN_LONGS_IN_MEMORY)
-#define NEW_MEM_SLOT_INT_LNG(r)  NEW_MEM_SLOT_ALIGNED(r)
-#else
 #define NEW_MEM_SLOT_INT_LNG(r)  NEW_MEM_SLOT(r)
-#endif
-
-#if defined(ALIGN_DOUBLES_IN_MEMORY)
-#define NEW_MEM_SLOT_FLT_DBL(r)  NEW_MEM_SLOT_ALIGNED(r)
-#else
 #define NEW_MEM_SLOT_FLT_DBL(r)  NEW_MEM_SLOT(r)
-#endif
-
-#if defined(ALIGN_LONGS_IN_MEMORY) || defined(ALIGN_DOUBLES_IN_MEMORY)
-#define NEW_MEM_SLOT_REUSE_PADDING(r)  NEW_MEM_SLOT_ALIGNED_REUSE_PADDING(r)
-#else
 #define NEW_MEM_SLOT_REUSE_PADDING(r)  NEW_MEM_SLOT(r)
-#endif
 
 
 /* macros for creating/freeing temporary variables ***************************/
@@ -282,9 +246,9 @@ static void simplereg_allocate_temporaries(jitdata *jd);
 /* regalloc ********************************************************************
 
    Does a simple register allocation.
-       
+
 *******************************************************************************/
-       
+
 bool regalloc(jitdata *jd)
 {
        /* There is a problem with the use of unused float argument
@@ -308,21 +272,21 @@ bool regalloc(jitdata *jd)
 /* simplereg_allocate_interfaces ***********************************************
 
    Allocates registers for all interface variables.
-       
+
 *******************************************************************************/
-       
+
 static void simplereg_allocate_interfaces(jitdata *jd)
 {
        methodinfo   *m;
+       codeinfo     *code;
        codegendata  *cd;
        registerdata *rd;
 
        int     s, t, tt, saved;
        int     intalloc, fltalloc; /* Remember allocated Register/Memory offset */
                        /* in case more vars are packed into this interface slot */
-       int             memneeded = 0;
-       /* Allocate LNG and DBL types first to ensure 2 memory slots or          */
-       /* registers on HAS_4BYTE_STACKSLOT architectures.                       */
+       /* Allocate LNG and DBL types first to ensure 2 registers                */
+       /* on some architectures.                                                */
        int     typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
        int     flags, regoff;
 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
@@ -331,22 +295,23 @@ static void simplereg_allocate_interfaces(jitdata *jd)
 
        /* get required compiler data */
 
-       m  = jd->m;
-       cd = jd->cd;
-       rd = jd->rd;
+       m    = jd->m;
+       code = jd->code;
+       cd   = jd->cd;
+       rd   = jd->rd;
 
        /* rd->memuse was already set in stack.c to allocate stack space
           for passing arguments to called methods. */
 
 #if defined(__I386__)
-       if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
+       if (checksync && code_is_synchronized(code)) {
                /* reserve 0(%esp) for Monitorenter/exit Argument on i386 */
                if (rd->memuse < 1)
                        rd->memuse = 1;
        }
 #endif
 
-       if (jd->isleafmethod) {
+       if (code_is_leafmethod(code)) {
                /* Reserve argument register, which will be used for Locals acting */
                /* as Parameters */
                if (rd->argintreguse < m->parseddesc->argintreguse)
@@ -359,7 +324,7 @@ static void simplereg_allocate_interfaces(jitdata *jd)
 #endif
        }
 
-       for (s = 0; s < cd->maxstack; s++) {
+       for (s = 0; s < jd->maxinterfaces; s++) {
                intalloc = -1; fltalloc = -1;
 
                /* check if the interface at this stack depth must be a SAVEDVAR */
@@ -386,14 +351,10 @@ static void simplereg_allocate_interfaces(jitdata *jd)
                        intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
 #endif
 
-#if defined(HAS_4BYTE_STACKSLOT)
-                       memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
-#endif
-
                        if (!saved) {
 #if defined(HAS_ADDRESS_REGISTER_FILE)
                                if (IS_ADR_TYPE(t)) {
-                                       if (!jd->isleafmethod && AVAIL_ARG_ADR) {
+                                       if (!code_is_leafmethod(code) && AVAIL_ARG_ADR) {
                                                flags |= ARGREG;
                                                TAKE_ARG_ADR(regoff);
                                        } 
@@ -406,7 +367,7 @@ static void simplereg_allocate_interfaces(jitdata *jd)
                                        } 
                                        else {
                                                flags |= INMEMORY;
-                                               regoff = rd->memuse++;
+                                               regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
                                        }                                               
                                } 
                                else /* !IS_ADR_TYPE */
@@ -436,7 +397,7 @@ static void simplereg_allocate_interfaces(jitdata *jd)
                                                fltalloc = s * 5 + t;
                                        }
                                        else { /* !IS_FLT_DBL_TYPE(t) */
-#if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
+#if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
                                                /*
                                                 * for i386 put all longs in memory
                                                 */
@@ -445,7 +406,7 @@ static void simplereg_allocate_interfaces(jitdata *jd)
                                                        NEW_MEM_SLOT_INT_LNG(regoff);
                                                } 
                                                else
-#endif /* defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE...GISTERS) */
+#endif
                                                        if (intalloc >= 0) {
                                                                /* Reuse memory slot(s)/register(s) for shared interface slots */
                                                                flags |= jd->interface_map[intalloc].flags & ~SAVEDVAR;
@@ -488,7 +449,7 @@ static void simplereg_allocate_interfaces(jitdata *jd)
                                        }
                                        else {
                                                flags |= INMEMORY;
-                                               regoff = rd->memuse++;
+                                               regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
                                        }                                               
                                } 
                                else
@@ -511,7 +472,7 @@ static void simplereg_allocate_interfaces(jitdata *jd)
                                                fltalloc = s * 5 + t;
                                        }
                                        else { /* IS_INT_LNG */
-#if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
+#if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
                                                /*
                                                 * for i386 put all longs in memory
                                                 */
@@ -559,9 +520,9 @@ static void simplereg_allocate_interfaces(jitdata *jd)
 /* simplereg_allocate_locals_leafmethod ****************************************
 
    Allocates registers for all local variables of a leafmethod.
-       
+
 *******************************************************************************/
-       
+
 static void simplereg_allocate_locals_leafmethod(jitdata *jd)
 {
        methodinfo   *m;
@@ -569,11 +530,10 @@ static void simplereg_allocate_locals_leafmethod(jitdata *jd)
        registerdata *rd;
        methoddesc *md;
 
-       int     p, s, t, tt, lm;
+       int     p, s, t, tt, varindex;
        int     intalloc, fltalloc;
        varinfo *v;
        int     intregsneeded = 0;
-       int     memneeded = 0;
        int     typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
        int     fargcnt, iargcnt;
 #ifdef HAS_ADDRESS_REGISTER_FILE
@@ -593,22 +553,19 @@ static void simplereg_allocate_locals_leafmethod(jitdata *jd)
 #ifdef HAS_ADDRESS_REGISTER_FILE
        aargcnt = rd->argadrreguse;
 #endif
-       for (p = 0, s = 0; s < cd->maxlocals; s++, p++) {
+       for (p = 0, s = 0; s < jd->maxlocals; s++, p++) {
                intalloc = -1; fltalloc = -1;
                for (tt = 0; tt <= 4; tt++) {
                        t = typeloop[tt];
-                       lm = jd->local_map[s * 5 + t];
-                       if (lm == UNUSED)
+                       varindex = jd->local_map[s * 5 + t];
+                       if (varindex == UNUSED)
                                continue;
 
-                       v = VAR(lm);
+                       v = VAR(varindex);
 
 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
                        intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
 #endif
-#if defined(HAS_4BYTE_STACKSLOT)
-                       memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
-#endif
 
                        /*
                         *  The order of
@@ -650,7 +607,7 @@ static void simplereg_allocate_locals_leafmethod(jitdata *jd)
                                }
                                else {
                                        v->flags |= INMEMORY;
-                                       v->vv.regoff = rd->memuse++;
+                                       v->vv.regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
                                }                                               
                        } 
                        else {
@@ -663,11 +620,9 @@ static void simplereg_allocate_locals_leafmethod(jitdata *jd)
 #if !defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
                                        /* We can only use float arguments as local variables,
                                         * if we do not pass them in integer registers. */
-                                       else if ((p < md->paramcount) &&
-                                                        !md->params[p].inmemory) 
-                                       {
+                                       else if ((p < md->paramcount) && !md->params[p].inmemory) {
                                                v->flags = 0;
-                                               v->vv.regoff = rd->argfltregs[md->params[p].regoff];
+                                               v->vv.regoff = md->params[p].regoff;
                                        }
 #endif
                                        else if (AVAIL_TMP_FLT) {
@@ -675,11 +630,10 @@ static void simplereg_allocate_locals_leafmethod(jitdata *jd)
                                                TAKE_TMP_FLT(v->vv.regoff);
                                        }
                                        /* use unused argument registers as local registers */
-                                       else if ((p >= md->paramcount) &&
-                                                        (fargcnt < FLT_ARG_CNT)) 
-                                       {
+                                       else if ((p >= md->paramcount) && (fargcnt < FLT_ARG_CNT)) {
                                                v->flags = 0;
-                                               POP_FRONT(rd->argfltregs, fargcnt, v->vv.regoff);
+                                               POP_FRONT(abi_registers_float_argument,
+                                                                 fargcnt, v->vv.regoff);
                                        }
                                        else if (AVAIL_SAV_FLT) {
                                                v->flags = 0;
@@ -693,7 +647,7 @@ static void simplereg_allocate_locals_leafmethod(jitdata *jd)
 
                                } 
                                else {
-#if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
+#if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
                                        /*
                                         * for i386 put all longs in memory
                                         */
@@ -721,13 +675,12 @@ static void simplereg_allocate_locals_leafmethod(jitdata *jd)
                                                        v->flags = 0;
 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
                                                        if (IS_2_WORD_TYPE(t))
-                                                               v->vv.regoff = PACK_REGS(
-                                               rd->argintregs[GET_LOW_REG(md->params[p].regoff)],
-                                               rd->argintregs[GET_HIGH_REG(md->params[p].regoff)]);
+                                                               v->vv.regoff =
+                                                                       PACK_REGS(GET_LOW_REG(md->params[p].regoff),
+                                                                                         GET_HIGH_REG(md->params[p].regoff));
                                                                else
 #endif
-                                                                       v->vv.regoff =
-                                                                          rd->argintregs[md->params[p].regoff];
+                                                                       v->vv.regoff = md->params[p].regoff;
                                                }
                                                else if (AVAIL_TMP_INT) {
                                                        v->flags = 0;
@@ -740,7 +693,8 @@ static void simplereg_allocate_locals_leafmethod(jitdata *jd)
                                                                 (iargcnt + intregsneeded < INT_ARG_CNT)) 
                                                {
                                                        v->flags = 0;
-                                                       POP_FRONT_INT(rd->argintregs, iargcnt, v->vv.regoff);
+                                                       POP_FRONT_INT(abi_registers_integer_argument,
+                                                                                 iargcnt, v->vv.regoff);
                                                }
                                                else if (AVAIL_SAV_INT) {
                                                        v->flags = 0;
@@ -770,18 +724,18 @@ static void simplereg_allocate_locals_leafmethod(jitdata *jd)
 /* simplereg_allocate_locals ***************************************************
 
    Allocates registers for all local variables.
-       
+
 *******************************************************************************/
-       
+
 static void simplereg_allocate_locals(jitdata *jd)
 {
+       codeinfo     *code;
        codegendata  *cd;
        registerdata *rd;
 
-       int     s, t, tt, lm;
+       int     s, t, tt, varindex;
        int     intalloc, fltalloc;
        varinfo *v;
-       int     memneeded = 0;
        int     typeloop[] = { TYPE_LNG, TYPE_DBL, TYPE_INT, TYPE_FLT, TYPE_ADR };
 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
        s4 intregsneeded;
@@ -789,33 +743,30 @@ static void simplereg_allocate_locals(jitdata *jd)
 
        /* get required compiler data */
 
-       cd = jd->cd;
-       rd = jd->rd;
+       code = jd->code;
+       cd   = jd->cd;
+       rd   = jd->rd;
 
-       if (jd->isleafmethod) {
+       if (code_is_leafmethod(code)) {
                simplereg_allocate_locals_leafmethod(jd);
                return;
        }
 
-       for (s = 0; s < cd->maxlocals; s++) {
+       for (s = 0; s < jd->maxlocals; s++) {
                intalloc = -1; fltalloc = -1;
                for (tt=0; tt<=4; tt++) {
                        t = typeloop[tt];
 
-                       lm = jd->local_map[s * 5 + t];
-                       if (lm == UNUSED)
+                       varindex = jd->local_map[s * 5 + t];
+                       if (varindex == UNUSED)
                                continue;
 
-                       v = VAR(lm);
+                       v = VAR(varindex);
 
 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
                                intregsneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
 #endif
 
-#if defined(HAS_4BYTE_STACKSLOT)
-                               memneeded = (IS_2_WORD_TYPE(t)) ? 1 : 0;
-#endif
-
 #ifdef HAS_ADDRESS_REGISTER_FILE
                                if (IS_ADR_TYPE(t)) {
                                        if (AVAIL_SAV_ADR) {
@@ -824,7 +775,7 @@ static void simplereg_allocate_locals(jitdata *jd)
                                        }
                                        else {
                                                v->flags = INMEMORY;
-                                               v->vv.regoff = rd->memuse++;
+                                               v->vv.regoff = rd->memuse++ * SIZE_OF_STACKSLOT;
                                        }
                                } 
                                else {
@@ -845,7 +796,7 @@ static void simplereg_allocate_locals(jitdata *jd)
                                        fltalloc = jd->local_map[s * 5 + t];
                                }
                                else {
-#if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
+#if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
                                        /*
                                         * for i386 put all longs in memory
                                         */
@@ -874,7 +825,7 @@ static void simplereg_allocate_locals(jitdata *jd)
                                                        v->flags = INMEMORY;
                                                        NEW_MEM_SLOT_INT_LNG(v->vv.regoff);
                                                }
-#if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
+#if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
                                        }
 #endif
                                        intalloc = jd->local_map[s * 5 + t];
@@ -892,9 +843,6 @@ static void simplereg_init(jitdata *jd, registerdata *rd)
        int i;
 
        rd->freememtop = 0;
-#if defined(HAS_4BYTE_STACKSLOT)
-       rd->freememtop_2 = 0;
-#endif
 
        rd->freetmpinttop = 0;
        rd->freesavinttop = 0;
@@ -928,14 +876,14 @@ static void simplereg_init(jitdata *jd, registerdata *rd)
        /* record the interface registers as used */
 
        for (i=0; i<rd->argintreguse; ++i)
-               rd->intusedinout[rd->argintregs[i]] = 1;
+               rd->intusedinout[abi_registers_integer_argument[i]] = 1;
        for (i=rd->tmpintreguse; i<INT_TMP_CNT; ++i)
                rd->intusedinout[rd->tmpintregs[i]] = 1;
        for (i=rd->savintreguse; i<INT_SAV_CNT; ++i)
                rd->intusedinout[rd->savintregs[i]] = 1;
 
        for (i=0; i<rd->argfltreguse; ++i)
-               rd->fltusedinout[rd->argfltregs[i]] = 1;
+               rd->fltusedinout[abi_registers_float_argument[i]] = 1;
        for (i=rd->tmpfltreguse; i<FLT_TMP_CNT; ++i)
                rd->fltusedinout[rd->tmpfltregs[i]] = 1;
        for (i=rd->savfltreguse; i<FLT_SAV_CNT; ++i)
@@ -1009,7 +957,6 @@ static void simplereg_new_temp(jitdata *jd, s4 index)
 #ifdef SUPPORT_COMBINE_INTEGER_REGISTERS
        s4 intregsneeded;
 #endif
-       s4 memneeded;
        s4 tryagain;
        registerdata *rd;
        varinfo      *v;
@@ -1017,6 +964,10 @@ static void simplereg_new_temp(jitdata *jd, s4 index)
        rd = jd->rd;
        v = VAR(index);
 
+       /* assert that constants are not allocated */
+
+       assert(v->type != TYPE_RET);
+
        /* Try to allocate a saved register if there is no temporary one          */
        /* available. This is what happens during the second run.                 */
        tryagain = (v->flags & SAVEDVAR) ? 1 : 2;
@@ -1025,12 +976,6 @@ static void simplereg_new_temp(jitdata *jd, s4 index)
        intregsneeded = (IS_2_WORD_TYPE(v->type)) ? 1 : 0;
 #endif
 
-#if defined(HAS_4BYTE_STACKSLOT)
-       memneeded = (IS_2_WORD_TYPE(v->type)) ? 1 : 0;
-#else
-       memneeded = 0;
-#endif
-
        for(; tryagain; --tryagain) {
                if (tryagain == 1) {
                        if (!(v->flags & SAVEDVAR))
@@ -1060,7 +1005,7 @@ static void simplereg_new_temp(jitdata *jd, s4 index)
                                        }
                                } 
                                else {
-#if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
+#if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
                                        /*
                                         * for i386 put all longs in memory
                                         */
@@ -1116,7 +1061,7 @@ static void simplereg_new_temp(jitdata *jd, s4 index)
 
                                } 
                                else {
-#if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
+#if (SIZEOF_VOID_P == 4) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
                                        /*
                                         * for i386 put all longs in memory
                                         */
@@ -1151,30 +1096,31 @@ static void simplereg_new_temp(jitdata *jd, s4 index)
 
        v->flags |= INMEMORY;
 
-#if defined(HAS_4BYTE_STACKSLOT)
-       if ((memneeded == 1) && (rd->freememtop_2 > 0))
-               POP_BACK(rd->freemem_2, rd->freememtop_2, v->vv.regoff);
+       if (rd->freememtop > 0)
+               POP_BACK(rd->freemem, rd->freememtop, v->vv.regoff);
        else
-#endif /*defined(HAS_4BYTE_STACKSLOT) */
-               if ((memneeded == 0) && (rd->freememtop > 0))
-                       POP_BACK(rd->freemem, rd->freememtop, v->vv.regoff);
-               else
-                       NEW_MEM_SLOT_REUSE_PADDING(v->vv.regoff);
+               NEW_MEM_SLOT_REUSE_PADDING(v->vv.regoff);
 }
 
 
 static void simplereg_free(registerdata *rd, s4 flags, s4 regoff, s4 type)
 {
-       /* if this is a copy of another variable, just decrement the copy counter */
+       /* assert that constants are not freed */
+
+       assert(type != TYPE_RET);
 
-       /* XXX split reg/mem variables on arm may need special handling here */
+       /* if this is a copy of another variable, just decrement the copy counter */
 
        if (flags & INMEMORY) {
+               int32_t memindex;
+
                if (flags & INOUT)
                        return;
 
-               if (regoff < rd->memcopycountsize && rd->memcopycount[regoff]) {
-                       rd->memcopycount[regoff]--;
+               memindex = regoff / SIZE_OF_STACKSLOT;
+
+               if (memindex < rd->memcopycountsize && rd->memcopycount[memindex]) {
+                       rd->memcopycount[memindex]--;
                        return;
                }
        }
@@ -1201,13 +1147,7 @@ static void simplereg_free(registerdata *rd, s4 flags, s4 regoff, s4 type)
        }
 
        if (flags & INMEMORY) {
-#if defined(HAS_4BYTE_STACKSLOT)
-               if (IS_2_WORD_TYPE(type))
-                       PUSH_BACK(rd->freemem_2, rd->freememtop_2, regoff);
-               else 
-#endif
-                       PUSH_BACK(rd->freemem, rd->freememtop, regoff);
-
+               PUSH_BACK(rd->freemem, rd->freememtop, regoff);
                return;
        } 
 
@@ -1336,7 +1276,7 @@ static void simplereg_allocate_temporaries(jitdata *jd)
 
                        /* assert that all copy counts are zero */
 
-#if !defined(NDEBUG)
+#if !defined(NDEBUG) && !defined(ENABLE_SSA)
                        for (i=0; i < TOTAL_REG_CNT; ++i)
                                assert(rd->regcopycount[i] == 0);
 #endif
@@ -1350,6 +1290,8 @@ static void simplereg_allocate_temporaries(jitdata *jd)
                        for (i=0; i<bptr->indepth; ++i) 
                        {
                                v = VAR(bptr->invars[i]);
+                               if (v->type == TYPE_RET)
+                                       continue;
 
                                v->vv.regoff = jd->interface_map[5*i + v->type].regoff;
                                v->flags  = jd->interface_map[5*i + v->type].flags;
@@ -1363,6 +1305,8 @@ static void simplereg_allocate_temporaries(jitdata *jd)
                        for (i=0; i<bptr->outdepth; ++i) 
                        {
                                v = VAR(bptr->outvars[i]);
+                               if (v->type == TYPE_RET)
+                                       continue;
 
                                v->vv.regoff = jd->interface_map[5*i + v->type].regoff;
                                v->flags  = jd->interface_map[5*i + v->type].flags;
@@ -1376,7 +1320,7 @@ static void simplereg_allocate_temporaries(jitdata *jd)
 
                        /* free interface registers not used in this block */
 
-                       for (i=0; i < 5 * m->maxstack; ++i) {
+                       for (i=0; i < 5 * jd->maxinterfaces; ++i) {
                                type = i%5;
                                regoff = jd->interface_map[i].regoff;
                                flags = jd->interface_map[i].flags;
@@ -1409,10 +1353,6 @@ static void simplereg_allocate_temporaries(jitdata *jd)
                                        /* pop 0 push 0 */
 
                                case ICMD_JSR:
-#if !defined(NDEBUG)
-                                       /* avoid problems with show_allocation */
-                                       VAROP(iptr->dst)->vv.regoff = 0;
-#endif
                                case ICMD_NOP:
                                case ICMD_CHECKNULL:
                                case ICMD_IINC:
@@ -1422,7 +1362,7 @@ static void simplereg_allocate_temporaries(jitdata *jd)
                                case ICMD_PUTSTATICCONST:
                                case ICMD_INLINE_START:
                                case ICMD_INLINE_END:
-                               case ICMD_INLINE_GOTO:
+                               case ICMD_INLINE_BODY:
                                        break;
 
                                        /* pop 0 push 1 const */
@@ -1432,6 +1372,7 @@ static void simplereg_allocate_temporaries(jitdata *jd)
                                case ICMD_FCONST:
                                case ICMD_DCONST:
                                case ICMD_ACONST:
+                               case ICMD_GETEXCEPTION:
 
                                        /* pop 0 push 1 load */
                                        
@@ -1543,32 +1484,6 @@ static void simplereg_allocate_temporaries(jitdata *jd)
                                case ICMD_IF_LCMPGT:
                                case ICMD_IF_LCMPLE:
 
-                               case ICMD_IF_FCMPEQ:
-                               case ICMD_IF_FCMPNE:
-
-                               case ICMD_IF_FCMPL_LT:
-                               case ICMD_IF_FCMPL_GE:
-                               case ICMD_IF_FCMPL_GT:
-                               case ICMD_IF_FCMPL_LE:
-
-                               case ICMD_IF_FCMPG_LT:
-                               case ICMD_IF_FCMPG_GE:
-                               case ICMD_IF_FCMPG_GT:
-                               case ICMD_IF_FCMPG_LE:
-
-                               case ICMD_IF_DCMPEQ:
-                               case ICMD_IF_DCMPNE:
-
-                               case ICMD_IF_DCMPL_LT:
-                               case ICMD_IF_DCMPL_GE:
-                               case ICMD_IF_DCMPL_GT:
-                               case ICMD_IF_DCMPL_LE:
-
-                               case ICMD_IF_DCMPG_LT:
-                               case ICMD_IF_DCMPG_GE:
-                               case ICMD_IF_DCMPG_GT:
-                               case ICMD_IF_DCMPG_LE:
-
                                case ICMD_IF_ACMPEQ:
                                case ICMD_IF_ACMPNE:
 
@@ -1601,14 +1516,15 @@ static void simplereg_allocate_temporaries(jitdata *jd)
                                                v = VAROP(iptr->dst);
 
                                                if (v->flags & INMEMORY) {
-                                                       if (v->vv.regoff >= rd->memcopycountsize) {
-                                                               int newsize = (v->vv.regoff + 1) * 2;
+                                                       int32_t memindex = v->vv.regoff / SIZE_OF_STACKSLOT;
+                                                       if (memindex >= rd->memcopycountsize) {
+                                                               int newsize = (memindex + 1) * 2;
                                                                i = rd->memcopycountsize;
                                                                rd->memcopycount = DMREALLOC(rd->memcopycount, int, i, newsize);
                                                                MZERO(rd->memcopycount + i, int, newsize - i);
                                                                rd->memcopycountsize = newsize;
                                                        }
-                                                       rd->memcopycount[v->vv.regoff]++;
+                                                       rd->memcopycount[memindex]++;
                                                }
                                                else {
                                                        /* XXX split reg/mem variables on arm may need special handling here */
@@ -1791,9 +1707,8 @@ static void simplereg_allocate_temporaries(jitdata *jd)
                                        break;
 
                                default:
-                                       *exceptionptr =
-                                               new_internalerror("Unknown ICMD %d during register allocation",
-                                                                                 iptr->opc);
+                                       exceptions_throw_internalerror("Unknown ICMD %d during register allocation",
+                                                                                                  iptr->opc);
                                        return;
                                } /* switch */
                                iptr++;
@@ -1810,11 +1725,13 @@ void simplereg_make_statistics(jitdata *jd)
        methodinfo   *m;
        codegendata  *cd;
        registerdata *rd;
-       int i,type;
+       int i;
        s4 len;
-       stackptr    src, src_old;
-       stackptr    dst;
+#if 0
+       stackelement_t*    src, src_old;
+       stackelement_t*    dst;
        instruction *iptr;
+#endif
        basicblock  *bptr;
        int size_interface; /* == maximum size of in/out stack at basic block boundaries */
        bool in_register;