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 725 2003-12-10 00:24:36Z 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
367 stdopdescriptor *breplace;
368 breplace = find_builtin(opcode);
370 if (breplace && opcode == breplace->opcode) {
371 iptr[0].opc = breplace->icmd;
372 iptr[0].op1 = breplace->type_d;
373 iptr[0].val.a = breplace->builtin;
374 isleafmethod = false;
375 switch (breplace->icmd) {
390 case ICMD_CHECKASIZE:
392 case ICMD_IFEQ_ICONST:
393 case ICMD_IFNE_ICONST:
394 case ICMD_IFLT_ICONST:
395 case ICMD_IFGE_ICONST:
396 case ICMD_IFGT_ICONST:
397 case ICMD_IFLE_ICONST:
398 case ICMD_ELSE_ICONST:
403 locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
405 COUNT(count_pcmd_return);
407 superblockend = true;
410 /* pop 0 push 1 const */
413 COUNT(count_pcmd_load);
415 switch (iptr[1].opc) {
417 iptr[0].opc = ICMD_IADDCONST;
419 iptr[1].opc = ICMD_NOP;
420 OP1_1(TYPE_INT,TYPE_INT);
421 COUNT(count_pcmd_op);
424 iptr[0].opc = ICMD_ISUBCONST;
425 goto icmd_iconst_tail;
427 iptr[0].opc = ICMD_IMULCONST;
428 goto icmd_iconst_tail;
430 if (iptr[0].val.i == 0x00000002)
432 else if (iptr[0].val.i == 0x00000004)
434 else if (iptr[0].val.i == 0x00000008)
436 else if (iptr[0].val.i == 0x00000010)
438 else if (iptr[0].val.i == 0x00000020)
440 else if (iptr[0].val.i == 0x00000040)
442 else if (iptr[0].val.i == 0x00000080)
444 else if (iptr[0].val.i == 0x00000100)
446 else if (iptr[0].val.i == 0x00000200)
448 else if (iptr[0].val.i == 0x00000400)
450 else if (iptr[0].val.i == 0x00000800)
452 else if (iptr[0].val.i == 0x00001000)
454 else if (iptr[0].val.i == 0x00002000)
456 else if (iptr[0].val.i == 0x00004000)
458 else if (iptr[0].val.i == 0x00008000)
460 else if (iptr[0].val.i == 0x00010000)
462 else if (iptr[0].val.i == 0x00020000)
464 else if (iptr[0].val.i == 0x00040000)
466 else if (iptr[0].val.i == 0x00080000)
468 else if (iptr[0].val.i == 0x00100000)
470 else if (iptr[0].val.i == 0x00200000)
472 else if (iptr[0].val.i == 0x00400000)
474 else if (iptr[0].val.i == 0x00800000)
476 else if (iptr[0].val.i == 0x01000000)
478 else if (iptr[0].val.i == 0x02000000)
480 else if (iptr[0].val.i == 0x04000000)
482 else if (iptr[0].val.i == 0x08000000)
484 else if (iptr[0].val.i == 0x10000000)
486 else if (iptr[0].val.i == 0x20000000)
488 else if (iptr[0].val.i == 0x40000000)
490 else if (iptr[0].val.i == 0x80000000)
496 iptr[0].opc = ICMD_IDIVPOW2;
497 goto icmd_iconst_tail;
499 #if !defined(NO_DIV_OPT)
500 if (iptr[0].val.i == 0x10001) {
501 iptr[0].opc = ICMD_IREM0X10001;
502 goto icmd_iconst_tail;
505 if ((iptr[0].val.i == 0x00000002) ||
506 (iptr[0].val.i == 0x00000004) ||
507 (iptr[0].val.i == 0x00000008) ||
508 (iptr[0].val.i == 0x00000010) ||
509 (iptr[0].val.i == 0x00000020) ||
510 (iptr[0].val.i == 0x00000040) ||
511 (iptr[0].val.i == 0x00000080) ||
512 (iptr[0].val.i == 0x00000100) ||
513 (iptr[0].val.i == 0x00000200) ||
514 (iptr[0].val.i == 0x00000400) ||
515 (iptr[0].val.i == 0x00000800) ||
516 (iptr[0].val.i == 0x00001000) ||
517 (iptr[0].val.i == 0x00002000) ||
518 (iptr[0].val.i == 0x00004000) ||
519 (iptr[0].val.i == 0x00008000) ||
520 (iptr[0].val.i == 0x00010000) ||
521 (iptr[0].val.i == 0x00020000) ||
522 (iptr[0].val.i == 0x00040000) ||
523 (iptr[0].val.i == 0x00080000) ||
524 (iptr[0].val.i == 0x00100000) ||
525 (iptr[0].val.i == 0x00200000) ||
526 (iptr[0].val.i == 0x00400000) ||
527 (iptr[0].val.i == 0x00800000) ||
528 (iptr[0].val.i == 0x01000000) ||
529 (iptr[0].val.i == 0x02000000) ||
530 (iptr[0].val.i == 0x04000000) ||
531 (iptr[0].val.i == 0x08000000) ||
532 (iptr[0].val.i == 0x10000000) ||
533 (iptr[0].val.i == 0x20000000) ||
534 (iptr[0].val.i == 0x40000000) ||
535 (iptr[0].val.i == 0x80000000)) {
536 iptr[0].opc = ICMD_IREMPOW2;
538 goto icmd_iconst_tail;
543 iptr[0].opc = ICMD_IANDCONST;
544 goto icmd_iconst_tail;
546 iptr[0].opc = ICMD_IORCONST;
547 goto icmd_iconst_tail;
549 iptr[0].opc = ICMD_IXORCONST;
550 goto icmd_iconst_tail;
552 iptr[0].opc = ICMD_ISHLCONST;
553 goto icmd_iconst_tail;
555 iptr[0].opc = ICMD_ISHRCONST;
556 goto icmd_iconst_tail;
558 iptr[0].opc = ICMD_IUSHRCONST;
559 goto icmd_iconst_tail;
560 #if SUPPORT_LONG_SHIFT
562 iptr[0].opc = ICMD_LSHLCONST;
563 goto icmd_lconst_tail;
565 iptr[0].opc = ICMD_LSHRCONST;
566 goto icmd_lconst_tail;
568 iptr[0].opc = ICMD_LUSHRCONST;
569 goto icmd_lconst_tail;
572 iptr[0].opc = ICMD_IFEQ;
574 iptr[0].op1 = iptr[1].op1;
577 /* iptr[1].opc = ICMD_NOP; */
579 tbptr = block + block_index[iptr->op1];
581 iptr[0].target = (void *) tbptr;
583 MARKREACHED(tbptr, copy);
584 COUNT(count_pcmd_bra);
587 iptr[0].opc = ICMD_IFLT;
588 goto icmd_if_icmp_tail;
590 iptr[0].opc = ICMD_IFLE;
591 goto icmd_if_icmp_tail;
593 iptr[0].opc = ICMD_IFNE;
594 goto icmd_if_icmp_tail;
596 iptr[0].opc = ICMD_IFGT;
597 goto icmd_if_icmp_tail;
599 iptr[0].opc = ICMD_IFGE;
600 goto icmd_if_icmp_tail;
609 COUNT(count_pcmd_load);
611 switch (iptr[1].opc) {
614 iptr[0].opc = ICMD_LADDCONST;
616 iptr[1].opc = ICMD_NOP;
617 OP1_1(TYPE_LNG,TYPE_LNG);
618 COUNT(count_pcmd_op);
621 iptr[0].opc = ICMD_LSUBCONST;
622 goto icmd_lconst_tail;
626 iptr[0].opc = ICMD_LMULCONST;
627 goto icmd_lconst_tail;
631 if (iptr[0].val.l == 0x00000002)
633 else if (iptr[0].val.l == 0x00000004)
635 else if (iptr[0].val.l == 0x00000008)
637 else if (iptr[0].val.l == 0x00000010)
639 else if (iptr[0].val.l == 0x00000020)
641 else if (iptr[0].val.l == 0x00000040)
643 else if (iptr[0].val.l == 0x00000080)
645 else if (iptr[0].val.l == 0x00000100)
647 else if (iptr[0].val.l == 0x00000200)
649 else if (iptr[0].val.l == 0x00000400)
651 else if (iptr[0].val.l == 0x00000800)
653 else if (iptr[0].val.l == 0x00001000)
655 else if (iptr[0].val.l == 0x00002000)
657 else if (iptr[0].val.l == 0x00004000)
659 else if (iptr[0].val.l == 0x00008000)
661 else if (iptr[0].val.l == 0x00010000)
663 else if (iptr[0].val.l == 0x00020000)
665 else if (iptr[0].val.l == 0x00040000)
667 else if (iptr[0].val.l == 0x00080000)
669 else if (iptr[0].val.l == 0x00100000)
671 else if (iptr[0].val.l == 0x00200000)
673 else if (iptr[0].val.l == 0x00400000)
675 else if (iptr[0].val.l == 0x00800000)
677 else if (iptr[0].val.l == 0x01000000)
679 else if (iptr[0].val.l == 0x02000000)
681 else if (iptr[0].val.l == 0x04000000)
683 else if (iptr[0].val.l == 0x08000000)
685 else if (iptr[0].val.l == 0x10000000)
687 else if (iptr[0].val.l == 0x20000000)
689 else if (iptr[0].val.l == 0x40000000)
691 else if (iptr[0].val.l == 0x80000000)
697 iptr[0].opc = ICMD_LDIVPOW2;
698 goto icmd_lconst_tail;
700 #if !defined(NO_DIV_OPT)
701 if (iptr[0].val.l == 0x10001) {
702 iptr[0].opc = ICMD_LREM0X10001;
703 goto icmd_lconst_tail;
706 if ((iptr[0].val.l == 0x00000002) ||
707 (iptr[0].val.l == 0x00000004) ||
708 (iptr[0].val.l == 0x00000008) ||
709 (iptr[0].val.l == 0x00000010) ||
710 (iptr[0].val.l == 0x00000020) ||
711 (iptr[0].val.l == 0x00000040) ||
712 (iptr[0].val.l == 0x00000080) ||
713 (iptr[0].val.l == 0x00000100) ||
714 (iptr[0].val.l == 0x00000200) ||
715 (iptr[0].val.l == 0x00000400) ||
716 (iptr[0].val.l == 0x00000800) ||
717 (iptr[0].val.l == 0x00001000) ||
718 (iptr[0].val.l == 0x00002000) ||
719 (iptr[0].val.l == 0x00004000) ||
720 (iptr[0].val.l == 0x00008000) ||
721 (iptr[0].val.l == 0x00010000) ||
722 (iptr[0].val.l == 0x00020000) ||
723 (iptr[0].val.l == 0x00040000) ||
724 (iptr[0].val.l == 0x00080000) ||
725 (iptr[0].val.l == 0x00100000) ||
726 (iptr[0].val.l == 0x00200000) ||
727 (iptr[0].val.l == 0x00400000) ||
728 (iptr[0].val.l == 0x00800000) ||
729 (iptr[0].val.l == 0x01000000) ||
730 (iptr[0].val.l == 0x02000000) ||
731 (iptr[0].val.l == 0x04000000) ||
732 (iptr[0].val.l == 0x08000000) ||
733 (iptr[0].val.l == 0x10000000) ||
734 (iptr[0].val.l == 0x20000000) ||
735 (iptr[0].val.l == 0x40000000) ||
736 (iptr[0].val.l == 0x80000000)) {
737 iptr[0].opc = ICMD_LREMPOW2;
739 goto icmd_lconst_tail;
746 iptr[0].opc = ICMD_LANDCONST;
747 goto icmd_lconst_tail;
749 iptr[0].opc = ICMD_LORCONST;
750 goto icmd_lconst_tail;
752 iptr[0].opc = ICMD_LXORCONST;
753 goto icmd_lconst_tail;
755 #if !defined(NOLONG_CONDITIONAL)
757 if ((len > 1) && (iptr[2].val.i == 0)) {
758 switch (iptr[2].opc) {
760 iptr[0].opc = ICMD_IF_LEQ;
761 icmd_lconst_lcmp_tail:
762 iptr[0].op1 = iptr[2].op1;
765 /* iptr[1].opc = ICMD_NOP;
766 iptr[2].opc = ICMD_NOP; */
768 tbptr = block + block_index[iptr->op1];
770 iptr[0].target = (void *) tbptr;
772 MARKREACHED(tbptr, copy);
773 COUNT(count_pcmd_bra);
774 COUNT(count_pcmd_op);
777 iptr[0].opc = ICMD_IF_LNE;
778 goto icmd_lconst_lcmp_tail;
780 iptr[0].opc = ICMD_IF_LLT;
781 goto icmd_lconst_lcmp_tail;
783 iptr[0].opc = ICMD_IF_LGT;
784 goto icmd_lconst_lcmp_tail;
786 iptr[0].opc = ICMD_IF_LLE;
787 goto icmd_lconst_lcmp_tail;
789 iptr[0].opc = ICMD_IF_LGE;
790 goto icmd_lconst_lcmp_tail;
793 } /* switch (iptr[2].opc) */
794 } /* if (iptr[2].val.i == 0) */
807 COUNT(count_pcmd_load);
811 COUNT(count_pcmd_load);
815 COUNT(count_pcmd_load);
819 /* pop 0 push 1 load */
826 COUNT(count_load_instruction);
827 i = opcode-ICMD_ILOAD;
828 iptr->op1 = argren[iptr->op1];
829 locals[iptr->op1][i].type = i;
830 LOAD(i, LOCALVAR, iptr->op1);
840 COUNT(count_check_null);
841 COUNT(count_check_bound);
842 COUNT(count_pcmd_mem);
843 OP2IAT_1(opcode-ICMD_IALOAD);
849 COUNT(count_check_null);
850 COUNT(count_check_bound);
851 COUNT(count_pcmd_mem);
855 /* pop 0 push 0 iinc */
861 count_store_depth[10]++;
863 count_store_depth[i]++;
868 if ((copy->varkind == LOCALVAR) &&
869 (copy->varnum == iptr->op1)) {
870 copy->varkind = TEMPVAR;
879 /* pop 1 push 0 store */
889 i = opcode - ICMD_ISTORE;
890 locals[iptr->op1][i].type = i;
895 count_store_length[20]++;
897 count_store_length[i]++;
900 count_store_depth[10]++;
902 count_store_depth[i]++;
904 copy = curstack->prev;
907 if ((copy->varkind == LOCALVAR) &&
908 (copy->varnum == iptr->op1)) {
909 copy->varkind = TEMPVAR;
915 if ((new - curstack) == 1) {
916 curstack->varkind = LOCALVAR;
917 curstack->varnum = iptr->op1;
919 STORE(opcode-ICMD_ISTORE);
929 COUNT(count_check_null);
930 COUNT(count_check_bound);
931 COUNT(count_pcmd_mem);
932 OP3TIA_0(opcode-ICMD_IASTORE);
937 COUNT(count_check_null);
938 COUNT(count_check_bound);
939 COUNT(count_pcmd_mem);
954 COUNT(count_pcmd_return);
955 OP1_0(opcode-ICMD_IRETURN);
956 superblockend = true;
960 COUNT(count_check_null);
964 superblockend = true;
968 COUNT(count_pcmd_mem);
972 /* pop 1 push 0 branch */
976 COUNT(count_pcmd_bra);
978 tbptr = block + block_index[iptr->op1];
980 iptr[0].target = (void *) tbptr;
982 MARKREACHED(tbptr, copy);
991 COUNT(count_pcmd_bra);
992 #ifdef CONDITIONAL_LOADCONST
994 tbptr = block + b_index;
995 if ((b_count >= 3) &&
996 ((b_index + 2) == block_index[iptr[0].op1]) &&
997 (tbptr[1].pre_count == 1) &&
998 (iptr[1].opc == ICMD_ICONST) &&
999 (iptr[2].opc == ICMD_GOTO) &&
1000 ((b_index + 3) == block_index[iptr[2].op1]) &&
1001 (tbptr[2].pre_count == 1) &&
1002 (iptr[3].opc == ICMD_ICONST)) {
1003 OP1_1(TYPE_INT, TYPE_INT);
1004 switch (iptr[0].opc) {
1006 iptr[0].opc = ICMD_IFNE_ICONST;
1009 iptr[0].opc = ICMD_IFEQ_ICONST;
1012 iptr[0].opc = ICMD_IFGE_ICONST;
1015 iptr[0].opc = ICMD_IFLT_ICONST;
1018 iptr[0].opc = ICMD_IFLE_ICONST;
1021 iptr[0].opc = ICMD_IFGT_ICONST;
1024 iptr[0].val.i = iptr[1].val.i;
1025 iptr[1].opc = ICMD_ELSE_ICONST;
1026 iptr[1].val.i = iptr[3].val.i;
1027 iptr[2].opc = ICMD_NOP;
1028 iptr[3].opc = ICMD_NOP;
1029 tbptr[1].flags = BBDELETED;
1030 tbptr[2].flags = BBDELETED;
1031 tbptr[1].icount = 0;
1032 tbptr[2].icount = 0;
1033 if (tbptr[3].pre_count == 2) {
1034 len += tbptr[3].icount + 3;
1035 bptr->icount += tbptr[3].icount + 3;
1036 tbptr[3].flags = BBDELETED;
1037 tbptr[3].icount = 0;
1050 tbptr = block + block_index[iptr->op1];
1052 iptr[0].target = (void *) tbptr;
1054 MARKREACHED(tbptr, copy);
1057 /* pop 0 push 0 branch */
1060 COUNT(count_pcmd_bra);
1061 tbptr = block + block_index[iptr->op1];
1063 iptr[0].target = (void *) tbptr;
1065 MARKREACHED(tbptr, copy);
1067 superblockend = true;
1070 /* pop 1 push 0 table branch */
1072 case ICMD_TABLESWITCH:
1073 COUNT(count_pcmd_table);
1075 s4ptr = iptr->val.a;
1076 tbptr = block + block_index[*s4ptr++]; /* default */
1077 MARKREACHED(tbptr, copy);
1078 i = *s4ptr++; /* low */
1079 i = *s4ptr++ - i + 1; /* high */
1081 tptr = DMNEW(void*, i+1);
1082 iptr->target = (void *) tptr;
1084 tptr[0] = (void *) tbptr;
1088 tbptr = block + block_index[*s4ptr++];
1090 tptr[0] = (void *) tbptr;
1093 MARKREACHED(tbptr, copy);
1096 superblockend = true;
1099 /* pop 1 push 0 table branch */
1101 case ICMD_LOOKUPSWITCH:
1102 COUNT(count_pcmd_table);
1104 s4ptr = iptr->val.a;
1105 tbptr = block + block_index[*s4ptr++]; /* default */
1106 MARKREACHED(tbptr, copy);
1107 i = *s4ptr++; /* count */
1109 tptr = DMNEW(void*, i+1);
1110 iptr->target = (void *) tptr;
1112 tptr[0] = (void *) tbptr;
1116 tbptr = block + block_index[s4ptr[1]];
1118 tptr[0] = (void *) tbptr;
1121 MARKREACHED(tbptr, copy);
1125 superblockend = true;
1128 case ICMD_NULLCHECKPOP:
1129 case ICMD_MONITORENTER:
1130 COUNT(count_check_null);
1131 case ICMD_MONITOREXIT:
1135 /* pop 2 push 0 branch */
1137 case ICMD_IF_ICMPEQ:
1138 case ICMD_IF_ICMPNE:
1139 case ICMD_IF_ICMPLT:
1140 case ICMD_IF_ICMPGE:
1141 case ICMD_IF_ICMPGT:
1142 case ICMD_IF_ICMPLE:
1143 COUNT(count_pcmd_bra);
1145 tbptr = block + block_index[iptr->op1];
1147 iptr[0].target = (void *) tbptr;
1149 MARKREACHED(tbptr, copy);
1152 case ICMD_IF_ACMPEQ:
1153 case ICMD_IF_ACMPNE:
1154 COUNT(count_pcmd_bra);
1156 tbptr = block + block_index[iptr->op1];
1158 iptr[0].target = (void *) tbptr;
1160 MARKREACHED(tbptr, copy);
1166 COUNT(count_check_null);
1167 COUNT(count_pcmd_mem);
1168 OPTT2_0(iptr->op1,TYPE_ADR);
1173 if (! IS_2_WORD_TYPE(curstack->type)) {
1174 OP1_0ANY; /* second pop */
1177 iptr->opc = ICMD_POP;
1181 /* pop 0 push 1 dup */
1184 COUNT(count_dup_instruction);
1190 if (IS_2_WORD_TYPE(curstack->type)) {
1191 iptr->opc = ICMD_DUP;
1197 NEWSTACK(copy->prev->type, copy->prev->varkind,
1198 copy->prev->varnum);
1199 NEWSTACK(copy->type, copy->varkind,
1206 /* pop 2 push 3 dup */
1214 if (IS_2_WORD_TYPE(curstack->type)) {
1215 iptr->opc = ICMD_DUP_X1;
1223 /* pop 3 push 4 dup */
1227 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1228 iptr->opc = ICMD_DUP_X1;
1238 if (IS_2_WORD_TYPE(curstack->type)) {
1239 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1240 iptr->opc = ICMD_DUP_X1;
1244 iptr->opc = ICMD_DUP_X2;
1250 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1251 iptr->opc = ICMD_DUP2_X1;
1259 /* pop 2 push 2 swap */
1268 #if !SUPPORT_DIVISION
1269 iptr[0].opc = ICMD_BUILTIN2;
1270 iptr[0].op1 = TYPE_INT;
1271 iptr[0].val.a = (functionptr) asm_builtin_idiv;
1272 isleafmethod = false;
1277 #if !SUPPORT_DIVISION
1278 iptr[0].opc = ICMD_BUILTIN2;
1279 iptr[0].op1 = TYPE_INT;
1280 iptr[0].val.a = (functionptr) asm_builtin_irem;
1281 isleafmethod = false;
1295 COUNT(count_pcmd_op);
1300 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1301 iptr[0].opc = ICMD_BUILTIN2;
1302 iptr[0].op1 = TYPE_LNG;
1303 iptr[0].val.a = (functionptr) asm_builtin_ldiv;
1304 isleafmethod = false;
1309 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1310 iptr[0].opc = ICMD_BUILTIN2;
1311 iptr[0].op1 = TYPE_LNG;
1312 iptr[0].val.a = (functionptr) asm_builtin_lrem;
1313 isleafmethod = false;
1324 /* XXX DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1325 COUNT(count_pcmd_op);
1332 COUNT(count_pcmd_op);
1341 COUNT(count_pcmd_op);
1350 COUNT(count_pcmd_op);
1355 COUNT(count_pcmd_op);
1356 #if !defined(NOLONG_CONDITIONAL)
1357 if ((len > 0) && (iptr[1].val.i == 0)) {
1358 switch (iptr[1].opc) {
1360 iptr[0].opc = ICMD_IF_LCMPEQ;
1362 iptr[0].op1 = iptr[1].op1;
1365 /* iptr[1].opc = ICMD_NOP; */
1367 tbptr = block + block_index[iptr->op1];
1369 iptr[0].target = (void *) tbptr;
1371 MARKREACHED(tbptr, copy);
1372 COUNT(count_pcmd_bra);
1375 iptr[0].opc = ICMD_IF_LCMPNE;
1376 goto icmd_lcmp_if_tail;
1378 iptr[0].opc = ICMD_IF_LCMPLT;
1379 goto icmd_lcmp_if_tail;
1381 iptr[0].opc = ICMD_IF_LCMPGT;
1382 goto icmd_lcmp_if_tail;
1384 iptr[0].opc = ICMD_IF_LCMPLE;
1385 goto icmd_lcmp_if_tail;
1387 iptr[0].opc = ICMD_IF_LCMPGE;
1388 goto icmd_lcmp_if_tail;
1390 OPTT2_1(TYPE_LNG, TYPE_INT);
1395 OPTT2_1(TYPE_LNG, TYPE_INT);
1399 COUNT(count_pcmd_op);
1400 OPTT2_1(TYPE_FLT, TYPE_INT);
1404 COUNT(count_pcmd_op);
1405 OPTT2_1(TYPE_DBL, TYPE_INT);
1413 case ICMD_INT2SHORT:
1414 COUNT(count_pcmd_op);
1415 OP1_1(TYPE_INT, TYPE_INT);
1418 COUNT(count_pcmd_op);
1419 OP1_1(TYPE_LNG, TYPE_LNG);
1422 COUNT(count_pcmd_op);
1423 OP1_1(TYPE_FLT, TYPE_FLT);
1426 COUNT(count_pcmd_op);
1427 OP1_1(TYPE_DBL, TYPE_DBL);
1431 COUNT(count_pcmd_op);
1432 OP1_1(TYPE_INT, TYPE_LNG);
1435 COUNT(count_pcmd_op);
1436 OP1_1(TYPE_INT, TYPE_FLT);
1439 COUNT(count_pcmd_op);
1440 OP1_1(TYPE_INT, TYPE_DBL);
1443 COUNT(count_pcmd_op);
1444 OP1_1(TYPE_LNG, TYPE_INT);
1447 COUNT(count_pcmd_op);
1448 OP1_1(TYPE_LNG, TYPE_FLT);
1451 COUNT(count_pcmd_op);
1452 OP1_1(TYPE_LNG, TYPE_DBL);
1455 COUNT(count_pcmd_op);
1456 OP1_1(TYPE_FLT, TYPE_INT);
1459 COUNT(count_pcmd_op);
1460 OP1_1(TYPE_FLT, TYPE_LNG);
1463 COUNT(count_pcmd_op);
1464 OP1_1(TYPE_FLT, TYPE_DBL);
1467 COUNT(count_pcmd_op);
1468 OP1_1(TYPE_DBL, TYPE_INT);
1471 COUNT(count_pcmd_op);
1472 OP1_1(TYPE_DBL, TYPE_LNG);
1475 COUNT(count_pcmd_op);
1476 OP1_1(TYPE_DBL, TYPE_FLT);
1479 case ICMD_CHECKCAST:
1480 OP1_1(TYPE_ADR, TYPE_ADR);
1483 case ICMD_ARRAYLENGTH:
1484 case ICMD_INSTANCEOF:
1485 OP1_1(TYPE_ADR, TYPE_INT);
1489 case ICMD_ANEWARRAY:
1490 OP1_1(TYPE_INT, TYPE_ADR);
1494 COUNT(count_check_null);
1495 COUNT(count_pcmd_mem);
1496 OP1_1(TYPE_ADR, iptr->op1);
1501 case ICMD_GETSTATIC:
1502 COUNT(count_pcmd_mem);
1512 tbptr = block + block_index[iptr->op1];
1514 iptr[0].target = (void *) tbptr;
1516 /* XXX This is a dirty hack. The typechecker
1517 * needs it because the OP1_0ANY below
1518 * overwrites iptr->dst.
1520 iptr->val.a = (void*) iptr->dst;
1522 tbptr->type=BBTYPE_SBR;
1523 MARKREACHED(tbptr, copy);
1527 /* pop many push any */
1529 case ICMD_INVOKEVIRTUAL:
1530 case ICMD_INVOKESPECIAL:
1531 case ICMD_INVOKEINTERFACE:
1532 case ICMD_INVOKESTATIC:
1533 COUNT(count_pcmd_met);
1535 methodinfo *m = iptr->val.a;
1536 if (m->flags & ACC_STATIC)
1537 {COUNT(count_check_null);}
1539 if (i > arguments_num)
1542 #if defined(__X86_64__)
1550 (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1554 stackargs += (iarg < intreg_argnum) ? 0 : (iarg - intreg_argnum);
1555 stackargs += (farg < fltreg_argnum) ? 0 : (farg - fltreg_argnum);
1560 if (!(copy->flags & SAVEDVAR)) {
1561 copy->varkind = ARGVAR;
1562 if (IS_FLT_DBL_TYPE(copy->type)) {
1563 if (--farg < fltreg_argnum) {
1564 copy->varnum = farg;
1566 copy->varnum = --stackargs + intreg_argnum;
1569 if (--iarg < intreg_argnum) {
1570 copy->varnum = iarg;
1572 copy->varnum = --stackargs + intreg_argnum;
1576 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1584 if (! (copy->flags & SAVEDVAR)) {
1585 copy->varkind = ARGVAR;
1592 copy->flags |= SAVEDVAR;
1597 if (m->returntype != TYPE_VOID) {
1598 OP0_1(m->returntype);
1604 /* XXX DEBUG */ /*dolog("builtin3");*/
1606 if (! (curstack->flags & SAVEDVAR)) {
1607 curstack->varkind = ARGVAR;
1608 curstack->varnum = 2;
1610 if (3 > arguments_num) {
1618 /* XXX DEBUG */ /*dolog("builtin2");*/
1619 if (!(curstack->flags & SAVEDVAR)) {
1620 curstack->varkind = ARGVAR;
1621 curstack->varnum = 1;
1623 if (2 > arguments_num) {
1631 /* XXX DEBUG */ /*dolog("builtin1");*/
1632 if (!(curstack->flags & SAVEDVAR)) {
1633 curstack->varkind = ARGVAR;
1634 curstack->varnum = 0;
1636 if (1 > arguments_num) {
1642 copy->flags |= SAVEDVAR;
1645 if (iptr->op1 != TYPE_VOID)
1649 case ICMD_MULTIANEWARRAY:
1652 if ((i + intreg_argnum) > arguments_num)
1653 arguments_num = i + intreg_argnum;
1656 if (! (copy->flags & SAVEDVAR)) {
1657 copy->varkind = ARGVAR;
1658 copy->varnum = i + intreg_argnum;
1663 copy->flags |= SAVEDVAR;
1671 case ICMD_CLEAR_ARGREN:
1672 for (i = iptr->op1; i<maxlocals; i++)
1674 iptr->opc = opcode = ICMD_NOP;
1678 case ICMD_READONLY_ARG:
1679 case ICMD_READONLY_ARG+1:
1680 case ICMD_READONLY_ARG+2:
1681 case ICMD_READONLY_ARG+3:
1682 case ICMD_READONLY_ARG+4:
1685 if (curstack->varkind == LOCALVAR) {
1686 i = curstack->varnum;
1687 argren[iptr->op1] = i;
1690 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
1696 printf("ICMD %d at %d\n", iptr->opc, (int)(iptr-instr));
1697 panic("Missing ICMD code during stack analysis");
1699 /* XXX DEBUG */ /*dolog("iptr++");*/
1701 } /* while instructions */
1702 bptr->outstack = curstack;
1703 bptr->outdepth = stackdepth;
1707 superblockend = true;
1709 } /* while blocks */
1710 } while (repeat && !deadcode);
1713 if (block_count > count_max_basic_blocks)
1714 count_max_basic_blocks = block_count;
1715 count_basic_blocks += block_count;
1716 if (instr_count > count_max_javainstr)
1717 count_max_javainstr = instr_count;
1718 count_javainstr += instr_count;
1719 if (stack_count > count_upper_bound_new_stack)
1720 count_upper_bound_new_stack = stack_count;
1721 if ((new - stack) > count_max_new_stack)
1722 count_max_new_stack = (new - stack);
1724 b_count = block_count;
1726 while (--b_count >= 0) {
1727 if (bptr->flags > BBREACHED) {
1728 if (bptr->indepth >= 10)
1729 count_block_stack[10]++;
1731 count_block_stack[bptr->indepth]++;
1734 count_block_size_distribution[len]++;
1736 count_block_size_distribution[10]++;
1738 count_block_size_distribution[11]++;
1740 count_block_size_distribution[12]++;
1742 count_block_size_distribution[13]++;
1744 count_block_size_distribution[14]++;
1746 count_block_size_distribution[15]++;
1748 count_block_size_distribution[16]++;
1750 count_block_size_distribution[17]++;
1756 count_analyse_iterations[0]++;
1757 else if (loops == 2)
1758 count_analyse_iterations[1]++;
1759 else if (loops == 3)
1760 count_analyse_iterations[2]++;
1761 else if (loops == 4)
1762 count_analyse_iterations[3]++;
1764 count_analyse_iterations[4]++;
1766 if (block_count <= 5)
1767 count_method_bb_distribution[0]++;
1768 else if (block_count <= 10)
1769 count_method_bb_distribution[1]++;
1770 else if (block_count <= 15)
1771 count_method_bb_distribution[2]++;
1772 else if (block_count <= 20)
1773 count_method_bb_distribution[3]++;
1774 else if (block_count <= 30)
1775 count_method_bb_distribution[4]++;
1776 else if (block_count <= 40)
1777 count_method_bb_distribution[5]++;
1778 else if (block_count <= 50)
1779 count_method_bb_distribution[6]++;
1780 else if (block_count <= 75)
1781 count_method_bb_distribution[7]++;
1783 count_method_bb_distribution[8]++;
1788 void icmd_print_stack(stackptr s)
1805 /* XXX remove */ /* printf("(%d)",s->flags); fflush(stdout); */
1806 if (s->flags & SAVEDVAR)
1807 switch (s->varkind) {
1809 if (s->flags & INMEMORY)
1810 printf((regs_ok) ? " M%02d" : " M??", s->regoff);
1811 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1812 printf((regs_ok) ? " F%02d" : " F??", s->regoff);
1814 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1818 printf(" I%02d", s->varnum);
1821 printf(" L%02d", s->varnum);
1824 printf(" A%02d", s->varnum);
1827 printf(" !%02d", j);
1830 switch (s->varkind) {
1832 if (s->flags & INMEMORY)
1833 printf((regs_ok) ? " m%02d" : " m??", s->regoff);
1834 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1835 printf((regs_ok) ? " f%02d" : " f??", s->regoff);
1837 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1841 printf(" i%02d", s->varnum);
1844 printf(" l%02d", s->varnum);
1847 printf(" a%02d", s->varnum);
1850 printf(" ?%02d", j);
1858 static void print_reg(stackptr s) {
1860 if (s->flags & SAVEDVAR)
1861 switch (s->varkind) {
1863 if (s->flags & INMEMORY)
1864 printf(" tm%02d", s->regoff);
1866 printf(" tr%02d", s->regoff);
1869 printf(" s %02d", s->varnum);
1872 printf(" l %02d", s->varnum);
1875 printf(" a %02d", s->varnum);
1878 printf(" ! %02d", s->varnum);
1881 switch (s->varkind) {
1883 if (s->flags & INMEMORY)
1884 printf(" Tm%02d", s->regoff);
1886 printf(" Tr%02d", s->regoff);
1889 printf(" S %02d", s->varnum);
1892 printf(" L %02d", s->varnum);
1895 printf(" A %02d", s->varnum);
1898 printf(" ? %02d", s->varnum);
1908 char *icmd_builtin_name(functionptr bptr)
1910 builtin_descriptor *bdesc = builtin_desc;
1911 while ((bdesc->bptr != NULL) && (bdesc->bptr != bptr))
1917 static char *jit_type[] = {
1926 void show_icmd_method()
1937 utf_fprint(stdout, class->name);
1939 utf_fprint(stdout, method->name);
1941 utf_fprint(stdout, method->descriptor);
1942 printf ("\n\nMax locals: %d\n", (int) maxlocals);
1943 printf ("Max stack: %d\n", (int) maxstack);
1945 printf ("Exceptions (Number: %d):\n", exceptiontablelength);
1946 for (ex = extable; ex != NULL; ex = ex->down) {
1947 printf(" L%03d ... ", ex->start->debug_nr );
1948 printf("L%03d = ", ex->end->debug_nr);
1949 printf("L%03d\n", ex->handler->debug_nr);
1952 printf ("Local Table:\n");
1953 for (i = 0; i < maxlocals; i++) {
1954 printf(" %3d: ", i);
1955 for (j = TYPE_INT; j <= TYPE_ADR; j++)
1956 if (locals[i][j].type >= 0) {
1957 printf(" (%s) ", jit_type[j]);
1958 if (locals[i][j].flags & INMEMORY)
1959 printf((regs_ok) ? "m%2d" : "m??", locals[i][j].regoff);
1960 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
1961 printf((regs_ok) ? "f%02d" : "f??", locals[i][j].regoff);
1963 if (regs_ok) printf("%3s",regs[locals[i][j].regoff]); else printf("???");
1970 printf ("Interface Table:\n");
1971 for (i = 0; i < maxstack; i++) {
1972 if ((interfaces[i][0].type >= 0) || (interfaces[i][1].type >= 0) ||
1973 (interfaces[i][2].type >= 0) || (interfaces[i][3].type >= 0) ||
1974 (interfaces[i][4].type >= 0)) {
1975 printf(" %3d: ", i);
1976 for (j = TYPE_INT; j <= TYPE_ADR; j++)
1977 if (interfaces[i][j].type >= 0) {
1978 printf(" (%s) ", jit_type[j]);
1979 if (interfaces[i][j].flags & SAVEDVAR) {
1980 if (interfaces[i][j].flags & INMEMORY)
1981 printf((regs_ok) ? "M%2d" : "M??", interfaces[i][j].regoff);
1982 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
1983 printf((regs_ok) ? "F%02d" : "F??", interfaces[i][j].regoff);
1985 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
1989 if (interfaces[i][j].flags & INMEMORY)
1990 printf((regs_ok) ? "m%2d" : "m??", interfaces[i][j].regoff);
1991 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
1992 printf((regs_ok) ? "f%02d" : "f??", interfaces[i][j].regoff);
1994 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2003 if (showdisassemble) {
2004 #if defined(__I386__) || defined(__X86_64__)
2008 u1ptr = method->mcode + dseglen;
2009 for (i = 0; i < block[0].mpc; i++, u1ptr++) {
2010 a = disassinstr(u1ptr, i);
2016 s4ptr = (s4 *) (method->mcode + dseglen);
2017 for (i = 0; i < block[0].mpc; i += 4, s4ptr++) {
2018 disassinstr(*s4ptr, i);
2025 for (bptr = block; bptr != NULL; bptr = bptr->next) {
2026 show_icmd_block(bptr);
2031 show_icmd_block(basicblock *bptr)
2038 if (bptr->flags != BBDELETED) {
2039 deadcode = bptr->flags <= BBREACHED;
2042 for (j = method->maxstack; j > 0; j--)
2045 icmd_print_stack(bptr->instack);
2046 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2047 iptr = bptr->iinstr;
2049 for (i=0; i < bptr->icount; i++, iptr++) {
2052 for (j = method->maxstack; j > 0; j--)
2056 icmd_print_stack(iptr->dst);
2057 printf("] %4d ", i);
2058 /* XXX remove */ /*fflush(stdout);*/
2059 show_icmd(iptr,deadcode);
2063 if (showdisassemble && (!deadcode)) {
2064 #if defined(__I386__) || defined(__X86_64__)
2070 u1ptr = method->mcode + dseglen + i;
2072 if (bptr->next != NULL) {
2073 for (; i < bptr->next->mpc; i++, u1ptr++) {
2074 a = disassinstr(u1ptr, i);
2081 for (; u1ptr < (u1 *) (method->mcode + method->mcodelength); i++, u1ptr++) {
2082 a = disassinstr(u1ptr, i);
2091 s4ptr = (s4 *) (method->mcode + dseglen + i);
2093 if (bptr->next != NULL) {
2094 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2095 disassinstr(*s4ptr, i);
2100 for (; s4ptr < (s4 *) (method->mcode + method->mcodelength); i += 4, s4ptr++) {
2101 disassinstr(*s4ptr, i);
2111 show_icmd(instruction *iptr,bool deadcode)
2117 printf("%s",icmd_names[iptr->opc]);
2118 switch ((int) iptr->opc) {
2119 case ICMD_IADDCONST:
2120 case ICMD_ISUBCONST:
2121 case ICMD_IMULCONST:
2124 case ICMD_IREM0X10001:
2125 case ICMD_IANDCONST:
2127 case ICMD_IXORCONST:
2128 case ICMD_ISHLCONST:
2129 case ICMD_ISHRCONST:
2130 case ICMD_IUSHRCONST:
2131 case ICMD_LSHLCONST:
2132 case ICMD_LSHRCONST:
2133 case ICMD_LUSHRCONST:
2135 case ICMD_ELSE_ICONST:
2136 case ICMD_IFEQ_ICONST:
2137 case ICMD_IFNE_ICONST:
2138 case ICMD_IFLT_ICONST:
2139 case ICMD_IFGE_ICONST:
2140 case ICMD_IFGT_ICONST:
2141 case ICMD_IFLE_ICONST:
2142 printf(" %d", iptr->val.i);
2144 case ICMD_LADDCONST:
2145 case ICMD_LSUBCONST:
2146 case ICMD_LMULCONST:
2149 case ICMD_LANDCONST:
2151 case ICMD_LXORCONST:
2153 #if defined(__I386__)
2154 printf(" %lld", iptr->val.l);
2156 printf(" %ld", iptr->val.l);
2160 printf(" %f", iptr->val.f);
2163 printf(" %f", iptr->val.d);
2166 printf(" %p", iptr->val.a);
2170 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2171 case ICMD_PUTSTATIC:
2172 case ICMD_GETSTATIC:
2175 ((fieldinfo *) iptr->val.a)->name);
2178 printf(" %d + %d", iptr->op1, iptr->val.i);
2213 printf(" %d", iptr->op1);
2218 ((classinfo *) iptr->val.a)->name);
2221 switch (iptr->op1) {
2248 case ICMD_ANEWARRAY:
2252 ((classinfo *) iptr->val.a)->name);
2255 case ICMD_CHECKCAST:
2256 case ICMD_INSTANCEOF:
2258 classinfo *c = iptr->val.a;
2259 if (c->flags & ACC_INTERFACE)
2260 printf(" (INTERFACE) ");
2262 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2263 utf_fprint(stdout, c->name);
2269 printf(" %s", icmd_builtin_name((functionptr) iptr->val.a));
2271 case ICMD_INVOKEVIRTUAL:
2272 case ICMD_INVOKESPECIAL:
2273 case ICMD_INVOKESTATIC:
2274 case ICMD_INVOKEINTERFACE:
2277 ((methodinfo *) iptr->val.a)->class->name);
2280 ((methodinfo *) iptr->val.a)->name);
2288 if (deadcode || !iptr->target)
2289 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2291 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2299 if (deadcode || !iptr->target)
2300 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2302 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2307 case ICMD_IFNONNULL:
2308 case ICMD_IF_ICMPEQ:
2309 case ICMD_IF_ICMPNE:
2310 case ICMD_IF_ICMPLT:
2311 case ICMD_IF_ICMPGE:
2312 case ICMD_IF_ICMPGT:
2313 case ICMD_IF_ICMPLE:
2314 case ICMD_IF_LCMPEQ:
2315 case ICMD_IF_LCMPNE:
2316 case ICMD_IF_LCMPLT:
2317 case ICMD_IF_LCMPGE:
2318 case ICMD_IF_LCMPGT:
2319 case ICMD_IF_LCMPLE:
2320 case ICMD_IF_ACMPEQ:
2321 case ICMD_IF_ACMPNE:
2322 if (deadcode || !iptr->target)
2323 printf(" op1=%d", iptr->op1);
2325 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2327 case ICMD_TABLESWITCH:
2329 s4ptr = iptr->val.a;
2331 if (deadcode || !iptr->target) {
2332 printf(" %d;", *s4ptr);
2335 tptr = (void **) iptr->target;
2336 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2340 s4ptr++; /* skip default */
2341 j = *s4ptr++; /* low */
2342 j = *s4ptr++ - j; /* high */
2344 if (deadcode || !*tptr)
2345 printf(" %d", *s4ptr++);
2347 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2353 case ICMD_LOOKUPSWITCH:
2354 s4ptr = iptr->val.a;
2356 if (deadcode || !iptr->target) {
2357 printf(" %d;", *s4ptr);
2360 tptr = (void **) iptr->target;
2361 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2364 s4ptr++; /* default */
2365 j = *s4ptr++; /* count */
2368 if (deadcode || !*tptr) {
2369 s4ptr++; /* skip value */
2370 printf(" %d",*s4ptr++);
2373 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2382 * These are local overrides for various environment variables in Emacs.
2383 * Please do not remove this and leave it at the end of the file, where
2384 * Emacs will automagically detect them.
2385 * ---------------------------------------------------------------------
2388 * indent-tabs-mode: t