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 5332 2006-09-05 19:38:28Z twisti $
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 */
389 s4 *last_store; /* instruction index of last XSTORE */
390 /* [ local_index * 5 + type ] */
391 s4 last_pei; /* ins. index of last possible exception */
392 /* used for conflict resolution for copy */
393 /* elimination (XLOAD, IINC, XSTORE) */
395 branch_target_t *table;
396 lookup_target_t *lookup;
397 #if defined(ENABLE_VERIFIER)
398 int expectedtype; /* used by CHECK_BASIC_TYPE */
400 builtintable_entry *bte;
402 constant_FMIref *fmiref;
403 #if defined(ENABLE_STATISTICS)
404 int iteration_count; /* number of iterations of analysis */
407 #if defined(STACK_VERBOSE)
408 new_show_method(jd, SHOW_PARSE);
411 /* get required compiler data - initialization */
418 #if defined(ENABLE_LSRA)
422 #if defined(ENABLE_STATISTICS)
426 last_store = DMNEW(s4 , cd->maxlocals * 5);
428 /* initialize in-stack of first block */
431 jd->new_basicblocks[0].flags = BBREACHED;
432 jd->new_basicblocks[0].instack = NULL;
433 jd->new_basicblocks[0].invars = NULL;
434 jd->new_basicblocks[0].indepth = 0;
436 /* initialize in-stack of exception handlers */
438 for (i = 0; i < cd->exceptiontablelength; i++) {
439 bptr = BLOCK_OF(cd->exceptiontable[i].handlerpc);
440 bptr->flags = BBREACHED;
441 bptr->type = BBTYPE_EXH;
443 bptr->invars = DMNEW(stackptr, 1);
444 bptr->invars[0] = new;
446 bptr->predecessorcount = CFG_UNKNOWN_PREDECESSORS;
451 /* count predecessors of each block ***************************************/
453 #if CONDITIONAL_LOADCONST
454 /* XXX move this to a separate function */
456 b_count = jd->new_basicblockcount;
457 bptr = jd->new_basicblocks;
458 for (; --b_count >= 0; bptr++) {
459 if (bptr->icount == 0)
462 /* get the last instruction of the block */
464 iptr = bptr->iinstr + (bptr->icount - 1);
467 /* instruction stopping control flow */
478 /* conditional branches */
495 /* XXX add missing conditional branches */
496 bptr[1].predecessorcount++;
499 /* unconditional branch */
501 BLOCK_OF(iptr->dst.insindex)->predecessorcount++;
505 case ICMD_TABLESWITCH:
506 table = iptr->dst.table;
507 BLOCK_OF((table++)->insindex)->predecessorcount++;
508 i = iptr->sx.s23.s3.tablehigh
509 - iptr->sx.s23.s2.tablelow + 1;
511 BLOCK_OF((table++)->insindex)->predecessorcount++;
515 case ICMD_LOOKUPSWITCH:
516 lookup = iptr->dst.lookup;
517 BLOCK_OF(iptr->sx.s23.s3.lookupdefault.insindex)->predecessorcount++;
518 i = iptr->sx.s23.s2.lookupcount;
520 BLOCK_OF((lookup++)->target.insindex)->predecessorcount++;
524 /* default - fall into next block */
526 bptr[1].predecessorcount++;
529 } /* end basic block loop */
531 #endif /* CONDITIONAL_LOADCONST */
533 /* stack analysis loop (until fixpoint reached) **************************/
536 #if defined(ENABLE_STATISTICS)
540 /* initialize loop over basic blocks */
542 b_count = jd->new_basicblockcount;
543 bptr = jd->new_basicblocks;
544 superblockend = true;
549 /* iterate over basic blocks *****************************************/
551 while (--b_count >= 0) {
552 #if defined(STACK_VERBOSE)
553 printf("ANALYZING BLOCK L%03d\n", bptr->nr);
556 if (bptr->flags == BBDELETED) {
557 /* This block has been deleted - do nothing. */
559 else if (superblockend && (bptr->flags < BBREACHED)) {
560 /* This block has not been reached so far, and we */
561 /* don't fall into it, so we'll have to iterate again. */
564 else if (bptr->flags <= BBREACHED) {
566 /* We know that bptr->flags == BBREACHED. */
567 /* This block has been reached before. */
568 stackdepth = bptr->indepth;
570 else if (bptr->flags < BBREACHED) {
571 /* This block is reached for the first time now */
572 /* by falling through from the previous block. */
574 bptr->instack = copy;
575 bptr->invars = DMNEW(stackptr, stackdepth);
576 for (i=stackdepth; i--; copy = copy->prev)
577 bptr->invars[i] = copy;
578 bptr->indepth = stackdepth;
581 /* This block has been reached before. now we are */
582 /* falling into it from the previous block. */
583 /* Check that stack depth is well-defined. */
584 CHECK_STACK_DEPTH(bptr->indepth, stackdepth);
587 /* set up local variables for analyzing this block */
589 curstack = bptr->instack;
591 superblockend = false;
592 bptr->flags = BBFINISHED;
595 b_index = bptr - jd->new_basicblocks;
597 /* reset variables for dependency checking */
601 for( i = 0; i < cd->maxlocals; i++)
602 for( j = 0; j < 5; j++)
603 last_store[5 * i + j] = -1;
605 /* XXX store the start of the block's stack representation */
609 /* iterate over ICMDs ****************************************/
612 #if defined(STACK_VERBOSE)
613 new_show_icmd(jd, iptr, false, SHOW_PARSE); printf("\n");
614 for( copy = curstack; copy; copy = copy->prev ) {
615 printf("%d ", copy->type);
620 /* fetch the current opcode */
624 /* automatically replace some ICMDs with builtins */
626 #if defined(USEBUILTINTABLE)
628 bte = builtintable_get_automatic(opcode);
630 if (bte && bte->opcode == opcode) {
631 iptr->opc = ICMD_BUILTIN;
632 iptr->flags.bits = INS_FLAG_NOCHECK;
633 iptr->sx.s23.s3.bte = bte;
634 /* iptr->line is already set */
635 jd->isleafmethod = false;
639 #endif /* defined(USEBUILTINTABLE) */
641 /* main opcode switch *************************************/
654 COUNT(count_check_null);
657 CLR_DST; /* XXX live through? */
661 USE_S1_LOCAL(TYPE_ADR);
664 IF_NO_INTRP( rd->locals[iptr->s1.localindex][TYPE_ADR].type = TYPE_ADR; );
665 superblockend = true;
669 COUNT(count_pcmd_return);
672 superblockend = true;
676 /* pop 0 push 1 const */
678 /************************** ICONST OPTIMIZATIONS **************************/
681 COUNT(count_pcmd_load);
685 switch (iptr[1].opc) {
687 iptr->opc = ICMD_IADDCONST;
691 iptr[1].opc = ICMD_NOP;
692 NEW_OP1_1(TYPE_INT, TYPE_INT);
693 COUNT(count_pcmd_op);
697 iptr->opc = ICMD_ISUBCONST;
698 goto icmd_iconst_tail;
699 #if SUPPORT_CONST_MUL
701 iptr->opc = ICMD_IMULCONST;
702 goto icmd_iconst_tail;
703 #else /* SUPPORT_CONST_MUL */
705 if (iptr->sx.val.i == 0x00000002)
707 else if (iptr->sx.val.i == 0x00000004)
709 else if (iptr->sx.val.i == 0x00000008)
711 else if (iptr->sx.val.i == 0x00000010)
713 else if (iptr->sx.val.i == 0x00000020)
715 else if (iptr->sx.val.i == 0x00000040)
717 else if (iptr->sx.val.i == 0x00000080)
719 else if (iptr->sx.val.i == 0x00000100)
721 else if (iptr->sx.val.i == 0x00000200)
723 else if (iptr->sx.val.i == 0x00000400)
725 else if (iptr->sx.val.i == 0x00000800)
727 else if (iptr->sx.val.i == 0x00001000)
729 else if (iptr->sx.val.i == 0x00002000)
731 else if (iptr->sx.val.i == 0x00004000)
733 else if (iptr->sx.val.i == 0x00008000)
735 else if (iptr->sx.val.i == 0x00010000)
737 else if (iptr->sx.val.i == 0x00020000)
739 else if (iptr->sx.val.i == 0x00040000)
741 else if (iptr->sx.val.i == 0x00080000)
743 else if (iptr->sx.val.i == 0x00100000)
745 else if (iptr->sx.val.i == 0x00200000)
747 else if (iptr->sx.val.i == 0x00400000)
749 else if (iptr->sx.val.i == 0x00800000)
751 else if (iptr->sx.val.i == 0x01000000)
753 else if (iptr->sx.val.i == 0x02000000)
755 else if (iptr->sx.val.i == 0x04000000)
757 else if (iptr->sx.val.i == 0x08000000)
759 else if (iptr->sx.val.i == 0x10000000)
761 else if (iptr->sx.val.i == 0x20000000)
763 else if (iptr->sx.val.i == 0x40000000)
765 else if (iptr->sx.val.i == 0x80000000)
770 iptr->opc = ICMD_IMULPOW2;
771 goto icmd_iconst_tail;
772 #endif /* SUPPORT_CONST_MUL */
774 if (iptr->sx.val.i == 0x00000002)
776 else if (iptr->sx.val.i == 0x00000004)
778 else if (iptr->sx.val.i == 0x00000008)
780 else if (iptr->sx.val.i == 0x00000010)
782 else if (iptr->sx.val.i == 0x00000020)
784 else if (iptr->sx.val.i == 0x00000040)
786 else if (iptr->sx.val.i == 0x00000080)
788 else if (iptr->sx.val.i == 0x00000100)
790 else if (iptr->sx.val.i == 0x00000200)
792 else if (iptr->sx.val.i == 0x00000400)
794 else if (iptr->sx.val.i == 0x00000800)
796 else if (iptr->sx.val.i == 0x00001000)
798 else if (iptr->sx.val.i == 0x00002000)
800 else if (iptr->sx.val.i == 0x00004000)
802 else if (iptr->sx.val.i == 0x00008000)
804 else if (iptr->sx.val.i == 0x00010000)
806 else if (iptr->sx.val.i == 0x00020000)
808 else if (iptr->sx.val.i == 0x00040000)
810 else if (iptr->sx.val.i == 0x00080000)
812 else if (iptr->sx.val.i == 0x00100000)
814 else if (iptr->sx.val.i == 0x00200000)
816 else if (iptr->sx.val.i == 0x00400000)
818 else if (iptr->sx.val.i == 0x00800000)
820 else if (iptr->sx.val.i == 0x01000000)
822 else if (iptr->sx.val.i == 0x02000000)
824 else if (iptr->sx.val.i == 0x04000000)
826 else if (iptr->sx.val.i == 0x08000000)
828 else if (iptr->sx.val.i == 0x10000000)
830 else if (iptr->sx.val.i == 0x20000000)
832 else if (iptr->sx.val.i == 0x40000000)
834 else if (iptr->sx.val.i == 0x80000000)
839 iptr->opc = ICMD_IDIVPOW2;
840 goto icmd_iconst_tail;
843 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
844 if ((iptr->sx.val.i == 0x00000002) ||
845 (iptr->sx.val.i == 0x00000004) ||
846 (iptr->sx.val.i == 0x00000008) ||
847 (iptr->sx.val.i == 0x00000010) ||
848 (iptr->sx.val.i == 0x00000020) ||
849 (iptr->sx.val.i == 0x00000040) ||
850 (iptr->sx.val.i == 0x00000080) ||
851 (iptr->sx.val.i == 0x00000100) ||
852 (iptr->sx.val.i == 0x00000200) ||
853 (iptr->sx.val.i == 0x00000400) ||
854 (iptr->sx.val.i == 0x00000800) ||
855 (iptr->sx.val.i == 0x00001000) ||
856 (iptr->sx.val.i == 0x00002000) ||
857 (iptr->sx.val.i == 0x00004000) ||
858 (iptr->sx.val.i == 0x00008000) ||
859 (iptr->sx.val.i == 0x00010000) ||
860 (iptr->sx.val.i == 0x00020000) ||
861 (iptr->sx.val.i == 0x00040000) ||
862 (iptr->sx.val.i == 0x00080000) ||
863 (iptr->sx.val.i == 0x00100000) ||
864 (iptr->sx.val.i == 0x00200000) ||
865 (iptr->sx.val.i == 0x00400000) ||
866 (iptr->sx.val.i == 0x00800000) ||
867 (iptr->sx.val.i == 0x01000000) ||
868 (iptr->sx.val.i == 0x02000000) ||
869 (iptr->sx.val.i == 0x04000000) ||
870 (iptr->sx.val.i == 0x08000000) ||
871 (iptr->sx.val.i == 0x10000000) ||
872 (iptr->sx.val.i == 0x20000000) ||
873 (iptr->sx.val.i == 0x40000000) ||
874 (iptr->sx.val.i == 0x80000000))
876 iptr->opc = ICMD_IREMPOW2;
878 goto icmd_iconst_tail;
881 #if SUPPORT_CONST_LOGICAL
883 iptr->opc = ICMD_IANDCONST;
884 goto icmd_iconst_tail;
887 iptr->opc = ICMD_IORCONST;
888 goto icmd_iconst_tail;
891 iptr->opc = ICMD_IXORCONST;
892 goto icmd_iconst_tail;
894 #endif /* SUPPORT_CONST_LOGICAL */
896 iptr->opc = ICMD_ISHLCONST;
897 goto icmd_iconst_tail;
900 iptr->opc = ICMD_ISHRCONST;
901 goto icmd_iconst_tail;
904 iptr->opc = ICMD_IUSHRCONST;
905 goto icmd_iconst_tail;
906 #if SUPPORT_LONG_SHIFT
908 iptr->opc = ICMD_LSHLCONST;
909 goto icmd_lconst_tail;
912 iptr->opc = ICMD_LSHRCONST;
913 goto icmd_lconst_tail;
916 iptr->opc = ICMD_LUSHRCONST;
917 goto icmd_lconst_tail;
918 #endif /* SUPPORT_LONG_SHIFT */
920 iptr[1].opc = ICMD_IFEQ;
924 /* set the constant for the following icmd */
925 iptr[1].sx.val.i = iptr->sx.val.i;
927 /* this instruction becomes a nop */
928 iptr->opc = ICMD_NOP;
932 iptr[1].opc = ICMD_IFLT;
933 goto icmd_if_icmp_tail;
936 iptr[1].opc = ICMD_IFLE;
937 goto icmd_if_icmp_tail;
940 iptr[1].opc = ICMD_IFNE;
941 goto icmd_if_icmp_tail;
944 iptr[1].opc = ICMD_IFGT;
945 goto icmd_if_icmp_tail;
948 iptr[1].opc = ICMD_IFGE;
949 goto icmd_if_icmp_tail;
951 #if SUPPORT_CONST_STORE
956 IF_INTRP( goto normal_ICONST; )
957 # if SUPPORT_CONST_STORE_ZERO_ONLY
958 if (iptr->sx.val.i != 0)
961 switch (iptr[1].opc) {
963 iptr->opc = ICMD_IASTORECONST;
966 iptr->opc = ICMD_BASTORECONST;
969 iptr->opc = ICMD_CASTORECONST;
972 iptr->opc = ICMD_SASTORECONST;
976 iptr[1].opc = ICMD_NOP;
978 /* copy the constant to s3 */
979 /* XXX constval -> astoreconstval? */
980 iptr->sx.s23.s3.constval = iptr->sx.val.i;
981 NEW_OP2_0(TYPE_ADR, TYPE_INT);
982 COUNT(count_pcmd_op);
987 IF_INTRP( goto normal_ICONST; )
988 # if SUPPORT_CONST_STORE_ZERO_ONLY
989 if (iptr->sx.val.i != 0)
992 /* XXX check field type? */
994 /* copy the constant to s2 */
995 /* XXX constval -> fieldconstval? */
996 iptr->sx.s23.s2.constval = iptr->sx.val.i;
999 /* set the field reference (s3) */
1000 if (iptr[1].flags.bits & INS_FLAG_UNRESOLVED) {
1001 iptr->sx.s23.s3.uf = iptr[1].sx.s23.s3.uf;
1002 iptr->flags.bits |= INS_FLAG_UNRESOLVED;
1005 iptr->sx.s23.s3.fmiref = iptr[1].sx.s23.s3.fmiref;
1008 switch (iptr[1].opc) {
1009 case ICMD_PUTSTATIC:
1010 iptr->opc = ICMD_PUTSTATICCONST;
1014 iptr->opc = ICMD_PUTFIELDCONST;
1015 NEW_OP1_0(TYPE_ADR);
1019 iptr[1].opc = ICMD_NOP;
1020 COUNT(count_pcmd_op);
1022 #endif /* SUPPORT_CONST_STORE */
1028 /* if we get here, the ICONST has been optimized */
1032 /* normal case of an unoptimized ICONST */
1033 NEW_OP0_1(TYPE_INT);
1036 /************************** LCONST OPTIMIZATIONS **************************/
1039 COUNT(count_pcmd_load);
1043 /* switch depending on the following instruction */
1045 switch (iptr[1].opc) {
1046 #if SUPPORT_LONG_ADD
1048 iptr->opc = ICMD_LADDCONST;
1052 /* instruction of type LONG -> LONG */
1053 iptr[1].opc = ICMD_NOP;
1054 NEW_OP1_1(TYPE_LNG, TYPE_LNG);
1055 COUNT(count_pcmd_op);
1059 iptr->opc = ICMD_LSUBCONST;
1060 goto icmd_lconst_tail;
1062 #endif /* SUPPORT_LONG_ADD */
1063 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
1065 iptr->opc = ICMD_LMULCONST;
1066 goto icmd_lconst_tail;
1067 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1068 # if SUPPORT_LONG_SHIFT
1070 if (iptr->sx.val.l == 0x00000002)
1072 else if (iptr->sx.val.l == 0x00000004)
1074 else if (iptr->sx.val.l == 0x00000008)
1076 else if (iptr->sx.val.l == 0x00000010)
1078 else if (iptr->sx.val.l == 0x00000020)
1080 else if (iptr->sx.val.l == 0x00000040)
1082 else if (iptr->sx.val.l == 0x00000080)
1084 else if (iptr->sx.val.l == 0x00000100)
1086 else if (iptr->sx.val.l == 0x00000200)
1088 else if (iptr->sx.val.l == 0x00000400)
1089 iptr->sx.val.i = 10;
1090 else if (iptr->sx.val.l == 0x00000800)
1091 iptr->sx.val.i = 11;
1092 else if (iptr->sx.val.l == 0x00001000)
1093 iptr->sx.val.i = 12;
1094 else if (iptr->sx.val.l == 0x00002000)
1095 iptr->sx.val.i = 13;
1096 else if (iptr->sx.val.l == 0x00004000)
1097 iptr->sx.val.i = 14;
1098 else if (iptr->sx.val.l == 0x00008000)
1099 iptr->sx.val.i = 15;
1100 else if (iptr->sx.val.l == 0x00010000)
1101 iptr->sx.val.i = 16;
1102 else if (iptr->sx.val.l == 0x00020000)
1103 iptr->sx.val.i = 17;
1104 else if (iptr->sx.val.l == 0x00040000)
1105 iptr->sx.val.i = 18;
1106 else if (iptr->sx.val.l == 0x00080000)
1107 iptr->sx.val.i = 19;
1108 else if (iptr->sx.val.l == 0x00100000)
1109 iptr->sx.val.i = 20;
1110 else if (iptr->sx.val.l == 0x00200000)
1111 iptr->sx.val.i = 21;
1112 else if (iptr->sx.val.l == 0x00400000)
1113 iptr->sx.val.i = 22;
1114 else if (iptr->sx.val.l == 0x00800000)
1115 iptr->sx.val.i = 23;
1116 else if (iptr->sx.val.l == 0x01000000)
1117 iptr->sx.val.i = 24;
1118 else if (iptr->sx.val.l == 0x02000000)
1119 iptr->sx.val.i = 25;
1120 else if (iptr->sx.val.l == 0x04000000)
1121 iptr->sx.val.i = 26;
1122 else if (iptr->sx.val.l == 0x08000000)
1123 iptr->sx.val.i = 27;
1124 else if (iptr->sx.val.l == 0x10000000)
1125 iptr->sx.val.i = 28;
1126 else if (iptr->sx.val.l == 0x20000000)
1127 iptr->sx.val.i = 29;
1128 else if (iptr->sx.val.l == 0x40000000)
1129 iptr->sx.val.i = 30;
1130 else if (iptr->sx.val.l == 0x80000000)
1131 iptr->sx.val.i = 31;
1135 iptr->opc = ICMD_LMULPOW2;
1136 goto icmd_lconst_tail;
1137 # endif /* SUPPORT_LONG_SHIFT */
1138 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1139 #if SUPPORT_LONG_DIV_POW2
1141 if (iptr->sx.val.l == 0x00000002)
1143 else if (iptr->sx.val.l == 0x00000004)
1145 else if (iptr->sx.val.l == 0x00000008)
1147 else if (iptr->sx.val.l == 0x00000010)
1149 else if (iptr->sx.val.l == 0x00000020)
1151 else if (iptr->sx.val.l == 0x00000040)
1153 else if (iptr->sx.val.l == 0x00000080)
1155 else if (iptr->sx.val.l == 0x00000100)
1157 else if (iptr->sx.val.l == 0x00000200)
1159 else if (iptr->sx.val.l == 0x00000400)
1160 iptr->sx.val.i = 10;
1161 else if (iptr->sx.val.l == 0x00000800)
1162 iptr->sx.val.i = 11;
1163 else if (iptr->sx.val.l == 0x00001000)
1164 iptr->sx.val.i = 12;
1165 else if (iptr->sx.val.l == 0x00002000)
1166 iptr->sx.val.i = 13;
1167 else if (iptr->sx.val.l == 0x00004000)
1168 iptr->sx.val.i = 14;
1169 else if (iptr->sx.val.l == 0x00008000)
1170 iptr->sx.val.i = 15;
1171 else if (iptr->sx.val.l == 0x00010000)
1172 iptr->sx.val.i = 16;
1173 else if (iptr->sx.val.l == 0x00020000)
1174 iptr->sx.val.i = 17;
1175 else if (iptr->sx.val.l == 0x00040000)
1176 iptr->sx.val.i = 18;
1177 else if (iptr->sx.val.l == 0x00080000)
1178 iptr->sx.val.i = 19;
1179 else if (iptr->sx.val.l == 0x00100000)
1180 iptr->sx.val.i = 20;
1181 else if (iptr->sx.val.l == 0x00200000)
1182 iptr->sx.val.i = 21;
1183 else if (iptr->sx.val.l == 0x00400000)
1184 iptr->sx.val.i = 22;
1185 else if (iptr->sx.val.l == 0x00800000)
1186 iptr->sx.val.i = 23;
1187 else if (iptr->sx.val.l == 0x01000000)
1188 iptr->sx.val.i = 24;
1189 else if (iptr->sx.val.l == 0x02000000)
1190 iptr->sx.val.i = 25;
1191 else if (iptr->sx.val.l == 0x04000000)
1192 iptr->sx.val.i = 26;
1193 else if (iptr->sx.val.l == 0x08000000)
1194 iptr->sx.val.i = 27;
1195 else if (iptr->sx.val.l == 0x10000000)
1196 iptr->sx.val.i = 28;
1197 else if (iptr->sx.val.l == 0x20000000)
1198 iptr->sx.val.i = 29;
1199 else if (iptr->sx.val.l == 0x40000000)
1200 iptr->sx.val.i = 30;
1201 else if (iptr->sx.val.l == 0x80000000)
1202 iptr->sx.val.i = 31;
1206 iptr->opc = ICMD_LDIVPOW2;
1207 goto icmd_lconst_tail;
1208 #endif /* SUPPORT_LONG_DIV_POW2 */
1210 #if SUPPORT_LONG_REM_POW2
1212 if ((iptr->sx.val.l == 0x00000002) ||
1213 (iptr->sx.val.l == 0x00000004) ||
1214 (iptr->sx.val.l == 0x00000008) ||
1215 (iptr->sx.val.l == 0x00000010) ||
1216 (iptr->sx.val.l == 0x00000020) ||
1217 (iptr->sx.val.l == 0x00000040) ||
1218 (iptr->sx.val.l == 0x00000080) ||
1219 (iptr->sx.val.l == 0x00000100) ||
1220 (iptr->sx.val.l == 0x00000200) ||
1221 (iptr->sx.val.l == 0x00000400) ||
1222 (iptr->sx.val.l == 0x00000800) ||
1223 (iptr->sx.val.l == 0x00001000) ||
1224 (iptr->sx.val.l == 0x00002000) ||
1225 (iptr->sx.val.l == 0x00004000) ||
1226 (iptr->sx.val.l == 0x00008000) ||
1227 (iptr->sx.val.l == 0x00010000) ||
1228 (iptr->sx.val.l == 0x00020000) ||
1229 (iptr->sx.val.l == 0x00040000) ||
1230 (iptr->sx.val.l == 0x00080000) ||
1231 (iptr->sx.val.l == 0x00100000) ||
1232 (iptr->sx.val.l == 0x00200000) ||
1233 (iptr->sx.val.l == 0x00400000) ||
1234 (iptr->sx.val.l == 0x00800000) ||
1235 (iptr->sx.val.l == 0x01000000) ||
1236 (iptr->sx.val.l == 0x02000000) ||
1237 (iptr->sx.val.l == 0x04000000) ||
1238 (iptr->sx.val.l == 0x08000000) ||
1239 (iptr->sx.val.l == 0x10000000) ||
1240 (iptr->sx.val.l == 0x20000000) ||
1241 (iptr->sx.val.l == 0x40000000) ||
1242 (iptr->sx.val.l == 0x80000000))
1244 iptr->opc = ICMD_LREMPOW2;
1245 iptr->sx.val.l -= 1;
1246 goto icmd_lconst_tail;
1249 #endif /* SUPPORT_LONG_REM_POW2 */
1251 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
1254 iptr->opc = ICMD_LANDCONST;
1255 goto icmd_lconst_tail;
1258 iptr->opc = ICMD_LORCONST;
1259 goto icmd_lconst_tail;
1262 iptr->opc = ICMD_LXORCONST;
1263 goto icmd_lconst_tail;
1264 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
1266 #if SUPPORT_LONG_CMP_CONST
1268 if ((len <= 1) || (iptr[2].sx.val.i != 0))
1271 /* switch on the instruction after LCONST - LCMP */
1273 switch (iptr[2].opc) {
1275 iptr->opc = ICMD_IF_LEQ;
1278 icmd_lconst_lcmp_tail:
1279 /* convert LCONST, LCMP, IFXX to IF_LXX */
1280 iptr->dst.insindex = iptr[2].dst.insindex;
1281 iptr[1].opc = ICMD_NOP;
1282 iptr[2].opc = ICMD_NOP;
1284 NEW_OP1_BRANCH(TYPE_LNG);
1285 BRANCH(tbptr, copy);
1286 COUNT(count_pcmd_bra);
1287 COUNT(count_pcmd_op);
1291 iptr->opc = ICMD_IF_LNE;
1292 goto icmd_lconst_lcmp_tail;
1295 iptr->opc = ICMD_IF_LLT;
1296 goto icmd_lconst_lcmp_tail;
1299 iptr->opc = ICMD_IF_LGT;
1300 goto icmd_lconst_lcmp_tail;
1303 iptr->opc = ICMD_IF_LLE;
1304 goto icmd_lconst_lcmp_tail;
1307 iptr->opc = ICMD_IF_LGE;
1308 goto icmd_lconst_lcmp_tail;
1312 } /* end switch on opcode after LCONST - LCMP */
1314 #endif /* SUPPORT_LONG_CMP_CONST */
1316 #if SUPPORT_CONST_STORE
1318 IF_INTRP( goto normal_LCONST; )
1319 # if SUPPORT_CONST_STORE_ZERO_ONLY
1320 if (iptr->sx.val.l != 0)
1323 #if SIZEOF_VOID_P == 4
1324 /* the constant must fit into a ptrint */
1325 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1328 /* move the constant to s3 */
1329 iptr->sx.s23.s3.constval = iptr->sx.val.l;
1331 iptr->opc = ICMD_LASTORECONST;
1332 NEW_OP2_0(TYPE_ADR, TYPE_INT);
1334 iptr[1].opc = ICMD_NOP;
1335 COUNT(count_pcmd_op);
1338 case ICMD_PUTSTATIC:
1340 IF_INTRP( goto normal_LCONST; )
1341 # if SUPPORT_CONST_STORE_ZERO_ONLY
1342 if (iptr->sx.val.l != 0)
1345 #if SIZEOF_VOID_P == 4
1346 /* the constant must fit into a ptrint */
1347 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1350 /* XXX check field type? */
1352 /* copy the constant to s2 */
1353 /* XXX constval -> fieldconstval? */
1354 iptr->sx.s23.s2.constval = iptr->sx.val.l;
1358 #endif /* SUPPORT_CONST_STORE */
1362 } /* end switch opcode after LCONST */
1364 /* if we get here, the LCONST has been optimized */
1368 /* the normal case of an unoptimized LCONST */
1369 NEW_OP0_1(TYPE_LNG);
1372 /************************ END OF LCONST OPTIMIZATIONS *********************/
1375 COUNT(count_pcmd_load);
1376 NEW_OP0_1(TYPE_FLT);
1380 COUNT(count_pcmd_load);
1381 NEW_OP0_1(TYPE_DBL);
1384 /************************** ACONST OPTIMIZATIONS **************************/
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;
1449 IF_NO_INTRP( rd->locals[iptr->s1.localindex][i].type = i; )
1450 NEW_LOAD(i, iptr->s1.localindex);
1459 COUNT(count_check_null);
1460 COUNT(count_check_bound);
1461 COUNT(count_pcmd_mem);
1462 NEW_OP2_1(TYPE_ADR, TYPE_INT, opcode - ICMD_IALOAD);
1469 COUNT(count_check_null);
1470 COUNT(count_check_bound);
1471 COUNT(count_pcmd_mem);
1472 NEW_OP2_1(TYPE_ADR, TYPE_INT, TYPE_INT);
1475 /* pop 0 push 0 iinc */
1478 STATISTICS_STACKDEPTH_DISTRIBUTION(count_store_depth);
1480 last_store[5 * iptr->s1.localindex + TYPE_INT] = bptr->icount - len - 1;
1485 if ((copy->varkind == LOCALVAR) &&
1486 (copy->varnum == iptr->s1.localindex))
1488 copy->varkind = TEMPVAR;
1495 iptr->dst.localindex = iptr->s1.localindex;
1498 /* pop 1 push 0 store */
1507 i = opcode - ICMD_ISTORE; /* type */
1508 IF_NO_INTRP( rd->locals[iptr->dst.localindex][i].type = i; )
1510 #if defined(ENABLE_STATISTICS)
1515 count_store_length[20]++;
1517 count_store_length[i]++;
1520 count_store_depth[10]++;
1522 count_store_depth[i]++;
1525 /* check for conflicts as described in Figure 5.2 */
1526 copy = curstack->prev;
1529 if ((copy->varkind == LOCALVAR) &&
1530 (copy->varnum == iptr->dst.localindex))
1532 copy->varkind = TEMPVAR;
1539 if ((curstack->varkind == LOCALVAR)
1540 && (curstack->varnum == iptr->dst.localindex))
1542 curstack->varkind = TEMPVAR;
1543 curstack->varnum = stackdepth-1;
1546 last_store[5 * iptr->dst.localindex + (opcode - ICMD_ISTORE)] = bptr->icount - len - 1;
1548 NEW_STORE(opcode - ICMD_ISTORE, iptr->dst.localindex);
1554 COUNT(count_check_null);
1555 COUNT(count_check_bound);
1556 COUNT(count_pcmd_mem);
1558 bte = builtintable_get_internal(BUILTIN_canstore);
1561 if (md->memuse > rd->memuse)
1562 rd->memuse = md->memuse;
1563 if (md->argintreguse > rd->argintreguse)
1564 rd->argintreguse = md->argintreguse;
1565 /* XXX non-leaf method? */
1567 /* make all stack variables saved */
1571 copy->flags |= SAVEDVAR;
1575 NEW_OP3_0(TYPE_ADR, TYPE_INT, TYPE_ADR);
1582 COUNT(count_check_null);
1583 COUNT(count_check_bound);
1584 COUNT(count_pcmd_mem);
1585 NEW_OP3_0(TYPE_ADR, TYPE_INT, opcode - ICMD_IASTORE);
1592 COUNT(count_check_null);
1593 COUNT(count_check_bound);
1594 COUNT(count_pcmd_mem);
1595 NEW_OP3_0(TYPE_ADR, TYPE_INT, TYPE_INT);
1601 #ifdef ENABLE_VERIFIER
1604 if (IS_2_WORD_TYPE(curstack->type))
1605 goto throw_stack_category_error;
1616 IF_JIT( md_return_alloc(jd, curstack); )
1617 COUNT(count_pcmd_return);
1618 NEW_OP1_0(opcode - ICMD_IRETURN);
1619 superblockend = true;
1623 COUNT(count_check_null);
1624 NEW_OP1_0(TYPE_ADR);
1626 superblockend = true;
1629 case ICMD_PUTSTATIC:
1630 COUNT(count_pcmd_mem);
1631 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1632 NEW_OP1_0(fmiref->parseddesc.fd->type);
1635 /* pop 1 push 0 branch */
1638 case ICMD_IFNONNULL:
1639 COUNT(count_pcmd_bra);
1640 NEW_OP1_BRANCH(TYPE_ADR);
1641 BRANCH(tbptr, copy);
1650 COUNT(count_pcmd_bra);
1651 /* iptr->sx.val.i is set implicitly in parse by
1652 clearing the memory or from IF_ICMPxx
1655 NEW_OP1_BRANCH(TYPE_INT);
1656 /* iptr->sx.val.i = 0; */
1657 BRANCH(tbptr, copy);
1660 /* pop 0 push 0 branch */
1663 COUNT(count_pcmd_bra);
1665 BRANCH(tbptr, copy);
1666 superblockend = true;
1669 /* pop 1 push 0 table branch */
1671 case ICMD_TABLESWITCH:
1672 COUNT(count_pcmd_table);
1673 NEW_OP1_BRANCH(TYPE_INT);
1675 table = iptr->dst.table;
1676 BRANCH_TARGET(*table, tbptr, copy);
1679 i = iptr->sx.s23.s3.tablehigh
1680 - iptr->sx.s23.s2.tablelow + 1;
1683 BRANCH_TARGET(*table, tbptr, copy);
1686 superblockend = true;
1689 /* pop 1 push 0 table branch */
1691 case ICMD_LOOKUPSWITCH:
1692 COUNT(count_pcmd_table);
1693 NEW_OP1_BRANCH(TYPE_INT);
1695 BRANCH_TARGET(iptr->sx.s23.s3.lookupdefault, tbptr, copy);
1697 lookup = iptr->dst.lookup;
1699 i = iptr->sx.s23.s2.lookupcount;
1702 BRANCH_TARGET(lookup->target, tbptr, copy);
1705 superblockend = true;
1708 case ICMD_MONITORENTER:
1709 case ICMD_MONITOREXIT:
1710 COUNT(count_check_null);
1711 NEW_OP1_0(TYPE_ADR);
1714 /* pop 2 push 0 branch */
1716 case ICMD_IF_ICMPEQ:
1717 case ICMD_IF_ICMPNE:
1718 case ICMD_IF_ICMPLT:
1719 case ICMD_IF_ICMPGE:
1720 case ICMD_IF_ICMPGT:
1721 case ICMD_IF_ICMPLE:
1722 COUNT(count_pcmd_bra);
1723 NEW_OP2_BRANCH(TYPE_INT, TYPE_INT);
1724 BRANCH(tbptr, copy);
1727 case ICMD_IF_ACMPEQ:
1728 case ICMD_IF_ACMPNE:
1729 COUNT(count_pcmd_bra);
1730 NEW_OP2_BRANCH(TYPE_ADR, TYPE_ADR);
1731 BRANCH(tbptr, copy);
1737 COUNT(count_check_null);
1738 COUNT(count_pcmd_mem);
1739 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1740 NEW_OP2_0(TYPE_ADR, fmiref->parseddesc.fd->type);
1745 if (!IS_2_WORD_TYPE(curstack->type)) {
1747 #ifdef ENABLE_VERIFIER
1750 if (IS_2_WORD_TYPE(curstack->prev->type))
1751 goto throw_stack_category_error;
1754 NEW_OP2_0_ANY_ANY; /* pop two slots */
1757 iptr->opc = ICMD_POP;
1758 NEW_OP1_0_ANY; /* pop one (two-word) slot */
1762 /* pop 0 push 1 dup */
1765 #ifdef ENABLE_VERIFIER
1768 if (IS_2_WORD_TYPE(curstack->type))
1769 goto throw_stack_category_error;
1772 last_dupx = bptr->icount - len - 1;
1773 COUNT(count_dup_instruction);
1776 USE_S1_ANY; /* XXX live through */
1777 DUP_SLOT(iptr->s1.var);
1778 iptr->dst.var = curstack;
1783 last_dupx = bptr->icount - len - 1;
1785 if (IS_2_WORD_TYPE(curstack->type)) {
1787 iptr->opc = ICMD_DUP;
1792 /* ..., ????, cat1 */
1793 #ifdef ENABLE_VERIFIER
1795 if (IS_2_WORD_TYPE(curstack->prev->type))
1796 goto throw_stack_category_error;
1799 iptr->dst.dupslots = DMNEW(stackptr, 2 + 2);
1800 iptr->dst.dupslots[0] = curstack->prev; /* XXX live through */
1801 iptr->dst.dupslots[1] = curstack; /* XXX live through */
1803 DUP_SLOT(iptr->dst.dupslots[0]);
1804 iptr->dst.dupslots[2+0] = curstack;
1805 DUP_SLOT(iptr->dst.dupslots[1]);
1806 iptr->dst.dupslots[2+1] = curstack;
1811 /* pop 2 push 3 dup */
1814 #ifdef ENABLE_VERIFIER
1817 if (IS_2_WORD_TYPE(curstack->type) ||
1818 IS_2_WORD_TYPE(curstack->prev->type))
1819 goto throw_stack_category_error;
1822 last_dupx = bptr->icount - len - 1;
1825 iptr->dst.dupslots = DMNEW(stackptr, 2 + 3);
1826 iptr->dst.dupslots[0] = curstack->prev;
1827 iptr->dst.dupslots[1] = curstack;
1830 DUP_SLOT(iptr->dst.dupslots[1]);
1831 iptr->dst.dupslots[2+0] = curstack;
1832 DUP_SLOT(iptr->dst.dupslots[0]);
1833 iptr->dst.dupslots[2+1] = curstack;
1834 DUP_SLOT(iptr->dst.dupslots[1]);
1835 iptr->dst.dupslots[2+2] = curstack;
1840 last_dupx = bptr->icount - len - 1;
1842 if (IS_2_WORD_TYPE(curstack->type)) {
1843 /* ..., ????, cat2 */
1844 #ifdef ENABLE_VERIFIER
1846 if (IS_2_WORD_TYPE(curstack->prev->type))
1847 goto throw_stack_category_error;
1850 iptr->opc = ICMD_DUP_X1;
1854 /* ..., ????, cat1 */
1855 #ifdef ENABLE_VERIFIER
1858 if (IS_2_WORD_TYPE(curstack->prev->type)
1859 || IS_2_WORD_TYPE(curstack->prev->prev->type))
1860 goto throw_stack_category_error;
1865 iptr->dst.dupslots = DMNEW(stackptr, 3 + 5);
1866 iptr->dst.dupslots[0] = curstack->prev->prev;
1867 iptr->dst.dupslots[1] = curstack->prev;
1868 iptr->dst.dupslots[2] = curstack;
1869 POPANY; POPANY; POPANY;
1871 DUP_SLOT(iptr->dst.dupslots[1]);
1872 iptr->dst.dupslots[3+0] = curstack;
1873 DUP_SLOT(iptr->dst.dupslots[2]);
1874 iptr->dst.dupslots[3+1] = curstack;
1875 DUP_SLOT(iptr->dst.dupslots[0]);
1876 iptr->dst.dupslots[3+2] = curstack;
1877 DUP_SLOT(iptr->dst.dupslots[1]);
1878 iptr->dst.dupslots[3+3] = curstack;
1879 DUP_SLOT(iptr->dst.dupslots[2]);
1880 iptr->dst.dupslots[3+4] = curstack;
1885 /* pop 3 push 4 dup */
1888 last_dupx = bptr->icount - len - 1;
1890 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1891 /* ..., cat2, ???? */
1892 #ifdef ENABLE_VERIFIER
1894 if (IS_2_WORD_TYPE(curstack->type))
1895 goto throw_stack_category_error;
1898 iptr->opc = ICMD_DUP_X1;
1902 /* ..., cat1, ???? */
1903 #ifdef ENABLE_VERIFIER
1906 if (IS_2_WORD_TYPE(curstack->type)
1907 || IS_2_WORD_TYPE(curstack->prev->prev->type))
1908 goto throw_stack_category_error;
1912 iptr->dst.dupslots = DMNEW(stackptr, 3 + 4);
1913 iptr->dst.dupslots[0] = curstack->prev->prev;
1914 iptr->dst.dupslots[1] = curstack->prev;
1915 iptr->dst.dupslots[2] = curstack;
1916 POPANY; POPANY; POPANY;
1918 DUP_SLOT(iptr->dst.dupslots[2]);
1919 iptr->dst.dupslots[3+0] = curstack;
1920 DUP_SLOT(iptr->dst.dupslots[0]);
1921 iptr->dst.dupslots[3+1] = curstack;
1922 DUP_SLOT(iptr->dst.dupslots[1]);
1923 iptr->dst.dupslots[3+2] = curstack;
1924 DUP_SLOT(iptr->dst.dupslots[2]);
1925 iptr->dst.dupslots[3+3] = curstack;
1931 last_dupx = bptr->icount - len - 1;
1933 if (IS_2_WORD_TYPE(curstack->type)) {
1934 /* ..., ????, cat2 */
1935 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1936 /* ..., cat2, cat2 */
1937 iptr->opc = ICMD_DUP_X1;
1941 /* ..., cat1, cat2 */
1942 #ifdef ENABLE_VERIFIER
1945 if (IS_2_WORD_TYPE(curstack->prev->prev->type))
1946 goto throw_stack_category_error;
1949 iptr->opc = ICMD_DUP_X2;
1955 /* ..., ????, ????, cat1 */
1957 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1958 /* ..., cat2, ????, cat1 */
1959 #ifdef ENABLE_VERIFIER
1961 if (IS_2_WORD_TYPE(curstack->prev->type))
1962 goto throw_stack_category_error;
1965 iptr->opc = ICMD_DUP2_X1;
1969 /* ..., cat1, ????, cat1 */
1970 #ifdef ENABLE_VERIFIER
1973 if (IS_2_WORD_TYPE(curstack->prev->type)
1974 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
1975 goto throw_stack_category_error;
1978 iptr->dst.dupslots = DMNEW(stackptr, 4 + 6);
1979 iptr->dst.dupslots[0] = curstack->prev->prev->prev;
1980 iptr->dst.dupslots[1] = curstack->prev->prev;
1981 iptr->dst.dupslots[2] = curstack->prev;
1982 iptr->dst.dupslots[3] = curstack;
1983 POPANY; POPANY; POPANY; POPANY;
1985 DUP_SLOT(iptr->dst.dupslots[2]);
1986 iptr->dst.dupslots[4+0] = curstack;
1987 DUP_SLOT(iptr->dst.dupslots[3]);
1988 iptr->dst.dupslots[4+1] = curstack;
1989 DUP_SLOT(iptr->dst.dupslots[0]);
1990 iptr->dst.dupslots[4+2] = curstack;
1991 DUP_SLOT(iptr->dst.dupslots[1]);
1992 iptr->dst.dupslots[4+3] = curstack;
1993 DUP_SLOT(iptr->dst.dupslots[2]);
1994 iptr->dst.dupslots[4+4] = curstack;
1995 DUP_SLOT(iptr->dst.dupslots[3]);
1996 iptr->dst.dupslots[4+5] = curstack;
2001 /* pop 2 push 2 swap */
2004 last_dupx = bptr->icount - len - 1;
2005 #ifdef ENABLE_VERIFIER
2008 if (IS_2_WORD_TYPE(curstack->type)
2009 || IS_2_WORD_TYPE(curstack->prev->type))
2010 goto throw_stack_category_error;
2013 iptr->dst.dupslots = DMNEW(stackptr, 2 + 2);
2014 iptr->dst.dupslots[0] = curstack->prev;
2015 iptr->dst.dupslots[1] = curstack;
2018 DUP_SLOT(iptr->dst.dupslots[1]);
2019 iptr->dst.dupslots[2+0] = curstack;
2020 DUP_SLOT(iptr->dst.dupslots[0]);
2021 iptr->dst.dupslots[2+1] = curstack;
2028 #if !SUPPORT_DIVISION
2029 bte = iptr->sx.s23.s3.bte;
2032 if (md->memuse > rd->memuse)
2033 rd->memuse = md->memuse;
2034 if (md->argintreguse > rd->argintreguse)
2035 rd->argintreguse = md->argintreguse;
2037 /* make all stack variables saved */
2041 copy->flags |= SAVEDVAR;
2046 #endif /* !SUPPORT_DIVISION */
2057 COUNT(count_pcmd_op);
2058 NEW_OP2_1(TYPE_INT, TYPE_INT, TYPE_INT);
2063 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
2064 bte = iptr->sx.s23.s3.bte;
2067 if (md->memuse > rd->memuse)
2068 rd->memuse = md->memuse;
2069 if (md->argintreguse > rd->argintreguse)
2070 rd->argintreguse = md->argintreguse;
2071 /* XXX non-leaf method? */
2073 /* make all stack variables saved */
2077 copy->flags |= SAVEDVAR;
2082 #endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
2087 #if SUPPORT_LONG_LOGICAL
2091 #endif /* SUPPORT_LONG_LOGICAL */
2092 COUNT(count_pcmd_op);
2093 NEW_OP2_1(TYPE_LNG, TYPE_LNG, TYPE_LNG);
2099 COUNT(count_pcmd_op);
2100 NEW_OP2_1(TYPE_LNG, TYPE_INT, TYPE_LNG);
2108 COUNT(count_pcmd_op);
2109 NEW_OP2_1(TYPE_FLT, TYPE_FLT, TYPE_FLT);
2117 COUNT(count_pcmd_op);
2118 NEW_OP2_1(TYPE_DBL, TYPE_DBL, TYPE_DBL);
2122 COUNT(count_pcmd_op);
2123 #if SUPPORT_LONG_CMP_CONST
2124 if ((len == 0) || (iptr[1].sx.val.i != 0))
2127 switch (iptr[1].opc) {
2129 iptr->opc = ICMD_IF_LCMPEQ;
2131 iptr->dst.insindex = iptr[1].dst.insindex;
2132 iptr[1].opc = ICMD_NOP;
2134 NEW_OP2_BRANCH(TYPE_LNG, TYPE_LNG);
2135 BRANCH(tbptr, copy);
2137 COUNT(count_pcmd_bra);
2140 iptr->opc = ICMD_IF_LCMPNE;
2141 goto icmd_lcmp_if_tail;
2143 iptr->opc = ICMD_IF_LCMPLT;
2144 goto icmd_lcmp_if_tail;
2146 iptr->opc = ICMD_IF_LCMPGT;
2147 goto icmd_lcmp_if_tail;
2149 iptr->opc = ICMD_IF_LCMPLE;
2150 goto icmd_lcmp_if_tail;
2152 iptr->opc = ICMD_IF_LCMPGE;
2153 goto icmd_lcmp_if_tail;
2159 #endif /* SUPPORT_LONG_CMP_CONST */
2160 NEW_OP2_1(TYPE_LNG, TYPE_LNG, TYPE_INT);
2163 /* XXX why is this deactivated? */
2166 COUNT(count_pcmd_op);
2167 if ((len == 0) || (iptr[1].sx.val.i != 0))
2170 switch (iptr[1].opc) {
2172 iptr->opc = ICMD_IF_FCMPEQ;
2174 iptr->dst.insindex = iptr[1].dst.insindex;
2175 iptr[1].opc = ICMD_NOP;
2177 NEW_OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2178 BRANCH(tbptr, copy);
2180 COUNT(count_pcmd_bra);
2183 iptr->opc = ICMD_IF_FCMPNE;
2184 goto icmd_if_fcmpl_tail;
2186 iptr->opc = ICMD_IF_FCMPL_LT;
2187 goto icmd_if_fcmpl_tail;
2189 iptr->opc = ICMD_IF_FCMPL_GT;
2190 goto icmd_if_fcmpl_tail;
2192 iptr->opc = ICMD_IF_FCMPL_LE;
2193 goto icmd_if_fcmpl_tail;
2195 iptr->opc = ICMD_IF_FCMPL_GE;
2196 goto icmd_if_fcmpl_tail;
2203 OPTT2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2207 COUNT(count_pcmd_op);
2208 if ((len == 0) || (iptr[1].sx.val.i != 0))
2211 switch (iptr[1].opc) {
2213 iptr->opc = ICMD_IF_FCMPEQ;
2215 iptr->dst.insindex = iptr[1].dst.insindex;
2216 iptr[1].opc = ICMD_NOP;
2218 NEW_OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2219 BRANCH(tbptr, copy);
2221 COUNT(count_pcmd_bra);
2224 iptr->opc = ICMD_IF_FCMPNE;
2225 goto icmd_if_fcmpg_tail;
2227 iptr->opc = ICMD_IF_FCMPG_LT;
2228 goto icmd_if_fcmpg_tail;
2230 iptr->opc = ICMD_IF_FCMPG_GT;
2231 goto icmd_if_fcmpg_tail;
2233 iptr->opc = ICMD_IF_FCMPG_LE;
2234 goto icmd_if_fcmpg_tail;
2236 iptr->opc = ICMD_IF_FCMPG_GE;
2237 goto icmd_if_fcmpg_tail;
2244 NEW_OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2248 COUNT(count_pcmd_op);
2249 if ((len == 0) || (iptr[1].sx.val.i != 0))
2252 switch (iptr[1].opc) {
2254 iptr->opc = ICMD_IF_DCMPEQ;
2256 iptr->dst.insindex = iptr[1].dst.insindex;
2257 iptr[1].opc = ICMD_NOP;
2259 NEW_OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2260 BRANCH(tbptr, copy);
2262 COUNT(count_pcmd_bra);
2265 iptr->opc = ICMD_IF_DCMPNE;
2266 goto icmd_if_dcmpl_tail;
2268 iptr->opc = ICMD_IF_DCMPL_LT;
2269 goto icmd_if_dcmpl_tail;
2271 iptr->opc = ICMD_IF_DCMPL_GT;
2272 goto icmd_if_dcmpl_tail;
2274 iptr->opc = ICMD_IF_DCMPL_LE;
2275 goto icmd_if_dcmpl_tail;
2277 iptr->opc = ICMD_IF_DCMPL_GE;
2278 goto icmd_if_dcmpl_tail;
2285 OPTT2_1(TYPE_DBL, TYPE_INT);
2289 COUNT(count_pcmd_op);
2290 if ((len == 0) || (iptr[1].sx.val.i != 0))
2293 switch (iptr[1].opc) {
2295 iptr->opc = ICMD_IF_DCMPEQ;
2297 iptr->dst.insindex = iptr[1].dst.insindex;
2298 iptr[1].opc = ICMD_NOP;
2300 NEW_OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2301 BRANCH(tbptr, copy);
2303 COUNT(count_pcmd_bra);
2306 iptr->opc = ICMD_IF_DCMPNE;
2307 goto icmd_if_dcmpg_tail;
2309 iptr->opc = ICMD_IF_DCMPG_LT;
2310 goto icmd_if_dcmpg_tail;
2312 iptr->opc = ICMD_IF_DCMPG_GT;
2313 goto icmd_if_dcmpg_tail;
2315 iptr->opc = ICMD_IF_DCMPG_LE;
2316 goto icmd_if_dcmpg_tail;
2318 iptr->opc = ICMD_IF_DCMPG_GE;
2319 goto icmd_if_dcmpg_tail;
2326 NEW_OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2331 COUNT(count_pcmd_op);
2332 NEW_OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2337 COUNT(count_pcmd_op);
2338 NEW_OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2347 case ICMD_INT2SHORT:
2348 COUNT(count_pcmd_op);
2349 NEW_OP1_1(TYPE_INT, TYPE_INT);
2352 COUNT(count_pcmd_op);
2353 NEW_OP1_1(TYPE_LNG, TYPE_LNG);
2356 COUNT(count_pcmd_op);
2357 NEW_OP1_1(TYPE_FLT, TYPE_FLT);
2360 COUNT(count_pcmd_op);
2361 NEW_OP1_1(TYPE_DBL, TYPE_DBL);
2365 COUNT(count_pcmd_op);
2366 NEW_OP1_1(TYPE_INT, TYPE_LNG);
2369 COUNT(count_pcmd_op);
2370 NEW_OP1_1(TYPE_INT, TYPE_FLT);
2373 COUNT(count_pcmd_op);
2374 NEW_OP1_1(TYPE_INT, TYPE_DBL);
2377 COUNT(count_pcmd_op);
2378 NEW_OP1_1(TYPE_LNG, TYPE_INT);
2381 COUNT(count_pcmd_op);
2382 NEW_OP1_1(TYPE_LNG, TYPE_FLT);
2385 COUNT(count_pcmd_op);
2386 NEW_OP1_1(TYPE_LNG, TYPE_DBL);
2389 COUNT(count_pcmd_op);
2390 NEW_OP1_1(TYPE_FLT, TYPE_INT);
2393 COUNT(count_pcmd_op);
2394 NEW_OP1_1(TYPE_FLT, TYPE_LNG);
2397 COUNT(count_pcmd_op);
2398 NEW_OP1_1(TYPE_FLT, TYPE_DBL);
2401 COUNT(count_pcmd_op);
2402 NEW_OP1_1(TYPE_DBL, TYPE_INT);
2405 COUNT(count_pcmd_op);
2406 NEW_OP1_1(TYPE_DBL, TYPE_LNG);
2409 COUNT(count_pcmd_op);
2410 NEW_OP1_1(TYPE_DBL, TYPE_FLT);
2413 case ICMD_CHECKCAST:
2414 if (iptr->flags.bits & INS_FLAG_ARRAY) {
2415 /* array type cast-check */
2417 bte = builtintable_get_internal(BUILTIN_arraycheckcast);
2420 if (md->memuse > rd->memuse)
2421 rd->memuse = md->memuse;
2422 if (md->argintreguse > rd->argintreguse)
2423 rd->argintreguse = md->argintreguse;
2425 /* make all stack variables saved */
2429 copy->flags |= SAVEDVAR;
2433 NEW_OP1_1(TYPE_ADR, TYPE_ADR);
2436 case ICMD_INSTANCEOF:
2437 case ICMD_ARRAYLENGTH:
2438 NEW_OP1_1(TYPE_ADR, TYPE_INT);
2442 case ICMD_ANEWARRAY:
2443 NEW_OP1_1(TYPE_INT, TYPE_ADR);
2447 COUNT(count_check_null);
2448 COUNT(count_pcmd_mem);
2449 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2450 NEW_OP1_1(TYPE_ADR, fmiref->parseddesc.fd->type);
2455 case ICMD_GETSTATIC:
2456 COUNT(count_pcmd_mem);
2457 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2458 NEW_OP0_1(fmiref->parseddesc.fd->type);
2462 NEW_OP0_1(TYPE_ADR);
2466 NEW_OP0_1(TYPE_ADR);
2468 BRANCH_TARGET(iptr->sx.s23.s3.jsrtarget, tbptr, copy);
2470 tbptr->type = BBTYPE_SBR;
2472 /* We need to check for overflow right here because
2473 * the pushed value is poped afterwards */
2476 /* calculate stack after return */
2481 /* pop many push any */
2485 bte = iptr->sx.s23.s3.bte;
2489 case ICMD_INVOKESTATIC:
2490 case ICMD_INVOKESPECIAL:
2491 case ICMD_INVOKEVIRTUAL:
2492 case ICMD_INVOKEINTERFACE:
2493 COUNT(count_pcmd_met);
2495 /* Check for functions to replace with builtin
2498 if (builtintable_replace_function(iptr))
2501 INSTRUCTION_GET_METHODDESC(iptr, md);
2502 /* XXX resurrect this COUNT? */
2503 /* if (lm->flags & ACC_STATIC) */
2504 /* {COUNT(count_check_null);} */
2508 last_pei = bptr->icount - len - 1;
2512 if (md->memuse > rd->memuse)
2513 rd->memuse = md->memuse;
2514 if (md->argintreguse > rd->argintreguse)
2515 rd->argintreguse = md->argintreguse;
2516 if (md->argfltreguse > rd->argfltreguse)
2517 rd->argfltreguse = md->argfltreguse;
2521 /* XXX optimize for <= 2 args */
2522 /* XXX not for ICMD_BUILTIN */
2523 iptr->s1.argcount = stackdepth;
2524 iptr->sx.s23.s2.args = DMNEW(stackptr, stackdepth);
2527 for (i-- ; i >= 0; i--) {
2528 iptr->sx.s23.s2.args[i] = copy;
2530 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2531 /* If we pass float arguments in integer argument registers, we
2532 * are not allowed to precolor them here. Floats have to be moved
2533 * to this regs explicitly in codegen().
2534 * Only arguments that are passed by stack anyway can be precolored
2535 * (michi 2005/07/24) */
2536 if (!(copy->flags & SAVEDVAR) &&
2537 (!IS_FLT_DBL_TYPE(copy->type) || md->params[i].inmemory)) {
2539 if (!(copy->flags & SAVEDVAR)) {
2541 copy->varkind = ARGVAR;
2544 #if defined(ENABLE_INTRP)
2547 if (md->params[i].inmemory) {
2548 copy->flags = INMEMORY;
2549 copy->regoff = md->params[i].regoff;
2553 if (IS_FLT_DBL_TYPE(copy->type)) {
2554 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2555 assert(0); /* XXX is this assert ok? */
2558 rd->argfltregs[md->params[i].regoff];
2559 #endif /* SUPPORT_PASS_FLOATARGS_IN_INTREGS */
2562 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
2563 if (IS_2_WORD_TYPE(copy->type))
2564 copy->regoff = PACK_REGS(
2565 rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
2566 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
2568 #endif /* SUPPORT_COMBINE_INTEGER_REGISTERS */
2570 rd->argintregs[md->params[i].regoff];
2573 #if defined(ENABLE_INTRP)
2574 } /* end if (!opt_intrp) */
2580 /* deal with live-through stack slots "under" the arguments */
2581 /* XXX not for ICMD_BUILTIN */
2586 iptr->sx.s23.s2.args[i++] = copy;
2587 copy->flags |= SAVEDVAR;
2591 /* pop the arguments */
2600 /* push the return value */
2602 if (md->returntype.type != TYPE_VOID) {
2603 NEW_DST(md->returntype.type, stackdepth);
2608 case ICMD_INLINE_START:
2609 case ICMD_INLINE_END:
2614 case ICMD_MULTIANEWARRAY:
2615 if (rd->argintreguse < 3)
2616 rd->argintreguse = 3;
2618 i = iptr->s1.argcount;
2622 iptr->sx.s23.s2.args = DMNEW(stackptr, i);
2624 #if defined(SPECIALMEMUSE)
2625 # if defined(__DARWIN__)
2626 if (rd->memuse < (i + INT_ARG_CNT + LA_SIZE_IN_POINTERS))
2627 rd->memuse = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2629 if (rd->memuse < (i + LA_SIZE_IN_POINTERS + 3))
2630 rd->memuse = i + LA_SIZE_IN_POINTERS + 3;
2633 # if defined(__I386__)
2634 if (rd->memuse < i + 3)
2635 rd->memuse = i + 3; /* n integer args spilled on stack */
2636 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2637 if (rd->memuse < i + 2)
2638 rd->memuse = i + 2; /* 4*4 bytes callee save space */
2641 rd->memuse = i; /* n integer args spilled on stack */
2642 # endif /* defined(__I386__) */
2646 /* check INT type here? Currently typecheck does this. */
2647 iptr->sx.s23.s2.args[i] = copy;
2648 if (!(copy->flags & SAVEDVAR)) {
2649 copy->varkind = ARGVAR;
2650 copy->varnum = i + INT_ARG_CNT;
2651 copy->flags |= INMEMORY;
2652 #if defined(SPECIALMEMUSE)
2653 # if defined(__DARWIN__)
2654 copy->regoff = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2656 copy->regoff = i + LA_SIZE_IN_POINTERS + 3;
2659 # if defined(__I386__)
2660 copy->regoff = i + 3;
2661 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2662 copy->regoff = i + 2;
2665 # endif /* defined(__I386__) */
2666 #endif /* defined(SPECIALMEMUSE) */
2671 copy->flags |= SAVEDVAR;
2675 i = iptr->s1.argcount;
2680 NEW_DST(TYPE_ADR, stackdepth);
2686 new_internalerror("Unknown ICMD %d", opcode);
2692 } /* while instructions */
2694 /* set out-stack of block */
2696 bptr->outstack = curstack;
2697 bptr->outdepth = stackdepth;
2698 bptr->outvars = DMNEW(stackptr, stackdepth);
2699 for (i = stackdepth, copy = curstack; i--; copy = copy->prev)
2700 bptr->outvars[i] = copy;
2702 /* stack slots at basic block end become interfaces */
2705 for (copy = curstack; copy; i--, copy = copy->prev) {
2706 if ((copy->varkind == STACKVAR) && (copy->varnum > i))
2707 copy->varkind = TEMPVAR;
2709 copy->varkind = STACKVAR;
2713 rd->interfaces[i][copy->type].type = copy->type;
2714 rd->interfaces[i][copy->type].flags |= copy->flags;
2718 /* check if interface slots at basic block begin must be saved */
2721 i = bptr->indepth - 1;
2722 for (copy = bptr->instack; copy; i--, copy = copy->prev) {
2723 rd->interfaces[i][copy->type].type = copy->type;
2724 if (copy->varkind == STACKVAR) {
2725 if (copy->flags & SAVEDVAR)
2726 rd->interfaces[i][copy->type].flags |= SAVEDVAR;
2733 superblockend = true;
2736 } /* while blocks */
2737 } while (repeat && !deadcode);
2739 /* gather statistics *****************************************************/
2741 #if defined(ENABLE_STATISTICS)
2743 if (jd->new_basicblockcount > count_max_basic_blocks)
2744 count_max_basic_blocks = jd->new_basicblockcount;
2745 count_basic_blocks += jd->new_basicblockcount;
2746 if (jd->new_instructioncount > count_max_javainstr)
2747 count_max_javainstr = jd->new_instructioncount;
2748 count_javainstr += jd->new_instructioncount;
2749 if (jd->new_stackcount > count_upper_bound_new_stack)
2750 count_upper_bound_new_stack = jd->new_stackcount;
2751 if ((new - jd->new_stack) > count_max_new_stack)
2752 count_max_new_stack = (new - jd->new_stack);
2754 b_count = jd->new_basicblockcount;
2755 bptr = jd->new_basicblocks;
2756 while (--b_count >= 0) {
2757 if (bptr->flags > BBREACHED) {
2758 if (bptr->indepth >= 10)
2759 count_block_stack[10]++;
2761 count_block_stack[bptr->indepth]++;
2764 count_block_size_distribution[len]++;
2766 count_block_size_distribution[10]++;
2768 count_block_size_distribution[11]++;
2770 count_block_size_distribution[12]++;
2772 count_block_size_distribution[13]++;
2774 count_block_size_distribution[14]++;
2776 count_block_size_distribution[15]++;
2778 count_block_size_distribution[16]++;
2780 count_block_size_distribution[17]++;
2785 if (iteration_count == 1)
2786 count_analyse_iterations[0]++;
2787 else if (iteration_count == 2)
2788 count_analyse_iterations[1]++;
2789 else if (iteration_count == 3)
2790 count_analyse_iterations[2]++;
2791 else if (iteration_count == 4)
2792 count_analyse_iterations[3]++;
2794 count_analyse_iterations[4]++;
2796 if (jd->new_basicblockcount <= 5)
2797 count_method_bb_distribution[0]++;
2798 else if (jd->new_basicblockcount <= 10)
2799 count_method_bb_distribution[1]++;
2800 else if (jd->new_basicblockcount <= 15)
2801 count_method_bb_distribution[2]++;
2802 else if (jd->new_basicblockcount <= 20)
2803 count_method_bb_distribution[3]++;
2804 else if (jd->new_basicblockcount <= 30)
2805 count_method_bb_distribution[4]++;
2806 else if (jd->new_basicblockcount <= 40)
2807 count_method_bb_distribution[5]++;
2808 else if (jd->new_basicblockcount <= 50)
2809 count_method_bb_distribution[6]++;
2810 else if (jd->new_basicblockcount <= 75)
2811 count_method_bb_distribution[7]++;
2813 count_method_bb_distribution[8]++;
2815 #endif /* defined(ENABLE_STATISTICS) */
2817 /* everything's ok *******************************************************/
2821 /* goto labels for throwing verifier exceptions **************************/
2823 #if defined(ENABLE_VERIFIER)
2825 throw_stack_underflow:
2826 exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
2829 throw_stack_overflow:
2830 exceptions_throw_verifyerror(m, "Stack size too large");
2833 throw_stack_depth_error:
2834 exceptions_throw_verifyerror(m,"Stack depth mismatch");
2837 throw_stack_type_error:
2838 exceptions_throw_verifyerror_for_stack(m, expectedtype);
2841 throw_stack_category_error:
2842 exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
2850 * These are local overrides for various environment variables in Emacs.
2851 * Please do not remove this and leave it at the end of the file, where
2852 * Emacs will automagically detect them.
2853 * ---------------------------------------------------------------------
2856 * indent-tabs-mode: t
2860 * vim:noexpandtab:sw=4:ts=4: