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
31 $Id: parse.c 689 2003-12-05 18:03:47Z stefan $
42 #include "loop/loop.h"
48 #include "toolbox/memory.h"
49 #include "toolbox/loging.h"
52 /* data about the currently parsed method */
54 classinfo *rt_class; /* class the compiled method belongs to */
55 methodinfo *rt_method; /* pointer to method info of compiled method */
56 utf *rt_descriptor; /* type descriptor of compiled method */
57 int rt_jcodelength; /* length of JavaVM-codes */
58 u1 *rt_jcode; /* pointer to start of JavaVM-code */
64 /*#define debug_writebranch printf("op: %s i: %d label_index[i]: %d\n",icmd_names[opcode], i, label_index[i]);*/
65 #define debug_writebranch
69 /* functionc compiler_addinitclass *********************************************
71 add class into the list of classes to initialize
73 *******************************************************************************/
75 void compiler_addinitclass(classinfo *c)
79 if (c->initialized) return;
81 cl = chain_first(uninitializedclasses);
86 cl = chain_next(uninitializedclasses);
92 char logtext[MAXLOGTEXT];
93 sprintf(logtext, "compiler_addinitclass: ");
94 utf_sprint(logtext+strlen(logtext), c->name);
97 chain_addlast(uninitializedclasses, c);
102 char logtext[MAXLOGTEXT];
103 sprintf(logtext, "compiler_addinitclass: ");
104 utf_sprint(logtext+strlen(logtext), c->name);
107 chain_addbefore(uninitializedclasses, c);
110 cl = chain_next(uninitializedclasses);
116 /* function descriptor2typesL ***************************************************
118 decodes a already checked method descriptor. The parameter count, the
119 return type and the argument types are stored in the passed methodinfo.
120 gets and saves classptr for object ref.s
122 *******************************************************************************/
124 classSetNode *descriptor2typesL(methodinfo *m)
131 classinfo** classtypes;
134 classSetNode *p=NULL;
135 if (debugInfo >= 1) {
136 printf("In descriptor2typesL >>>\t"); fflush(stdout);
137 utf_display(m->class->name); printf(".");
138 method_display(m);fflush(stdout);
142 desc = MNEW (char, 256);
143 types = DMNEW (u1, m->descriptor->blength);
144 classtypes = MNEW (classinfo*, m->descriptor->blength+1);
145 m->returnclass = NULL;
147 if (!(m->flags & ACC_STATIC)) {
149 if (debugInfo >= 1) {
150 printf("param #0 (this?) method class =");utf_display(m->class->name);printf("\n");
152 classtypes[pcount] = m->class;
153 p = addClassCone(p, m->class);
157 utf_ptr = m->descriptor->text + 1;
158 strcpy (desc,utf_ptr);
160 while ((c = *desc++) != ')') {
167 case 'Z': *tptr++ = TYPE_INT;
169 case 'J': *tptr++ = TYPE_LNG;
171 case 'F': *tptr++ = TYPE_FLT;
173 case 'D': *tptr++ = TYPE_DBL;
175 case 'L': *tptr++ = TYPE_ADR;
176 /* get class string */
177 class = strtok(desc,";");
178 desc = strtok(NULL,"\0");
179 /* get/save classinfo ptr */
180 classtypes[pcount-1] = class_get(utf_new_char(class));
181 p = addClassCone(p, class_get(utf_new_char(class)));
182 if (debugInfo >= 1) {
183 printf("LParam#%i 's class type is: %s\n",pcount-1,class);fflush(stdout);
184 printf("Lclasstypes[%i]=",pcount-1);fflush(stdout);
185 utf_display(classtypes[pcount-1]->name);
188 case '[': *tptr++ = TYPE_ADR;
191 /* get class string */
193 class = strtok(desc,";");
194 desc = strtok(NULL,"\0");
195 /* get/save classinfo ptr */
196 classtypes[pcount-1] = class_get(utf_new_char(class));
197 p= addClassCone(p, class_get(utf_new_char(class)));
198 if (debugInfo >= 1) {
199 printf("[Param#%i 's class type is: %s\n",pcount-1,class);
200 printf("[classtypes[%i]=",pcount-1);fflush(stdout);
201 utf_display(classtypes[pcount-1]->name);
206 classtypes[pcount-1] = NULL;
209 panic("Ill formed methodtype-descriptor");
213 /* compute return type */
219 case 'Z': m->returntype = TYPE_INT;
221 case 'J': m->returntype = TYPE_LNG;
223 case 'F': m->returntype = TYPE_FLT;
225 case 'D': m->returntype = TYPE_DBL;
228 m->returntype = TYPE_ADR;
236 m->returntype = TYPE_ADR;
238 /* get class string */
239 class = strtok(desc,";");
240 m->returnclass = class_get(utf_new_char(class));
241 if (m->returnclass == NULL) {
242 printf("class=%s :\t",class);
243 panic ("return class not found");
246 case 'V': m->returntype = TYPE_VOID;
249 default: panic("Ill formed methodtype-descriptor-ReturnType");
252 m->paramcount = pcount;
253 m->paramtypes = types;
254 m->paramclass = classtypes;
258 for (i=0; i< m->paramcount; i++) {
259 if ((m->paramtypes[i] == TYPE_ADR) && (m->paramclass[i] != NULL)) {
260 printf("Param #%i is:\t",i);
261 utf_display(m->paramclass[i]->name);
266 if ((m->returntype == TYPE_ADR) && (m->returnclass != NULL)) {
267 printf("\tReturn Type is:\t"); fflush(stdout);
268 utf_display(m->returnclass->name);
272 printf("params2types: START results in a set \n");
273 printf("param2types: A Set size=%i=\n",sizeOfSet(p));
282 /* function descriptor2types ***************************************************
284 decodes a already checked method descriptor. The parameter count, the
285 return type and the argument types are stored in the passed methodinfo.
287 *******************************************************************************/
289 void descriptor2types(methodinfo *m)
295 types = DMNEW(u1, m->descriptor->blength);
298 if (!(m->flags & ACC_STATIC)) {
303 utf_ptr = m->descriptor->text + 1;
305 while ((c = *utf_ptr++) != ')') {
312 case 'Z': *tptr++ = TYPE_INT;
314 case 'J': *tptr++ = TYPE_LNG;
316 case 'F': *tptr++ = TYPE_FLT;
318 case 'D': *tptr++ = TYPE_DBL;
320 case 'L': *tptr++ = TYPE_ADR;
321 while (*utf_ptr++ != ';');
323 case '[': *tptr++ = TYPE_ADR;
327 while (*utf_ptr++ != ';') /* skip */;
329 default: panic ("Ill formed methodtype-descriptor");
333 /* compute return type */
335 switch (*utf_ptr++) {
340 case 'Z': m->returntype = TYPE_INT;
342 case 'J': m->returntype = TYPE_LNG;
344 case 'F': m->returntype = TYPE_FLT;
346 case 'D': m->returntype = TYPE_DBL;
349 case 'L': m->returntype = TYPE_ADR;
351 case 'V': m->returntype = TYPE_VOID;
354 default: panic ("Ill formed methodtype-descriptor");
357 m->paramcount = pcount;
358 m->paramtypes = types;
363 /*******************************************************************************
365 function 'parse' scans the JavaVM code and generates intermediate code
367 During parsing the block index table is used to store at bit pos 0
368 a flag which marks basic block starts and at position 1 to 31 the
369 intermediate instruction index. After parsing the block index table
370 is scanned, for marked positions a block is generated and the block
371 number is stored in the block index table.
373 *******************************************************************************/
375 /* intermediate code generating macros */
377 #define PINC iptr++;ipc++
378 #define LOADCONST_I(v) iptr->opc=ICMD_ICONST;iptr->op1=0;iptr->val.i=(v);PINC
379 #define LOADCONST_L(v) iptr->opc=ICMD_LCONST;iptr->op1=0;iptr->val.l=(v);PINC
380 #define LOADCONST_F(v) iptr->opc=ICMD_FCONST;iptr->op1=0;iptr->val.f=(v);PINC
381 #define LOADCONST_D(v) iptr->opc=ICMD_DCONST;iptr->op1=0;iptr->val.d=(v);PINC
382 #define LOADCONST_A(v) iptr->opc=ICMD_ACONST;iptr->op1=0;iptr->val.a=(v);PINC
383 #define OP(o) iptr->opc=(o);iptr->op1=0;iptr->val.l=0;PINC
384 #define OP1(o,o1) iptr->opc=(o);iptr->op1=(o1);iptr->val.l=(0);PINC
385 #define OP2I(o,o1,v) iptr->opc=(o);iptr->op1=(o1);iptr->val.i=(v);PINC
386 #define OP2A(o,o1,v) iptr->opc=(o);iptr->op1=(o1);iptr->val.a=(v);PINC
387 #define BUILTIN1(v,t) isleafmethod=false;iptr->opc=ICMD_BUILTIN1;iptr->op1=t;\
389 #define BUILTIN2(v,t) isleafmethod=false;iptr->opc=ICMD_BUILTIN2;iptr->op1=t;\
391 #define BUILTIN3(v,t) isleafmethod=false;iptr->opc=ICMD_BUILTIN3;iptr->op1=t;\
395 /* block generating and checking macros */
397 #define block_insert(i) \
399 if (!(block_index[(i)] & 1)) { \
401 block_index[(i)] |= 1; \
406 /* FIXME really use cumjcodelength for the bound_checkers ? */
408 #define bound_check(i) \
410 if (i < 0 || i >= cumjcodelength) { \
411 panic("branch target out of code-boundary"); \
415 #define bound_check1(i) \
417 if (i < 0 || i > cumjcodelength) { \
418 panic("branch target out of code-boundary"); \
424 static xtable* fillextable(xtable* extable, exceptiontable *raw_extable, int exceptiontablelength, int *label_index, int *block_count)
428 if (exceptiontablelength == 0)
431 b_count = *block_count;
432 for (i = 0; i < exceptiontablelength; i++) {
434 p = raw_extable[i].startpc;
435 if (label_index != NULL) p = label_index[p];
436 extable[i].startpc = p;
440 p = raw_extable[i].endpc;
441 if (label_index != NULL) p = label_index[p];
442 extable[i].endpc = p;
444 if (p < cumjcodelength)
447 p = raw_extable[i].handlerpc;
448 if (label_index != NULL) p = label_index[p];
449 extable[i].handlerpc = p;
453 extable[i].catchtype = raw_extable[i].catchtype;
455 extable[i].next = NULL;
456 extable[i].down = &extable[i+1];
458 *block_count = b_count;
459 return &extable[i]; /* return the next free xtable* */
466 int p; /* java instruction counter */
467 int nextp; /* start of next java instruction */
468 int opcode; /* java opcode */
469 int i; /* temporary for different uses (counters) */
470 int ipc = 0; /* intermediate instruction counter */
471 int b_count = 0; /* basic block counter */
472 int s_count = 0; /* stack element counter */
473 bool blockend = false; /* true if basic block end has been reached */
474 bool iswide = false; /* true if last instruction was a wide */
475 instruction *iptr; /* current pointer into instruction array */
476 int gp; /* global java instruction counter */
477 /* inlining info for current method */
478 inlining_methodinfo *inlinfo = inlining_rootinfo;
479 inlining_methodinfo *tmpinlinf;
480 int nextgp = -1; /* start of next method to be inlined */
481 int *label_index = NULL; /* label redirection table */
482 int firstlocal = 0; /* first local variable of method */
483 xtable* nextex; /* points next free entry in extable */
489 label_index = inlinfo->label_index;
490 maxstack = cummaxstack;
491 exceptiontablelength = cumextablelength;
494 useinltmp = useinlining; /* FIXME remove this after debugging */
495 /*useinlining = false;*/ /* and merge the if-statements */
498 cumjcodelength = jcodelength;
501 tmpinlinf = (inlining_methodinfo*) list_first(inlinfo->inlinedmethods);
502 if (tmpinlinf != NULL) nextgp = tmpinlinf->startgp;
505 if ((opt_rt || opt_xta || opt_vta) && (pOpcodes == 2 || pOpcodes == 3)) {
506 printf("PARSE method name =");
507 utf_display(method->class->name);
509 method_display(method);
514 if (opt_rt || opt_xta) {
515 RT_jit_parse(method);
519 printf("VTA requested, but not yet implemented\n");
523 /* allocate instruction array and block index table */
525 /* 1 additional for end ipc and 3 for loop unrolling */
527 block_index = DMNEW(int, cumjcodelength + 4);
529 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
530 /* additional MONITOREXITS are reached by branches which are 3 bytes */
532 iptr = instr = DMNEW(instruction, cumjcodelength + 5);
534 /* initialize block_index table (unrolled four times) */
539 for (i = 0, ip = block_index; i <= cumjcodelength; i += 4, ip += 4) {
547 /* compute branch targets of exception table */
549 extable = DMNEW(xtable, exceptiontablelength + 1);
551 for (i = 0; i < method->exceptiontablelength; i++) {
553 p = extable[i].startpc = raw_extable[i].startpc;
554 if (useinlining) p = label_index[p];
558 p = extable[i].endpc = raw_extable[i].endpc;
559 if (useinlining) p = label_index[p];
561 if (p < cumjcodelength)
564 p = extable[i].handlerpc = raw_extable[i].handlerpc;
568 extable[i].catchtype = raw_extable[i].catchtype;
570 extable[i].next = NULL;
571 extable[i].down = &extable[i+1];
575 nextex = fillextable(extable, raw_extable, method->exceptiontablelength, label_index, &b_count);
577 s_count = 1 + exceptiontablelength; /* initialize stack element counter */
580 if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
581 isleafmethod = false;
585 /* scan all java instructions */
587 for (p = 0, gp = 0; p < jcodelength; gp += (nextp - p), p = nextp) {
589 /* DEBUG printf("p:%d gp:%d ",p,gp); */
592 if ((useinlining) && (gp == nextgp)) {
594 bool *readonly = NULL;
596 opcode = code_get_u1(p);
597 nextp = p += jcommandsize[opcode];
598 tmpinlinf = list_first(inlinfo->inlinedmethods);
599 firstlocal = tmpinlinf->firstlocal;
600 label_index = tmpinlinf->label_index;
601 readonly = tmpinlinf->readonly;
603 for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) {
606 if ((i == 0) && inlineparamopt) {
607 OP1(ICMD_CLEAR_ARGREN, firstlocal);
610 if (!inlineparamopt || !readonly[i]) {
614 op = ICMD_READONLY_ARG;
618 OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i);
620 /* block_index[gp] |= (ipc << 1);*/ /*FIXME: necessary ? */
623 inlining_save_compiler_variables();
624 inlining_set_compiler_variables(tmpinlinf);
626 if (inlinfo->inlinedmethods == NULL) {
629 tmpinlinf = list_first(inlinfo->inlinedmethods);
630 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
632 if (method->exceptiontablelength > 0)
633 nextex = fillextable(nextex, method->exceptiontable, method->exceptiontablelength, label_index, &b_count);
637 opcode = code_get_u1(p); /* fetch op code */
640 if (opt_rt && (pOpcodes == 2 || pOpcodes == 3)) {
641 printf("Parse<%i> p=%i<%i< opcode=<%i> %s\n",
642 pOpcodes, p, rt_jcodelength, opcode, icmd_names[opcode]);
645 block_index[gp] |= (ipc << 1); /* store intermediate count */
648 block_insert(gp); /* start new block */
652 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
653 s_count += stackreq[opcode]; /* compute stack element count */
659 /* pushing constants onto the stack p */
662 LOADCONST_I(code_get_s1(p+1));
666 LOADCONST_I(code_get_s2(p+1));
670 i = code_get_u1(p+1);
671 goto pushconstantitem;
674 i = code_get_u2(p + 1);
678 if (i >= class->cpcount)
679 panic ("Attempt to access constant outside range");
681 switch (class->cptags[i]) {
682 case CONSTANT_Integer:
683 LOADCONST_I(((constant_integer*)
684 (class->cpinfos[i]))->value);
687 LOADCONST_L(((constant_long*)
688 (class->cpinfos[i]))->value);
691 LOADCONST_F(((constant_float*)
692 (class->cpinfos[i]))->value);
694 case CONSTANT_Double:
695 LOADCONST_D(((constant_double*)
696 (class->cpinfos[i]))->value);
698 case CONSTANT_String:
699 LOADCONST_A(literalstring_new((utf*)
700 (class->cpinfos[i])));
702 default: panic("Invalid constant type to push");
706 case JAVA_ACONST_NULL:
717 LOADCONST_I(opcode - JAVA_ICONST_0);
722 LOADCONST_L(opcode - JAVA_LCONST_0);
728 LOADCONST_F(opcode - JAVA_FCONST_0);
733 LOADCONST_D(opcode - JAVA_DCONST_0);
736 /* loading variables onto the stack */
744 i = code_get_u1(p + 1);
746 i = code_get_u2(p + 1);
750 OP1(opcode, i + firstlocal);
757 OP1(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
764 OP1(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
771 OP1(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
778 OP1(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
785 OP1(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
788 /* storing stack values into local variables */
796 i = code_get_u1(p + 1);
798 i = code_get_u2(p + 1);
802 OP1(opcode, i + firstlocal);
809 OP1(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
816 OP1(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
823 OP1(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
830 OP1(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
837 OP1(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
845 i = code_get_u1(p + 1);
846 v = code_get_s1(p + 2);
849 i = code_get_u2(p + 1);
850 v = code_get_s2(p + 3);
854 OP2I(opcode, i + firstlocal, v);
858 /* wider index for loading, storing and incrementing */
865 /* managing arrays ************************************************/
868 OP2I(ICMD_CHECKASIZE, 0, 0);
869 switch (code_get_s1(p + 1)) {
871 BUILTIN1((functionptr) builtin_newarray_boolean, TYPE_ADR);
874 BUILTIN1((functionptr) builtin_newarray_char, TYPE_ADR);
877 BUILTIN1((functionptr) builtin_newarray_float, TYPE_ADR);
880 BUILTIN1((functionptr) builtin_newarray_double, TYPE_ADR);
883 BUILTIN1((functionptr) builtin_newarray_byte, TYPE_ADR);
886 BUILTIN1((functionptr) builtin_newarray_short, TYPE_ADR);
889 BUILTIN1((functionptr) builtin_newarray_int, TYPE_ADR);
892 BUILTIN1((functionptr) builtin_newarray_long, TYPE_ADR);
894 default: panic("Invalid array-type to create");
899 OP2I(ICMD_CHECKASIZE, 0, 0);
900 i = code_get_u2(p + 1);
902 classinfo *component = (classinfo*)class_getconstant(class, i, CONSTANT_Class);
903 LOADCONST_A(class_array_of(component)->vftbl);
907 #if defined(__I386__)
908 BUILTIN2((functionptr) asm_builtin_newarray, TYPE_ADR);
910 BUILTIN2((functionptr)builtin_newarray, TYPE_ADR);
915 case JAVA_MULTIANEWARRAY:
917 i = code_get_u2(p + 1);
919 int v = code_get_u1(p + 3);
920 vftbl *arrayvftbl = ((classinfo*)class_getconstant (class, i, CONSTANT_Class))->vftbl;
921 OP2A(opcode, v, arrayvftbl);
943 i = p + code_get_s2(p + 1);
955 i = p + code_get_s4(p + 1);
968 i = code_get_u1(p + 1);
970 i = code_get_u2(p + 1);
977 if (isinlinedmethod) {
978 OP1(ICMD_GOTO, inlinfo->stopgp);
982 OP1(opcode, i + firstlocal);
991 if (isinlinedmethod) {
992 /* if (p==jcodelength-1) {*/ /* return is at end of inlined method */
997 OP1(ICMD_GOTO, inlinfo->stopgp);
1011 /* table jumps ********************************/
1013 case JAVA_LOOKUPSWITCH:
1019 nextp = ALIGN((p + 1), 4);
1021 tablep = (s4*)(jcode + nextp);
1024 num = code_get_u4(nextp + 4);
1025 tablep = DMNEW(s4, num * 2 + 2);
1028 OP2A(opcode, 0, tablep);
1030 /* default target */
1032 j = p + code_get_s4(nextp);
1035 *tablep = j; /* restore for little endian */
1041 /* number of pairs */
1043 num = code_get_u4(nextp);
1048 for (i = 0; i < num; i++) {
1051 j = code_get_s4(nextp);
1052 *tablep = j; /* restore for little endian */
1058 j = p + code_get_s4(nextp);
1061 *tablep = j; /* restore for little endian */
1072 case JAVA_TABLESWITCH:
1078 nextp = ALIGN((p + 1), 4);
1080 tablep = (s4*)(jcode + nextp);
1083 num = code_get_u4(nextp + 8) - code_get_u4(nextp + 4);
1084 tablep = DMNEW(s4, num + 1 + 3);
1087 OP2A(opcode, 0, tablep);
1089 /* default target */
1091 j = p + code_get_s4(nextp);
1094 *tablep = j; /* restore for little endian */
1102 j = code_get_s4(nextp);
1103 *tablep = j; /* restore for little endian */
1109 num = code_get_s4(nextp);
1110 *tablep = num; /* restore for little endian */
1116 for (i = 0; i <= num; i++) {
1117 j = p + code_get_s4(nextp);
1120 *tablep = j; /* restore for little endian */
1131 /* load and store of object fields *******************/
1134 BUILTIN3((functionptr) asm_builtin_aastore, TYPE_VOID);
1137 case JAVA_PUTSTATIC:
1138 case JAVA_GETSTATIC:
1139 i = code_get_u2(p + 1);
1141 constant_FMIref *fr;
1143 fr = class_getconstant (class, i, CONSTANT_Fieldref);
1144 fi = class_findfield (fr->class, fr->name, fr->descriptor);
1145 compiler_addinitclass (fr->class);
1146 OP2A(opcode, fi->type, fi);
1152 i = code_get_u2(p + 1);
1154 constant_FMIref *fr;
1156 fr = class_getconstant (class, i, CONSTANT_Fieldref);
1157 fi = class_findfield (fr->class, fr->name, fr->descriptor);
1158 OP2A(opcode, fi->type, fi);
1163 /* method invocation *****/
1165 case JAVA_INVOKESTATIC:
1166 i = code_get_u2(p + 1);
1168 constant_FMIref *mr;
1171 mr = class_getconstant (class, i, CONSTANT_Methodref);
1172 mi = class_findmethod (mr->class, mr->name, mr->descriptor);
1173 /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt)
1174 /*RTAprint*/ {printf(" method name =");
1175 /*RTAprint*/ utf_display(mi->class->name); printf(".");
1176 /*RTAprint*/ utf_display(mi->name);printf("\tINVOKE STATIC\n");
1177 /*RTAprint*/ fflush(stdout);}
1178 if (!(mi->flags & ACC_STATIC))
1179 panic ("Static/Nonstatic mismatch calling static method");
1180 descriptor2types(mi);
1183 OP2A(opcode, mi->paramcount, mi);
1187 case JAVA_INVOKESPECIAL:
1188 case JAVA_INVOKEVIRTUAL:
1189 i = code_get_u2(p + 1);
1191 constant_FMIref *mr;
1194 mr = class_getconstant (class, i, CONSTANT_Methodref);
1195 mi = class_findmethod (mr->class, mr->name, mr->descriptor);
1196 /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt)
1197 /*RTAprint*/ {printf(" method name =");
1199 /*RTAprint*/ utf_display(mi->class->name); printf(".");
1200 /*RTAprint*/ utf_display(mi->name);printf("\tINVOKE SPECIAL/VIRTUAL\n");
1201 /*RTAprint*/ fflush(stdout);}
1203 if (mi->flags & ACC_STATIC)
1204 panic ("Static/Nonstatic mismatch calling static method");
1205 descriptor2types(mi);
1207 OP2A(opcode, mi->paramcount, mi);
1211 case JAVA_INVOKEINTERFACE:
1212 i = code_get_u2(p + 1);
1214 constant_FMIref *mr;
1217 mr = class_getconstant (class, i, CONSTANT_InterfaceMethodref);
1218 mi = class_findmethod (mr->class, mr->name, mr->descriptor);
1219 if (mi->flags & ACC_STATIC)
1220 panic ("Static/Nonstatic mismatch calling static method");
1221 descriptor2types(mi);
1223 OP2A(opcode, mi->paramcount, mi);
1227 /* miscellaneous object operations *******/
1230 i = code_get_u2 (p+1);
1232 LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1234 BUILTIN1((functionptr) builtin_new, TYPE_ADR);
1237 case JAVA_CHECKCAST:
1238 i = code_get_u2(p+1);
1240 classinfo *cls = (classinfo*)class_getconstant(class, i, CONSTANT_Class);
1241 if (cls->vftbl->arraydesc) {
1242 /* array type cast-check */
1243 LOADCONST_A(cls->vftbl->arraydesc);
1245 BUILTIN2((functionptr) asm_builtin_checkarraycast, TYPE_ADR);
1247 else { /* object type cast-check */
1249 + LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1251 + BUILTIN2((functionptr) asm_builtin_checkcast, TYPE_ADR);
1253 OP2A(opcode, 1, cls);
1259 case JAVA_INSTANCEOF:
1260 i = code_get_u2(p+1);
1263 classinfo *cls = (classinfo*)class_getconstant(class, i, CONSTANT_Class);
1264 if (cls->vftbl->arraydesc) {
1265 /* array type cast-check */
1266 LOADCONST_A(cls->vftbl->arraydesc);
1268 #if defined(__I386__)
1269 BUILTIN2((functionptr) asm_builtin_arrayinstanceof, TYPE_INT);
1271 BUILTIN2((functionptr) builtin_arrayinstanceof, TYPE_INT);
1274 else { /* object type cast-check */
1276 LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1278 BUILTIN2((functionptr) builtin_instanceof, TYPE_INT);
1280 OP2A(opcode, 1, cls);
1285 case JAVA_MONITORENTER:
1288 BUILTIN1((functionptr) asm_builtin_monitorenter, TYPE_VOID);
1292 OP(ICMD_NULLCHECKPOP);
1296 case JAVA_MONITOREXIT:
1299 BUILTIN1((functionptr) asm_builtin_monitorexit, TYPE_VOID);
1308 /* any other basic operation **************************************/
1327 #if defined(__I386__)
1330 BUILTIN2((functionptr) builtin_frem, TYPE_FLOAT);
1335 #if defined(__I386__)
1338 BUILTIN2((functionptr) builtin_drem, TYPE_DOUBLE);
1343 #if defined(__ALPHA__)
1345 BUILTIN1((functionptr) builtin_f2i, TYPE_INT);
1354 #if defined(__ALPHA__)
1356 BUILTIN1((functionptr) builtin_f2l, TYPE_LONG);
1365 #if defined(__ALPHA__)
1367 BUILTIN1((functionptr) builtin_d2i, TYPE_INT);
1376 #if defined(__ALPHA__)
1378 BUILTIN1((functionptr) builtin_d2l, TYPE_LONG);
1386 case JAVA_BREAKPOINT:
1387 panic("Illegal opcode Breakpoint encountered");
1443 printf("Illegal opcode %d at instr %d", opcode, ipc);
1444 panic("encountered");
1455 if (isinlinedmethod && p == jcodelength - 1) { /* end of an inlined method */
1456 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1457 gp = inlinfo->stopgp;
1458 inlining_restore_compiler_variables();
1459 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1460 if (inlinfo->inlinedmethods == NULL) {
1463 tmpinlinf = list_first(inlinfo->inlinedmethods);
1464 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1466 /* printf("nextpgp: %d\n", nextgp); */
1467 label_index=inlinfo->label_index;
1468 firstlocal = inlinfo->firstlocal;
1472 if (p != jcodelength)
1473 panic("Command-sequence crosses code-boundary");
1476 panic("Code does not end with branch/return/athrow - stmt");
1478 /* adjust block count if target 0 is not first intermediate instruction */
1480 if (!block_index[0] || (block_index[0] > 1))
1483 /* copy local to global variables */
1486 block_count = b_count;
1487 stack_count = s_count + block_count * maxstack;
1489 /* allocate stack table */
1491 stack = DMNEW(stackelement, stack_count);
1496 bptr = block = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1501 /* additional block if target 0 is not first intermediate instruction */
1503 if (!block_index[0] || (block_index[0] > 1)) {
1504 bptr->iinstr = instr;
1507 bptr->type = BBTYPE_STD;
1508 bptr->branchrefs = NULL;
1509 bptr->pre_count = 0;
1510 bptr->debug_nr = c_debug_nr++;
1513 (bptr - 1)->next = bptr;
1516 /* allocate blocks */
1518 for (p = 0; p < cumjcodelength; p++) {
1519 if (block_index[p] & 1) {
1520 bptr->iinstr = instr + (block_index[p] >> 1);
1521 bptr->debug_nr = c_debug_nr++;
1523 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1527 bptr->type = BBTYPE_STD;
1528 bptr->branchrefs = NULL;
1529 block_index[p] = b_count;
1530 bptr->pre_count = 0;
1533 (bptr - 1)->next = bptr;
1537 /* allocate additional block at end */
1539 bptr->instack = bptr->outstack = NULL;
1540 bptr->indepth = bptr->outdepth = 0;
1541 bptr->iinstr = NULL;
1542 (bptr - 1)->icount = (instr + instr_count) - (bptr - 1)->iinstr;
1547 bptr->type = BBTYPE_STD;
1548 bptr->branchrefs = NULL;
1549 bptr->pre_count = 0;
1550 bptr->debug_nr = c_debug_nr++;
1551 (bptr - 1)->next = bptr;
1556 if (exceptiontablelength > 0)
1557 extable[exceptiontablelength - 1].down = NULL;
1561 for (i = 0; i < exceptiontablelength; ++i) {
1562 p = extable[i].startpc;
1563 extable[i].start = block + block_index[p];
1565 p = extable[i].endpc;
1566 extable[i].end = block + block_index[p];
1568 p = extable[i].handlerpc;
1569 extable[i].handler = block + block_index[p];
1573 if (useinlining) inlining_cleanup();
1574 useinlining = useinltmp;
1579 * These are local overrides for various environment variables in Emacs.
1580 * Please do not remove this and leave it at the end of the file, where
1581 * Emacs will automagically detect them.
1582 * ---------------------------------------------------------------------
1585 * indent-tabs-mode: t