1 /* jit/parse.c - parser for JavaVM to intermediate code translation
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5 M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6 P. Tomsich, J. Wenninger
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
32 $Id: parse.c 1203 2004-06-22 23:14:55Z twisti $
44 #include "loop/loop.h"
50 #include "toolbox/memory.h"
51 #include "toolbox/logging.h"
54 /* data about the currently parsed method */
56 classinfo *rt_class; /* class the compiled method belongs to */
57 methodinfo *rt_method; /* pointer to method info of compiled method */
58 utf *rt_descriptor; /* type descriptor of compiled method */
59 int rt_jcodelength; /* length of JavaVM-codes */
60 u1 *rt_jcode; /* pointer to start of JavaVM-code */
66 /*#define debug_writebranch printf("op: %s i: %d label_index[i]: %d\n",icmd_names[opcode], i, label_index[i]);*/
67 #define debug_writebranch
70 /* function descriptor2typesL ***************************************************
72 decodes a already checked method descriptor. The parameter count, the
73 return type and the argument types are stored in the passed methodinfo.
74 gets and saves classptr for object ref.s
76 *******************************************************************************/
78 classSetNode *descriptor2typesL(methodinfo *m)
85 classinfo** classtypes;
90 printf("In descriptor2typesL >>>\t"); fflush(stdout);
91 utf_display(m->class->name); printf(".");
92 method_display(m);fflush(stdout);
96 desc = MNEW (char, 256);
97 types = DMNEW (u1, m->descriptor->blength);
98 classtypes = MNEW (classinfo*, m->descriptor->blength+1);
99 m->returnclass = NULL;
101 if (!(m->flags & ACC_STATIC)) {
103 if (debugInfo >= 1) {
104 printf("param #0 (this?) method class =");utf_display(m->class->name);printf("\n");
106 classtypes[pcount] = m->class;
107 p = addClassCone(p, m->class);
111 utf_ptr = m->descriptor->text + 1;
112 strcpy (desc,utf_ptr);
114 while ((c = *desc++) != ')') {
121 case 'Z': *tptr++ = TYPE_INT;
123 case 'J': *tptr++ = TYPE_LNG;
125 case 'F': *tptr++ = TYPE_FLT;
127 case 'D': *tptr++ = TYPE_DBL;
129 case 'L': *tptr++ = TYPE_ADR;
130 /* get class string */
131 class = strtok(desc,";");
132 desc = strtok(NULL,"\0");
133 /* get/save classinfo ptr */
134 classtypes[pcount-1] = class_get(utf_new_char(class));
135 p = addClassCone(p, class_get(utf_new_char(class)));
136 if (debugInfo >= 1) {
137 printf("LParam#%i 's class type is: %s\n",pcount-1,class);fflush(stdout);
138 printf("Lclasstypes[%i]=",pcount-1);fflush(stdout);
139 utf_display(classtypes[pcount-1]->name);
142 case '[': *tptr++ = TYPE_ADR;
145 /* get class string */
147 class = strtok(desc,";");
148 desc = strtok(NULL,"\0");
149 /* get/save classinfo ptr */
150 classtypes[pcount-1] = class_get(utf_new_char(class));
151 p= addClassCone(p, class_get(utf_new_char(class)));
152 if (debugInfo >= 1) {
153 printf("[Param#%i 's class type is: %s\n",pcount-1,class);
154 printf("[classtypes[%i]=",pcount-1);fflush(stdout);
155 utf_display(classtypes[pcount-1]->name);
160 classtypes[pcount-1] = NULL;
163 panic("Ill formed methodtype-descriptor");
167 /* compute return type */
173 case 'Z': m->returntype = TYPE_INT;
175 case 'J': m->returntype = TYPE_LNG;
177 case 'F': m->returntype = TYPE_FLT;
179 case 'D': m->returntype = TYPE_DBL;
182 m->returntype = TYPE_ADR;
190 m->returntype = TYPE_ADR;
192 /* get class string */
193 class = strtok(desc,";");
194 m->returnclass = class_get(utf_new_char(class));
195 if (m->returnclass == NULL) {
196 printf("class=%s :\t",class);
197 panic ("return class not found");
200 case 'V': m->returntype = TYPE_VOID;
203 default: panic("Ill formed methodtype-descriptor-ReturnType");
206 m->paramcount = pcount;
207 m->paramtypes = types;
208 m->paramclass = classtypes;
212 for (i=0; i< m->paramcount; i++) {
213 if ((m->paramtypes[i] == TYPE_ADR) && (m->paramclass[i] != NULL)) {
214 printf("Param #%i is:\t",i);
215 utf_display(m->paramclass[i]->name);
220 if ((m->returntype == TYPE_ADR) && (m->returnclass != NULL)) {
221 printf("\tReturn Type is:\t"); fflush(stdout);
222 utf_display(m->returnclass->name);
226 printf("params2types: START results in a set \n");
227 printf("param2types: A Set size=%i=\n",sizeOfSet(p));
236 /* function descriptor2types ***************************************************
238 decodes a already checked method descriptor. The parameter count, the
239 return type and the argument types are stored in the passed methodinfo.
241 *******************************************************************************/
243 void descriptor2types(methodinfo *m)
249 types = DMNEW(u1, m->descriptor->blength);
252 if (!(m->flags & ACC_STATIC)) {
257 utf_ptr = m->descriptor->text + 1;
259 while ((c = *utf_ptr++) != ')') {
280 while (*utf_ptr++ != ';');
287 while (*utf_ptr++ != ';') /* skip */;
290 panic("Ill formed methodtype-descriptor");
294 /* compute return type */
296 switch (*utf_ptr++) {
302 m->returntype = TYPE_INT;
305 m->returntype = TYPE_LNG;
308 m->returntype = TYPE_FLT;
311 m->returntype = TYPE_DBL;
315 m->returntype = TYPE_ADR;
318 m->returntype = TYPE_VOID;
321 panic("Ill formed methodtype-descriptor");
324 m->paramcount = pcount;
325 m->paramtypes = types;
330 /*******************************************************************************
332 function 'parse' scans the JavaVM code and generates intermediate code
334 During parsing the block index table is used to store at bit pos 0
335 a flag which marks basic block starts and at position 1 to 31 the
336 intermediate instruction index. After parsing the block index table
337 is scanned, for marked positions a block is generated and the block
338 number is stored in the block index table.
340 *******************************************************************************/
342 static exceptiontable* fillextable(methodinfo *m, exceptiontable* extable, exceptiontable *raw_extable, int exceptiontablelength, int *label_index, int *block_count)
346 if (exceptiontablelength == 0)
349 b_count = *block_count;
351 for (i = 0; i < exceptiontablelength; i++) {
352 p = raw_extable[i].startpc;
353 if (label_index != NULL) p = label_index[p];
354 extable[i].startpc = p;
358 p = raw_extable[i].endpc;
359 if (p <= raw_extable[i].startpc)
360 panic("Invalid exception handler range");
361 if (label_index != NULL) p = label_index[p];
362 extable[i].endpc = p;
364 if (p < cumjcodelength)
367 p = raw_extable[i].handlerpc;
368 if (label_index != NULL) p = label_index[p];
369 extable[i].handlerpc = p;
373 extable[i].catchtype = raw_extable[i].catchtype;
374 extable[i].next = NULL;
375 extable[i].down = &extable[i + 1];
378 *block_count = b_count;
379 return &extable[i]; /* return the next free xtable* */
384 methodinfo *parse(methodinfo *m)
386 int p; /* java instruction counter */
387 int nextp; /* start of next java instruction */
388 int opcode; /* java opcode */
389 int i; /* temporary for different uses (counters) */
390 int ipc = 0; /* intermediate instruction counter */
391 int b_count = 0; /* basic block counter */
392 int s_count = 0; /* stack element counter */
393 bool blockend = false; /* true if basic block end has been reached */
394 bool iswide = false; /* true if last instruction was a wide */
395 instruction *iptr; /* current pointer into instruction array */
396 int gp; /* global java instruction counter */
397 /* inlining info for current method */
398 inlining_methodinfo *inlinfo = inlining_rootinfo;
399 inlining_methodinfo *tmpinlinf;
400 int nextgp = -1; /* start of next method to be inlined */
401 int *label_index = NULL; /* label redirection table */
402 int firstlocal = 0; /* first local variable of method */
403 exceptiontable* nextex; /* points next free entry in extable */
404 u1 *instructionstart; /* 1 for pcs which are valid instr. starts */
414 label_index = inlinfo->label_index;
415 m->maxstack = cummaxstack;
416 m->exceptiontablelength = cumextablelength;
419 useinltmp = useinlining; /* FIXME remove this after debugging */
420 /*useinlining = false;*/ /* and merge the if-statements */
423 cumjcodelength = m->jcodelength;
426 tmpinlinf = (inlining_methodinfo*) list_first(inlinfo->inlinedmethods);
427 if (tmpinlinf != NULL) nextgp = tmpinlinf->startgp;
430 if ((opt_rt || opt_xta || opt_vta) && (pOpcodes == 2 || pOpcodes == 3)) {
431 printf("PARSE method name =");
432 utf_display(m->class->name);
439 if (opt_rt || opt_xta) {
444 printf("VTA requested, but not yet implemented\n");
448 /* allocate instruction array and block index table */
450 /* 1 additional for end ipc and 3 for loop unrolling */
452 m->basicblockindex = DMNEW(int, cumjcodelength + 4);
453 instructionstart = DMNEW(u1, cumjcodelength + 4);
454 memset(instructionstart,0,sizeof(u1) * (cumjcodelength + 4));
456 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
457 /* additional MONITOREXITS are reached by branches which are 3 bytes */
459 iptr = m->instructions = DMNEW(instruction, cumjcodelength + 5);
461 /* Zero the intermediate instructions array so we don't have any
462 * invalid pointers in it if we cannot finish analyse_stack(). */
463 memset(iptr, 0, sizeof(instruction) * (cumjcodelength + 5));
465 /* initialize m->basicblockindex table (unrolled four times) */
470 for (i = 0, ip = m->basicblockindex; i <= cumjcodelength; i += 4, ip += 4) {
478 /* compute branch targets of exception table */
480 /* m->exceptiontable = DMNEW(exceptiontable, m->exceptiontablelength + 1); */
482 for (i = 0; i < method->m->exceptiontablelength; i++) {
484 p = m->exceptiontable[i].startpc = raw_extable[i].startpc;
485 if (useinlining) p = label_index[p];
489 p = m->exceptiontable[i].endpc = raw_extable[i].endpc;
490 if (useinlining) p = label_index[p];
492 if (p < cumjcodelength)
495 p = m->exceptiontable[i].handlerpc = raw_extable[i].handlerpc;
499 m->exceptiontable[i].catchtype = raw_extable[i].catchtype;
501 m->exceptiontable[i].next = NULL;
502 m->exceptiontable[i].down = &m->exceptiontable[i+1];
506 nextex = fillextable(m, m->exceptiontable, m->exceptiontable, m->exceptiontablelength, label_index, &b_count);
508 s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */
511 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
512 m->isleafmethod = false;
516 /* scan all java instructions */
520 if (m->linenumbercount == 0) {
524 linepcchange = m->linenumbers[0].start_pc;
527 for (p = 0, gp = 0; p < m->jcodelength; gp += (nextp - p), p = nextp) {
529 /* DEBUG */ /*printf("p:%d gp:%d ",p,gp);*/
531 /* mark this position as a valid instruction start */
533 instructionstart[gp] = 1;
534 /*log_text("new start of instruction");*/
535 if (linepcchange==p) {
536 if (m->linenumbercount > lineindex) {
537 currentline = m->linenumbers[lineindex].line_number;
539 if (lineindex < m->linenumbercount)
540 linepcchange = m->linenumbers[lineindex].start_pc;
541 /*printf("Line number changed to: %ld\n",currentline);*/
547 if ((useinlining) && (gp == nextgp)) {
549 bool *readonly = NULL;
552 opcode = code_get_u1(p);
553 nextp = p += jcommandsize[opcode];
554 if (nextp > m->jcodelength)
555 panic("Unexpected end of bytecode");
556 tmpinlinf = list_first(inlinfo->inlinedmethods);
557 firstlocal = tmpinlinf->firstlocal;
558 label_index = tmpinlinf->label_index;
559 readonly = tmpinlinf->readonly;
561 for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) {
564 if ((i == 0) && inlineparamopt) {
565 OP1(ICMD_CLEAR_ARGREN, firstlocal);
568 if (!inlineparamopt || !readonly[i]) {
572 op = ICMD_READONLY_ARG;
576 OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i);
578 /* m->basicblockindex[gp] |= (ipc << 1);*/ /*FIXME: necessary ? */
581 inlining_save_compiler_variables();
582 inlining_set_compiler_variables(tmpinlinf);
583 if (compileverbose) {
584 char logtext[MAXLOGTEXT];
585 sprintf(logtext, "Parsing (inlined): ");
586 utf_sprint(logtext+strlen(logtext), m->class->name);
587 strcpy(logtext+strlen(logtext), ".");
588 utf_sprint(logtext+strlen(logtext), m->name);
589 utf_sprint(logtext+strlen(logtext), m->descriptor);
594 if (inlinfo->inlinedmethods == NULL) {
597 tmpinlinf = list_first(inlinfo->inlinedmethods);
598 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
600 if (m->exceptiontablelength > 0)
601 nextex = fillextable(m, nextex, m->exceptiontable, m->exceptiontablelength, label_index, &b_count);
605 opcode = code_get_u1(p); /* fetch op code */
608 if (opt_rt && (pOpcodes == 2 || pOpcodes == 3)) {
609 printf("Parse<%i> p=%i<%i< opcode=<%i> %s\n",
610 pOpcodes, p, rt_jcodelength, opcode, icmd_names[opcode]);
613 m->basicblockindex[gp] |= (ipc << 1); /* store intermediate count */
616 block_insert(gp); /* start new block */
620 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
621 if (nextp > m->jcodelength)
622 panic("Unexpected end of bytecode");
623 s_count += stackreq[opcode]; /* compute stack element count */
629 /* pushing constants onto the stack p */
632 LOADCONST_I(code_get_s1(p+1));
636 LOADCONST_I(code_get_s2(p+1));
640 i = code_get_u1(p+1);
641 goto pushconstantitem;
644 i = code_get_u2(p + 1);
648 if (i >= m->class->cpcount)
649 panic ("Attempt to access constant outside range");
651 switch (m->class->cptags[i]) {
652 case CONSTANT_Integer:
653 LOADCONST_I(((constant_integer *) (m->class->cpinfos[i]))->value);
656 LOADCONST_L(((constant_long *) (m->class->cpinfos[i]))->value);
659 LOADCONST_F(((constant_float *) (m->class->cpinfos[i]))->value);
661 case CONSTANT_Double:
662 LOADCONST_D(((constant_double *) (m->class->cpinfos[i]))->value);
664 case CONSTANT_String:
665 LOADCONST_A(literalstring_new((utf *) (m->class->cpinfos[i])));
667 default: panic("Invalid constant type to push");
671 case JAVA_ACONST_NULL:
682 LOADCONST_I(opcode - JAVA_ICONST_0);
687 LOADCONST_L(opcode - JAVA_LCONST_0);
693 LOADCONST_F(opcode - JAVA_FCONST_0);
698 LOADCONST_D(opcode - JAVA_DCONST_0);
701 /* loading variables onto the stack */
709 i = code_get_u1(p + 1);
711 i = code_get_u2(p + 1);
715 OP1LOAD(opcode, i + firstlocal);
722 OP1LOAD(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
729 OP1LOAD(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
736 OP1LOAD(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
743 OP1LOAD(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
750 OP1LOAD(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
753 /* storing stack values into local variables */
761 i = code_get_u1(p + 1);
763 i = code_get_u2(p + 1);
767 OP1STORE(opcode, i + firstlocal);
774 OP1STORE(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
781 OP1STORE(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
788 OP1STORE(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
795 OP1STORE(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
802 OP1STORE(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
810 i = code_get_u1(p + 1);
811 v = code_get_s1(p + 2);
814 i = code_get_u2(p + 1);
815 v = code_get_s2(p + 3);
819 INDEX_ONEWORD(i + firstlocal);
820 OP2I(opcode, i + firstlocal, v);
824 /* wider index for loading, storing and incrementing */
831 /* managing arrays ************************************************/
835 switch (code_get_s1(p + 1)) {
837 BUILTIN1(BUILTIN_newarray_boolean, TYPE_ADR,currentline);
840 BUILTIN1(BUILTIN_newarray_char, TYPE_ADR,currentline);
843 BUILTIN1(BUILTIN_newarray_float, TYPE_ADR,currentline);
846 BUILTIN1(BUILTIN_newarray_double, TYPE_ADR,currentline);
849 BUILTIN1(BUILTIN_newarray_byte, TYPE_ADR,currentline);
852 BUILTIN1(BUILTIN_newarray_short, TYPE_ADR,currentline);
855 BUILTIN1(BUILTIN_newarray_int, TYPE_ADR,currentline);
858 BUILTIN1(BUILTIN_newarray_long, TYPE_ADR,currentline);
860 default: panic("Invalid array-type to create");
862 OP(ICMD_CHECKEXCEPTION);
867 i = code_get_u2(p + 1);
869 classinfo *component =
870 (classinfo *) class_getconstant(m->class, i, CONSTANT_Class);
872 if (!class_load(component))
875 if (!class_link(component))
878 LOADCONST_A_BUILTIN(class_array_of(component)->vftbl);
879 /* LOADCONST_A_BUILTIN(component); */
881 BUILTIN2(BUILTIN_newarray, TYPE_ADR, currentline);
883 OP(ICMD_CHECKEXCEPTION);
886 case JAVA_MULTIANEWARRAY:
887 m->isleafmethod = false;
888 i = code_get_u2(p + 1);
891 s4 v = code_get_u1(p + 3);
894 /* vftbl *arrayvftbl = */
895 /* ((classinfo *) class_getconstant(class, i, CONSTANT_Class))->vftbl; */
896 /* OP2A(opcode, v, arrayvftbl,currentline); */
899 classinfo *component =
900 (classinfo *) class_getconstant(m->class, i, CONSTANT_Class);
902 if (!class_load(component))
905 if (!class_link(component))
908 arrayvftbl = component->vftbl;
909 OP2A(opcode, v, arrayvftbl, currentline);
911 /* classinfo *arrayclass = */
912 /* (classinfo *) class_getconstant(class, i, CONSTANT_Class); */
913 /* OP2A(opcode, v, arrayclass, currentline); */
935 i = p + code_get_s2(p + 1);
947 i = p + code_get_s4(p + 1);
960 i = code_get_u1(p + 1);
962 i = code_get_u2(p + 1);
969 if (isinlinedmethod) {
970 OP1(ICMD_GOTO, inlinfo->stopgp);
974 OP1LOAD(opcode, i + firstlocal);
983 if (isinlinedmethod) {
984 /* if (p==m->jcodelength-1) {*/ /* return is at end of inlined method */
989 OP1(ICMD_GOTO, inlinfo->stopgp);
1003 /* table jumps ********************************/
1005 case JAVA_LOOKUPSWITCH:
1012 nextp = ALIGN((p + 1), 4);
1013 if (nextp + 8 > m->jcodelength)
1014 panic("Unexpected end of bytecode");
1016 tablep = (s4 *) (m->jcode + nextp);
1019 num = code_get_u4(nextp + 4);
1020 tablep = DMNEW(s4, num * 2 + 2);
1023 OP2A(opcode, 0, tablep,currentline);
1025 /* default target */
1027 j = p + code_get_s4(nextp);
1030 *tablep = j; /* restore for little endian */
1036 /* number of pairs */
1038 num = code_get_u4(nextp);
1043 if (nextp + 8*(num) > m->jcodelength)
1044 panic("Unexpected end of bytecode");
1046 for (i = 0; i < num; i++) {
1049 j = code_get_s4(nextp);
1050 *tablep = j; /* restore for little endian */
1054 /* check if the lookup table is sorted correctly */
1056 if (i && (j <= prevvalue))
1057 panic("invalid LOOKUPSWITCH: table not sorted");
1062 j = p + code_get_s4(nextp);
1065 *tablep = j; /* restore for little endian */
1076 case JAVA_TABLESWITCH:
1082 nextp = ALIGN((p + 1), 4);
1083 if (nextp + 12 > m->jcodelength)
1084 panic("Unexpected end of bytecode");
1086 tablep = (s4 *) (m->jcode + nextp);
1089 num = code_get_u4(nextp + 8) - code_get_u4(nextp + 4);
1090 tablep = DMNEW(s4, num + 1 + 3);
1093 OP2A(opcode, 0, tablep,currentline);
1095 /* default target */
1097 j = p + code_get_s4(nextp);
1100 *tablep = j; /* restore for little endian */
1108 j = code_get_s4(nextp);
1109 *tablep = j; /* restore for little endian */
1115 num = code_get_s4(nextp);
1116 *tablep = num; /* restore for little endian */
1120 num -= j; /* difference of upper - lower */
1122 panic("invalid TABLESWITCH: upper bound < lower bound");
1124 if (nextp + 4*(num+1) > m->jcodelength)
1125 panic("Unexpected end of bytecode");
1127 for (i = 0; i <= num; i++) {
1128 j = p + code_get_s4(nextp);
1131 *tablep = j; /* restore for little endian */
1142 /* load and store of object fields *******************/
1145 BUILTIN3(BUILTIN_aastore, TYPE_VOID, currentline);
1148 case JAVA_PUTSTATIC:
1149 case JAVA_GETSTATIC:
1150 i = code_get_u2(p + 1);
1152 constant_FMIref *fr;
1155 fr = class_getconstant(m->class, i, CONSTANT_Fieldref);
1157 if (!class_load(fr->class))
1160 if (!class_link(fr->class))
1163 fi = class_resolvefield(fr->class,
1172 OP2A(opcode, fi->type, fi, currentline);
1173 if (!fi->class->initialized) {
1174 m->isleafmethod = false;
1181 i = code_get_u2(p + 1);
1183 constant_FMIref *fr;
1186 fr = class_getconstant(m->class, i, CONSTANT_Fieldref);
1188 if (!class_load(fr->class))
1191 if (!class_link(fr->class))
1194 fi = class_resolvefield(fr->class,
1203 OP2A(opcode, fi->type, fi, currentline);
1208 /* method invocation *****/
1210 case JAVA_INVOKESTATIC:
1211 i = code_get_u2(p + 1);
1213 constant_FMIref *mr;
1216 m->isleafmethod = false;
1218 mr = class_getconstant(m->class, i, CONSTANT_Methodref);
1220 if (!class_load(mr->class))
1223 if (!class_link(mr->class))
1226 mi = class_resolveclassmethod(mr->class,
1235 /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt)
1236 /*RTAprint*/ {printf(" method name =");
1237 /*RTAprint*/ utf_display(mi->class->name); printf(".");
1238 /*RTAprint*/ utf_display(mi->name);printf("\tINVOKE STATIC\n");
1239 /*RTAprint*/ fflush(stdout);}
1241 if (!(mi->flags & ACC_STATIC)) {
1243 new_exception(string_java_lang_IncompatibleClassChangeError);
1247 descriptor2types(mi);
1248 OP2A(opcode, mi->paramcount, mi, currentline);
1252 case JAVA_INVOKESPECIAL:
1253 case JAVA_INVOKEVIRTUAL:
1254 i = code_get_u2(p + 1);
1256 constant_FMIref *mr;
1259 m->isleafmethod = false;
1261 mr = class_getconstant(m->class, i, CONSTANT_Methodref);
1263 if (!class_load(mr->class))
1266 if (!class_link(mr->class))
1269 mi = class_resolveclassmethod(mr->class,
1278 /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt)
1279 /*RTAprint*/ {printf(" method name =");
1281 /*RTAprint*/ utf_display(mi->class->name); printf(".");
1282 /*RTAprint*/ utf_display(mi->name);printf("\tINVOKE SPECIAL/VIRTUAL\n");
1283 /*RTAprint*/ fflush(stdout);}
1285 if (mi->flags & ACC_STATIC) {
1287 new_exception(string_java_lang_IncompatibleClassChangeError);
1291 descriptor2types(mi);
1292 OP2A(opcode, mi->paramcount, mi, currentline);
1296 case JAVA_INVOKEINTERFACE:
1297 i = code_get_u2(p + 1);
1299 constant_FMIref *mr;
1302 m->isleafmethod = false;
1304 mr = class_getconstant(m->class, i, CONSTANT_InterfaceMethodref);
1306 if (!class_load(mr->class))
1309 if (!class_link(mr->class))
1312 mi = class_resolveinterfacemethod(mr->class,
1320 if (mi->flags & ACC_STATIC) {
1322 new_exception(string_java_lang_IncompatibleClassChangeError);
1326 descriptor2types(mi);
1327 OP2A(opcode, mi->paramcount, mi, currentline);
1331 /* miscellaneous object operations *******/
1334 i = code_get_u2(p + 1);
1335 LOADCONST_A_BUILTIN(class_getconstant(m->class, i, CONSTANT_Class));
1337 BUILTIN1(BUILTIN_new, TYPE_ADR, currentline);
1338 OP(ICMD_CHECKEXCEPTION);
1341 case JAVA_CHECKCAST:
1342 i = code_get_u2(p + 1);
1345 (classinfo *) class_getconstant(m->class, i, CONSTANT_Class);
1348 if (!class_load(cls))
1352 if (!class_link(cls))
1355 if (cls->vftbl->arraydesc) {
1356 /* array type cast-check */
1357 LOADCONST_A_BUILTIN(cls->vftbl);
1359 BUILTIN2(BUILTIN_checkarraycast, TYPE_ADR,currentline);
1361 } else { /* object type cast-check */
1363 + LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
1365 + BUILTIN2(BUILTIN_checkcast, TYPE_ADR,currentline);
1367 OP2A(opcode, 1, cls, currentline);
1372 case JAVA_INSTANCEOF:
1373 i = code_get_u2(p + 1);
1376 (classinfo *) class_getconstant(m->class, i, CONSTANT_Class);
1379 if (!class_load(cls))
1383 if (!class_link(cls))
1386 if (cls->vftbl->arraydesc) {
1387 /* array type cast-check */
1388 LOADCONST_A_BUILTIN(cls->vftbl);
1390 BUILTIN2(BUILTIN_arrayinstanceof, TYPE_INT, currentline);
1392 else { /* object type cast-check */
1394 LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
1396 BUILTIN2(BUILTIN_instanceof, TYPE_INT,currentline);
1398 OP2A(opcode, 1, cls, currentline);
1403 case JAVA_MONITORENTER:
1406 BUILTIN1(BUILTIN_monitorenter, TYPE_VOID,currentline);
1410 OP(ICMD_NULLCHECKPOP);
1414 case JAVA_MONITOREXIT:
1417 BUILTIN1(BUILTIN_monitorexit, TYPE_VOID,currentline);
1426 /* any other basic operation **************************************/
1445 #if defined(__I386__)
1448 BUILTIN2(BUILTIN_frem, TYPE_FLOAT,currentline);
1453 #if defined(__I386__)
1456 BUILTIN2(BUILTIN_drem, TYPE_DOUBLE,currentline);
1461 #if defined(__ALPHA__)
1463 BUILTIN1(BUILTIN_f2i, TYPE_INT,currentline);
1472 #if defined(__ALPHA__)
1474 BUILTIN1(BUILTIN_f2l, TYPE_LONG,currentline);
1483 #if defined(__ALPHA__)
1485 BUILTIN1(BUILTIN_d2i, TYPE_INT,currentline);
1494 #if defined(__ALPHA__)
1496 BUILTIN1(BUILTIN_d2l, TYPE_LONG,currentline);
1504 case JAVA_BREAKPOINT:
1505 panic("Illegal opcode Breakpoint encountered");
1508 case 204: /* unused opcode */
1560 printf("Illegal opcode %d at instr %d\n", opcode, ipc);
1561 panic("Illegal opcode encountered");
1570 /* If WIDE was used correctly, iswide should have been reset by now. */
1571 if (iswide && opcode != JAVA_WIDE)
1572 panic("Illegal instruction: WIDE before incompatible opcode");
1576 if (isinlinedmethod && p == m->jcodelength - 1) { /* end of an inlined method */
1577 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1578 gp = inlinfo->stopgp;
1579 inlining_restore_compiler_variables();
1580 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1581 if (inlinfo->inlinedmethods == NULL) {
1584 tmpinlinf = list_first(inlinfo->inlinedmethods);
1585 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1587 /* printf("nextpgp: %d\n", nextgp); */
1588 label_index=inlinfo->label_index;
1589 firstlocal = inlinfo->firstlocal;
1593 if (p != m->jcodelength)
1594 panic("Command-sequence crosses code-boundary");
1597 panic("Code does not end with branch/return/athrow - stmt");
1599 /* adjust block count if target 0 is not first intermediate instruction */
1601 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1))
1604 /* copy local to global variables */
1606 m->instructioncount = ipc;
1607 m->basicblockcount = b_count;
1608 m->stackcount = s_count + m->basicblockcount * m->maxstack;
1610 /* allocate stack table */
1612 m->stack = DMNEW(stackelement, m->stackcount);
1617 bptr = m->basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1622 /* additional block if target 0 is not first intermediate instruction */
1624 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) {
1625 bptr->iinstr = m->instructions;
1628 bptr->type = BBTYPE_STD;
1629 bptr->branchrefs = NULL;
1630 bptr->pre_count = 0;
1631 bptr->debug_nr = c_debug_nr++;
1634 (bptr - 1)->next = bptr;
1637 /* allocate blocks */
1639 for (p = 0; p < cumjcodelength; p++) {
1640 if (m->basicblockindex[p] & 1) {
1641 /* check if this block starts at the beginning of an instruction */
1642 if (!instructionstart[p])
1643 panic("Branch into middle of instruction");
1644 /* allocate the block */
1645 bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
1646 bptr->debug_nr = c_debug_nr++;
1648 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1652 bptr->type = BBTYPE_STD;
1653 bptr->branchrefs = NULL;
1654 m->basicblockindex[p] = b_count;
1655 bptr->pre_count = 0;
1658 (bptr - 1)->next = bptr;
1662 /* allocate additional block at end */
1664 bptr->instack = bptr->outstack = NULL;
1665 bptr->indepth = bptr->outdepth = 0;
1666 bptr->iinstr = NULL;
1667 (bptr - 1)->icount = (m->instructions + m->instructioncount) - (bptr - 1)->iinstr;
1672 bptr->type = BBTYPE_STD;
1673 bptr->branchrefs = NULL;
1674 bptr->pre_count = 0;
1675 bptr->debug_nr = c_debug_nr++;
1676 (bptr - 1)->next = bptr;
1679 if (m->exceptiontablelength > 0) {
1680 m->exceptiontable[m->exceptiontablelength - 1].down = NULL;
1683 m->exceptiontable = NULL;
1686 for (i = 0; i < m->exceptiontablelength; ++i) {
1687 p = m->exceptiontable[i].startpc;
1688 m->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1690 p = m->exceptiontable[i].endpc;
1691 m->exceptiontable[i].end = (p == cumjcodelength) ? (m->basicblocks + m->basicblockcount + 1) : (m->basicblocks + m->basicblockindex[p]);
1693 p = m->exceptiontable[i].handlerpc;
1694 m->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1698 if (useinlining) inlining_cleanup();
1699 useinlining = useinltmp;
1701 /* just return methodinfo* to signal everything was ok */
1708 * These are local overrides for various environment variables in Emacs.
1709 * Please do not remove this and leave it at the end of the file, where
1710 * Emacs will automagically detect them.
1711 * ---------------------------------------------------------------------
1714 * indent-tabs-mode: t