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 1318 2004-07-16 13:30:51Z twisti $
45 #include "statistics.h"
47 #include "jit/stack.h"
49 #include "toolbox/logging.h"
50 #include "toolbox/memory.h"
53 /* from codegen.inc */
56 /**********************************************************************/
57 /* Macros used internally by analyse_stack */
58 /**********************************************************************/
61 #define COUNT(cnt) cnt++
66 /* convenient abbreviations */
67 #define CURKIND curstack->varkind
68 #define CURTYPE curstack->type
70 /*--------------------------------------------------*/
71 /* SIGNALING ERRORS */
72 /*--------------------------------------------------*/
74 #define TYPEPANIC {panic("Stack type mismatch");}
77 /*--------------------------------------------------*/
78 /* STACK UNDERFLOW/OVERFLOW CHECKS */
79 /*--------------------------------------------------*/
81 /* underflow checks */
83 #define REQUIRE(num) \
85 if (stackdepth < (num)) { \
86 sprintf(msg, "(class: "); \
87 utf_sprint(msg + strlen(msg), m->class->name); \
88 sprintf(msg + strlen(msg), ", method: "); \
89 utf_sprint(msg + strlen(msg), m->name); \
90 sprintf(msg + strlen(msg), ", signature: "); \
91 utf_sprint(msg + strlen(msg), m->descriptor); \
92 sprintf(msg + strlen(msg), ") Unable to pop operand off an empty stack"); \
94 new_exception_message(string_java_lang_VerifyError, msg); \
99 #define REQUIRE_1 REQUIRE(1)
100 #define REQUIRE_2 REQUIRE(2)
101 #define REQUIRE_3 REQUIRE(3)
102 #define REQUIRE_4 REQUIRE(4)
106 /* We allow ACONST instructions inserted as arguments to builtin
107 * functions to exceed the maximum stack depth. Maybe we should check
108 * against maximum stack depth only at block boundaries?
111 #define CHECKOVERFLOW \
113 if (stackdepth > m->maxstack) { \
114 if (iptr[0].opc != ICMD_ACONST \
115 || iptr[0].op1 == 0) { \
116 sprintf(msg, "(class: "); \
117 utf_sprint_classname(msg + strlen(msg), m->class->name); \
118 sprintf(msg + strlen(msg), ", method: "); \
119 utf_sprint(msg + strlen(msg), m->name); \
120 sprintf(msg + strlen(msg), ", signature: "); \
121 utf_sprint(msg + strlen(msg), m->descriptor); \
122 sprintf(msg + strlen(msg), ") Stack size too large"); \
124 new_exception_message(string_java_lang_VerifyError, msg); \
131 /*--------------------------------------------------*/
132 /* ALLOCATING STACK SLOTS */
133 /*--------------------------------------------------*/
135 #define NEWSTACK(s,v,n) {new->prev=curstack;new->type=s;new->flags=0; \
136 new->varkind=v;new->varnum=n;curstack=new;new++;}
137 #define NEWSTACKn(s,n) NEWSTACK(s,UNDEFVAR,n)
138 #define NEWSTACK0(s) NEWSTACK(s,UNDEFVAR,0)
140 /* allocate the input stack for an exception handler */
141 #define NEWXSTACK {NEWSTACK(TYPE_ADR,STACKVAR,0);curstack=0;}
144 /*--------------------------------------------------*/
145 /* STACK MANIPULATION */
146 /*--------------------------------------------------*/
148 /* resetting to an empty operand stack */
149 #define STACKRESET {curstack=0;stackdepth=0;}
151 /* set the output stack of the current instruction */
152 #define SETDST {iptr->dst=curstack;}
154 /* The following macros do NOT check stackdepth, set stackdepth or iptr->dst */
155 #define POP(s) {if(s!=curstack->type){TYPEPANIC;} \
156 if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR;\
157 curstack=curstack->prev;}
158 #define POPANY {if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR; \
159 curstack=curstack->prev;}
160 #define COPY(s,d) {(d)->flags=0;(d)->type=(s)->type;\
161 (d)->varkind=(s)->varkind;(d)->varnum=(s)->varnum;}
164 /*--------------------------------------------------*/
165 /* STACK OPERATIONS MODELING */
166 /*--------------------------------------------------*/
168 /* The following macros are used to model the stack manipulations of
169 * different kinds of instructions.
171 * These macros check the input stackdepth and they set the output
172 * stackdepth and the output stack of the instruction (iptr->dst).
174 * These macros do *not* check for stack overflows!
177 #define PUSHCONST(s){NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
178 #define LOAD(s,v,n) {NEWSTACK(s,v,n);SETDST;stackdepth++;}
179 #define STORE(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
180 #define OP1_0(s) {REQUIRE_1;POP(s);SETDST;stackdepth--;}
181 #define OP1_0ANY {REQUIRE_1;POPANY;SETDST;stackdepth--;}
182 #define OP0_1(s) {NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
183 #define OP1_1(s,d) {REQUIRE_1;POP(s);NEWSTACKn(d,stackdepth-1);SETDST;}
184 #define OP2_0(s) {REQUIRE_2;POP(s);POP(s);SETDST;stackdepth-=2;}
185 #define OPTT2_0(t,b){REQUIRE_2;POP(t);POP(b);SETDST;stackdepth-=2;}
186 #define OP2_1(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);SETDST;stackdepth--;}
187 #define OP2IAT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(TYPE_ADR);NEWSTACKn(s,stackdepth-2);\
188 SETDST;stackdepth--;}
189 #define OP2IT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(s);NEWSTACKn(s,stackdepth-2);\
190 SETDST;stackdepth--;}
191 #define OPTT2_1(s,d){REQUIRE_2;POP(s);POP(s);NEWSTACKn(d,stackdepth-2);SETDST;stackdepth--;}
192 #define OP2_2(s) {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);\
193 NEWSTACKn(s,stackdepth-1);SETDST;}
194 #define OP3TIA_0(s) {REQUIRE_3;POP(s);POP(TYPE_INT);POP(TYPE_ADR);SETDST;stackdepth-=3;}
195 #define OP3_0(s) {REQUIRE_3;POP(s);POP(s);POP(s);SETDST;stackdepth-=3;}
196 #define POPMANY(i) {REQUIRE(i);stackdepth-=i;while(--i>=0){POPANY;}SETDST;}
197 #define DUP {REQUIRE_1;NEWSTACK(CURTYPE,CURKIND,curstack->varnum);SETDST; \
199 #define SWAP {REQUIRE_2;COPY(curstack,new);POPANY;COPY(curstack,new+1);POPANY;\
200 new[0].prev=curstack;new[1].prev=new;\
201 curstack=new+1;new+=2;SETDST;}
202 #define DUP_X1 {REQUIRE_2;COPY(curstack,new);COPY(curstack,new+2);POPANY;\
203 COPY(curstack,new+1);POPANY;new[0].prev=curstack;\
204 new[1].prev=new;new[2].prev=new+1;\
205 curstack=new+2;new+=3;SETDST;stackdepth++;}
206 #define DUP2_X1 {REQUIRE_3;COPY(curstack,new+1);COPY(curstack,new+4);POPANY;\
207 COPY(curstack,new);COPY(curstack,new+3);POPANY;\
208 COPY(curstack,new+2);POPANY;new[0].prev=curstack;\
209 new[1].prev=new;new[2].prev=new+1;\
210 new[3].prev=new+2;new[4].prev=new+3;\
211 curstack=new+4;new+=5;SETDST;stackdepth+=2;}
212 #define DUP_X2 {REQUIRE_3;COPY(curstack,new);COPY(curstack,new+3);POPANY;\
213 COPY(curstack,new+2);POPANY;COPY(curstack,new+1);POPANY;\
214 new[0].prev=curstack;new[1].prev=new;\
215 new[2].prev=new+1;new[3].prev=new+2;\
216 curstack=new+3;new+=4;SETDST;stackdepth++;}
217 #define DUP2_X2 {REQUIRE_4;COPY(curstack,new+1);COPY(curstack,new+5);POPANY;\
218 COPY(curstack,new);COPY(curstack,new+4);POPANY;\
219 COPY(curstack,new+3);POPANY;COPY(curstack,new+2);POPANY;\
220 new[0].prev=curstack;new[1].prev=new;\
221 new[2].prev=new+1;new[3].prev=new+2;\
222 new[4].prev=new+3;new[5].prev=new+4;\
223 curstack=new+5;new+=6;SETDST;stackdepth+=2;}
226 /*--------------------------------------------------*/
227 /* MACROS FOR HANDLING BASIC BLOCKS */
228 /*--------------------------------------------------*/
230 /* COPYCURSTACK makes a copy of the current operand stack (curstack)
231 * and returns it in the variable copy.
233 * This macro is used to propagate the operand stack from one basic
234 * block to another. The destination block receives the copy as its
237 #define COPYCURSTACK(copy) {\
250 copy->varkind=STACKVAR;\
261 /* BBEND is called at the end of each basic block (after the last
262 * instruction of the block has been processed).
265 #define BBEND(s,i){ \
266 i = stackdepth - 1; \
269 if ((copy->varkind == STACKVAR) && (copy->varnum > i)) \
270 copy->varkind = TEMPVAR; \
272 copy->varkind = STACKVAR; \
275 m->registerdata->interfaces[i][copy->type].type = copy->type; \
276 m->registerdata->interfaces[i][copy->type].flags |= copy->flags; \
277 i--; copy = copy->prev; \
279 i = bptr->indepth - 1; \
280 copy = bptr->instack; \
282 m->registerdata->interfaces[i][copy->type].type = copy->type; \
283 if (copy->varkind == STACKVAR) { \
284 if (copy->flags & SAVEDVAR) \
285 m->registerdata->interfaces[i][copy->type].flags |= SAVEDVAR; \
287 i--; copy = copy->prev; \
292 /* MARKREACHED marks the destination block <b> as reached. If this
293 * block has been reached before we check if stack depth and types
294 * match. Otherwise the destination block receives a copy of the
295 * current stack as its input stack.
297 * b...destination block
300 #define MARKREACHED(b,c) { \
302 {COPYCURSTACK(c);b->flags=0;b->instack=c;b->indepth=stackdepth;} \
303 else {stackptr s=curstack;stackptr t=b->instack; \
304 if(b->indepth!=stackdepth) \
305 {show_icmd_method(m);panic("Stack depth mismatch");} \
306 while(s){if (s->type!=t->type) \
308 s=s->prev;t=t->prev; \
314 /**********************************************************************/
316 /**********************************************************************/
318 /* analyse_stack uses the intermediate code created by parse.c to
319 * build a model of the JVM operand stack for the current method.
321 * The following checks are performed:
322 * - check for operand stack underflow (before each instruction)
323 * - check for operand stack overflow (after[1] each instruction)
324 * - check for matching stack depth at merging points
325 * - check for matching basic types[2] at merging points
326 * - check basic types for instruction input (except for BUILTIN*
327 * opcodes, INVOKE* opcodes and MULTIANEWARRAY)
329 * [1]) Checking this after the instruction should be ok. parse.c
330 * counts the number of required stack slots in such a way that it is
331 * only vital that we don't exceed `maxstack` at basic block
334 * [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
335 * DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
336 * types are not discerned.
339 methodinfo *analyse_stack(methodinfo *m)
347 int opcode, i, len, loops;
348 int superblockend, repeat, deadcode;
355 char msg[MAXLOGTEXT]; /* maybe we get an exception */
357 argren = DMNEW(int, m->maxlocals);
358 /*int *argren = (int *)alloca(m->maxlocals * sizeof(int));*/ /* table for argument renaming */
359 for (i = 0; i < m->maxlocals; i++)
362 m->registerdata->arguments_num = 0;
365 m->basicblocks[0].flags = BBREACHED;
366 m->basicblocks[0].instack = 0;
367 m->basicblocks[0].indepth = 0;
369 for (i = 0; i < m->exceptiontablelength; i++) {
370 bptr = &m->basicblocks[m->basicblockindex[m->exceptiontable[i].handlerpc]];
371 bptr->flags = BBREACHED;
372 bptr->type = BBTYPE_EXH;
375 bptr->pre_count = 10000;
380 #ifdef CONDITIONAL_LOADCONST
381 b_count = m->basicblockcount;
382 bptr = m->basicblocks;
383 while (--b_count >= 0) {
384 if (bptr->icount != 0) {
385 iptr = bptr->iinstr + bptr->icount - 1;
418 m->basicblocks[m->basicblockindex[iptr->op1]].pre_count++;
421 case ICMD_TABLESWITCH:
423 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
424 i = *s4ptr++; /* low */
425 i = *s4ptr++ - i + 1; /* high */
427 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
431 case ICMD_LOOKUPSWITCH:
433 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
434 i = *s4ptr++; /* count */
436 m->basicblocks[m->basicblockindex[s4ptr[1]]].pre_count++;
452 b_count = m->basicblockcount;
453 bptr = m->basicblocks;
454 superblockend = true;
458 while (--b_count >= 0) {
459 if (bptr->flags == BBDELETED) {
462 else if (superblockend && (bptr->flags < BBREACHED))
464 else if (bptr->flags <= BBREACHED) {
466 stackdepth = bptr->indepth;
467 else if (bptr->flags < BBREACHED) {
469 bptr->instack = copy;
470 bptr->indepth = stackdepth;
472 else if (bptr->indepth != stackdepth) {
474 panic("Stack depth mismatch");
477 curstack = bptr->instack;
479 superblockend = false;
480 bptr->flags = BBFINISHED;
483 b_index = bptr - m->basicblocks;
488 /* dolog("p: %04d op: %s stack: %p", iptr - instr, icmd_names[opcode], curstack); */
490 #ifdef USEBUILTINTABLE
493 stdopdescriptor *breplace;
494 breplace = find_builtin(opcode);
496 if (breplace && opcode == breplace->opcode) {
497 iptr[0].opc = breplace->icmd;
498 iptr[0].op1 = breplace->type_d;
499 iptr[0].val.a = breplace->builtin;
500 m->isleafmethod = false;
501 switch (breplace->icmd) {
509 builtin_descriptor *breplace;
510 breplace = find_builtin(opcode);
512 if (breplace && opcode == breplace->opcode) {
513 iptr[0].opc = breplace->icmd;
514 iptr[0].op1 = breplace->type_d;
515 iptr[0].val.a = breplace->builtin;
516 m->isleafmethod = false;
517 switch (breplace->icmd) {
532 case ICMD_CHECKASIZE:
533 case ICMD_CHECKEXCEPTION:
535 case ICMD_IFEQ_ICONST:
536 case ICMD_IFNE_ICONST:
537 case ICMD_IFLT_ICONST:
538 case ICMD_IFGE_ICONST:
539 case ICMD_IFGT_ICONST:
540 case ICMD_IFLE_ICONST:
541 case ICMD_ELSE_ICONST:
546 m->registerdata->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
548 COUNT(count_pcmd_return);
550 superblockend = true;
553 /* pop 0 push 1 const */
556 COUNT(count_pcmd_load);
558 switch (iptr[1].opc) {
560 iptr[0].opc = ICMD_IADDCONST;
562 iptr[1].opc = ICMD_NOP;
563 OP1_1(TYPE_INT,TYPE_INT);
564 COUNT(count_pcmd_op);
567 iptr[0].opc = ICMD_ISUBCONST;
568 goto icmd_iconst_tail;
570 iptr[0].opc = ICMD_IMULCONST;
571 goto icmd_iconst_tail;
573 if (iptr[0].val.i == 0x00000002)
575 else if (iptr[0].val.i == 0x00000004)
577 else if (iptr[0].val.i == 0x00000008)
579 else if (iptr[0].val.i == 0x00000010)
581 else if (iptr[0].val.i == 0x00000020)
583 else if (iptr[0].val.i == 0x00000040)
585 else if (iptr[0].val.i == 0x00000080)
587 else if (iptr[0].val.i == 0x00000100)
589 else if (iptr[0].val.i == 0x00000200)
591 else if (iptr[0].val.i == 0x00000400)
593 else if (iptr[0].val.i == 0x00000800)
595 else if (iptr[0].val.i == 0x00001000)
597 else if (iptr[0].val.i == 0x00002000)
599 else if (iptr[0].val.i == 0x00004000)
601 else if (iptr[0].val.i == 0x00008000)
603 else if (iptr[0].val.i == 0x00010000)
605 else if (iptr[0].val.i == 0x00020000)
607 else if (iptr[0].val.i == 0x00040000)
609 else if (iptr[0].val.i == 0x00080000)
611 else if (iptr[0].val.i == 0x00100000)
613 else if (iptr[0].val.i == 0x00200000)
615 else if (iptr[0].val.i == 0x00400000)
617 else if (iptr[0].val.i == 0x00800000)
619 else if (iptr[0].val.i == 0x01000000)
621 else if (iptr[0].val.i == 0x02000000)
623 else if (iptr[0].val.i == 0x04000000)
625 else if (iptr[0].val.i == 0x08000000)
627 else if (iptr[0].val.i == 0x10000000)
629 else if (iptr[0].val.i == 0x20000000)
631 else if (iptr[0].val.i == 0x40000000)
633 else if (iptr[0].val.i == 0x80000000)
639 iptr[0].opc = ICMD_IDIVPOW2;
640 goto icmd_iconst_tail;
642 if ((iptr[0].val.i == 0x00000002) ||
643 (iptr[0].val.i == 0x00000004) ||
644 (iptr[0].val.i == 0x00000008) ||
645 (iptr[0].val.i == 0x00000010) ||
646 (iptr[0].val.i == 0x00000020) ||
647 (iptr[0].val.i == 0x00000040) ||
648 (iptr[0].val.i == 0x00000080) ||
649 (iptr[0].val.i == 0x00000100) ||
650 (iptr[0].val.i == 0x00000200) ||
651 (iptr[0].val.i == 0x00000400) ||
652 (iptr[0].val.i == 0x00000800) ||
653 (iptr[0].val.i == 0x00001000) ||
654 (iptr[0].val.i == 0x00002000) ||
655 (iptr[0].val.i == 0x00004000) ||
656 (iptr[0].val.i == 0x00008000) ||
657 (iptr[0].val.i == 0x00010000) ||
658 (iptr[0].val.i == 0x00020000) ||
659 (iptr[0].val.i == 0x00040000) ||
660 (iptr[0].val.i == 0x00080000) ||
661 (iptr[0].val.i == 0x00100000) ||
662 (iptr[0].val.i == 0x00200000) ||
663 (iptr[0].val.i == 0x00400000) ||
664 (iptr[0].val.i == 0x00800000) ||
665 (iptr[0].val.i == 0x01000000) ||
666 (iptr[0].val.i == 0x02000000) ||
667 (iptr[0].val.i == 0x04000000) ||
668 (iptr[0].val.i == 0x08000000) ||
669 (iptr[0].val.i == 0x10000000) ||
670 (iptr[0].val.i == 0x20000000) ||
671 (iptr[0].val.i == 0x40000000) ||
672 (iptr[0].val.i == 0x80000000)) {
673 iptr[0].opc = ICMD_IREMPOW2;
675 #if defined(__I386__)
676 method_uses_ecx = true;
678 goto icmd_iconst_tail;
683 iptr[0].opc = ICMD_IANDCONST;
684 goto icmd_iconst_tail;
686 iptr[0].opc = ICMD_IORCONST;
687 goto icmd_iconst_tail;
689 iptr[0].opc = ICMD_IXORCONST;
690 goto icmd_iconst_tail;
692 iptr[0].opc = ICMD_ISHLCONST;
693 goto icmd_iconst_tail;
695 iptr[0].opc = ICMD_ISHRCONST;
696 goto icmd_iconst_tail;
698 iptr[0].opc = ICMD_IUSHRCONST;
699 goto icmd_iconst_tail;
700 #if SUPPORT_LONG_SHIFT
702 iptr[0].opc = ICMD_LSHLCONST;
703 #if defined(__I386__)
704 method_uses_ecx = true;
706 goto icmd_lconst_tail;
708 iptr[0].opc = ICMD_LSHRCONST;
709 #if defined(__I386__)
710 method_uses_ecx = true;
712 goto icmd_lconst_tail;
714 iptr[0].opc = ICMD_LUSHRCONST;
715 #if defined(__I386__)
716 method_uses_ecx = true;
718 goto icmd_lconst_tail;
721 iptr[0].opc = ICMD_IFEQ;
723 iptr[0].op1 = iptr[1].op1;
726 /* iptr[1].opc = ICMD_NOP; */
728 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
730 iptr[0].target = (void *) tbptr;
732 MARKREACHED(tbptr, copy);
733 COUNT(count_pcmd_bra);
736 iptr[0].opc = ICMD_IFLT;
737 goto icmd_if_icmp_tail;
739 iptr[0].opc = ICMD_IFLE;
740 goto icmd_if_icmp_tail;
742 iptr[0].opc = ICMD_IFNE;
743 goto icmd_if_icmp_tail;
745 iptr[0].opc = ICMD_IFGT;
746 goto icmd_if_icmp_tail;
748 iptr[0].opc = ICMD_IFGE;
749 goto icmd_if_icmp_tail;
751 #if SUPPORT_CONST_ASTORE
756 #if SUPPORT_ONLY_ZERO_ASTORE
757 if (iptr[0].val.i == 0) {
758 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
759 switch (iptr[1].opc) {
761 iptr[0].opc = ICMD_IASTORECONST;
764 iptr[0].opc = ICMD_BASTORECONST;
767 iptr[0].opc = ICMD_CASTORECONST;
770 iptr[0].opc = ICMD_SASTORECONST;
774 iptr[1].opc = ICMD_NOP;
775 OPTT2_0(TYPE_INT, TYPE_ADR);
776 COUNT(count_pcmd_op);
777 #if SUPPORT_ONLY_ZERO_ASTORE
780 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
782 #endif /* SUPPORT_CONST_ASTORE */
793 COUNT(count_pcmd_load);
795 switch (iptr[1].opc) {
798 iptr[0].opc = ICMD_LADDCONST;
800 iptr[1].opc = ICMD_NOP;
801 OP1_1(TYPE_LNG,TYPE_LNG);
802 COUNT(count_pcmd_op);
805 iptr[0].opc = ICMD_LSUBCONST;
806 goto icmd_lconst_tail;
810 iptr[0].opc = ICMD_LMULCONST;
811 #if defined(__I386__)
812 method_uses_ecx = true;
813 method_uses_edx = true;
815 goto icmd_lconst_tail;
819 if (iptr[0].val.l == 0x00000002)
821 else if (iptr[0].val.l == 0x00000004)
823 else if (iptr[0].val.l == 0x00000008)
825 else if (iptr[0].val.l == 0x00000010)
827 else if (iptr[0].val.l == 0x00000020)
829 else if (iptr[0].val.l == 0x00000040)
831 else if (iptr[0].val.l == 0x00000080)
833 else if (iptr[0].val.l == 0x00000100)
835 else if (iptr[0].val.l == 0x00000200)
837 else if (iptr[0].val.l == 0x00000400)
839 else if (iptr[0].val.l == 0x00000800)
841 else if (iptr[0].val.l == 0x00001000)
843 else if (iptr[0].val.l == 0x00002000)
845 else if (iptr[0].val.l == 0x00004000)
847 else if (iptr[0].val.l == 0x00008000)
849 else if (iptr[0].val.l == 0x00010000)
851 else if (iptr[0].val.l == 0x00020000)
853 else if (iptr[0].val.l == 0x00040000)
855 else if (iptr[0].val.l == 0x00080000)
857 else if (iptr[0].val.l == 0x00100000)
859 else if (iptr[0].val.l == 0x00200000)
861 else if (iptr[0].val.l == 0x00400000)
863 else if (iptr[0].val.l == 0x00800000)
865 else if (iptr[0].val.l == 0x01000000)
867 else if (iptr[0].val.l == 0x02000000)
869 else if (iptr[0].val.l == 0x04000000)
871 else if (iptr[0].val.l == 0x08000000)
873 else if (iptr[0].val.l == 0x10000000)
875 else if (iptr[0].val.l == 0x20000000)
877 else if (iptr[0].val.l == 0x40000000)
879 else if (iptr[0].val.l == 0x80000000)
885 iptr[0].opc = ICMD_LDIVPOW2;
886 #if defined(__I386__)
887 method_uses_ecx = true;
889 goto icmd_lconst_tail;
891 if ((iptr[0].val.l == 0x00000002) ||
892 (iptr[0].val.l == 0x00000004) ||
893 (iptr[0].val.l == 0x00000008) ||
894 (iptr[0].val.l == 0x00000010) ||
895 (iptr[0].val.l == 0x00000020) ||
896 (iptr[0].val.l == 0x00000040) ||
897 (iptr[0].val.l == 0x00000080) ||
898 (iptr[0].val.l == 0x00000100) ||
899 (iptr[0].val.l == 0x00000200) ||
900 (iptr[0].val.l == 0x00000400) ||
901 (iptr[0].val.l == 0x00000800) ||
902 (iptr[0].val.l == 0x00001000) ||
903 (iptr[0].val.l == 0x00002000) ||
904 (iptr[0].val.l == 0x00004000) ||
905 (iptr[0].val.l == 0x00008000) ||
906 (iptr[0].val.l == 0x00010000) ||
907 (iptr[0].val.l == 0x00020000) ||
908 (iptr[0].val.l == 0x00040000) ||
909 (iptr[0].val.l == 0x00080000) ||
910 (iptr[0].val.l == 0x00100000) ||
911 (iptr[0].val.l == 0x00200000) ||
912 (iptr[0].val.l == 0x00400000) ||
913 (iptr[0].val.l == 0x00800000) ||
914 (iptr[0].val.l == 0x01000000) ||
915 (iptr[0].val.l == 0x02000000) ||
916 (iptr[0].val.l == 0x04000000) ||
917 (iptr[0].val.l == 0x08000000) ||
918 (iptr[0].val.l == 0x10000000) ||
919 (iptr[0].val.l == 0x20000000) ||
920 (iptr[0].val.l == 0x40000000) ||
921 (iptr[0].val.l == 0x80000000)) {
922 iptr[0].opc = ICMD_LREMPOW2;
924 #if defined(__I386__)
925 method_uses_ecx = true;
927 goto icmd_lconst_tail;
934 iptr[0].opc = ICMD_LANDCONST;
935 goto icmd_lconst_tail;
937 iptr[0].opc = ICMD_LORCONST;
938 goto icmd_lconst_tail;
940 iptr[0].opc = ICMD_LXORCONST;
941 goto icmd_lconst_tail;
943 #if !defined(NOLONG_CONDITIONAL)
945 if ((len > 1) && (iptr[2].val.i == 0)) {
946 switch (iptr[2].opc) {
948 iptr[0].opc = ICMD_IF_LEQ;
949 #if defined(__I386__)
950 method_uses_ecx = true;
952 icmd_lconst_lcmp_tail:
953 iptr[0].op1 = iptr[2].op1;
956 /* iptr[1].opc = ICMD_NOP;
957 iptr[2].opc = ICMD_NOP; */
959 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
961 iptr[0].target = (void *) tbptr;
963 MARKREACHED(tbptr, copy);
964 COUNT(count_pcmd_bra);
965 COUNT(count_pcmd_op);
968 iptr[0].opc = ICMD_IF_LNE;
969 #if defined(__I386__)
970 method_uses_ecx = true;
972 goto icmd_lconst_lcmp_tail;
974 iptr[0].opc = ICMD_IF_LLT;
975 goto icmd_lconst_lcmp_tail;
977 iptr[0].opc = ICMD_IF_LGT;
978 goto icmd_lconst_lcmp_tail;
980 iptr[0].opc = ICMD_IF_LLE;
981 goto icmd_lconst_lcmp_tail;
983 iptr[0].opc = ICMD_IF_LGE;
984 goto icmd_lconst_lcmp_tail;
987 } /* switch (iptr[2].opc) */
988 } /* if (iptr[2].val.i == 0) */
994 #if SUPPORT_CONST_ASTORE
996 #if SUPPORT_ONLY_ZERO_ASTORE
997 if (iptr[0].val.l == 0) {
998 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
999 iptr[0].opc = ICMD_LASTORECONST;
1000 iptr[1].opc = ICMD_NOP;
1001 OPTT2_0(TYPE_INT, TYPE_ADR);
1002 COUNT(count_pcmd_op);
1003 #if SUPPORT_ONLY_ZERO_ASTORE
1005 PUSHCONST(TYPE_LNG);
1006 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
1008 #endif /* SUPPORT_CONST_ASTORE */
1011 PUSHCONST(TYPE_LNG);
1015 PUSHCONST(TYPE_LNG);
1019 COUNT(count_pcmd_load);
1020 PUSHCONST(TYPE_FLT);
1024 COUNT(count_pcmd_load);
1025 PUSHCONST(TYPE_DBL);
1029 COUNT(count_pcmd_load);
1030 #if SUPPORT_CONST_ASTORE
1031 if (len > 0 && iptr->val.a == 0) {
1032 if (iptr[1].opc == ICMD_BUILTIN3 &&
1033 iptr[1].val.a == BUILTIN_aastore) {
1034 iptr[0].opc = ICMD_AASTORECONST;
1035 iptr[1].opc = ICMD_NOP;
1036 OPTT2_0(TYPE_INT, TYPE_ADR);
1037 COUNT(count_pcmd_op);
1040 PUSHCONST(TYPE_ADR);
1044 #endif /* SUPPORT_CONST_ASTORE */
1045 PUSHCONST(TYPE_ADR);
1048 /* pop 0 push 1 load */
1055 COUNT(count_load_instruction);
1056 i = opcode-ICMD_ILOAD;
1057 iptr->op1 = argren[iptr->op1];
1058 m->registerdata->locals[iptr->op1][i].type = i;
1059 LOAD(i, LOCALVAR, iptr->op1);
1065 #if defined(__I386__)
1066 method_uses_ecx = true;
1067 method_uses_edx = true;
1073 COUNT(count_check_null);
1074 COUNT(count_check_bound);
1075 COUNT(count_pcmd_mem);
1076 OP2IAT_1(opcode-ICMD_IALOAD);
1077 #if defined(__I386__)
1078 method_uses_ecx = true;
1085 COUNT(count_check_null);
1086 COUNT(count_check_bound);
1087 COUNT(count_pcmd_mem);
1089 #if defined(__I386__)
1090 method_uses_ecx = true;
1094 /* pop 0 push 0 iinc */
1100 count_store_depth[10]++;
1102 count_store_depth[i]++;
1107 if ((copy->varkind == LOCALVAR) &&
1108 (copy->varnum == iptr->op1)) {
1109 copy->varkind = TEMPVAR;
1118 /* pop 1 push 0 store */
1128 i = opcode - ICMD_ISTORE;
1129 m->registerdata->locals[iptr->op1][i].type = i;
1134 count_store_length[20]++;
1136 count_store_length[i]++;
1139 count_store_depth[10]++;
1141 count_store_depth[i]++;
1143 copy = curstack->prev;
1146 if ((copy->varkind == LOCALVAR) &&
1147 (copy->varnum == iptr->op1)) {
1148 copy->varkind = TEMPVAR;
1154 if ((new - curstack) == 1) {
1155 curstack->varkind = LOCALVAR;
1156 curstack->varnum = iptr->op1;
1158 STORE(opcode-ICMD_ISTORE);
1166 #if defined(__I386__)
1167 method_uses_ecx = true;
1168 method_uses_edx = true;
1172 COUNT(count_check_null);
1173 COUNT(count_check_bound);
1174 COUNT(count_pcmd_mem);
1175 OP3TIA_0(opcode-ICMD_IASTORE);
1181 COUNT(count_check_null);
1182 COUNT(count_check_bound);
1183 COUNT(count_pcmd_mem);
1185 #if defined(__I386__)
1186 method_uses_ecx = true;
1187 method_uses_edx = true;
1194 #ifdef TYPECHECK_STACK_COMPCAT
1197 if (IS_2_WORD_TYPE(curstack->type))
1198 panic("Illegal instruction: POP on category 2 type");
1209 COUNT(count_pcmd_return);
1210 OP1_0(opcode-ICMD_IRETURN);
1211 superblockend = true;
1215 COUNT(count_check_null);
1219 superblockend = true;
1222 case ICMD_PUTSTATIC:
1223 COUNT(count_pcmd_mem);
1225 #if defined(__I386__)
1226 method_uses_ecx = true;
1230 /* pop 1 push 0 branch */
1233 case ICMD_IFNONNULL:
1234 COUNT(count_pcmd_bra);
1236 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1238 iptr[0].target = (void *) tbptr;
1240 MARKREACHED(tbptr, copy);
1249 COUNT(count_pcmd_bra);
1250 #ifdef CONDITIONAL_LOADCONST
1252 tbptr = m->basicblocks + b_index;
1253 if ((b_count >= 3) &&
1254 ((b_index + 2) == m->basicblockindex[iptr[0].op1]) &&
1255 (tbptr[1].pre_count == 1) &&
1256 (iptr[1].opc == ICMD_ICONST) &&
1257 (iptr[2].opc == ICMD_GOTO) &&
1258 ((b_index + 3) == m->basicblockindex[iptr[2].op1]) &&
1259 (tbptr[2].pre_count == 1) &&
1260 (iptr[3].opc == ICMD_ICONST)) {
1261 OP1_1(TYPE_INT, TYPE_INT);
1262 switch (iptr[0].opc) {
1264 iptr[0].opc = ICMD_IFNE_ICONST;
1267 iptr[0].opc = ICMD_IFEQ_ICONST;
1270 iptr[0].opc = ICMD_IFGE_ICONST;
1273 iptr[0].opc = ICMD_IFLT_ICONST;
1276 iptr[0].opc = ICMD_IFLE_ICONST;
1279 iptr[0].opc = ICMD_IFGT_ICONST;
1282 iptr[0].val.i = iptr[1].val.i;
1283 iptr[1].opc = ICMD_ELSE_ICONST;
1284 iptr[1].val.i = iptr[3].val.i;
1285 iptr[2].opc = ICMD_NOP;
1286 iptr[3].opc = ICMD_NOP;
1287 tbptr[1].flags = BBDELETED;
1288 tbptr[2].flags = BBDELETED;
1289 tbptr[1].icount = 0;
1290 tbptr[2].icount = 0;
1291 if (tbptr[3].pre_count == 2) {
1292 len += tbptr[3].icount + 3;
1293 bptr->icount += tbptr[3].icount + 3;
1294 tbptr[3].flags = BBDELETED;
1295 tbptr[3].icount = 0;
1308 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1310 iptr[0].target = (void *) tbptr;
1312 MARKREACHED(tbptr, copy);
1315 /* pop 0 push 0 branch */
1318 COUNT(count_pcmd_bra);
1319 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1321 iptr[0].target = (void *) tbptr;
1323 MARKREACHED(tbptr, copy);
1325 superblockend = true;
1328 /* pop 1 push 0 table branch */
1330 case ICMD_TABLESWITCH:
1331 COUNT(count_pcmd_table);
1333 s4ptr = iptr->val.a;
1334 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1335 MARKREACHED(tbptr, copy);
1336 i = *s4ptr++; /* low */
1337 i = *s4ptr++ - i + 1; /* high */
1339 tptr = DMNEW(void*, i+1);
1340 iptr->target = (void *) tptr;
1342 tptr[0] = (void *) tbptr;
1346 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1348 tptr[0] = (void *) tbptr;
1351 MARKREACHED(tbptr, copy);
1354 superblockend = true;
1355 #if defined(__I386__)
1356 method_uses_ecx = true;
1360 /* pop 1 push 0 table branch */
1362 case ICMD_LOOKUPSWITCH:
1363 COUNT(count_pcmd_table);
1365 s4ptr = iptr->val.a;
1366 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1367 MARKREACHED(tbptr, copy);
1368 i = *s4ptr++; /* count */
1370 tptr = DMNEW(void*, i+1);
1371 iptr->target = (void *) tptr;
1373 tptr[0] = (void *) tbptr;
1377 tbptr = m->basicblocks + m->basicblockindex[s4ptr[1]];
1379 tptr[0] = (void *) tbptr;
1382 MARKREACHED(tbptr, copy);
1386 superblockend = true;
1389 case ICMD_NULLCHECKPOP:
1390 case ICMD_MONITORENTER:
1391 COUNT(count_check_null);
1392 case ICMD_MONITOREXIT:
1396 /* pop 2 push 0 branch */
1398 case ICMD_IF_ICMPEQ:
1399 case ICMD_IF_ICMPNE:
1400 case ICMD_IF_ICMPLT:
1401 case ICMD_IF_ICMPGE:
1402 case ICMD_IF_ICMPGT:
1403 case ICMD_IF_ICMPLE:
1404 COUNT(count_pcmd_bra);
1406 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1408 iptr[0].target = (void *) tbptr;
1410 MARKREACHED(tbptr, copy);
1413 case ICMD_IF_ACMPEQ:
1414 case ICMD_IF_ACMPNE:
1415 COUNT(count_pcmd_bra);
1417 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1419 iptr[0].target = (void *) tbptr;
1421 MARKREACHED(tbptr, copy);
1427 COUNT(count_check_null);
1428 COUNT(count_pcmd_mem);
1429 OPTT2_0(iptr->op1,TYPE_ADR);
1430 #if defined(__I386__)
1431 method_uses_ecx = true;
1437 if (! IS_2_WORD_TYPE(curstack->type)) {
1439 #ifdef TYPECHECK_STACK_COMPCAT
1442 if (IS_2_WORD_TYPE(curstack->prev->type))
1443 panic("Illegal instruction: POP2 on cat2, cat1 types");
1446 OP1_0ANY; /* second pop */
1449 iptr->opc = ICMD_POP;
1453 /* pop 0 push 1 dup */
1456 #ifdef TYPECHECK_STACK_COMPCAT
1459 if (IS_2_WORD_TYPE(curstack->type))
1460 panic("Illegal instruction: DUP on category 2 type");
1463 COUNT(count_dup_instruction);
1469 if (IS_2_WORD_TYPE(curstack->type)) {
1471 iptr->opc = ICMD_DUP;
1476 /* ..., ????, cat1 */
1477 #ifdef TYPECHECK_STACK_COMPCAT
1479 if (IS_2_WORD_TYPE(curstack->prev->type))
1480 panic("Illegal instruction: DUP2 on cat2, cat1 types");
1484 NEWSTACK(copy->prev->type, copy->prev->varkind,
1485 copy->prev->varnum);
1486 NEWSTACK(copy->type, copy->varkind,
1493 /* pop 2 push 3 dup */
1496 #ifdef TYPECHECK_STACK_COMPCAT
1499 if (IS_2_WORD_TYPE(curstack->type) ||
1500 IS_2_WORD_TYPE(curstack->prev->type))
1501 panic("Illegal instruction: DUP_X1 on cat 2 type");
1509 if (IS_2_WORD_TYPE(curstack->type)) {
1510 /* ..., ????, cat2 */
1511 #ifdef TYPECHECK_STACK_COMPCAT
1513 if (IS_2_WORD_TYPE(curstack->prev->type))
1514 panic("Illegal instruction: DUP2_X1 on cat2, cat2 types");
1517 iptr->opc = ICMD_DUP_X1;
1521 /* ..., ????, cat1 */
1522 #ifdef TYPECHECK_STACK_COMPCAT
1525 if (IS_2_WORD_TYPE(curstack->prev->type)
1526 || IS_2_WORD_TYPE(curstack->prev->prev->type))
1527 panic("Illegal instruction: DUP2_X1 on invalid types");
1534 /* pop 3 push 4 dup */
1538 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1539 /* ..., cat2, ???? */
1540 #ifdef TYPECHECK_STACK_COMPCAT
1542 if (IS_2_WORD_TYPE(curstack->type))
1543 panic("Illegal instruction: DUP_X2 on cat2, cat2 types");
1546 iptr->opc = ICMD_DUP_X1;
1550 /* ..., cat1, ???? */
1551 #ifdef TYPECHECK_STACK_COMPCAT
1554 if (IS_2_WORD_TYPE(curstack->type)
1555 || IS_2_WORD_TYPE(curstack->prev->prev->type))
1556 panic("Illegal instruction: DUP_X2 on invalid types");
1565 if (IS_2_WORD_TYPE(curstack->type)) {
1566 /* ..., ????, cat2 */
1567 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1568 /* ..., cat2, cat2 */
1569 iptr->opc = ICMD_DUP_X1;
1573 /* ..., cat1, cat2 */
1574 #ifdef TYPECHECK_STACK_COMPCAT
1577 if (IS_2_WORD_TYPE(curstack->prev->prev->type))
1578 panic("Illegal instruction: DUP2_X2 on invalid types");
1581 iptr->opc = ICMD_DUP_X2;
1587 /* ..., ????, ????, cat1 */
1588 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1589 /* ..., cat2, ????, cat1 */
1590 #ifdef TYPECHECK_STACK_COMPCAT
1592 if (IS_2_WORD_TYPE(curstack->prev->type))
1593 panic("Illegal instruction: DUP2_X2 on invalid types");
1596 iptr->opc = ICMD_DUP2_X1;
1600 /* ..., cat1, ????, cat1 */
1601 #ifdef TYPECHECK_STACK_COMPCAT
1604 if (IS_2_WORD_TYPE(curstack->prev->type)
1605 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
1606 panic("Illegal instruction: DUP2_X2 on invalid types");
1614 /* pop 2 push 2 swap */
1617 #ifdef TYPECHECK_STACK_COMPCAT
1620 if (IS_2_WORD_TYPE(curstack->type)
1621 || IS_2_WORD_TYPE(curstack->prev->type))
1622 panic("Illegal instruction: SWAP on category 2 type");
1631 #if !SUPPORT_DIVISION
1632 iptr[0].opc = ICMD_BUILTIN2;
1633 iptr[0].op1 = TYPE_INT;
1634 iptr[0].val.a = BUILTIN_idiv;
1635 m->isleafmethod = false;
1640 #if !SUPPORT_DIVISION
1641 iptr[0].opc = ICMD_BUILTIN2;
1642 iptr[0].op1 = TYPE_INT;
1643 iptr[0].val.a = BUILTIN_irem;
1644 m->isleafmethod = false;
1647 #if defined(__I386__)
1648 method_uses_ecx = true;
1649 method_uses_edx = true;
1655 #if defined(__I386__)
1656 method_uses_ecx = true;
1664 COUNT(count_pcmd_op);
1669 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1670 iptr[0].opc = ICMD_BUILTIN2;
1671 iptr[0].op1 = TYPE_LNG;
1672 iptr[0].val.a = BUILTIN_ldiv;
1673 m->isleafmethod = false;
1678 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1679 iptr[0].opc = ICMD_BUILTIN2;
1680 iptr[0].op1 = TYPE_LNG;
1681 iptr[0].val.a = BUILTIN_lrem;
1682 m->isleafmethod = false;
1687 #if defined(__I386__)
1688 method_uses_ecx = true;
1689 method_uses_edx = true;
1696 /* DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1697 COUNT(count_pcmd_op);
1704 COUNT(count_pcmd_op);
1706 #if defined(__I386__)
1707 method_uses_ecx = true;
1708 method_uses_edx = true;
1717 COUNT(count_pcmd_op);
1726 COUNT(count_pcmd_op);
1731 COUNT(count_pcmd_op);
1732 #if !defined(NOLONG_CONDITIONAL)
1733 if ((len > 0) && (iptr[1].val.i == 0)) {
1734 switch (iptr[1].opc) {
1736 iptr[0].opc = ICMD_IF_LCMPEQ;
1737 #if defined(__I386__)
1738 method_uses_ecx = true;
1741 iptr[0].op1 = iptr[1].op1;
1744 /* iptr[1].opc = ICMD_NOP; */
1746 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1748 iptr[0].target = (void *) tbptr;
1750 MARKREACHED(tbptr, copy);
1751 COUNT(count_pcmd_bra);
1754 iptr[0].opc = ICMD_IF_LCMPNE;
1755 #if defined(__I386__)
1756 method_uses_ecx = true;
1758 goto icmd_lcmp_if_tail;
1760 iptr[0].opc = ICMD_IF_LCMPLT;
1761 goto icmd_lcmp_if_tail;
1763 iptr[0].opc = ICMD_IF_LCMPGT;
1764 goto icmd_lcmp_if_tail;
1766 iptr[0].opc = ICMD_IF_LCMPLE;
1767 goto icmd_lcmp_if_tail;
1769 iptr[0].opc = ICMD_IF_LCMPGE;
1770 goto icmd_lcmp_if_tail;
1772 OPTT2_1(TYPE_LNG, TYPE_INT);
1777 OPTT2_1(TYPE_LNG, TYPE_INT);
1781 COUNT(count_pcmd_op);
1782 OPTT2_1(TYPE_FLT, TYPE_INT);
1786 COUNT(count_pcmd_op);
1787 OPTT2_1(TYPE_DBL, TYPE_INT);
1795 case ICMD_INT2SHORT:
1796 COUNT(count_pcmd_op);
1797 OP1_1(TYPE_INT, TYPE_INT);
1800 COUNT(count_pcmd_op);
1801 OP1_1(TYPE_LNG, TYPE_LNG);
1804 COUNT(count_pcmd_op);
1805 OP1_1(TYPE_FLT, TYPE_FLT);
1808 COUNT(count_pcmd_op);
1809 OP1_1(TYPE_DBL, TYPE_DBL);
1813 COUNT(count_pcmd_op);
1814 OP1_1(TYPE_INT, TYPE_LNG);
1815 #if defined(__I386__)
1816 method_uses_edx = true;
1820 COUNT(count_pcmd_op);
1821 OP1_1(TYPE_INT, TYPE_FLT);
1824 COUNT(count_pcmd_op);
1825 OP1_1(TYPE_INT, TYPE_DBL);
1828 COUNT(count_pcmd_op);
1829 OP1_1(TYPE_LNG, TYPE_INT);
1832 COUNT(count_pcmd_op);
1833 OP1_1(TYPE_LNG, TYPE_FLT);
1836 COUNT(count_pcmd_op);
1837 OP1_1(TYPE_LNG, TYPE_DBL);
1840 COUNT(count_pcmd_op);
1841 OP1_1(TYPE_FLT, TYPE_INT);
1844 COUNT(count_pcmd_op);
1845 OP1_1(TYPE_FLT, TYPE_LNG);
1846 #if defined(__I386__)
1847 method_uses_edx = true;
1851 COUNT(count_pcmd_op);
1852 OP1_1(TYPE_FLT, TYPE_DBL);
1855 COUNT(count_pcmd_op);
1856 OP1_1(TYPE_DBL, TYPE_INT);
1859 COUNT(count_pcmd_op);
1860 OP1_1(TYPE_DBL, TYPE_LNG);
1861 #if defined(__I386__)
1862 method_uses_edx = true;
1866 COUNT(count_pcmd_op);
1867 OP1_1(TYPE_DBL, TYPE_FLT);
1870 case ICMD_CHECKCAST:
1871 OP1_1(TYPE_ADR, TYPE_ADR);
1872 #if defined(__I386__)
1873 method_uses_ecx = true;
1874 method_uses_edx = true;
1878 case ICMD_INSTANCEOF:
1879 #if defined(__I386__)
1880 method_uses_ecx = true;
1881 method_uses_edx = true;
1883 case ICMD_ARRAYLENGTH:
1884 OP1_1(TYPE_ADR, TYPE_INT);
1888 case ICMD_ANEWARRAY:
1889 OP1_1(TYPE_INT, TYPE_ADR);
1893 COUNT(count_check_null);
1894 COUNT(count_pcmd_mem);
1895 OP1_1(TYPE_ADR, iptr->op1);
1896 #if defined(__I386__)
1897 method_uses_ecx = true;
1903 case ICMD_GETSTATIC:
1904 COUNT(count_pcmd_mem);
1906 #if defined(__I386__)
1907 method_uses_ecx = true;
1917 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1919 iptr[0].target = (void *) tbptr;
1921 /* This is a dirty hack. The typechecker
1922 * needs it because the OP1_0ANY below
1923 * overwrites iptr->dst.
1925 iptr->val.a = (void *) iptr->dst;
1927 tbptr->type = BBTYPE_SBR;
1929 /* We need to check for overflow right here because
1930 * the pushed value is poped after MARKREACHED. */
1932 MARKREACHED(tbptr, copy);
1936 /* pop many push any */
1938 case ICMD_INVOKEVIRTUAL:
1939 case ICMD_INVOKESPECIAL:
1940 case ICMD_INVOKEINTERFACE:
1941 case ICMD_INVOKESTATIC:
1942 COUNT(count_pcmd_met);
1943 #if defined(__I386__)
1944 method_uses_ecx = true;
1947 methodinfo *lm = iptr->val.a;
1948 if (lm->flags & ACC_STATIC)
1949 {COUNT(count_check_null);}
1951 if (i > m->registerdata->arguments_num)
1952 m->registerdata->arguments_num = i;
1954 #if defined(__X86_64__)
1962 (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1966 stackargs += (iarg < m->registerdata->intreg_argnum) ?
1967 0 : (iarg - m->registerdata->intreg_argnum);
1968 stackargs += (farg < m->registerdata->fltreg_argnum) ?
1969 0 : (farg - m->registerdata->fltreg_argnum);
1974 if (!(copy->flags & SAVEDVAR)) {
1975 copy->varkind = ARGVAR;
1976 if (IS_FLT_DBL_TYPE(copy->type)) {
1977 if (--farg < m->registerdata->fltreg_argnum) {
1978 copy->varnum = farg;
1980 copy->varnum = --stackargs + m->registerdata->intreg_argnum;
1983 if (--iarg < m->registerdata->intreg_argnum) {
1984 copy->varnum = iarg;
1986 copy->varnum = --stackargs + m->registerdata->intreg_argnum;
1990 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1998 if (! (copy->flags & SAVEDVAR)) {
1999 copy->varkind = ARGVAR;
2006 copy->flags |= SAVEDVAR;
2011 if (lm->returntype != TYPE_VOID) {
2012 OP0_1(lm->returntype);
2018 /* DEBUG */ /*dolog("builtin3");*/
2020 if (! (curstack->flags & SAVEDVAR)) {
2021 curstack->varkind = ARGVAR;
2022 curstack->varnum = 2;
2024 if (3 > m->registerdata->arguments_num) {
2025 m->registerdata->arguments_num = 3;
2032 /* DEBUG */ /*dolog("builtin2");*/
2033 if (!(curstack->flags & SAVEDVAR)) {
2034 curstack->varkind = ARGVAR;
2035 curstack->varnum = 1;
2037 if (2 > m->registerdata->arguments_num) {
2038 m->registerdata->arguments_num = 2;
2045 /* DEBUG */ /*dolog("builtin1");*/
2046 if (!(curstack->flags & SAVEDVAR)) {
2047 curstack->varkind = ARGVAR;
2048 curstack->varnum = 0;
2050 if (1 > m->registerdata->arguments_num) {
2051 m->registerdata->arguments_num = 1;
2056 copy->flags |= SAVEDVAR;
2059 if (iptr->op1 != TYPE_VOID)
2063 case ICMD_MULTIANEWARRAY:
2066 if ((i + m->registerdata->intreg_argnum) > m->registerdata->arguments_num)
2067 m->registerdata->arguments_num = i + m->registerdata->intreg_argnum;
2070 /* check INT type here? Currently typecheck does this. */
2071 if (! (copy->flags & SAVEDVAR)) {
2072 copy->varkind = ARGVAR;
2073 copy->varnum = i + m->registerdata->intreg_argnum;
2078 copy->flags |= SAVEDVAR;
2086 case ICMD_CLEAR_ARGREN:
2087 for (i = iptr->op1; i<m->maxlocals; i++)
2089 iptr->opc = opcode = ICMD_NOP;
2093 case ICMD_READONLY_ARG:
2094 case ICMD_READONLY_ARG+1:
2095 case ICMD_READONLY_ARG+2:
2096 case ICMD_READONLY_ARG+3:
2097 case ICMD_READONLY_ARG+4:
2100 if (curstack->varkind == LOCALVAR) {
2101 i = curstack->varnum;
2102 argren[iptr->op1] = i;
2105 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
2111 printf("ICMD %d at %d\n", iptr->opc, (s4) (iptr - m->instructions));
2112 panic("Missing ICMD code during stack analysis");
2117 /* DEBUG */ /*dolog("iptr++");*/
2119 } /* while instructions */
2120 bptr->outstack = curstack;
2121 bptr->outdepth = stackdepth;
2125 superblockend = true;
2127 } /* while blocks */
2128 } while (repeat && !deadcode);
2131 if (m->basicblockcount > count_max_basic_blocks)
2132 count_max_basic_blocks = m->basicblockcount;
2133 count_basic_blocks += m->basicblockcount;
2134 if (m->instructioncount > count_max_javainstr)
2135 count_max_javainstr = m->instructioncount;
2136 count_javainstr += m->instructioncount;
2137 if (m->stackcount > count_upper_bound_new_stack)
2138 count_upper_bound_new_stack = m->stackcount;
2139 if ((new - m->stack) > count_max_new_stack)
2140 count_max_new_stack = (new - m->stack);
2142 b_count = m->basicblockcount;
2143 bptr = m->basicblocks;
2144 while (--b_count >= 0) {
2145 if (bptr->flags > BBREACHED) {
2146 if (bptr->indepth >= 10)
2147 count_block_stack[10]++;
2149 count_block_stack[bptr->indepth]++;
2152 count_block_size_distribution[len]++;
2154 count_block_size_distribution[10]++;
2156 count_block_size_distribution[11]++;
2158 count_block_size_distribution[12]++;
2160 count_block_size_distribution[13]++;
2162 count_block_size_distribution[14]++;
2164 count_block_size_distribution[15]++;
2166 count_block_size_distribution[16]++;
2168 count_block_size_distribution[17]++;
2174 count_analyse_iterations[0]++;
2175 else if (loops == 2)
2176 count_analyse_iterations[1]++;
2177 else if (loops == 3)
2178 count_analyse_iterations[2]++;
2179 else if (loops == 4)
2180 count_analyse_iterations[3]++;
2182 count_analyse_iterations[4]++;
2184 if (m->basicblockcount <= 5)
2185 count_method_bb_distribution[0]++;
2186 else if (m->basicblockcount <= 10)
2187 count_method_bb_distribution[1]++;
2188 else if (m->basicblockcount <= 15)
2189 count_method_bb_distribution[2]++;
2190 else if (m->basicblockcount <= 20)
2191 count_method_bb_distribution[3]++;
2192 else if (m->basicblockcount <= 30)
2193 count_method_bb_distribution[4]++;
2194 else if (m->basicblockcount <= 40)
2195 count_method_bb_distribution[5]++;
2196 else if (m->basicblockcount <= 50)
2197 count_method_bb_distribution[6]++;
2198 else if (m->basicblockcount <= 75)
2199 count_method_bb_distribution[7]++;
2201 count_method_bb_distribution[8]++;
2204 /* just return methodinfo* to signal everything was ok */
2210 /**********************************************************************/
2211 /* DEBUGGING HELPERS */
2212 /**********************************************************************/
2214 void icmd_print_stack(methodinfo *m, stackptr s)
2226 j = m->maxstack - i;
2231 /* DEBUG */ /*printf("(%d,%d,%d,%d)",s->varkind,s->flags,s->regoff,s->varnum); fflush(stdout);*/
2232 if (s->flags & SAVEDVAR)
2233 switch (s->varkind) {
2235 if (s->flags & INMEMORY)
2236 printf(" M%02d", s->regoff);
2237 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2238 printf(" F%02d", s->regoff);
2240 printf(" %3s", regs[s->regoff]);
2244 printf(" I%02d", s->varnum);
2247 printf(" L%02d", s->varnum);
2250 printf(" A%02d", s->varnum);
2253 printf(" !%02d", j);
2256 switch (s->varkind) {
2258 if (s->flags & INMEMORY)
2259 printf(" m%02d", s->regoff);
2260 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2261 printf(" f%02d", s->regoff);
2263 printf(" %3s", regs[s->regoff]);
2267 printf(" i%02d", s->varnum);
2270 printf(" l%02d", s->varnum);
2273 printf(" a%02d", s->varnum);
2276 printf(" ?%02d", j);
2284 static void print_reg(stackptr s) {
2286 if (s->flags & SAVEDVAR)
2287 switch (s->varkind) {
2289 if (s->flags & INMEMORY)
2290 printf(" tm%02d", s->regoff);
2292 printf(" tr%02d", s->regoff);
2295 printf(" s %02d", s->varnum);
2298 printf(" l %02d", s->varnum);
2301 printf(" a %02d", s->varnum);
2304 printf(" ! %02d", s->varnum);
2307 switch (s->varkind) {
2309 if (s->flags & INMEMORY)
2310 printf(" Tm%02d", s->regoff);
2312 printf(" Tr%02d", s->regoff);
2315 printf(" S %02d", s->varnum);
2318 printf(" L %02d", s->varnum);
2321 printf(" A %02d", s->varnum);
2324 printf(" ? %02d", s->varnum);
2334 char *icmd_builtin_name(functionptr bptr)
2336 builtin_descriptor *bdesc = builtin_desc;
2337 while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
2339 return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
2343 static char *jit_type[] = {
2352 void show_icmd_method(methodinfo *m)
2359 utf_fprint_classname(stdout, m->class->name);
2361 utf_fprint(stdout, m->name);
2362 utf_fprint_classname(stdout, m->descriptor);
2363 printf ("\n\nMax locals: %d\n", (int) m->maxlocals);
2364 printf ("Max stack: %d\n", (int) m->maxstack);
2366 printf ("Line number table length: %d\n", m->linenumbercount);
2368 printf ("Exceptions (Number: %d):\n", m->exceptiontablelength);
2369 for (ex = m->exceptiontable; ex != NULL; ex = ex->down) {
2370 printf(" L%03d ... ", ex->start->debug_nr );
2371 printf("L%03d = ", ex->end->debug_nr);
2372 printf("L%03d\n", ex->handler->debug_nr);
2375 printf ("Local Table:\n");
2376 for (i = 0; i < m->maxlocals; i++) {
2377 printf(" %3d: ", i);
2378 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2379 if (m->registerdata->locals[i][j].type >= 0) {
2380 printf(" (%s) ", jit_type[j]);
2381 if (m->registerdata->locals[i][j].flags & INMEMORY)
2382 printf("m%2d", m->registerdata->locals[i][j].regoff);
2383 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2384 printf("f%02d", m->registerdata->locals[i][j].regoff);
2386 printf("%3s", regs[m->registerdata->locals[i][j].regoff]);
2393 printf ("Interface Table:\n");
2394 for (i = 0; i < m->maxstack; i++) {
2395 if ((m->registerdata->interfaces[i][0].type >= 0) ||
2396 (m->registerdata->interfaces[i][1].type >= 0) ||
2397 (m->registerdata->interfaces[i][2].type >= 0) ||
2398 (m->registerdata->interfaces[i][3].type >= 0) ||
2399 (m->registerdata->interfaces[i][4].type >= 0)) {
2400 printf(" %3d: ", i);
2401 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2402 if (m->registerdata->interfaces[i][j].type >= 0) {
2403 printf(" (%s) ", jit_type[j]);
2404 if (m->registerdata->interfaces[i][j].flags & SAVEDVAR) {
2405 if (m->registerdata->interfaces[i][j].flags & INMEMORY)
2406 printf("M%2d", m->registerdata->interfaces[i][j].regoff);
2407 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2408 printf("F%02d", m->registerdata->interfaces[i][j].regoff);
2410 printf("%3s", regs[m->registerdata->interfaces[i][j].regoff]);
2414 if (m->registerdata->interfaces[i][j].flags & INMEMORY)
2415 printf("m%2d", m->registerdata->interfaces[i][j].regoff);
2416 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2417 printf("f%02d", m->registerdata->interfaces[i][j].regoff);
2419 printf("%3s", regs[m->registerdata->interfaces[i][j].regoff]);
2428 if (showdisassemble) {
2429 #if defined(__I386__) || defined(__X86_64__)
2433 u1ptr = m->mcode + dseglen;
2434 for (i = 0; i < m->basicblocks[0].mpc; i++, u1ptr++) {
2435 a = disassinstr(u1ptr, i);
2443 s4ptr = (s4 *) (m->mcode + dseglen);
2444 for (i = 0; i < m->basicblocks[0].mpc; i += 4, s4ptr++) {
2445 disassinstr(s4ptr, i);
2451 for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
2452 show_icmd_block(m, bptr);
2457 void show_icmd_block(methodinfo *m, basicblock *bptr)
2463 if (bptr->flags != BBDELETED) {
2464 deadcode = bptr->flags <= BBREACHED;
2467 for (j = m->maxstack; j > 0; j--)
2470 icmd_print_stack(m, bptr->instack);
2471 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2472 iptr = bptr->iinstr;
2474 for (i = 0; i < bptr->icount; i++, iptr++) {
2477 for (j = m->maxstack; j > 0; j--)
2481 icmd_print_stack(m, iptr->dst);
2482 printf("] %4d ", i);
2483 show_icmd(iptr, deadcode);
2487 if (showdisassemble && (!deadcode)) {
2488 #if defined(__I386__) || defined(__X86_64__)
2494 u1ptr = m->mcode + dseglen + i;
2496 if (bptr->next != NULL) {
2497 for (; i < bptr->next->mpc; i++, u1ptr++) {
2498 a = disassinstr(u1ptr, i);
2505 for (; u1ptr < (u1 *) (m->mcode + m->mcodelength); i++, u1ptr++) {
2506 a = disassinstr(u1ptr, i);
2517 s4ptr = (s4 *) (m->mcode + dseglen + i);
2519 if (bptr->next != NULL) {
2520 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2521 disassinstr(s4ptr, i);
2526 for (; s4ptr < (s4 *) (m->mcode + m->mcodelength); i += 4, s4ptr++) {
2527 disassinstr(s4ptr, i);
2537 void show_icmd(instruction *iptr, bool deadcode)
2543 printf("%s", icmd_names[iptr->opc]);
2545 switch ((int) iptr->opc) {
2546 case ICMD_IADDCONST:
2547 case ICMD_ISUBCONST:
2548 case ICMD_IMULCONST:
2551 case ICMD_IANDCONST:
2553 case ICMD_IXORCONST:
2554 case ICMD_ISHLCONST:
2555 case ICMD_ISHRCONST:
2556 case ICMD_IUSHRCONST:
2557 case ICMD_LSHLCONST:
2558 case ICMD_LSHRCONST:
2559 case ICMD_LUSHRCONST:
2561 case ICMD_ELSE_ICONST:
2562 case ICMD_IFEQ_ICONST:
2563 case ICMD_IFNE_ICONST:
2564 case ICMD_IFLT_ICONST:
2565 case ICMD_IFGE_ICONST:
2566 case ICMD_IFGT_ICONST:
2567 case ICMD_IFLE_ICONST:
2568 case ICMD_IASTORECONST:
2569 case ICMD_BASTORECONST:
2570 case ICMD_CASTORECONST:
2571 case ICMD_SASTORECONST:
2572 printf(" %d", iptr->val.i);
2575 case ICMD_LADDCONST:
2576 case ICMD_LSUBCONST:
2577 case ICMD_LMULCONST:
2580 case ICMD_LANDCONST:
2582 case ICMD_LXORCONST:
2584 case ICMD_LASTORECONST:
2585 #if defined(__I386__)
2586 printf(" %lld", iptr->val.l);
2588 printf(" %ld", iptr->val.l);
2593 printf(" %f", iptr->val.f);
2597 printf(" %f", iptr->val.d);
2601 case ICMD_AASTORECONST:
2602 printf(" %p", iptr->val.a);
2607 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2608 case ICMD_PUTSTATIC:
2609 case ICMD_GETSTATIC:
2611 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->class->name);
2613 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->name);
2615 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->descriptor);
2620 printf(" %d + %d", iptr->op1, iptr->val.i);
2655 printf(" %d", iptr->op1);
2661 ((classinfo *) iptr->val.a)->name);
2665 switch (iptr->op1) {
2693 case ICMD_ANEWARRAY:
2697 ((classinfo *) iptr->val.a)->name);
2701 case ICMD_MULTIANEWARRAY:
2704 printf(" %d ",iptr->op1);
2705 vft = (vftbl_t *)iptr->val.a;
2707 utf_fprint(stdout,vft->class->name);
2713 case ICMD_CHECKCAST:
2714 case ICMD_INSTANCEOF:
2716 classinfo *c = iptr->val.a;
2717 if (c->flags & ACC_INTERFACE)
2718 printf(" (INTERFACE) ");
2720 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2721 utf_fprint(stdout, c->name);
2728 printf(" %s", icmd_builtin_name((functionptr) iptr->val.a));
2731 case ICMD_INVOKEVIRTUAL:
2732 case ICMD_INVOKESPECIAL:
2733 case ICMD_INVOKESTATIC:
2734 case ICMD_INVOKEINTERFACE:
2737 ((methodinfo *) iptr->val.a)->class->name);
2740 ((methodinfo *) iptr->val.a)->name);
2749 if (deadcode || !iptr->target)
2750 printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2752 printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2761 if (deadcode || !iptr->target)
2762 #if defined(__I386__) || defined(__POWERPC__)
2763 printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2765 printf("(%ld) op1=%d", iptr->val.l, iptr->op1);
2768 #if defined(__I386__) || defined(__POWERPC__)
2769 printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2771 printf("(%ld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2778 case ICMD_IFNONNULL:
2779 case ICMD_IF_ICMPEQ:
2780 case ICMD_IF_ICMPNE:
2781 case ICMD_IF_ICMPLT:
2782 case ICMD_IF_ICMPGE:
2783 case ICMD_IF_ICMPGT:
2784 case ICMD_IF_ICMPLE:
2785 case ICMD_IF_LCMPEQ:
2786 case ICMD_IF_LCMPNE:
2787 case ICMD_IF_LCMPLT:
2788 case ICMD_IF_LCMPGE:
2789 case ICMD_IF_LCMPGT:
2790 case ICMD_IF_LCMPLE:
2791 case ICMD_IF_ACMPEQ:
2792 case ICMD_IF_ACMPNE:
2793 if (deadcode || !iptr->target)
2794 printf(" op1=%d", iptr->op1);
2796 printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2799 case ICMD_TABLESWITCH:
2800 s4ptr = (s4*)iptr->val.a;
2802 if (deadcode || !iptr->target) {
2803 printf(" %d;", *s4ptr);
2806 tptr = (void **) iptr->target;
2807 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2811 s4ptr++; /* skip default */
2812 j = *s4ptr++; /* low */
2813 j = *s4ptr++ - j; /* high */
2815 if (deadcode || !*tptr)
2816 printf(" %d", *s4ptr++);
2818 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2825 case ICMD_LOOKUPSWITCH:
2826 s4ptr = (s4*)iptr->val.a;
2828 if (deadcode || !iptr->target) {
2829 printf(" %d;", *s4ptr);
2832 tptr = (void **) iptr->target;
2833 printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2836 s4ptr++; /* default */
2837 j = *s4ptr++; /* count */
2840 if (deadcode || !*tptr) {
2841 s4ptr++; /* skip value */
2842 printf(" %d",*s4ptr++);
2845 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2851 printf(" Line number: %d, method:",iptr->line);
2852 utf_display(iptr->method->class->name);
2854 utf_display(iptr->method->name);
2859 * These are local overrides for various environment variables in Emacs.
2860 * Please do not remove this and leave it at the end of the file, where
2861 * Emacs will automagically detect them.
2862 * ---------------------------------------------------------------------
2865 * indent-tabs-mode: t