Removed lazy loading defines and old, unused code.
[cacao.git] / src / vm / jit / parse.c
index b2e7547fbd545286a38c9f72e62ded7c7ce8c25e..7a02bb8a45004fd7ea8e7ed38c35ddd81812c4c9 100644 (file)
@@ -1,9 +1,9 @@
-/* jit/parse.c - parser for JavaVM to intermediate code translation
+/* src/vm/jit/parse.c - parser for JavaVM to intermediate code translation
 
-   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
-   R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
-   M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
-   P. Tomsich, J. Wenninger
+   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+   Institut f. Computersprachen - TU Wien
 
    This file is part of CACAO.
 
 
    Changes: Carolyn Oates
             Edwin Steiner
+            Joseph Wenninger
+            Christian Thalinger
 
-   $Id: parse.c 1546 2004-11-18 12:25:04Z twisti $
+   $Id: parse.c 2541 2005-05-31 16:02:14Z twisti $
 
 */
 
 
+#include <assert.h>
 #include <string.h>
-#include "parse.h"
-#include "global.h"
-#include "jit.h"
-#include "parseRT.h"
-#include "inline.h"
-#include "loop/loop.h"
+
+#include "config.h"
 #include "types.h"
-#include "builtin.h"
-#include "exceptions.h"
-#include "tables.h"
-#include "native.h"
-#include "loader.h"
-#include "options.h"
-#include "statistics.h"
-#include "toolbox/memory.h"
+#include "mm/memory.h"
+#include "native/native.h"
 #include "toolbox/logging.h"
+#include "vm/builtin.h"
+#include "vm/exceptions.h"
+#include "vm/global.h"
+#include "vm/linker.h"
+#include "vm/loader.h"
+#include "vm/resolve.h"
+#include "vm/options.h"
+#include "vm/statistics.h"
+#include "vm/stringlocal.h"
+#include "vm/tables.h"
+#include "vm/jit/asmpart.h"
+#include "vm/jit/jit.h"
+#include "vm/jit/parse.h"
+#include "vm/jit/patcher.h"
+#include "vm/jit/inline/parseRT.h"
+#include "vm/jit/inline/parseXTA.h"
+#include "vm/jit/inline/inline.h"
+#include "vm/jit/loop/loop.h"
+#include "vm/jit/inline/parseRTprint.h"
 
-#define METHINFO(mm) \
-        { \
-                printf("PARSE method name ="); \
-                utf_display(mm->class->name); \
-                printf("."); \
-                method_display(mm); \
-                fflush(stdout); \
-        }
-#define DEBUGMETH(mm) \
-if (DEBUG == true) \
-        { \
-                printf("PARSE method name ="); \
-                utf_display(mm->class->name); \
-                printf("."); \
-                method_display(mm); \
-                fflush(stdout); \
-        }
-
-#define SHOWOPCODE \
-if (DEBUG4 == true) {printf("Parse p=%i<%i<   opcode=<%i> %s\n", \
-                           p, m->jcodelength,opcode,opcode_names[opcode]);}
 bool DEBUG = false;
 bool DEBUG2 = false;
 bool DEBUG3 = false;
-bool DEBUG4 = false;  /*opcodes*/
+bool DEBUG4 = false;  /*opcodes for parse.c*/
+
 
 /*INLINING*/
-#define debug_writebranch if (DEBUG2==true) printf("op:: %s i: %d label_index[i]: %d label_index=0x%x\n",opcode_names[opcode], i, label_index[i], label_index);
+#define debug_writebranch if (DEBUG2==true) printf("op:: %s i: %d label_index[i]: %d label_index=0x%p\n",opcode_names[opcode], i, label_index[i], (void *)label_index);
 #define debug_writebranch1
 
