1 /* src/vm/jit/stack.c - stack analysis
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
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., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Andreas Krall
29 Changes: Edwin Steiner
33 $Id: stack.c 5375 2006-09-06 16:01:23Z edwin $
49 #include "mm/memory.h"
50 #include "native/native.h"
51 #include "toolbox/logging.h"
52 #include "vm/global.h"
53 #include "vm/builtin.h"
54 #include "vm/options.h"
55 #include "vm/resolve.h"
56 #include "vm/statistics.h"
57 #include "vm/stringlocal.h"
58 #include "vm/jit/cfg.h"
59 #include "vm/jit/codegen-common.h"
60 #include "vm/jit/abi.h"
61 #include "vm/jit/show.h"
63 #if defined(ENABLE_DISASSEMBLER)
64 # include "vm/jit/disass.h"
67 #include "vm/jit/jit.h"
68 #include "vm/jit/stack.h"
70 #if defined(ENABLE_LSRA)
71 # include "vm/jit/allocator/lsra.h"
74 /*#define STACK_VERBOSE*/
77 /* macro for saving #ifdefs ***************************************************/
79 #if defined(ENABLE_INTRP)
80 #define IF_INTRP(x) if (opt_intrp) { x }
81 #define IF_NO_INTRP(x) if (!opt_intrp) { x }
84 #define IF_NO_INTRP(x) { x }
87 #if defined(ENABLE_INTRP)
88 #if defined(ENABLE_JIT)
89 #define IF_JIT(x) if (!opt_intrp) { x }
93 #else /* !defined(ENABLE_INTRP) */
94 #define IF_JIT(x) { x }
95 #endif /* defined(ENABLE_INTRP) */
97 #if defined(ENABLE_STATISTICS)
98 #define STATISTICS_STACKDEPTH_DISTRIBUTION(distr) \
101 if (stackdepth >= 10) \
102 count_store_depth[10]++; \
104 count_store_depth[stackdepth]++; \
107 #else /* !defined(ENABLE_STATISTICS) */
108 #define STATISTICS_STACKDEPTH_DISTRIBUTION(distr)
111 /* stack_init ******************************************************************
113 Initialized the stack analysis subsystem (called by jit_init).
115 *******************************************************************************/
117 bool stack_init(void)
123 /* stack_analyse ***************************************************************
125 Analyse_stack uses the intermediate code created by parse.c to
126 build a model of the JVM operand stack for the current method.
128 The following checks are performed:
129 - check for operand stack underflow (before each instruction)
130 - check for operand stack overflow (after[1] each instruction)
131 - check for matching stack depth at merging points
132 - check for matching basic types[2] at merging points
133 - check basic types for instruction input (except for BUILTIN*
134 opcodes, INVOKE* opcodes and MULTIANEWARRAY)
136 [1]) Checking this after the instruction should be ok. parse.c
137 counts the number of required stack slots in such a way that it is
138 only vital that we don't exceed `maxstack` at basic block
141 [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
142 DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
143 types are not discerned.
145 *******************************************************************************/
147 #define GET_NEW_INDEX(new_varindex) \
149 assert(jd->vartop < jd->varcount); \
150 (new_varindex) = (jd->vartop)++; \
153 /* not implemented now, can be used to reuse varindices */
154 #define RELEASE_INDEX(varindex)
157 (iptr->s1.varindex = -1)
159 #define USE_S1_LOCAL(type1)
161 #define USE_S1(type1) \
164 CHECK_BASIC_TYPE(type1, curstack->type); \
165 iptr->s1.varindex = curstack->varnum; \
171 iptr->s1.varindex = curstack->varnum; \
174 #define USE_S1_S2(type1, type2) \
177 CHECK_BASIC_TYPE(type1, curstack->prev->type); \
178 CHECK_BASIC_TYPE(type2, curstack->type); \
179 iptr->sx.s23.s2.varindex = curstack->varnum; \
180 iptr->s1.varindex = curstack->prev->varnum; \
183 #define USE_S1_S2_ANY_ANY \
186 iptr->sx.s23.s2.varindex = curstack->varnum; \
187 iptr->s1.varindex = curstack->prev->varnum; \
190 #define USE_S1_S2_S3(type1, type2, type3) \
193 CHECK_BASIC_TYPE(type1, curstack->prev->prev->type); \
194 CHECK_BASIC_TYPE(type2, curstack->prev->type); \
195 CHECK_BASIC_TYPE(type3, curstack->type); \
196 iptr->sx.s23.s3.varindex = curstack->varnum; \
197 iptr->sx.s23.s2.varindex = curstack->prev->varnum; \
198 iptr->s1.varindex = curstack->prev->prev->varnum; \
202 (iptr->dst.varindex = -1)
204 #define DST(typed, varindex) \
206 NEWSTACKn((varindex)); \
207 iptr->dst.varindex = (varindex); \
210 #define DST_LOCALVAR(typed, index) \
212 NEWSTACK(typed, LOCALVAR, (index)); \
213 iptr->dst.varindex = (index); \
216 #define OP0_1(typed) \
219 GET_NEW_INDEX(new_index); \
220 DST(typed, new_index); \
231 #define OP1_BRANCH(type1) \
237 #define OP1_1(type1, typed) \
240 GET_NEW_INDEX(new_index); \
241 DST(typed, new_index; \
244 #define OP2_1(type1, type2, typed) \
246 POP_S1_S2(type1, type2); \
247 GET_NEW_INDEX(new_index); \
248 DST(typed, new_index); \
252 #define DUP_SLOT(sp) \
254 if ((sp)->varkind != TEMPVAR) { \
255 GET_NEW_INDEX(new_index); \
256 NEWSTACK((sp)->type, TEMPVAR, new_index); \
259 NEWSTACK((sp)->type, (sp)->varkind, (sp)->varnum); \
262 #else /* defined(NEW_VAR) */
265 (iptr->s1.var = NULL)
267 #define USE_S1_LOCAL(type1)
269 #define USE_S1(type1) \
272 CHECK_BASIC_TYPE(type1, curstack->type); \
273 iptr->s1.var = curstack; \
279 iptr->s1.var = curstack; \
282 #define USE_S1_S2(type1, type2) \
285 CHECK_BASIC_TYPE(type1, curstack->prev->type); \
286 CHECK_BASIC_TYPE(type2, curstack->type); \
287 iptr->sx.s23.s2.var = curstack; \
288 iptr->s1.var = curstack->prev; \
291 #define USE_S1_S2_ANY_ANY \
294 iptr->sx.s23.s2.var = curstack; \
295 iptr->s1.var = curstack->prev; \
298 #define USE_S1_S2_S3(type1, type2, type3) \
301 CHECK_BASIC_TYPE(type1, curstack->prev->prev->type); \
302 CHECK_BASIC_TYPE(type2, curstack->prev->type); \
303 CHECK_BASIC_TYPE(type3, curstack->type); \
304 iptr->sx.s23.s3.var = curstack; \
305 iptr->sx.s23.s2.var = curstack->prev; \
306 iptr->s1.var = curstack->prev->prev; \
310 (iptr->dst.var = NULL)
312 #define DST(typed, depth) \
314 NEWSTACKn(typed, (depth)); \
315 iptr->dst.var = curstack; \
318 #define DST_LOCALVAR(typed, index) \
320 NEWSTACK(typed, LOCALVAR, (index)); \
321 iptr->dst.var = curstack; \
324 #define OP0_1(typed) \
327 DST(typed, stackdepth); \
338 #define OP1_BRANCH(type1) \
344 #define OP1_1(type1, typed) \
347 DST(typed, stackdepth - 1); \
350 #define OP2_1(type1, type2, typed) \
352 POP_S1_S2(type1, type2); \
353 DST(typed, stackdepth - 2); \
357 #define DUP_SLOT(sp) \
359 if ((sp)->varkind != TEMPVAR) \
360 NEWSTACK((sp)->type, TEMPVAR, stackdepth); \
362 NEWSTACK((sp)->type, (sp)->varkind, (sp)->varnum); \
365 #endif /* defined(NEW_VAR) */
368 #define POP_S1(type1) \
371 if (curstack->varkind == UNDEFVAR) \
372 curstack->varkind = TEMPVAR; \
373 curstack = curstack->prev; \
379 if (curstack->varkind == UNDEFVAR) \
380 curstack->varkind = TEMPVAR; \
381 curstack = curstack->prev; \
384 #define POP_S1_S2(type1, type2) \
386 USE_S1_S2(type1, type2); \
387 if (curstack->varkind == UNDEFVAR) \
388 curstack->varkind = TEMPVAR; \
389 if (curstack->prev->varkind == UNDEFVAR) \
390 curstack->prev->varkind = TEMPVAR; \
391 curstack = curstack->prev->prev; \
394 #define POP_S1_S2_ANY_ANY \
397 if (curstack->varkind == UNDEFVAR) \
398 curstack->varkind = TEMPVAR; \
399 if (curstack->prev->varkind == UNDEFVAR) \
400 curstack->prev->varkind = TEMPVAR; \
401 curstack = curstack->prev->prev; \
404 #define POP_S1_S2_S3(type1, type2, type3) \
406 USE_S1_S2_S3(type1, type2, type3); \
407 if (curstack->varkind == UNDEFVAR) \
408 curstack->varkind = TEMPVAR; \
409 if (curstack->prev->varkind == UNDEFVAR) \
410 curstack->prev->varkind = TEMPVAR; \
411 if (curstack->prev->prev->varkind == UNDEFVAR) \
412 curstack->prev->prev->varkind = TEMPVAR; \
413 curstack = curstack->prev->prev->prev; \
430 #define OP1_0(type1) \
437 #define OP2_0(type1, type2) \
439 POP_S1_S2(type1, type2); \
444 #define OP2_BRANCH(type1, type2) \
446 POP_S1_S2(type1, type2); \
450 #define OP2_0_ANY_ANY \
457 #define OP3_0(type1, type2, type3) \
459 POP_S1_S2_S3(type1, type2, type3); \
464 #define LOAD(type1, index) \
466 DST_LOCALVAR(type1, index); \
470 #define STORE(type1, index) \
476 #define BRANCH_TARGET(bt, tempbptr, tempsp) \
478 (bt).block = tempbptr = BLOCK_OF((bt).insindex); \
479 MARKREACHED(tempbptr, tempsp); \
482 #define BRANCH(tempbptr, tempsp) \
484 iptr->dst.block = tempbptr = BLOCK_OF(iptr->dst.insindex); \
485 MARKREACHED(tempbptr, tempsp); \
488 bool new_stack_analyse(jitdata *jd)
490 methodinfo *m; /* method being analyzed */
494 int b_count; /* basic block counter */
495 int b_index; /* basic block index */
497 stackptr curstack; /* current stack top */
500 int opcode; /* opcode of current instruction */
502 int len; /* # of instructions after the current one */
503 bool superblockend; /* if true, no fallthrough to next block */
504 bool repeat; /* if true, outermost loop must run again */
505 bool deadcode; /* true if no live code has been reached */
506 instruction *iptr; /* the current instruction */
507 basicblock *bptr; /* the current basic block */
510 stackptr *last_store_boundary;
511 stackptr last_pei_boundary;
512 stackptr last_dup_boundary;
514 branch_target_t *table;
515 lookup_target_t *lookup;
516 #if defined(ENABLE_VERIFIER)
517 int expectedtype; /* used by CHECK_BASIC_TYPE */
519 builtintable_entry *bte;
521 constant_FMIref *fmiref;
522 #if defined(ENABLE_STATISTICS)
523 int iteration_count; /* number of iterations of analysis */
526 int new_index; /* used to get a new var index with GET_NEW_INDEX*/
528 #if defined(STACK_VERBOSE)
529 new_show_method(jd, SHOW_PARSE);
532 /* get required compiler data - initialization */
539 #if defined(ENABLE_LSRA)
543 #if defined(ENABLE_STATISTICS)
548 last_store_boundary = DMNEW(stackptr, jd->localcount);
550 last_store_boundary = DMNEW(stackptr , cd->maxlocals);
553 /* initialize in-stack of first block */
556 jd->new_basicblocks[0].flags = BBREACHED;
557 jd->new_basicblocks[0].instack = NULL;
558 jd->new_basicblocks[0].invars = NULL;
559 jd->new_basicblocks[0].indepth = 0;
561 /* initialize in-stack of exception handlers */
563 for (i = 0; i < cd->exceptiontablelength; i++) {
564 bptr = BLOCK_OF(cd->exceptiontable[i].handlerpc);
565 bptr->flags = BBREACHED;
566 bptr->type = BBTYPE_EXH;
569 bptr->predecessorcount = CFG_UNKNOWN_PREDECESSORS;
572 GET_NEW_INDEX(new_index);
573 bptr->invars = DMNEW(s4, 1);
574 bptr->invars[0] = new_index;
575 NEWSTACK(TYPE_ADR, STACKVAR,new_index);
577 bptr->invars = DMNEW(stackptr, 1);
578 bptr->invars[0] = new;
583 /* count predecessors of each block ***************************************/
585 #if CONDITIONAL_LOADCONST
586 /* XXX move this to a separate function */
588 b_count = jd->new_basicblockcount;
589 bptr = jd->new_basicblocks;
590 for (; --b_count >= 0; bptr++) {
591 if (bptr->icount == 0)
594 /* get the last instruction of the block */
596 iptr = bptr->iinstr + (bptr->icount - 1);
599 /* instruction stopping control flow */
610 /* conditional branches */
627 /* XXX add missing conditional branches */
628 bptr[1].predecessorcount++;
631 /* unconditional branch */
633 BLOCK_OF(iptr->dst.insindex)->predecessorcount++;
637 case ICMD_TABLESWITCH:
638 table = iptr->dst.table;
639 BLOCK_OF((table++)->insindex)->predecessorcount++;
640 i = iptr->sx.s23.s3.tablehigh
641 - iptr->sx.s23.s2.tablelow + 1;
643 BLOCK_OF((table++)->insindex)->predecessorcount++;
647 case ICMD_LOOKUPSWITCH:
648 lookup = iptr->dst.lookup;
649 BLOCK_OF(iptr->sx.s23.s3.lookupdefault.insindex)->predecessorcount++;
650 i = iptr->sx.s23.s2.lookupcount;
652 BLOCK_OF((lookup++)->target.insindex)->predecessorcount++;
656 /* default - fall into next block */
658 bptr[1].predecessorcount++;
661 } /* end basic block loop */
663 #endif /* CONDITIONAL_LOADCONST */
665 /* stack analysis loop (until fixpoint reached) **************************/
668 #if defined(ENABLE_STATISTICS)
672 /* initialize loop over basic blocks */
674 b_count = jd->new_basicblockcount;
675 bptr = jd->new_basicblocks;
676 superblockend = true;
681 /* iterate over basic blocks *****************************************/
683 while (--b_count >= 0) {
684 #if defined(STACK_VERBOSE)
685 printf("ANALYZING BLOCK L%03d\n", bptr->nr);
688 if (bptr->flags == BBDELETED) {
689 /* This block has been deleted - do nothing. */
691 else if (superblockend && (bptr->flags < BBREACHED)) {
692 /* This block has not been reached so far, and we */
693 /* don't fall into it, so we'll have to iterate again. */
696 else if (bptr->flags <= BBREACHED) {
698 /* We know that bptr->flags == BBREACHED. */
699 /* This block has been reached before. */
700 stackdepth = bptr->indepth;
702 else if (bptr->flags < BBREACHED) {
703 /* This block is reached for the first time now */
704 /* by falling through from the previous block. */
706 bptr->instack = copy;
709 bptr->invars = DMNEW(s4, stackdepth);
710 for (i=stackdepth; i--; copy = copy->prev)
711 bptr->invars[i] = copy->varnum;
713 bptr->invars = DMNEW(stackptr, stackdepth);
714 for (i=stackdepth; i--; copy = copy->prev)
715 bptr->invars[i] = copy;
717 bptr->indepth = stackdepth;
720 /* This block has been reached before. now we are */
721 /* falling into it from the previous block. */
722 /* Check that stack depth is well-defined. */
723 CHECK_STACK_DEPTH(bptr->indepth, stackdepth);
726 /* set up local variables for analyzing this block */
728 curstack = bptr->instack;
730 superblockend = false;
731 bptr->flags = BBFINISHED;
734 b_index = bptr - jd->new_basicblocks;
736 /* reset variables for dependency checking */
738 last_pei_boundary = new;
739 last_dup_boundary = new;
740 for( i = 0; i < cd->maxlocals; i++)
741 last_store_boundary[i] = new;
743 /* XXX store the start of the block's stack representation */
747 /* iterate over ICMDs ****************************************/
750 #if defined(STACK_VERBOSE)
751 new_show_icmd(jd, iptr, false, SHOW_PARSE); printf("\n");
752 for( copy = curstack; copy; copy = copy->prev ) {
753 printf("%d ", copy->type);
758 /* fetch the current opcode */
762 /* automatically replace some ICMDs with builtins */
764 #if defined(USEBUILTINTABLE)
766 bte = builtintable_get_automatic(opcode);
768 if (bte && bte->opcode == opcode) {
769 iptr->opc = ICMD_BUILTIN;
770 iptr->flags.bits = 0;
771 iptr->sx.s23.s3.bte = bte;
772 /* iptr->line is already set */
773 jd->isleafmethod = false;
777 #endif /* defined(USEBUILTINTABLE) */
779 /* main opcode switch *************************************/
792 last_pei_boundary = new;
793 COUNT(count_check_null);
796 CLR_DST; /* XXX live through? */
800 USE_S1_LOCAL(TYPE_ADR);
803 #if !defined(NEW_VAR)
804 IF_NO_INTRP( rd->locals[iptr->s1.localindex][TYPE_ADR].type = TYPE_ADR; );
806 superblockend = true;
810 COUNT(count_pcmd_return);
813 superblockend = true;
817 /* pop 0 push 1 const */
819 /************************** ICONST OPTIMIZATIONS **************************/
822 COUNT(count_pcmd_load);
826 switch (iptr[1].opc) {
828 iptr->opc = ICMD_IADDCONST;
832 iptr[1].opc = ICMD_NOP;
833 OP1_1(TYPE_INT, TYPE_INT);
834 COUNT(count_pcmd_op);
838 iptr->opc = ICMD_ISUBCONST;
839 goto icmd_iconst_tail;
840 #if SUPPORT_CONST_MUL
842 iptr->opc = ICMD_IMULCONST;
843 goto icmd_iconst_tail;
844 #else /* SUPPORT_CONST_MUL */
846 if (iptr->sx.val.i == 0x00000002)
848 else if (iptr->sx.val.i == 0x00000004)
850 else if (iptr->sx.val.i == 0x00000008)
852 else if (iptr->sx.val.i == 0x00000010)
854 else if (iptr->sx.val.i == 0x00000020)
856 else if (iptr->sx.val.i == 0x00000040)
858 else if (iptr->sx.val.i == 0x00000080)
860 else if (iptr->sx.val.i == 0x00000100)
862 else if (iptr->sx.val.i == 0x00000200)
864 else if (iptr->sx.val.i == 0x00000400)
866 else if (iptr->sx.val.i == 0x00000800)
868 else if (iptr->sx.val.i == 0x00001000)
870 else if (iptr->sx.val.i == 0x00002000)
872 else if (iptr->sx.val.i == 0x00004000)
874 else if (iptr->sx.val.i == 0x00008000)
876 else if (iptr->sx.val.i == 0x00010000)
878 else if (iptr->sx.val.i == 0x00020000)
880 else if (iptr->sx.val.i == 0x00040000)
882 else if (iptr->sx.val.i == 0x00080000)
884 else if (iptr->sx.val.i == 0x00100000)
886 else if (iptr->sx.val.i == 0x00200000)
888 else if (iptr->sx.val.i == 0x00400000)
890 else if (iptr->sx.val.i == 0x00800000)
892 else if (iptr->sx.val.i == 0x01000000)
894 else if (iptr->sx.val.i == 0x02000000)
896 else if (iptr->sx.val.i == 0x04000000)
898 else if (iptr->sx.val.i == 0x08000000)
900 else if (iptr->sx.val.i == 0x10000000)
902 else if (iptr->sx.val.i == 0x20000000)
904 else if (iptr->sx.val.i == 0x40000000)
906 else if (iptr->sx.val.i == 0x80000000)
911 iptr->opc = ICMD_IMULPOW2;
912 goto icmd_iconst_tail;
913 #endif /* SUPPORT_CONST_MUL */
915 if (iptr->sx.val.i == 0x00000002)
917 else if (iptr->sx.val.i == 0x00000004)
919 else if (iptr->sx.val.i == 0x00000008)
921 else if (iptr->sx.val.i == 0x00000010)
923 else if (iptr->sx.val.i == 0x00000020)
925 else if (iptr->sx.val.i == 0x00000040)
927 else if (iptr->sx.val.i == 0x00000080)
929 else if (iptr->sx.val.i == 0x00000100)
931 else if (iptr->sx.val.i == 0x00000200)
933 else if (iptr->sx.val.i == 0x00000400)
935 else if (iptr->sx.val.i == 0x00000800)
937 else if (iptr->sx.val.i == 0x00001000)
939 else if (iptr->sx.val.i == 0x00002000)
941 else if (iptr->sx.val.i == 0x00004000)
943 else if (iptr->sx.val.i == 0x00008000)
945 else if (iptr->sx.val.i == 0x00010000)
947 else if (iptr->sx.val.i == 0x00020000)
949 else if (iptr->sx.val.i == 0x00040000)
951 else if (iptr->sx.val.i == 0x00080000)
953 else if (iptr->sx.val.i == 0x00100000)
955 else if (iptr->sx.val.i == 0x00200000)
957 else if (iptr->sx.val.i == 0x00400000)
959 else if (iptr->sx.val.i == 0x00800000)
961 else if (iptr->sx.val.i == 0x01000000)
963 else if (iptr->sx.val.i == 0x02000000)
965 else if (iptr->sx.val.i == 0x04000000)
967 else if (iptr->sx.val.i == 0x08000000)
969 else if (iptr->sx.val.i == 0x10000000)
971 else if (iptr->sx.val.i == 0x20000000)
973 else if (iptr->sx.val.i == 0x40000000)
975 else if (iptr->sx.val.i == 0x80000000)
980 iptr->opc = ICMD_IDIVPOW2;
981 goto icmd_iconst_tail;
984 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
985 if ((iptr->sx.val.i == 0x00000002) ||
986 (iptr->sx.val.i == 0x00000004) ||
987 (iptr->sx.val.i == 0x00000008) ||
988 (iptr->sx.val.i == 0x00000010) ||
989 (iptr->sx.val.i == 0x00000020) ||
990 (iptr->sx.val.i == 0x00000040) ||
991 (iptr->sx.val.i == 0x00000080) ||
992 (iptr->sx.val.i == 0x00000100) ||
993 (iptr->sx.val.i == 0x00000200) ||
994 (iptr->sx.val.i == 0x00000400) ||
995 (iptr->sx.val.i == 0x00000800) ||
996 (iptr->sx.val.i == 0x00001000) ||
997 (iptr->sx.val.i == 0x00002000) ||
998 (iptr->sx.val.i == 0x00004000) ||
999 (iptr->sx.val.i == 0x00008000) ||
1000 (iptr->sx.val.i == 0x00010000) ||
1001 (iptr->sx.val.i == 0x00020000) ||
1002 (iptr->sx.val.i == 0x00040000) ||
1003 (iptr->sx.val.i == 0x00080000) ||
1004 (iptr->sx.val.i == 0x00100000) ||
1005 (iptr->sx.val.i == 0x00200000) ||
1006 (iptr->sx.val.i == 0x00400000) ||
1007 (iptr->sx.val.i == 0x00800000) ||
1008 (iptr->sx.val.i == 0x01000000) ||
1009 (iptr->sx.val.i == 0x02000000) ||
1010 (iptr->sx.val.i == 0x04000000) ||
1011 (iptr->sx.val.i == 0x08000000) ||
1012 (iptr->sx.val.i == 0x10000000) ||
1013 (iptr->sx.val.i == 0x20000000) ||
1014 (iptr->sx.val.i == 0x40000000) ||
1015 (iptr->sx.val.i == 0x80000000))
1017 iptr->opc = ICMD_IREMPOW2;
1018 iptr->sx.val.i -= 1;
1019 goto icmd_iconst_tail;
1022 #if SUPPORT_CONST_LOGICAL
1024 iptr->opc = ICMD_IANDCONST;
1025 goto icmd_iconst_tail;
1028 iptr->opc = ICMD_IORCONST;
1029 goto icmd_iconst_tail;
1032 iptr->opc = ICMD_IXORCONST;
1033 goto icmd_iconst_tail;
1035 #endif /* SUPPORT_CONST_LOGICAL */
1037 iptr->opc = ICMD_ISHLCONST;
1038 goto icmd_iconst_tail;
1041 iptr->opc = ICMD_ISHRCONST;
1042 goto icmd_iconst_tail;
1045 iptr->opc = ICMD_IUSHRCONST;
1046 goto icmd_iconst_tail;
1047 #if SUPPORT_LONG_SHIFT
1049 iptr->opc = ICMD_LSHLCONST;
1050 goto icmd_lconst_tail;
1053 iptr->opc = ICMD_LSHRCONST;
1054 goto icmd_lconst_tail;
1057 iptr->opc = ICMD_LUSHRCONST;
1058 goto icmd_lconst_tail;
1059 #endif /* SUPPORT_LONG_SHIFT */
1060 case ICMD_IF_ICMPEQ:
1061 iptr[1].opc = ICMD_IFEQ;
1065 /* set the constant for the following icmd */
1066 iptr[1].sx.val.i = iptr->sx.val.i;
1068 /* this instruction becomes a nop */
1069 iptr->opc = ICMD_NOP;
1072 case ICMD_IF_ICMPLT:
1073 iptr[1].opc = ICMD_IFLT;
1074 goto icmd_if_icmp_tail;
1076 case ICMD_IF_ICMPLE:
1077 iptr[1].opc = ICMD_IFLE;
1078 goto icmd_if_icmp_tail;
1080 case ICMD_IF_ICMPNE:
1081 iptr[1].opc = ICMD_IFNE;
1082 goto icmd_if_icmp_tail;
1084 case ICMD_IF_ICMPGT:
1085 iptr[1].opc = ICMD_IFGT;
1086 goto icmd_if_icmp_tail;
1088 case ICMD_IF_ICMPGE:
1089 iptr[1].opc = ICMD_IFGE;
1090 goto icmd_if_icmp_tail;
1092 #if SUPPORT_CONST_STORE
1097 IF_INTRP( goto normal_ICONST; )
1098 # if SUPPORT_CONST_STORE_ZERO_ONLY
1099 if (iptr->sx.val.i != 0)
1102 switch (iptr[1].opc) {
1104 iptr->opc = ICMD_IASTORECONST;
1105 iptr->flags.bits |= INS_FLAG_CHECK;
1108 iptr->opc = ICMD_BASTORECONST;
1109 iptr->flags.bits |= INS_FLAG_CHECK;
1112 iptr->opc = ICMD_CASTORECONST;
1113 iptr->flags.bits |= INS_FLAG_CHECK;
1116 iptr->opc = ICMD_SASTORECONST;
1117 iptr->flags.bits |= INS_FLAG_CHECK;
1121 iptr[1].opc = ICMD_NOP;
1123 /* copy the constant to s3 */
1124 /* XXX constval -> astoreconstval? */
1125 iptr->sx.s23.s3.constval = iptr->sx.val.i;
1126 OP2_0(TYPE_ADR, TYPE_INT);
1127 COUNT(count_pcmd_op);
1130 case ICMD_PUTSTATIC:
1132 IF_INTRP( goto normal_ICONST; )
1133 # if SUPPORT_CONST_STORE_ZERO_ONLY
1134 if (iptr->sx.val.i != 0)
1137 /* XXX check field type? */
1139 /* copy the constant to s2 */
1140 /* XXX constval -> fieldconstval? */
1141 iptr->sx.s23.s2.constval = iptr->sx.val.i;
1144 /* set the field reference (s3) */
1145 if (iptr[1].flags.bits & INS_FLAG_UNRESOLVED) {
1146 iptr->sx.s23.s3.uf = iptr[1].sx.s23.s3.uf;
1147 iptr->flags.bits |= INS_FLAG_UNRESOLVED;
1150 iptr->sx.s23.s3.fmiref = iptr[1].sx.s23.s3.fmiref;
1153 switch (iptr[1].opc) {
1154 case ICMD_PUTSTATIC:
1155 iptr->opc = ICMD_PUTSTATICCONST;
1159 iptr->opc = ICMD_PUTFIELDCONST;
1164 iptr[1].opc = ICMD_NOP;
1165 COUNT(count_pcmd_op);
1167 #endif /* SUPPORT_CONST_STORE */
1173 /* if we get here, the ICONST has been optimized */
1177 /* normal case of an unoptimized ICONST */
1181 /************************** LCONST OPTIMIZATIONS **************************/
1184 COUNT(count_pcmd_load);
1188 /* switch depending on the following instruction */
1190 switch (iptr[1].opc) {
1191 #if SUPPORT_LONG_ADD
1193 iptr->opc = ICMD_LADDCONST;
1197 /* instruction of type LONG -> LONG */
1198 iptr[1].opc = ICMD_NOP;
1199 OP1_1(TYPE_LNG, TYPE_LNG);
1200 COUNT(count_pcmd_op);
1204 iptr->opc = ICMD_LSUBCONST;
1205 goto icmd_lconst_tail;
1207 #endif /* SUPPORT_LONG_ADD */
1208 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
1210 iptr->opc = ICMD_LMULCONST;
1211 goto icmd_lconst_tail;
1212 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1213 # if SUPPORT_LONG_SHIFT
1215 if (iptr->sx.val.l == 0x00000002)
1217 else if (iptr->sx.val.l == 0x00000004)
1219 else if (iptr->sx.val.l == 0x00000008)
1221 else if (iptr->sx.val.l == 0x00000010)
1223 else if (iptr->sx.val.l == 0x00000020)
1225 else if (iptr->sx.val.l == 0x00000040)
1227 else if (iptr->sx.val.l == 0x00000080)
1229 else if (iptr->sx.val.l == 0x00000100)
1231 else if (iptr->sx.val.l == 0x00000200)
1233 else if (iptr->sx.val.l == 0x00000400)
1234 iptr->sx.val.i = 10;
1235 else if (iptr->sx.val.l == 0x00000800)
1236 iptr->sx.val.i = 11;
1237 else if (iptr->sx.val.l == 0x00001000)
1238 iptr->sx.val.i = 12;
1239 else if (iptr->sx.val.l == 0x00002000)
1240 iptr->sx.val.i = 13;
1241 else if (iptr->sx.val.l == 0x00004000)
1242 iptr->sx.val.i = 14;
1243 else if (iptr->sx.val.l == 0x00008000)
1244 iptr->sx.val.i = 15;
1245 else if (iptr->sx.val.l == 0x00010000)
1246 iptr->sx.val.i = 16;
1247 else if (iptr->sx.val.l == 0x00020000)
1248 iptr->sx.val.i = 17;
1249 else if (iptr->sx.val.l == 0x00040000)
1250 iptr->sx.val.i = 18;
1251 else if (iptr->sx.val.l == 0x00080000)
1252 iptr->sx.val.i = 19;
1253 else if (iptr->sx.val.l == 0x00100000)
1254 iptr->sx.val.i = 20;
1255 else if (iptr->sx.val.l == 0x00200000)
1256 iptr->sx.val.i = 21;
1257 else if (iptr->sx.val.l == 0x00400000)
1258 iptr->sx.val.i = 22;
1259 else if (iptr->sx.val.l == 0x00800000)
1260 iptr->sx.val.i = 23;
1261 else if (iptr->sx.val.l == 0x01000000)
1262 iptr->sx.val.i = 24;
1263 else if (iptr->sx.val.l == 0x02000000)
1264 iptr->sx.val.i = 25;
1265 else if (iptr->sx.val.l == 0x04000000)
1266 iptr->sx.val.i = 26;
1267 else if (iptr->sx.val.l == 0x08000000)
1268 iptr->sx.val.i = 27;
1269 else if (iptr->sx.val.l == 0x10000000)
1270 iptr->sx.val.i = 28;
1271 else if (iptr->sx.val.l == 0x20000000)
1272 iptr->sx.val.i = 29;
1273 else if (iptr->sx.val.l == 0x40000000)
1274 iptr->sx.val.i = 30;
1275 else if (iptr->sx.val.l == 0x80000000)
1276 iptr->sx.val.i = 31;
1280 iptr->opc = ICMD_LMULPOW2;
1281 goto icmd_lconst_tail;
1282 # endif /* SUPPORT_LONG_SHIFT */
1283 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1284 #if SUPPORT_LONG_DIV_POW2
1286 if (iptr->sx.val.l == 0x00000002)
1288 else if (iptr->sx.val.l == 0x00000004)
1290 else if (iptr->sx.val.l == 0x00000008)
1292 else if (iptr->sx.val.l == 0x00000010)
1294 else if (iptr->sx.val.l == 0x00000020)
1296 else if (iptr->sx.val.l == 0x00000040)
1298 else if (iptr->sx.val.l == 0x00000080)
1300 else if (iptr->sx.val.l == 0x00000100)
1302 else if (iptr->sx.val.l == 0x00000200)
1304 else if (iptr->sx.val.l == 0x00000400)
1305 iptr->sx.val.i = 10;
1306 else if (iptr->sx.val.l == 0x00000800)
1307 iptr->sx.val.i = 11;
1308 else if (iptr->sx.val.l == 0x00001000)
1309 iptr->sx.val.i = 12;
1310 else if (iptr->sx.val.l == 0x00002000)
1311 iptr->sx.val.i = 13;
1312 else if (iptr->sx.val.l == 0x00004000)
1313 iptr->sx.val.i = 14;
1314 else if (iptr->sx.val.l == 0x00008000)
1315 iptr->sx.val.i = 15;
1316 else if (iptr->sx.val.l == 0x00010000)
1317 iptr->sx.val.i = 16;
1318 else if (iptr->sx.val.l == 0x00020000)
1319 iptr->sx.val.i = 17;
1320 else if (iptr->sx.val.l == 0x00040000)
1321 iptr->sx.val.i = 18;
1322 else if (iptr->sx.val.l == 0x00080000)
1323 iptr->sx.val.i = 19;
1324 else if (iptr->sx.val.l == 0x00100000)
1325 iptr->sx.val.i = 20;
1326 else if (iptr->sx.val.l == 0x00200000)
1327 iptr->sx.val.i = 21;
1328 else if (iptr->sx.val.l == 0x00400000)
1329 iptr->sx.val.i = 22;
1330 else if (iptr->sx.val.l == 0x00800000)
1331 iptr->sx.val.i = 23;
1332 else if (iptr->sx.val.l == 0x01000000)
1333 iptr->sx.val.i = 24;
1334 else if (iptr->sx.val.l == 0x02000000)
1335 iptr->sx.val.i = 25;
1336 else if (iptr->sx.val.l == 0x04000000)
1337 iptr->sx.val.i = 26;
1338 else if (iptr->sx.val.l == 0x08000000)
1339 iptr->sx.val.i = 27;
1340 else if (iptr->sx.val.l == 0x10000000)
1341 iptr->sx.val.i = 28;
1342 else if (iptr->sx.val.l == 0x20000000)
1343 iptr->sx.val.i = 29;
1344 else if (iptr->sx.val.l == 0x40000000)
1345 iptr->sx.val.i = 30;
1346 else if (iptr->sx.val.l == 0x80000000)
1347 iptr->sx.val.i = 31;
1351 iptr->opc = ICMD_LDIVPOW2;
1352 goto icmd_lconst_tail;
1353 #endif /* SUPPORT_LONG_DIV_POW2 */
1355 #if SUPPORT_LONG_REM_POW2
1357 if ((iptr->sx.val.l == 0x00000002) ||
1358 (iptr->sx.val.l == 0x00000004) ||
1359 (iptr->sx.val.l == 0x00000008) ||
1360 (iptr->sx.val.l == 0x00000010) ||
1361 (iptr->sx.val.l == 0x00000020) ||
1362 (iptr->sx.val.l == 0x00000040) ||
1363 (iptr->sx.val.l == 0x00000080) ||
1364 (iptr->sx.val.l == 0x00000100) ||
1365 (iptr->sx.val.l == 0x00000200) ||
1366 (iptr->sx.val.l == 0x00000400) ||
1367 (iptr->sx.val.l == 0x00000800) ||
1368 (iptr->sx.val.l == 0x00001000) ||
1369 (iptr->sx.val.l == 0x00002000) ||
1370 (iptr->sx.val.l == 0x00004000) ||
1371 (iptr->sx.val.l == 0x00008000) ||
1372 (iptr->sx.val.l == 0x00010000) ||
1373 (iptr->sx.val.l == 0x00020000) ||
1374 (iptr->sx.val.l == 0x00040000) ||
1375 (iptr->sx.val.l == 0x00080000) ||
1376 (iptr->sx.val.l == 0x00100000) ||
1377 (iptr->sx.val.l == 0x00200000) ||
1378 (iptr->sx.val.l == 0x00400000) ||
1379 (iptr->sx.val.l == 0x00800000) ||
1380 (iptr->sx.val.l == 0x01000000) ||
1381 (iptr->sx.val.l == 0x02000000) ||
1382 (iptr->sx.val.l == 0x04000000) ||
1383 (iptr->sx.val.l == 0x08000000) ||
1384 (iptr->sx.val.l == 0x10000000) ||
1385 (iptr->sx.val.l == 0x20000000) ||
1386 (iptr->sx.val.l == 0x40000000) ||
1387 (iptr->sx.val.l == 0x80000000))
1389 iptr->opc = ICMD_LREMPOW2;
1390 iptr->sx.val.l -= 1;
1391 goto icmd_lconst_tail;
1394 #endif /* SUPPORT_LONG_REM_POW2 */
1396 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
1399 iptr->opc = ICMD_LANDCONST;
1400 goto icmd_lconst_tail;
1403 iptr->opc = ICMD_LORCONST;
1404 goto icmd_lconst_tail;
1407 iptr->opc = ICMD_LXORCONST;
1408 goto icmd_lconst_tail;
1409 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
1411 #if SUPPORT_LONG_CMP_CONST
1413 if ((len <= 1) || (iptr[2].sx.val.i != 0))
1416 /* switch on the instruction after LCONST - LCMP */
1418 switch (iptr[2].opc) {
1420 iptr->opc = ICMD_IF_LEQ;
1423 icmd_lconst_lcmp_tail:
1424 /* convert LCONST, LCMP, IFXX to IF_LXX */
1425 iptr->dst.insindex = iptr[2].dst.insindex;
1426 iptr[1].opc = ICMD_NOP;
1427 iptr[2].opc = ICMD_NOP;
1429 OP1_BRANCH(TYPE_LNG);
1430 BRANCH(tbptr, copy);
1431 COUNT(count_pcmd_bra);
1432 COUNT(count_pcmd_op);
1436 iptr->opc = ICMD_IF_LNE;
1437 goto icmd_lconst_lcmp_tail;
1440 iptr->opc = ICMD_IF_LLT;
1441 goto icmd_lconst_lcmp_tail;
1444 iptr->opc = ICMD_IF_LGT;
1445 goto icmd_lconst_lcmp_tail;
1448 iptr->opc = ICMD_IF_LLE;
1449 goto icmd_lconst_lcmp_tail;
1452 iptr->opc = ICMD_IF_LGE;
1453 goto icmd_lconst_lcmp_tail;
1457 } /* end switch on opcode after LCONST - LCMP */
1459 #endif /* SUPPORT_LONG_CMP_CONST */
1461 #if SUPPORT_CONST_STORE
1463 IF_INTRP( goto normal_LCONST; )
1464 # if SUPPORT_CONST_STORE_ZERO_ONLY
1465 if (iptr->sx.val.l != 0)
1468 #if SIZEOF_VOID_P == 4
1469 /* the constant must fit into a ptrint */
1470 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1473 /* move the constant to s3 */
1474 iptr->sx.s23.s3.constval = iptr->sx.val.l;
1476 iptr->opc = ICMD_LASTORECONST;
1477 iptr->flags.bits |= INS_FLAG_CHECK;
1478 OP2_0(TYPE_ADR, TYPE_INT);
1480 iptr[1].opc = ICMD_NOP;
1481 COUNT(count_pcmd_op);
1484 case ICMD_PUTSTATIC:
1486 IF_INTRP( goto normal_LCONST; )
1487 # if SUPPORT_CONST_STORE_ZERO_ONLY
1488 if (iptr->sx.val.l != 0)
1491 #if SIZEOF_VOID_P == 4
1492 /* the constant must fit into a ptrint */
1493 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1496 /* XXX check field type? */
1498 /* copy the constant to s2 */
1499 /* XXX constval -> fieldconstval? */
1500 iptr->sx.s23.s2.constval = iptr->sx.val.l;
1504 #endif /* SUPPORT_CONST_STORE */
1508 } /* end switch opcode after LCONST */
1510 /* if we get here, the LCONST has been optimized */
1514 /* the normal case of an unoptimized LCONST */
1518 /************************ END OF LCONST OPTIMIZATIONS *********************/
1521 COUNT(count_pcmd_load);
1526 COUNT(count_pcmd_load);
1530 /************************** ACONST OPTIMIZATIONS **************************/
1533 last_pei_boundary = new;
1534 COUNT(count_pcmd_load);
1535 #if SUPPORT_CONST_STORE
1536 IF_INTRP( goto normal_ACONST; )
1538 /* We can only optimize if the ACONST is resolved
1539 * and there is an instruction after it. */
1541 if ((len == 0) || (iptr->flags.bits & INS_FLAG_UNRESOLVED))
1544 switch (iptr[1].opc) {
1546 /* We can only optimize for NULL values
1547 * here because otherwise a checkcast is
1549 if (iptr->sx.val.anyptr != NULL)
1552 /* copy the constant (NULL) to s3 */
1553 iptr->sx.s23.s3.constval = 0;
1554 iptr->opc = ICMD_AASTORECONST;
1555 iptr->flags.bits |= INS_FLAG_CHECK;
1556 OP2_0(TYPE_ADR, TYPE_INT);
1558 iptr[1].opc = ICMD_NOP;
1559 COUNT(count_pcmd_op);
1562 case ICMD_PUTSTATIC:
1564 # if SUPPORT_CONST_STORE_ZERO_ONLY
1565 if (iptr->sx.val.anyptr != NULL)
1568 /* XXX check field type? */
1569 /* copy the constant to s2 */
1570 /* XXX constval -> fieldconstval? */
1571 iptr->sx.s23.s2.constval = (ptrint) iptr->sx.val.anyptr;
1579 /* if we get here the ACONST has been optimized */
1583 #endif /* SUPPORT_CONST_STORE */
1588 /* pop 0 push 1 load */
1595 COUNT(count_load_instruction);
1596 i = opcode - ICMD_ILOAD;
1597 #if defined(NEW_VAR)
1599 jd->local_map[iptr->s1.varindex * 5 + i];
1601 LOAD(i, iptr->s1.varindex);
1604 IF_NO_INTRP( rd->locals[iptr->s1.localindex][i].type =
1606 LOAD(i, iptr->s1.localindex);
1616 last_pei_boundary = new;
1617 iptr->flags.bits |= INS_FLAG_CHECK;
1618 COUNT(count_check_null);
1619 COUNT(count_check_bound);
1620 COUNT(count_pcmd_mem);
1621 OP2_1(TYPE_ADR, TYPE_INT, opcode - ICMD_IALOAD);
1628 last_pei_boundary = new;
1629 iptr->flags.bits |= INS_FLAG_CHECK;
1630 COUNT(count_check_null);
1631 COUNT(count_check_bound);
1632 COUNT(count_pcmd_mem);
1633 OP2_1(TYPE_ADR, TYPE_INT, TYPE_INT);
1636 /* pop 0 push 0 iinc */
1639 STATISTICS_STACKDEPTH_DISTRIBUTION(count_store_depth);
1641 #if defined(NEW_VAR)
1643 jd->local_map[iptr->s1.varindex * 5 + i];
1645 last_store_boundary[iptr->s1.varindex] = new;
1647 last_store_boundary[iptr->s1.localindex] = new;
1653 if ((copy->varkind == LOCALVAR) &&
1654 (copy->varnum == iptr->s1.localindex))
1656 copy->varkind = TEMPVAR;
1657 #if defined(NEW_VAR)
1658 GET_NEW_INDEX(new_index);
1659 copy->varnum = new_index;
1668 #if defined(NEW_VAR)
1669 iptr->dst.varindex = iptr->s1.varindex;
1671 iptr->dst.localindex = iptr->s1.localindex;
1675 /* pop 1 push 0 store */
1684 i = opcode - ICMD_ISTORE; /* type */
1685 #if defined(NEW_VAR)
1686 j = iptr->dst.varindex =
1687 jd->local_map[iptr->dst.varindex * 5 + 1]:
1690 j = iptr->dst.localindex; /* index */
1692 IF_NO_INTRP( rd->locals[j][i].type = i; )
1695 #if defined(ENABLE_STATISTICS)
1700 count_store_length[20]++;
1702 count_store_length[i]++;
1705 count_store_depth[10]++;
1707 count_store_depth[i]++;
1710 /* check for conflicts as described in Figure 5.2 */
1712 copy = curstack->prev;
1715 if ((copy->varkind == LOCALVAR) &&
1716 (copy->varnum == j))
1718 copy->varkind = TEMPVAR;
1719 #if defined(NEW_VAR)
1720 GET_NEW_INDEX(new_index);
1721 copy->varnum = new_index;
1730 /* if the variable is already coalesced, don't bother */
1732 if (curstack->varkind == STACKVAR
1733 || (curstack->varkind == LOCALVAR
1734 && curstack->varnum != j))
1737 /* there is no STORE Lj while curstack is live */
1739 if (curstack < last_store_boundary[j])
1740 goto assume_conflict;
1742 /* there is no PEI while curstack is live */
1744 if (curstack < last_pei_boundary)
1745 goto assume_conflict;
1747 /* there is no non-consuming USE while curstack is live */
1749 if (curstack < last_dup_boundary)
1750 goto assume_conflict;
1752 /* there is no DEF LOCALVAR(j) while curstack is live */
1754 copy = new; /* most recent stackslot created + 1 */
1755 while (--copy > curstack) {
1756 if (copy->varkind == LOCALVAR && copy->varnum == j)
1757 goto assume_conflict;
1760 /* coalesce the temporary variable with Lj */
1761 #if defined(NEW_VAR)
1762 assert(currstack->varkind == TEMPVAR);
1763 RELEASE_INDEX(curstack->varnum);
1765 curstack->varkind = LOCALVAR;
1766 curstack->varnum = j;
1769 /* revert the coalescing, if it has been done earlier */
1771 if ((curstack->varkind == LOCALVAR)
1772 && (curstack->varnum == j))
1774 curstack->varkind = TEMPVAR;
1775 #if defined(NEW_VAR)
1776 GET_NEW_INDEX(new_index);
1777 curstack->varnum = new_index;
1779 curstack->varnum = stackdepth-1;
1783 /* remember the stack boundary at this store */
1785 last_store_boundary[j] = new;
1787 STORE(opcode - ICMD_ISTORE, j);
1793 last_pei_boundary = new;
1794 iptr->flags.bits |= INS_FLAG_CHECK;
1795 COUNT(count_check_null);
1796 COUNT(count_check_bound);
1797 COUNT(count_pcmd_mem);
1799 bte = builtintable_get_internal(BUILTIN_canstore);
1802 if (md->memuse > rd->memuse)
1803 rd->memuse = md->memuse;
1804 if (md->argintreguse > rd->argintreguse)
1805 rd->argintreguse = md->argintreguse;
1806 /* XXX non-leaf method? */
1808 /* make all stack variables saved */
1812 copy->flags |= SAVEDVAR;
1816 OP3_0(TYPE_ADR, TYPE_INT, TYPE_ADR);
1823 last_pei_boundary = new;
1824 iptr->flags.bits |= INS_FLAG_CHECK;
1825 COUNT(count_check_null);
1826 COUNT(count_check_bound);
1827 COUNT(count_pcmd_mem);
1828 OP3_0(TYPE_ADR, TYPE_INT, opcode - ICMD_IASTORE);
1835 last_pei_boundary = new;
1836 iptr->flags.bits |= INS_FLAG_CHECK;
1837 COUNT(count_check_null);
1838 COUNT(count_check_bound);
1839 COUNT(count_pcmd_mem);
1840 OP3_0(TYPE_ADR, TYPE_INT, TYPE_INT);
1846 #ifdef ENABLE_VERIFIER
1849 if (IS_2_WORD_TYPE(curstack->type))
1850 goto throw_stack_category_error;
1861 last_pei_boundary = new;
1862 IF_JIT( md_return_alloc(jd, curstack); )
1863 COUNT(count_pcmd_return);
1864 OP1_0(opcode - ICMD_IRETURN);
1865 superblockend = true;
1869 last_pei_boundary = new;
1870 COUNT(count_check_null);
1873 superblockend = true;
1876 case ICMD_PUTSTATIC:
1877 last_pei_boundary = new;
1878 COUNT(count_pcmd_mem);
1879 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1880 OP1_0(fmiref->parseddesc.fd->type);
1883 /* pop 1 push 0 branch */
1886 case ICMD_IFNONNULL:
1887 COUNT(count_pcmd_bra);
1888 OP1_BRANCH(TYPE_ADR);
1889 BRANCH(tbptr, copy);
1898 COUNT(count_pcmd_bra);
1899 /* iptr->sx.val.i is set implicitly in parse by
1900 clearing the memory or from IF_ICMPxx
1903 OP1_BRANCH(TYPE_INT);
1904 /* iptr->sx.val.i = 0; */
1905 BRANCH(tbptr, copy);
1908 /* pop 0 push 0 branch */
1911 COUNT(count_pcmd_bra);
1913 BRANCH(tbptr, copy);
1914 superblockend = true;
1917 /* pop 1 push 0 table branch */
1919 case ICMD_TABLESWITCH:
1920 COUNT(count_pcmd_table);
1921 OP1_BRANCH(TYPE_INT);
1923 table = iptr->dst.table;
1924 BRANCH_TARGET(*table, tbptr, copy);
1927 i = iptr->sx.s23.s3.tablehigh
1928 - iptr->sx.s23.s2.tablelow + 1;
1931 BRANCH_TARGET(*table, tbptr, copy);
1934 superblockend = true;
1937 /* pop 1 push 0 table branch */
1939 case ICMD_LOOKUPSWITCH:
1940 COUNT(count_pcmd_table);
1941 OP1_BRANCH(TYPE_INT);
1943 BRANCH_TARGET(iptr->sx.s23.s3.lookupdefault, tbptr, copy);
1945 lookup = iptr->dst.lookup;
1947 i = iptr->sx.s23.s2.lookupcount;
1950 BRANCH_TARGET(lookup->target, tbptr, copy);
1953 superblockend = true;
1956 case ICMD_MONITORENTER:
1957 case ICMD_MONITOREXIT:
1958 last_pei_boundary = new;
1959 COUNT(count_check_null);
1963 /* pop 2 push 0 branch */
1965 case ICMD_IF_ICMPEQ:
1966 case ICMD_IF_ICMPNE:
1967 case ICMD_IF_ICMPLT:
1968 case ICMD_IF_ICMPGE:
1969 case ICMD_IF_ICMPGT:
1970 case ICMD_IF_ICMPLE:
1971 COUNT(count_pcmd_bra);
1972 OP2_BRANCH(TYPE_INT, TYPE_INT);
1973 BRANCH(tbptr, copy);
1976 case ICMD_IF_ACMPEQ:
1977 case ICMD_IF_ACMPNE:
1978 COUNT(count_pcmd_bra);
1979 OP2_BRANCH(TYPE_ADR, TYPE_ADR);
1980 BRANCH(tbptr, copy);
1986 last_pei_boundary = new;
1987 COUNT(count_check_null);
1988 COUNT(count_pcmd_mem);
1989 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1990 OP2_0(TYPE_ADR, fmiref->parseddesc.fd->type);
1995 if (!IS_2_WORD_TYPE(curstack->type)) {
1997 #ifdef ENABLE_VERIFIER
2000 if (IS_2_WORD_TYPE(curstack->prev->type))
2001 goto throw_stack_category_error;
2004 OP2_0_ANY_ANY; /* pop two slots */
2007 iptr->opc = ICMD_POP;
2008 OP1_0_ANY; /* pop one (two-word) slot */
2012 /* pop 0 push 1 dup */
2015 #ifdef ENABLE_VERIFIER
2018 if (IS_2_WORD_TYPE(curstack->type))
2019 goto throw_stack_category_error;
2022 COUNT(count_dup_instruction);
2025 USE_S1_ANY; /* XXX live through */
2026 /* DUP_SLOT(iptr->s1.var); */
2028 last_dup_boundary = new - 1;
2029 #if defined(NEW_VAR)
2030 iptr->dst.varindex = curstack->varnum;
2032 iptr->dst.var = curstack;
2039 if (IS_2_WORD_TYPE(curstack->type)) {
2041 iptr->opc = ICMD_DUP;
2046 /* ..., ????, cat1 */
2047 #ifdef ENABLE_VERIFIER
2049 if (IS_2_WORD_TYPE(curstack->prev->type))
2050 goto throw_stack_category_error;
2053 iptr->dst.dupslots = DMNEW(stackptr, 2 + 2);
2054 iptr->dst.dupslots[0] = curstack->prev; /* XXX live through */
2055 iptr->dst.dupslots[1] = curstack; /* XXX live through */
2057 DUP_SLOT(iptr->dst.dupslots[0]);
2058 iptr->dst.dupslots[2+0] = curstack;
2059 DUP_SLOT(iptr->dst.dupslots[1]);
2060 iptr->dst.dupslots[2+1] = curstack;
2061 last_dup_boundary = new;
2066 /* pop 2 push 3 dup */
2069 #ifdef ENABLE_VERIFIER
2072 if (IS_2_WORD_TYPE(curstack->type) ||
2073 IS_2_WORD_TYPE(curstack->prev->type))
2074 goto throw_stack_category_error;
2079 iptr->dst.dupslots = DMNEW(stackptr, 2 + 3);
2080 iptr->dst.dupslots[0] = curstack->prev;
2081 iptr->dst.dupslots[1] = curstack;
2084 DUP_SLOT(iptr->dst.dupslots[1]);
2085 iptr->dst.dupslots[2+0] = curstack;
2086 DUP_SLOT(iptr->dst.dupslots[0]);
2087 iptr->dst.dupslots[2+1] = curstack;
2088 DUP_SLOT(iptr->dst.dupslots[1]);
2089 iptr->dst.dupslots[2+2] = curstack;
2090 last_dup_boundary = new;
2096 if (IS_2_WORD_TYPE(curstack->type)) {
2097 /* ..., ????, cat2 */
2098 #ifdef ENABLE_VERIFIER
2100 if (IS_2_WORD_TYPE(curstack->prev->type))
2101 goto throw_stack_category_error;
2104 iptr->opc = ICMD_DUP_X1;
2108 /* ..., ????, cat1 */
2109 #ifdef ENABLE_VERIFIER
2112 if (IS_2_WORD_TYPE(curstack->prev->type)
2113 || IS_2_WORD_TYPE(curstack->prev->prev->type))
2114 goto throw_stack_category_error;
2119 iptr->dst.dupslots = DMNEW(stackptr, 3 + 5);
2120 iptr->dst.dupslots[0] = curstack->prev->prev;
2121 iptr->dst.dupslots[1] = curstack->prev;
2122 iptr->dst.dupslots[2] = curstack;
2123 POPANY; POPANY; POPANY;
2125 DUP_SLOT(iptr->dst.dupslots[1]);
2126 iptr->dst.dupslots[3+0] = curstack;
2127 DUP_SLOT(iptr->dst.dupslots[2]);
2128 iptr->dst.dupslots[3+1] = curstack;
2129 DUP_SLOT(iptr->dst.dupslots[0]);
2130 iptr->dst.dupslots[3+2] = curstack;
2131 DUP_SLOT(iptr->dst.dupslots[1]);
2132 iptr->dst.dupslots[3+3] = curstack;
2133 DUP_SLOT(iptr->dst.dupslots[2]);
2134 iptr->dst.dupslots[3+4] = curstack;
2135 last_dup_boundary = new;
2140 /* pop 3 push 4 dup */
2144 if (IS_2_WORD_TYPE(curstack->prev->type)) {
2145 /* ..., cat2, ???? */
2146 #ifdef ENABLE_VERIFIER
2148 if (IS_2_WORD_TYPE(curstack->type))
2149 goto throw_stack_category_error;
2152 iptr->opc = ICMD_DUP_X1;
2156 /* ..., cat1, ???? */
2157 #ifdef ENABLE_VERIFIER
2160 if (IS_2_WORD_TYPE(curstack->type)
2161 || IS_2_WORD_TYPE(curstack->prev->prev->type))
2162 goto throw_stack_category_error;
2166 iptr->dst.dupslots = DMNEW(stackptr, 3 + 4);
2167 iptr->dst.dupslots[0] = curstack->prev->prev;
2168 iptr->dst.dupslots[1] = curstack->prev;
2169 iptr->dst.dupslots[2] = curstack;
2170 POPANY; POPANY; POPANY;
2172 DUP_SLOT(iptr->dst.dupslots[2]);
2173 iptr->dst.dupslots[3+0] = curstack;
2174 DUP_SLOT(iptr->dst.dupslots[0]);
2175 iptr->dst.dupslots[3+1] = curstack;
2176 DUP_SLOT(iptr->dst.dupslots[1]);
2177 iptr->dst.dupslots[3+2] = curstack;
2178 DUP_SLOT(iptr->dst.dupslots[2]);
2179 iptr->dst.dupslots[3+3] = curstack;
2180 last_dup_boundary = new;
2187 if (IS_2_WORD_TYPE(curstack->type)) {
2188 /* ..., ????, cat2 */
2189 if (IS_2_WORD_TYPE(curstack->prev->type)) {
2190 /* ..., cat2, cat2 */
2191 iptr->opc = ICMD_DUP_X1;
2195 /* ..., cat1, cat2 */
2196 #ifdef ENABLE_VERIFIER
2199 if (IS_2_WORD_TYPE(curstack->prev->prev->type))
2200 goto throw_stack_category_error;
2203 iptr->opc = ICMD_DUP_X2;
2209 /* ..., ????, ????, cat1 */
2211 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
2212 /* ..., cat2, ????, cat1 */
2213 #ifdef ENABLE_VERIFIER
2215 if (IS_2_WORD_TYPE(curstack->prev->type))
2216 goto throw_stack_category_error;
2219 iptr->opc = ICMD_DUP2_X1;
2223 /* ..., cat1, ????, cat1 */
2224 #ifdef ENABLE_VERIFIER
2227 if (IS_2_WORD_TYPE(curstack->prev->type)
2228 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
2229 goto throw_stack_category_error;
2232 iptr->dst.dupslots = DMNEW(stackptr, 4 + 6);
2233 iptr->dst.dupslots[0] = curstack->prev->prev->prev;
2234 iptr->dst.dupslots[1] = curstack->prev->prev;
2235 iptr->dst.dupslots[2] = curstack->prev;
2236 iptr->dst.dupslots[3] = curstack;
2237 POPANY; POPANY; POPANY; POPANY;
2239 DUP_SLOT(iptr->dst.dupslots[2]);
2240 iptr->dst.dupslots[4+0] = curstack;
2241 DUP_SLOT(iptr->dst.dupslots[3]);
2242 iptr->dst.dupslots[4+1] = curstack;
2243 DUP_SLOT(iptr->dst.dupslots[0]);
2244 iptr->dst.dupslots[4+2] = curstack;
2245 DUP_SLOT(iptr->dst.dupslots[1]);
2246 iptr->dst.dupslots[4+3] = curstack;
2247 DUP_SLOT(iptr->dst.dupslots[2]);
2248 iptr->dst.dupslots[4+4] = curstack;
2249 DUP_SLOT(iptr->dst.dupslots[3]);
2250 iptr->dst.dupslots[4+5] = curstack;
2251 last_dup_boundary = new;
2256 /* pop 2 push 2 swap */
2259 #ifdef ENABLE_VERIFIER
2262 if (IS_2_WORD_TYPE(curstack->type)
2263 || IS_2_WORD_TYPE(curstack->prev->type))
2264 goto throw_stack_category_error;
2267 iptr->dst.dupslots = DMNEW(stackptr, 2 + 2);
2268 iptr->dst.dupslots[0] = curstack->prev;
2269 iptr->dst.dupslots[1] = curstack;
2272 DUP_SLOT(iptr->dst.dupslots[1]);
2273 iptr->dst.dupslots[2+0] = curstack;
2274 DUP_SLOT(iptr->dst.dupslots[0]);
2275 iptr->dst.dupslots[2+1] = curstack;
2276 last_dup_boundary = new;
2283 last_pei_boundary = new;
2284 #if !SUPPORT_DIVISION
2285 bte = iptr->sx.s23.s3.bte;
2288 if (md->memuse > rd->memuse)
2289 rd->memuse = md->memuse;
2290 if (md->argintreguse > rd->argintreguse)
2291 rd->argintreguse = md->argintreguse;
2293 /* make all stack variables saved */
2297 copy->flags |= SAVEDVAR;
2302 #endif /* !SUPPORT_DIVISION */
2313 COUNT(count_pcmd_op);
2314 OP2_1(TYPE_INT, TYPE_INT, TYPE_INT);
2319 last_pei_boundary = new;
2320 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
2321 bte = iptr->sx.s23.s3.bte;
2324 if (md->memuse > rd->memuse)
2325 rd->memuse = md->memuse;
2326 if (md->argintreguse > rd->argintreguse)
2327 rd->argintreguse = md->argintreguse;
2328 /* XXX non-leaf method? */
2330 /* make all stack variables saved */
2334 copy->flags |= SAVEDVAR;
2339 #endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
2344 #if SUPPORT_LONG_LOGICAL
2348 #endif /* SUPPORT_LONG_LOGICAL */
2349 COUNT(count_pcmd_op);
2350 OP2_1(TYPE_LNG, TYPE_LNG, TYPE_LNG);
2356 COUNT(count_pcmd_op);
2357 OP2_1(TYPE_LNG, TYPE_INT, TYPE_LNG);
2365 COUNT(count_pcmd_op);
2366 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_FLT);
2374 COUNT(count_pcmd_op);
2375 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_DBL);
2379 COUNT(count_pcmd_op);
2380 #if SUPPORT_LONG_CMP_CONST
2381 if ((len == 0) || (iptr[1].sx.val.i != 0))
2384 switch (iptr[1].opc) {
2386 iptr->opc = ICMD_IF_LCMPEQ;
2388 iptr->dst.insindex = iptr[1].dst.insindex;
2389 iptr[1].opc = ICMD_NOP;
2391 OP2_BRANCH(TYPE_LNG, TYPE_LNG);
2392 BRANCH(tbptr, copy);
2394 COUNT(count_pcmd_bra);
2397 iptr->opc = ICMD_IF_LCMPNE;
2398 goto icmd_lcmp_if_tail;
2400 iptr->opc = ICMD_IF_LCMPLT;
2401 goto icmd_lcmp_if_tail;
2403 iptr->opc = ICMD_IF_LCMPGT;
2404 goto icmd_lcmp_if_tail;
2406 iptr->opc = ICMD_IF_LCMPLE;
2407 goto icmd_lcmp_if_tail;
2409 iptr->opc = ICMD_IF_LCMPGE;
2410 goto icmd_lcmp_if_tail;
2416 #endif /* SUPPORT_LONG_CMP_CONST */
2417 OP2_1(TYPE_LNG, TYPE_LNG, TYPE_INT);
2420 /* XXX why is this deactivated? */
2423 COUNT(count_pcmd_op);
2424 if ((len == 0) || (iptr[1].sx.val.i != 0))
2427 switch (iptr[1].opc) {
2429 iptr->opc = ICMD_IF_FCMPEQ;
2431 iptr->dst.insindex = iptr[1].dst.insindex;
2432 iptr[1].opc = ICMD_NOP;
2434 OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2435 BRANCH(tbptr, copy);
2437 COUNT(count_pcmd_bra);
2440 iptr->opc = ICMD_IF_FCMPNE;
2441 goto icmd_if_fcmpl_tail;
2443 iptr->opc = ICMD_IF_FCMPL_LT;
2444 goto icmd_if_fcmpl_tail;
2446 iptr->opc = ICMD_IF_FCMPL_GT;
2447 goto icmd_if_fcmpl_tail;
2449 iptr->opc = ICMD_IF_FCMPL_LE;
2450 goto icmd_if_fcmpl_tail;
2452 iptr->opc = ICMD_IF_FCMPL_GE;
2453 goto icmd_if_fcmpl_tail;
2460 OPTT2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2464 COUNT(count_pcmd_op);
2465 if ((len == 0) || (iptr[1].sx.val.i != 0))
2468 switch (iptr[1].opc) {
2470 iptr->opc = ICMD_IF_FCMPEQ;
2472 iptr->dst.insindex = iptr[1].dst.insindex;
2473 iptr[1].opc = ICMD_NOP;
2475 OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2476 BRANCH(tbptr, copy);
2478 COUNT(count_pcmd_bra);
2481 iptr->opc = ICMD_IF_FCMPNE;
2482 goto icmd_if_fcmpg_tail;
2484 iptr->opc = ICMD_IF_FCMPG_LT;
2485 goto icmd_if_fcmpg_tail;
2487 iptr->opc = ICMD_IF_FCMPG_GT;
2488 goto icmd_if_fcmpg_tail;
2490 iptr->opc = ICMD_IF_FCMPG_LE;
2491 goto icmd_if_fcmpg_tail;
2493 iptr->opc = ICMD_IF_FCMPG_GE;
2494 goto icmd_if_fcmpg_tail;
2501 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2505 COUNT(count_pcmd_op);
2506 if ((len == 0) || (iptr[1].sx.val.i != 0))
2509 switch (iptr[1].opc) {
2511 iptr->opc = ICMD_IF_DCMPEQ;
2513 iptr->dst.insindex = iptr[1].dst.insindex;
2514 iptr[1].opc = ICMD_NOP;
2516 OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2517 BRANCH(tbptr, copy);
2519 COUNT(count_pcmd_bra);
2522 iptr->opc = ICMD_IF_DCMPNE;
2523 goto icmd_if_dcmpl_tail;
2525 iptr->opc = ICMD_IF_DCMPL_LT;
2526 goto icmd_if_dcmpl_tail;
2528 iptr->opc = ICMD_IF_DCMPL_GT;
2529 goto icmd_if_dcmpl_tail;
2531 iptr->opc = ICMD_IF_DCMPL_LE;
2532 goto icmd_if_dcmpl_tail;
2534 iptr->opc = ICMD_IF_DCMPL_GE;
2535 goto icmd_if_dcmpl_tail;
2542 OPTT2_1(TYPE_DBL, TYPE_INT);
2546 COUNT(count_pcmd_op);
2547 if ((len == 0) || (iptr[1].sx.val.i != 0))
2550 switch (iptr[1].opc) {
2552 iptr->opc = ICMD_IF_DCMPEQ;
2554 iptr->dst.insindex = iptr[1].dst.insindex;
2555 iptr[1].opc = ICMD_NOP;
2557 OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2558 BRANCH(tbptr, copy);
2560 COUNT(count_pcmd_bra);
2563 iptr->opc = ICMD_IF_DCMPNE;
2564 goto icmd_if_dcmpg_tail;
2566 iptr->opc = ICMD_IF_DCMPG_LT;
2567 goto icmd_if_dcmpg_tail;
2569 iptr->opc = ICMD_IF_DCMPG_GT;
2570 goto icmd_if_dcmpg_tail;
2572 iptr->opc = ICMD_IF_DCMPG_LE;
2573 goto icmd_if_dcmpg_tail;
2575 iptr->opc = ICMD_IF_DCMPG_GE;
2576 goto icmd_if_dcmpg_tail;
2583 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2588 COUNT(count_pcmd_op);
2589 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2594 COUNT(count_pcmd_op);
2595 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2604 case ICMD_INT2SHORT:
2605 COUNT(count_pcmd_op);
2606 OP1_1(TYPE_INT, TYPE_INT);
2609 COUNT(count_pcmd_op);
2610 OP1_1(TYPE_LNG, TYPE_LNG);
2613 COUNT(count_pcmd_op);
2614 OP1_1(TYPE_FLT, TYPE_FLT);
2617 COUNT(count_pcmd_op);
2618 OP1_1(TYPE_DBL, TYPE_DBL);
2622 COUNT(count_pcmd_op);
2623 OP1_1(TYPE_INT, TYPE_LNG);
2626 COUNT(count_pcmd_op);
2627 OP1_1(TYPE_INT, TYPE_FLT);
2630 COUNT(count_pcmd_op);
2631 OP1_1(TYPE_INT, TYPE_DBL);
2634 COUNT(count_pcmd_op);
2635 OP1_1(TYPE_LNG, TYPE_INT);
2638 COUNT(count_pcmd_op);
2639 OP1_1(TYPE_LNG, TYPE_FLT);
2642 COUNT(count_pcmd_op);
2643 OP1_1(TYPE_LNG, TYPE_DBL);
2646 COUNT(count_pcmd_op);
2647 OP1_1(TYPE_FLT, TYPE_INT);
2650 COUNT(count_pcmd_op);
2651 OP1_1(TYPE_FLT, TYPE_LNG);
2654 COUNT(count_pcmd_op);
2655 OP1_1(TYPE_FLT, TYPE_DBL);
2658 COUNT(count_pcmd_op);
2659 OP1_1(TYPE_DBL, TYPE_INT);
2662 COUNT(count_pcmd_op);
2663 OP1_1(TYPE_DBL, TYPE_LNG);
2666 COUNT(count_pcmd_op);
2667 OP1_1(TYPE_DBL, TYPE_FLT);
2670 case ICMD_CHECKCAST:
2671 last_pei_boundary = new;
2672 if (iptr->flags.bits & INS_FLAG_ARRAY) {
2673 /* array type cast-check */
2675 bte = builtintable_get_internal(BUILTIN_arraycheckcast);
2678 if (md->memuse > rd->memuse)
2679 rd->memuse = md->memuse;
2680 if (md->argintreguse > rd->argintreguse)
2681 rd->argintreguse = md->argintreguse;
2683 /* make all stack variables saved */
2687 copy->flags |= SAVEDVAR;
2691 OP1_1(TYPE_ADR, TYPE_ADR);
2694 case ICMD_INSTANCEOF:
2695 case ICMD_ARRAYLENGTH:
2696 last_pei_boundary = new;
2697 OP1_1(TYPE_ADR, TYPE_INT);
2701 case ICMD_ANEWARRAY:
2702 last_pei_boundary = new;
2703 OP1_1(TYPE_INT, TYPE_ADR);
2707 last_pei_boundary = new;
2708 COUNT(count_check_null);
2709 COUNT(count_pcmd_mem);
2710 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2711 OP1_1(TYPE_ADR, fmiref->parseddesc.fd->type);
2716 case ICMD_GETSTATIC:
2717 last_pei_boundary = new;
2718 COUNT(count_pcmd_mem);
2719 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2720 OP0_1(fmiref->parseddesc.fd->type);
2724 last_pei_boundary = new;
2731 BRANCH_TARGET(iptr->sx.s23.s3.jsrtarget, tbptr, copy);
2733 tbptr->type = BBTYPE_SBR;
2735 /* We need to check for overflow right here because
2736 * the pushed value is poped afterwards */
2739 /* calculate stack after return */
2744 /* pop many push any */
2748 bte = iptr->sx.s23.s3.bte;
2752 case ICMD_INVOKESTATIC:
2753 case ICMD_INVOKESPECIAL:
2754 case ICMD_INVOKEVIRTUAL:
2755 case ICMD_INVOKEINTERFACE:
2756 COUNT(count_pcmd_met);
2758 /* Check for functions to replace with builtin
2761 if (builtintable_replace_function(iptr))
2764 INSTRUCTION_GET_METHODDESC(iptr, md);
2765 /* XXX resurrect this COUNT? */
2766 /* if (lm->flags & ACC_STATIC) */
2767 /* {COUNT(count_check_null);} */
2771 last_pei_boundary = new;
2775 if (md->memuse > rd->memuse)
2776 rd->memuse = md->memuse;
2777 if (md->argintreguse > rd->argintreguse)
2778 rd->argintreguse = md->argintreguse;
2779 if (md->argfltreguse > rd->argfltreguse)
2780 rd->argfltreguse = md->argfltreguse;
2784 /* XXX optimize for <= 2 args */
2785 /* XXX not for ICMD_BUILTIN */
2786 iptr->s1.argcount = stackdepth;
2787 iptr->sx.s23.s2.args = DMNEW(stackptr, stackdepth);
2790 for (i-- ; i >= 0; i--) {
2791 iptr->sx.s23.s2.args[i] = copy;
2793 /* do not change STACKVARs to ARGVAR ->
2794 won't help anyway */
2795 if (copy->varkind != STACKVAR) {
2797 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2798 /* If we pass float arguments in integer argument registers, we
2799 * are not allowed to precolor them here. Floats have to be moved
2800 * to this regs explicitly in codegen().
2801 * Only arguments that are passed by stack anyway can be precolored
2802 * (michi 2005/07/24) */
2803 if (!(copy->flags & SAVEDVAR) &&
2804 (!IS_FLT_DBL_TYPE(copy->type) || md->params[i].inmemory)) {
2806 if (!(copy->flags & SAVEDVAR)) {
2808 copy->varkind = ARGVAR;
2811 #if defined(ENABLE_INTRP)
2814 if (md->params[i].inmemory) {
2815 copy->flags = INMEMORY;
2816 copy->regoff = md->params[i].regoff;
2820 if (IS_FLT_DBL_TYPE(copy->type)) {
2821 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2822 assert(0); /* XXX is this assert ok? */
2825 rd->argfltregs[md->params[i].regoff];
2826 #endif /* SUPPORT_PASS_FLOATARGS_IN_INTREGS */
2829 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
2830 if (IS_2_WORD_TYPE(copy->type))
2831 copy->regoff = PACK_REGS(
2832 rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
2833 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
2835 #endif /* SUPPORT_COMBINE_INTEGER_REGISTERS */
2837 rd->argintregs[md->params[i].regoff];
2840 #if defined(ENABLE_INTRP)
2841 } /* end if (!opt_intrp) */
2848 /* deal with live-through stack slots "under" the arguments */
2849 /* XXX not for ICMD_BUILTIN */
2854 iptr->sx.s23.s2.args[i++] = copy;
2855 copy->flags |= SAVEDVAR;
2859 /* pop the arguments */
2868 /* push the return value */
2870 if (md->returntype.type != TYPE_VOID) {
2871 DST(md->returntype.type, stackdepth);
2876 case ICMD_INLINE_START:
2877 case ICMD_INLINE_END:
2882 case ICMD_MULTIANEWARRAY:
2883 last_pei_boundary = new;
2884 if (rd->argintreguse < 3)
2885 rd->argintreguse = 3;
2887 i = iptr->s1.argcount;
2891 iptr->sx.s23.s2.args = DMNEW(stackptr, i);
2893 #if defined(SPECIALMEMUSE)
2894 # if defined(__DARWIN__)
2895 if (rd->memuse < (i + INT_ARG_CNT + LA_SIZE_IN_POINTERS))
2896 rd->memuse = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2898 if (rd->memuse < (i + LA_SIZE_IN_POINTERS + 3))
2899 rd->memuse = i + LA_SIZE_IN_POINTERS + 3;
2902 # if defined(__I386__)
2903 if (rd->memuse < i + 3)
2904 rd->memuse = i + 3; /* n integer args spilled on stack */
2905 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2906 if (rd->memuse < i + 2)
2907 rd->memuse = i + 2; /* 4*4 bytes callee save space */
2910 rd->memuse = i; /* n integer args spilled on stack */
2911 # endif /* defined(__I386__) */
2915 /* check INT type here? Currently typecheck does this. */
2916 iptr->sx.s23.s2.args[i] = copy;
2917 if (!(copy->flags & SAVEDVAR)
2918 && (copy->varkind != STACKVAR)) {
2919 copy->varkind = ARGVAR;
2920 copy->varnum = i + INT_ARG_CNT;
2921 copy->flags |= INMEMORY;
2922 #if defined(SPECIALMEMUSE)
2923 # if defined(__DARWIN__)
2924 copy->regoff = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2926 copy->regoff = i + LA_SIZE_IN_POINTERS + 3;
2929 # if defined(__I386__)
2930 copy->regoff = i + 3;
2931 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2932 copy->regoff = i + 2;
2935 # endif /* defined(__I386__) */
2936 #endif /* defined(SPECIALMEMUSE) */
2941 copy->flags |= SAVEDVAR;
2945 i = iptr->s1.argcount;
2950 DST(TYPE_ADR, stackdepth);
2956 new_internalerror("Unknown ICMD %d", opcode);
2962 } /* while instructions */
2964 /* set out-stack of block */
2966 bptr->outstack = curstack;
2967 bptr->outdepth = stackdepth;
2968 bptr->outvars = DMNEW(stackptr, stackdepth);
2969 for (i = stackdepth, copy = curstack; i--; copy = copy->prev)
2970 bptr->outvars[i] = copy;
2972 /* stack slots at basic block end become interfaces */
2975 for (copy = curstack; copy; i--, copy = copy->prev) {
2976 if ((copy->varkind == STACKVAR) && (copy->varnum > i)) {
2977 #if defined(NEW_VAR)
2978 /* with the new vars rd->interfaces will be removed */
2979 /* and all in and outvars have to be STACKVARS! */
2980 /* in the moment i.e. SWAP with in and out vars */
2981 /* an unresolvable conflict */
2984 copy->varkind = TEMPVAR;
2986 copy->varkind = STACKVAR;
2990 rd->interfaces[i][copy->type].type = copy->type;
2991 rd->interfaces[i][copy->type].flags |= copy->flags;
2995 /* check if interface slots at basic block begin must be saved */
2998 i = bptr->indepth - 1;
2999 for (copy = bptr->instack; copy; i--, copy = copy->prev) {
3000 rd->interfaces[i][copy->type].type = copy->type;
3001 if (copy->varkind == STACKVAR) {
3002 if (copy->flags & SAVEDVAR)
3003 rd->interfaces[i][copy->type].flags |= SAVEDVAR;
3010 superblockend = true;
3013 } /* while blocks */
3014 } while (repeat && !deadcode);
3016 /* gather statistics *****************************************************/
3018 #if defined(ENABLE_STATISTICS)
3020 if (jd->new_basicblockcount > count_max_basic_blocks)
3021 count_max_basic_blocks = jd->new_basicblockcount;
3022 count_basic_blocks += jd->new_basicblockcount;
3023 if (jd->new_instructioncount > count_max_javainstr)
3024 count_max_javainstr = jd->new_instructioncount;
3025 count_javainstr += jd->new_instructioncount;
3026 if (jd->new_stackcount > count_upper_bound_new_stack)
3027 count_upper_bound_new_stack = jd->new_stackcount;
3028 if ((new - jd->new_stack) > count_max_new_stack)
3029 count_max_new_stack = (new - jd->new_stack);
3031 b_count = jd->new_basicblockcount;
3032 bptr = jd->new_basicblocks;
3033 while (--b_count >= 0) {
3034 if (bptr->flags > BBREACHED) {
3035 if (bptr->indepth >= 10)
3036 count_block_stack[10]++;
3038 count_block_stack[bptr->indepth]++;
3041 count_block_size_distribution[len]++;
3043 count_block_size_distribution[10]++;
3045 count_block_size_distribution[11]++;
3047 count_block_size_distribution[12]++;
3049 count_block_size_distribution[13]++;
3051 count_block_size_distribution[14]++;
3053 count_block_size_distribution[15]++;
3055 count_block_size_distribution[16]++;
3057 count_block_size_distribution[17]++;
3062 if (iteration_count == 1)
3063 count_analyse_iterations[0]++;
3064 else if (iteration_count == 2)
3065 count_analyse_iterations[1]++;
3066 else if (iteration_count == 3)
3067 count_analyse_iterations[2]++;
3068 else if (iteration_count == 4)
3069 count_analyse_iterations[3]++;
3071 count_analyse_iterations[4]++;
3073 if (jd->new_basicblockcount <= 5)
3074 count_method_bb_distribution[0]++;
3075 else if (jd->new_basicblockcount <= 10)
3076 count_method_bb_distribution[1]++;
3077 else if (jd->new_basicblockcount <= 15)
3078 count_method_bb_distribution[2]++;
3079 else if (jd->new_basicblockcount <= 20)
3080 count_method_bb_distribution[3]++;
3081 else if (jd->new_basicblockcount <= 30)
3082 count_method_bb_distribution[4]++;
3083 else if (jd->new_basicblockcount <= 40)
3084 count_method_bb_distribution[5]++;
3085 else if (jd->new_basicblockcount <= 50)
3086 count_method_bb_distribution[6]++;
3087 else if (jd->new_basicblockcount <= 75)
3088 count_method_bb_distribution[7]++;
3090 count_method_bb_distribution[8]++;
3092 #endif /* defined(ENABLE_STATISTICS) */
3094 /* everything's ok *******************************************************/
3098 /* goto labels for throwing verifier exceptions **************************/
3100 #if defined(ENABLE_VERIFIER)
3102 throw_stack_underflow:
3103 exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
3106 throw_stack_overflow:
3107 exceptions_throw_verifyerror(m, "Stack size too large");
3110 throw_stack_depth_error:
3111 exceptions_throw_verifyerror(m,"Stack depth mismatch");
3114 throw_stack_type_error:
3115 exceptions_throw_verifyerror_for_stack(m, expectedtype);
3118 throw_stack_category_error:
3119 exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
3127 * These are local overrides for various environment variables in Emacs.
3128 * Please do not remove this and leave it at the end of the file, where
3129 * Emacs will automagically detect them.
3130 * ---------------------------------------------------------------------
3133 * indent-tabs-mode: t
3137 * vim:noexpandtab:sw=4:ts=4: