* show_icmd: Fixed ICMD_ARRAYCHECKCAST output.
[cacao.git] / src / vm / jit / stack.c
index 6bbefeb3a5f05c3a62bfdb173fe733588229f94f..ac85076d4b81a666bac592c23286c1baef2a71a2 100644 (file)
@@ -30,7 +30,7 @@
             Christian Thalinger
                        Christian Ullrich
 
-   $Id: stack.c 2952 2005-07-09 13:38:21Z twisti $
+   $Id: stack.c 3580 2005-11-05 17:57:09Z twisti $
 
 */
 
 #include <stdio.h>
 #include <string.h>
 
-#include "disass.h"
-#include "types.h"
+#include "vm/types.h"
+
+#include "arch.h"
 #include "md-abi.h"
-#include "codegen.h"
 
 #include "mm/memory.h"
 #include "native/native.h"
 #include "vm/stringlocal.h"
 #include "vm/tables.h"
 #include "vm/jit/codegen.inc.h"
+#include "vm/jit/disass.h"
 #include "vm/jit/jit.h"
 #include "vm/jit/reg.h"
 #include "vm/jit/stack.h"
 #include "vm/jit/lsra.h"
 
 
+/* global variables ***********************************************************/
+
+#if defined(USE_THREADS)
+static java_objectheader show_icmd_lock;
+#endif
+
+
+/* stack_init ******************************************************************
+
+   Initialized the stack analysis subsystem (called by jit_init).
+
+*******************************************************************************/
+
+bool stack_init(void)
+{
+#if defined(USE_THREADS)
+       /* initialize the show lock */
+
+       show_icmd_lock.monitorPtr = get_dummyLR();
+#endif
+
+       /* everything's ok */
+
+       return true;
+}
+
+
 /**********************************************************************/
 /* analyse_stack                                                      */
 /**********************************************************************/
@@ -228,10 +256,11 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                        bptr->indepth = stackdepth;
 
                                } else if (bptr->indepth != stackdepth) {
-                                       show_icmd_method(m, cd, rd);
-                                       printf("Block: %d, required depth: %d, current depth: %d\n", bptr->debug_nr, bptr->indepth, stackdepth);
-                                       log_text("Stack depth mismatch");
-                                       assert(0);
+                                       /*show_icmd_method(m, cd, rd);
+                                       printf("Block: %d, required depth: %d, current depth: %d\n",
+                                       bptr->debug_nr, bptr->indepth, stackdepth);*/
+                                       *exceptionptr = new_verifyerror(m,"Stack depth mismatch");
+                                       return NULL;
                                }
 
                                curstack = bptr->instack;
