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 3394 2005-10-10 17:11:00Z edwin $
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 *exceptionptr = new_verifyerror(inline_env->method,
123 "Invalid exception handler range");
127 if (p >inline_env->method->jcodelength) {
128 *exceptionptr = new_verifyerror(inline_env->method,
129 "Invalid exception handler end is after code end");
133 if (p<inline_env->method->jcodelength) insertBlock=1; else insertBlock=0;
134 /*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
135 printf("%s:fillextab: endpc:%ld\n",m->name->text,p);*/
136 if (label_index != NULL) p = label_index[p];
139 /*if (p < inline_env->method->jcodelength) {
141 if (insertBlock) block_insert(p);
143 p = raw_extable[src].handlerpc;
144 if (label_index != NULL) p = label_index[p];
145 extable->handlerpc = p;
149 extable->catchtype = raw_extable[src].catchtype;
150 extable->next = NULL;
151 extable->down = &extable[1];
155 *block_count = b_count;
156 return extable; /*&extable[i];*/ /* return the next free xtable* */
161 methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env)
163 int p; /* java instruction counter */
164 int nextp; /* start of next java instruction */
165 int opcode; /* java opcode */
166 int i; /* temporary for different uses (ctrs)*/
167 int ipc = 0; /* intermediate instruction counter */
168 int b_count = 0; /* basic block counter */
169 int s_count = 0; /* stack element counter */
170 bool blockend = false; /* true if basic block end has been reached */
171 bool iswide = false; /* true if last instruction was a wide*/
172 instruction *iptr; /* current ptr into instruction array */
173 int gp; /* global java instruction counter */
174 /* inlining info for current method */
176 inlining_methodinfo *inlinfo = inline_env->inlining_rootinfo;
177 inlining_methodinfo *tmpinlinf;
178 int nextgp = -1; /* start of next method to be inlined */
179 int *label_index = NULL; /* label redirection table */
180 int firstlocal = 0; /* first local variable of method */
181 exceptiontable* nextex; /* points next free entry in extable */
182 u1 *instructionstart; /* 1 for pcs which are valid instr. starts */
184 constant_classref *cr;
185 constant_classref *compr;
187 builtintable_entry *bte;
193 u2 skipBasicBlockChange;
195 #if defined(USE_INLINING)
196 METHINFOt(m,"\nPARSING: ",DEBUG4);
197 if ((opt_rt) || (opt_xta)) {
200 if (opt_rt) Missed = rtMissed;
201 if (opt_xta) Missed = xtaMissed;
203 if (m->methodUsed != USED) {
205 printf(" rta/xta missed: "); fflush(stdout);
206 METHINFO(m,opt_verbose);
208 if ( (Missed = fopen("Missed", "a")) == NULL) {
209 printf("CACAO - rt/xtaMissed file: cant open file to write append \n");
212 utf_fprint(Missed,m->class->name);
213 fprintf(Missed," "); fflush(Missed);
214 utf_fprint(Missed,m->name);
215 fprintf(Missed," "); fflush(Missed);
216 utf_fprint(Missed,m->descriptor);
217 fprintf(Missed,"\n"); fflush(Missed);
224 #if defined(USE_INLINING)
226 label_index = inlinfo->label_index;
227 m->maxstack = inline_env->cummaxstack;
228 /*JOWENN m->exceptiontablelength = inline_env->cumextablelength;*/
230 tmpinlinf = (inlining_methodinfo *) list_first(inlinfo->inlinedmethods);
232 if (tmpinlinf != NULL)
233 nextgp = tmpinlinf->startgp;
237 /**** static analysis has to be called before inlining
238 which has to be called before reg_set
239 which has to be called before parse (or ???)
240 will check if method being parsed was analysed here
241 if (opt_xta && opt_verbose) {
243 printf("XTA requested, not available\n");
245 if (opt_vta && opt_verbose)
246 printf("VTA requested, not yet implemented\n");
249 /* allocate instruction array and block index table */
251 /* 1 additional for end ipc * # cum inline methods*/
253 m->basicblockindex = DMNEW(s4, inline_env->cumjcodelength + inline_env->cummethods);
254 memset(m->basicblockindex, 0, sizeof(s4) * (inline_env->cumjcodelength + inline_env->cummethods));
256 instructionstart = DMNEW(u1, inline_env->cumjcodelength + inline_env->cummethods);
257 memset(instructionstart, 0, sizeof(u1) * (inline_env->cumjcodelength + inline_env->cummethods));
259 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
260 /* additional MONITOREXITS are reached by branches which are 3 bytes */
262 iptr = m->instructions = DMNEW(instruction, inline_env->cumjcodelength + 5);
264 /* Zero the intermediate instructions array so we don't have any
265 * invalid pointers in it if we cannot finish analyse_stack(). */
267 memset(iptr, 0, sizeof(instruction) * (inline_env->cumjcodelength + 5));
269 /* compute branch targets of exception table */
271 if (m->exceptiontable == NULL) {
272 printf("m->exceptiontable=NULL\n");fflush(stdout);
275 printf("m->exceptiontable != NULL\n");fflush(stdout);
277 printf("m->exceptiontablelength=%i, inline_env->method->exceptiontablelength=%i,inline_env->cumextablelength=%i\n",
278 m->exceptiontablelength, inline_env->method->exceptiontablelength,inline_env->cumextablelength);
281 if (m->exceptiontablelength > 0)
282 m->exceptiontable = DMNEW(exceptiontable, m->exceptiontablelength + 1);
285 nextex = fillextable(m,
286 &(cd->exceptiontable[cd->exceptiontablelength-1]), m->exceptiontable, m->exceptiontablelength,
287 label_index, &b_count, inline_env);
290 s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */
292 #if defined(USE_THREADS)
293 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
294 m->isleafmethod = false;
295 inline_env->method->isleafmethod = false;
299 /* scan all java instructions */
303 if (m->linenumbercount == 0) {
305 /*printf("linenumber count == 0\n");*/
307 linepcchange = m->linenumbers[0].start_pc;
310 skipBasicBlockChange=0;
311 for (p = 0, gp = 0; p < inline_env->method->jcodelength; gp += (nextp - p), p = nextp) {
313 /* DEBUG */ if (DEBUG==true) printf("----- p:%d gp:%d\n",p,gp);
315 /* mark this position as a valid instruction start */
317 instructionstart[gp] = 1;
318 /*log_text("new start of instruction");*/
319 /*printf ("%s, linepcchange %d,p %d\n",inline_env->method->name->text,linepcchange,p);*/
320 if (linepcchange==p) {
321 if (inline_env->method->linenumbercount > lineindex) {
322 currentline = inline_env->method->linenumbers[lineindex].line_number;
324 if (lineindex < inline_env->method->linenumbercount)
325 linepcchange = inline_env->method->linenumbers[lineindex].start_pc;
326 /*printf("Line number changed to: %ld\n",currentline);*/
331 #if defined(USE_INLINING)
332 if ((useinlining) && (gp == nextgp)) {
334 bool *readonly = NULL;
337 block_insert(gp); /* JJJJJJJJJJ */
339 instructionstart[gp] = 1;
340 m->basicblockindex[gp] |= (ipc << 1); /*FIXME: necessary ? */
342 opcode = code_get_u1(p,inline_env->method);
343 nextp = p += jcommandsize[opcode];
344 if (nextp > inline_env->method->jcodelength) {
345 *exceptionptr = new_verifyerror(inline_env->method,
346 "Unexpected end of bytecode");
350 tmpinlinf = list_first(inlinfo->inlinedmethods);
351 firstlocal = tmpinlinf->firstlocal;
352 label_index = tmpinlinf->label_index;
353 readonly = tmpinlinf->readonly;
355 for (i=0,tptr=tmpinlinf->method->paramtypes;i<tmpinlinf->method->paramcount;i++,tptr++) {
356 if ( ((*tptr)==TYPE_LNG) ||
357 ((*tptr)==TYPE_DBL) )
363 for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) {
366 if ((i == 0) && inlineparamopt) {
367 OP1(ICMD_CLEAR_ARGREN, firstlocal);
370 if (!inlineparamopt || !readonly[i]) {
374 op = ICMD_READONLY_ARG;
378 if ( ((*tptr)==TYPE_LNG) ||
379 ((*tptr)==TYPE_DBL) )
384 OP1(op, firstlocal + argBlockIdx);
385 /* OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i); */
386 /* printf("inline argument load operation for local: %ld\n",firstlocal + tmpinlinf->method->paramcount - 1 - i); */
388 skipBasicBlockChange=1;
389 METHINFOt(inline_env->method,"BEFORE SAVE: ",DEBUG);
390 inlining_save_compiler_variables();
391 METHINFOt(inline_env->method,"AFTER SAVE: ",DEBUG);
392 inlining_set_compiler_variables(tmpinlinf);
393 METHINFOt(inline_env->method,"AFTER SET :: ",DEBUG);
394 METHINFOt(m,"\n.......Parsing (inlined): ",DEBUG);
395 METHINFO(inline_env->method,DEBUG);
397 OP1(ICMD_INLINE_START,tmpinlinf->level);
399 if (inlinfo->inlinedmethods == NULL) {
402 tmpinlinf = list_first(inlinfo->inlinedmethods);
403 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
405 if (inline_env->method->exceptiontablelength > 0) {
406 nextex = fillextable(m, nextex,
407 inline_env->method->exceptiontable, inline_env->method->exceptiontablelength,
408 label_index, &b_count, inline_env);
414 #endif /* defined(USE_INLINING) */
416 opcode = code_get_u1(p,inline_env->method); /* fetch op code */
419 printf("Parse p=%i<%i<%i< opcode=<%i> %s\n",
420 p, gp, inline_env->jcodelength, opcode, opcode_names[opcode]);
422 printf("label_index[%d]=%d\n",p,label_index[p]);
425 printf("basicblockindex[gp=%i]=%i=%p ipc=%i=%p shifted ipc=%i=%p\n",
426 gp,m->basicblockindex[gp],m->basicblockindex[gp],ipc,ipc,(ipc<<1),(ipc<<1));
429 if (!skipBasicBlockChange) {
430 m->basicblockindex[gp] |= (ipc << 1); /*store intermed cnt*/
431 } else skipBasicBlockChange=0;
433 printf("basicblockindex[gp=%i]=%i=%p \n",
434 gp,m->basicblockindex[gp],m->basicblockindex[gp]);
439 block_insert(gp); /* start new block */
441 /*printf("blockend was set: new blockcount: %ld at:%ld\n",b_count,gp);*/
444 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
446 if (nextp > inline_env->method->jcodelength) {
447 *exceptionptr = new_verifyerror(inline_env->method,
448 "Unexpected end of bytecode");
452 s_count += stackreq[opcode]; /* compute stack element count */
458 /* pushing constants onto the stack p */
461 LOADCONST_I(code_get_s1(p+1,inline_env->method));
465 LOADCONST_I(code_get_s2(p+1,inline_env->method));
469 i = code_get_u1(p + 1, inline_env->method);
470 goto pushconstantitem;
474 i = code_get_u2(p + 1, inline_env->method);
478 if (i >= inline_env->method->class->cpcount) {
479 *exceptionptr = new_verifyerror(inline_env->method,
480 "Attempt to access constant outside range");
484 switch (inline_env->method->class->cptags[i]) {
485 case CONSTANT_Integer:
486 LOADCONST_I(((constant_integer *) (inline_env->method->class->cpinfos[i]))->value);
489 LOADCONST_L(((constant_long *) (inline_env->method->class->cpinfos[i]))->value);
492 LOADCONST_F(((constant_float *) (inline_env->method->class->cpinfos[i]))->value);
494 case CONSTANT_Double:
495 LOADCONST_D(((constant_double *) (inline_env->method->class->cpinfos[i]))->value);
497 case CONSTANT_String:
498 LOADCONST_A(literalstring_new((utf *) (inline_env->method->class->cpinfos[i])));
501 *exceptionptr = new_verifyerror(inline_env->method,
502 "Invalid constant type to push");
507 case JAVA_ACONST_NULL:
518 LOADCONST_I(opcode - JAVA_ICONST_0);
523 LOADCONST_L(opcode - JAVA_LCONST_0);
529 LOADCONST_F(opcode - JAVA_FCONST_0);
534 LOADCONST_D(opcode - JAVA_DCONST_0);
537 /* loading variables onto the stack */
545 i = code_get_u1(p + 1,inline_env->method);
547 i = code_get_u2(p + 1,inline_env->method);
551 OP1LOAD(opcode, i + firstlocal);
558 OP1LOAD(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
565 OP1LOAD(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
572 OP1LOAD(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
579 OP1LOAD(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
586 OP1LOAD(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
589 /* storing stack values into local variables */
597 i = code_get_u1(p + 1,inline_env->method);
599 i = code_get_u2(p + 1,inline_env->method);
603 OP1STORE(opcode, i + firstlocal);
610 OP1STORE(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
617 OP1STORE(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
624 OP1STORE(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
631 OP1STORE(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
638 OP1STORE(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
646 i = code_get_u1(p + 1,inline_env->method);
647 v = code_get_s1(p + 2,inline_env->method);
650 i = code_get_u2(p + 1,inline_env->method);
651 v = code_get_s2(p + 3,inline_env->method);
655 INDEX_ONEWORD(i + firstlocal);
656 OP2I(opcode, i + firstlocal, v);
660 /* wider index for loading, storing and incrementing */
667 /* managing arrays ****************************************************/
670 switch (code_get_s1(p + 1, inline_env->method)) {
672 bte = builtintable_get_internal(BUILTIN_newarray_boolean);
675 bte = builtintable_get_internal(BUILTIN_newarray_char);
678 bte = builtintable_get_internal(BUILTIN_newarray_float);
681 bte = builtintable_get_internal(BUILTIN_newarray_double);
684 bte = builtintable_get_internal(BUILTIN_newarray_byte);
687 bte = builtintable_get_internal(BUILTIN_newarray_short);
690 bte = builtintable_get_internal(BUILTIN_newarray_int);
693 bte = builtintable_get_internal(BUILTIN_newarray_long);
696 *exceptionptr = new_verifyerror(inline_env->method,
697 "Invalid array-type to create");
700 BUILTIN(bte, true, NULL, currentline);
704 i = code_get_u2(p + 1, inline_env->method);
705 compr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
709 if (!(cr = class_get_classref_multiarray_of(1, compr)))
712 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
716 bte = builtintable_get_internal(BUILTIN_newarray);
717 LOADCONST_A_BUILTIN(c->vftbl);
718 BUILTIN(bte, true, NULL, currentline);
721 bte = builtintable_get_internal(PATCHER_builtin_newarray);
722 LOADCONST_A_BUILTIN(cr);
723 BUILTIN(bte, true, cr, currentline);
728 case JAVA_MULTIANEWARRAY:
729 inline_env->method->isleafmethod = false;
730 i = code_get_u2(p + 1, inline_env->method);
732 s4 v = code_get_u1(p + 3, inline_env->method);
734 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
738 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
742 OP2AT(opcode, v, c->vftbl, NULL, currentline);
746 (voidptr) (ptrint) PATCHER_builtin_multianewarray,
770 i = p + code_get_s2(p + 1,inline_env->method);
775 /*printf("GOTO: %d\n",i);*/
783 i = p + code_get_s4(p + 1,inline_env->method);
789 /*printf("B6 JSR_W\t"); fflush(stdout);*/
797 i = code_get_u1(p + 1,inline_env->method);
799 i = code_get_u2(p + 1,inline_env->method);
806 if (inline_env->isinlinedmethod) {
807 OP1(ICMD_GOTO, inlinfo->stopgp);
811 OP1LOAD(opcode, i + firstlocal);
820 if (inline_env->isinlinedmethod) {
821 /* if (p==m->jcodelength-1) {*/ /* return is at end of inlined method */
825 if (nextp>inline_env->method->jcodelength-1) {
826 /* OP1(ICMD_GOTO, inlinfo->stopgp);
834 OP1(ICMD_GOTO, inlinfo->stopgp);
839 /* zero val.a so no patcher is inserted */
840 /* the type checker may set this later */
847 /* zero val.a so no patcher is inserted */
848 /* the type checker may set this later */
854 /* table jumps ********************************************************/
856 case JAVA_LOOKUPSWITCH:
863 nextp = ALIGN((p + 1), 4);
865 if (nextp + 8 > inline_env->method->jcodelength) {
866 *exceptionptr = new_verifyerror(inline_env->method,
867 "Unexpected end of bytecode");
872 tablep = (s4 *) (inline_env->method->jcode + nextp);
875 num = code_get_u4(nextp + 4, inline_env->method);
876 tablep = DMNEW(s4, num * 2 + 2);
879 OP2A(opcode, 0, tablep, currentline);
883 j = p + code_get_s4(nextp, inline_env->method);
886 *tablep = j; /* restore for little endian */
892 /* number of pairs */
894 num = code_get_u4(nextp, inline_env->method);
899 if (nextp + 8 * num > inline_env->method->jcodelength) {
900 *exceptionptr = new_verifyerror(inline_env->method,
901 "Unexpected end of bytecode");
905 for (i = 0; i < num; i++) {
908 j = code_get_s4(nextp, inline_env->method);
909 *tablep = j; /* restore for little endian */
913 /* check if the lookup table is sorted correctly */
915 if (i && (j <= prevvalue)) {
916 *exceptionptr = new_verifyerror(m, "Unsorted lookup switch");
923 j = p + code_get_s4(nextp,inline_env->method);
926 *tablep = j; /* restore for little endian */
937 case JAVA_TABLESWITCH:
943 nextp = ALIGN((p + 1), 4);
944 if (nextp + 12 > inline_env->method->jcodelength) {
945 *exceptionptr = new_verifyerror(inline_env->method,
946 "Unexpected end of bytecode");
951 tablep = (s4 *) (inline_env->method->jcode + nextp);
954 num = code_get_u4(nextp + 8,inline_env->method) - code_get_u4(nextp + 4,inline_env->method);
955 tablep = DMNEW(s4, num + 1 + 3);
958 OP2A(opcode, 0, tablep, currentline);
962 j = p + code_get_s4(nextp, inline_env->method);
965 *tablep = j; /* restore for little endian */
973 j = code_get_s4(nextp, inline_env->method);
974 *tablep = j; /* restore for little endian */
980 num = code_get_s4(nextp, inline_env->method);
981 *tablep = num; /* restore for little endian */
985 num -= j; /* difference of upper - lower */
988 *exceptionptr = new_verifyerror(inline_env->method,
989 "invalid TABLESWITCH: upper bound < lower bound");
993 if (nextp + 4 * (num + 1) > inline_env->method->jcodelength) {
994 *exceptionptr = new_verifyerror(inline_env->method,
995 "Unexpected end of bytecode");
999 for (i = 0; i <= num; i++) {
1000 j = p + code_get_s4(nextp,inline_env->method);
1002 /*printf("TABLESWITCH: j before mapping=%ld\n",j);*/
1005 *tablep = j; /* restore for little endian */
1010 /*printf("TABLESWITCH: block_insert(%ld)\n",j);*/
1017 /* load and store of object fields ************************************/
1020 bte = builtintable_get_internal(BUILTIN_canstore);
1021 OP2A(opcode, bte->md->paramcount, bte, currentline);
1022 inline_env->method->isleafmethod = false;
1025 case JAVA_GETSTATIC:
1026 case JAVA_PUTSTATIC:
1030 constant_FMIref *fr;
1031 unresolved_field *uf;
1034 i = code_get_u2(p + 1, inline_env->method);
1035 fr = class_getconstant(inline_env->method->class, i,
1040 OP2A_NOINC(opcode, fr->parseddesc.fd->type, fr, currentline);
1042 if (!(uf = create_unresolved_field(inline_env->method->class,
1047 /* store unresolved_field pointer */
1051 /* only with -noverify, otherwise the typechecker does this */
1054 if (!resolve_field(uf, resolveLazy, &fi))
1059 #if defined(__MIPS__) || defined(__POWERPC__)
1060 if (!fi || !fi->class->initialized)
1061 inline_env->method->isleafmethod = false;
1072 /* method invocation **************************************************/
1074 case JAVA_INVOKESTATIC:
1075 i = code_get_u2(p + 1, inline_env->method);
1077 constant_FMIref *mr;
1079 unresolved_method *um;
1082 inline_env->method->isleafmethod = false;
1084 mr = class_getconstant(inline_env->method->class, i,
1085 CONSTANT_Methodref);
1089 md = mr->parseddesc.md;
1092 if (!descriptor_params_from_paramtypes(md, ACC_STATIC))
1095 OP2A_NOINC(opcode, 0, mr, currentline);
1097 um = create_unresolved_method(inline_env->method->class,
1098 inline_env->method, iptr);
1103 /* store the unresolved_method pointer */
1107 /* only with -noverify, otherwise the typechecker does this */
1110 if (!resolve_method(um, resolveLazy, &mi))
1122 case JAVA_INVOKESPECIAL:
1123 case JAVA_INVOKEVIRTUAL:
1125 constant_FMIref *mr;
1127 unresolved_method *um;
1130 inline_env->method->isleafmethod = false;
1132 i = code_get_u2(p + 1, inline_env->method);
1133 mr = class_getconstant(inline_env->method->class, i,
1134 CONSTANT_Methodref);
1138 md = mr->parseddesc.md;
1141 if (!descriptor_params_from_paramtypes(md, 0))
1144 OP2A_NOINC(opcode, 0, mr, currentline);
1146 um = create_unresolved_method(inline_env->method->class,
1147 inline_env->method, iptr);
1152 /* store the unresolved_method* */
1156 /* only with -noverify, otherwise the typechecker does this */
1159 if (!resolve_method(um, resolveLazy, &mi))
1171 case JAVA_INVOKEINTERFACE:
1172 i = code_get_u2(p + 1, inline_env->method);
1174 constant_FMIref *mr;
1176 unresolved_method *um;
1179 inline_env->method->isleafmethod = false;
1181 mr = class_getconstant(inline_env->method->class, i,
1182 CONSTANT_InterfaceMethodref);
1186 md = mr->parseddesc.md;
1189 if (!descriptor_params_from_paramtypes(md, 0))
1192 OP2A_NOINC(opcode, 0, mr, currentline);
1194 um = create_unresolved_method(inline_env->method->class,
1195 inline_env->method, iptr);
1200 /* store the unresolved_method* */
1204 /* only with -noverify, otherwise the typechecker does this */
1207 if (!resolve_method(um, resolveLazy, &mi))
1219 /* miscellaneous object operations ************************************/
1222 i = code_get_u2(p + 1, inline_env->method);
1223 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1227 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true,
1231 if (c && c->initialized) {
1232 bte = builtintable_get_internal(BUILTIN_new);
1233 LOADCONST_A_BUILTIN(c);
1234 BUILTIN(bte, true, NULL, currentline);
1237 bte = builtintable_get_internal(PATCHER_builtin_new);
1238 LOADCONST_A_BUILTIN(cr);
1239 BUILTIN(bte, true, cr, currentline);
1245 case JAVA_CHECKCAST:
1246 i = code_get_u2(p + 1, inline_env->method);
1247 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1251 if (!resolve_classref(inline_env->method, cr, resolveLazy, true,
1255 if (cr->name->text[0] == '[') {
1256 /* array type cast-check */
1258 bte = builtintable_get_internal(BUILTIN_arraycheckcast);
1259 OP2AT(ICMD_ARRAYCHECKCAST, 1, bte, c->vftbl, currentline);
1262 bte = builtintable_get_internal(PATCHER_builtin_arraycheckcast);
1263 OP2AT(ICMD_ARRAYCHECKCAST, 0, bte, cr, currentline);
1265 inline_env->method->isleafmethod = false;
1268 /* object type cast-check */
1269 OP2AT(opcode, 1, c, cr, currentline);
1271 #if defined(__MIPS__) || defined(__POWERPC__)
1273 inline_env->method->isleafmethod = false;
1278 case JAVA_INSTANCEOF:
1279 i = code_get_u2(p + 1,inline_env->method);
1280 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1284 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
1287 if (cr->name->text[0] == '[') {
1288 /* array type cast-check */
1290 bte = builtintable_get_internal(BUILTIN_arrayinstanceof);
1291 LOADCONST_A_BUILTIN(c->vftbl);
1292 BUILTIN(bte, false, NULL, currentline);
1295 bte = builtintable_get_internal(PATCHER_builtin_arrayinstanceof);
1296 LOADCONST_A_BUILTIN(cr);
1297 BUILTIN(bte, false, cr, currentline);
1302 /* object type cast-check */
1303 OP2AT(opcode, 1, c, cr, currentline);
1305 #if defined(__MIPS__) || defined(__POWERPC__)
1307 inline_env->method->isleafmethod = false;
1311 case JAVA_MONITORENTER:
1312 #if defined(USE_THREADS)
1315 bte = builtintable_get_internal(BUILTIN_monitorenter);
1316 BUILTIN(bte, false, NULL, currentline);
1325 case JAVA_MONITOREXIT:
1326 #if defined(USE_THREADS)
1328 bte = builtintable_get_internal(BUILTIN_monitorexit);
1329 BUILTIN(bte, false, NULL, currentline);
1337 /* any other basic operation ******************************************/
1340 #if !SUPPORT_DIVISION
1341 bte = builtintable_get_internal(BUILTIN_idiv);
1342 OP2A(opcode, bte->md->paramcount, bte, currentline);
1343 inline_env->method->isleafmethod = false;
1350 #if !SUPPORT_DIVISION
1351 bte = builtintable_get_internal(BUILTIN_irem);
1352 OP2A(opcode, bte->md->paramcount, bte, currentline);
1353 inline_env->method->isleafmethod = false;
1360 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1361 bte = builtintable_get_internal(BUILTIN_ldiv);
1362 OP2A(opcode, bte->md->paramcount, bte, currentline);
1363 inline_env->method->isleafmethod = false;
1370 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1371 bte = builtintable_get_internal(BUILTIN_lrem);
1372 OP2A(opcode, bte->md->paramcount, bte, currentline);
1373 inline_env->method->isleafmethod = false;
1380 #if defined(__I386__)
1383 bte = builtintable_get_internal(BUILTIN_frem);
1384 BUILTIN(bte, false, NULL, currentline);
1389 #if defined(__I386__)
1392 bte = builtintable_get_internal(BUILTIN_drem);
1393 BUILTIN(bte, false, NULL, currentline);
1398 #if defined(__ALPHA__)
1400 bte = builtintable_get_internal(BUILTIN_f2i);
1401 BUILTIN(bte, false, NULL, currentline);
1410 #if defined(__ALPHA__)
1412 bte = builtintable_get_internal(BUILTIN_f2l);
1413 BUILTIN(bte, false, NULL, currentline);
1422 #if defined(__ALPHA__)
1424 bte = builtintable_get_internal(BUILTIN_d2i);
1425 BUILTIN(bte, false, NULL, currentline);
1434 #if defined(__ALPHA__)
1436 bte = builtintable_get_internal(BUILTIN_d2l);
1437 BUILTIN(bte, false, NULL, currentline);
1445 case JAVA_BREAKPOINT:
1447 new_verifyerror(m, "Quick instructions shouldn't appear yet.");
1450 case 186: /* unused opcode */
1505 new_verifyerror(inline_env->method,"Illegal opcode %d at instr %d\n",
1516 /* If WIDE was used correctly, iswide should have been reset by now. */
1517 if (iswide && opcode != JAVA_WIDE) {
1518 *exceptionptr = new_verifyerror(inline_env->method,
1519 "Illegal instruction: WIDE before incompatible opcode");
1523 #if defined(USE_INLINING)
1524 /* if (inline_env->isinlinedmethod && p == inline_env->method->jcodelength - 1) { */ /* end of an inlined method */
1525 if (inline_env->isinlinedmethod && (nextp >= inline_env->method->jcodelength) ) { /* end of an inlined method */
1526 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1527 gp = inlinfo->stopgp;
1528 inlining_restore_compiler_variables();
1529 OP(ICMD_INLINE_END);
1530 /*label_index = inlinfo->label_index;*/
1532 METHINFOt(inline_env->method,"AFTER RESTORE : ",DEBUG);
1533 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1534 if (inlinfo->inlinedmethods == NULL) { /* JJJJ */
1537 tmpinlinf = list_first(inlinfo->inlinedmethods);
1538 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1540 /* printf("nextpgp: %d\n", nextgp); */
1541 label_index=inlinfo->label_index;
1542 firstlocal = inlinfo->firstlocal;
1544 #endif /* defined(USE_INLINING) */
1549 if (p != m->jcodelength) {
1550 printf("p (%d) != m->jcodelength (%d)\n",p,m->jcodelength);
1551 *exceptionptr = new_verifyerror(inline_env->method,
1552 "Command-sequence crosses code-boundary");
1557 *exceptionptr = new_verifyerror(m, "Falling off the end of the code");
1561 /* adjust block count if target 0 is not first intermediate instruction */
1563 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1))
1566 /* copy local to method variables */
1568 m->instructioncount = ipc;
1569 m->basicblockcount = b_count;
1570 m->stackcount = s_count + m->basicblockcount * m->maxstack;
1572 /* allocate stack table */
1574 m->stack = DMNEW(stackelement, m->stackcount);
1579 bptr = m->basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1584 /* additional block if target 0 is not first intermediate instruction */
1586 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) {
1587 bptr->iinstr = m->instructions;
1590 bptr->type = BBTYPE_STD;
1591 bptr->branchrefs = NULL;
1592 bptr->pre_count = 0;
1593 bptr->debug_nr = m->c_debug_nr++;
1596 (bptr - 1)->next = bptr;
1599 /* allocate blocks */
1601 for (p = 0; p < inline_env->cumjcodelength; p++) {
1602 /* for (p = 0; p < m->jcodelength; p++) { */
1603 if (m->basicblockindex[p] & 1) {
1604 /* Check if this block starts at the beginning of an */
1607 if (!instructionstart[p]) {
1608 *exceptionptr = new_verifyerror(inline_env->method,
1609 "Branch into middle of instruction");
1613 /* allocate the block */
1614 bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
1615 bptr->debug_nr = m->c_debug_nr++;
1617 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1621 bptr->type = BBTYPE_STD;
1622 bptr->branchrefs = NULL;
1623 m->basicblockindex[p] = b_count;
1624 bptr->pre_count = 0;
1627 (bptr - 1)->next = bptr;
1631 /* allocate additional block at end */
1633 bptr->instack = bptr->outstack = NULL;
1634 bptr->indepth = bptr->outdepth = 0;
1635 bptr->iinstr = NULL;
1636 (bptr - 1)->icount = (m->instructions + m->instructioncount) - (bptr - 1)->iinstr;
1641 bptr->type = BBTYPE_STD;
1642 bptr->branchrefs = NULL;
1643 bptr->pre_count = 0;
1644 bptr->debug_nr = m->c_debug_nr++;
1645 (bptr - 1)->next = bptr;
1648 if (cd->exceptiontablelength > 0) {
1649 cd->exceptiontable[cd->exceptiontablelength - 1].down = NULL;
1652 for (i = 0; i < cd->exceptiontablelength; ++i) {
1653 p = cd->exceptiontable[i].startpc;
1654 cd->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1656 p = cd->exceptiontable[i].endpc;
1657 cd->exceptiontable[i].end = (p == inline_env->method->jcodelength) ? (m->basicblocks + m->basicblockcount /*+ 1*/) : (m->basicblocks + m->basicblockindex[p]);
1659 p = cd->exceptiontable[i].handlerpc;
1660 cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1664 #if defined(USE_INLINING)
1666 inlining_cleanup(inline_env);
1669 /* just return methodinfo* to signal everything was ok */
1676 * These are local overrides for various environment variables in Emacs.
1677 * Please do not remove this and leave it at the end of the file, where
1678 * Emacs will automagically detect them.
1679 * ---------------------------------------------------------------------
1682 * indent-tabs-mode: t