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 768 2003-12-13 22:56:53Z twisti $
46 #include "toolbox/loging.h"
47 #include "toolbox/memory.h"
50 /* from codegen.inc */
55 #define COUNT(cnt) cnt++
60 #define STACKRESET {curstack=0;stackdepth=0;}
62 #define TYPEPANIC {show_icmd_method();panic("Stack type mismatch");}
63 #define UNDERFLOW {show_icmd_method();panic("Stack underflow");} /* XXX why isn't this caught in parse.c? */
64 #define CURKIND curstack->varkind
65 #define CURTYPE curstack->type
67 #define REQUIRE(num) do { if (stackdepth<(num)) {UNDERFLOW;} } while(0)
68 #define REQUIRE_1 REQUIRE(1)
69 #define REQUIRE_2 REQUIRE(2)
70 #define REQUIRE_3 REQUIRE(3)
71 #define REQUIRE_4 REQUIRE(4)
73 #define NEWSTACK(s,v,n) {new->prev=curstack;new->type=s;new->flags=0; \
74 new->varkind=v;new->varnum=n;curstack=new;new++;}
75 #define NEWSTACKn(s,n) NEWSTACK(s,UNDEFVAR,n)
76 #define NEWSTACK0(s) NEWSTACK(s,UNDEFVAR,0)
77 #define NEWXSTACK {NEWSTACK(TYPE_ADR,STACKVAR,0);curstack=0;}
79 #define SETDST {iptr->dst=curstack;}
81 /* The following macros do NOT check stackdepth, set stackdepth and iptr->dst */
82 #define POP(s) {if(s!=curstack->type){TYPEPANIC;} \
83 if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR;\
84 curstack=curstack->prev;}
85 #define POPANY {if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR; \
86 curstack=curstack->prev;}
87 #define COPY(s,d) {(d)->flags=0;(d)->type=(s)->type;\
88 (d)->varkind=(s)->varkind;(d)->varnum=(s)->varnum;}
89 /******************************/
91 /* The following macros check stackdepth, set stackdepth and itpr->dst */
92 #define PUSHCONST(s){NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
93 #define LOAD(s,v,n) {NEWSTACK(s,v,n);SETDST;stackdepth++;}
94 #define STORE(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
95 #define OP1_0(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
96 #define OP1_0ANY {REQUIRE_1;POPANY;SETDST;stackdepth--;}
97 #define OP0_1(s) {NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
98 #define OP1_1(s,d) {REQUIRE_1;POP(s);NEWSTACKn(d,stackdepth-1);SETDST;}
99 #define OP2_0(s) {REQUIRE_2;POP(s);POP(s);SETDST;stackdepth-=2;}
100 #define OPTT2_0(t,b){REQUIRE_2;POP(t);POP(b);SETDST;stackdepth-=2;}
101 #define OP2_1(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);SETDST;stackdepth--;}
102 #define OP2IAT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(TYPE_ADR);NEWSTACKn(s,stackdepth-2);\
103 SETDST;stackdepth--;}
104 #define OP2IT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(s);NEWSTACKn(s,stackdepth-2);\
105 SETDST;stackdepth--;}
106 #define OPTT2_1(s,d){REQUIRE_2;POP(s);POP(s);NEWSTACKn(d,stackdepth-2);SETDST;stackdepth--;}
107 #define OP2_2(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);\
108 NEWSTACKn(s,stackdepth-1);SETDST;}
109 #define OP3TIA_0(s) {REQUIRE_3;POP(s);POP(TYPE_INT);POP(TYPE_ADR);SETDST;stackdepth-=3;}
110 #define OP3_0(s) {REQUIRE_3;POP(s);POP(s);POP(s);SETDST;stackdepth-=3;}
111 #define POPMANY(i) {REQUIRE(i);stackdepth-=i;while(--i>=0){POPANY;}SETDST;}
112 #define DUP {REQUIRE_1;NEWSTACK(CURTYPE,CURKIND,curstack->varnum);SETDST; \
114 #define SWAP {REQUIRE_2;COPY(curstack,new);POPANY;COPY(curstack,new+1);POPANY;\
115 new[0].prev=curstack;new[1].prev=new;\
116 curstack=new+1;new+=2;SETDST;}
117 #define DUP_X1 {REQUIRE_2;COPY(curstack,new);COPY(curstack,new+2);POPANY;\
118 COPY(curstack,new+1);POPANY;new[0].prev=curstack;\
119 new[1].prev=new;new[2].prev=new+1;\
120 curstack=new+2;new+=3;SETDST;stackdepth++;}
121 #define DUP2_X1 {REQUIRE_3;COPY(curstack,new+1);COPY(curstack,new+4);POPANY;\
122 COPY(curstack,new);COPY(curstack,new+3);POPANY;\
123 COPY(curstack,new+2);POPANY;new[0].prev=curstack;\
124 new[1].prev=new;new[2].prev=new+1;\
125 new[3].prev=new+2;new[4].prev=new+3;\
126 curstack=new+4;new+=5;SETDST;stackdepth+=2;}
127 #define DUP_X2 {REQUIRE_3;COPY(curstack,new);COPY(curstack,new+3);POPANY;\
128 COPY(curstack,new+2);POPANY;COPY(curstack,new+1);POPANY;\
129 new[0].prev=curstack;new[1].prev=new;\
130 new[2].prev=new+1;new[3].prev=new+2;\
131 curstack=new+3;new+=4;SETDST;stackdepth++;}
132 #define DUP2_X2 {REQUIRE_4;COPY(curstack,new+1);COPY(curstack,new+5);POPANY;\
133 COPY(curstack,new);COPY(curstack,new+4);POPANY;\
134 COPY(curstack,new+3);POPANY;COPY(curstack,new+2);POPANY;\
135 new[0].prev=curstack;new[1].prev=new;\
136 new[2].prev=new+1;new[3].prev=new+2;\
137 new[4].prev=new+3;new[5].prev=new+4;\
138 curstack=new+5;new+=6;SETDST;stackdepth+=2;}
139 /******************************/
141 #define COPYCURSTACK(copy) {\
154 copy->varkind=STACKVAR;\
170 if((copy->varkind==STACKVAR)&&(copy->varnum>i))\
171 copy->varkind=TEMPVAR;\
173 copy->varkind=STACKVAR;\
176 interfaces[i][copy->type].type = copy->type;\
177 interfaces[i][copy->type].flags |= copy->flags;\
178 i--;copy=copy->prev;\
183 interfaces[i][copy->type].type = copy->type;\
184 if(copy->varkind==STACKVAR){\
185 if (copy->flags & SAVEDVAR)\
186 interfaces[i][copy->type].flags |= SAVEDVAR;\
188 i--;copy=copy->prev;\
193 #define MARKREACHED(b,c) {\
195 {COPYCURSTACK(c);b->flags=0;b->instack=c;b->indepth=stackdepth;}\
196 else {stackptr s=curstack;stackptr t=b->instack;\
197 if(b->indepth!=stackdepth)\
198 {show_icmd_method();panic("Stack depth mismatch");}\
199 while(s){if (s->type!=t->type)\
201 s=s->prev;t=t->prev;\
215 int opcode, i, len, loops;
216 int superblockend, repeat, deadcode;
224 if (compileverbose) {
225 char logtext[MAXLOGTEXT];
226 sprintf(logtext, "Analysing: ");
227 utf_sprint(logtext+strlen(logtext), method->class->name);
228 strcpy(logtext+strlen(logtext), ".");
229 utf_sprint(logtext+strlen(logtext), method->name);
230 utf_sprint(logtext+strlen(logtext), method->descriptor);
234 argren = DMNEW(int, maxlocals);
235 //int *argren = (int *)alloca(maxlocals * sizeof(int)); /* table for argument renaming */
236 for (i = 0; i < maxlocals; i++)
242 block[0].flags = BBREACHED;
243 block[0].instack = 0;
244 block[0].indepth = 0;
246 for (i = 0; i < exceptiontablelength; i++) {
247 bptr = &block[block_index[extable[i].handlerpc]];
248 bptr->flags = BBREACHED;
249 bptr->type = BBTYPE_EXH;
252 bptr->pre_count = 10000;
257 #ifdef CONDITIONAL_LOADCONST
258 b_count = block_count;
260 while (--b_count >= 0) {
261 if (bptr->icount != 0) {
262 iptr = bptr->iinstr + bptr->icount - 1;
295 block[block_index[iptr->op1]].pre_count++;
298 case ICMD_TABLESWITCH:
300 block[block_index[*s4ptr++]].pre_count++; /* default */
301 i = *s4ptr++; /* low */
302 i = *s4ptr++ - i + 1; /* high */
304 block[block_index[*s4ptr++]].pre_count++;
308 case ICMD_LOOKUPSWITCH:
310 block[block_index[*s4ptr++]].pre_count++; /* default */
311 i = *s4ptr++; /* count */
313 block[block_index[s4ptr[1]]].pre_count++;
329 b_count = block_count;
331 superblockend = true;
335 while (--b_count >= 0) {
336 if (bptr->flags == BBDELETED) {
339 else if (superblockend && (bptr->flags < BBREACHED))
341 else if (bptr->flags <= BBREACHED) {
343 stackdepth = bptr->indepth;
344 else if (bptr->flags < BBREACHED) {
346 bptr->instack = copy;
347 bptr->indepth = stackdepth;
349 else if (bptr->indepth != stackdepth) {
351 panic("Stack depth mismatch");
354 curstack = bptr->instack;
356 superblockend = false;
357 bptr->flags = BBFINISHED;
360 b_index = bptr - block;
365 /* DEBUG XXX */ /* dolog("p:%04d op: %s",iptr-instr,icmd_names[opcode]); */
367 #ifdef USEBUILTINTABLE
370 stdopdescriptor *breplace;
371 breplace = find_builtin(opcode);
373 if (breplace && opcode == breplace->opcode) {
374 iptr[0].opc = breplace->icmd;
375 iptr[0].op1 = breplace->type_d;
376 iptr[0].val.a = breplace->builtin;
377 isleafmethod = false;
378 switch (breplace->icmd) {
386 builtin_descriptor *breplace;
387 breplace = find_builtin(opcode);
389 if (breplace && opcode == breplace->opcode) {
390 iptr[0].opc = breplace->icmd;
391 iptr[0].op1 = breplace->type_d;
392 iptr[0].val.a = breplace->builtin;
393 isleafmethod = false;
394 switch (breplace->icmd) {
409 case ICMD_CHECKASIZE:
411 case ICMD_IFEQ_ICONST:
412 case ICMD_IFNE_ICONST:
413 case ICMD_IFLT_ICONST:
414 case ICMD_IFGE_ICONST:
415 case ICMD_IFGT_ICONST:
416 case ICMD_IFLE_ICONST:
417 case ICMD_ELSE_ICONST:
422 locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
424 COUNT(count_pcmd_return);
426 superblockend = true;
429 /* pop 0 push 1 const */
432 COUNT(count_pcmd_load);
434 switch (iptr[1].opc) {
436 iptr[0].opc = ICMD_IADDCONST;
438 iptr[1].opc = ICMD_NOP;
439 OP1_1(TYPE_INT,TYPE_INT);
440 COUNT(count_pcmd_op);
443 iptr[0].opc = ICMD_ISUBCONST;
444 goto icmd_iconst_tail;
446 iptr[0].opc = ICMD_IMULCONST;
447 goto icmd_iconst_tail;
449 if (iptr[0].val.i == 0x00000002)
451 else if (iptr[0].val.i == 0x00000004)
453 else if (iptr[0].val.i == 0x00000008)
455 else if (iptr[0].val.i == 0x00000010)
457 else if (iptr[0].val.i == 0x00000020)
459 else if (iptr[0].val.i == 0x00000040)
461 else if (iptr[0].val.i == 0x00000080)
463 else if (iptr[0].val.i == 0x00000100)
465 else if (iptr[0].val.i == 0x00000200)
467 else if (iptr[0].val.i == 0x00000400)
469 else if (iptr[0].val.i == 0x00000800)
471 else if (iptr[0].val.i == 0x00001000)
473 else if (iptr[0].val.i == 0x00002000)
475 else if (iptr[0].val.i == 0x00004000)
477 else if (iptr[0].val.i == 0x00008000)
479 else if (iptr[0].val.i == 0x00010000)
481 else if (iptr[0].val.i == 0x00020000)
483 else if (iptr[0].val.i == 0x00040000)
485 else if (iptr[0].val.i == 0x00080000)
487 else if (iptr[0].val.i == 0x00100000)
489 else if (iptr[0].val.i == 0x00200000)
491 else if (iptr[0].val.i == 0x00400000)
493 else if (iptr[0].val.i == 0x00800000)
495 else if (iptr[0].val.i == 0x01000000)
497 else if (iptr[0].val.i == 0x02000000)
499 else if (iptr[0].val.i == 0x04000000)
501 else if (iptr[0].val.i == 0x08000000)
503 else if (iptr[0].val.i == 0x10000000)
505 else if (iptr[0].val.i == 0x20000000)
507 else if (iptr[0].val.i == 0x40000000)
509 else if (iptr[0].val.i == 0x80000000)
515 iptr[0].opc = ICMD_IDIVPOW2;
516 goto icmd_iconst_tail;
518 #if !defined(NO_DIV_OPT)
519 if (iptr[0].val.i == 0x10001) {
520 iptr[0].opc = ICMD_IREM0X10001;
521 goto icmd_iconst_tail;
524 if ((iptr[0].val.i == 0x00000002) ||
525 (iptr[0].val.i == 0x00000004) ||
526 (iptr[0].val.i == 0x00000008) ||
527 (iptr[0].val.i == 0x00000010) ||
528 (iptr[0].val.i == 0x00000020) ||
529 (iptr[0].val.i == 0x00000040) ||
530 (iptr[0].val.i == 0x00000080) ||
531 (iptr[0].val.i == 0x00000100) ||
532 (iptr[0].val.i == 0x00000200) ||
533 (iptr[0].val.i == 0x00000400) ||
534 (iptr[0].val.i == 0x00000800) ||
535 (iptr[0].val.i == 0x00001000) ||
536 (iptr[0].val.i == 0x00002000) ||
537 (iptr[0].val.i == 0x00004000) ||
538 (iptr[0].val.i == 0x00008000) ||
539 (iptr[0].val.i == 0x00010000) ||
540 (iptr[0].val.i == 0x00020000) ||
541 (iptr[0].val.i == 0x00040000) ||
542 (iptr[0].val.i == 0x00080000) ||
543 (iptr[0].val.i == 0x00100000) ||
544 (iptr[0].val.i == 0x00200000) ||
545 (iptr[0].val.i == 0x00400000) ||
546 (iptr[0].val.i == 0x00800000) ||
547 (iptr[0].val.i == 0x01000000) ||
548 (iptr[0].val.i == 0x02000000) ||
549 (iptr[0].val.i == 0x04000000) ||
550 (iptr[0].val.i == 0x08000000) ||
551 (iptr[0].val.i == 0x10000000) ||
552 (iptr[0].val.i == 0x20000000) ||
553 (iptr[0].val.i == 0x40000000) ||
554 (iptr[0].val.i == 0x80000000)) {
555 iptr[0].opc = ICMD_IREMPOW2;
557 goto icmd_iconst_tail;
562 iptr[0].opc = ICMD_IANDCONST;
563 goto icmd_iconst_tail;
565 iptr[0].opc = ICMD_IORCONST;
566 goto icmd_iconst_tail;
568 iptr[0].opc = ICMD_IXORCONST;
569 goto icmd_iconst_tail;
571 iptr[0].opc = ICMD_ISHLCONST;
572 goto icmd_iconst_tail;
574 iptr[0].opc = ICMD_ISHRCONST;
575 goto icmd_iconst_tail;
577 iptr[0].opc = ICMD_IUSHRCONST;
578 goto icmd_iconst_tail;
579 #if SUPPORT_LONG_SHIFT
581 iptr[0].opc = ICMD_LSHLCONST;
582 goto icmd_lconst_tail;
584 iptr[0].opc = ICMD_LSHRCONST;
585 goto icmd_lconst_tail;
587 iptr[0].opc = ICMD_LUSHRCONST;
588 goto icmd_lconst_tail;
591 iptr[0].opc = ICMD_IFEQ;
593 iptr[0].op1 = iptr[1].op1;
596 /* iptr[1].opc = ICMD_NOP; */
598 tbptr = block + block_index[iptr->op1];
600 iptr[0].target = (void *) tbptr;
602 MARKREACHED(tbptr, copy);
603 COUNT(count_pcmd_bra);
606 iptr[0].opc = ICMD_IFLT;
607 goto icmd_if_icmp_tail;
609 iptr[0].opc = ICMD_IFLE;
610 goto icmd_if_icmp_tail;
612 iptr[0].opc = ICMD_IFNE;
613 goto icmd_if_icmp_tail;
615 iptr[0].opc = ICMD_IFGT;
616 goto icmd_if_icmp_tail;
618 iptr[0].opc = ICMD_IFGE;
619 goto icmd_if_icmp_tail;
628 COUNT(count_pcmd_load);
630 switch (iptr[1].opc) {
633 iptr[0].opc = ICMD_LADDCONST;
635 iptr[1].opc = ICMD_NOP;
636 OP1_1(TYPE_LNG,TYPE_LNG);
637 COUNT(count_pcmd_op);
640 iptr[0].opc = ICMD_LSUBCONST;
641 goto icmd_lconst_tail;
645 iptr[0].opc = ICMD_LMULCONST;
646 #if defined(__I386__)
647 method_uses_edx = true;
649 goto icmd_lconst_tail;
653 if (iptr[0].val.l == 0x00000002)
655 else if (iptr[0].val.l == 0x00000004)
657 else if (iptr[0].val.l == 0x00000008)
659 else if (iptr[0].val.l == 0x00000010)
661 else if (iptr[0].val.l == 0x00000020)
663 else if (iptr[0].val.l == 0x00000040)
665 else if (iptr[0].val.l == 0x00000080)
667 else if (iptr[0].val.l == 0x00000100)
669 else if (iptr[0].val.l == 0x00000200)
671 else if (iptr[0].val.l == 0x00000400)
673 else if (iptr[0].val.l == 0x00000800)
675 else if (iptr[0].val.l == 0x00001000)
677 else if (iptr[0].val.l == 0x00002000)
679 else if (iptr[0].val.l == 0x00004000)
681 else if (iptr[0].val.l == 0x00008000)
683 else if (iptr[0].val.l == 0x00010000)
685 else if (iptr[0].val.l == 0x00020000)
687 else if (iptr[0].val.l == 0x00040000)
689 else if (iptr[0].val.l == 0x00080000)
691 else if (iptr[0].val.l == 0x00100000)
693 else if (iptr[0].val.l == 0x00200000)
695 else if (iptr[0].val.l == 0x00400000)
697 else if (iptr[0].val.l == 0x00800000)
699 else if (iptr[0].val.l == 0x01000000)
701 else if (iptr[0].val.l == 0x02000000)
703 else if (iptr[0].val.l == 0x04000000)
705 else if (iptr[0].val.l == 0x08000000)
707 else if (iptr[0].val.l == 0x10000000)
709 else if (iptr[0].val.l == 0x20000000)
711 else if (iptr[0].val.l == 0x40000000)
713 else if (iptr[0].val.l == 0x80000000)
719 iptr[0].opc = ICMD_LDIVPOW2;
720 goto icmd_lconst_tail;
722 #if !defined(NO_DIV_OPT)
723 if (iptr[0].val.l == 0x10001) {
724 iptr[0].opc = ICMD_LREM0X10001;
725 goto icmd_lconst_tail;
728 if ((iptr[0].val.l == 0x00000002) ||
729 (iptr[0].val.l == 0x00000004) ||
730 (iptr[0].val.l == 0x00000008) ||
731 (iptr[0].val.l == 0x00000010) ||
732 (iptr[0].val.l == 0x00000020) ||
733 (iptr[0].val.l == 0x00000040) ||
734 (iptr[0].val.l == 0x00000080) ||
735 (iptr[0].val.l == 0x00000100) ||
736 (iptr[0].val.l == 0x00000200) ||
737 (iptr[0].val.l == 0x00000400) ||
738 (iptr[0].val.l == 0x00000800) ||
739 (iptr[0].val.l == 0x00001000) ||
740 (iptr[0].val.l == 0x00002000) ||
741 (iptr[0].val.l == 0x00004000) ||
742 (iptr[0].val.l == 0x00008000) ||
743 (iptr[0].val.l == 0x00010000) ||
744 (iptr[0].val.l == 0x00020000) ||
745 (iptr[0].val.l == 0x00040000) ||
746 (iptr[0].val.l == 0x00080000) ||
747 (iptr[0].val.l == 0x00100000) ||
748 (iptr[0].val.l == 0x00200000) ||
749 (iptr[0].val.l == 0x00400000) ||
750 (iptr[0].val.l == 0x00800000) ||
751 (iptr[0].val.l == 0x01000000) ||
752 (iptr[0].val.l == 0x02000000) ||
753 (iptr[0].val.l == 0x04000000) ||
754 (iptr[0].val.l == 0x08000000) ||
755 (iptr[0].val.l == 0x10000000) ||
756 (iptr[0].val.l == 0x20000000) ||
757 (iptr[0].val.l == 0x40000000) ||
758 (iptr[0].val.l == 0x80000000)) {
759 iptr[0].opc = ICMD_LREMPOW2;
761 goto icmd_lconst_tail;
768 iptr[0].opc = ICMD_LANDCONST;
769 goto icmd_lconst_tail;
771 iptr[0].opc = ICMD_LORCONST;
772 goto icmd_lconst_tail;
774 iptr[0].opc = ICMD_LXORCONST;
775 goto icmd_lconst_tail;
777 #if !defined(NOLONG_CONDITIONAL)
779 if ((len > 1) && (iptr[2].val.i == 0)) {
780 switch (iptr[2].opc) {
782 iptr[0].opc = ICMD_IF_LEQ;
783 icmd_lconst_lcmp_tail:
784 iptr[0].op1 = iptr[2].op1;
787 /* iptr[1].opc = ICMD_NOP;
788 iptr[2].opc = ICMD_NOP; */
790 tbptr = block + block_index[iptr->op1];
792 iptr[0].target = (void *) tbptr;
794 MARKREACHED(tbptr, copy);
795 COUNT(count_pcmd_bra);
796 COUNT(count_pcmd_op);
799 iptr[0].opc = ICMD_IF_LNE;
800 goto icmd_lconst_lcmp_tail;
802 iptr[0].opc = ICMD_IF_LLT;
803 goto icmd_lconst_lcmp_tail;
805 iptr[0].opc = ICMD_IF_LGT;
806 goto icmd_lconst_lcmp_tail;
808 iptr[0].opc = ICMD_IF_LLE;
809 goto icmd_lconst_lcmp_tail;
811 iptr[0].opc = ICMD_IF_LGE;
812 goto icmd_lconst_lcmp_tail;
815 } /* switch (iptr[2].opc) */
816 } /* if (iptr[2].val.i == 0) */
829 COUNT(count_pcmd_load);
833 COUNT(count_pcmd_load);
837 COUNT(count_pcmd_load);
841 /* pop 0 push 1 load */
848 COUNT(count_load_instruction);
849 i = opcode-ICMD_ILOAD;
850 iptr->op1 = argren[iptr->op1];
851 locals[iptr->op1][i].type = i;
852 LOAD(i, LOCALVAR, iptr->op1);
858 #if defined(__I386__)
859 method_uses_edx = true;
865 COUNT(count_check_null);
866 COUNT(count_check_bound);
867 COUNT(count_pcmd_mem);
868 OP2IAT_1(opcode-ICMD_IALOAD);
874 COUNT(count_check_null);
875 COUNT(count_check_bound);
876 COUNT(count_pcmd_mem);
880 /* pop 0 push 0 iinc */
886 count_store_depth[10]++;
888 count_store_depth[i]++;
893 if ((copy->varkind == LOCALVAR) &&
894 (copy->varnum == iptr->op1)) {
895 copy->varkind = TEMPVAR;
904 /* pop 1 push 0 store */
914 i = opcode - ICMD_ISTORE;
915 locals[iptr->op1][i].type = i;
920 count_store_length[20]++;
922 count_store_length[i]++;
925 count_store_depth[10]++;
927 count_store_depth[i]++;
929 copy = curstack->prev;
932 if ((copy->varkind == LOCALVAR) &&
933 (copy->varnum == iptr->op1)) {
934 copy->varkind = TEMPVAR;
940 if ((new - curstack) == 1) {
941 curstack->varkind = LOCALVAR;
942 curstack->varnum = iptr->op1;
944 STORE(opcode-ICMD_ISTORE);
952 #if defined(__I386__)
953 method_uses_edx = true;
957 COUNT(count_check_null);
958 COUNT(count_check_bound);
959 COUNT(count_pcmd_mem);
960 OP3TIA_0(opcode-ICMD_IASTORE);
966 COUNT(count_check_null);
967 COUNT(count_check_bound);
968 COUNT(count_pcmd_mem);
970 #if defined(__I386__)
971 method_uses_edx = true;
986 COUNT(count_pcmd_return);
987 OP1_0(opcode-ICMD_IRETURN);
988 superblockend = true;
992 COUNT(count_check_null);
996 superblockend = true;
1000 COUNT(count_pcmd_mem);
1004 /* pop 1 push 0 branch */
1007 case ICMD_IFNONNULL:
1008 COUNT(count_pcmd_bra);
1010 tbptr = block + block_index[iptr->op1];
1012 iptr[0].target = (void *) tbptr;
1014 MARKREACHED(tbptr, copy);
1023 COUNT(count_pcmd_bra);
1024 #ifdef CONDITIONAL_LOADCONST
1026 tbptr = block + b_index;
1027 if ((b_count >= 3) &&
1028 ((b_index + 2) == block_index[iptr[0].op1]) &&
1029 (tbptr[1].pre_count == 1) &&
1030 (iptr[1].opc == ICMD_ICONST) &&
1031 (iptr[2].opc == ICMD_GOTO) &&
1032 ((b_index + 3) == block_index[iptr[2].op1]) &&
1033 (tbptr[2].pre_count == 1) &&
1034 (iptr[3].opc == ICMD_ICONST)) {
1035 OP1_1(TYPE_INT, TYPE_INT);
1036 switch (iptr[0].opc) {
1038 iptr[0].opc = ICMD_IFNE_ICONST;
1041 iptr[0].opc = ICMD_IFEQ_ICONST;
1044 iptr[0].opc = ICMD_IFGE_ICONST;
1047 iptr[0].opc = ICMD_IFLT_ICONST;
1050 iptr[0].opc = ICMD_IFLE_ICONST;
1053 iptr[0].opc = ICMD_IFGT_ICONST;
1056 iptr[0].val.i = iptr[1].val.i;
1057 iptr[1].opc = ICMD_ELSE_ICONST;
1058 iptr[1].val.i = iptr[3].val.i;
1059 iptr[2].opc = ICMD_NOP;
1060 iptr[3].opc = ICMD_NOP;
1061 tbptr[1].flags = BBDELETED;
1062 tbptr[2].flags = BBDELETED;
1063 tbptr[1].icount = 0;
1064 tbptr[2].icount = 0;
1065 if (tbptr[3].pre_count == 2) {
1066 len += tbptr[3].icount + 3;
1067 bptr->icount += tbptr[3].icount + 3;
1068 tbptr[3].flags = BBDELETED;
1069 tbptr[3].icount = 0;
1082 tbptr = block + block_index[iptr->op1];
1084 iptr[0].target = (void *) tbptr;
1086 MARKREACHED(tbptr, copy);
1089 /* pop 0 push 0 branch */
1092 COUNT(count_pcmd_bra);
1093 tbptr = block + block_index[iptr->op1];
1095 iptr[0].target = (void *) tbptr;
1097 MARKREACHED(tbptr, copy);
1099 superblockend = true;
1102 /* pop 1 push 0 table branch */
1104 case ICMD_TABLESWITCH:
1105 COUNT(count_pcmd_table);
1107 s4ptr = iptr->val.a;
1108 tbptr = block + block_index[*s4ptr++]; /* default */
1109 MARKREACHED(tbptr, copy);
1110 i = *s4ptr++; /* low */
1111 i = *s4ptr++ - i + 1; /* high */
1113 tptr = DMNEW(void*, i+1);
1114 iptr->target = (void *) tptr;
1116 tptr[0] = (void *) tbptr;
1120 tbptr = block + block_index[*s4ptr++];
1122 tptr[0] = (void *) tbptr;
1125 MARKREACHED(tbptr, copy);
1128 superblockend = true;
1131 /* pop 1 push 0 table branch */
1133 case ICMD_LOOKUPSWITCH:
1134 COUNT(count_pcmd_table);
1136 s4ptr = iptr->val.a;
1137 tbptr = block + block_index[*s4ptr++]; /* default */
1138 MARKREACHED(tbptr, copy);
1139 i = *s4ptr++; /* count */
1141 tptr = DMNEW(void*, i+1);
1142 iptr->target = (void *) tptr;
1144 tptr[0] = (void *) tbptr;
1148 tbptr = block + block_index[s4ptr[1]];
1150 tptr[0] = (void *) tbptr;
1153 MARKREACHED(tbptr, copy);
1157 superblockend = true;
1160 case ICMD_NULLCHECKPOP:
1161 case ICMD_MONITORENTER:
1162 COUNT(count_check_null);
1163 case ICMD_MONITOREXIT:
1167 /* pop 2 push 0 branch */
1169 case ICMD_IF_ICMPEQ:
1170 case ICMD_IF_ICMPNE:
1171 case ICMD_IF_ICMPLT:
1172 case ICMD_IF_ICMPGE:
1173 case ICMD_IF_ICMPGT:
1174 case ICMD_IF_ICMPLE:
1175 COUNT(count_pcmd_bra);
1177 tbptr = block + block_index[iptr->op1];
1179 iptr[0].target = (void *) tbptr;
1181 MARKREACHED(tbptr, copy);
1184 case ICMD_IF_ACMPEQ:
1185 case ICMD_IF_ACMPNE:
1186 COUNT(count_pcmd_bra);
1188 tbptr = block + block_index[iptr->op1];
1190 iptr[0].target = (void *) tbptr;
1192 MARKREACHED(tbptr, copy);
1198 COUNT(count_check_null);
1199 COUNT(count_pcmd_mem);
1200 OPTT2_0(iptr->op1,TYPE_ADR);
1205 if (! IS_2_WORD_TYPE(curstack->type)) {
1206 OP1_0ANY; /* second pop */
1209 iptr->opc = ICMD_POP;
1213 /* pop 0 push 1 dup */
1216 COUNT(count_dup_instruction);
1222 if (IS_2_WORD_TYPE(curstack->type)) {
1223 iptr->opc = ICMD_DUP;
1229 NEWSTACK(copy->prev->type, copy->prev->varkind,
1230 copy->prev->varnum);
1231 NEWSTACK(copy->type, copy->varkind,
1238 /* pop 2 push 3 dup */
1246 if (IS_2_WORD_TYPE(curstack->type)) {
1247 iptr->opc = ICMD_DUP_X1;
1255 /* pop 3 push 4 dup */
1259 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1260 iptr->opc = ICMD_DUP_X1;
1270 if (IS_2_WORD_TYPE(curstack->type)) {
1271 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1272 iptr->opc = ICMD_DUP_X1;
1276 iptr->opc = ICMD_DUP_X2;
1282 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1283 iptr->opc = ICMD_DUP2_X1;
1291 /* pop 2 push 2 swap */
1300 #if !SUPPORT_DIVISION
1301 iptr[0].opc = ICMD_BUILTIN2;
1302 iptr[0].op1 = TYPE_INT;
1303 iptr[0].val.a = BUILTIN_idiv;
1304 isleafmethod = false;
1309 #if !SUPPORT_DIVISION
1310 iptr[0].opc = ICMD_BUILTIN2;
1311 iptr[0].op1 = TYPE_INT;
1312 iptr[0].val.a = BUILTIN_irem;
1313 isleafmethod = false;
1316 #if defined(__I386__)
1317 method_uses_edx = true;
1323 #if defined(__I386__)
1324 method_uses_ecx = true;
1332 COUNT(count_pcmd_op);
1337 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1338 iptr[0].opc = ICMD_BUILTIN2;
1339 iptr[0].op1 = TYPE_LNG;
1340 iptr[0].val.a = BUILTIN_ldiv;
1341 isleafmethod = false;
1346 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1347 iptr[0].opc = ICMD_BUILTIN2;
1348 iptr[0].op1 = TYPE_LNG;
1349 iptr[0].val.a = BUILTIN_lrem;
1350 isleafmethod = false;
1355 #if defined(__I386__)
1356 method_uses_edx = true;
1363 /* XXX DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1364 COUNT(count_pcmd_op);
1371 COUNT(count_pcmd_op);
1373 #if defined(__I386__)
1374 method_uses_ecx = true;
1375 method_uses_edx = true;
1384 COUNT(count_pcmd_op);
1393 COUNT(count_pcmd_op);
1398 COUNT(count_pcmd_op);
1399 #if !defined(NOLONG_CONDITIONAL)
1400 if ((len > 0) && (iptr[1].val.i == 0)) {
1401 switch (iptr[1].opc) {
1403 iptr[0].opc = ICMD_IF_LCMPEQ;
1405 iptr[0].op1 = iptr[1].op1;
1408 /* iptr[1].opc = ICMD_NOP; */
1410 tbptr = block + block_index[iptr->op1];
1412 iptr[0].target = (void *) tbptr;
1414 MARKREACHED(tbptr, copy);
1415 COUNT(count_pcmd_bra);
1418 iptr[0].opc = ICMD_IF_LCMPNE;
1419 goto icmd_lcmp_if_tail;
1421 iptr[0].opc = ICMD_IF_LCMPLT;
1422 goto icmd_lcmp_if_tail;
1424 iptr[0].opc = ICMD_IF_LCMPGT;
1425 goto icmd_lcmp_if_tail;
1427 iptr[0].opc = ICMD_IF_LCMPLE;
1428 goto icmd_lcmp_if_tail;
1430 iptr[0].opc = ICMD_IF_LCMPGE;
1431 goto icmd_lcmp_if_tail;
1433 OPTT2_1(TYPE_LNG, TYPE_INT);
1438 OPTT2_1(TYPE_LNG, TYPE_INT);
1442 COUNT(count_pcmd_op);
1443 OPTT2_1(TYPE_FLT, TYPE_INT);
1447 COUNT(count_pcmd_op);
1448 OPTT2_1(TYPE_DBL, TYPE_INT);
1456 case ICMD_INT2SHORT:
1457 COUNT(count_pcmd_op);
1458 OP1_1(TYPE_INT, TYPE_INT);
1461 COUNT(count_pcmd_op);
1462 OP1_1(TYPE_LNG, TYPE_LNG);
1465 COUNT(count_pcmd_op);
1466 OP1_1(TYPE_FLT, TYPE_FLT);
1469 COUNT(count_pcmd_op);
1470 OP1_1(TYPE_DBL, TYPE_DBL);
1474 COUNT(count_pcmd_op);
1475 OP1_1(TYPE_INT, TYPE_LNG);
1476 #if defined(__I386__)
1477 method_uses_edx = true;
1481 COUNT(count_pcmd_op);
1482 OP1_1(TYPE_INT, TYPE_FLT);
1485 COUNT(count_pcmd_op);
1486 OP1_1(TYPE_INT, TYPE_DBL);
1489 COUNT(count_pcmd_op);
1490 OP1_1(TYPE_LNG, TYPE_INT);
1493 COUNT(count_pcmd_op);
1494 OP1_1(TYPE_LNG, TYPE_FLT);
1497 COUNT(count_pcmd_op);
1498 OP1_1(TYPE_LNG, TYPE_DBL);
1501 COUNT(count_pcmd_op);
1502 OP1_1(TYPE_FLT, TYPE_INT);
1505 COUNT(count_pcmd_op);
1506 OP1_1(TYPE_FLT, TYPE_LNG);
1507 #if defined(__I386__)
1508 method_uses_edx = true;
1512 COUNT(count_pcmd_op);
1513 OP1_1(TYPE_FLT, TYPE_DBL);
1516 COUNT(count_pcmd_op);
1517 OP1_1(TYPE_DBL, TYPE_INT);
1520 COUNT(count_pcmd_op);
1521 OP1_1(TYPE_DBL, TYPE_LNG);
1522 #if defined(__I386__)
1523 method_uses_edx = true;
1527 COUNT(count_pcmd_op);
1528 OP1_1(TYPE_DBL, TYPE_FLT);
1531 case ICMD_CHECKCAST:
1532 OP1_1(TYPE_ADR, TYPE_ADR);
1533 #if defined(__I386__)
1534 method_uses_edx = true;
1538 case ICMD_INSTANCEOF:
1539 #if defined(__I386__)
1540 method_uses_edx = true;
1542 case ICMD_ARRAYLENGTH:
1543 OP1_1(TYPE_ADR, TYPE_INT);
1547 case ICMD_ANEWARRAY:
1548 OP1_1(TYPE_INT, TYPE_ADR);
1552 COUNT(count_check_null);
1553 COUNT(count_pcmd_mem);
1554 OP1_1(TYPE_ADR, iptr->op1);
1559 case ICMD_GETSTATIC:
1560 COUNT(count_pcmd_mem);
1570 tbptr = block + block_index[iptr->op1];
1572 iptr[0].target = (void *) tbptr;
1574 /* XXX This is a dirty hack. The typechecker
1575 * needs it because the OP1_0ANY below
1576 * overwrites iptr->dst.
1578 iptr->val.a = (void*) iptr->dst;
1580 tbptr->type=BBTYPE_SBR;
1581 MARKREACHED(tbptr, copy);
1585 /* pop many push any */
1587 case ICMD_INVOKEVIRTUAL:
1588 case ICMD_INVOKESPECIAL:
1589 case ICMD_INVOKEINTERFACE:
1590 case ICMD_INVOKESTATIC:
1591 COUNT(count_pcmd_met);
1593 methodinfo *m = iptr->val.a;
1594 if (m->flags & ACC_STATIC)
1595 {COUNT(count_check_null);}
1597 if (i > arguments_num)
1600 #if defined(__X86_64__)
1608 (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1612 stackargs += (iarg < intreg_argnum) ? 0 : (iarg - intreg_argnum);
1613 stackargs += (farg < fltreg_argnum) ? 0 : (farg - fltreg_argnum);
1618 if (!(copy->flags & SAVEDVAR)) {
1619 copy->varkind = ARGVAR;
1620 if (IS_FLT_DBL_TYPE(copy->type)) {
1621 if (--farg < fltreg_argnum) {
1622 copy->varnum = farg;
1624 copy->varnum = --stackargs + intreg_argnum;
1627 if (--iarg < intreg_argnum) {
1628 copy->varnum = iarg;
1630 copy->varnum = --stackargs + intreg_argnum;
1634 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1642 if (! (copy->flags & SAVEDVAR)) {
1643 copy->varkind = ARGVAR;
1650 copy->flags |= SAVEDVAR;
1655 if (m->returntype != TYPE_VOID) {
1656 OP0_1(m->returntype);
1662 /* XXX DEBUG */ /*dolog("builtin3");*/
1664 if (! (curstack->flags & SAVEDVAR)) {
1665 curstack->varkind = ARGVAR;
1666 curstack->varnum = 2;
1668 if (3 > arguments_num) {
1676 /* XXX DEBUG */ /*dolog("builtin2");*/
1677 if (!(curstack->flags & SAVEDVAR)) {
1678 curstack->varkind = ARGVAR;
1679 curstack->varnum = 1;
1681 if (2 > arguments_num) {
1689 /* XXX DEBUG */ /*dolog("builtin1");*/
1690 if (!(curstack->flags & SAVEDVAR)) {
1691 curstack->varkind = ARGVAR;
1692 curstack->varnum = 0;
1694 if (1 > arguments_num) {
1700 copy->flags |= SAVEDVAR;
1703 if (iptr->op1 != TYPE_VOID)
1707 case ICMD_MULTIANEWARRAY:
1710 if ((i + intreg_argnum) > arguments_num)
1711 arguments_num = i + intreg_argnum;
1714 if (! (copy->flags & SAVEDVAR)) {
1715 copy->varkind = ARGVAR;
1716 copy->varnum = i + intreg_argnum;
1721 copy->flags |= SAVEDVAR;
1729 case ICMD_CLEAR_ARGREN:
1730 for (i = iptr->op1; i<maxlocals; i++)
1732 iptr->opc = opcode = ICMD_NOP;
1736 case ICMD_READONLY_ARG:
1737 case ICMD_READONLY_ARG+1:
1738 case ICMD_READONLY_ARG+2:
1739 case ICMD_READONLY_ARG+3:
1740 case ICMD_READONLY_ARG+4:
1743 if (curstack->varkind == LOCALVAR) {
1744 i = curstack->varnum;
1745 argren[iptr->op1] = i;
1748 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
1754 printf("ICMD %d at %d\n", iptr->opc, (int)(iptr-instr));
1755 panic("Missing ICMD code during stack analysis");
1757 /* XXX DEBUG */ /*dolog("iptr++");*/
1759 } /* while instructions */
1760 bptr->outstack = curstack;
1761 bptr->outdepth = stackdepth;
1765 superblockend = true;
1767 } /* while blocks */
1768 } while (repeat && !deadcode);
1771 if (block_count > count_max_basic_blocks)
1772 count_max_basic_blocks = block_count;
1773 count_basic_blocks += block_count;
1774 if (instr_count > count_max_javainstr)
1775 count_max_javainstr = instr_count;
1776 count_javainstr += instr_count;
1777 if (stack_count > count_upper_bound_new_stack)
1778 count_upper_bound_new_stack = stack_count;
1779 if ((new - stack) > count_max_new_stack)
1780 count_max_new_stack = (new - stack);
1782 b_count = block_count;
1784 while (--b_count >= 0) {
1785 if (bptr->flags > BBREACHED) {
1786 if (bptr->indepth >= 10)
1787 count_block_stack[10]++;
1789 count_block_stack[bptr->indepth]++;
1792 count_block_size_distribution[len]++;
1794 count_block_size_distribution[10]++;
1796 count_block_size_distribution[11]++;
1798 count_block_size_distribution[12]++;
1800 count_block_size_distribution[13]++;
1802 count_block_size_distribution[14]++;
1804 count_block_size_distribution[15]++;
1806 count_block_size_distribution[16]++;
1808 count_block_size_distribution[17]++;
1814 count_analyse_iterations[0]++;
1815 else if (loops == 2)
1816 count_analyse_iterations[1]++;
1817 else if (loops == 3)
1818 count_analyse_iterations[2]++;
1819 else if (loops == 4)
1820 count_analyse_iterations[3]++;
1822 count_analyse_iterations[4]++;
1824 if (block_count <= 5)
1825 count_method_bb_distribution[0]++;
1826 else if (block_count <= 10)
1827 count_method_bb_distribution[1]++;
1828 else if (block_count <= 15)
1829 count_method_bb_distribution[2]++;
1830 else if (block_count <= 20)
1831 count_method_bb_distribution[3]++;
1832 else if (block_count <= 30)
1833 count_method_bb_distribution[4]++;
1834 else if (block_count <= 40)
1835 count_method_bb_distribution[5]++;
1836 else if (block_count <= 50)
1837 count_method_bb_distribution[6]++;
1838 else if (block_count <= 75)
1839 count_method_bb_distribution[7]++;
1841 count_method_bb_distribution[8]++;
1846 void icmd_print_stack(stackptr s)
1863 /* XXX remove */ /* printf("(%d)",s->flags); fflush(stdout); */
1864 if (s->flags & SAVEDVAR)
1865 switch (s->varkind) {
1867 if (s->flags & INMEMORY)
1868 printf((regs_ok) ? " M%02d" : " M??", s->regoff);
1869 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1870 printf((regs_ok) ? " F%02d" : " F??", s->regoff);
1872 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1876 printf(" I%02d", s->varnum);
1879 printf(" L%02d", s->varnum);
1882 printf(" A%02d", s->varnum);
1885 printf(" !%02d", j);
1888 switch (s->varkind) {
1890 if (s->flags & INMEMORY)
1891 printf((regs_ok) ? " m%02d" : " m??", s->regoff);
1892 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1893 printf((regs_ok) ? " f%02d" : " f??", s->regoff);
1895 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1899 printf(" i%02d", s->varnum);
1902 printf(" l%02d", s->varnum);
1905 printf(" a%02d", s->varnum);
1908 printf(" ?%02d", j);
1916 static void print_reg(stackptr s) {
1918 if (s->flags & SAVEDVAR)
1919 switch (s->varkind) {
1921 if (s->flags & INMEMORY)
1922 printf(" tm%02d", s->regoff);
1924 printf(" tr%02d", s->regoff);
1927 printf(" s %02d", s->varnum);
1930 printf(" l %02d", s->varnum);
1933 printf(" a %02d", s->varnum);
1936 printf(" ! %02d", s->varnum);
1939 switch (s->varkind) {
1941 if (s->flags & INMEMORY)
1942 printf(" Tm%02d", s->regoff);
1944 printf(" Tr%02d", s->regoff);
1947 printf(" S %02d", s->varnum);
1950 printf(" L %02d", s->varnum);
1953 printf(" A %02d", s->varnum);
1956 printf(" ? %02d", s->varnum);
1966 char *icmd_builtin_name(functionptr bptr)
1968 builtin_descriptor *bdesc = builtin_desc;
1969 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
1971 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
1975 static char *jit_type[] = {
1984 void show_icmd_method()
1995 utf_fprint(stdout, class->name);
1997 utf_fprint(stdout, method->name);
1999 utf_fprint(stdout, method->descriptor);
2000 printf ("\n\nMax locals: %d\n", (int) maxlocals);
2001 printf ("Max stack: %d\n", (int) maxstack);
2003 printf ("Exceptions (Number: %d):\n", exceptiontablelength);
2004 for (ex = extable; ex != NULL; ex = ex->down) {
2005 printf(" L%03d ... ", ex->start->debug_nr );
2006 printf("L%03d = ", ex->end->debug_nr);
2007 printf("L%03d\n", ex->handler->debug_nr);
2010 printf ("Local Table:\n");
2011 for (i = 0; i < maxlocals; i++) {
2012 printf(" %3d: ", i);
2013 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2014 if (locals[i][j].type >= 0) {
2015 printf(" (%s) ", jit_type[j]);
2016 if (locals[i][j].flags & INMEMORY)
2017 printf((regs_ok) ? "m%2d" : "m??", locals[i][j].regoff);
2018 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2019 printf((regs_ok) ? "f%02d" : "f??", locals[i][j].regoff);
2021 if (regs_ok) printf("%3s",regs[locals[i][j].regoff]); else printf("???");
2028 printf ("Interface Table:\n");
2029 for (i = 0; i < maxstack; i++) {
2030 if ((interfaces[i][0].type >= 0) || (interfaces[i][1].type >= 0) ||
2031 (interfaces[i][2].type >= 0) || (interfaces[i][3].type >= 0) ||
2032 (interfaces[i][4].type >= 0)) {
2033 printf(" %3d: ", i);
2034 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2035 if (interfaces[i][j].type >= 0) {
2036 printf(" (%s) ", jit_type[j]);
2037 if (interfaces[i][j].flags & SAVEDVAR) {
2038 if (interfaces[i][j].flags & INMEMORY)
2039 printf((regs_ok) ? "M%2d" : "M??", interfaces[i][j].regoff);
2040 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2041 printf((regs_ok) ? "F%02d" : "F??", interfaces[i][j].regoff);
2043 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2047 if (interfaces[i][j].flags & INMEMORY)
2048 printf((regs_ok) ? "m%2d" : "m??", interfaces[i][j].regoff);
2049 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2050 printf((regs_ok) ? "f%02d" : "f??", interfaces[i][j].regoff);
2052 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2061 if (showdisassemble) {
2062 #if defined(__I386__) || defined(__X86_64__)
2066 u1ptr = method->mcode + dseglen;
2067 for (i = 0; i < block[0].mpc; i++, u1ptr++) {
2068 a = disassinstr(u1ptr, i);
2074 s4ptr = (s4 *) (method->mcode + dseglen);
2075 for (i = 0; i < block[0].mpc; i += 4, s4ptr++) {
2076 disassinstr(*s4ptr, i);
2083 for (bptr = block; bptr != NULL; bptr = bptr->next) {
2084 show_icmd_block(bptr);
2089 void show_icmd_block(basicblock *bptr)
2096 if (bptr->flags != BBDELETED) {
2097 deadcode = bptr->flags <= BBREACHED;
2100 for (j = method->maxstack; j > 0; j--)
2103 icmd_print_stack(bptr->instack);
2104 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2105 iptr = bptr->iinstr;
2107 for (i=0; i < bptr->icount; i++, iptr++) {
2110 for (j = method->maxstack; j > 0; j--)
2114 icmd_print_stack(iptr->dst);
2115 printf("] %4d ", i);
2116 /* XXX remove */ /*fflush(stdout);*/
2117 show_icmd(iptr,deadcode);
2121 if (showdisassemble && (!deadcode)) {
2122 #if defined(__I386__) || defined(__X86_64__)
2128 u1ptr = method->mcode + dseglen + i;
2130 if (bptr->next != NULL) {
2131 for (; i < bptr->next->mpc; i++, u1ptr++) {
2132 a = disassinstr(u1ptr, i);
2139 for (; u1ptr < (u1 *) (method->mcode + method->mcodelength); i++, u1ptr++) {
2140 a = disassinstr(u1ptr, i);
2149 s4ptr = (s4 *) (method->mcode + dseglen + i);
2151 if (bptr->next != NULL) {
2152 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2153 disassinstr(*s4ptr, i);
2158 for (; s4ptr < (s4 *) (method->mcode + method->mcodelength); i += 4, s4ptr++) {
2159 disassinstr(*s4ptr, i);
2169 void show_icmd(instruction *iptr,bool deadcode)
2175 printf("%s", icmd_names[iptr->opc]);
2177 switch ((int) iptr->opc) {
2178 case ICMD_IADDCONST:
2179 case ICMD_ISUBCONST:
2180 case ICMD_IMULCONST:
2183 case ICMD_IREM0X10001:
2184 case ICMD_IANDCONST:
2186 case ICMD_IXORCONST:
2187 case ICMD_ISHLCONST:
2188 case ICMD_ISHRCONST:
2189 case ICMD_IUSHRCONST:
2190 case ICMD_LSHLCONST:
2191 case ICMD_LSHRCONST:
2192 case ICMD_LUSHRCONST:
2194 case ICMD_ELSE_ICONST:
2195 case ICMD_IFEQ_ICONST:
2196 case ICMD_IFNE_ICONST:
2197 case ICMD_IFLT_ICONST:
2198 case ICMD_IFGE_ICONST:
2199 case ICMD_IFGT_ICONST:
2200 case ICMD_IFLE_ICONST:
2201 printf(" %d", iptr->val.i);
2204 case ICMD_LADDCONST:
2205 case ICMD_LSUBCONST:
2206 case ICMD_LMULCONST:
2209 case ICMD_LANDCONST:
2211 case ICMD_LXORCONST:
2213 #if defined(__I386__)
2214 printf(" %lld", iptr->val.l);
2216 printf(" %ld", iptr->val.l);
2221 printf(" %f", iptr->val.f);
2225 printf(" %f", iptr->val.d);
2229 printf(" %p", iptr->val.a);
2234 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2235 case ICMD_PUTSTATIC:
2236 case ICMD_GETSTATIC:
2239 ((fieldinfo *) iptr->val.a)->class->name);
2242 ((fieldinfo *) iptr->val.a)->name);
2245 ((fieldinfo *) iptr->val.a)->descriptor);
2250 printf(" %d + %d", iptr->op1, iptr->val.i);
2285 printf(" %d", iptr->op1);
2291 ((classinfo *) iptr->val.a)->name);
2295 switch (iptr->op1) {
2323 case ICMD_ANEWARRAY:
2327 ((classinfo *) iptr->val.a)->name);
2331 case ICMD_MULTIANEWARRAY:
2334 printf(" %d ",iptr->op1);
2335 vft = (vftbl *)iptr->val.a;
2337 utf_fprint(stdout,vft->class->name);
2343 case ICMD_CHECKCAST:
2344 case ICMD_INSTANCEOF:
2346 classinfo *c = iptr->val.a;
2347 if (c->flags & ACC_INTERFACE)
2348 printf(" (INTERFACE) ");
2350 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2351 utf_fprint(stdout, c->name);
2358 printf(" %s", icmd_builtin_name((functionptr) iptr->val.a));
2361 case ICMD_INVOKEVIRTUAL:
2362 case ICMD_INVOKESPECIAL:
2363 case ICMD_INVOKESTATIC:
2364 case ICMD_INVOKEINTERFACE:
2367 ((methodinfo *) iptr->val.a)->class->name);
2370 ((methodinfo *) iptr->val.a)->name);
2379 if (deadcode || !iptr->target)
2380 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2382 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2391 if (deadcode || !iptr->target)
2392 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2394 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2400 case ICMD_IFNONNULL:
2401 case ICMD_IF_ICMPEQ:
2402 case ICMD_IF_ICMPNE:
2403 case ICMD_IF_ICMPLT:
2404 case ICMD_IF_ICMPGE:
2405 case ICMD_IF_ICMPGT:
2406 case ICMD_IF_ICMPLE:
2407 case ICMD_IF_LCMPEQ:
2408 case ICMD_IF_LCMPNE:
2409 case ICMD_IF_LCMPLT:
2410 case ICMD_IF_LCMPGE:
2411 case ICMD_IF_LCMPGT:
2412 case ICMD_IF_LCMPLE:
2413 case ICMD_IF_ACMPEQ:
2414 case ICMD_IF_ACMPNE:
2415 if (deadcode || !iptr->target)
2416 printf(" op1=%d", iptr->op1);
2418 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2421 case ICMD_TABLESWITCH:
2424 if (deadcode || !iptr->target) {
2425 printf(" %d;", *s4ptr);
2428 tptr = (void **) iptr->target;
2429 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2433 s4ptr++; /* skip default */
2434 j = *s4ptr++; /* low */
2435 j = *s4ptr++ - j; /* high */
2437 if (deadcode || !*tptr)
2438 printf(" %d", *s4ptr++);
2440 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2447 case ICMD_LOOKUPSWITCH:
2448 s4ptr = iptr->val.a;
2450 if (deadcode || !iptr->target) {
2451 printf(" %d;", *s4ptr);
2454 tptr = (void **) iptr->target;
2455 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2458 s4ptr++; /* default */
2459 j = *s4ptr++; /* count */
2462 if (deadcode || !*tptr) {
2463 s4ptr++; /* skip value */
2464 printf(" %d",*s4ptr++);
2467 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2477 * These are local overrides for various environment variables in Emacs.
2478 * Please do not remove this and leave it at the end of the file, where
2479 * Emacs will automagically detect them.
2480 * ---------------------------------------------------------------------
2483 * indent-tabs-mode: t