X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Fjit%2Fparse.c;h=2f5446d321fb95251f7fc779c77024278844d616;hb=bc21650c967b161e3a86e67baae5b63ee7b30189;hp=dcc42bd198b4ffd0546a1e78bfe1e94e8e545974;hpb=c5df16dd82320fa7cb87214d2f47a6f5d23ed6c9;p=cacao.git diff --git a/src/vm/jit/parse.c b/src/vm/jit/parse.c index dcc42bd19..2f5446d32 100644 --- a/src/vm/jit/parse.c +++ b/src/vm/jit/parse.c @@ -1,4 +1,4 @@ -/* jit/parse.c - parser for JavaVM to intermediate code translation +/* 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, @@ -29,42 +29,61 @@ Changes: Carolyn Oates Edwin Steiner - $Id: parse.c 1038 2004-04-26 16:41:30Z twisti $ + $Id: parse.c 1630 2004-11-30 19:33:41Z carolyn $ */ #include -#include "parse.h" -#include "global.h" -#include "main.h" -#include "jit.h" -#include "parseRT.h" -#include "inline.h" -#include "loop/loop.h" -#include "types.h" -#include "builtin.h" -#include "tables.h" -#include "native.h" -#include "loader.h" -#include "toolbox/memory.h" -#include "toolbox/loging.h" - - -/* data about the currently parsed method */ - -classinfo *rt_class; /* class the compiled method belongs to */ -methodinfo *rt_method; /* pointer to method info of compiled method */ -utf *rt_descriptor; /* type descriptor of compiled method */ -int rt_jcodelength; /* length of JavaVM-codes */ -u1 *rt_jcode; /* pointer to start of JavaVM-code */ - +#include "config.h" +#include "types.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/loader.h" +#include "vm/options.h" +#include "vm/statistics.h" +#include "vm/tables.h" +#include "vm/jit/jit.h" +#include "vm/jit/parse.h" +#include "vm/jit/inline/parseRT.h" +#include "vm/jit/inline/inline.h" +#include "vm/jit/loop/loop.h" + + +#define METHINFO(mm) \ + { \ + printf("PARSE method name ="); \ + utf_display(mm->class->name); \ + printf("."); \ + method_display(mm); \ + fflush(stdout); \ + } +#define DEBUGMETH(mm) \ +if (DEBUG4 == 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*/ /*INLINING*/ -//#include "inline.c" -/*#define debug_writebranch printf("op: %s i: %d label_index[i]: %d\n",icmd_names[opcode], i, label_index[i]);*/ -#define debug_writebranch +#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_writebranch1 /* function descriptor2typesL *************************************************** @@ -263,24 +282,31 @@ void descriptor2types(methodinfo *m) case 'C': case 'I': case 'S': - case 'Z': *tptr++ = TYPE_INT; + case 'Z': + *tptr++ = TYPE_INT; break; - case 'J': *tptr++ = TYPE_LNG; + case 'J': + *tptr++ = TYPE_LNG; break; - case 'F': *tptr++ = TYPE_FLT; + case 'F': + *tptr++ = TYPE_FLT; break; - case 'D': *tptr++ = TYPE_DBL; + case 'D': + *tptr++ = TYPE_DBL; break; - case 'L': *tptr++ = TYPE_ADR; + case 'L': + *tptr++ = TYPE_ADR; while (*utf_ptr++ != ';'); break; - case '[': *tptr++ = TYPE_ADR; + case '[': + *tptr++ = TYPE_ADR; while (c == '[') c = *utf_ptr++; if (c == 'L') while (*utf_ptr++ != ';') /* skip */; break; - default: panic ("Ill formed methodtype-descriptor"); + default: + panic("Ill formed methodtype-descriptor"); } } @@ -291,21 +317,27 @@ void descriptor2types(methodinfo *m) case 'C': case 'I': case 'S': - case 'Z': m->returntype = TYPE_INT; + case 'Z': + m->returntype = TYPE_INT; break; - case 'J': m->returntype = TYPE_LNG; + case 'J': + m->returntype = TYPE_LNG; break; - case 'F': m->returntype = TYPE_FLT; + case 'F': + m->returntype = TYPE_FLT; break; - case 'D': m->returntype = TYPE_DBL; + case 'D': + m->returntype = TYPE_DBL; break; case '[': - case 'L': m->returntype = TYPE_ADR; + case 'L': + m->returntype = TYPE_ADR; break; - case 'V': m->returntype = TYPE_VOID; + case 'V': + m->returntype = TYPE_VOID; break; - - default: panic ("Ill formed methodtype-descriptor"); + default: + panic("Ill formed methodtype-descriptor"); } m->paramcount = pcount; @@ -326,228 +358,220 @@ void descriptor2types(methodinfo *m) *******************************************************************************/ -static xtable* fillextable(xtable* extable, exceptiontable *raw_extable, int exceptiontablelength, int *label_index, int *block_count) +static exceptiontable* fillextable(methodinfo *m, + exceptiontable* extable, exceptiontable *raw_extable, + int exceptiontablelength, + int *label_index, int *block_count, + t_inlining_globals *inline_env) { - int b_count, i, p; + int b_count, i, p, src, insertBlock; if (exceptiontablelength == 0) return extable; + + /*if (m->exceptiontablelength > 0) { + DEBUGMETH(m); + printf("m->exceptiontablelength=%i\n",m->exceptiontablelength); + panic("exceptiontablelength > 0"); + }*/ + b_count = *block_count; - for (i = 0; i < exceptiontablelength; i++) { - p = raw_extable[i].startpc; + for (src = exceptiontablelength-1; src >=0; src--) { + /* printf("Excepiont table index: %d\n",i); */ + p = raw_extable[src].startpc; if (label_index != NULL) p = label_index[p]; - extable[i].startpc = p; + extable->startpc = p; bound_check(p); block_insert(p); - p = raw_extable[i].endpc; - if (p <= raw_extable[i].startpc) +/*** 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 >inline_env->method->jcodelength) { + panic("Invalid exception handler end is after code end"); + } + if (pmethod->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);*/ if (label_index != NULL) p = label_index[p]; - extable[i].endpc = p; + extable->endpc = p; bound_check1(p); - if (p < cumjcodelength) - block_insert(p); + /*if (p < inline_env->method->jcodelength) { + block_insert(p); }*/ + if (insertBlock) block_insert(p); - p = raw_extable[i].handlerpc; + p = raw_extable[src].handlerpc; if (label_index != NULL) p = label_index[p]; - extable[i].handlerpc = p; + extable->handlerpc = p; bound_check(p); block_insert(p); - extable[i].catchtype = raw_extable[i].catchtype; - -#if 0 - if (extable[i].catchtype) { - utf_display_classname(extable[i].catchtype->name); - printf("\n"); - /* is this catch class loaded */ - if (!extable[i].catchtype->loaded) - class_load(extable[i].catchtype); - - /* is this catch class linked */ - if (!extable[i].catchtype->linked) - class_link(extable[i].catchtype); - } -#endif - - extable[i].next = NULL; - extable[i].down = &extable[i + 1]; + extable->catchtype = raw_extable[src].catchtype; + extable->next = NULL; + extable->down = &extable[1]; + extable--; } *block_count = b_count; - return &extable[i]; /* return the next free xtable* */ + return extable; /*&extable[i];*/ /* return the next free xtable* */ } -void parse() +methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env) { - int p; /* java instruction counter */ - int nextp; /* start of next java instruction */ - int opcode; /* java opcode */ - int i; /* temporary for different uses (counters) */ - int ipc = 0; /* intermediate instruction counter */ - int b_count = 0; /* basic block counter */ - int s_count = 0; /* stack element counter */ + int p; /* java instruction counter */ + int nextp; /* start of next java instruction */ + int opcode; /* java opcode */ + int i; /* temporary for different uses (ctrs)*/ + int ipc = 0; /* intermediate instruction counter */ + int b_count = 0; /* basic block counter */ + int s_count = 0; /* stack element counter */ bool blockend = false; /* true if basic block end has been reached */ - bool iswide = false; /* true if last instruction was a wide */ - instruction *iptr; /* current pointer into instruction array */ - int gp; /* global java instruction counter */ - /* inlining info for current method */ - inlining_methodinfo *inlinfo = inlining_rootinfo; + bool iswide = false; /* true if last instruction was a wide*/ + instruction *iptr; /* current ptr into instruction array */ + int gp; /* global java instruction counter */ + /* inlining info for current method */ + + inlining_methodinfo *inlinfo = inline_env->inlining_rootinfo; inlining_methodinfo *tmpinlinf; - int nextgp = -1; /* start of next method to be inlined */ - int *label_index = NULL; /* label redirection table */ - int firstlocal = 0; /* first local variable of method */ - xtable* nextex; /* points next free entry in extable */ + int nextgp = -1; /* start of next method to be inlined */ + int *label_index = NULL; /* label redirection table */ + int firstlocal = 0; /* first local variable of method */ + exceptiontable* nextex; /* points next free entry in extable */ u1 *instructionstart; /* 1 for pcs which are valid instr. starts */ - u2 lineindex=0; - u2 currentline=0; - u2 linepcchange=0; + u2 lineindex = 0; + u2 currentline = 0; + u2 linepcchange = 0; - bool useinltmp; - - if (compileverbose) { - char logtext[MAXLOGTEXT]; - sprintf(logtext, "Parsing: "); - utf_sprint_classname(logtext+strlen(logtext), method->class->name); - strcpy(logtext+strlen(logtext), "."); - utf_sprint(logtext+strlen(logtext), method->name); - utf_sprint_classname(logtext+strlen(logtext), method->descriptor); - log_text(logtext); - } + u2 skipBasicBlockChange; +if (DEBUG4==true) {printf("\nPARSING: "); fflush(stdout); +DEBUGMETH(m); +} +if (opt_rt) { + if (m->methodUsed != USED) { + if (opt_verbose) { + printf(" rta missed: "); fflush(stdout); + METHINFO(m); + } + if ( (rtMissed = fopen("rtMissed", "a")) == NULL) { + printf("CACAO - rtMissed 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); + } + } +} /* INLINING */ + if (useinlining) { label_index = inlinfo->label_index; - maxstack = cummaxstack; - exceptiontablelength = cumextablelength; - } - - useinltmp = useinlining; /* FIXME remove this after debugging */ - /*useinlining = false;*/ /* and merge the if-statements */ - - if (!useinlining) { - cumjcodelength = jcodelength; - - } else { - tmpinlinf = (inlining_methodinfo*) list_first(inlinfo->inlinedmethods); + m->maxstack = inline_env->cummaxstack; + /*JOWENN m->exceptiontablelength = inline_env->cumextablelength;*/ + tmpinlinf = (inlining_methodinfo*) + list_first(inlinfo->inlinedmethods); if (tmpinlinf != NULL) nextgp = tmpinlinf->startgp; } - if ((opt_rt || opt_xta || opt_vta) && (pOpcodes == 2 || pOpcodes == 3)) { - printf("PARSE method name ="); - utf_display(method->class->name); - printf("."); - method_display(method); - printf(">\n\n"); - fflush(stdout); - } - - if (opt_rt || opt_xta) { - RT_jit_parse(method); - - } else { - if (opt_vta) - printf("VTA requested, but not yet implemented\n"); - } - +/**** 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);**/ + 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 */ - /* 1 additional for end ipc and 3 for loop unrolling */ + /* 1 additional for end ipc * # cum inline methods*/ - block_index = DMNEW(int, cumjcodelength + 4); - instructionstart = DMNEW(u1, cumjcodelength + 4); - memset(instructionstart,0,sizeof(u1) * (cumjcodelength + 4)); + m->basicblockindex = DMNEW(s4, inline_env->cumjcodelength + inline_env->cummethods); + memset(m->basicblockindex, 0, sizeof(s4) * (inline_env->cumjcodelength + inline_env->cummethods)); + + instructionstart = DMNEW(u1, inline_env->cumjcodelength + inline_env->cummethods); + memset(instructionstart, 0, sizeof(u1) * (inline_env->cumjcodelength + inline_env->cummethods)); /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */ /* additional MONITOREXITS are reached by branches which are 3 bytes */ - iptr = instr = DMNEW(instruction, cumjcodelength + 5); + iptr = m->instructions = DMNEW(instruction, inline_env->cumjcodelength + 5); /* Zero the intermediate instructions array so we don't have any * invalid pointers in it if we cannot finish analyse_stack(). */ - memset(iptr,0,sizeof(instruction) * (cumjcodelength + 5)); - - /* initialize block_index table (unrolled four times) */ - { - int *ip; + memset(iptr, 0, sizeof(instruction) * (inline_env->cumjcodelength + 5)); - for (i = 0, ip = block_index; i <= cumjcodelength; i += 4, ip += 4) { - ip[0] = 0; - ip[1] = 0; - ip[2] = 0; - ip[3] = 0; - } - } - /* compute branch targets of exception table */ - - extable = DMNEW(xtable, exceptiontablelength + 1); /* - for (i = 0; i < method->exceptiontablelength; i++) { - - p = extable[i].startpc = raw_extable[i].startpc; - if (useinlining) p = label_index[p]; - bound_check(p); - block_insert(p); - - p = extable[i].endpc = raw_extable[i].endpc; - if (useinlining) p = label_index[p]; - bound_check1(p); - if (p < cumjcodelength) - block_insert(p); - - p = extable[i].handlerpc = raw_extable[i].handlerpc; - bound_check(p); - block_insert(p); - - extable[i].catchtype = raw_extable[i].catchtype; - - extable[i].next = NULL; - extable[i].down = &extable[i+1]; - } +if (m->exceptiontable == NULL) { + printf("m->exceptiontable=NULL\n");fflush(stdout); + } +else { + printf("m->exceptiontable != NULL\n");fflush(stdout); + } +printf("m->exceptiontablelength=%i, inline_env->method->exceptiontablelength=%i,inline_env->cumextablelength=%i\n", +m->exceptiontablelength, inline_env->method->exceptiontablelength,inline_env->cumextablelength); + */ + /* +if (m->exceptiontablelength > 0) + m->exceptiontable = DMNEW(exceptiontable, m->exceptiontablelength + 1); */ - nextex = fillextable(extable, raw_extable, method->exceptiontablelength, label_index, &b_count); - - s_count = 1 + exceptiontablelength; /* initialize stack element counter */ + nextex = fillextable(m, + &(cd->exceptiontable[cd->exceptiontablelength-1]), m->exceptiontable, m->exceptiontablelength, + label_index, &b_count, inline_env); + s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */ -#ifdef USE_THREADS - if (checksync && (method->flags & ACC_SYNCHRONIZED)) { - isleafmethod = false; +#if defined(USE_THREADS) + if (checksync && (m->flags & ACC_SYNCHRONIZED)) { + m->isleafmethod = false; + inline_env->method->isleafmethod = false; } #endif /* scan all java instructions */ - currentline=0; - linepcchange=0; - if (jlinenumbercount==0) { - lineindex=0; + currentline = 0; + linepcchange = 0; + + if (m->linenumbercount == 0) { + lineindex = 0; + } else { - linepcchange=jlinenumbers[0].start_pc; + linepcchange = m->linenumbers[0].start_pc; } - for (p = 0, gp = 0; p < jcodelength; gp += (nextp - p), p = nextp) { + skipBasicBlockChange=0; + for (p = 0, gp = 0; p < inline_env->method->jcodelength; gp += (nextp - p), p = nextp) { - /* DEBUG */ /*printf("p:%d gp:%d ",p,gp);*/ + /* DEBUG */ if (DEBUG==true) printf("----- p:%d gp:%d\n",p,gp); /* mark this position as a valid instruction start */ if (!iswide) { instructionstart[gp] = 1; /*log_text("new start of instruction");*/ if (linepcchange==p) { - if (jlinenumbercount>lineindex) { - currentline=jlinenumbers[lineindex].line_number; + if (inline_env->method->linenumbercount > lineindex) { + currentline = inline_env->method->linenumbers[lineindex].line_number; lineindex++; - if (lineindexmethod->linenumbercount) + linepcchange = inline_env->method->linenumbers[lineindex].start_pc; /*printf("Line number changed to: %ld\n",currentline);*/ } } @@ -557,17 +581,30 @@ void parse() if ((useinlining) && (gp == nextgp)) { u1 *tptr; bool *readonly = NULL; + int argBlockIdx=0; + block_insert(gp); /* JJJJJJJJJJ */ + blockend=false; + instructionstart[gp] = 1; + m->basicblockindex[gp] |= (ipc << 1); /*FIXME: necessary ? */ - opcode = code_get_u1(p); + opcode = code_get_u1(p,inline_env->method); nextp = p += jcommandsize[opcode]; - if (nextp > jcodelength) + if (nextp > inline_env->method->jcodelength) panic("Unexpected end of bytecode"); tmpinlinf = list_first(inlinfo->inlinedmethods); firstlocal = tmpinlinf->firstlocal; label_index = tmpinlinf->label_index; readonly = tmpinlinf->readonly; + for (i=0,tptr=tmpinlinf->method->paramtypes;imethod->paramcount;i++,tptr++) { + if ( ((*tptr)==TYPE_LNG) || + ((*tptr)==TYPE_DBL) ) + argBlockIdx+=2; + else + argBlockIdx++; + } + for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) { int op; @@ -583,55 +620,86 @@ void parse() } op += *tptr; - OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i); - - /* block_index[gp] |= (ipc << 1);*/ /*FIXME: necessary ? */ + if ( ((*tptr)==TYPE_LNG) || + ((*tptr)==TYPE_DBL) ) + argBlockIdx-=2; + else + argBlockIdx--; + + OP1(op, firstlocal + argBlockIdx); + /* OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i); */ + /* 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); +} inlining_save_compiler_variables(); +if (DEBUG==true) { +printf("AFTER SAVE: "); fflush(stdout); +DEBUGMETH(inline_env->method); +} inlining_set_compiler_variables(tmpinlinf); - if (compileverbose) { - char logtext[MAXLOGTEXT]; - sprintf(logtext, "Parsing (inlined): "); - utf_sprint(logtext+strlen(logtext), method->class->name); - strcpy(logtext+strlen(logtext), "."); - utf_sprint(logtext+strlen(logtext), method->name); - utf_sprint(logtext+strlen(logtext), method->descriptor); - log_text(logtext); +if (DEBUG==true) { +printf("AFTER SET :: "); fflush(stdout); +DEBUGMETH(inline_env->method); +} + if (DEBUG) { + printf("\n.......Parsing (inlined): "); + DEBUGMETH(m); + DEBUGMETH(inline_env->method); } + OP1(ICMD_INLINE_START,tmpinlinf->level); + if (inlinfo->inlinedmethods == NULL) { gp = -1; } else { tmpinlinf = list_first(inlinfo->inlinedmethods); nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1; } - if (method->exceptiontablelength > 0) - nextex = fillextable(nextex, method->exceptiontable, method->exceptiontablelength, label_index, &b_count); + if (inline_env->method->exceptiontablelength > 0) + nextex = fillextable(m, nextex, + inline_env->method->exceptiontable, inline_env->method->exceptiontablelength, + label_index, &b_count, inline_env); continue; } - opcode = code_get_u1(p); /* fetch op code */ - - - if (opt_rt && (pOpcodes == 2 || pOpcodes == 3)) { - printf("Parse<%i> p=%i<%i< opcode=<%i> %s\n", - pOpcodes, p, rt_jcodelength, opcode, icmd_names[opcode]); + 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[%d]=%d\n",p,label_index[p]); } - - block_index[gp] |= (ipc << 1); /* store intermediate count */ + /* +printf("basicblockindex[gp=%i]=%i=%p ipc=%i=%p shifted ipc=%i=%p\n", +gp,m->basicblockindex[gp],m->basicblockindex[gp],ipc,ipc,(ipc<<1),(ipc<<1)); +fflush(stdout); + */ + if (!skipBasicBlockChange) { + m->basicblockindex[gp] |= (ipc << 1); /*store intermed cnt*/ + } else skipBasicBlockChange=0; + /* +printf("basicblockindex[gp=%i]=%i=%p \n", +gp,m->basicblockindex[gp],m->basicblockindex[gp]); +fflush(stdout); + */ if (blockend) { 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 > jcodelength) + if (nextp > inline_env->method->jcodelength) panic("Unexpected end of bytecode"); s_count += stackreq[opcode]; /* compute stack element count */ - +SHOWOPCODE switch (opcode) { case JAVA_NOP: break; @@ -639,45 +707,41 @@ void parse() /* pushing constants onto the stack p */ case JAVA_BIPUSH: - LOADCONST_I(code_get_s1(p+1)); + LOADCONST_I(code_get_s1(p+1,inline_env->method)); break; case JAVA_SIPUSH: - LOADCONST_I(code_get_s2(p+1)); + LOADCONST_I(code_get_s2(p+1,inline_env->method)); break; case JAVA_LDC1: - i = code_get_u1(p+1); + i = code_get_u1(p+1,inline_env->method); + goto pushconstantitem; case JAVA_LDC2: case JAVA_LDC2W: - i = code_get_u2(p + 1); + i = code_get_u2(p + 1,inline_env->method); pushconstantitem: - if (i >= class->cpcount) + if (i >= inline_env->method->class->cpcount) panic ("Attempt to access constant outside range"); - switch (class->cptags[i]) { + switch (inline_env->method->class->cptags[i]) { case CONSTANT_Integer: - LOADCONST_I(((constant_integer*) - (class->cpinfos[i]))->value); + LOADCONST_I(((constant_integer *) (inline_env->method->class->cpinfos[i]))->value); break; case CONSTANT_Long: - LOADCONST_L(((constant_long*) - (class->cpinfos[i]))->value); + LOADCONST_L(((constant_long *) (inline_env->method->class->cpinfos[i]))->value); break; case CONSTANT_Float: - LOADCONST_F(((constant_float*) - (class->cpinfos[i]))->value); + LOADCONST_F(((constant_float *) (inline_env->method->class->cpinfos[i]))->value); break; case CONSTANT_Double: - LOADCONST_D(((constant_double*) - (class->cpinfos[i]))->value); + LOADCONST_D(((constant_double *) (inline_env->method->class->cpinfos[i]))->value); break; case CONSTANT_String: - LOADCONST_A(literalstring_new((utf*) - (class->cpinfos[i]))); + LOADCONST_A(literalstring_new((utf *) (inline_env->method->class->cpinfos[i]))); break; default: panic("Invalid constant type to push"); } @@ -721,9 +785,9 @@ void parse() case JAVA_DLOAD: case JAVA_ALOAD: if (!iswide) { - i = code_get_u1(p + 1); + i = code_get_u1(p + 1,inline_env->method); } else { - i = code_get_u2(p + 1); + i = code_get_u2(p + 1,inline_env->method); nextp = p + 3; iswide = false; } @@ -773,9 +837,9 @@ void parse() case JAVA_DSTORE: case JAVA_ASTORE: if (!iswide) { - i = code_get_u1(p + 1); + i = code_get_u1(p + 1,inline_env->method); } else { - i = code_get_u2(p + 1); + i = code_get_u2(p + 1,inline_env->method); iswide = false; nextp = p + 3; } @@ -822,12 +886,12 @@ void parse() int v; if (!iswide) { - i = code_get_u1(p + 1); - v = code_get_s1(p + 2); + i = code_get_u1(p + 1,inline_env->method); + v = code_get_s1(p + 2,inline_env->method); } else { - i = code_get_u2(p + 1); - v = code_get_s2(p + 3); + i = code_get_u2(p + 1,inline_env->method); + v = code_get_s2(p + 3,inline_env->method); iswide = false; nextp = p + 5; } @@ -846,8 +910,8 @@ void parse() /* managing arrays ************************************************/ case JAVA_NEWARRAY: - OP2I(ICMD_CHECKASIZE, 0, 0); - switch (code_get_s1(p + 1)) { + OP(ICMD_CHECKASIZE); + switch (code_get_s1(p + 1,inline_env->method)) { case 4: BUILTIN1(BUILTIN_newarray_boolean, TYPE_ADR,currentline); break; @@ -874,32 +938,36 @@ void parse() break; default: panic("Invalid array-type to create"); } - OP2I(ICMD_CHECKOOM, 0, 0); + OP(ICMD_CHECKEXCEPTION); break; case JAVA_ANEWARRAY: - OP2I(ICMD_CHECKASIZE, 0, 0); - i = code_get_u2(p + 1); + OP(ICMD_CHECKASIZE); + i = code_get_u2(p + 1,inline_env->method); { classinfo *component = - (classinfo *) class_getconstant(class, i, CONSTANT_Class); + (classinfo *) class_getconstant(inline_env->method->class, i, CONSTANT_Class); - class_load(component); - class_link(component); + if (!class_load(component)) + return NULL; + + if (!class_link(component)) + return NULL; LOADCONST_A_BUILTIN(class_array_of(component)->vftbl); /* LOADCONST_A_BUILTIN(component); */ s_count++; - BUILTIN2(BUILTIN_newarray, TYPE_ADR,currentline); + BUILTIN2(BUILTIN_newarray, TYPE_ADR, currentline); } - OP2I(ICMD_CHECKOOM, 0, 0); + OP(ICMD_CHECKEXCEPTION); break; case JAVA_MULTIANEWARRAY: - isleafmethod = false; - i = code_get_u2(p + 1); + inline_env->method->isleafmethod = false; + i = code_get_u2(p + 1,inline_env->method); { - s4 v = code_get_u1(p + 3); + vftbl_t *arrayvftbl; + s4 v = code_get_u1(p + 3,inline_env->method); /* vftbl *arrayvftbl = */ @@ -908,13 +976,16 @@ void parse() classinfo *component = - (classinfo *) class_getconstant(class, i, CONSTANT_Class); + (classinfo *) class_getconstant(inline_env->method->class, i, CONSTANT_Class); + + if (!class_load(component)) + return NULL; - class_load(component); - class_link(component); + if (!class_link(component)) + return NULL; - vftbl *arrayvftbl = component->vftbl; - OP2A(opcode, v, arrayvftbl,currentline); + arrayvftbl = component->vftbl; + OP2A(opcode, v, arrayvftbl, currentline); /* classinfo *arrayclass = */ /* (classinfo *) class_getconstant(class, i, CONSTANT_Class); */ @@ -940,7 +1011,7 @@ void parse() case JAVA_IF_ACMPNE: case JAVA_GOTO: case JAVA_JSR: - i = p + code_get_s2(p + 1); + i = p + code_get_s2(p + 1,inline_env->method); if (useinlining) { debug_writebranch; i = label_index[i]; @@ -952,12 +1023,13 @@ void parse() break; case JAVA_GOTO_W: case JAVA_JSR_W: - i = p + code_get_s4(p + 1); + i = p + code_get_s4(p + 1,inline_env->method); if (useinlining) { debug_writebranch; i = label_index[i]; } bound_check(i); + /*printf("B6 JSR_W\t"); fflush(stdout);*/ block_insert(i); blockend = true; OP1(opcode, i); @@ -965,16 +1037,16 @@ void parse() case JAVA_RET: if (!iswide) { - i = code_get_u1(p + 1); + i = code_get_u1(p + 1,inline_env->method); } else { - i = code_get_u2(p + 1); + i = code_get_u2(p + 1,inline_env->method); nextp = p + 3; iswide = false; } blockend = true; /* - if (isinlinedmethod) { + if (inline_env->isinlinedmethod) { OP1(ICMD_GOTO, inlinfo->stopgp); break; }*/ @@ -988,11 +1060,19 @@ void parse() case JAVA_DRETURN: case JAVA_ARETURN: case JAVA_RETURN: - if (isinlinedmethod) { - /* if (p==jcodelength-1) {*/ /* return is at end of inlined method */ + if (inline_env->isinlinedmethod) { + /* if (p==m->jcodelength-1) {*/ /* return is at end of inlined method */ /* OP(ICMD_NOP); */ /* break; */ /* } */ + if (nextp>inline_env->method->jcodelength-1) { + /* OP1(ICMD_GOTO, inlinfo->stopgp); + OP(ICMD_NOP); + OP(ICMD_NOP); + */ + blockend=true; + break; + } /* JJJJJJJ */ blockend = true; OP1(ICMD_GOTO, inlinfo->stopgp); break; @@ -1018,13 +1098,13 @@ void parse() blockend = true; nextp = ALIGN((p + 1), 4); - if (nextp + 8 > jcodelength) + if (nextp + 8 > inline_env->method->jcodelength) panic("Unexpected end of bytecode"); if (!useinlining) { - tablep = (s4*)(jcode + nextp); + tablep = (s4 *) (inline_env->method->jcode + nextp); } else { - num = code_get_u4(nextp + 4); + num = code_get_u4(nextp + 4,inline_env->method); tablep = DMNEW(s4, num * 2 + 2); } @@ -1032,7 +1112,7 @@ void parse() /* default target */ - j = p + code_get_s4(nextp); + j = p + code_get_s4(nextp,inline_env->method); if (useinlining) j = label_index[j]; *tablep = j; /* restore for little endian */ @@ -1043,18 +1123,18 @@ void parse() /* number of pairs */ - num = code_get_u4(nextp); + num = code_get_u4(nextp,inline_env->method); *tablep = num; tablep++; nextp += 4; - if (nextp + 8*(num) > jcodelength) + if (nextp + 8*(num) > inline_env->method->jcodelength) panic("Unexpected end of bytecode"); for (i = 0; i < num; i++) { /* value */ - j = code_get_s4(nextp); + j = code_get_s4(nextp,inline_env->method); *tablep = j; /* restore for little endian */ tablep++; nextp += 4; @@ -1067,7 +1147,7 @@ void parse() /* target */ - j = p + code_get_s4(nextp); + j = p + code_get_s4(nextp,inline_env->method); if (useinlining) j = label_index[j]; *tablep = j; /* restore for little endian */ @@ -1088,13 +1168,13 @@ void parse() blockend = true; nextp = ALIGN((p + 1), 4); - if (nextp + 12 > jcodelength) + if (nextp + 12 > inline_env->method->jcodelength) panic("Unexpected end of bytecode"); if (!useinlining) { - tablep = (s4*)(jcode + nextp); + tablep = (s4 *) (inline_env->method->jcode + nextp); } else { - num = code_get_u4(nextp + 8) - code_get_u4(nextp + 4); + num = code_get_u4(nextp + 8,inline_env->method) - code_get_u4(nextp + 4,inline_env->method); tablep = DMNEW(s4, num + 1 + 3); } @@ -1102,7 +1182,7 @@ void parse() /* default target */ - j = p + code_get_s4(nextp); + j = p + code_get_s4(nextp,inline_env->method); if (useinlining) j = label_index[j]; *tablep = j; /* restore for little endian */ @@ -1113,14 +1193,14 @@ void parse() /* lower bound */ - j = code_get_s4(nextp); + j = code_get_s4(nextp,inline_env->method); *tablep = j; /* restore for little endian */ tablep++; nextp += 4; /* upper bound */ - num = code_get_s4(nextp); + num = code_get_s4(nextp,inline_env->method); *tablep = num; /* restore for little endian */ tablep++; nextp += 4; @@ -1129,18 +1209,21 @@ void parse() if (num < 0) panic("invalid TABLESWITCH: upper bound < lower bound"); - if (nextp + 4*(num+1) > jcodelength) + if (nextp + 4*(num+1) > inline_env->method->jcodelength) panic("Unexpected end of bytecode"); for (i = 0; i <= num; i++) { - j = p + code_get_s4(nextp); - if (useinlining) + j = p + code_get_s4(nextp,inline_env->method); + if (useinlining) { + /*printf("TABLESWITCH: j before mapping=%ld\n",j);*/ j = label_index[j]; + } *tablep = j; /* restore for little endian */ tablep++; nextp += 4; bound_check(j); block_insert(j); + /*printf("TABLESWITCH: block_insert(%ld)\n",j);*/ } break; @@ -1150,47 +1233,65 @@ void parse() /* load and store of object fields *******************/ case JAVA_AASTORE: - BUILTIN3(BUILTIN_aastore, TYPE_VOID,currentline); + BUILTIN3(BUILTIN_aastore, TYPE_VOID, currentline); break; case JAVA_PUTSTATIC: case JAVA_GETSTATIC: - i = code_get_u2(p + 1); + i = code_get_u2(p + 1,inline_env->method); { constant_FMIref *fr; fieldinfo *fi; - fr = class_getconstant(class, i, CONSTANT_Fieldref); + fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref); + + if (!class_load(fr->class)) + return NULL; - class_load(fr->class); - class_link(fr->class); + if (!class_link(fr->class)) + return NULL; + + fi = class_resolvefield(fr->class, + fr->name, + fr->descriptor, + inline_env->method->class, + true); - fi = class_resolvefield(fr->class, fr->name, fr->descriptor, class, true); if (!fi) - panic("Exception thrown while parsing bytecode"); /* XXX should be passed on */ - OP2A(opcode, fi->type, fi,currentline); + return NULL; + + OP2A(opcode, fi->type, fi, currentline); if (!fi->class->initialized) { - isleafmethod = false; + inline_env->method->isleafmethod = false; } } break; case JAVA_PUTFIELD: case JAVA_GETFIELD: - i = code_get_u2(p + 1); + i = code_get_u2(p + 1,inline_env->method); { constant_FMIref *fr; fieldinfo *fi; - fr = class_getconstant (class, i, CONSTANT_Fieldref); + fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref); - class_load(fr->class); - class_link(fr->class); + 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); - fi = class_resolvefield(fr->class, fr->name, fr->descriptor, class, true); if (!fi) - panic("Exception thrown while parsing bytecode"); /* XXX should be passed on */ - OP2A(opcode, fi->type, fi,currentline); + return NULL; + + OP2A(opcode, fi->type, fi, currentline); } break; @@ -1198,163 +1299,201 @@ void parse() /* method invocation *****/ case JAVA_INVOKESTATIC: - i = code_get_u2(p + 1); + i = code_get_u2(p + 1,inline_env->method); { constant_FMIref *mr; methodinfo *mi; - mr = class_getconstant(class, i, CONSTANT_Methodref); + inline_env->method->isleafmethod = false; + + mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref); + + if (!class_load(mr->class)) + return NULL; - class_load(mr->class); - class_link(mr->class); + if (!class_link(mr->class)) + return NULL; + + mi = class_resolveclassmethod(mr->class, + mr->name, + mr->descriptor, + inline_env->method->class, + true); - mi = class_resolveclassmethod(mr->class, mr->name, mr->descriptor, class, true); if (!mi) - panic("Exception thrown while parsing bytecode"); /* XXX should be passed on */ - /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt) - /*RTAprint*/ {printf(" method name ="); - /*RTAprint*/ utf_display(mi->class->name); printf("."); - /*RTAprint*/ utf_display(mi->name);printf("\tINVOKE STATIC\n"); - /*RTAprint*/ fflush(stdout);} - if (!(mi->flags & ACC_STATIC)) - panic ("Static/Nonstatic mismatch calling static method"); - descriptor2types(mi); + return NULL; - isleafmethod=false; - OP2A(opcode, mi->paramcount, mi,currentline); +if (DEBUG4==true) { + method_display_w_class(mi); + printf("\tINVOKE STATIC\n"); + fflush(stdout);} + + if (!(mi->flags & ACC_STATIC)) { + *exceptionptr = + new_exception(string_java_lang_IncompatibleClassChangeError); + return NULL; + } + + descriptor2types(mi); + OP2A(opcode, mi->paramcount, mi, currentline); } break; case JAVA_INVOKESPECIAL: case JAVA_INVOKEVIRTUAL: - i = code_get_u2(p + 1); + i = code_get_u2(p + 1,inline_env->method); { constant_FMIref *mr; methodinfo *mi; - mr = class_getconstant(class, i, CONSTANT_Methodref); + inline_env->method->isleafmethod = false; + + mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref); + + if (!class_load(mr->class)) + return NULL; - class_load(mr->class); - class_link(mr->class); + if (!class_link(mr->class)) + return NULL; + + mi = class_resolveclassmethod(mr->class, + mr->name, + mr->descriptor, + inline_env->method->class, + true); - mi = class_resolveclassmethod(mr->class, mr->name, mr->descriptor, class, true); if (!mi) - panic("Exception thrown while parsing bytecode"); + return NULL; + +if (DEBUG4==true) { + method_display_w_class(mi); + printf("\tINVOKE SPEC/VIRT\n"); + fflush(stdout);} - /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt) - /*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; + } - if (mi->flags & ACC_STATIC) - panic ("Static/Nonstatic mismatch calling static method"); descriptor2types(mi); - isleafmethod=false; - OP2A(opcode, mi->paramcount, mi,currentline); + OP2A(opcode, mi->paramcount, mi, currentline); } break; case JAVA_INVOKEINTERFACE: - i = code_get_u2(p + 1); + i = code_get_u2(p + 1,inline_env->method); { constant_FMIref *mr; methodinfo *mi; - mr = class_getconstant(class, i, CONSTANT_InterfaceMethodref); + inline_env->method->isleafmethod = false; + + mr = class_getconstant(inline_env->method->class, i, CONSTANT_InterfaceMethodref); - class_load(mr->class); - class_link(mr->class); + if (!class_load(mr->class)) + return NULL; - mi = class_resolveinterfacemethod(mr->class, mr->name, mr->descriptor, class, true); + if (!class_link(mr->class)) + return NULL; + + mi = class_resolveinterfacemethod(mr->class, + mr->name, + mr->descriptor, + inline_env->method->class, + true); if (!mi) - panic("Exception thrown while parsing bytecode"); /* XXX should be passed on */ - if (mi->flags & ACC_STATIC) - panic ("Static/Nonstatic mismatch calling static method"); + return NULL; + + if (mi->flags & ACC_STATIC) { + *exceptionptr = + new_exception(string_java_lang_IncompatibleClassChangeError); + return NULL; + } + +if (DEBUG4==true) { + method_display_w_class(mi); + printf("\tINVOKE INTERFACE\n"); + fflush(stdout);} descriptor2types(mi); - isleafmethod=false; - OP2A(opcode, mi->paramcount, mi,currentline); + OP2A(opcode, mi->paramcount, mi, currentline); } break; /* miscellaneous object operations *******/ case JAVA_NEW: - i = code_get_u2 (p+1); - - LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class)); + 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); - OP2I(ICMD_CHECKOOM, 0, 0); + BUILTIN1(BUILTIN_new, TYPE_ADR, currentline); + OP(ICMD_CHECKEXCEPTION); break; case JAVA_CHECKCAST: - i = code_get_u2(p+1); - { - classinfo *cls = - (classinfo *) class_getconstant(class, i, CONSTANT_Class); - - /* is the class loaded */ - if (!cls->loaded) - class_load(cls); - - /* is the class linked */ - if (!cls->linked) - class_link(cls); - - if (cls->vftbl->arraydesc) { - /* array type cast-check */ - LOADCONST_A_BUILTIN(cls->vftbl); - 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); - } - } - + 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; + + if (!cls->linked) + if (!class_link(cls)) + return NULL; + + if (cls->vftbl->arraydesc) { + /* array type cast-check */ + LOADCONST_A_BUILTIN(cls->vftbl); + 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); + } + } break; case JAVA_INSTANCEOF: - i = code_get_u2(p+1); - - { - classinfo *cls = - (classinfo *) class_getconstant(class, i, CONSTANT_Class); - - /* is the class loaded */ - if (!cls->loaded) - class_load(cls); - - /* is the class linked */ - if (!cls->linked) - class_link(cls); - - if (cls->vftbl->arraydesc) { - /* array type cast-check */ - LOADCONST_A_BUILTIN(cls->vftbl); - 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); - } - } + 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; + + if (!cls->linked) + if (!class_link(cls)) + return NULL; + + if (cls->vftbl->arraydesc) { + /* array type cast-check */ + LOADCONST_A_BUILTIN(cls->vftbl); + 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); + } + } break; case JAVA_MONITORENTER: -#ifdef USE_THREADS +#if defined(USE_THREADS) if (checksync) { BUILTIN1(BUILTIN_monitorenter, TYPE_VOID,currentline); } else @@ -1365,11 +1504,11 @@ void parse() break; case JAVA_MONITOREXIT: -#ifdef USE_THREADS +#if defined(USE_THREADS) if (checksync) { BUILTIN1(BUILTIN_monitorexit, TYPE_VOID,currentline); - } - else + OP(ICMD_CHECKEXCEPTION); + } else #endif { OP(ICMD_POP); @@ -1455,12 +1594,11 @@ void parse() break; case JAVA_BREAKPOINT: - panic("Illegal opcode Breakpoint encountered"); - break; + *exceptionptr = + new_verifyerror(m, "Quick instructions shouldn't appear yet."); + return NULL; - case 186: /* unused opcode */ - case 203: - case 204: + case 204: /* unused opcode */ case 205: case 206: case 207: @@ -1528,12 +1666,20 @@ void parse() /* INLINING */ - if (isinlinedmethod && p == jcodelength - 1) { /* end of an inlined method */ + /* 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); */ gp = inlinfo->stopgp; inlining_restore_compiler_variables(); + OP(ICMD_INLINE_END); +/*label_index = inlinfo->label_index;*/ + +if (DEBUG==true) { +printf("AFTER RESTORE : "); fflush(stdout); +DEBUGMETH(inline_env->method); +} list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods)); - if (inlinfo->inlinedmethods == NULL) { + if (inlinfo->inlinedmethods == NULL) { /* JJJJ */ nextgp = -1; } else { tmpinlinf = list_first(inlinfo->inlinedmethods); @@ -1543,47 +1689,52 @@ void parse() label_index=inlinfo->label_index; firstlocal = inlinfo->firstlocal; } + } /* end for */ - if (p != jcodelength) - panic("Command-sequence crosses code-boundary"); - if (!blockend) - panic("Code does not end with branch/return/athrow - stmt"); + if (p != m->jcodelength) { + printf("p (%d) != m->jcodelength (%d)\n",p,m->jcodelength); + panic("Command-sequence crosses code-boundary"); + } + if (!blockend) { + *exceptionptr = new_verifyerror(m, "Falling off the end of the code"); + return NULL; + } - /* adjust block count if target 0 is not first intermediate instruction */ + /* adjust block count if target 0 is not first intermediate instruction */ - if (!block_index[0] || (block_index[0] > 1)) + if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) b_count++; - /* copy local to global variables */ + /* copy local to method variables */ - instr_count = ipc; - block_count = b_count; - stack_count = s_count + block_count * maxstack; + m->instructioncount = ipc; + m->basicblockcount = b_count; + m->stackcount = s_count + m->basicblockcount * m->maxstack; /* allocate stack table */ - stack = DMNEW(stackelement, stack_count); + m->stack = DMNEW(stackelement, m->stackcount); { - basicblock *bptr; + basicblock *bptr; - bptr = block = DMNEW(basicblock, b_count + 1); /* one more for end ipc */ + bptr = m->basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */ b_count = 0; - c_debug_nr = 0; + m->c_debug_nr = 0; - /* additional block if target 0 is not first intermediate instruction */ + /* additional block if target 0 is not first intermediate instruction */ - if (!block_index[0] || (block_index[0] > 1)) { - bptr->iinstr = instr; + if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) { + bptr->iinstr = m->instructions; bptr->mpc = -1; bptr->flags = -1; bptr->type = BBTYPE_STD; bptr->branchrefs = NULL; bptr->pre_count = 0; - bptr->debug_nr = c_debug_nr++; + bptr->debug_nr = m->c_debug_nr++; bptr++; b_count++; (bptr - 1)->next = bptr; @@ -1591,14 +1742,17 @@ void parse() /* allocate blocks */ - for (p = 0; p < cumjcodelength; p++) { - if (block_index[p] & 1) { + 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 */ - if (!instructionstart[p]) + if (!instructionstart[p]) { + printf("Basic Block beginn: %d\n",p); panic("Branch into middle of instruction"); + } /* allocate the block */ - bptr->iinstr = instr + (block_index[p] >> 1); - bptr->debug_nr = c_debug_nr++; + bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1); + bptr->debug_nr = m->c_debug_nr++; if (b_count != 0) (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr; bptr->mpc = -1; @@ -1606,7 +1760,7 @@ void parse() bptr->lflags = 0; bptr->type = BBTYPE_STD; bptr->branchrefs = NULL; - block_index[p] = b_count; + m->basicblockindex[p] = b_count; bptr->pre_count = 0; bptr++; b_count++; @@ -1619,7 +1773,7 @@ void parse() bptr->instack = bptr->outstack = NULL; bptr->indepth = bptr->outdepth = 0; bptr->iinstr = NULL; - (bptr - 1)->icount = (instr + instr_count) - (bptr - 1)->iinstr; + (bptr - 1)->icount = (m->instructions + m->instructioncount) - (bptr - 1)->iinstr; bptr->icount = 0; bptr->mpc = -1; bptr->flags = -1; @@ -1627,41 +1781,31 @@ void parse() bptr->type = BBTYPE_STD; bptr->branchrefs = NULL; bptr->pre_count = 0; - bptr->debug_nr = c_debug_nr++; + bptr->debug_nr = m->c_debug_nr++; (bptr - 1)->next = bptr; bptr->next = NULL; - last_block = bptr; - - if (exceptiontablelength > 0) - extable[exceptiontablelength - 1].down = NULL; - else - extable = NULL; - - for (i = 0; i < exceptiontablelength; ++i) { - p = extable[i].startpc; - extable[i].start = block + block_index[p]; + if (cd->exceptiontablelength > 0) { + cd->exceptiontable[cd->exceptiontablelength - 1].down = NULL; + } + + for (i = 0; i < cd->exceptiontablelength; ++i) { + p = cd->exceptiontable[i].startpc; + cd->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p]; - p = extable[i].endpc; - extable[i].end = (p == cumjcodelength) ? last_block : (block + block_index[p]); + p = cd->exceptiontable[i].endpc; + cd->exceptiontable[i].end = (p == inline_env->method->jcodelength) ? (m->basicblocks + m->basicblockcount /*+ 1*/) : (m->basicblocks + m->basicblockindex[p]); - p = extable[i].handlerpc; - extable[i].handler = block + block_index[p]; + p = cd->exceptiontable[i].handlerpc; + cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p]; } } - if (useinlining) inlining_cleanup(); - useinlining = useinltmp; - - if (compileverbose) { - char logtext[MAXLOGTEXT]; - sprintf(logtext, "Parsing done: "); - utf_sprint_classname(logtext + strlen(logtext), method->class->name); - strcpy(logtext + strlen(logtext), "."); - utf_sprint(logtext + strlen(logtext), method->name); - utf_sprint_classname(logtext + strlen(logtext), method->descriptor); - log_text(logtext); - } + if (useinlining) inlining_cleanup(inline_env); + + /* just return methodinfo* to signal everything was ok */ + + return m; }