-/* vm/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-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
- R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
- C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
- Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
- Contact: cacao@complang.tuwien.ac.at
+ Contact: cacao@cacaojvm.org
Author: Andreas Krall
Changes: Carolyn Oates
Edwin Steiner
Joseph Wenninger
+ Christian Thalinger
- $Id: parse.c 2189 2005-04-02 02:05:59Z edwin $
+ $Id: parse.c 4357 2006-01-22 23:33:38Z twisti $
*/
+#include <assert.h>
#include <string.h>
#include "config.h"
-#include "types.h"
+
+#include "vm/types.h"
+
#include "mm/memory.h"
#include "native/native.h"
#include "toolbox/logging.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"
-bool DEBUG = false;
-bool DEBUG2 = false;
-bool DEBUG3 = false;
-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%p\n",opcode_names[opcode], i, label_index[i], (void *)label_index);
-#define debug_writebranch1
-
/*******************************************************************************
function 'parse' scans the JavaVM code and generates intermediate code
*******************************************************************************/
-static exceptiontable* fillextable(methodinfo *m,
- exceptiontable* extable, exceptiontable *raw_extable,
- int exceptiontablelength,
- int *label_index, int *block_count,
- t_inlining_globals *inline_env)
+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, p, src, insertBlock;
if (exceptiontablelength == 0)
return extable;
- /*if (m->exceptiontablelength > 0) {
- METHINFOx(m);
- printf("m->exceptiontablelength=%i\n",m->exceptiontablelength);
- panic("exceptiontablelength > 0");
- }*/
-
b_count = *block_count;
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->startpc = p;
bound_check(p);
block_insert(p);
-/*** 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) {
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "Invalid exception handler range");
+ return NULL;
+ }
if (p >inline_env->method->jcodelength) {
- panic("Invalid exception handler end is after code end");
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "Invalid exception handler end is after code end");
+ return NULL;
}
+
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);*/
if (label_index != NULL) p = label_index[p];
extable->endpc = p;
bound_check1(p);
- /*if (p < inline_env->method->jcodelength) {
- block_insert(p); }*/
- if (insertBlock) block_insert(p);
+ /* if (p < inline_env->method->jcodelength) block_insert(p); */
+ if (insertBlock)
+ block_insert(p);
p = raw_extable[src].handlerpc;
if (label_index != NULL) p = label_index[p];
exceptiontable* nextex; /* points next free entry in extable */
u1 *instructionstart; /* 1 for pcs which are valid instr. starts */
+ constant_classref *cr;
+ constant_classref *compr;
+ classinfo *c;
+ builtintable_entry *bte;
+
u2 lineindex = 0;
u2 currentline = 0;
u2 linepcchange = 0;
u2 skipBasicBlockChange;
-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/xta missed: "); fflush(stdout);
- METHINFO(m,opt_verbose);
- }
- if ( (Missed = fopen("Missed", "a")) == NULL) {
- printf("CACAO - rt/xtaMissed file: cant open file to write append \n");
- }
- else {
- 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 */
-
- 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;
- }
-
-/**** 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 * # cum inline methods*/
memset(iptr, 0, sizeof(instruction) * (inline_env->cumjcodelength + 5));
/* compute branch targets of exception table */
- /*
-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(m,
&(cd->exceptiontable[cd->exceptiontablelength-1]), m->exceptiontable, m->exceptiontablelength,
label_index, &b_count, inline_env);
+ if (!nextex)
+ return NULL;
s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */
#if defined(USE_THREADS)
if (m->linenumbercount == 0) {
lineindex = 0;
-
} else {
linepcchange = m->linenumbers[0].start_pc;
}
skipBasicBlockChange=0;
for (p = 0, gp = 0; p < inline_env->method->jcodelength; gp += (nextp - p), p = nextp) {
- /* 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 (inline_env->method->linenumbercount > lineindex) {
currentline = inline_env->method->linenumbers[lineindex].line_number;
lineindex++;
if (lineindex < inline_env->method->linenumbercount)
linepcchange = inline_env->method->linenumbers[lineindex].start_pc;
- /*printf("Line number changed to: %ld\n",currentline);*/
}
}
}
- /*INLINING*/
- 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,inline_env->method);
- nextp = p += jcommandsize[opcode];
- 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;i<tmpinlinf->method->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;
-
- if ((i == 0) && inlineparamopt) {
- OP1(ICMD_CLEAR_ARGREN, firstlocal);
- }
-
- if (!inlineparamopt || !readonly[i]) {
- op = ICMD_ISTORE;
-
- } else {
- op = ICMD_READONLY_ARG;
- }
+ /* fetch next opcode */
- op += *tptr;
- if ( ((*tptr)==TYPE_LNG) ||
- ((*tptr)==TYPE_DBL) )
- argBlockIdx-=2;
- else
- argBlockIdx--;
+ opcode = code_get_u1(p, inline_env->method);
- 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;
-METHINFOt(inline_env->method,"BEFORE SAVE: ",DEBUG);
- inlining_save_compiler_variables();
-METHINFOt(inline_env->method,"AFTER SAVE: ",DEBUG);
- inlining_set_compiler_variables(tmpinlinf);
-METHINFOt(inline_env->method,"AFTER SET :: ",DEBUG);
-METHINFOt(m,"\n.......Parsing (inlined): ",DEBUG);
-METHINFO(inline_env->method,DEBUG);
-
- 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 (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,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]);
- }
- /*
-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 */
+
+ /* some compilers put a JAVA_NOP after a blockend instruction */
+
+ if ((opcode != JAVA_NOP) && (blockend == true)) {
+ /* start new block */
+
+ block_insert(gp);
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) {
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "Unexpected end of bytecode");
+ return NULL;
+ }
+
s_count += stackreq[opcode]; /* compute stack element count */
-SHOWOPCODE(DEBUG4)
switch (opcode) {
case JAVA_NOP:
break;
break;
case JAVA_LDC1:
- i = code_get_u1(p+1,inline_env->method);
-
+ i = code_get_u1(p + 1, inline_env->method);
goto pushconstantitem;
+
case JAVA_LDC2:
case JAVA_LDC2W:
- i = code_get_u2(p + 1,inline_env->method);
+ i = code_get_u2(p + 1, inline_env->method);
pushconstantitem:
- if (i >= inline_env->method->class->cpcount)
- panic ("Attempt to access constant outside range");
+ if (i >= inline_env->method->class->cpcount) {
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "Attempt to access constant outside range");
+ return NULL;
+ }
switch (inline_env->method->class->cptags[i]) {
case CONSTANT_Integer:
case CONSTANT_String:
LOADCONST_A(literalstring_new((utf *) (inline_env->method->class->cpinfos[i])));
break;
- default: panic("Invalid constant type to push");
+ case CONSTANT_Class:
+ cr = (constant_classref *) (inline_env->method->class->cpinfos[i]);
+
+ if (!resolve_classref(inline_env->method, cr, resolveLazy, true,
+ true, &c))
+ return NULL;
+
+ /* if not resolved, c == NULL */
+
+ LOADCONST_A_CLASS(c, cr);
+ break;
+ default:
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "Invalid constant type to push");
+ return NULL;
}
break;
nextp = p + 1;
break;
- /* managing arrays ************************************************/
+ /* managing arrays ****************************************************/
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);
+ bte = builtintable_get_internal(BUILTIN_newarray_boolean);
break;
case 5:
- BUILTIN1(BUILTIN_newarray_char, TYPE_ADR,currentline);
+ bte = builtintable_get_internal(BUILTIN_newarray_char);
break;
case 6:
- BUILTIN1(BUILTIN_newarray_float, TYPE_ADR,currentline);
+ bte = builtintable_get_internal(BUILTIN_newarray_float);
break;
case 7:
- BUILTIN1(BUILTIN_newarray_double, TYPE_ADR,currentline);
+ bte = builtintable_get_internal(BUILTIN_newarray_double);
break;
case 8:
- BUILTIN1(BUILTIN_newarray_byte, TYPE_ADR,currentline);
+ bte = builtintable_get_internal(BUILTIN_newarray_byte);
break;
case 9:
- BUILTIN1(BUILTIN_newarray_short, TYPE_ADR,currentline);
+ bte = builtintable_get_internal(BUILTIN_newarray_short);
break;
case 10:
- BUILTIN1(BUILTIN_newarray_int, TYPE_ADR,currentline);
+ bte = builtintable_get_internal(BUILTIN_newarray_int);
break;
case 11:
- BUILTIN1(BUILTIN_newarray_long, TYPE_ADR,currentline);
+ bte = builtintable_get_internal(BUILTIN_newarray_long);
break;
- default: panic("Invalid array-type to create");
+ default:
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "Invalid array-type to create");
+ return NULL;
}
- OP(ICMD_CHECKEXCEPTION);
+ BUILTIN(bte, true, NULL, currentline);
break;
case JAVA_ANEWARRAY:
- OP(ICMD_CHECKASIZE);
- i = code_get_u2(p + 1,inline_env->method);
- {
- classinfo *component =
- (classinfo *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
+ i = code_get_u2(p + 1, inline_env->method);
+ compr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
+ if (!compr)
+ return NULL;
-#if 1
- if (!load_class_from_classloader(component, m->class->classloader))
- return NULL;
+ if (!(cr = class_get_classref_multiarray_of(1, compr)))
+ return NULL;
- if (!link_class(component))
- return NULL;
+ if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
+ return NULL;
- LOADCONST_A_BUILTIN(class_array_of(component)->vftbl);
- s_count++;
- BUILTIN2(BUILTIN_newarray, TYPE_ADR, currentline);
-#else
- LOADCONST_A_BUILTIN(component);
- s_count++;
- BUILTIN2(BUILTIN_anewarray, TYPE_ADR, currentline);
-#endif
- }
- OP(ICMD_CHECKEXCEPTION);
+ LOADCONST_A_BUILTIN(c, cr);
+ bte = builtintable_get_internal(BUILTIN_newarray);
+ BUILTIN(bte, true, NULL, currentline);
+ s_count++;
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);
-
-
-/* vftbl *arrayvftbl = */
-/* ((classinfo *) class_getconstant(class, i, CONSTANT_Class))->vftbl; */
-/* OP2A(opcode, v, arrayvftbl,currentline); */
+ s4 v = code_get_u1(p + 3, inline_env->method);
-
- classinfo *component =
- (classinfo *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
-
- if (!load_class_from_classloader(component, m->class->classloader))
+ cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
+ if (!cr)
return NULL;
- if (!link_class(component))
+ if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
return NULL;
- arrayvftbl = component->vftbl;
- OP2A(opcode, v, arrayvftbl, currentline);
-
-/* classinfo *arrayclass = */
-/* (classinfo *) class_getconstant(class, i, CONSTANT_Class); */
-/* OP2A(opcode, v, arrayclass, currentline); */
+ /* if unresolved, c == NULL */
+ OP2AT(opcode, v, c, cr, currentline);
}
break;
case JAVA_JSR:
i = p + code_get_s2(p + 1,inline_env->method);
if (useinlining) {
- debug_writebranch;
i = label_index[i];
}
bound_check(i);
blockend = true;
OP1(opcode, i);
break;
+
case JAVA_GOTO_W:
case JAVA_JSR_W:
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);
}
blockend = true;
+ /* zero val.a so no patcher is inserted */
+ /* the type checker may set this later */
+ iptr->val.a = NULL;
OP(opcode);
break;
case JAVA_ATHROW:
blockend = true;
+ /* zero val.a so no patcher is inserted */
+ /* the type checker may set this later */
+ iptr->val.a = NULL;
OP(opcode);
break;
- /* table jumps ********************************/
+ /* table jumps ********************************************************/
case JAVA_LOOKUPSWITCH:
{
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) {
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "Unexpected end of bytecode");
+ return NULL;
+ }
+
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 */
/* 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) {
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "Unexpected end of bytecode");
+ return NULL;
+ }
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;
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) {
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "Unexpected end of bytecode");
+ return NULL;
+ }
+
if (!useinlining) {
tablep = (s4 *) (inline_env->method->jcode + nextp);
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 */
/* 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) {
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "invalid TABLESWITCH: upper bound < lower bound");
+ return NULL;
+ }
+
+ if (nextp + 4 * (num + 1) > inline_env->method->jcodelength) {
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "Unexpected end of bytecode");
+ return NULL;
+ }
for (i = 0; i <= num; i++) {
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 */
nextp += 4;
bound_check(j);
block_insert(j);
- /*printf("TABLESWITCH: block_insert(%ld)\n",j);*/
}
break;
}
- /* load and store of object fields *******************/
+ /* load and store of object fields ************************************/
case JAVA_AASTORE:
- BUILTIN3(BUILTIN_aastore, TYPE_VOID, currentline);
+ OP(opcode);
+ inline_env->method->isleafmethod = false;
break;
- case JAVA_PUTSTATIC:
case JAVA_GETSTATIC:
- i = code_get_u2(p + 1,inline_env->method);
+ case JAVA_PUTSTATIC:
+ case JAVA_GETFIELD:
+ case JAVA_PUTFIELD:
{
- constant_FMIref *fr;
- fieldinfo *fi;
- classinfo *frclass;
-
- fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref);
- if (!resolve_classref(inline_env->method,fr->classref,resolveEager,true,&frclass))
+ constant_FMIref *fr;
+ unresolved_field *uf;
+ fieldinfo *fi;
+
+ i = code_get_u2(p + 1, inline_env->method);
+ fr = class_getconstant(inline_env->method->class, i,
+ CONSTANT_Fieldref);
+ if (!fr)
return NULL;
- fi = class_resolvefield(frclass,
- fr->name,
- fr->descriptor,
- inline_env->method->class,
- true);
+ OP2A_NOINC(opcode, fr->parseddesc.fd->type, fr, currentline);
- if (!fi)
+ if (!(uf = create_unresolved_field(inline_env->method->class,
+ inline_env->method,
+ iptr)))
return NULL;
- OP2A(opcode, fi->type, fi, currentline);
- if (!fi->class->initialized) {
- inline_env->method->isleafmethod = false;
- }
- }
- break;
+ /* store unresolved_field pointer */
- case JAVA_PUTFIELD:
- case JAVA_GETFIELD:
- i = code_get_u2(p + 1,inline_env->method);
- {
- constant_FMIref *fr;
- fieldinfo *fi;
- classinfo *frclass;
+ iptr->target = uf;
- fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref);
- if (!resolve_classref(inline_env->method,fr->classref,resolveEager,true,&frclass))
- return NULL;
+ /* only with -noverify, otherwise the typechecker does this */
- fi = class_resolvefield(frclass,
- fr->name,
- fr->descriptor,
- inline_env->method->class,
- true);
+ if (!opt_verify) {
+ if (!resolve_field(uf, resolveLazy, &fi))
+ return NULL;
- if (!fi)
- return NULL;
+ iptr->val.a = fi;
- OP2A(opcode, fi->type, fi, currentline);
+ } else {
+ iptr->val.a = NULL;
+ }
+ PINC;
}
break;
- /* method invocation *****/
+ /* 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;
- classinfo *mrclass;
-
+ constant_FMIref *mr;
+ methoddesc *md;
+ unresolved_method *um;
+ methodinfo *mi;
+
inline_env->method->isleafmethod = false;
- mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref);
- if (!resolve_classref(inline_env->method,mr->classref,resolveEager,true,&mrclass))
+ mr = class_getconstant(inline_env->method->class, i,
+ CONSTANT_Methodref);
+ if (!mr)
return NULL;
- mi = class_resolveclassmethod(mrclass,
- mr->name,
- mr->descriptor,
- inline_env->method->class,
- true);
+ md = mr->parseddesc.md;
- if (!mi)
- return NULL;
+ if (!md->params)
+ if (!descriptor_params_from_paramtypes(md, ACC_STATIC))
+ return NULL;
+
+ OP2A_NOINC(opcode, 0, mr, currentline);
-if (DEBUG4==true) {
- method_display_w_class(mi);
- printf("\tINVOKE STATIC\n");
- fflush(stdout);}
+ um = create_unresolved_method(inline_env->method->class,
+ inline_env->method, iptr);
- if (!(mi->flags & ACC_STATIC)) {
- *exceptionptr =
- new_exception(string_java_lang_IncompatibleClassChangeError);
+ if (!um)
return NULL;
- }
- method_descriptor2types(mi);
- OP2A(opcode, mi->paramcount, mi, currentline);
+ /* store the unresolved_method pointer */
+
+ iptr->target = um;
+
+ /* only with -noverify, otherwise the typechecker does this */
+
+ if (!opt_verify) {
+ if (!resolve_method(um, resolveLazy, &mi))
+ return NULL;
+
+ iptr->val.a = mi;
+ }
+ else {
+ iptr->val.a = NULL;
+ }
+ PINC;
}
break;
case JAVA_INVOKESPECIAL:
case JAVA_INVOKEVIRTUAL:
- i = code_get_u2(p + 1,inline_env->method);
{
- constant_FMIref *mr;
- methodinfo *mi;
- classinfo *mrclass;
+ constant_FMIref *mr;
+ methoddesc *md;
+ unresolved_method *um;
+ methodinfo *mi;
inline_env->method->isleafmethod = false;
- mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref);
- if (!resolve_classref(inline_env->method,mr->classref,resolveEager,true,&mrclass))
+ i = code_get_u2(p + 1, inline_env->method);
+ mr = class_getconstant(inline_env->method->class, i,
+ CONSTANT_Methodref);
+ if (!mr)
return NULL;
- mi = class_resolveclassmethod(mrclass,
- mr->name,
- mr->descriptor,
- inline_env->method->class,
- true);
+ md = mr->parseddesc.md;
- if (!mi)
- return NULL;
+ if (!md->params)
+ if (!descriptor_params_from_paramtypes(md, 0))
+ return NULL;
+
+ OP2A_NOINC(opcode, 0, mr, currentline);
-if (DEBUG4==true) {
- method_display_w_class(mi);
- printf("\tINVOKE SPEC/VIRT\n");
- fflush(stdout);}
+ um = create_unresolved_method(inline_env->method->class,
+ inline_env->method, iptr);
- if (mi->flags & ACC_STATIC) {
- *exceptionptr =
- new_exception(string_java_lang_IncompatibleClassChangeError);
+ if (!um)
return NULL;
- }
- method_descriptor2types(mi);
- OP2A(opcode, mi->paramcount, mi, currentline);
+ /* store the unresolved_method* */
+
+ iptr->target = um;
+
+ /* only with -noverify, otherwise the typechecker does this */
+
+ if (!opt_verify) {
+ if (!resolve_method(um, resolveLazy, &mi))
+ return NULL;
+
+ iptr->val.a = mi;
+ }
+ else {
+ iptr->val.a = NULL;
+ }
+ PINC;
}
break;
case JAVA_INVOKEINTERFACE:
- i = code_get_u2(p + 1,inline_env->method);
+ i = code_get_u2(p + 1, inline_env->method);
{
- constant_FMIref *mr;
- methodinfo *mi;
- classinfo *mrclass;
+ constant_FMIref *mr;
+ methoddesc *md;
+ unresolved_method *um;
+ methodinfo *mi;
inline_env->method->isleafmethod = false;
- mr = class_getconstant(inline_env->method->class, i, CONSTANT_InterfaceMethodref);
- if (!resolve_classref(inline_env->method,mr->classref,resolveEager,true,&mrclass))
+ mr = class_getconstant(inline_env->method->class, i,
+ CONSTANT_InterfaceMethodref);
+ if (!mr)
return NULL;
- mi = class_resolveinterfacemethod(mrclass,
- mr->name,
- mr->descriptor,
- inline_env->method->class,
- true);
- if (!mi)
- return NULL;
+ md = mr->parseddesc.md;
+
+ if (!md->params)
+ if (!descriptor_params_from_paramtypes(md, 0))
+ return NULL;
- if (mi->flags & ACC_STATIC) {
- *exceptionptr =
- new_exception(string_java_lang_IncompatibleClassChangeError);
+ OP2A_NOINC(opcode, 0, mr, currentline);
+
+ um = create_unresolved_method(inline_env->method->class,
+ inline_env->method, iptr);
+
+ if (!um)
return NULL;
- }
-if (DEBUG4==true) {
- method_display_w_class(mi);
- printf("\tINVOKE INTERFACE\n");
- fflush(stdout);}
- method_descriptor2types(mi);
- OP2A(opcode, mi->paramcount, mi, currentline);
+ /* store the unresolved_method* */
+
+ iptr->target = um;
+
+ /* only with -noverify, otherwise the typechecker does this */
+
+ if (!opt_verify) {
+ if (!resolve_method(um, resolveLazy, &mi))
+ return NULL;
+
+ iptr->val.a = mi;
+ }
+ else {
+ iptr->val.a = NULL;
+ }
+ PINC;
}
break;
- /* miscellaneous object operations *******/
+ /* 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));
+ i = code_get_u2(p + 1, inline_env->method);
+ cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
+ if (!cr)
+ return NULL;
+
+ if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true,
+ &c))
+ return NULL;
+
+ LOADCONST_A_BUILTIN(c, cr);
+ bte = builtintable_get_internal(BUILTIN_new);
+ BUILTIN(bte, true, NULL, currentline);
s_count++;
- BUILTIN1(BUILTIN_new, TYPE_ADR, currentline);
- OP(ICMD_CHECKEXCEPTION);
break;
case JAVA_CHECKCAST:
- i = code_get_u2(p + 1,inline_env->method);
- {
- classinfo *cls =
- (classinfo *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
-
- if (!load_class_from_classloader(cls, m->class->classloader))
- return NULL;
-
- if (!link_class(cls))
- return NULL;
+ i = code_get_u2(p + 1, inline_env->method);
+ cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
+ if (!cr)
+ return NULL;
+
+ if (!resolve_classref(inline_env->method, cr, resolveLazy, true,
+ true, &c))
+ return NULL;
+
+ if (cr->name->text[0] == '[') {
+ /* array type cast-check */
+ OP2AT(opcode, 0, c, cr, currentline);
+ inline_env->method->isleafmethod = false;
- 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);
- }
+ } else {
+ /* object type cast-check */
+ OP2AT(opcode, 1, c, cr, currentline);
}
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 (!load_class_from_classloader(cls, m->class->classloader))
- return NULL;
-
- if (!link_class(cls))
- return NULL;
+ cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
+ if (!cr)
+ return NULL;
+
+ if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
+ return NULL;
+
+ if (cr->name->text[0] == '[') {
+ /* array type cast-check */
+ LOADCONST_A_BUILTIN(c, cr);
+ bte = builtintable_get_internal(BUILTIN_arrayinstanceof);
+ BUILTIN(bte, false, NULL, currentline);
+ s_count++;
- 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);
- }
+ } else {
+ /* object type cast-check */
+ OP2AT(opcode, 1, c, cr, currentline);
}
break;
case JAVA_MONITORENTER:
#if defined(USE_THREADS)
if (checksync) {
- BUILTIN1(BUILTIN_monitorenter, TYPE_VOID,currentline);
+ OP(ICMD_CHECKNULL);
+ bte = builtintable_get_internal(BUILTIN_monitorenter);
+ BUILTIN(bte, false, NULL, currentline);
} else
#endif
{
- OP(ICMD_NULLCHECKPOP);
+ OP(ICMD_CHECKNULL);
+ OP(ICMD_POP);
}
break;
case JAVA_MONITOREXIT:
#if defined(USE_THREADS)
if (checksync) {
- BUILTIN1(BUILTIN_monitorexit, TYPE_VOID,currentline);
- OP(ICMD_CHECKEXCEPTION);
+ bte = builtintable_get_internal(BUILTIN_monitorexit);
+ BUILTIN(bte, false, NULL, currentline);
} else
#endif
{
}
break;
- /* any other basic operation **************************************/
+ /* any other basic operation ******************************************/
case JAVA_IDIV:
+#if !SUPPORT_DIVISION
+ bte = builtintable_get_internal(BUILTIN_idiv);
+ OP2A(opcode, bte->md->paramcount, bte, currentline);
+ inline_env->method->isleafmethod = false;
+#else
OP(opcode);
+#endif
break;
case JAVA_IREM:
+#if !SUPPORT_DIVISION
+ bte = builtintable_get_internal(BUILTIN_irem);
+ OP2A(opcode, bte->md->paramcount, bte, currentline);
+ inline_env->method->isleafmethod = false;
+#else
OP(opcode);
+#endif
break;
case JAVA_LDIV:
+#if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
+ bte = builtintable_get_internal(BUILTIN_ldiv);
+ OP2A(opcode, bte->md->paramcount, bte, currentline);
+ inline_env->method->isleafmethod = false;
+#else
OP(opcode);
+#endif
break;
case JAVA_LREM:
+#if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
+ bte = builtintable_get_internal(BUILTIN_lrem);
+ OP2A(opcode, bte->md->paramcount, bte, currentline);
+ inline_env->method->isleafmethod = false;
+#else
OP(opcode);
+#endif
break;
case JAVA_FREM:
#if defined(__I386__)
OP(opcode);
#else
- BUILTIN2(BUILTIN_frem, TYPE_FLOAT,currentline);
+ bte = builtintable_get_internal(BUILTIN_frem);
+ BUILTIN(bte, false, NULL, currentline);
#endif
break;
#if defined(__I386__)
OP(opcode);
#else
- BUILTIN2(BUILTIN_drem, TYPE_DOUBLE,currentline);
+ bte = builtintable_get_internal(BUILTIN_drem);
+ BUILTIN(bte, false, NULL, currentline);
#endif
break;
case JAVA_F2I:
#if defined(__ALPHA__)
if (!opt_noieee) {
- BUILTIN1(BUILTIN_f2i, TYPE_INT,currentline);
+ bte = builtintable_get_internal(BUILTIN_f2i);
+ BUILTIN(bte, false, NULL, currentline);
} else
#endif
{
case JAVA_F2L:
#if defined(__ALPHA__)
if (!opt_noieee) {
- BUILTIN1(BUILTIN_f2l, TYPE_LONG,currentline);
+ bte = builtintable_get_internal(BUILTIN_f2l);
+ BUILTIN(bte, false, NULL, currentline);
} else
#endif
{
case JAVA_D2I:
#if defined(__ALPHA__)
if (!opt_noieee) {
- BUILTIN1(BUILTIN_d2i, TYPE_INT,currentline);
+ bte = builtintable_get_internal(BUILTIN_d2i);
+ BUILTIN(bte, false, NULL, currentline);
} else
#endif
{
case JAVA_D2L:
#if defined(__ALPHA__)
if (!opt_noieee) {
- BUILTIN1(BUILTIN_d2l, TYPE_LONG,currentline);
+ bte = builtintable_get_internal(BUILTIN_d2l);
+ BUILTIN(bte, false, NULL, currentline);
} else
#endif
{
new_verifyerror(m, "Quick instructions shouldn't appear yet.");
return NULL;
- case 204: /* unused opcode */
+ case 186: /* unused opcode */
+ case 203:
+ case 204:
case 205:
case 206:
case 207:
case 253:
case 254:
case 255:
- printf("Illegal opcode %d at instr %d\n", opcode, ipc);
- panic("Illegal opcode encountered");
+ *exceptionptr =
+ new_verifyerror(inline_env->method,"Illegal opcode %d at instr %d\n",
+ opcode, ipc);
+ return NULL;
break;
default:
} /* 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) {
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "Illegal instruction: WIDE before incompatible opcode");
+ return NULL;
+ }
+
+#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); */
gp = inlinfo->stopgp;
inlining_restore_compiler_variables();
OP(ICMD_INLINE_END);
-/*label_index = inlinfo->label_index;*/
+ /*label_index = inlinfo->label_index;*/
-METHINFOt(inline_env->method,"AFTER RESTORE : ",DEBUG);
list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
if (inlinfo->inlinedmethods == NULL) { /* JJJJ */
nextgp = -1;
tmpinlinf = list_first(inlinfo->inlinedmethods);
nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
}
- /* printf("nextpgp: %d\n", nextgp); */
label_index=inlinfo->label_index;
firstlocal = inlinfo->firstlocal;
}
+#endif /* defined(USE_INLINING) */
} /* end for */
if (p != m->jcodelength) {
printf("p (%d) != m->jcodelength (%d)\n",p,m->jcodelength);
- panic("Command-sequence crosses code-boundary");
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "Command-sequence crosses code-boundary");
+ return NULL;
}
+
if (!blockend) {
*exceptionptr = new_verifyerror(m, "Falling off the end of the code");
return NULL;
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: %d\n",p);
- panic("Branch into middle of instruction");
+ *exceptionptr = new_verifyerror(inline_env->method,
+ "Branch into middle of instruction");
+ return NULL;
}
+
/* allocate the block */
bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
bptr->debug_nr = m->c_debug_nr++;
cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
}
}
-
- if (useinlining) inlining_cleanup(inline_env);
/* just return methodinfo* to signal everything was ok */
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/
-