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 3829 2005-12-01 19:47:56Z 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/jit/asmpart.h"
59 #include "vm/jit/jit.h"
60 #include "vm/jit/parse.h"
61 #include "vm/jit/patcher.h"
62 #include "vm/jit/inline/parseRT.h"
63 #include "vm/jit/inline/parseXTA.h"
64 #include "vm/jit/inline/inline.h"
65 #include "vm/jit/loop/loop.h"
66 #include "vm/jit/inline/parseRTprint.h"
71 bool DEBUG4 = false; /*opcodes for parse.c*/
75 #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);
76 #define debug_writebranch1
78 /*******************************************************************************
80 function 'parse' scans the JavaVM code and generates intermediate code
82 During parsing the block index table is used to store at bit pos 0
83 a flag which marks basic block starts and at position 1 to 31 the
84 intermediate instruction index. After parsing the block index table
85 is scanned, for marked positions a block is generated and the block
86 number is stored in the block index table.
88 *******************************************************************************/
90 static exceptiontable* fillextable(methodinfo *m,
91 exceptiontable* extable, exceptiontable *raw_extable,
92 int exceptiontablelength,
93 int *label_index, int *block_count,
94 t_inlining_globals *inline_env)
96 int b_count, p, src, insertBlock;
98 if (exceptiontablelength == 0)
101 /*if (m->exceptiontablelength > 0) {
103 printf("m->exceptiontablelength=%i\n",m->exceptiontablelength);
107 b_count = *block_count;
109 for (src = exceptiontablelength-1; src >=0; src--) {
110 /* printf("Excepiont table index: %d\n",i); */
111 p = raw_extable[src].startpc;
112 if (label_index != NULL) p = label_index[p];
113 extable->startpc = p;
117 /*** 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)]);
118 fflush(stdout); } ***/
119 p = raw_extable[src].endpc; /* see JVM Spec 4.7.3 */
120 if (p <= raw_extable[src].startpc) {
121 *exceptionptr = new_verifyerror(inline_env->method,
122 "Invalid exception handler range");
126 if (p >inline_env->method->jcodelength) {
127 *exceptionptr = new_verifyerror(inline_env->method,
128 "Invalid exception handler end is after code end");
132 if (p<inline_env->method->jcodelength) insertBlock=1; else insertBlock=0;
133 /*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
134 printf("%s:fillextab: endpc:%ld\n",m->name->text,p);*/
135 if (label_index != NULL) p = label_index[p];
138 /*if (p < inline_env->method->jcodelength) {
140 if (insertBlock) block_insert(p);
142 p = raw_extable[src].handlerpc;
143 if (label_index != NULL) p = label_index[p];
144 extable->handlerpc = p;
148 extable->catchtype = raw_extable[src].catchtype;
149 extable->next = NULL;
150 extable->down = &extable[1];
154 *block_count = b_count;
155 return extable; /*&extable[i];*/ /* return the next free xtable* */
160 methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env)
162 int p; /* java instruction counter */
163 int nextp; /* start of next java instruction */
164 int opcode; /* java opcode */
165 int i; /* temporary for different uses (ctrs)*/
166 int ipc = 0; /* intermediate instruction counter */
167 int b_count = 0; /* basic block counter */
168 int s_count = 0; /* stack element counter */
169 bool blockend = false; /* true if basic block end has been reached */
170 bool iswide = false; /* true if last instruction was a wide*/
171 instruction *iptr; /* current ptr into instruction array */
172 int gp; /* global java instruction counter */
173 /* inlining info for current method */
175 inlining_methodinfo *inlinfo = inline_env->inlining_rootinfo;
176 inlining_methodinfo *tmpinlinf;
177 int nextgp = -1; /* start of next method to be inlined */
178 int *label_index = NULL; /* label redirection table */
179 int firstlocal = 0; /* first local variable of method */
180 exceptiontable* nextex; /* points next free entry in extable */
181 u1 *instructionstart; /* 1 for pcs which are valid instr. starts */
183 constant_classref *cr;
184 constant_classref *compr;
186 builtintable_entry *bte;
192 u2 skipBasicBlockChange;
194 #if defined(USE_INLINING)
195 METHINFOt(m,"\nPARSING: ",DEBUG4);
196 if ((opt_rt) || (opt_xta)) {
199 if (opt_rt) Missed = rtMissed;
200 if (opt_xta) Missed = xtaMissed;
202 if (m->methodUsed != USED) {
204 printf(" rta/xta missed: "); fflush(stdout);
205 METHINFO(m,opt_verbose);
207 if ( (Missed = fopen("Missed", "a")) == NULL) {
208 printf("CACAO - rt/xtaMissed file: cant open file to write append \n");
211 utf_fprint(Missed,m->class->name);
212 fprintf(Missed," "); fflush(Missed);
213 utf_fprint(Missed,m->name);
214 fprintf(Missed," "); fflush(Missed);
215 utf_fprint(Missed,m->descriptor);
216 fprintf(Missed,"\n"); fflush(Missed);
223 #if defined(USE_INLINING)
225 label_index = inlinfo->label_index;
226 m->maxstack = inline_env->cummaxstack;
227 /*JOWENN m->exceptiontablelength = inline_env->cumextablelength;*/
229 tmpinlinf = (inlining_methodinfo *) list_first(inlinfo->inlinedmethods);
231 if (tmpinlinf != NULL)
232 nextgp = tmpinlinf->startgp;
236 /**** static analysis has to be called before inlining
237 which has to be called before reg_set
238 which has to be called before parse (or ???)
239 will check if method being parsed was analysed here
240 if (opt_xta && opt_verbose) {
242 printf("XTA requested, not available\n");
244 if (opt_vta && opt_verbose)
245 printf("VTA requested, not yet implemented\n");
248 /* allocate instruction array and block index table */
250 /* 1 additional for end ipc * # cum inline methods*/
252 m->basicblockindex = DMNEW(s4, inline_env->cumjcodelength + inline_env->cummethods);
253 memset(m->basicblockindex, 0, sizeof(s4) * (inline_env->cumjcodelength + inline_env->cummethods));
255 instructionstart = DMNEW(u1, inline_env->cumjcodelength + inline_env->cummethods);
256 memset(instructionstart, 0, sizeof(u1) * (inline_env->cumjcodelength + inline_env->cummethods));
258 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
259 /* additional MONITOREXITS are reached by branches which are 3 bytes */
261 iptr = m->instructions = DMNEW(instruction, inline_env->cumjcodelength + 5);
263 /* Zero the intermediate instructions array so we don't have any
264 * invalid pointers in it if we cannot finish analyse_stack(). */
266 memset(iptr, 0, sizeof(instruction) * (inline_env->cumjcodelength + 5));
268 /* compute branch targets of exception table */
270 if (m->exceptiontable == NULL) {
271 printf("m->exceptiontable=NULL\n");fflush(stdout);
274 printf("m->exceptiontable != NULL\n");fflush(stdout);
276 printf("m->exceptiontablelength=%i, inline_env->method->exceptiontablelength=%i,inline_env->cumextablelength=%i\n",
277 m->exceptiontablelength, inline_env->method->exceptiontablelength,inline_env->cumextablelength);
280 if (m->exceptiontablelength > 0)
281 m->exceptiontable = DMNEW(exceptiontable, m->exceptiontablelength + 1);
284 nextex = fillextable(m,
285 &(cd->exceptiontable[cd->exceptiontablelength-1]), m->exceptiontable, m->exceptiontablelength,
286 label_index, &b_count, inline_env);
289 s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */
291 #if defined(USE_THREADS)
292 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
293 m->isleafmethod = false;
294 inline_env->method->isleafmethod = false;
298 /* scan all java instructions */
302 if (m->linenumbercount == 0) {
304 /*printf("linenumber count == 0\n");*/
306 linepcchange = m->linenumbers[0].start_pc;
309 skipBasicBlockChange=0;
310 for (p = 0, gp = 0; p < inline_env->method->jcodelength; gp += (nextp - p), p = nextp) {
312 /* DEBUG */ if (DEBUG==true) printf("----- p:%d gp:%d\n",p,gp);
314 /* mark this position as a valid instruction start */
316 instructionstart[gp] = 1;
317 /*log_text("new start of instruction");*/
318 /*printf ("%s, linepcchange %d,p %d\n",inline_env->method->name->text,linepcchange,p);*/
319 if (linepcchange==p) {
320 if (inline_env->method->linenumbercount > lineindex) {
321 currentline = inline_env->method->linenumbers[lineindex].line_number;
323 if (lineindex < inline_env->method->linenumbercount)
324 linepcchange = inline_env->method->linenumbers[lineindex].start_pc;
325 /*printf("Line number changed to: %ld\n",currentline);*/
330 #if defined(USE_INLINING)
331 if ((useinlining) && (gp == nextgp)) {
333 bool *readonly = NULL;
336 block_insert(gp); /* JJJJJJJJJJ */
338 instructionstart[gp] = 1;
339 m->basicblockindex[gp] |= (ipc << 1); /*FIXME: necessary ? */
341 opcode = code_get_u1(p,inline_env->method);
342 nextp = p += jcommandsize[opcode];
343 if (nextp > inline_env->method->jcodelength) {
344 *exceptionptr = new_verifyerror(inline_env->method,
345 "Unexpected end of bytecode");
349 tmpinlinf = list_first(inlinfo->inlinedmethods);
350 firstlocal = tmpinlinf->firstlocal;
351 label_index = tmpinlinf->label_index;
352 readonly = tmpinlinf->readonly;
354 for (i=0,tptr=tmpinlinf->method->paramtypes;i<tmpinlinf->method->paramcount;i++,tptr++) {
355 if ( ((*tptr)==TYPE_LNG) ||
356 ((*tptr)==TYPE_DBL) )
362 for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) {
365 if ((i == 0) && inlineparamopt) {
366 OP1(ICMD_CLEAR_ARGREN, firstlocal);
369 if (!inlineparamopt || !readonly[i]) {
373 op = ICMD_READONLY_ARG;
377 if ( ((*tptr)==TYPE_LNG) ||
378 ((*tptr)==TYPE_DBL) )
383 OP1(op, firstlocal + argBlockIdx);
384 /* OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i); */
385 /* printf("inline argument load operation for local: %ld\n",firstlocal + tmpinlinf->method->paramcount - 1 - i); */
387 skipBasicBlockChange=1;
388 METHINFOt(inline_env->method,"BEFORE SAVE: ",DEBUG);
389 inlining_save_compiler_variables();
390 METHINFOt(inline_env->method,"AFTER SAVE: ",DEBUG);
391 inlining_set_compiler_variables(tmpinlinf);
392 METHINFOt(inline_env->method,"AFTER SET :: ",DEBUG);
393 METHINFOt(m,"\n.......Parsing (inlined): ",DEBUG);
394 METHINFO(inline_env->method,DEBUG);
396 OP1(ICMD_INLINE_START,tmpinlinf->level);
398 if (inlinfo->inlinedmethods == NULL) {
401 tmpinlinf = list_first(inlinfo->inlinedmethods);
402 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
404 if (inline_env->method->exceptiontablelength > 0) {
405 nextex = fillextable(m, nextex,
406 inline_env->method->exceptiontable, inline_env->method->exceptiontablelength,
407 label_index, &b_count, inline_env);
413 #endif /* defined(USE_INLINING) */
415 opcode = code_get_u1(p,inline_env->method); /* fetch op code */
418 printf("Parse p=%i<%i<%i< opcode=<%i> %s\n",
419 p, gp, inline_env->jcodelength, opcode, opcode_names[opcode]);
421 printf("label_index[%d]=%d\n",p,label_index[p]);
424 printf("basicblockindex[gp=%i]=%i=%p ipc=%i=%p shifted ipc=%i=%p\n",
425 gp,m->basicblockindex[gp],m->basicblockindex[gp],ipc,ipc,(ipc<<1),(ipc<<1));
428 if (!skipBasicBlockChange) {
429 m->basicblockindex[gp] |= (ipc << 1); /*store intermed cnt*/
430 } else skipBasicBlockChange=0;
432 printf("basicblockindex[gp=%i]=%i=%p \n",
433 gp,m->basicblockindex[gp],m->basicblockindex[gp]);
438 block_insert(gp); /* start new block */
440 /*printf("blockend was set: new blockcount: %ld at:%ld\n",b_count,gp);*/
443 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
445 if (nextp > inline_env->method->jcodelength) {
446 *exceptionptr = new_verifyerror(inline_env->method,
447 "Unexpected end of bytecode");
451 s_count += stackreq[opcode]; /* compute stack element count */
457 /* pushing constants onto the stack p */
460 LOADCONST_I(code_get_s1(p+1,inline_env->method));
464 LOADCONST_I(code_get_s2(p+1,inline_env->method));
468 i = code_get_u1(p + 1, inline_env->method);
469 goto pushconstantitem;
473 i = code_get_u2(p + 1, inline_env->method);
477 if (i >= inline_env->method->class->cpcount) {
478 *exceptionptr = new_verifyerror(inline_env->method,
479 "Attempt to access constant outside range");
483 switch (inline_env->method->class->cptags[i]) {
484 case CONSTANT_Integer:
485 LOADCONST_I(((constant_integer *) (inline_env->method->class->cpinfos[i]))->value);
488 LOADCONST_L(((constant_long *) (inline_env->method->class->cpinfos[i]))->value);
491 LOADCONST_F(((constant_float *) (inline_env->method->class->cpinfos[i]))->value);
493 case CONSTANT_Double:
494 LOADCONST_D(((constant_double *) (inline_env->method->class->cpinfos[i]))->value);
496 case CONSTANT_String:
497 LOADCONST_A(literalstring_new((utf *) (inline_env->method->class->cpinfos[i])));
500 cr = (constant_classref *) (inline_env->method->class->cpinfos[i]);
502 if (!resolve_classref(inline_env->method, cr, resolveLazy, true,
506 /* if not resolved, c == NULL */
508 LOADCONST_A_CLASS(c, cr);
511 *exceptionptr = new_verifyerror(inline_env->method,
512 "Invalid constant type to push");
517 case JAVA_ACONST_NULL:
528 LOADCONST_I(opcode - JAVA_ICONST_0);
533 LOADCONST_L(opcode - JAVA_LCONST_0);
539 LOADCONST_F(opcode - JAVA_FCONST_0);
544 LOADCONST_D(opcode - JAVA_DCONST_0);
547 /* loading variables onto the stack */
555 i = code_get_u1(p + 1,inline_env->method);
557 i = code_get_u2(p + 1,inline_env->method);
561 OP1LOAD(opcode, i + firstlocal);
568 OP1LOAD(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
575 OP1LOAD(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
582 OP1LOAD(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
589 OP1LOAD(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
596 OP1LOAD(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
599 /* storing stack values into local variables */
607 i = code_get_u1(p + 1,inline_env->method);
609 i = code_get_u2(p + 1,inline_env->method);
613 OP1STORE(opcode, i + firstlocal);
620 OP1STORE(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
627 OP1STORE(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
634 OP1STORE(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
641 OP1STORE(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
648 OP1STORE(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
656 i = code_get_u1(p + 1,inline_env->method);
657 v = code_get_s1(p + 2,inline_env->method);
660 i = code_get_u2(p + 1,inline_env->method);
661 v = code_get_s2(p + 3,inline_env->method);
665 INDEX_ONEWORD(i + firstlocal);
666 OP2I(opcode, i + firstlocal, v);
670 /* wider index for loading, storing and incrementing */
677 /* managing arrays ****************************************************/
680 switch (code_get_s1(p + 1, inline_env->method)) {
682 bte = builtintable_get_internal(BUILTIN_newarray_boolean);
685 bte = builtintable_get_internal(BUILTIN_newarray_char);
688 bte = builtintable_get_internal(BUILTIN_newarray_float);
691 bte = builtintable_get_internal(BUILTIN_newarray_double);
694 bte = builtintable_get_internal(BUILTIN_newarray_byte);
697 bte = builtintable_get_internal(BUILTIN_newarray_short);
700 bte = builtintable_get_internal(BUILTIN_newarray_int);
703 bte = builtintable_get_internal(BUILTIN_newarray_long);
706 *exceptionptr = new_verifyerror(inline_env->method,
707 "Invalid array-type to create");
710 BUILTIN(bte, true, NULL, currentline);
714 i = code_get_u2(p + 1, inline_env->method);
715 compr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
719 if (!(cr = class_get_classref_multiarray_of(1, compr)))
722 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
725 LOADCONST_A_BUILTIN(c, cr);
726 bte = builtintable_get_internal(BUILTIN_newarray);
727 BUILTIN(bte, true, NULL, currentline);
731 case JAVA_MULTIANEWARRAY:
732 inline_env->method->isleafmethod = false;
733 i = code_get_u2(p + 1, inline_env->method);
735 s4 v = code_get_u1(p + 3, inline_env->method);
737 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
741 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
745 OP2AT(opcode, v, c, NULL, currentline);
749 (voidptr) (ptrint) PATCHER_builtin_multianewarray,
773 i = p + code_get_s2(p + 1,inline_env->method);
778 /*printf("GOTO: %d\n",i);*/
786 i = p + code_get_s4(p + 1,inline_env->method);
792 /*printf("B6 JSR_W\t"); fflush(stdout);*/
800 i = code_get_u1(p + 1,inline_env->method);
802 i = code_get_u2(p + 1,inline_env->method);
809 if (inline_env->isinlinedmethod) {
810 OP1(ICMD_GOTO, inlinfo->stopgp);
814 OP1LOAD(opcode, i + firstlocal);
823 if (inline_env->isinlinedmethod) {
824 /* if (p==m->jcodelength-1) {*/ /* return is at end of inlined method */
828 if (nextp>inline_env->method->jcodelength-1) {
829 /* OP1(ICMD_GOTO, inlinfo->stopgp);
837 OP1(ICMD_GOTO, inlinfo->stopgp);
842 /* zero val.a so no patcher is inserted */
843 /* the type checker may set this later */
850 /* zero val.a so no patcher is inserted */
851 /* the type checker may set this later */
857 /* table jumps ********************************************************/
859 case JAVA_LOOKUPSWITCH:
866 nextp = ALIGN((p + 1), 4);
868 if (nextp + 8 > inline_env->method->jcodelength) {
869 *exceptionptr = new_verifyerror(inline_env->method,
870 "Unexpected end of bytecode");
875 tablep = (s4 *) (inline_env->method->jcode + nextp);
878 num = code_get_u4(nextp + 4, inline_env->method);
879 tablep = DMNEW(s4, num * 2 + 2);
882 OP2A(opcode, 0, tablep, currentline);
886 j = p + code_get_s4(nextp, inline_env->method);
889 *tablep = j; /* restore for little endian */
895 /* number of pairs */
897 num = code_get_u4(nextp, inline_env->method);
902 if (nextp + 8 * num > inline_env->method->jcodelength) {
903 *exceptionptr = new_verifyerror(inline_env->method,
904 "Unexpected end of bytecode");
908 for (i = 0; i < num; i++) {
911 j = code_get_s4(nextp, inline_env->method);
912 *tablep = j; /* restore for little endian */
916 /* check if the lookup table is sorted correctly */
918 if (i && (j <= prevvalue)) {
919 *exceptionptr = new_verifyerror(m, "Unsorted lookup switch");
926 j = p + code_get_s4(nextp,inline_env->method);
929 *tablep = j; /* restore for little endian */
940 case JAVA_TABLESWITCH:
946 nextp = ALIGN((p + 1), 4);
947 if (nextp + 12 > inline_env->method->jcodelength) {
948 *exceptionptr = new_verifyerror(inline_env->method,
949 "Unexpected end of bytecode");
954 tablep = (s4 *) (inline_env->method->jcode + nextp);
957 num = code_get_u4(nextp + 8,inline_env->method) - code_get_u4(nextp + 4,inline_env->method);
958 tablep = DMNEW(s4, num + 1 + 3);
961 OP2A(opcode, 0, tablep, currentline);
965 j = p + code_get_s4(nextp, inline_env->method);
968 *tablep = j; /* restore for little endian */
976 j = code_get_s4(nextp, inline_env->method);
977 *tablep = j; /* restore for little endian */
983 num = code_get_s4(nextp, inline_env->method);
984 *tablep = num; /* restore for little endian */
988 num -= j; /* difference of upper - lower */
991 *exceptionptr = new_verifyerror(inline_env->method,
992 "invalid TABLESWITCH: upper bound < lower bound");
996 if (nextp + 4 * (num + 1) > inline_env->method->jcodelength) {
997 *exceptionptr = new_verifyerror(inline_env->method,
998 "Unexpected end of bytecode");
1002 for (i = 0; i <= num; i++) {
1003 j = p + code_get_s4(nextp,inline_env->method);
1005 /*printf("TABLESWITCH: j before mapping=%ld\n",j);*/
1008 *tablep = j; /* restore for little endian */
1013 /*printf("TABLESWITCH: block_insert(%ld)\n",j);*/
1020 /* load and store of object fields ************************************/
1024 inline_env->method->isleafmethod = false;
1027 case JAVA_GETSTATIC:
1028 case JAVA_PUTSTATIC:
1032 constant_FMIref *fr;
1033 unresolved_field *uf;
1036 i = code_get_u2(p + 1, inline_env->method);
1037 fr = class_getconstant(inline_env->method->class, i,
1042 OP2A_NOINC(opcode, fr->parseddesc.fd->type, fr, currentline);
1044 if (!(uf = create_unresolved_field(inline_env->method->class,
1049 /* store unresolved_field pointer */
1053 /* only with -noverify, otherwise the typechecker does this */
1056 if (!resolve_field(uf, resolveLazy, &fi))
1061 #if defined(__MIPS__)
1062 if ((!fi || !fi->class->initialized) && inline_env->method->isleafmethod == true) {
1063 utf_display(inline_env->method->class->name);
1065 utf_display(inline_env->method->name);
1066 utf_display(inline_env->method->descriptor);
1067 printf(": NO LEAF!\n");
1069 inline_env->method->isleafmethod = false;
1081 /* method invocation **************************************************/
1083 case JAVA_INVOKESTATIC:
1084 i = code_get_u2(p + 1, inline_env->method);
1086 constant_FMIref *mr;
1088 unresolved_method *um;
1091 inline_env->method->isleafmethod = false;
1093 mr = class_getconstant(inline_env->method->class, i,
1094 CONSTANT_Methodref);
1098 md = mr->parseddesc.md;
1101 if (!descriptor_params_from_paramtypes(md, ACC_STATIC))
1104 OP2A_NOINC(opcode, 0, mr, currentline);
1106 um = create_unresolved_method(inline_env->method->class,
1107 inline_env->method, iptr);
1112 /* store the unresolved_method pointer */
1116 /* only with -noverify, otherwise the typechecker does this */
1119 if (!resolve_method(um, resolveLazy, &mi))
1131 case JAVA_INVOKESPECIAL:
1132 case JAVA_INVOKEVIRTUAL:
1134 constant_FMIref *mr;
1136 unresolved_method *um;
1139 inline_env->method->isleafmethod = false;
1141 i = code_get_u2(p + 1, inline_env->method);
1142 mr = class_getconstant(inline_env->method->class, i,
1143 CONSTANT_Methodref);
1147 md = mr->parseddesc.md;
1150 if (!descriptor_params_from_paramtypes(md, 0))
1153 OP2A_NOINC(opcode, 0, mr, currentline);
1155 um = create_unresolved_method(inline_env->method->class,
1156 inline_env->method, iptr);
1161 /* store the unresolved_method* */
1165 /* only with -noverify, otherwise the typechecker does this */
1168 if (!resolve_method(um, resolveLazy, &mi))
1180 case JAVA_INVOKEINTERFACE:
1181 i = code_get_u2(p + 1, inline_env->method);
1183 constant_FMIref *mr;
1185 unresolved_method *um;
1188 inline_env->method->isleafmethod = false;
1190 mr = class_getconstant(inline_env->method->class, i,
1191 CONSTANT_InterfaceMethodref);
1195 md = mr->parseddesc.md;
1198 if (!descriptor_params_from_paramtypes(md, 0))
1201 OP2A_NOINC(opcode, 0, mr, currentline);
1203 um = create_unresolved_method(inline_env->method->class,
1204 inline_env->method, iptr);
1209 /* store the unresolved_method* */
1213 /* only with -noverify, otherwise the typechecker does this */
1216 if (!resolve_method(um, resolveLazy, &mi))
1228 /* miscellaneous object operations ************************************/
1231 i = code_get_u2(p + 1, inline_env->method);
1232 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1236 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true,
1240 LOADCONST_A_BUILTIN(c, cr);
1241 bte = builtintable_get_internal(BUILTIN_new);
1242 BUILTIN(bte, true, NULL, currentline);
1246 case JAVA_CHECKCAST:
1247 i = code_get_u2(p + 1, inline_env->method);
1248 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1252 if (!resolve_classref(inline_env->method, cr, resolveLazy, true,
1256 if (cr->name->text[0] == '[') {
1257 /* array type cast-check */
1258 OP2AT(opcode, 0, c, cr, currentline);
1259 inline_env->method->isleafmethod = false;
1262 /* object type cast-check */
1263 OP2AT(opcode, 1, c, cr, currentline);
1265 #if defined(__MIPS__)
1266 if (!c && inline_env->method->isleafmethod == true) {
1267 utf_display(inline_env->method->class->name);
1269 utf_display(inline_env->method->name);
1270 utf_display(inline_env->method->descriptor);
1271 printf(": NO LEAF!\n");
1273 inline_env->method->isleafmethod = false;
1279 case JAVA_INSTANCEOF:
1280 i = code_get_u2(p + 1,inline_env->method);
1281 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1285 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
1288 if (cr->name->text[0] == '[') {
1289 /* array type cast-check */
1290 LOADCONST_A_BUILTIN(c, cr);
1291 bte = builtintable_get_internal(BUILTIN_arrayinstanceof);
1292 BUILTIN(bte, false, NULL, currentline);
1296 /* object type cast-check */
1297 OP2AT(opcode, 1, c, cr, currentline);
1299 #if defined(__MIPS__)
1300 if (!c && inline_env->method->isleafmethod == true) {
1301 utf_display(inline_env->method->class->name);
1303 utf_display(inline_env->method->name);
1304 utf_display(inline_env->method->descriptor);
1305 printf(": NO LEAF!\n");
1307 inline_env->method->isleafmethod = false;
1312 case JAVA_MONITORENTER:
1313 #if defined(USE_THREADS)
1316 bte = builtintable_get_internal(BUILTIN_monitorenter);
1317 BUILTIN(bte, false, NULL, currentline);
1326 case JAVA_MONITOREXIT:
1327 #if defined(USE_THREADS)
1329 bte = builtintable_get_internal(BUILTIN_monitorexit);
1330 BUILTIN(bte, false, NULL, currentline);
1338 /* any other basic operation ******************************************/
1341 #if !SUPPORT_DIVISION
1342 bte = builtintable_get_internal(BUILTIN_idiv);
1343 OP2A(opcode, bte->md->paramcount, bte, currentline);
1344 inline_env->method->isleafmethod = false;
1351 #if !SUPPORT_DIVISION
1352 bte = builtintable_get_internal(BUILTIN_irem);
1353 OP2A(opcode, bte->md->paramcount, bte, currentline);
1354 inline_env->method->isleafmethod = false;
1361 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1362 bte = builtintable_get_internal(BUILTIN_ldiv);
1363 OP2A(opcode, bte->md->paramcount, bte, currentline);
1364 inline_env->method->isleafmethod = false;
1371 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1372 bte = builtintable_get_internal(BUILTIN_lrem);
1373 OP2A(opcode, bte->md->paramcount, bte, currentline);
1374 inline_env->method->isleafmethod = false;
1381 #if defined(__I386__)
1384 bte = builtintable_get_internal(BUILTIN_frem);
1385 BUILTIN(bte, false, NULL, currentline);
1390 #if defined(__I386__)
1393 bte = builtintable_get_internal(BUILTIN_drem);
1394 BUILTIN(bte, false, NULL, currentline);
1399 #if defined(__ALPHA__)
1401 bte = builtintable_get_internal(BUILTIN_f2i);
1402 BUILTIN(bte, false, NULL, currentline);
1411 #if defined(__ALPHA__)
1413 bte = builtintable_get_internal(BUILTIN_f2l);
1414 BUILTIN(bte, false, NULL, currentline);
1423 #if defined(__ALPHA__)
1425 bte = builtintable_get_internal(BUILTIN_d2i);
1426 BUILTIN(bte, false, NULL, currentline);
1435 #if defined(__ALPHA__)
1437 bte = builtintable_get_internal(BUILTIN_d2l);
1438 BUILTIN(bte, false, NULL, currentline);
1446 case JAVA_BREAKPOINT:
1448 new_verifyerror(m, "Quick instructions shouldn't appear yet.");
1451 case 186: /* unused opcode */
1506 new_verifyerror(inline_env->method,"Illegal opcode %d at instr %d\n",
1517 /* If WIDE was used correctly, iswide should have been reset by now. */
1518 if (iswide && opcode != JAVA_WIDE) {
1519 *exceptionptr = new_verifyerror(inline_env->method,
1520 "Illegal instruction: WIDE before incompatible opcode");
1524 #if defined(USE_INLINING)
1525 /* if (inline_env->isinlinedmethod && p == inline_env->method->jcodelength - 1) { */ /* end of an inlined method */
1526 if (inline_env->isinlinedmethod && (nextp >= inline_env->method->jcodelength) ) { /* end of an inlined method */
1527 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1528 gp = inlinfo->stopgp;
1529 inlining_restore_compiler_variables();
1530 OP(ICMD_INLINE_END);
1531 /*label_index = inlinfo->label_index;*/
1533 METHINFOt(inline_env->method,"AFTER RESTORE : ",DEBUG);
1534 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1535 if (inlinfo->inlinedmethods == NULL) { /* JJJJ */
1538 tmpinlinf = list_first(inlinfo->inlinedmethods);
1539 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1541 /* printf("nextpgp: %d\n", nextgp); */
1542 label_index=inlinfo->label_index;
1543 firstlocal = inlinfo->firstlocal;
1545 #endif /* defined(USE_INLINING) */
1550 if (p != m->jcodelength) {
1551 printf("p (%d) != m->jcodelength (%d)\n",p,m->jcodelength);
1552 *exceptionptr = new_verifyerror(inline_env->method,
1553 "Command-sequence crosses code-boundary");
1558 *exceptionptr = new_verifyerror(m, "Falling off the end of the code");
1562 /* adjust block count if target 0 is not first intermediate instruction */
1564 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1))
1567 /* copy local to method variables */
1569 m->instructioncount = ipc;
1570 m->basicblockcount = b_count;
1571 m->stackcount = s_count + m->basicblockcount * m->maxstack;
1573 /* allocate stack table */
1575 m->stack = DMNEW(stackelement, m->stackcount);
1580 bptr = m->basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1585 /* additional block if target 0 is not first intermediate instruction */
1587 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) {
1588 bptr->iinstr = m->instructions;
1591 bptr->type = BBTYPE_STD;
1592 bptr->branchrefs = NULL;
1593 bptr->pre_count = 0;
1594 bptr->debug_nr = m->c_debug_nr++;
1597 (bptr - 1)->next = bptr;
1600 /* allocate blocks */
1602 for (p = 0; p < inline_env->cumjcodelength; p++) {
1603 /* for (p = 0; p < m->jcodelength; p++) { */
1604 if (m->basicblockindex[p] & 1) {
1605 /* Check if this block starts at the beginning of an */
1608 if (!instructionstart[p]) {
1609 *exceptionptr = new_verifyerror(inline_env->method,
1610 "Branch into middle of instruction");
1614 /* allocate the block */
1615 bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
1616 bptr->debug_nr = m->c_debug_nr++;
1618 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1622 bptr->type = BBTYPE_STD;
1623 bptr->branchrefs = NULL;
1624 m->basicblockindex[p] = b_count;
1625 bptr->pre_count = 0;
1628 (bptr - 1)->next = bptr;
1632 /* allocate additional block at end */
1634 bptr->instack = bptr->outstack = NULL;
1635 bptr->indepth = bptr->outdepth = 0;
1636 bptr->iinstr = NULL;
1637 (bptr - 1)->icount = (m->instructions + m->instructioncount) - (bptr - 1)->iinstr;
1642 bptr->type = BBTYPE_STD;
1643 bptr->branchrefs = NULL;
1644 bptr->pre_count = 0;
1645 bptr->debug_nr = m->c_debug_nr++;
1646 (bptr - 1)->next = bptr;
1649 if (cd->exceptiontablelength > 0) {
1650 cd->exceptiontable[cd->exceptiontablelength - 1].down = NULL;
1653 for (i = 0; i < cd->exceptiontablelength; ++i) {
1654 p = cd->exceptiontable[i].startpc;
1655 cd->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1657 p = cd->exceptiontable[i].endpc;
1658 cd->exceptiontable[i].end = (p == inline_env->method->jcodelength) ? (m->basicblocks + m->basicblockcount /*+ 1*/) : (m->basicblocks + m->basicblockindex[p]);
1660 p = cd->exceptiontable[i].handlerpc;
1661 cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1665 #if defined(USE_INLINING)
1667 inlining_cleanup(inline_env);
1670 /* just return methodinfo* to signal everything was ok */
1677 * These are local overrides for various environment variables in Emacs.
1678 * Please do not remove this and leave it at the end of the file, where
1679 * Emacs will automagically detect them.
1680 * ---------------------------------------------------------------------
1683 * indent-tabs-mode: t