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 665 2003-11-21 18:36:43Z jowenn $
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 sprintf(logtext, "compiler_addinitclass: ");
93 utf_sprint(logtext+strlen(logtext), c->name);
96 chain_addlast(uninitializedclasses, c);
101 sprintf(logtext, "compiler_addinitclass: ");
102 utf_sprint(logtext+strlen(logtext), c->name);
105 chain_addbefore(uninitializedclasses, c);
108 cl = chain_next(uninitializedclasses);
114 /* function descriptor2typesL ***************************************************
116 decodes a already checked method descriptor. The parameter count, the
117 return type and the argument types are stored in the passed methodinfo.
118 gets and saves classptr for object ref.s
120 *******************************************************************************/
122 classSetNode *descriptor2typesL(methodinfo *m)
129 classinfo** classtypes;
132 classSetNode *p=NULL;
133 if (debugInfo >= 1) {
134 printf("In descriptor2typesL >>>\t"); fflush(stdout);
135 utf_display(m->class->name); printf(".");
136 method_display(m);fflush(stdout);
140 desc = MNEW (char, 256);
141 types = DMNEW (u1, m->descriptor->blength);
142 classtypes = MNEW (classinfo*, m->descriptor->blength+1);
143 m->returnclass = NULL;
145 if (!(m->flags & ACC_STATIC)) {
147 if (debugInfo >= 1) {
148 printf("param #0 (this?) method class =");utf_display(m->class->name);printf("\n");
150 classtypes[pcount] = m->class;
151 p = addClassCone(p, m->class);
155 utf_ptr = m->descriptor->text + 1;
156 strcpy (desc,utf_ptr);
158 while ((c = *desc++) != ')') {
165 case 'Z': *tptr++ = TYPE_INT;
167 case 'J': *tptr++ = TYPE_LNG;
169 case 'F': *tptr++ = TYPE_FLT;
171 case 'D': *tptr++ = TYPE_DBL;
173 case 'L': *tptr++ = TYPE_ADR;
174 /* get class string */
175 class = strtok(desc,";");
176 desc = strtok(NULL,"\0");
177 /* get/save classinfo ptr */
178 classtypes[pcount-1] = class_get(utf_new_char(class));
179 p = addClassCone(p, class_get(utf_new_char(class)));
180 if (debugInfo >= 1) {
181 printf("LParam#%i 's class type is: %s\n",pcount-1,class);fflush(stdout);
182 printf("Lclasstypes[%i]=",pcount-1);fflush(stdout);
183 utf_display(classtypes[pcount-1]->name);
186 case '[': *tptr++ = TYPE_ADR;
189 /* get class string */
191 class = strtok(desc,";");
192 desc = strtok(NULL,"\0");
193 /* get/save classinfo ptr */
194 classtypes[pcount-1] = class_get(utf_new_char(class));
195 p= addClassCone(p, class_get(utf_new_char(class)));
196 if (debugInfo >= 1) {
197 printf("[Param#%i 's class type is: %s\n",pcount-1,class);
198 printf("[classtypes[%i]=",pcount-1);fflush(stdout);
199 utf_display(classtypes[pcount-1]->name);
204 classtypes[pcount-1] = NULL;
207 panic("Ill formed methodtype-descriptor");
211 /* compute return type */
217 case 'Z': m->returntype = TYPE_INT;
219 case 'J': m->returntype = TYPE_LNG;
221 case 'F': m->returntype = TYPE_FLT;
223 case 'D': m->returntype = TYPE_DBL;
226 m->returntype = TYPE_ADR;
234 m->returntype = TYPE_ADR;
236 /* get class string */
237 class = strtok(desc,";");
238 m->returnclass = class_get(utf_new_char(class));
239 if (m->returnclass == NULL) {
240 printf("class=%s :\t",class);
241 panic ("return class not found");
244 case 'V': m->returntype = TYPE_VOID;
247 default: panic("Ill formed methodtype-descriptor-ReturnType");
250 m->paramcount = pcount;
251 m->paramtypes = types;
252 m->paramclass = classtypes;
256 for (i=0; i< m->paramcount; i++) {
257 if ((m->paramtypes[i] == TYPE_ADR) && (m->paramclass[i] != NULL)) {
258 printf("Param #%i is:\t",i);
259 utf_display(m->paramclass[i]->name);
264 if ((m->returntype == TYPE_ADR) && (m->returnclass != NULL)) {
265 printf("\tReturn Type is:\t"); fflush(stdout);
266 utf_display(m->returnclass->name);
270 printf("params2types: START results in a set \n");
271 printf("param2types: A Set size=%i=\n",sizeOfSet(p));
280 /* function descriptor2types ***************************************************
282 decodes a already checked method descriptor. The parameter count, the
283 return type and the argument types are stored in the passed methodinfo.
285 *******************************************************************************/
287 void descriptor2types(methodinfo *m)
293 types = DMNEW(u1, m->descriptor->blength);
296 if (!(m->flags & ACC_STATIC)) {
301 utf_ptr = m->descriptor->text + 1;
303 while ((c = *utf_ptr++) != ')') {
310 case 'Z': *tptr++ = TYPE_INT;
312 case 'J': *tptr++ = TYPE_LNG;
314 case 'F': *tptr++ = TYPE_FLT;
316 case 'D': *tptr++ = TYPE_DBL;
318 case 'L': *tptr++ = TYPE_ADR;
319 while (*utf_ptr++ != ';');
321 case '[': *tptr++ = TYPE_ADR;
325 while (*utf_ptr++ != ';') /* skip */;
327 default: panic ("Ill formed methodtype-descriptor");
331 /* compute return type */
333 switch (*utf_ptr++) {
338 case 'Z': m->returntype = TYPE_INT;
340 case 'J': m->returntype = TYPE_LNG;
342 case 'F': m->returntype = TYPE_FLT;
344 case 'D': m->returntype = TYPE_DBL;
347 case 'L': m->returntype = TYPE_ADR;
349 case 'V': m->returntype = TYPE_VOID;
352 default: panic ("Ill formed methodtype-descriptor");
355 m->paramcount = pcount;
356 m->paramtypes = types;
361 /*******************************************************************************
363 function 'parse' scans the JavaVM code and generates intermediate code
365 During parsing the block index table is used to store at bit pos 0
366 a flag which marks basic block starts and at position 1 to 31 the
367 intermediate instruction index. After parsing the block index table
368 is scanned, for marked positions a block is generated and the block
369 number is stored in the block index table.
371 *******************************************************************************/
373 /* intermediate code generating macros */
375 #define PINC iptr++;ipc++
376 #define LOADCONST_I(v) iptr->opc=ICMD_ICONST;iptr->op1=0;iptr->val.i=(v);PINC
377 #define LOADCONST_L(v) iptr->opc=ICMD_LCONST;iptr->op1=0;iptr->val.l=(v);PINC
378 #define LOADCONST_F(v) iptr->opc=ICMD_FCONST;iptr->op1=0;iptr->val.f=(v);PINC
379 #define LOADCONST_D(v) iptr->opc=ICMD_DCONST;iptr->op1=0;iptr->val.d=(v);PINC
380 #define LOADCONST_A(v) iptr->opc=ICMD_ACONST;iptr->op1=0;iptr->val.a=(v);PINC
381 #define OP(o) iptr->opc=(o);iptr->op1=0;iptr->val.l=0;PINC
382 #define OP1(o,o1) iptr->opc=(o);iptr->op1=(o1);iptr->val.l=(0);PINC
383 #define OP2I(o,o1,v) iptr->opc=(o);iptr->op1=(o1);iptr->val.i=(v);PINC
384 #define OP2A(o,o1,v) iptr->opc=(o);iptr->op1=(o1);iptr->val.a=(v);PINC
385 #define BUILTIN1(v,t) isleafmethod=false;iptr->opc=ICMD_BUILTIN1;iptr->op1=t;\
387 #define BUILTIN2(v,t) isleafmethod=false;iptr->opc=ICMD_BUILTIN2;iptr->op1=t;\
389 #define BUILTIN3(v,t) isleafmethod=false;iptr->opc=ICMD_BUILTIN3;iptr->op1=t;\
393 /* block generating and checking macros */
395 #define block_insert(i) \
397 if (!(block_index[(i)] & 1)) { \
399 block_index[(i)] |= 1; \
404 /* FIXME really use cumjcodelength for the bound_checkers ? */
406 #define bound_check(i) \
408 if (i < 0 || i >= cumjcodelength) { \
409 panic("branch target out of code-boundary"); \
413 #define bound_check1(i) \
415 if (i < 0 || i > cumjcodelength) { \
416 panic("branch target out of code-boundary"); \
422 static xtable* fillextable(xtable* extable, exceptiontable *raw_extable, int exceptiontablelength, int *label_index, int *block_count)
426 if (exceptiontablelength == 0)
429 b_count = *block_count;
430 for (i = 0; i < exceptiontablelength; i++) {
432 p = raw_extable[i].startpc;
433 if (label_index != NULL) p = label_index[p];
434 extable[i].startpc = p;
438 p = raw_extable[i].endpc;
439 if (label_index != NULL) p = label_index[p];
440 extable[i].endpc = p;
442 if (p < cumjcodelength)
445 p = raw_extable[i].handlerpc;
446 if (label_index != NULL) p = label_index[p];
447 extable[i].handlerpc = p;
451 extable[i].catchtype = raw_extable[i].catchtype;
453 extable[i].next = NULL;
454 extable[i].down = &extable[i+1];
456 *block_count = b_count;
457 return &extable[i]; /* return the next free xtable* */
464 int p; /* java instruction counter */
465 int nextp; /* start of next java instruction */
466 int opcode; /* java opcode */
467 int i; /* temporary for different uses (counters) */
468 int ipc = 0; /* intermediate instruction counter */
469 int b_count = 0; /* basic block counter */
470 int s_count = 0; /* stack element counter */
471 bool blockend = false; /* true if basic block end has been reached */
472 bool iswide = false; /* true if last instruction was a wide */
473 instruction *iptr; /* current pointer into instruction array */
474 int gp; /* global java instruction counter */
475 /* inlining info for current method */
476 inlining_methodinfo *inlinfo = inlining_rootinfo;
477 inlining_methodinfo *tmpinlinf;
478 int nextgp = -1; /* start of next method to be inlined */
479 int *label_index = NULL; /* label redirection table */
480 int firstlocal = 0; /* first local variable of method */
481 xtable* nextex; /* points next free entry in extable */
487 label_index = inlinfo->label_index;
488 maxstack = cummaxstack;
489 exceptiontablelength = cumextablelength;
492 useinltmp = useinlining; /* FIXME remove this after debugging */
493 /*useinlining = false;*/ /* and merge the if-statements */
496 cumjcodelength = jcodelength;
499 tmpinlinf = (inlining_methodinfo*) list_first(inlinfo->inlinedmethods);
500 if (tmpinlinf != NULL) nextgp = tmpinlinf->startgp;
503 if ((opt_rt || opt_xta || opt_vta) && (pOpcodes == 2 || pOpcodes == 3)) {
504 printf("PARSE method name =");
505 utf_display(method->class->name);
507 method_display(method);
512 if (opt_rt || opt_xta) {
513 RT_jit_parse(method);
517 printf("VTA requested, but not yet implemented\n");
521 /* allocate instruction array and block index table */
523 /* 1 additional for end ipc and 3 for loop unrolling */
525 block_index = DMNEW(int, cumjcodelength + 4);
527 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
528 /* additional MONITOREXITS are reached by branches which are 3 bytes */
530 iptr = instr = DMNEW(instruction, cumjcodelength + 5);
532 /* initialize block_index table (unrolled four times) */
537 for (i = 0, ip = block_index; i <= cumjcodelength; i += 4, ip += 4) {
545 /* compute branch targets of exception table */
547 extable = DMNEW(xtable, exceptiontablelength + 1);
549 for (i = 0; i < method->exceptiontablelength; i++) {
551 p = extable[i].startpc = raw_extable[i].startpc;
552 if (useinlining) p = label_index[p];
556 p = extable[i].endpc = raw_extable[i].endpc;
557 if (useinlining) p = label_index[p];
559 if (p < cumjcodelength)
562 p = extable[i].handlerpc = raw_extable[i].handlerpc;
566 extable[i].catchtype = raw_extable[i].catchtype;
568 extable[i].next = NULL;
569 extable[i].down = &extable[i+1];
573 nextex = fillextable(extable, raw_extable, method->exceptiontablelength, label_index, &b_count);
575 s_count = 1 + exceptiontablelength; /* initialize stack element counter */
578 if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
579 isleafmethod = false;
583 /* scan all java instructions */
585 for (p = 0, gp = 0; p < jcodelength; gp += (nextp - p), p = nextp) {
587 /* DEBUG printf("p:%d gp:%d ",p,gp); */
590 if ((useinlining) && (gp == nextgp)) {
592 bool *readonly = NULL;
594 opcode = code_get_u1(p);
595 nextp = p += jcommandsize[opcode];
596 tmpinlinf = list_first(inlinfo->inlinedmethods);
597 firstlocal = tmpinlinf->firstlocal;
598 label_index = tmpinlinf->label_index;
599 readonly = tmpinlinf->readonly;
601 for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) {
604 if ((i == 0) && inlineparamopt) {
605 OP1(ICMD_CLEAR_ARGREN, firstlocal);
608 if (!inlineparamopt || !readonly[i]) {
612 op = ICMD_READONLY_ARG;
616 OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i);
618 /* block_index[gp] |= (ipc << 1);*/ /*FIXME: necessary ? */
621 inlining_save_compiler_variables();
622 inlining_set_compiler_variables(tmpinlinf);
624 if (inlinfo->inlinedmethods == NULL) {
627 tmpinlinf = list_first(inlinfo->inlinedmethods);
628 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
630 if (method->exceptiontablelength > 0)
631 nextex = fillextable(nextex, method->exceptiontable, method->exceptiontablelength, label_index, &b_count);
635 opcode = code_get_u1(p); /* fetch op code */
638 if (opt_rt && (pOpcodes == 2 || pOpcodes == 3)) {
639 printf("Parse<%i> p=%i<%i< opcode=<%i> %s\n",
640 pOpcodes, p, rt_jcodelength, opcode, icmd_names[opcode]);
643 block_index[gp] |= (ipc << 1); /* store intermediate count */
646 block_insert(gp); /* start new block */
650 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
651 s_count += stackreq[opcode]; /* compute stack element count */
654 /* log_text(opcode_names[opcode]); */
660 /* pushing constants onto the stack p */
663 LOADCONST_I(code_get_s1(p+1));
667 LOADCONST_I(code_get_s2(p+1));
671 i = code_get_u1(p+1);
672 goto pushconstantitem;
675 i = code_get_u2(p + 1);
679 if (i >= class->cpcount)
680 panic ("Attempt to access constant outside range");
682 switch (class->cptags[i]) {
683 case CONSTANT_Integer:
684 LOADCONST_I(((constant_integer*)
685 (class->cpinfos[i]))->value);
688 LOADCONST_L(((constant_long*)
689 (class->cpinfos[i]))->value);
692 LOADCONST_F(((constant_float*)
693 (class->cpinfos[i]))->value);
695 case CONSTANT_Double:
696 LOADCONST_D(((constant_double*)
697 (class->cpinfos[i]))->value);
699 case CONSTANT_String:
700 LOADCONST_A(literalstring_new((utf*)
701 (class->cpinfos[i])));
703 default: panic("Invalid constant type to push");
707 case JAVA_ACONST_NULL:
718 LOADCONST_I(opcode - JAVA_ICONST_0);
723 LOADCONST_L(opcode - JAVA_LCONST_0);
729 LOADCONST_F(opcode - JAVA_FCONST_0);
734 LOADCONST_D(opcode - JAVA_DCONST_0);
737 /* loading variables onto the stack */
745 i = code_get_u1(p + 1);
747 i = code_get_u2(p + 1);
751 OP1(opcode, i + firstlocal);
758 OP1(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
765 OP1(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
772 OP1(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
779 OP1(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
786 OP1(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
789 /* storing stack values into local variables */
797 i = code_get_u1(p + 1);
799 i = code_get_u2(p + 1);
803 OP1(opcode, i + firstlocal);
810 OP1(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
817 OP1(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
824 OP1(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
831 OP1(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
838 OP1(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
846 i = code_get_u1(p + 1);
847 v = code_get_s1(p + 2);
850 i = code_get_u2(p + 1);
851 v = code_get_s2(p + 3);
855 OP2I(opcode, i + firstlocal, v);
859 /* wider index for loading, storing and incrementing */
866 /* managing arrays ************************************************/
869 OP2I(ICMD_CHECKASIZE, 0, 0);
870 switch (code_get_s1(p + 1)) {
872 BUILTIN1((functionptr) builtin_newarray_boolean, TYPE_ADR);
875 BUILTIN1((functionptr) builtin_newarray_char, TYPE_ADR);
878 BUILTIN1((functionptr) builtin_newarray_float, TYPE_ADR);
881 BUILTIN1((functionptr) builtin_newarray_double, TYPE_ADR);
884 BUILTIN1((functionptr) builtin_newarray_byte, TYPE_ADR);
887 BUILTIN1((functionptr) builtin_newarray_short, TYPE_ADR);
890 BUILTIN1((functionptr) builtin_newarray_int, TYPE_ADR);
893 BUILTIN1((functionptr) builtin_newarray_long, TYPE_ADR);
895 default: panic("Invalid array-type to create");
900 OP2I(ICMD_CHECKASIZE, 0, 0);
901 i = code_get_u2(p + 1);
903 classinfo *component = (classinfo*)class_getconstant(class, i, CONSTANT_Class);
904 LOADCONST_A(class_array_of(component)->vftbl);
908 #if defined(__I386__)
909 BUILTIN2((functionptr) asm_builtin_newarray, TYPE_ADR);
911 BUILTIN2((functionptr)builtin_newarray, TYPE_ADR);
916 case JAVA_MULTIANEWARRAY:
918 i = code_get_u2(p + 1);
920 int v = code_get_u1(p + 3);
921 vftbl *arrayvftbl = ((classinfo*)class_getconstant (class, i, CONSTANT_Class))->vftbl;
922 OP2A(opcode, v, arrayvftbl);
944 i = p + code_get_s2(p + 1);
956 i = p + code_get_s4(p + 1);
969 i = code_get_u1(p + 1);
971 i = code_get_u2(p + 1);
978 if (isinlinedmethod) {
979 OP1(ICMD_GOTO, inlinfo->stopgp);
983 OP1(opcode, i + firstlocal);
992 if (isinlinedmethod) {
993 /* if (p==jcodelength-1) {*/ /* return is at end of inlined method */
998 OP1(ICMD_GOTO, inlinfo->stopgp);
1012 /* table jumps ********************************/
1014 case JAVA_LOOKUPSWITCH:
1020 nextp = ALIGN((p + 1), 4);
1022 tablep = (s4*)(jcode + nextp);
1025 num = code_get_u4(nextp + 4);
1026 tablep = DMNEW(s4, num * 2 + 2);
1029 OP2A(opcode, 0, tablep);
1031 /* default target */
1033 j = p + code_get_s4(nextp);
1036 *tablep = j; /* restore for little endian */
1042 /* number of pairs */
1044 num = code_get_u4(nextp);
1049 for (i = 0; i < num; i++) {
1052 j = code_get_s4(nextp);
1053 *tablep = j; /* restore for little endian */
1059 j = p + code_get_s4(nextp);
1062 *tablep = j; /* restore for little endian */
1073 case JAVA_TABLESWITCH:
1079 nextp = ALIGN((p + 1), 4);
1081 tablep = (s4*)(jcode + nextp);
1084 num = code_get_u4(nextp + 8) - code_get_u4(nextp + 4);
1085 tablep = DMNEW(s4, num + 1 + 3);
1088 OP2A(opcode, 0, tablep);
1090 /* default target */
1092 j = p + code_get_s4(nextp);
1095 *tablep = j; /* restore for little endian */
1103 j = code_get_s4(nextp);
1104 *tablep = j; /* restore for little endian */
1110 num = code_get_s4(nextp);
1111 *tablep = num; /* restore for little endian */
1117 for (i = 0; i <= num; i++) {
1118 j = p + code_get_s4(nextp);
1121 *tablep = j; /* restore for little endian */
1132 /* load and store of object fields *******************/
1135 BUILTIN3((functionptr) asm_builtin_aastore, TYPE_VOID);
1138 case JAVA_PUTSTATIC:
1139 case JAVA_GETSTATIC:
1140 i = code_get_u2(p + 1);
1142 constant_FMIref *fr;
1144 fr = class_getconstant (class, i, CONSTANT_Fieldref);
1145 fi = class_findfield (fr->class, fr->name, fr->descriptor);
1146 compiler_addinitclass (fr->class);
1147 OP2A(opcode, fi->type, fi);
1153 i = code_get_u2(p + 1);
1155 constant_FMIref *fr;
1157 fr = class_getconstant (class, i, CONSTANT_Fieldref);
1158 fi = class_findfield (fr->class, fr->name, fr->descriptor);
1159 OP2A(opcode, fi->type, fi);
1164 /* method invocation *****/
1166 case JAVA_INVOKESTATIC:
1167 i = code_get_u2(p + 1);
1169 constant_FMIref *mr;
1172 mr = class_getconstant (class, i, CONSTANT_Methodref);
1173 mi = class_findmethod (mr->class, mr->name, mr->descriptor);
1174 /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt)
1175 /*RTAprint*/ {printf(" method name =");
1176 /*RTAprint*/ utf_display(mi->class->name); printf(".");
1177 /*RTAprint*/ utf_display(mi->name);printf("\tINVOKE STATIC\n");
1178 /*RTAprint*/ fflush(stdout);}
1179 if (!(mi->flags & ACC_STATIC))
1180 panic ("Static/Nonstatic mismatch calling static method");
1181 descriptor2types(mi);
1184 OP2A(opcode, mi->paramcount, mi);
1188 case JAVA_INVOKESPECIAL:
1189 case JAVA_INVOKEVIRTUAL:
1190 i = code_get_u2(p + 1);
1192 constant_FMIref *mr;
1195 mr = class_getconstant (class, i, CONSTANT_Methodref);
1196 mi = class_findmethod (mr->class, mr->name, mr->descriptor);
1197 /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt)
1198 /*RTAprint*/ {printf(" method name =");
1200 /*RTAprint*/ utf_display(mi->class->name); printf(".");
1201 /*RTAprint*/ utf_display(mi->name);printf("\tINVOKE SPECIAL/VIRTUAL\n");
1202 /*RTAprint*/ fflush(stdout);}
1204 if (mi->flags & ACC_STATIC)
1205 panic ("Static/Nonstatic mismatch calling static method");
1206 descriptor2types(mi);
1208 OP2A(opcode, mi->paramcount, mi);
1212 case JAVA_INVOKEINTERFACE:
1213 i = code_get_u2(p + 1);
1215 constant_FMIref *mr;
1218 mr = class_getconstant (class, i, CONSTANT_InterfaceMethodref);
1219 mi = class_findmethod (mr->class, mr->name, mr->descriptor);
1220 if (mi->flags & ACC_STATIC)
1221 panic ("Static/Nonstatic mismatch calling static method");
1222 descriptor2types(mi);
1224 OP2A(opcode, mi->paramcount, mi);
1228 /* miscellaneous object operations *******/
1231 i = code_get_u2 (p+1);
1233 LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1235 BUILTIN1((functionptr) builtin_new, TYPE_ADR);
1238 case JAVA_CHECKCAST:
1239 i = code_get_u2(p+1);
1241 classinfo *cls = (classinfo*)class_getconstant(class, i, CONSTANT_Class);
1242 if (cls->vftbl->arraydesc) {
1243 /* array type cast-check */
1244 LOADCONST_A(cls->vftbl->arraydesc);
1246 BUILTIN2((functionptr) asm_builtin_checkarraycast, TYPE_ADR);
1248 else { /* object type cast-check */
1250 + LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1252 + BUILTIN2((functionptr) asm_builtin_checkcast, TYPE_ADR);
1254 OP2A(opcode, 1, cls);
1260 case JAVA_INSTANCEOF:
1261 i = code_get_u2(p+1);
1264 classinfo *cls = (classinfo*)class_getconstant(class, i, CONSTANT_Class);
1265 if (cls->vftbl->arraydesc) {
1266 /* array type cast-check */
1267 LOADCONST_A(cls->vftbl->arraydesc);
1269 #if defined(__I386__)
1270 BUILTIN2((functionptr) asm_builtin_arrayinstanceof, TYPE_INT);
1272 BUILTIN2((functionptr) builtin_arrayinstanceof, TYPE_INT);
1275 else { /* object type cast-check */
1277 LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1279 BUILTIN2((functionptr) builtin_instanceof, TYPE_INT);
1281 OP2A(opcode, 1, cls);
1286 case JAVA_MONITORENTER:
1289 BUILTIN1((functionptr) asm_builtin_monitorenter, TYPE_VOID);
1293 OP(ICMD_NULLCHECKPOP);
1297 case JAVA_MONITOREXIT:
1300 BUILTIN1((functionptr) asm_builtin_monitorexit, TYPE_VOID);
1309 /* any other basic operation **************************************/
1328 #if defined(__I386__)
1331 BUILTIN2((functionptr) builtin_frem, TYPE_FLOAT);
1336 #if defined(__I386__)
1339 BUILTIN2((functionptr) builtin_drem, TYPE_DOUBLE);
1344 #if defined(__ALPHA__)
1346 BUILTIN1((functionptr) builtin_f2i, TYPE_INT);
1355 #if defined(__ALPHA__)
1357 BUILTIN1((functionptr) builtin_f2l, TYPE_LONG);
1366 #if defined(__ALPHA__)
1368 BUILTIN1((functionptr) builtin_d2i, TYPE_INT);
1377 #if defined(__ALPHA__)
1379 BUILTIN1((functionptr) builtin_d2l, TYPE_LONG);
1387 case JAVA_BREAKPOINT:
1388 panic("Illegal opcode Breakpoint encountered");
1444 printf("Illegal opcode %d at instr %d", opcode, ipc);
1445 panic("encountered");
1456 if (isinlinedmethod && p == jcodelength - 1) { /* end of an inlined method */
1457 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1458 gp = inlinfo->stopgp;
1459 inlining_restore_compiler_variables();
1460 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1461 if (inlinfo->inlinedmethods == NULL) {
1464 tmpinlinf = list_first(inlinfo->inlinedmethods);
1465 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1467 /* printf("nextpgp: %d\n", nextgp); */
1468 label_index=inlinfo->label_index;
1469 firstlocal = inlinfo->firstlocal;
1473 if (p != jcodelength)
1474 panic("Command-sequence crosses code-boundary");
1477 panic("Code does not end with branch/return/athrow - stmt");
1479 /* adjust block count if target 0 is not first intermediate instruction */
1481 if (!block_index[0] || (block_index[0] > 1))
1484 /* copy local to global variables */
1487 block_count = b_count;
1488 stack_count = s_count + block_count * maxstack;
1490 /* allocate stack table */
1492 stack = DMNEW(stackelement, stack_count);
1497 bptr = block = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1502 /* additional block if target 0 is not first intermediate instruction */
1504 if (!block_index[0] || (block_index[0] > 1)) {
1505 bptr->iinstr = instr;
1508 bptr->type = BBTYPE_STD;
1509 bptr->branchrefs = NULL;
1510 bptr->pre_count = 0;
1511 bptr->debug_nr = c_debug_nr++;
1514 (bptr - 1)->next = bptr;
1517 /* allocate blocks */
1519 for (p = 0; p < cumjcodelength; p++) {
1520 if (block_index[p] & 1) {
1521 bptr->iinstr = instr + (block_index[p] >> 1);
1522 bptr->debug_nr = c_debug_nr++;
1524 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1528 bptr->type = BBTYPE_STD;
1529 bptr->branchrefs = NULL;
1530 block_index[p] = b_count;
1531 bptr->pre_count = 0;
1534 (bptr - 1)->next = bptr;
1538 /* allocate additional block at end */
1540 bptr->instack = bptr->outstack = NULL;
1541 bptr->indepth = bptr->outdepth = 0;
1542 bptr->iinstr = NULL;
1543 (bptr - 1)->icount = (instr + instr_count) - (bptr - 1)->iinstr;
1548 bptr->type = BBTYPE_STD;
1549 bptr->branchrefs = NULL;
1550 bptr->pre_count = 0;
1551 bptr->debug_nr = c_debug_nr++;
1552 (bptr - 1)->next = bptr;
1557 if (exceptiontablelength > 0)
1558 extable[exceptiontablelength - 1].down = NULL;
1562 for (i = 0; i < exceptiontablelength; ++i) {
1563 p = extable[i].startpc;
1564 extable[i].start = block + block_index[p];
1566 p = extable[i].endpc;
1567 extable[i].end = block + block_index[p];
1569 p = extable[i].handlerpc;
1570 extable[i].handler = block + block_index[p];
1574 if (useinlining) inlining_cleanup();
1575 useinlining = useinltmp;
1580 * These are local overrides for various environment variables in Emacs.
1581 * Please do not remove this and leave it at the end of the file, where
1582 * Emacs will automagically detect them.
1583 * ---------------------------------------------------------------------
1586 * indent-tabs-mode: t