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 1373 2004-08-01 21:56:36Z stefan $
43 #include "loop/loop.h"
46 #include "exceptions.h"
51 #include "statistics.h"
52 #include "toolbox/memory.h"
53 #include "toolbox/logging.h"
56 /* data about the currently parsed method */
58 classinfo *rt_class; /* class the compiled method belongs to */
59 methodinfo *rt_method; /* pointer to method info of compiled method */
60 utf *rt_descriptor; /* type descriptor of compiled method */
61 int rt_jcodelength; /* length of JavaVM-codes */
62 u1 *rt_jcode; /* pointer to start of JavaVM-code */
68 /*#define debug_writebranch printf("op: %s i: %d label_index[i]: %d\n",icmd_names[opcode], i, label_index[i]);*/
69 #define debug_writebranch
72 /* function descriptor2typesL ***************************************************
74 decodes a already checked method descriptor. The parameter count, the
75 return type and the argument types are stored in the passed methodinfo.
76 gets and saves classptr for object ref.s
78 *******************************************************************************/
80 classSetNode *descriptor2typesL(methodinfo *m)
87 classinfo** classtypes;
92 printf("In descriptor2typesL >>>\t"); fflush(stdout);
93 utf_display(m->class->name); printf(".");
94 method_display(m);fflush(stdout);
98 desc = MNEW (char, 256);
99 types = DMNEW (u1, m->descriptor->blength);
100 classtypes = MNEW (classinfo*, m->descriptor->blength+1);
101 m->returnclass = NULL;
103 if (!(m->flags & ACC_STATIC)) {
105 if (debugInfo >= 1) {
106 printf("param #0 (this?) method class =");utf_display(m->class->name);printf("\n");
108 classtypes[pcount] = m->class;
109 p = addClassCone(p, m->class);
113 utf_ptr = m->descriptor->text + 1;
114 strcpy (desc,utf_ptr);
116 while ((c = *desc++) != ')') {
123 case 'Z': *tptr++ = TYPE_INT;
125 case 'J': *tptr++ = TYPE_LNG;
127 case 'F': *tptr++ = TYPE_FLT;
129 case 'D': *tptr++ = TYPE_DBL;
131 case 'L': *tptr++ = TYPE_ADR;
132 /* get class string */
133 class = strtok(desc,";");
134 desc = strtok(NULL,"\0");
135 /* get/save classinfo ptr */
136 classtypes[pcount-1] = class_get(utf_new_char(class));
137 p = addClassCone(p, class_get(utf_new_char(class)));
138 if (debugInfo >= 1) {
139 printf("LParam#%i 's class type is: %s\n",pcount-1,class);fflush(stdout);
140 printf("Lclasstypes[%i]=",pcount-1);fflush(stdout);
141 utf_display(classtypes[pcount-1]->name);
144 case '[': *tptr++ = TYPE_ADR;
147 /* get class string */
149 class = strtok(desc,";");
150 desc = strtok(NULL,"\0");
151 /* get/save classinfo ptr */
152 classtypes[pcount-1] = class_get(utf_new_char(class));
153 p= addClassCone(p, class_get(utf_new_char(class)));
154 if (debugInfo >= 1) {
155 printf("[Param#%i 's class type is: %s\n",pcount-1,class);
156 printf("[classtypes[%i]=",pcount-1);fflush(stdout);
157 utf_display(classtypes[pcount-1]->name);
162 classtypes[pcount-1] = NULL;
165 panic("Ill formed methodtype-descriptor");
169 /* compute return type */
175 case 'Z': m->returntype = TYPE_INT;
177 case 'J': m->returntype = TYPE_LNG;
179 case 'F': m->returntype = TYPE_FLT;
181 case 'D': m->returntype = TYPE_DBL;
184 m->returntype = TYPE_ADR;
192 m->returntype = TYPE_ADR;
194 /* get class string */
195 class = strtok(desc,";");
196 m->returnclass = class_get(utf_new_char(class));
197 if (m->returnclass == NULL) {
198 printf("class=%s :\t",class);
199 panic ("return class not found");
202 case 'V': m->returntype = TYPE_VOID;
205 default: panic("Ill formed methodtype-descriptor-ReturnType");
208 m->paramcount = pcount;
209 m->paramtypes = types;
210 m->paramclass = classtypes;
214 for (i=0; i< m->paramcount; i++) {
215 if ((m->paramtypes[i] == TYPE_ADR) && (m->paramclass[i] != NULL)) {
216 printf("Param #%i is:\t",i);
217 utf_display(m->paramclass[i]->name);
222 if ((m->returntype == TYPE_ADR) && (m->returnclass != NULL)) {
223 printf("\tReturn Type is:\t"); fflush(stdout);
224 utf_display(m->returnclass->name);
228 printf("params2types: START results in a set \n");
229 printf("param2types: A Set size=%i=\n",sizeOfSet(p));
238 /* function descriptor2types ***************************************************
240 decodes a already checked method descriptor. The parameter count, the
241 return type and the argument types are stored in the passed methodinfo.
243 *******************************************************************************/
245 void descriptor2types(methodinfo *m)
251 types = DMNEW(u1, m->descriptor->blength);
254 if (!(m->flags & ACC_STATIC)) {
259 utf_ptr = m->descriptor->text + 1;
261 while ((c = *utf_ptr++) != ')') {
282 while (*utf_ptr++ != ';');
289 while (*utf_ptr++ != ';') /* skip */;
292 panic("Ill formed methodtype-descriptor");
296 /* compute return type */
298 switch (*utf_ptr++) {
304 m->returntype = TYPE_INT;
307 m->returntype = TYPE_LNG;
310 m->returntype = TYPE_FLT;
313 m->returntype = TYPE_DBL;
317 m->returntype = TYPE_ADR;
320 m->returntype = TYPE_VOID;
323 panic("Ill formed methodtype-descriptor");
326 m->paramcount = pcount;
327 m->paramtypes = types;
332 /*******************************************************************************
334 function 'parse' scans the JavaVM code and generates intermediate code
336 During parsing the block index table is used to store at bit pos 0
337 a flag which marks basic block starts and at position 1 to 31 the
338 intermediate instruction index. After parsing the block index table
339 is scanned, for marked positions a block is generated and the block
340 number is stored in the block index table.
342 *******************************************************************************/
344 static exceptiontable* fillextable(methodinfo *m, exceptiontable* extable, exceptiontable *raw_extable, int exceptiontablelength, int *label_index, int *block_count)
348 if (exceptiontablelength == 0)
351 b_count = *block_count;
353 for (i = 0; i < exceptiontablelength; i++) {
354 p = raw_extable[i].startpc;
355 if (label_index != NULL) p = label_index[p];
356 extable[i].startpc = p;
360 p = raw_extable[i].endpc;
361 if (p <= raw_extable[i].startpc)
362 panic("Invalid exception handler range");
363 if (label_index != NULL) p = label_index[p];
364 extable[i].endpc = p;
366 if (p < m->jcodelength)
369 p = raw_extable[i].handlerpc;
370 if (label_index != NULL) p = label_index[p];
371 extable[i].handlerpc = p;
375 extable[i].catchtype = raw_extable[i].catchtype;
376 extable[i].next = NULL;
377 extable[i].down = &extable[i + 1];
380 *block_count = b_count;
381 return &extable[i]; /* return the next free xtable* */
386 methodinfo *parse(methodinfo *m)
388 int p; /* java instruction counter */
389 int nextp; /* start of next java instruction */
390 int opcode; /* java opcode */
391 int i; /* temporary for different uses (counters) */
392 int ipc = 0; /* intermediate instruction counter */
393 int b_count = 0; /* basic block counter */
394 int s_count = 0; /* stack element counter */
395 bool blockend = false; /* true if basic block end has been reached */
396 bool iswide = false; /* true if last instruction was a wide */
397 instruction *iptr; /* current pointer into instruction array */
398 int gp; /* global java instruction counter */
399 /* inlining info for current method */
400 inlining_methodinfo *inlinfo = inlining_rootinfo;
401 inlining_methodinfo *tmpinlinf;
402 int nextgp = -1; /* start of next method to be inlined */
403 int *label_index = NULL; /* label redirection table */
404 int firstlocal = 0; /* first local variable of method */
405 exceptiontable* nextex; /* points next free entry in extable */
406 u1 *instructionstart; /* 1 for pcs which are valid instr. starts */
416 label_index = inlinfo->label_index;
417 m->maxstack = cummaxstack;
418 m->exceptiontablelength = cumextablelength;
421 useinltmp = useinlining; /* FIXME remove this after debugging */
422 /*useinlining = false;*/ /* and merge the if-statements */
425 /* cumjcodelength = m->jcodelength; */
428 tmpinlinf = (inlining_methodinfo*) list_first(inlinfo->inlinedmethods);
429 if (tmpinlinf != NULL) nextgp = tmpinlinf->startgp;
432 if ((opt_rt || opt_xta || opt_vta) && (pOpcodes == 2 || pOpcodes == 3)) {
433 printf("PARSE method name =");
434 utf_display(m->class->name);
441 if (opt_rt || opt_xta) {
446 printf("VTA requested, but not yet implemented\n");
450 /* allocate instruction array and block index table */
452 /* 1 additional for end ipc */
454 m->basicblockindex = DMNEW(s4, m->jcodelength + 1);
455 memset(m->basicblockindex, 0, sizeof(s4) * (m->jcodelength + 1));
457 instructionstart = DMNEW(u1, m->jcodelength + 1);
458 memset(instructionstart, 0, sizeof(u1) * (m->jcodelength + 1));
460 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
461 /* additional MONITOREXITS are reached by branches which are 3 bytes */
463 iptr = m->instructions = DMNEW(instruction, m->jcodelength + 5);
465 /* Zero the intermediate instructions array so we don't have any
466 * invalid pointers in it if we cannot finish analyse_stack(). */
468 memset(iptr, 0, sizeof(instruction) * (m->jcodelength + 5));
470 /* compute branch targets of exception table */
472 /* m->exceptiontable = DMNEW(exceptiontable, m->exceptiontablelength + 1); */
474 for (i = 0; i < method->m->exceptiontablelength; i++) {
476 p = m->exceptiontable[i].startpc = raw_extable[i].startpc;
477 if (useinlining) p = label_index[p];
481 p = m->exceptiontable[i].endpc = raw_extable[i].endpc;
482 if (useinlining) p = label_index[p];
484 if (p < cumjcodelength)
487 p = m->exceptiontable[i].handlerpc = raw_extable[i].handlerpc;
491 m->exceptiontable[i].catchtype = raw_extable[i].catchtype;
493 m->exceptiontable[i].next = NULL;
494 m->exceptiontable[i].down = &m->exceptiontable[i+1];
498 nextex = fillextable(m, m->exceptiontable, m->exceptiontable, m->exceptiontablelength, label_index, &b_count);
500 s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */
503 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
504 m->isleafmethod = false;
508 /* scan all java instructions */
512 if (m->linenumbercount == 0) {
516 linepcchange = m->linenumbers[0].start_pc;
519 for (p = 0, gp = 0; p < m->jcodelength; gp += (nextp - p), p = nextp) {
521 /* DEBUG */ /*printf("p:%d gp:%d ",p,gp);*/
523 /* mark this position as a valid instruction start */
525 instructionstart[gp] = 1;
526 /*log_text("new start of instruction");*/
527 if (linepcchange==p) {
528 if (m->linenumbercount > lineindex) {
529 currentline = m->linenumbers[lineindex].line_number;
531 if (lineindex < m->linenumbercount)
532 linepcchange = m->linenumbers[lineindex].start_pc;
533 /*printf("Line number changed to: %ld\n",currentline);*/
539 if ((useinlining) && (gp == nextgp)) {
541 bool *readonly = NULL;
544 opcode = code_get_u1(p);
545 nextp = p += jcommandsize[opcode];
546 if (nextp > m->jcodelength)
547 panic("Unexpected end of bytecode");
548 tmpinlinf = list_first(inlinfo->inlinedmethods);
549 firstlocal = tmpinlinf->firstlocal;
550 label_index = tmpinlinf->label_index;
551 readonly = tmpinlinf->readonly;
553 for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) {
556 if ((i == 0) && inlineparamopt) {
557 OP1(ICMD_CLEAR_ARGREN, firstlocal);
560 if (!inlineparamopt || !readonly[i]) {
564 op = ICMD_READONLY_ARG;
568 OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i);
570 /* m->basicblockindex[gp] |= (ipc << 1);*/ /*FIXME: necessary ? */
573 inlining_save_compiler_variables();
574 inlining_set_compiler_variables(tmpinlinf);
575 if (compileverbose) {
576 char logtext[MAXLOGTEXT];
577 sprintf(logtext, "Parsing (inlined): ");
578 utf_sprint(logtext+strlen(logtext), m->class->name);
579 strcpy(logtext+strlen(logtext), ".");
580 utf_sprint(logtext+strlen(logtext), m->name);
581 utf_sprint(logtext+strlen(logtext), m->descriptor);
586 if (inlinfo->inlinedmethods == NULL) {
589 tmpinlinf = list_first(inlinfo->inlinedmethods);
590 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
592 if (m->exceptiontablelength > 0)
593 nextex = fillextable(m, nextex, m->exceptiontable, m->exceptiontablelength, label_index, &b_count);
597 opcode = code_get_u1(p); /* fetch op code */
600 if (opt_rt && (pOpcodes == 2 || pOpcodes == 3)) {
601 printf("Parse<%i> p=%i<%i< opcode=<%i> %s\n",
602 pOpcodes, p, rt_jcodelength, opcode, icmd_names[opcode]);
605 m->basicblockindex[gp] |= (ipc << 1); /* store intermediate count */
608 block_insert(gp); /* start new block */
612 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
613 if (nextp > m->jcodelength)
614 panic("Unexpected end of bytecode");
615 s_count += stackreq[opcode]; /* compute stack element count */
621 /* pushing constants onto the stack p */
624 LOADCONST_I(code_get_s1(p+1));
628 LOADCONST_I(code_get_s2(p+1));
632 i = code_get_u1(p+1);
633 goto pushconstantitem;
636 i = code_get_u2(p + 1);
640 if (i >= m->class->cpcount)
641 panic ("Attempt to access constant outside range");
643 switch (m->class->cptags[i]) {
644 case CONSTANT_Integer:
645 LOADCONST_I(((constant_integer *) (m->class->cpinfos[i]))->value);
648 LOADCONST_L(((constant_long *) (m->class->cpinfos[i]))->value);
651 LOADCONST_F(((constant_float *) (m->class->cpinfos[i]))->value);
653 case CONSTANT_Double:
654 LOADCONST_D(((constant_double *) (m->class->cpinfos[i]))->value);
656 case CONSTANT_String:
657 LOADCONST_A(literalstring_new((utf *) (m->class->cpinfos[i])));
659 default: panic("Invalid constant type to push");
663 case JAVA_ACONST_NULL:
674 LOADCONST_I(opcode - JAVA_ICONST_0);
679 LOADCONST_L(opcode - JAVA_LCONST_0);
685 LOADCONST_F(opcode - JAVA_FCONST_0);
690 LOADCONST_D(opcode - JAVA_DCONST_0);
693 /* loading variables onto the stack */
701 i = code_get_u1(p + 1);
703 i = code_get_u2(p + 1);
707 OP1LOAD(opcode, i + firstlocal);
714 OP1LOAD(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
721 OP1LOAD(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
728 OP1LOAD(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
735 OP1LOAD(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
742 OP1LOAD(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
745 /* storing stack values into local variables */
753 i = code_get_u1(p + 1);
755 i = code_get_u2(p + 1);
759 OP1STORE(opcode, i + firstlocal);
766 OP1STORE(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
773 OP1STORE(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
780 OP1STORE(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
787 OP1STORE(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
794 OP1STORE(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
802 i = code_get_u1(p + 1);
803 v = code_get_s1(p + 2);
806 i = code_get_u2(p + 1);
807 v = code_get_s2(p + 3);
811 INDEX_ONEWORD(i + firstlocal);
812 OP2I(opcode, i + firstlocal, v);
816 /* wider index for loading, storing and incrementing */
823 /* managing arrays ************************************************/
827 switch (code_get_s1(p + 1)) {
829 BUILTIN1(BUILTIN_newarray_boolean, TYPE_ADR,currentline);
832 BUILTIN1(BUILTIN_newarray_char, TYPE_ADR,currentline);
835 BUILTIN1(BUILTIN_newarray_float, TYPE_ADR,currentline);
838 BUILTIN1(BUILTIN_newarray_double, TYPE_ADR,currentline);
841 BUILTIN1(BUILTIN_newarray_byte, TYPE_ADR,currentline);
844 BUILTIN1(BUILTIN_newarray_short, TYPE_ADR,currentline);
847 BUILTIN1(BUILTIN_newarray_int, TYPE_ADR,currentline);
850 BUILTIN1(BUILTIN_newarray_long, TYPE_ADR,currentline);
852 default: panic("Invalid array-type to create");
854 OP(ICMD_CHECKEXCEPTION);
859 i = code_get_u2(p + 1);
861 classinfo *component =
862 (classinfo *) class_getconstant(m->class, i, CONSTANT_Class);
864 if (!class_load(component))
867 if (!class_link(component))
870 LOADCONST_A_BUILTIN(class_array_of(component)->vftbl);
871 /* LOADCONST_A_BUILTIN(component); */
873 BUILTIN2(BUILTIN_newarray, TYPE_ADR, currentline);
875 OP(ICMD_CHECKEXCEPTION);
878 case JAVA_MULTIANEWARRAY:
879 m->isleafmethod = false;
880 i = code_get_u2(p + 1);
883 s4 v = code_get_u1(p + 3);
886 /* vftbl *arrayvftbl = */
887 /* ((classinfo *) class_getconstant(class, i, CONSTANT_Class))->vftbl; */
888 /* OP2A(opcode, v, arrayvftbl,currentline); */
891 classinfo *component =
892 (classinfo *) class_getconstant(m->class, i, CONSTANT_Class);
894 if (!class_load(component))
897 if (!class_link(component))
900 arrayvftbl = component->vftbl;
901 OP2A(opcode, v, arrayvftbl, currentline);
903 /* classinfo *arrayclass = */
904 /* (classinfo *) class_getconstant(class, i, CONSTANT_Class); */
905 /* OP2A(opcode, v, arrayclass, currentline); */
927 i = p + code_get_s2(p + 1);
939 i = p + code_get_s4(p + 1);
952 i = code_get_u1(p + 1);
954 i = code_get_u2(p + 1);
961 if (isinlinedmethod) {
962 OP1(ICMD_GOTO, inlinfo->stopgp);
966 OP1LOAD(opcode, i + firstlocal);
975 if (isinlinedmethod) {
976 /* if (p==m->jcodelength-1) {*/ /* return is at end of inlined method */
981 OP1(ICMD_GOTO, inlinfo->stopgp);
995 /* table jumps ********************************/
997 case JAVA_LOOKUPSWITCH:
1004 nextp = ALIGN((p + 1), 4);
1005 if (nextp + 8 > m->jcodelength)
1006 panic("Unexpected end of bytecode");
1008 tablep = (s4 *) (m->jcode + nextp);
1011 num = code_get_u4(nextp + 4);
1012 tablep = DMNEW(s4, num * 2 + 2);
1015 OP2A(opcode, 0, tablep,currentline);
1017 /* default target */
1019 j = p + code_get_s4(nextp);
1022 *tablep = j; /* restore for little endian */
1028 /* number of pairs */
1030 num = code_get_u4(nextp);
1035 if (nextp + 8*(num) > m->jcodelength)
1036 panic("Unexpected end of bytecode");
1038 for (i = 0; i < num; i++) {
1041 j = code_get_s4(nextp);
1042 *tablep = j; /* restore for little endian */
1046 /* check if the lookup table is sorted correctly */
1048 if (i && (j <= prevvalue))
1049 panic("invalid LOOKUPSWITCH: table not sorted");
1054 j = p + code_get_s4(nextp);
1057 *tablep = j; /* restore for little endian */
1068 case JAVA_TABLESWITCH:
1074 nextp = ALIGN((p + 1), 4);
1075 if (nextp + 12 > m->jcodelength)
1076 panic("Unexpected end of bytecode");
1078 tablep = (s4 *) (m->jcode + nextp);
1081 num = code_get_u4(nextp + 8) - code_get_u4(nextp + 4);
1082 tablep = DMNEW(s4, num + 1 + 3);
1085 OP2A(opcode, 0, tablep,currentline);
1087 /* default target */
1089 j = p + code_get_s4(nextp);
1092 *tablep = j; /* restore for little endian */
1100 j = code_get_s4(nextp);
1101 *tablep = j; /* restore for little endian */
1107 num = code_get_s4(nextp);
1108 *tablep = num; /* restore for little endian */
1112 num -= j; /* difference of upper - lower */
1114 panic("invalid TABLESWITCH: upper bound < lower bound");
1116 if (nextp + 4*(num+1) > m->jcodelength)
1117 panic("Unexpected end of bytecode");
1119 for (i = 0; i <= num; i++) {
1120 j = p + code_get_s4(nextp);
1123 *tablep = j; /* restore for little endian */
1134 /* load and store of object fields *******************/
1137 BUILTIN3(BUILTIN_aastore, TYPE_VOID, currentline);
1140 case JAVA_PUTSTATIC:
1141 case JAVA_GETSTATIC:
1142 i = code_get_u2(p + 1);
1144 constant_FMIref *fr;
1147 fr = class_getconstant(m->class, i, CONSTANT_Fieldref);
1149 if (!class_load(fr->class))
1152 if (!class_link(fr->class))
1155 fi = class_resolvefield(fr->class,
1164 OP2A(opcode, fi->type, fi, currentline);
1165 if (!fi->class->initialized) {
1166 m->isleafmethod = false;
1173 i = code_get_u2(p + 1);
1175 constant_FMIref *fr;
1178 fr = class_getconstant(m->class, i, CONSTANT_Fieldref);
1180 if (!class_load(fr->class))
1183 if (!class_link(fr->class))
1186 fi = class_resolvefield(fr->class,
1195 OP2A(opcode, fi->type, fi, currentline);
1200 /* method invocation *****/
1202 case JAVA_INVOKESTATIC:
1203 i = code_get_u2(p + 1);
1205 constant_FMIref *mr;
1208 m->isleafmethod = false;
1210 mr = class_getconstant(m->class, i, CONSTANT_Methodref);
1212 if (!class_load(mr->class))
1215 if (!class_link(mr->class))
1218 mi = class_resolveclassmethod(mr->class,
1227 /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt)
1228 /*RTAprint*/ {printf(" method name =");
1229 /*RTAprint*/ utf_display(mi->class->name); printf(".");
1230 /*RTAprint*/ utf_display(mi->name);printf("\tINVOKE STATIC\n");
1231 /*RTAprint*/ fflush(stdout);}
1233 if (!(mi->flags & ACC_STATIC)) {
1235 new_exception(string_java_lang_IncompatibleClassChangeError);
1239 descriptor2types(mi);
1240 OP2A(opcode, mi->paramcount, mi, currentline);
1244 case JAVA_INVOKESPECIAL:
1245 case JAVA_INVOKEVIRTUAL:
1246 i = code_get_u2(p + 1);
1248 constant_FMIref *mr;
1251 m->isleafmethod = false;
1253 mr = class_getconstant(m->class, i, CONSTANT_Methodref);
1255 if (!class_load(mr->class))
1258 if (!class_link(mr->class))
1261 mi = class_resolveclassmethod(mr->class,
1270 /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt)
1271 /*RTAprint*/ {printf(" method name =");
1273 /*RTAprint*/ utf_display(mi->class->name); printf(".");
1274 /*RTAprint*/ utf_display(mi->name);printf("\tINVOKE SPECIAL/VIRTUAL\n");
1275 /*RTAprint*/ fflush(stdout);}
1277 if (mi->flags & ACC_STATIC) {
1279 new_exception(string_java_lang_IncompatibleClassChangeError);
1283 descriptor2types(mi);
1284 OP2A(opcode, mi->paramcount, mi, currentline);
1288 case JAVA_INVOKEINTERFACE:
1289 i = code_get_u2(p + 1);
1291 constant_FMIref *mr;
1294 m->isleafmethod = false;
1296 mr = class_getconstant(m->class, i, CONSTANT_InterfaceMethodref);
1298 if (!class_load(mr->class))
1301 if (!class_link(mr->class))
1304 mi = class_resolveinterfacemethod(mr->class,
1312 if (mi->flags & ACC_STATIC) {
1314 new_exception(string_java_lang_IncompatibleClassChangeError);
1318 descriptor2types(mi);
1319 OP2A(opcode, mi->paramcount, mi, currentline);
1323 /* miscellaneous object operations *******/
1326 i = code_get_u2(p + 1);
1327 LOADCONST_A_BUILTIN(class_getconstant(m->class, i, CONSTANT_Class));
1329 BUILTIN1(BUILTIN_new, TYPE_ADR, currentline);
1330 OP(ICMD_CHECKEXCEPTION);
1333 case JAVA_CHECKCAST:
1334 i = code_get_u2(p + 1);
1337 (classinfo *) class_getconstant(m->class, i, CONSTANT_Class);
1340 if (!class_load(cls))
1344 if (!class_link(cls))
1347 if (cls->vftbl->arraydesc) {
1348 /* array type cast-check */
1349 LOADCONST_A_BUILTIN(cls->vftbl);
1351 BUILTIN2(BUILTIN_checkarraycast, TYPE_ADR,currentline);
1353 } else { /* object type cast-check */
1355 + LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
1357 + BUILTIN2(BUILTIN_checkcast, TYPE_ADR,currentline);
1359 OP2A(opcode, 1, cls, currentline);
1364 case JAVA_INSTANCEOF:
1365 i = code_get_u2(p + 1);
1368 (classinfo *) class_getconstant(m->class, i, CONSTANT_Class);
1371 if (!class_load(cls))
1375 if (!class_link(cls))
1378 if (cls->vftbl->arraydesc) {
1379 /* array type cast-check */
1380 LOADCONST_A_BUILTIN(cls->vftbl);
1382 BUILTIN2(BUILTIN_arrayinstanceof, TYPE_INT, currentline);
1384 else { /* object type cast-check */
1386 LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
1388 BUILTIN2(BUILTIN_instanceof, TYPE_INT,currentline);
1390 OP2A(opcode, 1, cls, currentline);
1395 case JAVA_MONITORENTER:
1398 BUILTIN1(BUILTIN_monitorenter, TYPE_VOID,currentline);
1402 OP(ICMD_NULLCHECKPOP);
1406 case JAVA_MONITOREXIT:
1409 BUILTIN1(BUILTIN_monitorexit, TYPE_VOID,currentline);
1410 OP(ICMD_CHECKEXCEPTION);
1418 /* any other basic operation **************************************/
1437 #if defined(__I386__)
1440 BUILTIN2(BUILTIN_frem, TYPE_FLOAT,currentline);
1445 #if defined(__I386__)
1448 BUILTIN2(BUILTIN_drem, TYPE_DOUBLE,currentline);
1453 #if defined(__ALPHA__)
1455 BUILTIN1(BUILTIN_f2i, TYPE_INT,currentline);
1464 #if defined(__ALPHA__)
1466 BUILTIN1(BUILTIN_f2l, TYPE_LONG,currentline);
1475 #if defined(__ALPHA__)
1477 BUILTIN1(BUILTIN_d2i, TYPE_INT,currentline);
1486 #if defined(__ALPHA__)
1488 BUILTIN1(BUILTIN_d2l, TYPE_LONG,currentline);
1496 case JAVA_BREAKPOINT:
1498 new_verifyerror(m, "Quick instructions shouldn't appear yet.");
1501 case 204: /* unused opcode */
1553 printf("Illegal opcode %d at instr %d\n", opcode, ipc);
1554 panic("Illegal opcode encountered");
1563 /* If WIDE was used correctly, iswide should have been reset by now. */
1564 if (iswide && opcode != JAVA_WIDE)
1565 panic("Illegal instruction: WIDE before incompatible opcode");
1569 if (isinlinedmethod && p == m->jcodelength - 1) { /* end of an inlined method */
1570 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1571 gp = inlinfo->stopgp;
1572 inlining_restore_compiler_variables();
1573 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1574 if (inlinfo->inlinedmethods == NULL) {
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;
1586 if (p != m->jcodelength)
1587 panic("Command-sequence crosses code-boundary");
1590 *exceptionptr = new_verifyerror(m, "Falling off the end of the code");
1594 /* adjust block count if target 0 is not first intermediate instruction */
1596 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1))
1599 /* copy local to method variables */
1601 m->instructioncount = ipc;
1602 m->basicblockcount = b_count;
1603 m->stackcount = s_count + m->basicblockcount * m->maxstack;
1605 /* allocate stack table */
1607 m->stack = DMNEW(stackelement, m->stackcount);
1612 bptr = m->basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1617 /* additional block if target 0 is not first intermediate instruction */
1619 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) {
1620 bptr->iinstr = m->instructions;
1623 bptr->type = BBTYPE_STD;
1624 bptr->branchrefs = NULL;
1625 bptr->pre_count = 0;
1626 bptr->debug_nr = c_debug_nr++;
1629 (bptr - 1)->next = bptr;
1632 /* allocate blocks */
1634 /* for (p = 0; p < cumjcodelength; p++) { */
1635 for (p = 0; p < m->jcodelength; p++) {
1636 if (m->basicblockindex[p] & 1) {
1637 /* check if this block starts at the beginning of an instruction */
1638 if (!instructionstart[p])
1639 panic("Branch into middle of instruction");
1640 /* allocate the block */
1641 bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
1642 bptr->debug_nr = c_debug_nr++;
1644 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1648 bptr->type = BBTYPE_STD;
1649 bptr->branchrefs = NULL;
1650 m->basicblockindex[p] = b_count;
1651 bptr->pre_count = 0;
1654 (bptr - 1)->next = bptr;
1658 /* allocate additional block at end */
1660 bptr->instack = bptr->outstack = NULL;
1661 bptr->indepth = bptr->outdepth = 0;
1662 bptr->iinstr = NULL;
1663 (bptr - 1)->icount = (m->instructions + m->instructioncount) - (bptr - 1)->iinstr;
1668 bptr->type = BBTYPE_STD;
1669 bptr->branchrefs = NULL;
1670 bptr->pre_count = 0;
1671 bptr->debug_nr = c_debug_nr++;
1672 (bptr - 1)->next = bptr;
1675 if (m->exceptiontablelength > 0) {
1676 m->exceptiontable[m->exceptiontablelength - 1].down = NULL;
1679 m->exceptiontable = NULL;
1682 for (i = 0; i < m->exceptiontablelength; ++i) {
1683 p = m->exceptiontable[i].startpc;
1684 m->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1686 p = m->exceptiontable[i].endpc;
1687 m->exceptiontable[i].end = (p == m->jcodelength) ? (m->basicblocks + m->basicblockcount + 1) : (m->basicblocks + m->basicblockindex[p]);
1689 p = m->exceptiontable[i].handlerpc;
1690 m->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1694 if (useinlining) inlining_cleanup();
1695 useinlining = useinltmp;
1697 /* just return methodinfo* to signal everything was ok */
1704 * These are local overrides for various environment variables in Emacs.
1705 * Please do not remove this and leave it at the end of the file, where
1706 * Emacs will automagically detect them.
1707 * ---------------------------------------------------------------------
1710 * indent-tabs-mode: t