-
-/* function descriptor2typesL ***************************************************
-
-       decodes a already checked method descriptor. The parameter count, the
-       return type and the argument types are stored in the passed methodinfo.
-        gets and saves classptr for object ref.s
-
-*******************************************************************************/               
-
-classSetNode *descriptor2typesL(methodinfo *m)
-{
-       int debugInfo = 0;
-       int i;
-       u1 *types, *tptr;
-       int pcount, c;
-       char *utf_ptr;
-       classinfo** classtypes;
-       char *class; 
-       char *desc;
-       classSetNode *p=NULL;
-       if (debugInfo >= 1) {
-               printf("In descriptor2typesL >>>\t"); fflush(stdout);
-               utf_display(m->class->name); printf(".");
-               method_display(m);fflush(stdout);
-       }
-
-       pcount = 0;
-       desc =       MNEW (char, 256); 
-       types = DMNEW (u1, m->descriptor->blength); 
-       classtypes = MNEW (classinfo*, m->descriptor->blength+1);
-       m->returnclass = NULL;
-       tptr = types;
-       if (!(m->flags & ACC_STATIC)) {
-               *tptr++ = TYPE_ADR;
-               if (debugInfo >= 1) {
-                       printf("param #0 (this?) method class =");utf_display(m->class->name);printf("\n");
-               }
-               classtypes[pcount] = m->class;
-               p = addClassCone(p,  m->class);
-               pcount++;
-       }
-
-       utf_ptr = m->descriptor->text + 1;
-       strcpy (desc,utf_ptr);
-   
-       while ((c = *desc++) != ')') {
-               pcount++;
-               switch (c) {
-               case 'B':
-               case 'C':
-               case 'I':
-               case 'S':
-               case 'Z':  *tptr++ = TYPE_INT;
-                       break;
-               case 'J':  *tptr++ = TYPE_LNG;
-                       break;
-               case 'F':  *tptr++ = TYPE_FLT;
-                       break;
-               case 'D':  *tptr++ = TYPE_DBL;
-                       break;
-               case 'L':  *tptr++ = TYPE_ADR;
-                       /* get class string */
-                       class = strtok(desc,";");
-                       desc = strtok(NULL,"\0");
-                       /* get/save classinfo ptr */
-                       classtypes[pcount-1] = class_get(utf_new_char(class));
-                       p = addClassCone(p,  class_get(utf_new_char(class)));
-                       if (debugInfo >= 1) {
-                               printf("LParam#%i 's class type is: %s\n",pcount-1,class);fflush(stdout);
-                               printf("Lclasstypes[%i]=",pcount-1);fflush(stdout);
-                               utf_display(classtypes[pcount-1]->name);
-                       }
-                       break;
-               case '[':  *tptr++ = TYPE_ADR;
-                       while (c == '[')
-                               c = *desc++;
-                       /* get class string */
-                       if (c == 'L') {
-                               class = strtok(desc,";");
-                               desc = strtok(NULL,"\0");
-                               /* get/save classinfo ptr */
-                               classtypes[pcount-1] = class_get(utf_new_char(class));
-                               p= addClassCone(p,  class_get(utf_new_char(class)));
-                               if (debugInfo >= 1) {
-                                       printf("[Param#%i 's class type is: %s\n",pcount-1,class);
-                                       printf("[classtypes[%i]=",pcount-1);fflush(stdout);
-                                       utf_display(classtypes[pcount-1]->name);
-                                       printf("\n");
-                               }
-                       }
-                       else
-                               classtypes[pcount-1] = NULL;
-                       break;
-               default:   
-                       panic("Ill formed methodtype-descriptor");
-               }
-       }
-
-       /* compute return type */
-       switch (*desc++) {
-       case 'B':
-       case 'C':
-       case 'I':
-       case 'S':
-       case 'Z':  m->returntype = TYPE_INT;
-               break;
-       case 'J':  m->returntype = TYPE_LNG;
-               break;
-       case 'F':  m->returntype = TYPE_FLT;
-               break;
-       case 'D':  m->returntype = TYPE_DBL;
-               break;
-       case '[':
-               m->returntype = TYPE_ADR;
-               c = *desc;
-               while (c == '[')
-                       c = *desc++;
-               if (c != 'L') break;
-               *(desc++);
-                          
-       case 'L':  
-               m->returntype = TYPE_ADR;
-                         
-               /* get class string */
-               class = strtok(desc,";");
-               m->returnclass = class_get(utf_new_char(class));
-               if (m->returnclass == NULL) {
-                       printf("class=%s :\t",class);
-                       panic ("return class not found");
-               }
-               break;
-       case 'V':  m->returntype = TYPE_VOID;
-               break;
-
-       default:   panic("Ill formed methodtype-descriptor-ReturnType");
-       }
-
-       m->paramcount = pcount;
-       m->paramtypes = types;
-       m->paramclass = classtypes;
-
-       if (debugInfo >=1) {
-               if (pcount > 0) {
-                       for (i=0; i< m->paramcount; i++) {
-                       if ((m->paramtypes[i] == TYPE_ADR) && (m->paramclass[i] != NULL)) {
-                                       printf("Param #%i is:\t",i);
-                                       utf_display(m->paramclass[i]->name);
-                                       printf("\n");
-                               }
-                       }
-               }
-               if ((m->returntype == TYPE_ADR) && (m->returnclass != NULL)) { 
-                       printf("\tReturn Type is:\t"); fflush(stdout);
-                       utf_display(m->returnclass->name);
-                       printf("\n");
-               }
-
-               printf("params2types: START  results in a set \n");
-               printf("param2types: A Set size=%i=\n",sizeOfSet(p));
-               printSet(p);
-       }
-
-       return p;
-}
-
-
-
-/* function descriptor2types ***************************************************
-
-       decodes a already checked method descriptor. The parameter count, the
-       return type and the argument types are stored in the passed methodinfo.
-
-*******************************************************************************/               
-
-void descriptor2types(methodinfo *m)
-{
-       u1 *types, *tptr;
-       int pcount, c;
-       char *utf_ptr;
-       pcount = 0;
-       types = DMNEW(u1, m->descriptor->blength); 
-       
-       tptr = types;
-       if (!(m->flags & ACC_STATIC)) {
-               *tptr++ = TYPE_ADR;
-               pcount++;
-       }
-
-       utf_ptr = m->descriptor->text + 1;
-   
-       while ((c = *utf_ptr++) != ')') {
-               pcount++;
-               switch (c) {
-               case 'B':
-               case 'C':
-               case 'I':
-               case 'S':
-               case 'Z':
-                       *tptr++ = TYPE_INT;
-                       break;
-               case 'J':
-                       *tptr++ = TYPE_LNG;
-                       break;
-               case 'F':
-                       *tptr++ = TYPE_FLT;
-                       break;
-               case 'D':
-                       *tptr++ = TYPE_DBL;
-                       break;
-               case 'L':
-                       *tptr++ = TYPE_ADR;
-                       while (*utf_ptr++ != ';');
-                       break;
-               case '[':
-                       *tptr++ = TYPE_ADR;
-                       while (c == '[')
-                               c = *utf_ptr++;
-                       if (c == 'L')
-                               while (*utf_ptr++ != ';') /* skip */;
-                       break;
-               default:
-                       panic("Ill formed methodtype-descriptor");
-               }
-       }
-
-       /* compute return type */
-
-       switch (*utf_ptr++) {
-       case 'B':
-       case 'C':
-       case 'I':
-       case 'S':
-       case 'Z':
-               m->returntype = TYPE_INT;
-               break;
-       case 'J':
-               m->returntype = TYPE_LNG;
-               break;
-       case 'F':
-               m->returntype = TYPE_FLT;
-               break;
-       case 'D':
-               m->returntype = TYPE_DBL;
-               break;
-       case '[':
-       case 'L':
-               m->returntype = TYPE_ADR;
-               break;
-       case 'V':
-               m->returntype = TYPE_VOID;
-               break;
-       default:
-               panic("Ill formed methodtype-descriptor");
-       }
-
-       m->paramcount = pcount;
-       m->paramtypes = types;
-}
-
-
-
 /*******************************************************************************
 
        function 'parse' scans the JavaVM code and generates intermediate code
@@ -361,16 +92,15 @@ static exceptiontable* fillextable(methodinfo *m,
                int *label_index, int *block_count, 
                t_inlining_globals *inline_env)
 {
-       int b_count, i, p, src, insertBlock;
+       int b_count, p, src, insertBlock;
        
        if (exceptiontablelength == 0) 
                return extable;
 
-       
        /*if (m->exceptiontablelength > 0) {
-         DEBUGMETH(m);
+         METHINFOx(m);
          printf("m->exceptiontablelength=%i\n",m->exceptiontablelength);
-         panic("exceptiontablelength > 0");
+         assert(0);
          }*/
 
        b_count = *block_count;
