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 2263 2005-04-11 09:56:52Z 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/inline/parseRT.h"
60 #include "vm/jit/inline/parseXTA.h"
61 #include "vm/jit/inline/inline.h"
62 #include "vm/jit/loop/loop.h"
63 #include "vm/jit/inline/parseRTprint.h"
68 bool DEBUG4 = false; /*opcodes for parse.c*/
72 #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);
73 #define debug_writebranch1
75 /*******************************************************************************
77 function 'parse' scans the JavaVM code and generates intermediate code
79 During parsing the block index table is used to store at bit pos 0
80 a flag which marks basic block starts and at position 1 to 31 the
81 intermediate instruction index. After parsing the block index table
82 is scanned, for marked positions a block is generated and the block
83 number is stored in the block index table.
85 *******************************************************************************/
87 static exceptiontable* fillextable(methodinfo *m,
88 exceptiontable* extable, exceptiontable *raw_extable,
89 int exceptiontablelength,
90 int *label_index, int *block_count,
91 t_inlining_globals *inline_env)
93 int b_count, p, src, insertBlock;
95 if (exceptiontablelength == 0)
98 /*if (m->exceptiontablelength > 0) {
100 printf("m->exceptiontablelength=%i\n",m->exceptiontablelength);
101 panic("exceptiontablelength > 0");
104 b_count = *block_count;
106 for (src = exceptiontablelength-1; src >=0; src--) {
107 /* printf("Excepiont table index: %d\n",i); */
108 p = raw_extable[src].startpc;
109 if (label_index != NULL) p = label_index[p];
110 extable->startpc = p;
114 /*** 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)]);
115 fflush(stdout); } ***/
116 p = raw_extable[src].endpc; /* see JVM Spec 4.7.3 */
117 if (p <= raw_extable[src].startpc)
118 panic("Invalid exception handler range");
120 if (p >inline_env->method->jcodelength) {
121 panic("Invalid exception handler end is after code end");
123 if (p<inline_env->method->jcodelength) insertBlock=1; else insertBlock=0;
124 /*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
125 printf("%s:fillextab: endpc:%ld\n",m->name->text,p);*/
126 if (label_index != NULL) p = label_index[p];
129 /*if (p < inline_env->method->jcodelength) {
131 if (insertBlock) block_insert(p);
133 p = raw_extable[src].handlerpc;
134 if (label_index != NULL) p = label_index[p];
135 extable->handlerpc = p;
139 extable->catchtype = raw_extable[src].catchtype;
140 extable->next = NULL;
141 extable->down = &extable[1];
145 *block_count = b_count;
146 return extable; /*&extable[i];*/ /* return the next free xtable* */
151 methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env)
153 int p; /* java instruction counter */
154 int nextp; /* start of next java instruction */
155 int opcode; /* java opcode */
156 int i; /* temporary for different uses (ctrs)*/
157 int ipc = 0; /* intermediate instruction counter */
158 int b_count = 0; /* basic block counter */
159 int s_count = 0; /* stack element counter */
160 bool blockend = false; /* true if basic block end has been reached */
161 bool iswide = false; /* true if last instruction was a wide*/
162 instruction *iptr; /* current ptr into instruction array */
163 int gp; /* global java instruction counter */
164 /* inlining info for current method */
166 inlining_methodinfo *inlinfo = inline_env->inlining_rootinfo;
167 inlining_methodinfo *tmpinlinf;
168 int nextgp = -1; /* start of next method to be inlined */
169 int *label_index = NULL; /* label redirection table */
170 int firstlocal = 0; /* first local variable of method */
171 exceptiontable* nextex; /* points next free entry in extable */
172 u1 *instructionstart; /* 1 for pcs which are valid instr. starts */
178 u2 skipBasicBlockChange;
180 METHINFOt(m,"\nPARSING: ",DEBUG4);
181 if ((opt_rt) || (opt_xta)) {
184 if (opt_rt) Missed = rtMissed;
185 if (opt_xta) Missed = xtaMissed;
187 if (m->methodUsed != USED) {
189 printf(" rta/xta missed: "); fflush(stdout);
190 METHINFO(m,opt_verbose);
192 if ( (Missed = fopen("Missed", "a")) == NULL) {
193 printf("CACAO - rt/xtaMissed file: cant open file to write append \n");
196 utf_fprint(Missed,m->class->name);
197 fprintf(Missed," "); fflush(Missed);
198 utf_fprint(Missed,m->name);
199 fprintf(Missed," "); fflush(Missed);
200 utf_fprint(Missed,m->descriptor);
201 fprintf(Missed,"\n"); fflush(Missed);
209 label_index = inlinfo->label_index;
210 m->maxstack = inline_env->cummaxstack;
211 /*JOWENN m->exceptiontablelength = inline_env->cumextablelength;*/
212 tmpinlinf = (inlining_methodinfo*)
213 list_first(inlinfo->inlinedmethods);
214 if (tmpinlinf != NULL) nextgp = tmpinlinf->startgp;
217 /**** static analysis has to be called before inlining
218 which has to be called before reg_set
219 which has to be called before parse (or ???)
220 will check if method being parsed was analysed here
221 if (opt_xta && opt_verbose) {
223 printf("XTA requested, not available\n");
225 if (opt_vta && opt_verbose)
226 printf("VTA requested, not yet implemented\n");
229 /* allocate instruction array and block index table */
231 /* 1 additional for end ipc * # cum inline methods*/
233 m->basicblockindex = DMNEW(s4, inline_env->cumjcodelength + inline_env->cummethods);
234 memset(m->basicblockindex, 0, sizeof(s4) * (inline_env->cumjcodelength + inline_env->cummethods));
236 instructionstart = DMNEW(u1, inline_env->cumjcodelength + inline_env->cummethods);
237 memset(instructionstart, 0, sizeof(u1) * (inline_env->cumjcodelength + inline_env->cummethods));
239 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
240 /* additional MONITOREXITS are reached by branches which are 3 bytes */
242 iptr = m->instructions = DMNEW(instruction, inline_env->cumjcodelength + 5);
244 /* Zero the intermediate instructions array so we don't have any
245 * invalid pointers in it if we cannot finish analyse_stack(). */
247 memset(iptr, 0, sizeof(instruction) * (inline_env->cumjcodelength + 5));
249 /* compute branch targets of exception table */
251 if (m->exceptiontable == NULL) {
252 printf("m->exceptiontable=NULL\n");fflush(stdout);
255 printf("m->exceptiontable != NULL\n");fflush(stdout);
257 printf("m->exceptiontablelength=%i, inline_env->method->exceptiontablelength=%i,inline_env->cumextablelength=%i\n",
258 m->exceptiontablelength, inline_env->method->exceptiontablelength,inline_env->cumextablelength);
261 if (m->exceptiontablelength > 0)
262 m->exceptiontable = DMNEW(exceptiontable, m->exceptiontablelength + 1);
265 nextex = fillextable(m,
266 &(cd->exceptiontable[cd->exceptiontablelength-1]), m->exceptiontable, m->exceptiontablelength,
267 label_index, &b_count, inline_env);
268 s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */
270 #if defined(USE_THREADS)
271 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
272 m->isleafmethod = false;
273 inline_env->method->isleafmethod = false;
277 /* scan all java instructions */
281 if (m->linenumbercount == 0) {
285 linepcchange = m->linenumbers[0].start_pc;
288 skipBasicBlockChange=0;
289 for (p = 0, gp = 0; p < inline_env->method->jcodelength; gp += (nextp - p), p = nextp) {
291 /* DEBUG */ if (DEBUG==true) printf("----- p:%d gp:%d\n",p,gp);
293 /* mark this position as a valid instruction start */
295 instructionstart[gp] = 1;
296 /*log_text("new start of instruction");*/
297 if (linepcchange==p) {
298 if (inline_env->method->linenumbercount > lineindex) {
299 currentline = inline_env->method->linenumbers[lineindex].line_number;
301 if (lineindex < inline_env->method->linenumbercount)
302 linepcchange = inline_env->method->linenumbers[lineindex].start_pc;
303 /*printf("Line number changed to: %ld\n",currentline);*/
309 if ((useinlining) && (gp == nextgp)) {
311 bool *readonly = NULL;
314 block_insert(gp); /* JJJJJJJJJJ */
316 instructionstart[gp] = 1;
317 m->basicblockindex[gp] |= (ipc << 1); /*FIXME: necessary ? */
319 opcode = code_get_u1(p,inline_env->method);
320 nextp = p += jcommandsize[opcode];
321 if (nextp > inline_env->method->jcodelength)
322 panic("Unexpected end of bytecode");
323 tmpinlinf = list_first(inlinfo->inlinedmethods);
324 firstlocal = tmpinlinf->firstlocal;
325 label_index = tmpinlinf->label_index;
326 readonly = tmpinlinf->readonly;
328 for (i=0,tptr=tmpinlinf->method->paramtypes;i<tmpinlinf->method->paramcount;i++,tptr++) {
329 if ( ((*tptr)==TYPE_LNG) ||
330 ((*tptr)==TYPE_DBL) )
336 for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) {
339 if ((i == 0) && inlineparamopt) {
340 OP1(ICMD_CLEAR_ARGREN, firstlocal);
343 if (!inlineparamopt || !readonly[i]) {
347 op = ICMD_READONLY_ARG;
351 if ( ((*tptr)==TYPE_LNG) ||
352 ((*tptr)==TYPE_DBL) )
357 OP1(op, firstlocal + argBlockIdx);
358 /* OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i); */
359 /* printf("inline argument load operation for local: %ld\n",firstlocal + tmpinlinf->method->paramcount - 1 - i); */
361 skipBasicBlockChange=1;
362 METHINFOt(inline_env->method,"BEFORE SAVE: ",DEBUG);
363 inlining_save_compiler_variables();
364 METHINFOt(inline_env->method,"AFTER SAVE: ",DEBUG);
365 inlining_set_compiler_variables(tmpinlinf);
366 METHINFOt(inline_env->method,"AFTER SET :: ",DEBUG);
367 METHINFOt(m,"\n.......Parsing (inlined): ",DEBUG);
368 METHINFO(inline_env->method,DEBUG);
370 OP1(ICMD_INLINE_START,tmpinlinf->level);
372 if (inlinfo->inlinedmethods == NULL) {
375 tmpinlinf = list_first(inlinfo->inlinedmethods);
376 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
378 if (inline_env->method->exceptiontablelength > 0)
379 nextex = fillextable(m, nextex,
380 inline_env->method->exceptiontable, inline_env->method->exceptiontablelength,
381 label_index, &b_count, inline_env);
385 opcode = code_get_u1(p,inline_env->method); /* fetch op code */
388 printf("Parse p=%i<%i<%i< opcode=<%i> %s\n",
389 p, gp, inline_env->jcodelength, opcode, opcode_names[opcode]);
391 printf("label_index[%d]=%d\n",p,label_index[p]);
394 printf("basicblockindex[gp=%i]=%i=%p ipc=%i=%p shifted ipc=%i=%p\n",
395 gp,m->basicblockindex[gp],m->basicblockindex[gp],ipc,ipc,(ipc<<1),(ipc<<1));
398 if (!skipBasicBlockChange) {
399 m->basicblockindex[gp] |= (ipc << 1); /*store intermed cnt*/
400 } else skipBasicBlockChange=0;
402 printf("basicblockindex[gp=%i]=%i=%p \n",
403 gp,m->basicblockindex[gp],m->basicblockindex[gp]);
408 block_insert(gp); /* start new block */
410 /*printf("blockend was set: new blockcount: %ld at:%ld\n",b_count,gp);*/
413 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
414 if (nextp > inline_env->method->jcodelength)
415 panic("Unexpected end of bytecode");
416 s_count += stackreq[opcode]; /* compute stack element count */
422 /* pushing constants onto the stack p */
425 LOADCONST_I(code_get_s1(p+1,inline_env->method));
429 LOADCONST_I(code_get_s2(p+1,inline_env->method));
433 i = code_get_u1(p+1,inline_env->method);
435 goto pushconstantitem;
438 i = code_get_u2(p + 1,inline_env->method);
442 if (i >= inline_env->method->class->cpcount)
443 error("Attempt to access constant outside range: %d >= %d", i, inline_env->method->class->cpcount);
445 switch (inline_env->method->class->cptags[i]) {
446 case CONSTANT_Integer:
447 LOADCONST_I(((constant_integer *) (inline_env->method->class->cpinfos[i]))->value);
450 LOADCONST_L(((constant_long *) (inline_env->method->class->cpinfos[i]))->value);
453 LOADCONST_F(((constant_float *) (inline_env->method->class->cpinfos[i]))->value);
455 case CONSTANT_Double:
456 LOADCONST_D(((constant_double *) (inline_env->method->class->cpinfos[i]))->value);
458 case CONSTANT_String:
459 LOADCONST_A(literalstring_new((utf *) (inline_env->method->class->cpinfos[i])));
461 default: panic("Invalid constant type to push");
465 case JAVA_ACONST_NULL:
476 LOADCONST_I(opcode - JAVA_ICONST_0);
481 LOADCONST_L(opcode - JAVA_LCONST_0);
487 LOADCONST_F(opcode - JAVA_FCONST_0);
492 LOADCONST_D(opcode - JAVA_DCONST_0);
495 /* loading variables onto the stack */
503 i = code_get_u1(p + 1,inline_env->method);
505 i = code_get_u2(p + 1,inline_env->method);
509 OP1LOAD(opcode, i + firstlocal);
516 OP1LOAD(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
523 OP1LOAD(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
530 OP1LOAD(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
537 OP1LOAD(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
544 OP1LOAD(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
547 /* storing stack values into local variables */
555 i = code_get_u1(p + 1,inline_env->method);
557 i = code_get_u2(p + 1,inline_env->method);
561 OP1STORE(opcode, i + firstlocal);
568 OP1STORE(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
575 OP1STORE(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
582 OP1STORE(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
589 OP1STORE(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
596 OP1STORE(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
604 i = code_get_u1(p + 1,inline_env->method);
605 v = code_get_s1(p + 2,inline_env->method);
608 i = code_get_u2(p + 1,inline_env->method);
609 v = code_get_s2(p + 3,inline_env->method);
613 INDEX_ONEWORD(i + firstlocal);
614 OP2I(opcode, i + firstlocal, v);
618 /* wider index for loading, storing and incrementing */
625 /* managing arrays ************************************************/
629 switch (code_get_s1(p + 1,inline_env->method)) {
631 BUILTIN1(BUILTIN_newarray_boolean, TYPE_ADR,currentline);
634 BUILTIN1(BUILTIN_newarray_char, TYPE_ADR,currentline);
637 BUILTIN1(BUILTIN_newarray_float, TYPE_ADR,currentline);
640 BUILTIN1(BUILTIN_newarray_double, TYPE_ADR,currentline);
643 BUILTIN1(BUILTIN_newarray_byte, TYPE_ADR,currentline);
646 BUILTIN1(BUILTIN_newarray_short, TYPE_ADR,currentline);
649 BUILTIN1(BUILTIN_newarray_int, TYPE_ADR,currentline);
652 BUILTIN1(BUILTIN_newarray_long, TYPE_ADR,currentline);
654 default: panic("Invalid array-type to create");
656 OP(ICMD_CHECKEXCEPTION);
661 i = code_get_u2(p + 1,inline_env->method);
663 classinfo *component;
664 constant_classref *compr;
665 constant_classref *cr;
668 #if defined(__X86_64__)
669 compr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
671 if (!(cr = class_get_classref_multiarray_of(1, compr)))
674 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
678 LOADCONST_A_BUILTIN(c->vftbl);
679 BUILTIN2(BUILTIN_newarray, TYPE_ADR, currentline);
682 LOADCONST_A_BUILTIN(cr);
683 BUILTIN2(asm_BUILTIN_newarray, TYPE_ADR, currentline);
687 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
689 if (!resolve_classref(inline_env->method,
690 cr,resolveEager,true,&component))
693 c = class_array_of(component,true);
696 LOADCONST_A_BUILTIN(c->vftbl);
698 BUILTIN2(BUILTIN_newarray, TYPE_ADR, currentline);
701 OP(ICMD_CHECKEXCEPTION);
704 case JAVA_MULTIANEWARRAY:
705 inline_env->method->isleafmethod = false;
706 i = code_get_u2(p + 1, inline_env->method);
708 classinfo *component;
710 constant_classref *cr;
712 s4 v = code_get_u1(p + 3, inline_env->method);
714 #if defined(__X86_64__)
715 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
717 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &c))
721 OP2AT(opcode, v, c->vftbl, BUILTIN_nmultianewarray, currentline);
724 OP2AT(opcode, v, cr, asm_BUILTIN_multianewarray, currentline);
727 /* vftbl *arrayvftbl = */
728 /* ((classinfo *) class_getconstant(class, i, CONSTANT_Class))->vftbl; */
729 /* OP2A(opcode, v, arrayvftbl,currentline); */
732 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
734 if (!resolve_classref_or_classinfo(inline_env->method,
735 CLASSREF_OR_CLASSINFO(cr),resolveEager,true,&component))
738 arrayvftbl = component->vftbl;
739 OP2A(opcode, v, arrayvftbl, currentline);
741 /* classinfo *arrayclass = */
742 /* (classinfo *) class_getconstant(class, i, CONSTANT_Class); */
743 /* OP2A(opcode, v, arrayclass, currentline); */
766 i = p + code_get_s2(p + 1,inline_env->method);
778 i = p + code_get_s4(p + 1,inline_env->method);
784 /*printf("B6 JSR_W\t"); fflush(stdout);*/
792 i = code_get_u1(p + 1,inline_env->method);
794 i = code_get_u2(p + 1,inline_env->method);
801 if (inline_env->isinlinedmethod) {
802 OP1(ICMD_GOTO, inlinfo->stopgp);
806 OP1LOAD(opcode, i + firstlocal);
815 if (inline_env->isinlinedmethod) {
816 /* if (p==m->jcodelength-1) {*/ /* return is at end of inlined method */
820 if (nextp>inline_env->method->jcodelength-1) {
821 /* OP1(ICMD_GOTO, inlinfo->stopgp);
829 OP1(ICMD_GOTO, inlinfo->stopgp);
843 /* table jumps ********************************/
845 case JAVA_LOOKUPSWITCH:
852 nextp = ALIGN((p + 1), 4);
853 if (nextp + 8 > inline_env->method->jcodelength)
854 panic("Unexpected end of bytecode");
856 tablep = (s4 *) (inline_env->method->jcode + nextp);
859 num = code_get_u4(nextp + 4,inline_env->method);
860 tablep = DMNEW(s4, num * 2 + 2);
863 OP2A(opcode, 0, tablep,currentline);
867 j = p + code_get_s4(nextp,inline_env->method);
870 *tablep = j; /* restore for little endian */
876 /* number of pairs */
878 num = code_get_u4(nextp,inline_env->method);
883 if (nextp + 8*(num) > inline_env->method->jcodelength)
884 panic("Unexpected end of bytecode");
886 for (i = 0; i < num; i++) {
889 j = code_get_s4(nextp,inline_env->method);
890 *tablep = j; /* restore for little endian */
894 /* check if the lookup table is sorted correctly */
896 if (i && (j <= prevvalue)) {
897 *exceptionptr = new_verifyerror(m, "Unsorted lookup switch");
904 j = p + code_get_s4(nextp,inline_env->method);
907 *tablep = j; /* restore for little endian */
918 case JAVA_TABLESWITCH:
924 nextp = ALIGN((p + 1), 4);
925 if (nextp + 12 > inline_env->method->jcodelength)
926 panic("Unexpected end of bytecode");
928 tablep = (s4 *) (inline_env->method->jcode + nextp);
931 num = code_get_u4(nextp + 8,inline_env->method) - code_get_u4(nextp + 4,inline_env->method);
932 tablep = DMNEW(s4, num + 1 + 3);
935 OP2A(opcode, 0, tablep,currentline);
939 j = p + code_get_s4(nextp,inline_env->method);
942 *tablep = j; /* restore for little endian */
950 j = code_get_s4(nextp,inline_env->method);
951 *tablep = j; /* restore for little endian */
957 num = code_get_s4(nextp,inline_env->method);
958 *tablep = num; /* restore for little endian */
962 num -= j; /* difference of upper - lower */
964 panic("invalid TABLESWITCH: upper bound < lower bound");
966 if (nextp + 4*(num+1) > inline_env->method->jcodelength)
967 panic("Unexpected end of bytecode");
969 for (i = 0; i <= num; i++) {
970 j = p + code_get_s4(nextp,inline_env->method);
972 /*printf("TABLESWITCH: j before mapping=%ld\n",j);*/
975 *tablep = j; /* restore for little endian */
980 /*printf("TABLESWITCH: block_insert(%ld)\n",j);*/
987 /* load and store of object fields *******************/
990 BUILTIN3(BUILTIN_aastore, TYPE_VOID, currentline);
995 #if defined(__X86_64__)
999 i = code_get_u2(p + 1, inline_env->method);
1001 constant_FMIref *fr;
1002 unresolved_field *uf;
1006 fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref);
1007 #if defined(__X86_64__)
1008 OP2A_NOINC(opcode, fr->parseddesc.fd->type, fr, currentline);
1010 if (!(uf = create_unresolved_field(inline_env->method->class,
1016 /* store unresolved_field pointer */
1020 /* only with -noverify, otherwise the typechecker does this */
1023 if (!resolve_field(uf, resolveLazy, &fi))
1030 if (!resolve_classref(inline_env->method,fr->classref,resolveEager,true,&frclass))
1033 fi = class_resolvefield(frclass,
1036 inline_env->method->class,
1042 OP2A(opcode, fi->type, fi, currentline);
1043 if (!fi->class->initialized) {
1044 inline_env->method->isleafmethod = false;
1050 #if !defined(__X86_64__)
1053 i = code_get_u2(p + 1,inline_env->method);
1055 constant_FMIref *fr;
1059 fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref);
1060 if (!resolve_classref(inline_env->method,fr->classref,resolveEager,true,&frclass))
1063 fi = class_resolvefield(frclass,
1066 inline_env->method->class,
1072 OP2A(opcode, fi->type, fi, currentline);
1078 /* method invocation *****/
1080 case JAVA_INVOKESTATIC:
1081 i = code_get_u2(p + 1, inline_env->method);
1083 constant_FMIref *mr;
1085 unresolved_method *um;
1088 inline_env->method->isleafmethod = false;
1090 mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref);
1091 #if defined(__X86_64__)
1092 OP2A_NOINC(opcode, mr->parseddesc.md->paramcount, mr, currentline);
1094 um = create_unresolved_method(inline_env->method->class,
1102 /* store the unresolved_method pointer */
1106 /* only with -noverify, otherwise the typechecker does this */
1109 if (!resolve_method(um, resolveLazy, &mi))
1116 if (!resolve_classref(inline_env->method,mr->classref,resolveEager,true,&mrclass))
1119 mi = class_resolveclassmethod(mrclass,
1122 inline_env->method->class,
1129 method_display_w_class(mi);
1130 printf("\tINVOKE SPEC/VIRT\n");
1133 if (mi->flags & ACC_STATIC) {
1135 new_exception(string_java_lang_IncompatibleClassChangeError);
1139 method_descriptor2types(mi);
1140 OP2A(opcode, mi->paramcount, mi, currentline);
1145 case JAVA_INVOKESPECIAL:
1146 case JAVA_INVOKEVIRTUAL:
1147 i = code_get_u2(p + 1, inline_env->method);
1149 constant_FMIref *mr;
1151 unresolved_method *um;
1154 inline_env->method->isleafmethod = false;
1156 mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref);
1157 #if defined(__X86_64__)
1158 OP2A_NOINC(opcode, mr->parseddesc.md->paramcount + 1, mr, currentline);
1160 um = create_unresolved_method(inline_env->method->class,
1168 /* store the unresolved_method* */
1172 /* only with -noverify, otherwise the typechecker does this */
1175 if (!resolve_method(um, resolveLazy, &mi))
1182 if (!resolve_classref(inline_env->method,mr->classref,resolveEager,true,&mrclass))
1185 mi = class_resolveclassmethod(mrclass,
1188 inline_env->method->class,
1195 method_display_w_class(mi);
1196 printf("\tINVOKE SPEC/VIRT\n");
1199 if (mi->flags & ACC_STATIC) {
1201 new_exception(string_java_lang_IncompatibleClassChangeError);
1205 method_descriptor2types(mi);
1206 OP2A(opcode, mi->paramcount, mi, currentline);
1211 case JAVA_INVOKEINTERFACE:
1212 i = code_get_u2(p + 1,inline_env->method);
1214 constant_FMIref *mr;
1217 unresolved_method *um;
1219 inline_env->method->isleafmethod = false;
1221 mr = class_getconstant(inline_env->method->class, i, CONSTANT_InterfaceMethodref);
1222 #if defined(__X86_64__)
1223 OP2A_NOINC(opcode, mr->parseddesc.md->paramcount + 1, mr, currentline);
1225 um = create_unresolved_method(inline_env->method->class,
1233 /* store the unresolved_method* */
1237 /* only with -noverify, otherwise the typechecker does this */
1240 if (!resolve_method(um, resolveLazy, &mi))
1247 if (!resolve_classref(inline_env->method,mr->classref,resolveEager,true,&mrclass))
1250 mi = class_resolveinterfacemethod(mrclass,
1253 inline_env->method->class,
1258 if (mi->flags & ACC_STATIC) {
1260 new_exception(string_java_lang_IncompatibleClassChangeError);
1265 method_display_w_class(mi);
1266 printf("\tINVOKE INTERFACE\n");
1268 method_descriptor2types(mi);
1269 OP2A(opcode, mi->paramcount, mi, currentline);
1274 /* miscellaneous object operations *******/
1278 constant_classref *cr;
1281 #if defined(__X86_64__)
1282 i = code_get_u2(p + 1, inline_env->method);
1283 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1285 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &cls))
1288 /* <clinit> can throw an exception over native code */
1290 if (cls && cls->initialized) {
1291 LOADCONST_A_BUILTIN(cls);
1292 BUILTIN1(BUILTIN_new, TYPE_ADR, currentline);
1295 LOADCONST_A_BUILTIN(cr);
1296 BUILTIN1((functionptr) asm_builtin_new, TYPE_ADR, currentline);
1300 OP(ICMD_CHECKEXCEPTION);
1302 i = code_get_u2(p + 1,inline_env->method);
1303 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1304 if (!resolve_classref(inline_env->method,cr,resolveEager,true,&cls))
1306 LOADCONST_A_BUILTIN(cls);
1308 BUILTIN1(BUILTIN_new, TYPE_ADR, currentline);
1309 OP(ICMD_CHECKEXCEPTION);
1314 case JAVA_CHECKCAST:
1315 i = code_get_u2(p + 1, inline_env->method);
1317 constant_classref *cr;
1320 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1322 #if defined(x__X86_64__)
1323 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, &cls))
1326 if (cr->name->text[0] == '[') {
1327 if (!resolve_classref(inline_env->method, cr, resolveEager, true, &cls))
1330 /* array type cast-check */
1331 LOADCONST_A_BUILTIN(cls->vftbl);
1332 BUILTIN2(BUILTIN_checkarraycast, TYPE_ADR, currentline);
1335 /* object type cast-check */
1336 OP2AT(opcode, 1, cls, cr, currentline);
1340 if (!resolve_classref(inline_env->method,
1341 cr,resolveEager,true,&cls))
1344 if (cls->vftbl->arraydesc) {
1345 /* array type cast-check */
1346 LOADCONST_A_BUILTIN(cls->vftbl);
1348 BUILTIN2(BUILTIN_checkarraycast, TYPE_ADR,currentline);
1350 } else { /* object type cast-check */
1352 + LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
1354 + BUILTIN2(BUILTIN_checkcast, TYPE_ADR,currentline);
1356 OP2A(opcode, 1, cls, currentline);
1362 case JAVA_INSTANCEOF:
1363 i = code_get_u2(p + 1,inline_env->method);
1365 constant_classref *cr;
1368 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1369 if (!resolve_classref(inline_env->method,
1370 cr,resolveEager,true,&cls))
1373 if (cls->vftbl->arraydesc) {
1374 /* array type cast-check */
1375 LOADCONST_A_BUILTIN(cls->vftbl);
1377 BUILTIN2(BUILTIN_arrayinstanceof, TYPE_INT, currentline);
1379 else { /* object type cast-check */
1381 LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
1383 BUILTIN2(BUILTIN_instanceof, TYPE_INT,currentline);
1385 OP2A(opcode, 1, cls, currentline);
1390 case JAVA_MONITORENTER:
1391 #if defined(USE_THREADS)
1393 BUILTIN1(BUILTIN_monitorenter, TYPE_VOID,currentline);
1397 OP(ICMD_NULLCHECKPOP);
1401 case JAVA_MONITOREXIT:
1402 #if defined(USE_THREADS)
1404 BUILTIN1(BUILTIN_monitorexit, TYPE_VOID,currentline);
1405 OP(ICMD_CHECKEXCEPTION);
1413 /* any other basic operation **************************************/
1432 #if defined(__I386__)
1435 BUILTIN2(BUILTIN_frem, TYPE_FLOAT,currentline);
1440 #if defined(__I386__)
1443 BUILTIN2(BUILTIN_drem, TYPE_DOUBLE,currentline);
1448 #if defined(__ALPHA__)
1450 BUILTIN1(BUILTIN_f2i, TYPE_INT,currentline);
1459 #if defined(__ALPHA__)
1461 BUILTIN1(BUILTIN_f2l, TYPE_LONG,currentline);
1470 #if defined(__ALPHA__)
1472 BUILTIN1(BUILTIN_d2i, TYPE_INT,currentline);
1481 #if defined(__ALPHA__)
1483 BUILTIN1(BUILTIN_d2l, TYPE_LONG,currentline);
1491 case JAVA_BREAKPOINT:
1493 new_verifyerror(m, "Quick instructions shouldn't appear yet.");
1496 case 204: /* unused opcode */
1548 printf("Illegal opcode %d at instr %d\n", opcode, ipc);
1549 panic("Illegal opcode encountered");
1558 /* If WIDE was used correctly, iswide should have been reset by now. */
1559 if (iswide && opcode != JAVA_WIDE)
1560 panic("Illegal instruction: WIDE before incompatible opcode");
1564 /* if (inline_env->isinlinedmethod && p == inline_env->method->jcodelength - 1) { */ /* end of an inlined method */
1565 if (inline_env->isinlinedmethod && (nextp >= inline_env->method->jcodelength) ) { /* end of an inlined method */
1566 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1567 gp = inlinfo->stopgp;
1568 inlining_restore_compiler_variables();
1569 OP(ICMD_INLINE_END);
1570 /*label_index = inlinfo->label_index;*/
1572 METHINFOt(inline_env->method,"AFTER RESTORE : ",DEBUG);
1573 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1574 if (inlinfo->inlinedmethods == NULL) { /* JJJJ */
1577 tmpinlinf = list_first(inlinfo->inlinedmethods);
1578 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1580 /* printf("nextpgp: %d\n", nextgp); */
1581 label_index=inlinfo->label_index;
1582 firstlocal = inlinfo->firstlocal;
1588 if (p != m->jcodelength) {
1589 printf("p (%d) != m->jcodelength (%d)\n",p,m->jcodelength);
1590 panic("Command-sequence crosses code-boundary");
1593 *exceptionptr = new_verifyerror(m, "Falling off the end of the code");
1597 /* adjust block count if target 0 is not first intermediate instruction */
1599 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1))
1602 /* copy local to method variables */
1604 m->instructioncount = ipc;
1605 m->basicblockcount = b_count;
1606 m->stackcount = s_count + m->basicblockcount * m->maxstack;
1608 /* allocate stack table */
1610 m->stack = DMNEW(stackelement, m->stackcount);
1615 bptr = m->basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1620 /* additional block if target 0 is not first intermediate instruction */
1622 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) {
1623 bptr->iinstr = m->instructions;
1626 bptr->type = BBTYPE_STD;
1627 bptr->branchrefs = NULL;
1628 bptr->pre_count = 0;
1629 bptr->debug_nr = m->c_debug_nr++;
1632 (bptr - 1)->next = bptr;
1635 /* allocate blocks */
1637 for (p = 0; p < inline_env->cumjcodelength; p++) {
1638 /* for (p = 0; p < m->jcodelength; p++) { */
1639 if (m->basicblockindex[p] & 1) {
1640 /* check if this block starts at the beginning of an instruction */
1641 if (!instructionstart[p]) {
1642 printf("Basic Block beginn: %d\n",p);
1643 panic("Branch into middle of instruction");
1645 /* allocate the block */
1646 bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
1647 bptr->debug_nr = m->c_debug_nr++;
1649 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1653 bptr->type = BBTYPE_STD;
1654 bptr->branchrefs = NULL;
1655 m->basicblockindex[p] = b_count;
1656 bptr->pre_count = 0;
1659 (bptr - 1)->next = bptr;
1663 /* allocate additional block at end */
1665 bptr->instack = bptr->outstack = NULL;
1666 bptr->indepth = bptr->outdepth = 0;
1667 bptr->iinstr = NULL;
1668 (bptr - 1)->icount = (m->instructions + m->instructioncount) - (bptr - 1)->iinstr;
1673 bptr->type = BBTYPE_STD;
1674 bptr->branchrefs = NULL;
1675 bptr->pre_count = 0;
1676 bptr->debug_nr = m->c_debug_nr++;
1677 (bptr - 1)->next = bptr;
1680 if (cd->exceptiontablelength > 0) {
1681 cd->exceptiontable[cd->exceptiontablelength - 1].down = NULL;
1684 for (i = 0; i < cd->exceptiontablelength; ++i) {
1685 p = cd->exceptiontable[i].startpc;
1686 cd->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1688 p = cd->exceptiontable[i].endpc;
1689 cd->exceptiontable[i].end = (p == inline_env->method->jcodelength) ? (m->basicblocks + m->basicblockcount /*+ 1*/) : (m->basicblocks + m->basicblockindex[p]);
1691 p = cd->exceptiontable[i].handlerpc;
1692 cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1696 if (useinlining) inlining_cleanup(inline_env);
1698 /* just return methodinfo* to signal everything was ok */
1705 * These are local overrides for various environment variables in Emacs.
1706 * Please do not remove this and leave it at the end of the file, where
1707 * Emacs will automagically detect them.
1708 * ---------------------------------------------------------------------
1711 * indent-tabs-mode: t