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 3129 2005-08-17 23:43:38Z michi $
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, 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, 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_canstore);
1002 OP2A(opcode, bte->md->paramcount, bte, currentline);
1003 inline_env->method->isleafmethod = false;
1006 case JAVA_GETSTATIC:
1007 case JAVA_PUTSTATIC:
1011 constant_FMIref *fr;
1012 unresolved_field *uf;
1015 i = code_get_u2(p + 1, inline_env->method);
1016 fr = class_getconstant(inline_env->method->class, i,
1019 OP2A_NOINC(opcode, fr->parseddesc.fd->type, fr, currentline);
1021 if (!(uf = create_unresolved_field(inline_env->method->class,
1026 /* store unresolved_field pointer */
1030 /* only with -noverify, otherwise the typechecker does this */
1033 if (!resolve_field(uf, resolveLazy, &fi))
1038 #if defined(__MIPS__) || defined(__POWERPC__)
1039 if (!fi || !fi->class->initialized)
1040 inline_env->method->isleafmethod = false;
1051 /* method invocation **************************************************/
1053 case JAVA_INVOKESTATIC:
1054 i = code_get_u2(p + 1, inline_env->method);
1056 constant_FMIref *mr;
1058 unresolved_method *um;
1061 inline_env->method->isleafmethod = false;
1063 mr = class_getconstant(inline_env->method->class, i,
1064 CONSTANT_Methodref);
1066 md = mr->parseddesc.md;
1069 if (!descriptor_params_from_paramtypes(md, ACC_STATIC))
1072 OP2A_NOINC(opcode, md->paramcount, mr, currentline);
1074 um = create_unresolved_method(inline_env->method->class,
1075 inline_env->method, iptr);
1080 /* store the unresolved_method pointer */
1084 /* only with -noverify, otherwise the typechecker does this */
1087 if (!resolve_method(um, resolveLazy, &mi))
1099 case JAVA_INVOKESPECIAL:
1100 case JAVA_INVOKEVIRTUAL:
1102 constant_FMIref *mr;
1104 unresolved_method *um;
1107 inline_env->method->isleafmethod = false;
1109 i = code_get_u2(p + 1, inline_env->method);
1110 mr = class_getconstant(inline_env->method->class, i,
1111 CONSTANT_Methodref);
1113 md = mr->parseddesc.md;
1116 if (!descriptor_params_from_paramtypes(md, 0))
1119 OP2A_NOINC(opcode, md->paramcount, mr, currentline);
1121 um = create_unresolved_method(inline_env->method->class,
1122 inline_env->method, iptr);
1127 /* store the unresolved_method* */
1131 /* only with -noverify, otherwise the typechecker does this */
1134 if (!resolve_method(um, resolveLazy, &mi))
1146 case JAVA_INVOKEINTERFACE:
1147 i = code_get_u2(p + 1, inline_env->method);
1149 constant_FMIref *mr;
1151 unresolved_method *um;
1154 inline_env->method->isleafmethod = false;
1156 mr = class_getconstant(inline_env->method->class, i,
1157 CONSTANT_InterfaceMethodref);
1159 md = mr->parseddesc.md;
1162 if (!descriptor_params_from_paramtypes(md, 0))
1165 OP2A_NOINC(opcode, md->paramcount, mr, currentline);
1167 um = create_unresolved_method(inline_env->method->class,
1168 inline_env->method, iptr);
1173 /* store the unresolved_method* */
1177 /* only with -noverify, otherwise the typechecker does this */
1180 if (!resolve_method(um, resolveLazy, &mi))
1192 /* miscellaneous object operations ************************************/
1195 i = code_get_u2(p + 1, inline_env->method);
1196 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1198 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true,
1202 if (c && c->initialized) {
1203 bte = builtintable_get_internal(BUILTIN_new);
1204 LOADCONST_A_BUILTIN(c);
1205 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1208 bte = builtintable_get_internal(PATCHER_builtin_new);
1209 LOADCONST_A_BUILTIN(cr);
1210 BUILTIN(bte, bte->md->paramcount, cr, currentline);
1214 OP(ICMD_CHECKEXCEPTION);
1217 case JAVA_CHECKCAST:
1218 i = code_get_u2(p + 1, inline_env->method);
1219 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1221 if (!resolve_classref(inline_env->method, cr, resolveLazy, true,
1225 if (cr->name->text[0] == '[') {
1226 /* array type cast-check */
1228 bte = builtintable_get_internal(BUILTIN_arraycheckcast);
1229 OP2AT(ICMD_ARRAYCHECKCAST, 1, bte, c->vftbl, currentline);
1232 bte = builtintable_get_internal(PATCHER_builtin_arraycheckcast);
1233 OP2AT(ICMD_ARRAYCHECKCAST, 0, bte, cr, currentline);
1235 inline_env->method->isleafmethod = false;
1238 /* object type cast-check */
1239 OP2AT(opcode, 1, c, cr, currentline);
1241 #if defined(__MIPS__) || defined(__POWERPC__)
1243 inline_env->method->isleafmethod = false;
1248 case JAVA_INSTANCEOF:
1249 i = code_get_u2(p + 1,inline_env->method);
1250 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1252 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
1255 if (cr->name->text[0] == '[') {
1256 /* array type cast-check */
1258 bte = builtintable_get_internal(BUILTIN_arrayinstanceof);
1259 LOADCONST_A_BUILTIN(c->vftbl);
1260 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1263 bte = builtintable_get_internal(PATCHER_builtin_arrayinstanceof);
1264 LOADCONST_A_BUILTIN(cr);
1265 BUILTIN(bte, bte->md->paramcount, cr, currentline);
1270 /* object type cast-check */
1271 OP2AT(opcode, 1, c, cr, currentline);
1273 #if defined(__MIPS__) || defined(__POWERPC__)
1275 inline_env->method->isleafmethod = false;
1279 case JAVA_MONITORENTER:
1280 #if defined(USE_THREADS)
1283 bte = builtintable_get_internal(BUILTIN_monitorenter);
1284 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1293 case JAVA_MONITOREXIT:
1294 #if defined(USE_THREADS)
1296 bte = builtintable_get_internal(BUILTIN_monitorexit);
1297 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1305 /* any other basic operation ******************************************/
1308 #if !SUPPORT_DIVISION
1309 bte = builtintable_get_internal(BUILTIN_idiv);
1310 OP2A(opcode, bte->md->paramcount, bte, currentline);
1311 inline_env->method->isleafmethod = false;
1318 #if !SUPPORT_DIVISION
1319 bte = builtintable_get_internal(BUILTIN_irem);
1320 OP2A(opcode, bte->md->paramcount, bte, currentline);
1321 inline_env->method->isleafmethod = false;
1328 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1329 bte = builtintable_get_internal(BUILTIN_ldiv);
1330 OP2A(opcode, bte->md->paramcount, bte, currentline);
1331 inline_env->method->isleafmethod = false;
1338 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1339 bte = builtintable_get_internal(BUILTIN_lrem);
1340 OP2A(opcode, bte->md->paramcount, bte, currentline);
1341 inline_env->method->isleafmethod = false;
1348 #if defined(__I386__)
1351 bte = builtintable_get_internal(BUILTIN_frem);
1352 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1357 #if defined(__I386__)
1360 bte = builtintable_get_internal(BUILTIN_drem);
1361 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1366 #if defined(__ALPHA__)
1368 bte = builtintable_get_internal(BUILTIN_f2i);
1369 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1378 #if defined(__ALPHA__)
1380 bte = builtintable_get_internal(BUILTIN_f2l);
1381 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1390 #if defined(__ALPHA__)
1392 bte = builtintable_get_internal(BUILTIN_d2i);
1393 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1402 #if defined(__ALPHA__)
1404 bte = builtintable_get_internal(BUILTIN_d2l);
1405 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1413 case JAVA_BREAKPOINT:
1415 new_verifyerror(m, "Quick instructions shouldn't appear yet.");
1418 case 204: /* unused opcode */
1471 new_internalerror("Illegal opcode %d at instr %d\n",
1482 /* If WIDE was used correctly, iswide should have been reset by now. */
1483 if (iswide && opcode != JAVA_WIDE) {
1484 log_text("Illegal instruction: WIDE before incompatible opcode");
1488 #if defined(USE_INLINING)
1489 /* if (inline_env->isinlinedmethod && p == inline_env->method->jcodelength - 1) { */ /* end of an inlined method */
1490 if (inline_env->isinlinedmethod && (nextp >= inline_env->method->jcodelength) ) { /* end of an inlined method */
1491 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1492 gp = inlinfo->stopgp;
1493 inlining_restore_compiler_variables();
1494 OP(ICMD_INLINE_END);
1495 /*label_index = inlinfo->label_index;*/
1497 METHINFOt(inline_env->method,"AFTER RESTORE : ",DEBUG);
1498 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1499 if (inlinfo->inlinedmethods == NULL) { /* JJJJ */
1502 tmpinlinf = list_first(inlinfo->inlinedmethods);
1503 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1505 /* printf("nextpgp: %d\n", nextgp); */
1506 label_index=inlinfo->label_index;
1507 firstlocal = inlinfo->firstlocal;
1509 #endif /* defined(USE_INLINING) */
1514 if (p != m->jcodelength) {
1515 printf("p (%d) != m->jcodelength (%d)\n",p,m->jcodelength);
1516 log_text("Command-sequence crosses code-boundary");
1521 *exceptionptr = new_verifyerror(m, "Falling off the end of the code");
1525 /* adjust block count if target 0 is not first intermediate instruction */
1527 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1))
1530 /* copy local to method variables */
1532 m->instructioncount = ipc;
1533 m->basicblockcount = b_count;
1534 m->stackcount = s_count + m->basicblockcount * m->maxstack;
1536 /* allocate stack table */
1538 m->stack = DMNEW(stackelement, m->stackcount);
1543 bptr = m->basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1548 /* additional block if target 0 is not first intermediate instruction */
1550 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) {
1551 bptr->iinstr = m->instructions;
1554 bptr->type = BBTYPE_STD;
1555 bptr->branchrefs = NULL;
1556 bptr->pre_count = 0;
1557 bptr->debug_nr = m->c_debug_nr++;
1560 (bptr - 1)->next = bptr;
1563 /* allocate blocks */
1565 for (p = 0; p < inline_env->cumjcodelength; p++) {
1566 /* for (p = 0; p < m->jcodelength; p++) { */
1567 if (m->basicblockindex[p] & 1) {
1568 /* Check if this block starts at the beginning of an */
1571 if (!instructionstart[p]) {
1572 /* XXX TODO throw exception? which one? */
1573 dolog("Branch into middle of instruction: Basic Block beginn: %d\n", p);
1577 /* allocate the block */
1578 bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
1579 bptr->debug_nr = m->c_debug_nr++;
1581 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1585 bptr->type = BBTYPE_STD;
1586 bptr->branchrefs = NULL;
1587 m->basicblockindex[p] = b_count;
1588 bptr->pre_count = 0;
1591 (bptr - 1)->next = bptr;
1595 /* allocate additional block at end */
1597 bptr->instack = bptr->outstack = NULL;
1598 bptr->indepth = bptr->outdepth = 0;
1599 bptr->iinstr = NULL;
1600 (bptr - 1)->icount = (m->instructions + m->instructioncount) - (bptr - 1)->iinstr;
1605 bptr->type = BBTYPE_STD;
1606 bptr->branchrefs = NULL;
1607 bptr->pre_count = 0;
1608 bptr->debug_nr = m->c_debug_nr++;
1609 (bptr - 1)->next = bptr;
1612 if (cd->exceptiontablelength > 0) {
1613 cd->exceptiontable[cd->exceptiontablelength - 1].down = NULL;
1616 for (i = 0; i < cd->exceptiontablelength; ++i) {
1617 p = cd->exceptiontable[i].startpc;
1618 cd->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1620 p = cd->exceptiontable[i].endpc;
1621 cd->exceptiontable[i].end = (p == inline_env->method->jcodelength) ? (m->basicblocks + m->basicblockcount /*+ 1*/) : (m->basicblocks + m->basicblockindex[p]);
1623 p = cd->exceptiontable[i].handlerpc;
1624 cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1628 #if defined(USE_INLINING)
1630 inlining_cleanup(inline_env);
1633 /* just return methodinfo* to signal everything was ok */
1640 * These are local overrides for various environment variables in Emacs.
1641 * Please do not remove this and leave it at the end of the file, where
1642 * Emacs will automagically detect them.
1643 * ---------------------------------------------------------------------
1646 * indent-tabs-mode: t