@@ -244,19 +273,23 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
 
                                while (--len >= 0)  {
                                        opcode = iptr->opc;
-                                        /* XXX TWISTI: why is this set to NULL here? */
- /*                 iptr->target = NULL; */
 
 #if defined(USEBUILTINTABLE)
-                                       bte = builtintable_get_automatic(opcode);
-
-                                       if (bte && bte->opcode == opcode) {
-                                               iptr->opc = ICMD_BUILTIN;
-                                               iptr->op1 = bte->md->paramcount;
-                                               iptr->val.a = bte;
-                                               m->isleafmethod = false;
-                                               goto builtin;
+# if defined(ENABLE_INTRP)
+                                       if (!opt_intrp) {
+# endif
+                                               bte = builtintable_get_automatic(opcode);
+
+                                               if (bte && bte->opcode == opcode) {
+                                                       iptr->opc = ICMD_BUILTIN;
+                                                       iptr->op1 = false;   /* don't check for exception */
+                                                       iptr->val.a = bte;
+                                                       m->isleafmethod = false;
+                                                       goto builtin;
+                                               }
+# if defined(ENABLE_INTRP)
                                        }
+# endif
 #endif /* defined(USEBUILTINTABLE) */
                                        
                                        switch (opcode) {
@@ -266,8 +299,6 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                        case ICMD_CHECKNULL:
                                                COUNT(count_check_null);
                                        case ICMD_NOP:
-                                       case ICMD_CHECKASIZE:
-                                       case ICMD_CHECKEXCEPTION:
 
                                        case ICMD_IFEQ_ICONST:
                                        case ICMD_IFNE_ICONST:
@@ -280,7 +311,10 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                break;
 
                                        case ICMD_RET:
-                                               rd->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
+#if defined(ENABLE_INTRP)
+                                               if (!opt_intrp)
+#endif
+                                                       rd->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
                                        case ICMD_RETURN:
                                                COUNT(count_pcmd_return);
                                                SETDST;
@@ -521,10 +555,12 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                                iptr[0].opc = ICMD_IFEQ;
                                                        icmd_if_icmp_tail:
                                                                iptr[0].op1 = iptr[1].op1;
+                                                               /* IF_ICMPxx is the last instruction in the   */
+                                                               /* basic block, just remove it                */
+                                                               /* iptr[1].opc = ICMD_NOP; */
                                                                bptr->icount--;
                                                                len--;
-#if 1
-                                                               /* iptr[1].opc = ICMD_NOP; */
+
                                                                OP1_0(TYPE_INT);
                                                                tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
 
@@ -532,9 +568,6 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
 
                                                                MARKREACHED(tbptr, copy);
                                                                COUNT(count_pcmd_bra);
-#else
-                                                               goto icmd_if;
-#endif
                                                                break;
                                                        case ICMD_IF_ICMPLT:
                                                                iptr[0].opc = ICMD_IFLT;
@@ -557,31 +590,38 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                        case ICMD_BASTORE:
                                                        case ICMD_CASTORE:
                                                        case ICMD_SASTORE:
+# if defined(ENABLE_INTRP)
+                                                               if (!opt_intrp) {
+# endif
 #if SUPPORT_CONST_STORE_ZERO_ONLY
-                                                               if (iptr[0].val.i == 0) {
+                                                                       if (iptr[0].val.i == 0) {
 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
-                                                                       switch (iptr[1].opc) {
-                                                                       case ICMD_IASTORE:
-                                                                               iptr[0].opc = ICMD_IASTORECONST;
-                                                                               break;
-                                                                       case ICMD_BASTORE:
-                                                                               iptr[0].opc = ICMD_BASTORECONST;
-                                                                               break;
-                                                                       case ICMD_CASTORE:
-                                                                               iptr[0].opc = ICMD_CASTORECONST;
-                                                                               break;
-                                                                       case ICMD_SASTORE:
-                                                                               iptr[0].opc = ICMD_SASTORECONST;
-                                                                               break;
-                                                                       }
-
-                                                                       iptr[1].opc = ICMD_NOP;
-                                                                       OPTT2_0(TYPE_INT, TYPE_ADR);
-                                                                       COUNT(count_pcmd_op);
+                                                                               switch (iptr[1].opc) {
+                                                                               case ICMD_IASTORE:
+                                                                                       iptr[0].opc = ICMD_IASTORECONST;
+                                                                                       break;
+                                                                               case ICMD_BASTORE:
+                                                                                       iptr[0].opc = ICMD_BASTORECONST;
+                                                                                       break;
+                                                                               case ICMD_CASTORE:
+                                                                                       iptr[0].opc = ICMD_CASTORECONST;
+                                                                                       break;
+                                                                               case ICMD_SASTORE:
+                                                                                       iptr[0].opc = ICMD_SASTORECONST;
+                                                                                       break;
+                                                                               }
+
+                                                                               iptr[1].opc = ICMD_NOP;
+                                                                               OPTT2_0(TYPE_INT, TYPE_ADR);
+                                                                               COUNT(count_pcmd_op);
 #if SUPPORT_CONST_STORE_ZERO_ONLY
+                                                                       } else
+                                                                               PUSHCONST(TYPE_INT);
+#endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
+# if defined(ENABLE_INTRP)
                                                                } else
                                                                        PUSHCONST(TYPE_INT);
-#endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
+# endif
                                                                break;
 
                                                        case ICMD_PUTSTATIC:
@@ -878,17 +918,24 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
 
 #if SUPPORT_CONST_STORE
                                                        case ICMD_LASTORE:
+# if defined(ENABLE_INTRP)
+                                                               if (!opt_intrp) {
+# endif
 #if SUPPORT_CONST_STORE_ZERO_ONLY
-                                                               if (iptr[0].val.l == 0) {
+                                                                       if (iptr[0].val.l == 0) {
 #endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
-                                                                       iptr[0].opc = ICMD_LASTORECONST;
-                                                                       iptr[1].opc = ICMD_NOP;
-                                                                       OPTT2_0(TYPE_INT, TYPE_ADR);
-                                                                       COUNT(count_pcmd_op);
+                                                                               iptr[0].opc = ICMD_LASTORECONST;
+                                                                               iptr[1].opc = ICMD_NOP;
+                                                                               OPTT2_0(TYPE_INT, TYPE_ADR);
+                                                                               COUNT(count_pcmd_op);
 #if SUPPORT_CONST_STORE_ZERO_ONLY
+                                                                       } else
+                                                                               PUSHCONST(TYPE_LNG);
+#endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
+# if defined(ENABLE_INTRP)
                                                                } else
                                                                        PUSHCONST(TYPE_LNG);
-#endif /* SUPPORT_CONST_STORE_ZERO_ONLY */
+# endif
                                                                break;
 
                                                        case ICMD_PUTSTATIC:
@@ -939,7 +986,7 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
 #if SUPPORT_CONST_STORE
                                                if (len > 0 && iptr->val.a == 0) {
                                                        switch (iptr[1].opc) {
-#if !defined(__POWERPC__) && !defined(__X86_64__)
+#if !defined(__POWERPC__) && !defined(__X86_64__) && !defined(__I386__) && !defined(__ALPHA__) && !defined(__MIPS__)
                                                        case ICMD_BUILTIN:
                                                                if (iptr[1].val.fp != BUILTIN_aastore) {
                                                                        PUSHCONST(TYPE_ADR);
@@ -986,9 +1033,12 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                        case ICMD_DLOAD:
                                        case ICMD_ALOAD:
                                                COUNT(count_load_instruction);
-                                               i = opcode-ICMD_ILOAD;
+                                               i = opcode - ICMD_ILOAD;
                                                iptr->op1 = argren[iptr->op1];
-                                               rd->locals[iptr->op1][i].type = i;
+#if defined(ENABLE_INTRP)
+                                               if (!opt_intrp)
+#endif
+                                                       rd->locals[iptr->op1][i].type = i;
                                                LOAD(i, LOCALVAR, iptr->op1);
                                                break;
 
@@ -1002,7 +1052,7 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                COUNT(count_check_null);
                                                COUNT(count_check_bound);
                                                COUNT(count_pcmd_mem);
-                                               OP2IAT_1(opcode-ICMD_IALOAD);
+                                               OP2IAT_1(opcode - ICMD_IALOAD);
                                                break;
 
                                        case ICMD_BALOAD:
@@ -1051,7 +1101,10 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                REQUIRE_1;
 
                                        i = opcode - ICMD_ISTORE;
-                                       rd->locals[iptr->op1][i].type = i;
+#if defined(ENABLE_INTRP)
+                                               if (!opt_intrp)
+#endif
+                                                       rd->locals[iptr->op1][i].type = i;
 #if defined(STATISTICS)
                                        if (opt_stat) {
                                                count_pcmd_store++;
@@ -1082,13 +1135,12 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                curstack->varkind = LOCALVAR;
                                                curstack->varnum = iptr->op1;
                                        };
-                                       STORE(opcode-ICMD_ISTORE);
+                                       STORE(opcode - ICMD_ISTORE);
                                        break;
 
                                        /* pop 3 push 0 */
 
                                        case ICMD_AASTORE:
-#if defined(__POWERPC__) || defined(__X86_64__)
                                                COUNT(count_check_null);
                                                COUNT(count_check_bound);
                                                COUNT(count_pcmd_mem);
@@ -1112,7 +1164,6 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
 
                                                OP3TIA_0(TYPE_ADR);
                                                break;
-#endif
 
                                        case ICMD_IASTORE:
                                        case ICMD_LASTORE:
@@ -1191,43 +1242,43 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                        case ICMD_IFGE:
                                        case ICMD_IFGT:
                                        case ICMD_IFLE:
-#if 0
-                                       icmd_if:
-#endif
                                                COUNT(count_pcmd_bra);
 #if CONDITIONAL_LOADCONST
-                                               tbptr = m->basicblocks + b_index;
-                                               if ((b_count >= 3) &&
-                                                       ((b_index + 2) == m->basicblockindex[iptr[0].op1]) &&
-                                                       (tbptr[1].pre_count == 1) &&
-                                                       (tbptr[1].iinstr[0].opc == ICMD_ICONST) &&
-                                                       (tbptr[1].iinstr[1].opc == ICMD_GOTO)   &&
-                                                       ((b_index + 3) == m->basicblockindex[tbptr[1].iinstr[1].op1]) &&
-                                                       (tbptr[2].pre_count == 1) &&
-                                                       (tbptr[2].iinstr[0].opc == ICMD_ICONST)  &&
-                                                       (tbptr[2].icount==1)) {
+# if defined(ENABLE_INTRP)
+                                               if (!opt_intrp) {
+# endif
+                                                       tbptr = m->basicblocks + b_index;
+                                                       if ((b_count >= 3) &&
+                                                               ((b_index + 2) == m->basicblockindex[iptr[0].op1]) &&
+                                                               (tbptr[1].pre_count == 1) &&
+                                                               (tbptr[1].iinstr[0].opc == ICMD_ICONST) &&
+                                                               (tbptr[1].iinstr[1].opc == ICMD_GOTO)   &&
+                                                               ((b_index + 3) == m->basicblockindex[tbptr[1].iinstr[1].op1]) &&
+                                                               (tbptr[2].pre_count == 1) &&
+                                                               (tbptr[2].iinstr[0].opc == ICMD_ICONST)  &&
+                                                               (tbptr[2].icount==1)) {
                                                                /*printf("tbptr[2].icount=%d\n",tbptr[2].icount);*/
                                                                OP1_1(TYPE_INT, TYPE_INT);
                                                                switch (iptr[0].opc) {
-                                                                       case ICMD_IFEQ:
-                                                                               iptr[0].opc = ICMD_IFNE_ICONST;
-                                                                               break;
-                                                                       case ICMD_IFNE:
-                                                                               iptr[0].opc = ICMD_IFEQ_ICONST;
-                                                                               break;
-                                                                       case ICMD_IFLT:
-                                                                               iptr[0].opc = ICMD_IFGE_ICONST;
-                                                                               break;
-                                                                       case ICMD_IFGE:
-                                                                               iptr[0].opc = ICMD_IFLT_ICONST;
-                                                                               break;
-                                                                       case ICMD_IFGT:
-                                                                               iptr[0].opc = ICMD_IFLE_ICONST;
-                                                                               break;
-                                                                       case ICMD_IFLE:
-                                                                               iptr[0].opc = ICMD_IFGT_ICONST;
-                                                                               break;
-                                                                       }
+                                                               case ICMD_IFEQ:
+                                                                       iptr[0].opc = ICMD_IFNE_ICONST;
+                                                                       break;
+                                                               case ICMD_IFNE:
+                                                                       iptr[0].opc = ICMD_IFEQ_ICONST;
+                                                                       break;
+                                                               case ICMD_IFLT:
+                                                                       iptr[0].opc = ICMD_IFGE_ICONST;
+                                                                       break;
+                                                               case ICMD_IFGE:
+                                                                       iptr[0].opc = ICMD_IFLT_ICONST;
+                                                                       break;
+                                                               case ICMD_IFGT:
+                                                                       iptr[0].opc = ICMD_IFLE_ICONST;
+                                                                       break;
+                                                               case ICMD_IFLE:
+                                                                       iptr[0].opc = ICMD_IFGT_ICONST;
+                                                                       break;
+                                                               }
 #if 1
                                                                iptr[0].val.i = iptr[1].val.i;
                                                                iptr[1].opc = ICMD_ELSE_ICONST;
@@ -1235,14 +1286,14 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                                iptr[2].opc = ICMD_NOP;
                                                                iptr[3].opc = ICMD_NOP;
 #else
-                                                       /* HACK: save compare value in iptr[1].op1 */    
-                                                       iptr[1].op1 = iptr[0].val.i;     
-                                                       iptr[0].val.i = tbptr[1].iinstr[0].val.i;        
-                                                       iptr[1].opc = ICMD_ELSE_ICONST;          
-                                                       iptr[1].val.i = tbptr[2].iinstr[0].val.i;        
-                                                       tbptr[1].iinstr[0].opc = ICMD_NOP;       
-                                                       tbptr[1].iinstr[1].opc = ICMD_NOP;       
-                                                       tbptr[2].iinstr[0].opc = ICMD_NOP;       
+                                                               /* HACK: save compare value in iptr[1].op1 */    
+                                                               iptr[1].op1 = iptr[0].val.i;     
+                                                               iptr[0].val.i = tbptr[1].iinstr[0].val.i;        
+                                                               iptr[1].opc = ICMD_ELSE_ICONST;          
+                                                               iptr[1].val.i = tbptr[2].iinstr[0].val.i;        
+                                                               tbptr[1].iinstr[0].opc = ICMD_NOP;       
+                                                               tbptr[1].iinstr[1].opc = ICMD_NOP;       
+                                                               tbptr[2].iinstr[0].opc = ICMD_NOP;       
 #endif
                                                                tbptr[1].flags = BBDELETED;
                                                                tbptr[2].flags = BBDELETED;
@@ -1259,12 +1310,17 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                                        bptr->icount++;
                                                                        len ++;
                                                                }
-                                                       b_index += 2;
-                                                       break;
+                                                               b_index += 2;
+                                                               break;
+                                                       }
+# if defined(ENABLE_INTRP)
                                                }
+# endif
+
 #endif /* CONDITIONAL_LOADCONST */
 
                                                OP1_0(TYPE_INT);
+                                               iptr->val.i = 0;
                                                tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
 
                                                iptr[0].target = (void *) tbptr;
@@ -1604,7 +1660,6 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
 
                                                /* pop 2 push 1 */
 
-#if defined(__POWERPC__)                                               
                                        case ICMD_IDIV:
                                        case ICMD_IREM:
 #if !SUPPORT_DIVISION
@@ -1624,28 +1679,9 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                        copy->flags |= SAVEDVAR;
                                                        copy = copy->prev;
                                                }
-#endif
-#else
-                                       case ICMD_IDIV:
-#if !SUPPORT_DIVISION
-                                               bte = builtintable_get_internal(BUILTIN_idiv);
-                                               iptr->opc = ICMD_BUILTIN;
-                                               iptr->op1 = bte->md->paramcount;
-                                               iptr->val.a = bte;
-                                               m->isleafmethod = false;
-                                               goto builtin;
-#endif
 
-                                       case ICMD_IREM:
-#if !SUPPORT_DIVISION
-                                               bte = builtintable_get_internal(BUILTIN_irem);
-                                               iptr->opc = ICMD_BUILTIN;
-                                               iptr->op1 = bte->md->paramcount;
-                                               iptr->val.a = bte;
-                                               m->isleafmethod = false;
-                                               goto builtin;
-#endif
-#endif
+                                               /* fall through */
+#endif /* !SUPPORT_DIVISION */
 
                                        case ICMD_ISHL:
                                        case ICMD_ISHR:
@@ -1660,7 +1696,6 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                OP2_1(TYPE_INT);
                                                break;
 
-#if defined(__POWERPC__)
                                        case ICMD_LDIV:
                                        case ICMD_LREM:
 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
@@ -1680,28 +1715,9 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                        copy->flags |= SAVEDVAR;
                                                        copy = copy->prev;
                                                }
-#endif
-#else
-                                       case ICMD_LDIV:
-#if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
-                                               bte = builtintable_get_internal(BUILTIN_ldiv);
-                                               iptr->opc = ICMD_BUILTIN;
-                                               iptr->op1 = bte->md->paramcount;
-                                               iptr->val.a = bte;
-                                               m->isleafmethod = false;
-                                               goto builtin;
-#endif
 
-                                       case ICMD_LREM:
-#if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
-                                               bte = builtintable_get_internal(BUILTIN_lrem);
-                                               iptr->opc = ICMD_BUILTIN;
-                                               iptr->op1 = bte->md->paramcount;
-                                               iptr->val.a = bte;
-                                               m->isleafmethod = false;
-                                               goto builtin;
-#endif
-#endif
+                                               /* fall through */
+#endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
 
                                        case ICMD_LMUL:
                                        case ICMD_LADD:
@@ -1940,7 +1956,9 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                        /* pop many push any */
 
                                        case ICMD_BUILTIN:
+#if defined(USEBUILTINTABLE)
                                        builtin:
+#endif
                                                bte = (builtintable_entry *) iptr->val.a;
                                                md = bte->md;
                                                goto _callhandling;
@@ -1954,8 +1972,9 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                md = um->methodref->parseddesc.md;
 /*                          if (lm->flags & ACC_STATIC) */
 /*                              {COUNT(count_check_null);} */   
+
                                        _callhandling:
-                                               i = iptr->op1;
+                                               i = md->paramcount;
 
                                                if (md->memuse > rd->memuse)
                                                        rd->memuse = md->memuse;
@@ -1968,29 +1987,50 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
 
                                                copy = curstack;
                                                for (i-- ; i >= 0; i--) {
+#if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
+                                               /* If we pass float arguments in integer argument registers, we
+                                                * are not allowed to precolor them here. Floats have to be moved
+                                                * to this regs explicitly in codegen().
+                                                * Only arguments that are passed by stack anyway can be precolored
+                                                * (michi 2005/07/24) */
+                                                       if (!(copy->flags & SAVEDVAR) &&
+                                                          (!IS_FLT_DBL_TYPE(copy->type) || md->params[i].inmemory)) {
+#else
                                                        if (!(copy->flags & SAVEDVAR)) {
+#endif
                                                                copy->varkind = ARGVAR;
                                                                copy->varnum = i;
-                                                               if (md->params[i].inmemory) {
-                                                                       copy->flags = INMEMORY;
-                                                                       copy->regoff = md->params[i].regoff;
-                                                               } else {
-                                                                       copy->flags = 0;
-                                                                       if (IS_FLT_DBL_TYPE(copy->type))
+
+#if defined(ENABLE_INTRP)
+                                                               if (!opt_intrp) {
+#endif
+                                                                       if (md->params[i].inmemory) {
+                                                                               copy->flags = INMEMORY;
+                                                                               copy->regoff = md->params[i].regoff;
+                                                                       } else {
+                                                                               copy->flags = 0;
+                                                                               if (IS_FLT_DBL_TYPE(copy->type))
+#if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
+                                                                                       assert(0); /* XXX is this assert ok? */
+#else
                                                                                copy->regoff =
-                                                                                  rd->argfltregs[md->params[i].regoff];
-                                                                       else {
+                                                                                       rd->argfltregs[md->params[i].regoff];
+#endif
+                                                                               else {
 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
-                                                                               if (IS_2_WORD_TYPE(copy->type))
-                                                                                       copy->regoff = PACK_REGS(
-                                                       rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
-                                                       rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
-                                                                               else
+                                                                                       if (IS_2_WORD_TYPE(copy->type))
+                                                                                               copy->regoff = PACK_REGS(
+                                                                                                                                                rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
+                                                                                                                                                rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
+                                                                                       else
 #endif
-                                                                                       copy->regoff =
-                                                                              rd->argintregs[md->params[i].regoff];
+                                                                                               copy->regoff =
+                                                                                                       rd->argintregs[md->params[i].regoff];
+                                                                               }
                                                                        }
+#if defined(ENABLE_INTRP)
                                                                }
+#endif
                                                        }
                                                        copy = copy->prev;
                                                }
@@ -2000,7 +2040,7 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                        copy = copy->prev;
                                                }
 
-                                               i = iptr->op1;
+                                               i = md->paramcount;
                                                POPMANY(i);
                                                if (md->returntype.type != TYPE_VOID)
                                                        OP0_1(md->returntype.type);
@@ -2012,8 +2052,8 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                break;
 
                                        case ICMD_MULTIANEWARRAY:
-                                               if (rd->argintreguse < 3)                                   
-                                                       rd->argintreguse = 3;   
+                                               if (rd->argintreguse < 3)
+                                                       rd->argintreguse = 3;
 
                                                i = iptr->op1;
 
@@ -2030,6 +2070,9 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
 # if defined(__I386__)
                                                if (rd->memuse < i + 3)
                                                        rd->memuse = i + 3; /* n integer args spilled on stack */
+# elif defined(__MIPS__) && SIZEOF_VOID_P == 4
+                                               if (rd->memuse < i + 2)
+                                                       rd->memuse = i + 2; /* 4*4 bytes callee save space */
 # else
                                                if (rd->memuse < i)
                                                        rd->memuse = i; /* n integer args spilled on stack */
@@ -2051,6 +2094,8 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
 #else
 # if defined(__I386__)
                                                                copy->regoff = i + 3;
+# elif defined(__MIPS__) && SIZEOF_VOID_P == 4
+                                                               copy->regoff = i + 2;
 # else
                                                                copy->regoff = i;
 # endif /* defined(__I386__) */
@@ -2092,9 +2137,7 @@ methodinfo *analyse_stack(methodinfo *m, codegendata *cd, registerdata *rd)
                                                break;
 
                                        default:
-                                               *exceptionptr =
-                                                       new_exception_message(string_java_lang_InternalError,
-                                                                                                 "Unknown ICMD");
+                                               *exceptionptr = new_internalerror("Unknown ICMD");
                                                return NULL;
                                        } /* switch */
 
@@ -2212,9 +2255,9 @@ void icmd_print_stack(codegendata *cd, stackptr s)
        j = cd->maxstack - i;
        while (--i >= 0)
                printf("    ");
+
        while (s) {
                j--;
-               /* DEBUG */ /*printf("(%d,%d,%d,%d)",s->varkind,s->flags,s->regoff,s->varnum); fflush(stdout);*/
                if (s->flags & SAVEDVAR)
                        switch (s->varkind) {
                        case TEMPVAR:
@@ -2233,7 +2276,11 @@ void icmd_print_stack(codegendata *cd, stackptr s)
                             regs[GET_HIGH_REG(s->regoff)]);
                                        else
 #endif
+#if defined(ENABLE_INTRP)
+                                               printf(" %3d", s->regoff);
+#else
                                                printf(" %3s", regs[s->regoff]);
+#endif
                                }
                                break;
                        case STACKVAR:
@@ -2246,7 +2293,7 @@ void icmd_print_stack(codegendata *cd, stackptr s)
                                if (s->varnum == -1) {
                                        /* Return Value                                  */
                                        /* varkind ARGVAR "misused for this special case */
-                                       printf("  RA");
+                                       printf("  V0");
                                } else /* "normal" Argvar */
                                        printf(" A%02d", s->varnum);
 #ifdef INVOKE_NEW_DEBUG
@@ -2277,7 +2324,11 @@ void icmd_print_stack(codegendata *cd, stackptr s)
                             regs[GET_HIGH_REG(s->regoff)]);
                                        else
 #endif
+#if defined(ENABLE_INTRP)
+                                               printf(" %3d", s->regoff);
+#else
                                                printf(" %3s", regs[s->regoff]);
+#endif
                                }
                                break;
                        case STACKVAR:
@@ -2290,7 +2341,7 @@ void icmd_print_stack(codegendata *cd, stackptr s)
                                if (s->varnum == -1) {
                                        /* Return Value                                  */
                                        /* varkind ARGVAR "misused for this special case */
-                                       printf("  ra");
+                                       printf("  v0");
                                } else /* "normal" Argvar */
                                printf(" a%02d", s->varnum);
 #ifdef INVOKE_NEW_DEBUG
@@ -2368,11 +2419,26 @@ static char *jit_type[] = {
 };
 
 
+/* show_icmd_method ************************************************************
+
+   XXX
+
+*******************************************************************************/
+
 void show_icmd_method(methodinfo *m, codegendata *cd, registerdata *rd)
 {
-       int i, j;
-       basicblock *bptr;
+       basicblock     *bptr;
        exceptiontable *ex;
+       s4              i, j;
+       u1             *u1ptr;
+
+#if defined(USE_THREADS)
+       /* We need to enter a lock here, since the binutils disassembler is not   */
+       /* reentrant-able and we could not read functions printed at the same     */
+       /* time.                                                                  */
+
+       builtin_monitorenter(&show_icmd_lock);
+#endif
 
        printf("\n");
        utf_fprint_classname(stdout, m->class->name);
@@ -2381,7 +2447,6 @@ void show_icmd_method(methodinfo *m, codegendata *cd, registerdata *rd)
        utf_fprint(stdout, m->descriptor);
        printf("\n\nMax locals: %d\n", (int) cd->maxlocals);
        printf("Max stack:  %d\n", (int) cd->maxstack);
-
        printf("Line number table length: %d\n", m->linenumbercount);
 
        printf("Exceptions (Number: %d):\n", cd->exceptiontablelength);
@@ -2403,33 +2468,44 @@ void show_icmd_method(methodinfo *m, codegendata *cd, registerdata *rd)
        printf("Local Table:\n");
        for (i = 0; i < cd->maxlocals; i++) {
                printf("   %3d: ", i);
-               for (j = TYPE_INT; j <= TYPE_ADR; j++)
-                       if (rd->locals[i][j].type >= 0) {
-                               printf("   (%s) ", jit_type[j]);
-                               if (rd->locals[i][j].flags & INMEMORY)
-                                       printf("m%2d", rd->locals[i][j].regoff);
+               for (j = TYPE_INT; j <= TYPE_ADR; j++) {
+#if defined(ENABLE_INTRP)
+                       if (!opt_intrp) {
+#endif
+                               if (rd->locals[i][j].type >= 0) {
+                                       printf("   (%s) ", jit_type[j]);
+                                       if (rd->locals[i][j].flags & INMEMORY)
+                                               printf("m%2d", rd->locals[i][j].regoff);
 #ifdef HAS_ADDRESS_REGISTER_FILE
-                               else if (j == TYPE_ADR)
-                                       printf("r%02d", rd->locals[i][j].regoff);
+                                       else if (j == TYPE_ADR)
+                                               printf("r%02d", rd->locals[i][j].regoff);
 #endif
-                               else if ((j == TYPE_FLT) || (j == TYPE_DBL))
-                                       printf("f%02d", rd->locals[i][j].regoff);
-                               else {
+                                       else if ((j == TYPE_FLT) || (j == TYPE_DBL))
+                                               printf("f%02d", rd->locals[i][j].regoff);
+                                       else {
 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
-                                       if (IS_2_WORD_TYPE(j))
-                                               printf(" %3s/%3s",
-                                                   regs[GET_LOW_REG(rd->locals[i][j].regoff)],
-                            regs[GET_HIGH_REG(rd->locals[i][j].regoff)]);
-                                       else
+                                               if (IS_2_WORD_TYPE(j))
+                                                       printf(" %3s/%3s",
+                                                                  regs[GET_LOW_REG(rd->locals[i][j].regoff)],
+                                                                  regs[GET_HIGH_REG(rd->locals[i][j].regoff)]);
+                                               else
 #endif
-                                               printf("%3s", regs[rd->locals[i][j].regoff]);
+                                                       printf("%3s", regs[rd->locals[i][j].regoff]);
+                                       }
                                }
+#if defined(ENABLE_INTRP)
                        }
+#endif
+               }
                printf("\n");
        }
        printf("\n");
+
 #ifdef LSRA
        if (!opt_lsra) {
+#endif
+#if defined(ENABLE_INTRP)
+               if (!opt_intrp) {
 #endif
        printf("Interface Table:\n");
        for (i = 0; i < cd->maxstack; i++) {
@@ -2487,6 +2563,10 @@ void show_icmd_method(methodinfo *m, codegendata *cd, registerdata *rd)
                }
        }
        printf("\n");
+
+#if defined(ENABLE_INTRP)
+               }
+#endif
 #ifdef LSRA
        }
 #endif
@@ -2494,41 +2574,15 @@ void show_icmd_method(methodinfo *m, codegendata *cd, registerdata *rd)
        /* show code before first basic block */
 
        if (opt_showdisassemble) {
-#if defined(__I386__) || defined(__X86_64__)
-               u1 *u1ptr;
-               s4 a;
-
                u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen);
-               for (i = 0; i < m->basicblocks[0].mpc;) {
-                       a = disassinstr(u1ptr);
-                       i += a;
-                       u1ptr += a;
-               }
-               printf("\n");
-#elif defined(__XDSPCORE__)
-               s4 *s4ptr;
-               s4 a;
 
-               s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen);
-               for (i = 0; i < m->basicblocks[0].mpc;) {
-                       a = disassinstr(stdout, s4ptr);
-                       printf("\n");
-                       i += a * 4;
-                       s4ptr += a;
-               }
-               printf("\n");
-#else
-               s4 *s4ptr;
+               for (; u1ptr < (u1 *) ((ptrint) m->mcode + cd->dseglen + m->basicblocks[0].mpc);)
+                       u1ptr = disassinstr(u1ptr);
 
-               s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen);
-               for (i = 0; i < m->basicblocks[0].mpc; i += 4, s4ptr++) {
-                       disassinstr(s4ptr);
-               }
                printf("\n");
-#endif
        }
 
-       /* show code off all basic blocks */
+       /* show code of all basic blocks */
 
        for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
                show_icmd_block(m, cd, bptr);
@@ -2542,57 +2596,27 @@ void show_icmd_method(methodinfo *m, codegendata *cd, registerdata *rd)
                                                                           ((ptrint) cd->dseglen +
                                                                                m->basicblocks[m->basicblockcount].mpc)));
 
-#if defined(__I386__) || defined(__X86_64__)
-               {
-                       u1 *u1ptr;
-                       s4  a;
-
-                       u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen +
-                                                       m->basicblocks[m->basicblockcount].mpc);
-
-                       for (; (ptrint) u1ptr < ((ptrint) m->mcode + m->mcodelength);) {
-                               a = disassinstr(u1ptr);
-                               i += a;
-                               u1ptr += a;
-                       }
-               }
-#elif defined(__XDSPCORE__)
-               {
-                       s4 *s4ptr;
-                       s4 a;
-
-                       s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen +
-                                                       m->basicblocks[m->basicblockcount].mpc);
-
-                       for (; (ptrint) s4ptr < ((ptrint) m->mcode + m->mcodelength);) {
-                               a = disassinstr(stdout, s4ptr);
-                               printf("\n");
-                               i += a * 4;
-                               s4ptr += a;
-                       }
-               }
-#else
-               {
-                       s4 *s4ptr;
-
-                       s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen +
-                                                       m->basicblocks[m->basicblockcount].mpc);
+               u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen +
+                                               m->basicblocks[m->basicblockcount].mpc);
 
