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 4305 2006-01-19 20:28:27Z 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/jit/asmpart.h"
59 #include "vm/jit/jit.h"
60 #include "vm/jit/parse.h"
61 #include "vm/jit/patcher.h"
62 #include "vm/jit/inline/parseRT.h"
63 #include "vm/jit/inline/parseXTA.h"
64 #include "vm/jit/inline/inline.h"
65 #include "vm/jit/loop/loop.h"
66 #include "vm/jit/inline/parseRTprint.h"
68 /*******************************************************************************
70 function 'parse' scans the JavaVM code and generates intermediate code
72 During parsing the block index table is used to store at bit pos 0
73 a flag which marks basic block starts and at position 1 to 31 the
74 intermediate instruction index. After parsing the block index table
75 is scanned, for marked positions a block is generated and the block
76 number is stored in the block index table.
78 *******************************************************************************/
80 static exceptiontable * fillextable(methodinfo *m,
81 exceptiontable *extable,
82 exceptiontable *raw_extable,
83 int exceptiontablelength,
86 t_inlining_globals *inline_env)
88 int b_count, p, src, insertBlock;
90 if (exceptiontablelength == 0)
93 b_count = *block_count;
95 for (src = exceptiontablelength-1; src >=0; src--) {
96 p = raw_extable[src].startpc;
97 if (label_index != NULL) p = label_index[p];
102 p = raw_extable[src].endpc; /* see JVM Spec 4.7.3 */
103 if (p <= raw_extable[src].startpc) {
104 *exceptionptr = new_verifyerror(inline_env->method,
105 "Invalid exception handler range");
109 if (p >inline_env->method->jcodelength) {
110 *exceptionptr = new_verifyerror(inline_env->method,
111 "Invalid exception handler end is after code end");
115 if (p<inline_env->method->jcodelength) insertBlock=1; else insertBlock=0;
116 if (label_index != NULL) p = label_index[p];
119 /* if (p < inline_env->method->jcodelength) block_insert(p); */
123 p = raw_extable[src].handlerpc;
124 if (label_index != NULL) p = label_index[p];
125 extable->handlerpc = p;
129 extable->catchtype = raw_extable[src].catchtype;
130 extable->next = NULL;
131 extable->down = &extable[1];
135 *block_count = b_count;
136 return extable; /*&extable[i];*/ /* return the next free xtable* */
141 methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env)
143 int p; /* java instruction counter */
144 int nextp; /* start of next java instruction */
145 int opcode; /* java opcode */
146 int i; /* temporary for different uses (ctrs)*/
147 int ipc = 0; /* intermediate instruction counter */
148 int b_count = 0; /* basic block counter */
149 int s_count = 0; /* stack element counter */
150 bool blockend = false; /* true if basic block end has been reached */
151 bool iswide = false; /* true if last instruction was a wide*/
152 instruction *iptr; /* current ptr into instruction array */
153 int gp; /* global java instruction counter */
154 /* inlining info for current method */
156 inlining_methodinfo *inlinfo = inline_env->inlining_rootinfo;
157 inlining_methodinfo *tmpinlinf;
158 int nextgp = -1; /* start of next method to be inlined */
159 int *label_index = NULL; /* label redirection table */
160 int firstlocal = 0; /* first local variable of method */
161 exceptiontable* nextex; /* points next free entry in extable */
162 u1 *instructionstart; /* 1 for pcs which are valid instr. starts */
164 constant_classref *cr;
165 constant_classref *compr;
167 builtintable_entry *bte;
173 u2 skipBasicBlockChange;
175 #if defined(USE_INLINING)
176 if ((opt_rt) || (opt_xta)) {
179 if (opt_rt) Missed = rtMissed;
180 if (opt_xta) Missed = xtaMissed;
182 if (m->methodUsed != USED) {
184 printf(" rta/xta missed: "); fflush(stdout);
185 METHINFO(m,opt_verbose);
187 if ( (Missed = fopen("Missed", "a")) == NULL) {
188 printf("CACAO - rt/xtaMissed file: cant open file to write append \n");
191 utf_fprint(Missed,m->class->name);
192 fprintf(Missed," "); fflush(Missed);
193 utf_fprint(Missed,m->name);
194 fprintf(Missed," "); fflush(Missed);
195 utf_fprint(Missed,m->descriptor);
196 fprintf(Missed,"\n"); fflush(Missed);
203 #if defined(USE_INLINING)
205 label_index = inlinfo->label_index;
206 m->maxstack = inline_env->cummaxstack;
207 /*JOWENN m->exceptiontablelength = inline_env->cumextablelength;*/
209 tmpinlinf = (inlining_methodinfo *) list_first(inlinfo->inlinedmethods);
211 if (tmpinlinf != NULL)
212 nextgp = tmpinlinf->startgp;
216 /* allocate instruction array and block index table */
218 /* 1 additional for end ipc * # cum inline methods*/
220 m->basicblockindex = DMNEW(s4, inline_env->cumjcodelength + inline_env->cummethods);
221 memset(m->basicblockindex, 0, sizeof(s4) * (inline_env->cumjcodelength + inline_env->cummethods));
223 instructionstart = DMNEW(u1, inline_env->cumjcodelength + inline_env->cummethods);
224 memset(instructionstart, 0, sizeof(u1) * (inline_env->cumjcodelength + inline_env->cummethods));
226 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
227 /* additional MONITOREXITS are reached by branches which are 3 bytes */
229 iptr = m->instructions = DMNEW(instruction, inline_env->cumjcodelength + 5);
231 /* Zero the intermediate instructions array so we don't have any
232 * invalid pointers in it if we cannot finish analyse_stack(). */
234 memset(iptr, 0, sizeof(instruction) * (inline_env->cumjcodelength + 5));
236 /* compute branch targets of exception table */
238 nextex = fillextable(m,
239 &(cd->exceptiontable[cd->exceptiontablelength-1]), m->exceptiontable, m->exceptiontablelength,
240 label_index, &b_count, inline_env);
243 s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */
245 #if defined(USE_THREADS)
246 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
247 m->isleafmethod = false;
248 inline_env->method->isleafmethod = false;
252 /* scan all java instructions */
256 if (m->linenumbercount == 0) {
259 linepcchange = m->linenumbers[0].start_pc;
262 skipBasicBlockChange=0;
263 for (p = 0, gp = 0; p < inline_env->method->jcodelength; gp += (nextp - p), p = nextp) {
265 /* mark this position as a valid instruction start */
267 instructionstart[gp] = 1;
268 if (linepcchange==p) {
269 if (inline_env->method->linenumbercount > lineindex) {
270 currentline = inline_env->method->linenumbers[lineindex].line_number;
272 if (lineindex < inline_env->method->linenumbercount)
273 linepcchange = inline_env->method->linenumbers[lineindex].start_pc;
278 #if defined(USE_INLINING)
279 if ((useinlining) && (gp == nextgp)) {
281 bool *readonly = NULL;
284 block_insert(gp); /* JJJJJJJJJJ */
286 instructionstart[gp] = 1;
287 m->basicblockindex[gp] |= (ipc << 1); /*FIXME: necessary ? */
289 opcode = code_get_u1(p,inline_env->method);
290 nextp = p += jcommandsize[opcode];
291 if (nextp > inline_env->method->jcodelength) {
292 *exceptionptr = new_verifyerror(inline_env->method,
293 "Unexpected end of bytecode");
297 tmpinlinf = list_first(inlinfo->inlinedmethods);
298 firstlocal = tmpinlinf->firstlocal;
299 label_index = tmpinlinf->label_index;
300 readonly = tmpinlinf->readonly;
302 for (i=0,tptr=tmpinlinf->method->paramtypes;i<tmpinlinf->method->paramcount;i++,tptr++) {
303 if ( ((*tptr)==TYPE_LNG) ||
304 ((*tptr)==TYPE_DBL) )
310 for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) {
313 if ((i == 0) && inlineparamopt) {
314 OP1(ICMD_CLEAR_ARGREN, firstlocal);
317 if (!inlineparamopt || !readonly[i]) {
321 op = ICMD_READONLY_ARG;
325 if ( ((*tptr)==TYPE_LNG) ||
326 ((*tptr)==TYPE_DBL) )
331 OP1(op, firstlocal + argBlockIdx);
332 /* OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i); */
334 skipBasicBlockChange=1;
335 inlining_save_compiler_variables();
336 inlining_set_compiler_variables(tmpinlinf);
338 OP1(ICMD_INLINE_START,tmpinlinf->level);
340 if (inlinfo->inlinedmethods == NULL) {
343 tmpinlinf = list_first(inlinfo->inlinedmethods);
344 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
346 if (inline_env->method->exceptiontablelength > 0) {
347 nextex = fillextable(m, nextex,
348 inline_env->method->exceptiontable, inline_env->method->exceptiontablelength,
349 label_index, &b_count, inline_env);
355 #endif /* defined(USE_INLINING) */
357 /* fetch next opcode */
359 opcode = code_get_u1(p, inline_env->method);
361 if (!skipBasicBlockChange) {
362 m->basicblockindex[gp] |= (ipc << 1); /*store intermed cnt*/
363 } else skipBasicBlockChange=0;
365 /* some compilers put a JAVA_NOP after a blockend instruction */
367 if ((opcode != JAVA_NOP) && (blockend == true)) {
368 /* start new block */
374 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
376 if (nextp > inline_env->method->jcodelength) {
377 *exceptionptr = new_verifyerror(inline_env->method,
378 "Unexpected end of bytecode");
382 s_count += stackreq[opcode]; /* compute stack element count */
387 /* pushing constants onto the stack p */
390 LOADCONST_I(code_get_s1(p+1,inline_env->method));
394 LOADCONST_I(code_get_s2(p+1,inline_env->method));
398 i = code_get_u1(p + 1, inline_env->method);
399 goto pushconstantitem;
403 i = code_get_u2(p + 1, inline_env->method);
407 if (i >= inline_env->method->class->cpcount) {
408 *exceptionptr = new_verifyerror(inline_env->method,
409 "Attempt to access constant outside range");
413 switch (inline_env->method->class->cptags[i]) {
414 case CONSTANT_Integer:
415 LOADCONST_I(((constant_integer *) (inline_env->method->class->cpinfos[i]))->value);
418 LOADCONST_L(((constant_long *) (inline_env->method->class->cpinfos[i]))->value);
421 LOADCONST_F(((constant_float *) (inline_env->method->class->cpinfos[i]))->value);
423 case CONSTANT_Double:
424 LOADCONST_D(((constant_double *) (inline_env->method->class->cpinfos[i]))->value);
426 case CONSTANT_String:
427 LOADCONST_A(literalstring_new((utf *) (inline_env->method->class->cpinfos[i])));
430 cr = (constant_classref *) (inline_env->method->class->cpinfos[i]);
432 if (!resolve_classref(inline_env->method, cr, resolveLazy, true,
436 /* if not resolved, c == NULL */
438 LOADCONST_A_CLASS(c, cr);
441 *exceptionptr = new_verifyerror(inline_env->method,
442 "Invalid constant type to push");
447 case JAVA_ACONST_NULL:
458 LOADCONST_I(opcode - JAVA_ICONST_0);
463 LOADCONST_L(opcode - JAVA_LCONST_0);
469 LOADCONST_F(opcode - JAVA_FCONST_0);
474 LOADCONST_D(opcode - JAVA_DCONST_0);
477 /* loading variables onto the stack */
485 i = code_get_u1(p + 1,inline_env->method);
487 i = code_get_u2(p + 1,inline_env->method);
491 OP1LOAD(opcode, i + firstlocal);
498 OP1LOAD(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
505 OP1LOAD(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
512 OP1LOAD(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
519 OP1LOAD(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
526 OP1LOAD(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
529 /* storing stack values into local variables */
537 i = code_get_u1(p + 1,inline_env->method);
539 i = code_get_u2(p + 1,inline_env->method);
543 OP1STORE(opcode, i + firstlocal);
550 OP1STORE(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
557 OP1STORE(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
564 OP1STORE(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
571 OP1STORE(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
578 OP1STORE(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
586 i = code_get_u1(p + 1,inline_env->method);
587 v = code_get_s1(p + 2,inline_env->method);
590 i = code_get_u2(p + 1,inline_env->method);
591 v = code_get_s2(p + 3,inline_env->method);
595 INDEX_ONEWORD(i + firstlocal);
596 OP2I(opcode, i + firstlocal, v);
600 /* wider index for loading, storing and incrementing */
607 /* managing arrays ****************************************************/
610 switch (code_get_s1(p + 1, inline_env->method)) {
612 bte = builtintable_get_internal(BUILTIN_newarray_boolean);
615 bte = builtintable_get_internal(BUILTIN_newarray_char);
618 bte = builtintable_get_internal(BUILTIN_newarray_float);
621 bte = builtintable_get_internal(BUILTIN_newarray_double);
624 bte = builtintable_get_internal(BUILTIN_newarray_byte);
627 bte = builtintable_get_internal(BUILTIN_newarray_short);
630 bte = builtintable_get_internal(BUILTIN_newarray_int);
633 bte = builtintable_get_internal(BUILTIN_newarray_long);
636 *exceptionptr = new_verifyerror(inline_env->method,
637 "Invalid array-type to create");
640 BUILTIN(bte, true, NULL, currentline);
644 i = code_get_u2(p + 1, inline_env->method);
645 compr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
649 if (!(cr = class_get_classref_multiarray_of(1, compr)))
652 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
655 LOADCONST_A_BUILTIN(c, cr);
656 bte = builtintable_get_internal(BUILTIN_newarray);
657 BUILTIN(bte, true, NULL, currentline);
661 case JAVA_MULTIANEWARRAY:
662 inline_env->method->isleafmethod = false;
663 i = code_get_u2(p + 1, inline_env->method);
665 s4 v = code_get_u1(p + 3, inline_env->method);
667 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
671 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
674 /* if unresolved, c == NULL */
675 OP2AT(opcode, v, c, cr, currentline);
697 i = p + code_get_s2(p + 1,inline_env->method);
709 i = p + code_get_s4(p + 1,inline_env->method);
721 i = code_get_u1(p + 1,inline_env->method);
723 i = code_get_u2(p + 1,inline_env->method);
730 if (inline_env->isinlinedmethod) {
731 OP1(ICMD_GOTO, inlinfo->stopgp);
735 OP1LOAD(opcode, i + firstlocal);
744 if (inline_env->isinlinedmethod) {
745 /* if (p==m->jcodelength-1) {*/ /* return is at end of inlined method */
749 if (nextp>inline_env->method->jcodelength-1) {
750 /* OP1(ICMD_GOTO, inlinfo->stopgp);
758 OP1(ICMD_GOTO, inlinfo->stopgp);
763 /* zero val.a so no patcher is inserted */
764 /* the type checker may set this later */
771 /* zero val.a so no patcher is inserted */
772 /* the type checker may set this later */
778 /* table jumps ********************************************************/
780 case JAVA_LOOKUPSWITCH:
787 nextp = ALIGN((p + 1), 4);
789 if (nextp + 8 > inline_env->method->jcodelength) {
790 *exceptionptr = new_verifyerror(inline_env->method,
791 "Unexpected end of bytecode");
796 tablep = (s4 *) (inline_env->method->jcode + nextp);
799 num = code_get_u4(nextp + 4, inline_env->method);
800 tablep = DMNEW(s4, num * 2 + 2);
803 OP2A(opcode, 0, tablep, currentline);
807 j = p + code_get_s4(nextp, inline_env->method);
810 *tablep = j; /* restore for little endian */
816 /* number of pairs */
818 num = code_get_u4(nextp, inline_env->method);
823 if (nextp + 8 * num > inline_env->method->jcodelength) {
824 *exceptionptr = new_verifyerror(inline_env->method,
825 "Unexpected end of bytecode");
829 for (i = 0; i < num; i++) {
832 j = code_get_s4(nextp, inline_env->method);
833 *tablep = j; /* restore for little endian */
837 /* check if the lookup table is sorted correctly */
839 if (i && (j <= prevvalue)) {
840 *exceptionptr = new_verifyerror(m, "Unsorted lookup switch");
847 j = p + code_get_s4(nextp,inline_env->method);
850 *tablep = j; /* restore for little endian */
861 case JAVA_TABLESWITCH:
867 nextp = ALIGN((p + 1), 4);
868 if (nextp + 12 > inline_env->method->jcodelength) {
869 *exceptionptr = new_verifyerror(inline_env->method,
870 "Unexpected end of bytecode");
875 tablep = (s4 *) (inline_env->method->jcode + nextp);
878 num = code_get_u4(nextp + 8,inline_env->method) - code_get_u4(nextp + 4,inline_env->method);
879 tablep = DMNEW(s4, num + 1 + 3);
882 OP2A(opcode, 0, tablep, currentline);
886 j = p + code_get_s4(nextp, inline_env->method);
889 *tablep = j; /* restore for little endian */
897 j = code_get_s4(nextp, inline_env->method);
898 *tablep = j; /* restore for little endian */
904 num = code_get_s4(nextp, inline_env->method);
905 *tablep = num; /* restore for little endian */
909 num -= j; /* difference of upper - lower */
912 *exceptionptr = new_verifyerror(inline_env->method,
913 "invalid TABLESWITCH: upper bound < lower bound");
917 if (nextp + 4 * (num + 1) > inline_env->method->jcodelength) {
918 *exceptionptr = new_verifyerror(inline_env->method,
919 "Unexpected end of bytecode");
923 for (i = 0; i <= num; i++) {
924 j = p + code_get_s4(nextp,inline_env->method);
928 *tablep = j; /* restore for little endian */
939 /* load and store of object fields ************************************/
943 inline_env->method->isleafmethod = false;
952 unresolved_field *uf;
955 i = code_get_u2(p + 1, inline_env->method);
956 fr = class_getconstant(inline_env->method->class, i,
961 OP2A_NOINC(opcode, fr->parseddesc.fd->type, fr, currentline);
963 if (!(uf = create_unresolved_field(inline_env->method->class,
968 /* store unresolved_field pointer */
972 /* only with -noverify, otherwise the typechecker does this */
975 if (!resolve_field(uf, resolveLazy, &fi))
988 /* method invocation **************************************************/
990 case JAVA_INVOKESTATIC:
991 i = code_get_u2(p + 1, inline_env->method);
995 unresolved_method *um;
998 inline_env->method->isleafmethod = false;
1000 mr = class_getconstant(inline_env->method->class, i,
1001 CONSTANT_Methodref);
1005 md = mr->parseddesc.md;
1008 if (!descriptor_params_from_paramtypes(md, ACC_STATIC))
1011 OP2A_NOINC(opcode, 0, mr, currentline);
1013 um = create_unresolved_method(inline_env->method->class,
1014 inline_env->method, iptr);
1019 /* store the unresolved_method pointer */
1023 /* only with -noverify, otherwise the typechecker does this */
1026 if (!resolve_method(um, resolveLazy, &mi))
1038 case JAVA_INVOKESPECIAL:
1039 case JAVA_INVOKEVIRTUAL:
1041 constant_FMIref *mr;
1043 unresolved_method *um;
1046 inline_env->method->isleafmethod = false;
1048 i = code_get_u2(p + 1, inline_env->method);
1049 mr = class_getconstant(inline_env->method->class, i,
1050 CONSTANT_Methodref);
1054 md = mr->parseddesc.md;
1057 if (!descriptor_params_from_paramtypes(md, 0))
1060 OP2A_NOINC(opcode, 0, mr, currentline);
1062 um = create_unresolved_method(inline_env->method->class,
1063 inline_env->method, iptr);
1068 /* store the unresolved_method* */
1072 /* only with -noverify, otherwise the typechecker does this */
1075 if (!resolve_method(um, resolveLazy, &mi))
1087 case JAVA_INVOKEINTERFACE:
1088 i = code_get_u2(p + 1, inline_env->method);
1090 constant_FMIref *mr;
1092 unresolved_method *um;
1095 inline_env->method->isleafmethod = false;
1097 mr = class_getconstant(inline_env->method->class, i,
1098 CONSTANT_InterfaceMethodref);
1102 md = mr->parseddesc.md;
1105 if (!descriptor_params_from_paramtypes(md, 0))
1108 OP2A_NOINC(opcode, 0, mr, currentline);
1110 um = create_unresolved_method(inline_env->method->class,
1111 inline_env->method, iptr);
1116 /* store the unresolved_method* */
1120 /* only with -noverify, otherwise the typechecker does this */
1123 if (!resolve_method(um, resolveLazy, &mi))
1135 /* miscellaneous object operations ************************************/
1138 i = code_get_u2(p + 1, inline_env->method);
1139 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1143 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true,
1147 LOADCONST_A_BUILTIN(c, cr);
1148 bte = builtintable_get_internal(BUILTIN_new);
1149 BUILTIN(bte, true, NULL, currentline);
1153 case JAVA_CHECKCAST:
1154 i = code_get_u2(p + 1, inline_env->method);
1155 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1159 if (!resolve_classref(inline_env->method, cr, resolveLazy, true,
1163 if (cr->name->text[0] == '[') {
1164 /* array type cast-check */
1165 OP2AT(opcode, 0, c, cr, currentline);
1166 inline_env->method->isleafmethod = false;
1169 /* object type cast-check */
1170 OP2AT(opcode, 1, c, cr, currentline);
1174 case JAVA_INSTANCEOF:
1175 i = code_get_u2(p + 1,inline_env->method);
1176 cr = (constant_classref *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1180 if (!resolve_classref(inline_env->method, cr, resolveLazy, true, true, &c))
1183 if (cr->name->text[0] == '[') {
1184 /* array type cast-check */
1185 LOADCONST_A_BUILTIN(c, cr);
1186 bte = builtintable_get_internal(BUILTIN_arrayinstanceof);
1187 BUILTIN(bte, false, NULL, currentline);
1191 /* object type cast-check */
1192 OP2AT(opcode, 1, c, cr, currentline);
1196 case JAVA_MONITORENTER:
1197 #if defined(USE_THREADS)
1200 bte = builtintable_get_internal(BUILTIN_monitorenter);
1201 BUILTIN(bte, false, NULL, currentline);
1210 case JAVA_MONITOREXIT:
1211 #if defined(USE_THREADS)
1213 bte = builtintable_get_internal(BUILTIN_monitorexit);
1214 BUILTIN(bte, false, NULL, currentline);
1222 /* any other basic operation ******************************************/
1225 #if !SUPPORT_DIVISION
1226 bte = builtintable_get_internal(BUILTIN_idiv);
1227 OP2A(opcode, bte->md->paramcount, bte, currentline);
1228 inline_env->method->isleafmethod = false;
1235 #if !SUPPORT_DIVISION
1236 bte = builtintable_get_internal(BUILTIN_irem);
1237 OP2A(opcode, bte->md->paramcount, bte, currentline);
1238 inline_env->method->isleafmethod = false;
1245 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1246 bte = builtintable_get_internal(BUILTIN_ldiv);
1247 OP2A(opcode, bte->md->paramcount, bte, currentline);
1248 inline_env->method->isleafmethod = false;
1255 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1256 bte = builtintable_get_internal(BUILTIN_lrem);
1257 OP2A(opcode, bte->md->paramcount, bte, currentline);
1258 inline_env->method->isleafmethod = false;
1265 #if defined(__I386__)
1268 bte = builtintable_get_internal(BUILTIN_frem);
1269 BUILTIN(bte, false, NULL, currentline);
1274 #if defined(__I386__)
1277 bte = builtintable_get_internal(BUILTIN_drem);
1278 BUILTIN(bte, false, NULL, currentline);
1283 #if defined(__ALPHA__)
1285 bte = builtintable_get_internal(BUILTIN_f2i);
1286 BUILTIN(bte, false, NULL, currentline);
1295 #if defined(__ALPHA__)
1297 bte = builtintable_get_internal(BUILTIN_f2l);
1298 BUILTIN(bte, false, NULL, currentline);
1307 #if defined(__ALPHA__)
1309 bte = builtintable_get_internal(BUILTIN_d2i);
1310 BUILTIN(bte, false, NULL, currentline);
1319 #if defined(__ALPHA__)
1321 bte = builtintable_get_internal(BUILTIN_d2l);
1322 BUILTIN(bte, false, NULL, currentline);
1330 case JAVA_BREAKPOINT:
1332 new_verifyerror(m, "Quick instructions shouldn't appear yet.");
1335 case 186: /* unused opcode */
1390 new_verifyerror(inline_env->method,"Illegal opcode %d at instr %d\n",
1401 /* If WIDE was used correctly, iswide should have been reset by now. */
1402 if (iswide && opcode != JAVA_WIDE) {
1403 *exceptionptr = new_verifyerror(inline_env->method,
1404 "Illegal instruction: WIDE before incompatible opcode");
1408 #if defined(USE_INLINING)
1409 /* if (inline_env->isinlinedmethod && p == inline_env->method->jcodelength - 1) { */ /* end of an inlined method */
1410 if (inline_env->isinlinedmethod && (nextp >= inline_env->method->jcodelength) ) { /* end of an inlined method */
1411 gp = inlinfo->stopgp;
1412 inlining_restore_compiler_variables();
1413 OP(ICMD_INLINE_END);
1414 /*label_index = inlinfo->label_index;*/
1416 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1417 if (inlinfo->inlinedmethods == NULL) { /* JJJJ */
1420 tmpinlinf = list_first(inlinfo->inlinedmethods);
1421 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1423 label_index=inlinfo->label_index;
1424 firstlocal = inlinfo->firstlocal;
1426 #endif /* defined(USE_INLINING) */
1431 if (p != m->jcodelength) {
1432 printf("p (%d) != m->jcodelength (%d)\n",p,m->jcodelength);
1433 *exceptionptr = new_verifyerror(inline_env->method,
1434 "Command-sequence crosses code-boundary");
1439 *exceptionptr = new_verifyerror(m, "Falling off the end of the code");
1443 /* adjust block count if target 0 is not first intermediate instruction */
1445 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1))
1448 /* copy local to method variables */
1450 m->instructioncount = ipc;
1451 m->basicblockcount = b_count;
1452 m->stackcount = s_count + m->basicblockcount * m->maxstack;
1454 /* allocate stack table */
1456 m->stack = DMNEW(stackelement, m->stackcount);
1461 bptr = m->basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1466 /* additional block if target 0 is not first intermediate instruction */
1468 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) {
1469 bptr->iinstr = m->instructions;
1472 bptr->type = BBTYPE_STD;
1473 bptr->branchrefs = NULL;
1474 bptr->pre_count = 0;
1475 bptr->debug_nr = m->c_debug_nr++;
1478 (bptr - 1)->next = bptr;
1481 /* allocate blocks */
1483 for (p = 0; p < inline_env->cumjcodelength; p++) {
1484 /* for (p = 0; p < m->jcodelength; p++) { */
1485 if (m->basicblockindex[p] & 1) {
1486 /* Check if this block starts at the beginning of an */
1489 if (!instructionstart[p]) {
1490 *exceptionptr = new_verifyerror(inline_env->method,
1491 "Branch into middle of instruction");
1495 /* allocate the block */
1496 bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
1497 bptr->debug_nr = m->c_debug_nr++;
1499 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1503 bptr->type = BBTYPE_STD;
1504 bptr->branchrefs = NULL;
1505 m->basicblockindex[p] = b_count;
1506 bptr->pre_count = 0;
1509 (bptr - 1)->next = bptr;
1513 /* allocate additional block at end */
1515 bptr->instack = bptr->outstack = NULL;
1516 bptr->indepth = bptr->outdepth = 0;
1517 bptr->iinstr = NULL;
1518 (bptr - 1)->icount = (m->instructions + m->instructioncount) - (bptr - 1)->iinstr;
1523 bptr->type = BBTYPE_STD;
1524 bptr->branchrefs = NULL;
1525 bptr->pre_count = 0;
1526 bptr->debug_nr = m->c_debug_nr++;
1527 (bptr - 1)->next = bptr;
1530 if (cd->exceptiontablelength > 0) {
1531 cd->exceptiontable[cd->exceptiontablelength - 1].down = NULL;
1534 for (i = 0; i < cd->exceptiontablelength; ++i) {
1535 p = cd->exceptiontable[i].startpc;
1536 cd->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1538 p = cd->exceptiontable[i].endpc;
1539 cd->exceptiontable[i].end = (p == inline_env->method->jcodelength) ? (m->basicblocks + m->basicblockcount /*+ 1*/) : (m->basicblocks + m->basicblockindex[p]);
1541 p = cd->exceptiontable[i].handlerpc;
1542 cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1546 #if defined(USE_INLINING)
1548 inlining_cleanup(inline_env);
1551 /* just return methodinfo* to signal everything was ok */
1558 * These are local overrides for various environment variables in Emacs.
1559 * Please do not remove this and leave it at the end of the file, where
1560 * Emacs will automagically detect them.
1561 * ---------------------------------------------------------------------
1564 * indent-tabs-mode: t
1568 * vim:noexpandtab:sw=4:ts=4: