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 803 2003-12-17 14:11:00Z edwin $
46 #include "toolbox/loging.h"
47 #include "toolbox/memory.h"
50 /* from codegen.inc */
53 /**********************************************************************/
54 /* Macros used internally by analyse_stack */
55 /**********************************************************************/
58 #define COUNT(cnt) cnt++
63 /* convenient abbreviations */
64 #define CURKIND curstack->varkind
65 #define CURTYPE curstack->type
67 /*--------------------------------------------------*/
68 /* SIGNALING ERRORS */
69 /*--------------------------------------------------*/
71 #define TYPEPANIC {show_icmd_method();panic("Stack type mismatch");}
72 #define UNDERFLOW {show_icmd_method();panic("Operand stack underflow");}
73 #define OVERFLOW {show_icmd_method();panic("Operand stack overflow");}
75 /*--------------------------------------------------*/
76 /* STACK UNDERFLOW/OVERFLOW CHECKS */
77 /*--------------------------------------------------*/
79 /* underflow checks */
80 #define REQUIRE(num) do { if (stackdepth<(num)) {UNDERFLOW;} } while(0)
81 #define REQUIRE_1 REQUIRE(1)
82 #define REQUIRE_2 REQUIRE(2)
83 #define REQUIRE_3 REQUIRE(3)
84 #define REQUIRE_4 REQUIRE(4)
87 /* XXX we allow ACONST to exceed the maximum stack depth because it is
88 * generated for builtin calls. Maybe we should check against maximum
89 * stack depth only at block boundaries?
91 #define CHECKOVERFLOW \
93 if (stackdepth > maxstack) { \
94 if (iptr[0].opc != ICMD_ACONST) \
99 /*--------------------------------------------------*/
100 /* ALLOCATING STACK SLOTS */
101 /*--------------------------------------------------*/
103 #define NEWSTACK(s,v,n) {new->prev=curstack;new->type=s;new->flags=0; \
104 new->varkind=v;new->varnum=n;curstack=new;new++;}
105 #define NEWSTACKn(s,n) NEWSTACK(s,UNDEFVAR,n)
106 #define NEWSTACK0(s) NEWSTACK(s,UNDEFVAR,0)
108 /* allocate the input stack for an exception handler */
109 #define NEWXSTACK {NEWSTACK(TYPE_ADR,STACKVAR,0);curstack=0;}
111 /*--------------------------------------------------*/
112 /* STACK MANIPULATION */
113 /*--------------------------------------------------*/
115 /* resetting to an empty operand stack */
116 #define STACKRESET {curstack=0;stackdepth=0;}
118 /* set the output stack of the current instruction */
119 #define SETDST {iptr->dst=curstack;}
121 /* The following macros do NOT check stackdepth, set stackdepth or iptr->dst */
122 #define POP(s) {if(s!=curstack->type){TYPEPANIC;} \
123 if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR;\
124 curstack=curstack->prev;}
125 #define POPANY {if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR; \
126 curstack=curstack->prev;}
127 #define COPY(s,d) {(d)->flags=0;(d)->type=(s)->type;\
128 (d)->varkind=(s)->varkind;(d)->varnum=(s)->varnum;}
130 /*--------------------------------------------------*/
131 /* STACK OPERATIONS MODELING */
132 /*--------------------------------------------------*/
134 /* The following macros are used to model the stack manipulations of
135 * different kinds of instructions.
137 * These macros check the input stackdepth and they set the output
138 * stackdepth and the output stack of the instruction (iptr->dst).
141 #define PUSHCONST(s){NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
142 #define LOAD(s,v,n) {NEWSTACK(s,v,n);SETDST;stackdepth++;}
143 #define STORE(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
144 #define OP1_0(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
145 #define OP1_0ANY {REQUIRE_1;POPANY;SETDST;stackdepth--;}
146 #define OP0_1(s) {NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
147 #define OP1_1(s,d) {REQUIRE_1;POP(s);NEWSTACKn(d,stackdepth-1);SETDST;}
148 #define OP2_0(s) {REQUIRE_2;POP(s);POP(s);SETDST;stackdepth-=2;}
149 #define OPTT2_0(t,b){REQUIRE_2;POP(t);POP(b);SETDST;stackdepth-=2;}
150 #define OP2_1(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);SETDST;stackdepth--;}
151 #define OP2IAT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(TYPE_ADR);NEWSTACKn(s,stackdepth-2);\
152 SETDST;stackdepth--;}
153 #define OP2IT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(s);NEWSTACKn(s,stackdepth-2);\
154 SETDST;stackdepth--;}
155 #define OPTT2_1(s,d){REQUIRE_2;POP(s);POP(s);NEWSTACKn(d,stackdepth-2);SETDST;stackdepth--;}
156 #define OP2_2(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);\
157 NEWSTACKn(s,stackdepth-1);SETDST;}
158 #define OP3TIA_0(s) {REQUIRE_3;POP(s);POP(TYPE_INT);POP(TYPE_ADR);SETDST;stackdepth-=3;}
159 #define OP3_0(s) {REQUIRE_3;POP(s);POP(s);POP(s);SETDST;stackdepth-=3;}
160 #define POPMANY(i) {REQUIRE(i);stackdepth-=i;while(--i>=0){POPANY;}SETDST;}
161 #define DUP {REQUIRE_1;NEWSTACK(CURTYPE,CURKIND,curstack->varnum);SETDST; \
163 #define SWAP {REQUIRE_2;COPY(curstack,new);POPANY;COPY(curstack,new+1);POPANY;\
164 new[0].prev=curstack;new[1].prev=new;\
165 curstack=new+1;new+=2;SETDST;}
166 #define DUP_X1 {REQUIRE_2;COPY(curstack,new);COPY(curstack,new+2);POPANY;\
167 COPY(curstack,new+1);POPANY;new[0].prev=curstack;\
168 new[1].prev=new;new[2].prev=new+1;\
169 curstack=new+2;new+=3;SETDST;stackdepth++;}
170 #define DUP2_X1 {REQUIRE_3;COPY(curstack,new+1);COPY(curstack,new+4);POPANY;\
171 COPY(curstack,new);COPY(curstack,new+3);POPANY;\
172 COPY(curstack,new+2);POPANY;new[0].prev=curstack;\
173 new[1].prev=new;new[2].prev=new+1;\
174 new[3].prev=new+2;new[4].prev=new+3;\
175 curstack=new+4;new+=5;SETDST;stackdepth+=2;}
176 #define DUP_X2 {REQUIRE_3;COPY(curstack,new);COPY(curstack,new+3);POPANY;\
177 COPY(curstack,new+2);POPANY;COPY(curstack,new+1);POPANY;\
178 new[0].prev=curstack;new[1].prev=new;\
179 new[2].prev=new+1;new[3].prev=new+2;\
180 curstack=new+3;new+=4;SETDST;stackdepth++;}
181 #define DUP2_X2 {REQUIRE_4;COPY(curstack,new+1);COPY(curstack,new+5);POPANY;\
182 COPY(curstack,new);COPY(curstack,new+4);POPANY;\
183 COPY(curstack,new+3);POPANY;COPY(curstack,new+2);POPANY;\
184 new[0].prev=curstack;new[1].prev=new;\
185 new[2].prev=new+1;new[3].prev=new+2;\
186 new[4].prev=new+3;new[5].prev=new+4;\
187 curstack=new+5;new+=6;SETDST;stackdepth+=2;}
188 /******************************/
190 /* COPYCURSTACK makes a copy of the current operand stack (curstack)
191 * and returns it in the variable copy.
193 * This macro is used to propagate the operand stack from one basic
194 * block to another. The destination block receives the copy as its
197 #define COPYCURSTACK(copy) {\
210 copy->varkind=STACKVAR;\
226 if((copy->varkind==STACKVAR)&&(copy->varnum>i))\
227 copy->varkind=TEMPVAR;\
229 copy->varkind=STACKVAR;\
232 interfaces[i][copy->type].type = copy->type;\
233 interfaces[i][copy->type].flags |= copy->flags;\
234 i--;copy=copy->prev;\
239 interfaces[i][copy->type].type = copy->type;\
240 if(copy->varkind==STACKVAR){\
241 if (copy->flags & SAVEDVAR)\
242 interfaces[i][copy->type].flags |= SAVEDVAR;\
244 i--;copy=copy->prev;\
249 /* MARKREACHED marks the destination block <b> as reached. If this
250 * block has been reached before we check if stack depth and types
251 * match. Otherwise the destination block receives a copy of the
252 * current stack as its input stack.
254 * b...destination block
257 #define MARKREACHED(b,c) { \
259 {COPYCURSTACK(c);b->flags=0;b->instack=c;b->indepth=stackdepth;} \
260 else {stackptr s=curstack;stackptr t=b->instack; \
261 if(b->indepth!=stackdepth) \
262 {show_icmd_method();panic("Stack depth mismatch");} \
263 while(s){if (s->type!=t->type) \
265 s=s->prev;t=t->prev; \
279 int opcode, i, len, loops;
280 int superblockend, repeat, deadcode;
288 if (compileverbose) {
289 char logtext[MAXLOGTEXT];
290 sprintf(logtext, "Analysing: ");
291 utf_sprint(logtext+strlen(logtext), method->class->name);
292 strcpy(logtext+strlen(logtext), ".");
293 utf_sprint(logtext+strlen(logtext), method->name);
294 utf_sprint(logtext+strlen(logtext), method->descriptor);
298 argren = DMNEW(int, maxlocals);
299 /*int *argren = (int *)alloca(maxlocals * sizeof(int));*/ /* table for argument renaming */
300 for (i = 0; i < maxlocals; i++)
306 block[0].flags = BBREACHED;
307 block[0].instack = 0;
308 block[0].indepth = 0;
310 for (i = 0; i < exceptiontablelength; i++) {
311 bptr = &block[block_index[extable[i].handlerpc]];
312 bptr->flags = BBREACHED;
313 bptr->type = BBTYPE_EXH;
316 bptr->pre_count = 10000;
321 #ifdef CONDITIONAL_LOADCONST
322 b_count = block_count;
324 while (--b_count >= 0) {
325 if (bptr->icount != 0) {
326 iptr = bptr->iinstr + bptr->icount - 1;
359 block[block_index[iptr->op1]].pre_count++;
362 case ICMD_TABLESWITCH:
364 block[block_index[*s4ptr++]].pre_count++; /* default */
365 i = *s4ptr++; /* low */
366 i = *s4ptr++ - i + 1; /* high */
368 block[block_index[*s4ptr++]].pre_count++;
372 case ICMD_LOOKUPSWITCH:
374 block[block_index[*s4ptr++]].pre_count++; /* default */
375 i = *s4ptr++; /* count */
377 block[block_index[s4ptr[1]]].pre_count++;
393 b_count = block_count;
395 superblockend = true;
399 while (--b_count >= 0) {
400 if (bptr->flags == BBDELETED) {
403 else if (superblockend && (bptr->flags < BBREACHED))
405 else if (bptr->flags <= BBREACHED) {
407 stackdepth = bptr->indepth;
408 else if (bptr->flags < BBREACHED) {
410 bptr->instack = copy;
411 bptr->indepth = stackdepth;
413 else if (bptr->indepth != stackdepth) {
415 panic("Stack depth mismatch");
418 curstack = bptr->instack;
420 superblockend = false;
421 bptr->flags = BBFINISHED;
424 b_index = bptr - block;
429 /* DEBUG XXX */ /* dolog("p:%04d op: %s",iptr-instr,icmd_names[opcode]); */
431 #ifdef USEBUILTINTABLE
434 stdopdescriptor *breplace;
435 breplace = find_builtin(opcode);
437 if (breplace && opcode == breplace->opcode) {
438 iptr[0].opc = breplace->icmd;
439 iptr[0].op1 = breplace->type_d;
440 iptr[0].val.a = breplace->builtin;
441 isleafmethod = false;
442 switch (breplace->icmd) {
450 builtin_descriptor *breplace;
451 breplace = find_builtin(opcode);
453 if (breplace && opcode == breplace->opcode) {
454 iptr[0].opc = breplace->icmd;
455 iptr[0].op1 = breplace->type_d;
456 iptr[0].val.a = breplace->builtin;
457 isleafmethod = false;
458 switch (breplace->icmd) {
473 case ICMD_CHECKASIZE:
475 case ICMD_IFEQ_ICONST:
476 case ICMD_IFNE_ICONST:
477 case ICMD_IFLT_ICONST:
478 case ICMD_IFGE_ICONST:
479 case ICMD_IFGT_ICONST:
480 case ICMD_IFLE_ICONST:
481 case ICMD_ELSE_ICONST:
486 locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
488 COUNT(count_pcmd_return);
490 superblockend = true;
493 /* pop 0 push 1 const */
496 COUNT(count_pcmd_load);
498 switch (iptr[1].opc) {
500 iptr[0].opc = ICMD_IADDCONST;
502 iptr[1].opc = ICMD_NOP;
503 OP1_1(TYPE_INT,TYPE_INT);
504 COUNT(count_pcmd_op);
507 iptr[0].opc = ICMD_ISUBCONST;
508 goto icmd_iconst_tail;
510 iptr[0].opc = ICMD_IMULCONST;
511 goto icmd_iconst_tail;
513 if (iptr[0].val.i == 0x00000002)
515 else if (iptr[0].val.i == 0x00000004)
517 else if (iptr[0].val.i == 0x00000008)
519 else if (iptr[0].val.i == 0x00000010)
521 else if (iptr[0].val.i == 0x00000020)
523 else if (iptr[0].val.i == 0x00000040)
525 else if (iptr[0].val.i == 0x00000080)
527 else if (iptr[0].val.i == 0x00000100)
529 else if (iptr[0].val.i == 0x00000200)
531 else if (iptr[0].val.i == 0x00000400)
533 else if (iptr[0].val.i == 0x00000800)
535 else if (iptr[0].val.i == 0x00001000)
537 else if (iptr[0].val.i == 0x00002000)
539 else if (iptr[0].val.i == 0x00004000)
541 else if (iptr[0].val.i == 0x00008000)
543 else if (iptr[0].val.i == 0x00010000)
545 else if (iptr[0].val.i == 0x00020000)
547 else if (iptr[0].val.i == 0x00040000)
549 else if (iptr[0].val.i == 0x00080000)
551 else if (iptr[0].val.i == 0x00100000)
553 else if (iptr[0].val.i == 0x00200000)
555 else if (iptr[0].val.i == 0x00400000)
557 else if (iptr[0].val.i == 0x00800000)
559 else if (iptr[0].val.i == 0x01000000)
561 else if (iptr[0].val.i == 0x02000000)
563 else if (iptr[0].val.i == 0x04000000)
565 else if (iptr[0].val.i == 0x08000000)
567 else if (iptr[0].val.i == 0x10000000)
569 else if (iptr[0].val.i == 0x20000000)
571 else if (iptr[0].val.i == 0x40000000)
573 else if (iptr[0].val.i == 0x80000000)
579 iptr[0].opc = ICMD_IDIVPOW2;
580 goto icmd_iconst_tail;
582 #if !defined(NO_DIV_OPT)
583 if (iptr[0].val.i == 0x10001) {
584 iptr[0].opc = ICMD_IREM0X10001;
585 goto icmd_iconst_tail;
588 if ((iptr[0].val.i == 0x00000002) ||
589 (iptr[0].val.i == 0x00000004) ||
590 (iptr[0].val.i == 0x00000008) ||
591 (iptr[0].val.i == 0x00000010) ||
592 (iptr[0].val.i == 0x00000020) ||
593 (iptr[0].val.i == 0x00000040) ||
594 (iptr[0].val.i == 0x00000080) ||
595 (iptr[0].val.i == 0x00000100) ||
596 (iptr[0].val.i == 0x00000200) ||
597 (iptr[0].val.i == 0x00000400) ||
598 (iptr[0].val.i == 0x00000800) ||
599 (iptr[0].val.i == 0x00001000) ||
600 (iptr[0].val.i == 0x00002000) ||
601 (iptr[0].val.i == 0x00004000) ||
602 (iptr[0].val.i == 0x00008000) ||
603 (iptr[0].val.i == 0x00010000) ||
604 (iptr[0].val.i == 0x00020000) ||
605 (iptr[0].val.i == 0x00040000) ||
606 (iptr[0].val.i == 0x00080000) ||
607 (iptr[0].val.i == 0x00100000) ||
608 (iptr[0].val.i == 0x00200000) ||
609 (iptr[0].val.i == 0x00400000) ||
610 (iptr[0].val.i == 0x00800000) ||
611 (iptr[0].val.i == 0x01000000) ||
612 (iptr[0].val.i == 0x02000000) ||
613 (iptr[0].val.i == 0x04000000) ||
614 (iptr[0].val.i == 0x08000000) ||
615 (iptr[0].val.i == 0x10000000) ||
616 (iptr[0].val.i == 0x20000000) ||
617 (iptr[0].val.i == 0x40000000) ||
618 (iptr[0].val.i == 0x80000000)) {
619 iptr[0].opc = ICMD_IREMPOW2;
621 goto icmd_iconst_tail;
626 iptr[0].opc = ICMD_IANDCONST;
627 goto icmd_iconst_tail;
629 iptr[0].opc = ICMD_IORCONST;
630 goto icmd_iconst_tail;
632 iptr[0].opc = ICMD_IXORCONST;
633 goto icmd_iconst_tail;
635 iptr[0].opc = ICMD_ISHLCONST;
636 goto icmd_iconst_tail;
638 iptr[0].opc = ICMD_ISHRCONST;
639 goto icmd_iconst_tail;
641 iptr[0].opc = ICMD_IUSHRCONST;
642 goto icmd_iconst_tail;
643 #if SUPPORT_LONG_SHIFT
645 iptr[0].opc = ICMD_LSHLCONST;
646 goto icmd_lconst_tail;
648 iptr[0].opc = ICMD_LSHRCONST;
649 goto icmd_lconst_tail;
651 iptr[0].opc = ICMD_LUSHRCONST;
652 goto icmd_lconst_tail;
655 iptr[0].opc = ICMD_IFEQ;
657 iptr[0].op1 = iptr[1].op1;
660 /* iptr[1].opc = ICMD_NOP; */
662 tbptr = block + block_index[iptr->op1];
664 iptr[0].target = (void *) tbptr;
666 MARKREACHED(tbptr, copy);
667 COUNT(count_pcmd_bra);
670 iptr[0].opc = ICMD_IFLT;
671 goto icmd_if_icmp_tail;
673 iptr[0].opc = ICMD_IFLE;
674 goto icmd_if_icmp_tail;
676 iptr[0].opc = ICMD_IFNE;
677 goto icmd_if_icmp_tail;
679 iptr[0].opc = ICMD_IFGT;
680 goto icmd_if_icmp_tail;
682 iptr[0].opc = ICMD_IFGE;
683 goto icmd_if_icmp_tail;
692 COUNT(count_pcmd_load);
694 switch (iptr[1].opc) {
697 iptr[0].opc = ICMD_LADDCONST;
699 iptr[1].opc = ICMD_NOP;
700 OP1_1(TYPE_LNG,TYPE_LNG);
701 COUNT(count_pcmd_op);
704 iptr[0].opc = ICMD_LSUBCONST;
705 goto icmd_lconst_tail;
709 iptr[0].opc = ICMD_LMULCONST;
710 #if defined(__I386__)
711 method_uses_edx = true;
713 goto icmd_lconst_tail;
717 if (iptr[0].val.l == 0x00000002)
719 else if (iptr[0].val.l == 0x00000004)
721 else if (iptr[0].val.l == 0x00000008)
723 else if (iptr[0].val.l == 0x00000010)
725 else if (iptr[0].val.l == 0x00000020)
727 else if (iptr[0].val.l == 0x00000040)
729 else if (iptr[0].val.l == 0x00000080)
731 else if (iptr[0].val.l == 0x00000100)
733 else if (iptr[0].val.l == 0x00000200)
735 else if (iptr[0].val.l == 0x00000400)
737 else if (iptr[0].val.l == 0x00000800)
739 else if (iptr[0].val.l == 0x00001000)
741 else if (iptr[0].val.l == 0x00002000)
743 else if (iptr[0].val.l == 0x00004000)
745 else if (iptr[0].val.l == 0x00008000)
747 else if (iptr[0].val.l == 0x00010000)
749 else if (iptr[0].val.l == 0x00020000)
751 else if (iptr[0].val.l == 0x00040000)
753 else if (iptr[0].val.l == 0x00080000)
755 else if (iptr[0].val.l == 0x00100000)
757 else if (iptr[0].val.l == 0x00200000)
759 else if (iptr[0].val.l == 0x00400000)
761 else if (iptr[0].val.l == 0x00800000)
763 else if (iptr[0].val.l == 0x01000000)
765 else if (iptr[0].val.l == 0x02000000)
767 else if (iptr[0].val.l == 0x04000000)
769 else if (iptr[0].val.l == 0x08000000)
771 else if (iptr[0].val.l == 0x10000000)
773 else if (iptr[0].val.l == 0x20000000)
775 else if (iptr[0].val.l == 0x40000000)
777 else if (iptr[0].val.l == 0x80000000)
783 iptr[0].opc = ICMD_LDIVPOW2;
784 goto icmd_lconst_tail;
786 #if !defined(NO_DIV_OPT)
787 if (iptr[0].val.l == 0x10001) {
788 iptr[0].opc = ICMD_LREM0X10001;
789 goto icmd_lconst_tail;
792 if ((iptr[0].val.l == 0x00000002) ||
793 (iptr[0].val.l == 0x00000004) ||
794 (iptr[0].val.l == 0x00000008) ||
795 (iptr[0].val.l == 0x00000010) ||
796 (iptr[0].val.l == 0x00000020) ||
797 (iptr[0].val.l == 0x00000040) ||
798 (iptr[0].val.l == 0x00000080) ||
799 (iptr[0].val.l == 0x00000100) ||
800 (iptr[0].val.l == 0x00000200) ||
801 (iptr[0].val.l == 0x00000400) ||
802 (iptr[0].val.l == 0x00000800) ||
803 (iptr[0].val.l == 0x00001000) ||
804 (iptr[0].val.l == 0x00002000) ||
805 (iptr[0].val.l == 0x00004000) ||
806 (iptr[0].val.l == 0x00008000) ||
807 (iptr[0].val.l == 0x00010000) ||
808 (iptr[0].val.l == 0x00020000) ||
809 (iptr[0].val.l == 0x00040000) ||
810 (iptr[0].val.l == 0x00080000) ||
811 (iptr[0].val.l == 0x00100000) ||
812 (iptr[0].val.l == 0x00200000) ||
813 (iptr[0].val.l == 0x00400000) ||
814 (iptr[0].val.l == 0x00800000) ||
815 (iptr[0].val.l == 0x01000000) ||
816 (iptr[0].val.l == 0x02000000) ||
817 (iptr[0].val.l == 0x04000000) ||
818 (iptr[0].val.l == 0x08000000) ||
819 (iptr[0].val.l == 0x10000000) ||
820 (iptr[0].val.l == 0x20000000) ||
821 (iptr[0].val.l == 0x40000000) ||
822 (iptr[0].val.l == 0x80000000)) {
823 iptr[0].opc = ICMD_LREMPOW2;
825 goto icmd_lconst_tail;
832 iptr[0].opc = ICMD_LANDCONST;
833 goto icmd_lconst_tail;
835 iptr[0].opc = ICMD_LORCONST;
836 goto icmd_lconst_tail;
838 iptr[0].opc = ICMD_LXORCONST;
839 goto icmd_lconst_tail;
841 #if !defined(NOLONG_CONDITIONAL)
843 if ((len > 1) && (iptr[2].val.i == 0)) {
844 switch (iptr[2].opc) {
846 iptr[0].opc = ICMD_IF_LEQ;
847 icmd_lconst_lcmp_tail:
848 iptr[0].op1 = iptr[2].op1;
851 /* iptr[1].opc = ICMD_NOP;
852 iptr[2].opc = ICMD_NOP; */
854 tbptr = block + block_index[iptr->op1];
856 iptr[0].target = (void *) tbptr;
858 MARKREACHED(tbptr, copy);
859 COUNT(count_pcmd_bra);
860 COUNT(count_pcmd_op);
863 iptr[0].opc = ICMD_IF_LNE;
864 goto icmd_lconst_lcmp_tail;
866 iptr[0].opc = ICMD_IF_LLT;
867 goto icmd_lconst_lcmp_tail;
869 iptr[0].opc = ICMD_IF_LGT;
870 goto icmd_lconst_lcmp_tail;
872 iptr[0].opc = ICMD_IF_LLE;
873 goto icmd_lconst_lcmp_tail;
875 iptr[0].opc = ICMD_IF_LGE;
876 goto icmd_lconst_lcmp_tail;
879 } /* switch (iptr[2].opc) */
880 } /* if (iptr[2].val.i == 0) */
893 COUNT(count_pcmd_load);
897 COUNT(count_pcmd_load);
901 COUNT(count_pcmd_load);
905 /* pop 0 push 1 load */
912 COUNT(count_load_instruction);
913 i = opcode-ICMD_ILOAD;
914 iptr->op1 = argren[iptr->op1];
915 locals[iptr->op1][i].type = i;
916 LOAD(i, LOCALVAR, iptr->op1);
922 #if defined(__I386__)
923 method_uses_edx = true;
929 COUNT(count_check_null);
930 COUNT(count_check_bound);
931 COUNT(count_pcmd_mem);
932 OP2IAT_1(opcode-ICMD_IALOAD);
938 COUNT(count_check_null);
939 COUNT(count_check_bound);
940 COUNT(count_pcmd_mem);
944 /* pop 0 push 0 iinc */
950 count_store_depth[10]++;
952 count_store_depth[i]++;
957 if ((copy->varkind == LOCALVAR) &&
958 (copy->varnum == iptr->op1)) {
959 copy->varkind = TEMPVAR;
968 /* pop 1 push 0 store */
978 i = opcode - ICMD_ISTORE;
979 locals[iptr->op1][i].type = i;
984 count_store_length[20]++;
986 count_store_length[i]++;
989 count_store_depth[10]++;
991 count_store_depth[i]++;
993 copy = curstack->prev;
996 if ((copy->varkind == LOCALVAR) &&
997 (copy->varnum == iptr->op1)) {
998 copy->varkind = TEMPVAR;
1004 if ((new - curstack) == 1) {
1005 curstack->varkind = LOCALVAR;
1006 curstack->varnum = iptr->op1;
1008 STORE(opcode-ICMD_ISTORE);
1016 #if defined(__I386__)
1017 method_uses_edx = true;
1021 COUNT(count_check_null);
1022 COUNT(count_check_bound);
1023 COUNT(count_pcmd_mem);
1024 OP3TIA_0(opcode-ICMD_IASTORE);
1030 COUNT(count_check_null);
1031 COUNT(count_check_bound);
1032 COUNT(count_pcmd_mem);
1034 #if defined(__I386__)
1035 method_uses_edx = true;
1050 COUNT(count_pcmd_return);
1051 OP1_0(opcode-ICMD_IRETURN);
1052 superblockend = true;
1056 COUNT(count_check_null);
1060 superblockend = true;
1063 case ICMD_PUTSTATIC:
1064 COUNT(count_pcmd_mem);
1068 /* pop 1 push 0 branch */
1071 case ICMD_IFNONNULL:
1072 COUNT(count_pcmd_bra);
1074 tbptr = block + block_index[iptr->op1];
1076 iptr[0].target = (void *) tbptr;
1078 MARKREACHED(tbptr, copy);
1087 COUNT(count_pcmd_bra);
1088 #ifdef CONDITIONAL_LOADCONST
1090 tbptr = block + b_index;
1091 if ((b_count >= 3) &&
1092 ((b_index + 2) == block_index[iptr[0].op1]) &&
1093 (tbptr[1].pre_count == 1) &&
1094 (iptr[1].opc == ICMD_ICONST) &&
1095 (iptr[2].opc == ICMD_GOTO) &&
1096 ((b_index + 3) == block_index[iptr[2].op1]) &&
1097 (tbptr[2].pre_count == 1) &&
1098 (iptr[3].opc == ICMD_ICONST)) {
1099 OP1_1(TYPE_INT, TYPE_INT);
1100 switch (iptr[0].opc) {
1102 iptr[0].opc = ICMD_IFNE_ICONST;
1105 iptr[0].opc = ICMD_IFEQ_ICONST;
1108 iptr[0].opc = ICMD_IFGE_ICONST;
1111 iptr[0].opc = ICMD_IFLT_ICONST;
1114 iptr[0].opc = ICMD_IFLE_ICONST;
1117 iptr[0].opc = ICMD_IFGT_ICONST;
1120 iptr[0].val.i = iptr[1].val.i;
1121 iptr[1].opc = ICMD_ELSE_ICONST;
1122 iptr[1].val.i = iptr[3].val.i;
1123 iptr[2].opc = ICMD_NOP;
1124 iptr[3].opc = ICMD_NOP;
1125 tbptr[1].flags = BBDELETED;
1126 tbptr[2].flags = BBDELETED;
1127 tbptr[1].icount = 0;
1128 tbptr[2].icount = 0;
1129 if (tbptr[3].pre_count == 2) {
1130 len += tbptr[3].icount + 3;
1131 bptr->icount += tbptr[3].icount + 3;
1132 tbptr[3].flags = BBDELETED;
1133 tbptr[3].icount = 0;
1146 tbptr = block + block_index[iptr->op1];
1148 iptr[0].target = (void *) tbptr;
1150 MARKREACHED(tbptr, copy);
1153 /* pop 0 push 0 branch */
1156 COUNT(count_pcmd_bra);
1157 tbptr = block + block_index[iptr->op1];
1159 iptr[0].target = (void *) tbptr;
1161 MARKREACHED(tbptr, copy);
1163 superblockend = true;
1166 /* pop 1 push 0 table branch */
1168 case ICMD_TABLESWITCH:
1169 COUNT(count_pcmd_table);
1171 s4ptr = iptr->val.a;
1172 tbptr = block + block_index[*s4ptr++]; /* default */
1173 MARKREACHED(tbptr, copy);
1174 i = *s4ptr++; /* low */
1175 i = *s4ptr++ - i + 1; /* high */
1177 tptr = DMNEW(void*, i+1);
1178 iptr->target = (void *) tptr;
1180 tptr[0] = (void *) tbptr;
1184 tbptr = block + block_index[*s4ptr++];
1186 tptr[0] = (void *) tbptr;
1189 MARKREACHED(tbptr, copy);
1192 superblockend = true;
1195 /* pop 1 push 0 table branch */
1197 case ICMD_LOOKUPSWITCH:
1198 COUNT(count_pcmd_table);
1200 s4ptr = iptr->val.a;
1201 tbptr = block + block_index[*s4ptr++]; /* default */
1202 MARKREACHED(tbptr, copy);
1203 i = *s4ptr++; /* count */
1205 tptr = DMNEW(void*, i+1);
1206 iptr->target = (void *) tptr;
1208 tptr[0] = (void *) tbptr;
1212 tbptr = block + block_index[s4ptr[1]];
1214 tptr[0] = (void *) tbptr;
1217 MARKREACHED(tbptr, copy);
1221 superblockend = true;
1224 case ICMD_NULLCHECKPOP:
1225 case ICMD_MONITORENTER:
1226 COUNT(count_check_null);
1227 case ICMD_MONITOREXIT:
1231 /* pop 2 push 0 branch */
1233 case ICMD_IF_ICMPEQ:
1234 case ICMD_IF_ICMPNE:
1235 case ICMD_IF_ICMPLT:
1236 case ICMD_IF_ICMPGE:
1237 case ICMD_IF_ICMPGT:
1238 case ICMD_IF_ICMPLE:
1239 COUNT(count_pcmd_bra);
1241 tbptr = block + block_index[iptr->op1];
1243 iptr[0].target = (void *) tbptr;
1245 MARKREACHED(tbptr, copy);
1248 case ICMD_IF_ACMPEQ:
1249 case ICMD_IF_ACMPNE:
1250 COUNT(count_pcmd_bra);
1252 tbptr = block + block_index[iptr->op1];
1254 iptr[0].target = (void *) tbptr;
1256 MARKREACHED(tbptr, copy);
1262 COUNT(count_check_null);
1263 COUNT(count_pcmd_mem);
1264 OPTT2_0(iptr->op1,TYPE_ADR);
1269 if (! IS_2_WORD_TYPE(curstack->type)) {
1270 OP1_0ANY; /* second pop */
1273 iptr->opc = ICMD_POP;
1277 /* pop 0 push 1 dup */
1280 COUNT(count_dup_instruction);
1286 if (IS_2_WORD_TYPE(curstack->type)) {
1287 iptr->opc = ICMD_DUP;
1293 NEWSTACK(copy->prev->type, copy->prev->varkind,
1294 copy->prev->varnum);
1295 NEWSTACK(copy->type, copy->varkind,
1302 /* pop 2 push 3 dup */
1310 if (IS_2_WORD_TYPE(curstack->type)) {
1311 iptr->opc = ICMD_DUP_X1;
1319 /* pop 3 push 4 dup */
1323 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1324 iptr->opc = ICMD_DUP_X1;
1334 if (IS_2_WORD_TYPE(curstack->type)) {
1335 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1336 iptr->opc = ICMD_DUP_X1;
1340 iptr->opc = ICMD_DUP_X2;
1346 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1347 iptr->opc = ICMD_DUP2_X1;
1356 /* pop 2 push 2 swap */
1365 #if !SUPPORT_DIVISION
1366 iptr[0].opc = ICMD_BUILTIN2;
1367 iptr[0].op1 = TYPE_INT;
1368 iptr[0].val.a = BUILTIN_idiv;
1369 isleafmethod = false;
1374 #if !SUPPORT_DIVISION
1375 iptr[0].opc = ICMD_BUILTIN2;
1376 iptr[0].op1 = TYPE_INT;
1377 iptr[0].val.a = BUILTIN_irem;
1378 isleafmethod = false;
1381 #if defined(__I386__)
1382 method_uses_edx = true;
1388 #if defined(__I386__)
1389 method_uses_ecx = true;
1397 COUNT(count_pcmd_op);
1402 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1403 iptr[0].opc = ICMD_BUILTIN2;
1404 iptr[0].op1 = TYPE_LNG;
1405 iptr[0].val.a = BUILTIN_ldiv;
1406 isleafmethod = false;
1411 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1412 iptr[0].opc = ICMD_BUILTIN2;
1413 iptr[0].op1 = TYPE_LNG;
1414 iptr[0].val.a = BUILTIN_lrem;
1415 isleafmethod = false;
1420 #if defined(__I386__)
1421 method_uses_edx = true;
1428 /* XXX DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1429 COUNT(count_pcmd_op);
1436 COUNT(count_pcmd_op);
1438 #if defined(__I386__)
1439 method_uses_ecx = true;
1440 method_uses_edx = true;
1449 COUNT(count_pcmd_op);
1458 COUNT(count_pcmd_op);
1463 COUNT(count_pcmd_op);
1464 #if !defined(NOLONG_CONDITIONAL)
1465 if ((len > 0) && (iptr[1].val.i == 0)) {
1466 switch (iptr[1].opc) {
1468 iptr[0].opc = ICMD_IF_LCMPEQ;
1470 iptr[0].op1 = iptr[1].op1;
1473 /* iptr[1].opc = ICMD_NOP; */
1475 tbptr = block + block_index[iptr->op1];
1477 iptr[0].target = (void *) tbptr;
1479 MARKREACHED(tbptr, copy);
1480 COUNT(count_pcmd_bra);
1483 iptr[0].opc = ICMD_IF_LCMPNE;
1484 goto icmd_lcmp_if_tail;
1486 iptr[0].opc = ICMD_IF_LCMPLT;
1487 goto icmd_lcmp_if_tail;
1489 iptr[0].opc = ICMD_IF_LCMPGT;
1490 goto icmd_lcmp_if_tail;
1492 iptr[0].opc = ICMD_IF_LCMPLE;
1493 goto icmd_lcmp_if_tail;
1495 iptr[0].opc = ICMD_IF_LCMPGE;
1496 goto icmd_lcmp_if_tail;
1498 OPTT2_1(TYPE_LNG, TYPE_INT);
1503 OPTT2_1(TYPE_LNG, TYPE_INT);
1507 COUNT(count_pcmd_op);
1508 OPTT2_1(TYPE_FLT, TYPE_INT);
1512 COUNT(count_pcmd_op);
1513 OPTT2_1(TYPE_DBL, TYPE_INT);
1521 case ICMD_INT2SHORT:
1522 COUNT(count_pcmd_op);
1523 OP1_1(TYPE_INT, TYPE_INT);
1526 COUNT(count_pcmd_op);
1527 OP1_1(TYPE_LNG, TYPE_LNG);
1530 COUNT(count_pcmd_op);
1531 OP1_1(TYPE_FLT, TYPE_FLT);
1534 COUNT(count_pcmd_op);
1535 OP1_1(TYPE_DBL, TYPE_DBL);
1539 COUNT(count_pcmd_op);
1540 OP1_1(TYPE_INT, TYPE_LNG);
1541 #if defined(__I386__)
1542 method_uses_edx = true;
1546 COUNT(count_pcmd_op);
1547 OP1_1(TYPE_INT, TYPE_FLT);
1550 COUNT(count_pcmd_op);
1551 OP1_1(TYPE_INT, TYPE_DBL);
1554 COUNT(count_pcmd_op);
1555 OP1_1(TYPE_LNG, TYPE_INT);
1558 COUNT(count_pcmd_op);
1559 OP1_1(TYPE_LNG, TYPE_FLT);
1562 COUNT(count_pcmd_op);
1563 OP1_1(TYPE_LNG, TYPE_DBL);
1566 COUNT(count_pcmd_op);
1567 OP1_1(TYPE_FLT, TYPE_INT);
1570 COUNT(count_pcmd_op);
1571 OP1_1(TYPE_FLT, TYPE_LNG);
1572 #if defined(__I386__)
1573 method_uses_edx = true;
1577 COUNT(count_pcmd_op);
1578 OP1_1(TYPE_FLT, TYPE_DBL);
1581 COUNT(count_pcmd_op);
1582 OP1_1(TYPE_DBL, TYPE_INT);
1585 COUNT(count_pcmd_op);
1586 OP1_1(TYPE_DBL, TYPE_LNG);
1587 #if defined(__I386__)
1588 method_uses_edx = true;
1592 COUNT(count_pcmd_op);
1593 OP1_1(TYPE_DBL, TYPE_FLT);
1596 case ICMD_CHECKCAST:
1597 OP1_1(TYPE_ADR, TYPE_ADR);
1598 #if defined(__I386__)
1599 method_uses_edx = true;
1603 case ICMD_INSTANCEOF:
1604 #if defined(__I386__)
1605 method_uses_edx = true;
1607 case ICMD_ARRAYLENGTH:
1608 OP1_1(TYPE_ADR, TYPE_INT);
1612 case ICMD_ANEWARRAY:
1613 OP1_1(TYPE_INT, TYPE_ADR);
1617 COUNT(count_check_null);
1618 COUNT(count_pcmd_mem);
1619 OP1_1(TYPE_ADR, iptr->op1);
1624 case ICMD_GETSTATIC:
1625 COUNT(count_pcmd_mem);
1635 tbptr = block + block_index[iptr->op1];
1637 iptr[0].target = (void *) tbptr;
1639 /* XXX This is a dirty hack. The typechecker
1640 * needs it because the OP1_0ANY below
1641 * overwrites iptr->dst.
1643 iptr->val.a = (void*) iptr->dst;
1645 tbptr->type=BBTYPE_SBR;
1647 MARKREACHED(tbptr, copy);
1651 /* pop many push any */
1653 case ICMD_INVOKEVIRTUAL:
1654 case ICMD_INVOKESPECIAL:
1655 case ICMD_INVOKEINTERFACE:
1656 case ICMD_INVOKESTATIC:
1657 COUNT(count_pcmd_met);
1659 methodinfo *m = iptr->val.a;
1660 if (m->flags & ACC_STATIC)
1661 {COUNT(count_check_null);}
1663 if (i > arguments_num)
1666 #if defined(__X86_64__)
1674 (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1678 stackargs += (iarg < intreg_argnum) ? 0 : (iarg - intreg_argnum);
1679 stackargs += (farg < fltreg_argnum) ? 0 : (farg - fltreg_argnum);
1684 if (!(copy->flags & SAVEDVAR)) {
1685 copy->varkind = ARGVAR;
1686 if (IS_FLT_DBL_TYPE(copy->type)) {
1687 if (--farg < fltreg_argnum) {
1688 copy->varnum = farg;
1690 copy->varnum = --stackargs + intreg_argnum;
1693 if (--iarg < intreg_argnum) {
1694 copy->varnum = iarg;
1696 copy->varnum = --stackargs + intreg_argnum;
1700 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1708 if (! (copy->flags & SAVEDVAR)) {
1709 copy->varkind = ARGVAR;
1716 copy->flags |= SAVEDVAR;
1721 if (m->returntype != TYPE_VOID) {
1722 OP0_1(m->returntype);
1728 /* XXX DEBUG */ /*dolog("builtin3");*/
1730 if (! (curstack->flags & SAVEDVAR)) {
1731 curstack->varkind = ARGVAR;
1732 curstack->varnum = 2;
1734 if (3 > arguments_num) {
1742 /* XXX DEBUG */ /*dolog("builtin2");*/
1743 if (!(curstack->flags & SAVEDVAR)) {
1744 curstack->varkind = ARGVAR;
1745 curstack->varnum = 1;
1747 if (2 > arguments_num) {
1755 /* XXX DEBUG */ /*dolog("builtin1");*/
1756 if (!(curstack->flags & SAVEDVAR)) {
1757 curstack->varkind = ARGVAR;
1758 curstack->varnum = 0;
1760 if (1 > arguments_num) {
1766 copy->flags |= SAVEDVAR;
1769 if (iptr->op1 != TYPE_VOID)
1773 case ICMD_MULTIANEWARRAY:
1776 if ((i + intreg_argnum) > arguments_num)
1777 arguments_num = i + intreg_argnum;
1780 if (! (copy->flags & SAVEDVAR)) {
1781 copy->varkind = ARGVAR;
1782 copy->varnum = i + intreg_argnum;
1787 copy->flags |= SAVEDVAR;
1795 case ICMD_CLEAR_ARGREN:
1796 for (i = iptr->op1; i<maxlocals; i++)
1798 iptr->opc = opcode = ICMD_NOP;
1802 case ICMD_READONLY_ARG:
1803 case ICMD_READONLY_ARG+1:
1804 case ICMD_READONLY_ARG+2:
1805 case ICMD_READONLY_ARG+3:
1806 case ICMD_READONLY_ARG+4:
1809 if (curstack->varkind == LOCALVAR) {
1810 i = curstack->varnum;
1811 argren[iptr->op1] = i;
1814 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
1820 printf("ICMD %d at %d\n", iptr->opc, (int)(iptr-instr));
1821 panic("Missing ICMD code during stack analysis");
1826 /* XXX DEBUG */ /*dolog("iptr++");*/
1828 } /* while instructions */
1829 bptr->outstack = curstack;
1830 bptr->outdepth = stackdepth;
1834 superblockend = true;
1836 } /* while blocks */
1837 } while (repeat && !deadcode);
1840 if (block_count > count_max_basic_blocks)
1841 count_max_basic_blocks = block_count;
1842 count_basic_blocks += block_count;
1843 if (instr_count > count_max_javainstr)
1844 count_max_javainstr = instr_count;
1845 count_javainstr += instr_count;
1846 if (stack_count > count_upper_bound_new_stack)
1847 count_upper_bound_new_stack = stack_count;
1848 if ((new - stack) > count_max_new_stack)
1849 count_max_new_stack = (new - stack);
1851 b_count = block_count;
1853 while (--b_count >= 0) {
1854 if (bptr->flags > BBREACHED) {
1855 if (bptr->indepth >= 10)
1856 count_block_stack[10]++;
1858 count_block_stack[bptr->indepth]++;
1861 count_block_size_distribution[len]++;
1863 count_block_size_distribution[10]++;
1865 count_block_size_distribution[11]++;
1867 count_block_size_distribution[12]++;
1869 count_block_size_distribution[13]++;
1871 count_block_size_distribution[14]++;
1873 count_block_size_distribution[15]++;
1875 count_block_size_distribution[16]++;
1877 count_block_size_distribution[17]++;
1883 count_analyse_iterations[0]++;
1884 else if (loops == 2)
1885 count_analyse_iterations[1]++;
1886 else if (loops == 3)
1887 count_analyse_iterations[2]++;
1888 else if (loops == 4)
1889 count_analyse_iterations[3]++;
1891 count_analyse_iterations[4]++;
1893 if (block_count <= 5)
1894 count_method_bb_distribution[0]++;
1895 else if (block_count <= 10)
1896 count_method_bb_distribution[1]++;
1897 else if (block_count <= 15)
1898 count_method_bb_distribution[2]++;
1899 else if (block_count <= 20)
1900 count_method_bb_distribution[3]++;
1901 else if (block_count <= 30)
1902 count_method_bb_distribution[4]++;
1903 else if (block_count <= 40)
1904 count_method_bb_distribution[5]++;
1905 else if (block_count <= 50)
1906 count_method_bb_distribution[6]++;
1907 else if (block_count <= 75)
1908 count_method_bb_distribution[7]++;
1910 count_method_bb_distribution[8]++;
1915 void icmd_print_stack(stackptr s)
1932 /* XXX remove */ /* printf("(%d)",s->flags); fflush(stdout); */
1933 if (s->flags & SAVEDVAR)
1934 switch (s->varkind) {
1936 if (s->flags & INMEMORY)
1937 printf((regs_ok) ? " M%02d" : " M??", s->regoff);
1938 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1939 printf((regs_ok) ? " F%02d" : " F??", s->regoff);
1941 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1945 printf(" I%02d", s->varnum);
1948 printf(" L%02d", s->varnum);
1951 printf(" A%02d", s->varnum);
1954 printf(" !%02d", j);
1957 switch (s->varkind) {
1959 if (s->flags & INMEMORY)
1960 printf((regs_ok) ? " m%02d" : " m??", s->regoff);
1961 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1962 printf((regs_ok) ? " f%02d" : " f??", s->regoff);
1964 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1968 printf(" i%02d", s->varnum);
1971 printf(" l%02d", s->varnum);
1974 printf(" a%02d", s->varnum);
1977 printf(" ?%02d", j);
1985 static void print_reg(stackptr s) {
1987 if (s->flags & SAVEDVAR)
1988 switch (s->varkind) {
1990 if (s->flags & INMEMORY)
1991 printf(" tm%02d", s->regoff);
1993 printf(" tr%02d", s->regoff);
1996 printf(" s %02d", s->varnum);
1999 printf(" l %02d", s->varnum);
2002 printf(" a %02d", s->varnum);
2005 printf(" ! %02d", s->varnum);
2008 switch (s->varkind) {
2010 if (s->flags & INMEMORY)
2011 printf(" Tm%02d", s->regoff);
2013 printf(" Tr%02d", s->regoff);
2016 printf(" S %02d", s->varnum);
2019 printf(" L %02d", s->varnum);
2022 printf(" A %02d", s->varnum);
2025 printf(" ? %02d", s->varnum);
2035 char *icmd_builtin_name(functionptr bptr)
2037 builtin_descriptor *bdesc = builtin_desc;
2038 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
2040 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
2044 static char *jit_type[] = {
2053 void show_icmd_method()
2056 s4 *s4ptr; /* used */
2061 utf_fprint(stdout, class->name);
2063 utf_fprint(stdout, method->name);
2065 utf_fprint(stdout, method->descriptor);
2066 printf ("\n\nMax locals: %d\n", (int) maxlocals);
2067 printf ("Max stack: %d\n", (int) maxstack);
2069 printf ("Exceptions (Number: %d):\n", exceptiontablelength);
2070 for (ex = extable; ex != NULL; ex = ex->down) {
2071 printf(" L%03d ... ", ex->start->debug_nr );
2072 printf("L%03d = ", ex->end->debug_nr);
2073 printf("L%03d\n", ex->handler->debug_nr);
2076 printf ("Local Table:\n");
2077 for (i = 0; i < maxlocals; i++) {
2078 printf(" %3d: ", i);
2079 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2080 if (locals[i][j].type >= 0) {
2081 printf(" (%s) ", jit_type[j]);
2082 if (locals[i][j].flags & INMEMORY)
2083 printf((regs_ok) ? "m%2d" : "m??", locals[i][j].regoff);
2084 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2085 printf((regs_ok) ? "f%02d" : "f??", locals[i][j].regoff);
2087 if (regs_ok) printf("%3s",regs[locals[i][j].regoff]); else printf("???");
2094 printf ("Interface Table:\n");
2095 for (i = 0; i < maxstack; i++) {
2096 if ((interfaces[i][0].type >= 0) || (interfaces[i][1].type >= 0) ||
2097 (interfaces[i][2].type >= 0) || (interfaces[i][3].type >= 0) ||
2098 (interfaces[i][4].type >= 0)) {
2099 printf(" %3d: ", i);
2100 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2101 if (interfaces[i][j].type >= 0) {
2102 printf(" (%s) ", jit_type[j]);
2103 if (interfaces[i][j].flags & SAVEDVAR) {
2104 if (interfaces[i][j].flags & INMEMORY)
2105 printf((regs_ok) ? "M%2d" : "M??", interfaces[i][j].regoff);
2106 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2107 printf((regs_ok) ? "F%02d" : "F??", interfaces[i][j].regoff);
2109 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2113 if (interfaces[i][j].flags & INMEMORY)
2114 printf((regs_ok) ? "m%2d" : "m??", interfaces[i][j].regoff);
2115 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2116 printf((regs_ok) ? "f%02d" : "f??", interfaces[i][j].regoff);
2118 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2127 if (showdisassemble) {
2128 #if defined(__I386__) || defined(__X86_64__)
2132 u1ptr = method->mcode + dseglen;
2133 for (i = 0; i < block[0].mpc; i++, u1ptr++) {
2134 a = disassinstr(u1ptr, i);
2140 s4ptr = (s4 *) (method->mcode + dseglen);
2141 for (i = 0; i < block[0].mpc; i += 4, s4ptr++) {
2142 disassinstr(*s4ptr, i);
2149 for (bptr = block; bptr != NULL; bptr = bptr->next) {
2150 show_icmd_block(bptr);
2155 void show_icmd_block(basicblock *bptr)
2159 s4 *s4ptr; /* used */
2162 if (bptr->flags != BBDELETED) {
2163 deadcode = bptr->flags <= BBREACHED;
2166 for (j = method->maxstack; j > 0; j--)
2169 icmd_print_stack(bptr->instack);
2170 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2171 iptr = bptr->iinstr;
2173 for (i=0; i < bptr->icount; i++, iptr++) {
2176 for (j = method->maxstack; j > 0; j--)
2180 icmd_print_stack(iptr->dst);
2181 printf("] %4d ", i);
2182 /* XXX remove */ /*fflush(stdout);*/
2183 show_icmd(iptr,deadcode);
2187 if (showdisassemble && (!deadcode)) {
2188 #if defined(__I386__) || defined(__X86_64__)
2194 u1ptr = method->mcode + dseglen + i;
2196 if (bptr->next != NULL) {
2197 for (; i < bptr->next->mpc; i++, u1ptr++) {
2198 a = disassinstr(u1ptr, i);
2205 for (; u1ptr < (u1 *) (method->mcode + method->mcodelength); i++, u1ptr++) {
2206 a = disassinstr(u1ptr, i);
2215 s4ptr = (s4 *) (method->mcode + dseglen + i);
2217 if (bptr->next != NULL) {
2218 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2219 disassinstr(*s4ptr, i);
2224 for (; s4ptr < (s4 *) (method->mcode + method->mcodelength); i += 4, s4ptr++) {
2225 disassinstr(*s4ptr, i);
2235 void show_icmd(instruction *iptr,bool deadcode)
2241 printf("%s", icmd_names[iptr->opc]);
2243 switch ((int) iptr->opc) {
2244 case ICMD_IADDCONST:
2245 case ICMD_ISUBCONST:
2246 case ICMD_IMULCONST:
2249 case ICMD_IREM0X10001:
2250 case ICMD_IANDCONST:
2252 case ICMD_IXORCONST:
2253 case ICMD_ISHLCONST:
2254 case ICMD_ISHRCONST:
2255 case ICMD_IUSHRCONST:
2256 case ICMD_LSHLCONST:
2257 case ICMD_LSHRCONST:
2258 case ICMD_LUSHRCONST:
2260 case ICMD_ELSE_ICONST:
2261 case ICMD_IFEQ_ICONST:
2262 case ICMD_IFNE_ICONST:
2263 case ICMD_IFLT_ICONST:
2264 case ICMD_IFGE_ICONST:
2265 case ICMD_IFGT_ICONST:
2266 case ICMD_IFLE_ICONST:
2267 printf(" %d", iptr->val.i);
2270 case ICMD_LADDCONST:
2271 case ICMD_LSUBCONST:
2272 case ICMD_LMULCONST:
2275 case ICMD_LANDCONST:
2277 case ICMD_LXORCONST:
2279 #if defined(__I386__)
2280 printf(" %lld", iptr->val.l);
2282 printf(" %ld", iptr->val.l);
2287 printf(" %f", iptr->val.f);
2291 printf(" %f", iptr->val.d);
2295 printf(" %p", iptr->val.a);
2300 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2301 case ICMD_PUTSTATIC:
2302 case ICMD_GETSTATIC:
2305 ((fieldinfo *) iptr->val.a)->class->name);
2308 ((fieldinfo *) iptr->val.a)->name);
2311 ((fieldinfo *) iptr->val.a)->descriptor);
2316 printf(" %d + %d", iptr->op1, iptr->val.i);
2351 printf(" %d", iptr->op1);
2357 ((classinfo *) iptr->val.a)->name);
2361 switch (iptr->op1) {
2389 case ICMD_ANEWARRAY:
2393 ((classinfo *) iptr->val.a)->name);
2397 case ICMD_MULTIANEWARRAY:
2400 printf(" %d ",iptr->op1);
2401 vft = (vftbl *)iptr->val.a;
2403 utf_fprint(stdout,vft->class->name);
2409 case ICMD_CHECKCAST:
2410 case ICMD_INSTANCEOF:
2412 classinfo *c = iptr->val.a;
2413 if (c->flags & ACC_INTERFACE)
2414 printf(" (INTERFACE) ");
2416 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2417 utf_fprint(stdout, c->name);
2424 printf(" %s", icmd_builtin_name((functionptr) iptr->val.a));
2427 case ICMD_INVOKEVIRTUAL:
2428 case ICMD_INVOKESPECIAL:
2429 case ICMD_INVOKESTATIC:
2430 case ICMD_INVOKEINTERFACE:
2433 ((methodinfo *) iptr->val.a)->class->name);
2436 ((methodinfo *) iptr->val.a)->name);
2445 if (deadcode || !iptr->target)
2446 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2448 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2457 if (deadcode || !iptr->target)
2458 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2460 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2466 case ICMD_IFNONNULL:
2467 case ICMD_IF_ICMPEQ:
2468 case ICMD_IF_ICMPNE:
2469 case ICMD_IF_ICMPLT:
2470 case ICMD_IF_ICMPGE:
2471 case ICMD_IF_ICMPGT:
2472 case ICMD_IF_ICMPLE:
2473 case ICMD_IF_LCMPEQ:
2474 case ICMD_IF_LCMPNE:
2475 case ICMD_IF_LCMPLT:
2476 case ICMD_IF_LCMPGE:
2477 case ICMD_IF_LCMPGT:
2478 case ICMD_IF_LCMPLE:
2479 case ICMD_IF_ACMPEQ:
2480 case ICMD_IF_ACMPNE:
2481 if (deadcode || !iptr->target)
2482 printf(" op1=%d", iptr->op1);
2484 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2487 case ICMD_TABLESWITCH:
2488 s4ptr = (s4*)iptr->val.a;
2490 if (deadcode || !iptr->target) {
2491 printf(" %d;", *s4ptr);
2494 tptr = (void **) iptr->target;
2495 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2499 s4ptr++; /* skip default */
2500 j = *s4ptr++; /* low */
2501 j = *s4ptr++ - j; /* high */
2503 if (deadcode || !*tptr)
2504 printf(" %d", *s4ptr++);
2506 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2513 case ICMD_LOOKUPSWITCH:
2514 s4ptr = (s4*)iptr->val.a;
2516 if (deadcode || !iptr->target) {
2517 printf(" %d;", *s4ptr);
2520 tptr = (void **) iptr->target;
2521 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2524 s4ptr++; /* default */
2525 j = *s4ptr++; /* count */
2528 if (deadcode || !*tptr) {
2529 s4ptr++; /* skip value */
2530 printf(" %d",*s4ptr++);
2533 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2543 * These are local overrides for various environment variables in Emacs.
2544 * Please do not remove this and leave it at the end of the file, where
2545 * Emacs will automagically detect them.
2546 * ---------------------------------------------------------------------
2549 * indent-tabs-mode: t