-                       for (; (ptrint) s4ptr < ((ptrint) m->mcode + m->mcodelength);)
-                               disassinstr(s4ptr);
-               }
-#endif
+               for (; (ptrint) u1ptr < ((ptrint) m->mcode + m->mcodelength);)
+                       u1ptr = disassinstr(u1ptr);
 
                printf("\n");
        }
+
+#if defined(USE_THREADS)
+       builtin_monitorexit(&show_icmd_lock);
+#endif
 }
 
 
 void show_icmd_block(methodinfo *m, codegendata *cd, basicblock *bptr)
 {
-       int i, j;
-       int deadcode;
+       s4           i, j;
+       bool         deadcode;
        instruction *iptr;
+       u1          *u1ptr;
 
        if (bptr->flags != BBDELETED) {
                deadcode = bptr->flags <= BBREACHED;
@@ -2613,7 +2637,7 @@ void show_icmd_block(methodinfo *m, codegendata *cd, basicblock *bptr)
                        }
                        else
                                icmd_print_stack(cd, iptr->dst);
-                       printf("]     %4d  ", i);
+                       printf("] %5d (line: %5d)  ", i, iptr->line);
 
 #ifdef LSRA_EDX
                        if (icmd_uses_tmp[iptr->opc][0])
@@ -2635,73 +2659,18 @@ void show_icmd_block(methodinfo *m, codegendata *cd, basicblock *bptr)
                }
 
                if (opt_showdisassemble && (!deadcode)) {
-#if defined(__I386__) || defined(__X86_64__)
-                       u1 *u1ptr;
-                       s4 a;
-
                        printf("\n");
-                       i = bptr->mpc;
-                       u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen + i);
+                       u1ptr = (u1 *) ((ptrint) m->mcode + cd->dseglen + bptr->mpc);
 
                        if (bptr->next != NULL) {
-                               for (; i < bptr->next->mpc; ) {
-                                       a = disassinstr(u1ptr);
-                                       i += a;
-                                       u1ptr += a;
-                               }
-                               printf("\n");
+                               for (; u1ptr < (u1 *) ((ptrint) m->mcode + cd->dseglen + bptr->next->mpc);)
+                                       u1ptr = disassinstr(u1ptr);
 
                        } else {
-                               for (; u1ptr < (u1 *) ((ptrint) m->mcode + m->mcodelength); ) {
-                                       a = disassinstr(u1ptr); 
-                                       i += a;
-                                       u1ptr += a;
-                               }
-                               printf("\n");
+                               for (; u1ptr < (u1 *) ((ptrint) m->mcode + m->mcodelength);)
+                                       u1ptr = disassinstr(u1ptr); 
                        }
