1 /* vm/jit/parse.c - parser for JavaVM to intermediate code translation
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5 M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6 P. Tomsich, J. Wenninger
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
29 Changes: Carolyn Oates
32 $Id: parse.c 1630 2004-11-30 19:33:41Z carolyn $
41 #include "mm/memory.h"
42 #include "native/native.h"
43 #include "toolbox/logging.h"
44 #include "vm/builtin.h"
45 #include "vm/exceptions.h"
46 #include "vm/global.h"
47 #include "vm/loader.h"
48 #include "vm/options.h"
49 #include "vm/statistics.h"
50 #include "vm/tables.h"
51 #include "vm/jit/jit.h"
52 #include "vm/jit/parse.h"
53 #include "vm/jit/inline/parseRT.h"
54 #include "vm/jit/inline/inline.h"
55 #include "vm/jit/loop/loop.h"
58 #define METHINFO(mm) \
60 printf("PARSE method name ="); \
61 utf_display(mm->class->name); \
66 #define DEBUGMETH(mm) \
69 printf("PARSE method name ="); \
70 utf_display(mm->class->name); \
77 if (DEBUG4 == true) {printf("Parse p=%i<%i< opcode=<%i> %s\n", \
78 p, m->jcodelength,opcode,opcode_names[opcode]);}
82 bool DEBUG4 = false; /*opcodes*/
85 #define debug_writebranch if (DEBUG2==true) printf("op:: %s i: %d label_index[i]: %d label_index=0x%x\n",opcode_names[opcode], i, label_index[i], label_index);
86 #define debug_writebranch1
89 /* function descriptor2typesL ***************************************************
91 decodes a already checked method descriptor. The parameter count, the
92 return type and the argument types are stored in the passed methodinfo.
93 gets and saves classptr for object ref.s
95 *******************************************************************************/
97 classSetNode *descriptor2typesL(methodinfo *m)
104 classinfo** classtypes;
107 classSetNode *p=NULL;
108 if (debugInfo >= 1) {
109 printf("In descriptor2typesL >>>\t"); fflush(stdout);
110 utf_display(m->class->name); printf(".");
111 method_display(m);fflush(stdout);
115 desc = MNEW (char, 256);
116 types = DMNEW (u1, m->descriptor->blength);
117 classtypes = MNEW (classinfo*, m->descriptor->blength+1);
118 m->returnclass = NULL;
120 if (!(m->flags & ACC_STATIC)) {
122 if (debugInfo >= 1) {
123 printf("param #0 (this?) method class =");utf_display(m->class->name);printf("\n");
125 classtypes[pcount] = m->class;
126 p = addClassCone(p, m->class);
130 utf_ptr = m->descriptor->text + 1;
131 strcpy (desc,utf_ptr);
133 while ((c = *desc++) != ')') {
140 case 'Z': *tptr++ = TYPE_INT;
142 case 'J': *tptr++ = TYPE_LNG;
144 case 'F': *tptr++ = TYPE_FLT;
146 case 'D': *tptr++ = TYPE_DBL;
148 case 'L': *tptr++ = TYPE_ADR;
149 /* get class string */
150 class = strtok(desc,";");
151 desc = strtok(NULL,"\0");
152 /* get/save classinfo ptr */
153 classtypes[pcount-1] = class_get(utf_new_char(class));
154 p = addClassCone(p, class_get(utf_new_char(class)));
155 if (debugInfo >= 1) {
156 printf("LParam#%i 's class type is: %s\n",pcount-1,class);fflush(stdout);
157 printf("Lclasstypes[%i]=",pcount-1);fflush(stdout);
158 utf_display(classtypes[pcount-1]->name);
161 case '[': *tptr++ = TYPE_ADR;
164 /* get class string */
166 class = strtok(desc,";");
167 desc = strtok(NULL,"\0");
168 /* get/save classinfo ptr */
169 classtypes[pcount-1] = class_get(utf_new_char(class));
170 p= addClassCone(p, class_get(utf_new_char(class)));
171 if (debugInfo >= 1) {
172 printf("[Param#%i 's class type is: %s\n",pcount-1,class);
173 printf("[classtypes[%i]=",pcount-1);fflush(stdout);
174 utf_display(classtypes[pcount-1]->name);
179 classtypes[pcount-1] = NULL;
182 panic("Ill formed methodtype-descriptor");
186 /* compute return type */
192 case 'Z': m->returntype = TYPE_INT;
194 case 'J': m->returntype = TYPE_LNG;
196 case 'F': m->returntype = TYPE_FLT;
198 case 'D': m->returntype = TYPE_DBL;
201 m->returntype = TYPE_ADR;
209 m->returntype = TYPE_ADR;
211 /* get class string */
212 class = strtok(desc,";");
213 m->returnclass = class_get(utf_new_char(class));
214 if (m->returnclass == NULL) {
215 printf("class=%s :\t",class);
216 panic ("return class not found");
219 case 'V': m->returntype = TYPE_VOID;
222 default: panic("Ill formed methodtype-descriptor-ReturnType");
225 m->paramcount = pcount;
226 m->paramtypes = types;
227 m->paramclass = classtypes;
231 for (i=0; i< m->paramcount; i++) {
232 if ((m->paramtypes[i] == TYPE_ADR) && (m->paramclass[i] != NULL)) {
233 printf("Param #%i is:\t",i);
234 utf_display(m->paramclass[i]->name);
239 if ((m->returntype == TYPE_ADR) && (m->returnclass != NULL)) {
240 printf("\tReturn Type is:\t"); fflush(stdout);
241 utf_display(m->returnclass->name);
245 printf("params2types: START results in a set \n");
246 printf("param2types: A Set size=%i=\n",sizeOfSet(p));
255 /* function descriptor2types ***************************************************
257 decodes a already checked method descriptor. The parameter count, the
258 return type and the argument types are stored in the passed methodinfo.
260 *******************************************************************************/
262 void descriptor2types(methodinfo *m)
268 types = DMNEW(u1, m->descriptor->blength);
271 if (!(m->flags & ACC_STATIC)) {
276 utf_ptr = m->descriptor->text + 1;
278 while ((c = *utf_ptr++) != ')') {
299 while (*utf_ptr++ != ';');
306 while (*utf_ptr++ != ';') /* skip */;
309 panic("Ill formed methodtype-descriptor");
313 /* compute return type */
315 switch (*utf_ptr++) {
321 m->returntype = TYPE_INT;
324 m->returntype = TYPE_LNG;
327 m->returntype = TYPE_FLT;
330 m->returntype = TYPE_DBL;
334 m->returntype = TYPE_ADR;
337 m->returntype = TYPE_VOID;
340 panic("Ill formed methodtype-descriptor");
343 m->paramcount = pcount;
344 m->paramtypes = types;
349 /*******************************************************************************
351 function 'parse' scans the JavaVM code and generates intermediate code
353 During parsing the block index table is used to store at bit pos 0
354 a flag which marks basic block starts and at position 1 to 31 the
355 intermediate instruction index. After parsing the block index table
356 is scanned, for marked positions a block is generated and the block
357 number is stored in the block index table.
359 *******************************************************************************/
361 static exceptiontable* fillextable(methodinfo *m,
362 exceptiontable* extable, exceptiontable *raw_extable,
363 int exceptiontablelength,
364 int *label_index, int *block_count,
365 t_inlining_globals *inline_env)
367 int b_count, i, p, src, insertBlock;
369 if (exceptiontablelength == 0)
373 /*if (m->exceptiontablelength > 0) {
375 printf("m->exceptiontablelength=%i\n",m->exceptiontablelength);
376 panic("exceptiontablelength > 0");
379 b_count = *block_count;
381 for (src = exceptiontablelength-1; src >=0; src--) {
382 /* printf("Excepiont table index: %d\n",i); */
383 p = raw_extable[src].startpc;
384 if (label_index != NULL) p = label_index[p];
385 extable->startpc = p;
389 /*** if (DEBUG==true){printf("---------------------block_inserted:b_count=%i m->basicblockindex[(p=%i)]=%i=%p\n",b_count,p,m->basicblockindex[(p)],m->basicblockindex[(p)]);
390 fflush(stdout); } ***/
391 p = raw_extable[src].endpc; /* see JVM Spec 4.7.3 */
392 if (p <= raw_extable[src].startpc)
393 panic("Invalid exception handler range");
395 if (p >inline_env->method->jcodelength) {
396 panic("Invalid exception handler end is after code end");
398 if (p<inline_env->method->jcodelength) insertBlock=1; else insertBlock=0;
399 /*if (label_index !=NULL) printf("%s:translating endpc:%ld to %ld, label_index:%p\n",m->name->text,p,label_index[p],label_index); else
400 printf("%s:fillextab: endpc:%ld\n",m->name->text,p);*/
401 if (label_index != NULL) p = label_index[p];
404 /*if (p < inline_env->method->jcodelength) {
406 if (insertBlock) block_insert(p);
408 p = raw_extable[src].handlerpc;
409 if (label_index != NULL) p = label_index[p];
410 extable->handlerpc = p;
414 extable->catchtype = raw_extable[src].catchtype;
415 extable->next = NULL;
416 extable->down = &extable[1];
420 *block_count = b_count;
421 return extable; /*&extable[i];*/ /* return the next free xtable* */
426 methodinfo *parse(methodinfo *m, codegendata *cd, t_inlining_globals *inline_env)
428 int p; /* java instruction counter */
429 int nextp; /* start of next java instruction */
430 int opcode; /* java opcode */
431 int i; /* temporary for different uses (ctrs)*/
432 int ipc = 0; /* intermediate instruction counter */
433 int b_count = 0; /* basic block counter */
434 int s_count = 0; /* stack element counter */
435 bool blockend = false; /* true if basic block end has been reached */
436 bool iswide = false; /* true if last instruction was a wide*/
437 instruction *iptr; /* current ptr into instruction array */
438 int gp; /* global java instruction counter */
439 /* inlining info for current method */
441 inlining_methodinfo *inlinfo = inline_env->inlining_rootinfo;
442 inlining_methodinfo *tmpinlinf;
443 int nextgp = -1; /* start of next method to be inlined */
444 int *label_index = NULL; /* label redirection table */
445 int firstlocal = 0; /* first local variable of method */
446 exceptiontable* nextex; /* points next free entry in extable */
447 u1 *instructionstart; /* 1 for pcs which are valid instr. starts */
453 u2 skipBasicBlockChange;
455 if (DEBUG4==true) {printf("\nPARSING: "); fflush(stdout);
459 if (m->methodUsed != USED) {
461 printf(" rta missed: "); fflush(stdout);
464 if ( (rtMissed = fopen("rtMissed", "a")) == NULL) {
465 printf("CACAO - rtMissed file: cant open file to write append \n");
468 utf_fprint(rtMissed,m->class->name);
469 fprintf(rtMissed," "); fflush(rtMissed);
470 utf_fprint(rtMissed,m->name);
471 fprintf(rtMissed," "); fflush(rtMissed);
472 utf_fprint(rtMissed,m->descriptor);
473 fprintf(rtMissed,"\n"); fflush(rtMissed);
481 label_index = inlinfo->label_index;
482 m->maxstack = inline_env->cummaxstack;
483 /*JOWENN m->exceptiontablelength = inline_env->cumextablelength;*/
484 tmpinlinf = (inlining_methodinfo*)
485 list_first(inlinfo->inlinedmethods);
486 if (tmpinlinf != NULL) nextgp = tmpinlinf->startgp;
489 /**** static analysis has to be called before inlining
490 which has to be called before reg_set
491 which has to be called before parse (or ???)
492 will check if method being parsed was analysed here
494 if (opt_xta && opt_verbose) {
495 /**RT_jit_parse(m);**/
496 printf("XTA requested, not available\n");
498 if (opt_vta && opt_verbose)
499 printf("VTA requested, not yet implemented\n");
501 /* allocate instruction array and block index table */
503 /* 1 additional for end ipc * # cum inline methods*/
505 m->basicblockindex = DMNEW(s4, inline_env->cumjcodelength + inline_env->cummethods);
506 memset(m->basicblockindex, 0, sizeof(s4) * (inline_env->cumjcodelength + inline_env->cummethods));
508 instructionstart = DMNEW(u1, inline_env->cumjcodelength + inline_env->cummethods);
509 memset(instructionstart, 0, sizeof(u1) * (inline_env->cumjcodelength + inline_env->cummethods));
511 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
512 /* additional MONITOREXITS are reached by branches which are 3 bytes */
514 iptr = m->instructions = DMNEW(instruction, inline_env->cumjcodelength + 5);
516 /* Zero the intermediate instructions array so we don't have any
517 * invalid pointers in it if we cannot finish analyse_stack(). */
519 memset(iptr, 0, sizeof(instruction) * (inline_env->cumjcodelength + 5));
521 /* compute branch targets of exception table */
523 if (m->exceptiontable == NULL) {
524 printf("m->exceptiontable=NULL\n");fflush(stdout);
527 printf("m->exceptiontable != NULL\n");fflush(stdout);
529 printf("m->exceptiontablelength=%i, inline_env->method->exceptiontablelength=%i,inline_env->cumextablelength=%i\n",
530 m->exceptiontablelength, inline_env->method->exceptiontablelength,inline_env->cumextablelength);
533 if (m->exceptiontablelength > 0)
534 m->exceptiontable = DMNEW(exceptiontable, m->exceptiontablelength + 1);
537 nextex = fillextable(m,
538 &(cd->exceptiontable[cd->exceptiontablelength-1]), m->exceptiontable, m->exceptiontablelength,
539 label_index, &b_count, inline_env);
540 s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */
542 #if defined(USE_THREADS)
543 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
544 m->isleafmethod = false;
545 inline_env->method->isleafmethod = false;
549 /* scan all java instructions */
553 if (m->linenumbercount == 0) {
557 linepcchange = m->linenumbers[0].start_pc;
560 skipBasicBlockChange=0;
561 for (p = 0, gp = 0; p < inline_env->method->jcodelength; gp += (nextp - p), p = nextp) {
563 /* DEBUG */ if (DEBUG==true) printf("----- p:%d gp:%d\n",p,gp);
565 /* mark this position as a valid instruction start */
567 instructionstart[gp] = 1;
568 /*log_text("new start of instruction");*/
569 if (linepcchange==p) {
570 if (inline_env->method->linenumbercount > lineindex) {
571 currentline = inline_env->method->linenumbers[lineindex].line_number;
573 if (lineindex < inline_env->method->linenumbercount)
574 linepcchange = inline_env->method->linenumbers[lineindex].start_pc;
575 /*printf("Line number changed to: %ld\n",currentline);*/
581 if ((useinlining) && (gp == nextgp)) {
583 bool *readonly = NULL;
586 block_insert(gp); /* JJJJJJJJJJ */
588 instructionstart[gp] = 1;
589 m->basicblockindex[gp] |= (ipc << 1); /*FIXME: necessary ? */
591 opcode = code_get_u1(p,inline_env->method);
592 nextp = p += jcommandsize[opcode];
593 if (nextp > inline_env->method->jcodelength)
594 panic("Unexpected end of bytecode");
595 tmpinlinf = list_first(inlinfo->inlinedmethods);
596 firstlocal = tmpinlinf->firstlocal;
597 label_index = tmpinlinf->label_index;
598 readonly = tmpinlinf->readonly;
600 for (i=0,tptr=tmpinlinf->method->paramtypes;i<tmpinlinf->method->paramcount;i++,tptr++) {
601 if ( ((*tptr)==TYPE_LNG) ||
602 ((*tptr)==TYPE_DBL) )
608 for (i = 0, tptr = tmpinlinf->method->paramtypes + tmpinlinf->method->paramcount - 1; i < tmpinlinf->method->paramcount; i++, tptr--) {
611 if ((i == 0) && inlineparamopt) {
612 OP1(ICMD_CLEAR_ARGREN, firstlocal);
615 if (!inlineparamopt || !readonly[i]) {
619 op = ICMD_READONLY_ARG;
623 if ( ((*tptr)==TYPE_LNG) ||
624 ((*tptr)==TYPE_DBL) )
629 OP1(op, firstlocal + argBlockIdx);
630 /* OP1(op, firstlocal + tmpinlinf->method->paramcount - 1 - i); */
631 /* printf("inline argument load operation for local: %ld\n",firstlocal + tmpinlinf->method->paramcount - 1 - i); */
633 skipBasicBlockChange=1;
635 printf("BEFORE SAVE: "); fflush(stdout);
636 DEBUGMETH(inline_env->method);
638 inlining_save_compiler_variables();
640 printf("AFTER SAVE: "); fflush(stdout);
641 DEBUGMETH(inline_env->method);
643 inlining_set_compiler_variables(tmpinlinf);
645 printf("AFTER SET :: "); fflush(stdout);
646 DEBUGMETH(inline_env->method);
649 printf("\n.......Parsing (inlined): ");
651 DEBUGMETH(inline_env->method);
655 OP1(ICMD_INLINE_START,tmpinlinf->level);
657 if (inlinfo->inlinedmethods == NULL) {
660 tmpinlinf = list_first(inlinfo->inlinedmethods);
661 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
663 if (inline_env->method->exceptiontablelength > 0)
664 nextex = fillextable(m, nextex,
665 inline_env->method->exceptiontable, inline_env->method->exceptiontablelength,
666 label_index, &b_count, inline_env);
670 opcode = code_get_u1(p,inline_env->method); /* fetch op code */
673 printf("Parse p=%i<%i<%i< opcode=<%i> %s\n",
674 p, gp, inline_env->jcodelength, opcode, opcode_names[opcode]);
676 printf("label_index[%d]=%d\n",p,label_index[p]);
679 printf("basicblockindex[gp=%i]=%i=%p ipc=%i=%p shifted ipc=%i=%p\n",
680 gp,m->basicblockindex[gp],m->basicblockindex[gp],ipc,ipc,(ipc<<1),(ipc<<1));
683 if (!skipBasicBlockChange) {
684 m->basicblockindex[gp] |= (ipc << 1); /*store intermed cnt*/
685 } else skipBasicBlockChange=0;
687 printf("basicblockindex[gp=%i]=%i=%p \n",
688 gp,m->basicblockindex[gp],m->basicblockindex[gp]);
693 block_insert(gp); /* start new block */
695 /*printf("blockend was set: new blockcount: %ld at:%ld\n",b_count,gp);*/
698 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
699 if (nextp > inline_env->method->jcodelength)
700 panic("Unexpected end of bytecode");
701 s_count += stackreq[opcode]; /* compute stack element count */
707 /* pushing constants onto the stack p */
710 LOADCONST_I(code_get_s1(p+1,inline_env->method));
714 LOADCONST_I(code_get_s2(p+1,inline_env->method));
718 i = code_get_u1(p+1,inline_env->method);
720 goto pushconstantitem;
723 i = code_get_u2(p + 1,inline_env->method);
727 if (i >= inline_env->method->class->cpcount)
728 panic ("Attempt to access constant outside range");
730 switch (inline_env->method->class->cptags[i]) {
731 case CONSTANT_Integer:
732 LOADCONST_I(((constant_integer *) (inline_env->method->class->cpinfos[i]))->value);
735 LOADCONST_L(((constant_long *) (inline_env->method->class->cpinfos[i]))->value);
738 LOADCONST_F(((constant_float *) (inline_env->method->class->cpinfos[i]))->value);
740 case CONSTANT_Double:
741 LOADCONST_D(((constant_double *) (inline_env->method->class->cpinfos[i]))->value);
743 case CONSTANT_String:
744 LOADCONST_A(literalstring_new((utf *) (inline_env->method->class->cpinfos[i])));
746 default: panic("Invalid constant type to push");
750 case JAVA_ACONST_NULL:
761 LOADCONST_I(opcode - JAVA_ICONST_0);
766 LOADCONST_L(opcode - JAVA_LCONST_0);
772 LOADCONST_F(opcode - JAVA_FCONST_0);
777 LOADCONST_D(opcode - JAVA_DCONST_0);
780 /* loading variables onto the stack */
788 i = code_get_u1(p + 1,inline_env->method);
790 i = code_get_u2(p + 1,inline_env->method);
794 OP1LOAD(opcode, i + firstlocal);
801 OP1LOAD(ICMD_ILOAD, opcode - JAVA_ILOAD_0 + firstlocal);
808 OP1LOAD(ICMD_LLOAD, opcode - JAVA_LLOAD_0 + firstlocal);
815 OP1LOAD(ICMD_FLOAD, opcode - JAVA_FLOAD_0 + firstlocal);
822 OP1LOAD(ICMD_DLOAD, opcode - JAVA_DLOAD_0 + firstlocal);
829 OP1LOAD(ICMD_ALOAD, opcode - JAVA_ALOAD_0 + firstlocal);
832 /* storing stack values into local variables */
840 i = code_get_u1(p + 1,inline_env->method);
842 i = code_get_u2(p + 1,inline_env->method);
846 OP1STORE(opcode, i + firstlocal);
853 OP1STORE(ICMD_ISTORE, opcode - JAVA_ISTORE_0 + firstlocal);
860 OP1STORE(ICMD_LSTORE, opcode - JAVA_LSTORE_0 + firstlocal);
867 OP1STORE(ICMD_FSTORE, opcode - JAVA_FSTORE_0 + firstlocal);
874 OP1STORE(ICMD_DSTORE, opcode - JAVA_DSTORE_0 + firstlocal);
881 OP1STORE(ICMD_ASTORE, opcode - JAVA_ASTORE_0 + firstlocal);
889 i = code_get_u1(p + 1,inline_env->method);
890 v = code_get_s1(p + 2,inline_env->method);
893 i = code_get_u2(p + 1,inline_env->method);
894 v = code_get_s2(p + 3,inline_env->method);
898 INDEX_ONEWORD(i + firstlocal);
899 OP2I(opcode, i + firstlocal, v);
903 /* wider index for loading, storing and incrementing */
910 /* managing arrays ************************************************/
914 switch (code_get_s1(p + 1,inline_env->method)) {
916 BUILTIN1(BUILTIN_newarray_boolean, TYPE_ADR,currentline);
919 BUILTIN1(BUILTIN_newarray_char, TYPE_ADR,currentline);
922 BUILTIN1(BUILTIN_newarray_float, TYPE_ADR,currentline);
925 BUILTIN1(BUILTIN_newarray_double, TYPE_ADR,currentline);
928 BUILTIN1(BUILTIN_newarray_byte, TYPE_ADR,currentline);
931 BUILTIN1(BUILTIN_newarray_short, TYPE_ADR,currentline);
934 BUILTIN1(BUILTIN_newarray_int, TYPE_ADR,currentline);
937 BUILTIN1(BUILTIN_newarray_long, TYPE_ADR,currentline);
939 default: panic("Invalid array-type to create");
941 OP(ICMD_CHECKEXCEPTION);
946 i = code_get_u2(p + 1,inline_env->method);
948 classinfo *component =
949 (classinfo *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
951 if (!class_load(component))
954 if (!class_link(component))
957 LOADCONST_A_BUILTIN(class_array_of(component)->vftbl);
958 /* LOADCONST_A_BUILTIN(component); */
960 BUILTIN2(BUILTIN_newarray, TYPE_ADR, currentline);
962 OP(ICMD_CHECKEXCEPTION);
965 case JAVA_MULTIANEWARRAY:
966 inline_env->method->isleafmethod = false;
967 i = code_get_u2(p + 1,inline_env->method);
970 s4 v = code_get_u1(p + 3,inline_env->method);
973 /* vftbl *arrayvftbl = */
974 /* ((classinfo *) class_getconstant(class, i, CONSTANT_Class))->vftbl; */
975 /* OP2A(opcode, v, arrayvftbl,currentline); */
978 classinfo *component =
979 (classinfo *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
981 if (!class_load(component))
984 if (!class_link(component))
987 arrayvftbl = component->vftbl;
988 OP2A(opcode, v, arrayvftbl, currentline);
990 /* classinfo *arrayclass = */
991 /* (classinfo *) class_getconstant(class, i, CONSTANT_Class); */
992 /* OP2A(opcode, v, arrayclass, currentline); */
1003 case JAVA_IFNONNULL:
1004 case JAVA_IF_ICMPEQ:
1005 case JAVA_IF_ICMPNE:
1006 case JAVA_IF_ICMPLT:
1007 case JAVA_IF_ICMPGT:
1008 case JAVA_IF_ICMPLE:
1009 case JAVA_IF_ICMPGE:
1010 case JAVA_IF_ACMPEQ:
1011 case JAVA_IF_ACMPNE:
1014 i = p + code_get_s2(p + 1,inline_env->method);
1026 i = p + code_get_s4(p + 1,inline_env->method);
1032 /*printf("B6 JSR_W\t"); fflush(stdout);*/
1040 i = code_get_u1(p + 1,inline_env->method);
1042 i = code_get_u2(p + 1,inline_env->method);
1049 if (inline_env->isinlinedmethod) {
1050 OP1(ICMD_GOTO, inlinfo->stopgp);
1054 OP1LOAD(opcode, i + firstlocal);
1063 if (inline_env->isinlinedmethod) {
1064 /* if (p==m->jcodelength-1) {*/ /* return is at end of inlined method */
1068 if (nextp>inline_env->method->jcodelength-1) {
1069 /* OP1(ICMD_GOTO, inlinfo->stopgp);
1077 OP1(ICMD_GOTO, inlinfo->stopgp);
1091 /* table jumps ********************************/
1093 case JAVA_LOOKUPSWITCH:
1100 nextp = ALIGN((p + 1), 4);
1101 if (nextp + 8 > inline_env->method->jcodelength)
1102 panic("Unexpected end of bytecode");
1104 tablep = (s4 *) (inline_env->method->jcode + nextp);
1107 num = code_get_u4(nextp + 4,inline_env->method);
1108 tablep = DMNEW(s4, num * 2 + 2);
1111 OP2A(opcode, 0, tablep,currentline);
1113 /* default target */
1115 j = p + code_get_s4(nextp,inline_env->method);
1118 *tablep = j; /* restore for little endian */
1124 /* number of pairs */
1126 num = code_get_u4(nextp,inline_env->method);
1131 if (nextp + 8*(num) > inline_env->method->jcodelength)
1132 panic("Unexpected end of bytecode");
1134 for (i = 0; i < num; i++) {
1137 j = code_get_s4(nextp,inline_env->method);
1138 *tablep = j; /* restore for little endian */
1142 /* check if the lookup table is sorted correctly */
1144 if (i && (j <= prevvalue))
1145 panic("invalid LOOKUPSWITCH: table not sorted");
1150 j = p + code_get_s4(nextp,inline_env->method);
1153 *tablep = j; /* restore for little endian */
1164 case JAVA_TABLESWITCH:
1170 nextp = ALIGN((p + 1), 4);
1171 if (nextp + 12 > inline_env->method->jcodelength)
1172 panic("Unexpected end of bytecode");
1174 tablep = (s4 *) (inline_env->method->jcode + nextp);
1177 num = code_get_u4(nextp + 8,inline_env->method) - code_get_u4(nextp + 4,inline_env->method);
1178 tablep = DMNEW(s4, num + 1 + 3);
1181 OP2A(opcode, 0, tablep,currentline);
1183 /* default target */
1185 j = p + code_get_s4(nextp,inline_env->method);
1188 *tablep = j; /* restore for little endian */
1196 j = code_get_s4(nextp,inline_env->method);
1197 *tablep = j; /* restore for little endian */
1203 num = code_get_s4(nextp,inline_env->method);
1204 *tablep = num; /* restore for little endian */
1208 num -= j; /* difference of upper - lower */
1210 panic("invalid TABLESWITCH: upper bound < lower bound");
1212 if (nextp + 4*(num+1) > inline_env->method->jcodelength)
1213 panic("Unexpected end of bytecode");
1215 for (i = 0; i <= num; i++) {
1216 j = p + code_get_s4(nextp,inline_env->method);
1218 /*printf("TABLESWITCH: j before mapping=%ld\n",j);*/
1221 *tablep = j; /* restore for little endian */
1226 /*printf("TABLESWITCH: block_insert(%ld)\n",j);*/
1233 /* load and store of object fields *******************/
1236 BUILTIN3(BUILTIN_aastore, TYPE_VOID, currentline);
1239 case JAVA_PUTSTATIC:
1240 case JAVA_GETSTATIC:
1241 i = code_get_u2(p + 1,inline_env->method);
1243 constant_FMIref *fr;
1246 fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref);
1248 if (!class_load(fr->class))
1251 if (!class_link(fr->class))
1254 fi = class_resolvefield(fr->class,
1257 inline_env->method->class,
1263 OP2A(opcode, fi->type, fi, currentline);
1264 if (!fi->class->initialized) {
1265 inline_env->method->isleafmethod = false;
1272 i = code_get_u2(p + 1,inline_env->method);
1274 constant_FMIref *fr;
1277 fr = class_getconstant(inline_env->method->class, i, CONSTANT_Fieldref);
1279 if (!class_load(fr->class))
1282 if (!class_link(fr->class))
1285 fi = class_resolvefield(fr->class,
1288 inline_env->method->class,
1294 OP2A(opcode, fi->type, fi, currentline);
1299 /* method invocation *****/
1301 case JAVA_INVOKESTATIC:
1302 i = code_get_u2(p + 1,inline_env->method);
1304 constant_FMIref *mr;
1307 inline_env->method->isleafmethod = false;
1309 mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref);
1311 if (!class_load(mr->class))
1314 if (!class_link(mr->class))
1317 mi = class_resolveclassmethod(mr->class,
1320 inline_env->method->class,
1327 method_display_w_class(mi);
1328 printf("\tINVOKE STATIC\n");
1331 if (!(mi->flags & ACC_STATIC)) {
1333 new_exception(string_java_lang_IncompatibleClassChangeError);
1337 descriptor2types(mi);
1338 OP2A(opcode, mi->paramcount, mi, currentline);
1342 case JAVA_INVOKESPECIAL:
1343 case JAVA_INVOKEVIRTUAL:
1344 i = code_get_u2(p + 1,inline_env->method);
1346 constant_FMIref *mr;
1349 inline_env->method->isleafmethod = false;
1351 mr = class_getconstant(inline_env->method->class, i, CONSTANT_Methodref);
1353 if (!class_load(mr->class))
1356 if (!class_link(mr->class))
1359 mi = class_resolveclassmethod(mr->class,
1362 inline_env->method->class,
1369 method_display_w_class(mi);
1370 printf("\tINVOKE SPEC/VIRT\n");
1373 if (mi->flags & ACC_STATIC) {
1375 new_exception(string_java_lang_IncompatibleClassChangeError);
1379 descriptor2types(mi);
1380 OP2A(opcode, mi->paramcount, mi, currentline);
1384 case JAVA_INVOKEINTERFACE:
1385 i = code_get_u2(p + 1,inline_env->method);
1387 constant_FMIref *mr;
1390 inline_env->method->isleafmethod = false;
1392 mr = class_getconstant(inline_env->method->class, i, CONSTANT_InterfaceMethodref);
1394 if (!class_load(mr->class))
1397 if (!class_link(mr->class))
1400 mi = class_resolveinterfacemethod(mr->class,
1403 inline_env->method->class,
1408 if (mi->flags & ACC_STATIC) {
1410 new_exception(string_java_lang_IncompatibleClassChangeError);
1415 method_display_w_class(mi);
1416 printf("\tINVOKE INTERFACE\n");
1418 descriptor2types(mi);
1419 OP2A(opcode, mi->paramcount, mi, currentline);
1423 /* miscellaneous object operations *******/
1426 i = code_get_u2(p + 1,inline_env->method);
1427 LOADCONST_A_BUILTIN(class_getconstant(inline_env->method->class, i, CONSTANT_Class));
1429 BUILTIN1(BUILTIN_new, TYPE_ADR, currentline);
1430 OP(ICMD_CHECKEXCEPTION);
1433 case JAVA_CHECKCAST:
1434 i = code_get_u2(p + 1,inline_env->method);
1437 (classinfo *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1440 if (!class_load(cls))
1444 if (!class_link(cls))
1447 if (cls->vftbl->arraydesc) {
1448 /* array type cast-check */
1449 LOADCONST_A_BUILTIN(cls->vftbl);
1451 BUILTIN2(BUILTIN_checkarraycast, TYPE_ADR,currentline);
1453 } else { /* object type cast-check */
1455 + LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
1457 + BUILTIN2(BUILTIN_checkcast, TYPE_ADR,currentline);
1459 OP2A(opcode, 1, cls, currentline);
1464 case JAVA_INSTANCEOF:
1465 i = code_get_u2(p + 1,inline_env->method);
1468 (classinfo *) class_getconstant(inline_env->method->class, i, CONSTANT_Class);
1471 if (!class_load(cls))
1475 if (!class_link(cls))
1478 if (cls->vftbl->arraydesc) {
1479 /* array type cast-check */
1480 LOADCONST_A_BUILTIN(cls->vftbl);
1482 BUILTIN2(BUILTIN_arrayinstanceof, TYPE_INT, currentline);
1484 else { /* object type cast-check */
1486 LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
1488 BUILTIN2(BUILTIN_instanceof, TYPE_INT,currentline);
1490 OP2A(opcode, 1, cls, currentline);
1495 case JAVA_MONITORENTER:
1496 #if defined(USE_THREADS)
1498 BUILTIN1(BUILTIN_monitorenter, TYPE_VOID,currentline);
1502 OP(ICMD_NULLCHECKPOP);
1506 case JAVA_MONITOREXIT:
1507 #if defined(USE_THREADS)
1509 BUILTIN1(BUILTIN_monitorexit, TYPE_VOID,currentline);
1510 OP(ICMD_CHECKEXCEPTION);
1518 /* any other basic operation **************************************/
1537 #if defined(__I386__)
1540 BUILTIN2(BUILTIN_frem, TYPE_FLOAT,currentline);
1545 #if defined(__I386__)
1548 BUILTIN2(BUILTIN_drem, TYPE_DOUBLE,currentline);
1553 #if defined(__ALPHA__)
1555 BUILTIN1(BUILTIN_f2i, TYPE_INT,currentline);
1564 #if defined(__ALPHA__)
1566 BUILTIN1(BUILTIN_f2l, TYPE_LONG,currentline);
1575 #if defined(__ALPHA__)
1577 BUILTIN1(BUILTIN_d2i, TYPE_INT,currentline);
1586 #if defined(__ALPHA__)
1588 BUILTIN1(BUILTIN_d2l, TYPE_LONG,currentline);
1596 case JAVA_BREAKPOINT:
1598 new_verifyerror(m, "Quick instructions shouldn't appear yet.");
1601 case 204: /* unused opcode */
1653 printf("Illegal opcode %d at instr %d\n", opcode, ipc);
1654 panic("Illegal opcode encountered");
1663 /* If WIDE was used correctly, iswide should have been reset by now. */
1664 if (iswide && opcode != JAVA_WIDE)
1665 panic("Illegal instruction: WIDE before incompatible opcode");
1669 /* if (inline_env->isinlinedmethod && p == inline_env->method->jcodelength - 1) { */ /* end of an inlined method */
1670 if (inline_env->isinlinedmethod && (nextp >= inline_env->method->jcodelength) ) { /* end of an inlined method */
1671 /* printf("setting gp from %d to %d\n",gp, inlinfo->stopgp); */
1672 gp = inlinfo->stopgp;
1673 inlining_restore_compiler_variables();
1674 OP(ICMD_INLINE_END);
1675 /*label_index = inlinfo->label_index;*/
1678 printf("AFTER RESTORE : "); fflush(stdout);
1679 DEBUGMETH(inline_env->method);
1681 list_remove(inlinfo->inlinedmethods, list_first(inlinfo->inlinedmethods));
1682 if (inlinfo->inlinedmethods == NULL) { /* JJJJ */
1685 tmpinlinf = list_first(inlinfo->inlinedmethods);
1686 nextgp = (tmpinlinf != NULL) ? tmpinlinf->startgp : -1;
1688 /* printf("nextpgp: %d\n", nextgp); */
1689 label_index=inlinfo->label_index;
1690 firstlocal = inlinfo->firstlocal;
1696 if (p != m->jcodelength) {
1697 printf("p (%d) != m->jcodelength (%d)\n",p,m->jcodelength);
1698 panic("Command-sequence crosses code-boundary");
1701 *exceptionptr = new_verifyerror(m, "Falling off the end of the code");
1705 /* adjust block count if target 0 is not first intermediate instruction */
1707 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1))
1710 /* copy local to method variables */
1712 m->instructioncount = ipc;
1713 m->basicblockcount = b_count;
1714 m->stackcount = s_count + m->basicblockcount * m->maxstack;
1716 /* allocate stack table */
1718 m->stack = DMNEW(stackelement, m->stackcount);
1723 bptr = m->basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1728 /* additional block if target 0 is not first intermediate instruction */
1730 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) {
1731 bptr->iinstr = m->instructions;
1734 bptr->type = BBTYPE_STD;
1735 bptr->branchrefs = NULL;
1736 bptr->pre_count = 0;
1737 bptr->debug_nr = m->c_debug_nr++;
1740 (bptr - 1)->next = bptr;
1743 /* allocate blocks */
1745 for (p = 0; p < inline_env->cumjcodelength; p++) {
1746 /* for (p = 0; p < m->jcodelength; p++) { */
1747 if (m->basicblockindex[p] & 1) {
1748 /* check if this block starts at the beginning of an instruction */
1749 if (!instructionstart[p]) {
1750 printf("Basic Block beginn: %d\n",p);
1751 panic("Branch into middle of instruction");
1753 /* allocate the block */
1754 bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
1755 bptr->debug_nr = m->c_debug_nr++;
1757 (bptr - 1)->icount = bptr->iinstr - (bptr - 1)->iinstr;
1761 bptr->type = BBTYPE_STD;
1762 bptr->branchrefs = NULL;
1763 m->basicblockindex[p] = b_count;
1764 bptr->pre_count = 0;
1767 (bptr - 1)->next = bptr;
1771 /* allocate additional block at end */
1773 bptr->instack = bptr->outstack = NULL;
1774 bptr->indepth = bptr->outdepth = 0;
1775 bptr->iinstr = NULL;
1776 (bptr - 1)->icount = (m->instructions + m->instructioncount) - (bptr - 1)->iinstr;
1781 bptr->type = BBTYPE_STD;
1782 bptr->branchrefs = NULL;
1783 bptr->pre_count = 0;
1784 bptr->debug_nr = m->c_debug_nr++;
1785 (bptr - 1)->next = bptr;
1788 if (cd->exceptiontablelength > 0) {
1789 cd->exceptiontable[cd->exceptiontablelength - 1].down = NULL;
1792 for (i = 0; i < cd->exceptiontablelength; ++i) {
1793 p = cd->exceptiontable[i].startpc;
1794 cd->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1796 p = cd->exceptiontable[i].endpc;
1797 cd->exceptiontable[i].end = (p == inline_env->method->jcodelength) ? (m->basicblocks + m->basicblockcount /*+ 1*/) : (m->basicblocks + m->basicblockindex[p]);
1799 p = cd->exceptiontable[i].handlerpc;
1800 cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1804 if (useinlining) inlining_cleanup(inline_env);
1806 /* just return methodinfo* to signal everything was ok */
1813 * These are local overrides for various environment variables in Emacs.
1814 * Please do not remove this and leave it at the end of the file, where
1815 * Emacs will automagically detect them.
1816 * ---------------------------------------------------------------------
1819 * indent-tabs-mode: t