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 3225 2005-09-19 13:58:44Z twisti $
46 #include "mm/memory.h"
47 #include "native/native.h"
48 #include "toolbox/logging.h"
49 #include "vm/builtin.h"
50 #include "vm/exceptions.h"
51 #include "vm/global.h"
52 #include "vm/linker.h"
53 #include "vm/loader.h"
54 #include "vm/resolve.h"
55 #include "vm/options.h"
56 #include "vm/statistics.h"
57 #include "vm/stringlocal.h"
58 #include "vm/tables.h"
59 #include "vm/jit/asmpart.h"
60 #include "vm/jit/jit.h"
61 #include "vm/jit/parse.h"
62 #include "vm/jit/patcher.h"
63 #include "vm/jit/inline/parseRT.h"
64 #include "vm/jit/inline/parseXTA.h"
65 #include "vm/jit/inline/inline.h"
66 #include "vm/jit/loop/loop.h"
67 #include "vm/jit/inline/parseRTprint.h"
72 bool DEBUG4 = false; /*opcodes for parse.c*/
76 #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);
77 #define debug_writebranch1
79 /*******************************************************************************
81 function 'parse' scans the JavaVM code and generates intermediate code
83 During parsing the block index table is used to store at bit pos 0
84 a flag which marks basic block starts and at position 1 to 31 the
85 intermediate instruction index. After parsing the block index table
86 is scanned, for marked positions a block is generated and the block
87 number is stored in the block index table.
89 *******************************************************************************/
91 static exceptiontable* fillextable(methodinfo *m,
92 exceptiontable* extable, exceptiontable *raw_extable,
93 int exceptiontablelength,
94 int *label_index, int *block_count,
95 t_inlining_globals *inline_env)
97 int b_count, p, src, insertBlock;
99 if (exceptiontablelength == 0)
102 /*if (m->exceptiontablelength > 0) {
104 printf("m->exceptiontablelength=%i\n",m->exceptiontablelength);
108 b_count = *block_count;
110 for (src = exceptiontablelength-1; src >=0; src--) {
111 /* printf("Excepiont table index: %d\n",i); */
112 p = raw_extable[src].startpc;
113 if (label_index != NULL) p = label_index[p];
114 extable->startpc = p;
118 /*** 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)]);
119 fflush(stdout); } ***/
120 p = raw_extable[src].endpc; /* see JVM Spec 4.7.3 */
121 if (p <= raw_extable[src].startpc) {
122 log_text("Invalid exception handler range");
126 if (p >inline_env->method->jcodelength) {
127 log_text("Invalid exception handler end is after code end");
131 if (p<inline_env->method->jcodelength) insertBlock=1; else insertBlock=0;
132 /*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
133 printf("%s:fillextab: endpc:%ld\n",m->name->text,p);*/
134 if (label_index != NULL) p = label_index[p];
137 /*if (p < inline_env->method->jcodelength) {
139 if (insertBlock) block_insert(p);
141 p = raw_extable[src].handlerpc;
142 if (label_index != NULL) p = label_index[p];
143 extable->handlerpc = p;
147 extable->catchtype = raw_extable[src].catchtype;
148 extable->next = NULL;
149 extable->down = &extable[1];
153 *block_count = b_count;
154 return extable; /*&extable[i];*/ /* return the next free xtable* */
159 methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env)
161 int p; /* java instruction counter */
162 int nextp; /* start of next java instruction */
163 int opcode; /* java opcode */
164 int i; /* temporary for different uses (ctrs)*/
165 int ipc = 0; /* intermediate instruction counter */
166 int b_count = 0; /* basic block counter */
167 int s_count = 0; /* stack element counter */
168 bool blockend = false; /* true if basic block end has been reached */
169 bool iswide = false; /* true if last instruction was a wide*/
170 instruction *iptr; /* current ptr into instruction array */
171 int gp; /* global java instruction counter */
172 /* inlining info for current method */
174 inlining_methodinfo *inlinfo = inline_env->inlining_rootinfo;
175 inlining_methodinfo *tmpinlinf;
176 int nextgp = -1; /* start of next method to be inlined */
177 int *label_index = NULL; /* label redirection table */
178 int firstlocal = 0; /* first local variable of method */
179 exceptiontable* nextex; /* points next free entry in extable */
180 u1 *instructionstart; /* 1 for pcs which are valid instr. starts */
182 constant_classref *cr;
183 constant_classref *compr;
185 builtintable_entry *bte;
191 u2 skipBasicBlockChange;
193 #if defined(USE_INLINING)
194 METHINFOt(m,"\nPARSING: ",DEBUG4);
195 if ((opt_rt) || (opt_xta)) {
198 if (opt_rt) Missed = rtMissed;
199 if (opt_xta) Missed = xtaMissed;
201 if (m->methodUsed != USED) {
203 printf(" rta/xta missed: "); fflush(stdout);
204 METHINFO(m,opt_verbose);
206 if ( (Missed = fopen("Missed", "a")) == NULL) {
207 printf("CACAO - rt/xtaMissed file: cant open file to write append \n");
210 utf_fprint(Missed,m->class->name);
211 fprintf(Missed," "); fflush(Missed);
212 utf_fprint(Missed,m->name);
213 fprintf(Missed," "); fflush(Missed);
214 utf_fprint(Missed,m->descriptor);
215 fprintf(Missed,"\n"); fflush(Missed);
222 #if defined(USE_INLINING)
224 label_index = inlinfo->label_index;
225 m->maxstack = inline_env->cummaxstack;
226 /*JOWENN m->exceptiontablelength = inline_env->cumextablelength;*/
228 tmpinlinf = (inlining_methodinfo *) list_first(inlinfo->inlinedmethods);
230 if (tmpinlinf != NULL)
231 nextgp = tmpinlinf->startgp;
235 /**** static analysis has to be called before inlining
236 which has to be called before reg_set
237 which has to be called before parse (or ???)
238 will check if method being parsed was analysed here
239 if (opt_xta && opt_verbose) {
241 printf("XTA requested, not available\n");
243 if (opt_vta && opt_verbose)
244 printf("VTA requested, not yet implemented\n");
247 /* allocate instruction array and block index table */
249 /* 1 additional for end ipc * # cum inline methods*/
251 m->basicblockindex = DMNEW(s4, inline_env->cumjcodelength + inline_env->cummethods);
252 memset(m->basicblockindex, 0, sizeof(s4) * (inline_env->cumjcodelength + inline_env->cummethods));
254 instructionstart = DMNEW(u1, inline_env->cumjcodelength + inline_env->cummethods);
255 memset(instructionstart, 0, sizeof(u1) * (inline_env->cumjcodelength + inline_env->cummethods));
257 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
258 /* additional MONITOREXITS are reached by branches which are 3 bytes */
260 iptr = m->instructions = DMNEW(instruction, inline_env->cumjcodelength + 5);
262 /* Zero the intermediate instructions array so we don't have any
263 * invalid pointers in it if we cannot finish analyse_stack(). */
265 memset(iptr, 0, sizeof(instruction) * (inline_env->cumjcodelength + 5));
267 /* compute branch targets of exception table */
269 if (m->exceptiontable == NULL) {
270 printf("m->exceptiontable=NULL\n");fflush(stdout);
273 printf("m->exceptiontable != NULL\n");fflush(stdout);
275 printf("m->exceptiontablelength=%i, inline_env->method->exceptiontablelength=%i,inline_env->cumextablelength=%i\n",
276 m->exceptiontablelength, inline_env->method->exceptiontablelength,inline_env->cumextablelength);
279 if (m->exceptiontablelength > 0)
280 m->exceptiontable = DMNEW(exceptiontable, m->exceptiontablelength + 1);
283 nextex = fillextable(m,
284 &(cd->exceptiontable[cd->exceptiontablelength-1]), m->exceptiontable, m->exceptiontablelength,
285 label_index, &b_count, inline_env);
286 s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */
288 #if defined(USE_THREADS)
289 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
290 m->isleafmethod = false;
291 inline_env->method->isleafmethod = false;
295 /* scan all java instructions */
299 if (m->linenumbercount == 0) {
301 /*printf("linenumber count == 0\n");*/
303 linepcchange = m->linenumbers[0].start_pc;
306 skipBasicBlockChange=0;
307 for (p = 0, gp = 0; p < inline_env->method->jcodelength; gp += (nextp - p), p = nextp) {
309 /* DEBUG */ if (DEBUG==true) printf("----- p:%d gp:%d\n",p,gp);
311 /* mark this position as a valid instruction start */
313 instructionstart[gp] = 1;
314 /*log_text("new start of instruction");*/
315 /*printf ("%s, linepcchange %d,p %d\n",inline_env->method->name->text,linepcchange,p);*/
316 if (linepcchange==p) {
317 if (inline_env->method->linenumbercount > lineindex) {
318 currentline = inline_env->method->linenumbers[lineindex].line_number;
320 if (lineindex < inline_env->method->linenumbercount)
321 linepcchange = inline_env->method->linenumbers[lineindex].start_pc;
322 /*printf("Line number changed to: %ld\n",currentline);*/
327 #if defined(USE_INLINING)
328 if ((useinlining) && (gp == nextgp)) {
330 bool *readonly = NULL;
333 block_insert(gp); /* JJJJJJJJJJ */
335 instructionstart[gp] = 1;
336 m->basicblockindex[gp] |= (ipc << 1); /*FIXME: necessary ? */
338 opcode = code_get_u1(p,inline_env->method);
339 nextp = p += jcommandsize[opcode];
340 if (nextp > inline_env->method->jcodelength) {
341 log_text("Unexpected end of bytecode");
345 tmpinlinf = list_first(inlinfo->inlinedmethods);
346 firstlocal = tmpinlinf->firstlocal;
347 label_index = tmpinlinf->label_index;
348 readonly = tmpinlinf->readonly;
350 for (i=0,tptr=tmpinlinf->method->paramtypes;i<tmpinlinf->method->paramcount;i++,tptr++) {
351 if ( ((*tptr)==TYPE_LNG) ||
352 ((*tptr)==TYPE_DBL) )
358 for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) {
361 if ((i == 0) && inlineparamopt) {
362 OP1(ICMD_CLEAR_ARGREN, firstlocal);
365 if (!inlineparamopt || !readonly[i]) {
369 op = ICMD_READONLY_ARG;
373 if ( ((*tptr)==TYPE_LNG) ||
374 ((*tptr)==TYPE_DBL) )
379 OP1(op, firstlocal + argBlockIdx);
380 /* OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i); */
381 /* printf("inline argument load operation for local: %ld\n",firstlocal + tmpinlinf->method->paramcount - 1 - i); */
383 skipBasicBlockChange=1;
384 METHINFOt(inline_env->method,"BEFORE SAVE: ",DEBUG);
385 inlining_save_compiler_variables();
386 METHINFOt(inline_env->method,"AFTER SAVE: ",DEBUG);
387 inlining_set_compiler_variables(tmpinlinf);
388 METHINFOt(inline_env->method,"AFTER SET :: ",DEBUG);
389 METHINFOt(m,"\n.......Parsing (inlined): ",DEBUG);
390 METHINFO(inline_env->method,DEBUG);
392 OP1(ICMD_INLINE_START,tmpinlinf->level);
394 if (inlinfo->inlinedmethods == NULL) {
397 tmpinlinf = list_first(inlinfo->inlinedmethods);
398 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
400 if (inline_env->method->exceptiontablelength > 0)
401 nextex = fillextable(m, nextex,
402 inline_env->method->exceptiontable, inline_env->method->exceptiontablelength,
403 label_index, &b_count, inline_env);
406 #endif /* defined(USE_INLINING) */
408 opcode = code_get_u1(p,inline_env->method); /* fetch op code */
411 printf("Parse p=%i<%i<%i< opcode=<%i> %s\n",
412 p, gp, inline_env->jcodelength, opcode, opcode_names[opcode]);
414 printf("label_index[%d]=%d\n",p,label_index[p]);
417 printf("basicblockindex[gp=%i]=%i=%p ipc=%i=%p shifted ipc=%i=%p\n",
418 gp,m->basicblockindex[gp],m->basicblockindex[gp],ipc,ipc,(ipc<<1),(ipc<<1));
421 if (!skipBasicBlockChange) {
422 m->basicblockindex[gp] |= (ipc << 1); /*store intermed cnt*/
423 } else skipBasicBlockChange=0;
425 printf("basicblockindex[gp=%i]=%i=%p \n",
426 gp,m->basicblockindex[gp],m->basicblockindex[gp]);
431 block_insert(gp); /* start new block */
433 /*printf("blockend was set: new blockcount: %ld at:%ld\n",b_count,gp);*/
436 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
438 if (nextp > inline_env->method->jcodelength) {
439 log_text("Unexpected end of bytecode");
443 s_count += stackreq[opcode]; /* compute stack element count */
449 /* pushing constants onto the stack p */
452 LOADCONST_I(code_get_s1(p+1,inline_env->method));
456 LOADCONST_I(code_get_s2(p+1,inline_env->method));
460 i = code_get_u1(p + 1, inline_env->method);
461 goto pushconstantitem;
465 i = code_get_u2(p + 1, inline_env->method);
469 if (i >= inline_env->method->class->cpcount) {
470 dolog("Attempt to access constant outside range: %d >= %d", i, inline_env->method->class->cpcount);
474 switch (inline_env->method->class->cptags[i]) {
475 case CONSTANT_Integer:
476 LOADCONST_I(((constant_integer *) (inline_env->method->class->cpinfos[i]))->value);
479 LOADCONST_L(((constant_long *) (inline_env->method->class->cpinfos[i]))->value);
482 LOADCONST_F(((constant_float *) (inline_env->method->class->cpinfos[i]))->value);
484 case CONSTANT_Double:
485 LOADCONST_D(((constant_double *) (inline_env->method->class->cpinfos[i]))->value);
487 case CONSTANT_String:
488 LOADCONST_A(literalstring_new((utf *) (inline_env->method->class->cpinfos[i])));
491 log_text("Invalid constant type to push");
496 case JAVA_ACONST_NULL:
507 LOADCONST_I(opcode - JAVA_ICONST_0);
512 LOADCONST_L(opcode - JAVA_LCONST_0);
518 LOADCONST_F(opcode - JAVA_FCONST_0);
523 LOADCONST_D(opcode - JAVA_DCONST_0);
526 /* loading variables onto the stack */
534 i = code_get_u1(p + 1,inline_env->method);
536 i = code_get_u2(p + 1,inline_env->method);
540 OP1LOAD(opcode, i + firstlocal);
547 OP1LOAD(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
554 OP1LOAD(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
561 OP1LOAD(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
568 OP1LOAD(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
575 OP1LOAD(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
578 /* storing stack values into local variables */
586 i = code_get_u1(p + 1,inline_env->method);
588 i = code_get_u2(p + 1,inline_env->method);
592 OP1STORE(opcode, i + firstlocal);
599 OP1STORE(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
606 OP1STORE(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
613 OP1STORE(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
620 OP1STORE(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
627 OP1STORE(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
635 i = code_get_u1(p + 1,inline_env->method);
636 v = code_get_s1(p + 2,inline_env->method);
639 i = code_get_u2(p + 1,inline_env->method);
640 v = code_get_s2(p + 3,inline_env->method);
644 INDEX_ONEWORD(i + firstlocal);
645 OP2I(opcode, i + firstlocal, v);
649 /* wider index for loading, storing and incrementing */
656 /* managing arrays ****************************************************/
660 switch (code_get_s1(p + 1, inline_env->method)) {
662 bte = builtintable_get_internal(BUILTIN_newarray_boolean);
665 bte = builtintable_get_internal(BUILTIN_newarray_char);
668 bte = builtintable_get_internal(BUILTIN_newarray_float);
671 bte = builtintable_get_internal(BUILTIN_newarray_double);
674 bte = builtintable_get_internal(BUILTIN_newarray_byte);
677 bte = builtintable_get_internal(BUILTIN_newarray_short);
680 bte = builtintable_get_internal(BUILTIN_newarray_int);
683 bte = builtintable_get_internal(BUILTIN_newarray_long);
686 log_text("Invalid array-type to create");
689 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
690 OP(ICMD_CHECKEXCEPTION);
695 i = code_get_u2(p + 1, inline_env->method);
696 compr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
698 if (!(cr = class_get_classref_multiarray_of(1, compr)))
701 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
705 bte = builtintable_get_internal(BUILTIN_newarray);
706 LOADCONST_A_BUILTIN(c->vftbl);
707 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
710 bte = builtintable_get_internal(PATCHER_builtin_newarray);
711 LOADCONST_A_BUILTIN(cr);
712 BUILTIN(bte, bte->md->paramcount, cr, currentline);
715 OP(ICMD_CHECKEXCEPTION);
718 case JAVA_MULTIANEWARRAY:
719 inline_env->method->isleafmethod = false;
720 i = code_get_u2(p + 1, inline_env->method);
722 constant_classref *cr;
724 s4 v = code_get_u1(p + 3, inline_env->method);
726 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
728 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
732 OP2AT(opcode, v, c->vftbl, NULL, currentline);
736 (voidptr) (ptrint) PATCHER_builtin_multianewarray,
760 i = p + code_get_s2(p + 1,inline_env->method);
765 /*printf("GOTO: %d\n",i);*/
773 i = p + code_get_s4(p + 1,inline_env->method);
779 /*printf("B6 JSR_W\t"); fflush(stdout);*/
787 i = code_get_u1(p + 1,inline_env->method);
789 i = code_get_u2(p + 1,inline_env->method);
796 if (inline_env->isinlinedmethod) {
797 OP1(ICMD_GOTO, inlinfo->stopgp);
801 OP1LOAD(opcode, i + firstlocal);
810 if (inline_env->isinlinedmethod) {
811 /* if (p==m->jcodelength-1) {*/ /* return is at end of inlined method */
815 if (nextp>inline_env->method->jcodelength-1) {
816 /* OP1(ICMD_GOTO, inlinfo->stopgp);
824 OP1(ICMD_GOTO, inlinfo->stopgp);
838 /* table jumps ********************************************************/
840 case JAVA_LOOKUPSWITCH:
847 nextp = ALIGN((p + 1), 4);
849 if (nextp + 8 > inline_env->method->jcodelength) {
850 log_text("Unexpected end of bytecode");
855 tablep = (s4 *) (inline_env->method->jcode + nextp);
858 num = code_get_u4(nextp + 4, inline_env->method);
859 tablep = DMNEW(s4, num * 2 + 2);
862 OP2A(opcode, 0, tablep, currentline);
866 j = p + code_get_s4(nextp, inline_env->method);
869 *tablep = j; /* restore for little endian */
875 /* number of pairs */
877 num = code_get_u4(nextp, inline_env->method);
882 if (nextp + 8 * num > inline_env->method->jcodelength) {
883 /* XXX TODO VerifyError */
884 log_text("Unexpected end of bytecode");
888 for (i = 0; i < num; i++) {
891 j = code_get_s4(nextp, inline_env->method);
892 *tablep = j; /* restore for little endian */
896 /* check if the lookup table is sorted correctly */
898 if (i && (j <= prevvalue)) {
899 *exceptionptr = new_verifyerror(m, "Unsorted lookup switch");
906 j = p + code_get_s4(nextp,inline_env->method);
909 *tablep = j; /* restore for little endian */
920 case JAVA_TABLESWITCH:
926 nextp = ALIGN((p + 1), 4);
927 if (nextp + 12 > inline_env->method->jcodelength) {
928 /* XXX TODO VerifyError */
929 log_text("Unexpected end of bytecode");
934 tablep = (s4 *) (inline_env->method->jcode + nextp);
937 num = code_get_u4(nextp + 8,inline_env->method) - code_get_u4(nextp + 4,inline_env->method);
938 tablep = DMNEW(s4, num + 1 + 3);
941 OP2A(opcode, 0, tablep, currentline);
945 j = p + code_get_s4(nextp, inline_env->method);
948 *tablep = j; /* restore for little endian */
956 j = code_get_s4(nextp, inline_env->method);
957 *tablep = j; /* restore for little endian */
963 num = code_get_s4(nextp, inline_env->method);
964 *tablep = num; /* restore for little endian */
968 num -= j; /* difference of upper - lower */
971 /* XXX TODO VerifyError */
972 log_text("invalid TABLESWITCH: upper bound < lower bound");
976 if (nextp + 4 * (num + 1) > inline_env->method->jcodelength) {
977 /* XXX TODO VerifyError */
978 log_text("Unexpected end of bytecode");
982 for (i = 0; i <= num; i++) {
983 j = p + code_get_s4(nextp,inline_env->method);
985 /*printf("TABLESWITCH: j before mapping=%ld\n",j);*/
988 *tablep = j; /* restore for little endian */
993 /*printf("TABLESWITCH: block_insert(%ld)\n",j);*/
1000 /* load and store of object fields ************************************/
1003 bte = builtintable_get_internal(BUILTIN_canstore);
1004 OP2A(opcode, bte->md->paramcount, bte, currentline);
1005 inline_env->method->isleafmethod = false;
1008 case JAVA_GETSTATIC:
1009 case JAVA_PUTSTATIC:
1013 constant_FMIref *fr;
1014 unresolved_field *uf;
1017 i = code_get_u2(p + 1, inline_env->method);
1018 fr = class_getconstant(inline_env->method->class, i,
1021 OP2A_NOINC(opcode, fr->parseddesc.fd->type, fr, currentline);
1023 if (!(uf = create_unresolved_field(inline_env->method->class,
1028 /* store unresolved_field pointer */
1032 /* only with -noverify, otherwise the typechecker does this */
1035 if (!resolve_field(uf, resolveLazy, &fi))
1040 #if defined(__MIPS__) || defined(__POWERPC__)
1041 if (!fi || !fi->class->initialized)
1042 inline_env->method->isleafmethod = false;
1053 /* method invocation **************************************************/
1055 case JAVA_INVOKESTATIC:
1056 i = code_get_u2(p + 1, inline_env->method);
1058 constant_FMIref *mr;
1060 unresolved_method *um;
1063 inline_env->method->isleafmethod = false;
1065 mr = class_getconstant(inline_env->method->class, i,
1066 CONSTANT_Methodref);
1068 md = mr->parseddesc.md;
1071 if (!descriptor_params_from_paramtypes(md, ACC_STATIC))
1074 OP2A_NOINC(opcode, md->paramcount, mr, currentline);
1076 um = create_unresolved_method(inline_env->method->class,
1077 inline_env->method, iptr);
1082 /* store the unresolved_method pointer */
1086 /* only with -noverify, otherwise the typechecker does this */
1089 if (!resolve_method(um, resolveLazy, &mi))
1101 case JAVA_INVOKESPECIAL:
1102 case JAVA_INVOKEVIRTUAL:
1104 constant_FMIref *mr;
1106 unresolved_method *um;
1109 inline_env->method->isleafmethod = false;
1111 i = code_get_u2(p + 1, inline_env->method);
1112 mr = class_getconstant(inline_env->method->class, i,
1113 CONSTANT_Methodref);
1115 md = mr->parseddesc.md;
1118 if (!descriptor_params_from_paramtypes(md, 0))
1121 OP2A_NOINC(opcode, md->paramcount, mr, currentline);
1123 um = create_unresolved_method(inline_env->method->class,
1124 inline_env->method, iptr);
1129 /* store the unresolved_method* */
1133 /* only with -noverify, otherwise the typechecker does this */
1136 if (!resolve_method(um, resolveLazy, &mi))
1148 case JAVA_INVOKEINTERFACE:
1149 i = code_get_u2(p + 1, inline_env->method);
1151 constant_FMIref *mr;
1153 unresolved_method *um;
1156 inline_env->method->isleafmethod = false;
1158 mr = class_getconstant(inline_env->method->class, i,
1159 CONSTANT_InterfaceMethodref);
1161 md = mr->parseddesc.md;
1164 if (!descriptor_params_from_paramtypes(md, 0))
1167 OP2A_NOINC(opcode, md->paramcount, mr, currentline);
1169 um = create_unresolved_method(inline_env->method->class,
1170 inline_env->method, iptr);
1175 /* store the unresolved_method* */
1179 /* only with -noverify, otherwise the typechecker does this */
1182 if (!resolve_method(um, resolveLazy, &mi))
1194 /* miscellaneous object operations ************************************/
1197 i = code_get_u2(p + 1, inline_env->method);
1198 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1200 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true,
1204 if (c && c->initialized) {
1205 bte = builtintable_get_internal(BUILTIN_new);
1206 LOADCONST_A_BUILTIN(c);
1207 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1210 bte = builtintable_get_internal(PATCHER_builtin_new);
1211 LOADCONST_A_BUILTIN(cr);
1212 BUILTIN(bte, bte->md->paramcount, cr, currentline);
1216 OP(ICMD_CHECKEXCEPTION);
1219 case JAVA_CHECKCAST:
1220 i = code_get_u2(p + 1, inline_env->method);
1221 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1223 if (!resolve_classref(inline_env->method, cr, resolveLazy, true,
1227 if (cr->name->text[0] == '[') {
1228 /* array type cast-check */
1230 bte = builtintable_get_internal(BUILTIN_arraycheckcast);
1231 OP2AT(ICMD_ARRAYCHECKCAST, 1, bte, c->vftbl, currentline);
1234 bte = builtintable_get_internal(PATCHER_builtin_arraycheckcast);
1235 OP2AT(ICMD_ARRAYCHECKCAST, 0, bte, cr, currentline);
1237 inline_env->method->isleafmethod = false;
1240 /* object type cast-check */
1241 OP2AT(opcode, 1, c, cr, currentline);
1243 #if defined(__MIPS__) || defined(__POWERPC__)
1245 inline_env->method->isleafmethod = false;
1250 case JAVA_INSTANCEOF:
1251 i = code_get_u2(p + 1,inline_env->method);
1252 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1254 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
1257 if (cr->name->text[0] == '[') {
1258 /* array type cast-check */
1260 bte = builtintable_get_internal(BUILTIN_arrayinstanceof);
1261 LOADCONST_A_BUILTIN(c->vftbl);
1262 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1265 bte = builtintable_get_internal(PATCHER_builtin_arrayinstanceof);
1266 LOADCONST_A_BUILTIN(cr);
1267 BUILTIN(bte, bte->md->paramcount, cr, currentline);
1272 /* object type cast-check */
1273 OP2AT(opcode, 1, c, cr, currentline);
1275 #if defined(__MIPS__) || defined(__POWERPC__)
1277 inline_env->method->isleafmethod = false;
1281 case JAVA_MONITORENTER:
1282 #if defined(USE_THREADS)
1285 bte = builtintable_get_internal(BUILTIN_monitorenter);
1286 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1295 case JAVA_MONITOREXIT:
1296 #if defined(USE_THREADS)
1298 bte = builtintable_get_internal(BUILTIN_monitorexit);
1299 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1307 /* any other basic operation ******************************************/
1310 #if !SUPPORT_DIVISION
1311 bte = builtintable_get_internal(BUILTIN_idiv);
1312 OP2A(opcode, bte->md->paramcount, bte, currentline);
1313 inline_env->method->isleafmethod = false;
1320 #if !SUPPORT_DIVISION
1321 bte = builtintable_get_internal(BUILTIN_irem);
1322 OP2A(opcode, bte->md->paramcount, bte, currentline);
1323 inline_env->method->isleafmethod = false;
1330 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1331 bte = builtintable_get_internal(BUILTIN_ldiv);
1332 OP2A(opcode, bte->md->paramcount, bte, currentline);
1333 inline_env->method->isleafmethod = false;
1340 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1341 bte = builtintable_get_internal(BUILTIN_lrem);
1342 OP2A(opcode, bte->md->paramcount, bte, currentline);
1343 inline_env->method->isleafmethod = false;
1350 #if defined(__I386__)
1353 bte = builtintable_get_internal(BUILTIN_frem);
1354 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1359 #if defined(__I386__)
1362 bte = builtintable_get_internal(BUILTIN_drem);
1363 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1368 #if defined(__ALPHA__)
1370 bte = builtintable_get_internal(BUILTIN_f2i);
1371 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1380 #if defined(__ALPHA__)
1382 bte = builtintable_get_internal(BUILTIN_f2l);
1383 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1392 #if defined(__ALPHA__)
1394 bte = builtintable_get_internal(BUILTIN_d2i);
1395 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1404 #if defined(__ALPHA__)
1406 bte = builtintable_get_internal(BUILTIN_d2l);
1407 BUILTIN(bte, bte->md->paramcount, NULL, currentline);
1415 case JAVA_BREAKPOINT:
1417 new_verifyerror(m, "Quick instructions shouldn't appear yet.");
1420 case 204: /* unused opcode */
1473 new_internalerror("Illegal opcode %d at instr %d\n",
1484 /* If WIDE was used correctly, iswide should have been reset by now. */
1485 if (iswide && opcode != JAVA_WIDE) {
1486 log_text("Illegal instruction: WIDE before incompatible opcode");
1490 #if defined(USE_INLINING)
1491 /* if (inline_env->isinlinedmethod && p == inline_env->method->jcodelength - 1) { */ /* end of an inlined method */
1492 if (inline_env->isinlinedmethod && (nextp >= inline_env->method->jcodelength) ) { /* end of an inlined method */
1493 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1494 gp = inlinfo->stopgp;
1495 inlining_restore_compiler_variables();
1496 OP(ICMD_INLINE_END);
1497 /*label_index = inlinfo->label_index;*/
1499 METHINFOt(inline_env->method,"AFTER RESTORE : ",DEBUG);
1500 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1501 if (inlinfo->inlinedmethods == NULL) { /* JJJJ */
1504 tmpinlinf = list_first(inlinfo->inlinedmethods);
1505 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1507 /* printf("nextpgp: %d\n", nextgp); */
1508 label_index=inlinfo->label_index;
1509 firstlocal = inlinfo->firstlocal;
1511 #endif /* defined(USE_INLINING) */
1516 if (p != m->jcodelength) {
1517 printf("p (%d) != m->jcodelength (%d)\n",p,m->jcodelength);
1518 log_text("Command-sequence crosses code-boundary");
1523 *exceptionptr = new_verifyerror(m, "Falling off the end of the code");
1527 /* adjust block count if target 0 is not first intermediate instruction */
1529 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1))
1532 /* copy local to method variables */
1534 m->instructioncount = ipc;
1535 m->basicblockcount = b_count;
1536 m->stackcount = s_count + m->basicblockcount * m->maxstack;
1538 /* allocate stack table */
1540 m->stack = DMNEW(stackelement, m->stackcount);
1545 bptr = m->basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1550 /* additional block if target 0 is not first intermediate instruction */
1552 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) {
1553 bptr->iinstr = m->instructions;
1556 bptr->type = BBTYPE_STD;
1557 bptr->branchrefs = NULL;
1558 bptr->pre_count = 0;
1559 bptr->debug_nr = m->c_debug_nr++;
1562 (bptr - 1)->next = bptr;
1565 /* allocate blocks */
1567 for (p = 0; p < inline_env->cumjcodelength; p++) {
1568 /* for (p = 0; p < m->jcodelength; p++) { */
1569 if (m->basicblockindex[p] & 1) {
1570 /* Check if this block starts at the beginning of an */
1573 if (!instructionstart[p]) {
1574 /* XXX TODO throw exception? which one? */
1575 dolog("Branch into middle of instruction: Basic Block beginn: %d\n", p);
1579 /* allocate the block */
1580 bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
1581 bptr->debug_nr = m->c_debug_nr++;
1583 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1587 bptr->type = BBTYPE_STD;
1588 bptr->branchrefs = NULL;
1589 m->basicblockindex[p] = b_count;
1590 bptr->pre_count = 0;
1593 (bptr - 1)->next = bptr;
1597 /* allocate additional block at end */
1599 bptr->instack = bptr->outstack = NULL;
1600 bptr->indepth = bptr->outdepth = 0;
1601 bptr->iinstr = NULL;
1602 (bptr - 1)->icount = (m->instructions + m->instructioncount) - (bptr - 1)->iinstr;
1607 bptr->type = BBTYPE_STD;
1608 bptr->branchrefs = NULL;
1609 bptr->pre_count = 0;
1610 bptr->debug_nr = m->c_debug_nr++;
1611 (bptr - 1)->next = bptr;
1614 if (cd->exceptiontablelength > 0) {
1615 cd->exceptiontable[cd->exceptiontablelength - 1].down = NULL;
1618 for (i = 0; i < cd->exceptiontablelength; ++i) {
1619 p = cd->exceptiontable[i].startpc;
1620 cd->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1622 p = cd->exceptiontable[i].endpc;
1623 cd->exceptiontable[i].end = (p == inline_env->method->jcodelength) ? (m->basicblocks + m->basicblockcount /*+ 1*/) : (m->basicblocks + m->basicblockindex[p]);
1625 p = cd->exceptiontable[i].handlerpc;
1626 cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1630 #if defined(USE_INLINING)
1632 inlining_cleanup(inline_env);
1635 /* just return methodinfo* to signal everything was ok */
1642 * These are local overrides for various environment variables in Emacs.
1643 * Please do not remove this and leave it at the end of the file, where
1644 * Emacs will automagically detect them.
1645 * ---------------------------------------------------------------------
1648 * indent-tabs-mode: t