-#elif defined(__XDSPCORE__)
-                       s4 *s4ptr;
-                       s4 a;
-
                        printf("\n");
-                       i = bptr->mpc;
-                       s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen + i);
-
-                       if (bptr->next != NULL) {
-                               for (; i < bptr->next->mpc;) {
-                                       a = disassinstr(stdout, s4ptr);
-                                       printf("\n");
-                                       i += a * 4;
-                                       s4ptr += a;
-                               }
-                               printf("\n");
-
-                       } else {
-                               for (; s4ptr < (s4 *) ((ptrint) m->mcode + m->mcodelength); ) {
-                                       a = disassinstr(stdout, s4ptr);
-                                       i += a * 4;
-                                       s4ptr += a;
-                               }
-                               printf("\n");
-                       }
-#else
-                       s4 *s4ptr;
-
-                       printf("\n");
-                       i = bptr->mpc;
-                       s4ptr = (s4 *) ((ptrint) m->mcode + cd->dseglen + i);
-
-                       if (bptr->next != NULL) {
-                               for (; i < bptr->next->mpc; i += 4, s4ptr++)
-                                       disassinstr(s4ptr);
-                               printf("\n");
-
-                       } else {
-                               for (; s4ptr < (s4 *) ((ptrint) m->mcode + m->mcodelength); i += 4, s4ptr++)
-                                       disassinstr(s4ptr);
-                               printf("\n");
-                       }
-#endif
                }
        }
 }
