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 562 2003-11-03 00:34:34Z twisti $
41 #include "loop/loop.h"
47 #include "toolbox/memory.h"
48 #include "toolbox/loging.h"
51 /* data about the currently parsed method */
53 classinfo *rt_class; /* class the compiled method belongs to */
54 methodinfo *rt_method; /* pointer to method info of compiled method */
55 utf *rt_descriptor; /* type descriptor of compiled method */
56 int rt_jcodelength; /*length of JavaVM-codes */
57 u1 *rt_jcode; /* pointer to start of JavaVM-code */
63 /*#define debug_writebranch printf("op: %s i: %d label_index[i]: %d\n",icmd_names[opcode], i, label_index[i]);*/
64 #define debug_writebranch
68 /* functionc compiler_addinitclass *********************************************
70 add class into the list of classes to initialize
72 *******************************************************************************/
74 void compiler_addinitclass(classinfo *c)
78 if (c->initialized) return;
80 cl = chain_first(uninitializedclasses);
85 cl = chain_next(uninitializedclasses);
91 sprintf(logtext, "compiler_addinitclass: ");
92 utf_sprint(logtext+strlen(logtext), c->name);
95 chain_addlast(uninitializedclasses, c);
100 sprintf(logtext, "compiler_addinitclass: ");
101 utf_sprint(logtext+strlen(logtext), c->name);
104 chain_addbefore(uninitializedclasses, c);
107 cl = chain_next(uninitializedclasses);
113 /* function descriptor2typesL ***************************************************
115 decodes a already checked method descriptor. The parameter count, the
116 return type and the argument types are stored in the passed methodinfo.
117 gets and saves classptr for object ref.s
119 *******************************************************************************/
121 classSetNode *descriptor2typesL(methodinfo *m)
128 classinfo** classtypes;
131 classSetNode *p=NULL;
132 if (debugInfo >= 1) {
133 printf("In descriptor2typesL >>>\t"); fflush(stdout);
134 utf_display(m->class->name); printf(".");
135 method_display(m);fflush(stdout);
139 desc = MNEW (char, 256);
140 types = DMNEW (u1, m->descriptor->blength);
141 classtypes = MNEW (classinfo*, m->descriptor->blength+1);
142 m->returnclass = NULL;
144 if (!(m->flags & ACC_STATIC)) {
146 if (debugInfo >= 1) {
147 printf("param #0 (this?) method class =");utf_display(m->class->name);printf("\n");
149 classtypes[pcount] = m->class;
150 p = addClassCone(p, m->class);
154 utf_ptr = m->descriptor->text + 1;
155 strcpy (desc,utf_ptr);
157 while ((c = *desc++) != ')') {
164 case 'Z': *tptr++ = TYPE_INT;
166 case 'J': *tptr++ = TYPE_LNG;
168 case 'F': *tptr++ = TYPE_FLT;
170 case 'D': *tptr++ = TYPE_DBL;
172 case 'L': *tptr++ = TYPE_ADR;
173 /* get class string */
174 class = strtok(desc,";");
175 desc = strtok(NULL,"\0");
176 /* get/save classinfo ptr */
177 classtypes[pcount-1] = class_get(utf_new_char(class));
178 p = addClassCone(p, class_get(utf_new_char(class)));
179 if (debugInfo >= 1) {
180 printf("LParam#%i 's class type is: %s\n",pcount-1,class);fflush(stdout);
181 printf("Lclasstypes[%i]=",pcount-1);fflush(stdout);
182 utf_display(classtypes[pcount-1]->name);
185 case '[': *tptr++ = TYPE_ADR;
188 /* get class string */
190 class = strtok(desc,";");
191 desc = strtok(NULL,"\0");
192 /* get/save classinfo ptr */
193 classtypes[pcount-1] = class_get(utf_new_char(class));
194 p= addClassCone(p, class_get(utf_new_char(class)));
195 if (debugInfo >= 1) {
196 printf("[Param#%i 's class type is: %s\n",pcount-1,class);
197 printf("[classtypes[%i]=",pcount-1);fflush(stdout);
198 utf_display(classtypes[pcount-1]->name);
203 classtypes[pcount-1] = NULL;
206 panic("Ill formed methodtype-descriptor");
210 /* compute return type */
216 case 'Z': m->returntype = TYPE_INT;
218 case 'J': m->returntype = TYPE_LNG;
220 case 'F': m->returntype = TYPE_FLT;
222 case 'D': m->returntype = TYPE_DBL;
225 m->returntype = TYPE_ADR;
233 m->returntype = TYPE_ADR;
235 /* get class string */
236 class = strtok(desc,";");
237 m->returnclass = class_get(utf_new_char(class));
238 if (m->returnclass == NULL) {
239 printf("class=%s :\t",class);
240 panic ("return class not found");
243 case 'V': m->returntype = TYPE_VOID;
246 default: panic("Ill formed methodtype-descriptor-ReturnType");
249 m->paramcount = pcount;
250 m->paramtypes = types;
251 m->paramclass = classtypes;
255 for (i=0; i< m->paramcount; i++) {
256 if ((m->paramtypes[i] == TYPE_ADR) && (m->paramclass[i] != NULL)) {
257 printf("Param #%i is:\t",i);
258 utf_display(m->paramclass[i]->name);
263 if ((m->returntype == TYPE_ADR) && (m->returnclass != NULL)) {
264 printf("\tReturn Type is:\t"); fflush(stdout);
265 utf_display(m->returnclass->name);
269 printf("params2types: START results in a set \n");
270 printf("param2types: A Set size=%i=\n",sizeOfSet(p));
279 /* function descriptor2types ***************************************************
281 decodes a already checked method descriptor. The parameter count, the
282 return type and the argument types are stored in the passed methodinfo.
284 *******************************************************************************/
286 void descriptor2types(methodinfo *m)
292 types = DMNEW(u1, m->descriptor->blength);
295 if (!(m->flags & ACC_STATIC)) {
300 utf_ptr = m->descriptor->text + 1;
302 while ((c = *utf_ptr++) != ')') {
309 case 'Z': *tptr++ = TYPE_INT;
311 case 'J': *tptr++ = TYPE_LNG;
313 case 'F': *tptr++ = TYPE_FLT;
315 case 'D': *tptr++ = TYPE_DBL;
317 case 'L': *tptr++ = TYPE_ADR;
318 while (*utf_ptr++ != ';');
320 case '[': *tptr++ = TYPE_ADR;
324 while (*utf_ptr++ != ';') /* skip */;
326 default: panic ("Ill formed methodtype-descriptor");
330 /* compute return type */
332 switch (*utf_ptr++) {
337 case 'Z': m->returntype = TYPE_INT;
339 case 'J': m->returntype = TYPE_LNG;
341 case 'F': m->returntype = TYPE_FLT;
343 case 'D': m->returntype = TYPE_DBL;
346 case 'L': m->returntype = TYPE_ADR;
348 case 'V': m->returntype = TYPE_VOID;
351 default: panic ("Ill formed methodtype-descriptor");
354 m->paramcount = pcount;
355 m->paramtypes = types;
360 /*******************************************************************************
362 function 'parse' scans the JavaVM code and generates intermediate code
364 During parsing the block index table is used to store at bit pos 0
365 a flag which marks basic block starts and at position 1 to 31 the
366 intermediate instruction index. After parsing the block index table
367 is scanned, for marked positions a block is generated and the block
368 number is stored in the block index table.
370 *******************************************************************************/
372 /* intermediate code generating macros */
374 #define PINC iptr++;ipc++
375 #define LOADCONST_I(v) iptr->opc=ICMD_ICONST;iptr->op1=0;iptr->val.i=(v);PINC
376 #define LOADCONST_L(v) iptr->opc=ICMD_LCONST;iptr->op1=0;iptr->val.l=(v);PINC
377 #define LOADCONST_F(v) iptr->opc=ICMD_FCONST;iptr->op1=0;iptr->val.f=(v);PINC
378 #define LOADCONST_D(v) iptr->opc=ICMD_DCONST;iptr->op1=0;iptr->val.d=(v);PINC
379 #define LOADCONST_A(v) iptr->opc=ICMD_ACONST;iptr->op1=0;iptr->val.a=(v);PINC
380 #define OP(o) iptr->opc=(o);iptr->op1=0;iptr->val.l=0;PINC
381 #define OP1(o,o1) iptr->opc=(o);iptr->op1=(o1);iptr->val.l=(0);PINC
382 #define OP2I(o,o1,v) iptr->opc=(o);iptr->op1=(o1);iptr->val.i=(v);PINC
383 #define OP2A(o,o1,v) iptr->opc=(o);iptr->op1=(o1);iptr->val.a=(v);PINC
384 #define BUILTIN1(v,t) isleafmethod=false;iptr->opc=ICMD_BUILTIN1;iptr->op1=t;\
386 #define BUILTIN2(v,t) isleafmethod=false;iptr->opc=ICMD_BUILTIN2;iptr->op1=t;\
388 #define BUILTIN3(v,t) isleafmethod=false;iptr->opc=ICMD_BUILTIN3;iptr->op1=t;\
392 /* block generating and checking macros */
394 #define block_insert(i) \
396 if (!(block_index[(i)] & 1)) { \
398 block_index[(i)] |= 1; \
403 /* FIXME really use cumjcodelength for the bound_checkers ? */
405 #define bound_check(i) \
407 if (i < 0 || i >= cumjcodelength) { \
408 panic("branch target out of code-boundary"); \
412 #define bound_check1(i) \
414 if (i < 0 || i > cumjcodelength) { \
415 panic("branch target out of code-boundary"); \
421 static xtable* fillextable(xtable* extable, exceptiontable *raw_extable, int exceptiontablelength, int *label_index, int *block_count)
425 if (exceptiontablelength == 0)
428 b_count = *block_count;
429 for (i = 0; i < exceptiontablelength; i++) {
431 p = raw_extable[i].startpc;
432 if (label_index != NULL) p = label_index[p];
433 extable[i].startpc = p;
437 p = raw_extable[i].endpc;
438 if (label_index != NULL) p = label_index[p];
439 extable[i].endpc = p;
441 if (p < cumjcodelength)
444 p = raw_extable[i].handlerpc;
445 if (label_index != NULL) p = label_index[p];
446 extable[i].handlerpc = p;
450 extable[i].catchtype = raw_extable[i].catchtype;
452 extable[i].next = NULL;
453 extable[i].down = &extable[i+1];
455 *block_count = b_count;
456 return &extable[i]; /* return the next free xtable* */
463 int p; /* java instruction counter */
464 int nextp; /* start of next java instruction */
465 int opcode; /* java opcode */
466 int i; /* temporary for different uses (counters) */
467 int ipc = 0; /* intermediate instruction counter */
468 int b_count = 0; /* basic block counter */
469 int s_count = 0; /* stack element counter */
470 bool blockend = false; /* true if basic block end has been reached */
471 bool iswide = false; /* true if last instruction was a wide */
472 instruction *iptr; /* current pointer into instruction array */
473 int gp; /* global java instruction counter */
474 /* inlining info for current method */
475 inlining_methodinfo *inlinfo = inlining_rootinfo;
476 inlining_methodinfo *tmpinlinf;
477 int nextgp = -1; /* start of next method to be inlined */
478 int *label_index = NULL; /* label redirection table */
479 int firstlocal = 0; /* first local variable of method */
480 xtable* nextex; /* points next free entry in extable */
486 label_index = inlinfo->label_index;
487 maxstack = cummaxstack;
488 exceptiontablelength = cumextablelength;
491 useinltmp = useinlining; /* FIXME remove this after debugging */
492 /*useinlining = false;*/ /* and merge the if-statements */
495 cumjcodelength = jcodelength;
498 tmpinlinf = (inlining_methodinfo*) list_first(inlinfo->inlinedmethods);
499 if (tmpinlinf != NULL) nextgp = tmpinlinf->startgp;
502 if ((opt_rt || opt_xta || opt_vta) && (pOpcodes == 2 || pOpcodes == 3)) {
503 printf("PARSE method name =");
504 utf_display(method->class->name);
506 method_display(method);
511 if (opt_rt || opt_xta) {
512 RT_jit_parse(method);
516 printf("VTA requested, but not yet implemented\n");
520 /* allocate instruction array and block index table */
522 /* 1 additional for end ipc and 3 for loop unrolling */
524 block_index = DMNEW(int, cumjcodelength + 4);
526 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
527 /* additional MONITOREXITS are reached by branches which are 3 bytes */
529 iptr = instr = DMNEW(instruction, cumjcodelength + 5);
531 /* initialize block_index table (unrolled four times) */
536 for (i = 0, ip = block_index; i <= cumjcodelength; i += 4, ip += 4) {
544 /* compute branch targets of exception table */
546 extable = DMNEW(xtable, exceptiontablelength + 1);
548 for (i = 0; i < method->exceptiontablelength; i++) {
550 p = extable[i].startpc = raw_extable[i].startpc;
551 if (useinlining) p = label_index[p];
555 p = extable[i].endpc = raw_extable[i].endpc;
556 if (useinlining) p = label_index[p];
558 if (p < cumjcodelength)
561 p = extable[i].handlerpc = raw_extable[i].handlerpc;
565 extable[i].catchtype = raw_extable[i].catchtype;
567 extable[i].next = NULL;
568 extable[i].down = &extable[i+1];
572 nextex = fillextable(extable, raw_extable, method->exceptiontablelength, label_index, &b_count);
574 s_count = 1 + exceptiontablelength; /* initialize stack element counter */
577 if (checksync && (method->flags & ACC_SYNCHRONIZED)) {
582 /* scan all java instructions */
584 for (p = 0, gp = 0; p < jcodelength; gp += (nextp - p), p = nextp) {
586 /* DEBUG printf("p:%d gp:%d ",p,gp); */
589 if ((useinlining) && (gp == nextgp)) {
591 bool *readonly = NULL;
593 opcode = code_get_u1 (p);
594 nextp = p += jcommandsize[opcode];
595 tmpinlinf = list_first(inlinfo->inlinedmethods);
596 firstlocal = tmpinlinf->firstlocal;
597 label_index = tmpinlinf->label_index;
598 readonly = tmpinlinf->readonly;
599 for (i=0, tptr=tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1 ; i<tmpinlinf->method->paramcount; i++, tptr--) {
602 if ( (i==0) && inlineparamopt) {
603 OP1(ICMD_CLEAR_ARGREN, firstlocal);
606 if ( !inlineparamopt || !readonly[i] )
608 else op = ICMD_READONLY_ARG;
611 OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i);
613 /* block_index[gp] |= (ipc << 1);*/ /*FIXME: necessary ? */
616 inlining_save_compiler_variables();
617 inlining_set_compiler_variables(tmpinlinf);
619 if (inlinfo->inlinedmethods == NULL) {
622 tmpinlinf = list_first(inlinfo->inlinedmethods);
623 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
625 if (method->exceptiontablelength > 0)
626 nextex = fillextable(nextex, method->exceptiontable, method->exceptiontablelength, label_index, &b_count);
630 opcode = code_get_u1(p); /* fetch op code */
633 if (opt_rt && (pOpcodes == 2 || pOpcodes == 3)) {
634 printf("Parse<%i> p=%i<%i< opcode=<%i> %s\n",
635 pOpcodes, p, rt_jcodelength, opcode, icmd_names[opcode]);
638 block_index[gp] |= (ipc << 1); /* store intermediate count */
641 block_insert(gp); /* start new block */
645 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
646 s_count += stackreq[opcode]; /* compute stack element count */
652 /* pushing constants onto the stack p */
655 LOADCONST_I(code_get_s1(p+1));
659 LOADCONST_I(code_get_s2(p+1));
663 i = code_get_u1(p+1);
664 goto pushconstantitem;
667 i = code_get_u2(p + 1);
671 if (i >= class->cpcount)
672 panic ("Attempt to access constant outside range");
674 switch (class->cptags[i]) {
675 case CONSTANT_Integer:
676 LOADCONST_I(((constant_integer*)
677 (class->cpinfos[i]))->value);
680 LOADCONST_L(((constant_long*)
681 (class->cpinfos[i]))->value);
684 LOADCONST_F(((constant_float*)
685 (class->cpinfos[i]))->value);
687 case CONSTANT_Double:
688 LOADCONST_D(((constant_double*)
689 (class->cpinfos[i]))->value);
691 case CONSTANT_String:
692 LOADCONST_A(literalstring_new((utf*)
693 (class->cpinfos[i])));
695 default: panic("Invalid constant type to push");
699 case JAVA_ACONST_NULL:
710 LOADCONST_I(opcode - JAVA_ICONST_0);
715 LOADCONST_L(opcode - JAVA_LCONST_0);
721 LOADCONST_F(opcode - JAVA_FCONST_0);
726 LOADCONST_D(opcode - JAVA_DCONST_0);
729 /* loading variables onto the stack */
737 i = code_get_u1(p+1);
739 i = code_get_u2(p+1);
743 OP1(opcode, i + firstlocal);
750 OP1(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
757 OP1(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
764 OP1(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
771 OP1(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
778 OP1(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
781 /* storing stack values into local variables */
789 i = code_get_u1(p+1);
791 i = code_get_u2(p+1);
795 OP1(opcode, i + firstlocal);
802 OP1(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
809 OP1(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
816 OP1(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
823 OP1(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
830 OP1(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
838 i = code_get_u1(p + 1);
839 v = code_get_s1(p + 2);
842 i = code_get_u2(p + 1);
843 v = code_get_s2(p + 3);
847 OP2I(opcode, i + firstlocal, v);
851 /* wider index for loading, storing and incrementing */
858 /* managing arrays ************************************************/
861 OP2I(ICMD_CHECKASIZE, 0, 0);
862 switch (code_get_s1(p + 1)) {
864 BUILTIN1((functionptr)builtin_newarray_boolean, TYPE_ADR);
867 BUILTIN1((functionptr)builtin_newarray_char, TYPE_ADR);
870 BUILTIN1((functionptr)builtin_newarray_float, TYPE_ADR);
873 BUILTIN1((functionptr)builtin_newarray_double, TYPE_ADR);
876 BUILTIN1((functionptr)builtin_newarray_byte, TYPE_ADR);
879 BUILTIN1((functionptr)builtin_newarray_short, TYPE_ADR);
882 BUILTIN1((functionptr)builtin_newarray_int, TYPE_ADR);
885 BUILTIN1((functionptr)builtin_newarray_long, TYPE_ADR);
887 default: panic("Invalid array-type to create");
892 OP2I(ICMD_CHECKASIZE, 0, 0);
893 i = code_get_u2(p+1);
894 /* array or class type ? */
895 if (class_constanttype (class, i) == CONSTANT_Arraydescriptor) {
897 LOADCONST_A(class_getconstant(class, i,
898 CONSTANT_Arraydescriptor));
899 #if defined(__I386__)
900 BUILTIN2((functionptr) asm_builtin_newarray_array, TYPE_ADR);
902 BUILTIN2((functionptr) builtin_newarray_array, TYPE_ADR);
906 LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
908 #if defined(__I386__)
909 BUILTIN2((functionptr) asm_builtin_anewarray, TYPE_ADR);
911 BUILTIN2((functionptr) builtin_anewarray, TYPE_ADR);
916 case JAVA_MULTIANEWARRAY:
918 i = code_get_u2(p + 1);
920 int v = code_get_u1(p + 3);
921 constant_arraydescriptor *desc =
922 class_getconstant (class, i, CONSTANT_Arraydescriptor);
923 OP2A(opcode, v, desc);
945 i = p + code_get_s2(p+1);
957 i = p + code_get_s4(p+1);
970 i = code_get_u1(p+1);
972 i = code_get_u2(p+1);
979 if (isinlinedmethod) {
980 OP1(ICMD_GOTO, inlinfo->stopgp);
984 OP1(opcode, i + firstlocal);
995 if (isinlinedmethod) {
996 /* if (p==jcodelength-1) {*/ /* return is at end of inlined method */
1001 OP1(ICMD_GOTO, inlinfo->stopgp);
1015 /* table jumps ********************************/
1017 case JAVA_LOOKUPSWITCH:
1023 nextp = ALIGN((p + 1), 4);
1025 tablep = (s4*)(jcode + nextp);
1028 num = code_get_u4(nextp + 4);
1029 tablep = DMNEW(s4, num * 2 + 2);
1032 OP2A(opcode, 0, tablep);
1034 /* default target */
1036 j = p + code_get_s4(nextp);
1037 if (useinlining) j = label_index[j];
1038 *tablep = j; /* restore for little endian */
1044 /* number of pairs */
1046 num = code_get_u4(nextp);
1051 for (i = 0; i < num; i++) {
1055 j = code_get_s4(nextp);
1056 *tablep = j; /* restore for little endian */
1062 j = p + code_get_s4(nextp);
1063 if (useinlining) j = label_index[j];
1064 *tablep = j; /* restore for little endian */
1075 case JAVA_TABLESWITCH:
1081 nextp = ALIGN((p + 1), 4);
1083 tablep = (s4*)(jcode + nextp);
1086 num = code_get_u4(nextp + 8) - code_get_u4(nextp + 4);
1087 tablep = DMNEW(s4, num + 1 + 3);
1090 OP2A(opcode, 0, tablep);
1092 /* default target */
1094 j = p + code_get_s4(nextp);
1095 if (useinlining) j = label_index[j];
1096 *tablep = j; /* restore for little endian */
1104 j = code_get_s4(nextp);
1105 *tablep = j; /* restore for little endian */
1111 num = code_get_s4(nextp);
1112 *tablep = num; /* restore for little endian */
1118 for (i = 0; i <= num; i++) {
1119 j = p + code_get_s4(nextp);
1120 if (useinlining) j = label_index[j];
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);
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 /* array type cast-check */
1241 if (class_constanttype (class, i) == CONSTANT_Arraydescriptor) {
1242 LOADCONST_A(class_getconstant(class, i, CONSTANT_Arraydescriptor));
1244 BUILTIN2((functionptr) asm_builtin_checkarraycast, TYPE_ADR);
1246 else { /* object type cast-check */
1248 LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1250 BUILTIN2((functionptr) asm_builtin_checkcast, TYPE_ADR);
1252 OP2A(opcode, 1, (class_getconstant(class, i, CONSTANT_Class)));
1256 case JAVA_INSTANCEOF:
1257 i = code_get_u2(p+1);
1259 /* array type cast-check */
1260 if (class_constanttype (class, i) == CONSTANT_Arraydescriptor) {
1261 LOADCONST_A(class_getconstant(class, i, CONSTANT_Arraydescriptor));
1263 #if defined(__I386__)
1264 BUILTIN2((functionptr) asm_builtin_arrayinstanceof, TYPE_INT);
1266 BUILTIN2((functionptr) builtin_arrayinstanceof, TYPE_INT);
1269 else { /* object type cast-check */
1271 LOADCONST_A(class_getconstant(class, i, CONSTANT_Class));
1273 BUILTIN2((functionptr) builtin_instanceof, TYPE_INT);
1275 OP2A(opcode, 1, (class_getconstant(class, i, CONSTANT_Class)));
1279 case JAVA_MONITORENTER:
1282 BUILTIN1((functionptr) asm_builtin_monitorenter, TYPE_VOID);
1286 OP(ICMD_NULLCHECKPOP);
1290 case JAVA_MONITOREXIT:
1293 BUILTIN1((functionptr) asm_builtin_monitorexit, TYPE_VOID);
1302 /* any other basic operation **************************************/
1321 #if defined(__I386__)
1324 BUILTIN2((functionptr) builtin_frem, TYPE_FLOAT);
1329 #if defined(__I386__)
1332 BUILTIN2((functionptr) builtin_drem, TYPE_DOUBLE);
1337 #if defined(__ALPHA__)
1339 BUILTIN1((functionptr) builtin_f2i, TYPE_INT);
1348 #if defined(__ALPHA__)
1350 BUILTIN1((functionptr) builtin_f2l, TYPE_LONG);
1359 #if defined(__ALPHA__)
1361 BUILTIN1((functionptr) builtin_d2i, TYPE_INT);
1370 #if defined(__ALPHA__)
1372 BUILTIN1((functionptr) builtin_d2l, TYPE_LONG);
1380 case JAVA_BREAKPOINT:
1381 panic("Illegal opcode Breakpoint encountered");
1437 printf("Illegal opcode %d at instr %d", opcode, ipc);
1438 panic("encountered");
1449 if (isinlinedmethod && p == jcodelength - 1) { /* end of an inlined method */
1450 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1451 gp = inlinfo->stopgp;
1452 inlining_restore_compiler_variables();
1453 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1454 if (inlinfo->inlinedmethods == NULL) nextgp = -1;
1456 tmpinlinf = list_first(inlinfo->inlinedmethods);
1457 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1459 /* printf("nextpgp: %d\n", nextgp); */
1460 label_index=inlinfo->label_index;
1461 firstlocal = inlinfo->firstlocal;
1465 if (p != jcodelength)
1466 panic("Command-sequence crosses code-boundary");
1469 panic("Code does not end with branch/return/athrow - stmt");
1471 /* adjust block count if target 0 is not first intermediate instruction */
1473 if (!block_index[0] || (block_index[0] > 1))
1476 /* copy local to global variables */
1479 block_count = b_count;
1480 stack_count = s_count + block_count * maxstack;
1482 /* allocate stack table */
1484 stack = DMNEW(stackelement, stack_count);
1489 bptr = block = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1494 /* additional block if target 0 is not first intermediate instruction */
1496 if (!block_index[0] || (block_index[0] > 1)) {
1497 bptr->iinstr = instr;
1500 bptr->type = BBTYPE_STD;
1501 bptr->branchrefs = NULL;
1502 bptr->pre_count = 0;
1503 bptr->debug_nr = c_debug_nr++;
1506 (bptr - 1)->next = bptr;
1509 /* allocate blocks */
1511 for (p = 0; p < cumjcodelength; p++) {
1512 if (block_index[p] & 1) {
1513 bptr->iinstr = instr + (block_index[p] >> 1);
1514 bptr->debug_nr = c_debug_nr++;
1516 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1520 bptr->type = BBTYPE_STD;
1521 bptr->branchrefs = NULL;
1522 block_index[p] = b_count;
1523 bptr->pre_count = 0;
1526 (bptr - 1)->next = bptr;
1530 /* allocate additional block at end */
1532 bptr->instack = bptr->outstack = NULL;
1533 bptr->indepth = bptr->outdepth = 0;
1534 bptr->iinstr = NULL;
1535 (bptr - 1)->icount = (instr + instr_count) - (bptr - 1)->iinstr;
1540 bptr->type = BBTYPE_STD;
1541 bptr->branchrefs = NULL;
1542 bptr->pre_count = 0;
1543 bptr->debug_nr = c_debug_nr++;
1544 (bptr - 1)->next = bptr;
1549 if (exceptiontablelength > 0)
1550 extable[exceptiontablelength - 1].down = NULL;
1554 for (i = 0; i < exceptiontablelength; ++i) {
1555 p = extable[i].startpc;
1556 extable[i].start = block + block_index[p];
1558 p = extable[i].endpc;
1559 extable[i].end = block + block_index[p];
1561 p = extable[i].handlerpc;
1562 extable[i].handler = block + block_index[p];
1566 if (useinlining) inlining_cleanup();
1567 useinlining = useinltmp;
1572 * These are local overrides for various environment variables in Emacs.
1573 * Please do not remove this and leave it at the end of the file, where
1574 * Emacs will automagically detect them.
1575 * ---------------------------------------------------------------------
1578 * indent-tabs-mode: t