1 /* jit/parse.c *****************************************************************
3 Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
5 See file COPYRIGHT for information on usage and disclaimer of warranties
7 Parser for JavaVM to intermediate code translation
9 Author: Andreas Krall EMAIL: cacao@complang.tuwien.ac.at
11 Last Change: $Id: parse.c 553 2003-11-01 20:50:03Z twisti $
12 include Rapid Type Analysis parse - 5/2003 - carolyn
15 *******************************************************************************/
19 /* data about the currently parsed method */
21 static classinfo *rt_class; /* class the compiled method belongs to */
22 static methodinfo *rt_method; /* pointer to method info of compiled method */
23 static utf *rt_descriptor; /* type descriptor of compiled method */
24 static int rt_jcodelength; /*length of JavaVM-codes */
25 static u1 *rt_jcode; /* pointer to start of JavaVM-code */
28 /* macros for byte code fetching ***********************************************
30 fetch a byte code of given size from position p in code array jcode
32 *******************************************************************************/
34 #define code_get_u1(p) jcode[p]
35 #define code_get_s1(p) ((s1)jcode[p])
36 #define code_get_u2(p) ((((u2)jcode[p])<<8)+jcode[p+1])
37 #define code_get_s2(p) ((s2)((((u2)jcode[p])<<8)+jcode[p+1]))
38 #define code_get_u4(p) ((((u4)jcode[p])<<24)+(((u4)jcode[p+1])<<16)\
39 +(((u4)jcode[p+2])<<8)+jcode[p+3])
40 #define code_get_s4(p) ((s4)((((u4)jcode[p])<<24)+(((u4)jcode[p+1])<<16)\
41 +(((u4)jcode[p+2])<<8)+jcode[p+3]))
47 /*#define debug_writebranch printf("op: %s i: %d label_index[i]: %d\n",icmd_names[opcode], i, label_index[i]);*/
48 #define debug_writebranch
50 /* functionc compiler_addinitclass *********************************************
52 add class into the list of classes to initialize
54 *******************************************************************************/
56 static void compiler_addinitclass (classinfo *c)
60 if (c->initialized) return;
62 cl = chain_first(uninitializedclasses);
67 cl = chain_next(uninitializedclasses);
73 sprintf(logtext, "compiler_addinitclass: ");
74 utf_sprint(logtext+strlen(logtext), c->name);
77 chain_addlast(uninitializedclasses, c);
82 sprintf(logtext, "compiler_addinitclass: ");
83 utf_sprint(logtext+strlen(logtext), c->name);
86 chain_addbefore(uninitializedclasses, c);
89 cl = chain_next(uninitializedclasses);
94 /* function descriptor2typesL ***************************************************
96 decodes a already checked method descriptor. The parameter count, the
97 return type and the argument types are stored in the passed methodinfo.
98 gets and saves classptr for object ref.s
100 *******************************************************************************/
102 classSetNode * descriptor2typesL (methodinfo *m)
109 classinfo** classtypes;
112 classSetNode *p=NULL;
113 if (debugInfo >= 1) {
114 printf("In descriptor2typesL >>>\t"); fflush(stdout);
115 utf_display(m->class->name); printf(".");
116 method_display(m);fflush(stdout);
120 desc = MNEW (char, 256);
121 types = DMNEW (u1, m->descriptor->blength);
122 classtypes = MNEW (classinfo*, m->descriptor->blength+1);
123 m->returnclass = NULL;
125 if (!(m->flags & ACC_STATIC)) {
127 if (debugInfo >= 1) {
128 printf("param #0 (this?) method class =");utf_display(m->class->name);printf("\n");
130 classtypes[pcount] = m->class;
131 p = addClassCone(p, m->class);
135 utf_ptr = m->descriptor->text + 1;
136 strcpy (desc,utf_ptr);
138 while ((c = *desc++) != ')') {
145 case 'Z': *tptr++ = TYPE_INT;
147 case 'J': *tptr++ = TYPE_LNG;
149 case 'F': *tptr++ = TYPE_FLT;
151 case 'D': *tptr++ = TYPE_DBL;
153 case 'L': *tptr++ = TYPE_ADR;
154 /* get class string */
155 class = strtok(desc,";");
156 desc = strtok(NULL,"\0");
157 /* get/save classinfo ptr */
158 classtypes[pcount-1] = class_get(utf_new_char(class));
159 p = addClassCone(p, class_get(utf_new_char(class)));
160 if (debugInfo >= 1) {
161 printf("LParam#%i 's class type is: %s\n",pcount-1,class);fflush(stdout);
162 printf("Lclasstypes[%i]=",pcount-1);fflush(stdout);
163 utf_display(classtypes[pcount-1]->name);
166 case '[': *tptr++ = TYPE_ADR;
169 /* get class string */
171 class = strtok(desc,";");
172 desc = strtok(NULL,"\0");
173 /* get/save classinfo ptr */
174 classtypes[pcount-1] = class_get(utf_new_char(class));
175 p= addClassCone(p, class_get(utf_new_char(class)));
176 if (debugInfo >= 1) {
177 printf("[Param#%i 's class type is: %s\n",pcount-1,class);
178 printf("[classtypes[%i]=",pcount-1);fflush(stdout);
179 utf_display(classtypes[pcount-1]->name);
184 classtypes[pcount-1] = NULL;
187 panic("Ill formed methodtype-descriptor");
191 /* compute return type */
197 case 'Z': m->returntype = TYPE_INT;
199 case 'J': m->returntype = TYPE_LNG;
201 case 'F': m->returntype = TYPE_FLT;
203 case 'D': m->returntype = TYPE_DBL;
206 m->returntype = TYPE_ADR;
214 m->returntype = TYPE_ADR;
216 /* get class string */
217 class = strtok(desc,";");
218 m->returnclass = class_get(utf_new_char(class));
219 if (m->returnclass == NULL) {
220 printf("class=%s :\t",class);
221 panic ("return class not found");
224 case 'V': m->returntype = TYPE_VOID;
227 default: panic("Ill formed methodtype-descriptor-ReturnType");
230 m->paramcount = pcount;
231 m->paramtypes = types;
232 m->paramclass = classtypes;
236 for (i=0; i< m->paramcount; i++) {
237 if ((m->paramtypes[i] == TYPE_ADR) && (m->paramclass[i] != NULL)) {
238 printf("Param #%i is:\t",i);
239 utf_display(m->paramclass[i]->name);
244 if ((m->returntype == TYPE_ADR) && (m->returnclass != NULL)) {
245 printf("\tReturn Type is:\t"); fflush(stdout);
246 utf_display(m->returnclass->name);
250 printf("params2types: START results in a set \n");
251 printf("param2types: A Set size=%i=\n",sizeOfSet(p));
258 /* function descriptor2types ***************************************************
260 decodes a already checked method descriptor. The parameter count, the
261 return type and the argument types are stored in the passed methodinfo.
263 *******************************************************************************/
265 static void descriptor2types (methodinfo *m)
271 types = DMNEW (u1, m->descriptor->blength);
274 if (!(m->flags & ACC_STATIC)) {
279 utf_ptr = m->descriptor->text + 1;
281 while ((c = *utf_ptr++) != ')') {
288 case 'Z': *tptr++ = TYPE_INT;
290 case 'J': *tptr++ = TYPE_LNG;
292 case 'F': *tptr++ = TYPE_FLT;
294 case 'D': *tptr++ = TYPE_DBL;
296 case 'L': *tptr++ = TYPE_ADR;
297 while (*utf_ptr++ != ';');
299 case '[': *tptr++ = TYPE_ADR;
303 while (*utf_ptr++ != ';') /* skip */;
305 default: panic ("Ill formed methodtype-descriptor");
309 /* compute return type */
311 switch (*utf_ptr++) {
316 case 'Z': m->returntype = TYPE_INT;
318 case 'J': m->returntype = TYPE_LNG;
320 case 'F': m->returntype = TYPE_FLT;
322 case 'D': m->returntype = TYPE_DBL;
325 case 'L': m->returntype = TYPE_ADR;
327 case 'V': m->returntype = TYPE_VOID;
330 default: panic ("Ill formed methodtype-descriptor");
333 m->paramcount = pcount;
334 m->paramtypes = types;
338 /*******************************************************************************
340 function 'parse' scans the JavaVM code and generates intermediate code
342 During parsing the block index table is used to store at bit pos 0
343 a flag which marks basic block starts and at position 1 to 31 the
344 intermediate instruction index. After parsing the block index table
345 is scanned, for marked positions a block is generated and the block
346 number is stored in the block index table.
348 *******************************************************************************/
350 /* intermediate code generating macros */
352 #define PINC iptr++;ipc++
353 #define LOADCONST_I(v) iptr->opc=ICMD_ICONST;iptr->op1=0;iptr->val.i=(v);PINC
354 #define LOADCONST_L(v) iptr->opc=ICMD_LCONST;iptr->op1=0;iptr->val.l=(v);PINC
355 #define LOADCONST_F(v) iptr->opc=ICMD_FCONST;iptr->op1=0;iptr->val.f=(v);PINC
356 #define LOADCONST_D(v) iptr->opc=ICMD_DCONST;iptr->op1=0;iptr->val.d=(v);PINC
357 #define LOADCONST_A(v) iptr->opc=ICMD_ACONST;iptr->op1=0;iptr->val.a=(v);PINC
358 #define OP(o) iptr->opc=(o);iptr->op1=0;iptr->val.l=0;PINC
359 #define OP1(o,o1) iptr->opc=(o);iptr->op1=(o1);iptr->val.l=(0);PINC
360 #define OP2I(o,o1,v) iptr->opc=(o);iptr->op1=(o1);iptr->val.i=(v);PINC
361 #define OP2A(o,o1,v) iptr->opc=(o);iptr->op1=(o1);iptr->val.a=(v);PINC
362 #define BUILTIN1(v,t) isleafmethod=false;iptr->opc=ICMD_BUILTIN1;iptr->op1=t;\
364 #define BUILTIN2(v,t) isleafmethod=false;iptr->opc=ICMD_BUILTIN2;iptr->op1=t;\
366 #define BUILTIN3(v,t) isleafmethod=false;iptr->opc=ICMD_BUILTIN3;iptr->op1=t;\
370 /* block generating and checking macros */
372 #define block_insert(i) {if(!(block_index[i]&1))\
373 {b_count++;block_index[i] |= 1;}}
374 #define bound_check(i) {if((i< 0) || (i>=cumjcodelength)) \
375 panic("branch target out of code-boundary");}
376 #define bound_check1(i) {if((i< 0) || (i>cumjcodelength)) \
377 panic("branch target out of code-boundary");}
378 /* FIXME really use cumjcodelength for the bound_checkers ? */
380 static xtable* fillextable (xtable* extable, exceptiontable *raw_extable, int exceptiontablelength, int *label_index, int *block_count)
384 if (exceptiontablelength == 0)
387 b_count = *block_count;
388 for (i = 0; i < exceptiontablelength; i++) {
390 p = raw_extable[i].startpc;
391 if (label_index != NULL) p = label_index[p];
392 extable[i].startpc = p;
396 p = raw_extable[i].endpc;
397 if (label_index != NULL) p = label_index[p];
398 extable[i].endpc = p;
400 if (p < cumjcodelength)
403 p = raw_extable[i].handlerpc;
404 if (label_index != NULL) p = label_index[p];
405 extable[i].handlerpc = p;
409 extable[i].catchtype = raw_extable[i].catchtype;
411 extable[i].next = NULL;
412 extable[i].down = &extable[i+1];
414 *block_count = b_count;
415 return &extable[i]; /* return the next free xtable* */
420 int p; /* java instruction counter */
421 int nextp; /* start of next java instruction */
422 int opcode; /* java opcode */
423 int i; /* temporary for different uses (counters) */
424 int ipc = 0; /* intermediate instruction counter */
425 int b_count = 0; /* basic block counter */
426 int s_count = 0; /* stack element counter */
427 bool blockend = false; /* true if basic block end has been reached */
428 bool iswide = false; /* true if last instruction was a wide */
429 instruction *iptr; /* current pointer into instruction array */
430 int gp; /* global java instruction counter */
431 /* inlining info for current method */
432 inlining_methodinfo *inlinfo = inlining_rootinfo, *tmpinlinf;
433 int nextgp = -1; /* start of next method to be inlined */
434 int *label_index = NULL; /* label redirection table */
435 int firstlocal = 0; /* first local variable of method */
436 xtable* nextex; /* points next free entry in extable */
443 label_index = inlinfo->label_index;
444 maxstack = cummaxstack;
445 exceptiontablelength=cumextablelength;
448 useinltmp = useinlining; /*FIXME remove this after debugging */
449 /*useinlining = false;*/ /* and merge the if-statements */
452 cumjcodelength = jcodelength;
454 tmpinlinf = (inlining_methodinfo*) list_first(inlinfo->inlinedmethods);
455 if (tmpinlinf != NULL) nextgp = tmpinlinf->startgp;
458 /*RTAprint*/ if ( ((opt_rt) ||(opt_xta) || (opt_vta)) && ((pOpcodes == 2) || (pOpcodes == 3)) )
459 /*RTAprint*/ {printf("PARSE method name =");
460 /*RTAprint*/ utf_display(method->class->name);printf(".");
461 /*RTAprint*/ method_display(method); printf(">\n\n");fflush(stdout);}
462 if ((opt_rt) || (opt_xta)) {
463 RT_jit_parse(method);
467 printf("VTA requested, but not yet implemented\n");
471 /* allocate instruction array and block index table */
473 /* 1 additional for end ipc and 3 for loop unrolling */
475 block_index = DMNEW(int, cumjcodelength + 4);
477 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
478 /* additional MONITOREXITS are reached by branches which are 3 bytes */
480 iptr = instr = DMNEW(instruction, cumjcodelength + 5);
482 /* initialize block_index table (unrolled four times) */
487 for (i = 0, ip = block_index; i <= cumjcodelength; i += 4, ip += 4) {
495 /* compute branch targets of exception table */
497 extable = DMNEW(xtable, exceptiontablelength + 1);
499 for (i = 0; i < method->exceptiontablelength; i++) {
501 p = extable[i].startpc = raw_extable[i].startpc;
502 if (useinlining) p = label_index[p];
506 p = extable[i].endpc = raw_extable[i].endpc;
507 if (useinlining) p = label_index[p];
509 if (p < cumjcodelength)
512 p = extable[i].handlerpc = raw_extable[i].handlerpc;
516 extable[i].catchtype = raw_extable[i].catchtype;
518 extable[i].next = NULL;
519 extable[i].down = &extable[i+1];
523 nextex = fillextable(extable, raw_extable, method->exceptiontablelength, label_index, &b_count);
525 s_count = 1 + exceptiontablelength; /* initialize stack element counter */
528 if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
533 /* scan all java instructions */
535 for (p = 0, gp = 0; p < jcodelength; gp += (nextp - p), p = nextp) {
537 /* DEBUG printf("p:%d gp:%d ",p,gp); */
540 if ((useinlining) && (gp == nextgp)) {
542 bool *readonly = NULL;
544 opcode = code_get_u1 (p);
545 nextp = p += jcommandsize[opcode];
546 tmpinlinf = list_first(inlinfo->inlinedmethods);
547 firstlocal = tmpinlinf->firstlocal;
548 label_index = tmpinlinf->label_index;
549 readonly = tmpinlinf->readonly;
550 for (i=0, tptr=tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1 ; i<tmpinlinf->method->paramcount; i++, tptr--)
554 if ( (i==0) && inlineparamopt) {
555 OP1(ICMD_CLEAR_ARGREN, firstlocal);
558 if ( !inlineparamopt || !readonly[i] )
560 else op = ICMD_READONLY_ARG;
563 OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i);
565 /* block_index[gp] |= (ipc << 1);*/ /*FIXME: necessary ? */
567 inlining_save_compiler_variables();
568 inlining_set_compiler_variables(tmpinlinf);
569 if (inlinfo->inlinedmethods == NULL) gp = -1;
571 tmpinlinf = list_first(inlinfo->inlinedmethods);
572 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
574 if (method->exceptiontablelength > 0)
575 nextex = fillextable(nextex, method->exceptiontable, method->exceptiontablelength, label_index, &b_count);
579 opcode = code_get_u1 (p); /* fetch op code */
582 /*RTAprint*/ if ((opt_rt) && ((pOpcodes == 2) || (pOpcodes == 3)) )
583 /*RTAprint*/ {printf("Parse<%i> p=%i<%i< opcode=<%i> %s\n",
584 /*RTAprint*/ pOpcodes, p,rt_jcodelength,opcode,icmd_names[opcode]);}
586 block_index[gp] |= (ipc << 1); /* store intermediate count */
589 block_insert(gp); /* start new block */
593 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
594 s_count += stackreq[opcode]; /* compute stack element count */
601 /* pushing constants onto the stack p */
604 LOADCONST_I(code_get_s1(p+1));
608 LOADCONST_I(code_get_s2(p+1));
612 i = code_get_u1(p+1);
613 goto pushconstantitem;
616 i = code_get_u2(p + 1);
620 if (i >= class->cpcount)
621 panic ("Attempt to access constant outside range");
623 switch (class->cptags[i]) {
624 case CONSTANT_Integer:
625 LOADCONST_I(((constant_integer*)
626 (class->cpinfos[i]))->value);
629 LOADCONST_L(((constant_long*)
630 (class->cpinfos[i]))->value);
633 LOADCONST_F(((constant_float*)
634 (class->cpinfos[i]))->value);
636 case CONSTANT_Double:
637 LOADCONST_D(((constant_double*)
638 (class->cpinfos[i]))->value);
640 case CONSTANT_String:
641 LOADCONST_A(literalstring_new((utf*)
642 (class->cpinfos[i])));
644 default: panic("Invalid constant type to push");
648 case JAVA_ACONST_NULL:
659 LOADCONST_I(opcode - JAVA_ICONST_0);
664 LOADCONST_L(opcode - JAVA_LCONST_0);
670 LOADCONST_F(opcode - JAVA_FCONST_0);
675 LOADCONST_D(opcode - JAVA_DCONST_0);
678 /* loading variables onto the stack */
686 i = code_get_u1(p+1);
688 i = code_get_u2(p+1);
692 OP1(opcode, i + firstlocal);
699 OP1(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
706 OP1(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
713 OP1(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
720 OP1(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
727 OP1(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
730 /* storing stack values into local variables */
738 i = code_get_u1(p+1);
740 i = code_get_u2(p+1);
744 OP1(opcode, i + firstlocal);
751 OP1(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
758 OP1(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
765 OP1(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
772 OP1(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
779 OP1(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
787 i = code_get_u1(p + 1);
788 v = code_get_s1(p + 2);
791 i = code_get_u2(p + 1);
792 v = code_get_s2(p + 3);
796 OP2I(opcode, i + firstlocal, v);
800 /* wider index for loading, storing and incrementing */
807 /* managing arrays ************************************************/
810 OP2I(ICMD_CHECKASIZE, 0, 0);
811 switch (code_get_s1(p+1)) {
813 BUILTIN1((functionptr)builtin_newarray_boolean, TYPE_ADR);
816 BUILTIN1((functionptr)builtin_newarray_char, TYPE_ADR);
819 BUILTIN1((functionptr)builtin_newarray_float, TYPE_ADR);
822 BUILTIN1((functionptr)builtin_newarray_double, TYPE_ADR);
825 BUILTIN1((functionptr)builtin_newarray_byte, TYPE_ADR);
828 BUILTIN1((functionptr)builtin_newarray_short, TYPE_ADR);
831 BUILTIN1((functionptr)builtin_newarray_int, TYPE_ADR);
834 BUILTIN1((functionptr)builtin_newarray_long, TYPE_ADR);
836 default: panic("Invalid array-type to create");
841 OP2I(ICMD_CHECKASIZE, 0, 0);
842 i = code_get_u2(p+1);
843 /* array or class type ? */
844 if (class_constanttype (class, i) == CONSTANT_Arraydescriptor) {
846 LOADCONST_A(class_getconstant(class, i,
847 CONSTANT_Arraydescriptor));
848 #if defined(__I386__)
849 BUILTIN2((functionptr) asm_builtin_newarray_array, TYPE_ADR);
851 BUILTIN2((functionptr)builtin_newarray_array, TYPE_ADR);
855 LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
857 #if defined(__I386__)
858 BUILTIN2((functionptr) asm_builtin_anewarray, TYPE_ADR);
860 BUILTIN2((functionptr)builtin_anewarray, TYPE_ADR);
865 case JAVA_MULTIANEWARRAY:
867 i = code_get_u2(p+1);
869 int v = code_get_u1(p+3);
870 constant_arraydescriptor *desc =
871 class_getconstant (class, i, CONSTANT_Arraydescriptor);
872 OP2A(opcode, v, desc);
894 i = p + code_get_s2(p+1);
906 i = p + code_get_s4(p+1);
919 i = code_get_u1(p+1);
921 i = code_get_u2(p+1);
928 if (isinlinedmethod) {
929 OP1(ICMD_GOTO, inlinfo->stopgp);
933 OP1(opcode, i + firstlocal);
944 if (isinlinedmethod) {
945 /* if (p==jcodelength-1) {*/ /* return is at end of inlined method */
950 OP1(ICMD_GOTO, inlinfo->stopgp);
964 /* table jumps ********************************/
966 case JAVA_LOOKUPSWITCH:
972 nextp = ALIGN((p + 1), 4);
974 tablep = (s4*)(jcode + nextp);
977 num = code_get_u4(nextp + 4);
978 tablep = DMNEW(s4, num * 2 + 2);
981 OP2A(opcode, 0, tablep);
985 j = p + code_get_s4(nextp);
986 if (useinlining) j = label_index[j];
987 *tablep = j; /* restore for little endian */
993 /* number of pairs */
995 num = code_get_u4(nextp);
1000 for (i = 0; i < num; i++) {
1004 j = code_get_s4(nextp);
1005 *tablep = j; /* restore for little endian */
1011 j = p + code_get_s4(nextp);
1012 if (useinlining) j = label_index[j];
1013 *tablep = j; /* restore for little endian */
1024 case JAVA_TABLESWITCH:
1030 nextp = ALIGN((p + 1), 4);
1032 tablep = (s4*)(jcode + nextp);
1035 num = code_get_u4(nextp + 8) - code_get_u4(nextp + 4);
1036 tablep = DMNEW(s4, num + 1 + 3);
1039 OP2A(opcode, 0, tablep);
1041 /* default target */
1043 j = p + code_get_s4(nextp);
1044 if (useinlining) j = label_index[j];
1045 *tablep = j; /* restore for little endian */
1053 j = code_get_s4(nextp);
1054 *tablep = j; /* restore for little endian */
1060 num = code_get_s4(nextp);
1061 *tablep = num; /* restore for little endian */
1067 for (i = 0; i <= num; i++) {
1068 j = p + code_get_s4(nextp);
1069 if (useinlining) j = label_index[j];
1070 *tablep = j; /* restore for little endian */
1081 /* load and store of object fields *******************/
1084 BUILTIN3((functionptr) asm_builtin_aastore, TYPE_VOID);
1087 case JAVA_PUTSTATIC:
1088 case JAVA_GETSTATIC:
1089 i = code_get_u2(p + 1);
1091 constant_FMIref *fr;
1093 fr = class_getconstant (class, i, CONSTANT_Fieldref);
1094 fi = class_findfield (fr->class, fr->name, fr->descriptor);
1095 compiler_addinitclass (fr->class);
1096 OP2A(opcode, fi->type, fi);
1101 i = code_get_u2(p + 1);
1103 constant_FMIref *fr;
1105 fr = class_getconstant (class, i, CONSTANT_Fieldref);
1106 fi = class_findfield (fr->class, fr->name, fr->descriptor);
1107 OP2A(opcode, fi->type, fi);
1112 /* method invocation *****/
1114 case JAVA_INVOKESTATIC:
1115 i = code_get_u2(p + 1);
1117 constant_FMIref *mr;
1120 mr = class_getconstant (class, i, CONSTANT_Methodref);
1121 mi = class_findmethod (mr->class, mr->name, mr->descriptor);
1122 /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt)
1123 /*RTAprint*/ {printf(" method name =");
1124 /*RTAprint*/ utf_display(mi->class->name); printf(".");
1125 /*RTAprint*/ utf_display(mi->name);printf("\tINVOKE STATIC\n");
1126 /*RTAprint*/ fflush(stdout);}
1127 if (! (mi->flags & ACC_STATIC))
1128 panic ("Static/Nonstatic mismatch calling static method");
1129 descriptor2types(mi);
1132 OP2A(opcode, mi->paramcount, mi);
1135 case JAVA_INVOKESPECIAL:
1136 case JAVA_INVOKEVIRTUAL:
1137 i = code_get_u2(p + 1);
1139 constant_FMIref *mr;
1142 mr = class_getconstant (class, i, CONSTANT_Methodref);
1143 mi = class_findmethod (mr->class, mr->name, mr->descriptor);
1144 /*RTAprint*/ if (((pOpcodes == 2) || (pOpcodes == 3)) && opt_rt)
1145 /*RTAprint*/ {printf(" method name =");
1147 /*RTAprint*/ utf_display(mi->class->name); printf(".");
1148 /*RTAprint*/ utf_display(mi->name);printf("\tINVOKE SPECIAL/VIRTUAL\n");
1149 /*RTAprint*/ fflush(stdout);}
1151 if (mi->flags & ACC_STATIC)
1152 panic ("Static/Nonstatic mismatch calling static method");
1153 descriptor2types(mi);
1155 OP2A(opcode, mi->paramcount, mi);
1158 case JAVA_INVOKEINTERFACE:
1159 i = code_get_u2(p + 1);
1161 constant_FMIref *mr;
1164 mr = class_getconstant (class, i, CONSTANT_InterfaceMethodref);
1165 mi = class_findmethod (mr->class, mr->name, mr->descriptor);
1166 if (mi->flags & ACC_STATIC)
1167 panic ("Static/Nonstatic mismatch calling static method");
1168 descriptor2types(mi);
1170 OP2A(opcode, mi->paramcount, mi);
1174 /* miscellaneous object operations *******/
1177 i = code_get_u2 (p+1);
1179 LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1181 BUILTIN1((functionptr) builtin_new, TYPE_ADR);
1184 case JAVA_CHECKCAST:
1185 i = code_get_u2(p+1);
1187 /* array type cast-check */
1188 if (class_constanttype (class, i) == CONSTANT_Arraydescriptor) {
1189 LOADCONST_A(class_getconstant(class, i, CONSTANT_Arraydescriptor));
1191 BUILTIN2((functionptr) asm_builtin_checkarraycast, TYPE_ADR);
1193 else { /* object type cast-check */
1195 LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1197 BUILTIN2((functionptr) asm_builtin_checkcast, TYPE_ADR);
1199 OP2A(opcode, 1, (class_getconstant(class, i, CONSTANT_Class)));
1203 case JAVA_INSTANCEOF:
1204 i = code_get_u2(p+1);
1206 /* array type cast-check */
1207 if (class_constanttype (class, i) == CONSTANT_Arraydescriptor) {
1208 LOADCONST_A(class_getconstant(class, i, CONSTANT_Arraydescriptor));
1210 #if defined(__I386__)
1211 BUILTIN2((functionptr) asm_builtin_arrayinstanceof, TYPE_INT);
1213 BUILTIN2((functionptr) builtin_arrayinstanceof, TYPE_INT);
1216 else { /* object type cast-check */
1218 LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1220 BUILTIN2((functionptr) builtin_instanceof, TYPE_INT);
1222 OP2A(opcode, 1, (class_getconstant(class, i, CONSTANT_Class)));
1226 case JAVA_MONITORENTER:
1229 BUILTIN1((functionptr) asm_builtin_monitorenter, TYPE_VOID);
1233 OP(ICMD_NULLCHECKPOP);
1237 case JAVA_MONITOREXIT:
1240 BUILTIN1((functionptr) asm_builtin_monitorexit, TYPE_VOID);
1249 /* any other basic operation **************************************/
1268 #if defined(__I386__)
1271 BUILTIN2((functionptr) builtin_frem, TYPE_FLOAT);
1276 #if defined(__I386__)
1279 BUILTIN2((functionptr) builtin_drem, TYPE_DOUBLE);
1284 #if defined(__ALPHA__)
1286 BUILTIN1((functionptr) builtin_f2i, TYPE_INT);
1295 #if defined(__ALPHA__)
1297 BUILTIN1((functionptr) builtin_f2l, TYPE_LONG);
1306 #if defined(__ALPHA__)
1308 BUILTIN1((functionptr) builtin_d2i, TYPE_INT);
1317 #if defined(__ALPHA__)
1319 BUILTIN1((functionptr) builtin_d2l, TYPE_LONG);
1327 case JAVA_BREAKPOINT:
1328 panic("Illegal opcode Breakpoint encountered");
1384 printf("Illegal opcode %d at instr %d", opcode, ipc);
1385 panic("encountered");
1396 if ((isinlinedmethod) && (p==jcodelength-1)) { /*end of an inlined method */
1397 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1398 gp = inlinfo->stopgp;
1399 inlining_restore_compiler_variables();
1400 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1401 if (inlinfo->inlinedmethods == NULL) nextgp = -1;
1403 tmpinlinf = list_first(inlinfo->inlinedmethods);
1404 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1406 /* printf("nextpgp: %d\n", nextgp); */
1407 label_index=inlinfo->label_index;
1408 firstlocal = inlinfo->firstlocal;
1412 if (p != jcodelength)
1413 panic("Command-sequence crosses code-boundary");
1416 panic("Code does not end with branch/return/athrow - stmt");
1418 /* adjust block count if target 0 is not first intermediate instruction */
1420 if (!block_index[0] || (block_index[0] > 1))
1423 /* copy local to global variables */
1426 block_count = b_count;
1427 stack_count = s_count + block_count * maxstack;
1429 /* allocate stack table */
1431 stack = DMNEW(stackelement, stack_count);
1436 bptr = block = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1441 /* additional block if target 0 is not first intermediate instruction */
1443 if (!block_index[0] || (block_index[0] > 1)) {
1444 bptr->iinstr = instr;
1447 bptr->type = BBTYPE_STD;
1448 bptr->branchrefs = NULL;
1449 bptr->pre_count = 0;
1450 bptr->debug_nr = c_debug_nr++;
1453 (bptr - 1)->next = bptr;
1457 /* allocate blocks */
1460 for (p = 0; p < cumjcodelength; p++)
1462 if (block_index[p] & 1) {
1463 bptr->iinstr = instr + (block_index[p] >> 1);
1464 bptr->debug_nr = c_debug_nr++;
1466 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1470 bptr->type = BBTYPE_STD;
1471 bptr->branchrefs = NULL;
1472 block_index[p] = b_count;
1473 bptr->pre_count = 0;
1477 (bptr - 1)->next = bptr;
1480 /* allocate additional block at end */
1483 bptr->instack = bptr->outstack = NULL;
1484 bptr->indepth = bptr->outdepth = 0;
1485 bptr->iinstr = NULL;
1486 (bptr - 1)->icount = (instr + instr_count) - (bptr - 1)->iinstr;
1491 bptr->type = BBTYPE_STD;
1492 bptr->branchrefs = NULL;
1493 bptr->pre_count = 0;
1494 bptr->debug_nr = c_debug_nr++;
1496 (bptr - 1)->next = bptr;
1501 if (exceptiontablelength > 0)
1502 extable[exceptiontablelength-1].down = NULL;
1506 for (i = 0; i < exceptiontablelength; ++i) {
1507 p = extable[i].startpc;
1508 extable[i].start = block + block_index[p];
1510 p = extable[i].endpc;
1511 extable[i].end = block + block_index[p];
1513 p = extable[i].handlerpc;
1514 extable[i].handler = block + block_index[p];
1518 if (useinlining) inlining_cleanup();
1519 useinlining = useinltmp;
1522 #include "parseRT.h"
1525 * These are local overrides for various environment variables in Emacs.
1526 * Please do not remove this and leave it at the end of the file, where
1527 * Emacs will automagically detect them.
1528 * ---------------------------------------------------------------------
1531 * indent-tabs-mode: t