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 5423 2006-09-08 14:15:39Z 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 /* stack_init ******************************************************************
127 Initialized the stack analysis subsystem (called by jit_init).
129 *******************************************************************************/
131 bool stack_init(void)
137 /* stack_analyse ***************************************************************
139 Analyse_stack uses the intermediate code created by parse.c to
140 build a model of the JVM operand stack for the current method.
142 The following checks are performed:
143 - check for operand stack underflow (before each instruction)
144 - check for operand stack overflow (after[1] each instruction)
145 - check for matching stack depth at merging points
146 - check for matching basic types[2] at merging points
147 - check basic types for instruction input (except for BUILTIN*
148 opcodes, INVOKE* opcodes and MULTIANEWARRAY)
150 [1]) Checking this after the instruction should be ok. parse.c
151 counts the number of required stack slots in such a way that it is
152 only vital that we don't exceed `maxstack` at basic block
155 [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
156 DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
157 types are not discerned.
159 *******************************************************************************/
161 #define GET_NEW_INDEX(sd, new_varindex) \
163 assert((sd).vartop < (sd).varcount); \
164 (new_varindex) = ((sd).vartop)++; \
167 /* not implemented now, can be used to reuse varindices */
168 /* pay attention to not release a localvar once implementing it! */
169 #define RELEASE_INDEX(sd, varindex)
171 /* with the new vars setting an OUTVAR is not as trivial as changing */
172 /* the varkind before. If varindex was a localvar, a new TEMPVAR has */
173 /* to be created for the slot and the OUTVAR flag set */
174 #define SET_OUTVAR(sd, sp) \
176 if (IS_LOCALVAR_SD(sd, (sp))) { \
177 GET_NEW_INDEX((sd),new_index); \
178 sp->varnum = new_index; \
181 SET_OUTVAR_BY_INDEX((sd), (sp)->varnum); \
184 #define SET_OUTVAR_BY_INDEX(sd, index) \
186 assert(index >= (sd).localcount); \
187 (sd).var[(index)].flags |= OUTVAR; \
190 #define SET_TEMPVAR(sp) \
192 if ( IS_LOCALVAR( (sp) ) ) { \
193 GET_NEW_INDEX(sd, new_index); \
194 (sp)->varnum = new_index; \
195 sd.var[(sp)->varnum].flags = copy->flags; \
197 sd.var[(sp)->varnum].flags &= ~(OUTVAR | PREALLOC); \
200 #define SET_PREALLOC(sp) \
202 assert(!IS_LOCALVAR((sp))); \
203 sd.var[(sp)->varnum].flags |= PREALLOC; \
206 #define IS_OUTVAR(sp) \
207 (sd.var[(sp)->varnum].flags & OUTVAR)
209 #define IS_PREALLOC(sp) \
210 (sd.var[(sp)->varnum].flags & PREALLOC)
212 #define IS_TEMPVAR(sp) \
213 ( (sd.var[(sp)->varnum].flags & (OUTVAR | PREALLOC) \
214 && (((sp)->varnum < sd.localcount)) == 0) )
216 #define IS_LOCALVAR_SD(sd, sp) \
217 ((sp)->varnum < (sd).localcount)
219 #define IS_LOCALVAR(sp) \
220 IS_LOCALVAR_SD(sd, (sp))
223 (iptr->s1.varindex = -1)
225 #define USE_S1_LOCAL(type1)
227 #define USE_S1(type1) \
230 CHECK_BASIC_TYPE(type1, curstack->type); \
231 iptr->s1.varindex = curstack->varnum; \
237 iptr->s1.varindex = curstack->varnum; \
240 #define USE_S1_S2(type1, type2) \
243 CHECK_BASIC_TYPE(type1, curstack->prev->type); \
244 CHECK_BASIC_TYPE(type2, curstack->type); \
245 iptr->sx.s23.s2.varindex = curstack->varnum; \
246 iptr->s1.varindex = curstack->prev->varnum; \
249 #define USE_S1_S2_ANY_ANY \
252 iptr->sx.s23.s2.varindex = curstack->varnum; \
253 iptr->s1.varindex = curstack->prev->varnum; \
256 #define USE_S1_S2_S3(type1, type2, type3) \
259 CHECK_BASIC_TYPE(type1, curstack->prev->prev->type); \
260 CHECK_BASIC_TYPE(type2, curstack->prev->type); \
261 CHECK_BASIC_TYPE(type3, curstack->type); \
262 iptr->sx.s23.s3.varindex = curstack->varnum; \
263 iptr->sx.s23.s2.varindex = curstack->prev->varnum; \
264 iptr->s1.varindex = curstack->prev->prev->varnum; \
268 (iptr->dst.varindex = -1)
270 #define DST(typed, index) \
272 NEWSTACKn((typed),(index)); \
273 iptr->dst.varindex = (index); \
276 /* XXX temporatily turn off coalescing */
278 #define DST_LOCALVAR(typed, index) \
280 NEWSTACK((typed), LOCALVAR, (index)); \
281 iptr->dst.varindex = (index); \
284 #define DST_LOCALVAR(typed, index) \
286 GET_NEW_INDEX(sd, new_index); \
287 NEWSTACKn((typed), (new_index)); \
288 iptr->dst.varindex = (new_index); \
292 #define OP0_1(typed) \
295 GET_NEW_INDEX(sd, new_index); \
296 DST(typed, new_index); \
307 #define OP1_BRANCH(type1) \
313 #define OP1_1(type1, typed) \
316 GET_NEW_INDEX(sd, new_index); \
317 DST(typed, new_index); \
320 #define OP2_1(type1, type2, typed) \
322 POP_S1_S2(type1, type2); \
323 GET_NEW_INDEX(sd, new_index); \
324 DST(typed, new_index); \
328 #define DUP_SLOT(sp) \
330 if ((sp)->varkind != TEMPVAR) { \
331 GET_NEW_INDEX(sd, new_index); \
332 NEWSTACK((sp)->type, TEMPVAR, new_index); \
335 NEWSTACK((sp)->type, (sp)->varkind, (sp)->varnum); \
338 #define POP_S1(type1) \
341 if (curstack->varkind == UNDEFVAR) \
342 curstack->varkind = TEMPVAR; \
343 curstack = curstack->prev; \
349 if (curstack->varkind == UNDEFVAR) \
350 curstack->varkind = TEMPVAR; \
351 curstack = curstack->prev; \
354 #define POP_S1_S2(type1, type2) \
356 USE_S1_S2(type1, type2); \
357 if (curstack->varkind == UNDEFVAR) \
358 curstack->varkind = TEMPVAR; \
359 if (curstack->prev->varkind == UNDEFVAR) \
360 curstack->prev->varkind = TEMPVAR; \
361 curstack = curstack->prev->prev; \
364 #define POP_S1_S2_ANY_ANY \
367 if (curstack->varkind == UNDEFVAR) \
368 curstack->varkind = TEMPVAR; \
369 if (curstack->prev->varkind == UNDEFVAR) \
370 curstack->prev->varkind = TEMPVAR; \
371 curstack = curstack->prev->prev; \
374 #define POP_S1_S2_S3(type1, type2, type3) \
376 USE_S1_S2_S3(type1, type2, type3); \
377 if (curstack->varkind == UNDEFVAR) \
378 curstack->varkind = TEMPVAR; \
379 if (curstack->prev->varkind == UNDEFVAR) \
380 curstack->prev->varkind = TEMPVAR; \
381 if (curstack->prev->prev->varkind == UNDEFVAR) \
382 curstack->prev->prev->varkind = TEMPVAR; \
383 curstack = curstack->prev->prev->prev; \
400 #define OP1_0(type1) \
407 #define OP2_0(type1, type2) \
409 POP_S1_S2(type1, type2); \
414 #define OP2_BRANCH(type1, type2) \
416 POP_S1_S2(type1, type2); \
420 #define OP2_0_ANY_ANY \
427 #define OP3_0(type1, type2, type3) \
429 POP_S1_S2_S3(type1, type2, type3); \
434 #define LOAD(type1, index) \
436 DST_LOCALVAR(type1, index); \
440 #define STORE(type1, index) \
446 #if defined(ENABLE_VERIFIER)
447 #define MARKREACHED(b, c) \
449 if (!stack_mark_reached(&sd, (b), curstack, stackdepth)) \
453 #define MARKREACHED(b, c) \
455 (void) stack_mark_reached(&sd, (b), curstack, stackdepth); \
459 #define BRANCH_TARGET(bt, tempbptr, tempsp) \
461 (bt).block = tempbptr = BLOCK_OF((bt).insindex); \
462 MARKREACHED(tempbptr, tempsp); \
465 #define BRANCH(tempbptr, tempsp) \
467 iptr->dst.block = tempbptr = BLOCK_OF(iptr->dst.insindex); \
468 MARKREACHED(tempbptr, tempsp); \
471 /* MARKREACHED marks the destination block <b> as reached. If this
472 * block has been reached before we check if stack depth and types
473 * match. Otherwise the destination block receives a copy of the
474 * current stack as its input stack.
476 * b...destination block
480 static bool stack_mark_reached(stackdata_t *sd, basicblock *b, stackptr curstack, int stackdepth)
485 #if defined(ENABLE_VERIFIER)
486 int expectedtype; /* used by CHECK_BASIC_TYPE */
490 b->bitflags |= BBFLAG_REPLACEMENT;
492 if (b->flags < BBREACHED) {
493 /* b is reached for the first time. Create its instack */
494 COPYCURSTACK(*sd, sp);
495 b->flags = BBREACHED;
497 b->indepth = stackdepth;
498 b->invars = DMNEW(s4, stackdepth);
499 for (i = stackdepth; i--; sp = sp->prev) {
500 b->invars[i] = sp->varnum;
505 /* b has been reached before. Check that its instack matches */
508 CHECK_STACK_DEPTH(b->indepth, stackdepth);
510 CHECK_BASIC_TYPE(sp->type,tsp->type);
518 #if defined(ENABLE_VERIFIER)
519 throw_stack_depth_error:
520 exceptions_throw_verifyerror(m,"Stack depth mismatch");
523 throw_stack_type_error:
524 exceptions_throw_verifyerror_for_stack(m, expectedtype);
529 bool new_stack_analyse(jitdata *jd)
531 methodinfo *m; /* method being analyzed */
536 int b_count; /* basic block counter */
537 int b_index; /* basic block index */
539 stackptr curstack; /* current stack top */
541 int opcode; /* opcode of current instruction */
544 int len; /* # of instructions after the current one */
545 bool superblockend; /* if true, no fallthrough to next block */
546 bool repeat; /* if true, outermost loop must run again */
547 bool deadcode; /* true if no live code has been reached */
548 instruction *iptr; /* the current instruction */
551 stackptr *last_store_boundary;
552 stackptr last_pei_boundary;
553 stackptr last_dup_boundary;
555 branch_target_t *table;
556 lookup_target_t *lookup;
557 #if defined(ENABLE_VERIFIER)
558 int expectedtype; /* used by CHECK_BASIC_TYPE */
560 builtintable_entry *bte;
562 constant_FMIref *fmiref;
563 #if defined(ENABLE_STATISTICS)
564 int iteration_count; /* number of iterations of analysis */
566 int new_index; /* used to get a new var index with GET_NEW_INDEX*/
568 #if defined(STACK_VERBOSE)
569 new_show_method(jd, SHOW_PARSE);
572 /* get required compiler data - initialization */
579 /* initialize the stackdata_t struct */
581 sd.varcount = jd->varcount;
582 sd.vartop = jd->vartop;
583 sd.localcount = jd->localcount;
585 sd.new = jd->new_stack;
587 #if defined(ENABLE_LSRA)
591 #if defined(ENABLE_STATISTICS)
595 /* init jd->interface_map */
597 jd->interface_map = DMNEW(s4, m->maxstack * 5);
598 for (i = 0; i < m->maxstack * 5; i++)
599 jd->interface_map[i] = UNUSED;
601 last_store_boundary = DMNEW(stackptr, cd->maxlocals);
603 /* initialize in-stack of first block */
605 jd->new_basicblocks[0].flags = BBREACHED;
606 jd->new_basicblocks[0].instack = NULL;
607 jd->new_basicblocks[0].invars = NULL;
608 jd->new_basicblocks[0].indepth = 0;
610 /* initialize in-stack of exception handlers */
612 for (i = 0; i < cd->exceptiontablelength; i++) {
613 sd.bptr = BLOCK_OF(cd->exceptiontable[i].handlerpc);
614 sd.bptr->flags = BBREACHED;
615 sd.bptr->type = BBTYPE_EXH;
616 sd.bptr->instack = sd.new;
617 sd.bptr->indepth = 1;
618 sd.bptr->predecessorcount = CFG_UNKNOWN_PREDECESSORS;
620 GET_NEW_INDEX(sd, new_index);
621 sd.bptr->invars = DMNEW(s4, 1);
622 sd.bptr->invars[0] = new_index;
623 NEWSTACK(TYPE_ADR, STACKVAR, new_index);
625 jd->interface_map[0 * 5 + TYPE_ADR] = 0;
626 SET_OUTVAR_BY_INDEX(sd, new_index);
629 /* stack analysis loop (until fixpoint reached) **************************/
632 #if defined(ENABLE_STATISTICS)
636 /* initialize loop over basic blocks */
638 b_count = jd->new_basicblockcount;
639 sd.bptr = jd->new_basicblocks;
640 superblockend = true;
645 /* iterate over basic blocks *****************************************/
647 while (--b_count >= 0) {
648 #if defined(STACK_VERBOSE)
649 printf("----\nANALYZING BLOCK L%03d ", sd.bptr->nr);
650 if (sd.bptr->type == BBTYPE_EXH) printf("EXH\n");
651 else if (sd.bptr->type == BBTYPE_SBR) printf("SBR\n");
652 else printf("STD\n");
656 if (sd.bptr->flags == BBDELETED) {
657 /* This block has been deleted - do nothing. */
659 else if (superblockend && (sd.bptr->flags < BBREACHED)) {
660 /* This block has not been reached so far, and we */
661 /* don't fall into it, so we'll have to iterate again. */
664 else if (sd.bptr->flags <= BBREACHED) {
666 /* We know that sd.bptr->flags == BBREACHED. */
667 /* This block has been reached before. */
668 stackdepth = sd.bptr->indepth;
670 else if (sd.bptr->flags < BBREACHED) {
671 /* This block is reached for the first time now */
672 /* by falling through from the previous block. */
673 /* Create the instack (propagated). */
674 COPYCURSTACK(sd, copy);
675 sd.bptr->instack = copy;
677 sd.bptr->invars = DMNEW(s4, stackdepth);
678 for (i=stackdepth; i--; copy = copy->prev)
679 sd.bptr->invars[i] = copy->varnum;
680 sd.bptr->indepth = stackdepth;
683 /* This block has been reached before. now we are */
684 /* falling into it from the previous block. */
685 /* Check that stack depth is well-defined. */
686 CHECK_STACK_DEPTH(sd.bptr->indepth, stackdepth);
688 /* XXX check stack types? */
691 /* set up local variables for analyzing this block */
693 curstack = sd.bptr->instack;
695 superblockend = false;
696 len = sd.bptr->icount;
697 iptr = sd.bptr->iinstr;
698 b_index = sd.bptr - jd->new_basicblocks;
700 /* mark the block as analysed */
702 sd.bptr->flags = BBFINISHED;
704 /* reset variables for dependency checking */
706 last_pei_boundary = sd.new;
707 last_dup_boundary = sd.new;
708 for( i = 0; i < cd->maxlocals; i++)
709 last_store_boundary[i] = sd.new;
711 /* XXX store the start of the block's stack representation */
713 sd.bptr->stack = sd.new;
715 #if defined(STACK_VERBOSE)
717 for( copy = sd.bptr->instack; copy; copy = copy->prev ) {
718 printf("%2d(%d", copy->varnum, copy->type);
721 if (IS_PREALLOC(copy))
729 /* iterate over ICMDs ****************************************/
733 #if defined(STACK_VERBOSE)
734 new_show_icmd(jd, iptr, false, SHOW_PARSE); printf("\n");
735 for( copy = curstack; copy; copy = copy->prev ) {
736 printf("%2d(%d", copy->varnum, copy->type);
739 if (IS_PREALLOC(copy))
746 /* fetch the current opcode */
750 /* automatically replace some ICMDs with builtins */
752 #if defined(USEBUILTINTABLE)
754 bte = builtintable_get_automatic(opcode);
756 if (bte && bte->opcode == opcode) {
757 iptr->opc = ICMD_BUILTIN;
758 iptr->flags.bits = 0;
759 iptr->sx.s23.s3.bte = bte;
760 /* iptr->line is already set */
761 jd->isleafmethod = false;
765 #endif /* defined(USEBUILTINTABLE) */
767 /* main opcode switch *************************************/
780 last_pei_boundary = sd.new;
781 COUNT(count_check_null);
784 CLR_DST; /* XXX live through? */
788 USE_S1_LOCAL(TYPE_ADR);
791 #if !defined(NEW_VAR)
792 IF_NO_INTRP( rd->locals[iptr->s1.localindex][TYPE_ADR].type = TYPE_ADR; );
794 superblockend = true;
798 COUNT(count_pcmd_return);
801 superblockend = true;
805 /* pop 0 push 1 const */
807 /************************** ICONST OPTIMIZATIONS **************************/
810 COUNT(count_pcmd_load);
814 switch (iptr[1].opc) {
816 iptr->opc = ICMD_IADDCONST;
820 iptr[1].opc = ICMD_NOP;
821 OP1_1(TYPE_INT, TYPE_INT);
822 COUNT(count_pcmd_op);
826 iptr->opc = ICMD_ISUBCONST;
827 goto icmd_iconst_tail;
828 #if SUPPORT_CONST_MUL
830 iptr->opc = ICMD_IMULCONST;
831 goto icmd_iconst_tail;
832 #else /* SUPPORT_CONST_MUL */
834 if (iptr->sx.val.i == 0x00000002)
836 else if (iptr->sx.val.i == 0x00000004)
838 else if (iptr->sx.val.i == 0x00000008)
840 else if (iptr->sx.val.i == 0x00000010)
842 else if (iptr->sx.val.i == 0x00000020)
844 else if (iptr->sx.val.i == 0x00000040)
846 else if (iptr->sx.val.i == 0x00000080)
848 else if (iptr->sx.val.i == 0x00000100)
850 else if (iptr->sx.val.i == 0x00000200)
852 else if (iptr->sx.val.i == 0x00000400)
854 else if (iptr->sx.val.i == 0x00000800)
856 else if (iptr->sx.val.i == 0x00001000)
858 else if (iptr->sx.val.i == 0x00002000)
860 else if (iptr->sx.val.i == 0x00004000)
862 else if (iptr->sx.val.i == 0x00008000)
864 else if (iptr->sx.val.i == 0x00010000)
866 else if (iptr->sx.val.i == 0x00020000)
868 else if (iptr->sx.val.i == 0x00040000)
870 else if (iptr->sx.val.i == 0x00080000)
872 else if (iptr->sx.val.i == 0x00100000)
874 else if (iptr->sx.val.i == 0x00200000)
876 else if (iptr->sx.val.i == 0x00400000)
878 else if (iptr->sx.val.i == 0x00800000)
880 else if (iptr->sx.val.i == 0x01000000)
882 else if (iptr->sx.val.i == 0x02000000)
884 else if (iptr->sx.val.i == 0x04000000)
886 else if (iptr->sx.val.i == 0x08000000)
888 else if (iptr->sx.val.i == 0x10000000)
890 else if (iptr->sx.val.i == 0x20000000)
892 else if (iptr->sx.val.i == 0x40000000)
894 else if (iptr->sx.val.i == 0x80000000)
899 iptr->opc = ICMD_IMULPOW2;
900 goto icmd_iconst_tail;
901 #endif /* SUPPORT_CONST_MUL */
903 if (iptr->sx.val.i == 0x00000002)
905 else if (iptr->sx.val.i == 0x00000004)
907 else if (iptr->sx.val.i == 0x00000008)
909 else if (iptr->sx.val.i == 0x00000010)
911 else if (iptr->sx.val.i == 0x00000020)
913 else if (iptr->sx.val.i == 0x00000040)
915 else if (iptr->sx.val.i == 0x00000080)
917 else if (iptr->sx.val.i == 0x00000100)
919 else if (iptr->sx.val.i == 0x00000200)
921 else if (iptr->sx.val.i == 0x00000400)
923 else if (iptr->sx.val.i == 0x00000800)
925 else if (iptr->sx.val.i == 0x00001000)
927 else if (iptr->sx.val.i == 0x00002000)
929 else if (iptr->sx.val.i == 0x00004000)
931 else if (iptr->sx.val.i == 0x00008000)
933 else if (iptr->sx.val.i == 0x00010000)
935 else if (iptr->sx.val.i == 0x00020000)
937 else if (iptr->sx.val.i == 0x00040000)
939 else if (iptr->sx.val.i == 0x00080000)
941 else if (iptr->sx.val.i == 0x00100000)
943 else if (iptr->sx.val.i == 0x00200000)
945 else if (iptr->sx.val.i == 0x00400000)
947 else if (iptr->sx.val.i == 0x00800000)
949 else if (iptr->sx.val.i == 0x01000000)
951 else if (iptr->sx.val.i == 0x02000000)
953 else if (iptr->sx.val.i == 0x04000000)
955 else if (iptr->sx.val.i == 0x08000000)
957 else if (iptr->sx.val.i == 0x10000000)
959 else if (iptr->sx.val.i == 0x20000000)
961 else if (iptr->sx.val.i == 0x40000000)
963 else if (iptr->sx.val.i == 0x80000000)
968 iptr->opc = ICMD_IDIVPOW2;
969 goto icmd_iconst_tail;
972 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
973 if ((iptr->sx.val.i == 0x00000002) ||
974 (iptr->sx.val.i == 0x00000004) ||
975 (iptr->sx.val.i == 0x00000008) ||
976 (iptr->sx.val.i == 0x00000010) ||
977 (iptr->sx.val.i == 0x00000020) ||
978 (iptr->sx.val.i == 0x00000040) ||
979 (iptr->sx.val.i == 0x00000080) ||
980 (iptr->sx.val.i == 0x00000100) ||
981 (iptr->sx.val.i == 0x00000200) ||
982 (iptr->sx.val.i == 0x00000400) ||
983 (iptr->sx.val.i == 0x00000800) ||
984 (iptr->sx.val.i == 0x00001000) ||
985 (iptr->sx.val.i == 0x00002000) ||
986 (iptr->sx.val.i == 0x00004000) ||
987 (iptr->sx.val.i == 0x00008000) ||
988 (iptr->sx.val.i == 0x00010000) ||
989 (iptr->sx.val.i == 0x00020000) ||
990 (iptr->sx.val.i == 0x00040000) ||
991 (iptr->sx.val.i == 0x00080000) ||
992 (iptr->sx.val.i == 0x00100000) ||
993 (iptr->sx.val.i == 0x00200000) ||
994 (iptr->sx.val.i == 0x00400000) ||
995 (iptr->sx.val.i == 0x00800000) ||
996 (iptr->sx.val.i == 0x01000000) ||
997 (iptr->sx.val.i == 0x02000000) ||
998 (iptr->sx.val.i == 0x04000000) ||
999 (iptr->sx.val.i == 0x08000000) ||
1000 (iptr->sx.val.i == 0x10000000) ||
1001 (iptr->sx.val.i == 0x20000000) ||
1002 (iptr->sx.val.i == 0x40000000) ||
1003 (iptr->sx.val.i == 0x80000000))
1005 iptr->opc = ICMD_IREMPOW2;
1006 iptr->sx.val.i -= 1;
1007 goto icmd_iconst_tail;
1010 #if SUPPORT_CONST_LOGICAL
1012 iptr->opc = ICMD_IANDCONST;
1013 goto icmd_iconst_tail;
1016 iptr->opc = ICMD_IORCONST;
1017 goto icmd_iconst_tail;
1020 iptr->opc = ICMD_IXORCONST;
1021 goto icmd_iconst_tail;
1023 #endif /* SUPPORT_CONST_LOGICAL */
1025 iptr->opc = ICMD_ISHLCONST;
1026 goto icmd_iconst_tail;
1029 iptr->opc = ICMD_ISHRCONST;
1030 goto icmd_iconst_tail;
1033 iptr->opc = ICMD_IUSHRCONST;
1034 goto icmd_iconst_tail;
1035 #if SUPPORT_LONG_SHIFT
1037 iptr->opc = ICMD_LSHLCONST;
1038 goto icmd_lconst_tail;
1041 iptr->opc = ICMD_LSHRCONST;
1042 goto icmd_lconst_tail;
1045 iptr->opc = ICMD_LUSHRCONST;
1046 goto icmd_lconst_tail;
1047 #endif /* SUPPORT_LONG_SHIFT */
1048 case ICMD_IF_ICMPEQ:
1049 iptr[1].opc = ICMD_IFEQ;
1053 /* set the constant for the following icmd */
1054 iptr[1].sx.val.i = iptr->sx.val.i;
1056 /* this instruction becomes a nop */
1057 iptr->opc = ICMD_NOP;
1060 case ICMD_IF_ICMPLT:
1061 iptr[1].opc = ICMD_IFLT;
1062 goto icmd_if_icmp_tail;
1064 case ICMD_IF_ICMPLE:
1065 iptr[1].opc = ICMD_IFLE;
1066 goto icmd_if_icmp_tail;
1068 case ICMD_IF_ICMPNE:
1069 iptr[1].opc = ICMD_IFNE;
1070 goto icmd_if_icmp_tail;
1072 case ICMD_IF_ICMPGT:
1073 iptr[1].opc = ICMD_IFGT;
1074 goto icmd_if_icmp_tail;
1076 case ICMD_IF_ICMPGE:
1077 iptr[1].opc = ICMD_IFGE;
1078 goto icmd_if_icmp_tail;
1080 #if SUPPORT_CONST_STORE
1085 IF_INTRP( goto normal_ICONST; )
1086 # if SUPPORT_CONST_STORE_ZERO_ONLY
1087 if (iptr->sx.val.i != 0)
1090 switch (iptr[1].opc) {
1092 iptr->opc = ICMD_IASTORECONST;
1093 iptr->flags.bits |= INS_FLAG_CHECK;
1096 iptr->opc = ICMD_BASTORECONST;
1097 iptr->flags.bits |= INS_FLAG_CHECK;
1100 iptr->opc = ICMD_CASTORECONST;
1101 iptr->flags.bits |= INS_FLAG_CHECK;
1104 iptr->opc = ICMD_SASTORECONST;
1105 iptr->flags.bits |= INS_FLAG_CHECK;
1109 iptr[1].opc = ICMD_NOP;
1111 /* copy the constant to s3 */
1112 /* XXX constval -> astoreconstval? */
1113 iptr->sx.s23.s3.constval = iptr->sx.val.i;
1114 OP2_0(TYPE_ADR, TYPE_INT);
1115 COUNT(count_pcmd_op);
1118 case ICMD_PUTSTATIC:
1120 IF_INTRP( goto normal_ICONST; )
1121 # if SUPPORT_CONST_STORE_ZERO_ONLY
1122 if (iptr->sx.val.i != 0)
1125 /* XXX check field type? */
1127 /* copy the constant to s2 */
1128 /* XXX constval -> fieldconstval? */
1129 iptr->sx.s23.s2.constval = iptr->sx.val.i;
1132 /* set the field reference (s3) */
1133 if (iptr[1].flags.bits & INS_FLAG_UNRESOLVED) {
1134 iptr->sx.s23.s3.uf = iptr[1].sx.s23.s3.uf;
1135 iptr->flags.bits |= INS_FLAG_UNRESOLVED;
1138 iptr->sx.s23.s3.fmiref = iptr[1].sx.s23.s3.fmiref;
1141 switch (iptr[1].opc) {
1142 case ICMD_PUTSTATIC:
1143 iptr->opc = ICMD_PUTSTATICCONST;
1147 iptr->opc = ICMD_PUTFIELDCONST;
1152 iptr[1].opc = ICMD_NOP;
1153 COUNT(count_pcmd_op);
1155 #endif /* SUPPORT_CONST_STORE */
1161 /* if we get here, the ICONST has been optimized */
1165 /* normal case of an unoptimized ICONST */
1169 /************************** LCONST OPTIMIZATIONS **************************/
1172 COUNT(count_pcmd_load);
1176 /* switch depending on the following instruction */
1178 switch (iptr[1].opc) {
1179 #if SUPPORT_LONG_ADD
1181 iptr->opc = ICMD_LADDCONST;
1185 /* instruction of type LONG -> LONG */
1186 iptr[1].opc = ICMD_NOP;
1187 OP1_1(TYPE_LNG, TYPE_LNG);
1188 COUNT(count_pcmd_op);
1192 iptr->opc = ICMD_LSUBCONST;
1193 goto icmd_lconst_tail;
1195 #endif /* SUPPORT_LONG_ADD */
1196 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
1198 iptr->opc = ICMD_LMULCONST;
1199 goto icmd_lconst_tail;
1200 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1201 # if SUPPORT_LONG_SHIFT
1203 if (iptr->sx.val.l == 0x00000002)
1205 else if (iptr->sx.val.l == 0x00000004)
1207 else if (iptr->sx.val.l == 0x00000008)
1209 else if (iptr->sx.val.l == 0x00000010)
1211 else if (iptr->sx.val.l == 0x00000020)
1213 else if (iptr->sx.val.l == 0x00000040)
1215 else if (iptr->sx.val.l == 0x00000080)
1217 else if (iptr->sx.val.l == 0x00000100)
1219 else if (iptr->sx.val.l == 0x00000200)
1221 else if (iptr->sx.val.l == 0x00000400)
1222 iptr->sx.val.i = 10;
1223 else if (iptr->sx.val.l == 0x00000800)
1224 iptr->sx.val.i = 11;
1225 else if (iptr->sx.val.l == 0x00001000)
1226 iptr->sx.val.i = 12;
1227 else if (iptr->sx.val.l == 0x00002000)
1228 iptr->sx.val.i = 13;
1229 else if (iptr->sx.val.l == 0x00004000)
1230 iptr->sx.val.i = 14;
1231 else if (iptr->sx.val.l == 0x00008000)
1232 iptr->sx.val.i = 15;
1233 else if (iptr->sx.val.l == 0x00010000)
1234 iptr->sx.val.i = 16;
1235 else if (iptr->sx.val.l == 0x00020000)
1236 iptr->sx.val.i = 17;
1237 else if (iptr->sx.val.l == 0x00040000)
1238 iptr->sx.val.i = 18;
1239 else if (iptr->sx.val.l == 0x00080000)
1240 iptr->sx.val.i = 19;
1241 else if (iptr->sx.val.l == 0x00100000)
1242 iptr->sx.val.i = 20;
1243 else if (iptr->sx.val.l == 0x00200000)
1244 iptr->sx.val.i = 21;
1245 else if (iptr->sx.val.l == 0x00400000)
1246 iptr->sx.val.i = 22;
1247 else if (iptr->sx.val.l == 0x00800000)
1248 iptr->sx.val.i = 23;
1249 else if (iptr->sx.val.l == 0x01000000)
1250 iptr->sx.val.i = 24;
1251 else if (iptr->sx.val.l == 0x02000000)
1252 iptr->sx.val.i = 25;
1253 else if (iptr->sx.val.l == 0x04000000)
1254 iptr->sx.val.i = 26;
1255 else if (iptr->sx.val.l == 0x08000000)
1256 iptr->sx.val.i = 27;
1257 else if (iptr->sx.val.l == 0x10000000)
1258 iptr->sx.val.i = 28;
1259 else if (iptr->sx.val.l == 0x20000000)
1260 iptr->sx.val.i = 29;
1261 else if (iptr->sx.val.l == 0x40000000)
1262 iptr->sx.val.i = 30;
1263 else if (iptr->sx.val.l == 0x80000000)
1264 iptr->sx.val.i = 31;
1268 iptr->opc = ICMD_LMULPOW2;
1269 goto icmd_lconst_tail;
1270 # endif /* SUPPORT_LONG_SHIFT */
1271 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1272 #if SUPPORT_LONG_DIV_POW2
1274 if (iptr->sx.val.l == 0x00000002)
1276 else if (iptr->sx.val.l == 0x00000004)
1278 else if (iptr->sx.val.l == 0x00000008)
1280 else if (iptr->sx.val.l == 0x00000010)
1282 else if (iptr->sx.val.l == 0x00000020)
1284 else if (iptr->sx.val.l == 0x00000040)
1286 else if (iptr->sx.val.l == 0x00000080)
1288 else if (iptr->sx.val.l == 0x00000100)
1290 else if (iptr->sx.val.l == 0x00000200)
1292 else if (iptr->sx.val.l == 0x00000400)
1293 iptr->sx.val.i = 10;
1294 else if (iptr->sx.val.l == 0x00000800)
1295 iptr->sx.val.i = 11;
1296 else if (iptr->sx.val.l == 0x00001000)
1297 iptr->sx.val.i = 12;
1298 else if (iptr->sx.val.l == 0x00002000)
1299 iptr->sx.val.i = 13;
1300 else if (iptr->sx.val.l == 0x00004000)
1301 iptr->sx.val.i = 14;
1302 else if (iptr->sx.val.l == 0x00008000)
1303 iptr->sx.val.i = 15;
1304 else if (iptr->sx.val.l == 0x00010000)
1305 iptr->sx.val.i = 16;
1306 else if (iptr->sx.val.l == 0x00020000)
1307 iptr->sx.val.i = 17;
1308 else if (iptr->sx.val.l == 0x00040000)
1309 iptr->sx.val.i = 18;
1310 else if (iptr->sx.val.l == 0x00080000)
1311 iptr->sx.val.i = 19;
1312 else if (iptr->sx.val.l == 0x00100000)
1313 iptr->sx.val.i = 20;
1314 else if (iptr->sx.val.l == 0x00200000)
1315 iptr->sx.val.i = 21;
1316 else if (iptr->sx.val.l == 0x00400000)
1317 iptr->sx.val.i = 22;
1318 else if (iptr->sx.val.l == 0x00800000)
1319 iptr->sx.val.i = 23;
1320 else if (iptr->sx.val.l == 0x01000000)
1321 iptr->sx.val.i = 24;
1322 else if (iptr->sx.val.l == 0x02000000)
1323 iptr->sx.val.i = 25;
1324 else if (iptr->sx.val.l == 0x04000000)
1325 iptr->sx.val.i = 26;
1326 else if (iptr->sx.val.l == 0x08000000)
1327 iptr->sx.val.i = 27;
1328 else if (iptr->sx.val.l == 0x10000000)
1329 iptr->sx.val.i = 28;
1330 else if (iptr->sx.val.l == 0x20000000)
1331 iptr->sx.val.i = 29;
1332 else if (iptr->sx.val.l == 0x40000000)
1333 iptr->sx.val.i = 30;
1334 else if (iptr->sx.val.l == 0x80000000)
1335 iptr->sx.val.i = 31;
1339 iptr->opc = ICMD_LDIVPOW2;
1340 goto icmd_lconst_tail;
1341 #endif /* SUPPORT_LONG_DIV_POW2 */
1343 #if SUPPORT_LONG_REM_POW2
1345 if ((iptr->sx.val.l == 0x00000002) ||
1346 (iptr->sx.val.l == 0x00000004) ||
1347 (iptr->sx.val.l == 0x00000008) ||
1348 (iptr->sx.val.l == 0x00000010) ||
1349 (iptr->sx.val.l == 0x00000020) ||
1350 (iptr->sx.val.l == 0x00000040) ||
1351 (iptr->sx.val.l == 0x00000080) ||
1352 (iptr->sx.val.l == 0x00000100) ||
1353 (iptr->sx.val.l == 0x00000200) ||
1354 (iptr->sx.val.l == 0x00000400) ||
1355 (iptr->sx.val.l == 0x00000800) ||
1356 (iptr->sx.val.l == 0x00001000) ||
1357 (iptr->sx.val.l == 0x00002000) ||
1358 (iptr->sx.val.l == 0x00004000) ||
1359 (iptr->sx.val.l == 0x00008000) ||
1360 (iptr->sx.val.l == 0x00010000) ||
1361 (iptr->sx.val.l == 0x00020000) ||
1362 (iptr->sx.val.l == 0x00040000) ||
1363 (iptr->sx.val.l == 0x00080000) ||
1364 (iptr->sx.val.l == 0x00100000) ||
1365 (iptr->sx.val.l == 0x00200000) ||
1366 (iptr->sx.val.l == 0x00400000) ||
1367 (iptr->sx.val.l == 0x00800000) ||
1368 (iptr->sx.val.l == 0x01000000) ||
1369 (iptr->sx.val.l == 0x02000000) ||
1370 (iptr->sx.val.l == 0x04000000) ||
1371 (iptr->sx.val.l == 0x08000000) ||
1372 (iptr->sx.val.l == 0x10000000) ||
1373 (iptr->sx.val.l == 0x20000000) ||
1374 (iptr->sx.val.l == 0x40000000) ||
1375 (iptr->sx.val.l == 0x80000000))
1377 iptr->opc = ICMD_LREMPOW2;
1378 iptr->sx.val.l -= 1;
1379 goto icmd_lconst_tail;
1382 #endif /* SUPPORT_LONG_REM_POW2 */
1384 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
1387 iptr->opc = ICMD_LANDCONST;
1388 goto icmd_lconst_tail;
1391 iptr->opc = ICMD_LORCONST;
1392 goto icmd_lconst_tail;
1395 iptr->opc = ICMD_LXORCONST;
1396 goto icmd_lconst_tail;
1397 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
1399 #if SUPPORT_LONG_CMP_CONST
1401 if ((len <= 1) || (iptr[2].sx.val.i != 0))
1404 /* switch on the instruction after LCONST - LCMP */
1406 switch (iptr[2].opc) {
1408 iptr->opc = ICMD_IF_LEQ;
1411 icmd_lconst_lcmp_tail:
1412 /* convert LCONST, LCMP, IFXX to IF_LXX */
1413 iptr->dst.insindex = iptr[2].dst.insindex;
1414 iptr[1].opc = ICMD_NOP;
1415 iptr[2].opc = ICMD_NOP;
1417 OP1_BRANCH(TYPE_LNG);
1418 BRANCH(tbptr, copy);
1419 COUNT(count_pcmd_bra);
1420 COUNT(count_pcmd_op);
1424 iptr->opc = ICMD_IF_LNE;
1425 goto icmd_lconst_lcmp_tail;
1428 iptr->opc = ICMD_IF_LLT;
1429 goto icmd_lconst_lcmp_tail;
1432 iptr->opc = ICMD_IF_LGT;
1433 goto icmd_lconst_lcmp_tail;
1436 iptr->opc = ICMD_IF_LLE;
1437 goto icmd_lconst_lcmp_tail;
1440 iptr->opc = ICMD_IF_LGE;
1441 goto icmd_lconst_lcmp_tail;
1445 } /* end switch on opcode after LCONST - LCMP */
1447 #endif /* SUPPORT_LONG_CMP_CONST */
1449 #if SUPPORT_CONST_STORE
1451 IF_INTRP( goto normal_LCONST; )
1452 # if SUPPORT_CONST_STORE_ZERO_ONLY
1453 if (iptr->sx.val.l != 0)
1456 #if SIZEOF_VOID_P == 4
1457 /* the constant must fit into a ptrint */
1458 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1461 /* move the constant to s3 */
1462 iptr->sx.s23.s3.constval = iptr->sx.val.l;
1464 iptr->opc = ICMD_LASTORECONST;
1465 iptr->flags.bits |= INS_FLAG_CHECK;
1466 OP2_0(TYPE_ADR, TYPE_INT);
1468 iptr[1].opc = ICMD_NOP;
1469 COUNT(count_pcmd_op);
1472 case ICMD_PUTSTATIC:
1474 IF_INTRP( goto normal_LCONST; )
1475 # if SUPPORT_CONST_STORE_ZERO_ONLY
1476 if (iptr->sx.val.l != 0)
1479 #if SIZEOF_VOID_P == 4
1480 /* the constant must fit into a ptrint */
1481 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1484 /* XXX check field type? */
1486 /* copy the constant to s2 */
1487 /* XXX constval -> fieldconstval? */
1488 iptr->sx.s23.s2.constval = iptr->sx.val.l;
1492 #endif /* SUPPORT_CONST_STORE */
1496 } /* end switch opcode after LCONST */
1498 /* if we get here, the LCONST has been optimized */
1502 /* the normal case of an unoptimized LCONST */
1506 /************************ END OF LCONST OPTIMIZATIONS *********************/
1509 COUNT(count_pcmd_load);
1514 COUNT(count_pcmd_load);
1518 /************************** ACONST OPTIMIZATIONS **************************/
1521 last_pei_boundary = sd.new;
1522 COUNT(count_pcmd_load);
1523 #if SUPPORT_CONST_STORE
1524 IF_INTRP( goto normal_ACONST; )
1526 /* We can only optimize if the ACONST is resolved
1527 * and there is an instruction after it. */
1529 if ((len == 0) || (iptr->flags.bits & INS_FLAG_UNRESOLVED))
1532 switch (iptr[1].opc) {
1534 /* We can only optimize for NULL values
1535 * here because otherwise a checkcast is
1537 if (iptr->sx.val.anyptr != NULL)
1540 /* copy the constant (NULL) to s3 */
1541 iptr->sx.s23.s3.constval = 0;
1542 iptr->opc = ICMD_AASTORECONST;
1543 iptr->flags.bits |= INS_FLAG_CHECK;
1544 OP2_0(TYPE_ADR, TYPE_INT);
1546 iptr[1].opc = ICMD_NOP;
1547 COUNT(count_pcmd_op);
1550 case ICMD_PUTSTATIC:
1552 # if SUPPORT_CONST_STORE_ZERO_ONLY
1553 if (iptr->sx.val.anyptr != NULL)
1556 /* XXX check field type? */
1557 /* copy the constant to s2 */
1558 /* XXX constval -> fieldconstval? */
1559 iptr->sx.s23.s2.constval = (ptrint) iptr->sx.val.anyptr;
1567 /* if we get here the ACONST has been optimized */
1571 #endif /* SUPPORT_CONST_STORE */
1576 /* pop 0 push 1 load */
1583 COUNT(count_load_instruction);
1584 i = opcode - ICMD_ILOAD; /* type */
1587 jd->local_map[iptr->s1.varindex * 5 + i];
1589 LOAD(i, iptr->s1.varindex);
1598 last_pei_boundary = sd.new;
1599 iptr->flags.bits |= INS_FLAG_CHECK;
1600 COUNT(count_check_null);
1601 COUNT(count_check_bound);
1602 COUNT(count_pcmd_mem);
1603 OP2_1(TYPE_ADR, TYPE_INT, opcode - ICMD_IALOAD);
1610 last_pei_boundary = sd.new;
1611 iptr->flags.bits |= INS_FLAG_CHECK;
1612 COUNT(count_check_null);
1613 COUNT(count_check_bound);
1614 COUNT(count_pcmd_mem);
1615 OP2_1(TYPE_ADR, TYPE_INT, TYPE_INT);
1618 /* pop 0 push 0 iinc */
1621 STATISTICS_STACKDEPTH_DISTRIBUTION(count_store_depth);
1623 last_store_boundary[iptr->s1.varindex] = sd.new;
1626 jd->local_map[iptr->s1.varindex * 5 + TYPE_INT];
1631 if ((copy->varkind == LOCALVAR) &&
1632 (copy->varnum == iptr->s1.varindex))
1634 copy->varkind = TEMPVAR;
1635 assert(IS_LOCALVAR(copy));
1642 iptr->dst.varindex = iptr->s1.varindex;
1645 /* pop 1 push 0 store */
1654 i = opcode - ICMD_ISTORE; /* type */
1655 javaindex = iptr->dst.varindex;
1656 j = iptr->dst.varindex =
1657 jd->local_map[javaindex * 5 + i];
1660 #if defined(ENABLE_STATISTICS)
1663 i = sd.new - curstack;
1665 count_store_length[20]++;
1667 count_store_length[i]++;
1670 count_store_depth[10]++;
1672 count_store_depth[i]++;
1675 /* check for conflicts as described in Figure 5.2 */
1677 copy = curstack->prev;
1680 if ((copy->varkind == LOCALVAR) &&
1681 (copy->varnum == j))
1683 copy->varkind = TEMPVAR;
1684 assert(IS_LOCALVAR(copy));
1691 /* if the variable is already coalesced, don't bother */
1693 if (IS_OUTVAR(curstack)
1694 || (curstack->varkind == LOCALVAR
1695 && curstack->varnum != j))
1698 /* there is no STORE Lj while curstack is live */
1700 if (curstack < last_store_boundary[javaindex])
1701 goto assume_conflict;
1703 /* there is no PEI while curstack is live */
1705 if (curstack < last_pei_boundary)
1706 goto assume_conflict;
1708 /*there is no non-consuming USE while curstack is live*/
1710 if (curstack < last_dup_boundary)
1711 goto assume_conflict;
1713 /* there is no DEF LOCALVAR(j) while curstack is live */
1715 copy = sd.new; /* most recent stackslot created + 1 */
1716 while (--copy > curstack) {
1717 if (copy->varkind == LOCALVAR && copy->varnum == j)
1718 goto assume_conflict;
1721 /* XXX temporatily turn off coalescing */ goto assume_conflict;
1723 /* coalesce the temporary variable with Lj */
1724 assert( (CURKIND == TEMPVAR) || (CURKIND == UNDEFVAR));
1725 assert(!IS_LOCALVAR(curstack));
1726 assert(!IS_OUTVAR(curstack));
1727 assert(!IS_PREALLOC(curstack));
1729 RELEASE_INDEX(sd, curstack);
1730 curstack->varkind = LOCALVAR;
1731 curstack->varnum = j;
1734 /* revert the coalescing, if it has been done earlier */
1736 if ((curstack->varkind == LOCALVAR)
1737 && (curstack->varnum == j))
1739 curstack->varkind = TEMPVAR;
1740 assert(IS_LOCALVAR(curstack));
1741 SET_TEMPVAR(curstack);
1744 /* remember the stack boundary at this store */
1746 last_store_boundary[j] = sd.new;
1748 STORE(opcode - ICMD_ISTORE, j);
1754 last_pei_boundary = sd.new;
1755 iptr->flags.bits |= INS_FLAG_CHECK;
1756 COUNT(count_check_null);
1757 COUNT(count_check_bound);
1758 COUNT(count_pcmd_mem);
1760 bte = builtintable_get_internal(BUILTIN_canstore);
1763 if (md->memuse > rd->memuse)
1764 rd->memuse = md->memuse;
1765 if (md->argintreguse > rd->argintreguse)
1766 rd->argintreguse = md->argintreguse;
1767 /* XXX non-leaf method? */
1769 /* make all stack variables saved */
1773 sd.var[copy->varnum].flags |= SAVEDVAR;
1774 /* in case copy->varnum is/will be a LOCALVAR */
1775 /* once and set back to a non LOCALVAR */
1776 /* the correct SAVEDVAR flag has to be */
1777 /* remembered in copy->flags, too */
1778 copy->flags |= SAVEDVAR;
1782 OP3_0(TYPE_ADR, TYPE_INT, TYPE_ADR);
1789 last_pei_boundary = sd.new;
1790 iptr->flags.bits |= INS_FLAG_CHECK;
1791 COUNT(count_check_null);
1792 COUNT(count_check_bound);
1793 COUNT(count_pcmd_mem);
1794 OP3_0(TYPE_ADR, TYPE_INT, opcode - ICMD_IASTORE);
1801 last_pei_boundary = sd.new;
1802 iptr->flags.bits |= INS_FLAG_CHECK;
1803 COUNT(count_check_null);
1804 COUNT(count_check_bound);
1805 COUNT(count_pcmd_mem);
1806 OP3_0(TYPE_ADR, TYPE_INT, TYPE_INT);
1812 #ifdef ENABLE_VERIFIER
1815 if (IS_2_WORD_TYPE(curstack->type))
1816 goto throw_stack_category_error;
1827 last_pei_boundary = sd.new;
1828 IF_JIT( md_return_alloc(jd, curstack); )
1829 COUNT(count_pcmd_return);
1830 OP1_0(opcode - ICMD_IRETURN);
1831 superblockend = true;
1835 last_pei_boundary = sd.new;
1836 COUNT(count_check_null);
1839 superblockend = true;
1842 case ICMD_PUTSTATIC:
1843 last_pei_boundary = sd.new;
1844 COUNT(count_pcmd_mem);
1845 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1846 OP1_0(fmiref->parseddesc.fd->type);
1849 /* pop 1 push 0 branch */
1852 case ICMD_IFNONNULL:
1853 COUNT(count_pcmd_bra);
1854 OP1_BRANCH(TYPE_ADR);
1855 BRANCH(tbptr, copy);
1864 COUNT(count_pcmd_bra);
1865 /* iptr->sx.val.i is set implicitly in parse by
1866 clearing the memory or from IF_ICMPxx
1869 OP1_BRANCH(TYPE_INT);
1870 /* iptr->sx.val.i = 0; */
1871 BRANCH(tbptr, copy);
1874 /* pop 0 push 0 branch */
1877 COUNT(count_pcmd_bra);
1879 BRANCH(tbptr, copy);
1880 superblockend = true;
1883 /* pop 1 push 0 table branch */
1885 case ICMD_TABLESWITCH:
1886 COUNT(count_pcmd_table);
1887 OP1_BRANCH(TYPE_INT);
1889 table = iptr->dst.table;
1890 BRANCH_TARGET(*table, tbptr, copy);
1893 i = iptr->sx.s23.s3.tablehigh
1894 - iptr->sx.s23.s2.tablelow + 1;
1897 BRANCH_TARGET(*table, tbptr, copy);
1900 superblockend = true;
1903 /* pop 1 push 0 table branch */
1905 case ICMD_LOOKUPSWITCH:
1906 COUNT(count_pcmd_table);
1907 OP1_BRANCH(TYPE_INT);
1909 BRANCH_TARGET(iptr->sx.s23.s3.lookupdefault, tbptr, copy);
1911 lookup = iptr->dst.lookup;
1913 i = iptr->sx.s23.s2.lookupcount;
1916 BRANCH_TARGET(lookup->target, tbptr, copy);
1919 superblockend = true;
1922 case ICMD_MONITORENTER:
1923 case ICMD_MONITOREXIT:
1924 last_pei_boundary = sd.new;
1925 COUNT(count_check_null);
1929 /* pop 2 push 0 branch */
1931 case ICMD_IF_ICMPEQ:
1932 case ICMD_IF_ICMPNE:
1933 case ICMD_IF_ICMPLT:
1934 case ICMD_IF_ICMPGE:
1935 case ICMD_IF_ICMPGT:
1936 case ICMD_IF_ICMPLE:
1937 COUNT(count_pcmd_bra);
1938 OP2_BRANCH(TYPE_INT, TYPE_INT);
1939 BRANCH(tbptr, copy);
1942 case ICMD_IF_ACMPEQ:
1943 case ICMD_IF_ACMPNE:
1944 COUNT(count_pcmd_bra);
1945 OP2_BRANCH(TYPE_ADR, TYPE_ADR);
1946 BRANCH(tbptr, copy);
1952 last_pei_boundary = sd.new;
1953 COUNT(count_check_null);
1954 COUNT(count_pcmd_mem);
1955 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1956 OP2_0(TYPE_ADR, fmiref->parseddesc.fd->type);
1961 if (!IS_2_WORD_TYPE(curstack->type)) {
1963 #ifdef ENABLE_VERIFIER
1966 if (IS_2_WORD_TYPE(curstack->prev->type))
1967 goto throw_stack_category_error;
1970 OP2_0_ANY_ANY; /* pop two slots */
1973 iptr->opc = ICMD_POP;
1974 OP1_0_ANY; /* pop one (two-word) slot */
1978 /* pop 0 push 1 dup */
1981 #ifdef ENABLE_VERIFIER
1984 if (IS_2_WORD_TYPE(curstack->type))
1985 goto throw_stack_category_error;
1988 COUNT(count_dup_instruction);
1991 USE_S1_ANY; /* XXX live through */
1992 /* DUP_SLOT(iptr->s1.var); */
1994 last_dup_boundary = sd.new - 1;
1995 iptr->dst.varindex = curstack->varnum;
2001 if (IS_2_WORD_TYPE(curstack->type)) {
2003 iptr->opc = ICMD_DUP;
2008 /* ..., ????, cat1 */
2009 #ifdef ENABLE_VERIFIER
2011 if (IS_2_WORD_TYPE(curstack->prev->type))
2012 goto throw_stack_category_error;
2015 iptr->dst.dupslots = DMNEW(s4, 2 + 2);
2016 /* XXX live through */
2017 iptr->dst.dupslots[0] = curstack->prev->varnum;
2018 /* XXX live through */
2019 iptr->dst.dupslots[1] = curstack->varnum;
2022 DUP_SLOT(copy->prev);
2023 iptr->dst.dupslots[2+0] = curstack->varnum;
2025 iptr->dst.dupslots[2+1] = curstack->varnum;
2026 last_dup_boundary = sd.new;
2031 /* pop 2 push 3 dup */
2034 #ifdef ENABLE_VERIFIER
2037 if (IS_2_WORD_TYPE(curstack->type) ||
2038 IS_2_WORD_TYPE(curstack->prev->type))
2039 goto throw_stack_category_error;
2044 iptr->dst.dupslots = DMNEW(int, 2 + 3);
2045 iptr->dst.dupslots[0] = curstack->prev->varnum;
2046 iptr->dst.dupslots[1] = curstack->varnum;
2051 iptr->dst.dupslots[2+0] = curstack->varnum;
2052 DUP_SLOT(copy->prev);
2053 iptr->dst.dupslots[2+1] = curstack->varnum;
2055 iptr->dst.dupslots[2+2] = curstack->varnum;
2056 last_dup_boundary = sd.new;
2062 if (IS_2_WORD_TYPE(curstack->type)) {
2063 /* ..., ????, cat2 */
2064 #ifdef ENABLE_VERIFIER
2066 if (IS_2_WORD_TYPE(curstack->prev->type))
2067 goto throw_stack_category_error;
2070 iptr->opc = ICMD_DUP_X1;
2074 /* ..., ????, cat1 */
2075 #ifdef ENABLE_VERIFIER
2078 if (IS_2_WORD_TYPE(curstack->prev->type)
2079 || IS_2_WORD_TYPE(curstack->prev->prev->type))
2080 goto throw_stack_category_error;
2085 iptr->dst.dupslots = DMNEW(s4, 3 + 5);
2086 iptr->dst.dupslots[0] =curstack->prev->prev->varnum;
2087 iptr->dst.dupslots[1] = curstack->prev->varnum;
2088 iptr->dst.dupslots[2] = curstack->varnum;
2090 POPANY; POPANY; POPANY;
2092 DUP_SLOT(copy->prev);
2093 iptr->dst.dupslots[3+0] = curstack->varnum;
2095 iptr->dst.dupslots[3+1] = curstack->varnum;
2096 DUP_SLOT(copy->prev->prev);
2097 iptr->dst.dupslots[3+2] = curstack->varnum;
2098 DUP_SLOT(copy->prev);
2099 iptr->dst.dupslots[3+3] = curstack->varnum;
2101 iptr->dst.dupslots[3+4] = curstack->varnum;
2102 last_dup_boundary = sd.new;
2107 /* pop 3 push 4 dup */
2111 if (IS_2_WORD_TYPE(curstack->prev->type)) {
2112 /* ..., cat2, ???? */
2113 #ifdef ENABLE_VERIFIER
2115 if (IS_2_WORD_TYPE(curstack->type))
2116 goto throw_stack_category_error;
2119 iptr->opc = ICMD_DUP_X1;
2123 /* ..., cat1, ???? */
2124 #ifdef ENABLE_VERIFIER
2127 if (IS_2_WORD_TYPE(curstack->type)
2128 || IS_2_WORD_TYPE(curstack->prev->prev->type))
2129 goto throw_stack_category_error;
2133 iptr->dst.dupslots = DMNEW(s4, 3 + 4);
2134 iptr->dst.dupslots[0] =curstack->prev->prev->varnum;
2135 iptr->dst.dupslots[1] = curstack->prev->varnum;
2136 iptr->dst.dupslots[2] = curstack->varnum;
2138 POPANY; POPANY; POPANY;
2141 iptr->dst.dupslots[3+0] = curstack->varnum;
2142 DUP_SLOT(copy->prev->prev);
2143 iptr->dst.dupslots[3+1] = curstack->varnum;
2144 DUP_SLOT(copy->prev);
2145 iptr->dst.dupslots[3+2] = curstack->varnum;
2147 iptr->dst.dupslots[3+3] = curstack->varnum;
2148 last_dup_boundary = sd.new;
2155 if (IS_2_WORD_TYPE(curstack->type)) {
2156 /* ..., ????, cat2 */
2157 if (IS_2_WORD_TYPE(curstack->prev->type)) {
2158 /* ..., cat2, cat2 */
2159 iptr->opc = ICMD_DUP_X1;
2163 /* ..., cat1, cat2 */
2164 #ifdef ENABLE_VERIFIER
2167 if (IS_2_WORD_TYPE(curstack->prev->prev->type))
2168 goto throw_stack_category_error;
2171 iptr->opc = ICMD_DUP_X2;
2177 /* ..., ????, ????, cat1 */
2179 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
2180 /* ..., cat2, ????, cat1 */
2181 #ifdef ENABLE_VERIFIER
2183 if (IS_2_WORD_TYPE(curstack->prev->type))
2184 goto throw_stack_category_error;
2187 iptr->opc = ICMD_DUP2_X1;
2191 /* ..., cat1, ????, cat1 */
2192 #ifdef ENABLE_VERIFIER
2195 if (IS_2_WORD_TYPE(curstack->prev->type)
2196 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
2197 goto throw_stack_category_error;
2201 iptr->dst.dupslots = DMNEW(s4, 4 + 6);
2202 iptr->dst.dupslots[0] =
2203 curstack->prev->prev->prev->varnum;
2204 iptr->dst.dupslots[1] =
2205 curstack->prev->prev->varnum;
2206 iptr->dst.dupslots[2] = curstack->prev->varnum;
2207 iptr->dst.dupslots[3] = curstack->varnum;
2209 POPANY; POPANY; POPANY; POPANY;
2211 DUP_SLOT(copy->prev);
2212 iptr->dst.dupslots[4+0] = curstack->varnum;
2214 iptr->dst.dupslots[4+1] = curstack->varnum;
2215 DUP_SLOT(copy->prev->prev->prev);
2216 iptr->dst.dupslots[4+2] = curstack->varnum;
2217 DUP_SLOT(copy->prev->prev);
2218 iptr->dst.dupslots[4+3] = curstack->varnum;
2219 DUP_SLOT(copy->prev);
2220 iptr->dst.dupslots[4+4] = curstack->varnum;
2222 iptr->dst.dupslots[4+5] = curstack->varnum;
2223 last_dup_boundary = sd.new;
2228 /* pop 2 push 2 swap */
2231 #ifdef ENABLE_VERIFIER
2234 if (IS_2_WORD_TYPE(curstack->type)
2235 || IS_2_WORD_TYPE(curstack->prev->type))
2236 goto throw_stack_category_error;
2240 iptr->dst.dupslots = DMNEW(s4, 2 + 2);
2241 iptr->dst.dupslots[0] = curstack->prev->varnum;
2242 iptr->dst.dupslots[1] = curstack->varnum;
2247 iptr->dst.dupslots[2+0] = curstack->varnum;
2248 DUP_SLOT(copy->prev);
2249 iptr->dst.dupslots[2+1] = curstack->varnum;
2250 last_dup_boundary = sd.new;
2257 last_pei_boundary = sd.new;
2258 #if !SUPPORT_DIVISION
2259 bte = iptr->sx.s23.s3.bte;
2262 if (md->memuse > rd->memuse)
2263 rd->memuse = md->memuse;
2264 if (md->argintreguse > rd->argintreguse)
2265 rd->argintreguse = md->argintreguse;
2267 /* make all stack variables saved */
2271 sd.var[copy->varnum].flags |= SAVEDVAR;
2272 copy->flags |= SAVEDVAR;
2277 #endif /* !SUPPORT_DIVISION */
2288 COUNT(count_pcmd_op);
2289 OP2_1(TYPE_INT, TYPE_INT, TYPE_INT);
2294 last_pei_boundary = sd.new;
2295 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
2296 bte = iptr->sx.s23.s3.bte;
2299 if (md->memuse > rd->memuse)
2300 rd->memuse = md->memuse;
2301 if (md->argintreguse > rd->argintreguse)
2302 rd->argintreguse = md->argintreguse;
2303 /* XXX non-leaf method? */
2305 /* make all stack variables saved */
2309 sd.var[copy->varnum].flags |= SAVEDVAR;
2310 copy->flags |= SAVEDVAR;
2315 #endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
2320 #if SUPPORT_LONG_LOGICAL
2324 #endif /* SUPPORT_LONG_LOGICAL */
2325 COUNT(count_pcmd_op);
2326 OP2_1(TYPE_LNG, TYPE_LNG, TYPE_LNG);
2332 COUNT(count_pcmd_op);
2333 OP2_1(TYPE_LNG, TYPE_INT, TYPE_LNG);
2341 COUNT(count_pcmd_op);
2342 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_FLT);
2350 COUNT(count_pcmd_op);
2351 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_DBL);
2355 COUNT(count_pcmd_op);
2356 #if SUPPORT_LONG_CMP_CONST
2357 if ((len == 0) || (iptr[1].sx.val.i != 0))
2360 switch (iptr[1].opc) {
2362 iptr->opc = ICMD_IF_LCMPEQ;
2364 iptr->dst.insindex = iptr[1].dst.insindex;
2365 iptr[1].opc = ICMD_NOP;
2367 OP2_BRANCH(TYPE_LNG, TYPE_LNG);
2368 BRANCH(tbptr, copy);
2370 COUNT(count_pcmd_bra);
2373 iptr->opc = ICMD_IF_LCMPNE;
2374 goto icmd_lcmp_if_tail;
2376 iptr->opc = ICMD_IF_LCMPLT;
2377 goto icmd_lcmp_if_tail;
2379 iptr->opc = ICMD_IF_LCMPGT;
2380 goto icmd_lcmp_if_tail;
2382 iptr->opc = ICMD_IF_LCMPLE;
2383 goto icmd_lcmp_if_tail;
2385 iptr->opc = ICMD_IF_LCMPGE;
2386 goto icmd_lcmp_if_tail;
2392 #endif /* SUPPORT_LONG_CMP_CONST */
2393 OP2_1(TYPE_LNG, TYPE_LNG, TYPE_INT);
2396 /* XXX why is this deactivated? */
2399 COUNT(count_pcmd_op);
2400 if ((len == 0) || (iptr[1].sx.val.i != 0))
2403 switch (iptr[1].opc) {
2405 iptr->opc = ICMD_IF_FCMPEQ;
2407 iptr->dst.insindex = iptr[1].dst.insindex;
2408 iptr[1].opc = ICMD_NOP;
2410 OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2411 BRANCH(tbptr, copy);
2413 COUNT(count_pcmd_bra);
2416 iptr->opc = ICMD_IF_FCMPNE;
2417 goto icmd_if_fcmpl_tail;
2419 iptr->opc = ICMD_IF_FCMPL_LT;
2420 goto icmd_if_fcmpl_tail;
2422 iptr->opc = ICMD_IF_FCMPL_GT;
2423 goto icmd_if_fcmpl_tail;
2425 iptr->opc = ICMD_IF_FCMPL_LE;
2426 goto icmd_if_fcmpl_tail;
2428 iptr->opc = ICMD_IF_FCMPL_GE;
2429 goto icmd_if_fcmpl_tail;
2436 OPTT2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2440 COUNT(count_pcmd_op);
2441 if ((len == 0) || (iptr[1].sx.val.i != 0))
2444 switch (iptr[1].opc) {
2446 iptr->opc = ICMD_IF_FCMPEQ;
2448 iptr->dst.insindex = iptr[1].dst.insindex;
2449 iptr[1].opc = ICMD_NOP;
2451 OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2452 BRANCH(tbptr, copy);
2454 COUNT(count_pcmd_bra);
2457 iptr->opc = ICMD_IF_FCMPNE;
2458 goto icmd_if_fcmpg_tail;
2460 iptr->opc = ICMD_IF_FCMPG_LT;
2461 goto icmd_if_fcmpg_tail;
2463 iptr->opc = ICMD_IF_FCMPG_GT;
2464 goto icmd_if_fcmpg_tail;
2466 iptr->opc = ICMD_IF_FCMPG_LE;
2467 goto icmd_if_fcmpg_tail;
2469 iptr->opc = ICMD_IF_FCMPG_GE;
2470 goto icmd_if_fcmpg_tail;
2477 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2481 COUNT(count_pcmd_op);
2482 if ((len == 0) || (iptr[1].sx.val.i != 0))
2485 switch (iptr[1].opc) {
2487 iptr->opc = ICMD_IF_DCMPEQ;
2489 iptr->dst.insindex = iptr[1].dst.insindex;
2490 iptr[1].opc = ICMD_NOP;
2492 OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2493 BRANCH(tbptr, copy);
2495 COUNT(count_pcmd_bra);
2498 iptr->opc = ICMD_IF_DCMPNE;
2499 goto icmd_if_dcmpl_tail;
2501 iptr->opc = ICMD_IF_DCMPL_LT;
2502 goto icmd_if_dcmpl_tail;
2504 iptr->opc = ICMD_IF_DCMPL_GT;
2505 goto icmd_if_dcmpl_tail;
2507 iptr->opc = ICMD_IF_DCMPL_LE;
2508 goto icmd_if_dcmpl_tail;
2510 iptr->opc = ICMD_IF_DCMPL_GE;
2511 goto icmd_if_dcmpl_tail;
2518 OPTT2_1(TYPE_DBL, TYPE_INT);
2522 COUNT(count_pcmd_op);
2523 if ((len == 0) || (iptr[1].sx.val.i != 0))
2526 switch (iptr[1].opc) {
2528 iptr->opc = ICMD_IF_DCMPEQ;
2530 iptr->dst.insindex = iptr[1].dst.insindex;
2531 iptr[1].opc = ICMD_NOP;
2533 OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2534 BRANCH(tbptr, copy);
2536 COUNT(count_pcmd_bra);
2539 iptr->opc = ICMD_IF_DCMPNE;
2540 goto icmd_if_dcmpg_tail;
2542 iptr->opc = ICMD_IF_DCMPG_LT;
2543 goto icmd_if_dcmpg_tail;
2545 iptr->opc = ICMD_IF_DCMPG_GT;
2546 goto icmd_if_dcmpg_tail;
2548 iptr->opc = ICMD_IF_DCMPG_LE;
2549 goto icmd_if_dcmpg_tail;
2551 iptr->opc = ICMD_IF_DCMPG_GE;
2552 goto icmd_if_dcmpg_tail;
2559 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2564 COUNT(count_pcmd_op);
2565 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2570 COUNT(count_pcmd_op);
2571 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2580 case ICMD_INT2SHORT:
2581 COUNT(count_pcmd_op);
2582 OP1_1(TYPE_INT, TYPE_INT);
2585 COUNT(count_pcmd_op);
2586 OP1_1(TYPE_LNG, TYPE_LNG);
2589 COUNT(count_pcmd_op);
2590 OP1_1(TYPE_FLT, TYPE_FLT);
2593 COUNT(count_pcmd_op);
2594 OP1_1(TYPE_DBL, TYPE_DBL);
2598 COUNT(count_pcmd_op);
2599 OP1_1(TYPE_INT, TYPE_LNG);
2602 COUNT(count_pcmd_op);
2603 OP1_1(TYPE_INT, TYPE_FLT);
2606 COUNT(count_pcmd_op);
2607 OP1_1(TYPE_INT, TYPE_DBL);
2610 COUNT(count_pcmd_op);
2611 OP1_1(TYPE_LNG, TYPE_INT);
2614 COUNT(count_pcmd_op);
2615 OP1_1(TYPE_LNG, TYPE_FLT);
2618 COUNT(count_pcmd_op);
2619 OP1_1(TYPE_LNG, TYPE_DBL);
2622 COUNT(count_pcmd_op);
2623 OP1_1(TYPE_FLT, TYPE_INT);
2626 COUNT(count_pcmd_op);
2627 OP1_1(TYPE_FLT, TYPE_LNG);
2630 COUNT(count_pcmd_op);
2631 OP1_1(TYPE_FLT, TYPE_DBL);
2634 COUNT(count_pcmd_op);
2635 OP1_1(TYPE_DBL, TYPE_INT);
2638 COUNT(count_pcmd_op);
2639 OP1_1(TYPE_DBL, TYPE_LNG);
2642 COUNT(count_pcmd_op);
2643 OP1_1(TYPE_DBL, TYPE_FLT);
2646 case ICMD_CHECKCAST:
2647 last_pei_boundary = sd.new;
2648 if (iptr->flags.bits & INS_FLAG_ARRAY) {
2649 /* array type cast-check */
2651 bte = builtintable_get_internal(BUILTIN_arraycheckcast);
2654 if (md->memuse > rd->memuse)
2655 rd->memuse = md->memuse;
2656 if (md->argintreguse > rd->argintreguse)
2657 rd->argintreguse = md->argintreguse;
2659 /* make all stack variables saved */
2663 sd.var[copy->varnum].flags |= SAVEDVAR;
2664 copy->flags |= SAVEDVAR;
2668 OP1_1(TYPE_ADR, TYPE_ADR);
2671 case ICMD_INSTANCEOF:
2672 case ICMD_ARRAYLENGTH:
2673 last_pei_boundary = sd.new;
2674 OP1_1(TYPE_ADR, TYPE_INT);
2678 case ICMD_ANEWARRAY:
2679 last_pei_boundary = sd.new;
2680 OP1_1(TYPE_INT, TYPE_ADR);
2684 last_pei_boundary = sd.new;
2685 COUNT(count_check_null);
2686 COUNT(count_pcmd_mem);
2687 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2688 OP1_1(TYPE_ADR, fmiref->parseddesc.fd->type);
2693 case ICMD_GETSTATIC:
2694 last_pei_boundary = sd.new;
2695 COUNT(count_pcmd_mem);
2696 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2697 OP0_1(fmiref->parseddesc.fd->type);
2701 last_pei_boundary = sd.new;
2708 BRANCH_TARGET(iptr->sx.s23.s3.jsrtarget, tbptr, copy);
2710 tbptr->type = BBTYPE_SBR;
2712 /* We need to check for overflow right here because
2713 * the pushed value is poped afterwards */
2716 /* calculate stack after return */
2721 /* pop many push any */
2725 bte = iptr->sx.s23.s3.bte;
2729 case ICMD_INVOKESTATIC:
2730 case ICMD_INVOKESPECIAL:
2731 case ICMD_INVOKEVIRTUAL:
2732 case ICMD_INVOKEINTERFACE:
2733 COUNT(count_pcmd_met);
2735 /* Check for functions to replace with builtin
2738 if (builtintable_replace_function(iptr))
2741 INSTRUCTION_GET_METHODDESC(iptr, md);
2742 /* XXX resurrect this COUNT? */
2743 /* if (lm->flags & ACC_STATIC) */
2744 /* {COUNT(count_check_null);} */
2748 last_pei_boundary = sd.new;
2752 if (md->memuse > rd->memuse)
2753 rd->memuse = md->memuse;
2754 if (md->argintreguse > rd->argintreguse)
2755 rd->argintreguse = md->argintreguse;
2756 if (md->argfltreguse > rd->argfltreguse)
2757 rd->argfltreguse = md->argfltreguse;
2761 /* XXX optimize for <= 2 args */
2762 /* XXX not for ICMD_BUILTIN */
2763 iptr->s1.argcount = stackdepth;
2764 iptr->sx.s23.s2.args = DMNEW(s4, stackdepth);
2767 for (i-- ; i >= 0; i--) {
2768 iptr->sx.s23.s2.args[i] = copy->varnum;
2770 /* do not change STACKVARs or LOCALVARS to ARGVAR*/
2771 /* -> won't help anyway */
2772 if (!(IS_OUTVAR(copy) || IS_LOCALVAR(copy))) {
2774 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2775 /* If we pass float arguments in integer argument registers, we
2776 * are not allowed to precolor them here. Floats have to be moved
2777 * to this regs explicitly in codegen().
2778 * Only arguments that are passed by stack anyway can be precolored
2779 * (michi 2005/07/24) */
2780 if (!(sd.var[copy->varnum].flags & SAVEDVAR) &&
2781 (!IS_FLT_DBL_TYPE(copy->type)
2782 || md->params[i].inmemory)) {
2784 if (!(sd.var[copy->varnum].flags & SAVEDVAR)) {
2789 #if defined(ENABLE_INTRP)
2792 if (md->params[i].inmemory) {
2793 sd.var[copy->varnum].regoff =
2794 md->params[i].regoff;
2795 sd.var[copy->varnum].flags |=
2799 if (IS_FLT_DBL_TYPE(copy->type)) {
2800 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2801 assert(0); /* XXX is this assert ok? */
2803 sd.var[copy->varnum].regoff =
2804 rd->argfltregs[md->params[i].regoff];
2805 #endif /* SUPPORT_PASS_FLOATARGS_IN_INTREGS */
2808 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
2809 if (IS_2_WORD_TYPE(copy->type))
2810 sd.var[copy->varnum].regoff =
2811 PACK_REGS( rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
2812 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
2815 #endif /* SUPPORT_COMBINE_INTEGER_REGISTERS */
2816 sd.var[copy->varnum].regoff =
2817 rd->argintregs[md->params[i].regoff];
2820 #if defined(ENABLE_INTRP)
2821 } /* end if (!opt_intrp) */
2828 /* deal with live-through stack slots "under" the */
2830 /* XXX not for ICMD_BUILTIN */
2835 iptr->sx.s23.s2.args[i++] = copy->varnum;
2836 sd.var[copy->varnum].flags |= SAVEDVAR;
2840 /* pop the arguments */
2849 /* push the return value */
2851 if (md->returntype.type != TYPE_VOID) {
2852 GET_NEW_INDEX(sd, new_index);
2853 DST(md->returntype.type, new_index);
2858 case ICMD_INLINE_START:
2859 case ICMD_INLINE_END:
2864 case ICMD_MULTIANEWARRAY:
2865 last_pei_boundary = sd.new;
2866 if (rd->argintreguse < 3)
2867 rd->argintreguse = 3;
2869 i = iptr->s1.argcount;
2873 iptr->sx.s23.s2.args = DMNEW(s4, i);
2875 #if defined(SPECIALMEMUSE)
2876 # if defined(__DARWIN__)
2877 if (rd->memuse < (i + INT_ARG_CNT +LA_SIZE_IN_POINTERS))
2878 rd->memuse = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2880 if (rd->memuse < (i + LA_SIZE_IN_POINTERS + 3))
2881 rd->memuse = i + LA_SIZE_IN_POINTERS + 3;
2884 # if defined(__I386__)
2885 if (rd->memuse < i + 3)
2886 rd->memuse = i + 3; /* n integer args spilled on stack */
2887 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2888 if (rd->memuse < i + 2)
2889 rd->memuse = i + 2; /* 4*4 bytes callee save space */
2892 rd->memuse = i; /* n integer args spilled on stack */
2893 # endif /* defined(__I386__) */
2897 /* check INT type here? Currently typecheck does this. */
2898 iptr->sx.s23.s2.args[i] = copy->varnum;
2899 if (!(sd.var[copy->varnum].flags & SAVEDVAR)
2900 && (!IS_OUTVAR(copy))
2901 && (!IS_LOCALVAR(copy)) ) {
2902 copy->varkind = ARGVAR;
2903 sd.var[copy->varnum].flags |=
2904 INMEMORY & PREALLOC;
2905 #if defined(SPECIALMEMUSE)
2906 # if defined(__DARWIN__)
2907 sd.var[copy->varnum].regoff = i +
2908 LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2910 sd.var[copy->varnum].regoff = i +
2911 LA_SIZE_IN_POINTERS + 3;
2914 # if defined(__I386__)
2915 sd.var[copy->varnum].regoff = i + 3;
2916 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2917 sd.var[copy->varnum].regoff = i + 2;
2919 sd.var[copy->varnum].regoff = i;
2920 # endif /* defined(__I386__) */
2921 #endif /* defined(SPECIALMEMUSE) */
2926 sd.var[copy->varnum].flags |= SAVEDVAR;
2930 i = iptr->s1.argcount;
2935 GET_NEW_INDEX(sd, new_index);
2936 DST(TYPE_ADR, new_index);
2942 new_internalerror("Unknown ICMD %d", opcode);
2948 } /* while instructions */
2950 /* set out-stack of block */
2952 sd.bptr->outstack = curstack;
2953 sd.bptr->outdepth = stackdepth;
2954 sd.bptr->outvars = DMNEW(s4, stackdepth);
2955 for (i = stackdepth, copy = curstack; i--; copy = copy->prev)
2956 sd.bptr->outvars[i] = copy->varnum;
2958 /* stack slots at basic block end become interfaces */
2961 for (copy = curstack; copy; i--, copy = copy->prev) {
2964 /* with the new vars rd->interfaces will be removed */
2965 /* and all in and outvars have to be STACKVARS! */
2966 /* in the moment i.e. SWAP with in and out vars can */
2967 /* create an unresolvable conflict */
2969 v = sd.var + copy->varnum;
2970 j = jd->interface_map[i * 5 + copy->type];
2972 SET_OUTVAR(sd, copy);
2975 /* no interface var until now for this depth and */
2977 jd->interface_map[i*5 + copy->type] = v->flags;
2980 jd->interface_map[i*5 + copy->type] |= v->flags;
2984 /* check if interface slots at basic block begin must be saved */
2986 for (i=0; i<sd.bptr->indepth; ++i) {
2987 varinfo *v = sd.var + sd.bptr->invars[i];
2989 jd->interface_map[i*5 + v->type] |= v->flags & SAVEDVAR;
2993 #if defined(STACK_VERBOSE)
2994 printf("OUTVARS\n");
2995 for( copy = sd.bptr->outstack; copy; copy = copy->prev ) {
2996 printf("%2d(%d", copy->varnum, copy->type);
2997 if (IS_OUTVAR(copy))
2999 if (IS_PREALLOC(copy))
3007 superblockend = true;
3010 } /* while blocks */
3011 } while (repeat && !deadcode);
3013 /* gather statistics *****************************************************/
3015 #if defined(ENABLE_STATISTICS)
3017 if (jd->new_basicblockcount > count_max_basic_blocks)
3018 count_max_basic_blocks = jd->new_basicblockcount;
3019 count_basic_blocks += jd->new_basicblockcount;
3020 if (jd->new_instructioncount > count_max_javainstr)
3021 count_max_javainstr = jd->new_instructioncount;
3022 count_javainstr += jd->new_instructioncount;
3023 if (jd->new_stackcount > count_upper_bound_new_stack)
3024 count_upper_bound_new_stack = jd->new_stackcount;
3025 if ((sd.new - jd->new_stack) > count_max_new_stack)
3026 count_max_new_stack = (sd.new - jd->new_stack);
3028 b_count = jd->new_basicblockcount;
3029 sd.bptr = jd->new_basicblocks;
3030 while (--b_count >= 0) {
3031 if (sd.bptr->flags > BBREACHED) {
3032 if (sd.bptr->indepth >= 10)
3033 count_block_stack[10]++;
3035 count_block_stack[sd.bptr->indepth]++;
3036 len = sd.bptr->icount;
3038 count_block_size_distribution[len]++;
3040 count_block_size_distribution[10]++;
3042 count_block_size_distribution[11]++;
3044 count_block_size_distribution[12]++;
3046 count_block_size_distribution[13]++;
3048 count_block_size_distribution[14]++;
3050 count_block_size_distribution[15]++;
3052 count_block_size_distribution[16]++;
3054 count_block_size_distribution[17]++;
3059 if (iteration_count == 1)
3060 count_analyse_iterations[0]++;
3061 else if (iteration_count == 2)
3062 count_analyse_iterations[1]++;
3063 else if (iteration_count == 3)
3064 count_analyse_iterations[2]++;
3065 else if (iteration_count == 4)
3066 count_analyse_iterations[3]++;
3068 count_analyse_iterations[4]++;
3070 if (jd->new_basicblockcount <= 5)
3071 count_method_bb_distribution[0]++;
3072 else if (jd->new_basicblockcount <= 10)
3073 count_method_bb_distribution[1]++;
3074 else if (jd->new_basicblockcount <= 15)
3075 count_method_bb_distribution[2]++;
3076 else if (jd->new_basicblockcount <= 20)
3077 count_method_bb_distribution[3]++;
3078 else if (jd->new_basicblockcount <= 30)
3079 count_method_bb_distribution[4]++;
3080 else if (jd->new_basicblockcount <= 40)
3081 count_method_bb_distribution[5]++;
3082 else if (jd->new_basicblockcount <= 50)
3083 count_method_bb_distribution[6]++;
3084 else if (jd->new_basicblockcount <= 75)
3085 count_method_bb_distribution[7]++;
3087 count_method_bb_distribution[8]++;
3089 #endif /* defined(ENABLE_STATISTICS) */
3091 /* everything's ok *******************************************************/
3095 /* goto labels for throwing verifier exceptions **************************/
3097 #if defined(ENABLE_VERIFIER)
3099 throw_stack_underflow:
3100 exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
3103 throw_stack_overflow:
3104 exceptions_throw_verifyerror(m, "Stack size too large");
3107 throw_stack_depth_error:
3108 exceptions_throw_verifyerror(m,"Stack depth mismatch");
3111 throw_stack_type_error:
3112 exceptions_throw_verifyerror_for_stack(m, expectedtype);
3115 throw_stack_category_error:
3116 exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
3124 * These are local overrides for various environment variables in Emacs.
3125 * Please do not remove this and leave it at the end of the file, where
3126 * Emacs will automagically detect them.
3127 * ---------------------------------------------------------------------
3130 * indent-tabs-mode: t
3134 * vim:noexpandtab:sw=4:ts=4: