1 /* src/vm/jit/parse.c - parser for JavaVM to intermediate code translation
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
29 Changes: Carolyn Oates
34 $Id: parse.c 2783 2005-06-22 12:05:49Z edwin $
44 #include "mm/memory.h"
45 #include "native/native.h"
46 #include "toolbox/logging.h"
47 #include "vm/builtin.h"
48 #include "vm/exceptions.h"
49 #include "vm/global.h"
50 #include "vm/linker.h"
51 #include "vm/loader.h"
52 #include "vm/resolve.h"
53 #include "vm/options.h"
54 #include "vm/statistics.h"
55 #include "vm/stringlocal.h"
56 #include "vm/tables.h"
57 #include "vm/jit/asmpart.h"
58 #include "vm/jit/jit.h"
59 #include "vm/jit/parse.h"
60 #include "vm/jit/patcher.h"
61 #include "vm/jit/inline/parseRT.h"
62 #include "vm/jit/inline/parseXTA.h"
63 #include "vm/jit/inline/inline.h"
64 #include "vm/jit/loop/loop.h"
65 #include "vm/jit/inline/parseRTprint.h"
70 bool DEBUG4 = false; /*opcodes for parse.c*/
74 #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);
75 #define debug_writebranch1
77 /*******************************************************************************
79 function 'parse' scans the JavaVM code and generates intermediate code
81 During parsing the block index table is used to store at bit pos 0
82 a flag which marks basic block starts and at position 1 to 31 the
83 intermediate instruction index. After parsing the block index table
84 is scanned, for marked positions a block is generated and the block
85 number is stored in the block index table.
87 *******************************************************************************/
89 static exceptiontable* fillextable(methodinfo *m,
90 exceptiontable* extable, exceptiontable *raw_extable,
91 int exceptiontablelength,
92 int *label_index, int *block_count,
93 t_inlining_globals *inline_env)
95 int b_count, p, src, insertBlock;
97 if (exceptiontablelength == 0)
100 /*if (m->exceptiontablelength > 0) {
102 printf("m->exceptiontablelength=%i\n",m->exceptiontablelength);
106 b_count = *block_count;
108 for (src = exceptiontablelength-1; src >=0; src--) {
109 /* printf("Excepiont table index: %d\n",i); */
110 p = raw_extable[src].startpc;
111 if (label_index != NULL) p = label_index[p];
112 extable->startpc = p;
116 /*** 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)]);
117 fflush(stdout); } ***/
118 p = raw_extable[src].endpc; /* see JVM Spec 4.7.3 */
119 if (p <= raw_extable[src].startpc) {
120 log_text("Invalid exception handler range");
124 if (p >inline_env->method->jcodelength) {
125 log_text("Invalid exception handler end is after code end");
129 if (p<inline_env->method->jcodelength) insertBlock=1; else insertBlock=0;
130 /*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
131 printf("%s:fillextab: endpc:%ld\n",m->name->text,p);*/
132 if (label_index != NULL) p = label_index[p];
135 /*if (p < inline_env->method->jcodelength) {
137 if (insertBlock) block_insert(p);
139 p = raw_extable[src].handlerpc;
140 if (label_index != NULL) p = label_index[p];
141 extable->handlerpc = p;
145 extable->catchtype = raw_extable[src].catchtype;
146 extable->next = NULL;
147 extable->down = &extable[1];
151 *block_count = b_count;
152 return extable; /*&extable[i];*/ /* return the next free xtable* */
157 methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env)
159 int p; /* java instruction counter */
160 int nextp; /* start of next java instruction */
161 int opcode; /* java opcode */
162 int i; /* temporary for different uses (ctrs)*/
163 int ipc = 0; /* intermediate instruction counter */
164 int b_count = 0; /* basic block counter */
165 int s_count = 0; /* stack element counter */
166 bool blockend = false; /* true if basic block end has been reached */
167 bool iswide = false; /* true if last instruction was a wide*/
168 instruction *iptr; /* current ptr into instruction array */
169 int gp; /* global java instruction counter */
170 /* inlining info for current method */
172 inlining_methodinfo *inlinfo = inline_env->inlining_rootinfo;
173 inlining_methodinfo *tmpinlinf;
174 int nextgp = -1; /* start of next method to be inlined */
175 int *label_index = NULL; /* label redirection table */
176 int firstlocal = 0; /* first local variable of method */
177 exceptiontable* nextex; /* points next free entry in extable */
178 u1 *instructionstart; /* 1 for pcs which are valid instr. starts */
180 constant_classref *cr;
181 constant_classref *compr;
183 builtintable_entry *bte;
189 u2 skipBasicBlockChange;
191 #if defined(USE_INLINING)
192 METHINFOt(m,"\nPARSING: ",DEBUG4);
193 if ((opt_rt) || (opt_xta)) {
196 if (opt_rt) Missed = rtMissed;
197 if (opt_xta) Missed = xtaMissed;
199 if (m->methodUsed != USED) {
201 printf(" rta/xta missed: "); fflush(stdout);
202 METHINFO(m,opt_verbose);
204 if ( (Missed = fopen("Missed", "a")) == NULL) {
205 printf("CACAO - rt/xtaMissed file: cant open file to write append \n");
208 utf_fprint(Missed,m->class->name);
209 fprintf(Missed," "); fflush(Missed);
210 utf_fprint(Missed,m->name);
211 fprintf(Missed," "); fflush(Missed);
212 utf_fprint(Missed,m->descriptor);
213 fprintf(Missed,"\n"); fflush(Missed);
220 #if defined(USE_INLINING)
222 label_index = inlinfo->label_index;
223 m->maxstack = inline_env->cummaxstack;
224 /*JOWENN m->exceptiontablelength = inline_env->cumextablelength;*/
226 tmpinlinf = (inlining_methodinfo *) list_first(inlinfo->inlinedmethods);
228 if (tmpinlinf != NULL)
229 nextgp = tmpinlinf->startgp;
233 /**** static analysis has to be called before inlining
234 which has to be called before reg_set
235 which has to be called before parse (or ???)
236 will check if method being parsed was analysed here
237 if (opt_xta && opt_verbose) {
239 printf("XTA requested, not available\n");
241 if (opt_vta && opt_verbose)
242 printf("VTA requested, not yet implemented\n");
245 /* allocate instruction array and block index table */
247 /* 1 additional for end ipc * # cum inline methods*/
249 m->basicblockindex = DMNEW(s4, inline_env->cumjcodelength + inline_env->cummethods);
250 memset(m->basicblockindex, 0, sizeof(s4) * (inline_env->cumjcodelength + inline_env->cummethods));
252 instructionstart = DMNEW(u1, inline_env->cumjcodelength + inline_env->cummethods);
253 memset(instructionstart, 0, sizeof(u1) * (inline_env->cumjcodelength + inline_env->cummethods));
255 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
256 /* additional MONITOREXITS are reached by branches which are 3 bytes */
258 iptr = m->instructions = DMNEW(instruction, inline_env->cumjcodelength + 5);
260 /* Zero the intermediate instructions array so we don't have any
261 * invalid pointers in it if we cannot finish analyse_stack(). */
263 memset(iptr, 0, sizeof(instruction) * (inline_env->cumjcodelength + 5));
265 /* compute branch targets of exception table */
267 if (m->exceptiontable == NULL) {
268 printf("m->exceptiontable=NULL\n");fflush(stdout);
271 printf("m->exceptiontable != NULL\n");fflush(stdout);
273 printf("m->exceptiontablelength=%i, inline_env->method->exceptiontablelength=%i,inline_env->cumextablelength=%i\n",
274 m->exceptiontablelength, inline_env->method->exceptiontablelength,inline_env->cumextablelength);
277 if (m->exceptiontablelength > 0)
278 m->exceptiontable = DMNEW(exceptiontable, m->exceptiontablelength + 1);
281 nextex = fillextable(m,
282 &(cd->exceptiontable[cd->exceptiontablelength-1]), m->exceptiontable, m->exceptiontablelength,
283 label_index, &b_count, inline_env);
284 s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */
286 #if defined(USE_THREADS)
287 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
288 m->isleafmethod = false;
289 inline_env->method->isleafmethod = false;
293 /* scan all java instructions */
297 if (m->linenumbercount == 0) {
299 /*printf("linenumber count == 0\n");*/
301 linepcchange = m->linenumbers[0].start_pc;
304 skipBasicBlockChange=0;
305 for (p = 0, gp = 0; p < inline_env->method->jcodelength; gp += (nextp - p), p = nextp) {
307 /* DEBUG */ if (DEBUG==true) printf("----- p:%d gp:%d\n",p,gp);
309 /* mark this position as a valid instruction start */
311 instructionstart[gp] = 1;
312 /*log_text("new start of instruction");*/
313 /*printf ("%s, linepcchange %d,p %d\n",inline_env->method->name->text,linepcchange,p);*/
314 if (linepcchange==p) {
315 if (inline_env->method->linenumbercount > lineindex) {
316 currentline = inline_env->method->linenumbers[lineindex].line_number;
318 if (lineindex < inline_env->method->linenumbercount)
319 linepcchange = inline_env->method->linenumbers[lineindex].start_pc;
320 /*printf("Line number changed to: %ld\n",currentline);*/
325 #if defined(USE_INLINING)
326 if ((useinlining) && (gp == nextgp)) {
328 bool *readonly = NULL;
331 block_insert(gp); /* JJJJJJJJJJ */
333 instructionstart[gp] = 1;
334 m->basicblockindex[gp] |= (ipc << 1); /*FIXME: necessary ? */
336 opcode = code_get_u1(p,inline_env->method);
337 nextp = p += jcommandsize[opcode];
338 if (nextp > inline_env->method->jcodelength) {
339 log_text("Unexpected end of bytecode");
343 tmpinlinf = list_first(inlinfo->inlinedmethods);
344 firstlocal = tmpinlinf->firstlocal;
345 label_index = tmpinlinf->label_index;
346 readonly = tmpinlinf->readonly;
348 for (i=0,tptr=tmpinlinf->method->paramtypes;i<tmpinlinf->method->paramcount;i++,tptr++) {
349 if ( ((*tptr)==TYPE_LNG) ||
350 ((*tptr)==TYPE_DBL) )
356 for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) {
359 if ((i == 0) && inlineparamopt) {
360 OP1(ICMD_CLEAR_ARGREN, firstlocal);
363 if (!inlineparamopt || !readonly[i]) {
367 op = ICMD_READONLY_ARG;
371 if ( ((*tptr)==TYPE_LNG) ||
372 ((*tptr)==TYPE_DBL) )
377 OP1(op, firstlocal + argBlockIdx);
378 /* OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i); */
379 /* printf("inline argument load operation for local: %ld\n",firstlocal + tmpinlinf->method->paramcount - 1 - i); */
381 skipBasicBlockChange=1;
382 METHINFOt(inline_env->method,"BEFORE SAVE: ",DEBUG);
383 inlining_save_compiler_variables();
384 METHINFOt(inline_env->method,"AFTER SAVE: ",DEBUG);
385 inlining_set_compiler_variables(tmpinlinf);
386 METHINFOt(inline_env->method,"AFTER SET :: ",DEBUG);
387 METHINFOt(m,"\n.......Parsing (inlined): ",DEBUG);
388 METHINFO(inline_env->method,DEBUG);
390 OP1(ICMD_INLINE_START,tmpinlinf->level);
392 if (inlinfo->inlinedmethods == NULL) {
395 tmpinlinf = list_first(inlinfo->inlinedmethods);
396 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
398 if (inline_env->method->exceptiontablelength > 0)
399 nextex = fillextable(m, nextex,
400 inline_env->method->exceptiontable, inline_env->method->exceptiontablelength,
401 label_index, &b_count, inline_env);
404 #endif /* defined(USE_INLINING) */
406 opcode = code_get_u1(p,inline_env->method); /* fetch op code */
409 printf("Parse p=%i<%i<%i< opcode=<%i> %s\n",
410 p, gp, inline_env->jcodelength, opcode, opcode_names[opcode]);
412 printf("label_index[%d]=%d\n",p,label_index[p]);
415 printf("basicblockindex[gp=%i]=%i=%p ipc=%i=%p shifted ipc=%i=%p\n",
416 gp,m->basicblockindex[gp],m->basicblockindex[gp],ipc,ipc,(ipc<<1),(ipc<<1));
419 if (!skipBasicBlockChange) {
420 m->basicblockindex[gp] |= (ipc << 1); /*store intermed cnt*/
421 } else skipBasicBlockChange=0;
423 printf("basicblockindex[gp=%i]=%i=%p \n",
424 gp,m->basicblockindex[gp],m->basicblockindex[gp]);
429 block_insert(gp); /* start new block */
431 /*printf("blockend was set: new blockcount: %ld at:%ld\n",b_count,gp);*/
434 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
436 if (nextp > inline_env->method->jcodelength) {
437 log_text("Unexpected end of bytecode");
441 s_count += stackreq[opcode]; /* compute stack element count */
447 /* pushing constants onto the stack p */
450 LOADCONST_I(code_get_s1(p+1,inline_env->method));
454 LOADCONST_I(code_get_s2(p+1,inline_env->method));
458 i = code_get_u1(p + 1, inline_env->method);
459 goto pushconstantitem;
463 i = code_get_u2(p + 1, inline_env->method);
467 if (i >= inline_env->method->class->cpcount) {
468 dolog("Attempt to access constant outside range: %d >= %d", i, inline_env->method->class->cpcount);
472 switch (inline_env->method->class->cptags[i]) {
473 case CONSTANT_Integer:
474 LOADCONST_I(((constant_integer *) (inline_env->method->class->cpinfos[i]))->value);
477 LOADCONST_L(((constant_long *) (inline_env->method->class->cpinfos[i]))->value);
480 LOADCONST_F(((constant_float *) (inline_env->method->class->cpinfos[i]))->value);
482 case CONSTANT_Double:
483 LOADCONST_D(((constant_double *) (inline_env->method->class->cpinfos[i]))->value);
485 case CONSTANT_String:
486 LOADCONST_A(literalstring_new((utf *) (inline_env->method->class->cpinfos[i])));
489 log_text("Invalid constant type to push");
494 case JAVA_ACONST_NULL:
505 LOADCONST_I(opcode - JAVA_ICONST_0);
510 LOADCONST_L(opcode - JAVA_LCONST_0);
516 LOADCONST_F(opcode - JAVA_FCONST_0);
521 LOADCONST_D(opcode - JAVA_DCONST_0);
524 /* loading variables onto the stack */
532 i = code_get_u1(p + 1,inline_env->method);
534 i = code_get_u2(p + 1,inline_env->method);
538 OP1LOAD(opcode, i + firstlocal);
545 OP1LOAD(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
552 OP1LOAD(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
559 OP1LOAD(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
566 OP1LOAD(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
573 OP1LOAD(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
576 /* storing stack values into local variables */
584 i = code_get_u1(p + 1,inline_env->method);
586 i = code_get_u2(p + 1,inline_env->method);
590 OP1STORE(opcode, i + firstlocal);
597 OP1STORE(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
604 OP1STORE(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
611 OP1STORE(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
618 OP1STORE(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
625 OP1STORE(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
633 i = code_get_u1(p + 1,inline_env->method);
634 v = code_get_s1(p + 2,inline_env->method);
637 i = code_get_u2(p + 1,inline_env->method);
638 v = code_get_s2(p + 3,inline_env->method);
642 INDEX_ONEWORD(i + firstlocal);
643 OP2I(opcode, i + firstlocal, v);
647 /* wider index for loading, storing and incrementing */
654 /* managing arrays ****************************************************/
658 switch (code_get_s1(p + 1, inline_env->method)) {
660 bte = builtintable_get_internal(BUILTIN_newarray_boolean);
663 bte = builtintable_get_internal(BUILTIN_newarray_char);
666 bte = builtintable_get_internal(BUILTIN_newarray_float);
669 bte = builtintable_get_internal(BUILTIN_newarray_double);
672 bte = builtintable_get_internal(BUILTIN_newarray_byte);
675 bte = builtintable_get_internal(BUILTIN_newarray_short);
678 bte = builtintable_get_internal(BUILTIN_newarray_int);
681 bte = builtintable_get_internal(BUILTIN_newarray_long);
684 log_text("Invalid array-type to create");
687 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
688 OP(ICMD_CHECKEXCEPTION);
693 i = code_get_u2(p + 1, inline_env->method);
694 compr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
696 if (!(cr = class_get_classref_multiarray_of(1, compr)))
699 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
703 bte = builtintable_get_internal(BUILTIN_newarray);
704 LOADCONST_A_BUILTIN(c->vftbl);
705 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
708 bte = builtintable_get_internal(PATCHER_builtin_newarray);
709 LOADCONST_A_BUILTIN(cr);
710 BUILTIN(bte, bte->md->paramcount, cr, currentline);
713 OP(ICMD_CHECKEXCEPTION);
716 case JAVA_MULTIANEWARRAY:
717 inline_env->method->isleafmethod = false;
718 i = code_get_u2(p + 1, inline_env->method);
720 constant_classref *cr;
722 s4 v = code_get_u1(p + 3, inline_env->method);
724 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
726 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
730 OP2AT(opcode, v, c->vftbl, NULL, currentline);
734 (voidptr) (ptrint) PATCHER_builtin_multianewarray,
758 i = p + code_get_s2(p + 1,inline_env->method);
763 /*printf("GOTO: %d\n",i);*/
771 i = p + code_get_s4(p + 1,inline_env->method);
777 /*printf("B6 JSR_W\t"); fflush(stdout);*/
785 i = code_get_u1(p + 1,inline_env->method);
787 i = code_get_u2(p + 1,inline_env->method);
794 if (inline_env->isinlinedmethod) {
795 OP1(ICMD_GOTO, inlinfo->stopgp);
799 OP1LOAD(opcode, i + firstlocal);
808 if (inline_env->isinlinedmethod) {
809 /* if (p==m->jcodelength-1) {*/ /* return is at end of inlined method */
813 if (nextp>inline_env->method->jcodelength-1) {
814 /* OP1(ICMD_GOTO, inlinfo->stopgp);
822 OP1(ICMD_GOTO, inlinfo->stopgp);
836 /* table jumps ********************************************************/
838 case JAVA_LOOKUPSWITCH:
845 nextp = ALIGN((p + 1), 4);
847 if (nextp + 8 > inline_env->method->jcodelength) {
848 log_text("Unexpected end of bytecode");
853 tablep = (s4 *) (inline_env->method->jcode + nextp);
856 num = code_get_u4(nextp + 4, inline_env->method);
857 tablep = DMNEW(s4, num * 2 + 2);
860 OP2A(opcode, 0, tablep, currentline);
864 j = p + code_get_s4(nextp, inline_env->method);
867 *tablep = j; /* restore for little endian */
873 /* number of pairs */
875 num = code_get_u4(nextp, inline_env->method);
880 if (nextp + 8 * num > inline_env->method->jcodelength) {
881 /* XXX TODO VerifyError */
882 log_text("Unexpected end of bytecode");
886 for (i = 0; i < num; i++) {
889 j = code_get_s4(nextp, inline_env->method);
890 *tablep = j; /* restore for little endian */
894 /* check if the lookup table is sorted correctly */
896 if (i && (j <= prevvalue)) {
897 *exceptionptr = new_verifyerror(m, "Unsorted lookup switch");
904 j = p + code_get_s4(nextp,inline_env->method);
907 *tablep = j; /* restore for little endian */
918 case JAVA_TABLESWITCH:
924 nextp = ALIGN((p + 1), 4);
925 if (nextp + 12 > inline_env->method->jcodelength) {
926 /* XXX TODO VerifyError */
927 log_text("Unexpected end of bytecode");
932 tablep = (s4 *) (inline_env->method->jcode + nextp);
935 num = code_get_u4(nextp + 8,inline_env->method) - code_get_u4(nextp + 4,inline_env->method);
936 tablep = DMNEW(s4, num + 1 + 3);
939 OP2A(opcode, 0, tablep, currentline);
943 j = p + code_get_s4(nextp, inline_env->method);
946 *tablep = j; /* restore for little endian */
954 j = code_get_s4(nextp, inline_env->method);
955 *tablep = j; /* restore for little endian */
961 num = code_get_s4(nextp, inline_env->method);
962 *tablep = num; /* restore for little endian */
966 num -= j; /* difference of upper - lower */
969 /* XXX TODO VerifyError */
970 log_text("invalid TABLESWITCH: upper bound < lower bound");
974 if (nextp + 4 * (num + 1) > inline_env->method->jcodelength) {
975 /* XXX TODO VerifyError */
976 log_text("Unexpected end of bytecode");
980 for (i = 0; i <= num; i++) {
981 j = p + code_get_s4(nextp,inline_env->method);
983 /*printf("TABLESWITCH: j before mapping=%ld\n",j);*/
986 *tablep = j; /* restore for little endian */
991 /*printf("TABLESWITCH: block_insert(%ld)\n",j);*/
998 /* load and store of object fields ************************************/
1001 bte = builtintable_get_internal(BUILTIN_aastore);
1002 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1005 case JAVA_GETSTATIC:
1006 case JAVA_PUTSTATIC:
1010 constant_FMIref *fr;
1011 unresolved_field *uf;
1014 i = code_get_u2(p + 1, inline_env->method);
1015 fr = class_getconstant(inline_env->method->class, i,
1018 OP2A_NOINC(opcode, fr->parseddesc.fd->type, fr, currentline);
1020 if (!(uf = create_unresolved_field(inline_env->method->class,
1025 /* store unresolved_field pointer */
1029 /* only with -noverify, otherwise the typechecker does this */
1032 if (!resolve_field(uf, resolveLazy, &fi))
1041 #if defined(__MIPS__) || defined(__POWERPC__)
1042 if (!fi || !fi->class->initialized)
1043 inline_env->method->isleafmethod = false;
1049 /* method invocation **************************************************/
1051 case JAVA_INVOKESTATIC:
1052 i = code_get_u2(p + 1, inline_env->method);
1054 constant_FMIref *mr;
1056 unresolved_method *um;
1059 inline_env->method->isleafmethod = false;
1061 mr = class_getconstant(inline_env->method->class, i,
1062 CONSTANT_Methodref);
1064 md = mr->parseddesc.md;
1067 if (!descriptor_params_from_paramtypes(md, ACC_STATIC))
1070 OP2A_NOINC(opcode, md->paramcount, mr, currentline);
1072 um = create_unresolved_method(inline_env->method->class,
1073 inline_env->method, iptr);
1078 /* store the unresolved_method pointer */
1082 /* only with -noverify, otherwise the typechecker does this */
1085 if (!resolve_method(um, resolveLazy, &mi))
1097 case JAVA_INVOKESPECIAL:
1098 case JAVA_INVOKEVIRTUAL:
1100 constant_FMIref *mr;
1102 unresolved_method *um;
1105 inline_env->method->isleafmethod = false;
1107 i = code_get_u2(p + 1, inline_env->method);
1108 mr = class_getconstant(inline_env->method->class, i,
1109 CONSTANT_Methodref);
1111 md = mr->parseddesc.md;
1114 if (!descriptor_params_from_paramtypes(md, 0))
1117 OP2A_NOINC(opcode, md->paramcount, mr, currentline);
1119 um = create_unresolved_method(inline_env->method->class,
1120 inline_env->method, iptr);
1125 /* store the unresolved_method* */
1129 /* only with -noverify, otherwise the typechecker does this */
1132 if (!resolve_method(um, resolveLazy, &mi))
1144 case JAVA_INVOKEINTERFACE:
1145 i = code_get_u2(p + 1, inline_env->method);
1147 constant_FMIref *mr;
1149 unresolved_method *um;
1152 inline_env->method->isleafmethod = false;
1154 mr = class_getconstant(inline_env->method->class, i,
1155 CONSTANT_InterfaceMethodref);
1157 md = mr->parseddesc.md;
1160 if (!descriptor_params_from_paramtypes(md, 0))
1163 OP2A_NOINC(opcode, md->paramcount, mr, currentline);
1165 um = create_unresolved_method(inline_env->method->class,
1166 inline_env->method, iptr);
1171 /* store the unresolved_method* */
1175 /* only with -noverify, otherwise the typechecker does this */
1178 if (!resolve_method(um, resolveLazy, &mi))
1190 /* miscellaneous object operations ************************************/
1193 i = code_get_u2(p + 1, inline_env->method);
1194 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1196 if (!resolve_classref(inline_env->method, cr, resolveLazy, true,
1200 if (c && c->initialized) {
1201 bte = builtintable_get_internal(BUILTIN_new);
1202 LOADCONST_A_BUILTIN(c);
1203 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1206 bte = builtintable_get_internal(PATCHER_builtin_new);
1207 LOADCONST_A_BUILTIN(cr);
1208 BUILTIN(bte, bte->md->paramcount, cr, currentline);
1212 OP(ICMD_CHECKEXCEPTION);
1215 case JAVA_CHECKCAST:
1216 i = code_get_u2(p + 1, inline_env->method);
1217 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1219 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
1222 if (cr->name->text[0] == '[') {
1223 /* array type cast-check */
1225 bte = builtintable_get_internal(BUILTIN_arraycheckcast);
1226 LOADCONST_A_BUILTIN(c->vftbl);
1227 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1230 bte = builtintable_get_internal(PATCHER_builtin_arraycheckcast);
1231 LOADCONST_A_BUILTIN(cr);
1232 BUILTIN(bte, bte->md->paramcount, cr, currentline);
1237 /* object type cast-check */
1238 OP2AT(opcode, 1, c, cr, currentline);
1240 #if defined(__MIPS__) || defined(__POWERPC__)
1242 inline_env->method->isleafmethod = false;
1246 case JAVA_INSTANCEOF:
1247 i = code_get_u2(p + 1,inline_env->method);
1248 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1250 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
1253 if (cr->name->text[0] == '[') {
1254 /* array type cast-check */
1256 bte = builtintable_get_internal(BUILTIN_arrayinstanceof);
1257 LOADCONST_A_BUILTIN(c->vftbl);
1258 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1261 bte = builtintable_get_internal(PATCHER_builtin_arrayinstanceof);
1262 LOADCONST_A_BUILTIN(cr);
1263 BUILTIN(bte, bte->md->paramcount, cr, currentline);
1268 /* object type cast-check */
1269 OP2AT(opcode, 1, c, cr, currentline);
1271 #if defined(__MIPS__) || defined(__POWERPC__)
1273 inline_env->method->isleafmethod = false;
1277 case JAVA_MONITORENTER:
1278 #if defined(USE_THREADS)
1281 bte = builtintable_get_internal(BUILTIN_monitorenter);
1282 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1291 case JAVA_MONITOREXIT:
1292 #if defined(USE_THREADS)
1294 bte = builtintable_get_internal(BUILTIN_monitorexit);
1295 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1303 /* any other basic operation ******************************************/
1322 #if defined(__I386__)
1325 bte = builtintable_get_internal(BUILTIN_frem);
1326 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1331 #if defined(__I386__)
1334 bte = builtintable_get_internal(BUILTIN_drem);
1335 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1340 #if defined(__ALPHA__)
1342 bte = builtintable_get_internal(BUILTIN_f2i);
1343 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1352 #if defined(__ALPHA__)
1354 bte = builtintable_get_internal(BUILTIN_f2l);
1355 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1364 #if defined(__ALPHA__)
1366 bte = builtintable_get_internal(BUILTIN_d2i);
1367 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1376 #if defined(__ALPHA__)
1378 bte = builtintable_get_internal(BUILTIN_d2l);
1379 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1387 case JAVA_BREAKPOINT:
1389 new_verifyerror(m, "Quick instructions shouldn't appear yet.");
1392 case 204: /* unused opcode */
1445 new_internalerror("Illegal opcode %d at instr %d\n",
1456 /* If WIDE was used correctly, iswide should have been reset by now. */
1457 if (iswide && opcode != JAVA_WIDE) {
1458 log_text("Illegal instruction: WIDE before incompatible opcode");
1462 #if defined(USE_INLINING)
1463 /* if (inline_env->isinlinedmethod && p == inline_env->method->jcodelength - 1) { */ /* end of an inlined method */
1464 if (inline_env->isinlinedmethod && (nextp >= inline_env->method->jcodelength) ) { /* end of an inlined method */
1465 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1466 gp = inlinfo->stopgp;
1467 inlining_restore_compiler_variables();
1468 OP(ICMD_INLINE_END);
1469 /*label_index = inlinfo->label_index;*/
1471 METHINFOt(inline_env->method,"AFTER RESTORE : ",DEBUG);
1472 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1473 if (inlinfo->inlinedmethods == NULL) { /* JJJJ */
1476 tmpinlinf = list_first(inlinfo->inlinedmethods);
1477 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1479 /* printf("nextpgp: %d\n", nextgp); */
1480 label_index=inlinfo->label_index;
1481 firstlocal = inlinfo->firstlocal;
1483 #endif /* defined(USE_INLINING) */
1488 if (p != m->jcodelength) {
1489 printf("p (%d) != m->jcodelength (%d)\n",p,m->jcodelength);
1490 log_text("Command-sequence crosses code-boundary");
1495 *exceptionptr = new_verifyerror(m, "Falling off the end of the code");
1499 /* adjust block count if target 0 is not first intermediate instruction */
1501 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1))
1504 /* copy local to method variables */
1506 m->instructioncount = ipc;
1507 m->basicblockcount = b_count;
1508 m->stackcount = s_count + m->basicblockcount * m->maxstack;
1510 /* allocate stack table */
1512 m->stack = DMNEW(stackelement, m->stackcount);
1517 bptr = m->basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1522 /* additional block if target 0 is not first intermediate instruction */
1524 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) {
1525 bptr->iinstr = m->instructions;
1528 bptr->type = BBTYPE_STD;
1529 bptr->branchrefs = NULL;
1530 bptr->pre_count = 0;
1531 bptr->debug_nr = m->c_debug_nr++;
1534 (bptr - 1)->next = bptr;
1537 /* allocate blocks */
1539 for (p = 0; p < inline_env->cumjcodelength; p++) {
1540 /* for (p = 0; p < m->jcodelength; p++) { */
1541 if (m->basicblockindex[p] & 1) {
1542 /* Check if this block starts at the beginning of an */
1545 if (!instructionstart[p]) {
1546 /* XXX TODO throw exception? which one? */
1547 dolog("Branch into middle of instruction: Basic Block beginn: %d\n", p);
1551 /* allocate the block */
1552 bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
1553 bptr->debug_nr = m->c_debug_nr++;
1555 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1559 bptr->type = BBTYPE_STD;
1560 bptr->branchrefs = NULL;
1561 m->basicblockindex[p] = b_count;
1562 bptr->pre_count = 0;
1565 (bptr - 1)->next = bptr;
1569 /* allocate additional block at end */
1571 bptr->instack = bptr->outstack = NULL;
1572 bptr->indepth = bptr->outdepth = 0;
1573 bptr->iinstr = NULL;
1574 (bptr - 1)->icount = (m->instructions + m->instructioncount) - (bptr - 1)->iinstr;
1579 bptr->type = BBTYPE_STD;
1580 bptr->branchrefs = NULL;
1581 bptr->pre_count = 0;
1582 bptr->debug_nr = m->c_debug_nr++;
1583 (bptr - 1)->next = bptr;
1586 if (cd->exceptiontablelength > 0) {
1587 cd->exceptiontable[cd->exceptiontablelength - 1].down = NULL;
1590 for (i = 0; i < cd->exceptiontablelength; ++i) {
1591 p = cd->exceptiontable[i].startpc;
1592 cd->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1594 p = cd->exceptiontable[i].endpc;
1595 cd->exceptiontable[i].end = (p == inline_env->method->jcodelength) ? (m->basicblocks + m->basicblockcount /*+ 1*/) : (m->basicblocks + m->basicblockindex[p]);
1597 p = cd->exceptiontable[i].handlerpc;
1598 cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1602 #if defined(USE_INLINING)
1604 inlining_cleanup(inline_env);
1607 /* just return methodinfo* to signal everything was ok */
1614 * These are local overrides for various environment variables in Emacs.
1615 * Please do not remove this and leave it at the end of the file, where
1616 * Emacs will automagically detect them.
1617 * ---------------------------------------------------------------------
1620 * indent-tabs-mode: t