@@ -2782,6 +2751,42 @@ void show_icmd(instruction *iptr, bool deadcode)
        case ICMD_ACONST:
        case ICMD_AASTORECONST:
                printf(" %p", iptr->val.a);
+
+               if (iptr->val.a) {
+                       /* check if this is a constant string */
+
+                       if (iptr->op1 == 0) {
+                               printf(", String = \"");
+                               utf_display(javastring_toutf(iptr->val.a, false));
+                               printf("\"");
+
+                       } else {
+                               /* it is a BUILTIN argument */
+
+                               printf(", Class = \"");
+
+                               /* is it resolved? */
+
+                               if (iptr[1].target == NULL) {
+                                       builtintable_entry *bte = iptr[1].val.a;
+
+                                       /* NEW gets a classinfo* as argument */
+
+                                       if (bte->fp == BUILTIN_new) {
+                                               utf_display(((classinfo *) iptr->val.a)->name);
+
+                                       } else {
+                                               utf_display(((vftbl_t *) iptr->val.a)->class->name);
+                                       }
+
+                               } else {
+                                       /* iptr->target is a constant_classref */
+
+                                       utf_display(((constant_classref *) iptr->val.a)->name);
+                               }
+                               printf("\"");
+                       }
+               }
                break;
 
        case ICMD_GETFIELD:
