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 787 2003-12-15 18:20:31Z edwin $
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;
1292 /* pop 2 push 2 swap */
1301 #if !SUPPORT_DIVISION
1302 iptr[0].opc = ICMD_BUILTIN2;
1303 iptr[0].op1 = TYPE_INT;
1304 iptr[0].val.a = BUILTIN_idiv;
1305 isleafmethod = false;
1310 #if !SUPPORT_DIVISION
1311 iptr[0].opc = ICMD_BUILTIN2;
1312 iptr[0].op1 = TYPE_INT;
1313 iptr[0].val.a = BUILTIN_irem;
1314 isleafmethod = false;
1317 #if defined(__I386__)
1318 method_uses_edx = true;
1324 #if defined(__I386__)
1325 method_uses_ecx = true;
1333 COUNT(count_pcmd_op);
1338 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1339 iptr[0].opc = ICMD_BUILTIN2;
1340 iptr[0].op1 = TYPE_LNG;
1341 iptr[0].val.a = BUILTIN_ldiv;
1342 isleafmethod = false;
1347 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1348 iptr[0].opc = ICMD_BUILTIN2;
1349 iptr[0].op1 = TYPE_LNG;
1350 iptr[0].val.a = BUILTIN_lrem;
1351 isleafmethod = false;
1356 #if defined(__I386__)
1357 method_uses_edx = true;
1364 /* XXX DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1365 COUNT(count_pcmd_op);
1372 COUNT(count_pcmd_op);
1374 #if defined(__I386__)
1375 method_uses_ecx = true;
1376 method_uses_edx = true;
1385 COUNT(count_pcmd_op);
1394 COUNT(count_pcmd_op);
1399 COUNT(count_pcmd_op);
1400 #if !defined(NOLONG_CONDITIONAL)
1401 if ((len > 0) && (iptr[1].val.i == 0)) {
1402 switch (iptr[1].opc) {
1404 iptr[0].opc = ICMD_IF_LCMPEQ;
1406 iptr[0].op1 = iptr[1].op1;
1409 /* iptr[1].opc = ICMD_NOP; */
1411 tbptr = block + block_index[iptr->op1];
1413 iptr[0].target = (void *) tbptr;
1415 MARKREACHED(tbptr, copy);
1416 COUNT(count_pcmd_bra);
1419 iptr[0].opc = ICMD_IF_LCMPNE;
1420 goto icmd_lcmp_if_tail;
1422 iptr[0].opc = ICMD_IF_LCMPLT;
1423 goto icmd_lcmp_if_tail;
1425 iptr[0].opc = ICMD_IF_LCMPGT;
1426 goto icmd_lcmp_if_tail;
1428 iptr[0].opc = ICMD_IF_LCMPLE;
1429 goto icmd_lcmp_if_tail;
1431 iptr[0].opc = ICMD_IF_LCMPGE;
1432 goto icmd_lcmp_if_tail;
1434 OPTT2_1(TYPE_LNG, TYPE_INT);
1439 OPTT2_1(TYPE_LNG, TYPE_INT);
1443 COUNT(count_pcmd_op);
1444 OPTT2_1(TYPE_FLT, TYPE_INT);
1448 COUNT(count_pcmd_op);
1449 OPTT2_1(TYPE_DBL, TYPE_INT);
1457 case ICMD_INT2SHORT:
1458 COUNT(count_pcmd_op);
1459 OP1_1(TYPE_INT, TYPE_INT);
1462 COUNT(count_pcmd_op);
1463 OP1_1(TYPE_LNG, TYPE_LNG);
1466 COUNT(count_pcmd_op);
1467 OP1_1(TYPE_FLT, TYPE_FLT);
1470 COUNT(count_pcmd_op);
1471 OP1_1(TYPE_DBL, TYPE_DBL);
1475 COUNT(count_pcmd_op);
1476 OP1_1(TYPE_INT, TYPE_LNG);
1477 #if defined(__I386__)
1478 method_uses_edx = true;
1482 COUNT(count_pcmd_op);
1483 OP1_1(TYPE_INT, TYPE_FLT);
1486 COUNT(count_pcmd_op);
1487 OP1_1(TYPE_INT, TYPE_DBL);
1490 COUNT(count_pcmd_op);
1491 OP1_1(TYPE_LNG, TYPE_INT);
1494 COUNT(count_pcmd_op);
1495 OP1_1(TYPE_LNG, TYPE_FLT);
1498 COUNT(count_pcmd_op);
1499 OP1_1(TYPE_LNG, TYPE_DBL);
1502 COUNT(count_pcmd_op);
1503 OP1_1(TYPE_FLT, TYPE_INT);
1506 COUNT(count_pcmd_op);
1507 OP1_1(TYPE_FLT, TYPE_LNG);
1508 #if defined(__I386__)
1509 method_uses_edx = true;
1513 COUNT(count_pcmd_op);
1514 OP1_1(TYPE_FLT, TYPE_DBL);
1517 COUNT(count_pcmd_op);
1518 OP1_1(TYPE_DBL, TYPE_INT);
1521 COUNT(count_pcmd_op);
1522 OP1_1(TYPE_DBL, TYPE_LNG);
1523 #if defined(__I386__)
1524 method_uses_edx = true;
1528 COUNT(count_pcmd_op);
1529 OP1_1(TYPE_DBL, TYPE_FLT);
1532 case ICMD_CHECKCAST:
1533 OP1_1(TYPE_ADR, TYPE_ADR);
1534 #if defined(__I386__)
1535 method_uses_edx = true;
1539 case ICMD_INSTANCEOF:
1540 #if defined(__I386__)
1541 method_uses_edx = true;
1543 case ICMD_ARRAYLENGTH:
1544 OP1_1(TYPE_ADR, TYPE_INT);
1548 case ICMD_ANEWARRAY:
1549 OP1_1(TYPE_INT, TYPE_ADR);
1553 COUNT(count_check_null);
1554 COUNT(count_pcmd_mem);
1555 OP1_1(TYPE_ADR, iptr->op1);
1560 case ICMD_GETSTATIC:
1561 COUNT(count_pcmd_mem);
1571 tbptr = block + block_index[iptr->op1];
1573 iptr[0].target = (void *) tbptr;
1575 /* XXX This is a dirty hack. The typechecker
1576 * needs it because the OP1_0ANY below
1577 * overwrites iptr->dst.
1579 iptr->val.a = (void*) iptr->dst;
1581 tbptr->type=BBTYPE_SBR;
1582 MARKREACHED(tbptr, copy);
1586 /* pop many push any */
1588 case ICMD_INVOKEVIRTUAL:
1589 case ICMD_INVOKESPECIAL:
1590 case ICMD_INVOKEINTERFACE:
1591 case ICMD_INVOKESTATIC:
1592 COUNT(count_pcmd_met);
1594 methodinfo *m = iptr->val.a;
1595 if (m->flags & ACC_STATIC)
1596 {COUNT(count_check_null);}
1598 if (i > arguments_num)
1601 #if defined(__X86_64__)
1609 (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1613 stackargs += (iarg < intreg_argnum) ? 0 : (iarg - intreg_argnum);
1614 stackargs += (farg < fltreg_argnum) ? 0 : (farg - fltreg_argnum);
1619 if (!(copy->flags & SAVEDVAR)) {
1620 copy->varkind = ARGVAR;
1621 if (IS_FLT_DBL_TYPE(copy->type)) {
1622 if (--farg < fltreg_argnum) {
1623 copy->varnum = farg;
1625 copy->varnum = --stackargs + intreg_argnum;
1628 if (--iarg < intreg_argnum) {
1629 copy->varnum = iarg;
1631 copy->varnum = --stackargs + intreg_argnum;
1635 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1643 if (! (copy->flags & SAVEDVAR)) {
1644 copy->varkind = ARGVAR;
1651 copy->flags |= SAVEDVAR;
1656 if (m->returntype != TYPE_VOID) {
1657 OP0_1(m->returntype);
1663 /* XXX DEBUG */ /*dolog("builtin3");*/
1665 if (! (curstack->flags & SAVEDVAR)) {
1666 curstack->varkind = ARGVAR;
1667 curstack->varnum = 2;
1669 if (3 > arguments_num) {
1677 /* XXX DEBUG */ /*dolog("builtin2");*/
1678 if (!(curstack->flags & SAVEDVAR)) {
1679 curstack->varkind = ARGVAR;
1680 curstack->varnum = 1;
1682 if (2 > arguments_num) {
1690 /* XXX DEBUG */ /*dolog("builtin1");*/
1691 if (!(curstack->flags & SAVEDVAR)) {
1692 curstack->varkind = ARGVAR;
1693 curstack->varnum = 0;
1695 if (1 > arguments_num) {
1701 copy->flags |= SAVEDVAR;
1704 if (iptr->op1 != TYPE_VOID)
1708 case ICMD_MULTIANEWARRAY:
1711 if ((i + intreg_argnum) > arguments_num)
1712 arguments_num = i + intreg_argnum;
1715 if (! (copy->flags & SAVEDVAR)) {
1716 copy->varkind = ARGVAR;
1717 copy->varnum = i + intreg_argnum;
1722 copy->flags |= SAVEDVAR;
1730 case ICMD_CLEAR_ARGREN:
1731 for (i = iptr->op1; i<maxlocals; i++)
1733 iptr->opc = opcode = ICMD_NOP;
1737 case ICMD_READONLY_ARG:
1738 case ICMD_READONLY_ARG+1:
1739 case ICMD_READONLY_ARG+2:
1740 case ICMD_READONLY_ARG+3:
1741 case ICMD_READONLY_ARG+4:
1744 if (curstack->varkind == LOCALVAR) {
1745 i = curstack->varnum;
1746 argren[iptr->op1] = i;
1749 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
1755 printf("ICMD %d at %d\n", iptr->opc, (int)(iptr-instr));
1756 panic("Missing ICMD code during stack analysis");
1758 /* XXX DEBUG */ /*dolog("iptr++");*/
1760 } /* while instructions */
1761 bptr->outstack = curstack;
1762 bptr->outdepth = stackdepth;
1766 superblockend = true;
1768 } /* while blocks */
1769 } while (repeat && !deadcode);
1772 if (block_count > count_max_basic_blocks)
1773 count_max_basic_blocks = block_count;
1774 count_basic_blocks += block_count;
1775 if (instr_count > count_max_javainstr)
1776 count_max_javainstr = instr_count;
1777 count_javainstr += instr_count;
1778 if (stack_count > count_upper_bound_new_stack)
1779 count_upper_bound_new_stack = stack_count;
1780 if ((new - stack) > count_max_new_stack)
1781 count_max_new_stack = (new - stack);
1783 b_count = block_count;
1785 while (--b_count >= 0) {
1786 if (bptr->flags > BBREACHED) {
1787 if (bptr->indepth >= 10)
1788 count_block_stack[10]++;
1790 count_block_stack[bptr->indepth]++;
1793 count_block_size_distribution[len]++;
1795 count_block_size_distribution[10]++;
1797 count_block_size_distribution[11]++;
1799 count_block_size_distribution[12]++;
1801 count_block_size_distribution[13]++;
1803 count_block_size_distribution[14]++;
1805 count_block_size_distribution[15]++;
1807 count_block_size_distribution[16]++;
1809 count_block_size_distribution[17]++;
1815 count_analyse_iterations[0]++;
1816 else if (loops == 2)
1817 count_analyse_iterations[1]++;
1818 else if (loops == 3)
1819 count_analyse_iterations[2]++;
1820 else if (loops == 4)
1821 count_analyse_iterations[3]++;
1823 count_analyse_iterations[4]++;
1825 if (block_count <= 5)
1826 count_method_bb_distribution[0]++;
1827 else if (block_count <= 10)
1828 count_method_bb_distribution[1]++;
1829 else if (block_count <= 15)
1830 count_method_bb_distribution[2]++;
1831 else if (block_count <= 20)
1832 count_method_bb_distribution[3]++;
1833 else if (block_count <= 30)
1834 count_method_bb_distribution[4]++;
1835 else if (block_count <= 40)
1836 count_method_bb_distribution[5]++;
1837 else if (block_count <= 50)
1838 count_method_bb_distribution[6]++;
1839 else if (block_count <= 75)
1840 count_method_bb_distribution[7]++;
1842 count_method_bb_distribution[8]++;
1847 void icmd_print_stack(stackptr s)
1864 /* XXX remove */ /* printf("(%d)",s->flags); fflush(stdout); */
1865 if (s->flags & SAVEDVAR)
1866 switch (s->varkind) {
1868 if (s->flags & INMEMORY)
1869 printf((regs_ok) ? " M%02d" : " M??", s->regoff);
1870 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1871 printf((regs_ok) ? " F%02d" : " F??", s->regoff);
1873 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1877 printf(" I%02d", s->varnum);
1880 printf(" L%02d", s->varnum);
1883 printf(" A%02d", s->varnum);
1886 printf(" !%02d", j);
1889 switch (s->varkind) {
1891 if (s->flags & INMEMORY)
1892 printf((regs_ok) ? " m%02d" : " m??", s->regoff);
1893 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
1894 printf((regs_ok) ? " f%02d" : " f??", s->regoff);
1896 if (regs_ok) printf(" %3s",regs[s->regoff]); else printf(" ???");
1900 printf(" i%02d", s->varnum);
1903 printf(" l%02d", s->varnum);
1906 printf(" a%02d", s->varnum);
1909 printf(" ?%02d", j);
1917 static void print_reg(stackptr s) {
1919 if (s->flags & SAVEDVAR)
1920 switch (s->varkind) {
1922 if (s->flags & INMEMORY)
1923 printf(" tm%02d", s->regoff);
1925 printf(" tr%02d", s->regoff);
1928 printf(" s %02d", s->varnum);
1931 printf(" l %02d", s->varnum);
1934 printf(" a %02d", s->varnum);
1937 printf(" ! %02d", s->varnum);
1940 switch (s->varkind) {
1942 if (s->flags & INMEMORY)
1943 printf(" Tm%02d", s->regoff);
1945 printf(" Tr%02d", s->regoff);
1948 printf(" S %02d", s->varnum);
1951 printf(" L %02d", s->varnum);
1954 printf(" A %02d", s->varnum);
1957 printf(" ? %02d", s->varnum);
1967 char *icmd_builtin_name(functionptr bptr)
1969 builtin_descriptor *bdesc = builtin_desc;
1970 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
1972 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
1976 static char *jit_type[] = {
1985 void show_icmd_method()
1996 utf_fprint(stdout, class->name);
1998 utf_fprint(stdout, method->name);
2000 utf_fprint(stdout, method->descriptor);
2001 printf ("\n\nMax locals: %d\n", (int) maxlocals);
2002 printf ("Max stack: %d\n", (int) maxstack);
2004 printf ("Exceptions (Number: %d):\n", exceptiontablelength);
2005 for (ex = extable; ex != NULL; ex = ex->down) {
2006 printf(" L%03d ... ", ex->start->debug_nr );
2007 printf("L%03d = ", ex->end->debug_nr);
2008 printf("L%03d\n", ex->handler->debug_nr);
2011 printf ("Local Table:\n");
2012 for (i = 0; i < maxlocals; i++) {
2013 printf(" %3d: ", i);
2014 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2015 if (locals[i][j].type >= 0) {
2016 printf(" (%s) ", jit_type[j]);
2017 if (locals[i][j].flags & INMEMORY)
2018 printf((regs_ok) ? "m%2d" : "m??", locals[i][j].regoff);
2019 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2020 printf((regs_ok) ? "f%02d" : "f??", locals[i][j].regoff);
2022 if (regs_ok) printf("%3s",regs[locals[i][j].regoff]); else printf("???");
2029 printf ("Interface Table:\n");
2030 for (i = 0; i < maxstack; i++) {
2031 if ((interfaces[i][0].type >= 0) || (interfaces[i][1].type >= 0) ||
2032 (interfaces[i][2].type >= 0) || (interfaces[i][3].type >= 0) ||
2033 (interfaces[i][4].type >= 0)) {
2034 printf(" %3d: ", i);
2035 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2036 if (interfaces[i][j].type >= 0) {
2037 printf(" (%s) ", jit_type[j]);
2038 if (interfaces[i][j].flags & SAVEDVAR) {
2039 if (interfaces[i][j].flags & INMEMORY)
2040 printf((regs_ok) ? "M%2d" : "M??", interfaces[i][j].regoff);
2041 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2042 printf((regs_ok) ? "F%02d" : "F??", interfaces[i][j].regoff);
2044 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2048 if (interfaces[i][j].flags & INMEMORY)
2049 printf((regs_ok) ? "m%2d" : "m??", interfaces[i][j].regoff);
2050 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2051 printf((regs_ok) ? "f%02d" : "f??", interfaces[i][j].regoff);
2053 if (regs_ok) printf("%3s",regs[interfaces[i][j].regoff]); else printf("???");
2062 if (showdisassemble) {
2063 #if defined(__I386__) || defined(__X86_64__)
2067 u1ptr = method->mcode + dseglen;
2068 for (i = 0; i < block[0].mpc; i++, u1ptr++) {
2069 a = disassinstr(u1ptr, i);
2075 s4ptr = (s4 *) (method->mcode + dseglen);
2076 for (i = 0; i < block[0].mpc; i += 4, s4ptr++) {
2077 disassinstr(*s4ptr, i);
2084 for (bptr = block; bptr != NULL; bptr = bptr->next) {
2085 show_icmd_block(bptr);
2090 void show_icmd_block(basicblock *bptr)
2097 if (bptr->flags != BBDELETED) {
2098 deadcode = bptr->flags <= BBREACHED;
2101 for (j = method->maxstack; j > 0; j--)
2104 icmd_print_stack(bptr->instack);
2105 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2106 iptr = bptr->iinstr;
2108 for (i=0; i < bptr->icount; i++, iptr++) {
2111 for (j = method->maxstack; j > 0; j--)
2115 icmd_print_stack(iptr->dst);
2116 printf("] %4d ", i);
2117 /* XXX remove */ /*fflush(stdout);*/
2118 show_icmd(iptr,deadcode);
2122 if (showdisassemble && (!deadcode)) {
2123 #if defined(__I386__) || defined(__X86_64__)
2129 u1ptr = method->mcode + dseglen + i;
2131 if (bptr->next != NULL) {
2132 for (; i < bptr->next->mpc; i++, u1ptr++) {
2133 a = disassinstr(u1ptr, i);
2140 for (; u1ptr < (u1 *) (method->mcode + method->mcodelength); i++, u1ptr++) {
2141 a = disassinstr(u1ptr, i);
2150 s4ptr = (s4 *) (method->mcode + dseglen + i);
2152 if (bptr->next != NULL) {
2153 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2154 disassinstr(*s4ptr, i);
2159 for (; s4ptr < (s4 *) (method->mcode + method->mcodelength); i += 4, s4ptr++) {
2160 disassinstr(*s4ptr, i);
2170 void show_icmd(instruction *iptr,bool deadcode)
2176 printf("%s", icmd_names[iptr->opc]);
2178 switch ((int) iptr->opc) {
2179 case ICMD_IADDCONST:
2180 case ICMD_ISUBCONST:
2181 case ICMD_IMULCONST:
2184 case ICMD_IREM0X10001:
2185 case ICMD_IANDCONST:
2187 case ICMD_IXORCONST:
2188 case ICMD_ISHLCONST:
2189 case ICMD_ISHRCONST:
2190 case ICMD_IUSHRCONST:
2191 case ICMD_LSHLCONST:
2192 case ICMD_LSHRCONST:
2193 case ICMD_LUSHRCONST:
2195 case ICMD_ELSE_ICONST:
2196 case ICMD_IFEQ_ICONST:
2197 case ICMD_IFNE_ICONST:
2198 case ICMD_IFLT_ICONST:
2199 case ICMD_IFGE_ICONST:
2200 case ICMD_IFGT_ICONST:
2201 case ICMD_IFLE_ICONST:
2202 printf(" %d", iptr->val.i);
2205 case ICMD_LADDCONST:
2206 case ICMD_LSUBCONST:
2207 case ICMD_LMULCONST:
2210 case ICMD_LANDCONST:
2212 case ICMD_LXORCONST:
2214 #if defined(__I386__)
2215 printf(" %lld", iptr->val.l);
2217 printf(" %ld", iptr->val.l);
2222 printf(" %f", iptr->val.f);
2226 printf(" %f", iptr->val.d);
2230 printf(" %p", iptr->val.a);
2235 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2236 case ICMD_PUTSTATIC:
2237 case ICMD_GETSTATIC:
2240 ((fieldinfo *) iptr->val.a)->class->name);
2243 ((fieldinfo *) iptr->val.a)->name);
2246 ((fieldinfo *) iptr->val.a)->descriptor);
2251 printf(" %d + %d", iptr->op1, iptr->val.i);
2286 printf(" %d", iptr->op1);
2292 ((classinfo *) iptr->val.a)->name);
2296 switch (iptr->op1) {
2324 case ICMD_ANEWARRAY:
2328 ((classinfo *) iptr->val.a)->name);
2332 case ICMD_MULTIANEWARRAY:
2335 printf(" %d ",iptr->op1);
2336 vft = (vftbl *)iptr->val.a;
2338 utf_fprint(stdout,vft->class->name);
2344 case ICMD_CHECKCAST:
2345 case ICMD_INSTANCEOF:
2347 classinfo *c = iptr->val.a;
2348 if (c->flags & ACC_INTERFACE)
2349 printf(" (INTERFACE) ");
2351 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2352 utf_fprint(stdout, c->name);
2359 printf(" %s", icmd_builtin_name((functionptr) iptr->val.a));
2362 case ICMD_INVOKEVIRTUAL:
2363 case ICMD_INVOKESPECIAL:
2364 case ICMD_INVOKESTATIC:
2365 case ICMD_INVOKEINTERFACE:
2368 ((methodinfo *) iptr->val.a)->class->name);
2371 ((methodinfo *) iptr->val.a)->name);
2380 if (deadcode || !iptr->target)
2381 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2383 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2392 if (deadcode || !iptr->target)
2393 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2395 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2401 case ICMD_IFNONNULL:
2402 case ICMD_IF_ICMPEQ:
2403 case ICMD_IF_ICMPNE:
2404 case ICMD_IF_ICMPLT:
2405 case ICMD_IF_ICMPGE:
2406 case ICMD_IF_ICMPGT:
2407 case ICMD_IF_ICMPLE:
2408 case ICMD_IF_LCMPEQ:
2409 case ICMD_IF_LCMPNE:
2410 case ICMD_IF_LCMPLT:
2411 case ICMD_IF_LCMPGE:
2412 case ICMD_IF_LCMPGT:
2413 case ICMD_IF_LCMPLE:
2414 case ICMD_IF_ACMPEQ:
2415 case ICMD_IF_ACMPNE:
2416 if (deadcode || !iptr->target)
2417 printf(" op1=%d", iptr->op1);
2419 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2422 case ICMD_TABLESWITCH:
2423 s4ptr = (s4*)iptr->val.a;
2425 if (deadcode || !iptr->target) {
2426 printf(" %d;", *s4ptr);
2429 tptr = (void **) iptr->target;
2430 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2434 s4ptr++; /* skip default */
2435 j = *s4ptr++; /* low */
2436 j = *s4ptr++ - j; /* high */
2438 if (deadcode || !*tptr)
2439 printf(" %d", *s4ptr++);
2441 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2448 case ICMD_LOOKUPSWITCH:
2449 s4ptr = (s4*)iptr->val.a;
2451 if (deadcode || !iptr->target) {
2452 printf(" %d;", *s4ptr);
2455 tptr = (void **) iptr->target;
2456 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2459 s4ptr++; /* default */
2460 j = *s4ptr++; /* count */
2463 if (deadcode || !*tptr) {
2464 s4ptr++; /* skip value */
2465 printf(" %d",*s4ptr++);
2468 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2478 * These are local overrides for various environment variables in Emacs.
2479 * Please do not remove this and leave it at the end of the file, where
2480 * Emacs will automagically detect them.
2481 * ---------------------------------------------------------------------
2484 * indent-tabs-mode: t