@@ -386,12 +116,16 @@ static exceptiontable* fillextable(methodinfo *m,
 /*** if (DEBUG==true){printf("---------------------block_inserted:b_count=%i m->basicblockindex[(p=%i)]=%i=%p\n",b_count,p,m->basicblockindex[(p)],m->basicblockindex[(p)]); 
   fflush(stdout); } ***/   
                p = raw_extable[src].endpc; /* see JVM Spec 4.7.3 */
-               if (p <= raw_extable[src].startpc)
-                       panic("Invalid exception handler range");
+               if (p <= raw_extable[src].startpc) {
+                       log_text("Invalid exception handler range");
+                       assert(0);
+               }
 
                if (p >inline_env->method->jcodelength) {
-                       panic("Invalid exception handler end is after code end");
+                       log_text("Invalid exception handler end is after code end");
+                       assert(0);
                }
+
                if (p<inline_env->method->jcodelength) insertBlock=1; else insertBlock=0;
                 /*if (label_index !=NULL) printf("%s:translating endpc:%ld to %ld, label_index:%p\n",m->name->text,p,label_index[p],label_index); else
                        printf("%s:fillextab: endpc:%ld\n",m->name->text,p);*/
@@ -449,51 +183,59 @@ methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env
 
        u2 skipBasicBlockChange;
 
-if (DEBUG==true) {printf("PARSING: "); fflush(stdout);
-DEBUGMETH(m);
-}
-if (opt_rt) {
+#if defined(USE_INLINING)
+METHINFOt(m,"\nPARSING: ",DEBUG4);
+if ((opt_rt) || (opt_xta)) {
+  FILE *Missed;
+
+  if (opt_rt)  Missed =  rtMissed;  
+  if (opt_xta) Missed = xtaMissed;  
+
   if (m->methodUsed != USED) {
     if (opt_verbose) {
-      printf(" rta missed: "); fflush(stdout);
-      METHINFO(m);
+      printf(" rta/xta missed: "); fflush(stdout);
+      METHINFO(m,opt_verbose);
       }
-    if ( (rtMissed = fopen("rtMissed", "a")) == NULL) {
-      printf("CACAO - rtMissed file: cant open file to write append \n");
+    if ( (Missed = fopen("Missed", "a")) == NULL) {
+      printf("CACAO - rt/xtaMissed file: cant open file to write append \n");
       }
     else {
-      utf_fprint(rtMissed,m->class->name); 
-       fprintf(rtMissed," "); fflush(rtMissed);
-      utf_fprint(rtMissed,m->name);
-       fprintf(rtMissed," "); fflush(rtMissed);
-      utf_fprint(rtMissed,m->descriptor); 
-       fprintf(rtMissed,"\n"); fflush(rtMissed);
-      fclose(rtMissed);
+      utf_fprint(Missed,m->class->name); 
+       fprintf(Missed," "); fflush(Missed);
+      utf_fprint(Missed,m->name);
+       fprintf(Missed," "); fflush(Missed);
+      utf_fprint(Missed,m->descriptor); 
+       fprintf(Missed,"\n"); fflush(Missed);
+      fclose(Missed);
       }
    } 
 }
-       /* INLINING */
+#endif
 
+#if defined(USE_INLINING)
        if (useinlining) {
                label_index = inlinfo->label_index;
                m->maxstack = inline_env->cummaxstack;
                /*JOWENN m->exceptiontablelength = inline_env->cumextablelength;*/
-               tmpinlinf = (inlining_methodinfo*) 
-                               list_first(inlinfo->inlinedmethods);
-               if (tmpinlinf != NULL) nextgp = tmpinlinf->startgp;
+
+               tmpinlinf = (inlining_methodinfo *) list_first(inlinfo->inlinedmethods);
+
+               if (tmpinlinf != NULL)
+                       nextgp = tmpinlinf->startgp;
        }
+#endif
 
 /**** static analysis has to be called before inlining
         which has to be called before reg_set
         which has to be called before parse (or ???)
         will check if method being parsed was analysed here
-       ****/ 
        if (opt_xta && opt_verbose) { 
-               /**RT_jit_parse(m);**/
+               **RT_jit_parse(m);**
                printf("XTA requested, not available\n");
                }
        if (opt_vta && opt_verbose)  
                    printf("VTA requested, not yet implemented\n");
+       ****/ 
 
        /* allocate instruction array and block index table */
        
@@ -536,7 +278,7 @@ if (m->exceptiontablelength > 0)
           label_index, &b_count, inline_env);
        s_count = 1 + m->exceptiontablelength; /* initialize stack element counter   */
 
-#ifdef USE_THREADS
+#if defined(USE_THREADS)
        if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
                m->isleafmethod = false;
                inline_env->method->isleafmethod = false;
@@ -549,7 +291,7 @@ if (m->exceptiontablelength > 0)
 
        if (m->linenumbercount == 0) {
                lineindex = 0;
-
+               /*printf("linenumber count == 0\n");*/
        } else {
                linepcchange = m->linenumbers[0].start_pc;
        }
@@ -563,6 +305,7 @@ if (m->exceptiontablelength > 0)
                if (!iswide) {
                        instructionstart[gp] = 1;
                        /*log_text("new start of instruction");*/
+                        /*printf ("%s, linepcchange %d,p %d\n",inline_env->method->name->text,linepcchange,p);*/
                        if (linepcchange==p) {
                                if (inline_env->method->linenumbercount > lineindex) {
                                        currentline = inline_env->method->linenumbers[lineindex].line_number;
@@ -574,7 +317,7 @@ if (m->exceptiontablelength > 0)
                        }
                }
 
-               /*INLINING*/
+#if defined(USE_INLINING)
                if ((useinlining) && (gp == nextgp)) {
                        u1 *tptr;
                        bool *readonly = NULL;
@@ -587,8 +330,11 @@ if (m->exceptiontablelength > 0)
 
                        opcode = code_get_u1(p,inline_env->method);
                        nextp = p += jcommandsize[opcode];
-                       if (nextp > inline_env->method->jcodelength)
-                               panic("Unexpected end of bytecode");
+                       if (nextp > inline_env->method->jcodelength) {
+                               log_text("Unexpected end of bytecode");
+                               assert(0);
+                       }
+
                        tmpinlinf = list_first(inlinfo->inlinedmethods);
                        firstlocal = tmpinlinf->firstlocal;
                        label_index = tmpinlinf->label_index;
@@ -628,28 +374,15 @@ if (m->exceptiontablelength > 0)
                                /* printf("inline argument load operation for local: %ld\n",firstlocal + tmpinlinf->method->paramcount - 1 - i); */
                        }
                        skipBasicBlockChange=1;
-if (DEBUG==true) {
-printf("BEFORE SAVE: "); fflush(stdout);
-DEBUGMETH(inline_env->method);
-}
+METHINFOt(inline_env->method,"BEFORE SAVE: ",DEBUG);
                        inlining_save_compiler_variables();
-if (DEBUG==true) {
-printf("AFTER SAVE: "); fflush(stdout);
-DEBUGMETH(inline_env->method);
-}
+METHINFOt(inline_env->method,"AFTER SAVE: ",DEBUG);
                        inlining_set_compiler_variables(tmpinlinf);
-if (DEBUG==true) {
-printf("AFTER SET :: "); fflush(stdout);
-DEBUGMETH(inline_env->method);
-}
-                       if (DEBUG) {
-                               printf("\n.......Parsing (inlined): ");
-                               DEBUGMETH(m);
-                               DEBUGMETH(inline_env->method);
-                       }
-
+METHINFOt(inline_env->method,"AFTER SET :: ",DEBUG);
+METHINFOt(m,"\n.......Parsing (inlined): ",DEBUG);
+METHINFO(inline_env->method,DEBUG);
 
-                        OP(ICMD_INLINE_START);
+                        OP1(ICMD_INLINE_START,tmpinlinf->level);
 
                        if (inlinfo->inlinedmethods == NULL) {
                                gp = -1;
@@ -663,14 +396,15 @@ DEBUGMETH(inline_env->method);
                            label_index, &b_count, inline_env);
                        continue;
                }
-         
+#endif /* defined(USE_INLINING) */
+
                opcode = code_get_u1(p,inline_env->method);            /* fetch op code  */
         if (DEBUG==true) 
                {
                        printf("Parse p=%i<%i<%i<   opcode=<%i> %s\n",
                           p, gp, inline_env->jcodelength, opcode, opcode_names[opcode]);
                        if (label_index)
-                               printf("label_index[%ld]=%ld\n",p,label_index[p]);
+                               printf("label_index[%d]=%d\n",p,label_index[p]);
                }
         /*
 printf("basicblockindex[gp=%i]=%i=%p ipc=%i=%p shifted ipc=%i=%p\n",
@@ -687,17 +421,20 @@ fflush(stdout);
                */
 
                if (blockend) {
-                       /* printf("B4 BEND\t"); fflush(stdout); */
                        block_insert(gp);               /* start new block                */
                        blockend = false;
                        /*printf("blockend was set: new blockcount: %ld at:%ld\n",b_count,gp);*/
                }
 
                nextp = p + jcommandsize[opcode];   /* compute next instruction start */
-               if (nextp > inline_env->method->jcodelength)
-                       panic("Unexpected end of bytecode");
+
+               if (nextp > inline_env->method->jcodelength) {
+                       log_text("Unexpected end of bytecode");
+                       assert(0);
+               }
+
                s_count += stackreq[opcode];            /* compute stack element count    */
-SHOWOPCODE
+SHOWOPCODE(DEBUG4)
                switch (opcode) {
                case JAVA_NOP:
                        break;
@@ -722,8 +459,10 @@ SHOWOPCODE
 
                pushconstantitem:
 
-                       if (i >= inline_env->method->class->cpcount) 
-                               panic ("Attempt to access constant outside range");
+                       if (i >= inline_env->method->class->cpcount) {
+                               dolog("Attempt to access constant outside range: %d >= %d", i, inline_env->method->class->cpcount);
+                               assert(0);
+                       }
 
                        switch (inline_env->method->class->cptags[i]) {
                        case CONSTANT_Integer:
@@ -741,7 +480,9 @@ SHOWOPCODE
                        case CONSTANT_String:
                                LOADCONST_A(literalstring_new((utf *) (inline_env->method->class->cpinfos[i])));
                                break;
-                       default: panic("Invalid constant type to push");
+                       default:
+                               log_text("Invalid constant type to push");
+                               assert(0);
                        }
                        break;
 
@@ -909,85 +650,88 @@ SHOWOPCODE
 
                case JAVA_NEWARRAY:
                        OP(ICMD_CHECKASIZE);
-                       switch (code_get_s1(p + 1,inline_env->method)) {
+                       switch (code_get_s1(p + 1, inline_env->method)) {
                        case 4:
-                               BUILTIN1(BUILTIN_newarray_boolean, TYPE_ADR,currentline);
+                               BUILTIN1(BUILTIN_newarray_boolean, TYPE_ADR, currentline);
                                break;
                        case 5:
-                               BUILTIN1(BUILTIN_newarray_char, TYPE_ADR,currentline);
+                               BUILTIN1(BUILTIN_newarray_char, TYPE_ADR, currentline);
                                break;
                        case 6:
-                               BUILTIN1(BUILTIN_newarray_float, TYPE_ADR,currentline);
+                               BUILTIN1(BUILTIN_newarray_float, TYPE_ADR, currentline);
                                break;
                        case 7:
-                               BUILTIN1(BUILTIN_newarray_double, TYPE_ADR,currentline);
+                               BUILTIN1(BUILTIN_newarray_double, TYPE_ADR, currentline);
                                break;
                        case 8:
-                               BUILTIN1(BUILTIN_newarray_byte, TYPE_ADR,currentline);
+                               BUILTIN1(BUILTIN_newarray_byte, TYPE_ADR, currentline);
                                break;
                        case 9:
-                               BUILTIN1(BUILTIN_newarray_short, TYPE_ADR,currentline);
+                               BUILTIN1(BUILTIN_newarray_short, TYPE_ADR, currentline);
                                break;
                        case 10:
-                               BUILTIN1(BUILTIN_newarray_int, TYPE_ADR,currentline);
+                               BUILTIN1(BUILTIN_newarray_int, TYPE_ADR, currentline);
                                break;
                        case 11:
-                               BUILTIN1(BUILTIN_newarray_long, TYPE_ADR,currentline);
+                               BUILTIN1(BUILTIN_newarray_long, TYPE_ADR, currentline);
                                break;
-                       default: panic("Invalid array-type to create");
+                       default:
+                               log_text("Invalid array-type to create");
+                               assert(0);
                        }
                        OP(ICMD_CHECKEXCEPTION);
                        break;
 
                case JAVA_ANEWARRAY:
                        OP(ICMD_CHECKASIZE);
-                       i = code_get_u2(p + 1,inline_env->method);
+                       i = code_get_u2(p + 1, inline_env->method);
                        {
-                               classinfo *component =
-                                       (classinfo *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
+                               constant_classref *compr;
+                               constant_classref *cr;
+                               classinfo         *c;
 
-                               if (!class_load(component))
+                               compr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
+
+                               if (!(cr = class_get_classref_multiarray_of(1, compr)))
                                        return NULL;
 
-                               if (!class_link(component))
+                               if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
                                        return NULL;
 
-                               LOADCONST_A_BUILTIN(class_array_of(component)->vftbl);
-/*                             LOADCONST_A_BUILTIN(component); */
+                               if (c) {
+                                       LOADCONST_A_BUILTIN(c->vftbl);
+                                       BUILTIN2T(BUILTIN_newarray, TYPE_ADR, NULL, currentline);
+
+                               } else {
+                                       LOADCONST_A_BUILTIN(cr);
+                                       BUILTIN2T(PATCHER_builtin_newarray, TYPE_ADR, cr, currentline);
+                               }
                                s_count++;
-                               BUILTIN2(BUILTIN_newarray, TYPE_ADR, currentline);
                        }
                        OP(ICMD_CHECKEXCEPTION);
                        break;
 
                case JAVA_MULTIANEWARRAY:
                        inline_env->method->isleafmethod = false;
-                       i = code_get_u2(p + 1,inline_env->method);
+                       i = code_get_u2(p + 1, inline_env->method);
                        {
-                               vftbl_t *arrayvftbl;
-                               s4 v = code_get_u1(p + 3,inline_env->method);
+                               constant_classref *cr;
+                               classinfo *c;
+                               s4 v = code_get_u1(p + 3, inline_env->method);
 
-                               
-/*                             vftbl *arrayvftbl = */
-/*                                     ((classinfo *) class_getconstant(class, i, CONSTANT_Class))->vftbl; */
-/*                             OP2A(opcode, v, arrayvftbl,currentline); */
-
-                               
-                               classinfo *component =
-                                       (classinfo *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
+                               cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
 
-                               if (!class_load(component))
+                               if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
                                        return NULL;
 
-                               if (!class_link(component))
-                                       return NULL;
+                               if (c) {
+                                       OP2AT(opcode, v, c->vftbl, NULL, currentline);
 
-                               arrayvftbl = component->vftbl;
-                               OP2A(opcode, v, arrayvftbl, currentline);
-
-/*                             classinfo *arrayclass = */
-/*                                     (classinfo *) class_getconstant(class, i, CONSTANT_Class); */
-/*                             OP2A(opcode, v, arrayclass, currentline); */
+                               } else {
+                                       OP2AT(opcode, v, cr,
+                                                 (voidptr) (ptrint) PATCHER_builtin_multianewarray,
+                                                 currentline);
+                               }
                        }
                        break;
 
@@ -1014,6 +758,7 @@ SHOWOPCODE
                                debug_writebranch;
                                i = label_index[i];
                        }
+                       /*printf("GOTO: %d\n",i);*/
                        bound_check(i);
                        block_insert(i);
                        blockend = true;
@@ -1092,58 +837,64 @@ SHOWOPCODE
                        {
                                s4 num, j;
                                s4 *tablep;
-                               s4 prevvalue;
+                               s4 prevvalue=0;
 
                                blockend = true;
                                nextp = ALIGN((p + 1), 4);
-                               if (nextp + 8 > inline_env->method->jcodelength)
-                                       panic("Unexpected end of bytecode");
+
+                               if (nextp + 8 > inline_env->method->jcodelength) {
+                                       log_text("Unexpected end of bytecode");
+                                       assert(0);
+                               }
+
                                if (!useinlining) {
                                        tablep = (s4 *) (inline_env->method->jcode + nextp);
 
                                } else {
-                                       num = code_get_u4(nextp + 4,inline_env->method);
+                                       num = code_get_u4(nextp + 4, inline_env->method);
                                        tablep = DMNEW(s4, num * 2 + 2);
                                }
 
-                               OP2A(opcode, 0, tablep,currentline);
+                               OP2A(opcode, 0, tablep, currentline);
 
                                /* default target */
 
-                               j =  p + code_get_s4(nextp,inline_env->method);
+                               j =  p + code_get_s4(nextp, inline_env->method);
                                if (useinlining) 
                                        j = label_index[j];
                                *tablep = j;     /* restore for little endian */
                                tablep++;
                                nextp += 4;
                                bound_check(j);
-/*
-printf("B7 LOOKUP1\t"); fflush(stdout);
-*/
                                block_insert(j);
 
                                /* number of pairs */
 
-                               num = code_get_u4(nextp,inline_env->method);
+                               num = code_get_u4(nextp, inline_env->method);
                                *tablep = num;
                                tablep++;
                                nextp += 4;
 
-                               if (nextp + 8*(num) > inline_env->method->jcodelength)
-                                       panic("Unexpected end of bytecode");
+                               if (nextp + 8 * num > inline_env->method->jcodelength) {
+                                       /* XXX TODO VerifyError */
+                                       log_text("Unexpected end of bytecode");
+                                       assert(0);
+                               }
 
                                for (i = 0; i < num; i++) {
                                        /* value */
 
-                                       j = code_get_s4(nextp,inline_env->method);
+                                       j = code_get_s4(nextp, inline_env->method);
                                        *tablep = j; /* restore for little endian */
                                        tablep++;
                                        nextp += 4;
 
                                        /* check if the lookup table is sorted correctly */
                                        
-                                       if (i && (j <= prevvalue))
-                                               panic("invalid LOOKUPSWITCH: table not sorted");
+                                       if (i && (j <= prevvalue)) {
+                                               *exceptionptr = new_verifyerror(m, "Unsorted lookup switch");
+                                               return NULL;
+                                       }
                                        prevvalue = j;
 
                                        /* target */
@@ -1155,9 +906,6 @@ printf("B7 LOOKUP1\t"); fflush(stdout);
                                        tablep++;
                                        nextp += 4;
                                        bound_check(j);
-/*
-printf("B8 LOOKUP2\t"); fflush(stdout);
-*/
                                        block_insert(j);
                                }
 
@@ -1172,8 +920,12 @@ printf("B8 LOOKUP2\t"); fflush(stdout);
 
                                blockend = true;
                                nextp = ALIGN((p + 1), 4);
-                               if (nextp + 12 > inline_env->method->jcodelength)
-                                       panic("Unexpected end of bytecode");
+                               if (nextp + 12 > inline_env->method->jcodelength) {
+                                       /* XXX TODO VerifyError */
+                                       log_text("Unexpected end of bytecode");
+                                       assert(0);
+                               }
+
                                if (!useinlining) {
                                        tablep = (s4 *) (inline_env->method->jcode + nextp);
 
@@ -1182,42 +934,46 @@ printf("B8 LOOKUP2\t"); fflush(stdout);
                                        tablep = DMNEW(s4, num + 1 + 3);
                                }
 
-                               OP2A(opcode, 0, tablep,currentline);
+                               OP2A(opcode, 0, tablep, currentline);
 
                                /* default target */
 
-                               j = p + code_get_s4(nextp,inline_env->method);
+                               j = p + code_get_s4(nextp, inline_env->method);
                                if (useinlining)
                                        j = label_index[j];
                                *tablep = j;     /* restore for little endian */
                                tablep++;
                                nextp += 4;
                                bound_check(j);
-/*
-printf("B9 TABLESWITCH1\t"); fflush(stdout);
-*/
                                block_insert(j);
 
                                /* lower bound */
 
-                               j = code_get_s4(nextp,inline_env->method);
+                               j = code_get_s4(nextp, inline_env->method);
                                *tablep = j;     /* restore for little endian */
                                tablep++;
                                nextp += 4;
 
                                /* upper bound */
 
-                               num = code_get_s4(nextp,inline_env->method);
+                               num = code_get_s4(nextp, inline_env->method);
                                *tablep = num;   /* restore for little endian */
                                tablep++;
                                nextp += 4;
 
                                num -= j;  /* difference of upper - lower */
-                               if (num < 0)
-                                       panic("invalid TABLESWITCH: upper bound < lower bound");
 
-                               if (nextp + 4*(num+1) > inline_env->method->jcodelength)
-                                       panic("Unexpected end of bytecode");
+                               if (num < 0) {
+                                       /* XXX TODO VerifyError */
+                                       log_text("invalid TABLESWITCH: upper bound < lower bound");
+                                       assert(0);
+                               }
+
+                               if (nextp + 4 * (num + 1) > inline_env->method->jcodelength) {
+                                       /* XXX TODO VerifyError */
+                                       log_text("Unexpected end of bytecode");
+                                       assert(0);
+                               }
 
                                for (i = 0; i <= num; i++) {
                                        j = p + code_get_s4(nextp,inline_env->method);
@@ -1229,9 +985,6 @@ printf("B9 TABLESWITCH1\t"); fflush(stdout);
                                        tablep++;
                                        nextp += 4;
                                        bound_check(j);
-/*
-printf("B10 TABLESWITCH2\t"); fflush(stdout);
-*/
                                        block_insert(j);
                                        /*printf("TABLESWITCH: block_insert(%ld)\n",j);*/
                                }
@@ -1246,62 +999,42 @@ printf("B10 TABLESWITCH2\t"); fflush(stdout);
                        BUILTIN3(BUILTIN_aastore, TYPE_VOID, currentline);
                        break;
 
-               case JAVA_PUTSTATIC:
                case JAVA_GETSTATIC:
-                       i = code_get_u2(p + 1,inline_env->method);
-                       {
-                               constant_FMIref *fr;
-                               fieldinfo *fi;
-
-                               fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref);
-
-                               if (!class_load(fr->class))
-                                       return NULL;
-
-                               if (!class_link(fr->class))
-                                       return NULL;
-
-                               fi = class_resolvefield(fr->class,
-                                                                               fr->name,
-                                                                               fr->descriptor,
-                                                                               inline_env->method->class,
-                                                                               true);
-
-                               if (!fi)
-                                       return NULL;
-
-                               OP2A(opcode, fi->type, fi, currentline);
-                               if (!fi->class->initialized) {
-                                       inline_env->method->isleafmethod = false;
-                               }
-                       }
-                       break;
-
-               case JAVA_PUTFIELD:
+               case JAVA_PUTSTATIC:
                case JAVA_GETFIELD:
-                       i = code_get_u2(p + 1,inline_env->method);
+               case JAVA_PUTFIELD:
+                       i = code_get_u2(p + 1, inline_env->method);
                        {
-                               constant_FMIref *fr;
-                               fieldinfo *fi;
+                               constant_FMIref  *fr;
+                               unresolved_field *uf;
+                               fieldinfo        *fi;
 
                                fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref);
+                               OP2A_NOINC(opcode, fr->parseddesc.fd->type, fr, currentline);
 
-                               if (!class_load(fr->class))
+                               if (!(uf = create_unresolved_field(inline_env->method->class,
+                                                                                                  inline_env->method,
+                                                                                                  iptr,
+                                                                                                  NULL)))
                                        return NULL;
 
-                               if (!class_link(fr->class))
-                                       return NULL;
+                               /* store unresolved_field pointer */
 
-                               fi = class_resolvefield(fr->class,
-                                                                               fr->name,
-                                                                               fr->descriptor,
-                                                                               inline_env->method->class,
-                                                                               true);
+                               iptr->target = uf;
 
-                               if (!fi)
-                                       return NULL;
+                               /* only with -noverify, otherwise the typechecker does this */
 
-                               OP2A(opcode, fi->type, fi, currentline);
+                               if (!opt_verify) {
+                                       if (!resolve_field(uf, resolveLazy, &fi))
+                                               return NULL;
+
+                                       iptr->val.a = fi;
+                               }
+                               PINC;
+#if defined(__MIPS__) || defined(__POWERPC__)
+                               if (!fi || !fi->class->initialized)
+                                       inline_env->method->isleafmethod = false;
+#endif
                        }
                        break;
 
@@ -1309,216 +1042,228 @@ printf("B10 TABLESWITCH2\t"); fflush(stdout);
                        /* method invocation *****/
 
                case JAVA_INVOKESTATIC:
-                       i = code_get_u2(p + 1,inline_env->method);
+                       i = code_get_u2(p + 1, inline_env->method);
                        {
-                               constant_FMIref *mr;
-                               methodinfo *mi;
-                               
+                               constant_FMIref   *mr;
+                               unresolved_method *um;
+                               methodinfo        *mi;
+
                                inline_env->method->isleafmethod = false;
 
                                mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref);
+                               OP2A_NOINC(opcode, mr->parseddesc.md->paramcount, mr, currentline);
 
-                               if (!class_load(mr->class))
-                                       return NULL;
+                               um = create_unresolved_method(inline_env->method->class,
+                                                                                         inline_env->method,
+                                                                                         iptr,
+                                                                                         NULL);
 
-                               if (!class_link(mr->class))
+                               if (!um)
                                        return NULL;
 
-                               mi = class_resolveclassmethod(mr->class,
-                                                                                         mr->name,
-                                                                                         mr->descriptor,
-                                                                                         inline_env->method->class,
-                                                                                         true);
+                               /* store the unresolved_method pointer */
 
-                               if (!mi)
-                                       return NULL;
+                               iptr->target = um;
 
-                               /*RTAprint*/ /* if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt) */
-if (DEBUG4==true) 
-                                       /*RTAprint*/    {printf(" method name =");
-                                       /*RTAprint*/    utf_display(mi->class->name); printf(".");
-                                       /*RTAprint*/    utf_display(mi->name);printf("\tINVOKE STATIC\n");
-                                       /*RTAprint*/    fflush(stdout);}
+                               /* only with -noverify, otherwise the typechecker does this */
 
-                               if (!(mi->flags & ACC_STATIC)) {
-                                       *exceptionptr =
-                                               new_exception(string_java_lang_IncompatibleClassChangeError);
-                                       return NULL;
-                               }
+                               if (!opt_verify) {
+                                       if (!resolve_method(um, resolveLazy, &mi))
+                                               return NULL;
 
-                               descriptor2types(mi);
-                               OP2A(opcode, mi->paramcount, mi, currentline);
+                                       iptr->val.a = mi;
+                               }
+                               PINC;
                        }
                        break;
 
                case JAVA_INVOKESPECIAL:
                case JAVA_INVOKEVIRTUAL:
-                       i = code_get_u2(p + 1,inline_env->method);
+                       i = code_get_u2(p + 1, inline_env->method);
                        {
-                               constant_FMIref *mr;
-                               methodinfo *mi;
+                               constant_FMIref   *mr;
+                               unresolved_method *um;
+                               methodinfo        *mi;
 
                                inline_env->method->isleafmethod = false;
 
                                mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref);
+                               OP2A_NOINC(opcode, mr->parseddesc.md->paramcount + 1, mr, currentline);
 
-                               if (!class_load(mr->class))
-                                       return NULL;
+                               um = create_unresolved_method(inline_env->method->class,
+                                                                                         inline_env->method,
+                                                                                         iptr,
+                                                                                         NULL);
 
-                               if (!class_link(mr->class))
+                               if (!um)
                                        return NULL;
 
-                               mi = class_resolveclassmethod(mr->class,
-                                                                                         mr->name,
-                                                                                         mr->descriptor,
-                                                                                         inline_env->method->class,
-                                                                                         true);
+                               /* store the unresolved_method* */
 
-                               if (!mi)
-                                       return NULL;
+                               iptr->target = um;
 
-                               /*RTAprint*/ /* if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt) */
-if (DEBUG4==true)
-                                       /*RTAprint*/    {printf(" method name =");
-                                       method_display(mi);
-                                       /*RTAprint*/    utf_display(mi->class->name); printf(".");
-                                       /*RTAprint*/    utf_display(mi->name);printf("\tINVOKE SPECIAL/VIRTUAL\n");
-                                       /*RTAprint*/    fflush(stdout);}
-
-                               if (mi->flags & ACC_STATIC) {
-                                       *exceptionptr =
-                                               new_exception(string_java_lang_IncompatibleClassChangeError);
-                                       return NULL;
-                               }
+                               /* only with -noverify, otherwise the typechecker does this */
+
+                               if (!opt_verify) {
+                                       if (!resolve_method(um, resolveLazy, &mi))
+                                               return NULL;
 
-                               descriptor2types(mi);
-                               OP2A(opcode, mi->paramcount, mi, currentline);
+                                       iptr->val.a = mi;
+                               }
+                               PINC;
                        }
                        break;
 
                case JAVA_INVOKEINTERFACE:
                        i = code_get_u2(p + 1,inline_env->method);
                        {
-                               constant_FMIref *mr;
-                               methodinfo *mi;
+                               constant_FMIref   *mr;
+                               unresolved_method *um;
+                               methodinfo        *mi;
                                
                                inline_env->method->isleafmethod = false;
 
                                mr = class_getconstant(inline_env->method->class, i, CONSTANT_InterfaceMethodref);
+                               OP2A_NOINC(opcode, mr->parseddesc.md->paramcount + 1, mr, currentline);
 
-                               if (!class_load(mr->class))
-                                       return NULL;
+                               um = create_unresolved_method(inline_env->method->class,
+                                                                                         inline_env->method,
+                                                                                         iptr,
+                                                                                         NULL);
 
-                               if (!class_link(mr->class))
+                               if (!um)
                                        return NULL;
 
-                               mi = class_resolveinterfacemethod(mr->class,
-                                                                                                 mr->name,
-                                                                                                 mr->descriptor,
-                                                                                                 inline_env->method->class,
-                                                                                                 true);
-                               if (!mi)
-                                       return NULL;
+                               /* store the unresolved_method* */
 
-                               if (mi->flags & ACC_STATIC) {
-                                       *exceptionptr =
-                                               new_exception(string_java_lang_IncompatibleClassChangeError);
-                                       return NULL;
-                               }
+                               iptr->target = um;
+
+                               /* only with -noverify, otherwise the typechecker does this */
 
-                               descriptor2types(mi);
-                               OP2A(opcode, mi->paramcount, mi, currentline);
+                               if (!opt_verify) {
+                                       if (!resolve_method(um, resolveLazy, &mi))
+                                               return NULL;
+
+                                       iptr->val.a = mi;
+                               }
+                               PINC;
                        }
                        break;
 
                        /* miscellaneous object operations *******/
 
                case JAVA_NEW:
-                       i = code_get_u2(p + 1,inline_env->method);
-                       LOADCONST_A_BUILTIN(class_getconstant(inline_env->method->class, i, CONSTANT_Class));
-                       s_count++;
-                       BUILTIN1(BUILTIN_new, TYPE_ADR, currentline);
-                       OP(ICMD_CHECKEXCEPTION);
+                       {
+                               constant_classref *cr;
+                               classinfo         *c;
+                               
+                               i = code_get_u2(p + 1, inline_env->method);
+                               cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
+
+                               if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
+                                       return NULL;
+
+                               /* <clinit> can throw an exception over native code */
+
+                               if (c && c->initialized) {
+                                       LOADCONST_A_BUILTIN(c);
+                                       BUILTIN1T(BUILTIN_new, TYPE_ADR, NULL, currentline);
+
+                               } else {
+                                       LOADCONST_A_BUILTIN(cr);
+                                       BUILTIN1T(PATCHER_builtin_new, TYPE_ADR, cr, currentline);
+                               }
+
+                               s_count++;
+                               OP(ICMD_CHECKEXCEPTION);
+                       }
                        break;
 
                case JAVA_CHECKCAST:
-                       i = code_get_u2(p + 1,inline_env->method);
+                       i = code_get_u2(p + 1, inline_env->method);
                        {
-                               classinfo *cls =
-                                       (classinfo *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
-
-                               if (!cls->loaded)
-                                       if (!class_load(cls))
-                                               return NULL;
+                               constant_classref *cr;
+                               classinfo         *c;
+                               
+                               cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
 
-                               if (!cls->linked)
-                                       if (!class_link(cls))
-                                               return NULL;
+                               if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
+                                       return NULL;
 
-                               if (cls->vftbl->arraydesc) {
+                               if (cr->name->text[0] == '[') {
                                        /* array type cast-check */
-                                       LOADCONST_A_BUILTIN(cls->vftbl);
+                                       if (c) {
+                                               LOADCONST_A_BUILTIN(c->vftbl);
+                                               BUILTIN2T(BUILTIN_arraycheckcast, TYPE_ADR, NULL, currentline);
+
+                                       } else {
+                                               LOADCONST_A_BUILTIN(cr);
+                                               BUILTIN2T(PATCHER_builtin_arraycheckcast, TYPE_ADR, cr, currentline);
+                                       }
                                        s_count++;
-                                       BUILTIN2(BUILTIN_checkarraycast, TYPE_ADR,currentline);
-
-                               } else { /* object type cast-check */
-                                       /*
-                                         +                                               LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
-                                         +                                               s_count++;
-                                         +                                               BUILTIN2(BUILTIN_checkcast, TYPE_ADR,currentline);
-                                         +                                             */
-                                       OP2A(opcode, 1, cls, currentline);
+
+                               } else {
+                                       /* object type cast-check */
+                                       OP2AT(opcode, 1, c, cr, currentline);
                                }
+#if defined(__MIPS__) || defined(__POWERPC__)
+                               if (!c)
+                                       inline_env->method->isleafmethod = false;
+#endif
                        }
                        break;
 
                case JAVA_INSTANCEOF:
                        i = code_get_u2(p + 1,inline_env->method);
                        {
-                               classinfo *cls =
-                                       (classinfo *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
-
-                               if (!cls->loaded)
-                                       if (!class_load(cls))
-                                               return NULL;
+                               constant_classref *cr;
+                               classinfo         *c;
+                               
+                               cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
 
-                               if (!cls->linked)
-                                       if (!class_link(cls))
-                                               return NULL;
+                               if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
+                                       return NULL;
 
-                               if (cls->vftbl->arraydesc) {
+                               if (cr->name->text[0] == '[') {
                                        /* array type cast-check */
-                                       LOADCONST_A_BUILTIN(cls->vftbl);
+                                       if (c) {
+                                               LOADCONST_A_BUILTIN(c->vftbl);
+                                               BUILTIN2T(BUILTIN_arrayinstanceof, TYPE_INT, NULL, currentline);
+
+                                       } else {
+                                               LOADCONST_A_BUILTIN(cr);
+                                               BUILTIN2T(PATCHER_builtin_arrayinstanceof, TYPE_INT, cr, currentline);
+                                       }
                                        s_count++;
-                                       BUILTIN2(BUILTIN_arrayinstanceof, TYPE_INT, currentline);
-                               }
-                               else { /* object type cast-check */
-                                       /*
-                                         LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
-                                         s_count++;
-                                         BUILTIN2(BUILTIN_instanceof, TYPE_INT,currentline);
-                                         +                                             */
-                                       OP2A(opcode, 1, cls, currentline);
+
+                               } else {
+                                       /* object type cast-check */
+                                       OP2AT(opcode, 1, c, cr, currentline);
                                }
+#if defined(__MIPS__) || defined(__POWERPC__)
+                               if (!c)
+                                       inline_env->method->isleafmethod = false;
+#endif
                        }
                        break;
 
                case JAVA_MONITORENTER:
-#ifdef USE_THREADS
+#if defined(USE_THREADS)
                        if (checksync) {
-                               BUILTIN1(BUILTIN_monitorenter, TYPE_VOID,currentline);
+                               OP(ICMD_CHECKNULL);
+                               BUILTIN1(BUILTIN_monitorenter, TYPE_VOID, currentline);
                        } else
 #endif
                                {
-                                       OP(ICMD_NULLCHECKPOP);
+                                       OP(ICMD_CHECKNULL);
+                                       OP(ICMD_POP);
                                }
                        break;
 
                case JAVA_MONITOREXIT:
-#ifdef USE_THREADS
+#if defined(USE_THREADS)
                        if (checksync) {
-                               BUILTIN1(BUILTIN_monitorexit, TYPE_VOID,currentline);
-                               OP(ICMD_CHECKEXCEPTION);
+                               BUILTIN1(BUILTIN_monitorexit, TYPE_VOID, currentline);
                        } else
 #endif
                                {
@@ -1533,6 +1278,7 @@ if (DEBUG4==true)
                        break;
 
                case JAVA_IREM:
+                       /*log_text("parse.c: adding IREM to bytecode list");*/
                        OP(opcode);
                        break;
 
@@ -1661,8 +1407,10 @@ if (DEBUG4==true)
                case 253:
                case 254:
                case 255:
-                       printf("Illegal opcode %d at instr %d\n", opcode, ipc);
-                       panic("Illegal opcode encountered");
+                       *exceptionptr =
+                               new_internalerror("Illegal opcode %d at instr %d\n",
+                                                                 opcode, ipc);
+                       return NULL;
                        break;
 
                default:
@@ -1672,11 +1420,12 @@ if (DEBUG4==true)
                } /* end switch */
 
                /* If WIDE was used correctly, iswide should have been reset by now. */
-               if (iswide && opcode != JAVA_WIDE)
-                       panic("Illegal instruction: WIDE before incompatible opcode");
-               
-               /* INLINING */
-                 
+               if (iswide && opcode != JAVA_WIDE) {
+                       log_text("Illegal instruction: WIDE before incompatible opcode");
+                       assert(0);
+               }
+
+#if defined(USE_INLINING)
                /* if (inline_env->isinlinedmethod && p == inline_env->method->jcodelength - 1) { */ /* end of an inlined method */
                if (inline_env->isinlinedmethod && (nextp >= inline_env->method->jcodelength) ) { /* end of an inlined method */
                        /*                printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
@@ -1685,10 +1434,7 @@ if (DEBUG4==true)
                        OP(ICMD_INLINE_END);
 /*label_index = inlinfo->label_index;*/
 
-if (DEBUG==true) {
-printf("AFTER RESTORE : "); fflush(stdout);
-DEBUGMETH(inline_env->method);
-}
+METHINFOt(inline_env->method,"AFTER RESTORE : ",DEBUG);
                        list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
                        if (inlinfo->inlinedmethods == NULL) { /* JJJJ */
                                nextgp = -1;
@@ -1700,14 +1446,17 @@ DEBUGMETH(inline_env->method);
                        label_index=inlinfo->label_index;
                        firstlocal = inlinfo->firstlocal;
                }
+#endif /* defined(USE_INLINING) */
 
        } /* end for */
 
 
        if (p != m->jcodelength) {
-               printf("p (%ld) != m->jcodelength (%ld)\n",p,m->jcodelength);
-               panic("Command-sequence crosses code-boundary");
+               printf("p (%d) != m->jcodelength (%d)\n",p,m->jcodelength);
+               log_text("Command-sequence crosses code-boundary");
+               assert(0);
        }
+
        if (!blockend) {
                *exceptionptr = new_verifyerror(m, "Falling off the end of the code");
                return NULL;
@@ -1756,11 +1505,15 @@ DEBUGMETH(inline_env->method);
                for (p = 0; p < inline_env->cumjcodelength; p++) { 
                /* for (p = 0; p < m->jcodelength; p++) { */
                        if (m->basicblockindex[p] & 1) {
-                               /* check if this block starts at the beginning of an instruction */
+                               /* Check if this block starts at the beginning of an          */
+                               /* instruction.                                               */
+
                                if (!instructionstart[p]) {
-                                       printf("Basic Block beginn: %ld\n",p);
-                                       panic("Branch into middle of instruction");
+                                       /* XXX TODO throw exception? which one? */
+                                       dolog("Branch into middle of instruction: Basic Block beginn: %d\n", p);
+                                       assert(0);
                                }
+
                                /* allocate the block */
                                bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
                                bptr->debug_nr = m->c_debug_nr++;
@@ -1811,8 +1564,11 @@ DEBUGMETH(inline_env->method);
                        cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
            }
        }
-       
-       if (useinlining) inlining_cleanup(inline_env);
+
+#if defined(USE_INLINING)      
+       if (useinlining)
+               inlining_cleanup(inline_env);
+#endif
 
        /* just return methodinfo* to signal everything was ok */
 
@@ -1832,3 +1588,4 @@ DEBUGMETH(inline_env->method);
  * tab-width: 4
  * End:
  */
+