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 724 2003-12-09 18:56:11Z 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_1 do{ if (!curstack) {UNDERFLOW;} } while(0)
67 #define REQUIRE_2 do{ if (!curstack || !curstack->prev) {UNDERFLOW;} } while(0)
68 #define REQUIRE_3 do{ if (!curstack || !curstack->prev || !curstack->prev->prev) {UNDERFLOW;} } while(0)
69 #define REQUIRE_4 do{ if (!curstack || !curstack->prev || !curstack->prev->prev || !curstack->prev->prev->prev) {UNDERFLOW;} } while(0)
71 #define REQUIRE(num) \
72 do{ int macro_i = (num); stackptr st = curstack; \
73 while(--macro_i>=0) { \
74 if (!st) {UNDERFLOW;} \
78 #define NEWSTACK(s,v,n) {new->prev=curstack;new->type=s;new->flags=0;\
79 new->varkind=v;new->varnum=n;curstack=new;new++;}
80 #define NEWSTACKn(s,n) NEWSTACK(s,UNDEFVAR,n)
81 #define NEWSTACK0(s) NEWSTACK(s,UNDEFVAR,0)
82 #define NEWXSTACK {NEWSTACK(TYPE_ADR,STACKVAR,0);curstack=0;}
84 #define SETDST {iptr->dst=curstack;}
85 #define POP(s) {REQUIRE_1; \
86 if(s!=curstack->type){TYPEPANIC;} \
87 if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR;\
88 curstack=curstack->prev;}
89 #define POPANY {REQUIRE_1; \
90 if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR; \
91 curstack=curstack->prev;}
92 #define COPY(s,d) {(d)->flags=0;(d)->type=(s)->type;\
93 (d)->varkind=(s)->varkind;(d)->varnum=(s)->varnum;}
95 #define PUSHCONST(s){NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
96 #define LOAD(s,v,n) {NEWSTACK(s,v,n);SETDST;stackdepth++;}
97 #define STORE(s) {POP(s);SETDST;stackdepth--;}
98 #define OP1_0(s) {POP(s);SETDST;stackdepth--;}
99 #define OP1_0ANY {POPANY;SETDST;stackdepth--;}
100 #define OP0_1(s) {NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
101 #define OP1_1(s,d) {POP(s);NEWSTACKn(d,stackdepth-1);SETDST;}
102 #define OP2_0(s) {POP(s);POP(s);SETDST;stackdepth-=2;}
103 #define OPTT2_0(t,b){POP(t);POP(b);SETDST;stackdepth-=2;}
104 #define OP2_1(s) {POP(s);POP(s);NEWSTACKn(s,stackdepth-2);SETDST;stackdepth--;}
105 #define OP2IAT_1(s) {POP(TYPE_INT);POP(TYPE_ADR);NEWSTACKn(s,stackdepth-2);\
106 SETDST;stackdepth--;}
107 #define OP2IT_1(s) {POP(TYPE_INT);POP(s);NEWSTACKn(s,stackdepth-2);\
108 SETDST;stackdepth--;}
109 #define OPTT2_1(s,d){POP(s);POP(s);NEWSTACKn(d,stackdepth-2);SETDST;stackdepth--;}
110 #define OP2_2(s) {POP(s);POP(s);NEWSTACKn(s,stackdepth-2);\
111 NEWSTACKn(s,stackdepth-1);SETDST;}
112 #define OP3TIA_0(s) {POP(s);POP(TYPE_INT);POP(TYPE_ADR);SETDST;stackdepth-=3;}
113 #define OP3_0(s) {POP(s);POP(s);POP(s);SETDST;stackdepth-=3;}
114 #define POPMANY(i) {stackdepth-=i;while(--i>=0){POPANY;}SETDST;}
115 #define DUP {REQUIRE_1;NEWSTACK(CURTYPE,CURKIND,curstack->varnum);SETDST; \
117 #define SWAP {REQUIRE_1;COPY(curstack,new);POPANY;COPY(curstack,new+1);POPANY;\
118 new[0].prev=curstack;new[1].prev=new;\
119 curstack=new+1;new+=2;SETDST;}
120 #define DUP_X1 {REQUIRE_2;COPY(curstack,new);COPY(curstack,new+2);POPANY;\
121 COPY(curstack,new+1);POPANY;new[0].prev=curstack;\
122 new[1].prev=new;new[2].prev=new+1;\
123 curstack=new+2;new+=3;SETDST;stackdepth++;}
124 #define DUP2_X1 {REQUIRE_3;COPY(curstack,new+1);COPY(curstack,new+4);POPANY;\
125 COPY(curstack,new);COPY(curstack,new+3);POPANY;\
126 COPY(curstack,new+2);POPANY;new[0].prev=curstack;\
127 new[1].prev=new;new[2].prev=new+1;\
128 new[3].prev=new+2;new[4].prev=new+3;\
129 curstack=new+4;new+=5;SETDST;stackdepth+=2;}
130 #define DUP_X2 {REQUIRE_3;COPY(curstack,new);COPY(curstack,new+3);POPANY;\
131 COPY(curstack,new+2);POPANY;COPY(curstack,new+1);POPANY;\
132 new[0].prev=curstack;new[1].prev=new;\
133 new[2].prev=new+1;new[3].prev=new+2;\
134 curstack=new+3;new+=4;SETDST;stackdepth++;}
135 #define DUP2_X2 {REQUIRE_4;COPY(curstack,new+1);COPY(curstack,new+5);POPANY;\
136 COPY(curstack,new);COPY(curstack,new+4);POPANY;\
137 COPY(curstack,new+3);POPANY;COPY(curstack,new+2);POPANY;\
138 new[0].prev=curstack;new[1].prev=new;\
139 new[2].prev=new+1;new[3].prev=new+2;\
140 new[4].prev=new+3;new[5].prev=new+4;\
141 curstack=new+5;new+=6;SETDST;stackdepth+=2;}
143 #define COPYCURSTACK(copy) {\
156 copy->varkind=STACKVAR;\
172 if((copy->varkind==STACKVAR)&&(copy->varnum>i))\
173 copy->varkind=TEMPVAR;\
175 copy->varkind=STACKVAR;\
178 interfaces[i][copy->type].type = copy->type;\
179 interfaces[i][copy->type].flags |= copy->flags;\
180 i--;copy=copy->prev;\
185 interfaces[i][copy->type].type = copy->type;\
186 if(copy->varkind==STACKVAR){\
187 if (copy->flags & SAVEDVAR)\
188 interfaces[i][copy->type].flags |= SAVEDVAR;\
190 i--;copy=copy->prev;\
195 #define MARKREACHED(b,c) {\
197 {COPYCURSTACK(c);b->flags=0;b->instack=c;b->indepth=stackdepth;}\
198 else {stackptr s=curstack;stackptr t=b->instack;\
199 if(b->indepth!=stackdepth)\
200 {show_icmd_method();panic("Stack depth mismatch");}\
201 while(s){if (s->type!=t->type)\
203 s=s->prev;t=t->prev;\
217 int opcode, i, len, loops;
218 int superblockend, repeat, deadcode;
225 if (compileverbose) {
226 char logtext[MAXLOGTEXT];
227 sprintf(logtext, "Analysing: ");
228 utf_sprint(logtext+strlen(logtext), method->class->name);
229 strcpy(logtext+strlen(logtext), ".");
230 utf_sprint(logtext+strlen(logtext), method->name);
231 utf_sprint(logtext+strlen(logtext), method->descriptor);
235 int *argren = DMNEW(int, maxlocals);
236 //int *argren = (int *)alloca(maxlocals * sizeof(int)); /* table for argument renaming */
237 for (i = 0; i < maxlocals; i++)
243 block[0].flags = BBREACHED;
244 block[0].instack = 0;
245 block[0].indepth = 0;
247 for (i = 0; i < exceptiontablelength; i++) {
248 bptr = &block[block_index[extable[i].handlerpc]];
249 bptr->flags = BBREACHED;
250 bptr->type = BBTYPE_EXH;
253 bptr->pre_count = 10000;
258 #ifdef CONDITIONAL_LOADCONST
259 b_count = block_count;
261 while (--b_count >= 0) {
262 if (bptr->icount != 0) {
263 iptr = bptr->iinstr + bptr->icount - 1;
296 block[block_index[iptr->op1]].pre_count++;
299 case ICMD_TABLESWITCH:
301 block[block_index[*s4ptr++]].pre_count++; /* default */
302 i = *s4ptr++; /* low */
303 i = *s4ptr++ - i + 1; /* high */
305 block[block_index[*s4ptr++]].pre_count++;
309 case ICMD_LOOKUPSWITCH:
311 block[block_index[*s4ptr++]].pre_count++; /* default */
312 i = *s4ptr++; /* count */
314 block[block_index[s4ptr[1]]].pre_count++;
330 b_count = block_count;
332 superblockend = true;
336 while (--b_count >= 0) {
337 if (bptr->flags == BBDELETED) {
340 else if (superblockend && (bptr->flags < BBREACHED))
342 else if (bptr->flags <= BBREACHED) {
344 stackdepth = bptr->indepth;
345 else if (bptr->flags < BBREACHED) {
347 bptr->instack = copy;
348 bptr->indepth = stackdepth;
350 else if (bptr->indepth != stackdepth) {
352 panic("Stack depth mismatch");
355 curstack = bptr->instack;
357 superblockend = false;
358 bptr->flags = BBFINISHED;
361 b_index = bptr - block;
366 /* DEBUG XXX */ /* dolog("p:%04d op: %s",iptr-instr,icmd_names[opcode]); */
368 #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) {
393 case ICMD_CHECKASIZE:
395 case ICMD_IFEQ_ICONST:
396 case ICMD_IFNE_ICONST:
397 case ICMD_IFLT_ICONST:
398 case ICMD_IFGE_ICONST:
399 case ICMD_IFGT_ICONST:
400 case ICMD_IFLE_ICONST:
401 case ICMD_ELSE_ICONST:
406 locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
408 COUNT(count_pcmd_return);
410 superblockend = true;
413 /* pop 0 push 1 const */
416 COUNT(count_pcmd_load);
418 switch (iptr[1].opc) {
420 iptr[0].opc = ICMD_IADDCONST;
422 iptr[1].opc = ICMD_NOP;
423 OP1_1(TYPE_INT,TYPE_INT);
424 COUNT(count_pcmd_op);
427 iptr[0].opc = ICMD_ISUBCONST;
428 goto icmd_iconst_tail;
430 iptr[0].opc = ICMD_IMULCONST;
431 goto icmd_iconst_tail;
433 if (iptr[0].val.i == 0x00000002)
435 else if (iptr[0].val.i == 0x00000004)
437 else if (iptr[0].val.i == 0x00000008)
439 else if (iptr[0].val.i == 0x00000010)
441 else if (iptr[0].val.i == 0x00000020)
443 else if (iptr[0].val.i == 0x00000040)
445 else if (iptr[0].val.i == 0x00000080)
447 else if (iptr[0].val.i == 0x00000100)
449 else if (iptr[0].val.i == 0x00000200)
451 else if (iptr[0].val.i == 0x00000400)
453 else if (iptr[0].val.i == 0x00000800)
455 else if (iptr[0].val.i == 0x00001000)
457 else if (iptr[0].val.i == 0x00002000)
459 else if (iptr[0].val.i == 0x00004000)
461 else if (iptr[0].val.i == 0x00008000)
463 else if (iptr[0].val.i == 0x00010000)
465 else if (iptr[0].val.i == 0x00020000)
467 else if (iptr[0].val.i == 0x00040000)
469 else if (iptr[0].val.i == 0x00080000)
471 else if (iptr[0].val.i == 0x00100000)
473 else if (iptr[0].val.i == 0x00200000)
475 else if (iptr[0].val.i == 0x00400000)
477 else if (iptr[0].val.i == 0x00800000)
479 else if (iptr[0].val.i == 0x01000000)
481 else if (iptr[0].val.i == 0x02000000)
483 else if (iptr[0].val.i == 0x04000000)
485 else if (iptr[0].val.i == 0x08000000)
487 else if (iptr[0].val.i == 0x10000000)
489 else if (iptr[0].val.i == 0x20000000)
491 else if (iptr[0].val.i == 0x40000000)
493 else if (iptr[0].val.i == 0x80000000)
499 iptr[0].opc = ICMD_IDIVPOW2;
500 goto icmd_iconst_tail;
502 #if !defined(NO_DIV_OPT)
503 if (iptr[0].val.i == 0x10001) {
504 iptr[0].opc = ICMD_IREM0X10001;
505 goto icmd_iconst_tail;
508 if ((iptr[0].val.i == 0x00000002) ||
509 (iptr[0].val.i == 0x00000004) ||
510 (iptr[0].val.i == 0x00000008) ||
511 (iptr[0].val.i == 0x00000010) ||
512 (iptr[0].val.i == 0x00000020) ||
513 (iptr[0].val.i == 0x00000040) ||
514 (iptr[0].val.i == 0x00000080) ||
515 (iptr[0].val.i == 0x00000100) ||
516 (iptr[0].val.i == 0x00000200) ||
517 (iptr[0].val.i == 0x00000400) ||
518 (iptr[0].val.i == 0x00000800) ||
519 (iptr[0].val.i == 0x00001000) ||
520 (iptr[0].val.i == 0x00002000) ||
521 (iptr[0].val.i == 0x00004000) ||
522 (iptr[0].val.i == 0x00008000) ||
523 (iptr[0].val.i == 0x00010000) ||
524 (iptr[0].val.i == 0x00020000) ||
525 (iptr[0].val.i == 0x00040000) ||
526 (iptr[0].val.i == 0x00080000) ||
527 (iptr[0].val.i == 0x00100000) ||
528 (iptr[0].val.i == 0x00200000) ||
529 (iptr[0].val.i == 0x00400000) ||
530 (iptr[0].val.i == 0x00800000) ||
531 (iptr[0].val.i == 0x01000000) ||
532 (iptr[0].val.i == 0x02000000) ||
533 (iptr[0].val.i == 0x04000000) ||
534 (iptr[0].val.i == 0x08000000) ||
535 (iptr[0].val.i == 0x10000000) ||
536 (iptr[0].val.i == 0x20000000) ||
537 (iptr[0].val.i == 0x40000000) ||
538 (iptr[0].val.i == 0x80000000)) {
539 iptr[0].opc = ICMD_IREMPOW2;
541 goto icmd_iconst_tail;
546 iptr[0].opc = ICMD_IANDCONST;
547 goto icmd_iconst_tail;
549 iptr[0].opc = ICMD_IORCONST;
550 goto icmd_iconst_tail;
552 iptr[0].opc = ICMD_IXORCONST;
553 goto icmd_iconst_tail;
555 iptr[0].opc = ICMD_ISHLCONST;
556 goto icmd_iconst_tail;
558 iptr[0].opc = ICMD_ISHRCONST;
559 goto icmd_iconst_tail;
561 iptr[0].opc = ICMD_IUSHRCONST;
562 goto icmd_iconst_tail;
563 #if SUPPORT_LONG_SHIFT
565 iptr[0].opc = ICMD_LSHLCONST;
566 goto icmd_lconst_tail;
568 iptr[0].opc = ICMD_LSHRCONST;
569 goto icmd_lconst_tail;
571 iptr[0].opc = ICMD_LUSHRCONST;
572 goto icmd_lconst_tail;
575 iptr[0].opc = ICMD_IFEQ;
577 iptr[0].op1 = iptr[1].op1;
580 /* iptr[1].opc = ICMD_NOP; */
582 tbptr = block + block_index[iptr->op1];
584 iptr[0].target = (void *) tbptr;
586 MARKREACHED(tbptr, copy);
587 COUNT(count_pcmd_bra);
590 iptr[0].opc = ICMD_IFLT;
591 goto icmd_if_icmp_tail;
593 iptr[0].opc = ICMD_IFLE;
594 goto icmd_if_icmp_tail;
596 iptr[0].opc = ICMD_IFNE;
597 goto icmd_if_icmp_tail;
599 iptr[0].opc = ICMD_IFGT;
600 goto icmd_if_icmp_tail;
602 iptr[0].opc = ICMD_IFGE;
603 goto icmd_if_icmp_tail;
612 COUNT(count_pcmd_load);
614 switch (iptr[1].opc) {
617 iptr[0].opc = ICMD_LADDCONST;
619 iptr[1].opc = ICMD_NOP;
620 OP1_1(TYPE_LNG,TYPE_LNG);
621 COUNT(count_pcmd_op);
624 iptr[0].opc = ICMD_LSUBCONST;
625 goto icmd_lconst_tail;
629 iptr[0].opc = ICMD_LMULCONST;
630 goto icmd_lconst_tail;
634 if (iptr[0].val.l == 0x00000002)
636 else if (iptr[0].val.l == 0x00000004)
638 else if (iptr[0].val.l == 0x00000008)
640 else if (iptr[0].val.l == 0x00000010)
642 else if (iptr[0].val.l == 0x00000020)
644 else if (iptr[0].val.l == 0x00000040)
646 else if (iptr[0].val.l == 0x00000080)
648 else if (iptr[0].val.l == 0x00000100)
650 else if (iptr[0].val.l == 0x00000200)
652 else if (iptr[0].val.l == 0x00000400)
654 else if (iptr[0].val.l == 0x00000800)
656 else if (iptr[0].val.l == 0x00001000)
658 else if (iptr[0].val.l == 0x00002000)
660 else if (iptr[0].val.l == 0x00004000)
662 else if (iptr[0].val.l == 0x00008000)
664 else if (iptr[0].val.l == 0x00010000)
666 else if (iptr[0].val.l == 0x00020000)
668 else if (iptr[0].val.l == 0x00040000)
670 else if (iptr[0].val.l == 0x00080000)
672 else if (iptr[0].val.l == 0x00100000)
674 else if (iptr[0].val.l == 0x00200000)
676 else if (iptr[0].val.l == 0x00400000)
678 else if (iptr[0].val.l == 0x00800000)
680 else if (iptr[0].val.l == 0x01000000)
682 else if (iptr[0].val.l == 0x02000000)
684 else if (iptr[0].val.l == 0x04000000)
686 else if (iptr[0].val.l == 0x08000000)
688 else if (iptr[0].val.l == 0x10000000)
690 else if (iptr[0].val.l == 0x20000000)
692 else if (iptr[0].val.l == 0x40000000)
694 else if (iptr[0].val.l == 0x80000000)
700 iptr[0].opc = ICMD_LDIVPOW2;
701 goto icmd_lconst_tail;
703 #if !defined(NO_DIV_OPT)
704 if (iptr[0].val.l == 0x10001) {
705 iptr[0].opc = ICMD_LREM0X10001;
706 goto icmd_lconst_tail;
709 if ((iptr[0].val.l == 0x00000002) ||
710 (iptr[0].val.l == 0x00000004) ||
711 (iptr[0].val.l == 0x00000008) ||
712 (iptr[0].val.l == 0x00000010) ||
713 (iptr[0].val.l == 0x00000020) ||
714 (iptr[0].val.l == 0x00000040) ||
715 (iptr[0].val.l == 0x00000080) ||
716 (iptr[0].val.l == 0x00000100) ||
717 (iptr[0].val.l == 0x00000200) ||
718 (iptr[0].val.l == 0x00000400) ||
719 (iptr[0].val.l == 0x00000800) ||
720 (iptr[0].val.l == 0x00001000) ||
721 (iptr[0].val.l == 0x00002000) ||
722 (iptr[0].val.l == 0x00004000) ||
723 (iptr[0].val.l == 0x00008000) ||
724 (iptr[0].val.l == 0x00010000) ||
725 (iptr[0].val.l == 0x00020000) ||
726 (iptr[0].val.l == 0x00040000) ||
727 (iptr[0].val.l == 0x00080000) ||
728 (iptr[0].val.l == 0x00100000) ||
729 (iptr[0].val.l == 0x00200000) ||
730 (iptr[0].val.l == 0x00400000) ||
731 (iptr[0].val.l == 0x00800000) ||
732 (iptr[0].val.l == 0x01000000) ||
733 (iptr[0].val.l == 0x02000000) ||
734 (iptr[0].val.l == 0x04000000) ||
735 (iptr[0].val.l == 0x08000000) ||
736 (iptr[0].val.l == 0x10000000) ||
737 (iptr[0].val.l == 0x20000000) ||
738 (iptr[0].val.l == 0x40000000) ||
739 (iptr[0].val.l == 0x80000000)) {
740 iptr[0].opc = ICMD_LREMPOW2;
742 goto icmd_lconst_tail;
749 iptr[0].opc = ICMD_LANDCONST;
750 goto icmd_lconst_tail;
752 iptr[0].opc = ICMD_LORCONST;
753 goto icmd_lconst_tail;
755 iptr[0].opc = ICMD_LXORCONST;
756 goto icmd_lconst_tail;
758 #if !defined(NOLONG_CONDITIONAL)
760 if ((len > 1) && (iptr[2].val.i == 0)) {
761 switch (iptr[2].opc) {
763 iptr[0].opc = ICMD_IF_LEQ;
764 icmd_lconst_lcmp_tail:
765 iptr[0].op1 = iptr[2].op1;
768 /* iptr[1].opc = ICMD_NOP;
769 iptr[2].opc = ICMD_NOP; */
771 tbptr = block + block_index[iptr->op1];
773 iptr[0].target = (void *) tbptr;
775 MARKREACHED(tbptr, copy);
776 COUNT(count_pcmd_bra);
777 COUNT(count_pcmd_op);
780 iptr[0].opc = ICMD_IF_LNE;
781 goto icmd_lconst_lcmp_tail;
783 iptr[0].opc = ICMD_IF_LLT;
784 goto icmd_lconst_lcmp_tail;
786 iptr[0].opc = ICMD_IF_LGT;
787 goto icmd_lconst_lcmp_tail;
789 iptr[0].opc = ICMD_IF_LLE;
790 goto icmd_lconst_lcmp_tail;
792 iptr[0].opc = ICMD_IF_LGE;
793 goto icmd_lconst_lcmp_tail;
796 } /* switch (iptr[2].opc) */
797 } /* if (iptr[2].val.i == 0) */
810 COUNT(count_pcmd_load);
814 COUNT(count_pcmd_load);
818 COUNT(count_pcmd_load);
822 /* pop 0 push 1 load */
829 COUNT(count_load_instruction);
830 i = opcode-ICMD_ILOAD;
831 iptr->op1 = argren[iptr->op1];
832 locals[iptr->op1][i].type = i;
833 LOAD(i, LOCALVAR, iptr->op1);
843 COUNT(count_check_null);
844 COUNT(count_check_bound);
845 COUNT(count_pcmd_mem);
846 OP2IAT_1(opcode-ICMD_IALOAD);
852 COUNT(count_check_null);
853 COUNT(count_check_bound);
854 COUNT(count_pcmd_mem);
858 /* pop 0 push 0 iinc */
864 count_store_depth[10]++;
866 count_store_depth[i]++;
871 if ((copy->varkind == LOCALVAR) &&
872 (copy->varnum == iptr->op1)) {
873 copy->varkind = TEMPVAR;
882 /* pop 1 push 0 store */
892 i = opcode - ICMD_ISTORE;
893 locals[iptr->op1][i].type = i;
898 count_store_length[20]++;
900 count_store_length[i]++;
903 count_store_depth[10]++;
905 count_store_depth[i]++;
907 copy = curstack->prev;
910 if ((copy->varkind == LOCALVAR) &&
911 (copy->varnum == iptr->op1)) {
912 copy->varkind = TEMPVAR;
918 if ((new - curstack) == 1) {
919 curstack->varkind = LOCALVAR;
920 curstack->varnum = iptr->op1;
922 STORE(opcode-ICMD_ISTORE);
932 COUNT(count_check_null);
933 COUNT(count_check_bound);
934 COUNT(count_pcmd_mem);
935 OP3TIA_0(opcode-ICMD_IASTORE);
940 COUNT(count_check_null);
941 COUNT(count_check_bound);
942 COUNT(count_pcmd_mem);
957 COUNT(count_pcmd_return);
958 OP1_0(opcode-ICMD_IRETURN);
959 superblockend = true;
963 COUNT(count_check_null);
967 superblockend = true;
971 COUNT(count_pcmd_mem);
975 /* pop 1 push 0 branch */
979 COUNT(count_pcmd_bra);
981 tbptr = block + block_index[iptr->op1];
983 iptr[0].target = (void *) tbptr;
985 MARKREACHED(tbptr, copy);
994 COUNT(count_pcmd_bra);
995 #ifdef CONDITIONAL_LOADCONST
997 tbptr = block + b_index;
998 if ((b_count >= 3) &&
999 ((b_index + 2) == block_index[iptr[0].op1]) &&
1000 (tbptr[1].pre_count == 1) &&
1001 (iptr[1].opc == ICMD_ICONST) &&
1002 (iptr[2].opc == ICMD_GOTO) &&
1003 ((b_index + 3) == block_index[iptr[2].op1]) &&
1004 (tbptr[2].pre_count == 1) &&
1005 (iptr[3].opc == ICMD_ICONST)) {
1006 OP1_1(TYPE_INT, TYPE_INT);
1007 switch (iptr[0].opc) {
1009 iptr[0].opc = ICMD_IFNE_ICONST;
1012 iptr[0].opc = ICMD_IFEQ_ICONST;
1015 iptr[0].opc = ICMD_IFGE_ICONST;
1018 iptr[0].opc = ICMD_IFLT_ICONST;
1021 iptr[0].opc = ICMD_IFLE_ICONST;
1024 iptr[0].opc = ICMD_IFGT_ICONST;
1027 iptr[0].val.i = iptr[1].val.i;
1028 iptr[1].opc = ICMD_ELSE_ICONST;
1029 iptr[1].val.i = iptr[3].val.i;
1030 iptr[2].opc = ICMD_NOP;
1031 iptr[3].opc = ICMD_NOP;
1032 tbptr[1].flags = BBDELETED;
1033 tbptr[2].flags = BBDELETED;
1034 tbptr[1].icount = 0;
1035 tbptr[2].icount = 0;
1036 if (tbptr[3].pre_count == 2) {
1037 len += tbptr[3].icount + 3;
1038 bptr->icount += tbptr[3].icount + 3;
1039 tbptr[3].flags = BBDELETED;
1040 tbptr[3].icount = 0;
1053 tbptr = block + block_index[iptr->op1];
1055 iptr[0].target = (void *) tbptr;
1057 MARKREACHED(tbptr, copy);
1060 /* pop 0 push 0 branch */
1063 COUNT(count_pcmd_bra);
1064 tbptr = block + block_index[iptr->op1];
1066 iptr[0].target = (void *) tbptr;
1068 MARKREACHED(tbptr, copy);
1070 superblockend = true;
1073 /* pop 1 push 0 table branch */
1075 case ICMD_TABLESWITCH:
1076 COUNT(count_pcmd_table);
1078 s4ptr = iptr->val.a;
1079 tbptr = block + block_index[*s4ptr++]; /* default */
1080 MARKREACHED(tbptr, copy);
1081 i = *s4ptr++; /* low */
1082 i = *s4ptr++ - i + 1; /* high */
1084 tptr = DMNEW(void*, i+1);
1085 iptr->target = (void *) tptr;
1087 tptr[0] = (void *) tbptr;
1091 tbptr = block + block_index[*s4ptr++];
1093 tptr[0] = (void *) tbptr;
1096 MARKREACHED(tbptr, copy);
1099 superblockend = true;
1102 /* pop 1 push 0 table branch */
1104 case ICMD_LOOKUPSWITCH:
1105 COUNT(count_pcmd_table);
1107 s4ptr = iptr->val.a;
1108 tbptr = block + block_index[*s4ptr++]; /* default */
1109 MARKREACHED(tbptr, copy);
1110 i = *s4ptr++; /* count */
1112 tptr = DMNEW(void*, i+1);
1113 iptr->target = (void *) tptr;
1115 tptr[0] = (void *) tbptr;
1119 tbptr = block + block_index[s4ptr[1]];
1121 tptr[0] = (void *) tbptr;
1124 MARKREACHED(tbptr, copy);
1128 superblockend = true;
1131 case ICMD_NULLCHECKPOP:
1132 case ICMD_MONITORENTER:
1133 COUNT(count_check_null);
1134 case ICMD_MONITOREXIT:
1138 /* pop 2 push 0 branch */
1140 case ICMD_IF_ICMPEQ:
1141 case ICMD_IF_ICMPNE:
1142 case ICMD_IF_ICMPLT:
1143 case ICMD_IF_ICMPGE:
1144 case ICMD_IF_ICMPGT:
1145 case ICMD_IF_ICMPLE:
1146 COUNT(count_pcmd_bra);
1148 tbptr = block + block_index[iptr->op1];
1150 iptr[0].target = (void *) tbptr;
1152 MARKREACHED(tbptr, copy);
1155 case ICMD_IF_ACMPEQ:
1156 case ICMD_IF_ACMPNE:
1157 COUNT(count_pcmd_bra);
1159 tbptr = block + block_index[iptr->op1];
1161 iptr[0].target = (void *) tbptr;
1163 MARKREACHED(tbptr, copy);
1169 COUNT(count_check_null);
1170 COUNT(count_pcmd_mem);
1171 OPTT2_0(iptr->op1,TYPE_ADR);
1176 if (! IS_2_WORD_TYPE(curstack->type)) {
1177 OP1_0ANY; /* second pop */
1180 iptr->opc = ICMD_POP;
1184 /* pop 0 push 1 dup */
1187 COUNT(count_dup_instruction);
1193 if (IS_2_WORD_TYPE(curstack->type)) {
1194 iptr->opc = ICMD_DUP;
1200 NEWSTACK(copy->prev->type, copy->prev->varkind,
1201 copy->prev->varnum);
1202 NEWSTACK(copy->type, copy->varkind,
1209 /* pop 2 push 3 dup */
1217 if (IS_2_WORD_TYPE(curstack->type)) {
1218 iptr->opc = ICMD_DUP_X1;
1226 /* pop 3 push 4 dup */
1230 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1231 iptr->opc = ICMD_DUP_X1;
1241 if (IS_2_WORD_TYPE(curstack->type)) {
1243 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1244 iptr->opc = ICMD_DUP_X1;
1248 iptr->opc = ICMD_DUP_X2;
1254 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1255 iptr->opc = ICMD_DUP2_X1;
1263 /* pop 2 push 2 swap */
1272 #if !SUPPORT_DIVISION
1273 iptr[0].opc = ICMD_BUILTIN2;
1274 iptr[0].op1 = TYPE_INT;
1275 iptr[0].val.a = (functionptr) asm_builtin_idiv;
1276 isleafmethod = false;
1281 #if !SUPPORT_DIVISION
1282 iptr[0].opc = ICMD_BUILTIN2;
1283 iptr[0].op1 = TYPE_INT;
1284 iptr[0].val.a = (functionptr) asm_builtin_irem;
1285 isleafmethod = false;
1299 COUNT(count_pcmd_op);
1304 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1305 iptr[0].opc = ICMD_BUILTIN2;
1306 iptr[0].op1 = TYPE_LNG;
1307 iptr[0].val.a = (functionptr) asm_builtin_ldiv;
1308 isleafmethod = false;
1313 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1314 iptr[0].opc = ICMD_BUILTIN2;
1315 iptr[0].op1 = TYPE_LNG;
1316 iptr[0].val.a = (functionptr) asm_builtin_lrem;
1317 isleafmethod = false;
1328 /* XXX DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1329 COUNT(count_pcmd_op);
1336 COUNT(count_pcmd_op);
1345 COUNT(count_pcmd_op);
1354 COUNT(count_pcmd_op);
1359 COUNT(count_pcmd_op);
1360 #if !defined(NOLONG_CONDITIONAL)
1361 if ((len > 0) && (iptr[1].val.i == 0)) {
1362 switch (iptr[1].opc) {
1364 iptr[0].opc = ICMD_IF_LCMPEQ;
1366 iptr[0].op1 = iptr[1].op1;
1369 /* iptr[1].opc = ICMD_NOP; */
1371 tbptr = block + block_index[iptr->op1];
1373 iptr[0].target = (void *) tbptr;
1375 MARKREACHED(tbptr, copy);
1376 COUNT(count_pcmd_bra);
1379 iptr[0].opc = ICMD_IF_LCMPNE;
1380 goto icmd_lcmp_if_tail;
1382 iptr[0].opc = ICMD_IF_LCMPLT;
1383 goto icmd_lcmp_if_tail;
1385 iptr[0].opc = ICMD_IF_LCMPGT;
1386 goto icmd_lcmp_if_tail;
1388 iptr[0].opc = ICMD_IF_LCMPLE;
1389 goto icmd_lcmp_if_tail;
1391 iptr[0].opc = ICMD_IF_LCMPGE;
1392 goto icmd_lcmp_if_tail;
1394 OPTT2_1(TYPE_LNG, TYPE_INT);
1399 OPTT2_1(TYPE_LNG, TYPE_INT);
1403 COUNT(count_pcmd_op);
1404 OPTT2_1(TYPE_FLT, TYPE_INT);
1408 COUNT(count_pcmd_op);
1409 OPTT2_1(TYPE_DBL, TYPE_INT);
1417 case ICMD_INT2SHORT:
1418 COUNT(count_pcmd_op);
1419 OP1_1(TYPE_INT, TYPE_INT);
1422 COUNT(count_pcmd_op);
1423 OP1_1(TYPE_LNG, TYPE_LNG);
1426 COUNT(count_pcmd_op);
1427 OP1_1(TYPE_FLT, TYPE_FLT);
1430 COUNT(count_pcmd_op);
1431 OP1_1(TYPE_DBL, TYPE_DBL);
1435 COUNT(count_pcmd_op);
1436 OP1_1(TYPE_INT, TYPE_LNG);
1439 COUNT(count_pcmd_op);
1440 OP1_1(TYPE_INT, TYPE_FLT);
1443 COUNT(count_pcmd_op);
1444 OP1_1(TYPE_INT, TYPE_DBL);
1447 COUNT(count_pcmd_op);
1448 OP1_1(TYPE_LNG, TYPE_INT);
1451 COUNT(count_pcmd_op);
1452 OP1_1(TYPE_LNG, TYPE_FLT);
1455 COUNT(count_pcmd_op);
1456 OP1_1(TYPE_LNG, TYPE_DBL);
1459 COUNT(count_pcmd_op);
1460 OP1_1(TYPE_FLT, TYPE_INT);
1463 COUNT(count_pcmd_op);
1464 OP1_1(TYPE_FLT, TYPE_LNG);
1467 COUNT(count_pcmd_op);
1468 OP1_1(TYPE_FLT, TYPE_DBL);
1471 COUNT(count_pcmd_op);
1472 OP1_1(TYPE_DBL, TYPE_INT);
1475 COUNT(count_pcmd_op);
1476 OP1_1(TYPE_DBL, TYPE_LNG);
1479 COUNT(count_pcmd_op);
1480 OP1_1(TYPE_DBL, TYPE_FLT);
1483 case ICMD_CHECKCAST:
1484 OP1_1(TYPE_ADR, TYPE_ADR);
1487 case ICMD_ARRAYLENGTH:
1488 case ICMD_INSTANCEOF:
1489 OP1_1(TYPE_ADR, TYPE_INT);
1493 case ICMD_ANEWARRAY:
1494 OP1_1(TYPE_INT, TYPE_ADR);
1498 COUNT(count_check_null);
1499 COUNT(count_pcmd_mem);
1500 OP1_1(TYPE_ADR, iptr->op1);
1505 case ICMD_GETSTATIC:
1506 COUNT(count_pcmd_mem);
1516 tbptr = block + block_index[iptr->op1];
1518 iptr[0].target = (void *) tbptr;
1520 /* XXX This is a dirty hack. The typechecker
1521 * needs it because the OP1_0ANY below
1522 * overwrites iptr->dst.
1524 iptr->val.a = (void*) iptr->dst;
1526 tbptr->type=BBTYPE_SBR;
1527 MARKREACHED(tbptr, copy);
1531 /* pop many push any */
1533 case ICMD_INVOKEVIRTUAL:
1534 case ICMD_INVOKESPECIAL:
1535 case ICMD_INVOKEINTERFACE:
1536 case ICMD_INVOKESTATIC:
1537 COUNT(count_pcmd_met);
1539 methodinfo *m = iptr->val.a;
1540 if (m->flags & ACC_STATIC)
1541 {COUNT(count_check_null);}
1543 if (i > arguments_num)
1546 #if defined(__X86_64__)
1554 (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1558 stackargs += (iarg < intreg_argnum) ? 0 : (iarg - intreg_argnum);
1559 stackargs += (farg < fltreg_argnum) ? 0 : (farg - fltreg_argnum);
1564 if (!(copy->flags & SAVEDVAR)) {
1565 copy->varkind = ARGVAR;
1566 if (IS_FLT_DBL_TYPE(copy->type)) {
1567 if (--farg < fltreg_argnum) {
1568 copy->varnum = farg;
1570 copy->varnum = --stackargs + intreg_argnum;
1573 if (--iarg < intreg_argnum) {
1574 copy->varnum = iarg;
1576 copy->varnum = --stackargs + intreg_argnum;
1580 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1588 if (! (copy->flags & SAVEDVAR)) {
1589 copy->varkind = ARGVAR;
1596 copy->flags |= SAVEDVAR;
1601 if (m->returntype != TYPE_VOID) {
1602 OP0_1(m->returntype);
1608 /* XXX DEBUG */ /*dolog("builtin3");*/
1610 if (! (curstack->flags & SAVEDVAR)) {
1611 curstack->varkind = ARGVAR;
1612 curstack->varnum = 2;
1614 if (3 > arguments_num) {
1622 /* XXX DEBUG */ /*dolog("builtin2");*/
1623 if (!(curstack->flags & SAVEDVAR)) {
1624 curstack->varkind = ARGVAR;
1625 curstack->varnum = 1;
1627 if (2 > arguments_num) {
1635 /* XXX DEBUG */ /*dolog("builtin1");*/
1636 if (!(curstack->flags & SAVEDVAR)) {
1637 curstack->varkind = ARGVAR;
1638 curstack->varnum = 0;
1640 if (1 > arguments_num) {
1646 copy->flags |= SAVEDVAR;
1649 if (iptr->op1 != TYPE_VOID)
1653 case ICMD_MULTIANEWARRAY:
1656 if ((i + intreg_argnum) > arguments_num)
1657 arguments_num = i + intreg_argnum;
1660 if (! (copy->flags & SAVEDVAR)) {
1661 copy->varkind = ARGVAR;
1662 copy->varnum = i + intreg_argnum;
1667 copy->flags |= SAVEDVAR;
1675 case ICMD_CLEAR_ARGREN:
1676 for (i = iptr->op1; i<maxlocals; i++)
1678 iptr->opc = opcode = ICMD_NOP;
1682 case ICMD_READONLY_ARG:
1683 case ICMD_READONLY_ARG+1:
1684 case ICMD_READONLY_ARG+2:
1685 case ICMD_READONLY_ARG+3:
1686 case ICMD_READONLY_ARG+4:
1689 if (curstack->varkind == LOCALVAR) {
1690 i = curstack->varnum;
1691 argren[iptr->op1] = i;
1694 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
1700 printf("ICMD %d at %d\n", iptr->opc, (int)(iptr-instr));
1701 panic("Missing ICMD code during stack analysis");
1703 /* XXX DEBUG */ /*dolog("iptr++");*/
1705 } /* while instructions */
1706 bptr->outstack = curstack;
1707 bptr->outdepth = stackdepth;
1711 superblockend = true;
1713 } /* while blocks */
1714 } while (repeat && !deadcode);
1717 if (block_count > count_max_basic_blocks)
1718 count_max_basic_blocks = block_count;
1719 count_basic_blocks += block_count;
1720 if (instr_count > count_max_javainstr)
1721 count_max_javainstr = instr_count;
1722 count_javainstr += instr_count;
1723 if (stack_count > count_upper_bound_new_stack)
1724 count_upper_bound_new_stack = stack_count;
1725 if ((new - stack) > count_max_new_stack)
1726 count_max_new_stack = (new - stack);
1728 b_count = block_count;
1730 while (--b_count >= 0) {
1731 if (bptr->flags > BBREACHED) {
1732 if (bptr->indepth >= 10)
1733 count_block_stack[10]++;
1735 count_block_stack[bptr->indepth]++;
1738 count_block_size_distribution[len]++;
1740 count_block_size_distribution[10]++;
1742 count_block_size_distribution[11]++;
1744 count_block_size_distribution[12]++;
1746 count_block_size_distribution[13]++;
1748 count_block_size_distribution[14]++;
1750 count_block_size_distribution[15]++;
1752 count_block_size_distribution[16]++;
1754 count_block_size_distribution[17]++;
1760 count_analyse_iterations[0]++;
1761 else if (loops == 2)
1762 count_analyse_iterations[1]++;
1763 else if (loops == 3)
1764 count_analyse_iterations[2]++;
1765 else if (loops == 4)
1766 count_analyse_iterations[3]++;
1768 count_analyse_iterations[4]++;
1770 if (block_count <= 5)
1771 count_method_bb_distribution[0]++;
1772 else if (block_count <= 10)
1773 count_method_bb_distribution[1]++;
1774 else if (block_count <= 15)
1775 count_method_bb_distribution[2]++;
1776 else if (block_count <= 20)
1777 count_method_bb_distribution[3]++;
1778 else if (block_count <= 30)
1779 count_method_bb_distribution[4]++;
1780 else if (block_count <= 40)
1781 count_method_bb_distribution[5]++;
1782 else if (block_count <= 50)
1783 count_method_bb_distribution[6]++;
1784 else if (block_count <= 75)
1785 count_method_bb_distribution[7]++;
1787 count_method_bb_distribution[8]++;
1792 void icmd_print_stack(stackptr s)
1809 /* XXX remove */ /* printf("(%d)",s->flags); fflush(stdout); */
1810 if (s->flags & SAVEDVAR)
1811 switch (s->varkind) {
1813 if (s->flags & INMEMORY)
1814 printf((regs_ok) ? " M%02d" : " M??", s->regoff);
1815 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1816 printf((regs_ok) ? " F%02d" : " F??", s->regoff);
1818 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1822 printf(" I%02d", s->varnum);
1825 printf(" L%02d", s->varnum);
1828 printf(" A%02d", s->varnum);
1831 printf(" !%02d", j);
1834 switch (s->varkind) {
1836 if (s->flags & INMEMORY)
1837 printf((regs_ok) ? " m%02d" : " m??", s->regoff);
1838 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1839 printf((regs_ok) ? " f%02d" : " f??", s->regoff);
1841 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1845 printf(" i%02d", s->varnum);
1848 printf(" l%02d", s->varnum);
1851 printf(" a%02d", s->varnum);
1854 printf(" ?%02d", j);
1862 static void print_reg(stackptr s) {
1864 if (s->flags & SAVEDVAR)
1865 switch (s->varkind) {
1867 if (s->flags & INMEMORY)
1868 printf(" tm%02d", s->regoff);
1870 printf(" tr%02d", s->regoff);
1873 printf(" s %02d", s->varnum);
1876 printf(" l %02d", s->varnum);
1879 printf(" a %02d", s->varnum);
1882 printf(" ! %02d", s->varnum);
1885 switch (s->varkind) {
1887 if (s->flags & INMEMORY)
1888 printf(" Tm%02d", s->regoff);
1890 printf(" Tr%02d", s->regoff);
1893 printf(" S %02d", s->varnum);
1896 printf(" L %02d", s->varnum);
1899 printf(" A %02d", s->varnum);
1902 printf(" ? %02d", s->varnum);
1912 char *icmd_builtin_name(functionptr bptr)
1914 builtin_descriptor *bdesc = builtin_desc;
1915 while ((bdesc->bptr != NULL) && (bdesc->bptr != bptr))
1921 static char *jit_type[] = {
1930 void show_icmd_method()
1941 utf_fprint(stdout, class->name);
1943 utf_fprint(stdout, method->name);
1945 utf_fprint(stdout, method->descriptor);
1946 printf ("\n\nMax locals: %d\n", (int) maxlocals);
1947 printf ("Max stack: %d\n", (int) maxstack);
1949 printf ("Exceptions (Number: %d):\n", exceptiontablelength);
1950 for (ex = extable; ex != NULL; ex = ex->down) {
1951 printf(" L%03d ... ", ex->start->debug_nr );
1952 printf("L%03d = ", ex->end->debug_nr);
1953 printf("L%03d\n", ex->handler->debug_nr);
1956 printf ("Local Table:\n");
1957 for (i = 0; i < maxlocals; i++) {
1958 printf(" %3d: ", i);
1959 for (j = TYPE_INT; j <= TYPE_ADR; j++)
1960 if (locals[i][j].type >= 0) {
1961 printf(" (%s) ", jit_type[j]);
1962 if (locals[i][j].flags & INMEMORY)
1963 printf((regs_ok) ? "m%2d" : "m??", locals[i][j].regoff);
1964 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
1965 printf((regs_ok) ? "f%02d" : "f??", locals[i][j].regoff);
1967 if (regs_ok) printf("%3s",regs[locals[i][j].regoff]); else printf("???");
1974 printf ("Interface Table:\n");
1975 for (i = 0; i < maxstack; i++) {
1976 if ((interfaces[i][0].type >= 0) || (interfaces[i][1].type >= 0) ||
1977 (interfaces[i][2].type >= 0) || (interfaces[i][3].type >= 0) ||
1978 (interfaces[i][4].type >= 0)) {
1979 printf(" %3d: ", i);
1980 for (j = TYPE_INT; j <= TYPE_ADR; j++)
1981 if (interfaces[i][j].type >= 0) {
1982 printf(" (%s) ", jit_type[j]);
1983 if (interfaces[i][j].flags & SAVEDVAR) {
1984 if (interfaces[i][j].flags & INMEMORY)
1985 printf((regs_ok) ? "M%2d" : "M??", interfaces[i][j].regoff);
1986 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
1987 printf((regs_ok) ? "F%02d" : "F??", interfaces[i][j].regoff);
1989 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
1993 if (interfaces[i][j].flags & INMEMORY)
1994 printf((regs_ok) ? "m%2d" : "m??", interfaces[i][j].regoff);
1995 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
1996 printf((regs_ok) ? "f%02d" : "f??", interfaces[i][j].regoff);
1998 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2007 if (showdisassemble) {
2008 #if defined(__I386__) || defined(__X86_64__)
2012 u1ptr = method->mcode + dseglen;
2013 for (i = 0; i < block[0].mpc; i++, u1ptr++) {
2014 a = disassinstr(u1ptr, i);
2020 s4ptr = (s4 *) (method->mcode + dseglen);
2021 for (i = 0; i < block[0].mpc; i += 4, s4ptr++) {
2022 disassinstr(*s4ptr, i);
2029 for (bptr = block; bptr != NULL; bptr = bptr->next) {
2030 show_icmd_block(bptr);
2035 show_icmd_block(basicblock *bptr)
2042 if (bptr->flags != BBDELETED) {
2043 deadcode = bptr->flags <= BBREACHED;
2046 for (j = method->maxstack; j > 0; j--)
2049 icmd_print_stack(bptr->instack);
2050 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2051 iptr = bptr->iinstr;
2053 for (i=0; i < bptr->icount; i++, iptr++) {
2056 for (j = method->maxstack; j > 0; j--)
2060 icmd_print_stack(iptr->dst);
2061 printf("] %4d ", i);
2062 /* XXX remove */ /*fflush(stdout);*/
2063 show_icmd(iptr,deadcode);
2067 if (showdisassemble && (!deadcode)) {
2068 #if defined(__I386__) || defined(__X86_64__)
2074 u1ptr = method->mcode + dseglen + i;
2076 if (bptr->next != NULL) {
2077 for (; i < bptr->next->mpc; i++, u1ptr++) {
2078 a = disassinstr(u1ptr, i);
2085 for (; u1ptr < (u1 *) (method->mcode + method->mcodelength); i++, u1ptr++) {
2086 a = disassinstr(u1ptr, i);
2095 s4ptr = (s4 *) (method->mcode + dseglen + i);
2097 if (bptr->next != NULL) {
2098 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2099 disassinstr(*s4ptr, i);
2104 for (; s4ptr < (s4 *) (method->mcode + method->mcodelength); i += 4, s4ptr++) {
2105 disassinstr(*s4ptr, i);
2115 show_icmd(instruction *iptr,bool deadcode)
2121 printf("%s",icmd_names[iptr->opc]);
2122 switch ((int) iptr->opc) {
2123 case ICMD_IADDCONST:
2124 case ICMD_ISUBCONST:
2125 case ICMD_IMULCONST:
2128 case ICMD_IREM0X10001:
2129 case ICMD_IANDCONST:
2131 case ICMD_IXORCONST:
2132 case ICMD_ISHLCONST:
2133 case ICMD_ISHRCONST:
2134 case ICMD_IUSHRCONST:
2135 case ICMD_LSHLCONST:
2136 case ICMD_LSHRCONST:
2137 case ICMD_LUSHRCONST:
2139 case ICMD_ELSE_ICONST:
2140 case ICMD_IFEQ_ICONST:
2141 case ICMD_IFNE_ICONST:
2142 case ICMD_IFLT_ICONST:
2143 case ICMD_IFGE_ICONST:
2144 case ICMD_IFGT_ICONST:
2145 case ICMD_IFLE_ICONST:
2146 printf(" %d", iptr->val.i);
2148 case ICMD_LADDCONST:
2149 case ICMD_LSUBCONST:
2150 case ICMD_LMULCONST:
2153 case ICMD_LANDCONST:
2155 case ICMD_LXORCONST:
2157 #if defined(__I386__)
2158 printf(" %lld", iptr->val.l);
2160 printf(" %ld", iptr->val.l);
2164 printf(" %f", iptr->val.f);
2167 printf(" %f", iptr->val.d);
2170 printf(" %p", iptr->val.a);
2174 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2175 case ICMD_PUTSTATIC:
2176 case ICMD_GETSTATIC:
2179 ((fieldinfo *) iptr->val.a)->name);
2182 printf(" %d + %d", iptr->op1, iptr->val.i);
2217 printf(" %d", iptr->op1);
2222 ((classinfo *) iptr->val.a)->name);
2225 switch (iptr->op1) {
2252 case ICMD_ANEWARRAY:
2256 ((classinfo *) iptr->val.a)->name);
2259 case ICMD_CHECKCAST:
2260 case ICMD_INSTANCEOF:
2262 classinfo *c = iptr->val.a;
2263 if (c->flags & ACC_INTERFACE)
2264 printf(" (INTERFACE) ");
2266 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2267 utf_fprint(stdout, c->name);
2273 printf(" %s", icmd_builtin_name((functionptr) iptr->val.a));
2275 case ICMD_INVOKEVIRTUAL:
2276 case ICMD_INVOKESPECIAL:
2277 case ICMD_INVOKESTATIC:
2278 case ICMD_INVOKEINTERFACE:
2281 ((methodinfo *) iptr->val.a)->class->name);
2284 ((methodinfo *) iptr->val.a)->name);
2292 if (deadcode || !iptr->target)
2293 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2295 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2303 if (deadcode || !iptr->target)
2304 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2306 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2311 case ICMD_IFNONNULL:
2312 case ICMD_IF_ICMPEQ:
2313 case ICMD_IF_ICMPNE:
2314 case ICMD_IF_ICMPLT:
2315 case ICMD_IF_ICMPGE:
2316 case ICMD_IF_ICMPGT:
2317 case ICMD_IF_ICMPLE:
2318 case ICMD_IF_LCMPEQ:
2319 case ICMD_IF_LCMPNE:
2320 case ICMD_IF_LCMPLT:
2321 case ICMD_IF_LCMPGE:
2322 case ICMD_IF_LCMPGT:
2323 case ICMD_IF_LCMPLE:
2324 case ICMD_IF_ACMPEQ:
2325 case ICMD_IF_ACMPNE:
2326 if (deadcode || !iptr->target)
2327 printf(" op1=%d", iptr->op1);
2329 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2331 case ICMD_TABLESWITCH:
2333 s4ptr = iptr->val.a;
2335 if (deadcode || !iptr->target) {
2336 printf(" %d;", *s4ptr);
2339 tptr = (void **) iptr->target;
2340 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2344 s4ptr++; /* skip default */
2345 j = *s4ptr++; /* low */
2346 j = *s4ptr++ - j; /* high */
2348 if (deadcode || !*tptr)
2349 printf(" %d", *s4ptr++);
2351 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2357 case ICMD_LOOKUPSWITCH:
2358 s4ptr = iptr->val.a;
2360 if (deadcode || !iptr->target) {
2361 printf(" %d;", *s4ptr);
2364 tptr = (void **) iptr->target;
2365 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2368 s4ptr++; /* default */
2369 j = *s4ptr++; /* count */
2372 if (deadcode || !*tptr) {
2373 s4ptr++; /* skip value */
2374 printf(" %d",*s4ptr++);
2377 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2386 * These are local overrides for various environment variables in Emacs.
2387 * Please do not remove this and leave it at the end of the file, where
2388 * Emacs will automagically detect them.
2389 * ---------------------------------------------------------------------
2392 * indent-tabs-mode: t