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 733 2003-12-12 17:29:40Z stefan $
46 #include "toolbox/loging.h"
47 #include "toolbox/memory.h"
50 /* from codegen.inc */
55 #define COUNT(cnt) cnt++
60 #define STACKRESET {curstack=0;stackdepth=0;}
62 #define TYPEPANIC {show_icmd_method();panic("Stack type mismatch");}
63 #define UNDERFLOW {show_icmd_method();panic("Stack underflow");} /* XXX why isn't this caught in parse.c? */
64 #define CURKIND curstack->varkind
65 #define CURTYPE curstack->type
67 #define REQUIRE(num) do { if (stackdepth<(num)) {UNDERFLOW;} } while(0)
68 #define REQUIRE_1 REQUIRE(1)
69 #define REQUIRE_2 REQUIRE(2)
70 #define REQUIRE_3 REQUIRE(3)
71 #define REQUIRE_4 REQUIRE(4)
73 #define NEWSTACK(s,v,n) {new->prev=curstack;new->type=s;new->flags=0; \
74 new->varkind=v;new->varnum=n;curstack=new;new++;}
75 #define NEWSTACKn(s,n) NEWSTACK(s,UNDEFVAR,n)
76 #define NEWSTACK0(s) NEWSTACK(s,UNDEFVAR,0)
77 #define NEWXSTACK {NEWSTACK(TYPE_ADR,STACKVAR,0);curstack=0;}
79 #define SETDST {iptr->dst=curstack;}
81 /* The following macros do NOT check stackdepth, set stackdepth and iptr->dst */
82 #define POP(s) {if(s!=curstack->type){TYPEPANIC;} \
83 if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR;\
84 curstack=curstack->prev;}
85 #define POPANY {if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR; \
86 curstack=curstack->prev;}
87 #define COPY(s,d) {(d)->flags=0;(d)->type=(s)->type;\
88 (d)->varkind=(s)->varkind;(d)->varnum=(s)->varnum;}
89 /******************************/
91 /* The following macros check stackdepth, set stackdepth and itpr->dst */
92 #define PUSHCONST(s){NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
93 #define LOAD(s,v,n) {NEWSTACK(s,v,n);SETDST;stackdepth++;}
94 #define STORE(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
95 #define OP1_0(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
96 #define OP1_0ANY {REQUIRE_1;POPANY;SETDST;stackdepth--;}
97 #define OP0_1(s) {NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
98 #define OP1_1(s,d) {REQUIRE_1;POP(s);NEWSTACKn(d,stackdepth-1);SETDST;}
99 #define OP2_0(s) {REQUIRE_2;POP(s);POP(s);SETDST;stackdepth-=2;}
100 #define OPTT2_0(t,b){REQUIRE_2;POP(t);POP(b);SETDST;stackdepth-=2;}
101 #define OP2_1(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);SETDST;stackdepth--;}
102 #define OP2IAT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(TYPE_ADR);NEWSTACKn(s,stackdepth-2);\
103 SETDST;stackdepth--;}
104 #define OP2IT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(s);NEWSTACKn(s,stackdepth-2);\
105 SETDST;stackdepth--;}
106 #define OPTT2_1(s,d){REQUIRE_2;POP(s);POP(s);NEWSTACKn(d,stackdepth-2);SETDST;stackdepth--;}
107 #define OP2_2(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);\
108 NEWSTACKn(s,stackdepth-1);SETDST;}
109 #define OP3TIA_0(s) {REQUIRE_3;POP(s);POP(TYPE_INT);POP(TYPE_ADR);SETDST;stackdepth-=3;}
110 #define OP3_0(s) {REQUIRE_3;POP(s);POP(s);POP(s);SETDST;stackdepth-=3;}
111 #define POPMANY(i) {REQUIRE(i);stackdepth-=i;while(--i>=0){POPANY;}SETDST;}
112 #define DUP {REQUIRE_1;NEWSTACK(CURTYPE,CURKIND,curstack->varnum);SETDST; \
114 #define SWAP {REQUIRE_2;COPY(curstack,new);POPANY;COPY(curstack,new+1);POPANY;\
115 new[0].prev=curstack;new[1].prev=new;\
116 curstack=new+1;new+=2;SETDST;}
117 #define DUP_X1 {REQUIRE_2;COPY(curstack,new);COPY(curstack,new+2);POPANY;\
118 COPY(curstack,new+1);POPANY;new[0].prev=curstack;\
119 new[1].prev=new;new[2].prev=new+1;\
120 curstack=new+2;new+=3;SETDST;stackdepth++;}
121 #define DUP2_X1 {REQUIRE_3;COPY(curstack,new+1);COPY(curstack,new+4);POPANY;\
122 COPY(curstack,new);COPY(curstack,new+3);POPANY;\
123 COPY(curstack,new+2);POPANY;new[0].prev=curstack;\
124 new[1].prev=new;new[2].prev=new+1;\
125 new[3].prev=new+2;new[4].prev=new+3;\
126 curstack=new+4;new+=5;SETDST;stackdepth+=2;}
127 #define DUP_X2 {REQUIRE_3;COPY(curstack,new);COPY(curstack,new+3);POPANY;\
128 COPY(curstack,new+2);POPANY;COPY(curstack,new+1);POPANY;\
129 new[0].prev=curstack;new[1].prev=new;\
130 new[2].prev=new+1;new[3].prev=new+2;\
131 curstack=new+3;new+=4;SETDST;stackdepth++;}
132 #define DUP2_X2 {REQUIRE_4;COPY(curstack,new+1);COPY(curstack,new+5);POPANY;\
133 COPY(curstack,new);COPY(curstack,new+4);POPANY;\
134 COPY(curstack,new+3);POPANY;COPY(curstack,new+2);POPANY;\
135 new[0].prev=curstack;new[1].prev=new;\
136 new[2].prev=new+1;new[3].prev=new+2;\
137 new[4].prev=new+3;new[5].prev=new+4;\
138 curstack=new+5;new+=6;SETDST;stackdepth+=2;}
139 /******************************/
141 #define COPYCURSTACK(copy) {\
154 copy->varkind=STACKVAR;\
170 if((copy->varkind==STACKVAR)&&(copy->varnum>i))\
171 copy->varkind=TEMPVAR;\
173 copy->varkind=STACKVAR;\
176 interfaces[i][copy->type].type = copy->type;\
177 interfaces[i][copy->type].flags |= copy->flags;\
178 i--;copy=copy->prev;\
183 interfaces[i][copy->type].type = copy->type;\
184 if(copy->varkind==STACKVAR){\
185 if (copy->flags & SAVEDVAR)\
186 interfaces[i][copy->type].flags |= SAVEDVAR;\
188 i--;copy=copy->prev;\
193 #define MARKREACHED(b,c) {\
195 {COPYCURSTACK(c);b->flags=0;b->instack=c;b->indepth=stackdepth;}\
196 else {stackptr s=curstack;stackptr t=b->instack;\
197 if(b->indepth!=stackdepth)\
198 {show_icmd_method();panic("Stack depth mismatch");}\
199 while(s){if (s->type!=t->type)\
201 s=s->prev;t=t->prev;\
215 int opcode, i, len, loops;
216 int superblockend, repeat, deadcode;
224 if (compileverbose) {
225 char logtext[MAXLOGTEXT];
226 sprintf(logtext, "Analysing: ");
227 utf_sprint(logtext+strlen(logtext), method->class->name);
228 strcpy(logtext+strlen(logtext), ".");
229 utf_sprint(logtext+strlen(logtext), method->name);
230 utf_sprint(logtext+strlen(logtext), method->descriptor);
234 argren = DMNEW(int, maxlocals);
235 //int *argren = (int *)alloca(maxlocals * sizeof(int)); /* table for argument renaming */
236 for (i = 0; i < maxlocals; i++)
242 block[0].flags = BBREACHED;
243 block[0].instack = 0;
244 block[0].indepth = 0;
246 for (i = 0; i < exceptiontablelength; i++) {
247 bptr = &block[block_index[extable[i].handlerpc]];
248 bptr->flags = BBREACHED;
249 bptr->type = BBTYPE_EXH;
252 bptr->pre_count = 10000;
257 #ifdef CONDITIONAL_LOADCONST
258 b_count = block_count;
260 while (--b_count >= 0) {
261 if (bptr->icount != 0) {
262 iptr = bptr->iinstr + bptr->icount - 1;
295 block[block_index[iptr->op1]].pre_count++;
298 case ICMD_TABLESWITCH:
300 block[block_index[*s4ptr++]].pre_count++; /* default */
301 i = *s4ptr++; /* low */
302 i = *s4ptr++ - i + 1; /* high */
304 block[block_index[*s4ptr++]].pre_count++;
308 case ICMD_LOOKUPSWITCH:
310 block[block_index[*s4ptr++]].pre_count++; /* default */
311 i = *s4ptr++; /* count */
313 block[block_index[s4ptr[1]]].pre_count++;
329 b_count = block_count;
331 superblockend = true;
335 while (--b_count >= 0) {
336 if (bptr->flags == BBDELETED) {
339 else if (superblockend && (bptr->flags < BBREACHED))
341 else if (bptr->flags <= BBREACHED) {
343 stackdepth = bptr->indepth;
344 else if (bptr->flags < BBREACHED) {
346 bptr->instack = copy;
347 bptr->indepth = stackdepth;
349 else if (bptr->indepth != stackdepth) {
351 panic("Stack depth mismatch");
354 curstack = bptr->instack;
356 superblockend = false;
357 bptr->flags = BBFINISHED;
360 b_index = bptr - block;
365 /* DEBUG XXX */ /* dolog("p:%04d op: %s",iptr-instr,icmd_names[opcode]); */
367 #ifdef USEBUILTINTABLE
370 stdopdescriptor *breplace;
371 breplace = find_builtin(opcode);
373 if (breplace && opcode == breplace->opcode) {
374 iptr[0].opc = breplace->icmd;
375 iptr[0].op1 = breplace->type_d;
376 iptr[0].val.a = breplace->builtin;
377 isleafmethod = false;
378 switch (breplace->icmd) {
386 builtin_descriptor *breplace;
387 breplace = find_builtin(opcode);
389 if (breplace && opcode == breplace->opcode) {
390 iptr[0].opc = breplace->icmd;
391 iptr[0].op1 = breplace->type_d;
392 iptr[0].val.a = breplace->builtin;
393 isleafmethod = false;
394 switch (breplace->icmd) {
409 case ICMD_CHECKASIZE:
411 case ICMD_IFEQ_ICONST:
412 case ICMD_IFNE_ICONST:
413 case ICMD_IFLT_ICONST:
414 case ICMD_IFGE_ICONST:
415 case ICMD_IFGT_ICONST:
416 case ICMD_IFLE_ICONST:
417 case ICMD_ELSE_ICONST:
422 locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
424 COUNT(count_pcmd_return);
426 superblockend = true;
429 /* pop 0 push 1 const */
432 COUNT(count_pcmd_load);
434 switch (iptr[1].opc) {
436 iptr[0].opc = ICMD_IADDCONST;
438 iptr[1].opc = ICMD_NOP;
439 OP1_1(TYPE_INT,TYPE_INT);
440 COUNT(count_pcmd_op);
443 iptr[0].opc = ICMD_ISUBCONST;
444 goto icmd_iconst_tail;
446 iptr[0].opc = ICMD_IMULCONST;
447 goto icmd_iconst_tail;
449 if (iptr[0].val.i == 0x00000002)
451 else if (iptr[0].val.i == 0x00000004)
453 else if (iptr[0].val.i == 0x00000008)
455 else if (iptr[0].val.i == 0x00000010)
457 else if (iptr[0].val.i == 0x00000020)
459 else if (iptr[0].val.i == 0x00000040)
461 else if (iptr[0].val.i == 0x00000080)
463 else if (iptr[0].val.i == 0x00000100)
465 else if (iptr[0].val.i == 0x00000200)
467 else if (iptr[0].val.i == 0x00000400)
469 else if (iptr[0].val.i == 0x00000800)
471 else if (iptr[0].val.i == 0x00001000)
473 else if (iptr[0].val.i == 0x00002000)
475 else if (iptr[0].val.i == 0x00004000)
477 else if (iptr[0].val.i == 0x00008000)
479 else if (iptr[0].val.i == 0x00010000)
481 else if (iptr[0].val.i == 0x00020000)
483 else if (iptr[0].val.i == 0x00040000)
485 else if (iptr[0].val.i == 0x00080000)
487 else if (iptr[0].val.i == 0x00100000)
489 else if (iptr[0].val.i == 0x00200000)
491 else if (iptr[0].val.i == 0x00400000)
493 else if (iptr[0].val.i == 0x00800000)
495 else if (iptr[0].val.i == 0x01000000)
497 else if (iptr[0].val.i == 0x02000000)
499 else if (iptr[0].val.i == 0x04000000)
501 else if (iptr[0].val.i == 0x08000000)
503 else if (iptr[0].val.i == 0x10000000)
505 else if (iptr[0].val.i == 0x20000000)
507 else if (iptr[0].val.i == 0x40000000)
509 else if (iptr[0].val.i == 0x80000000)
515 iptr[0].opc = ICMD_IDIVPOW2;
516 goto icmd_iconst_tail;
518 #if !defined(NO_DIV_OPT)
519 if (iptr[0].val.i == 0x10001) {
520 iptr[0].opc = ICMD_IREM0X10001;
521 goto icmd_iconst_tail;
524 if ((iptr[0].val.i == 0x00000002) ||
525 (iptr[0].val.i == 0x00000004) ||
526 (iptr[0].val.i == 0x00000008) ||
527 (iptr[0].val.i == 0x00000010) ||
528 (iptr[0].val.i == 0x00000020) ||
529 (iptr[0].val.i == 0x00000040) ||
530 (iptr[0].val.i == 0x00000080) ||
531 (iptr[0].val.i == 0x00000100) ||
532 (iptr[0].val.i == 0x00000200) ||
533 (iptr[0].val.i == 0x00000400) ||
534 (iptr[0].val.i == 0x00000800) ||
535 (iptr[0].val.i == 0x00001000) ||
536 (iptr[0].val.i == 0x00002000) ||
537 (iptr[0].val.i == 0x00004000) ||
538 (iptr[0].val.i == 0x00008000) ||
539 (iptr[0].val.i == 0x00010000) ||
540 (iptr[0].val.i == 0x00020000) ||
541 (iptr[0].val.i == 0x00040000) ||
542 (iptr[0].val.i == 0x00080000) ||
543 (iptr[0].val.i == 0x00100000) ||
544 (iptr[0].val.i == 0x00200000) ||
545 (iptr[0].val.i == 0x00400000) ||
546 (iptr[0].val.i == 0x00800000) ||
547 (iptr[0].val.i == 0x01000000) ||
548 (iptr[0].val.i == 0x02000000) ||
549 (iptr[0].val.i == 0x04000000) ||
550 (iptr[0].val.i == 0x08000000) ||
551 (iptr[0].val.i == 0x10000000) ||
552 (iptr[0].val.i == 0x20000000) ||
553 (iptr[0].val.i == 0x40000000) ||
554 (iptr[0].val.i == 0x80000000)) {
555 iptr[0].opc = ICMD_IREMPOW2;
557 goto icmd_iconst_tail;
562 iptr[0].opc = ICMD_IANDCONST;
563 goto icmd_iconst_tail;
565 iptr[0].opc = ICMD_IORCONST;
566 goto icmd_iconst_tail;
568 iptr[0].opc = ICMD_IXORCONST;
569 goto icmd_iconst_tail;
571 iptr[0].opc = ICMD_ISHLCONST;
572 goto icmd_iconst_tail;
574 iptr[0].opc = ICMD_ISHRCONST;
575 goto icmd_iconst_tail;
577 iptr[0].opc = ICMD_IUSHRCONST;
578 goto icmd_iconst_tail;
579 #if SUPPORT_LONG_SHIFT
581 iptr[0].opc = ICMD_LSHLCONST;
582 goto icmd_lconst_tail;
584 iptr[0].opc = ICMD_LSHRCONST;
585 goto icmd_lconst_tail;
587 iptr[0].opc = ICMD_LUSHRCONST;
588 goto icmd_lconst_tail;
591 iptr[0].opc = ICMD_IFEQ;
593 iptr[0].op1 = iptr[1].op1;
596 /* iptr[1].opc = ICMD_NOP; */
598 tbptr = block + block_index[iptr->op1];
600 iptr[0].target = (void *) tbptr;
602 MARKREACHED(tbptr, copy);
603 COUNT(count_pcmd_bra);
606 iptr[0].opc = ICMD_IFLT;
607 goto icmd_if_icmp_tail;
609 iptr[0].opc = ICMD_IFLE;
610 goto icmd_if_icmp_tail;
612 iptr[0].opc = ICMD_IFNE;
613 goto icmd_if_icmp_tail;
615 iptr[0].opc = ICMD_IFGT;
616 goto icmd_if_icmp_tail;
618 iptr[0].opc = ICMD_IFGE;
619 goto icmd_if_icmp_tail;
628 COUNT(count_pcmd_load);
630 switch (iptr[1].opc) {
633 iptr[0].opc = ICMD_LADDCONST;
635 iptr[1].opc = ICMD_NOP;
636 OP1_1(TYPE_LNG,TYPE_LNG);
637 COUNT(count_pcmd_op);
640 iptr[0].opc = ICMD_LSUBCONST;
641 goto icmd_lconst_tail;
645 iptr[0].opc = ICMD_LMULCONST;
646 goto icmd_lconst_tail;
650 if (iptr[0].val.l == 0x00000002)
652 else if (iptr[0].val.l == 0x00000004)
654 else if (iptr[0].val.l == 0x00000008)
656 else if (iptr[0].val.l == 0x00000010)
658 else if (iptr[0].val.l == 0x00000020)
660 else if (iptr[0].val.l == 0x00000040)
662 else if (iptr[0].val.l == 0x00000080)
664 else if (iptr[0].val.l == 0x00000100)
666 else if (iptr[0].val.l == 0x00000200)
668 else if (iptr[0].val.l == 0x00000400)
670 else if (iptr[0].val.l == 0x00000800)
672 else if (iptr[0].val.l == 0x00001000)
674 else if (iptr[0].val.l == 0x00002000)
676 else if (iptr[0].val.l == 0x00004000)
678 else if (iptr[0].val.l == 0x00008000)
680 else if (iptr[0].val.l == 0x00010000)
682 else if (iptr[0].val.l == 0x00020000)
684 else if (iptr[0].val.l == 0x00040000)
686 else if (iptr[0].val.l == 0x00080000)
688 else if (iptr[0].val.l == 0x00100000)
690 else if (iptr[0].val.l == 0x00200000)
692 else if (iptr[0].val.l == 0x00400000)
694 else if (iptr[0].val.l == 0x00800000)
696 else if (iptr[0].val.l == 0x01000000)
698 else if (iptr[0].val.l == 0x02000000)
700 else if (iptr[0].val.l == 0x04000000)
702 else if (iptr[0].val.l == 0x08000000)
704 else if (iptr[0].val.l == 0x10000000)
706 else if (iptr[0].val.l == 0x20000000)
708 else if (iptr[0].val.l == 0x40000000)
710 else if (iptr[0].val.l == 0x80000000)
716 iptr[0].opc = ICMD_LDIVPOW2;
717 goto icmd_lconst_tail;
719 #if !defined(NO_DIV_OPT)
720 if (iptr[0].val.l == 0x10001) {
721 iptr[0].opc = ICMD_LREM0X10001;
722 goto icmd_lconst_tail;
725 if ((iptr[0].val.l == 0x00000002) ||
726 (iptr[0].val.l == 0x00000004) ||
727 (iptr[0].val.l == 0x00000008) ||
728 (iptr[0].val.l == 0x00000010) ||
729 (iptr[0].val.l == 0x00000020) ||
730 (iptr[0].val.l == 0x00000040) ||
731 (iptr[0].val.l == 0x00000080) ||
732 (iptr[0].val.l == 0x00000100) ||
733 (iptr[0].val.l == 0x00000200) ||
734 (iptr[0].val.l == 0x00000400) ||
735 (iptr[0].val.l == 0x00000800) ||
736 (iptr[0].val.l == 0x00001000) ||
737 (iptr[0].val.l == 0x00002000) ||
738 (iptr[0].val.l == 0x00004000) ||
739 (iptr[0].val.l == 0x00008000) ||
740 (iptr[0].val.l == 0x00010000) ||
741 (iptr[0].val.l == 0x00020000) ||
742 (iptr[0].val.l == 0x00040000) ||
743 (iptr[0].val.l == 0x00080000) ||
744 (iptr[0].val.l == 0x00100000) ||
745 (iptr[0].val.l == 0x00200000) ||
746 (iptr[0].val.l == 0x00400000) ||
747 (iptr[0].val.l == 0x00800000) ||
748 (iptr[0].val.l == 0x01000000) ||
749 (iptr[0].val.l == 0x02000000) ||
750 (iptr[0].val.l == 0x04000000) ||
751 (iptr[0].val.l == 0x08000000) ||
752 (iptr[0].val.l == 0x10000000) ||
753 (iptr[0].val.l == 0x20000000) ||
754 (iptr[0].val.l == 0x40000000) ||
755 (iptr[0].val.l == 0x80000000)) {
756 iptr[0].opc = ICMD_LREMPOW2;
758 goto icmd_lconst_tail;
765 iptr[0].opc = ICMD_LANDCONST;
766 goto icmd_lconst_tail;
768 iptr[0].opc = ICMD_LORCONST;
769 goto icmd_lconst_tail;
771 iptr[0].opc = ICMD_LXORCONST;
772 goto icmd_lconst_tail;
774 #if !defined(NOLONG_CONDITIONAL)
776 if ((len > 1) && (iptr[2].val.i == 0)) {
777 switch (iptr[2].opc) {
779 iptr[0].opc = ICMD_IF_LEQ;
780 icmd_lconst_lcmp_tail:
781 iptr[0].op1 = iptr[2].op1;
784 /* iptr[1].opc = ICMD_NOP;
785 iptr[2].opc = ICMD_NOP; */
787 tbptr = block + block_index[iptr->op1];
789 iptr[0].target = (void *) tbptr;
791 MARKREACHED(tbptr, copy);
792 COUNT(count_pcmd_bra);
793 COUNT(count_pcmd_op);
796 iptr[0].opc = ICMD_IF_LNE;
797 goto icmd_lconst_lcmp_tail;
799 iptr[0].opc = ICMD_IF_LLT;
800 goto icmd_lconst_lcmp_tail;
802 iptr[0].opc = ICMD_IF_LGT;
803 goto icmd_lconst_lcmp_tail;
805 iptr[0].opc = ICMD_IF_LLE;
806 goto icmd_lconst_lcmp_tail;
808 iptr[0].opc = ICMD_IF_LGE;
809 goto icmd_lconst_lcmp_tail;
812 } /* switch (iptr[2].opc) */
813 } /* if (iptr[2].val.i == 0) */
826 COUNT(count_pcmd_load);
830 COUNT(count_pcmd_load);
834 COUNT(count_pcmd_load);
838 /* pop 0 push 1 load */
845 COUNT(count_load_instruction);
846 i = opcode-ICMD_ILOAD;
847 iptr->op1 = argren[iptr->op1];
848 locals[iptr->op1][i].type = i;
849 LOAD(i, LOCALVAR, iptr->op1);
859 COUNT(count_check_null);
860 COUNT(count_check_bound);
861 COUNT(count_pcmd_mem);
862 OP2IAT_1(opcode-ICMD_IALOAD);
868 COUNT(count_check_null);
869 COUNT(count_check_bound);
870 COUNT(count_pcmd_mem);
874 /* pop 0 push 0 iinc */
880 count_store_depth[10]++;
882 count_store_depth[i]++;
887 if ((copy->varkind == LOCALVAR) &&
888 (copy->varnum == iptr->op1)) {
889 copy->varkind = TEMPVAR;
898 /* pop 1 push 0 store */
908 i = opcode - ICMD_ISTORE;
909 locals[iptr->op1][i].type = i;
914 count_store_length[20]++;
916 count_store_length[i]++;
919 count_store_depth[10]++;
921 count_store_depth[i]++;
923 copy = curstack->prev;
926 if ((copy->varkind == LOCALVAR) &&
927 (copy->varnum == iptr->op1)) {
928 copy->varkind = TEMPVAR;
934 if ((new - curstack) == 1) {
935 curstack->varkind = LOCALVAR;
936 curstack->varnum = iptr->op1;
938 STORE(opcode-ICMD_ISTORE);
948 COUNT(count_check_null);
949 COUNT(count_check_bound);
950 COUNT(count_pcmd_mem);
951 OP3TIA_0(opcode-ICMD_IASTORE);
956 COUNT(count_check_null);
957 COUNT(count_check_bound);
958 COUNT(count_pcmd_mem);
973 COUNT(count_pcmd_return);
974 OP1_0(opcode-ICMD_IRETURN);
975 superblockend = true;
979 COUNT(count_check_null);
983 superblockend = true;
987 COUNT(count_pcmd_mem);
991 /* pop 1 push 0 branch */
995 COUNT(count_pcmd_bra);
997 tbptr = block + block_index[iptr->op1];
999 iptr[0].target = (void *) tbptr;
1001 MARKREACHED(tbptr, copy);
1010 COUNT(count_pcmd_bra);
1011 #ifdef CONDITIONAL_LOADCONST
1013 tbptr = block + b_index;
1014 if ((b_count >= 3) &&
1015 ((b_index + 2) == block_index[iptr[0].op1]) &&
1016 (tbptr[1].pre_count == 1) &&
1017 (iptr[1].opc == ICMD_ICONST) &&
1018 (iptr[2].opc == ICMD_GOTO) &&
1019 ((b_index + 3) == block_index[iptr[2].op1]) &&
1020 (tbptr[2].pre_count == 1) &&
1021 (iptr[3].opc == ICMD_ICONST)) {
1022 OP1_1(TYPE_INT, TYPE_INT);
1023 switch (iptr[0].opc) {
1025 iptr[0].opc = ICMD_IFNE_ICONST;
1028 iptr[0].opc = ICMD_IFEQ_ICONST;
1031 iptr[0].opc = ICMD_IFGE_ICONST;
1034 iptr[0].opc = ICMD_IFLT_ICONST;
1037 iptr[0].opc = ICMD_IFLE_ICONST;
1040 iptr[0].opc = ICMD_IFGT_ICONST;
1043 iptr[0].val.i = iptr[1].val.i;
1044 iptr[1].opc = ICMD_ELSE_ICONST;
1045 iptr[1].val.i = iptr[3].val.i;
1046 iptr[2].opc = ICMD_NOP;
1047 iptr[3].opc = ICMD_NOP;
1048 tbptr[1].flags = BBDELETED;
1049 tbptr[2].flags = BBDELETED;
1050 tbptr[1].icount = 0;
1051 tbptr[2].icount = 0;
1052 if (tbptr[3].pre_count == 2) {
1053 len += tbptr[3].icount + 3;
1054 bptr->icount += tbptr[3].icount + 3;
1055 tbptr[3].flags = BBDELETED;
1056 tbptr[3].icount = 0;
1069 tbptr = block + block_index[iptr->op1];
1071 iptr[0].target = (void *) tbptr;
1073 MARKREACHED(tbptr, copy);
1076 /* pop 0 push 0 branch */
1079 COUNT(count_pcmd_bra);
1080 tbptr = block + block_index[iptr->op1];
1082 iptr[0].target = (void *) tbptr;
1084 MARKREACHED(tbptr, copy);
1086 superblockend = true;
1089 /* pop 1 push 0 table branch */
1091 case ICMD_TABLESWITCH:
1092 COUNT(count_pcmd_table);
1094 s4ptr = iptr->val.a;
1095 tbptr = block + block_index[*s4ptr++]; /* default */
1096 MARKREACHED(tbptr, copy);
1097 i = *s4ptr++; /* low */
1098 i = *s4ptr++ - i + 1; /* high */
1100 tptr = DMNEW(void*, i+1);
1101 iptr->target = (void *) tptr;
1103 tptr[0] = (void *) tbptr;
1107 tbptr = block + block_index[*s4ptr++];
1109 tptr[0] = (void *) tbptr;
1112 MARKREACHED(tbptr, copy);
1115 superblockend = true;
1118 /* pop 1 push 0 table branch */
1120 case ICMD_LOOKUPSWITCH:
1121 COUNT(count_pcmd_table);
1123 s4ptr = iptr->val.a;
1124 tbptr = block + block_index[*s4ptr++]; /* default */
1125 MARKREACHED(tbptr, copy);
1126 i = *s4ptr++; /* count */
1128 tptr = DMNEW(void*, i+1);
1129 iptr->target = (void *) tptr;
1131 tptr[0] = (void *) tbptr;
1135 tbptr = block + block_index[s4ptr[1]];
1137 tptr[0] = (void *) tbptr;
1140 MARKREACHED(tbptr, copy);
1144 superblockend = true;
1147 case ICMD_NULLCHECKPOP:
1148 case ICMD_MONITORENTER:
1149 COUNT(count_check_null);
1150 case ICMD_MONITOREXIT:
1154 /* pop 2 push 0 branch */
1156 case ICMD_IF_ICMPEQ:
1157 case ICMD_IF_ICMPNE:
1158 case ICMD_IF_ICMPLT:
1159 case ICMD_IF_ICMPGE:
1160 case ICMD_IF_ICMPGT:
1161 case ICMD_IF_ICMPLE:
1162 COUNT(count_pcmd_bra);
1164 tbptr = block + block_index[iptr->op1];
1166 iptr[0].target = (void *) tbptr;
1168 MARKREACHED(tbptr, copy);
1171 case ICMD_IF_ACMPEQ:
1172 case ICMD_IF_ACMPNE:
1173 COUNT(count_pcmd_bra);
1175 tbptr = block + block_index[iptr->op1];
1177 iptr[0].target = (void *) tbptr;
1179 MARKREACHED(tbptr, copy);
1185 COUNT(count_check_null);
1186 COUNT(count_pcmd_mem);
1187 OPTT2_0(iptr->op1,TYPE_ADR);
1192 if (! IS_2_WORD_TYPE(curstack->type)) {
1193 OP1_0ANY; /* second pop */
1196 iptr->opc = ICMD_POP;
1200 /* pop 0 push 1 dup */
1203 COUNT(count_dup_instruction);
1209 if (IS_2_WORD_TYPE(curstack->type)) {
1210 iptr->opc = ICMD_DUP;
1216 NEWSTACK(copy->prev->type, copy->prev->varkind,
1217 copy->prev->varnum);
1218 NEWSTACK(copy->type, copy->varkind,
1225 /* pop 2 push 3 dup */
1233 if (IS_2_WORD_TYPE(curstack->type)) {
1234 iptr->opc = ICMD_DUP_X1;
1242 /* pop 3 push 4 dup */
1246 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1247 iptr->opc = ICMD_DUP_X1;
1257 if (IS_2_WORD_TYPE(curstack->type)) {
1258 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1259 iptr->opc = ICMD_DUP_X1;
1263 iptr->opc = ICMD_DUP_X2;
1269 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1270 iptr->opc = ICMD_DUP2_X1;
1278 /* pop 2 push 2 swap */
1287 #if !SUPPORT_DIVISION
1288 iptr[0].opc = ICMD_BUILTIN2;
1289 iptr[0].op1 = TYPE_INT;
1290 iptr[0].val.a = BUILTIN_idiv;
1291 isleafmethod = false;
1296 #if !SUPPORT_DIVISION
1297 iptr[0].opc = ICMD_BUILTIN2;
1298 iptr[0].op1 = TYPE_INT;
1299 iptr[0].val.a = BUILTIN_irem;
1300 isleafmethod = false;
1314 COUNT(count_pcmd_op);
1319 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1320 iptr[0].opc = ICMD_BUILTIN2;
1321 iptr[0].op1 = TYPE_LNG;
1322 iptr[0].val.a = BUILTIN_ldiv;
1323 isleafmethod = false;
1328 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1329 iptr[0].opc = ICMD_BUILTIN2;
1330 iptr[0].op1 = TYPE_LNG;
1331 iptr[0].val.a = BUILTIN_lrem;
1332 isleafmethod = false;
1343 /* XXX DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1344 COUNT(count_pcmd_op);
1351 COUNT(count_pcmd_op);
1360 COUNT(count_pcmd_op);
1369 COUNT(count_pcmd_op);
1374 COUNT(count_pcmd_op);
1375 #if !defined(NOLONG_CONDITIONAL)
1376 if ((len > 0) && (iptr[1].val.i == 0)) {
1377 switch (iptr[1].opc) {
1379 iptr[0].opc = ICMD_IF_LCMPEQ;
1381 iptr[0].op1 = iptr[1].op1;
1384 /* iptr[1].opc = ICMD_NOP; */
1386 tbptr = block + block_index[iptr->op1];
1388 iptr[0].target = (void *) tbptr;
1390 MARKREACHED(tbptr, copy);
1391 COUNT(count_pcmd_bra);
1394 iptr[0].opc = ICMD_IF_LCMPNE;
1395 goto icmd_lcmp_if_tail;
1397 iptr[0].opc = ICMD_IF_LCMPLT;
1398 goto icmd_lcmp_if_tail;
1400 iptr[0].opc = ICMD_IF_LCMPGT;
1401 goto icmd_lcmp_if_tail;
1403 iptr[0].opc = ICMD_IF_LCMPLE;
1404 goto icmd_lcmp_if_tail;
1406 iptr[0].opc = ICMD_IF_LCMPGE;
1407 goto icmd_lcmp_if_tail;
1409 OPTT2_1(TYPE_LNG, TYPE_INT);
1414 OPTT2_1(TYPE_LNG, TYPE_INT);
1418 COUNT(count_pcmd_op);
1419 OPTT2_1(TYPE_FLT, TYPE_INT);
1423 COUNT(count_pcmd_op);
1424 OPTT2_1(TYPE_DBL, TYPE_INT);
1432 case ICMD_INT2SHORT:
1433 COUNT(count_pcmd_op);
1434 OP1_1(TYPE_INT, TYPE_INT);
1437 COUNT(count_pcmd_op);
1438 OP1_1(TYPE_LNG, TYPE_LNG);
1441 COUNT(count_pcmd_op);
1442 OP1_1(TYPE_FLT, TYPE_FLT);
1445 COUNT(count_pcmd_op);
1446 OP1_1(TYPE_DBL, TYPE_DBL);
1450 COUNT(count_pcmd_op);
1451 OP1_1(TYPE_INT, TYPE_LNG);
1454 COUNT(count_pcmd_op);
1455 OP1_1(TYPE_INT, TYPE_FLT);
1458 COUNT(count_pcmd_op);
1459 OP1_1(TYPE_INT, TYPE_DBL);
1462 COUNT(count_pcmd_op);
1463 OP1_1(TYPE_LNG, TYPE_INT);
1466 COUNT(count_pcmd_op);
1467 OP1_1(TYPE_LNG, TYPE_FLT);
1470 COUNT(count_pcmd_op);
1471 OP1_1(TYPE_LNG, TYPE_DBL);
1474 COUNT(count_pcmd_op);
1475 OP1_1(TYPE_FLT, TYPE_INT);
1478 COUNT(count_pcmd_op);
1479 OP1_1(TYPE_FLT, TYPE_LNG);
1482 COUNT(count_pcmd_op);
1483 OP1_1(TYPE_FLT, TYPE_DBL);
1486 COUNT(count_pcmd_op);
1487 OP1_1(TYPE_DBL, TYPE_INT);
1490 COUNT(count_pcmd_op);
1491 OP1_1(TYPE_DBL, TYPE_LNG);
1494 COUNT(count_pcmd_op);
1495 OP1_1(TYPE_DBL, TYPE_FLT);
1498 case ICMD_CHECKCAST:
1499 OP1_1(TYPE_ADR, TYPE_ADR);
1502 case ICMD_ARRAYLENGTH:
1503 case ICMD_INSTANCEOF:
1504 OP1_1(TYPE_ADR, TYPE_INT);
1508 case ICMD_ANEWARRAY:
1509 OP1_1(TYPE_INT, TYPE_ADR);
1513 COUNT(count_check_null);
1514 COUNT(count_pcmd_mem);
1515 OP1_1(TYPE_ADR, iptr->op1);
1520 case ICMD_GETSTATIC:
1521 COUNT(count_pcmd_mem);
1531 tbptr = block + block_index[iptr->op1];
1533 iptr[0].target = (void *) tbptr;
1535 /* XXX This is a dirty hack. The typechecker
1536 * needs it because the OP1_0ANY below
1537 * overwrites iptr->dst.
1539 iptr->val.a = (void*) iptr->dst;
1541 tbptr->type=BBTYPE_SBR;
1542 MARKREACHED(tbptr, copy);
1546 /* pop many push any */
1548 case ICMD_INVOKEVIRTUAL:
1549 case ICMD_INVOKESPECIAL:
1550 case ICMD_INVOKEINTERFACE:
1551 case ICMD_INVOKESTATIC:
1552 COUNT(count_pcmd_met);
1554 methodinfo *m = iptr->val.a;
1555 if (m->flags & ACC_STATIC)
1556 {COUNT(count_check_null);}
1558 if (i > arguments_num)
1561 #if defined(__X86_64__)
1569 (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1573 stackargs += (iarg < intreg_argnum) ? 0 : (iarg - intreg_argnum);
1574 stackargs += (farg < fltreg_argnum) ? 0 : (farg - fltreg_argnum);
1579 if (!(copy->flags & SAVEDVAR)) {
1580 copy->varkind = ARGVAR;
1581 if (IS_FLT_DBL_TYPE(copy->type)) {
1582 if (--farg < fltreg_argnum) {
1583 copy->varnum = farg;
1585 copy->varnum = --stackargs + intreg_argnum;
1588 if (--iarg < intreg_argnum) {
1589 copy->varnum = iarg;
1591 copy->varnum = --stackargs + intreg_argnum;
1595 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1603 if (! (copy->flags & SAVEDVAR)) {
1604 copy->varkind = ARGVAR;
1611 copy->flags |= SAVEDVAR;
1616 if (m->returntype != TYPE_VOID) {
1617 OP0_1(m->returntype);
1623 /* XXX DEBUG */ /*dolog("builtin3");*/
1625 if (! (curstack->flags & SAVEDVAR)) {
1626 curstack->varkind = ARGVAR;
1627 curstack->varnum = 2;
1629 if (3 > arguments_num) {
1637 /* XXX DEBUG */ /*dolog("builtin2");*/
1638 if (!(curstack->flags & SAVEDVAR)) {
1639 curstack->varkind = ARGVAR;
1640 curstack->varnum = 1;
1642 if (2 > arguments_num) {
1650 /* XXX DEBUG */ /*dolog("builtin1");*/
1651 if (!(curstack->flags & SAVEDVAR)) {
1652 curstack->varkind = ARGVAR;
1653 curstack->varnum = 0;
1655 if (1 > arguments_num) {
1661 copy->flags |= SAVEDVAR;
1664 if (iptr->op1 != TYPE_VOID)
1668 case ICMD_MULTIANEWARRAY:
1671 if ((i + intreg_argnum) > arguments_num)
1672 arguments_num = i + intreg_argnum;
1675 if (! (copy->flags & SAVEDVAR)) {
1676 copy->varkind = ARGVAR;
1677 copy->varnum = i + intreg_argnum;
1682 copy->flags |= SAVEDVAR;
1690 case ICMD_CLEAR_ARGREN:
1691 for (i = iptr->op1; i<maxlocals; i++)
1693 iptr->opc = opcode = ICMD_NOP;
1697 case ICMD_READONLY_ARG:
1698 case ICMD_READONLY_ARG+1:
1699 case ICMD_READONLY_ARG+2:
1700 case ICMD_READONLY_ARG+3:
1701 case ICMD_READONLY_ARG+4:
1704 if (curstack->varkind == LOCALVAR) {
1705 i = curstack->varnum;
1706 argren[iptr->op1] = i;
1709 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
1715 printf("ICMD %d at %d\n", iptr->opc, (int)(iptr-instr));
1716 panic("Missing ICMD code during stack analysis");
1718 /* XXX DEBUG */ /*dolog("iptr++");*/
1720 } /* while instructions */
1721 bptr->outstack = curstack;
1722 bptr->outdepth = stackdepth;
1726 superblockend = true;
1728 } /* while blocks */
1729 } while (repeat && !deadcode);
1732 if (block_count > count_max_basic_blocks)
1733 count_max_basic_blocks = block_count;
1734 count_basic_blocks += block_count;
1735 if (instr_count > count_max_javainstr)
1736 count_max_javainstr = instr_count;
1737 count_javainstr += instr_count;
1738 if (stack_count > count_upper_bound_new_stack)
1739 count_upper_bound_new_stack = stack_count;
1740 if ((new - stack) > count_max_new_stack)
1741 count_max_new_stack = (new - stack);
1743 b_count = block_count;
1745 while (--b_count >= 0) {
1746 if (bptr->flags > BBREACHED) {
1747 if (bptr->indepth >= 10)
1748 count_block_stack[10]++;
1750 count_block_stack[bptr->indepth]++;
1753 count_block_size_distribution[len]++;
1755 count_block_size_distribution[10]++;
1757 count_block_size_distribution[11]++;
1759 count_block_size_distribution[12]++;
1761 count_block_size_distribution[13]++;
1763 count_block_size_distribution[14]++;
1765 count_block_size_distribution[15]++;
1767 count_block_size_distribution[16]++;
1769 count_block_size_distribution[17]++;
1775 count_analyse_iterations[0]++;
1776 else if (loops == 2)
1777 count_analyse_iterations[1]++;
1778 else if (loops == 3)
1779 count_analyse_iterations[2]++;
1780 else if (loops == 4)
1781 count_analyse_iterations[3]++;
1783 count_analyse_iterations[4]++;
1785 if (block_count <= 5)
1786 count_method_bb_distribution[0]++;
1787 else if (block_count <= 10)
1788 count_method_bb_distribution[1]++;
1789 else if (block_count <= 15)
1790 count_method_bb_distribution[2]++;
1791 else if (block_count <= 20)
1792 count_method_bb_distribution[3]++;
1793 else if (block_count <= 30)
1794 count_method_bb_distribution[4]++;
1795 else if (block_count <= 40)
1796 count_method_bb_distribution[5]++;
1797 else if (block_count <= 50)
1798 count_method_bb_distribution[6]++;
1799 else if (block_count <= 75)
1800 count_method_bb_distribution[7]++;
1802 count_method_bb_distribution[8]++;
1807 void icmd_print_stack(stackptr s)
1824 /* XXX remove */ /* printf("(%d)",s->flags); fflush(stdout); */
1825 if (s->flags & SAVEDVAR)
1826 switch (s->varkind) {
1828 if (s->flags & INMEMORY)
1829 printf((regs_ok) ? " M%02d" : " M??", s->regoff);
1830 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1831 printf((regs_ok) ? " F%02d" : " F??", s->regoff);
1833 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1837 printf(" I%02d", s->varnum);
1840 printf(" L%02d", s->varnum);
1843 printf(" A%02d", s->varnum);
1846 printf(" !%02d", j);
1849 switch (s->varkind) {
1851 if (s->flags & INMEMORY)
1852 printf((regs_ok) ? " m%02d" : " m??", s->regoff);
1853 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1854 printf((regs_ok) ? " f%02d" : " f??", s->regoff);
1856 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1860 printf(" i%02d", s->varnum);
1863 printf(" l%02d", s->varnum);
1866 printf(" a%02d", s->varnum);
1869 printf(" ?%02d", j);
1877 static void print_reg(stackptr s) {
1879 if (s->flags & SAVEDVAR)
1880 switch (s->varkind) {
1882 if (s->flags & INMEMORY)
1883 printf(" tm%02d", s->regoff);
1885 printf(" tr%02d", s->regoff);
1888 printf(" s %02d", s->varnum);
1891 printf(" l %02d", s->varnum);
1894 printf(" a %02d", s->varnum);
1897 printf(" ! %02d", s->varnum);
1900 switch (s->varkind) {
1902 if (s->flags & INMEMORY)
1903 printf(" Tm%02d", s->regoff);
1905 printf(" Tr%02d", s->regoff);
1908 printf(" S %02d", s->varnum);
1911 printf(" L %02d", s->varnum);
1914 printf(" A %02d", s->varnum);
1917 printf(" ? %02d", s->varnum);
1927 char *icmd_builtin_name(functionptr bptr)
1929 builtin_descriptor *bdesc = builtin_desc;
1930 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
1932 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
1936 static char *jit_type[] = {
1945 void show_icmd_method()
1956 utf_fprint(stdout, class->name);
1958 utf_fprint(stdout, method->name);
1960 utf_fprint(stdout, method->descriptor);
1961 printf ("\n\nMax locals: %d\n", (int) maxlocals);
1962 printf ("Max stack: %d\n", (int) maxstack);
1964 printf ("Exceptions (Number: %d):\n", exceptiontablelength);
1965 for (ex = extable; ex != NULL; ex = ex->down) {
1966 printf(" L%03d ... ", ex->start->debug_nr );
1967 printf("L%03d = ", ex->end->debug_nr);
1968 printf("L%03d\n", ex->handler->debug_nr);
1971 printf ("Local Table:\n");
1972 for (i = 0; i < maxlocals; i++) {
1973 printf(" %3d: ", i);
1974 for (j = TYPE_INT; j <= TYPE_ADR; j++)
1975 if (locals[i][j].type >= 0) {
1976 printf(" (%s) ", jit_type[j]);
1977 if (locals[i][j].flags & INMEMORY)
1978 printf((regs_ok) ? "m%2d" : "m??", locals[i][j].regoff);
1979 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
1980 printf((regs_ok) ? "f%02d" : "f??", locals[i][j].regoff);
1982 if (regs_ok) printf("%3s",regs[locals[i][j].regoff]); else printf("???");
1989 printf ("Interface Table:\n");
1990 for (i = 0; i < maxstack; i++) {
1991 if ((interfaces[i][0].type >= 0) || (interfaces[i][1].type >= 0) ||
1992 (interfaces[i][2].type >= 0) || (interfaces[i][3].type >= 0) ||
1993 (interfaces[i][4].type >= 0)) {
1994 printf(" %3d: ", i);
1995 for (j = TYPE_INT; j <= TYPE_ADR; j++)
1996 if (interfaces[i][j].type >= 0) {
1997 printf(" (%s) ", jit_type[j]);
1998 if (interfaces[i][j].flags & SAVEDVAR) {
1999 if (interfaces[i][j].flags & INMEMORY)
2000 printf((regs_ok) ? "M%2d" : "M??", interfaces[i][j].regoff);
2001 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2002 printf((regs_ok) ? "F%02d" : "F??", interfaces[i][j].regoff);
2004 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2008 if (interfaces[i][j].flags & INMEMORY)
2009 printf((regs_ok) ? "m%2d" : "m??", interfaces[i][j].regoff);
2010 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2011 printf((regs_ok) ? "f%02d" : "f??", interfaces[i][j].regoff);
2013 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2022 if (showdisassemble) {
2023 #if defined(__I386__) || defined(__X86_64__)
2027 u1ptr = method->mcode + dseglen;
2028 for (i = 0; i < block[0].mpc; i++, u1ptr++) {
2029 a = disassinstr(u1ptr, i);
2035 s4ptr = (s4 *) (method->mcode + dseglen);
2036 for (i = 0; i < block[0].mpc; i += 4, s4ptr++) {
2037 disassinstr(*s4ptr, i);
2044 for (bptr = block; bptr != NULL; bptr = bptr->next) {
2045 show_icmd_block(bptr);
2050 show_icmd_block(basicblock *bptr)
2057 if (bptr->flags != BBDELETED) {
2058 deadcode = bptr->flags <= BBREACHED;
2061 for (j = method->maxstack; j > 0; j--)
2064 icmd_print_stack(bptr->instack);
2065 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2066 iptr = bptr->iinstr;
2068 for (i=0; i < bptr->icount; i++, iptr++) {
2071 for (j = method->maxstack; j > 0; j--)
2075 icmd_print_stack(iptr->dst);
2076 printf("] %4d ", i);
2077 /* XXX remove */ /*fflush(stdout);*/
2078 show_icmd(iptr,deadcode);
2082 if (showdisassemble && (!deadcode)) {
2083 #if defined(__I386__) || defined(__X86_64__)
2089 u1ptr = method->mcode + dseglen + i;
2091 if (bptr->next != NULL) {
2092 for (; i < bptr->next->mpc; i++, u1ptr++) {
2093 a = disassinstr(u1ptr, i);
2100 for (; u1ptr < (u1 *) (method->mcode + method->mcodelength); i++, u1ptr++) {
2101 a = disassinstr(u1ptr, i);
2110 s4ptr = (s4 *) (method->mcode + dseglen + i);
2112 if (bptr->next != NULL) {
2113 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2114 disassinstr(*s4ptr, i);
2119 for (; s4ptr < (s4 *) (method->mcode + method->mcodelength); i += 4, s4ptr++) {
2120 disassinstr(*s4ptr, i);
2130 show_icmd(instruction *iptr,bool deadcode)
2136 printf("%s",icmd_names[iptr->opc]);
2137 switch ((int) iptr->opc) {
2138 case ICMD_IADDCONST:
2139 case ICMD_ISUBCONST:
2140 case ICMD_IMULCONST:
2143 case ICMD_IREM0X10001:
2144 case ICMD_IANDCONST:
2146 case ICMD_IXORCONST:
2147 case ICMD_ISHLCONST:
2148 case ICMD_ISHRCONST:
2149 case ICMD_IUSHRCONST:
2150 case ICMD_LSHLCONST:
2151 case ICMD_LSHRCONST:
2152 case ICMD_LUSHRCONST:
2154 case ICMD_ELSE_ICONST:
2155 case ICMD_IFEQ_ICONST:
2156 case ICMD_IFNE_ICONST:
2157 case ICMD_IFLT_ICONST:
2158 case ICMD_IFGE_ICONST:
2159 case ICMD_IFGT_ICONST:
2160 case ICMD_IFLE_ICONST:
2161 printf(" %d", iptr->val.i);
2163 case ICMD_LADDCONST:
2164 case ICMD_LSUBCONST:
2165 case ICMD_LMULCONST:
2168 case ICMD_LANDCONST:
2170 case ICMD_LXORCONST:
2172 #if defined(__I386__)
2173 printf(" %lld", iptr->val.l);
2175 printf(" %ld", iptr->val.l);
2179 printf(" %f", iptr->val.f);
2182 printf(" %f", iptr->val.d);
2185 printf(" %p", iptr->val.a);
2189 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2190 case ICMD_PUTSTATIC:
2191 case ICMD_GETSTATIC:
2194 ((fieldinfo *) iptr->val.a)->class->name);
2197 ((fieldinfo *) iptr->val.a)->name);
2200 ((fieldinfo *) iptr->val.a)->descriptor);
2204 printf(" %d + %d", iptr->op1, iptr->val.i);
2239 printf(" %d", iptr->op1);
2244 ((classinfo *) iptr->val.a)->name);
2247 switch (iptr->op1) {
2274 case ICMD_ANEWARRAY:
2278 ((classinfo *) iptr->val.a)->name);
2281 case ICMD_MULTIANEWARRAY:
2284 printf(" %d ",iptr->op1);
2285 vft = (vftbl *)iptr->val.a;
2287 utf_fprint(stdout,vft->class->name);
2292 case ICMD_CHECKCAST:
2293 case ICMD_INSTANCEOF:
2295 classinfo *c = iptr->val.a;
2296 if (c->flags & ACC_INTERFACE)
2297 printf(" (INTERFACE) ");
2299 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2300 utf_fprint(stdout, c->name);
2306 printf(" %s", icmd_builtin_name((functionptr) iptr->val.a));
2308 case ICMD_INVOKEVIRTUAL:
2309 case ICMD_INVOKESPECIAL:
2310 case ICMD_INVOKESTATIC:
2311 case ICMD_INVOKEINTERFACE:
2314 ((methodinfo *) iptr->val.a)->class->name);
2317 ((methodinfo *) iptr->val.a)->name);
2325 if (deadcode || !iptr->target)
2326 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2328 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2336 if (deadcode || !iptr->target)
2337 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2339 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2344 case ICMD_IFNONNULL:
2345 case ICMD_IF_ICMPEQ:
2346 case ICMD_IF_ICMPNE:
2347 case ICMD_IF_ICMPLT:
2348 case ICMD_IF_ICMPGE:
2349 case ICMD_IF_ICMPGT:
2350 case ICMD_IF_ICMPLE:
2351 case ICMD_IF_LCMPEQ:
2352 case ICMD_IF_LCMPNE:
2353 case ICMD_IF_LCMPLT:
2354 case ICMD_IF_LCMPGE:
2355 case ICMD_IF_LCMPGT:
2356 case ICMD_IF_LCMPLE:
2357 case ICMD_IF_ACMPEQ:
2358 case ICMD_IF_ACMPNE:
2359 if (deadcode || !iptr->target)
2360 printf(" op1=%d", iptr->op1);
2362 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2364 case ICMD_TABLESWITCH:
2366 s4ptr = iptr->val.a;
2368 if (deadcode || !iptr->target) {
2369 printf(" %d;", *s4ptr);
2372 tptr = (void **) iptr->target;
2373 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2377 s4ptr++; /* skip default */
2378 j = *s4ptr++; /* low */
2379 j = *s4ptr++ - j; /* high */
2381 if (deadcode || !*tptr)
2382 printf(" %d", *s4ptr++);
2384 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2390 case ICMD_LOOKUPSWITCH:
2391 s4ptr = iptr->val.a;
2393 if (deadcode || !iptr->target) {
2394 printf(" %d;", *s4ptr);
2397 tptr = (void **) iptr->target;
2398 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2401 s4ptr++; /* default */
2402 j = *s4ptr++; /* count */
2405 if (deadcode || !*tptr) {
2406 s4ptr++; /* skip value */
2407 printf(" %d",*s4ptr++);
2410 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2419 * These are local overrides for various environment variables in Emacs.
2420 * Please do not remove this and leave it at the end of the file, where
2421 * Emacs will automagically detect them.
2422 * ---------------------------------------------------------------------
2425 * indent-tabs-mode: t