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 5441 2006-09-09 14:41:03Z 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 /* stackdata_t ****************************************************************/
113 typedef struct stackdata_t stackdata_t;
125 /* macros for allocating/releasing variable indices */
127 #define GET_NEW_INDEX(sd, new_varindex) \
129 assert((sd).vartop < (sd).varcount); \
130 (new_varindex) = ((sd).vartop)++; \
133 /* not implemented now, can be used to reuse varindices */
134 /* pay attention to not release a localvar once implementing it! */
135 #define RELEASE_INDEX(sd, varindex)
137 #define GET_NEW_VAR(sd, new_varindex, newtype) \
139 GET_NEW_INDEX((sd), (new_varindex)); \
140 (sd).var[new_index].type = (newtype); \
143 /* macros for querying variable properties **************************/
145 #define IS_OUTVAR(sp) \
146 (sd.var[(sp)->varnum].flags & OUTVAR)
148 #define IS_PREALLOC(sp) \
149 (sd.var[(sp)->varnum].flags & PREALLOC)
151 #define IS_TEMPVAR(sp) \
152 ( ((sp)->varnum >= sd.localcount) \
153 && !(sd.var[(sp)->varnum].flags & (OUTVAR | PREALLOC)) )
155 #define IS_LOCALVAR_SD(sd, sp) \
156 ((sp)->varnum < (sd).localcount)
158 #define IS_LOCALVAR(sp) \
159 IS_LOCALVAR_SD(sd, (sp))
162 /* macros for setting variable properties ****************************/
164 #define SET_TEMPVAR(sp) \
166 if (IS_LOCALVAR((sp))) { \
167 GET_NEW_VAR(sd, new_index, (sp)->type); \
168 sd.var[new_index].flags = (sp)->flags; \
169 (sp)->varnum = new_index; \
170 (sp)->varkind = TEMPVAR; \
172 (sp)->creator->dst.varindex = new_index; \
174 sd.var[(sp)->varnum].flags &= ~(OUTVAR | PREALLOC); \
177 #define SET_PREALLOC(sp) \
179 assert(!IS_LOCALVAR((sp))); \
180 sd.var[(sp)->varnum].flags |= PREALLOC; \
183 /* macros for source operands ***************************************/
186 (iptr->s1.varindex = -1)
188 #define USE_S1_LOCAL(type1)
190 #define USE_S1(type1) \
193 CHECK_BASIC_TYPE(type1, curstack->type); \
194 iptr->s1.varindex = curstack->varnum; \
200 iptr->s1.varindex = curstack->varnum; \
203 #define USE_S1_S2(type1, type2) \
206 CHECK_BASIC_TYPE(type1, curstack->prev->type); \
207 CHECK_BASIC_TYPE(type2, curstack->type); \
208 iptr->sx.s23.s2.varindex = curstack->varnum; \
209 iptr->s1.varindex = curstack->prev->varnum; \
212 #define USE_S1_S2_ANY_ANY \
215 iptr->sx.s23.s2.varindex = curstack->varnum; \
216 iptr->s1.varindex = curstack->prev->varnum; \
219 #define USE_S1_S2_S3(type1, type2, type3) \
222 CHECK_BASIC_TYPE(type1, curstack->prev->prev->type); \
223 CHECK_BASIC_TYPE(type2, curstack->prev->type); \
224 CHECK_BASIC_TYPE(type3, curstack->type); \
225 iptr->sx.s23.s3.varindex = curstack->varnum; \
226 iptr->sx.s23.s2.varindex = curstack->prev->varnum; \
227 iptr->s1.varindex = curstack->prev->prev->varnum; \
230 /* The POPANY macro does NOT check stackdepth, or set stackdepth! */
233 if (curstack->varkind == UNDEFVAR) \
234 curstack->varkind = TEMPVAR; \
235 curstack = curstack->prev; \
238 #define POP_S1(type1) \
241 if (curstack->varkind == UNDEFVAR) \
242 curstack->varkind = TEMPVAR; \
243 curstack = curstack->prev; \
249 if (curstack->varkind == UNDEFVAR) \
250 curstack->varkind = TEMPVAR; \
251 curstack = curstack->prev; \
254 #define POP_S1_S2(type1, type2) \
256 USE_S1_S2(type1, type2); \
257 if (curstack->varkind == UNDEFVAR) \
258 curstack->varkind = TEMPVAR; \
259 if (curstack->prev->varkind == UNDEFVAR) \
260 curstack->prev->varkind = TEMPVAR; \
261 curstack = curstack->prev->prev; \
264 #define POP_S1_S2_ANY_ANY \
267 if (curstack->varkind == UNDEFVAR) \
268 curstack->varkind = TEMPVAR; \
269 if (curstack->prev->varkind == UNDEFVAR) \
270 curstack->prev->varkind = TEMPVAR; \
271 curstack = curstack->prev->prev; \
274 #define POP_S1_S2_S3(type1, type2, type3) \
276 USE_S1_S2_S3(type1, type2, type3); \
277 if (curstack->varkind == UNDEFVAR) \
278 curstack->varkind = TEMPVAR; \
279 if (curstack->prev->varkind == UNDEFVAR) \
280 curstack->prev->varkind = TEMPVAR; \
281 if (curstack->prev->prev->varkind == UNDEFVAR) \
282 curstack->prev->prev->varkind = TEMPVAR; \
283 curstack = curstack->prev->prev->prev; \
290 /* macros for setting the destination operand ***********************/
293 (iptr->dst.varindex = -1)
295 #define DST(typed, index) \
297 NEWSTACKn((typed),(index)); \
298 curstack->creator = iptr; \
299 iptr->dst.varindex = (index); \
302 #define DST_LOCALVAR(typed, index) \
304 NEWSTACK((typed), LOCALVAR, (index)); \
305 curstack->creator = iptr; \
306 iptr->dst.varindex = (index); \
310 /* stack modelling macros *******************************************/
312 #define OP0_1(typed) \
315 GET_NEW_VAR(sd, new_index, (typed)); \
316 DST(typed, new_index); \
327 #define OP1_BRANCH(type1) \
333 #define OP1_1(type1, typed) \
336 GET_NEW_VAR(sd, new_index, (typed)); \
337 DST(typed, new_index); \
340 #define OP2_1(type1, type2, typed) \
342 POP_S1_S2(type1, type2); \
343 GET_NEW_VAR(sd, new_index, (typed)); \
344 DST(typed, new_index); \
359 #define OP1_0(type1) \
366 #define OP2_0(type1, type2) \
368 POP_S1_S2(type1, type2); \
373 #define OP2_BRANCH(type1, type2) \
375 POP_S1_S2(type1, type2); \
379 #define OP2_0_ANY_ANY \
386 #define OP3_0(type1, type2, type3) \
388 POP_S1_S2_S3(type1, type2, type3); \
393 #define LOAD(type1, index) \
395 DST_LOCALVAR(type1, index); \
399 #define STORE(type1, index) \
406 /* macros for DUP elimination ***************************************/
408 /* XXX turn off coalescing */
410 #define DUP_SLOT(sp) \
412 if ((sp)->varkind != TEMPVAR) { \
413 GET_NEW_VAR(sd, new_index, (sp)->type); \
414 NEWSTACK((sp)->type, TEMPVAR, new_index); \
417 NEWSTACK((sp)->type, (sp)->varkind, (sp)->varnum); \
420 #define DUP_SLOT(sp) \
422 GET_NEW_VAR(sd, new_index, (sp)->type); \
423 NEWSTACK((sp)->type, TEMPVAR, new_index); \
427 /* does not check input stackdepth */
428 #define MOVE_UP(sp) \
430 iptr->opc = ICMD_MOVE; \
431 iptr->s1.varindex = (sp)->varnum; \
433 curstack->creator = iptr; \
434 iptr->dst.varindex = curstack->varnum; \
438 /* does not check input stackdepth */
439 #define COPY_UP(sp) \
442 iptr->opc = ICMD_COPY; \
443 iptr->s1.varindex = (sp)->varnum; \
445 curstack->creator = iptr; \
446 iptr->dst.varindex = curstack->varnum; \
450 #define COPY_DOWN(s, d) \
453 iptr->opc = ICMD_COPY; \
454 iptr->s1.varindex = (s)->varnum; \
455 iptr->dst.varindex = (d)->varnum; \
456 (d)->creator = iptr; \
460 /* macros for branching / reaching basic blocks *********************/
462 #if defined(ENABLE_VERIFIER)
463 #define MARKREACHED(b, c) \
465 if (!stack_mark_reached(&sd, (b), curstack, stackdepth)) \
469 #define MARKREACHED(b, c) \
471 (void) stack_mark_reached(&sd, (b), curstack, stackdepth); \
475 #define BRANCH_TARGET(bt, tempbptr, tempsp) \
477 (bt).block = tempbptr = BLOCK_OF((bt).insindex); \
478 MARKREACHED(tempbptr, tempsp); \
481 #define BRANCH(tempbptr, tempsp) \
483 iptr->dst.block = tempbptr = BLOCK_OF(iptr->dst.insindex); \
484 MARKREACHED(tempbptr, tempsp); \
488 /* stack_init ******************************************************************
490 Initialized the stack analysis subsystem (called by jit_init).
492 *******************************************************************************/
494 bool stack_init(void)
500 /* MARKREACHED marks the destination block <b> as reached. If this
501 * block has been reached before we check if stack depth and types
502 * match. Otherwise the destination block receives a copy of the
503 * current stack as its input stack.
505 * b...destination block
509 static bool stack_mark_reached(stackdata_t *sd, basicblock *b, stackptr curstack, int stackdepth)
514 #if defined(ENABLE_VERIFIER)
515 int expectedtype; /* used by CHECK_BASIC_TYPE */
519 b->bitflags |= BBFLAG_REPLACEMENT;
521 if (b->flags < BBREACHED) {
522 /* b is reached for the first time. Create its instack */
523 COPYCURSTACK(*sd, sp);
524 b->flags = BBREACHED;
526 b->indepth = stackdepth;
527 b->invars = DMNEW(s4, stackdepth);
528 for (i = stackdepth; i--; sp = sp->prev) {
529 b->invars[i] = sp->varnum;
530 sd->var[sp->varnum].flags |= OUTVAR;
534 /* b has been reached before. Check that its instack matches */
537 CHECK_STACK_DEPTH(b->indepth, stackdepth);
539 CHECK_BASIC_TYPE(sp->type,tsp->type);
547 #if defined(ENABLE_VERIFIER)
548 throw_stack_depth_error:
549 exceptions_throw_verifyerror(m,"Stack depth mismatch");
552 throw_stack_type_error:
553 exceptions_throw_verifyerror_for_stack(m, expectedtype);
559 /* stack_analyse ***************************************************************
561 Analyse_stack uses the intermediate code created by parse.c to
562 build a model of the JVM operand stack for the current method.
564 The following checks are performed:
565 - check for operand stack underflow (before each instruction)
566 - check for operand stack overflow (after[1] each instruction)
567 - check for matching stack depth at merging points
568 - check for matching basic types[2] at merging points
569 - check basic types for instruction input (except for BUILTIN*
570 opcodes, INVOKE* opcodes and MULTIANEWARRAY)
572 [1]) Checking this after the instruction should be ok. parse.c
573 counts the number of required stack slots in such a way that it is
574 only vital that we don't exceed `maxstack` at basic block
577 [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
578 DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
579 types are not discerned.
581 *******************************************************************************/
583 bool new_stack_analyse(jitdata *jd)
585 methodinfo *m; /* method being analyzed */
590 int b_count; /* basic block counter */
591 int b_index; /* basic block index */
593 stackptr curstack; /* current stack top */
595 int opcode; /* opcode of current instruction */
598 int len; /* # of instructions after the current one */
599 bool superblockend; /* if true, no fallthrough to next block */
600 bool repeat; /* if true, outermost loop must run again */
601 bool deadcode; /* true if no live code has been reached */
602 instruction *iptr; /* the current instruction */
605 stackptr *last_store_boundary;
606 stackptr coalescing_boundary;
608 stackptr src1, src2, src3, src4, dst1, dst2;
610 branch_target_t *table;
611 lookup_target_t *lookup;
612 #if defined(ENABLE_VERIFIER)
613 int expectedtype; /* used by CHECK_BASIC_TYPE */
615 builtintable_entry *bte;
617 constant_FMIref *fmiref;
618 #if defined(ENABLE_STATISTICS)
619 int iteration_count; /* number of iterations of analysis */
621 int new_index; /* used to get a new var index with GET_NEW_INDEX*/
623 #if defined(STACK_VERBOSE)
624 new_show_method(jd, SHOW_PARSE);
627 /* get required compiler data - initialization */
634 /* initialize the stackdata_t struct */
636 sd.varcount = jd->varcount;
637 sd.vartop = jd->vartop;
638 sd.localcount = jd->localcount;
640 sd.new = jd->new_stack;
642 #if defined(ENABLE_LSRA)
646 #if defined(ENABLE_STATISTICS)
650 /* init jd->interface_map */
652 jd->interface_map = DMNEW(interface_info, m->maxstack * 5);
653 for (i = 0; i < m->maxstack * 5; i++)
654 jd->interface_map[i].flags = UNUSED;
656 last_store_boundary = DMNEW(stackptr, cd->maxlocals);
658 /* initialize in-stack of first block */
660 jd->new_basicblocks[0].flags = BBREACHED;
661 jd->new_basicblocks[0].instack = NULL;
662 jd->new_basicblocks[0].invars = NULL;
663 jd->new_basicblocks[0].indepth = 0;
665 /* initialize in-stack of exception handlers */
667 for (i = 0; i < cd->exceptiontablelength; i++) {
668 sd.bptr = BLOCK_OF(cd->exceptiontable[i].handlerpc);
669 sd.bptr->flags = BBREACHED;
670 sd.bptr->type = BBTYPE_EXH;
671 sd.bptr->instack = sd.new;
672 sd.bptr->indepth = 1;
673 sd.bptr->predecessorcount = CFG_UNKNOWN_PREDECESSORS;
674 curstack = NULL; stackdepth = 0;
675 GET_NEW_VAR(sd, new_index, TYPE_ADR);
676 sd.bptr->invars = DMNEW(s4, 1);
677 sd.bptr->invars[0] = new_index;
678 sd.var[new_index].flags |= OUTVAR;
679 NEWSTACK(TYPE_ADR, STACKVAR, new_index);
680 curstack->creator = NULL;
682 jd->interface_map[0 * 5 + TYPE_ADR].flags = 0;
685 /* stack analysis loop (until fixpoint reached) **************************/
688 #if defined(ENABLE_STATISTICS)
692 /* initialize loop over basic blocks */
694 b_count = jd->new_basicblockcount;
695 sd.bptr = jd->new_basicblocks;
696 superblockend = true;
698 curstack = NULL; stackdepth = 0;
701 /* iterate over basic blocks *****************************************/
703 while (--b_count >= 0) {
704 #if defined(STACK_VERBOSE)
705 printf("----\nANALYZING BLOCK L%03d ", sd.bptr->nr);
706 if (sd.bptr->type == BBTYPE_EXH) printf("EXH\n");
707 else if (sd.bptr->type == BBTYPE_SBR) printf("SBR\n");
708 else printf("STD\n");
712 if (sd.bptr->flags == BBDELETED) {
713 /* This block has been deleted - do nothing. */
715 else if (superblockend && (sd.bptr->flags < BBREACHED)) {
716 /* This block has not been reached so far, and we */
717 /* don't fall into it, so we'll have to iterate again. */
720 else if (sd.bptr->flags <= BBREACHED) {
722 /* We know that sd.bptr->flags == BBREACHED. */
723 /* This block has been reached before. */
724 stackdepth = sd.bptr->indepth;
726 else if (sd.bptr->flags < BBREACHED) {
727 /* This block is reached for the first time now */
728 /* by falling through from the previous block. */
729 /* Create the instack (propagated). */
730 COPYCURSTACK(sd, copy);
731 sd.bptr->instack = copy;
733 sd.bptr->invars = DMNEW(s4, stackdepth);
734 for (i=stackdepth; i--; copy = copy->prev)
735 sd.bptr->invars[i] = copy->varnum;
736 sd.bptr->indepth = stackdepth;
739 /* This block has been reached before. now we are */
740 /* falling into it from the previous block. */
741 /* Check that stack depth is well-defined. */
742 CHECK_STACK_DEPTH(sd.bptr->indepth, stackdepth);
744 /* XXX check stack types? */
747 /* set up local variables for analyzing this block */
749 curstack = sd.bptr->instack;
751 superblockend = false;
752 len = sd.bptr->icount;
753 iptr = sd.bptr->iinstr;
754 b_index = sd.bptr - jd->new_basicblocks;
756 /* mark the block as analysed */
758 sd.bptr->flags = BBFINISHED;
760 /* reset variables for dependency checking */
762 coalescing_boundary = sd.new;
763 for( i = 0; i < cd->maxlocals; i++)
764 last_store_boundary[i] = sd.new;
766 #if defined(STACK_VERBOSE)
768 for( copy = sd.bptr->instack; copy; copy = copy->prev ) {
769 printf("%2d(%d", copy->varnum, copy->type);
772 if (IS_PREALLOC(copy))
778 printf("INVARS - indices:\t\n");
779 for (i=0; i<sd.bptr->indepth; ++i) {
780 printf("%d ", sd.bptr->invars[i]);
786 /* iterate over ICMDs ****************************************/
790 #if defined(STACK_VERBOSE)
791 new_show_icmd(jd, iptr, false, SHOW_PARSE); printf("\n");
792 for( copy = curstack; copy; copy = copy->prev ) {
793 printf("%2d(%d", copy->varnum, copy->type);
796 if (IS_PREALLOC(copy))
803 /* fetch the current opcode */
807 /* automatically replace some ICMDs with builtins */
809 #if defined(USEBUILTINTABLE)
811 bte = builtintable_get_automatic(opcode);
813 if (bte && bte->opcode == opcode) {
814 iptr->opc = ICMD_BUILTIN;
815 iptr->flags.bits = 0;
816 iptr->sx.s23.s3.bte = bte;
817 /* iptr->line is already set */
818 jd->isleafmethod = false;
822 #endif /* defined(USEBUILTINTABLE) */
824 /* main opcode switch *************************************/
837 coalescing_boundary = sd.new;
838 COUNT(count_check_null);
841 CLR_DST; /* XXX live through? */
846 jd->local_map[iptr->s1.varindex * 5 + TYPE_ADR];
848 USE_S1_LOCAL(TYPE_ADR);
852 IF_NO_INTRP( rd->locals[iptr->s1.localindex/*XXX invalid here*/][TYPE_ADR].type = TYPE_ADR; );
854 superblockend = true;
858 COUNT(count_pcmd_return);
861 superblockend = true;
865 /* pop 0 push 1 const */
867 /************************** ICONST OPTIMIZATIONS **************************/
870 COUNT(count_pcmd_load);
874 switch (iptr[1].opc) {
876 iptr->opc = ICMD_IADDCONST;
880 iptr[1].opc = ICMD_NOP;
881 OP1_1(TYPE_INT, TYPE_INT);
882 COUNT(count_pcmd_op);
886 iptr->opc = ICMD_ISUBCONST;
887 goto icmd_iconst_tail;
888 #if SUPPORT_CONST_MUL
890 iptr->opc = ICMD_IMULCONST;
891 goto icmd_iconst_tail;
892 #else /* SUPPORT_CONST_MUL */
894 if (iptr->sx.val.i == 0x00000002)
896 else if (iptr->sx.val.i == 0x00000004)
898 else if (iptr->sx.val.i == 0x00000008)
900 else if (iptr->sx.val.i == 0x00000010)
902 else if (iptr->sx.val.i == 0x00000020)
904 else if (iptr->sx.val.i == 0x00000040)
906 else if (iptr->sx.val.i == 0x00000080)
908 else if (iptr->sx.val.i == 0x00000100)
910 else if (iptr->sx.val.i == 0x00000200)
912 else if (iptr->sx.val.i == 0x00000400)
914 else if (iptr->sx.val.i == 0x00000800)
916 else if (iptr->sx.val.i == 0x00001000)
918 else if (iptr->sx.val.i == 0x00002000)
920 else if (iptr->sx.val.i == 0x00004000)
922 else if (iptr->sx.val.i == 0x00008000)
924 else if (iptr->sx.val.i == 0x00010000)
926 else if (iptr->sx.val.i == 0x00020000)
928 else if (iptr->sx.val.i == 0x00040000)
930 else if (iptr->sx.val.i == 0x00080000)
932 else if (iptr->sx.val.i == 0x00100000)
934 else if (iptr->sx.val.i == 0x00200000)
936 else if (iptr->sx.val.i == 0x00400000)
938 else if (iptr->sx.val.i == 0x00800000)
940 else if (iptr->sx.val.i == 0x01000000)
942 else if (iptr->sx.val.i == 0x02000000)
944 else if (iptr->sx.val.i == 0x04000000)
946 else if (iptr->sx.val.i == 0x08000000)
948 else if (iptr->sx.val.i == 0x10000000)
950 else if (iptr->sx.val.i == 0x20000000)
952 else if (iptr->sx.val.i == 0x40000000)
954 else if (iptr->sx.val.i == 0x80000000)
959 iptr->opc = ICMD_IMULPOW2;
960 goto icmd_iconst_tail;
961 #endif /* SUPPORT_CONST_MUL */
963 if (iptr->sx.val.i == 0x00000002)
965 else if (iptr->sx.val.i == 0x00000004)
967 else if (iptr->sx.val.i == 0x00000008)
969 else if (iptr->sx.val.i == 0x00000010)
971 else if (iptr->sx.val.i == 0x00000020)
973 else if (iptr->sx.val.i == 0x00000040)
975 else if (iptr->sx.val.i == 0x00000080)
977 else if (iptr->sx.val.i == 0x00000100)
979 else if (iptr->sx.val.i == 0x00000200)
981 else if (iptr->sx.val.i == 0x00000400)
983 else if (iptr->sx.val.i == 0x00000800)
985 else if (iptr->sx.val.i == 0x00001000)
987 else if (iptr->sx.val.i == 0x00002000)
989 else if (iptr->sx.val.i == 0x00004000)
991 else if (iptr->sx.val.i == 0x00008000)
993 else if (iptr->sx.val.i == 0x00010000)
995 else if (iptr->sx.val.i == 0x00020000)
997 else if (iptr->sx.val.i == 0x00040000)
999 else if (iptr->sx.val.i == 0x00080000)
1000 iptr->sx.val.i = 19;
1001 else if (iptr->sx.val.i == 0x00100000)
1002 iptr->sx.val.i = 20;
1003 else if (iptr->sx.val.i == 0x00200000)
1004 iptr->sx.val.i = 21;
1005 else if (iptr->sx.val.i == 0x00400000)
1006 iptr->sx.val.i = 22;
1007 else if (iptr->sx.val.i == 0x00800000)
1008 iptr->sx.val.i = 23;
1009 else if (iptr->sx.val.i == 0x01000000)
1010 iptr->sx.val.i = 24;
1011 else if (iptr->sx.val.i == 0x02000000)
1012 iptr->sx.val.i = 25;
1013 else if (iptr->sx.val.i == 0x04000000)
1014 iptr->sx.val.i = 26;
1015 else if (iptr->sx.val.i == 0x08000000)
1016 iptr->sx.val.i = 27;
1017 else if (iptr->sx.val.i == 0x10000000)
1018 iptr->sx.val.i = 28;
1019 else if (iptr->sx.val.i == 0x20000000)
1020 iptr->sx.val.i = 29;
1021 else if (iptr->sx.val.i == 0x40000000)
1022 iptr->sx.val.i = 30;
1023 else if (iptr->sx.val.i == 0x80000000)
1024 iptr->sx.val.i = 31;
1028 iptr->opc = ICMD_IDIVPOW2;
1029 goto icmd_iconst_tail;
1032 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
1033 if ((iptr->sx.val.i == 0x00000002) ||
1034 (iptr->sx.val.i == 0x00000004) ||
1035 (iptr->sx.val.i == 0x00000008) ||
1036 (iptr->sx.val.i == 0x00000010) ||
1037 (iptr->sx.val.i == 0x00000020) ||
1038 (iptr->sx.val.i == 0x00000040) ||
1039 (iptr->sx.val.i == 0x00000080) ||
1040 (iptr->sx.val.i == 0x00000100) ||
1041 (iptr->sx.val.i == 0x00000200) ||
1042 (iptr->sx.val.i == 0x00000400) ||
1043 (iptr->sx.val.i == 0x00000800) ||
1044 (iptr->sx.val.i == 0x00001000) ||
1045 (iptr->sx.val.i == 0x00002000) ||
1046 (iptr->sx.val.i == 0x00004000) ||
1047 (iptr->sx.val.i == 0x00008000) ||
1048 (iptr->sx.val.i == 0x00010000) ||
1049 (iptr->sx.val.i == 0x00020000) ||
1050 (iptr->sx.val.i == 0x00040000) ||
1051 (iptr->sx.val.i == 0x00080000) ||
1052 (iptr->sx.val.i == 0x00100000) ||
1053 (iptr->sx.val.i == 0x00200000) ||
1054 (iptr->sx.val.i == 0x00400000) ||
1055 (iptr->sx.val.i == 0x00800000) ||
1056 (iptr->sx.val.i == 0x01000000) ||
1057 (iptr->sx.val.i == 0x02000000) ||
1058 (iptr->sx.val.i == 0x04000000) ||
1059 (iptr->sx.val.i == 0x08000000) ||
1060 (iptr->sx.val.i == 0x10000000) ||
1061 (iptr->sx.val.i == 0x20000000) ||
1062 (iptr->sx.val.i == 0x40000000) ||
1063 (iptr->sx.val.i == 0x80000000))
1065 iptr->opc = ICMD_IREMPOW2;
1066 iptr->sx.val.i -= 1;
1067 goto icmd_iconst_tail;
1070 #if SUPPORT_CONST_LOGICAL
1072 iptr->opc = ICMD_IANDCONST;
1073 goto icmd_iconst_tail;
1076 iptr->opc = ICMD_IORCONST;
1077 goto icmd_iconst_tail;
1080 iptr->opc = ICMD_IXORCONST;
1081 goto icmd_iconst_tail;
1083 #endif /* SUPPORT_CONST_LOGICAL */
1085 iptr->opc = ICMD_ISHLCONST;
1086 goto icmd_iconst_tail;
1089 iptr->opc = ICMD_ISHRCONST;
1090 goto icmd_iconst_tail;
1093 iptr->opc = ICMD_IUSHRCONST;
1094 goto icmd_iconst_tail;
1095 #if SUPPORT_LONG_SHIFT
1097 iptr->opc = ICMD_LSHLCONST;
1098 goto icmd_lconst_tail;
1101 iptr->opc = ICMD_LSHRCONST;
1102 goto icmd_lconst_tail;
1105 iptr->opc = ICMD_LUSHRCONST;
1106 goto icmd_lconst_tail;
1107 #endif /* SUPPORT_LONG_SHIFT */
1108 case ICMD_IF_ICMPEQ:
1109 iptr[1].opc = ICMD_IFEQ;
1113 /* set the constant for the following icmd */
1114 iptr[1].sx.val.i = iptr->sx.val.i;
1116 /* this instruction becomes a nop */
1117 iptr->opc = ICMD_NOP;
1120 case ICMD_IF_ICMPLT:
1121 iptr[1].opc = ICMD_IFLT;
1122 goto icmd_if_icmp_tail;
1124 case ICMD_IF_ICMPLE:
1125 iptr[1].opc = ICMD_IFLE;
1126 goto icmd_if_icmp_tail;
1128 case ICMD_IF_ICMPNE:
1129 iptr[1].opc = ICMD_IFNE;
1130 goto icmd_if_icmp_tail;
1132 case ICMD_IF_ICMPGT:
1133 iptr[1].opc = ICMD_IFGT;
1134 goto icmd_if_icmp_tail;
1136 case ICMD_IF_ICMPGE:
1137 iptr[1].opc = ICMD_IFGE;
1138 goto icmd_if_icmp_tail;
1140 #if SUPPORT_CONST_STORE
1145 IF_INTRP( goto normal_ICONST; )
1146 # if SUPPORT_CONST_STORE_ZERO_ONLY
1147 if (iptr->sx.val.i != 0)
1150 switch (iptr[1].opc) {
1152 iptr->opc = ICMD_IASTORECONST;
1153 iptr->flags.bits |= INS_FLAG_CHECK;
1156 iptr->opc = ICMD_BASTORECONST;
1157 iptr->flags.bits |= INS_FLAG_CHECK;
1160 iptr->opc = ICMD_CASTORECONST;
1161 iptr->flags.bits |= INS_FLAG_CHECK;
1164 iptr->opc = ICMD_SASTORECONST;
1165 iptr->flags.bits |= INS_FLAG_CHECK;
1169 iptr[1].opc = ICMD_NOP;
1171 /* copy the constant to s3 */
1172 /* XXX constval -> astoreconstval? */
1173 iptr->sx.s23.s3.constval = iptr->sx.val.i;
1174 OP2_0(TYPE_ADR, TYPE_INT);
1175 COUNT(count_pcmd_op);
1178 case ICMD_PUTSTATIC:
1180 IF_INTRP( goto normal_ICONST; )
1181 # if SUPPORT_CONST_STORE_ZERO_ONLY
1182 if (iptr->sx.val.i != 0)
1185 /* XXX check field type? */
1187 /* copy the constant to s2 */
1188 /* XXX constval -> fieldconstval? */
1189 iptr->sx.s23.s2.constval = iptr->sx.val.i;
1192 /* set the field reference (s3) */
1193 if (iptr[1].flags.bits & INS_FLAG_UNRESOLVED) {
1194 iptr->sx.s23.s3.uf = iptr[1].sx.s23.s3.uf;
1195 iptr->flags.bits |= INS_FLAG_UNRESOLVED;
1198 iptr->sx.s23.s3.fmiref = iptr[1].sx.s23.s3.fmiref;
1201 switch (iptr[1].opc) {
1202 case ICMD_PUTSTATIC:
1203 iptr->opc = ICMD_PUTSTATICCONST;
1207 iptr->opc = ICMD_PUTFIELDCONST;
1212 iptr[1].opc = ICMD_NOP;
1213 COUNT(count_pcmd_op);
1215 #endif /* SUPPORT_CONST_STORE */
1221 /* if we get here, the ICONST has been optimized */
1225 /* normal case of an unoptimized ICONST */
1229 /************************** LCONST OPTIMIZATIONS **************************/
1232 COUNT(count_pcmd_load);
1236 /* switch depending on the following instruction */
1238 switch (iptr[1].opc) {
1239 #if SUPPORT_LONG_ADD
1241 iptr->opc = ICMD_LADDCONST;
1245 /* instruction of type LONG -> LONG */
1246 iptr[1].opc = ICMD_NOP;
1247 OP1_1(TYPE_LNG, TYPE_LNG);
1248 COUNT(count_pcmd_op);
1252 iptr->opc = ICMD_LSUBCONST;
1253 goto icmd_lconst_tail;
1255 #endif /* SUPPORT_LONG_ADD */
1256 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
1258 iptr->opc = ICMD_LMULCONST;
1259 goto icmd_lconst_tail;
1260 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1261 # if SUPPORT_LONG_SHIFT
1263 if (iptr->sx.val.l == 0x00000002)
1265 else if (iptr->sx.val.l == 0x00000004)
1267 else if (iptr->sx.val.l == 0x00000008)
1269 else if (iptr->sx.val.l == 0x00000010)
1271 else if (iptr->sx.val.l == 0x00000020)
1273 else if (iptr->sx.val.l == 0x00000040)
1275 else if (iptr->sx.val.l == 0x00000080)
1277 else if (iptr->sx.val.l == 0x00000100)
1279 else if (iptr->sx.val.l == 0x00000200)
1281 else if (iptr->sx.val.l == 0x00000400)
1282 iptr->sx.val.i = 10;
1283 else if (iptr->sx.val.l == 0x00000800)
1284 iptr->sx.val.i = 11;
1285 else if (iptr->sx.val.l == 0x00001000)
1286 iptr->sx.val.i = 12;
1287 else if (iptr->sx.val.l == 0x00002000)
1288 iptr->sx.val.i = 13;
1289 else if (iptr->sx.val.l == 0x00004000)
1290 iptr->sx.val.i = 14;
1291 else if (iptr->sx.val.l == 0x00008000)
1292 iptr->sx.val.i = 15;
1293 else if (iptr->sx.val.l == 0x00010000)
1294 iptr->sx.val.i = 16;
1295 else if (iptr->sx.val.l == 0x00020000)
1296 iptr->sx.val.i = 17;
1297 else if (iptr->sx.val.l == 0x00040000)
1298 iptr->sx.val.i = 18;
1299 else if (iptr->sx.val.l == 0x00080000)
1300 iptr->sx.val.i = 19;
1301 else if (iptr->sx.val.l == 0x00100000)
1302 iptr->sx.val.i = 20;
1303 else if (iptr->sx.val.l == 0x00200000)
1304 iptr->sx.val.i = 21;
1305 else if (iptr->sx.val.l == 0x00400000)
1306 iptr->sx.val.i = 22;
1307 else if (iptr->sx.val.l == 0x00800000)
1308 iptr->sx.val.i = 23;
1309 else if (iptr->sx.val.l == 0x01000000)
1310 iptr->sx.val.i = 24;
1311 else if (iptr->sx.val.l == 0x02000000)
1312 iptr->sx.val.i = 25;
1313 else if (iptr->sx.val.l == 0x04000000)
1314 iptr->sx.val.i = 26;
1315 else if (iptr->sx.val.l == 0x08000000)
1316 iptr->sx.val.i = 27;
1317 else if (iptr->sx.val.l == 0x10000000)
1318 iptr->sx.val.i = 28;
1319 else if (iptr->sx.val.l == 0x20000000)
1320 iptr->sx.val.i = 29;
1321 else if (iptr->sx.val.l == 0x40000000)
1322 iptr->sx.val.i = 30;
1323 else if (iptr->sx.val.l == 0x80000000)
1324 iptr->sx.val.i = 31;
1328 iptr->opc = ICMD_LMULPOW2;
1329 goto icmd_lconst_tail;
1330 # endif /* SUPPORT_LONG_SHIFT */
1331 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1332 #if SUPPORT_LONG_DIV_POW2
1334 if (iptr->sx.val.l == 0x00000002)
1336 else if (iptr->sx.val.l == 0x00000004)
1338 else if (iptr->sx.val.l == 0x00000008)
1340 else if (iptr->sx.val.l == 0x00000010)
1342 else if (iptr->sx.val.l == 0x00000020)
1344 else if (iptr->sx.val.l == 0x00000040)
1346 else if (iptr->sx.val.l == 0x00000080)
1348 else if (iptr->sx.val.l == 0x00000100)
1350 else if (iptr->sx.val.l == 0x00000200)
1352 else if (iptr->sx.val.l == 0x00000400)
1353 iptr->sx.val.i = 10;
1354 else if (iptr->sx.val.l == 0x00000800)
1355 iptr->sx.val.i = 11;
1356 else if (iptr->sx.val.l == 0x00001000)
1357 iptr->sx.val.i = 12;
1358 else if (iptr->sx.val.l == 0x00002000)
1359 iptr->sx.val.i = 13;
1360 else if (iptr->sx.val.l == 0x00004000)
1361 iptr->sx.val.i = 14;
1362 else if (iptr->sx.val.l == 0x00008000)
1363 iptr->sx.val.i = 15;
1364 else if (iptr->sx.val.l == 0x00010000)
1365 iptr->sx.val.i = 16;
1366 else if (iptr->sx.val.l == 0x00020000)
1367 iptr->sx.val.i = 17;
1368 else if (iptr->sx.val.l == 0x00040000)
1369 iptr->sx.val.i = 18;
1370 else if (iptr->sx.val.l == 0x00080000)
1371 iptr->sx.val.i = 19;
1372 else if (iptr->sx.val.l == 0x00100000)
1373 iptr->sx.val.i = 20;
1374 else if (iptr->sx.val.l == 0x00200000)
1375 iptr->sx.val.i = 21;
1376 else if (iptr->sx.val.l == 0x00400000)
1377 iptr->sx.val.i = 22;
1378 else if (iptr->sx.val.l == 0x00800000)
1379 iptr->sx.val.i = 23;
1380 else if (iptr->sx.val.l == 0x01000000)
1381 iptr->sx.val.i = 24;
1382 else if (iptr->sx.val.l == 0x02000000)
1383 iptr->sx.val.i = 25;
1384 else if (iptr->sx.val.l == 0x04000000)
1385 iptr->sx.val.i = 26;
1386 else if (iptr->sx.val.l == 0x08000000)
1387 iptr->sx.val.i = 27;
1388 else if (iptr->sx.val.l == 0x10000000)
1389 iptr->sx.val.i = 28;
1390 else if (iptr->sx.val.l == 0x20000000)
1391 iptr->sx.val.i = 29;
1392 else if (iptr->sx.val.l == 0x40000000)
1393 iptr->sx.val.i = 30;
1394 else if (iptr->sx.val.l == 0x80000000)
1395 iptr->sx.val.i = 31;
1399 iptr->opc = ICMD_LDIVPOW2;
1400 goto icmd_lconst_tail;
1401 #endif /* SUPPORT_LONG_DIV_POW2 */
1403 #if SUPPORT_LONG_REM_POW2
1405 if ((iptr->sx.val.l == 0x00000002) ||
1406 (iptr->sx.val.l == 0x00000004) ||
1407 (iptr->sx.val.l == 0x00000008) ||
1408 (iptr->sx.val.l == 0x00000010) ||
1409 (iptr->sx.val.l == 0x00000020) ||
1410 (iptr->sx.val.l == 0x00000040) ||
1411 (iptr->sx.val.l == 0x00000080) ||
1412 (iptr->sx.val.l == 0x00000100) ||
1413 (iptr->sx.val.l == 0x00000200) ||
1414 (iptr->sx.val.l == 0x00000400) ||
1415 (iptr->sx.val.l == 0x00000800) ||
1416 (iptr->sx.val.l == 0x00001000) ||
1417 (iptr->sx.val.l == 0x00002000) ||
1418 (iptr->sx.val.l == 0x00004000) ||
1419 (iptr->sx.val.l == 0x00008000) ||
1420 (iptr->sx.val.l == 0x00010000) ||
1421 (iptr->sx.val.l == 0x00020000) ||
1422 (iptr->sx.val.l == 0x00040000) ||
1423 (iptr->sx.val.l == 0x00080000) ||
1424 (iptr->sx.val.l == 0x00100000) ||
1425 (iptr->sx.val.l == 0x00200000) ||
1426 (iptr->sx.val.l == 0x00400000) ||
1427 (iptr->sx.val.l == 0x00800000) ||
1428 (iptr->sx.val.l == 0x01000000) ||
1429 (iptr->sx.val.l == 0x02000000) ||
1430 (iptr->sx.val.l == 0x04000000) ||
1431 (iptr->sx.val.l == 0x08000000) ||
1432 (iptr->sx.val.l == 0x10000000) ||
1433 (iptr->sx.val.l == 0x20000000) ||
1434 (iptr->sx.val.l == 0x40000000) ||
1435 (iptr->sx.val.l == 0x80000000))
1437 iptr->opc = ICMD_LREMPOW2;
1438 iptr->sx.val.l -= 1;
1439 goto icmd_lconst_tail;
1442 #endif /* SUPPORT_LONG_REM_POW2 */
1444 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
1447 iptr->opc = ICMD_LANDCONST;
1448 goto icmd_lconst_tail;
1451 iptr->opc = ICMD_LORCONST;
1452 goto icmd_lconst_tail;
1455 iptr->opc = ICMD_LXORCONST;
1456 goto icmd_lconst_tail;
1457 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
1459 #if SUPPORT_LONG_CMP_CONST
1461 if ((len <= 1) || (iptr[2].sx.val.i != 0))
1464 /* switch on the instruction after LCONST - LCMP */
1466 switch (iptr[2].opc) {
1468 iptr->opc = ICMD_IF_LEQ;
1471 icmd_lconst_lcmp_tail:
1472 /* convert LCONST, LCMP, IFXX to IF_LXX */
1473 iptr->dst.insindex = iptr[2].dst.insindex;
1474 iptr[1].opc = ICMD_NOP;
1475 iptr[2].opc = ICMD_NOP;
1477 OP1_BRANCH(TYPE_LNG);
1478 BRANCH(tbptr, copy);
1479 COUNT(count_pcmd_bra);
1480 COUNT(count_pcmd_op);
1484 iptr->opc = ICMD_IF_LNE;
1485 goto icmd_lconst_lcmp_tail;
1488 iptr->opc = ICMD_IF_LLT;
1489 goto icmd_lconst_lcmp_tail;
1492 iptr->opc = ICMD_IF_LGT;
1493 goto icmd_lconst_lcmp_tail;
1496 iptr->opc = ICMD_IF_LLE;
1497 goto icmd_lconst_lcmp_tail;
1500 iptr->opc = ICMD_IF_LGE;
1501 goto icmd_lconst_lcmp_tail;
1505 } /* end switch on opcode after LCONST - LCMP */
1507 #endif /* SUPPORT_LONG_CMP_CONST */
1509 #if SUPPORT_CONST_STORE
1511 IF_INTRP( goto normal_LCONST; )
1512 # if SUPPORT_CONST_STORE_ZERO_ONLY
1513 if (iptr->sx.val.l != 0)
1516 #if SIZEOF_VOID_P == 4
1517 /* the constant must fit into a ptrint */
1518 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1521 /* move the constant to s3 */
1522 iptr->sx.s23.s3.constval = iptr->sx.val.l;
1524 iptr->opc = ICMD_LASTORECONST;
1525 iptr->flags.bits |= INS_FLAG_CHECK;
1526 OP2_0(TYPE_ADR, TYPE_INT);
1528 iptr[1].opc = ICMD_NOP;
1529 COUNT(count_pcmd_op);
1532 case ICMD_PUTSTATIC:
1534 IF_INTRP( goto normal_LCONST; )
1535 # if SUPPORT_CONST_STORE_ZERO_ONLY
1536 if (iptr->sx.val.l != 0)
1539 #if SIZEOF_VOID_P == 4
1540 /* the constant must fit into a ptrint */
1541 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1544 /* XXX check field type? */
1546 /* copy the constant to s2 */
1547 /* XXX constval -> fieldconstval? */
1548 iptr->sx.s23.s2.constval = iptr->sx.val.l;
1552 #endif /* SUPPORT_CONST_STORE */
1556 } /* end switch opcode after LCONST */
1558 /* if we get here, the LCONST has been optimized */
1562 /* the normal case of an unoptimized LCONST */
1566 /************************ END OF LCONST OPTIMIZATIONS *********************/
1569 COUNT(count_pcmd_load);
1574 COUNT(count_pcmd_load);
1578 /************************** ACONST OPTIMIZATIONS **************************/
1581 coalescing_boundary = sd.new;
1582 COUNT(count_pcmd_load);
1583 #if SUPPORT_CONST_STORE
1584 IF_INTRP( goto normal_ACONST; )
1586 /* We can only optimize if the ACONST is resolved
1587 * and there is an instruction after it. */
1589 if ((len == 0) || (iptr->flags.bits & INS_FLAG_UNRESOLVED))
1592 switch (iptr[1].opc) {
1594 /* We can only optimize for NULL values
1595 * here because otherwise a checkcast is
1597 if (iptr->sx.val.anyptr != NULL)
1600 /* copy the constant (NULL) to s3 */
1601 iptr->sx.s23.s3.constval = 0;
1602 iptr->opc = ICMD_AASTORECONST;
1603 iptr->flags.bits |= INS_FLAG_CHECK;
1604 OP2_0(TYPE_ADR, TYPE_INT);
1606 iptr[1].opc = ICMD_NOP;
1607 COUNT(count_pcmd_op);
1610 case ICMD_PUTSTATIC:
1612 # if SUPPORT_CONST_STORE_ZERO_ONLY
1613 if (iptr->sx.val.anyptr != NULL)
1616 /* XXX check field type? */
1617 /* copy the constant to s2 */
1618 /* XXX constval -> fieldconstval? */
1619 iptr->sx.s23.s2.constval = (ptrint) iptr->sx.val.anyptr;
1627 /* if we get here the ACONST has been optimized */
1631 #endif /* SUPPORT_CONST_STORE */
1636 /* pop 0 push 1 load */
1643 COUNT(count_load_instruction);
1644 i = opcode - ICMD_ILOAD; /* type */
1647 jd->local_map[iptr->s1.varindex * 5 + i];
1649 LOAD(i, iptr->s1.varindex);
1658 coalescing_boundary = sd.new;
1659 iptr->flags.bits |= INS_FLAG_CHECK;
1660 COUNT(count_check_null);
1661 COUNT(count_check_bound);
1662 COUNT(count_pcmd_mem);
1663 OP2_1(TYPE_ADR, TYPE_INT, opcode - ICMD_IALOAD);
1670 coalescing_boundary = sd.new;
1671 iptr->flags.bits |= INS_FLAG_CHECK;
1672 COUNT(count_check_null);
1673 COUNT(count_check_bound);
1674 COUNT(count_pcmd_mem);
1675 OP2_1(TYPE_ADR, TYPE_INT, TYPE_INT);
1678 /* pop 0 push 0 iinc */
1681 STATISTICS_STACKDEPTH_DISTRIBUTION(count_store_depth);
1683 last_store_boundary[iptr->s1.varindex] = sd.new;
1686 jd->local_map[iptr->s1.varindex * 5 + TYPE_INT];
1691 if ((copy->varkind == LOCALVAR) &&
1692 (copy->varnum == iptr->s1.varindex))
1694 assert(IS_LOCALVAR(copy));
1701 iptr->dst.varindex = iptr->s1.varindex;
1704 /* pop 1 push 0 store */
1713 i = opcode - ICMD_ISTORE; /* type */
1714 javaindex = iptr->dst.varindex;
1715 j = iptr->dst.varindex =
1716 jd->local_map[javaindex * 5 + i];
1719 #if defined(ENABLE_STATISTICS)
1722 i = sd.new - curstack;
1724 count_store_length[20]++;
1726 count_store_length[i]++;
1729 count_store_depth[10]++;
1731 count_store_depth[i]++;
1734 /* check for conflicts as described in Figure 5.2 */
1736 copy = curstack->prev;
1739 if ((copy->varkind == LOCALVAR) &&
1740 (copy->varnum == j))
1742 copy->varkind = TEMPVAR;
1743 assert(IS_LOCALVAR(copy));
1750 /* if the variable is already coalesced, don't bother */
1752 if (IS_OUTVAR(curstack)
1753 || (curstack->varkind == LOCALVAR
1754 && curstack->varnum != j))
1757 /* there is no STORE Lj while curstack is live */
1759 if (curstack < last_store_boundary[javaindex])
1760 goto assume_conflict;
1762 /* curstack must be after the coalescing boundary */
1764 if (curstack < coalescing_boundary)
1765 goto assume_conflict;
1767 /* there is no DEF LOCALVAR(j) while curstack is live */
1769 copy = sd.new; /* most recent stackslot created + 1 */
1770 while (--copy > curstack) {
1771 if (copy->varkind == LOCALVAR && copy->varnum == j)
1772 goto assume_conflict;
1775 /* coalesce the temporary variable with Lj */
1776 assert( (CURKIND == TEMPVAR) || (CURKIND == UNDEFVAR));
1777 assert(!IS_LOCALVAR(curstack));
1778 assert(!IS_OUTVAR(curstack));
1779 assert(!IS_PREALLOC(curstack));
1781 assert(curstack->creator);
1782 assert(curstack->creator->dst.varindex == curstack->varnum);
1783 RELEASE_INDEX(sd, curstack);
1784 curstack->varkind = LOCALVAR;
1785 curstack->varnum = j;
1786 curstack->creator->dst.varindex = j;
1789 /* revert the coalescing, if it has been done earlier */
1791 if ((curstack->varkind == LOCALVAR)
1792 && (curstack->varnum == j))
1794 assert(IS_LOCALVAR(curstack));
1795 SET_TEMPVAR(curstack);
1798 /* remember the stack boundary at this store */
1800 last_store_boundary[javaindex] = sd.new;
1802 STORE(opcode - ICMD_ISTORE, j);
1808 coalescing_boundary = sd.new;
1809 iptr->flags.bits |= INS_FLAG_CHECK;
1810 COUNT(count_check_null);
1811 COUNT(count_check_bound);
1812 COUNT(count_pcmd_mem);
1814 bte = builtintable_get_internal(BUILTIN_canstore);
1817 if (md->memuse > rd->memuse)
1818 rd->memuse = md->memuse;
1819 if (md->argintreguse > rd->argintreguse)
1820 rd->argintreguse = md->argintreguse;
1821 /* XXX non-leaf method? */
1823 /* make all stack variables saved */
1827 sd.var[copy->varnum].flags |= SAVEDVAR;
1828 /* in case copy->varnum is/will be a LOCALVAR */
1829 /* once and set back to a non LOCALVAR */
1830 /* the correct SAVEDVAR flag has to be */
1831 /* remembered in copy->flags, too */
1832 copy->flags |= SAVEDVAR;
1836 OP3_0(TYPE_ADR, TYPE_INT, TYPE_ADR);
1843 coalescing_boundary = sd.new;
1844 iptr->flags.bits |= INS_FLAG_CHECK;
1845 COUNT(count_check_null);
1846 COUNT(count_check_bound);
1847 COUNT(count_pcmd_mem);
1848 OP3_0(TYPE_ADR, TYPE_INT, opcode - ICMD_IASTORE);
1855 coalescing_boundary = sd.new;
1856 iptr->flags.bits |= INS_FLAG_CHECK;
1857 COUNT(count_check_null);
1858 COUNT(count_check_bound);
1859 COUNT(count_pcmd_mem);
1860 OP3_0(TYPE_ADR, TYPE_INT, TYPE_INT);
1866 #ifdef ENABLE_VERIFIER
1869 if (IS_2_WORD_TYPE(curstack->type))
1870 goto throw_stack_category_error;
1881 coalescing_boundary = sd.new;
1882 IF_JIT( md_return_alloc(jd, curstack); )
1883 COUNT(count_pcmd_return);
1884 OP1_0(opcode - ICMD_IRETURN);
1885 superblockend = true;
1889 coalescing_boundary = sd.new;
1890 COUNT(count_check_null);
1892 curstack = NULL; stackdepth = 0;
1893 superblockend = true;
1896 case ICMD_PUTSTATIC:
1897 coalescing_boundary = sd.new;
1898 COUNT(count_pcmd_mem);
1899 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1900 OP1_0(fmiref->parseddesc.fd->type);
1903 /* pop 1 push 0 branch */
1906 case ICMD_IFNONNULL:
1907 COUNT(count_pcmd_bra);
1908 OP1_BRANCH(TYPE_ADR);
1909 BRANCH(tbptr, copy);
1918 COUNT(count_pcmd_bra);
1919 /* iptr->sx.val.i is set implicitly in parse by
1920 clearing the memory or from IF_ICMPxx
1923 OP1_BRANCH(TYPE_INT);
1924 /* iptr->sx.val.i = 0; */
1925 BRANCH(tbptr, copy);
1928 /* pop 0 push 0 branch */
1931 COUNT(count_pcmd_bra);
1933 BRANCH(tbptr, copy);
1934 superblockend = true;
1937 /* pop 1 push 0 table branch */
1939 case ICMD_TABLESWITCH:
1940 COUNT(count_pcmd_table);
1941 OP1_BRANCH(TYPE_INT);
1943 table = iptr->dst.table;
1944 BRANCH_TARGET(*table, tbptr, copy);
1947 i = iptr->sx.s23.s3.tablehigh
1948 - iptr->sx.s23.s2.tablelow + 1;
1951 BRANCH_TARGET(*table, tbptr, copy);
1954 superblockend = true;
1957 /* pop 1 push 0 table branch */
1959 case ICMD_LOOKUPSWITCH:
1960 COUNT(count_pcmd_table);
1961 OP1_BRANCH(TYPE_INT);
1963 BRANCH_TARGET(iptr->sx.s23.s3.lookupdefault, tbptr, copy);
1965 lookup = iptr->dst.lookup;
1967 i = iptr->sx.s23.s2.lookupcount;
1970 BRANCH_TARGET(lookup->target, tbptr, copy);
1973 superblockend = true;
1976 case ICMD_MONITORENTER:
1977 case ICMD_MONITOREXIT:
1978 coalescing_boundary = sd.new;
1979 COUNT(count_check_null);
1983 /* pop 2 push 0 branch */
1985 case ICMD_IF_ICMPEQ:
1986 case ICMD_IF_ICMPNE:
1987 case ICMD_IF_ICMPLT:
1988 case ICMD_IF_ICMPGE:
1989 case ICMD_IF_ICMPGT:
1990 case ICMD_IF_ICMPLE:
1991 COUNT(count_pcmd_bra);
1992 OP2_BRANCH(TYPE_INT, TYPE_INT);
1993 BRANCH(tbptr, copy);
1996 case ICMD_IF_ACMPEQ:
1997 case ICMD_IF_ACMPNE:
1998 COUNT(count_pcmd_bra);
1999 OP2_BRANCH(TYPE_ADR, TYPE_ADR);
2000 BRANCH(tbptr, copy);
2006 coalescing_boundary = sd.new;
2007 COUNT(count_check_null);
2008 COUNT(count_pcmd_mem);
2009 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2010 OP2_0(TYPE_ADR, fmiref->parseddesc.fd->type);
2015 if (!IS_2_WORD_TYPE(curstack->type)) {
2017 #ifdef ENABLE_VERIFIER
2020 if (IS_2_WORD_TYPE(curstack->prev->type))
2021 goto throw_stack_category_error;
2024 OP2_0_ANY_ANY; /* pop two slots */
2027 iptr->opc = ICMD_POP;
2028 OP1_0_ANY; /* pop one (two-word) slot */
2032 /* pop 0 push 1 dup */
2035 #ifdef ENABLE_VERIFIER
2038 if (IS_2_WORD_TYPE(curstack->type))
2039 goto throw_stack_category_error;
2042 COUNT(count_dup_instruction);
2048 coalescing_boundary = sd.new - 1;
2053 if (IS_2_WORD_TYPE(curstack->type)) {
2055 iptr->opc = ICMD_DUP;
2060 /* ..., ????, cat1 */
2061 #ifdef ENABLE_VERIFIER
2063 if (IS_2_WORD_TYPE(curstack->prev->type))
2064 goto throw_stack_category_error;
2067 src1 = curstack->prev;
2070 COPY_UP(src1); iptr++; len--;
2073 coalescing_boundary = sd.new;
2077 /* pop 2 push 3 dup */
2080 #ifdef ENABLE_VERIFIER
2083 if (IS_2_WORD_TYPE(curstack->type) ||
2084 IS_2_WORD_TYPE(curstack->prev->type))
2085 goto throw_stack_category_error;
2090 src1 = curstack->prev;
2095 DUP_SLOT(src2); dst1 = curstack; stackdepth++;
2097 MOVE_UP(src1); iptr++; len--;
2098 MOVE_UP(src2); iptr++; len--;
2100 COPY_DOWN(curstack, dst1);
2102 coalescing_boundary = sd.new;
2107 if (IS_2_WORD_TYPE(curstack->type)) {
2108 /* ..., ????, cat2 */
2109 #ifdef ENABLE_VERIFIER
2111 if (IS_2_WORD_TYPE(curstack->prev->type))
2112 goto throw_stack_category_error;
2115 iptr->opc = ICMD_DUP_X1;
2119 /* ..., ????, cat1 */
2120 #ifdef ENABLE_VERIFIER
2123 if (IS_2_WORD_TYPE(curstack->prev->type)
2124 || IS_2_WORD_TYPE(curstack->prev->prev->type))
2125 goto throw_stack_category_error;
2130 src1 = curstack->prev->prev;
2131 src2 = curstack->prev;
2133 POPANY; POPANY; POPANY;
2136 DUP_SLOT(src2); dst1 = curstack; stackdepth++;
2137 DUP_SLOT(src3); dst2 = curstack; stackdepth++;
2139 MOVE_UP(src1); iptr++; len--;
2140 MOVE_UP(src2); iptr++; len--;
2141 MOVE_UP(src3); iptr++; len--;
2143 COPY_DOWN(curstack, dst2); iptr++; len--;
2144 COPY_DOWN(curstack->prev, dst1);
2146 coalescing_boundary = sd.new;
2150 /* pop 3 push 4 dup */
2154 if (IS_2_WORD_TYPE(curstack->prev->type)) {
2155 /* ..., cat2, ???? */
2156 #ifdef ENABLE_VERIFIER
2158 if (IS_2_WORD_TYPE(curstack->type))
2159 goto throw_stack_category_error;
2162 iptr->opc = ICMD_DUP_X1;
2166 /* ..., cat1, ???? */
2167 #ifdef ENABLE_VERIFIER
2170 if (IS_2_WORD_TYPE(curstack->type)
2171 || IS_2_WORD_TYPE(curstack->prev->prev->type))
2172 goto throw_stack_category_error;
2176 src1 = curstack->prev->prev;
2177 src2 = curstack->prev;
2179 POPANY; POPANY; POPANY;
2182 DUP_SLOT(src3); dst1 = curstack; stackdepth++;
2184 MOVE_UP(src1); iptr++; len--;
2185 MOVE_UP(src2); iptr++; len--;
2186 MOVE_UP(src3); iptr++; len--;
2188 COPY_DOWN(curstack, dst1);
2190 coalescing_boundary = sd.new;
2196 if (IS_2_WORD_TYPE(curstack->type)) {
2197 /* ..., ????, cat2 */
2198 if (IS_2_WORD_TYPE(curstack->prev->type)) {
2199 /* ..., cat2, cat2 */
2200 iptr->opc = ICMD_DUP_X1;
2204 /* ..., cat1, cat2 */
2205 #ifdef ENABLE_VERIFIER
2208 if (IS_2_WORD_TYPE(curstack->prev->prev->type))
2209 goto throw_stack_category_error;
2212 iptr->opc = ICMD_DUP_X2;
2218 /* ..., ????, ????, cat1 */
2220 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
2221 /* ..., cat2, ????, cat1 */
2222 #ifdef ENABLE_VERIFIER
2224 if (IS_2_WORD_TYPE(curstack->prev->type))
2225 goto throw_stack_category_error;
2228 iptr->opc = ICMD_DUP2_X1;
2232 /* ..., cat1, ????, cat1 */
2233 #ifdef ENABLE_VERIFIER
2236 if (IS_2_WORD_TYPE(curstack->prev->type)
2237 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
2238 goto throw_stack_category_error;
2242 src1 = curstack->prev->prev->prev;
2243 src2 = curstack->prev->prev;
2244 src3 = curstack->prev;
2246 POPANY; POPANY; POPANY; POPANY;
2249 DUP_SLOT(src3); dst1 = curstack; stackdepth++;
2250 DUP_SLOT(src4); dst2 = curstack; stackdepth++;
2252 MOVE_UP(src1); iptr++; len--;
2253 MOVE_UP(src2); iptr++; len--;
2254 MOVE_UP(src3); iptr++; len--;
2255 MOVE_UP(src4); iptr++; len--;
2257 COPY_DOWN(curstack, dst2); iptr++; len--;
2258 COPY_DOWN(curstack->prev, dst1);
2260 coalescing_boundary = sd.new;
2264 /* pop 2 push 2 swap */
2267 #ifdef ENABLE_VERIFIER
2270 if (IS_2_WORD_TYPE(curstack->type)
2271 || IS_2_WORD_TYPE(curstack->prev->type))
2272 goto throw_stack_category_error;
2276 src1 = curstack->prev;
2281 MOVE_UP(src2); iptr++; len--;
2284 coalescing_boundary = sd.new;
2291 coalescing_boundary = sd.new;
2292 #if !SUPPORT_DIVISION
2293 bte = iptr->sx.s23.s3.bte;
2296 if (md->memuse > rd->memuse)
2297 rd->memuse = md->memuse;
2298 if (md->argintreguse > rd->argintreguse)
2299 rd->argintreguse = md->argintreguse;
2301 /* make all stack variables saved */
2305 sd.var[copy->varnum].flags |= SAVEDVAR;
2306 copy->flags |= SAVEDVAR;
2311 #endif /* !SUPPORT_DIVISION */
2322 COUNT(count_pcmd_op);
2323 OP2_1(TYPE_INT, TYPE_INT, TYPE_INT);
2328 coalescing_boundary = sd.new;
2329 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
2330 bte = iptr->sx.s23.s3.bte;
2333 if (md->memuse > rd->memuse)
2334 rd->memuse = md->memuse;
2335 if (md->argintreguse > rd->argintreguse)
2336 rd->argintreguse = md->argintreguse;
2337 /* XXX non-leaf method? */
2339 /* make all stack variables saved */
2343 sd.var[copy->varnum].flags |= SAVEDVAR;
2344 copy->flags |= SAVEDVAR;
2349 #endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
2354 #if SUPPORT_LONG_LOGICAL
2358 #endif /* SUPPORT_LONG_LOGICAL */
2359 COUNT(count_pcmd_op);
2360 OP2_1(TYPE_LNG, TYPE_LNG, TYPE_LNG);
2366 COUNT(count_pcmd_op);
2367 OP2_1(TYPE_LNG, TYPE_INT, TYPE_LNG);
2375 COUNT(count_pcmd_op);
2376 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_FLT);
2384 COUNT(count_pcmd_op);
2385 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_DBL);
2389 COUNT(count_pcmd_op);
2390 #if SUPPORT_LONG_CMP_CONST
2391 if ((len == 0) || (iptr[1].sx.val.i != 0))
2394 switch (iptr[1].opc) {
2396 iptr->opc = ICMD_IF_LCMPEQ;
2398 iptr->dst.insindex = iptr[1].dst.insindex;
2399 iptr[1].opc = ICMD_NOP;
2401 OP2_BRANCH(TYPE_LNG, TYPE_LNG);
2402 BRANCH(tbptr, copy);
2404 COUNT(count_pcmd_bra);
2407 iptr->opc = ICMD_IF_LCMPNE;
2408 goto icmd_lcmp_if_tail;
2410 iptr->opc = ICMD_IF_LCMPLT;
2411 goto icmd_lcmp_if_tail;
2413 iptr->opc = ICMD_IF_LCMPGT;
2414 goto icmd_lcmp_if_tail;
2416 iptr->opc = ICMD_IF_LCMPLE;
2417 goto icmd_lcmp_if_tail;
2419 iptr->opc = ICMD_IF_LCMPGE;
2420 goto icmd_lcmp_if_tail;
2426 #endif /* SUPPORT_LONG_CMP_CONST */
2427 OP2_1(TYPE_LNG, TYPE_LNG, TYPE_INT);
2430 /* XXX why is this deactivated? */
2433 COUNT(count_pcmd_op);
2434 if ((len == 0) || (iptr[1].sx.val.i != 0))
2437 switch (iptr[1].opc) {
2439 iptr->opc = ICMD_IF_FCMPEQ;
2441 iptr->dst.insindex = iptr[1].dst.insindex;
2442 iptr[1].opc = ICMD_NOP;
2444 OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2445 BRANCH(tbptr, copy);
2447 COUNT(count_pcmd_bra);
2450 iptr->opc = ICMD_IF_FCMPNE;
2451 goto icmd_if_fcmpl_tail;
2453 iptr->opc = ICMD_IF_FCMPL_LT;
2454 goto icmd_if_fcmpl_tail;
2456 iptr->opc = ICMD_IF_FCMPL_GT;
2457 goto icmd_if_fcmpl_tail;
2459 iptr->opc = ICMD_IF_FCMPL_LE;
2460 goto icmd_if_fcmpl_tail;
2462 iptr->opc = ICMD_IF_FCMPL_GE;
2463 goto icmd_if_fcmpl_tail;
2470 OPTT2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2474 COUNT(count_pcmd_op);
2475 if ((len == 0) || (iptr[1].sx.val.i != 0))
2478 switch (iptr[1].opc) {
2480 iptr->opc = ICMD_IF_FCMPEQ;
2482 iptr->dst.insindex = iptr[1].dst.insindex;
2483 iptr[1].opc = ICMD_NOP;
2485 OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2486 BRANCH(tbptr, copy);
2488 COUNT(count_pcmd_bra);
2491 iptr->opc = ICMD_IF_FCMPNE;
2492 goto icmd_if_fcmpg_tail;
2494 iptr->opc = ICMD_IF_FCMPG_LT;
2495 goto icmd_if_fcmpg_tail;
2497 iptr->opc = ICMD_IF_FCMPG_GT;
2498 goto icmd_if_fcmpg_tail;
2500 iptr->opc = ICMD_IF_FCMPG_LE;
2501 goto icmd_if_fcmpg_tail;
2503 iptr->opc = ICMD_IF_FCMPG_GE;
2504 goto icmd_if_fcmpg_tail;
2511 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2515 COUNT(count_pcmd_op);
2516 if ((len == 0) || (iptr[1].sx.val.i != 0))
2519 switch (iptr[1].opc) {
2521 iptr->opc = ICMD_IF_DCMPEQ;
2523 iptr->dst.insindex = iptr[1].dst.insindex;
2524 iptr[1].opc = ICMD_NOP;
2526 OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2527 BRANCH(tbptr, copy);
2529 COUNT(count_pcmd_bra);
2532 iptr->opc = ICMD_IF_DCMPNE;
2533 goto icmd_if_dcmpl_tail;
2535 iptr->opc = ICMD_IF_DCMPL_LT;
2536 goto icmd_if_dcmpl_tail;
2538 iptr->opc = ICMD_IF_DCMPL_GT;
2539 goto icmd_if_dcmpl_tail;
2541 iptr->opc = ICMD_IF_DCMPL_LE;
2542 goto icmd_if_dcmpl_tail;
2544 iptr->opc = ICMD_IF_DCMPL_GE;
2545 goto icmd_if_dcmpl_tail;
2552 OPTT2_1(TYPE_DBL, TYPE_INT);
2556 COUNT(count_pcmd_op);
2557 if ((len == 0) || (iptr[1].sx.val.i != 0))
2560 switch (iptr[1].opc) {
2562 iptr->opc = ICMD_IF_DCMPEQ;
2564 iptr->dst.insindex = iptr[1].dst.insindex;
2565 iptr[1].opc = ICMD_NOP;
2567 OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2568 BRANCH(tbptr, copy);
2570 COUNT(count_pcmd_bra);
2573 iptr->opc = ICMD_IF_DCMPNE;
2574 goto icmd_if_dcmpg_tail;
2576 iptr->opc = ICMD_IF_DCMPG_LT;
2577 goto icmd_if_dcmpg_tail;
2579 iptr->opc = ICMD_IF_DCMPG_GT;
2580 goto icmd_if_dcmpg_tail;
2582 iptr->opc = ICMD_IF_DCMPG_LE;
2583 goto icmd_if_dcmpg_tail;
2585 iptr->opc = ICMD_IF_DCMPG_GE;
2586 goto icmd_if_dcmpg_tail;
2593 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2598 COUNT(count_pcmd_op);
2599 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2604 COUNT(count_pcmd_op);
2605 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2614 case ICMD_INT2SHORT:
2615 COUNT(count_pcmd_op);
2616 OP1_1(TYPE_INT, TYPE_INT);
2619 COUNT(count_pcmd_op);
2620 OP1_1(TYPE_LNG, TYPE_LNG);
2623 COUNT(count_pcmd_op);
2624 OP1_1(TYPE_FLT, TYPE_FLT);
2627 COUNT(count_pcmd_op);
2628 OP1_1(TYPE_DBL, TYPE_DBL);
2632 COUNT(count_pcmd_op);
2633 OP1_1(TYPE_INT, TYPE_LNG);
2636 COUNT(count_pcmd_op);
2637 OP1_1(TYPE_INT, TYPE_FLT);
2640 COUNT(count_pcmd_op);
2641 OP1_1(TYPE_INT, TYPE_DBL);
2644 COUNT(count_pcmd_op);
2645 OP1_1(TYPE_LNG, TYPE_INT);
2648 COUNT(count_pcmd_op);
2649 OP1_1(TYPE_LNG, TYPE_FLT);
2652 COUNT(count_pcmd_op);
2653 OP1_1(TYPE_LNG, TYPE_DBL);
2656 COUNT(count_pcmd_op);
2657 OP1_1(TYPE_FLT, TYPE_INT);
2660 COUNT(count_pcmd_op);
2661 OP1_1(TYPE_FLT, TYPE_LNG);
2664 COUNT(count_pcmd_op);
2665 OP1_1(TYPE_FLT, TYPE_DBL);
2668 COUNT(count_pcmd_op);
2669 OP1_1(TYPE_DBL, TYPE_INT);
2672 COUNT(count_pcmd_op);
2673 OP1_1(TYPE_DBL, TYPE_LNG);
2676 COUNT(count_pcmd_op);
2677 OP1_1(TYPE_DBL, TYPE_FLT);
2680 case ICMD_CHECKCAST:
2681 coalescing_boundary = sd.new;
2682 if (iptr->flags.bits & INS_FLAG_ARRAY) {
2683 /* array type cast-check */
2685 bte = builtintable_get_internal(BUILTIN_arraycheckcast);
2688 if (md->memuse > rd->memuse)
2689 rd->memuse = md->memuse;
2690 if (md->argintreguse > rd->argintreguse)
2691 rd->argintreguse = md->argintreguse;
2693 /* make all stack variables saved */
2697 sd.var[copy->varnum].flags |= SAVEDVAR;
2698 copy->flags |= SAVEDVAR;
2702 OP1_1(TYPE_ADR, TYPE_ADR);
2705 case ICMD_INSTANCEOF:
2706 case ICMD_ARRAYLENGTH:
2707 coalescing_boundary = sd.new;
2708 OP1_1(TYPE_ADR, TYPE_INT);
2712 case ICMD_ANEWARRAY:
2713 coalescing_boundary = sd.new;
2714 OP1_1(TYPE_INT, TYPE_ADR);
2718 coalescing_boundary = sd.new;
2719 COUNT(count_check_null);
2720 COUNT(count_pcmd_mem);
2721 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2722 OP1_1(TYPE_ADR, fmiref->parseddesc.fd->type);
2727 case ICMD_GETSTATIC:
2728 coalescing_boundary = sd.new;
2729 COUNT(count_pcmd_mem);
2730 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2731 OP0_1(fmiref->parseddesc.fd->type);
2735 coalescing_boundary = sd.new;
2742 BRANCH_TARGET(iptr->sx.s23.s3.jsrtarget, tbptr, copy);
2744 tbptr->type = BBTYPE_SBR;
2746 /* We need to check for overflow right here because
2747 * the pushed value is poped afterwards */
2750 /* calculate stack after return */
2755 /* pop many push any */
2759 bte = iptr->sx.s23.s3.bte;
2763 case ICMD_INVOKESTATIC:
2764 case ICMD_INVOKESPECIAL:
2765 case ICMD_INVOKEVIRTUAL:
2766 case ICMD_INVOKEINTERFACE:
2767 COUNT(count_pcmd_met);
2769 /* Check for functions to replace with builtin
2772 if (builtintable_replace_function(iptr))
2775 INSTRUCTION_GET_METHODDESC(iptr, md);
2776 /* XXX resurrect this COUNT? */
2777 /* if (lm->flags & ACC_STATIC) */
2778 /* {COUNT(count_check_null);} */
2782 coalescing_boundary = sd.new;
2786 if (md->memuse > rd->memuse)
2787 rd->memuse = md->memuse;
2788 if (md->argintreguse > rd->argintreguse)
2789 rd->argintreguse = md->argintreguse;
2790 if (md->argfltreguse > rd->argfltreguse)
2791 rd->argfltreguse = md->argfltreguse;
2795 /* XXX optimize for <= 2 args */
2796 /* XXX not for ICMD_BUILTIN */
2797 iptr->s1.argcount = stackdepth;
2798 iptr->sx.s23.s2.args = DMNEW(s4, stackdepth);
2801 for (i-- ; i >= 0; i--) {
2802 iptr->sx.s23.s2.args[i] = copy->varnum;
2804 /* do not change STACKVARs or LOCALVARS to ARGVAR*/
2805 /* -> won't help anyway */
2806 if (!(IS_OUTVAR(copy) || IS_LOCALVAR(copy))) {
2808 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2809 /* If we pass float arguments in integer argument registers, we
2810 * are not allowed to precolor them here. Floats have to be moved
2811 * to this regs explicitly in codegen().
2812 * Only arguments that are passed by stack anyway can be precolored
2813 * (michi 2005/07/24) */
2814 if (!(sd.var[copy->varnum].flags & SAVEDVAR) &&
2815 (!IS_FLT_DBL_TYPE(copy->type)
2816 || md->params[i].inmemory)) {
2818 if (!(sd.var[copy->varnum].flags & SAVEDVAR)) {
2823 #if defined(ENABLE_INTRP)
2826 if (md->params[i].inmemory) {
2827 sd.var[copy->varnum].regoff =
2828 md->params[i].regoff;
2829 sd.var[copy->varnum].flags |=
2833 if (IS_FLT_DBL_TYPE(copy->type)) {
2834 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2835 assert(0); /* XXX is this assert ok? */
2837 sd.var[copy->varnum].regoff =
2838 rd->argfltregs[md->params[i].regoff];
2839 #endif /* SUPPORT_PASS_FLOATARGS_IN_INTREGS */
2842 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
2843 if (IS_2_WORD_TYPE(copy->type))
2844 sd.var[copy->varnum].regoff =
2845 PACK_REGS( rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
2846 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
2849 #endif /* SUPPORT_COMBINE_INTEGER_REGISTERS */
2850 sd.var[copy->varnum].regoff =
2851 rd->argintregs[md->params[i].regoff];
2854 #if defined(ENABLE_INTRP)
2855 } /* end if (!opt_intrp) */
2862 /* deal with live-through stack slots "under" the */
2864 /* XXX not for ICMD_BUILTIN */
2870 iptr->sx.s23.s2.args[i++] = copy->varnum;
2871 sd.var[copy->varnum].flags |= SAVEDVAR;
2875 /* pop the arguments */
2884 /* push the return value */
2886 if (md->returntype.type != TYPE_VOID) {
2887 GET_NEW_VAR(sd, new_index, md->returntype.type);
2888 DST(md->returntype.type, new_index);
2893 case ICMD_INLINE_START:
2894 case ICMD_INLINE_END:
2899 case ICMD_MULTIANEWARRAY:
2900 coalescing_boundary = sd.new;
2901 if (rd->argintreguse < 3)
2902 rd->argintreguse = 3;
2904 i = iptr->s1.argcount;
2908 iptr->sx.s23.s2.args = DMNEW(s4, i);
2910 #if defined(SPECIALMEMUSE)
2911 # if defined(__DARWIN__)
2912 if (rd->memuse < (i + INT_ARG_CNT +LA_SIZE_IN_POINTERS))
2913 rd->memuse = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2915 if (rd->memuse < (i + LA_SIZE_IN_POINTERS + 3))
2916 rd->memuse = i + LA_SIZE_IN_POINTERS + 3;
2919 # if defined(__I386__)
2920 if (rd->memuse < i + 3)
2921 rd->memuse = i + 3; /* n integer args spilled on stack */
2922 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2923 if (rd->memuse < i + 2)
2924 rd->memuse = i + 2; /* 4*4 bytes callee save space */
2927 rd->memuse = i; /* n integer args spilled on stack */
2928 # endif /* defined(__I386__) */
2932 /* check INT type here? Currently typecheck does this. */
2933 iptr->sx.s23.s2.args[i] = copy->varnum;
2934 if (!(sd.var[copy->varnum].flags & SAVEDVAR)
2935 && (!IS_OUTVAR(copy))
2936 && (!IS_LOCALVAR(copy)) ) {
2937 copy->varkind = ARGVAR;
2938 sd.var[copy->varnum].flags |=
2939 INMEMORY & PREALLOC;
2940 #if defined(SPECIALMEMUSE)
2941 # if defined(__DARWIN__)
2942 sd.var[copy->varnum].regoff = i +
2943 LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2945 sd.var[copy->varnum].regoff = i +
2946 LA_SIZE_IN_POINTERS + 3;
2949 # if defined(__I386__)
2950 sd.var[copy->varnum].regoff = i + 3;
2951 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2952 sd.var[copy->varnum].regoff = i + 2;
2954 sd.var[copy->varnum].regoff = i;
2955 # endif /* defined(__I386__) */
2956 #endif /* defined(SPECIALMEMUSE) */
2961 sd.var[copy->varnum].flags |= SAVEDVAR;
2965 i = iptr->s1.argcount;
2970 GET_NEW_VAR(sd, new_index, TYPE_ADR);
2971 DST(TYPE_ADR, new_index);
2977 new_internalerror("Unknown ICMD %d", opcode);
2983 } /* while instructions */
2985 /* stack slots at basic block end become interfaces */
2987 sd.bptr->outstack = curstack;
2988 sd.bptr->outdepth = stackdepth;
2989 sd.bptr->outvars = DMNEW(s4, stackdepth);
2992 for (copy = curstack; copy; i--, copy = copy->prev) {
2995 /* with the new vars rd->interfaces will be removed */
2996 /* and all in and outvars have to be STACKVARS! */
2997 /* in the moment i.e. SWAP with in and out vars can */
2998 /* create an unresolvable conflict */
3002 v = sd.var + copy->varnum;
3005 if (jd->interface_map[i*5 + copy->type].flags == UNUSED) {
3006 /* no interface var until now for this depth and */
3008 jd->interface_map[i*5 + copy->type].flags = v->flags;
3011 jd->interface_map[i*5 + copy->type].flags |= v->flags;
3014 sd.bptr->outvars[i] = copy->varnum;
3017 /* check if interface slots at basic block begin must be saved */
3019 for (i=0; i<sd.bptr->indepth; ++i) {
3020 varinfo *v = sd.var + sd.bptr->invars[i];
3022 if (jd->interface_map[i*5 + v->type].flags == UNUSED) {
3023 /* no interface var until now for this depth and */
3025 jd->interface_map[i*5 + v->type].flags = v->flags;
3028 jd->interface_map[i*5 + v->type].flags |= v->flags;
3033 #if defined(STACK_VERBOSE)
3034 printf("OUTVARS\n");
3035 for( copy = sd.bptr->outstack; copy; copy = copy->prev ) {
3036 printf("%2d(%d", copy->varnum, copy->type);
3037 if (IS_OUTVAR(copy))
3039 if (IS_PREALLOC(copy))
3047 superblockend = true;
3050 } /* while blocks */
3051 } while (repeat && !deadcode);
3053 /* gather statistics *****************************************************/
3055 #if defined(ENABLE_STATISTICS)
3057 if (jd->new_basicblockcount > count_max_basic_blocks)
3058 count_max_basic_blocks = jd->new_basicblockcount;
3059 count_basic_blocks += jd->new_basicblockcount;
3060 if (jd->new_instructioncount > count_max_javainstr)
3061 count_max_javainstr = jd->new_instructioncount;
3062 count_javainstr += jd->new_instructioncount;
3063 if (jd->new_stackcount > count_upper_bound_new_stack)
3064 count_upper_bound_new_stack = jd->new_stackcount;
3065 if ((sd.new - jd->new_stack) > count_max_new_stack)
3066 count_max_new_stack = (sd.new - jd->new_stack);
3068 b_count = jd->new_basicblockcount;
3069 sd.bptr = jd->new_basicblocks;
3070 while (--b_count >= 0) {
3071 if (sd.bptr->flags > BBREACHED) {
3072 if (sd.bptr->indepth >= 10)
3073 count_block_stack[10]++;
3075 count_block_stack[sd.bptr->indepth]++;
3076 len = sd.bptr->icount;
3078 count_block_size_distribution[len]++;
3080 count_block_size_distribution[10]++;
3082 count_block_size_distribution[11]++;
3084 count_block_size_distribution[12]++;
3086 count_block_size_distribution[13]++;
3088 count_block_size_distribution[14]++;
3090 count_block_size_distribution[15]++;
3092 count_block_size_distribution[16]++;
3094 count_block_size_distribution[17]++;
3099 if (iteration_count == 1)
3100 count_analyse_iterations[0]++;
3101 else if (iteration_count == 2)
3102 count_analyse_iterations[1]++;
3103 else if (iteration_count == 3)
3104 count_analyse_iterations[2]++;
3105 else if (iteration_count == 4)
3106 count_analyse_iterations[3]++;
3108 count_analyse_iterations[4]++;
3110 if (jd->new_basicblockcount <= 5)
3111 count_method_bb_distribution[0]++;
3112 else if (jd->new_basicblockcount <= 10)
3113 count_method_bb_distribution[1]++;
3114 else if (jd->new_basicblockcount <= 15)
3115 count_method_bb_distribution[2]++;
3116 else if (jd->new_basicblockcount <= 20)
3117 count_method_bb_distribution[3]++;
3118 else if (jd->new_basicblockcount <= 30)
3119 count_method_bb_distribution[4]++;
3120 else if (jd->new_basicblockcount <= 40)
3121 count_method_bb_distribution[5]++;
3122 else if (jd->new_basicblockcount <= 50)
3123 count_method_bb_distribution[6]++;
3124 else if (jd->new_basicblockcount <= 75)
3125 count_method_bb_distribution[7]++;
3127 count_method_bb_distribution[8]++;
3129 #endif /* defined(ENABLE_STATISTICS) */
3131 /* everything's ok *******************************************************/
3135 /* goto labels for throwing verifier exceptions **************************/
3137 #if defined(ENABLE_VERIFIER)
3139 throw_stack_underflow:
3140 exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
3143 throw_stack_overflow:
3144 exceptions_throw_verifyerror(m, "Stack size too large");
3147 throw_stack_depth_error:
3148 exceptions_throw_verifyerror(m,"Stack depth mismatch");
3151 throw_stack_type_error:
3152 exceptions_throw_verifyerror_for_stack(m, expectedtype);
3155 throw_stack_category_error:
3156 exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
3164 * These are local overrides for various environment variables in Emacs.
3165 * Please do not remove this and leave it at the end of the file, where
3166 * Emacs will automagically detect them.
3167 * ---------------------------------------------------------------------
3170 * indent-tabs-mode: t
3174 * vim:noexpandtab:sw=4:ts=4: