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 2394 2005-04-27 12:42:00Z twisti $
43 #include "mm/memory.h"
44 #include "native/native.h"
45 #include "toolbox/logging.h"
46 #include "vm/builtin.h"
47 #include "vm/exceptions.h"
48 #include "vm/global.h"
49 #include "vm/linker.h"
50 #include "vm/loader.h"
51 #include "vm/resolve.h"
52 #include "vm/options.h"
53 #include "vm/statistics.h"
54 #include "vm/stringlocal.h"
55 #include "vm/tables.h"
56 #include "vm/jit/asmpart.h"
57 #include "vm/jit/jit.h"
58 #include "vm/jit/parse.h"
59 #include "vm/jit/patcher.h"
60 #include "vm/jit/inline/parseRT.h"
61 #include "vm/jit/inline/parseXTA.h"
62 #include "vm/jit/inline/inline.h"
63 #include "vm/jit/loop/loop.h"
64 #include "vm/jit/inline/parseRTprint.h"
69 bool DEBUG4 = false; /*opcodes for parse.c*/
73 #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);
74 #define debug_writebranch1
76 /*******************************************************************************
78 function 'parse' scans the JavaVM code and generates intermediate code
80 During parsing the block index table is used to store at bit pos 0
81 a flag which marks basic block starts and at position 1 to 31 the
82 intermediate instruction index. After parsing the block index table
83 is scanned, for marked positions a block is generated and the block
84 number is stored in the block index table.
86 *******************************************************************************/
88 static exceptiontable* fillextable(methodinfo *m,
89 exceptiontable* extable, exceptiontable *raw_extable,
90 int exceptiontablelength,
91 int *label_index, int *block_count,
92 t_inlining_globals *inline_env)
94 int b_count, p, src, insertBlock;
96 if (exceptiontablelength == 0)
99 /*if (m->exceptiontablelength > 0) {
101 printf("m->exceptiontablelength=%i\n",m->exceptiontablelength);
102 panic("exceptiontablelength > 0");
105 b_count = *block_count;
107 for (src = exceptiontablelength-1; src >=0; src--) {
108 /* printf("Excepiont table index: %d\n",i); */
109 p = raw_extable[src].startpc;
110 if (label_index != NULL) p = label_index[p];
111 extable->startpc = p;
115 /*** 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)]);
116 fflush(stdout); } ***/
117 p = raw_extable[src].endpc; /* see JVM Spec 4.7.3 */
118 if (p <= raw_extable[src].startpc)
119 panic("Invalid exception handler range");
121 if (p >inline_env->method->jcodelength) {
122 panic("Invalid exception handler end is after code end");
124 if (p<inline_env->method->jcodelength) insertBlock=1; else insertBlock=0;
125 /*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
126 printf("%s:fillextab: endpc:%ld\n",m->name->text,p);*/
127 if (label_index != NULL) p = label_index[p];
130 /*if (p < inline_env->method->jcodelength) {
132 if (insertBlock) block_insert(p);
134 p = raw_extable[src].handlerpc;
135 if (label_index != NULL) p = label_index[p];
136 extable->handlerpc = p;
140 extable->catchtype = raw_extable[src].catchtype;
141 extable->next = NULL;
142 extable->down = &extable[1];
146 *block_count = b_count;
147 return extable; /*&extable[i];*/ /* return the next free xtable* */
152 methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env)
154 int p; /* java instruction counter */
155 int nextp; /* start of next java instruction */
156 int opcode; /* java opcode */
157 int i; /* temporary for different uses (ctrs)*/
158 int ipc = 0; /* intermediate instruction counter */
159 int b_count = 0; /* basic block counter */
160 int s_count = 0; /* stack element counter */
161 bool blockend = false; /* true if basic block end has been reached */
162 bool iswide = false; /* true if last instruction was a wide*/
163 instruction *iptr; /* current ptr into instruction array */
164 int gp; /* global java instruction counter */
165 /* inlining info for current method */
167 inlining_methodinfo *inlinfo = inline_env->inlining_rootinfo;
168 inlining_methodinfo *tmpinlinf;
169 int nextgp = -1; /* start of next method to be inlined */
170 int *label_index = NULL; /* label redirection table */
171 int firstlocal = 0; /* first local variable of method */
172 exceptiontable* nextex; /* points next free entry in extable */
173 u1 *instructionstart; /* 1 for pcs which are valid instr. starts */
179 u2 skipBasicBlockChange;
181 METHINFOt(m,"\nPARSING: ",DEBUG4);
182 if ((opt_rt) || (opt_xta)) {
185 if (opt_rt) Missed = rtMissed;
186 if (opt_xta) Missed = xtaMissed;
188 if (m->methodUsed != USED) {
190 printf(" rta/xta missed: "); fflush(stdout);
191 METHINFO(m,opt_verbose);
193 if ( (Missed = fopen("Missed", "a")) == NULL) {
194 printf("CACAO - rt/xtaMissed file: cant open file to write append \n");
197 utf_fprint(Missed,m->class->name);
198 fprintf(Missed," "); fflush(Missed);
199 utf_fprint(Missed,m->name);
200 fprintf(Missed," "); fflush(Missed);
201 utf_fprint(Missed,m->descriptor);
202 fprintf(Missed,"\n"); fflush(Missed);
210 label_index = inlinfo->label_index;
211 m->maxstack = inline_env->cummaxstack;
212 /*JOWENN m->exceptiontablelength = inline_env->cumextablelength;*/
213 tmpinlinf = (inlining_methodinfo*)
214 list_first(inlinfo->inlinedmethods);
215 if (tmpinlinf != NULL) nextgp = tmpinlinf->startgp;
218 /**** static analysis has to be called before inlining
219 which has to be called before reg_set
220 which has to be called before parse (or ???)
221 will check if method being parsed was analysed here
222 if (opt_xta && opt_verbose) {
224 printf("XTA requested, not available\n");
226 if (opt_vta && opt_verbose)
227 printf("VTA requested, not yet implemented\n");
230 /* allocate instruction array and block index table */
232 /* 1 additional for end ipc * # cum inline methods*/
234 m->basicblockindex = DMNEW(s4, inline_env->cumjcodelength + inline_env->cummethods);
235 memset(m->basicblockindex, 0, sizeof(s4) * (inline_env->cumjcodelength + inline_env->cummethods));
237 instructionstart = DMNEW(u1, inline_env->cumjcodelength + inline_env->cummethods);
238 memset(instructionstart, 0, sizeof(u1) * (inline_env->cumjcodelength + inline_env->cummethods));
240 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
241 /* additional MONITOREXITS are reached by branches which are 3 bytes */
243 iptr = m->instructions = DMNEW(instruction, inline_env->cumjcodelength + 5);
245 /* Zero the intermediate instructions array so we don't have any
246 * invalid pointers in it if we cannot finish analyse_stack(). */
248 memset(iptr, 0, sizeof(instruction) * (inline_env->cumjcodelength + 5));
250 /* compute branch targets of exception table */
252 if (m->exceptiontable == NULL) {
253 printf("m->exceptiontable=NULL\n");fflush(stdout);
256 printf("m->exceptiontable != NULL\n");fflush(stdout);
258 printf("m->exceptiontablelength=%i, inline_env->method->exceptiontablelength=%i,inline_env->cumextablelength=%i\n",
259 m->exceptiontablelength, inline_env->method->exceptiontablelength,inline_env->cumextablelength);
262 if (m->exceptiontablelength > 0)
263 m->exceptiontable = DMNEW(exceptiontable, m->exceptiontablelength + 1);
266 nextex = fillextable(m,
267 &(cd->exceptiontable[cd->exceptiontablelength-1]), m->exceptiontable, m->exceptiontablelength,
268 label_index, &b_count, inline_env);
269 s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */
271 #if defined(USE_THREADS)
272 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
273 m->isleafmethod = false;
274 inline_env->method->isleafmethod = false;
278 /* scan all java instructions */
282 if (m->linenumbercount == 0) {
284 /*printf("linenumber count == 0\n");*/
286 linepcchange = m->linenumbers[0].start_pc;
289 skipBasicBlockChange=0;
290 for (p = 0, gp = 0; p < inline_env->method->jcodelength; gp += (nextp - p), p = nextp) {
292 /* DEBUG */ if (DEBUG==true) printf("----- p:%d gp:%d\n",p,gp);
294 /* mark this position as a valid instruction start */
296 instructionstart[gp] = 1;
297 /*log_text("new start of instruction");*/
298 /*printf ("%s, linepcchange %d,p %d\n",inline_env->method->name->text,linepcchange,p);*/
299 if (linepcchange==p) {
300 if (inline_env->method->linenumbercount > lineindex) {
301 currentline = inline_env->method->linenumbers[lineindex].line_number;
303 if (lineindex < inline_env->method->linenumbercount)
304 linepcchange = inline_env->method->linenumbers[lineindex].start_pc;
305 /*printf("Line number changed to: %ld\n",currentline);*/
311 if ((useinlining) && (gp == nextgp)) {
313 bool *readonly = NULL;
316 block_insert(gp); /* JJJJJJJJJJ */
318 instructionstart[gp] = 1;
319 m->basicblockindex[gp] |= (ipc << 1); /*FIXME: necessary ? */
321 opcode = code_get_u1(p,inline_env->method);
322 nextp = p += jcommandsize[opcode];
323 if (nextp > inline_env->method->jcodelength)
324 panic("Unexpected end of bytecode");
325 tmpinlinf = list_first(inlinfo->inlinedmethods);
326 firstlocal = tmpinlinf->firstlocal;
327 label_index = tmpinlinf->label_index;
328 readonly = tmpinlinf->readonly;
330 for (i=0,tptr=tmpinlinf->method->paramtypes;i<tmpinlinf->method->paramcount;i++,tptr++) {
331 if ( ((*tptr)==TYPE_LNG) ||
332 ((*tptr)==TYPE_DBL) )
338 for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) {
341 if ((i == 0) && inlineparamopt) {
342 OP1(ICMD_CLEAR_ARGREN, firstlocal);
345 if (!inlineparamopt || !readonly[i]) {
349 op = ICMD_READONLY_ARG;
353 if ( ((*tptr)==TYPE_LNG) ||
354 ((*tptr)==TYPE_DBL) )
359 OP1(op, firstlocal + argBlockIdx);
360 /* OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i); */
361 /* printf("inline argument load operation for local: %ld\n",firstlocal + tmpinlinf->method->paramcount - 1 - i); */
363 skipBasicBlockChange=1;
364 METHINFOt(inline_env->method,"BEFORE SAVE: ",DEBUG);
365 inlining_save_compiler_variables();
366 METHINFOt(inline_env->method,"AFTER SAVE: ",DEBUG);
367 inlining_set_compiler_variables(tmpinlinf);
368 METHINFOt(inline_env->method,"AFTER SET :: ",DEBUG);
369 METHINFOt(m,"\n.......Parsing (inlined): ",DEBUG);
370 METHINFO(inline_env->method,DEBUG);
372 OP1(ICMD_INLINE_START,tmpinlinf->level);
374 if (inlinfo->inlinedmethods == NULL) {
377 tmpinlinf = list_first(inlinfo->inlinedmethods);
378 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
380 if (inline_env->method->exceptiontablelength > 0)
381 nextex = fillextable(m, nextex,
382 inline_env->method->exceptiontable, inline_env->method->exceptiontablelength,
383 label_index, &b_count, inline_env);
387 opcode = code_get_u1(p,inline_env->method); /* fetch op code */
390 printf("Parse p=%i<%i<%i< opcode=<%i> %s\n",
391 p, gp, inline_env->jcodelength, opcode, opcode_names[opcode]);
393 printf("label_index[%d]=%d\n",p,label_index[p]);
396 printf("basicblockindex[gp=%i]=%i=%p ipc=%i=%p shifted ipc=%i=%p\n",
397 gp,m->basicblockindex[gp],m->basicblockindex[gp],ipc,ipc,(ipc<<1),(ipc<<1));
400 if (!skipBasicBlockChange) {
401 m->basicblockindex[gp] |= (ipc << 1); /*store intermed cnt*/
402 } else skipBasicBlockChange=0;
404 printf("basicblockindex[gp=%i]=%i=%p \n",
405 gp,m->basicblockindex[gp],m->basicblockindex[gp]);
410 block_insert(gp); /* start new block */
412 /*printf("blockend was set: new blockcount: %ld at:%ld\n",b_count,gp);*/
415 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
416 if (nextp > inline_env->method->jcodelength)
417 panic("Unexpected end of bytecode");
418 s_count += stackreq[opcode]; /* compute stack element count */
424 /* pushing constants onto the stack p */
427 LOADCONST_I(code_get_s1(p+1,inline_env->method));
431 LOADCONST_I(code_get_s2(p+1,inline_env->method));
435 i = code_get_u1(p+1,inline_env->method);
437 goto pushconstantitem;
440 i = code_get_u2(p + 1,inline_env->method);
444 if (i >= inline_env->method->class->cpcount)
445 error("Attempt to access constant outside range: %d >= %d", i, inline_env->method->class->cpcount);
447 switch (inline_env->method->class->cptags[i]) {
448 case CONSTANT_Integer:
449 LOADCONST_I(((constant_integer *) (inline_env->method->class->cpinfos[i]))->value);
452 LOADCONST_L(((constant_long *) (inline_env->method->class->cpinfos[i]))->value);
455 LOADCONST_F(((constant_float *) (inline_env->method->class->cpinfos[i]))->value);
457 case CONSTANT_Double:
458 LOADCONST_D(((constant_double *) (inline_env->method->class->cpinfos[i]))->value);
460 case CONSTANT_String:
461 LOADCONST_A(literalstring_new((utf *) (inline_env->method->class->cpinfos[i])));
463 default: panic("Invalid constant type to push");
467 case JAVA_ACONST_NULL:
478 LOADCONST_I(opcode - JAVA_ICONST_0);
483 LOADCONST_L(opcode - JAVA_LCONST_0);
489 LOADCONST_F(opcode - JAVA_FCONST_0);
494 LOADCONST_D(opcode - JAVA_DCONST_0);
497 /* loading variables onto the stack */
505 i = code_get_u1(p + 1,inline_env->method);
507 i = code_get_u2(p + 1,inline_env->method);
511 OP1LOAD(opcode, i + firstlocal);
518 OP1LOAD(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
525 OP1LOAD(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
532 OP1LOAD(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
539 OP1LOAD(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
546 OP1LOAD(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
549 /* storing stack values into local variables */
557 i = code_get_u1(p + 1,inline_env->method);
559 i = code_get_u2(p + 1,inline_env->method);
563 OP1STORE(opcode, i + firstlocal);
570 OP1STORE(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
577 OP1STORE(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
584 OP1STORE(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
591 OP1STORE(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
598 OP1STORE(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
606 i = code_get_u1(p + 1,inline_env->method);
607 v = code_get_s1(p + 2,inline_env->method);
610 i = code_get_u2(p + 1,inline_env->method);
611 v = code_get_s2(p + 3,inline_env->method);
615 INDEX_ONEWORD(i + firstlocal);
616 OP2I(opcode, i + firstlocal, v);
620 /* wider index for loading, storing and incrementing */
627 /* managing arrays ************************************************/
631 switch (code_get_s1(p + 1, inline_env->method)) {
633 BUILTIN1(BUILTIN_newarray_boolean, TYPE_ADR, currentline);
636 BUILTIN1(BUILTIN_newarray_char, TYPE_ADR, currentline);
639 BUILTIN1(BUILTIN_newarray_float, TYPE_ADR, currentline);
642 BUILTIN1(BUILTIN_newarray_double, TYPE_ADR, currentline);
645 BUILTIN1(BUILTIN_newarray_byte, TYPE_ADR, currentline);
648 BUILTIN1(BUILTIN_newarray_short, TYPE_ADR, currentline);
651 BUILTIN1(BUILTIN_newarray_int, TYPE_ADR, currentline);
654 BUILTIN1(BUILTIN_newarray_long, TYPE_ADR, currentline);
656 default: panic("Invalid array-type to create");
658 OP(ICMD_CHECKEXCEPTION);
663 i = code_get_u2(p + 1, inline_env->method);
665 classinfo *component;
666 constant_classref *compr;
667 constant_classref *cr;
670 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__)
671 compr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
673 if (!(cr = class_get_classref_multiarray_of(1, compr)))
676 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
680 LOADCONST_A_BUILTIN(c->vftbl);
681 BUILTIN2T(BUILTIN_newarray, TYPE_ADR, NULL, currentline);
684 LOADCONST_A_BUILTIN(cr);
685 BUILTIN2T(PATCHER_builtin_newarray, TYPE_ADR, cr, currentline);
689 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
691 if (!resolve_classref(inline_env->method,
692 cr,resolveEager,true,&component))
695 c = class_array_of(component,true);
698 LOADCONST_A_BUILTIN(c->vftbl);
700 BUILTIN2(BUILTIN_newarray, TYPE_ADR, currentline);
703 OP(ICMD_CHECKEXCEPTION);
706 case JAVA_MULTIANEWARRAY:
707 inline_env->method->isleafmethod = false;
708 i = code_get_u2(p + 1, inline_env->method);
710 classinfo *component;
712 constant_classref *cr;
714 s4 v = code_get_u1(p + 3, inline_env->method);
716 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__)
717 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
719 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
723 OP2AT(opcode, v, c->vftbl, NULL, currentline);
726 OP2AT(opcode, v, cr, PATCHER_builtin_multianewarray, currentline);
729 /* vftbl *arrayvftbl = */
730 /* ((classinfo *) class_getconstant(class, i, CONSTANT_Class))->vftbl; */
731 /* OP2A(opcode, v, arrayvftbl,currentline); */
734 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
736 if (!resolve_classref_or_classinfo(inline_env->method,
737 CLASSREF_OR_CLASSINFO(cr),resolveEager,true,&component))
740 arrayvftbl = component->vftbl;
741 OP2A(opcode, v, arrayvftbl, currentline);
743 /* classinfo *arrayclass = */
744 /* (classinfo *) class_getconstant(class, i, CONSTANT_Class); */
745 /* OP2A(opcode, v, arrayclass, currentline); */
768 i = p + code_get_s2(p + 1,inline_env->method);
780 i = p + code_get_s4(p + 1,inline_env->method);
786 /*printf("B6 JSR_W\t"); fflush(stdout);*/
794 i = code_get_u1(p + 1,inline_env->method);
796 i = code_get_u2(p + 1,inline_env->method);
803 if (inline_env->isinlinedmethod) {
804 OP1(ICMD_GOTO, inlinfo->stopgp);
808 OP1LOAD(opcode, i + firstlocal);
817 if (inline_env->isinlinedmethod) {
818 /* if (p==m->jcodelength-1) {*/ /* return is at end of inlined method */
822 if (nextp>inline_env->method->jcodelength-1) {
823 /* OP1(ICMD_GOTO, inlinfo->stopgp);
831 OP1(ICMD_GOTO, inlinfo->stopgp);
845 /* table jumps ********************************/
847 case JAVA_LOOKUPSWITCH:
854 nextp = ALIGN((p + 1), 4);
855 if (nextp + 8 > inline_env->method->jcodelength)
856 panic("Unexpected end of bytecode");
858 tablep = (s4 *) (inline_env->method->jcode + nextp);
861 num = code_get_u4(nextp + 4,inline_env->method);
862 tablep = DMNEW(s4, num * 2 + 2);
865 OP2A(opcode, 0, tablep,currentline);
869 j = p + code_get_s4(nextp,inline_env->method);
872 *tablep = j; /* restore for little endian */
878 /* number of pairs */
880 num = code_get_u4(nextp,inline_env->method);
885 if (nextp + 8*(num) > inline_env->method->jcodelength)
886 panic("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 panic("Unexpected end of bytecode");
930 tablep = (s4 *) (inline_env->method->jcode + nextp);
933 num = code_get_u4(nextp + 8,inline_env->method) - code_get_u4(nextp + 4,inline_env->method);
934 tablep = DMNEW(s4, num + 1 + 3);
937 OP2A(opcode, 0, tablep,currentline);
941 j = p + code_get_s4(nextp,inline_env->method);
944 *tablep = j; /* restore for little endian */
952 j = code_get_s4(nextp,inline_env->method);
953 *tablep = j; /* restore for little endian */
959 num = code_get_s4(nextp,inline_env->method);
960 *tablep = num; /* restore for little endian */
964 num -= j; /* difference of upper - lower */
966 panic("invalid TABLESWITCH: upper bound < lower bound");
968 if (nextp + 4*(num+1) > inline_env->method->jcodelength)
969 panic("Unexpected end of bytecode");
971 for (i = 0; i <= num; i++) {
972 j = p + code_get_s4(nextp,inline_env->method);
974 /*printf("TABLESWITCH: j before mapping=%ld\n",j);*/
977 *tablep = j; /* restore for little endian */
982 /*printf("TABLESWITCH: block_insert(%ld)\n",j);*/
989 /* load and store of object fields *******************/
992 BUILTIN3(BUILTIN_aastore, TYPE_VOID, currentline);
997 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__)
1001 i = code_get_u2(p + 1, inline_env->method);
1003 constant_FMIref *fr;
1004 unresolved_field *uf;
1008 fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref);
1009 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__)
1010 OP2A_NOINC(opcode, fr->parseddesc.fd->type, fr, currentline);
1012 if (!(uf = create_unresolved_field(inline_env->method->class,
1018 /* store unresolved_field pointer */
1022 /* only with -noverify, otherwise the typechecker does this */
1025 if (!resolve_field(uf, resolveLazy, &fi))
1034 if (!resolve_classref(inline_env->method,fr->classref,resolveEager,true,&frclass))
1037 fi = class_resolvefield(frclass,
1040 inline_env->method->class,
1046 OP2A(opcode, fi->type, fi, currentline);
1047 if (!fi->class->initialized) {
1048 inline_env->method->isleafmethod = false;
1055 #if !defined(__X86_64__) && !defined(__I386__) && !defined(__ALPHA__)
1058 i = code_get_u2(p + 1,inline_env->method);
1060 constant_FMIref *fr;
1064 fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref);
1065 if (!resolve_classref(inline_env->method,fr->classref,resolveEager,true,&frclass))
1068 fi = class_resolvefield(frclass,
1071 inline_env->method->class,
1077 OP2A(opcode, fi->type, fi, currentline);
1083 /* method invocation *****/
1085 case JAVA_INVOKESTATIC:
1086 i = code_get_u2(p + 1, inline_env->method);
1088 constant_FMIref *mr;
1090 unresolved_method *um;
1093 inline_env->method->isleafmethod = false;
1095 mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref);
1096 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__)
1097 OP2A_NOINC(opcode, mr->parseddesc.md->paramcount, mr, currentline);
1099 um = create_unresolved_method(inline_env->method->class,
1107 /* store the unresolved_method pointer */
1111 /* only with -noverify, otherwise the typechecker does this */
1114 if (!resolve_method(um, resolveLazy, &mi))
1121 if (!resolve_classref(inline_env->method,mr->classref,resolveEager,true,&mrclass))
1124 mi = class_resolveclassmethod(mrclass,
1127 inline_env->method->class,
1134 method_display_w_class(mi);
1135 printf("\tINVOKE STAT\n");
1138 if (!(mi->flags & ACC_STATIC)) {
1140 new_exception(string_java_lang_IncompatibleClassChangeError);
1144 method_descriptor2types(mi);
1145 OP2A(opcode, mi->paramcount, mi, currentline);
1150 case JAVA_INVOKESPECIAL:
1151 case JAVA_INVOKEVIRTUAL:
1152 i = code_get_u2(p + 1, inline_env->method);
1154 constant_FMIref *mr;
1156 unresolved_method *um;
1159 inline_env->method->isleafmethod = false;
1161 mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref);
1162 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__)
1163 OP2A_NOINC(opcode, mr->parseddesc.md->paramcount + 1, mr, currentline);
1165 um = create_unresolved_method(inline_env->method->class,
1173 /* store the unresolved_method* */
1177 /* only with -noverify, otherwise the typechecker does this */
1180 if (!resolve_method(um, resolveLazy, &mi))
1187 if (!resolve_classref(inline_env->method,mr->classref,resolveEager,true,&mrclass))
1190 mi = class_resolveclassmethod(mrclass,
1193 inline_env->method->class,
1200 method_display_w_class(mi);
1201 printf("\tINVOKE SPEC/VIRT\n");
1204 if (mi->flags & ACC_STATIC) {
1206 new_exception(string_java_lang_IncompatibleClassChangeError);
1210 method_descriptor2types(mi);
1211 OP2A(opcode, mi->paramcount, mi, currentline);
1216 case JAVA_INVOKEINTERFACE:
1217 i = code_get_u2(p + 1,inline_env->method);
1219 constant_FMIref *mr;
1222 unresolved_method *um;
1224 inline_env->method->isleafmethod = false;
1226 mr = class_getconstant(inline_env->method->class, i, CONSTANT_InterfaceMethodref);
1227 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__)
1228 OP2A_NOINC(opcode, mr->parseddesc.md->paramcount + 1, mr, currentline);
1230 um = create_unresolved_method(inline_env->method->class,
1238 /* store the unresolved_method* */
1242 /* only with -noverify, otherwise the typechecker does this */
1245 if (!resolve_method(um, resolveLazy, &mi))
1252 if (!resolve_classref(inline_env->method,mr->classref,resolveEager,true,&mrclass))
1255 mi = class_resolveinterfacemethod(mrclass,
1258 inline_env->method->class,
1263 if (mi->flags & ACC_STATIC) {
1265 new_exception(string_java_lang_IncompatibleClassChangeError);
1270 method_display_w_class(mi);
1271 printf("\tINVOKE INTERFACE\n");
1274 method_descriptor2types(mi);
1275 OP2A(opcode, mi->paramcount, mi, currentline);
1280 /* miscellaneous object operations *******/
1284 constant_classref *cr;
1287 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__)
1288 i = code_get_u2(p + 1, inline_env->method);
1289 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1291 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &cls))
1294 /* <clinit> can throw an exception over native code */
1296 if (cls && cls->initialized) {
1297 LOADCONST_A_BUILTIN(cls);
1298 BUILTIN1T(BUILTIN_new, TYPE_ADR, NULL, currentline);
1301 LOADCONST_A_BUILTIN(cr);
1302 BUILTIN1T(PATCHER_builtin_new, TYPE_ADR, cr, currentline);
1306 OP(ICMD_CHECKEXCEPTION);
1308 i = code_get_u2(p + 1,inline_env->method);
1309 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1310 if (!resolve_classref(inline_env->method,cr,resolveEager,true,&cls))
1312 LOADCONST_A_BUILTIN(cls);
1314 BUILTIN1(BUILTIN_new, TYPE_ADR, currentline);
1315 OP(ICMD_CHECKEXCEPTION);
1320 case JAVA_CHECKCAST:
1321 i = code_get_u2(p + 1, inline_env->method);
1323 constant_classref *cr;
1326 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1328 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__)
1329 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &cls))
1332 if (cr->name->text[0] == '[') {
1333 /* array type cast-check */
1335 LOADCONST_A_BUILTIN(cls->vftbl);
1336 BUILTIN2T(BUILTIN_checkarraycast, TYPE_ADR, NULL, currentline);
1339 LOADCONST_A_BUILTIN(cr);
1340 BUILTIN2T(PATCHER_builtin_checkarraycast, TYPE_ADR, cr, currentline);
1345 /* object type cast-check */
1346 OP2AT(opcode, 1, cls, cr, currentline);
1349 if (!resolve_classref(inline_env->method,
1350 cr,resolveEager,true,&cls))
1353 if (cls->vftbl->arraydesc) {
1354 /* array type cast-check */
1355 LOADCONST_A_BUILTIN(cls->vftbl);
1357 BUILTIN2(BUILTIN_checkarraycast, TYPE_ADR,currentline);
1359 } else { /* object type cast-check */
1361 + LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
1363 + BUILTIN2(BUILTIN_checkcast, TYPE_ADR,currentline);
1365 OP2A(opcode, 1, cls, currentline);
1371 case JAVA_INSTANCEOF:
1372 i = code_get_u2(p + 1,inline_env->method);
1374 constant_classref *cr;
1377 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1379 #if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__)
1380 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &cls))
1383 if (cr->name->text[0] == '[') {
1384 /* array type cast-check */
1386 LOADCONST_A_BUILTIN(cls->vftbl);
1387 BUILTIN2T(BUILTIN_arrayinstanceof, TYPE_INT, NULL, currentline);
1390 LOADCONST_A_BUILTIN(cr);
1391 BUILTIN2T(PATCHER_builtin_arrayinstanceof, TYPE_INT, cr, currentline);
1396 /* object type cast-check */
1397 OP2AT(opcode, 1, cls, cr, currentline);
1400 if (!resolve_classref(inline_env->method,
1401 cr,resolveEager,true,&cls))
1404 if (cls->vftbl->arraydesc) {
1405 /* array type cast-check */
1406 LOADCONST_A_BUILTIN(cls->vftbl);
1408 BUILTIN2(BUILTIN_arrayinstanceof, TYPE_INT, currentline);
1410 else { /* object type cast-check */
1412 LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
1414 BUILTIN2(BUILTIN_instanceof, TYPE_INT,currentline);
1416 OP2A(opcode, 1, cls, currentline);
1422 case JAVA_MONITORENTER:
1423 #if defined(USE_THREADS)
1426 BUILTIN1(BUILTIN_monitorenter, TYPE_VOID, currentline);
1435 case JAVA_MONITOREXIT:
1436 #if defined(USE_THREADS)
1438 BUILTIN1(BUILTIN_monitorexit, TYPE_VOID, currentline);
1446 /* any other basic operation **************************************/
1465 #if defined(__I386__)
1468 BUILTIN2(BUILTIN_frem, TYPE_FLOAT,currentline);
1473 #if defined(__I386__)
1476 BUILTIN2(BUILTIN_drem, TYPE_DOUBLE,currentline);
1481 #if defined(__ALPHA__)
1483 BUILTIN1(BUILTIN_f2i, TYPE_INT,currentline);
1492 #if defined(__ALPHA__)
1494 BUILTIN1(BUILTIN_f2l, TYPE_LONG,currentline);
1503 #if defined(__ALPHA__)
1505 BUILTIN1(BUILTIN_d2i, TYPE_INT,currentline);
1514 #if defined(__ALPHA__)
1516 BUILTIN1(BUILTIN_d2l, TYPE_LONG,currentline);
1524 case JAVA_BREAKPOINT:
1526 new_verifyerror(m, "Quick instructions shouldn't appear yet.");
1529 case 204: /* unused opcode */
1581 printf("Illegal opcode %d at instr %d\n", opcode, ipc);
1582 panic("Illegal opcode encountered");
1591 /* If WIDE was used correctly, iswide should have been reset by now. */
1592 if (iswide && opcode != JAVA_WIDE)
1593 panic("Illegal instruction: WIDE before incompatible opcode");
1597 /* if (inline_env->isinlinedmethod && p == inline_env->method->jcodelength - 1) { */ /* end of an inlined method */
1598 if (inline_env->isinlinedmethod && (nextp >= inline_env->method->jcodelength) ) { /* end of an inlined method */
1599 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1600 gp = inlinfo->stopgp;
1601 inlining_restore_compiler_variables();
1602 OP(ICMD_INLINE_END);
1603 /*label_index = inlinfo->label_index;*/
1605 METHINFOt(inline_env->method,"AFTER RESTORE : ",DEBUG);
1606 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1607 if (inlinfo->inlinedmethods == NULL) { /* JJJJ */
1610 tmpinlinf = list_first(inlinfo->inlinedmethods);
1611 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1613 /* printf("nextpgp: %d\n", nextgp); */
1614 label_index=inlinfo->label_index;
1615 firstlocal = inlinfo->firstlocal;
1621 if (p != m->jcodelength) {
1622 printf("p (%d) != m->jcodelength (%d)\n",p,m->jcodelength);
1623 panic("Command-sequence crosses code-boundary");
1626 *exceptionptr = new_verifyerror(m, "Falling off the end of the code");
1630 /* adjust block count if target 0 is not first intermediate instruction */
1632 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1))
1635 /* copy local to method variables */
1637 m->instructioncount = ipc;
1638 m->basicblockcount = b_count;
1639 m->stackcount = s_count + m->basicblockcount * m->maxstack;
1641 /* allocate stack table */
1643 m->stack = DMNEW(stackelement, m->stackcount);
1648 bptr = m->basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1653 /* additional block if target 0 is not first intermediate instruction */
1655 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) {
1656 bptr->iinstr = m->instructions;
1659 bptr->type = BBTYPE_STD;
1660 bptr->branchrefs = NULL;
1661 bptr->pre_count = 0;
1662 bptr->debug_nr = m->c_debug_nr++;
1665 (bptr - 1)->next = bptr;
1668 /* allocate blocks */
1670 for (p = 0; p < inline_env->cumjcodelength; p++) {
1671 /* for (p = 0; p < m->jcodelength; p++) { */
1672 if (m->basicblockindex[p] & 1) {
1673 /* check if this block starts at the beginning of an instruction */
1674 if (!instructionstart[p]) {
1675 printf("Basic Block beginn: %d\n",p);
1676 panic("Branch into middle of instruction");
1678 /* allocate the block */
1679 bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
1680 bptr->debug_nr = m->c_debug_nr++;
1682 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1686 bptr->type = BBTYPE_STD;
1687 bptr->branchrefs = NULL;
1688 m->basicblockindex[p] = b_count;
1689 bptr->pre_count = 0;
1692 (bptr - 1)->next = bptr;
1696 /* allocate additional block at end */
1698 bptr->instack = bptr->outstack = NULL;
1699 bptr->indepth = bptr->outdepth = 0;
1700 bptr->iinstr = NULL;
1701 (bptr - 1)->icount = (m->instructions + m->instructioncount) - (bptr - 1)->iinstr;
1706 bptr->type = BBTYPE_STD;
1707 bptr->branchrefs = NULL;
1708 bptr->pre_count = 0;
1709 bptr->debug_nr = m->c_debug_nr++;
1710 (bptr - 1)->next = bptr;
1713 if (cd->exceptiontablelength > 0) {
1714 cd->exceptiontable[cd->exceptiontablelength - 1].down = NULL;
1717 for (i = 0; i < cd->exceptiontablelength; ++i) {
1718 p = cd->exceptiontable[i].startpc;
1719 cd->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1721 p = cd->exceptiontable[i].endpc;
1722 cd->exceptiontable[i].end = (p == inline_env->method->jcodelength) ? (m->basicblocks + m->basicblockcount /*+ 1*/) : (m->basicblocks + m->basicblockindex[p]);
1724 p = cd->exceptiontable[i].handlerpc;
1725 cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1729 if (useinlining) inlining_cleanup(inline_env);
1731 /* just return methodinfo* to signal everything was ok */
1738 * These are local overrides for various environment variables in Emacs.
1739 * Please do not remove this and leave it at the end of the file, where
1740 * Emacs will automagically detect them.
1741 * ---------------------------------------------------------------------
1744 * indent-tabs-mode: t