@@ -2819,27 +2824,35 @@ void show_icmd(instruction *iptr, bool deadcode)
        case ICMD_PUTFIELDCONST:
                switch (iptr[1].op1) {
                case TYPE_INT:
-                       printf(" %d,", iptr->val.i);
+                       printf(" %d (0x%08x),", iptr->val.i, iptr->val.i);
                        break;
                case TYPE_LNG:
 #if SIZEOF_VOID_P == 4
-                       printf(" %lld,", iptr->val.l);
+                       printf(" %lld (0x%016llx),", iptr->val.l, iptr->val.l);
 #else
-                       printf(" %ld,", iptr->val.l);
+                       printf(" %ld (0x%016lx),", iptr->val.l, iptr->val.l);
 #endif
                        break;
                case TYPE_ADR:
                        printf(" %p,", iptr->val.a);
                        break;
                case TYPE_FLT:
-                       printf(" %g,", iptr->val.f);
+                       printf(" %g (0x%08x),", iptr->val.f, iptr->val.i);
                        break;
                case TYPE_DBL:
-                       printf(" %g,", iptr->val.d);
+#if SIZEOF_VOID_P == 4
+                       printf(" %g (0x%016llx),", iptr->val.d, iptr->val.l);
+#else
+                       printf(" %g (0x%016lx),", iptr->val.d, iptr->val.l);
+#endif
                        break;
                }
