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 727 2003-12-11 10:52:40Z edwin $
45 #include "toolbox/loging.h"
46 #include "toolbox/memory.h"
49 /* from codegen.inc */
54 #define COUNT(cnt) cnt++
59 #define STACKRESET {curstack=0;stackdepth=0;}
61 #define TYPEPANIC {show_icmd_method();panic("Stack type mismatch");}
62 #define UNDERFLOW {show_icmd_method();panic("Stack underflow");} /* XXX why isn't this caught in parse.c? */
63 #define CURKIND curstack->varkind
64 #define CURTYPE curstack->type
66 #define REQUIRE(num) do { if (stackdepth<(num)) {UNDERFLOW;} } while(0)
67 #define REQUIRE_1 REQUIRE(1)
68 #define REQUIRE_2 REQUIRE(2)
69 #define REQUIRE_3 REQUIRE(3)
70 #define REQUIRE_4 REQUIRE(4)
72 #define NEWSTACK(s,v,n) {new->prev=curstack;new->type=s;new->flags=0; \
73 new->varkind=v;new->varnum=n;curstack=new;new++;}
74 #define NEWSTACKn(s,n) NEWSTACK(s,UNDEFVAR,n)
75 #define NEWSTACK0(s) NEWSTACK(s,UNDEFVAR,0)
76 #define NEWXSTACK {NEWSTACK(TYPE_ADR,STACKVAR,0);curstack=0;}
78 #define SETDST {iptr->dst=curstack;}
80 /* The following macros do NOT check stackdepth, set stackdepth and iptr->dst */
81 #define POP(s) {if(s!=curstack->type){TYPEPANIC;} \
82 if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR;\
83 curstack=curstack->prev;}
84 #define POPANY {if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR; \
85 curstack=curstack->prev;}
86 #define COPY(s,d) {(d)->flags=0;(d)->type=(s)->type;\
87 (d)->varkind=(s)->varkind;(d)->varnum=(s)->varnum;}
88 /******************************/
90 /* The following macros check stackdepth, set stackdepth and itpr->dst */
91 #define PUSHCONST(s){NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
92 #define LOAD(s,v,n) {NEWSTACK(s,v,n);SETDST;stackdepth++;}
93 #define STORE(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
94 #define OP1_0(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
95 #define OP1_0ANY {REQUIRE_1;POPANY;SETDST;stackdepth--;}
96 #define OP0_1(s) {NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
97 #define OP1_1(s,d) {REQUIRE_1;POP(s);NEWSTACKn(d,stackdepth-1);SETDST;}
98 #define OP2_0(s) {REQUIRE_2;POP(s);POP(s);SETDST;stackdepth-=2;}
99 #define OPTT2_0(t,b){REQUIRE_2;POP(t);POP(b);SETDST;stackdepth-=2;}
100 #define OP2_1(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);SETDST;stackdepth--;}
101 #define OP2IAT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(TYPE_ADR);NEWSTACKn(s,stackdepth-2);\
102 SETDST;stackdepth--;}
103 #define OP2IT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(s);NEWSTACKn(s,stackdepth-2);\
104 SETDST;stackdepth--;}
105 #define OPTT2_1(s,d){REQUIRE_2;POP(s);POP(s);NEWSTACKn(d,stackdepth-2);SETDST;stackdepth--;}
106 #define OP2_2(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);\
107 NEWSTACKn(s,stackdepth-1);SETDST;}
108 #define OP3TIA_0(s) {REQUIRE_3;POP(s);POP(TYPE_INT);POP(TYPE_ADR);SETDST;stackdepth-=3;}
109 #define OP3_0(s) {REQUIRE_3;POP(s);POP(s);POP(s);SETDST;stackdepth-=3;}
110 #define POPMANY(i) {REQUIRE(i);stackdepth-=i;while(--i>=0){POPANY;}SETDST;}
111 #define DUP {REQUIRE_1;NEWSTACK(CURTYPE,CURKIND,curstack->varnum);SETDST; \
113 #define SWAP {REQUIRE_2;COPY(curstack,new);POPANY;COPY(curstack,new+1);POPANY;\
114 new[0].prev=curstack;new[1].prev=new;\
115 curstack=new+1;new+=2;SETDST;}
116 #define DUP_X1 {REQUIRE_2;COPY(curstack,new);COPY(curstack,new+2);POPANY;\
117 COPY(curstack,new+1);POPANY;new[0].prev=curstack;\
118 new[1].prev=new;new[2].prev=new+1;\
119 curstack=new+2;new+=3;SETDST;stackdepth++;}
120 #define DUP2_X1 {REQUIRE_3;COPY(curstack,new+1);COPY(curstack,new+4);POPANY;\
121 COPY(curstack,new);COPY(curstack,new+3);POPANY;\
122 COPY(curstack,new+2);POPANY;new[0].prev=curstack;\
123 new[1].prev=new;new[2].prev=new+1;\
124 new[3].prev=new+2;new[4].prev=new+3;\
125 curstack=new+4;new+=5;SETDST;stackdepth+=2;}
126 #define DUP_X2 {REQUIRE_3;COPY(curstack,new);COPY(curstack,new+3);POPANY;\
127 COPY(curstack,new+2);POPANY;COPY(curstack,new+1);POPANY;\
128 new[0].prev=curstack;new[1].prev=new;\
129 new[2].prev=new+1;new[3].prev=new+2;\
130 curstack=new+3;new+=4;SETDST;stackdepth++;}
131 #define DUP2_X2 {REQUIRE_4;COPY(curstack,new+1);COPY(curstack,new+5);POPANY;\
132 COPY(curstack,new);COPY(curstack,new+4);POPANY;\
133 COPY(curstack,new+3);POPANY;COPY(curstack,new+2);POPANY;\
134 new[0].prev=curstack;new[1].prev=new;\
135 new[2].prev=new+1;new[3].prev=new+2;\
136 new[4].prev=new+3;new[5].prev=new+4;\
137 curstack=new+5;new+=6;SETDST;stackdepth+=2;}
138 /******************************/
140 #define COPYCURSTACK(copy) {\
153 copy->varkind=STACKVAR;\
169 if((copy->varkind==STACKVAR)&&(copy->varnum>i))\
170 copy->varkind=TEMPVAR;\
172 copy->varkind=STACKVAR;\
175 interfaces[i][copy->type].type = copy->type;\
176 interfaces[i][copy->type].flags |= copy->flags;\
177 i--;copy=copy->prev;\
182 interfaces[i][copy->type].type = copy->type;\
183 if(copy->varkind==STACKVAR){\
184 if (copy->flags & SAVEDVAR)\
185 interfaces[i][copy->type].flags |= SAVEDVAR;\
187 i--;copy=copy->prev;\
192 #define MARKREACHED(b,c) {\
194 {COPYCURSTACK(c);b->flags=0;b->instack=c;b->indepth=stackdepth;}\
195 else {stackptr s=curstack;stackptr t=b->instack;\
196 if(b->indepth!=stackdepth)\
197 {show_icmd_method();panic("Stack depth mismatch");}\
198 while(s){if (s->type!=t->type)\
200 s=s->prev;t=t->prev;\
214 int opcode, i, len, loops;
215 int superblockend, repeat, deadcode;
222 if (compileverbose) {
223 char logtext[MAXLOGTEXT];
224 sprintf(logtext, "Analysing: ");
225 utf_sprint(logtext+strlen(logtext), method->class->name);
226 strcpy(logtext+strlen(logtext), ".");
227 utf_sprint(logtext+strlen(logtext), method->name);
228 utf_sprint(logtext+strlen(logtext), method->descriptor);
232 int *argren = DMNEW(int, maxlocals);
233 //int *argren = (int *)alloca(maxlocals * sizeof(int)); /* table for argument renaming */
234 for (i = 0; i < maxlocals; i++)
240 block[0].flags = BBREACHED;
241 block[0].instack = 0;
242 block[0].indepth = 0;
244 for (i = 0; i < exceptiontablelength; i++) {
245 bptr = &block[block_index[extable[i].handlerpc]];
246 bptr->flags = BBREACHED;
247 bptr->type = BBTYPE_EXH;
250 bptr->pre_count = 10000;
255 #ifdef CONDITIONAL_LOADCONST
256 b_count = block_count;
258 while (--b_count >= 0) {
259 if (bptr->icount != 0) {
260 iptr = bptr->iinstr + bptr->icount - 1;
293 block[block_index[iptr->op1]].pre_count++;
296 case ICMD_TABLESWITCH:
298 block[block_index[*s4ptr++]].pre_count++; /* default */
299 i = *s4ptr++; /* low */
300 i = *s4ptr++ - i + 1; /* high */
302 block[block_index[*s4ptr++]].pre_count++;
306 case ICMD_LOOKUPSWITCH:
308 block[block_index[*s4ptr++]].pre_count++; /* default */
309 i = *s4ptr++; /* count */
311 block[block_index[s4ptr[1]]].pre_count++;
327 b_count = block_count;
329 superblockend = true;
333 while (--b_count >= 0) {
334 if (bptr->flags == BBDELETED) {
337 else if (superblockend && (bptr->flags < BBREACHED))
339 else if (bptr->flags <= BBREACHED) {
341 stackdepth = bptr->indepth;
342 else if (bptr->flags < BBREACHED) {
344 bptr->instack = copy;
345 bptr->indepth = stackdepth;
347 else if (bptr->indepth != stackdepth) {
349 panic("Stack depth mismatch");
352 curstack = bptr->instack;
354 superblockend = false;
355 bptr->flags = BBFINISHED;
358 b_index = bptr - block;
363 /* DEBUG XXX */ /* dolog("p:%04d op: %s",iptr-instr,icmd_names[opcode]); */
365 #ifdef USEBUILTINTABLE
368 stdopdescriptor *breplace;
369 breplace = find_builtin(opcode);
371 if (breplace && opcode == breplace->opcode) {
372 iptr[0].opc = breplace->icmd;
373 iptr[0].op1 = breplace->type_d;
374 iptr[0].val.a = breplace->builtin;
375 isleafmethod = false;
376 switch (breplace->icmd) {
384 builtin_descriptor *breplace;
385 breplace = find_builtin(opcode);
387 if (breplace && opcode == breplace->opcode) {
388 iptr[0].opc = breplace->icmd;
389 iptr[0].op1 = breplace->type_d;
390 iptr[0].val.a = breplace->builtin;
391 isleafmethod = false;
392 switch (breplace->icmd) {
407 case ICMD_CHECKASIZE:
409 case ICMD_IFEQ_ICONST:
410 case ICMD_IFNE_ICONST:
411 case ICMD_IFLT_ICONST:
412 case ICMD_IFGE_ICONST:
413 case ICMD_IFGT_ICONST:
414 case ICMD_IFLE_ICONST:
415 case ICMD_ELSE_ICONST:
420 locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
422 COUNT(count_pcmd_return);
424 superblockend = true;
427 /* pop 0 push 1 const */
430 COUNT(count_pcmd_load);
432 switch (iptr[1].opc) {
434 iptr[0].opc = ICMD_IADDCONST;
436 iptr[1].opc = ICMD_NOP;
437 OP1_1(TYPE_INT,TYPE_INT);
438 COUNT(count_pcmd_op);
441 iptr[0].opc = ICMD_ISUBCONST;
442 goto icmd_iconst_tail;
444 iptr[0].opc = ICMD_IMULCONST;
445 goto icmd_iconst_tail;
447 if (iptr[0].val.i == 0x00000002)
449 else if (iptr[0].val.i == 0x00000004)
451 else if (iptr[0].val.i == 0x00000008)
453 else if (iptr[0].val.i == 0x00000010)
455 else if (iptr[0].val.i == 0x00000020)
457 else if (iptr[0].val.i == 0x00000040)
459 else if (iptr[0].val.i == 0x00000080)
461 else if (iptr[0].val.i == 0x00000100)
463 else if (iptr[0].val.i == 0x00000200)
465 else if (iptr[0].val.i == 0x00000400)
467 else if (iptr[0].val.i == 0x00000800)
469 else if (iptr[0].val.i == 0x00001000)
471 else if (iptr[0].val.i == 0x00002000)
473 else if (iptr[0].val.i == 0x00004000)
475 else if (iptr[0].val.i == 0x00008000)
477 else if (iptr[0].val.i == 0x00010000)
479 else if (iptr[0].val.i == 0x00020000)
481 else if (iptr[0].val.i == 0x00040000)
483 else if (iptr[0].val.i == 0x00080000)
485 else if (iptr[0].val.i == 0x00100000)
487 else if (iptr[0].val.i == 0x00200000)
489 else if (iptr[0].val.i == 0x00400000)
491 else if (iptr[0].val.i == 0x00800000)
493 else if (iptr[0].val.i == 0x01000000)
495 else if (iptr[0].val.i == 0x02000000)
497 else if (iptr[0].val.i == 0x04000000)
499 else if (iptr[0].val.i == 0x08000000)
501 else if (iptr[0].val.i == 0x10000000)
503 else if (iptr[0].val.i == 0x20000000)
505 else if (iptr[0].val.i == 0x40000000)
507 else if (iptr[0].val.i == 0x80000000)
513 iptr[0].opc = ICMD_IDIVPOW2;
514 goto icmd_iconst_tail;
516 #if !defined(NO_DIV_OPT)
517 if (iptr[0].val.i == 0x10001) {
518 iptr[0].opc = ICMD_IREM0X10001;
519 goto icmd_iconst_tail;
522 if ((iptr[0].val.i == 0x00000002) ||
523 (iptr[0].val.i == 0x00000004) ||
524 (iptr[0].val.i == 0x00000008) ||
525 (iptr[0].val.i == 0x00000010) ||
526 (iptr[0].val.i == 0x00000020) ||
527 (iptr[0].val.i == 0x00000040) ||
528 (iptr[0].val.i == 0x00000080) ||
529 (iptr[0].val.i == 0x00000100) ||
530 (iptr[0].val.i == 0x00000200) ||
531 (iptr[0].val.i == 0x00000400) ||
532 (iptr[0].val.i == 0x00000800) ||
533 (iptr[0].val.i == 0x00001000) ||
534 (iptr[0].val.i == 0x00002000) ||
535 (iptr[0].val.i == 0x00004000) ||
536 (iptr[0].val.i == 0x00008000) ||
537 (iptr[0].val.i == 0x00010000) ||
538 (iptr[0].val.i == 0x00020000) ||
539 (iptr[0].val.i == 0x00040000) ||
540 (iptr[0].val.i == 0x00080000) ||
541 (iptr[0].val.i == 0x00100000) ||
542 (iptr[0].val.i == 0x00200000) ||
543 (iptr[0].val.i == 0x00400000) ||
544 (iptr[0].val.i == 0x00800000) ||
545 (iptr[0].val.i == 0x01000000) ||
546 (iptr[0].val.i == 0x02000000) ||
547 (iptr[0].val.i == 0x04000000) ||
548 (iptr[0].val.i == 0x08000000) ||
549 (iptr[0].val.i == 0x10000000) ||
550 (iptr[0].val.i == 0x20000000) ||
551 (iptr[0].val.i == 0x40000000) ||
552 (iptr[0].val.i == 0x80000000)) {
553 iptr[0].opc = ICMD_IREMPOW2;
555 goto icmd_iconst_tail;
560 iptr[0].opc = ICMD_IANDCONST;
561 goto icmd_iconst_tail;
563 iptr[0].opc = ICMD_IORCONST;
564 goto icmd_iconst_tail;
566 iptr[0].opc = ICMD_IXORCONST;
567 goto icmd_iconst_tail;
569 iptr[0].opc = ICMD_ISHLCONST;
570 goto icmd_iconst_tail;
572 iptr[0].opc = ICMD_ISHRCONST;
573 goto icmd_iconst_tail;
575 iptr[0].opc = ICMD_IUSHRCONST;
576 goto icmd_iconst_tail;
577 #if SUPPORT_LONG_SHIFT
579 iptr[0].opc = ICMD_LSHLCONST;
580 goto icmd_lconst_tail;
582 iptr[0].opc = ICMD_LSHRCONST;
583 goto icmd_lconst_tail;
585 iptr[0].opc = ICMD_LUSHRCONST;
586 goto icmd_lconst_tail;
589 iptr[0].opc = ICMD_IFEQ;
591 iptr[0].op1 = iptr[1].op1;
594 /* iptr[1].opc = ICMD_NOP; */
596 tbptr = block + block_index[iptr->op1];
598 iptr[0].target = (void *) tbptr;
600 MARKREACHED(tbptr, copy);
601 COUNT(count_pcmd_bra);
604 iptr[0].opc = ICMD_IFLT;
605 goto icmd_if_icmp_tail;
607 iptr[0].opc = ICMD_IFLE;
608 goto icmd_if_icmp_tail;
610 iptr[0].opc = ICMD_IFNE;
611 goto icmd_if_icmp_tail;
613 iptr[0].opc = ICMD_IFGT;
614 goto icmd_if_icmp_tail;
616 iptr[0].opc = ICMD_IFGE;
617 goto icmd_if_icmp_tail;
626 COUNT(count_pcmd_load);
628 switch (iptr[1].opc) {
631 iptr[0].opc = ICMD_LADDCONST;
633 iptr[1].opc = ICMD_NOP;
634 OP1_1(TYPE_LNG,TYPE_LNG);
635 COUNT(count_pcmd_op);
638 iptr[0].opc = ICMD_LSUBCONST;
639 goto icmd_lconst_tail;
643 iptr[0].opc = ICMD_LMULCONST;
644 goto icmd_lconst_tail;
648 if (iptr[0].val.l == 0x00000002)
650 else if (iptr[0].val.l == 0x00000004)
652 else if (iptr[0].val.l == 0x00000008)
654 else if (iptr[0].val.l == 0x00000010)
656 else if (iptr[0].val.l == 0x00000020)
658 else if (iptr[0].val.l == 0x00000040)
660 else if (iptr[0].val.l == 0x00000080)
662 else if (iptr[0].val.l == 0x00000100)
664 else if (iptr[0].val.l == 0x00000200)
666 else if (iptr[0].val.l == 0x00000400)
668 else if (iptr[0].val.l == 0x00000800)
670 else if (iptr[0].val.l == 0x00001000)
672 else if (iptr[0].val.l == 0x00002000)
674 else if (iptr[0].val.l == 0x00004000)
676 else if (iptr[0].val.l == 0x00008000)
678 else if (iptr[0].val.l == 0x00010000)
680 else if (iptr[0].val.l == 0x00020000)
682 else if (iptr[0].val.l == 0x00040000)
684 else if (iptr[0].val.l == 0x00080000)
686 else if (iptr[0].val.l == 0x00100000)
688 else if (iptr[0].val.l == 0x00200000)
690 else if (iptr[0].val.l == 0x00400000)
692 else if (iptr[0].val.l == 0x00800000)
694 else if (iptr[0].val.l == 0x01000000)
696 else if (iptr[0].val.l == 0x02000000)
698 else if (iptr[0].val.l == 0x04000000)
700 else if (iptr[0].val.l == 0x08000000)
702 else if (iptr[0].val.l == 0x10000000)
704 else if (iptr[0].val.l == 0x20000000)
706 else if (iptr[0].val.l == 0x40000000)
708 else if (iptr[0].val.l == 0x80000000)
714 iptr[0].opc = ICMD_LDIVPOW2;
715 goto icmd_lconst_tail;
717 #if !defined(NO_DIV_OPT)
718 if (iptr[0].val.l == 0x10001) {
719 iptr[0].opc = ICMD_LREM0X10001;
720 goto icmd_lconst_tail;
723 if ((iptr[0].val.l == 0x00000002) ||
724 (iptr[0].val.l == 0x00000004) ||
725 (iptr[0].val.l == 0x00000008) ||
726 (iptr[0].val.l == 0x00000010) ||
727 (iptr[0].val.l == 0x00000020) ||
728 (iptr[0].val.l == 0x00000040) ||
729 (iptr[0].val.l == 0x00000080) ||
730 (iptr[0].val.l == 0x00000100) ||
731 (iptr[0].val.l == 0x00000200) ||
732 (iptr[0].val.l == 0x00000400) ||
733 (iptr[0].val.l == 0x00000800) ||
734 (iptr[0].val.l == 0x00001000) ||
735 (iptr[0].val.l == 0x00002000) ||
736 (iptr[0].val.l == 0x00004000) ||
737 (iptr[0].val.l == 0x00008000) ||
738 (iptr[0].val.l == 0x00010000) ||
739 (iptr[0].val.l == 0x00020000) ||
740 (iptr[0].val.l == 0x00040000) ||
741 (iptr[0].val.l == 0x00080000) ||
742 (iptr[0].val.l == 0x00100000) ||
743 (iptr[0].val.l == 0x00200000) ||
744 (iptr[0].val.l == 0x00400000) ||
745 (iptr[0].val.l == 0x00800000) ||
746 (iptr[0].val.l == 0x01000000) ||
747 (iptr[0].val.l == 0x02000000) ||
748 (iptr[0].val.l == 0x04000000) ||
749 (iptr[0].val.l == 0x08000000) ||
750 (iptr[0].val.l == 0x10000000) ||
751 (iptr[0].val.l == 0x20000000) ||
752 (iptr[0].val.l == 0x40000000) ||
753 (iptr[0].val.l == 0x80000000)) {
754 iptr[0].opc = ICMD_LREMPOW2;
756 goto icmd_lconst_tail;
763 iptr[0].opc = ICMD_LANDCONST;
764 goto icmd_lconst_tail;
766 iptr[0].opc = ICMD_LORCONST;
767 goto icmd_lconst_tail;
769 iptr[0].opc = ICMD_LXORCONST;
770 goto icmd_lconst_tail;
772 #if !defined(NOLONG_CONDITIONAL)
774 if ((len > 1) && (iptr[2].val.i == 0)) {
775 switch (iptr[2].opc) {
777 iptr[0].opc = ICMD_IF_LEQ;
778 icmd_lconst_lcmp_tail:
779 iptr[0].op1 = iptr[2].op1;
782 /* iptr[1].opc = ICMD_NOP;
783 iptr[2].opc = ICMD_NOP; */
785 tbptr = block + block_index[iptr->op1];
787 iptr[0].target = (void *) tbptr;
789 MARKREACHED(tbptr, copy);
790 COUNT(count_pcmd_bra);
791 COUNT(count_pcmd_op);
794 iptr[0].opc = ICMD_IF_LNE;
795 goto icmd_lconst_lcmp_tail;
797 iptr[0].opc = ICMD_IF_LLT;
798 goto icmd_lconst_lcmp_tail;
800 iptr[0].opc = ICMD_IF_LGT;
801 goto icmd_lconst_lcmp_tail;
803 iptr[0].opc = ICMD_IF_LLE;
804 goto icmd_lconst_lcmp_tail;
806 iptr[0].opc = ICMD_IF_LGE;
807 goto icmd_lconst_lcmp_tail;
810 } /* switch (iptr[2].opc) */
811 } /* if (iptr[2].val.i == 0) */
824 COUNT(count_pcmd_load);
828 COUNT(count_pcmd_load);
832 COUNT(count_pcmd_load);
836 /* pop 0 push 1 load */
843 COUNT(count_load_instruction);
844 i = opcode-ICMD_ILOAD;
845 iptr->op1 = argren[iptr->op1];
846 locals[iptr->op1][i].type = i;
847 LOAD(i, LOCALVAR, iptr->op1);
857 COUNT(count_check_null);
858 COUNT(count_check_bound);
859 COUNT(count_pcmd_mem);
860 OP2IAT_1(opcode-ICMD_IALOAD);
866 COUNT(count_check_null);
867 COUNT(count_check_bound);
868 COUNT(count_pcmd_mem);
872 /* pop 0 push 0 iinc */
878 count_store_depth[10]++;
880 count_store_depth[i]++;
885 if ((copy->varkind == LOCALVAR) &&
886 (copy->varnum == iptr->op1)) {
887 copy->varkind = TEMPVAR;
896 /* pop 1 push 0 store */
906 i = opcode - ICMD_ISTORE;
907 locals[iptr->op1][i].type = i;
912 count_store_length[20]++;
914 count_store_length[i]++;
917 count_store_depth[10]++;
919 count_store_depth[i]++;
921 copy = curstack->prev;
924 if ((copy->varkind == LOCALVAR) &&
925 (copy->varnum == iptr->op1)) {
926 copy->varkind = TEMPVAR;
932 if ((new - curstack) == 1) {
933 curstack->varkind = LOCALVAR;
934 curstack->varnum = iptr->op1;
936 STORE(opcode-ICMD_ISTORE);
946 COUNT(count_check_null);
947 COUNT(count_check_bound);
948 COUNT(count_pcmd_mem);
949 OP3TIA_0(opcode-ICMD_IASTORE);
954 COUNT(count_check_null);
955 COUNT(count_check_bound);
956 COUNT(count_pcmd_mem);
971 COUNT(count_pcmd_return);
972 OP1_0(opcode-ICMD_IRETURN);
973 superblockend = true;
977 COUNT(count_check_null);
981 superblockend = true;
985 COUNT(count_pcmd_mem);
989 /* pop 1 push 0 branch */
993 COUNT(count_pcmd_bra);
995 tbptr = block + block_index[iptr->op1];
997 iptr[0].target = (void *) tbptr;
999 MARKREACHED(tbptr, copy);
1008 COUNT(count_pcmd_bra);
1009 #ifdef CONDITIONAL_LOADCONST
1011 tbptr = block + b_index;
1012 if ((b_count >= 3) &&
1013 ((b_index + 2) == block_index[iptr[0].op1]) &&
1014 (tbptr[1].pre_count == 1) &&
1015 (iptr[1].opc == ICMD_ICONST) &&
1016 (iptr[2].opc == ICMD_GOTO) &&
1017 ((b_index + 3) == block_index[iptr[2].op1]) &&
1018 (tbptr[2].pre_count == 1) &&
1019 (iptr[3].opc == ICMD_ICONST)) {
1020 OP1_1(TYPE_INT, TYPE_INT);
1021 switch (iptr[0].opc) {
1023 iptr[0].opc = ICMD_IFNE_ICONST;
1026 iptr[0].opc = ICMD_IFEQ_ICONST;
1029 iptr[0].opc = ICMD_IFGE_ICONST;
1032 iptr[0].opc = ICMD_IFLT_ICONST;
1035 iptr[0].opc = ICMD_IFLE_ICONST;
1038 iptr[0].opc = ICMD_IFGT_ICONST;
1041 iptr[0].val.i = iptr[1].val.i;
1042 iptr[1].opc = ICMD_ELSE_ICONST;
1043 iptr[1].val.i = iptr[3].val.i;
1044 iptr[2].opc = ICMD_NOP;
1045 iptr[3].opc = ICMD_NOP;
1046 tbptr[1].flags = BBDELETED;
1047 tbptr[2].flags = BBDELETED;
1048 tbptr[1].icount = 0;
1049 tbptr[2].icount = 0;
1050 if (tbptr[3].pre_count == 2) {
1051 len += tbptr[3].icount + 3;
1052 bptr->icount += tbptr[3].icount + 3;
1053 tbptr[3].flags = BBDELETED;
1054 tbptr[3].icount = 0;
1067 tbptr = block + block_index[iptr->op1];
1069 iptr[0].target = (void *) tbptr;
1071 MARKREACHED(tbptr, copy);
1074 /* pop 0 push 0 branch */
1077 COUNT(count_pcmd_bra);
1078 tbptr = block + block_index[iptr->op1];
1080 iptr[0].target = (void *) tbptr;
1082 MARKREACHED(tbptr, copy);
1084 superblockend = true;
1087 /* pop 1 push 0 table branch */
1089 case ICMD_TABLESWITCH:
1090 COUNT(count_pcmd_table);
1092 s4ptr = iptr->val.a;
1093 tbptr = block + block_index[*s4ptr++]; /* default */
1094 MARKREACHED(tbptr, copy);
1095 i = *s4ptr++; /* low */
1096 i = *s4ptr++ - i + 1; /* high */
1098 tptr = DMNEW(void*, i+1);
1099 iptr->target = (void *) tptr;
1101 tptr[0] = (void *) tbptr;
1105 tbptr = block + block_index[*s4ptr++];
1107 tptr[0] = (void *) tbptr;
1110 MARKREACHED(tbptr, copy);
1113 superblockend = true;
1116 /* pop 1 push 0 table branch */
1118 case ICMD_LOOKUPSWITCH:
1119 COUNT(count_pcmd_table);
1121 s4ptr = iptr->val.a;
1122 tbptr = block + block_index[*s4ptr++]; /* default */
1123 MARKREACHED(tbptr, copy);
1124 i = *s4ptr++; /* count */
1126 tptr = DMNEW(void*, i+1);
1127 iptr->target = (void *) tptr;
1129 tptr[0] = (void *) tbptr;
1133 tbptr = block + block_index[s4ptr[1]];
1135 tptr[0] = (void *) tbptr;
1138 MARKREACHED(tbptr, copy);
1142 superblockend = true;
1145 case ICMD_NULLCHECKPOP:
1146 case ICMD_MONITORENTER:
1147 COUNT(count_check_null);
1148 case ICMD_MONITOREXIT:
1152 /* pop 2 push 0 branch */
1154 case ICMD_IF_ICMPEQ:
1155 case ICMD_IF_ICMPNE:
1156 case ICMD_IF_ICMPLT:
1157 case ICMD_IF_ICMPGE:
1158 case ICMD_IF_ICMPGT:
1159 case ICMD_IF_ICMPLE:
1160 COUNT(count_pcmd_bra);
1162 tbptr = block + block_index[iptr->op1];
1164 iptr[0].target = (void *) tbptr;
1166 MARKREACHED(tbptr, copy);
1169 case ICMD_IF_ACMPEQ:
1170 case ICMD_IF_ACMPNE:
1171 COUNT(count_pcmd_bra);
1173 tbptr = block + block_index[iptr->op1];
1175 iptr[0].target = (void *) tbptr;
1177 MARKREACHED(tbptr, copy);
1183 COUNT(count_check_null);
1184 COUNT(count_pcmd_mem);
1185 OPTT2_0(iptr->op1,TYPE_ADR);
1190 if (! IS_2_WORD_TYPE(curstack->type)) {
1191 OP1_0ANY; /* second pop */
1194 iptr->opc = ICMD_POP;
1198 /* pop 0 push 1 dup */
1201 COUNT(count_dup_instruction);
1207 if (IS_2_WORD_TYPE(curstack->type)) {
1208 iptr->opc = ICMD_DUP;
1214 NEWSTACK(copy->prev->type, copy->prev->varkind,
1215 copy->prev->varnum);
1216 NEWSTACK(copy->type, copy->varkind,
1223 /* pop 2 push 3 dup */
1231 if (IS_2_WORD_TYPE(curstack->type)) {
1232 iptr->opc = ICMD_DUP_X1;
1240 /* pop 3 push 4 dup */
1244 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1245 iptr->opc = ICMD_DUP_X1;
1255 if (IS_2_WORD_TYPE(curstack->type)) {
1256 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1257 iptr->opc = ICMD_DUP_X1;
1261 iptr->opc = ICMD_DUP_X2;
1267 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1268 iptr->opc = ICMD_DUP2_X1;
1276 /* pop 2 push 2 swap */
1285 #if !SUPPORT_DIVISION
1286 iptr[0].opc = ICMD_BUILTIN2;
1287 iptr[0].op1 = TYPE_INT;
1288 iptr[0].val.a = BUILTIN_idiv;
1289 isleafmethod = false;
1294 #if !SUPPORT_DIVISION
1295 iptr[0].opc = ICMD_BUILTIN2;
1296 iptr[0].op1 = TYPE_INT;
1297 iptr[0].val.a = BUILTIN_irem;
1298 isleafmethod = false;
1312 COUNT(count_pcmd_op);
1317 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1318 iptr[0].opc = ICMD_BUILTIN2;
1319 iptr[0].op1 = TYPE_LNG;
1320 iptr[0].val.a = BUILTIN_ldiv;
1321 isleafmethod = false;
1326 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1327 iptr[0].opc = ICMD_BUILTIN2;
1328 iptr[0].op1 = TYPE_LNG;
1329 iptr[0].val.a = BUILTIN_lrem;
1330 isleafmethod = false;
1341 /* XXX DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1342 COUNT(count_pcmd_op);
1349 COUNT(count_pcmd_op);
1358 COUNT(count_pcmd_op);
1367 COUNT(count_pcmd_op);
1372 COUNT(count_pcmd_op);
1373 #if !defined(NOLONG_CONDITIONAL)
1374 if ((len > 0) && (iptr[1].val.i == 0)) {
1375 switch (iptr[1].opc) {
1377 iptr[0].opc = ICMD_IF_LCMPEQ;
1379 iptr[0].op1 = iptr[1].op1;
1382 /* iptr[1].opc = ICMD_NOP; */
1384 tbptr = block + block_index[iptr->op1];
1386 iptr[0].target = (void *) tbptr;
1388 MARKREACHED(tbptr, copy);
1389 COUNT(count_pcmd_bra);
1392 iptr[0].opc = ICMD_IF_LCMPNE;
1393 goto icmd_lcmp_if_tail;
1395 iptr[0].opc = ICMD_IF_LCMPLT;
1396 goto icmd_lcmp_if_tail;
1398 iptr[0].opc = ICMD_IF_LCMPGT;
1399 goto icmd_lcmp_if_tail;
1401 iptr[0].opc = ICMD_IF_LCMPLE;
1402 goto icmd_lcmp_if_tail;
1404 iptr[0].opc = ICMD_IF_LCMPGE;
1405 goto icmd_lcmp_if_tail;
1407 OPTT2_1(TYPE_LNG, TYPE_INT);
1412 OPTT2_1(TYPE_LNG, TYPE_INT);
1416 COUNT(count_pcmd_op);
1417 OPTT2_1(TYPE_FLT, TYPE_INT);
1421 COUNT(count_pcmd_op);
1422 OPTT2_1(TYPE_DBL, TYPE_INT);
1430 case ICMD_INT2SHORT:
1431 COUNT(count_pcmd_op);
1432 OP1_1(TYPE_INT, TYPE_INT);
1435 COUNT(count_pcmd_op);
1436 OP1_1(TYPE_LNG, TYPE_LNG);
1439 COUNT(count_pcmd_op);
1440 OP1_1(TYPE_FLT, TYPE_FLT);
1443 COUNT(count_pcmd_op);
1444 OP1_1(TYPE_DBL, TYPE_DBL);
1448 COUNT(count_pcmd_op);
1449 OP1_1(TYPE_INT, TYPE_LNG);
1452 COUNT(count_pcmd_op);
1453 OP1_1(TYPE_INT, TYPE_FLT);
1456 COUNT(count_pcmd_op);
1457 OP1_1(TYPE_INT, TYPE_DBL);
1460 COUNT(count_pcmd_op);
1461 OP1_1(TYPE_LNG, TYPE_INT);
1464 COUNT(count_pcmd_op);
1465 OP1_1(TYPE_LNG, TYPE_FLT);
1468 COUNT(count_pcmd_op);
1469 OP1_1(TYPE_LNG, TYPE_DBL);
1472 COUNT(count_pcmd_op);
1473 OP1_1(TYPE_FLT, TYPE_INT);
1476 COUNT(count_pcmd_op);
1477 OP1_1(TYPE_FLT, TYPE_LNG);
1480 COUNT(count_pcmd_op);
1481 OP1_1(TYPE_FLT, TYPE_DBL);
1484 COUNT(count_pcmd_op);
1485 OP1_1(TYPE_DBL, TYPE_INT);
1488 COUNT(count_pcmd_op);
1489 OP1_1(TYPE_DBL, TYPE_LNG);
1492 COUNT(count_pcmd_op);
1493 OP1_1(TYPE_DBL, TYPE_FLT);
1496 case ICMD_CHECKCAST:
1497 OP1_1(TYPE_ADR, TYPE_ADR);
1500 case ICMD_ARRAYLENGTH:
1501 case ICMD_INSTANCEOF:
1502 OP1_1(TYPE_ADR, TYPE_INT);
1506 case ICMD_ANEWARRAY:
1507 OP1_1(TYPE_INT, TYPE_ADR);
1511 COUNT(count_check_null);
1512 COUNT(count_pcmd_mem);
1513 OP1_1(TYPE_ADR, iptr->op1);
1518 case ICMD_GETSTATIC:
1519 COUNT(count_pcmd_mem);
1529 tbptr = block + block_index[iptr->op1];
1531 iptr[0].target = (void *) tbptr;
1533 /* XXX This is a dirty hack. The typechecker
1534 * needs it because the OP1_0ANY below
1535 * overwrites iptr->dst.
1537 iptr->val.a = (void*) iptr->dst;
1539 tbptr->type=BBTYPE_SBR;
1540 MARKREACHED(tbptr, copy);
1544 /* pop many push any */
1546 case ICMD_INVOKEVIRTUAL:
1547 case ICMD_INVOKESPECIAL:
1548 case ICMD_INVOKEINTERFACE:
1549 case ICMD_INVOKESTATIC:
1550 COUNT(count_pcmd_met);
1552 methodinfo *m = iptr->val.a;
1553 if (m->flags & ACC_STATIC)
1554 {COUNT(count_check_null);}
1556 if (i > arguments_num)
1559 #if defined(__X86_64__)
1567 (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1571 stackargs += (iarg < intreg_argnum) ? 0 : (iarg - intreg_argnum);
1572 stackargs += (farg < fltreg_argnum) ? 0 : (farg - fltreg_argnum);
1577 if (!(copy->flags & SAVEDVAR)) {
1578 copy->varkind = ARGVAR;
1579 if (IS_FLT_DBL_TYPE(copy->type)) {
1580 if (--farg < fltreg_argnum) {
1581 copy->varnum = farg;
1583 copy->varnum = --stackargs + intreg_argnum;
1586 if (--iarg < intreg_argnum) {
1587 copy->varnum = iarg;
1589 copy->varnum = --stackargs + intreg_argnum;
1593 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1601 if (! (copy->flags & SAVEDVAR)) {
1602 copy->varkind = ARGVAR;
1609 copy->flags |= SAVEDVAR;
1614 if (m->returntype != TYPE_VOID) {
1615 OP0_1(m->returntype);
1621 /* XXX DEBUG */ /*dolog("builtin3");*/
1623 if (! (curstack->flags & SAVEDVAR)) {
1624 curstack->varkind = ARGVAR;
1625 curstack->varnum = 2;
1627 if (3 > arguments_num) {
1635 /* XXX DEBUG */ /*dolog("builtin2");*/
1636 if (!(curstack->flags & SAVEDVAR)) {
1637 curstack->varkind = ARGVAR;
1638 curstack->varnum = 1;
1640 if (2 > arguments_num) {
1648 /* XXX DEBUG */ /*dolog("builtin1");*/
1649 if (!(curstack->flags & SAVEDVAR)) {
1650 curstack->varkind = ARGVAR;
1651 curstack->varnum = 0;
1653 if (1 > arguments_num) {
1659 copy->flags |= SAVEDVAR;
1662 if (iptr->op1 != TYPE_VOID)
1666 case ICMD_MULTIANEWARRAY:
1669 if ((i + intreg_argnum) > arguments_num)
1670 arguments_num = i + intreg_argnum;
1673 if (! (copy->flags & SAVEDVAR)) {
1674 copy->varkind = ARGVAR;
1675 copy->varnum = i + intreg_argnum;
1680 copy->flags |= SAVEDVAR;
1688 case ICMD_CLEAR_ARGREN:
1689 for (i = iptr->op1; i<maxlocals; i++)
1691 iptr->opc = opcode = ICMD_NOP;
1695 case ICMD_READONLY_ARG:
1696 case ICMD_READONLY_ARG+1:
1697 case ICMD_READONLY_ARG+2:
1698 case ICMD_READONLY_ARG+3:
1699 case ICMD_READONLY_ARG+4:
1702 if (curstack->varkind == LOCALVAR) {
1703 i = curstack->varnum;
1704 argren[iptr->op1] = i;
1707 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
1713 printf("ICMD %d at %d\n", iptr->opc, (int)(iptr-instr));
1714 panic("Missing ICMD code during stack analysis");
1716 /* XXX DEBUG */ /*dolog("iptr++");*/
1718 } /* while instructions */
1719 bptr->outstack = curstack;
1720 bptr->outdepth = stackdepth;
1724 superblockend = true;
1726 } /* while blocks */
1727 } while (repeat && !deadcode);
1730 if (block_count > count_max_basic_blocks)
1731 count_max_basic_blocks = block_count;
1732 count_basic_blocks += block_count;
1733 if (instr_count > count_max_javainstr)
1734 count_max_javainstr = instr_count;
1735 count_javainstr += instr_count;
1736 if (stack_count > count_upper_bound_new_stack)
1737 count_upper_bound_new_stack = stack_count;
1738 if ((new - stack) > count_max_new_stack)
1739 count_max_new_stack = (new - stack);
1741 b_count = block_count;
1743 while (--b_count >= 0) {
1744 if (bptr->flags > BBREACHED) {
1745 if (bptr->indepth >= 10)
1746 count_block_stack[10]++;
1748 count_block_stack[bptr->indepth]++;
1751 count_block_size_distribution[len]++;
1753 count_block_size_distribution[10]++;
1755 count_block_size_distribution[11]++;
1757 count_block_size_distribution[12]++;
1759 count_block_size_distribution[13]++;
1761 count_block_size_distribution[14]++;
1763 count_block_size_distribution[15]++;
1765 count_block_size_distribution[16]++;
1767 count_block_size_distribution[17]++;
1773 count_analyse_iterations[0]++;
1774 else if (loops == 2)
1775 count_analyse_iterations[1]++;
1776 else if (loops == 3)
1777 count_analyse_iterations[2]++;
1778 else if (loops == 4)
1779 count_analyse_iterations[3]++;
1781 count_analyse_iterations[4]++;
1783 if (block_count <= 5)
1784 count_method_bb_distribution[0]++;
1785 else if (block_count <= 10)
1786 count_method_bb_distribution[1]++;
1787 else if (block_count <= 15)
1788 count_method_bb_distribution[2]++;
1789 else if (block_count <= 20)
1790 count_method_bb_distribution[3]++;
1791 else if (block_count <= 30)
1792 count_method_bb_distribution[4]++;
1793 else if (block_count <= 40)
1794 count_method_bb_distribution[5]++;
1795 else if (block_count <= 50)
1796 count_method_bb_distribution[6]++;
1797 else if (block_count <= 75)
1798 count_method_bb_distribution[7]++;
1800 count_method_bb_distribution[8]++;
1805 void icmd_print_stack(stackptr s)
1822 /* XXX remove */ /* printf("(%d)",s->flags); fflush(stdout); */
1823 if (s->flags & SAVEDVAR)
1824 switch (s->varkind) {
1826 if (s->flags & INMEMORY)
1827 printf((regs_ok) ? " M%02d" : " M??", s->regoff);
1828 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1829 printf((regs_ok) ? " F%02d" : " F??", s->regoff);
1831 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1835 printf(" I%02d", s->varnum);
1838 printf(" L%02d", s->varnum);
1841 printf(" A%02d", s->varnum);
1844 printf(" !%02d", j);
1847 switch (s->varkind) {
1849 if (s->flags & INMEMORY)
1850 printf((regs_ok) ? " m%02d" : " m??", s->regoff);
1851 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1852 printf((regs_ok) ? " f%02d" : " f??", s->regoff);
1854 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1858 printf(" i%02d", s->varnum);
1861 printf(" l%02d", s->varnum);
1864 printf(" a%02d", s->varnum);
1867 printf(" ?%02d", j);
1875 static void print_reg(stackptr s) {
1877 if (s->flags & SAVEDVAR)
1878 switch (s->varkind) {
1880 if (s->flags & INMEMORY)
1881 printf(" tm%02d", s->regoff);
1883 printf(" tr%02d", s->regoff);
1886 printf(" s %02d", s->varnum);
1889 printf(" l %02d", s->varnum);
1892 printf(" a %02d", s->varnum);
1895 printf(" ! %02d", s->varnum);
1898 switch (s->varkind) {
1900 if (s->flags & INMEMORY)
1901 printf(" Tm%02d", s->regoff);
1903 printf(" Tr%02d", s->regoff);
1906 printf(" S %02d", s->varnum);
1909 printf(" L %02d", s->varnum);
1912 printf(" A %02d", s->varnum);
1915 printf(" ? %02d", s->varnum);
1925 char *icmd_builtin_name(functionptr bptr)
1927 builtin_descriptor *bdesc = builtin_desc;
1928 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
1930 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
1934 static char *jit_type[] = {
1943 void show_icmd_method()
1954 utf_fprint(stdout, class->name);
1956 utf_fprint(stdout, method->name);
1958 utf_fprint(stdout, method->descriptor);
1959 printf ("\n\nMax locals: %d\n", (int) maxlocals);
1960 printf ("Max stack: %d\n", (int) maxstack);
1962 printf ("Exceptions (Number: %d):\n", exceptiontablelength);
1963 for (ex = extable; ex != NULL; ex = ex->down) {
1964 printf(" L%03d ... ", ex->start->debug_nr );
1965 printf("L%03d = ", ex->end->debug_nr);
1966 printf("L%03d\n", ex->handler->debug_nr);
1969 printf ("Local Table:\n");
1970 for (i = 0; i < maxlocals; i++) {
1971 printf(" %3d: ", i);
1972 for (j = TYPE_INT; j <= TYPE_ADR; j++)
1973 if (locals[i][j].type >= 0) {
1974 printf(" (%s) ", jit_type[j]);
1975 if (locals[i][j].flags & INMEMORY)
1976 printf((regs_ok) ? "m%2d" : "m??", locals[i][j].regoff);
1977 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
1978 printf((regs_ok) ? "f%02d" : "f??", locals[i][j].regoff);
1980 if (regs_ok) printf("%3s",regs[locals[i][j].regoff]); else printf("???");
1987 printf ("Interface Table:\n");
1988 for (i = 0; i < maxstack; i++) {
1989 if ((interfaces[i][0].type >= 0) || (interfaces[i][1].type >= 0) ||
1990 (interfaces[i][2].type >= 0) || (interfaces[i][3].type >= 0) ||
1991 (interfaces[i][4].type >= 0)) {
1992 printf(" %3d: ", i);
1993 for (j = TYPE_INT; j <= TYPE_ADR; j++)
1994 if (interfaces[i][j].type >= 0) {
1995 printf(" (%s) ", jit_type[j]);
1996 if (interfaces[i][j].flags & SAVEDVAR) {
1997 if (interfaces[i][j].flags & INMEMORY)
1998 printf((regs_ok) ? "M%2d" : "M??", interfaces[i][j].regoff);
1999 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2000 printf((regs_ok) ? "F%02d" : "F??", interfaces[i][j].regoff);
2002 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2006 if (interfaces[i][j].flags & INMEMORY)
2007 printf((regs_ok) ? "m%2d" : "m??", interfaces[i][j].regoff);
2008 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2009 printf((regs_ok) ? "f%02d" : "f??", interfaces[i][j].regoff);
2011 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2020 if (showdisassemble) {
2021 #if defined(__I386__) || defined(__X86_64__)
2025 u1ptr = method->mcode + dseglen;
2026 for (i = 0; i < block[0].mpc; i++, u1ptr++) {
2027 a = disassinstr(u1ptr, i);
2033 s4ptr = (s4 *) (method->mcode + dseglen);
2034 for (i = 0; i < block[0].mpc; i += 4, s4ptr++) {
2035 disassinstr(*s4ptr, i);
2042 for (bptr = block; bptr != NULL; bptr = bptr->next) {
2043 show_icmd_block(bptr);
2048 show_icmd_block(basicblock *bptr)
2055 if (bptr->flags != BBDELETED) {
2056 deadcode = bptr->flags <= BBREACHED;
2059 for (j = method->maxstack; j > 0; j--)
2062 icmd_print_stack(bptr->instack);
2063 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2064 iptr = bptr->iinstr;
2066 for (i=0; i < bptr->icount; i++, iptr++) {
2069 for (j = method->maxstack; j > 0; j--)
2073 icmd_print_stack(iptr->dst);
2074 printf("] %4d ", i);
2075 /* XXX remove */ /*fflush(stdout);*/
2076 show_icmd(iptr,deadcode);
2080 if (showdisassemble && (!deadcode)) {
2081 #if defined(__I386__) || defined(__X86_64__)
2087 u1ptr = method->mcode + dseglen + i;
2089 if (bptr->next != NULL) {
2090 for (; i < bptr->next->mpc; i++, u1ptr++) {
2091 a = disassinstr(u1ptr, i);
2098 for (; u1ptr < (u1 *) (method->mcode + method->mcodelength); i++, u1ptr++) {
2099 a = disassinstr(u1ptr, i);
2108 s4ptr = (s4 *) (method->mcode + dseglen + i);
2110 if (bptr->next != NULL) {
2111 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2112 disassinstr(*s4ptr, i);
2117 for (; s4ptr < (s4 *) (method->mcode + method->mcodelength); i += 4, s4ptr++) {
2118 disassinstr(*s4ptr, i);
2128 show_icmd(instruction *iptr,bool deadcode)
2134 printf("%s",icmd_names[iptr->opc]);
2135 switch ((int) iptr->opc) {
2136 case ICMD_IADDCONST:
2137 case ICMD_ISUBCONST:
2138 case ICMD_IMULCONST:
2141 case ICMD_IREM0X10001:
2142 case ICMD_IANDCONST:
2144 case ICMD_IXORCONST:
2145 case ICMD_ISHLCONST:
2146 case ICMD_ISHRCONST:
2147 case ICMD_IUSHRCONST:
2148 case ICMD_LSHLCONST:
2149 case ICMD_LSHRCONST:
2150 case ICMD_LUSHRCONST:
2152 case ICMD_ELSE_ICONST:
2153 case ICMD_IFEQ_ICONST:
2154 case ICMD_IFNE_ICONST:
2155 case ICMD_IFLT_ICONST:
2156 case ICMD_IFGE_ICONST:
2157 case ICMD_IFGT_ICONST:
2158 case ICMD_IFLE_ICONST:
2159 printf(" %d", iptr->val.i);
2161 case ICMD_LADDCONST:
2162 case ICMD_LSUBCONST:
2163 case ICMD_LMULCONST:
2166 case ICMD_LANDCONST:
2168 case ICMD_LXORCONST:
2170 #if defined(__I386__)
2171 printf(" %lld", iptr->val.l);
2173 printf(" %ld", iptr->val.l);
2177 printf(" %f", iptr->val.f);
2180 printf(" %f", iptr->val.d);
2183 printf(" %p", iptr->val.a);
2187 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2188 case ICMD_PUTSTATIC:
2189 case ICMD_GETSTATIC:
2192 ((fieldinfo *) iptr->val.a)->class->name);
2195 ((fieldinfo *) iptr->val.a)->name);
2198 ((fieldinfo *) iptr->val.a)->descriptor);
2202 printf(" %d + %d", iptr->op1, iptr->val.i);
2237 printf(" %d", iptr->op1);
2242 ((classinfo *) iptr->val.a)->name);
2245 switch (iptr->op1) {
2272 case ICMD_ANEWARRAY:
2276 ((classinfo *) iptr->val.a)->name);
2279 case ICMD_MULTIANEWARRAY:
2282 printf(" %d ",iptr->op1);
2283 vft = (vftbl *)iptr->val.a;
2285 utf_fprint(stdout,vft->class->name);
2290 case ICMD_CHECKCAST:
2291 case ICMD_INSTANCEOF:
2293 classinfo *c = iptr->val.a;
2294 if (c->flags & ACC_INTERFACE)
2295 printf(" (INTERFACE) ");
2297 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2298 utf_fprint(stdout, c->name);
2304 printf(" %s", icmd_builtin_name((functionptr) iptr->val.a));
2306 case ICMD_INVOKEVIRTUAL:
2307 case ICMD_INVOKESPECIAL:
2308 case ICMD_INVOKESTATIC:
2309 case ICMD_INVOKEINTERFACE:
2312 ((methodinfo *) iptr->val.a)->class->name);
2315 ((methodinfo *) iptr->val.a)->name);
2323 if (deadcode || !iptr->target)
2324 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2326 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2334 if (deadcode || !iptr->target)
2335 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2337 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2342 case ICMD_IFNONNULL:
2343 case ICMD_IF_ICMPEQ:
2344 case ICMD_IF_ICMPNE:
2345 case ICMD_IF_ICMPLT:
2346 case ICMD_IF_ICMPGE:
2347 case ICMD_IF_ICMPGT:
2348 case ICMD_IF_ICMPLE:
2349 case ICMD_IF_LCMPEQ:
2350 case ICMD_IF_LCMPNE:
2351 case ICMD_IF_LCMPLT:
2352 case ICMD_IF_LCMPGE:
2353 case ICMD_IF_LCMPGT:
2354 case ICMD_IF_LCMPLE:
2355 case ICMD_IF_ACMPEQ:
2356 case ICMD_IF_ACMPNE:
2357 if (deadcode || !iptr->target)
2358 printf(" op1=%d", iptr->op1);
2360 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2362 case ICMD_TABLESWITCH:
2364 s4ptr = iptr->val.a;
2366 if (deadcode || !iptr->target) {
2367 printf(" %d;", *s4ptr);
2370 tptr = (void **) iptr->target;
2371 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2375 s4ptr++; /* skip default */
2376 j = *s4ptr++; /* low */
2377 j = *s4ptr++ - j; /* high */
2379 if (deadcode || !*tptr)
2380 printf(" %d", *s4ptr++);
2382 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2388 case ICMD_LOOKUPSWITCH:
2389 s4ptr = iptr->val.a;
2391 if (deadcode || !iptr->target) {
2392 printf(" %d;", *s4ptr);
2395 tptr = (void **) iptr->target;
2396 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2399 s4ptr++; /* default */
2400 j = *s4ptr++; /* count */
2403 if (deadcode || !*tptr) {
2404 s4ptr++; /* skip value */
2405 printf(" %d",*s4ptr++);
2408 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2417 * These are local overrides for various environment variables in Emacs.
2418 * Please do not remove this and leave it at the end of the file, where
2419 * Emacs will automagically detect them.
2420 * ---------------------------------------------------------------------
2423 * indent-tabs-mode: t