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 1232 2004-06-30 19:47:43Z twisti $
45 #include "statistics.h"
47 #include "jit/stack.h"
49 #include "toolbox/logging.h"
50 #include "toolbox/memory.h"
53 /* from codegen.inc */
56 /**********************************************************************/
57 /* Macros used internally by analyse_stack */
58 /**********************************************************************/
61 #define COUNT(cnt) cnt++
66 /* convenient abbreviations */
67 #define CURKIND curstack->varkind
68 #define CURTYPE curstack->type
70 /*--------------------------------------------------*/
71 /* SIGNALING ERRORS */
72 /*--------------------------------------------------*/
74 #define TYPEPANIC {panic("Stack type mismatch");}
77 /*--------------------------------------------------*/
78 /* STACK UNDERFLOW/OVERFLOW CHECKS */
79 /*--------------------------------------------------*/
81 /* underflow checks */
83 #define REQUIRE(num) \
85 if (stackdepth < (num)) { \
86 sprintf(msg, "(class: "); \
87 utf_sprint(msg + strlen(msg), m->class->name); \
88 sprintf(msg + strlen(msg), ", method: "); \
89 utf_sprint(msg + strlen(msg), m->name); \
90 sprintf(msg + strlen(msg), ", signature: "); \
91 utf_sprint(msg + strlen(msg), m->descriptor); \
92 sprintf(msg + strlen(msg), ") Unable to pop operand off an empty stack"); \
94 new_exception_message(string_java_lang_VerifyError, msg); \
99 #define REQUIRE_1 REQUIRE(1)
100 #define REQUIRE_2 REQUIRE(2)
101 #define REQUIRE_3 REQUIRE(3)
102 #define REQUIRE_4 REQUIRE(4)
106 /* We allow ACONST instructions inserted as arguments to builtin
107 * functions to exceed the maximum stack depth. Maybe we should check
108 * against maximum stack depth only at block boundaries?
111 #define CHECKOVERFLOW \
113 if (stackdepth > m->maxstack) { \
114 if (iptr[0].opc != ICMD_ACONST \
115 || iptr[0].op1 == 0) { \
116 sprintf(msg, "(class: "); \
117 utf_sprint_classname(msg + strlen(msg), m->class->name); \
118 sprintf(msg + strlen(msg), ", method: "); \
119 utf_sprint(msg + strlen(msg), m->name); \
120 sprintf(msg + strlen(msg), ", signature: "); \
121 utf_sprint(msg + strlen(msg), m->descriptor); \
122 sprintf(msg + strlen(msg), ") Stack size too large"); \
124 new_exception_message(string_java_lang_VerifyError, msg); \
131 /*--------------------------------------------------*/
132 /* ALLOCATING STACK SLOTS */
133 /*--------------------------------------------------*/
135 #define NEWSTACK(s,v,n) {new->prev=curstack;new->type=s;new->flags=0; \
136 new->varkind=v;new->varnum=n;curstack=new;new++;}
137 #define NEWSTACKn(s,n) NEWSTACK(s,UNDEFVAR,n)
138 #define NEWSTACK0(s) NEWSTACK(s,UNDEFVAR,0)
140 /* allocate the input stack for an exception handler */
141 #define NEWXSTACK {NEWSTACK(TYPE_ADR,STACKVAR,0);curstack=0;}
144 /*--------------------------------------------------*/
145 /* STACK MANIPULATION */
146 /*--------------------------------------------------*/
148 /* resetting to an empty operand stack */
149 #define STACKRESET {curstack=0;stackdepth=0;}
151 /* set the output stack of the current instruction */
152 #define SETDST {iptr->dst=curstack;}
154 /* The following macros do NOT check stackdepth, set stackdepth or iptr->dst */
155 #define POP(s) {if(s!=curstack->type){TYPEPANIC;} \
156 if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR;\
157 curstack=curstack->prev;}
158 #define POPANY {if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR; \
159 curstack=curstack->prev;}
160 #define COPY(s,d) {(d)->flags=0;(d)->type=(s)->type;\
161 (d)->varkind=(s)->varkind;(d)->varnum=(s)->varnum;}
164 /*--------------------------------------------------*/
165 /* STACK OPERATIONS MODELING */
166 /*--------------------------------------------------*/
168 /* The following macros are used to model the stack manipulations of
169 * different kinds of instructions.
171 * These macros check the input stackdepth and they set the output
172 * stackdepth and the output stack of the instruction (iptr->dst).
174 * These macros do *not* check for stack overflows!
177 #define PUSHCONST(s){NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
178 #define LOAD(s,v,n) {NEWSTACK(s,v,n);SETDST;stackdepth++;}
179 #define STORE(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
180 #define OP1_0(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
181 #define OP1_0ANY {REQUIRE_1;POPANY;SETDST;stackdepth--;}
182 #define OP0_1(s) {NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
183 #define OP1_1(s,d) {REQUIRE_1;POP(s);NEWSTACKn(d,stackdepth-1);SETDST;}
184 #define OP2_0(s) {REQUIRE_2;POP(s);POP(s);SETDST;stackdepth-=2;}
185 #define OPTT2_0(t,b){REQUIRE_2;POP(t);POP(b);SETDST;stackdepth-=2;}
186 #define OP2_1(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);SETDST;stackdepth--;}
187 #define OP2IAT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(TYPE_ADR);NEWSTACKn(s,stackdepth-2);\
188 SETDST;stackdepth--;}
189 #define OP2IT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(s);NEWSTACKn(s,stackdepth-2);\
190 SETDST;stackdepth--;}
191 #define OPTT2_1(s,d){REQUIRE_2;POP(s);POP(s);NEWSTACKn(d,stackdepth-2);SETDST;stackdepth--;}
192 #define OP2_2(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);\
193 NEWSTACKn(s,stackdepth-1);SETDST;}
194 #define OP3TIA_0(s) {REQUIRE_3;POP(s);POP(TYPE_INT);POP(TYPE_ADR);SETDST;stackdepth-=3;}
195 #define OP3_0(s) {REQUIRE_3;POP(s);POP(s);POP(s);SETDST;stackdepth-=3;}
196 #define POPMANY(i) {REQUIRE(i);stackdepth-=i;while(--i>=0){POPANY;}SETDST;}
197 #define DUP {REQUIRE_1;NEWSTACK(CURTYPE,CURKIND,curstack->varnum);SETDST; \
199 #define SWAP {REQUIRE_2;COPY(curstack,new);POPANY;COPY(curstack,new+1);POPANY;\
200 new[0].prev=curstack;new[1].prev=new;\
201 curstack=new+1;new+=2;SETDST;}
202 #define DUP_X1 {REQUIRE_2;COPY(curstack,new);COPY(curstack,new+2);POPANY;\
203 COPY(curstack,new+1);POPANY;new[0].prev=curstack;\
204 new[1].prev=new;new[2].prev=new+1;\
205 curstack=new+2;new+=3;SETDST;stackdepth++;}
206 #define DUP2_X1 {REQUIRE_3;COPY(curstack,new+1);COPY(curstack,new+4);POPANY;\
207 COPY(curstack,new);COPY(curstack,new+3);POPANY;\
208 COPY(curstack,new+2);POPANY;new[0].prev=curstack;\
209 new[1].prev=new;new[2].prev=new+1;\
210 new[3].prev=new+2;new[4].prev=new+3;\
211 curstack=new+4;new+=5;SETDST;stackdepth+=2;}
212 #define DUP_X2 {REQUIRE_3;COPY(curstack,new);COPY(curstack,new+3);POPANY;\
213 COPY(curstack,new+2);POPANY;COPY(curstack,new+1);POPANY;\
214 new[0].prev=curstack;new[1].prev=new;\
215 new[2].prev=new+1;new[3].prev=new+2;\
216 curstack=new+3;new+=4;SETDST;stackdepth++;}
217 #define DUP2_X2 {REQUIRE_4;COPY(curstack,new+1);COPY(curstack,new+5);POPANY;\
218 COPY(curstack,new);COPY(curstack,new+4);POPANY;\
219 COPY(curstack,new+3);POPANY;COPY(curstack,new+2);POPANY;\
220 new[0].prev=curstack;new[1].prev=new;\
221 new[2].prev=new+1;new[3].prev=new+2;\
222 new[4].prev=new+3;new[5].prev=new+4;\
223 curstack=new+5;new+=6;SETDST;stackdepth+=2;}
226 /*--------------------------------------------------*/
227 /* MACROS FOR HANDLING BASIC BLOCKS */
228 /*--------------------------------------------------*/
230 /* COPYCURSTACK makes a copy of the current operand stack (curstack)
231 * and returns it in the variable copy.
233 * This macro is used to propagate the operand stack from one basic
234 * block to another. The destination block receives the copy as its
237 #define COPYCURSTACK(copy) {\
250 copy->varkind=STACKVAR;\
261 /* BBEND is called at the end of each basic block (after the last
262 * instruction of the block has been processed).
265 #define BBEND(s,i){ \
266 i = stackdepth - 1; \
269 if ((copy->varkind == STACKVAR) && (copy->varnum > i)) \
270 copy->varkind = TEMPVAR; \
272 copy->varkind = STACKVAR; \
275 m->registerdata->interfaces[i][copy->type].type = copy->type; \
276 m->registerdata->interfaces[i][copy->type].flags |= copy->flags; \
277 i--; copy = copy->prev; \
279 i = bptr->indepth - 1; \
280 copy = bptr->instack; \
282 m->registerdata->interfaces[i][copy->type].type = copy->type; \
283 if (copy->varkind == STACKVAR) { \
284 if (copy->flags & SAVEDVAR) \
285 m->registerdata->interfaces[i][copy->type].flags |= SAVEDVAR; \
287 i--; copy = copy->prev; \
292 /* MARKREACHED marks the destination block <b> as reached. If this
293 * block has been reached before we check if stack depth and types
294 * match. Otherwise the destination block receives a copy of the
295 * current stack as its input stack.
297 * b...destination block
300 #define MARKREACHED(b,c) { \
302 {COPYCURSTACK(c);b->flags=0;b->instack=c;b->indepth=stackdepth;} \
303 else {stackptr s=curstack;stackptr t=b->instack; \
304 if(b->indepth!=stackdepth) \
305 {show_icmd_method(m);panic("Stack depth mismatch");} \
306 while(s){if (s->type!=t->type) \
308 s=s->prev;t=t->prev; \
314 /**********************************************************************/
316 /**********************************************************************/
318 /* analyse_stack uses the intermediate code created by parse.c to
319 * build a model of the JVM operand stack for the current method.
321 * The following checks are performed:
322 * - check for operand stack underflow (before each instruction)
323 * - check for operand stack overflow (after[1] each instruction)
324 * - check for matching stack depth at merging points
325 * - check for matching basic types[2] at merging points
326 * - check basic types for instruction input (except for BUILTIN*
327 * opcodes, INVOKE* opcodes and MULTIANEWARRAY)
329 * [1]) Checking this after the instruction should be ok. parse.c
330 * counts the number of required stack slots in such a way that it is
331 * only vital that we don't exceed `maxstack` at basic block
334 * [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
335 * DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
336 * types are not discerned.
339 methodinfo *analyse_stack(methodinfo *m)
347 int opcode, i, len, loops;
348 int superblockend, repeat, deadcode;
355 char msg[MAXLOGTEXT]; /* maybe we get an exception */
357 argren = DMNEW(int, m->maxlocals);
358 /*int *argren = (int *)alloca(m->maxlocals * sizeof(int));*/ /* table for argument renaming */
359 for (i = 0; i < m->maxlocals; i++)
362 m->registerdata->arguments_num = 0;
365 m->basicblocks[0].flags = BBREACHED;
366 m->basicblocks[0].instack = 0;
367 m->basicblocks[0].indepth = 0;
369 for (i = 0; i < m->exceptiontablelength; i++) {
370 bptr = &m->basicblocks[m->basicblockindex[m->exceptiontable[i].handlerpc]];
371 bptr->flags = BBREACHED;
372 bptr->type = BBTYPE_EXH;
375 bptr->pre_count = 10000;
380 #ifdef CONDITIONAL_LOADCONST
381 b_count = m->basicblockcount;
382 bptr = m->basicblocks;
383 while (--b_count >= 0) {
384 if (bptr->icount != 0) {
385 iptr = bptr->iinstr + bptr->icount - 1;
418 m->basicblocks[m->basicblockindex[iptr->op1]].pre_count++;
421 case ICMD_TABLESWITCH:
423 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
424 i = *s4ptr++; /* low */
425 i = *s4ptr++ - i + 1; /* high */
427 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
431 case ICMD_LOOKUPSWITCH:
433 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
434 i = *s4ptr++; /* count */
436 m->basicblocks[m->basicblockindex[s4ptr[1]]].pre_count++;
452 b_count = m->basicblockcount;
453 bptr = m->basicblocks;
454 superblockend = true;
458 while (--b_count >= 0) {
459 if (bptr->flags == BBDELETED) {
462 else if (superblockend && (bptr->flags < BBREACHED))
464 else if (bptr->flags <= BBREACHED) {
466 stackdepth = bptr->indepth;
467 else if (bptr->flags < BBREACHED) {
469 bptr->instack = copy;
470 bptr->indepth = stackdepth;
472 else if (bptr->indepth != stackdepth) {
474 panic("Stack depth mismatch");
477 curstack = bptr->instack;
479 superblockend = false;
480 bptr->flags = BBFINISHED;
483 b_index = bptr - m->basicblocks;
488 /* dolog("p: %04d op: %s stack: %p", iptr - instr, icmd_names[opcode], curstack); */
490 #ifdef USEBUILTINTABLE
493 stdopdescriptor *breplace;
494 breplace = find_builtin(opcode);
496 if (breplace && opcode == breplace->opcode) {
497 iptr[0].opc = breplace->icmd;
498 iptr[0].op1 = breplace->type_d;
499 iptr[0].val.a = breplace->builtin;
500 m->isleafmethod = false;
501 switch (breplace->icmd) {
509 builtin_descriptor *breplace;
510 breplace = find_builtin(opcode);
512 if (breplace && opcode == breplace->opcode) {
513 iptr[0].opc = breplace->icmd;
514 iptr[0].op1 = breplace->type_d;
515 iptr[0].val.a = breplace->builtin;
516 m->isleafmethod = false;
517 switch (breplace->icmd) {
532 case ICMD_CHECKASIZE:
533 case ICMD_CHECKEXCEPTION:
535 case ICMD_IFEQ_ICONST:
536 case ICMD_IFNE_ICONST:
537 case ICMD_IFLT_ICONST:
538 case ICMD_IFGE_ICONST:
539 case ICMD_IFGT_ICONST:
540 case ICMD_IFLE_ICONST:
541 case ICMD_ELSE_ICONST:
546 m->registerdata->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
548 COUNT(count_pcmd_return);
550 superblockend = true;
553 /* pop 0 push 1 const */
556 COUNT(count_pcmd_load);
558 switch (iptr[1].opc) {
560 iptr[0].opc = ICMD_IADDCONST;
562 iptr[1].opc = ICMD_NOP;
563 OP1_1(TYPE_INT,TYPE_INT);
564 COUNT(count_pcmd_op);
567 iptr[0].opc = ICMD_ISUBCONST;
568 goto icmd_iconst_tail;
570 iptr[0].opc = ICMD_IMULCONST;
571 goto icmd_iconst_tail;
573 if (iptr[0].val.i == 0x00000002)
575 else if (iptr[0].val.i == 0x00000004)
577 else if (iptr[0].val.i == 0x00000008)
579 else if (iptr[0].val.i == 0x00000010)
581 else if (iptr[0].val.i == 0x00000020)
583 else if (iptr[0].val.i == 0x00000040)
585 else if (iptr[0].val.i == 0x00000080)
587 else if (iptr[0].val.i == 0x00000100)
589 else if (iptr[0].val.i == 0x00000200)
591 else if (iptr[0].val.i == 0x00000400)
593 else if (iptr[0].val.i == 0x00000800)
595 else if (iptr[0].val.i == 0x00001000)
597 else if (iptr[0].val.i == 0x00002000)
599 else if (iptr[0].val.i == 0x00004000)
601 else if (iptr[0].val.i == 0x00008000)
603 else if (iptr[0].val.i == 0x00010000)
605 else if (iptr[0].val.i == 0x00020000)
607 else if (iptr[0].val.i == 0x00040000)
609 else if (iptr[0].val.i == 0x00080000)
611 else if (iptr[0].val.i == 0x00100000)
613 else if (iptr[0].val.i == 0x00200000)
615 else if (iptr[0].val.i == 0x00400000)
617 else if (iptr[0].val.i == 0x00800000)
619 else if (iptr[0].val.i == 0x01000000)
621 else if (iptr[0].val.i == 0x02000000)
623 else if (iptr[0].val.i == 0x04000000)
625 else if (iptr[0].val.i == 0x08000000)
627 else if (iptr[0].val.i == 0x10000000)
629 else if (iptr[0].val.i == 0x20000000)
631 else if (iptr[0].val.i == 0x40000000)
633 else if (iptr[0].val.i == 0x80000000)
639 iptr[0].opc = ICMD_IDIVPOW2;
640 goto icmd_iconst_tail;
642 #if !defined(NO_DIV_OPT)
643 if (iptr[0].val.i == 0x10001) {
644 iptr[0].opc = ICMD_IREM0X10001;
645 goto icmd_iconst_tail;
648 if ((iptr[0].val.i == 0x00000002) ||
649 (iptr[0].val.i == 0x00000004) ||
650 (iptr[0].val.i == 0x00000008) ||
651 (iptr[0].val.i == 0x00000010) ||
652 (iptr[0].val.i == 0x00000020) ||
653 (iptr[0].val.i == 0x00000040) ||
654 (iptr[0].val.i == 0x00000080) ||
655 (iptr[0].val.i == 0x00000100) ||
656 (iptr[0].val.i == 0x00000200) ||
657 (iptr[0].val.i == 0x00000400) ||
658 (iptr[0].val.i == 0x00000800) ||
659 (iptr[0].val.i == 0x00001000) ||
660 (iptr[0].val.i == 0x00002000) ||
661 (iptr[0].val.i == 0x00004000) ||
662 (iptr[0].val.i == 0x00008000) ||
663 (iptr[0].val.i == 0x00010000) ||
664 (iptr[0].val.i == 0x00020000) ||
665 (iptr[0].val.i == 0x00040000) ||
666 (iptr[0].val.i == 0x00080000) ||
667 (iptr[0].val.i == 0x00100000) ||
668 (iptr[0].val.i == 0x00200000) ||
669 (iptr[0].val.i == 0x00400000) ||
670 (iptr[0].val.i == 0x00800000) ||
671 (iptr[0].val.i == 0x01000000) ||
672 (iptr[0].val.i == 0x02000000) ||
673 (iptr[0].val.i == 0x04000000) ||
674 (iptr[0].val.i == 0x08000000) ||
675 (iptr[0].val.i == 0x10000000) ||
676 (iptr[0].val.i == 0x20000000) ||
677 (iptr[0].val.i == 0x40000000) ||
678 (iptr[0].val.i == 0x80000000)) {
679 iptr[0].opc = ICMD_IREMPOW2;
681 #if defined(__I386__)
682 method_uses_ecx = true;
684 goto icmd_iconst_tail;
689 iptr[0].opc = ICMD_IANDCONST;
690 goto icmd_iconst_tail;
692 iptr[0].opc = ICMD_IORCONST;
693 goto icmd_iconst_tail;
695 iptr[0].opc = ICMD_IXORCONST;
696 goto icmd_iconst_tail;
698 iptr[0].opc = ICMD_ISHLCONST;
699 goto icmd_iconst_tail;
701 iptr[0].opc = ICMD_ISHRCONST;
702 goto icmd_iconst_tail;
704 iptr[0].opc = ICMD_IUSHRCONST;
705 goto icmd_iconst_tail;
706 #if SUPPORT_LONG_SHIFT
708 iptr[0].opc = ICMD_LSHLCONST;
709 #if defined(__I386__)
710 method_uses_ecx = true;
712 goto icmd_lconst_tail;
714 iptr[0].opc = ICMD_LSHRCONST;
715 #if defined(__I386__)
716 method_uses_ecx = true;
718 goto icmd_lconst_tail;
720 iptr[0].opc = ICMD_LUSHRCONST;
721 #if defined(__I386__)
722 method_uses_ecx = true;
724 goto icmd_lconst_tail;
727 iptr[0].opc = ICMD_IFEQ;
729 iptr[0].op1 = iptr[1].op1;
732 /* iptr[1].opc = ICMD_NOP; */
734 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
736 iptr[0].target = (void *) tbptr;
738 MARKREACHED(tbptr, copy);
739 COUNT(count_pcmd_bra);
742 iptr[0].opc = ICMD_IFLT;
743 goto icmd_if_icmp_tail;
745 iptr[0].opc = ICMD_IFLE;
746 goto icmd_if_icmp_tail;
748 iptr[0].opc = ICMD_IFNE;
749 goto icmd_if_icmp_tail;
751 iptr[0].opc = ICMD_IFGT;
752 goto icmd_if_icmp_tail;
754 iptr[0].opc = ICMD_IFGE;
755 goto icmd_if_icmp_tail;
758 iptr[0].opc = ICMD_IASTORECONST;
760 iptr[1].opc = ICMD_NOP;
761 OPTT2_0(TYPE_INT, TYPE_ADR);
762 COUNT(count_pcmd_op);
765 iptr[0].opc = ICMD_BASTORECONST;
766 goto icmd_astore_tail;
768 iptr[0].opc = ICMD_CASTORECONST;
769 goto icmd_astore_tail;
771 iptr[0].opc = ICMD_SASTORECONST;
772 goto icmd_astore_tail;
783 COUNT(count_pcmd_load);
785 switch (iptr[1].opc) {
788 iptr[0].opc = ICMD_LADDCONST;
790 iptr[1].opc = ICMD_NOP;
791 OP1_1(TYPE_LNG,TYPE_LNG);
792 COUNT(count_pcmd_op);
795 iptr[0].opc = ICMD_LSUBCONST;
796 goto icmd_lconst_tail;
800 iptr[0].opc = ICMD_LMULCONST;
801 #if defined(__I386__)
802 method_uses_ecx = true;
803 method_uses_edx = true;
805 goto icmd_lconst_tail;
809 if (iptr[0].val.l == 0x00000002)
811 else if (iptr[0].val.l == 0x00000004)
813 else if (iptr[0].val.l == 0x00000008)
815 else if (iptr[0].val.l == 0x00000010)
817 else if (iptr[0].val.l == 0x00000020)
819 else if (iptr[0].val.l == 0x00000040)
821 else if (iptr[0].val.l == 0x00000080)
823 else if (iptr[0].val.l == 0x00000100)
825 else if (iptr[0].val.l == 0x00000200)
827 else if (iptr[0].val.l == 0x00000400)
829 else if (iptr[0].val.l == 0x00000800)
831 else if (iptr[0].val.l == 0x00001000)
833 else if (iptr[0].val.l == 0x00002000)
835 else if (iptr[0].val.l == 0x00004000)
837 else if (iptr[0].val.l == 0x00008000)
839 else if (iptr[0].val.l == 0x00010000)
841 else if (iptr[0].val.l == 0x00020000)
843 else if (iptr[0].val.l == 0x00040000)
845 else if (iptr[0].val.l == 0x00080000)
847 else if (iptr[0].val.l == 0x00100000)
849 else if (iptr[0].val.l == 0x00200000)
851 else if (iptr[0].val.l == 0x00400000)
853 else if (iptr[0].val.l == 0x00800000)
855 else if (iptr[0].val.l == 0x01000000)
857 else if (iptr[0].val.l == 0x02000000)
859 else if (iptr[0].val.l == 0x04000000)
861 else if (iptr[0].val.l == 0x08000000)
863 else if (iptr[0].val.l == 0x10000000)
865 else if (iptr[0].val.l == 0x20000000)
867 else if (iptr[0].val.l == 0x40000000)
869 else if (iptr[0].val.l == 0x80000000)
875 iptr[0].opc = ICMD_LDIVPOW2;
876 #if defined(__I386__)
877 method_uses_ecx = true;
879 goto icmd_lconst_tail;
881 #if !defined(NO_DIV_OPT)
882 if (iptr[0].val.l == 0x10001) {
883 iptr[0].opc = ICMD_LREM0X10001;
884 goto icmd_lconst_tail;
887 if ((iptr[0].val.l == 0x00000002) ||
888 (iptr[0].val.l == 0x00000004) ||
889 (iptr[0].val.l == 0x00000008) ||
890 (iptr[0].val.l == 0x00000010) ||
891 (iptr[0].val.l == 0x00000020) ||
892 (iptr[0].val.l == 0x00000040) ||
893 (iptr[0].val.l == 0x00000080) ||
894 (iptr[0].val.l == 0x00000100) ||
895 (iptr[0].val.l == 0x00000200) ||
896 (iptr[0].val.l == 0x00000400) ||
897 (iptr[0].val.l == 0x00000800) ||
898 (iptr[0].val.l == 0x00001000) ||
899 (iptr[0].val.l == 0x00002000) ||
900 (iptr[0].val.l == 0x00004000) ||
901 (iptr[0].val.l == 0x00008000) ||
902 (iptr[0].val.l == 0x00010000) ||
903 (iptr[0].val.l == 0x00020000) ||
904 (iptr[0].val.l == 0x00040000) ||
905 (iptr[0].val.l == 0x00080000) ||
906 (iptr[0].val.l == 0x00100000) ||
907 (iptr[0].val.l == 0x00200000) ||
908 (iptr[0].val.l == 0x00400000) ||
909 (iptr[0].val.l == 0x00800000) ||
910 (iptr[0].val.l == 0x01000000) ||
911 (iptr[0].val.l == 0x02000000) ||
912 (iptr[0].val.l == 0x04000000) ||
913 (iptr[0].val.l == 0x08000000) ||
914 (iptr[0].val.l == 0x10000000) ||
915 (iptr[0].val.l == 0x20000000) ||
916 (iptr[0].val.l == 0x40000000) ||
917 (iptr[0].val.l == 0x80000000)) {
918 iptr[0].opc = ICMD_LREMPOW2;
920 #if defined(__I386__)
921 method_uses_ecx = true;
923 goto icmd_lconst_tail;
930 iptr[0].opc = ICMD_LANDCONST;
931 goto icmd_lconst_tail;
933 iptr[0].opc = ICMD_LORCONST;
934 goto icmd_lconst_tail;
936 iptr[0].opc = ICMD_LXORCONST;
937 goto icmd_lconst_tail;
939 #if !defined(NOLONG_CONDITIONAL)
941 if ((len > 1) && (iptr[2].val.i == 0)) {
942 switch (iptr[2].opc) {
944 iptr[0].opc = ICMD_IF_LEQ;
945 #if defined(__I386__)
946 method_uses_ecx = true;
948 icmd_lconst_lcmp_tail:
949 iptr[0].op1 = iptr[2].op1;
952 /* iptr[1].opc = ICMD_NOP;
953 iptr[2].opc = ICMD_NOP; */
955 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
957 iptr[0].target = (void *) tbptr;
959 MARKREACHED(tbptr, copy);
960 COUNT(count_pcmd_bra);
961 COUNT(count_pcmd_op);
964 iptr[0].opc = ICMD_IF_LNE;
965 #if defined(__I386__)
966 method_uses_ecx = true;
968 goto icmd_lconst_lcmp_tail;
970 iptr[0].opc = ICMD_IF_LLT;
971 goto icmd_lconst_lcmp_tail;
973 iptr[0].opc = ICMD_IF_LGT;
974 goto icmd_lconst_lcmp_tail;
976 iptr[0].opc = ICMD_IF_LLE;
977 goto icmd_lconst_lcmp_tail;
979 iptr[0].opc = ICMD_IF_LGE;
980 goto icmd_lconst_lcmp_tail;
983 } /* switch (iptr[2].opc) */
984 } /* if (iptr[2].val.i == 0) */
991 iptr[0].opc = ICMD_LASTORECONST;
992 iptr[1].opc = ICMD_NOP;
993 OPTT2_0(TYPE_INT, TYPE_ADR);
994 COUNT(count_pcmd_op);
1002 PUSHCONST(TYPE_LNG);
1006 COUNT(count_pcmd_load);
1007 PUSHCONST(TYPE_FLT);
1011 COUNT(count_pcmd_load);
1012 PUSHCONST(TYPE_DBL);
1016 COUNT(count_pcmd_load);
1017 if (len > 0 && iptr->val.a == 0) {
1018 if (iptr[1].opc == ICMD_BUILTIN3 &&
1019 iptr[1].val.a == BUILTIN_aastore) {
1020 iptr[0].opc = ICMD_AASTORECONST;
1021 iptr[1].opc = ICMD_NOP;
1022 OPTT2_0(TYPE_INT, TYPE_ADR);
1023 COUNT(count_pcmd_op);
1026 PUSHCONST(TYPE_ADR);
1030 PUSHCONST(TYPE_ADR);
1034 /* pop 0 push 1 load */
1041 COUNT(count_load_instruction);
1042 i = opcode-ICMD_ILOAD;
1043 iptr->op1 = argren[iptr->op1];
1044 m->registerdata->locals[iptr->op1][i].type = i;
1045 LOAD(i, LOCALVAR, iptr->op1);
1051 #if defined(__I386__)
1052 method_uses_ecx = true;
1053 method_uses_edx = true;
1059 COUNT(count_check_null);
1060 COUNT(count_check_bound);
1061 COUNT(count_pcmd_mem);
1062 OP2IAT_1(opcode-ICMD_IALOAD);
1063 #if defined(__I386__)
1064 method_uses_ecx = true;
1071 COUNT(count_check_null);
1072 COUNT(count_check_bound);
1073 COUNT(count_pcmd_mem);
1075 #if defined(__I386__)
1076 method_uses_ecx = true;
1080 /* pop 0 push 0 iinc */
1086 count_store_depth[10]++;
1088 count_store_depth[i]++;
1093 if ((copy->varkind == LOCALVAR) &&
1094 (copy->varnum == iptr->op1)) {
1095 copy->varkind = TEMPVAR;
1104 /* pop 1 push 0 store */
1114 i = opcode - ICMD_ISTORE;
1115 m->registerdata->locals[iptr->op1][i].type = i;
1120 count_store_length[20]++;
1122 count_store_length[i]++;
1125 count_store_depth[10]++;
1127 count_store_depth[i]++;
1129 copy = curstack->prev;
1132 if ((copy->varkind == LOCALVAR) &&
1133 (copy->varnum == iptr->op1)) {
1134 copy->varkind = TEMPVAR;
1140 if ((new - curstack) == 1) {
1141 curstack->varkind = LOCALVAR;
1142 curstack->varnum = iptr->op1;
1144 STORE(opcode-ICMD_ISTORE);
1152 #if defined(__I386__)
1153 method_uses_ecx = true;
1154 method_uses_edx = true;
1158 COUNT(count_check_null);
1159 COUNT(count_check_bound);
1160 COUNT(count_pcmd_mem);
1161 OP3TIA_0(opcode-ICMD_IASTORE);
1167 COUNT(count_check_null);
1168 COUNT(count_check_bound);
1169 COUNT(count_pcmd_mem);
1171 #if defined(__I386__)
1172 method_uses_ecx = true;
1173 method_uses_edx = true;
1180 #ifdef TYPECHECK_STACK_COMPCAT
1183 if (IS_2_WORD_TYPE(curstack->type))
1184 panic("Illegal instruction: POP on category 2 type");
1195 COUNT(count_pcmd_return);
1196 OP1_0(opcode-ICMD_IRETURN);
1197 superblockend = true;
1201 COUNT(count_check_null);
1205 superblockend = true;
1208 case ICMD_PUTSTATIC:
1209 COUNT(count_pcmd_mem);
1211 #if defined(__I386__)
1212 method_uses_ecx = true;
1216 /* pop 1 push 0 branch */
1219 case ICMD_IFNONNULL:
1220 COUNT(count_pcmd_bra);
1222 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1224 iptr[0].target = (void *) tbptr;
1226 MARKREACHED(tbptr, copy);
1235 COUNT(count_pcmd_bra);
1236 #ifdef CONDITIONAL_LOADCONST
1238 tbptr = m->basicblocks + b_index;
1239 if ((b_count >= 3) &&
1240 ((b_index + 2) == m->basicblockindex[iptr[0].op1]) &&
1241 (tbptr[1].pre_count == 1) &&
1242 (iptr[1].opc == ICMD_ICONST) &&
1243 (iptr[2].opc == ICMD_GOTO) &&
1244 ((b_index + 3) == m->basicblockindex[iptr[2].op1]) &&
1245 (tbptr[2].pre_count == 1) &&
1246 (iptr[3].opc == ICMD_ICONST)) {
1247 OP1_1(TYPE_INT, TYPE_INT);
1248 switch (iptr[0].opc) {
1250 iptr[0].opc = ICMD_IFNE_ICONST;
1253 iptr[0].opc = ICMD_IFEQ_ICONST;
1256 iptr[0].opc = ICMD_IFGE_ICONST;
1259 iptr[0].opc = ICMD_IFLT_ICONST;
1262 iptr[0].opc = ICMD_IFLE_ICONST;
1265 iptr[0].opc = ICMD_IFGT_ICONST;
1268 iptr[0].val.i = iptr[1].val.i;
1269 iptr[1].opc = ICMD_ELSE_ICONST;
1270 iptr[1].val.i = iptr[3].val.i;
1271 iptr[2].opc = ICMD_NOP;
1272 iptr[3].opc = ICMD_NOP;
1273 tbptr[1].flags = BBDELETED;
1274 tbptr[2].flags = BBDELETED;
1275 tbptr[1].icount = 0;
1276 tbptr[2].icount = 0;
1277 if (tbptr[3].pre_count == 2) {
1278 len += tbptr[3].icount + 3;
1279 bptr->icount += tbptr[3].icount + 3;
1280 tbptr[3].flags = BBDELETED;
1281 tbptr[3].icount = 0;
1294 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1296 iptr[0].target = (void *) tbptr;
1298 MARKREACHED(tbptr, copy);
1301 /* pop 0 push 0 branch */
1304 COUNT(count_pcmd_bra);
1305 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1307 iptr[0].target = (void *) tbptr;
1309 MARKREACHED(tbptr, copy);
1311 superblockend = true;
1314 /* pop 1 push 0 table branch */
1316 case ICMD_TABLESWITCH:
1317 COUNT(count_pcmd_table);
1319 s4ptr = iptr->val.a;
1320 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1321 MARKREACHED(tbptr, copy);
1322 i = *s4ptr++; /* low */
1323 i = *s4ptr++ - i + 1; /* high */
1325 tptr = DMNEW(void*, i+1);
1326 iptr->target = (void *) tptr;
1328 tptr[0] = (void *) tbptr;
1332 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1334 tptr[0] = (void *) tbptr;
1337 MARKREACHED(tbptr, copy);
1340 superblockend = true;
1341 #if defined(__I386__)
1342 method_uses_ecx = true;
1346 /* pop 1 push 0 table branch */
1348 case ICMD_LOOKUPSWITCH:
1349 COUNT(count_pcmd_table);
1351 s4ptr = iptr->val.a;
1352 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1353 MARKREACHED(tbptr, copy);
1354 i = *s4ptr++; /* count */
1356 tptr = DMNEW(void*, i+1);
1357 iptr->target = (void *) tptr;
1359 tptr[0] = (void *) tbptr;
1363 tbptr = m->basicblocks + m->basicblockindex[s4ptr[1]];
1365 tptr[0] = (void *) tbptr;
1368 MARKREACHED(tbptr, copy);
1372 superblockend = true;
1375 case ICMD_NULLCHECKPOP:
1376 case ICMD_MONITORENTER:
1377 COUNT(count_check_null);
1378 case ICMD_MONITOREXIT:
1382 /* pop 2 push 0 branch */
1384 case ICMD_IF_ICMPEQ:
1385 case ICMD_IF_ICMPNE:
1386 case ICMD_IF_ICMPLT:
1387 case ICMD_IF_ICMPGE:
1388 case ICMD_IF_ICMPGT:
1389 case ICMD_IF_ICMPLE:
1390 COUNT(count_pcmd_bra);
1392 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1394 iptr[0].target = (void *) tbptr;
1396 MARKREACHED(tbptr, copy);
1399 case ICMD_IF_ACMPEQ:
1400 case ICMD_IF_ACMPNE:
1401 COUNT(count_pcmd_bra);
1403 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1405 iptr[0].target = (void *) tbptr;
1407 MARKREACHED(tbptr, copy);
1413 COUNT(count_check_null);
1414 COUNT(count_pcmd_mem);
1415 OPTT2_0(iptr->op1,TYPE_ADR);
1416 #if defined(__I386__)
1417 method_uses_ecx = true;
1423 if (! IS_2_WORD_TYPE(curstack->type)) {
1425 #ifdef TYPECHECK_STACK_COMPCAT
1428 if (IS_2_WORD_TYPE(curstack->prev->type))
1429 panic("Illegal instruction: POP2 on cat2, cat1 types");
1432 OP1_0ANY; /* second pop */
1435 iptr->opc = ICMD_POP;
1439 /* pop 0 push 1 dup */
1442 #ifdef TYPECHECK_STACK_COMPCAT
1445 if (IS_2_WORD_TYPE(curstack->type))
1446 panic("Illegal instruction: DUP on category 2 type");
1449 COUNT(count_dup_instruction);
1455 if (IS_2_WORD_TYPE(curstack->type)) {
1457 iptr->opc = ICMD_DUP;
1462 /* ..., ????, cat1 */
1463 #ifdef TYPECHECK_STACK_COMPCAT
1465 if (IS_2_WORD_TYPE(curstack->prev->type))
1466 panic("Illegal instruction: DUP2 on cat2, cat1 types");
1470 NEWSTACK(copy->prev->type, copy->prev->varkind,
1471 copy->prev->varnum);
1472 NEWSTACK(copy->type, copy->varkind,
1479 /* pop 2 push 3 dup */
1482 #ifdef TYPECHECK_STACK_COMPCAT
1485 if (IS_2_WORD_TYPE(curstack->type) ||
1486 IS_2_WORD_TYPE(curstack->prev->type))
1487 panic("Illegal instruction: DUP_X1 on cat 2 type");
1495 if (IS_2_WORD_TYPE(curstack->type)) {
1496 /* ..., ????, cat2 */
1497 #ifdef TYPECHECK_STACK_COMPCAT
1499 if (IS_2_WORD_TYPE(curstack->prev->type))
1500 panic("Illegal instruction: DUP2_X1 on cat2, cat2 types");
1503 iptr->opc = ICMD_DUP_X1;
1507 /* ..., ????, cat1 */
1508 #ifdef TYPECHECK_STACK_COMPCAT
1511 if (IS_2_WORD_TYPE(curstack->prev->type)
1512 || IS_2_WORD_TYPE(curstack->prev->prev->type))
1513 panic("Illegal instruction: DUP2_X1 on invalid types");
1520 /* pop 3 push 4 dup */
1524 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1525 /* ..., cat2, ???? */
1526 #ifdef TYPECHECK_STACK_COMPCAT
1528 if (IS_2_WORD_TYPE(curstack->type))
1529 panic("Illegal instruction: DUP_X2 on cat2, cat2 types");
1532 iptr->opc = ICMD_DUP_X1;
1536 /* ..., cat1, ???? */
1537 #ifdef TYPECHECK_STACK_COMPCAT
1540 if (IS_2_WORD_TYPE(curstack->type)
1541 || IS_2_WORD_TYPE(curstack->prev->prev->type))
1542 panic("Illegal instruction: DUP_X2 on invalid types");
1551 if (IS_2_WORD_TYPE(curstack->type)) {
1552 /* ..., ????, cat2 */
1553 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1554 /* ..., cat2, cat2 */
1555 iptr->opc = ICMD_DUP_X1;
1559 /* ..., cat1, cat2 */
1560 #ifdef TYPECHECK_STACK_COMPCAT
1563 if (IS_2_WORD_TYPE(curstack->prev->prev->type))
1564 panic("Illegal instruction: DUP2_X2 on invalid types");
1567 iptr->opc = ICMD_DUP_X2;
1573 /* ..., ????, ????, cat1 */
1574 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1575 /* ..., cat2, ????, cat1 */
1576 #ifdef TYPECHECK_STACK_COMPCAT
1578 if (IS_2_WORD_TYPE(curstack->prev->type))
1579 panic("Illegal instruction: DUP2_X2 on invalid types");
1582 iptr->opc = ICMD_DUP2_X1;
1586 /* ..., cat1, ????, cat1 */
1587 #ifdef TYPECHECK_STACK_COMPCAT
1590 if (IS_2_WORD_TYPE(curstack->prev->type)
1591 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
1592 panic("Illegal instruction: DUP2_X2 on invalid types");
1600 /* pop 2 push 2 swap */
1603 #ifdef TYPECHECK_STACK_COMPCAT
1606 if (IS_2_WORD_TYPE(curstack->type)
1607 || IS_2_WORD_TYPE(curstack->prev->type))
1608 panic("Illegal instruction: SWAP on category 2 type");
1617 #if !SUPPORT_DIVISION
1618 iptr[0].opc = ICMD_BUILTIN2;
1619 iptr[0].op1 = TYPE_INT;
1620 iptr[0].val.a = BUILTIN_idiv;
1621 m->isleafmethod = false;
1626 #if !SUPPORT_DIVISION
1627 iptr[0].opc = ICMD_BUILTIN2;
1628 iptr[0].op1 = TYPE_INT;
1629 iptr[0].val.a = BUILTIN_irem;
1630 m->isleafmethod = false;
1633 #if defined(__I386__)
1634 method_uses_ecx = true;
1635 method_uses_edx = true;
1641 #if defined(__I386__)
1642 method_uses_ecx = true;
1650 COUNT(count_pcmd_op);
1655 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1656 iptr[0].opc = ICMD_BUILTIN2;
1657 iptr[0].op1 = TYPE_LNG;
1658 iptr[0].val.a = BUILTIN_ldiv;
1659 m->isleafmethod = false;
1664 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1665 iptr[0].opc = ICMD_BUILTIN2;
1666 iptr[0].op1 = TYPE_LNG;
1667 iptr[0].val.a = BUILTIN_lrem;
1668 m->isleafmethod = false;
1673 #if defined(__I386__)
1674 method_uses_ecx = true;
1675 method_uses_edx = true;
1682 /* DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1683 COUNT(count_pcmd_op);
1690 COUNT(count_pcmd_op);
1692 #if defined(__I386__)
1693 method_uses_ecx = true;
1694 method_uses_edx = true;
1703 COUNT(count_pcmd_op);
1712 COUNT(count_pcmd_op);
1717 COUNT(count_pcmd_op);
1718 #if !defined(NOLONG_CONDITIONAL)
1719 if ((len > 0) && (iptr[1].val.i == 0)) {
1720 switch (iptr[1].opc) {
1722 iptr[0].opc = ICMD_IF_LCMPEQ;
1723 #if defined(__I386__)
1724 method_uses_ecx = true;
1727 iptr[0].op1 = iptr[1].op1;
1730 /* iptr[1].opc = ICMD_NOP; */
1732 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1734 iptr[0].target = (void *) tbptr;
1736 MARKREACHED(tbptr, copy);
1737 COUNT(count_pcmd_bra);
1740 iptr[0].opc = ICMD_IF_LCMPNE;
1741 #if defined(__I386__)
1742 method_uses_ecx = true;
1744 goto icmd_lcmp_if_tail;
1746 iptr[0].opc = ICMD_IF_LCMPLT;
1747 goto icmd_lcmp_if_tail;
1749 iptr[0].opc = ICMD_IF_LCMPGT;
1750 goto icmd_lcmp_if_tail;
1752 iptr[0].opc = ICMD_IF_LCMPLE;
1753 goto icmd_lcmp_if_tail;
1755 iptr[0].opc = ICMD_IF_LCMPGE;
1756 goto icmd_lcmp_if_tail;
1758 OPTT2_1(TYPE_LNG, TYPE_INT);
1763 OPTT2_1(TYPE_LNG, TYPE_INT);
1767 COUNT(count_pcmd_op);
1768 OPTT2_1(TYPE_FLT, TYPE_INT);
1772 COUNT(count_pcmd_op);
1773 OPTT2_1(TYPE_DBL, TYPE_INT);
1781 case ICMD_INT2SHORT:
1782 COUNT(count_pcmd_op);
1783 OP1_1(TYPE_INT, TYPE_INT);
1786 COUNT(count_pcmd_op);
1787 OP1_1(TYPE_LNG, TYPE_LNG);
1790 COUNT(count_pcmd_op);
1791 OP1_1(TYPE_FLT, TYPE_FLT);
1794 COUNT(count_pcmd_op);
1795 OP1_1(TYPE_DBL, TYPE_DBL);
1799 COUNT(count_pcmd_op);
1800 OP1_1(TYPE_INT, TYPE_LNG);
1801 #if defined(__I386__)
1802 method_uses_edx = true;
1806 COUNT(count_pcmd_op);
1807 OP1_1(TYPE_INT, TYPE_FLT);
1810 COUNT(count_pcmd_op);
1811 OP1_1(TYPE_INT, TYPE_DBL);
1814 COUNT(count_pcmd_op);
1815 OP1_1(TYPE_LNG, TYPE_INT);
1818 COUNT(count_pcmd_op);
1819 OP1_1(TYPE_LNG, TYPE_FLT);
1822 COUNT(count_pcmd_op);
1823 OP1_1(TYPE_LNG, TYPE_DBL);
1826 COUNT(count_pcmd_op);
1827 OP1_1(TYPE_FLT, TYPE_INT);
1830 COUNT(count_pcmd_op);
1831 OP1_1(TYPE_FLT, TYPE_LNG);
1832 #if defined(__I386__)
1833 method_uses_edx = true;
1837 COUNT(count_pcmd_op);
1838 OP1_1(TYPE_FLT, TYPE_DBL);
1841 COUNT(count_pcmd_op);
1842 OP1_1(TYPE_DBL, TYPE_INT);
1845 COUNT(count_pcmd_op);
1846 OP1_1(TYPE_DBL, TYPE_LNG);
1847 #if defined(__I386__)
1848 method_uses_edx = true;
1852 COUNT(count_pcmd_op);
1853 OP1_1(TYPE_DBL, TYPE_FLT);
1856 case ICMD_CHECKCAST:
1857 OP1_1(TYPE_ADR, TYPE_ADR);
1858 #if defined(__I386__)
1859 method_uses_ecx = true;
1860 method_uses_edx = true;
1864 case ICMD_INSTANCEOF:
1865 #if defined(__I386__)
1866 method_uses_ecx = true;
1867 method_uses_edx = true;
1869 case ICMD_ARRAYLENGTH:
1870 OP1_1(TYPE_ADR, TYPE_INT);
1874 case ICMD_ANEWARRAY:
1875 OP1_1(TYPE_INT, TYPE_ADR);
1879 COUNT(count_check_null);
1880 COUNT(count_pcmd_mem);
1881 OP1_1(TYPE_ADR, iptr->op1);
1882 #if defined(__I386__)
1883 method_uses_ecx = true;
1889 case ICMD_GETSTATIC:
1890 COUNT(count_pcmd_mem);
1892 #if defined(__I386__)
1893 method_uses_ecx = true;
1903 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1905 iptr[0].target = (void *) tbptr;
1907 /* This is a dirty hack. The typechecker
1908 * needs it because the OP1_0ANY below
1909 * overwrites iptr->dst.
1911 iptr->val.a = (void *) iptr->dst;
1913 tbptr->type = BBTYPE_SBR;
1915 /* We need to check for overflow right here because
1916 * the pushed value is poped after MARKREACHED. */
1918 MARKREACHED(tbptr, copy);
1922 /* pop many push any */
1924 case ICMD_INVOKEVIRTUAL:
1925 case ICMD_INVOKESPECIAL:
1926 case ICMD_INVOKEINTERFACE:
1927 case ICMD_INVOKESTATIC:
1928 COUNT(count_pcmd_met);
1929 #if defined(__I386__)
1930 method_uses_ecx = true;
1933 methodinfo *lm = iptr->val.a;
1934 if (lm->flags & ACC_STATIC)
1935 {COUNT(count_check_null);}
1937 if (i > m->registerdata->arguments_num)
1938 m->registerdata->arguments_num = i;
1940 #if defined(__X86_64__)
1948 (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1952 stackargs += (iarg < intreg_argnum) ? 0 : (iarg - intreg_argnum);
1953 stackargs += (farg < fltreg_argnum) ? 0 : (farg - fltreg_argnum);
1958 if (!(copy->flags & SAVEDVAR)) {
1959 copy->varkind = ARGVAR;
1960 if (IS_FLT_DBL_TYPE(copy->type)) {
1961 if (--farg < fltreg_argnum) {
1962 copy->varnum = farg;
1964 copy->varnum = --stackargs + intreg_argnum;
1967 if (--iarg < intreg_argnum) {
1968 copy->varnum = iarg;
1970 copy->varnum = --stackargs + intreg_argnum;
1974 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1982 if (! (copy->flags & SAVEDVAR)) {
1983 copy->varkind = ARGVAR;
1990 copy->flags |= SAVEDVAR;
1995 if (lm->returntype != TYPE_VOID) {
1996 OP0_1(lm->returntype);
2002 /* DEBUG */ /*dolog("builtin3");*/
2004 if (! (curstack->flags & SAVEDVAR)) {
2005 curstack->varkind = ARGVAR;
2006 curstack->varnum = 2;
2008 if (3 > m->registerdata->arguments_num) {
2009 m->registerdata->arguments_num = 3;
2016 /* DEBUG */ /*dolog("builtin2");*/
2017 if (!(curstack->flags & SAVEDVAR)) {
2018 curstack->varkind = ARGVAR;
2019 curstack->varnum = 1;
2021 if (2 > m->registerdata->arguments_num) {
2022 m->registerdata->arguments_num = 2;
2029 /* DEBUG */ /*dolog("builtin1");*/
2030 if (!(curstack->flags & SAVEDVAR)) {
2031 curstack->varkind = ARGVAR;
2032 curstack->varnum = 0;
2034 if (1 > m->registerdata->arguments_num) {
2035 m->registerdata->arguments_num = 1;
2040 copy->flags |= SAVEDVAR;
2043 if (iptr->op1 != TYPE_VOID)
2047 case ICMD_MULTIANEWARRAY:
2050 if ((i + m->registerdata->intreg_argnum) > m->registerdata->arguments_num)
2051 m->registerdata->arguments_num = i + m->registerdata->intreg_argnum;
2054 /* check INT type here? Currently typecheck does this. */
2055 if (! (copy->flags & SAVEDVAR)) {
2056 copy->varkind = ARGVAR;
2057 copy->varnum = i + m->registerdata->intreg_argnum;
2062 copy->flags |= SAVEDVAR;
2070 case ICMD_CLEAR_ARGREN:
2071 for (i = iptr->op1; i<m->maxlocals; i++)
2073 iptr->opc = opcode = ICMD_NOP;
2077 case ICMD_READONLY_ARG:
2078 case ICMD_READONLY_ARG+1:
2079 case ICMD_READONLY_ARG+2:
2080 case ICMD_READONLY_ARG+3:
2081 case ICMD_READONLY_ARG+4:
2084 if (curstack->varkind == LOCALVAR) {
2085 i = curstack->varnum;
2086 argren[iptr->op1] = i;
2089 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
2095 printf("ICMD %d at %d\n", iptr->opc, (s4) (iptr - m->instructions));
2096 panic("Missing ICMD code during stack analysis");
2101 /* DEBUG */ /*dolog("iptr++");*/
2103 } /* while instructions */
2104 bptr->outstack = curstack;
2105 bptr->outdepth = stackdepth;
2109 superblockend = true;
2111 } /* while blocks */
2112 } while (repeat && !deadcode);
2115 if (m->basicblockcount > count_max_basic_blocks)
2116 count_max_basic_blocks = m->basicblockcount;
2117 count_basic_blocks += m->basicblockcount;
2118 if (m->instructioncount > count_max_javainstr)
2119 count_max_javainstr = m->instructioncount;
2120 count_javainstr += m->instructioncount;
2121 if (m->stackcount > count_upper_bound_new_stack)
2122 count_upper_bound_new_stack = m->stackcount;
2123 if ((new - m->stack) > count_max_new_stack)
2124 count_max_new_stack = (new - m->stack);
2126 b_count = m->basicblockcount;
2127 bptr = m->basicblocks;
2128 while (--b_count >= 0) {
2129 if (bptr->flags > BBREACHED) {
2130 if (bptr->indepth >= 10)
2131 count_block_stack[10]++;
2133 count_block_stack[bptr->indepth]++;
2136 count_block_size_distribution[len]++;
2138 count_block_size_distribution[10]++;
2140 count_block_size_distribution[11]++;
2142 count_block_size_distribution[12]++;
2144 count_block_size_distribution[13]++;
2146 count_block_size_distribution[14]++;
2148 count_block_size_distribution[15]++;
2150 count_block_size_distribution[16]++;
2152 count_block_size_distribution[17]++;
2158 count_analyse_iterations[0]++;
2159 else if (loops == 2)
2160 count_analyse_iterations[1]++;
2161 else if (loops == 3)
2162 count_analyse_iterations[2]++;
2163 else if (loops == 4)
2164 count_analyse_iterations[3]++;
2166 count_analyse_iterations[4]++;
2168 if (m->basicblockcount <= 5)
2169 count_method_bb_distribution[0]++;
2170 else if (m->basicblockcount <= 10)
2171 count_method_bb_distribution[1]++;
2172 else if (m->basicblockcount <= 15)
2173 count_method_bb_distribution[2]++;
2174 else if (m->basicblockcount <= 20)
2175 count_method_bb_distribution[3]++;
2176 else if (m->basicblockcount <= 30)
2177 count_method_bb_distribution[4]++;
2178 else if (m->basicblockcount <= 40)
2179 count_method_bb_distribution[5]++;
2180 else if (m->basicblockcount <= 50)
2181 count_method_bb_distribution[6]++;
2182 else if (m->basicblockcount <= 75)
2183 count_method_bb_distribution[7]++;
2185 count_method_bb_distribution[8]++;
2188 /* just return methodinfo* to signal everything was ok */
2194 /**********************************************************************/
2195 /* DEBUGGING HELPERS */
2196 /**********************************************************************/
2198 void icmd_print_stack(methodinfo *m, stackptr s)
2210 j = m->maxstack - i;
2215 /* DEBUG */ /*printf("(%d,%d,%d,%d)",s->varkind,s->flags,s->regoff,s->varnum); fflush(stdout);*/
2216 if (s->flags & SAVEDVAR)
2217 switch (s->varkind) {
2219 if (s->flags & INMEMORY)
2220 printf(" M%02d", s->regoff);
2221 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2222 printf(" F%02d", s->regoff);
2224 printf(" %3s", regs[s->regoff]);
2228 printf(" I%02d", s->varnum);
2231 printf(" L%02d", s->varnum);
2234 printf(" A%02d", s->varnum);
2237 printf(" !%02d", j);
2240 switch (s->varkind) {
2242 if (s->flags & INMEMORY)
2243 printf(" m%02d", s->regoff);
2244 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2245 printf(" f%02d", s->regoff);
2247 printf(" %3s", regs[s->regoff]);
2251 printf(" i%02d", s->varnum);
2254 printf(" l%02d", s->varnum);
2257 printf(" a%02d", s->varnum);
2260 printf(" ?%02d", j);
2268 static void print_reg(stackptr s) {
2270 if (s->flags & SAVEDVAR)
2271 switch (s->varkind) {
2273 if (s->flags & INMEMORY)
2274 printf(" tm%02d", s->regoff);
2276 printf(" tr%02d", s->regoff);
2279 printf(" s %02d", s->varnum);
2282 printf(" l %02d", s->varnum);
2285 printf(" a %02d", s->varnum);
2288 printf(" ! %02d", s->varnum);
2291 switch (s->varkind) {
2293 if (s->flags & INMEMORY)
2294 printf(" Tm%02d", s->regoff);
2296 printf(" Tr%02d", s->regoff);
2299 printf(" S %02d", s->varnum);
2302 printf(" L %02d", s->varnum);
2305 printf(" A %02d", s->varnum);
2308 printf(" ? %02d", s->varnum);
2318 char *icmd_builtin_name(functionptr bptr)
2320 builtin_descriptor *bdesc = builtin_desc;
2321 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
2323 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
2327 static char *jit_type[] = {
2336 void show_icmd_method(methodinfo *m)
2343 utf_fprint_classname(stdout, m->class->name);
2345 utf_fprint(stdout, m->name);
2346 utf_fprint_classname(stdout, m->descriptor);
2347 printf ("\n\nMax locals: %d\n", (int) m->maxlocals);
2348 printf ("Max stack: %d\n", (int) m->maxstack);
2350 printf ("Line number table length: %d\n", m->linenumbercount);
2352 printf ("Exceptions (Number: %d):\n", m->exceptiontablelength);
2353 for (ex = m->exceptiontable; ex != NULL; ex = ex->down) {
2354 printf(" L%03d ... ", ex->start->debug_nr );
2355 printf("L%03d = ", ex->end->debug_nr);
2356 printf("L%03d\n", ex->handler->debug_nr);
2359 printf ("Local Table:\n");
2360 for (i = 0; i < m->maxlocals; i++) {
2361 printf(" %3d: ", i);
2362 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2363 if (m->registerdata->locals[i][j].type >= 0) {
2364 printf(" (%s) ", jit_type[j]);
2365 if (m->registerdata->locals[i][j].flags & INMEMORY)
2366 printf("m%2d", m->registerdata->locals[i][j].regoff);
2367 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2368 printf("f%02d", m->registerdata->locals[i][j].regoff);
2370 printf("%3s", regs[m->registerdata->locals[i][j].regoff]);
2377 printf ("Interface Table:\n");
2378 for (i = 0; i < m->maxstack; i++) {
2379 if ((m->registerdata->interfaces[i][0].type >= 0) ||
2380 (m->registerdata->interfaces[i][1].type >= 0) ||
2381 (m->registerdata->interfaces[i][2].type >= 0) ||
2382 (m->registerdata->interfaces[i][3].type >= 0) ||
2383 (m->registerdata->interfaces[i][4].type >= 0)) {
2384 printf(" %3d: ", i);
2385 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2386 if (m->registerdata->interfaces[i][j].type >= 0) {
2387 printf(" (%s) ", jit_type[j]);
2388 if (m->registerdata->interfaces[i][j].flags & SAVEDVAR) {
2389 if (m->registerdata->interfaces[i][j].flags & INMEMORY)
2390 printf("M%2d", m->registerdata->interfaces[i][j].regoff);
2391 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2392 printf("F%02d", m->registerdata->interfaces[i][j].regoff);
2394 printf("%3s", regs[m->registerdata->interfaces[i][j].regoff]);
2398 if (m->registerdata->interfaces[i][j].flags & INMEMORY)
2399 printf("m%2d", m->registerdata->interfaces[i][j].regoff);
2400 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2401 printf("f%02d", m->registerdata->interfaces[i][j].regoff);
2403 printf("%3s", regs[m->registerdata->interfaces[i][j].regoff]);
2412 if (showdisassemble) {
2413 #if defined(__I386__) || defined(__X86_64__)
2417 u1ptr = m->mcode + dseglen;
2418 for (i = 0; i < m->basicblocks[0].mpc; i++, u1ptr++) {
2419 a = disassinstr(u1ptr, i);
2427 s4ptr = (s4 *) (m->mcode + dseglen);
2428 for (i = 0; i < m->basicblocks[0].mpc; i += 4, s4ptr++) {
2429 disassinstr(s4ptr, i);
2435 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
2436 show_icmd_block(m, bptr);
2441 void show_icmd_block(methodinfo *m, basicblock *bptr)
2447 if (bptr->flags != BBDELETED) {
2448 deadcode = bptr->flags <= BBREACHED;
2451 for (j = m->maxstack; j > 0; j--)
2454 icmd_print_stack(m, bptr->instack);
2455 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2456 iptr = bptr->iinstr;
2458 for (i = 0; i < bptr->icount; i++, iptr++) {
2461 for (j = m->maxstack; j > 0; j--)
2465 icmd_print_stack(m, iptr->dst);
2466 printf("] %4d ", i);
2467 show_icmd(iptr, deadcode);
2471 if (showdisassemble && (!deadcode)) {
2472 #if defined(__I386__) || defined(__X86_64__)
2478 u1ptr = m->mcode + dseglen + i;
2480 if (bptr->next != NULL) {
2481 for (; i < bptr->next->mpc; i++, u1ptr++) {
2482 a = disassinstr(u1ptr, i);
2489 for (; u1ptr < (u1 *) (m->mcode + m->mcodelength); i++, u1ptr++) {
2490 a = disassinstr(u1ptr, i);
2501 s4ptr = (s4 *) (m->mcode + dseglen + i);
2503 if (bptr->next != NULL) {
2504 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2505 disassinstr(s4ptr, i);
2510 for (; s4ptr < (s4 *) (m->mcode + m->mcodelength); i += 4, s4ptr++) {
2511 disassinstr(s4ptr, i);
2521 void show_icmd(instruction *iptr, bool deadcode)
2527 printf("%s", icmd_names[iptr->opc]);
2529 switch ((int) iptr->opc) {
2530 case ICMD_IADDCONST:
2531 case ICMD_ISUBCONST:
2532 case ICMD_IMULCONST:
2535 case ICMD_IREM0X10001:
2536 case ICMD_IANDCONST:
2538 case ICMD_IXORCONST:
2539 case ICMD_ISHLCONST:
2540 case ICMD_ISHRCONST:
2541 case ICMD_IUSHRCONST:
2542 case ICMD_LSHLCONST:
2543 case ICMD_LSHRCONST:
2544 case ICMD_LUSHRCONST:
2546 case ICMD_ELSE_ICONST:
2547 case ICMD_IFEQ_ICONST:
2548 case ICMD_IFNE_ICONST:
2549 case ICMD_IFLT_ICONST:
2550 case ICMD_IFGE_ICONST:
2551 case ICMD_IFGT_ICONST:
2552 case ICMD_IFLE_ICONST:
2553 case ICMD_IASTORECONST:
2554 case ICMD_BASTORECONST:
2555 case ICMD_CASTORECONST:
2556 case ICMD_SASTORECONST:
2557 printf(" %d", iptr->val.i);
2560 case ICMD_LADDCONST:
2561 case ICMD_LSUBCONST:
2562 case ICMD_LMULCONST:
2565 case ICMD_LANDCONST:
2567 case ICMD_LXORCONST:
2569 case ICMD_LASTORECONST:
2570 #if defined(__I386__)
2571 printf(" %lld", iptr->val.l);
2573 printf(" %ld", iptr->val.l);
2578 printf(" %f", iptr->val.f);
2582 printf(" %f", iptr->val.d);
2586 case ICMD_AASTORECONST:
2587 printf(" %p", iptr->val.a);
2592 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2593 case ICMD_PUTSTATIC:
2594 case ICMD_GETSTATIC:
2596 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->class->name);
2598 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->name);
2600 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->descriptor);
2605 printf(" %d + %d", iptr->op1, iptr->val.i);
2640 printf(" %d", iptr->op1);
2646 ((classinfo *) iptr->val.a)->name);
2650 switch (iptr->op1) {
2678 case ICMD_ANEWARRAY:
2682 ((classinfo *) iptr->val.a)->name);
2686 case ICMD_MULTIANEWARRAY:
2689 printf(" %d ",iptr->op1);
2690 vft = (vftbl *)iptr->val.a;
2692 utf_fprint(stdout,vft->class->name);
2698 case ICMD_CHECKCAST:
2699 case ICMD_INSTANCEOF:
2701 classinfo *c = iptr->val.a;
2702 if (c->flags & ACC_INTERFACE)
2703 printf(" (INTERFACE) ");
2705 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2706 utf_fprint(stdout, c->name);
2713 printf(" %s", icmd_builtin_name((functionptr) iptr->val.a));
2716 case ICMD_INVOKEVIRTUAL:
2717 case ICMD_INVOKESPECIAL:
2718 case ICMD_INVOKESTATIC:
2719 case ICMD_INVOKEINTERFACE:
2722 ((methodinfo *) iptr->val.a)->class->name);
2725 ((methodinfo *) iptr->val.a)->name);
2734 if (deadcode || !iptr->target)
2735 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2737 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2746 if (deadcode || !iptr->target)
2747 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2749 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2755 case ICMD_IFNONNULL:
2756 case ICMD_IF_ICMPEQ:
2757 case ICMD_IF_ICMPNE:
2758 case ICMD_IF_ICMPLT:
2759 case ICMD_IF_ICMPGE:
2760 case ICMD_IF_ICMPGT:
2761 case ICMD_IF_ICMPLE:
2762 case ICMD_IF_LCMPEQ:
2763 case ICMD_IF_LCMPNE:
2764 case ICMD_IF_LCMPLT:
2765 case ICMD_IF_LCMPGE:
2766 case ICMD_IF_LCMPGT:
2767 case ICMD_IF_LCMPLE:
2768 case ICMD_IF_ACMPEQ:
2769 case ICMD_IF_ACMPNE:
2770 if (deadcode || !iptr->target)
2771 printf(" op1=%d", iptr->op1);
2773 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2776 case ICMD_TABLESWITCH:
2777 s4ptr = (s4*)iptr->val.a;
2779 if (deadcode || !iptr->target) {
2780 printf(" %d;", *s4ptr);
2783 tptr = (void **) iptr->target;
2784 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2788 s4ptr++; /* skip default */
2789 j = *s4ptr++; /* low */
2790 j = *s4ptr++ - j; /* high */
2792 if (deadcode || !*tptr)
2793 printf(" %d", *s4ptr++);
2795 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2802 case ICMD_LOOKUPSWITCH:
2803 s4ptr = (s4*)iptr->val.a;
2805 if (deadcode || !iptr->target) {
2806 printf(" %d;", *s4ptr);
2809 tptr = (void **) iptr->target;
2810 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2813 s4ptr++; /* default */
2814 j = *s4ptr++; /* count */
2817 if (deadcode || !*tptr) {
2818 s4ptr++; /* skip value */
2819 printf(" %d",*s4ptr++);
2822 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2828 printf(" Line number: %d, method:",iptr->line);
2829 utf_display(iptr->method->class->name);
2831 utf_display(iptr->method->name);
2836 * These are local overrides for various environment variables in Emacs.
2837 * Please do not remove this and leave it at the end of the file, where
2838 * Emacs will automagically detect them.
2839 * ---------------------------------------------------------------------
2842 * indent-tabs-mode: t