-               if (iptr->opc == ICMD_PUTFIELDCONST)     
-                       printf(" NOT RESOLVED,");        
+               if (iptr->opc == ICMD_PUTFIELDCONST) {
+                       if (iptr[1].val.a)
+                               printf(" %d,", ((fieldinfo *) iptr[1].val.a)->offset);
+                       else
+                               printf(" (NOT RESOLVED),");
+               }
                printf(" ");     
                utf_display_classname(((unresolved_field *) iptr[1].target)->fieldref->classref->name);          
                printf(".");     
@@ -2957,7 +2970,7 @@ void show_icmd(instruction *iptr, bool deadcode)
 
        case ICMD_ARRAYCHECKCAST:
                if (iptr->op1) {
-                       classinfo *c = ((vftbl_t *) iptr->target)->class;
+                       classinfo *c = iptr->target;
                        if (c->flags & ACC_INTERFACE)
                                printf(" (INTERFACE) ");
                        else
@@ -2970,7 +2983,12 @@ void show_icmd(instruction *iptr, bool deadcode)
                break;
 
        case ICMD_INLINE_START:
-               printf("\t\t\t%s.%s%s depth=%i",iptr->method->class->name->text,iptr->method->name->text,iptr->method->descriptor->text, iptr->op1);
+               printf(" ");
+               utf_display_classname(iptr->method->class->name);
+               printf(".");
+               utf_display_classname(iptr->method->name);
+               utf_display_classname(iptr->method->descriptor);
+               printf(", depth=%i", iptr->op1);
                break;
        case ICMD_INLINE_END:
                break;
@@ -3000,9 +3018,9 @@ void show_icmd(instruction *iptr, bool deadcode)
        case ICMD_IFGT:
        case ICMD_IFLE:
                if (deadcode || !iptr->target)
-                       printf("(%d) op1=%d", iptr->val.i, iptr->op1);
+                       printf(" %d (0x%08x) op1=%d", iptr->val.i, iptr->val.i, iptr->op1);
                else
-                       printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
+                       printf(" %d (0x%08x) L%03d", iptr->val.i, iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
                break;
 
        case ICMD_IF_LEQ:
@@ -3100,12 +3118,14 @@ void show_icmd(instruction *iptr, bool deadcode)
                        }
                }
                break;
+
+       case ICMD_ARETURN:
+               if (iptr->val.a) {
+                       printf(" (NOT RESOLVED), Class = \"");
+                       utf_display(((unresolved_class *) iptr->val.a)->classref->name);
+                       printf("\"");
+               }
        }
-       printf(" Line number: %d, method:",iptr->line);
-/*        printf("\t\t");
-       utf_display(iptr->method->class->name); 
-       printf("."); 
-       utf_display(iptr->method->name); */
 }