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 5359 2006-09-06 09:57:21Z edwin $
49 #include "mm/memory.h"
50 #include "native/native.h"
51 #include "toolbox/logging.h"
52 #include "vm/global.h"
53 #include "vm/builtin.h"
54 #include "vm/options.h"
55 #include "vm/resolve.h"
56 #include "vm/statistics.h"
57 #include "vm/stringlocal.h"
58 #include "vm/jit/cfg.h"
59 #include "vm/jit/codegen-common.h"
60 #include "vm/jit/abi.h"
61 #include "vm/jit/show.h"
63 #if defined(ENABLE_DISASSEMBLER)
64 # include "vm/jit/disass.h"
67 #include "vm/jit/jit.h"
68 #include "vm/jit/stack.h"
70 #if defined(ENABLE_LSRA)
71 # include "vm/jit/allocator/lsra.h"
74 /*#define STACK_VERBOSE*/
77 /* macro for saving #ifdefs ***************************************************/
79 #if defined(ENABLE_INTRP)
80 #define IF_INTRP(x) if (opt_intrp) { x }
81 #define IF_NO_INTRP(x) if (!opt_intrp) { x }
84 #define IF_NO_INTRP(x) { x }
87 #if defined(ENABLE_INTRP)
88 #if defined(ENABLE_JIT)
89 #define IF_JIT(x) if (!opt_intrp) { x }
93 #else /* !defined(ENABLE_INTRP) */
94 #define IF_JIT(x) { x }
95 #endif /* defined(ENABLE_INTRP) */
97 #if defined(ENABLE_STATISTICS)
98 #define STATISTICS_STACKDEPTH_DISTRIBUTION(distr) \
101 if (stackdepth >= 10) \
102 count_store_depth[10]++; \
104 count_store_depth[stackdepth]++; \
107 #else /* !defined(ENABLE_STATISTICS) */
108 #define STATISTICS_STACKDEPTH_DISTRIBUTION(distr)
111 /* stack_init ******************************************************************
113 Initialized the stack analysis subsystem (called by jit_init).
115 *******************************************************************************/
117 bool stack_init(void)
123 /* stack_analyse ***************************************************************
125 Analyse_stack uses the intermediate code created by parse.c to
126 build a model of the JVM operand stack for the current method.
128 The following checks are performed:
129 - check for operand stack underflow (before each instruction)
130 - check for operand stack overflow (after[1] each instruction)
131 - check for matching stack depth at merging points
132 - check for matching basic types[2] at merging points
133 - check basic types for instruction input (except for BUILTIN*
134 opcodes, INVOKE* opcodes and MULTIANEWARRAY)
136 [1]) Checking this after the instruction should be ok. parse.c
137 counts the number of required stack slots in such a way that it is
138 only vital that we don't exceed `maxstack` at basic block
141 [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
142 DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
143 types are not discerned.
145 *******************************************************************************/
148 (iptr->s1.var = NULL)
150 #define USE_S1_LOCAL(type1)
152 #define USE_S1(type1) \
155 CHECK_BASIC_TYPE(type1, curstack->type); \
156 iptr->s1.var = curstack; \
162 iptr->s1.var = curstack; \
165 #define USE_S1_S2(type1, type2) \
168 CHECK_BASIC_TYPE(type1, curstack->prev->type); \
169 CHECK_BASIC_TYPE(type2, curstack->type); \
170 iptr->sx.s23.s2.var = curstack; \
171 iptr->s1.var = curstack->prev; \
174 #define USE_S1_S2_ANY_ANY \
177 iptr->sx.s23.s2.var = curstack; \
178 iptr->s1.var = curstack->prev; \
181 #define USE_S1_S2_S3(type1, type2, type3) \
184 CHECK_BASIC_TYPE(type1, curstack->prev->prev->type); \
185 CHECK_BASIC_TYPE(type2, curstack->prev->type); \
186 CHECK_BASIC_TYPE(type3, curstack->type); \
187 iptr->sx.s23.s3.var = curstack; \
188 iptr->sx.s23.s2.var = curstack->prev; \
189 iptr->s1.var = curstack->prev->prev; \
192 #define POP_S1(type1) \
195 if (curstack->varkind == UNDEFVAR) \
196 curstack->varkind = TEMPVAR; \
197 curstack = curstack->prev; \
203 if (curstack->varkind == UNDEFVAR) \
204 curstack->varkind = TEMPVAR; \
205 curstack = curstack->prev; \
208 #define POP_S1_S2(type1, type2) \
210 USE_S1_S2(type1, type2); \
211 if (curstack->varkind == UNDEFVAR) \
212 curstack->varkind = TEMPVAR; \
213 if (curstack->prev->varkind == UNDEFVAR) \
214 curstack->prev->varkind = TEMPVAR; \
215 curstack = curstack->prev->prev; \
218 #define POP_S1_S2_ANY_ANY \
221 if (curstack->varkind == UNDEFVAR) \
222 curstack->varkind = TEMPVAR; \
223 if (curstack->prev->varkind == UNDEFVAR) \
224 curstack->prev->varkind = TEMPVAR; \
225 curstack = curstack->prev->prev; \
228 #define POP_S1_S2_S3(type1, type2, type3) \
230 USE_S1_S2_S3(type1, type2, type3); \
231 if (curstack->varkind == UNDEFVAR) \
232 curstack->varkind = TEMPVAR; \
233 if (curstack->prev->varkind == UNDEFVAR) \
234 curstack->prev->varkind = TEMPVAR; \
235 if (curstack->prev->prev->varkind == UNDEFVAR) \
236 curstack->prev->prev->varkind = TEMPVAR; \
237 curstack = curstack->prev->prev->prev; \
244 (iptr->dst.var = NULL)
246 #define NEW_DST(typed, depth) \
248 NEWSTACKn(typed, (depth)); \
249 iptr->dst.var = curstack; \
252 #define NEW_DST_LOCALVAR(typed, index) \
254 NEWSTACK(typed, LOCALVAR, (index)); \
255 iptr->dst.var = curstack; \
264 #define NEW_OP0_BRANCH \
269 #define NEW_OP0_1(typed) \
272 NEW_DST(typed, stackdepth); \
276 #define NEW_OP1_0(type1) \
283 #define NEW_OP1_0_ANY \
290 #define NEW_OP1_BRANCH(type1) \
296 #define NEW_OP1_1(type1, typed) \
299 NEW_DST(typed, stackdepth - 1); \
302 #define NEW_OP2_0(type1, type2) \
304 POP_S1_S2(type1, type2); \
309 #define NEW_OP2_BRANCH(type1, type2) \
311 POP_S1_S2(type1, type2); \
315 #define NEW_OP2_0_ANY_ANY \
322 #define NEW_OP2_1(type1, type2, typed) \
324 POP_S1_S2(type1, type2); \
325 NEW_DST(typed, stackdepth - 2); \
329 #define NEW_OP3_0(type1, type2, type3) \
331 POP_S1_S2_S3(type1, type2, type3); \
336 #define NEW_LOAD(type1, index) \
338 NEW_DST_LOCALVAR(type1, index); \
342 #define NEW_STORE(type1, index) \
348 #define BRANCH_TARGET(bt, tempbptr, tempsp) \
350 (bt).block = tempbptr = BLOCK_OF((bt).insindex); \
351 MARKREACHED(tempbptr, tempsp); \
354 #define BRANCH(tempbptr, tempsp) \
356 iptr->dst.block = tempbptr = BLOCK_OF(iptr->dst.insindex); \
357 MARKREACHED(tempbptr, tempsp); \
360 #define DUP_SLOT(sp) \
362 if ((sp)->varkind != TEMPVAR) \
363 NEWSTACK((sp)->type, TEMPVAR, stackdepth); \
365 NEWSTACK((sp)->type, (sp)->varkind, (sp)->varnum); \
368 bool new_stack_analyse(jitdata *jd)
370 methodinfo *m; /* method being analyzed */
374 int b_count; /* basic block counter */
375 int b_index; /* basic block index */
377 stackptr curstack; /* current stack top */
380 int opcode; /* opcode of current instruction */
382 int len; /* # of instructions after the current one */
383 bool superblockend; /* if true, no fallthrough to next block */
384 bool repeat; /* if true, outermost loop must run again */
385 bool deadcode; /* true if no live code has been reached */
386 instruction *iptr; /* the current instruction */
387 basicblock *bptr; /* the current basic block */
390 stackptr *last_store_boundary;
391 stackptr last_pei_boundary;
392 stackptr last_dup_boundary;
394 branch_target_t *table;
395 lookup_target_t *lookup;
396 #if defined(ENABLE_VERIFIER)
397 int expectedtype; /* used by CHECK_BASIC_TYPE */
399 builtintable_entry *bte;
401 constant_FMIref *fmiref;
402 #if defined(ENABLE_STATISTICS)
403 int iteration_count; /* number of iterations of analysis */
406 #if defined(STACK_VERBOSE)
407 new_show_method(jd, SHOW_PARSE);
410 /* get required compiler data - initialization */
417 #if defined(ENABLE_LSRA)
421 #if defined(ENABLE_STATISTICS)
425 last_store_boundary = DMNEW(stackptr , cd->maxlocals);
427 /* initialize in-stack of first block */
430 jd->new_basicblocks[0].flags = BBREACHED;
431 jd->new_basicblocks[0].instack = NULL;
432 jd->new_basicblocks[0].invars = NULL;
433 jd->new_basicblocks[0].indepth = 0;
435 /* initialize in-stack of exception handlers */
437 for (i = 0; i < cd->exceptiontablelength; i++) {
438 bptr = BLOCK_OF(cd->exceptiontable[i].handlerpc);
439 bptr->flags = BBREACHED;
440 bptr->type = BBTYPE_EXH;
442 bptr->invars = DMNEW(stackptr, 1);
443 bptr->invars[0] = new;
445 bptr->predecessorcount = CFG_UNKNOWN_PREDECESSORS;
450 /* count predecessors of each block ***************************************/
452 #if CONDITIONAL_LOADCONST
453 /* XXX move this to a separate function */
455 b_count = jd->new_basicblockcount;
456 bptr = jd->new_basicblocks;
457 for (; --b_count >= 0; bptr++) {
458 if (bptr->icount == 0)
461 /* get the last instruction of the block */
463 iptr = bptr->iinstr + (bptr->icount - 1);
466 /* instruction stopping control flow */
477 /* conditional branches */
494 /* XXX add missing conditional branches */
495 bptr[1].predecessorcount++;
498 /* unconditional branch */
500 BLOCK_OF(iptr->dst.insindex)->predecessorcount++;
504 case ICMD_TABLESWITCH:
505 table = iptr->dst.table;
506 BLOCK_OF((table++)->insindex)->predecessorcount++;
507 i = iptr->sx.s23.s3.tablehigh
508 - iptr->sx.s23.s2.tablelow + 1;
510 BLOCK_OF((table++)->insindex)->predecessorcount++;
514 case ICMD_LOOKUPSWITCH:
515 lookup = iptr->dst.lookup;
516 BLOCK_OF(iptr->sx.s23.s3.lookupdefault.insindex)->predecessorcount++;
517 i = iptr->sx.s23.s2.lookupcount;
519 BLOCK_OF((lookup++)->target.insindex)->predecessorcount++;
523 /* default - fall into next block */
525 bptr[1].predecessorcount++;
528 } /* end basic block loop */
530 #endif /* CONDITIONAL_LOADCONST */
532 /* stack analysis loop (until fixpoint reached) **************************/
535 #if defined(ENABLE_STATISTICS)
539 /* initialize loop over basic blocks */
541 b_count = jd->new_basicblockcount;
542 bptr = jd->new_basicblocks;
543 superblockend = true;
548 /* iterate over basic blocks *****************************************/
550 while (--b_count >= 0) {
551 #if defined(STACK_VERBOSE)
552 printf("ANALYZING BLOCK L%03d\n", bptr->nr);
555 if (bptr->flags == BBDELETED) {
556 /* This block has been deleted - do nothing. */
558 else if (superblockend && (bptr->flags < BBREACHED)) {
559 /* This block has not been reached so far, and we */
560 /* don't fall into it, so we'll have to iterate again. */
563 else if (bptr->flags <= BBREACHED) {
565 /* We know that bptr->flags == BBREACHED. */
566 /* This block has been reached before. */
567 stackdepth = bptr->indepth;
569 else if (bptr->flags < BBREACHED) {
570 /* This block is reached for the first time now */
571 /* by falling through from the previous block. */
573 bptr->instack = copy;
574 bptr->invars = DMNEW(stackptr, stackdepth);
575 for (i=stackdepth; i--; copy = copy->prev)
576 bptr->invars[i] = copy;
577 bptr->indepth = stackdepth;
580 /* This block has been reached before. now we are */
581 /* falling into it from the previous block. */
582 /* Check that stack depth is well-defined. */
583 CHECK_STACK_DEPTH(bptr->indepth, stackdepth);
586 /* set up local variables for analyzing this block */
588 curstack = bptr->instack;
590 superblockend = false;
591 bptr->flags = BBFINISHED;
594 b_index = bptr - jd->new_basicblocks;
596 /* reset variables for dependency checking */
598 last_pei_boundary = new;
599 last_dup_boundary = new;
600 for( i = 0; i < cd->maxlocals; i++)
601 last_store_boundary[i] = new;
603 /* XXX store the start of the block's stack representation */
607 /* iterate over ICMDs ****************************************/
610 #if defined(STACK_VERBOSE)
611 new_show_icmd(jd, iptr, false, SHOW_PARSE); printf("\n");
612 for( copy = curstack; copy; copy = copy->prev ) {
613 printf("%d ", copy->type);
618 /* fetch the current opcode */
622 /* automatically replace some ICMDs with builtins */
624 #if defined(USEBUILTINTABLE)
626 bte = builtintable_get_automatic(opcode);
628 if (bte && bte->opcode == opcode) {
629 iptr->opc = ICMD_BUILTIN;
630 iptr->flags.bits = INS_FLAG_NOCHECK;
631 iptr->sx.s23.s3.bte = bte;
632 /* iptr->line is already set */
633 jd->isleafmethod = false;
637 #endif /* defined(USEBUILTINTABLE) */
639 /* main opcode switch *************************************/
652 last_pei_boundary = new;
653 COUNT(count_check_null);
656 CLR_DST; /* XXX live through? */
660 USE_S1_LOCAL(TYPE_ADR);
663 IF_NO_INTRP( rd->locals[iptr->s1.localindex][TYPE_ADR].type = TYPE_ADR; );
664 superblockend = true;
668 COUNT(count_pcmd_return);
671 superblockend = true;
675 /* pop 0 push 1 const */
677 /************************** ICONST OPTIMIZATIONS **************************/
680 COUNT(count_pcmd_load);
684 switch (iptr[1].opc) {
686 iptr->opc = ICMD_IADDCONST;
690 iptr[1].opc = ICMD_NOP;
691 NEW_OP1_1(TYPE_INT, TYPE_INT);
692 COUNT(count_pcmd_op);
696 iptr->opc = ICMD_ISUBCONST;
697 goto icmd_iconst_tail;
698 #if SUPPORT_CONST_MUL
700 iptr->opc = ICMD_IMULCONST;
701 goto icmd_iconst_tail;
702 #else /* SUPPORT_CONST_MUL */
704 if (iptr->sx.val.i == 0x00000002)
706 else if (iptr->sx.val.i == 0x00000004)
708 else if (iptr->sx.val.i == 0x00000008)
710 else if (iptr->sx.val.i == 0x00000010)
712 else if (iptr->sx.val.i == 0x00000020)
714 else if (iptr->sx.val.i == 0x00000040)
716 else if (iptr->sx.val.i == 0x00000080)
718 else if (iptr->sx.val.i == 0x00000100)
720 else if (iptr->sx.val.i == 0x00000200)
722 else if (iptr->sx.val.i == 0x00000400)
724 else if (iptr->sx.val.i == 0x00000800)
726 else if (iptr->sx.val.i == 0x00001000)
728 else if (iptr->sx.val.i == 0x00002000)
730 else if (iptr->sx.val.i == 0x00004000)
732 else if (iptr->sx.val.i == 0x00008000)
734 else if (iptr->sx.val.i == 0x00010000)
736 else if (iptr->sx.val.i == 0x00020000)
738 else if (iptr->sx.val.i == 0x00040000)
740 else if (iptr->sx.val.i == 0x00080000)
742 else if (iptr->sx.val.i == 0x00100000)
744 else if (iptr->sx.val.i == 0x00200000)
746 else if (iptr->sx.val.i == 0x00400000)
748 else if (iptr->sx.val.i == 0x00800000)
750 else if (iptr->sx.val.i == 0x01000000)
752 else if (iptr->sx.val.i == 0x02000000)
754 else if (iptr->sx.val.i == 0x04000000)
756 else if (iptr->sx.val.i == 0x08000000)
758 else if (iptr->sx.val.i == 0x10000000)
760 else if (iptr->sx.val.i == 0x20000000)
762 else if (iptr->sx.val.i == 0x40000000)
764 else if (iptr->sx.val.i == 0x80000000)
769 iptr->opc = ICMD_IMULPOW2;
770 goto icmd_iconst_tail;
771 #endif /* SUPPORT_CONST_MUL */
773 if (iptr->sx.val.i == 0x00000002)
775 else if (iptr->sx.val.i == 0x00000004)
777 else if (iptr->sx.val.i == 0x00000008)
779 else if (iptr->sx.val.i == 0x00000010)
781 else if (iptr->sx.val.i == 0x00000020)
783 else if (iptr->sx.val.i == 0x00000040)
785 else if (iptr->sx.val.i == 0x00000080)
787 else if (iptr->sx.val.i == 0x00000100)
789 else if (iptr->sx.val.i == 0x00000200)
791 else if (iptr->sx.val.i == 0x00000400)
793 else if (iptr->sx.val.i == 0x00000800)
795 else if (iptr->sx.val.i == 0x00001000)
797 else if (iptr->sx.val.i == 0x00002000)
799 else if (iptr->sx.val.i == 0x00004000)
801 else if (iptr->sx.val.i == 0x00008000)
803 else if (iptr->sx.val.i == 0x00010000)
805 else if (iptr->sx.val.i == 0x00020000)
807 else if (iptr->sx.val.i == 0x00040000)
809 else if (iptr->sx.val.i == 0x00080000)
811 else if (iptr->sx.val.i == 0x00100000)
813 else if (iptr->sx.val.i == 0x00200000)
815 else if (iptr->sx.val.i == 0x00400000)
817 else if (iptr->sx.val.i == 0x00800000)
819 else if (iptr->sx.val.i == 0x01000000)
821 else if (iptr->sx.val.i == 0x02000000)
823 else if (iptr->sx.val.i == 0x04000000)
825 else if (iptr->sx.val.i == 0x08000000)
827 else if (iptr->sx.val.i == 0x10000000)
829 else if (iptr->sx.val.i == 0x20000000)
831 else if (iptr->sx.val.i == 0x40000000)
833 else if (iptr->sx.val.i == 0x80000000)
838 iptr->opc = ICMD_IDIVPOW2;
839 goto icmd_iconst_tail;
842 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
843 if ((iptr->sx.val.i == 0x00000002) ||
844 (iptr->sx.val.i == 0x00000004) ||
845 (iptr->sx.val.i == 0x00000008) ||
846 (iptr->sx.val.i == 0x00000010) ||
847 (iptr->sx.val.i == 0x00000020) ||
848 (iptr->sx.val.i == 0x00000040) ||
849 (iptr->sx.val.i == 0x00000080) ||
850 (iptr->sx.val.i == 0x00000100) ||
851 (iptr->sx.val.i == 0x00000200) ||
852 (iptr->sx.val.i == 0x00000400) ||
853 (iptr->sx.val.i == 0x00000800) ||
854 (iptr->sx.val.i == 0x00001000) ||
855 (iptr->sx.val.i == 0x00002000) ||
856 (iptr->sx.val.i == 0x00004000) ||
857 (iptr->sx.val.i == 0x00008000) ||
858 (iptr->sx.val.i == 0x00010000) ||
859 (iptr->sx.val.i == 0x00020000) ||
860 (iptr->sx.val.i == 0x00040000) ||
861 (iptr->sx.val.i == 0x00080000) ||
862 (iptr->sx.val.i == 0x00100000) ||
863 (iptr->sx.val.i == 0x00200000) ||
864 (iptr->sx.val.i == 0x00400000) ||
865 (iptr->sx.val.i == 0x00800000) ||
866 (iptr->sx.val.i == 0x01000000) ||
867 (iptr->sx.val.i == 0x02000000) ||
868 (iptr->sx.val.i == 0x04000000) ||
869 (iptr->sx.val.i == 0x08000000) ||
870 (iptr->sx.val.i == 0x10000000) ||
871 (iptr->sx.val.i == 0x20000000) ||
872 (iptr->sx.val.i == 0x40000000) ||
873 (iptr->sx.val.i == 0x80000000))
875 iptr->opc = ICMD_IREMPOW2;
877 goto icmd_iconst_tail;
880 #if SUPPORT_CONST_LOGICAL
882 iptr->opc = ICMD_IANDCONST;
883 goto icmd_iconst_tail;
886 iptr->opc = ICMD_IORCONST;
887 goto icmd_iconst_tail;
890 iptr->opc = ICMD_IXORCONST;
891 goto icmd_iconst_tail;
893 #endif /* SUPPORT_CONST_LOGICAL */
895 iptr->opc = ICMD_ISHLCONST;
896 goto icmd_iconst_tail;
899 iptr->opc = ICMD_ISHRCONST;
900 goto icmd_iconst_tail;
903 iptr->opc = ICMD_IUSHRCONST;
904 goto icmd_iconst_tail;
905 #if SUPPORT_LONG_SHIFT
907 iptr->opc = ICMD_LSHLCONST;
908 goto icmd_lconst_tail;
911 iptr->opc = ICMD_LSHRCONST;
912 goto icmd_lconst_tail;
915 iptr->opc = ICMD_LUSHRCONST;
916 goto icmd_lconst_tail;
917 #endif /* SUPPORT_LONG_SHIFT */
919 iptr[1].opc = ICMD_IFEQ;
923 /* set the constant for the following icmd */
924 iptr[1].sx.val.i = iptr->sx.val.i;
926 /* this instruction becomes a nop */
927 iptr->opc = ICMD_NOP;
931 iptr[1].opc = ICMD_IFLT;
932 goto icmd_if_icmp_tail;
935 iptr[1].opc = ICMD_IFLE;
936 goto icmd_if_icmp_tail;
939 iptr[1].opc = ICMD_IFNE;
940 goto icmd_if_icmp_tail;
943 iptr[1].opc = ICMD_IFGT;
944 goto icmd_if_icmp_tail;
947 iptr[1].opc = ICMD_IFGE;
948 goto icmd_if_icmp_tail;
950 #if SUPPORT_CONST_STORE
955 IF_INTRP( goto normal_ICONST; )
956 # if SUPPORT_CONST_STORE_ZERO_ONLY
957 if (iptr->sx.val.i != 0)
960 switch (iptr[1].opc) {
962 iptr->opc = ICMD_IASTORECONST;
965 iptr->opc = ICMD_BASTORECONST;
968 iptr->opc = ICMD_CASTORECONST;
971 iptr->opc = ICMD_SASTORECONST;
975 iptr[1].opc = ICMD_NOP;
977 /* copy the constant to s3 */
978 /* XXX constval -> astoreconstval? */
979 iptr->sx.s23.s3.constval = iptr->sx.val.i;
980 NEW_OP2_0(TYPE_ADR, TYPE_INT);
981 COUNT(count_pcmd_op);
986 IF_INTRP( goto normal_ICONST; )
987 # if SUPPORT_CONST_STORE_ZERO_ONLY
988 if (iptr->sx.val.i != 0)
991 /* XXX check field type? */
993 /* copy the constant to s2 */
994 /* XXX constval -> fieldconstval? */
995 iptr->sx.s23.s2.constval = iptr->sx.val.i;
998 /* set the field reference (s3) */
999 if (iptr[1].flags.bits & INS_FLAG_UNRESOLVED) {
1000 iptr->sx.s23.s3.uf = iptr[1].sx.s23.s3.uf;
1001 iptr->flags.bits |= INS_FLAG_UNRESOLVED;
1004 iptr->sx.s23.s3.fmiref = iptr[1].sx.s23.s3.fmiref;
1007 switch (iptr[1].opc) {
1008 case ICMD_PUTSTATIC:
1009 iptr->opc = ICMD_PUTSTATICCONST;
1013 iptr->opc = ICMD_PUTFIELDCONST;
1014 NEW_OP1_0(TYPE_ADR);
1018 iptr[1].opc = ICMD_NOP;
1019 COUNT(count_pcmd_op);
1021 #endif /* SUPPORT_CONST_STORE */
1027 /* if we get here, the ICONST has been optimized */
1031 /* normal case of an unoptimized ICONST */
1032 NEW_OP0_1(TYPE_INT);
1035 /************************** LCONST OPTIMIZATIONS **************************/
1038 COUNT(count_pcmd_load);
1042 /* switch depending on the following instruction */
1044 switch (iptr[1].opc) {
1045 #if SUPPORT_LONG_ADD
1047 iptr->opc = ICMD_LADDCONST;
1051 /* instruction of type LONG -> LONG */
1052 iptr[1].opc = ICMD_NOP;
1053 NEW_OP1_1(TYPE_LNG, TYPE_LNG);
1054 COUNT(count_pcmd_op);
1058 iptr->opc = ICMD_LSUBCONST;
1059 goto icmd_lconst_tail;
1061 #endif /* SUPPORT_LONG_ADD */
1062 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
1064 iptr->opc = ICMD_LMULCONST;
1065 goto icmd_lconst_tail;
1066 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1067 # if SUPPORT_LONG_SHIFT
1069 if (iptr->sx.val.l == 0x00000002)
1071 else if (iptr->sx.val.l == 0x00000004)
1073 else if (iptr->sx.val.l == 0x00000008)
1075 else if (iptr->sx.val.l == 0x00000010)
1077 else if (iptr->sx.val.l == 0x00000020)
1079 else if (iptr->sx.val.l == 0x00000040)
1081 else if (iptr->sx.val.l == 0x00000080)
1083 else if (iptr->sx.val.l == 0x00000100)
1085 else if (iptr->sx.val.l == 0x00000200)
1087 else if (iptr->sx.val.l == 0x00000400)
1088 iptr->sx.val.i = 10;
1089 else if (iptr->sx.val.l == 0x00000800)
1090 iptr->sx.val.i = 11;
1091 else if (iptr->sx.val.l == 0x00001000)
1092 iptr->sx.val.i = 12;
1093 else if (iptr->sx.val.l == 0x00002000)
1094 iptr->sx.val.i = 13;
1095 else if (iptr->sx.val.l == 0x00004000)
1096 iptr->sx.val.i = 14;
1097 else if (iptr->sx.val.l == 0x00008000)
1098 iptr->sx.val.i = 15;
1099 else if (iptr->sx.val.l == 0x00010000)
1100 iptr->sx.val.i = 16;
1101 else if (iptr->sx.val.l == 0x00020000)
1102 iptr->sx.val.i = 17;
1103 else if (iptr->sx.val.l == 0x00040000)
1104 iptr->sx.val.i = 18;
1105 else if (iptr->sx.val.l == 0x00080000)
1106 iptr->sx.val.i = 19;
1107 else if (iptr->sx.val.l == 0x00100000)
1108 iptr->sx.val.i = 20;
1109 else if (iptr->sx.val.l == 0x00200000)
1110 iptr->sx.val.i = 21;
1111 else if (iptr->sx.val.l == 0x00400000)
1112 iptr->sx.val.i = 22;
1113 else if (iptr->sx.val.l == 0x00800000)
1114 iptr->sx.val.i = 23;
1115 else if (iptr->sx.val.l == 0x01000000)
1116 iptr->sx.val.i = 24;
1117 else if (iptr->sx.val.l == 0x02000000)
1118 iptr->sx.val.i = 25;
1119 else if (iptr->sx.val.l == 0x04000000)
1120 iptr->sx.val.i = 26;
1121 else if (iptr->sx.val.l == 0x08000000)
1122 iptr->sx.val.i = 27;
1123 else if (iptr->sx.val.l == 0x10000000)
1124 iptr->sx.val.i = 28;
1125 else if (iptr->sx.val.l == 0x20000000)
1126 iptr->sx.val.i = 29;
1127 else if (iptr->sx.val.l == 0x40000000)
1128 iptr->sx.val.i = 30;
1129 else if (iptr->sx.val.l == 0x80000000)
1130 iptr->sx.val.i = 31;
1134 iptr->opc = ICMD_LMULPOW2;
1135 goto icmd_lconst_tail;
1136 # endif /* SUPPORT_LONG_SHIFT */
1137 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1138 #if SUPPORT_LONG_DIV_POW2
1140 if (iptr->sx.val.l == 0x00000002)
1142 else if (iptr->sx.val.l == 0x00000004)
1144 else if (iptr->sx.val.l == 0x00000008)
1146 else if (iptr->sx.val.l == 0x00000010)
1148 else if (iptr->sx.val.l == 0x00000020)
1150 else if (iptr->sx.val.l == 0x00000040)
1152 else if (iptr->sx.val.l == 0x00000080)
1154 else if (iptr->sx.val.l == 0x00000100)
1156 else if (iptr->sx.val.l == 0x00000200)
1158 else if (iptr->sx.val.l == 0x00000400)
1159 iptr->sx.val.i = 10;
1160 else if (iptr->sx.val.l == 0x00000800)
1161 iptr->sx.val.i = 11;
1162 else if (iptr->sx.val.l == 0x00001000)
1163 iptr->sx.val.i = 12;
1164 else if (iptr->sx.val.l == 0x00002000)
1165 iptr->sx.val.i = 13;
1166 else if (iptr->sx.val.l == 0x00004000)
1167 iptr->sx.val.i = 14;
1168 else if (iptr->sx.val.l == 0x00008000)
1169 iptr->sx.val.i = 15;
1170 else if (iptr->sx.val.l == 0x00010000)
1171 iptr->sx.val.i = 16;
1172 else if (iptr->sx.val.l == 0x00020000)
1173 iptr->sx.val.i = 17;
1174 else if (iptr->sx.val.l == 0x00040000)
1175 iptr->sx.val.i = 18;
1176 else if (iptr->sx.val.l == 0x00080000)
1177 iptr->sx.val.i = 19;
1178 else if (iptr->sx.val.l == 0x00100000)
1179 iptr->sx.val.i = 20;
1180 else if (iptr->sx.val.l == 0x00200000)
1181 iptr->sx.val.i = 21;
1182 else if (iptr->sx.val.l == 0x00400000)
1183 iptr->sx.val.i = 22;
1184 else if (iptr->sx.val.l == 0x00800000)
1185 iptr->sx.val.i = 23;
1186 else if (iptr->sx.val.l == 0x01000000)
1187 iptr->sx.val.i = 24;
1188 else if (iptr->sx.val.l == 0x02000000)
1189 iptr->sx.val.i = 25;
1190 else if (iptr->sx.val.l == 0x04000000)
1191 iptr->sx.val.i = 26;
1192 else if (iptr->sx.val.l == 0x08000000)
1193 iptr->sx.val.i = 27;
1194 else if (iptr->sx.val.l == 0x10000000)
1195 iptr->sx.val.i = 28;
1196 else if (iptr->sx.val.l == 0x20000000)
1197 iptr->sx.val.i = 29;
1198 else if (iptr->sx.val.l == 0x40000000)
1199 iptr->sx.val.i = 30;
1200 else if (iptr->sx.val.l == 0x80000000)
1201 iptr->sx.val.i = 31;
1205 iptr->opc = ICMD_LDIVPOW2;
1206 goto icmd_lconst_tail;
1207 #endif /* SUPPORT_LONG_DIV_POW2 */
1209 #if SUPPORT_LONG_REM_POW2
1211 if ((iptr->sx.val.l == 0x00000002) ||
1212 (iptr->sx.val.l == 0x00000004) ||
1213 (iptr->sx.val.l == 0x00000008) ||
1214 (iptr->sx.val.l == 0x00000010) ||
1215 (iptr->sx.val.l == 0x00000020) ||
1216 (iptr->sx.val.l == 0x00000040) ||
1217 (iptr->sx.val.l == 0x00000080) ||
1218 (iptr->sx.val.l == 0x00000100) ||
1219 (iptr->sx.val.l == 0x00000200) ||
1220 (iptr->sx.val.l == 0x00000400) ||
1221 (iptr->sx.val.l == 0x00000800) ||
1222 (iptr->sx.val.l == 0x00001000) ||
1223 (iptr->sx.val.l == 0x00002000) ||
1224 (iptr->sx.val.l == 0x00004000) ||
1225 (iptr->sx.val.l == 0x00008000) ||
1226 (iptr->sx.val.l == 0x00010000) ||
1227 (iptr->sx.val.l == 0x00020000) ||
1228 (iptr->sx.val.l == 0x00040000) ||
1229 (iptr->sx.val.l == 0x00080000) ||
1230 (iptr->sx.val.l == 0x00100000) ||
1231 (iptr->sx.val.l == 0x00200000) ||
1232 (iptr->sx.val.l == 0x00400000) ||
1233 (iptr->sx.val.l == 0x00800000) ||
1234 (iptr->sx.val.l == 0x01000000) ||
1235 (iptr->sx.val.l == 0x02000000) ||
1236 (iptr->sx.val.l == 0x04000000) ||
1237 (iptr->sx.val.l == 0x08000000) ||
1238 (iptr->sx.val.l == 0x10000000) ||
1239 (iptr->sx.val.l == 0x20000000) ||
1240 (iptr->sx.val.l == 0x40000000) ||
1241 (iptr->sx.val.l == 0x80000000))
1243 iptr->opc = ICMD_LREMPOW2;
1244 iptr->sx.val.l -= 1;
1245 goto icmd_lconst_tail;
1248 #endif /* SUPPORT_LONG_REM_POW2 */
1250 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
1253 iptr->opc = ICMD_LANDCONST;
1254 goto icmd_lconst_tail;
1257 iptr->opc = ICMD_LORCONST;
1258 goto icmd_lconst_tail;
1261 iptr->opc = ICMD_LXORCONST;
1262 goto icmd_lconst_tail;
1263 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
1265 #if SUPPORT_LONG_CMP_CONST
1267 if ((len <= 1) || (iptr[2].sx.val.i != 0))
1270 /* switch on the instruction after LCONST - LCMP */
1272 switch (iptr[2].opc) {
1274 iptr->opc = ICMD_IF_LEQ;
1277 icmd_lconst_lcmp_tail:
1278 /* convert LCONST, LCMP, IFXX to IF_LXX */
1279 iptr->dst.insindex = iptr[2].dst.insindex;
1280 iptr[1].opc = ICMD_NOP;
1281 iptr[2].opc = ICMD_NOP;
1283 NEW_OP1_BRANCH(TYPE_LNG);
1284 BRANCH(tbptr, copy);
1285 COUNT(count_pcmd_bra);
1286 COUNT(count_pcmd_op);
1290 iptr->opc = ICMD_IF_LNE;
1291 goto icmd_lconst_lcmp_tail;
1294 iptr->opc = ICMD_IF_LLT;
1295 goto icmd_lconst_lcmp_tail;
1298 iptr->opc = ICMD_IF_LGT;
1299 goto icmd_lconst_lcmp_tail;
1302 iptr->opc = ICMD_IF_LLE;
1303 goto icmd_lconst_lcmp_tail;
1306 iptr->opc = ICMD_IF_LGE;
1307 goto icmd_lconst_lcmp_tail;
1311 } /* end switch on opcode after LCONST - LCMP */
1313 #endif /* SUPPORT_LONG_CMP_CONST */
1315 #if SUPPORT_CONST_STORE
1317 IF_INTRP( goto normal_LCONST; )
1318 # if SUPPORT_CONST_STORE_ZERO_ONLY
1319 if (iptr->sx.val.l != 0)
1322 #if SIZEOF_VOID_P == 4
1323 /* the constant must fit into a ptrint */
1324 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1327 /* move the constant to s3 */
1328 iptr->sx.s23.s3.constval = iptr->sx.val.l;
1330 iptr->opc = ICMD_LASTORECONST;
1331 NEW_OP2_0(TYPE_ADR, TYPE_INT);
1333 iptr[1].opc = ICMD_NOP;
1334 COUNT(count_pcmd_op);
1337 case ICMD_PUTSTATIC:
1339 IF_INTRP( goto normal_LCONST; )
1340 # if SUPPORT_CONST_STORE_ZERO_ONLY
1341 if (iptr->sx.val.l != 0)
1344 #if SIZEOF_VOID_P == 4
1345 /* the constant must fit into a ptrint */
1346 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1349 /* XXX check field type? */
1351 /* copy the constant to s2 */
1352 /* XXX constval -> fieldconstval? */
1353 iptr->sx.s23.s2.constval = iptr->sx.val.l;
1357 #endif /* SUPPORT_CONST_STORE */
1361 } /* end switch opcode after LCONST */
1363 /* if we get here, the LCONST has been optimized */
1367 /* the normal case of an unoptimized LCONST */
1368 NEW_OP0_1(TYPE_LNG);
1371 /************************ END OF LCONST OPTIMIZATIONS *********************/
1374 COUNT(count_pcmd_load);
1375 NEW_OP0_1(TYPE_FLT);
1379 COUNT(count_pcmd_load);
1380 NEW_OP0_1(TYPE_DBL);
1383 /************************** ACONST OPTIMIZATIONS **************************/
1386 last_pei_boundary = new;
1387 COUNT(count_pcmd_load);
1388 #if SUPPORT_CONST_STORE
1389 IF_INTRP( goto normal_ACONST; )
1391 /* We can only optimize if the ACONST is resolved
1392 * and there is an instruction after it. */
1394 if ((len == 0) || (iptr->flags.bits & INS_FLAG_UNRESOLVED))
1397 switch (iptr[1].opc) {
1399 /* We can only optimize for NULL values
1400 * here because otherwise a checkcast is
1402 if (iptr->sx.val.anyptr != NULL)
1405 /* copy the constant (NULL) to s3 */
1406 iptr->sx.s23.s3.constval = 0;
1407 iptr->opc = ICMD_AASTORECONST;
1408 NEW_OP2_0(TYPE_ADR, TYPE_INT);
1410 iptr[1].opc = ICMD_NOP;
1411 COUNT(count_pcmd_op);
1414 case ICMD_PUTSTATIC:
1416 # if SUPPORT_CONST_STORE_ZERO_ONLY
1417 if (iptr->sx.val.anyptr != NULL)
1420 /* XXX check field type? */
1421 /* copy the constant to s2 */
1422 /* XXX constval -> fieldconstval? */
1423 iptr->sx.s23.s2.constval = (ptrint) iptr->sx.val.anyptr;
1431 /* if we get here the ACONST has been optimized */
1435 #endif /* SUPPORT_CONST_STORE */
1436 NEW_OP0_1(TYPE_ADR);
1440 /* pop 0 push 1 load */
1447 COUNT(count_load_instruction);
1448 i = opcode - ICMD_ILOAD;
1451 /* iptr->s1.localindex = jd->local_map[iptr->s1.localindex * 5 + i]; */
1453 IF_NO_INTRP( rd->locals[iptr->s1.localindex][i].type = i; )
1454 NEW_LOAD(i, iptr->s1.localindex);
1463 last_pei_boundary = new;
1464 COUNT(count_check_null);
1465 COUNT(count_check_bound);
1466 COUNT(count_pcmd_mem);
1467 NEW_OP2_1(TYPE_ADR, TYPE_INT, opcode - ICMD_IALOAD);
1474 last_pei_boundary = new;
1475 COUNT(count_check_null);
1476 COUNT(count_check_bound);
1477 COUNT(count_pcmd_mem);
1478 NEW_OP2_1(TYPE_ADR, TYPE_INT, TYPE_INT);
1481 /* pop 0 push 0 iinc */
1484 STATISTICS_STACKDEPTH_DISTRIBUTION(count_store_depth);
1487 /* iptr->s1.localindex = jd->local_map[iptr->s1.localindex * 5 + i]; */
1489 last_store_boundary[iptr->s1.localindex] = new;
1494 if ((copy->varkind == LOCALVAR) &&
1495 (copy->varnum == iptr->s1.localindex))
1497 copy->varkind = TEMPVAR;
1504 iptr->dst.localindex = iptr->s1.localindex;
1507 /* pop 1 push 0 store */
1516 i = opcode - ICMD_ISTORE; /* type */
1517 j = iptr->dst.localindex; /* index */
1520 /* iptr->dst.localindex = jd->local_map[iptr->dst.localindex * 5 + i]; */
1522 IF_NO_INTRP( rd->locals[j][i].type = i; )
1524 #if defined(ENABLE_STATISTICS)
1529 count_store_length[20]++;
1531 count_store_length[i]++;
1534 count_store_depth[10]++;
1536 count_store_depth[i]++;
1539 /* check for conflicts as described in Figure 5.2 */
1541 copy = curstack->prev;
1544 if ((copy->varkind == LOCALVAR) &&
1545 (copy->varnum == j))
1547 copy->varkind = TEMPVAR;
1554 /* if the variable is already coalesced, don't bother */
1556 if (curstack->varkind == STACKVAR
1557 || (curstack->varkind == LOCALVAR && curstack->varnum != j))
1560 /* there is no STORE Lj while curstack is live */
1562 if (curstack < last_store_boundary[j])
1563 goto assume_conflict;
1565 /* there is no PEI while curstack is live */
1567 if (curstack < last_pei_boundary)
1568 goto assume_conflict;
1570 /* there is no non-consuming USE while curstack is live */
1572 if (curstack < last_dup_boundary)
1573 goto assume_conflict;
1575 /* there is no DEF LOCALVAR(j) while curstack is live */
1577 copy = new; /* most recent stackslot created + 1 */
1578 while (--copy > curstack) {
1579 if (copy->varkind == LOCALVAR && copy->varnum == j)
1580 goto assume_conflict;
1583 /* coalesce the temporary variable with Lj */
1585 curstack->varkind = LOCALVAR;
1586 curstack->varnum = j;
1589 /* revert the coalescing, if it has been done earlier */
1591 if ((curstack->varkind == LOCALVAR)
1592 && (curstack->varnum == j))
1594 curstack->varkind = TEMPVAR;
1595 curstack->varnum = stackdepth-1;
1598 /* remember the stack boundary at this store */
1600 last_store_boundary[j] = new;
1602 NEW_STORE(opcode - ICMD_ISTORE, j);
1608 last_pei_boundary = new;
1609 COUNT(count_check_null);
1610 COUNT(count_check_bound);
1611 COUNT(count_pcmd_mem);
1613 bte = builtintable_get_internal(BUILTIN_canstore);
1616 if (md->memuse > rd->memuse)
1617 rd->memuse = md->memuse;
1618 if (md->argintreguse > rd->argintreguse)
1619 rd->argintreguse = md->argintreguse;
1620 /* XXX non-leaf method? */
1622 /* make all stack variables saved */
1626 copy->flags |= SAVEDVAR;
1630 NEW_OP3_0(TYPE_ADR, TYPE_INT, TYPE_ADR);
1637 last_pei_boundary = new;
1638 COUNT(count_check_null);
1639 COUNT(count_check_bound);
1640 COUNT(count_pcmd_mem);
1641 NEW_OP3_0(TYPE_ADR, TYPE_INT, opcode - ICMD_IASTORE);
1648 last_pei_boundary = new;
1649 COUNT(count_check_null);
1650 COUNT(count_check_bound);
1651 COUNT(count_pcmd_mem);
1652 NEW_OP3_0(TYPE_ADR, TYPE_INT, TYPE_INT);
1658 #ifdef ENABLE_VERIFIER
1661 if (IS_2_WORD_TYPE(curstack->type))
1662 goto throw_stack_category_error;
1673 last_pei_boundary = new;
1674 IF_JIT( md_return_alloc(jd, curstack); )
1675 COUNT(count_pcmd_return);
1676 NEW_OP1_0(opcode - ICMD_IRETURN);
1677 superblockend = true;
1681 last_pei_boundary = new;
1682 COUNT(count_check_null);
1683 NEW_OP1_0(TYPE_ADR);
1685 superblockend = true;
1688 case ICMD_PUTSTATIC:
1689 last_pei_boundary = new;
1690 COUNT(count_pcmd_mem);
1691 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1692 NEW_OP1_0(fmiref->parseddesc.fd->type);
1695 /* pop 1 push 0 branch */
1698 case ICMD_IFNONNULL:
1699 COUNT(count_pcmd_bra);
1700 NEW_OP1_BRANCH(TYPE_ADR);
1701 BRANCH(tbptr, copy);
1710 COUNT(count_pcmd_bra);
1711 /* iptr->sx.val.i is set implicitly in parse by
1712 clearing the memory or from IF_ICMPxx
1715 NEW_OP1_BRANCH(TYPE_INT);
1716 /* iptr->sx.val.i = 0; */
1717 BRANCH(tbptr, copy);
1720 /* pop 0 push 0 branch */
1723 COUNT(count_pcmd_bra);
1725 BRANCH(tbptr, copy);
1726 superblockend = true;
1729 /* pop 1 push 0 table branch */
1731 case ICMD_TABLESWITCH:
1732 COUNT(count_pcmd_table);
1733 NEW_OP1_BRANCH(TYPE_INT);
1735 table = iptr->dst.table;
1736 BRANCH_TARGET(*table, tbptr, copy);
1739 i = iptr->sx.s23.s3.tablehigh
1740 - iptr->sx.s23.s2.tablelow + 1;
1743 BRANCH_TARGET(*table, tbptr, copy);
1746 superblockend = true;
1749 /* pop 1 push 0 table branch */
1751 case ICMD_LOOKUPSWITCH:
1752 COUNT(count_pcmd_table);
1753 NEW_OP1_BRANCH(TYPE_INT);
1755 BRANCH_TARGET(iptr->sx.s23.s3.lookupdefault, tbptr, copy);
1757 lookup = iptr->dst.lookup;
1759 i = iptr->sx.s23.s2.lookupcount;
1762 BRANCH_TARGET(lookup->target, tbptr, copy);
1765 superblockend = true;
1768 case ICMD_MONITORENTER:
1769 case ICMD_MONITOREXIT:
1770 last_pei_boundary = new;
1771 COUNT(count_check_null);
1772 NEW_OP1_0(TYPE_ADR);
1775 /* pop 2 push 0 branch */
1777 case ICMD_IF_ICMPEQ:
1778 case ICMD_IF_ICMPNE:
1779 case ICMD_IF_ICMPLT:
1780 case ICMD_IF_ICMPGE:
1781 case ICMD_IF_ICMPGT:
1782 case ICMD_IF_ICMPLE:
1783 COUNT(count_pcmd_bra);
1784 NEW_OP2_BRANCH(TYPE_INT, TYPE_INT);
1785 BRANCH(tbptr, copy);
1788 case ICMD_IF_ACMPEQ:
1789 case ICMD_IF_ACMPNE:
1790 COUNT(count_pcmd_bra);
1791 NEW_OP2_BRANCH(TYPE_ADR, TYPE_ADR);
1792 BRANCH(tbptr, copy);
1798 last_pei_boundary = new;
1799 COUNT(count_check_null);
1800 COUNT(count_pcmd_mem);
1801 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1802 NEW_OP2_0(TYPE_ADR, fmiref->parseddesc.fd->type);
1807 if (!IS_2_WORD_TYPE(curstack->type)) {
1809 #ifdef ENABLE_VERIFIER
1812 if (IS_2_WORD_TYPE(curstack->prev->type))
1813 goto throw_stack_category_error;
1816 NEW_OP2_0_ANY_ANY; /* pop two slots */
1819 iptr->opc = ICMD_POP;
1820 NEW_OP1_0_ANY; /* pop one (two-word) slot */
1824 /* pop 0 push 1 dup */
1827 #ifdef ENABLE_VERIFIER
1830 if (IS_2_WORD_TYPE(curstack->type))
1831 goto throw_stack_category_error;
1834 COUNT(count_dup_instruction);
1837 USE_S1_ANY; /* XXX live through */
1838 DUP_SLOT(iptr->s1.var);
1839 last_dup_boundary = new - 1;
1840 iptr->dst.var = curstack;
1846 if (IS_2_WORD_TYPE(curstack->type)) {
1848 iptr->opc = ICMD_DUP;
1853 /* ..., ????, cat1 */
1854 #ifdef ENABLE_VERIFIER
1856 if (IS_2_WORD_TYPE(curstack->prev->type))
1857 goto throw_stack_category_error;
1860 iptr->dst.dupslots = DMNEW(stackptr, 2 + 2);
1861 iptr->dst.dupslots[0] = curstack->prev; /* XXX live through */
1862 iptr->dst.dupslots[1] = curstack; /* XXX live through */
1864 DUP_SLOT(iptr->dst.dupslots[0]);
1865 iptr->dst.dupslots[2+0] = curstack;
1866 DUP_SLOT(iptr->dst.dupslots[1]);
1867 iptr->dst.dupslots[2+1] = curstack;
1868 last_dup_boundary = new;
1873 /* pop 2 push 3 dup */
1876 #ifdef ENABLE_VERIFIER
1879 if (IS_2_WORD_TYPE(curstack->type) ||
1880 IS_2_WORD_TYPE(curstack->prev->type))
1881 goto throw_stack_category_error;
1886 iptr->dst.dupslots = DMNEW(stackptr, 2 + 3);
1887 iptr->dst.dupslots[0] = curstack->prev;
1888 iptr->dst.dupslots[1] = curstack;
1891 DUP_SLOT(iptr->dst.dupslots[1]);
1892 iptr->dst.dupslots[2+0] = curstack;
1893 DUP_SLOT(iptr->dst.dupslots[0]);
1894 iptr->dst.dupslots[2+1] = curstack;
1895 DUP_SLOT(iptr->dst.dupslots[1]);
1896 iptr->dst.dupslots[2+2] = curstack;
1897 last_dup_boundary = new;
1903 if (IS_2_WORD_TYPE(curstack->type)) {
1904 /* ..., ????, cat2 */
1905 #ifdef ENABLE_VERIFIER
1907 if (IS_2_WORD_TYPE(curstack->prev->type))
1908 goto throw_stack_category_error;
1911 iptr->opc = ICMD_DUP_X1;
1915 /* ..., ????, cat1 */
1916 #ifdef ENABLE_VERIFIER
1919 if (IS_2_WORD_TYPE(curstack->prev->type)
1920 || IS_2_WORD_TYPE(curstack->prev->prev->type))
1921 goto throw_stack_category_error;
1926 iptr->dst.dupslots = DMNEW(stackptr, 3 + 5);
1927 iptr->dst.dupslots[0] = curstack->prev->prev;
1928 iptr->dst.dupslots[1] = curstack->prev;
1929 iptr->dst.dupslots[2] = curstack;
1930 POPANY; POPANY; POPANY;
1932 DUP_SLOT(iptr->dst.dupslots[1]);
1933 iptr->dst.dupslots[3+0] = curstack;
1934 DUP_SLOT(iptr->dst.dupslots[2]);
1935 iptr->dst.dupslots[3+1] = curstack;
1936 DUP_SLOT(iptr->dst.dupslots[0]);
1937 iptr->dst.dupslots[3+2] = curstack;
1938 DUP_SLOT(iptr->dst.dupslots[1]);
1939 iptr->dst.dupslots[3+3] = curstack;
1940 DUP_SLOT(iptr->dst.dupslots[2]);
1941 iptr->dst.dupslots[3+4] = curstack;
1942 last_dup_boundary = new;
1947 /* pop 3 push 4 dup */
1951 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1952 /* ..., cat2, ???? */
1953 #ifdef ENABLE_VERIFIER
1955 if (IS_2_WORD_TYPE(curstack->type))
1956 goto throw_stack_category_error;
1959 iptr->opc = ICMD_DUP_X1;
1963 /* ..., cat1, ???? */
1964 #ifdef ENABLE_VERIFIER
1967 if (IS_2_WORD_TYPE(curstack->type)
1968 || IS_2_WORD_TYPE(curstack->prev->prev->type))
1969 goto throw_stack_category_error;
1973 iptr->dst.dupslots = DMNEW(stackptr, 3 + 4);
1974 iptr->dst.dupslots[0] = curstack->prev->prev;
1975 iptr->dst.dupslots[1] = curstack->prev;
1976 iptr->dst.dupslots[2] = curstack;
1977 POPANY; POPANY; POPANY;
1979 DUP_SLOT(iptr->dst.dupslots[2]);
1980 iptr->dst.dupslots[3+0] = curstack;
1981 DUP_SLOT(iptr->dst.dupslots[0]);
1982 iptr->dst.dupslots[3+1] = curstack;
1983 DUP_SLOT(iptr->dst.dupslots[1]);
1984 iptr->dst.dupslots[3+2] = curstack;
1985 DUP_SLOT(iptr->dst.dupslots[2]);
1986 iptr->dst.dupslots[3+3] = curstack;
1987 last_dup_boundary = new;
1994 if (IS_2_WORD_TYPE(curstack->type)) {
1995 /* ..., ????, cat2 */
1996 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1997 /* ..., cat2, cat2 */
1998 iptr->opc = ICMD_DUP_X1;
2002 /* ..., cat1, cat2 */
2003 #ifdef ENABLE_VERIFIER
2006 if (IS_2_WORD_TYPE(curstack->prev->prev->type))
2007 goto throw_stack_category_error;
2010 iptr->opc = ICMD_DUP_X2;
2016 /* ..., ????, ????, cat1 */
2018 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
2019 /* ..., cat2, ????, cat1 */
2020 #ifdef ENABLE_VERIFIER
2022 if (IS_2_WORD_TYPE(curstack->prev->type))
2023 goto throw_stack_category_error;
2026 iptr->opc = ICMD_DUP2_X1;
2030 /* ..., cat1, ????, cat1 */
2031 #ifdef ENABLE_VERIFIER
2034 if (IS_2_WORD_TYPE(curstack->prev->type)
2035 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
2036 goto throw_stack_category_error;
2039 iptr->dst.dupslots = DMNEW(stackptr, 4 + 6);
2040 iptr->dst.dupslots[0] = curstack->prev->prev->prev;
2041 iptr->dst.dupslots[1] = curstack->prev->prev;
2042 iptr->dst.dupslots[2] = curstack->prev;
2043 iptr->dst.dupslots[3] = curstack;
2044 POPANY; POPANY; POPANY; POPANY;
2046 DUP_SLOT(iptr->dst.dupslots[2]);
2047 iptr->dst.dupslots[4+0] = curstack;
2048 DUP_SLOT(iptr->dst.dupslots[3]);
2049 iptr->dst.dupslots[4+1] = curstack;
2050 DUP_SLOT(iptr->dst.dupslots[0]);
2051 iptr->dst.dupslots[4+2] = curstack;
2052 DUP_SLOT(iptr->dst.dupslots[1]);
2053 iptr->dst.dupslots[4+3] = curstack;
2054 DUP_SLOT(iptr->dst.dupslots[2]);
2055 iptr->dst.dupslots[4+4] = curstack;
2056 DUP_SLOT(iptr->dst.dupslots[3]);
2057 iptr->dst.dupslots[4+5] = curstack;
2058 last_dup_boundary = new;
2063 /* pop 2 push 2 swap */
2066 #ifdef ENABLE_VERIFIER
2069 if (IS_2_WORD_TYPE(curstack->type)
2070 || IS_2_WORD_TYPE(curstack->prev->type))
2071 goto throw_stack_category_error;
2074 iptr->dst.dupslots = DMNEW(stackptr, 2 + 2);
2075 iptr->dst.dupslots[0] = curstack->prev;
2076 iptr->dst.dupslots[1] = curstack;
2079 DUP_SLOT(iptr->dst.dupslots[1]);
2080 iptr->dst.dupslots[2+0] = curstack;
2081 DUP_SLOT(iptr->dst.dupslots[0]);
2082 iptr->dst.dupslots[2+1] = curstack;
2083 last_dup_boundary = new;
2090 last_pei_boundary = new;
2091 #if !SUPPORT_DIVISION
2092 bte = iptr->sx.s23.s3.bte;
2095 if (md->memuse > rd->memuse)
2096 rd->memuse = md->memuse;
2097 if (md->argintreguse > rd->argintreguse)
2098 rd->argintreguse = md->argintreguse;
2100 /* make all stack variables saved */
2104 copy->flags |= SAVEDVAR;
2109 #endif /* !SUPPORT_DIVISION */
2120 COUNT(count_pcmd_op);
2121 NEW_OP2_1(TYPE_INT, TYPE_INT, TYPE_INT);
2126 last_pei_boundary = new;
2127 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
2128 bte = iptr->sx.s23.s3.bte;
2131 if (md->memuse > rd->memuse)
2132 rd->memuse = md->memuse;
2133 if (md->argintreguse > rd->argintreguse)
2134 rd->argintreguse = md->argintreguse;
2135 /* XXX non-leaf method? */
2137 /* make all stack variables saved */
2141 copy->flags |= SAVEDVAR;
2146 #endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
2151 #if SUPPORT_LONG_LOGICAL
2155 #endif /* SUPPORT_LONG_LOGICAL */
2156 COUNT(count_pcmd_op);
2157 NEW_OP2_1(TYPE_LNG, TYPE_LNG, TYPE_LNG);
2163 COUNT(count_pcmd_op);
2164 NEW_OP2_1(TYPE_LNG, TYPE_INT, TYPE_LNG);
2172 COUNT(count_pcmd_op);
2173 NEW_OP2_1(TYPE_FLT, TYPE_FLT, TYPE_FLT);
2181 COUNT(count_pcmd_op);
2182 NEW_OP2_1(TYPE_DBL, TYPE_DBL, TYPE_DBL);
2186 COUNT(count_pcmd_op);
2187 #if SUPPORT_LONG_CMP_CONST
2188 if ((len == 0) || (iptr[1].sx.val.i != 0))
2191 switch (iptr[1].opc) {
2193 iptr->opc = ICMD_IF_LCMPEQ;
2195 iptr->dst.insindex = iptr[1].dst.insindex;
2196 iptr[1].opc = ICMD_NOP;
2198 NEW_OP2_BRANCH(TYPE_LNG, TYPE_LNG);
2199 BRANCH(tbptr, copy);
2201 COUNT(count_pcmd_bra);
2204 iptr->opc = ICMD_IF_LCMPNE;
2205 goto icmd_lcmp_if_tail;
2207 iptr->opc = ICMD_IF_LCMPLT;
2208 goto icmd_lcmp_if_tail;
2210 iptr->opc = ICMD_IF_LCMPGT;
2211 goto icmd_lcmp_if_tail;
2213 iptr->opc = ICMD_IF_LCMPLE;
2214 goto icmd_lcmp_if_tail;
2216 iptr->opc = ICMD_IF_LCMPGE;
2217 goto icmd_lcmp_if_tail;
2223 #endif /* SUPPORT_LONG_CMP_CONST */
2224 NEW_OP2_1(TYPE_LNG, TYPE_LNG, TYPE_INT);
2227 /* XXX why is this deactivated? */
2230 COUNT(count_pcmd_op);
2231 if ((len == 0) || (iptr[1].sx.val.i != 0))
2234 switch (iptr[1].opc) {
2236 iptr->opc = ICMD_IF_FCMPEQ;
2238 iptr->dst.insindex = iptr[1].dst.insindex;
2239 iptr[1].opc = ICMD_NOP;
2241 NEW_OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2242 BRANCH(tbptr, copy);
2244 COUNT(count_pcmd_bra);
2247 iptr->opc = ICMD_IF_FCMPNE;
2248 goto icmd_if_fcmpl_tail;
2250 iptr->opc = ICMD_IF_FCMPL_LT;
2251 goto icmd_if_fcmpl_tail;
2253 iptr->opc = ICMD_IF_FCMPL_GT;
2254 goto icmd_if_fcmpl_tail;
2256 iptr->opc = ICMD_IF_FCMPL_LE;
2257 goto icmd_if_fcmpl_tail;
2259 iptr->opc = ICMD_IF_FCMPL_GE;
2260 goto icmd_if_fcmpl_tail;
2267 OPTT2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2271 COUNT(count_pcmd_op);
2272 if ((len == 0) || (iptr[1].sx.val.i != 0))
2275 switch (iptr[1].opc) {
2277 iptr->opc = ICMD_IF_FCMPEQ;
2279 iptr->dst.insindex = iptr[1].dst.insindex;
2280 iptr[1].opc = ICMD_NOP;
2282 NEW_OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2283 BRANCH(tbptr, copy);
2285 COUNT(count_pcmd_bra);
2288 iptr->opc = ICMD_IF_FCMPNE;
2289 goto icmd_if_fcmpg_tail;
2291 iptr->opc = ICMD_IF_FCMPG_LT;
2292 goto icmd_if_fcmpg_tail;
2294 iptr->opc = ICMD_IF_FCMPG_GT;
2295 goto icmd_if_fcmpg_tail;
2297 iptr->opc = ICMD_IF_FCMPG_LE;
2298 goto icmd_if_fcmpg_tail;
2300 iptr->opc = ICMD_IF_FCMPG_GE;
2301 goto icmd_if_fcmpg_tail;
2308 NEW_OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2312 COUNT(count_pcmd_op);
2313 if ((len == 0) || (iptr[1].sx.val.i != 0))
2316 switch (iptr[1].opc) {
2318 iptr->opc = ICMD_IF_DCMPEQ;
2320 iptr->dst.insindex = iptr[1].dst.insindex;
2321 iptr[1].opc = ICMD_NOP;
2323 NEW_OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2324 BRANCH(tbptr, copy);
2326 COUNT(count_pcmd_bra);
2329 iptr->opc = ICMD_IF_DCMPNE;
2330 goto icmd_if_dcmpl_tail;
2332 iptr->opc = ICMD_IF_DCMPL_LT;
2333 goto icmd_if_dcmpl_tail;
2335 iptr->opc = ICMD_IF_DCMPL_GT;
2336 goto icmd_if_dcmpl_tail;
2338 iptr->opc = ICMD_IF_DCMPL_LE;
2339 goto icmd_if_dcmpl_tail;
2341 iptr->opc = ICMD_IF_DCMPL_GE;
2342 goto icmd_if_dcmpl_tail;
2349 OPTT2_1(TYPE_DBL, TYPE_INT);
2353 COUNT(count_pcmd_op);
2354 if ((len == 0) || (iptr[1].sx.val.i != 0))
2357 switch (iptr[1].opc) {
2359 iptr->opc = ICMD_IF_DCMPEQ;
2361 iptr->dst.insindex = iptr[1].dst.insindex;
2362 iptr[1].opc = ICMD_NOP;
2364 NEW_OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2365 BRANCH(tbptr, copy);
2367 COUNT(count_pcmd_bra);
2370 iptr->opc = ICMD_IF_DCMPNE;
2371 goto icmd_if_dcmpg_tail;
2373 iptr->opc = ICMD_IF_DCMPG_LT;
2374 goto icmd_if_dcmpg_tail;
2376 iptr->opc = ICMD_IF_DCMPG_GT;
2377 goto icmd_if_dcmpg_tail;
2379 iptr->opc = ICMD_IF_DCMPG_LE;
2380 goto icmd_if_dcmpg_tail;
2382 iptr->opc = ICMD_IF_DCMPG_GE;
2383 goto icmd_if_dcmpg_tail;
2390 NEW_OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2395 COUNT(count_pcmd_op);
2396 NEW_OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2401 COUNT(count_pcmd_op);
2402 NEW_OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2411 case ICMD_INT2SHORT:
2412 COUNT(count_pcmd_op);
2413 NEW_OP1_1(TYPE_INT, TYPE_INT);
2416 COUNT(count_pcmd_op);
2417 NEW_OP1_1(TYPE_LNG, TYPE_LNG);
2420 COUNT(count_pcmd_op);
2421 NEW_OP1_1(TYPE_FLT, TYPE_FLT);
2424 COUNT(count_pcmd_op);
2425 NEW_OP1_1(TYPE_DBL, TYPE_DBL);
2429 COUNT(count_pcmd_op);
2430 NEW_OP1_1(TYPE_INT, TYPE_LNG);
2433 COUNT(count_pcmd_op);
2434 NEW_OP1_1(TYPE_INT, TYPE_FLT);
2437 COUNT(count_pcmd_op);
2438 NEW_OP1_1(TYPE_INT, TYPE_DBL);
2441 COUNT(count_pcmd_op);
2442 NEW_OP1_1(TYPE_LNG, TYPE_INT);
2445 COUNT(count_pcmd_op);
2446 NEW_OP1_1(TYPE_LNG, TYPE_FLT);
2449 COUNT(count_pcmd_op);
2450 NEW_OP1_1(TYPE_LNG, TYPE_DBL);
2453 COUNT(count_pcmd_op);
2454 NEW_OP1_1(TYPE_FLT, TYPE_INT);
2457 COUNT(count_pcmd_op);
2458 NEW_OP1_1(TYPE_FLT, TYPE_LNG);
2461 COUNT(count_pcmd_op);
2462 NEW_OP1_1(TYPE_FLT, TYPE_DBL);
2465 COUNT(count_pcmd_op);
2466 NEW_OP1_1(TYPE_DBL, TYPE_INT);
2469 COUNT(count_pcmd_op);
2470 NEW_OP1_1(TYPE_DBL, TYPE_LNG);
2473 COUNT(count_pcmd_op);
2474 NEW_OP1_1(TYPE_DBL, TYPE_FLT);
2477 case ICMD_CHECKCAST:
2478 last_pei_boundary = new;
2479 if (iptr->flags.bits & INS_FLAG_ARRAY) {
2480 /* array type cast-check */
2482 bte = builtintable_get_internal(BUILTIN_arraycheckcast);
2485 if (md->memuse > rd->memuse)
2486 rd->memuse = md->memuse;
2487 if (md->argintreguse > rd->argintreguse)
2488 rd->argintreguse = md->argintreguse;
2490 /* make all stack variables saved */
2494 copy->flags |= SAVEDVAR;
2498 NEW_OP1_1(TYPE_ADR, TYPE_ADR);
2501 case ICMD_INSTANCEOF:
2502 case ICMD_ARRAYLENGTH:
2503 last_pei_boundary = new;
2504 NEW_OP1_1(TYPE_ADR, TYPE_INT);
2508 case ICMD_ANEWARRAY:
2509 last_pei_boundary = new;
2510 NEW_OP1_1(TYPE_INT, TYPE_ADR);
2514 last_pei_boundary = new;
2515 COUNT(count_check_null);
2516 COUNT(count_pcmd_mem);
2517 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2518 NEW_OP1_1(TYPE_ADR, fmiref->parseddesc.fd->type);
2523 case ICMD_GETSTATIC:
2524 last_pei_boundary = new;
2525 COUNT(count_pcmd_mem);
2526 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2527 NEW_OP0_1(fmiref->parseddesc.fd->type);
2531 last_pei_boundary = new;
2532 NEW_OP0_1(TYPE_ADR);
2536 NEW_OP0_1(TYPE_ADR);
2538 BRANCH_TARGET(iptr->sx.s23.s3.jsrtarget, tbptr, copy);
2540 tbptr->type = BBTYPE_SBR;
2542 /* We need to check for overflow right here because
2543 * the pushed value is poped afterwards */
2546 /* calculate stack after return */
2551 /* pop many push any */
2555 bte = iptr->sx.s23.s3.bte;
2559 case ICMD_INVOKESTATIC:
2560 case ICMD_INVOKESPECIAL:
2561 case ICMD_INVOKEVIRTUAL:
2562 case ICMD_INVOKEINTERFACE:
2563 COUNT(count_pcmd_met);
2565 /* Check for functions to replace with builtin
2568 if (builtintable_replace_function(iptr))
2571 INSTRUCTION_GET_METHODDESC(iptr, md);
2572 /* XXX resurrect this COUNT? */
2573 /* if (lm->flags & ACC_STATIC) */
2574 /* {COUNT(count_check_null);} */
2578 last_pei_boundary = new;
2582 if (md->memuse > rd->memuse)
2583 rd->memuse = md->memuse;
2584 if (md->argintreguse > rd->argintreguse)
2585 rd->argintreguse = md->argintreguse;
2586 if (md->argfltreguse > rd->argfltreguse)
2587 rd->argfltreguse = md->argfltreguse;
2591 /* XXX optimize for <= 2 args */
2592 /* XXX not for ICMD_BUILTIN */
2593 iptr->s1.argcount = stackdepth;
2594 iptr->sx.s23.s2.args = DMNEW(stackptr, stackdepth);
2597 for (i-- ; i >= 0; i--) {
2598 iptr->sx.s23.s2.args[i] = copy;
2600 /* do not change STACKVARs to ARGVAR -> won't help anyway */
2601 if (copy->varkind != STACKVAR) {
2603 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2604 /* If we pass float arguments in integer argument registers, we
2605 * are not allowed to precolor them here. Floats have to be moved
2606 * to this regs explicitly in codegen().
2607 * Only arguments that are passed by stack anyway can be precolored
2608 * (michi 2005/07/24) */
2609 if (!(copy->flags & SAVEDVAR) &&
2610 (!IS_FLT_DBL_TYPE(copy->type) || md->params[i].inmemory)) {
2612 if (!(copy->flags & SAVEDVAR)) {
2614 copy->varkind = ARGVAR;
2617 #if defined(ENABLE_INTRP)
2620 if (md->params[i].inmemory) {
2621 copy->flags = INMEMORY;
2622 copy->regoff = md->params[i].regoff;
2626 if (IS_FLT_DBL_TYPE(copy->type)) {
2627 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2628 assert(0); /* XXX is this assert ok? */
2631 rd->argfltregs[md->params[i].regoff];
2632 #endif /* SUPPORT_PASS_FLOATARGS_IN_INTREGS */
2635 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
2636 if (IS_2_WORD_TYPE(copy->type))
2637 copy->regoff = PACK_REGS(
2638 rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
2639 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
2641 #endif /* SUPPORT_COMBINE_INTEGER_REGISTERS */
2643 rd->argintregs[md->params[i].regoff];
2646 #if defined(ENABLE_INTRP)
2647 } /* end if (!opt_intrp) */
2654 /* deal with live-through stack slots "under" the arguments */
2655 /* XXX not for ICMD_BUILTIN */
2660 iptr->sx.s23.s2.args[i++] = copy;
2661 copy->flags |= SAVEDVAR;
2665 /* pop the arguments */
2674 /* push the return value */
2676 if (md->returntype.type != TYPE_VOID) {
2677 NEW_DST(md->returntype.type, stackdepth);
2682 case ICMD_INLINE_START:
2683 case ICMD_INLINE_END:
2688 case ICMD_MULTIANEWARRAY:
2689 last_pei_boundary = new;
2690 if (rd->argintreguse < 3)
2691 rd->argintreguse = 3;
2693 i = iptr->s1.argcount;
2697 iptr->sx.s23.s2.args = DMNEW(stackptr, i);
2699 #if defined(SPECIALMEMUSE)
2700 # if defined(__DARWIN__)
2701 if (rd->memuse < (i + INT_ARG_CNT + LA_SIZE_IN_POINTERS))
2702 rd->memuse = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2704 if (rd->memuse < (i + LA_SIZE_IN_POINTERS + 3))
2705 rd->memuse = i + LA_SIZE_IN_POINTERS + 3;
2708 # if defined(__I386__)
2709 if (rd->memuse < i + 3)
2710 rd->memuse = i + 3; /* n integer args spilled on stack */
2711 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2712 if (rd->memuse < i + 2)
2713 rd->memuse = i + 2; /* 4*4 bytes callee save space */
2716 rd->memuse = i; /* n integer args spilled on stack */
2717 # endif /* defined(__I386__) */
2721 /* check INT type here? Currently typecheck does this. */
2722 iptr->sx.s23.s2.args[i] = copy;
2723 if (!(copy->flags & SAVEDVAR) && (copy->varkind != STACKVAR)) {
2724 copy->varkind = ARGVAR;
2725 copy->varnum = i + INT_ARG_CNT;
2726 copy->flags |= INMEMORY;
2727 #if defined(SPECIALMEMUSE)
2728 # if defined(__DARWIN__)
2729 copy->regoff = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2731 copy->regoff = i + LA_SIZE_IN_POINTERS + 3;
2734 # if defined(__I386__)
2735 copy->regoff = i + 3;
2736 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2737 copy->regoff = i + 2;
2740 # endif /* defined(__I386__) */
2741 #endif /* defined(SPECIALMEMUSE) */
2746 copy->flags |= SAVEDVAR;
2750 i = iptr->s1.argcount;
2755 NEW_DST(TYPE_ADR, stackdepth);
2761 new_internalerror("Unknown ICMD %d", opcode);
2767 } /* while instructions */
2769 /* set out-stack of block */
2771 bptr->outstack = curstack;
2772 bptr->outdepth = stackdepth;
2773 bptr->outvars = DMNEW(stackptr, stackdepth);
2774 for (i = stackdepth, copy = curstack; i--; copy = copy->prev)
2775 bptr->outvars[i] = copy;
2777 /* stack slots at basic block end become interfaces */
2780 for (copy = curstack; copy; i--, copy = copy->prev) {
2781 if ((copy->varkind == STACKVAR) && (copy->varnum > i)) {
2783 copy->varkind = TEMPVAR;
2785 copy->varkind = STACKVAR;
2789 rd->interfaces[i][copy->type].type = copy->type;
2790 rd->interfaces[i][copy->type].flags |= copy->flags;
2794 /* check if interface slots at basic block begin must be saved */
2797 i = bptr->indepth - 1;
2798 for (copy = bptr->instack; copy; i--, copy = copy->prev) {
2799 rd->interfaces[i][copy->type].type = copy->type;
2800 if (copy->varkind == STACKVAR) {
2801 if (copy->flags & SAVEDVAR)
2802 rd->interfaces[i][copy->type].flags |= SAVEDVAR;
2809 superblockend = true;
2812 } /* while blocks */
2813 } while (repeat && !deadcode);
2815 /* gather statistics *****************************************************/
2817 #if defined(ENABLE_STATISTICS)
2819 if (jd->new_basicblockcount > count_max_basic_blocks)
2820 count_max_basic_blocks = jd->new_basicblockcount;
2821 count_basic_blocks += jd->new_basicblockcount;
2822 if (jd->new_instructioncount > count_max_javainstr)
2823 count_max_javainstr = jd->new_instructioncount;
2824 count_javainstr += jd->new_instructioncount;
2825 if (jd->new_stackcount > count_upper_bound_new_stack)
2826 count_upper_bound_new_stack = jd->new_stackcount;
2827 if ((new - jd->new_stack) > count_max_new_stack)
2828 count_max_new_stack = (new - jd->new_stack);
2830 b_count = jd->new_basicblockcount;
2831 bptr = jd->new_basicblocks;
2832 while (--b_count >= 0) {
2833 if (bptr->flags > BBREACHED) {
2834 if (bptr->indepth >= 10)
2835 count_block_stack[10]++;
2837 count_block_stack[bptr->indepth]++;
2840 count_block_size_distribution[len]++;
2842 count_block_size_distribution[10]++;
2844 count_block_size_distribution[11]++;
2846 count_block_size_distribution[12]++;
2848 count_block_size_distribution[13]++;
2850 count_block_size_distribution[14]++;
2852 count_block_size_distribution[15]++;
2854 count_block_size_distribution[16]++;
2856 count_block_size_distribution[17]++;
2861 if (iteration_count == 1)
2862 count_analyse_iterations[0]++;
2863 else if (iteration_count == 2)
2864 count_analyse_iterations[1]++;
2865 else if (iteration_count == 3)
2866 count_analyse_iterations[2]++;
2867 else if (iteration_count == 4)
2868 count_analyse_iterations[3]++;
2870 count_analyse_iterations[4]++;
2872 if (jd->new_basicblockcount <= 5)
2873 count_method_bb_distribution[0]++;
2874 else if (jd->new_basicblockcount <= 10)
2875 count_method_bb_distribution[1]++;
2876 else if (jd->new_basicblockcount <= 15)
2877 count_method_bb_distribution[2]++;
2878 else if (jd->new_basicblockcount <= 20)
2879 count_method_bb_distribution[3]++;
2880 else if (jd->new_basicblockcount <= 30)
2881 count_method_bb_distribution[4]++;
2882 else if (jd->new_basicblockcount <= 40)
2883 count_method_bb_distribution[5]++;
2884 else if (jd->new_basicblockcount <= 50)
2885 count_method_bb_distribution[6]++;
2886 else if (jd->new_basicblockcount <= 75)
2887 count_method_bb_distribution[7]++;
2889 count_method_bb_distribution[8]++;
2891 #endif /* defined(ENABLE_STATISTICS) */
2893 /* everything's ok *******************************************************/
2897 /* goto labels for throwing verifier exceptions **************************/
2899 #if defined(ENABLE_VERIFIER)
2901 throw_stack_underflow:
2902 exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
2905 throw_stack_overflow:
2906 exceptions_throw_verifyerror(m, "Stack size too large");
2909 throw_stack_depth_error:
2910 exceptions_throw_verifyerror(m,"Stack depth mismatch");
2913 throw_stack_type_error:
2914 exceptions_throw_verifyerror_for_stack(m, expectedtype);
2917 throw_stack_category_error:
2918 exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
2926 * These are local overrides for various environment variables in Emacs.
2927 * Please do not remove this and leave it at the end of the file, where
2928 * Emacs will automagically detect them.
2929 * ---------------------------------------------------------------------
2932 * indent-tabs-mode: t
2936 * vim:noexpandtab:sw=4:ts=4: