1 /* jit/stack.c - stack analysis
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
27 Authors: Andreas Krall
29 Changes: Edwin Steiner
31 $Id: stack.c 1095 2004-05-27 15:54:42Z twisti $
48 #include "toolbox/logging.h"
49 #include "toolbox/memory.h"
52 /* from codegen.inc */
55 /**********************************************************************/
56 /* Macros used internally by analyse_stack */
57 /**********************************************************************/
60 #define COUNT(cnt) cnt++
65 /* convenient abbreviations */
66 #define CURKIND curstack->varkind
67 #define CURTYPE curstack->type
69 /*--------------------------------------------------*/
70 /* SIGNALING ERRORS */
71 /*--------------------------------------------------*/
73 #define TYPEPANIC {show_icmd_method();panic("Stack type mismatch");}
76 /*--------------------------------------------------*/
77 /* STACK UNDERFLOW/OVERFLOW CHECKS */
78 /*--------------------------------------------------*/
80 /* underflow checks */
82 #define REQUIRE(num) \
84 if (stackdepth < (num)) { \
85 sprintf(msg, "(class: "); \
86 utf_sprint(msg + strlen(msg), m->class->name); \
87 sprintf(msg + strlen(msg), ", method: "); \
88 utf_sprint(msg + strlen(msg), m->name); \
89 sprintf(msg + strlen(msg), ", signature: "); \
90 utf_sprint(msg + strlen(msg), m->descriptor); \
91 sprintf(msg + strlen(msg), ") Unable to pop operand off an empty stack"); \
93 new_exception_message(string_java_lang_VerifyError, msg); \
98 #define REQUIRE_1 REQUIRE(1)
99 #define REQUIRE_2 REQUIRE(2)
100 #define REQUIRE_3 REQUIRE(3)
101 #define REQUIRE_4 REQUIRE(4)
105 /* We allow ACONST instructions inserted as arguments to builtin
106 * functions to exceed the maximum stack depth. Maybe we should check
107 * against maximum stack depth only at block boundaries?
110 #define CHECKOVERFLOW \
112 if (stackdepth > maxstack) { \
113 if (iptr[0].opc != ICMD_ACONST \
114 || iptr[0].op1 == 0) { \
115 sprintf(msg, "(class: "); \
116 utf_sprint_classname(msg + strlen(msg), m->class->name); \
117 sprintf(msg + strlen(msg), ", method: "); \
118 utf_sprint(msg + strlen(msg), m->name); \
119 sprintf(msg + strlen(msg), ", signature: "); \
120 utf_sprint(msg + strlen(msg), m->descriptor); \
121 sprintf(msg + strlen(msg), ") Stack size too large"); \
123 new_exception_message(string_java_lang_VerifyError, msg); \
130 /*--------------------------------------------------*/
131 /* ALLOCATING STACK SLOTS */
132 /*--------------------------------------------------*/
134 #define NEWSTACK(s,v,n) {new->prev=curstack;new->type=s;new->flags=0; \
135 new->varkind=v;new->varnum=n;curstack=new;new++;}
136 #define NEWSTACKn(s,n) NEWSTACK(s,UNDEFVAR,n)
137 #define NEWSTACK0(s) NEWSTACK(s,UNDEFVAR,0)
139 /* allocate the input stack for an exception handler */
140 #define NEWXSTACK {NEWSTACK(TYPE_ADR,STACKVAR,0);curstack=0;}
143 /*--------------------------------------------------*/
144 /* STACK MANIPULATION */
145 /*--------------------------------------------------*/
147 /* resetting to an empty operand stack */
148 #define STACKRESET {curstack=0;stackdepth=0;}
150 /* set the output stack of the current instruction */
151 #define SETDST {iptr->dst=curstack;}
153 /* The following macros do NOT check stackdepth, set stackdepth or iptr->dst */
154 #define POP(s) {if(s!=curstack->type){TYPEPANIC;} \
155 if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR;\
156 curstack=curstack->prev;}
157 #define POPANY {if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR; \
158 curstack=curstack->prev;}
159 #define COPY(s,d) {(d)->flags=0;(d)->type=(s)->type;\
160 (d)->varkind=(s)->varkind;(d)->varnum=(s)->varnum;}
163 /*--------------------------------------------------*/
164 /* STACK OPERATIONS MODELING */
165 /*--------------------------------------------------*/
167 /* The following macros are used to model the stack manipulations of
168 * different kinds of instructions.
170 * These macros check the input stackdepth and they set the output
171 * stackdepth and the output stack of the instruction (iptr->dst).
173 * These macros do *not* check for stack overflows!
176 #define PUSHCONST(s){NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
177 #define LOAD(s,v,n) {NEWSTACK(s,v,n);SETDST;stackdepth++;}
178 #define STORE(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
179 #define OP1_0(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
180 #define OP1_0ANY {REQUIRE_1;POPANY;SETDST;stackdepth--;}
181 #define OP0_1(s) {NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
182 #define OP1_1(s,d) {REQUIRE_1;POP(s);NEWSTACKn(d,stackdepth-1);SETDST;}
183 #define OP2_0(s) {REQUIRE_2;POP(s);POP(s);SETDST;stackdepth-=2;}
184 #define OPTT2_0(t,b){REQUIRE_2;POP(t);POP(b);SETDST;stackdepth-=2;}
185 #define OP2_1(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);SETDST;stackdepth--;}
186 #define OP2IAT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(TYPE_ADR);NEWSTACKn(s,stackdepth-2);\
187 SETDST;stackdepth--;}
188 #define OP2IT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(s);NEWSTACKn(s,stackdepth-2);\
189 SETDST;stackdepth--;}
190 #define OPTT2_1(s,d){REQUIRE_2;POP(s);POP(s);NEWSTACKn(d,stackdepth-2);SETDST;stackdepth--;}
191 #define OP2_2(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);\
192 NEWSTACKn(s,stackdepth-1);SETDST;}
193 #define OP3TIA_0(s) {REQUIRE_3;POP(s);POP(TYPE_INT);POP(TYPE_ADR);SETDST;stackdepth-=3;}
194 #define OP3_0(s) {REQUIRE_3;POP(s);POP(s);POP(s);SETDST;stackdepth-=3;}
195 #define POPMANY(i) {REQUIRE(i);stackdepth-=i;while(--i>=0){POPANY;}SETDST;}
196 #define DUP {REQUIRE_1;NEWSTACK(CURTYPE,CURKIND,curstack->varnum);SETDST; \
198 #define SWAP {REQUIRE_2;COPY(curstack,new);POPANY;COPY(curstack,new+1);POPANY;\
199 new[0].prev=curstack;new[1].prev=new;\
200 curstack=new+1;new+=2;SETDST;}
201 #define DUP_X1 {REQUIRE_2;COPY(curstack,new);COPY(curstack,new+2);POPANY;\
202 COPY(curstack,new+1);POPANY;new[0].prev=curstack;\
203 new[1].prev=new;new[2].prev=new+1;\
204 curstack=new+2;new+=3;SETDST;stackdepth++;}
205 #define DUP2_X1 {REQUIRE_3;COPY(curstack,new+1);COPY(curstack,new+4);POPANY;\
206 COPY(curstack,new);COPY(curstack,new+3);POPANY;\
207 COPY(curstack,new+2);POPANY;new[0].prev=curstack;\
208 new[1].prev=new;new[2].prev=new+1;\
209 new[3].prev=new+2;new[4].prev=new+3;\
210 curstack=new+4;new+=5;SETDST;stackdepth+=2;}
211 #define DUP_X2 {REQUIRE_3;COPY(curstack,new);COPY(curstack,new+3);POPANY;\
212 COPY(curstack,new+2);POPANY;COPY(curstack,new+1);POPANY;\
213 new[0].prev=curstack;new[1].prev=new;\
214 new[2].prev=new+1;new[3].prev=new+2;\
215 curstack=new+3;new+=4;SETDST;stackdepth++;}
216 #define DUP2_X2 {REQUIRE_4;COPY(curstack,new+1);COPY(curstack,new+5);POPANY;\
217 COPY(curstack,new);COPY(curstack,new+4);POPANY;\
218 COPY(curstack,new+3);POPANY;COPY(curstack,new+2);POPANY;\
219 new[0].prev=curstack;new[1].prev=new;\
220 new[2].prev=new+1;new[3].prev=new+2;\
221 new[4].prev=new+3;new[5].prev=new+4;\
222 curstack=new+5;new+=6;SETDST;stackdepth+=2;}
225 /*--------------------------------------------------*/
226 /* MACROS FOR HANDLING BASIC BLOCKS */
227 /*--------------------------------------------------*/
229 /* COPYCURSTACK makes a copy of the current operand stack (curstack)
230 * and returns it in the variable copy.
232 * This macro is used to propagate the operand stack from one basic
233 * block to another. The destination block receives the copy as its
236 #define COPYCURSTACK(copy) {\
249 copy->varkind=STACKVAR;\
260 /* BBEND is called at the end of each basic block (after the last
261 * instruction of the block has been processed).
264 #define BBEND(s,i){ \
265 i = stackdepth - 1; \
268 if ((copy->varkind == STACKVAR) && (copy->varnum > i)) \
269 copy->varkind = TEMPVAR; \
271 copy->varkind = STACKVAR; \
274 interfaces[i][copy->type].type = copy->type; \
275 interfaces[i][copy->type].flags |= copy->flags; \
276 i--; copy = copy->prev; \
278 i = bptr->indepth - 1; \
279 copy = bptr->instack; \
281 interfaces[i][copy->type].type = copy->type; \
282 if (copy->varkind == STACKVAR) { \
283 if (copy->flags & SAVEDVAR) \
284 interfaces[i][copy->type].flags |= SAVEDVAR; \
286 i--; copy = copy->prev; \
291 /* MARKREACHED marks the destination block <b> as reached. If this
292 * block has been reached before we check if stack depth and types
293 * match. Otherwise the destination block receives a copy of the
294 * current stack as its input stack.
296 * b...destination block
299 #define MARKREACHED(b,c) { \
301 {COPYCURSTACK(c);b->flags=0;b->instack=c;b->indepth=stackdepth;} \
302 else {stackptr s=curstack;stackptr t=b->instack; \
303 if(b->indepth!=stackdepth) \
304 {show_icmd_method();panic("Stack depth mismatch");} \
305 while(s){if (s->type!=t->type) \
307 s=s->prev;t=t->prev; \
313 /**********************************************************************/
315 /**********************************************************************/
317 /* analyse_stack uses the intermediate code created by parse.c to
318 * build a model of the JVM operand stack for the current method.
320 * The following checks are performed:
321 * - check for operand stack underflow (before each instruction)
322 * - check for operand stack overflow (after[1] each instruction)
323 * - check for matching stack depth at merging points
324 * - check for matching basic types[2] at merging points
325 * - check basic types for instruction input (except for BUILTIN*
326 * opcodes, INVOKE* opcodes and MULTIANEWARRAY)
328 * [1]) Checking this after the instruction should be ok. parse.c
329 * counts the number of required stack slots in such a way that it is
330 * only vital that we don't exceed `maxstack` at basic block
333 * [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
334 * DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
335 * types are not discerned.
338 methodinfo *analyse_stack(methodinfo *m)
346 int opcode, i, len, loops;
347 int superblockend, repeat, deadcode;
354 char msg[MAXLOGTEXT]; /* maybe we get an exception */
356 argren = DMNEW(int, maxlocals);
357 /*int *argren = (int *)alloca(maxlocals * sizeof(int));*/ /* table for argument renaming */
358 for (i = 0; i < maxlocals; i++)
364 block[0].flags = BBREACHED;
365 block[0].instack = 0;
366 block[0].indepth = 0;
368 for (i = 0; i < exceptiontablelength; i++) {
369 bptr = &block[block_index[extable[i].handlerpc]];
370 bptr->flags = BBREACHED;
371 bptr->type = BBTYPE_EXH;
374 bptr->pre_count = 10000;
379 #ifdef CONDITIONAL_LOADCONST
380 b_count = block_count;
382 while (--b_count >= 0) {
383 if (bptr->icount != 0) {
384 iptr = bptr->iinstr + bptr->icount - 1;
417 block[block_index[iptr->op1]].pre_count++;
420 case ICMD_TABLESWITCH:
422 block[block_index[*s4ptr++]].pre_count++; /* default */
423 i = *s4ptr++; /* low */
424 i = *s4ptr++ - i + 1; /* high */
426 block[block_index[*s4ptr++]].pre_count++;
430 case ICMD_LOOKUPSWITCH:
432 block[block_index[*s4ptr++]].pre_count++; /* default */
433 i = *s4ptr++; /* count */
435 block[block_index[s4ptr[1]]].pre_count++;
451 b_count = block_count;
453 superblockend = true;
457 while (--b_count >= 0) {
458 if (bptr->flags == BBDELETED) {
461 else if (superblockend && (bptr->flags < BBREACHED))
463 else if (bptr->flags <= BBREACHED) {
465 stackdepth = bptr->indepth;
466 else if (bptr->flags < BBREACHED) {
468 bptr->instack = copy;
469 bptr->indepth = stackdepth;
471 else if (bptr->indepth != stackdepth) {
473 panic("Stack depth mismatch");
476 curstack = bptr->instack;
478 superblockend = false;
479 bptr->flags = BBFINISHED;
482 b_index = bptr - block;
487 /* dolog("p: %04d op: %s stack: %p", iptr - instr, icmd_names[opcode], curstack); */
489 #ifdef USEBUILTINTABLE
492 stdopdescriptor *breplace;
493 breplace = find_builtin(opcode);
495 if (breplace && opcode == breplace->opcode) {
496 iptr[0].opc = breplace->icmd;
497 iptr[0].op1 = breplace->type_d;
498 iptr[0].val.a = breplace->builtin;
499 isleafmethod = false;
500 switch (breplace->icmd) {
508 builtin_descriptor *breplace;
509 breplace = find_builtin(opcode);
511 if (breplace && opcode == breplace->opcode) {
512 iptr[0].opc = breplace->icmd;
513 iptr[0].op1 = breplace->type_d;
514 iptr[0].val.a = breplace->builtin;
515 isleafmethod = false;
516 switch (breplace->icmd) {
531 case ICMD_CHECKASIZE:
532 case ICMD_CHECKEXCEPTION:
534 case ICMD_IFEQ_ICONST:
535 case ICMD_IFNE_ICONST:
536 case ICMD_IFLT_ICONST:
537 case ICMD_IFGE_ICONST:
538 case ICMD_IFGT_ICONST:
539 case ICMD_IFLE_ICONST:
540 case ICMD_ELSE_ICONST:
545 locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
547 COUNT(count_pcmd_return);
549 superblockend = true;
552 /* pop 0 push 1 const */
555 COUNT(count_pcmd_load);
557 switch (iptr[1].opc) {
559 iptr[0].opc = ICMD_IADDCONST;
561 iptr[1].opc = ICMD_NOP;
562 OP1_1(TYPE_INT,TYPE_INT);
563 COUNT(count_pcmd_op);
566 iptr[0].opc = ICMD_ISUBCONST;
567 goto icmd_iconst_tail;
569 iptr[0].opc = ICMD_IMULCONST;
570 goto icmd_iconst_tail;
572 if (iptr[0].val.i == 0x00000002)
574 else if (iptr[0].val.i == 0x00000004)
576 else if (iptr[0].val.i == 0x00000008)
578 else if (iptr[0].val.i == 0x00000010)
580 else if (iptr[0].val.i == 0x00000020)
582 else if (iptr[0].val.i == 0x00000040)
584 else if (iptr[0].val.i == 0x00000080)
586 else if (iptr[0].val.i == 0x00000100)
588 else if (iptr[0].val.i == 0x00000200)
590 else if (iptr[0].val.i == 0x00000400)
592 else if (iptr[0].val.i == 0x00000800)
594 else if (iptr[0].val.i == 0x00001000)
596 else if (iptr[0].val.i == 0x00002000)
598 else if (iptr[0].val.i == 0x00004000)
600 else if (iptr[0].val.i == 0x00008000)
602 else if (iptr[0].val.i == 0x00010000)
604 else if (iptr[0].val.i == 0x00020000)
606 else if (iptr[0].val.i == 0x00040000)
608 else if (iptr[0].val.i == 0x00080000)
610 else if (iptr[0].val.i == 0x00100000)
612 else if (iptr[0].val.i == 0x00200000)
614 else if (iptr[0].val.i == 0x00400000)
616 else if (iptr[0].val.i == 0x00800000)
618 else if (iptr[0].val.i == 0x01000000)
620 else if (iptr[0].val.i == 0x02000000)
622 else if (iptr[0].val.i == 0x04000000)
624 else if (iptr[0].val.i == 0x08000000)
626 else if (iptr[0].val.i == 0x10000000)
628 else if (iptr[0].val.i == 0x20000000)
630 else if (iptr[0].val.i == 0x40000000)
632 else if (iptr[0].val.i == 0x80000000)
638 iptr[0].opc = ICMD_IDIVPOW2;
639 goto icmd_iconst_tail;
641 #if !defined(NO_DIV_OPT)
642 if (iptr[0].val.i == 0x10001) {
643 iptr[0].opc = ICMD_IREM0X10001;
644 goto icmd_iconst_tail;
647 if ((iptr[0].val.i == 0x00000002) ||
648 (iptr[0].val.i == 0x00000004) ||
649 (iptr[0].val.i == 0x00000008) ||
650 (iptr[0].val.i == 0x00000010) ||
651 (iptr[0].val.i == 0x00000020) ||
652 (iptr[0].val.i == 0x00000040) ||
653 (iptr[0].val.i == 0x00000080) ||
654 (iptr[0].val.i == 0x00000100) ||
655 (iptr[0].val.i == 0x00000200) ||
656 (iptr[0].val.i == 0x00000400) ||
657 (iptr[0].val.i == 0x00000800) ||
658 (iptr[0].val.i == 0x00001000) ||
659 (iptr[0].val.i == 0x00002000) ||
660 (iptr[0].val.i == 0x00004000) ||
661 (iptr[0].val.i == 0x00008000) ||
662 (iptr[0].val.i == 0x00010000) ||
663 (iptr[0].val.i == 0x00020000) ||
664 (iptr[0].val.i == 0x00040000) ||
665 (iptr[0].val.i == 0x00080000) ||
666 (iptr[0].val.i == 0x00100000) ||
667 (iptr[0].val.i == 0x00200000) ||
668 (iptr[0].val.i == 0x00400000) ||
669 (iptr[0].val.i == 0x00800000) ||
670 (iptr[0].val.i == 0x01000000) ||
671 (iptr[0].val.i == 0x02000000) ||
672 (iptr[0].val.i == 0x04000000) ||
673 (iptr[0].val.i == 0x08000000) ||
674 (iptr[0].val.i == 0x10000000) ||
675 (iptr[0].val.i == 0x20000000) ||
676 (iptr[0].val.i == 0x40000000) ||
677 (iptr[0].val.i == 0x80000000)) {
678 iptr[0].opc = ICMD_IREMPOW2;
680 #if defined(__I386__)
681 method_uses_ecx = true;
683 goto icmd_iconst_tail;
688 iptr[0].opc = ICMD_IANDCONST;
689 goto icmd_iconst_tail;
691 iptr[0].opc = ICMD_IORCONST;
692 goto icmd_iconst_tail;
694 iptr[0].opc = ICMD_IXORCONST;
695 goto icmd_iconst_tail;
697 iptr[0].opc = ICMD_ISHLCONST;
698 goto icmd_iconst_tail;
700 iptr[0].opc = ICMD_ISHRCONST;
701 goto icmd_iconst_tail;
703 iptr[0].opc = ICMD_IUSHRCONST;
704 goto icmd_iconst_tail;
705 #if SUPPORT_LONG_SHIFT
707 iptr[0].opc = ICMD_LSHLCONST;
708 #if defined(__I386__)
709 method_uses_ecx = true;
711 goto icmd_lconst_tail;
713 iptr[0].opc = ICMD_LSHRCONST;
714 #if defined(__I386__)
715 method_uses_ecx = true;
717 goto icmd_lconst_tail;
719 iptr[0].opc = ICMD_LUSHRCONST;
720 #if defined(__I386__)
721 method_uses_ecx = true;
723 goto icmd_lconst_tail;
726 iptr[0].opc = ICMD_IFEQ;
728 iptr[0].op1 = iptr[1].op1;
731 /* iptr[1].opc = ICMD_NOP; */
733 tbptr = block + block_index[iptr->op1];
735 iptr[0].target = (void *) tbptr;
737 MARKREACHED(tbptr, copy);
738 COUNT(count_pcmd_bra);
741 iptr[0].opc = ICMD_IFLT;
742 goto icmd_if_icmp_tail;
744 iptr[0].opc = ICMD_IFLE;
745 goto icmd_if_icmp_tail;
747 iptr[0].opc = ICMD_IFNE;
748 goto icmd_if_icmp_tail;
750 iptr[0].opc = ICMD_IFGT;
751 goto icmd_if_icmp_tail;
753 iptr[0].opc = ICMD_IFGE;
754 goto icmd_if_icmp_tail;
763 COUNT(count_pcmd_load);
765 switch (iptr[1].opc) {
768 iptr[0].opc = ICMD_LADDCONST;
770 iptr[1].opc = ICMD_NOP;
771 OP1_1(TYPE_LNG,TYPE_LNG);
772 COUNT(count_pcmd_op);
775 iptr[0].opc = ICMD_LSUBCONST;
776 goto icmd_lconst_tail;
780 iptr[0].opc = ICMD_LMULCONST;
781 #if defined(__I386__)
782 method_uses_ecx = true;
783 method_uses_edx = true;
785 goto icmd_lconst_tail;
789 if (iptr[0].val.l == 0x00000002)
791 else if (iptr[0].val.l == 0x00000004)
793 else if (iptr[0].val.l == 0x00000008)
795 else if (iptr[0].val.l == 0x00000010)
797 else if (iptr[0].val.l == 0x00000020)
799 else if (iptr[0].val.l == 0x00000040)
801 else if (iptr[0].val.l == 0x00000080)
803 else if (iptr[0].val.l == 0x00000100)
805 else if (iptr[0].val.l == 0x00000200)
807 else if (iptr[0].val.l == 0x00000400)
809 else if (iptr[0].val.l == 0x00000800)
811 else if (iptr[0].val.l == 0x00001000)
813 else if (iptr[0].val.l == 0x00002000)
815 else if (iptr[0].val.l == 0x00004000)
817 else if (iptr[0].val.l == 0x00008000)
819 else if (iptr[0].val.l == 0x00010000)
821 else if (iptr[0].val.l == 0x00020000)
823 else if (iptr[0].val.l == 0x00040000)
825 else if (iptr[0].val.l == 0x00080000)
827 else if (iptr[0].val.l == 0x00100000)
829 else if (iptr[0].val.l == 0x00200000)
831 else if (iptr[0].val.l == 0x00400000)
833 else if (iptr[0].val.l == 0x00800000)
835 else if (iptr[0].val.l == 0x01000000)
837 else if (iptr[0].val.l == 0x02000000)
839 else if (iptr[0].val.l == 0x04000000)
841 else if (iptr[0].val.l == 0x08000000)
843 else if (iptr[0].val.l == 0x10000000)
845 else if (iptr[0].val.l == 0x20000000)
847 else if (iptr[0].val.l == 0x40000000)
849 else if (iptr[0].val.l == 0x80000000)
855 iptr[0].opc = ICMD_LDIVPOW2;
856 #if defined(__I386__)
857 method_uses_ecx = true;
859 goto icmd_lconst_tail;
861 #if !defined(NO_DIV_OPT)
862 if (iptr[0].val.l == 0x10001) {
863 iptr[0].opc = ICMD_LREM0X10001;
864 goto icmd_lconst_tail;
867 if ((iptr[0].val.l == 0x00000002) ||
868 (iptr[0].val.l == 0x00000004) ||
869 (iptr[0].val.l == 0x00000008) ||
870 (iptr[0].val.l == 0x00000010) ||
871 (iptr[0].val.l == 0x00000020) ||
872 (iptr[0].val.l == 0x00000040) ||
873 (iptr[0].val.l == 0x00000080) ||
874 (iptr[0].val.l == 0x00000100) ||
875 (iptr[0].val.l == 0x00000200) ||
876 (iptr[0].val.l == 0x00000400) ||
877 (iptr[0].val.l == 0x00000800) ||
878 (iptr[0].val.l == 0x00001000) ||
879 (iptr[0].val.l == 0x00002000) ||
880 (iptr[0].val.l == 0x00004000) ||
881 (iptr[0].val.l == 0x00008000) ||
882 (iptr[0].val.l == 0x00010000) ||
883 (iptr[0].val.l == 0x00020000) ||
884 (iptr[0].val.l == 0x00040000) ||
885 (iptr[0].val.l == 0x00080000) ||
886 (iptr[0].val.l == 0x00100000) ||
887 (iptr[0].val.l == 0x00200000) ||
888 (iptr[0].val.l == 0x00400000) ||
889 (iptr[0].val.l == 0x00800000) ||
890 (iptr[0].val.l == 0x01000000) ||
891 (iptr[0].val.l == 0x02000000) ||
892 (iptr[0].val.l == 0x04000000) ||
893 (iptr[0].val.l == 0x08000000) ||
894 (iptr[0].val.l == 0x10000000) ||
895 (iptr[0].val.l == 0x20000000) ||
896 (iptr[0].val.l == 0x40000000) ||
897 (iptr[0].val.l == 0x80000000)) {
898 iptr[0].opc = ICMD_LREMPOW2;
900 #if defined(__I386__)
901 method_uses_ecx = true;
903 goto icmd_lconst_tail;
910 iptr[0].opc = ICMD_LANDCONST;
911 goto icmd_lconst_tail;
913 iptr[0].opc = ICMD_LORCONST;
914 goto icmd_lconst_tail;
916 iptr[0].opc = ICMD_LXORCONST;
917 goto icmd_lconst_tail;
919 #if !defined(NOLONG_CONDITIONAL)
921 if ((len > 1) && (iptr[2].val.i == 0)) {
922 switch (iptr[2].opc) {
924 iptr[0].opc = ICMD_IF_LEQ;
925 #if defined(__I386__)
926 method_uses_ecx = true;
928 icmd_lconst_lcmp_tail:
929 iptr[0].op1 = iptr[2].op1;
932 /* iptr[1].opc = ICMD_NOP;
933 iptr[2].opc = ICMD_NOP; */
935 tbptr = block + block_index[iptr->op1];
937 iptr[0].target = (void *) tbptr;
939 MARKREACHED(tbptr, copy);
940 COUNT(count_pcmd_bra);
941 COUNT(count_pcmd_op);
944 iptr[0].opc = ICMD_IF_LNE;
945 #if defined(__I386__)
946 method_uses_ecx = true;
948 goto icmd_lconst_lcmp_tail;
950 iptr[0].opc = ICMD_IF_LLT;
951 goto icmd_lconst_lcmp_tail;
953 iptr[0].opc = ICMD_IF_LGT;
954 goto icmd_lconst_lcmp_tail;
956 iptr[0].opc = ICMD_IF_LLE;
957 goto icmd_lconst_lcmp_tail;
959 iptr[0].opc = ICMD_IF_LGE;
960 goto icmd_lconst_lcmp_tail;
963 } /* switch (iptr[2].opc) */
964 } /* if (iptr[2].val.i == 0) */
977 COUNT(count_pcmd_load);
981 COUNT(count_pcmd_load);
985 COUNT(count_pcmd_load);
989 /* pop 0 push 1 load */
996 COUNT(count_load_instruction);
997 i = opcode-ICMD_ILOAD;
998 iptr->op1 = argren[iptr->op1];
999 locals[iptr->op1][i].type = i;
1000 LOAD(i, LOCALVAR, iptr->op1);
1006 #if defined(__I386__)
1007 method_uses_ecx = true;
1008 method_uses_edx = true;
1014 COUNT(count_check_null);
1015 COUNT(count_check_bound);
1016 COUNT(count_pcmd_mem);
1017 OP2IAT_1(opcode-ICMD_IALOAD);
1018 #if defined(__I386__)
1019 method_uses_ecx = true;
1026 COUNT(count_check_null);
1027 COUNT(count_check_bound);
1028 COUNT(count_pcmd_mem);
1030 #if defined(__I386__)
1031 method_uses_ecx = true;
1035 /* pop 0 push 0 iinc */
1041 count_store_depth[10]++;
1043 count_store_depth[i]++;
1048 if ((copy->varkind == LOCALVAR) &&
1049 (copy->varnum == iptr->op1)) {
1050 copy->varkind = TEMPVAR;
1059 /* pop 1 push 0 store */
1069 i = opcode - ICMD_ISTORE;
1070 locals[iptr->op1][i].type = i;
1075 count_store_length[20]++;
1077 count_store_length[i]++;
1080 count_store_depth[10]++;
1082 count_store_depth[i]++;
1084 copy = curstack->prev;
1087 if ((copy->varkind == LOCALVAR) &&
1088 (copy->varnum == iptr->op1)) {
1089 copy->varkind = TEMPVAR;
1095 if ((new - curstack) == 1) {
1096 curstack->varkind = LOCALVAR;
1097 curstack->varnum = iptr->op1;
1099 STORE(opcode-ICMD_ISTORE);
1107 #if defined(__I386__)
1108 method_uses_ecx = true;
1109 method_uses_edx = true;
1113 COUNT(count_check_null);
1114 COUNT(count_check_bound);
1115 COUNT(count_pcmd_mem);
1116 OP3TIA_0(opcode-ICMD_IASTORE);
1122 COUNT(count_check_null);
1123 COUNT(count_check_bound);
1124 COUNT(count_pcmd_mem);
1126 #if defined(__I386__)
1127 method_uses_ecx = true;
1128 method_uses_edx = true;
1135 #ifdef TYPECHECK_STACK_COMPCAT
1138 if (IS_2_WORD_TYPE(curstack->type))
1139 panic("Illegal instruction: POP on category 2 type");
1150 COUNT(count_pcmd_return);
1151 OP1_0(opcode-ICMD_IRETURN);
1152 superblockend = true;
1156 COUNT(count_check_null);
1160 superblockend = true;
1163 case ICMD_PUTSTATIC:
1164 COUNT(count_pcmd_mem);
1166 #if defined(__I386__)
1167 method_uses_ecx = true;
1171 /* pop 1 push 0 branch */
1174 case ICMD_IFNONNULL:
1175 COUNT(count_pcmd_bra);
1177 tbptr = block + block_index[iptr->op1];
1179 iptr[0].target = (void *) tbptr;
1181 MARKREACHED(tbptr, copy);
1190 COUNT(count_pcmd_bra);
1191 #ifdef CONDITIONAL_LOADCONST
1193 tbptr = block + b_index;
1194 if ((b_count >= 3) &&
1195 ((b_index + 2) == block_index[iptr[0].op1]) &&
1196 (tbptr[1].pre_count == 1) &&
1197 (iptr[1].opc == ICMD_ICONST) &&
1198 (iptr[2].opc == ICMD_GOTO) &&
1199 ((b_index + 3) == block_index[iptr[2].op1]) &&
1200 (tbptr[2].pre_count == 1) &&
1201 (iptr[3].opc == ICMD_ICONST)) {
1202 OP1_1(TYPE_INT, TYPE_INT);
1203 switch (iptr[0].opc) {
1205 iptr[0].opc = ICMD_IFNE_ICONST;
1208 iptr[0].opc = ICMD_IFEQ_ICONST;
1211 iptr[0].opc = ICMD_IFGE_ICONST;
1214 iptr[0].opc = ICMD_IFLT_ICONST;
1217 iptr[0].opc = ICMD_IFLE_ICONST;
1220 iptr[0].opc = ICMD_IFGT_ICONST;
1223 iptr[0].val.i = iptr[1].val.i;
1224 iptr[1].opc = ICMD_ELSE_ICONST;
1225 iptr[1].val.i = iptr[3].val.i;
1226 iptr[2].opc = ICMD_NOP;
1227 iptr[3].opc = ICMD_NOP;
1228 tbptr[1].flags = BBDELETED;
1229 tbptr[2].flags = BBDELETED;
1230 tbptr[1].icount = 0;
1231 tbptr[2].icount = 0;
1232 if (tbptr[3].pre_count == 2) {
1233 len += tbptr[3].icount + 3;
1234 bptr->icount += tbptr[3].icount + 3;
1235 tbptr[3].flags = BBDELETED;
1236 tbptr[3].icount = 0;
1249 tbptr = block + block_index[iptr->op1];
1251 iptr[0].target = (void *) tbptr;
1253 MARKREACHED(tbptr, copy);
1256 /* pop 0 push 0 branch */
1259 COUNT(count_pcmd_bra);
1260 tbptr = block + block_index[iptr->op1];
1262 iptr[0].target = (void *) tbptr;
1264 MARKREACHED(tbptr, copy);
1266 superblockend = true;
1269 /* pop 1 push 0 table branch */
1271 case ICMD_TABLESWITCH:
1272 COUNT(count_pcmd_table);
1274 s4ptr = iptr->val.a;
1275 tbptr = block + block_index[*s4ptr++]; /* default */
1276 MARKREACHED(tbptr, copy);
1277 i = *s4ptr++; /* low */
1278 i = *s4ptr++ - i + 1; /* high */
1280 tptr = DMNEW(void*, i+1);
1281 iptr->target = (void *) tptr;
1283 tptr[0] = (void *) tbptr;
1287 tbptr = block + block_index[*s4ptr++];
1289 tptr[0] = (void *) tbptr;
1292 MARKREACHED(tbptr, copy);
1295 superblockend = true;
1296 #if defined(__I386__)
1297 method_uses_ecx = true;
1301 /* pop 1 push 0 table branch */
1303 case ICMD_LOOKUPSWITCH:
1304 COUNT(count_pcmd_table);
1306 s4ptr = iptr->val.a;
1307 tbptr = block + block_index[*s4ptr++]; /* default */
1308 MARKREACHED(tbptr, copy);
1309 i = *s4ptr++; /* count */
1311 tptr = DMNEW(void*, i+1);
1312 iptr->target = (void *) tptr;
1314 tptr[0] = (void *) tbptr;
1318 tbptr = block + block_index[s4ptr[1]];
1320 tptr[0] = (void *) tbptr;
1323 MARKREACHED(tbptr, copy);
1327 superblockend = true;
1330 case ICMD_NULLCHECKPOP:
1331 case ICMD_MONITORENTER:
1332 COUNT(count_check_null);
1333 case ICMD_MONITOREXIT:
1337 /* pop 2 push 0 branch */
1339 case ICMD_IF_ICMPEQ:
1340 case ICMD_IF_ICMPNE:
1341 case ICMD_IF_ICMPLT:
1342 case ICMD_IF_ICMPGE:
1343 case ICMD_IF_ICMPGT:
1344 case ICMD_IF_ICMPLE:
1345 COUNT(count_pcmd_bra);
1347 tbptr = block + block_index[iptr->op1];
1349 iptr[0].target = (void *) tbptr;
1351 MARKREACHED(tbptr, copy);
1354 case ICMD_IF_ACMPEQ:
1355 case ICMD_IF_ACMPNE:
1356 COUNT(count_pcmd_bra);
1358 tbptr = block + block_index[iptr->op1];
1360 iptr[0].target = (void *) tbptr;
1362 MARKREACHED(tbptr, copy);
1368 COUNT(count_check_null);
1369 COUNT(count_pcmd_mem);
1370 OPTT2_0(iptr->op1,TYPE_ADR);
1371 #if defined(__I386__)
1372 method_uses_ecx = true;
1378 if (! IS_2_WORD_TYPE(curstack->type)) {
1380 #ifdef TYPECHECK_STACK_COMPCAT
1383 if (IS_2_WORD_TYPE(curstack->prev->type))
1384 panic("Illegal instruction: POP2 on cat2, cat1 types");
1387 OP1_0ANY; /* second pop */
1390 iptr->opc = ICMD_POP;
1394 /* pop 0 push 1 dup */
1397 #ifdef TYPECHECK_STACK_COMPCAT
1400 if (IS_2_WORD_TYPE(curstack->type))
1401 panic("Illegal instruction: DUP on category 2 type");
1404 COUNT(count_dup_instruction);
1410 if (IS_2_WORD_TYPE(curstack->type)) {
1412 iptr->opc = ICMD_DUP;
1417 /* ..., ????, cat1 */
1418 #ifdef TYPECHECK_STACK_COMPCAT
1420 if (IS_2_WORD_TYPE(curstack->prev->type))
1421 panic("Illegal instruction: DUP2 on cat2, cat1 types");
1425 NEWSTACK(copy->prev->type, copy->prev->varkind,
1426 copy->prev->varnum);
1427 NEWSTACK(copy->type, copy->varkind,
1434 /* pop 2 push 3 dup */
1437 #ifdef TYPECHECK_STACK_COMPCAT
1440 if (IS_2_WORD_TYPE(curstack->type) ||
1441 IS_2_WORD_TYPE(curstack->prev->type))
1442 panic("Illegal instruction: DUP_X1 on cat 2 type");
1450 if (IS_2_WORD_TYPE(curstack->type)) {
1451 /* ..., ????, cat2 */
1452 #ifdef TYPECHECK_STACK_COMPCAT
1454 if (IS_2_WORD_TYPE(curstack->prev->type))
1455 panic("Illegal instruction: DUP2_X1 on cat2, cat2 types");
1458 iptr->opc = ICMD_DUP_X1;
1462 /* ..., ????, cat1 */
1463 #ifdef TYPECHECK_STACK_COMPCAT
1466 if (IS_2_WORD_TYPE(curstack->prev->type)
1467 || IS_2_WORD_TYPE(curstack->prev->prev->type))
1468 panic("Illegal instruction: DUP2_X1 on invalid types");
1475 /* pop 3 push 4 dup */
1479 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1480 /* ..., cat2, ???? */
1481 #ifdef TYPECHECK_STACK_COMPCAT
1483 if (IS_2_WORD_TYPE(curstack->type))
1484 panic("Illegal instruction: DUP_X2 on cat2, cat2 types");
1487 iptr->opc = ICMD_DUP_X1;
1491 /* ..., cat1, ???? */
1492 #ifdef TYPECHECK_STACK_COMPCAT
1495 if (IS_2_WORD_TYPE(curstack->type)
1496 || IS_2_WORD_TYPE(curstack->prev->prev->type))
1497 panic("Illegal instruction: DUP_X2 on invalid types");
1506 if (IS_2_WORD_TYPE(curstack->type)) {
1507 /* ..., ????, cat2 */
1508 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1509 /* ..., cat2, cat2 */
1510 iptr->opc = ICMD_DUP_X1;
1514 /* ..., cat1, cat2 */
1515 #ifdef TYPECHECK_STACK_COMPCAT
1518 if (IS_2_WORD_TYPE(curstack->prev->prev->type))
1519 panic("Illegal instruction: DUP2_X2 on invalid types");
1522 iptr->opc = ICMD_DUP_X2;
1528 /* ..., ????, ????, cat1 */
1529 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1530 /* ..., cat2, ????, cat1 */
1531 #ifdef TYPECHECK_STACK_COMPCAT
1533 if (IS_2_WORD_TYPE(curstack->prev->type))
1534 panic("Illegal instruction: DUP2_X2 on invalid types");
1537 iptr->opc = ICMD_DUP2_X1;
1541 /* ..., cat1, ????, cat1 */
1542 #ifdef TYPECHECK_STACK_COMPCAT
1545 if (IS_2_WORD_TYPE(curstack->prev->type)
1546 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
1547 panic("Illegal instruction: DUP2_X2 on invalid types");
1555 /* pop 2 push 2 swap */
1558 #ifdef TYPECHECK_STACK_COMPCAT
1561 if (IS_2_WORD_TYPE(curstack->type)
1562 || IS_2_WORD_TYPE(curstack->prev->type))
1563 panic("Illegal instruction: SWAP on category 2 type");
1572 #if !SUPPORT_DIVISION
1573 iptr[0].opc = ICMD_BUILTIN2;
1574 iptr[0].op1 = TYPE_INT;
1575 iptr[0].val.a = BUILTIN_idiv;
1576 isleafmethod = false;
1581 #if !SUPPORT_DIVISION
1582 iptr[0].opc = ICMD_BUILTIN2;
1583 iptr[0].op1 = TYPE_INT;
1584 iptr[0].val.a = BUILTIN_irem;
1585 isleafmethod = false;
1588 #if defined(__I386__)
1589 method_uses_ecx = true;
1590 method_uses_edx = true;
1596 #if defined(__I386__)
1597 method_uses_ecx = true;
1605 COUNT(count_pcmd_op);
1610 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1611 iptr[0].opc = ICMD_BUILTIN2;
1612 iptr[0].op1 = TYPE_LNG;
1613 iptr[0].val.a = BUILTIN_ldiv;
1614 isleafmethod = false;
1619 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1620 iptr[0].opc = ICMD_BUILTIN2;
1621 iptr[0].op1 = TYPE_LNG;
1622 iptr[0].val.a = BUILTIN_lrem;
1623 isleafmethod = false;
1628 #if defined(__I386__)
1629 method_uses_ecx = true;
1630 method_uses_edx = true;
1637 /* DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1638 COUNT(count_pcmd_op);
1645 COUNT(count_pcmd_op);
1647 #if defined(__I386__)
1648 method_uses_ecx = true;
1649 method_uses_edx = true;
1658 COUNT(count_pcmd_op);
1667 COUNT(count_pcmd_op);
1672 COUNT(count_pcmd_op);
1673 #if !defined(NOLONG_CONDITIONAL)
1674 if ((len > 0) && (iptr[1].val.i == 0)) {
1675 switch (iptr[1].opc) {
1677 iptr[0].opc = ICMD_IF_LCMPEQ;
1678 #if defined(__I386__)
1679 method_uses_ecx = true;
1682 iptr[0].op1 = iptr[1].op1;
1685 /* iptr[1].opc = ICMD_NOP; */
1687 tbptr = block + block_index[iptr->op1];
1689 iptr[0].target = (void *) tbptr;
1691 MARKREACHED(tbptr, copy);
1692 COUNT(count_pcmd_bra);
1695 iptr[0].opc = ICMD_IF_LCMPNE;
1696 #if defined(__I386__)
1697 method_uses_ecx = true;
1699 goto icmd_lcmp_if_tail;
1701 iptr[0].opc = ICMD_IF_LCMPLT;
1702 goto icmd_lcmp_if_tail;
1704 iptr[0].opc = ICMD_IF_LCMPGT;
1705 goto icmd_lcmp_if_tail;
1707 iptr[0].opc = ICMD_IF_LCMPLE;
1708 goto icmd_lcmp_if_tail;
1710 iptr[0].opc = ICMD_IF_LCMPGE;
1711 goto icmd_lcmp_if_tail;
1713 OPTT2_1(TYPE_LNG, TYPE_INT);
1718 OPTT2_1(TYPE_LNG, TYPE_INT);
1722 COUNT(count_pcmd_op);
1723 OPTT2_1(TYPE_FLT, TYPE_INT);
1727 COUNT(count_pcmd_op);
1728 OPTT2_1(TYPE_DBL, TYPE_INT);
1736 case ICMD_INT2SHORT:
1737 COUNT(count_pcmd_op);
1738 OP1_1(TYPE_INT, TYPE_INT);
1741 COUNT(count_pcmd_op);
1742 OP1_1(TYPE_LNG, TYPE_LNG);
1745 COUNT(count_pcmd_op);
1746 OP1_1(TYPE_FLT, TYPE_FLT);
1749 COUNT(count_pcmd_op);
1750 OP1_1(TYPE_DBL, TYPE_DBL);
1754 COUNT(count_pcmd_op);
1755 OP1_1(TYPE_INT, TYPE_LNG);
1756 #if defined(__I386__)
1757 method_uses_edx = true;
1761 COUNT(count_pcmd_op);
1762 OP1_1(TYPE_INT, TYPE_FLT);
1765 COUNT(count_pcmd_op);
1766 OP1_1(TYPE_INT, TYPE_DBL);
1769 COUNT(count_pcmd_op);
1770 OP1_1(TYPE_LNG, TYPE_INT);
1773 COUNT(count_pcmd_op);
1774 OP1_1(TYPE_LNG, TYPE_FLT);
1777 COUNT(count_pcmd_op);
1778 OP1_1(TYPE_LNG, TYPE_DBL);
1781 COUNT(count_pcmd_op);
1782 OP1_1(TYPE_FLT, TYPE_INT);
1785 COUNT(count_pcmd_op);
1786 OP1_1(TYPE_FLT, TYPE_LNG);
1787 #if defined(__I386__)
1788 method_uses_edx = true;
1792 COUNT(count_pcmd_op);
1793 OP1_1(TYPE_FLT, TYPE_DBL);
1796 COUNT(count_pcmd_op);
1797 OP1_1(TYPE_DBL, TYPE_INT);
1800 COUNT(count_pcmd_op);
1801 OP1_1(TYPE_DBL, TYPE_LNG);
1802 #if defined(__I386__)
1803 method_uses_edx = true;
1807 COUNT(count_pcmd_op);
1808 OP1_1(TYPE_DBL, TYPE_FLT);
1811 case ICMD_CHECKCAST:
1812 OP1_1(TYPE_ADR, TYPE_ADR);
1813 #if defined(__I386__)
1814 method_uses_ecx = true;
1815 method_uses_edx = true;
1819 case ICMD_INSTANCEOF:
1820 #if defined(__I386__)
1821 method_uses_ecx = true;
1822 method_uses_edx = true;
1824 case ICMD_ARRAYLENGTH:
1825 OP1_1(TYPE_ADR, TYPE_INT);
1829 case ICMD_ANEWARRAY:
1830 OP1_1(TYPE_INT, TYPE_ADR);
1834 COUNT(count_check_null);
1835 COUNT(count_pcmd_mem);
1836 OP1_1(TYPE_ADR, iptr->op1);
1837 #if defined(__I386__)
1838 method_uses_ecx = true;
1844 case ICMD_GETSTATIC:
1845 COUNT(count_pcmd_mem);
1847 #if defined(__I386__)
1848 method_uses_ecx = true;
1858 tbptr = block + block_index[iptr->op1];
1860 iptr[0].target = (void *) tbptr;
1862 /* This is a dirty hack. The typechecker
1863 * needs it because the OP1_0ANY below
1864 * overwrites iptr->dst.
1866 iptr->val.a = (void *) iptr->dst;
1868 tbptr->type = BBTYPE_SBR;
1870 /* We need to check for overflow right here because
1871 * the pushed value is poped after MARKREACHED. */
1873 MARKREACHED(tbptr, copy);
1877 /* pop many push any */
1879 case ICMD_INVOKEVIRTUAL:
1880 case ICMD_INVOKESPECIAL:
1881 case ICMD_INVOKEINTERFACE:
1882 case ICMD_INVOKESTATIC:
1883 COUNT(count_pcmd_met);
1884 #if defined(__I386__)
1885 method_uses_ecx = true;
1888 methodinfo *m = iptr->val.a;
1889 if (m->flags & ACC_STATIC)
1890 {COUNT(count_check_null);}
1892 if (i > arguments_num)
1895 #if defined(__X86_64__)
1903 (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1907 stackargs += (iarg < intreg_argnum) ? 0 : (iarg - intreg_argnum);
1908 stackargs += (farg < fltreg_argnum) ? 0 : (farg - fltreg_argnum);
1913 if (!(copy->flags & SAVEDVAR)) {
1914 copy->varkind = ARGVAR;
1915 if (IS_FLT_DBL_TYPE(copy->type)) {
1916 if (--farg < fltreg_argnum) {
1917 copy->varnum = farg;
1919 copy->varnum = --stackargs + intreg_argnum;
1922 if (--iarg < intreg_argnum) {
1923 copy->varnum = iarg;
1925 copy->varnum = --stackargs + intreg_argnum;
1929 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1937 if (! (copy->flags & SAVEDVAR)) {
1938 copy->varkind = ARGVAR;
1945 copy->flags |= SAVEDVAR;
1950 if (m->returntype != TYPE_VOID) {
1951 OP0_1(m->returntype);
1957 /* DEBUG */ /*dolog("builtin3");*/
1959 if (! (curstack->flags & SAVEDVAR)) {
1960 curstack->varkind = ARGVAR;
1961 curstack->varnum = 2;
1963 if (3 > arguments_num) {
1971 /* DEBUG */ /*dolog("builtin2");*/
1972 if (!(curstack->flags & SAVEDVAR)) {
1973 curstack->varkind = ARGVAR;
1974 curstack->varnum = 1;
1976 if (2 > arguments_num) {
1984 /* DEBUG */ /*dolog("builtin1");*/
1985 if (!(curstack->flags & SAVEDVAR)) {
1986 curstack->varkind = ARGVAR;
1987 curstack->varnum = 0;
1989 if (1 > arguments_num) {
1995 copy->flags |= SAVEDVAR;
1998 if (iptr->op1 != TYPE_VOID)
2002 case ICMD_MULTIANEWARRAY:
2005 if ((i + intreg_argnum) > arguments_num)
2006 arguments_num = i + intreg_argnum;
2009 /* check INT type here? Currently typecheck does this. */
2010 if (! (copy->flags & SAVEDVAR)) {
2011 copy->varkind = ARGVAR;
2012 copy->varnum = i + intreg_argnum;
2017 copy->flags |= SAVEDVAR;
2025 case ICMD_CLEAR_ARGREN:
2026 for (i = iptr->op1; i<maxlocals; i++)
2028 iptr->opc = opcode = ICMD_NOP;
2032 case ICMD_READONLY_ARG:
2033 case ICMD_READONLY_ARG+1:
2034 case ICMD_READONLY_ARG+2:
2035 case ICMD_READONLY_ARG+3:
2036 case ICMD_READONLY_ARG+4:
2039 if (curstack->varkind == LOCALVAR) {
2040 i = curstack->varnum;
2041 argren[iptr->op1] = i;
2044 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
2050 printf("ICMD %d at %d\n", iptr->opc, (int)(iptr-instr));
2051 panic("Missing ICMD code during stack analysis");
2056 /* DEBUG */ /*dolog("iptr++");*/
2058 } /* while instructions */
2059 bptr->outstack = curstack;
2060 bptr->outdepth = stackdepth;
2064 superblockend = true;
2066 } /* while blocks */
2067 } while (repeat && !deadcode);
2070 if (block_count > count_max_basic_blocks)
2071 count_max_basic_blocks = block_count;
2072 count_basic_blocks += block_count;
2073 if (instr_count > count_max_javainstr)
2074 count_max_javainstr = instr_count;
2075 count_javainstr += instr_count;
2076 if (stack_count > count_upper_bound_new_stack)
2077 count_upper_bound_new_stack = stack_count;
2078 if ((new - stack) > count_max_new_stack)
2079 count_max_new_stack = (new - stack);
2081 b_count = block_count;
2083 while (--b_count >= 0) {
2084 if (bptr->flags > BBREACHED) {
2085 if (bptr->indepth >= 10)
2086 count_block_stack[10]++;
2088 count_block_stack[bptr->indepth]++;
2091 count_block_size_distribution[len]++;
2093 count_block_size_distribution[10]++;
2095 count_block_size_distribution[11]++;
2097 count_block_size_distribution[12]++;
2099 count_block_size_distribution[13]++;
2101 count_block_size_distribution[14]++;
2103 count_block_size_distribution[15]++;
2105 count_block_size_distribution[16]++;
2107 count_block_size_distribution[17]++;
2113 count_analyse_iterations[0]++;
2114 else if (loops == 2)
2115 count_analyse_iterations[1]++;
2116 else if (loops == 3)
2117 count_analyse_iterations[2]++;
2118 else if (loops == 4)
2119 count_analyse_iterations[3]++;
2121 count_analyse_iterations[4]++;
2123 if (block_count <= 5)
2124 count_method_bb_distribution[0]++;
2125 else if (block_count <= 10)
2126 count_method_bb_distribution[1]++;
2127 else if (block_count <= 15)
2128 count_method_bb_distribution[2]++;
2129 else if (block_count <= 20)
2130 count_method_bb_distribution[3]++;
2131 else if (block_count <= 30)
2132 count_method_bb_distribution[4]++;
2133 else if (block_count <= 40)
2134 count_method_bb_distribution[5]++;
2135 else if (block_count <= 50)
2136 count_method_bb_distribution[6]++;
2137 else if (block_count <= 75)
2138 count_method_bb_distribution[7]++;
2140 count_method_bb_distribution[8]++;
2143 /* just return methodinfo* to signal everything was ok */
2149 /**********************************************************************/
2150 /* DEBUGGING HELPERS */
2151 /**********************************************************************/
2153 void icmd_print_stack(stackptr s)
2170 /* DEBUG */ /*printf("(%d,%d,%d,%d)",s->varkind,s->flags,s->regoff,s->varnum); fflush(stdout);*/
2171 if (s->flags & SAVEDVAR)
2172 switch (s->varkind) {
2174 if (s->flags & INMEMORY)
2175 printf((regs_ok) ? " M%02d" : " M??", s->regoff);
2176 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2177 printf((regs_ok) ? " F%02d" : " F??", s->regoff);
2179 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
2183 printf(" I%02d", s->varnum);
2186 printf(" L%02d", s->varnum);
2189 printf(" A%02d", s->varnum);
2192 printf(" !%02d", j);
2195 switch (s->varkind) {
2197 if (s->flags & INMEMORY)
2198 printf((regs_ok) ? " m%02d" : " m??", s->regoff);
2199 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2200 printf((regs_ok) ? " f%02d" : " f??", s->regoff);
2202 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
2206 printf(" i%02d", s->varnum);
2209 printf(" l%02d", s->varnum);
2212 printf(" a%02d", s->varnum);
2215 printf(" ?%02d", j);
2223 static void print_reg(stackptr s) {
2225 if (s->flags & SAVEDVAR)
2226 switch (s->varkind) {
2228 if (s->flags & INMEMORY)
2229 printf(" tm%02d", s->regoff);
2231 printf(" tr%02d", s->regoff);
2234 printf(" s %02d", s->varnum);
2237 printf(" l %02d", s->varnum);
2240 printf(" a %02d", s->varnum);
2243 printf(" ! %02d", s->varnum);
2246 switch (s->varkind) {
2248 if (s->flags & INMEMORY)
2249 printf(" Tm%02d", s->regoff);
2251 printf(" Tr%02d", s->regoff);
2254 printf(" S %02d", s->varnum);
2257 printf(" L %02d", s->varnum);
2260 printf(" A %02d", s->varnum);
2263 printf(" ? %02d", s->varnum);
2273 char *icmd_builtin_name(functionptr bptr)
2275 builtin_descriptor *bdesc = builtin_desc;
2276 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
2278 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
2282 static char *jit_type[] = {
2291 void show_icmd_method()
2298 utf_fprint_classname(stdout, class->name);
2300 utf_fprint(stdout, method->name);
2301 utf_fprint_classname(stdout, method->descriptor);
2302 printf ("\n\nMax locals: %d\n", (int) maxlocals);
2303 printf ("Max stack: %d\n", (int) maxstack);
2305 printf ("Line number table length: %d\n",method->linenumbercount);
2307 printf ("Exceptions (Number: %d):\n", exceptiontablelength);
2308 for (ex = extable; ex != NULL; ex = ex->down) {
2309 printf(" L%03d ... ", ex->start->debug_nr );
2310 printf("L%03d = ", ex->end->debug_nr);
2311 printf("L%03d\n", ex->handler->debug_nr);
2314 printf ("Local Table:\n");
2315 for (i = 0; i < maxlocals; i++) {
2316 printf(" %3d: ", i);
2317 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2318 if (locals[i][j].type >= 0) {
2319 printf(" (%s) ", jit_type[j]);
2320 if (locals[i][j].flags & INMEMORY)
2321 printf((regs_ok) ? "m%2d" : "m??", locals[i][j].regoff);
2322 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2323 printf((regs_ok) ? "f%02d" : "f??", locals[i][j].regoff);
2325 if (regs_ok) printf("%3s",regs[locals[i][j].regoff]); else printf("???");
2332 printf ("Interface Table:\n");
2333 for (i = 0; i < maxstack; i++) {
2334 if ((interfaces[i][0].type >= 0) || (interfaces[i][1].type >= 0) ||
2335 (interfaces[i][2].type >= 0) || (interfaces[i][3].type >= 0) ||
2336 (interfaces[i][4].type >= 0)) {
2337 printf(" %3d: ", i);
2338 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2339 if (interfaces[i][j].type >= 0) {
2340 printf(" (%s) ", jit_type[j]);
2341 if (interfaces[i][j].flags & SAVEDVAR) {
2342 if (interfaces[i][j].flags & INMEMORY)
2343 printf((regs_ok) ? "M%2d" : "M??", interfaces[i][j].regoff);
2344 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2345 printf((regs_ok) ? "F%02d" : "F??", interfaces[i][j].regoff);
2347 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2351 if (interfaces[i][j].flags & INMEMORY)
2352 printf((regs_ok) ? "m%2d" : "m??", interfaces[i][j].regoff);
2353 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2354 printf((regs_ok) ? "f%02d" : "f??", interfaces[i][j].regoff);
2356 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2365 if (showdisassemble) {
2366 #if defined(__I386__) || defined(__X86_64__)
2370 u1ptr = method->mcode + dseglen;
2371 for (i = 0; i < block[0].mpc; i++, u1ptr++) {
2372 a = disassinstr(u1ptr, i);
2380 s4ptr = (s4 *) (method->mcode + dseglen);
2381 for (i = 0; i < block[0].mpc; i += 4, s4ptr++) {
2382 disassinstr(s4ptr, i);
2388 for (bptr = block; bptr != NULL; bptr = bptr->next) {
2389 show_icmd_block(bptr);
2394 void show_icmd_block(basicblock *bptr)
2400 if (bptr->flags != BBDELETED) {
2401 deadcode = bptr->flags <= BBREACHED;
2404 for (j = method->maxstack; j > 0; j--)
2407 icmd_print_stack(bptr->instack);
2408 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2409 iptr = bptr->iinstr;
2411 for (i=0; i < bptr->icount; i++, iptr++) {
2414 for (j = method->maxstack; j > 0; j--)
2418 icmd_print_stack(iptr->dst);
2419 printf("] %4d ", i);
2420 /* DEBUG */ /*fflush(stdout);*/
2421 show_icmd(iptr,deadcode);
2425 if (showdisassemble && (!deadcode)) {
2426 #if defined(__I386__) || defined(__X86_64__)
2432 u1ptr = method->mcode + dseglen + i;
2434 if (bptr->next != NULL) {
2435 for (; i < bptr->next->mpc; i++, u1ptr++) {
2436 a = disassinstr(u1ptr, i);
2443 for (; u1ptr < (u1 *) (method->mcode + method->mcodelength); i++, u1ptr++) {
2444 a = disassinstr(u1ptr, i);
2455 s4ptr = (s4 *) (method->mcode + dseglen + i);
2457 if (bptr->next != NULL) {
2458 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2459 disassinstr(s4ptr, i);
2464 for (; s4ptr < (s4 *) (method->mcode + method->mcodelength); i += 4, s4ptr++) {
2465 disassinstr(s4ptr, i);
2475 void show_icmd(instruction *iptr,bool deadcode)
2481 printf("%s", icmd_names[iptr->opc]);
2483 switch ((int) iptr->opc) {
2484 case ICMD_IADDCONST:
2485 case ICMD_ISUBCONST:
2486 case ICMD_IMULCONST:
2489 case ICMD_IREM0X10001:
2490 case ICMD_IANDCONST:
2492 case ICMD_IXORCONST:
2493 case ICMD_ISHLCONST:
2494 case ICMD_ISHRCONST:
2495 case ICMD_IUSHRCONST:
2496 case ICMD_LSHLCONST:
2497 case ICMD_LSHRCONST:
2498 case ICMD_LUSHRCONST:
2500 case ICMD_ELSE_ICONST:
2501 case ICMD_IFEQ_ICONST:
2502 case ICMD_IFNE_ICONST:
2503 case ICMD_IFLT_ICONST:
2504 case ICMD_IFGE_ICONST:
2505 case ICMD_IFGT_ICONST:
2506 case ICMD_IFLE_ICONST:
2507 printf(" %d", iptr->val.i);
2510 case ICMD_LADDCONST:
2511 case ICMD_LSUBCONST:
2512 case ICMD_LMULCONST:
2515 case ICMD_LANDCONST:
2517 case ICMD_LXORCONST:
2519 #if defined(__I386__)
2520 printf(" %lld", iptr->val.l);
2522 printf(" %ld", iptr->val.l);
2527 printf(" %f", iptr->val.f);
2531 printf(" %f", iptr->val.d);
2535 printf(" %p", iptr->val.a);
2540 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2541 case ICMD_PUTSTATIC:
2542 case ICMD_GETSTATIC:
2544 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->class->name);
2546 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->name);
2548 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->descriptor);
2553 printf(" %d + %d", iptr->op1, iptr->val.i);
2588 printf(" %d", iptr->op1);
2594 ((classinfo *) iptr->val.a)->name);
2598 switch (iptr->op1) {
2626 case ICMD_ANEWARRAY:
2630 ((classinfo *) iptr->val.a)->name);
2634 case ICMD_MULTIANEWARRAY:
2637 printf(" %d ",iptr->op1);
2638 vft = (vftbl *)iptr->val.a;
2640 utf_fprint(stdout,vft->class->name);
2646 case ICMD_CHECKCAST:
2647 case ICMD_INSTANCEOF:
2649 classinfo *c = iptr->val.a;
2650 if (c->flags & ACC_INTERFACE)
2651 printf(" (INTERFACE) ");
2653 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2654 utf_fprint(stdout, c->name);
2661 printf(" %s", icmd_builtin_name((functionptr) iptr->val.a));
2664 case ICMD_INVOKEVIRTUAL:
2665 case ICMD_INVOKESPECIAL:
2666 case ICMD_INVOKESTATIC:
2667 case ICMD_INVOKEINTERFACE:
2670 ((methodinfo *) iptr->val.a)->class->name);
2673 ((methodinfo *) iptr->val.a)->name);
2682 if (deadcode || !iptr->target)
2683 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2685 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2694 if (deadcode || !iptr->target)
2695 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2697 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2703 case ICMD_IFNONNULL:
2704 case ICMD_IF_ICMPEQ:
2705 case ICMD_IF_ICMPNE:
2706 case ICMD_IF_ICMPLT:
2707 case ICMD_IF_ICMPGE:
2708 case ICMD_IF_ICMPGT:
2709 case ICMD_IF_ICMPLE:
2710 case ICMD_IF_LCMPEQ:
2711 case ICMD_IF_LCMPNE:
2712 case ICMD_IF_LCMPLT:
2713 case ICMD_IF_LCMPGE:
2714 case ICMD_IF_LCMPGT:
2715 case ICMD_IF_LCMPLE:
2716 case ICMD_IF_ACMPEQ:
2717 case ICMD_IF_ACMPNE:
2718 if (deadcode || !iptr->target)
2719 printf(" op1=%d", iptr->op1);
2721 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2724 case ICMD_TABLESWITCH:
2725 s4ptr = (s4*)iptr->val.a;
2727 if (deadcode || !iptr->target) {
2728 printf(" %d;", *s4ptr);
2731 tptr = (void **) iptr->target;
2732 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2736 s4ptr++; /* skip default */
2737 j = *s4ptr++; /* low */
2738 j = *s4ptr++ - j; /* high */
2740 if (deadcode || !*tptr)
2741 printf(" %d", *s4ptr++);
2743 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2750 case ICMD_LOOKUPSWITCH:
2751 s4ptr = (s4*)iptr->val.a;
2753 if (deadcode || !iptr->target) {
2754 printf(" %d;", *s4ptr);
2757 tptr = (void **) iptr->target;
2758 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2761 s4ptr++; /* default */
2762 j = *s4ptr++; /* count */
2765 if (deadcode || !*tptr) {
2766 s4ptr++; /* skip value */
2767 printf(" %d",*s4ptr++);
2770 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2776 printf(" Line number: %d, class:",iptr->line);
2777 utf_display(iptr->method->class->name);
2779 utf_display(iptr->method->name);
2784 * These are local overrides for various environment variables in Emacs.
2785 * Please do not remove this and leave it at the end of the file, where
2786 * Emacs will automagically detect them.
2787 * ---------------------------------------------------------------------
2790 * indent-tabs-mode: t