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 5385 2006-09-06 21:40:50Z 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 *******************************************************************************/
147 #define GET_NEW_INDEX(new_varindex) \
149 assert(jd->vartop < jd->varcount); \
150 (new_varindex) = (jd->vartop)++; \
153 /* not implemented now, can be used to reuse varindices */
154 #define RELEASE_INDEX(varindex)
157 (iptr->s1.varindex = -1)
159 #define USE_S1_LOCAL(type1)
161 #define USE_S1(type1) \
164 CHECK_BASIC_TYPE(type1, curstack->type); \
165 iptr->s1.varindex = curstack->varnum; \
171 iptr->s1.varindex = curstack->varnum; \
174 #define USE_S1_S2(type1, type2) \
177 CHECK_BASIC_TYPE(type1, curstack->prev->type); \
178 CHECK_BASIC_TYPE(type2, curstack->type); \
179 iptr->sx.s23.s2.varindex = curstack->varnum; \
180 iptr->s1.varindex = curstack->prev->varnum; \
183 #define USE_S1_S2_ANY_ANY \
186 iptr->sx.s23.s2.varindex = curstack->varnum; \
187 iptr->s1.varindex = curstack->prev->varnum; \
190 #define USE_S1_S2_S3(type1, type2, type3) \
193 CHECK_BASIC_TYPE(type1, curstack->prev->prev->type); \
194 CHECK_BASIC_TYPE(type2, curstack->prev->type); \
195 CHECK_BASIC_TYPE(type3, curstack->type); \
196 iptr->sx.s23.s3.varindex = curstack->varnum; \
197 iptr->sx.s23.s2.varindex = curstack->prev->varnum; \
198 iptr->s1.varindex = curstack->prev->prev->varnum; \
202 (iptr->dst.varindex = -1)
204 #define DST(typed, varindex) \
206 NEWSTACKn((varindex)); \
207 iptr->dst.varindex = (varindex); \
210 #define DST_LOCALVAR(typed, index) \
212 NEWSTACK(typed, LOCALVAR, (index)); \
213 iptr->dst.varindex = (index); \
216 #define OP0_1(typed) \
219 GET_NEW_INDEX(new_index); \
220 DST(typed, new_index); \
231 #define OP1_BRANCH(type1) \
237 #define OP1_1(type1, typed) \
240 GET_NEW_INDEX(new_index); \
241 DST(typed, new_index; \
244 #define OP2_1(type1, type2, typed) \
246 POP_S1_S2(type1, type2); \
247 GET_NEW_INDEX(new_index); \
248 DST(typed, new_index); \
252 #define DUP_SLOT(sp) \
254 if ((sp)->varkind != TEMPVAR) { \
255 GET_NEW_INDEX(new_index); \
256 NEWSTACK((sp)->type, TEMPVAR, new_index); \
259 NEWSTACK((sp)->type, (sp)->varkind, (sp)->varnum); \
262 #else /* defined(NEW_VAR) */
265 (iptr->s1.var = NULL)
267 #define USE_S1_LOCAL(type1)
269 #define USE_S1(type1) \
272 CHECK_BASIC_TYPE(type1, curstack->type); \
273 iptr->s1.var = curstack; \
279 iptr->s1.var = curstack; \
282 #define USE_S1_S2(type1, type2) \
285 CHECK_BASIC_TYPE(type1, curstack->prev->type); \
286 CHECK_BASIC_TYPE(type2, curstack->type); \
287 iptr->sx.s23.s2.var = curstack; \
288 iptr->s1.var = curstack->prev; \
291 #define USE_S1_S2_ANY_ANY \
294 iptr->sx.s23.s2.var = curstack; \
295 iptr->s1.var = curstack->prev; \
298 #define USE_S1_S2_S3(type1, type2, type3) \
301 CHECK_BASIC_TYPE(type1, curstack->prev->prev->type); \
302 CHECK_BASIC_TYPE(type2, curstack->prev->type); \
303 CHECK_BASIC_TYPE(type3, curstack->type); \
304 iptr->sx.s23.s3.var = curstack; \
305 iptr->sx.s23.s2.var = curstack->prev; \
306 iptr->s1.var = curstack->prev->prev; \
310 (iptr->dst.var = NULL)
312 #define DST(typed, depth) \
314 NEWSTACKn(typed, (depth)); \
315 iptr->dst.var = curstack; \
318 #define DST_LOCALVAR(typed, index) \
320 NEWSTACK(typed, LOCALVAR, (index)); \
321 iptr->dst.var = curstack; \
324 #define OP0_1(typed) \
327 DST(typed, stackdepth); \
338 #define OP1_BRANCH(type1) \
344 #define OP1_1(type1, typed) \
347 DST(typed, stackdepth - 1); \
350 #define OP2_1(type1, type2, typed) \
352 POP_S1_S2(type1, type2); \
353 DST(typed, stackdepth - 2); \
357 #define DUP_SLOT(sp) \
359 if ((sp)->varkind != TEMPVAR) \
360 NEWSTACK((sp)->type, TEMPVAR, stackdepth); \
362 NEWSTACK((sp)->type, (sp)->varkind, (sp)->varnum); \
365 #endif /* defined(NEW_VAR) */
368 #define POP_S1(type1) \
371 if (curstack->varkind == UNDEFVAR) \
372 curstack->varkind = TEMPVAR; \
373 curstack = curstack->prev; \
379 if (curstack->varkind == UNDEFVAR) \
380 curstack->varkind = TEMPVAR; \
381 curstack = curstack->prev; \
384 #define POP_S1_S2(type1, type2) \
386 USE_S1_S2(type1, type2); \
387 if (curstack->varkind == UNDEFVAR) \
388 curstack->varkind = TEMPVAR; \
389 if (curstack->prev->varkind == UNDEFVAR) \
390 curstack->prev->varkind = TEMPVAR; \
391 curstack = curstack->prev->prev; \
394 #define POP_S1_S2_ANY_ANY \
397 if (curstack->varkind == UNDEFVAR) \
398 curstack->varkind = TEMPVAR; \
399 if (curstack->prev->varkind == UNDEFVAR) \
400 curstack->prev->varkind = TEMPVAR; \
401 curstack = curstack->prev->prev; \
404 #define POP_S1_S2_S3(type1, type2, type3) \
406 USE_S1_S2_S3(type1, type2, type3); \
407 if (curstack->varkind == UNDEFVAR) \
408 curstack->varkind = TEMPVAR; \
409 if (curstack->prev->varkind == UNDEFVAR) \
410 curstack->prev->varkind = TEMPVAR; \
411 if (curstack->prev->prev->varkind == UNDEFVAR) \
412 curstack->prev->prev->varkind = TEMPVAR; \
413 curstack = curstack->prev->prev->prev; \
430 #define OP1_0(type1) \
437 #define OP2_0(type1, type2) \
439 POP_S1_S2(type1, type2); \
444 #define OP2_BRANCH(type1, type2) \
446 POP_S1_S2(type1, type2); \
450 #define OP2_0_ANY_ANY \
457 #define OP3_0(type1, type2, type3) \
459 POP_S1_S2_S3(type1, type2, type3); \
464 #define LOAD(type1, index) \
466 DST_LOCALVAR(type1, index); \
470 #define STORE(type1, index) \
476 #define BRANCH_TARGET(bt, tempbptr, tempsp) \
478 (bt).block = tempbptr = BLOCK_OF((bt).insindex); \
479 MARKREACHED(tempbptr, tempsp); \
482 #define BRANCH(tempbptr, tempsp) \
484 iptr->dst.block = tempbptr = BLOCK_OF(iptr->dst.insindex); \
485 MARKREACHED(tempbptr, tempsp); \
488 bool new_stack_analyse(jitdata *jd)
490 methodinfo *m; /* method being analyzed */
494 int b_count; /* basic block counter */
495 int b_index; /* basic block index */
497 stackptr curstack; /* current stack top */
500 int opcode; /* opcode of current instruction */
502 int len; /* # of instructions after the current one */
503 bool superblockend; /* if true, no fallthrough to next block */
504 bool repeat; /* if true, outermost loop must run again */
505 bool deadcode; /* true if no live code has been reached */
506 instruction *iptr; /* the current instruction */
507 basicblock *bptr; /* the current basic block */
510 stackptr *last_store_boundary;
511 stackptr last_pei_boundary;
512 stackptr last_dup_boundary;
514 branch_target_t *table;
515 lookup_target_t *lookup;
516 #if defined(ENABLE_VERIFIER)
517 int expectedtype; /* used by CHECK_BASIC_TYPE */
519 builtintable_entry *bte;
521 constant_FMIref *fmiref;
522 #if defined(ENABLE_STATISTICS)
523 int iteration_count; /* number of iterations of analysis */
526 int new_index; /* used to get a new var index with GET_NEW_INDEX*/
528 #if defined(STACK_VERBOSE)
529 new_show_method(jd, SHOW_PARSE);
532 /* get required compiler data - initialization */
539 #if defined(ENABLE_LSRA)
543 #if defined(ENABLE_STATISTICS)
548 last_store_boundary = DMNEW(stackptr, jd->localcount);
550 last_store_boundary = DMNEW(stackptr , cd->maxlocals);
553 /* initialize in-stack of first block */
556 jd->new_basicblocks[0].flags = BBREACHED;
557 jd->new_basicblocks[0].instack = NULL;
558 jd->new_basicblocks[0].invars = NULL;
559 jd->new_basicblocks[0].indepth = 0;
561 /* initialize in-stack of exception handlers */
563 for (i = 0; i < cd->exceptiontablelength; i++) {
564 bptr = BLOCK_OF(cd->exceptiontable[i].handlerpc);
565 bptr->flags = BBREACHED;
566 bptr->type = BBTYPE_EXH;
569 bptr->predecessorcount = CFG_UNKNOWN_PREDECESSORS;
572 GET_NEW_INDEX(new_index);
573 bptr->invars = DMNEW(s4, 1);
574 bptr->invars[0] = new_index;
575 NEWSTACK(TYPE_ADR, STACKVAR,new_index);
577 bptr->invars = DMNEW(stackptr, 1);
578 bptr->invars[0] = new;
583 /* stack analysis loop (until fixpoint reached) **************************/
586 #if defined(ENABLE_STATISTICS)
590 /* initialize loop over basic blocks */
592 b_count = jd->new_basicblockcount;
593 bptr = jd->new_basicblocks;
594 superblockend = true;
599 /* iterate over basic blocks *****************************************/
601 while (--b_count >= 0) {
602 #if defined(STACK_VERBOSE)
603 printf("ANALYZING BLOCK L%03d\n", bptr->nr);
606 if (bptr->flags == BBDELETED) {
607 /* This block has been deleted - do nothing. */
609 else if (superblockend && (bptr->flags < BBREACHED)) {
610 /* This block has not been reached so far, and we */
611 /* don't fall into it, so we'll have to iterate again. */
614 else if (bptr->flags <= BBREACHED) {
616 /* We know that bptr->flags == BBREACHED. */
617 /* This block has been reached before. */
618 stackdepth = bptr->indepth;
620 else if (bptr->flags < BBREACHED) {
621 /* This block is reached for the first time now */
622 /* by falling through from the previous block. */
624 bptr->instack = copy;
627 bptr->invars = DMNEW(s4, stackdepth);
628 for (i=stackdepth; i--; copy = copy->prev)
629 bptr->invars[i] = copy->varnum;
631 bptr->invars = DMNEW(stackptr, stackdepth);
632 for (i=stackdepth; i--; copy = copy->prev)
633 bptr->invars[i] = copy;
635 bptr->indepth = stackdepth;
638 /* This block has been reached before. now we are */
639 /* falling into it from the previous block. */
640 /* Check that stack depth is well-defined. */
641 CHECK_STACK_DEPTH(bptr->indepth, stackdepth);
644 /* set up local variables for analyzing this block */
646 curstack = bptr->instack;
648 superblockend = false;
649 bptr->flags = BBFINISHED;
652 b_index = bptr - jd->new_basicblocks;
654 /* reset variables for dependency checking */
656 last_pei_boundary = new;
657 last_dup_boundary = new;
658 for( i = 0; i < cd->maxlocals; i++)
659 last_store_boundary[i] = new;
661 /* XXX store the start of the block's stack representation */
665 /* iterate over ICMDs ****************************************/
668 #if defined(STACK_VERBOSE)
669 new_show_icmd(jd, iptr, false, SHOW_PARSE); printf("\n");
670 for( copy = curstack; copy; copy = copy->prev ) {
671 printf("%d ", copy->type);
676 /* fetch the current opcode */
680 /* automatically replace some ICMDs with builtins */
682 #if defined(USEBUILTINTABLE)
684 bte = builtintable_get_automatic(opcode);
686 if (bte && bte->opcode == opcode) {
687 iptr->opc = ICMD_BUILTIN;
688 iptr->flags.bits = 0;
689 iptr->sx.s23.s3.bte = bte;
690 /* iptr->line is already set */
691 jd->isleafmethod = false;
695 #endif /* defined(USEBUILTINTABLE) */
697 /* main opcode switch *************************************/
710 last_pei_boundary = new;
711 COUNT(count_check_null);
714 CLR_DST; /* XXX live through? */
718 USE_S1_LOCAL(TYPE_ADR);
721 #if !defined(NEW_VAR)
722 IF_NO_INTRP( rd->locals[iptr->s1.localindex][TYPE_ADR].type = TYPE_ADR; );
724 superblockend = true;
728 COUNT(count_pcmd_return);
731 superblockend = true;
735 /* pop 0 push 1 const */
737 /************************** ICONST OPTIMIZATIONS **************************/
740 COUNT(count_pcmd_load);
744 switch (iptr[1].opc) {
746 iptr->opc = ICMD_IADDCONST;
750 iptr[1].opc = ICMD_NOP;
751 OP1_1(TYPE_INT, TYPE_INT);
752 COUNT(count_pcmd_op);
756 iptr->opc = ICMD_ISUBCONST;
757 goto icmd_iconst_tail;
758 #if SUPPORT_CONST_MUL
760 iptr->opc = ICMD_IMULCONST;
761 goto icmd_iconst_tail;
762 #else /* SUPPORT_CONST_MUL */
764 if (iptr->sx.val.i == 0x00000002)
766 else if (iptr->sx.val.i == 0x00000004)
768 else if (iptr->sx.val.i == 0x00000008)
770 else if (iptr->sx.val.i == 0x00000010)
772 else if (iptr->sx.val.i == 0x00000020)
774 else if (iptr->sx.val.i == 0x00000040)
776 else if (iptr->sx.val.i == 0x00000080)
778 else if (iptr->sx.val.i == 0x00000100)
780 else if (iptr->sx.val.i == 0x00000200)
782 else if (iptr->sx.val.i == 0x00000400)
784 else if (iptr->sx.val.i == 0x00000800)
786 else if (iptr->sx.val.i == 0x00001000)
788 else if (iptr->sx.val.i == 0x00002000)
790 else if (iptr->sx.val.i == 0x00004000)
792 else if (iptr->sx.val.i == 0x00008000)
794 else if (iptr->sx.val.i == 0x00010000)
796 else if (iptr->sx.val.i == 0x00020000)
798 else if (iptr->sx.val.i == 0x00040000)
800 else if (iptr->sx.val.i == 0x00080000)
802 else if (iptr->sx.val.i == 0x00100000)
804 else if (iptr->sx.val.i == 0x00200000)
806 else if (iptr->sx.val.i == 0x00400000)
808 else if (iptr->sx.val.i == 0x00800000)
810 else if (iptr->sx.val.i == 0x01000000)
812 else if (iptr->sx.val.i == 0x02000000)
814 else if (iptr->sx.val.i == 0x04000000)
816 else if (iptr->sx.val.i == 0x08000000)
818 else if (iptr->sx.val.i == 0x10000000)
820 else if (iptr->sx.val.i == 0x20000000)
822 else if (iptr->sx.val.i == 0x40000000)
824 else if (iptr->sx.val.i == 0x80000000)
829 iptr->opc = ICMD_IMULPOW2;
830 goto icmd_iconst_tail;
831 #endif /* SUPPORT_CONST_MUL */
833 if (iptr->sx.val.i == 0x00000002)
835 else if (iptr->sx.val.i == 0x00000004)
837 else if (iptr->sx.val.i == 0x00000008)
839 else if (iptr->sx.val.i == 0x00000010)
841 else if (iptr->sx.val.i == 0x00000020)
843 else if (iptr->sx.val.i == 0x00000040)
845 else if (iptr->sx.val.i == 0x00000080)
847 else if (iptr->sx.val.i == 0x00000100)
849 else if (iptr->sx.val.i == 0x00000200)
851 else if (iptr->sx.val.i == 0x00000400)
853 else if (iptr->sx.val.i == 0x00000800)
855 else if (iptr->sx.val.i == 0x00001000)
857 else if (iptr->sx.val.i == 0x00002000)
859 else if (iptr->sx.val.i == 0x00004000)
861 else if (iptr->sx.val.i == 0x00008000)
863 else if (iptr->sx.val.i == 0x00010000)
865 else if (iptr->sx.val.i == 0x00020000)
867 else if (iptr->sx.val.i == 0x00040000)
869 else if (iptr->sx.val.i == 0x00080000)
871 else if (iptr->sx.val.i == 0x00100000)
873 else if (iptr->sx.val.i == 0x00200000)
875 else if (iptr->sx.val.i == 0x00400000)
877 else if (iptr->sx.val.i == 0x00800000)
879 else if (iptr->sx.val.i == 0x01000000)
881 else if (iptr->sx.val.i == 0x02000000)
883 else if (iptr->sx.val.i == 0x04000000)
885 else if (iptr->sx.val.i == 0x08000000)
887 else if (iptr->sx.val.i == 0x10000000)
889 else if (iptr->sx.val.i == 0x20000000)
891 else if (iptr->sx.val.i == 0x40000000)
893 else if (iptr->sx.val.i == 0x80000000)
898 iptr->opc = ICMD_IDIVPOW2;
899 goto icmd_iconst_tail;
902 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
903 if ((iptr->sx.val.i == 0x00000002) ||
904 (iptr->sx.val.i == 0x00000004) ||
905 (iptr->sx.val.i == 0x00000008) ||
906 (iptr->sx.val.i == 0x00000010) ||
907 (iptr->sx.val.i == 0x00000020) ||
908 (iptr->sx.val.i == 0x00000040) ||
909 (iptr->sx.val.i == 0x00000080) ||
910 (iptr->sx.val.i == 0x00000100) ||
911 (iptr->sx.val.i == 0x00000200) ||
912 (iptr->sx.val.i == 0x00000400) ||
913 (iptr->sx.val.i == 0x00000800) ||
914 (iptr->sx.val.i == 0x00001000) ||
915 (iptr->sx.val.i == 0x00002000) ||
916 (iptr->sx.val.i == 0x00004000) ||
917 (iptr->sx.val.i == 0x00008000) ||
918 (iptr->sx.val.i == 0x00010000) ||
919 (iptr->sx.val.i == 0x00020000) ||
920 (iptr->sx.val.i == 0x00040000) ||
921 (iptr->sx.val.i == 0x00080000) ||
922 (iptr->sx.val.i == 0x00100000) ||
923 (iptr->sx.val.i == 0x00200000) ||
924 (iptr->sx.val.i == 0x00400000) ||
925 (iptr->sx.val.i == 0x00800000) ||
926 (iptr->sx.val.i == 0x01000000) ||
927 (iptr->sx.val.i == 0x02000000) ||
928 (iptr->sx.val.i == 0x04000000) ||
929 (iptr->sx.val.i == 0x08000000) ||
930 (iptr->sx.val.i == 0x10000000) ||
931 (iptr->sx.val.i == 0x20000000) ||
932 (iptr->sx.val.i == 0x40000000) ||
933 (iptr->sx.val.i == 0x80000000))
935 iptr->opc = ICMD_IREMPOW2;
937 goto icmd_iconst_tail;
940 #if SUPPORT_CONST_LOGICAL
942 iptr->opc = ICMD_IANDCONST;
943 goto icmd_iconst_tail;
946 iptr->opc = ICMD_IORCONST;
947 goto icmd_iconst_tail;
950 iptr->opc = ICMD_IXORCONST;
951 goto icmd_iconst_tail;
953 #endif /* SUPPORT_CONST_LOGICAL */
955 iptr->opc = ICMD_ISHLCONST;
956 goto icmd_iconst_tail;
959 iptr->opc = ICMD_ISHRCONST;
960 goto icmd_iconst_tail;
963 iptr->opc = ICMD_IUSHRCONST;
964 goto icmd_iconst_tail;
965 #if SUPPORT_LONG_SHIFT
967 iptr->opc = ICMD_LSHLCONST;
968 goto icmd_lconst_tail;
971 iptr->opc = ICMD_LSHRCONST;
972 goto icmd_lconst_tail;
975 iptr->opc = ICMD_LUSHRCONST;
976 goto icmd_lconst_tail;
977 #endif /* SUPPORT_LONG_SHIFT */
979 iptr[1].opc = ICMD_IFEQ;
983 /* set the constant for the following icmd */
984 iptr[1].sx.val.i = iptr->sx.val.i;
986 /* this instruction becomes a nop */
987 iptr->opc = ICMD_NOP;
991 iptr[1].opc = ICMD_IFLT;
992 goto icmd_if_icmp_tail;
995 iptr[1].opc = ICMD_IFLE;
996 goto icmd_if_icmp_tail;
999 iptr[1].opc = ICMD_IFNE;
1000 goto icmd_if_icmp_tail;
1002 case ICMD_IF_ICMPGT:
1003 iptr[1].opc = ICMD_IFGT;
1004 goto icmd_if_icmp_tail;
1006 case ICMD_IF_ICMPGE:
1007 iptr[1].opc = ICMD_IFGE;
1008 goto icmd_if_icmp_tail;
1010 #if SUPPORT_CONST_STORE
1015 IF_INTRP( goto normal_ICONST; )
1016 # if SUPPORT_CONST_STORE_ZERO_ONLY
1017 if (iptr->sx.val.i != 0)
1020 switch (iptr[1].opc) {
1022 iptr->opc = ICMD_IASTORECONST;
1023 iptr->flags.bits |= INS_FLAG_CHECK;
1026 iptr->opc = ICMD_BASTORECONST;
1027 iptr->flags.bits |= INS_FLAG_CHECK;
1030 iptr->opc = ICMD_CASTORECONST;
1031 iptr->flags.bits |= INS_FLAG_CHECK;
1034 iptr->opc = ICMD_SASTORECONST;
1035 iptr->flags.bits |= INS_FLAG_CHECK;
1039 iptr[1].opc = ICMD_NOP;
1041 /* copy the constant to s3 */
1042 /* XXX constval -> astoreconstval? */
1043 iptr->sx.s23.s3.constval = iptr->sx.val.i;
1044 OP2_0(TYPE_ADR, TYPE_INT);
1045 COUNT(count_pcmd_op);
1048 case ICMD_PUTSTATIC:
1050 IF_INTRP( goto normal_ICONST; )
1051 # if SUPPORT_CONST_STORE_ZERO_ONLY
1052 if (iptr->sx.val.i != 0)
1055 /* XXX check field type? */
1057 /* copy the constant to s2 */
1058 /* XXX constval -> fieldconstval? */
1059 iptr->sx.s23.s2.constval = iptr->sx.val.i;
1062 /* set the field reference (s3) */
1063 if (iptr[1].flags.bits & INS_FLAG_UNRESOLVED) {
1064 iptr->sx.s23.s3.uf = iptr[1].sx.s23.s3.uf;
1065 iptr->flags.bits |= INS_FLAG_UNRESOLVED;
1068 iptr->sx.s23.s3.fmiref = iptr[1].sx.s23.s3.fmiref;
1071 switch (iptr[1].opc) {
1072 case ICMD_PUTSTATIC:
1073 iptr->opc = ICMD_PUTSTATICCONST;
1077 iptr->opc = ICMD_PUTFIELDCONST;
1082 iptr[1].opc = ICMD_NOP;
1083 COUNT(count_pcmd_op);
1085 #endif /* SUPPORT_CONST_STORE */
1091 /* if we get here, the ICONST has been optimized */
1095 /* normal case of an unoptimized ICONST */
1099 /************************** LCONST OPTIMIZATIONS **************************/
1102 COUNT(count_pcmd_load);
1106 /* switch depending on the following instruction */
1108 switch (iptr[1].opc) {
1109 #if SUPPORT_LONG_ADD
1111 iptr->opc = ICMD_LADDCONST;
1115 /* instruction of type LONG -> LONG */
1116 iptr[1].opc = ICMD_NOP;
1117 OP1_1(TYPE_LNG, TYPE_LNG);
1118 COUNT(count_pcmd_op);
1122 iptr->opc = ICMD_LSUBCONST;
1123 goto icmd_lconst_tail;
1125 #endif /* SUPPORT_LONG_ADD */
1126 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
1128 iptr->opc = ICMD_LMULCONST;
1129 goto icmd_lconst_tail;
1130 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1131 # if SUPPORT_LONG_SHIFT
1133 if (iptr->sx.val.l == 0x00000002)
1135 else if (iptr->sx.val.l == 0x00000004)
1137 else if (iptr->sx.val.l == 0x00000008)
1139 else if (iptr->sx.val.l == 0x00000010)
1141 else if (iptr->sx.val.l == 0x00000020)
1143 else if (iptr->sx.val.l == 0x00000040)
1145 else if (iptr->sx.val.l == 0x00000080)
1147 else if (iptr->sx.val.l == 0x00000100)
1149 else if (iptr->sx.val.l == 0x00000200)
1151 else if (iptr->sx.val.l == 0x00000400)
1152 iptr->sx.val.i = 10;
1153 else if (iptr->sx.val.l == 0x00000800)
1154 iptr->sx.val.i = 11;
1155 else if (iptr->sx.val.l == 0x00001000)
1156 iptr->sx.val.i = 12;
1157 else if (iptr->sx.val.l == 0x00002000)
1158 iptr->sx.val.i = 13;
1159 else if (iptr->sx.val.l == 0x00004000)
1160 iptr->sx.val.i = 14;
1161 else if (iptr->sx.val.l == 0x00008000)
1162 iptr->sx.val.i = 15;
1163 else if (iptr->sx.val.l == 0x00010000)
1164 iptr->sx.val.i = 16;
1165 else if (iptr->sx.val.l == 0x00020000)
1166 iptr->sx.val.i = 17;
1167 else if (iptr->sx.val.l == 0x00040000)
1168 iptr->sx.val.i = 18;
1169 else if (iptr->sx.val.l == 0x00080000)
1170 iptr->sx.val.i = 19;
1171 else if (iptr->sx.val.l == 0x00100000)
1172 iptr->sx.val.i = 20;
1173 else if (iptr->sx.val.l == 0x00200000)
1174 iptr->sx.val.i = 21;
1175 else if (iptr->sx.val.l == 0x00400000)
1176 iptr->sx.val.i = 22;
1177 else if (iptr->sx.val.l == 0x00800000)
1178 iptr->sx.val.i = 23;
1179 else if (iptr->sx.val.l == 0x01000000)
1180 iptr->sx.val.i = 24;
1181 else if (iptr->sx.val.l == 0x02000000)
1182 iptr->sx.val.i = 25;
1183 else if (iptr->sx.val.l == 0x04000000)
1184 iptr->sx.val.i = 26;
1185 else if (iptr->sx.val.l == 0x08000000)
1186 iptr->sx.val.i = 27;
1187 else if (iptr->sx.val.l == 0x10000000)
1188 iptr->sx.val.i = 28;
1189 else if (iptr->sx.val.l == 0x20000000)
1190 iptr->sx.val.i = 29;
1191 else if (iptr->sx.val.l == 0x40000000)
1192 iptr->sx.val.i = 30;
1193 else if (iptr->sx.val.l == 0x80000000)
1194 iptr->sx.val.i = 31;
1198 iptr->opc = ICMD_LMULPOW2;
1199 goto icmd_lconst_tail;
1200 # endif /* SUPPORT_LONG_SHIFT */
1201 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1202 #if SUPPORT_LONG_DIV_POW2
1204 if (iptr->sx.val.l == 0x00000002)
1206 else if (iptr->sx.val.l == 0x00000004)
1208 else if (iptr->sx.val.l == 0x00000008)
1210 else if (iptr->sx.val.l == 0x00000010)
1212 else if (iptr->sx.val.l == 0x00000020)
1214 else if (iptr->sx.val.l == 0x00000040)
1216 else if (iptr->sx.val.l == 0x00000080)
1218 else if (iptr->sx.val.l == 0x00000100)
1220 else if (iptr->sx.val.l == 0x00000200)
1222 else if (iptr->sx.val.l == 0x00000400)
1223 iptr->sx.val.i = 10;
1224 else if (iptr->sx.val.l == 0x00000800)
1225 iptr->sx.val.i = 11;
1226 else if (iptr->sx.val.l == 0x00001000)
1227 iptr->sx.val.i = 12;
1228 else if (iptr->sx.val.l == 0x00002000)
1229 iptr->sx.val.i = 13;
1230 else if (iptr->sx.val.l == 0x00004000)
1231 iptr->sx.val.i = 14;
1232 else if (iptr->sx.val.l == 0x00008000)
1233 iptr->sx.val.i = 15;
1234 else if (iptr->sx.val.l == 0x00010000)
1235 iptr->sx.val.i = 16;
1236 else if (iptr->sx.val.l == 0x00020000)
1237 iptr->sx.val.i = 17;
1238 else if (iptr->sx.val.l == 0x00040000)
1239 iptr->sx.val.i = 18;
1240 else if (iptr->sx.val.l == 0x00080000)
1241 iptr->sx.val.i = 19;
1242 else if (iptr->sx.val.l == 0x00100000)
1243 iptr->sx.val.i = 20;
1244 else if (iptr->sx.val.l == 0x00200000)
1245 iptr->sx.val.i = 21;
1246 else if (iptr->sx.val.l == 0x00400000)
1247 iptr->sx.val.i = 22;
1248 else if (iptr->sx.val.l == 0x00800000)
1249 iptr->sx.val.i = 23;
1250 else if (iptr->sx.val.l == 0x01000000)
1251 iptr->sx.val.i = 24;
1252 else if (iptr->sx.val.l == 0x02000000)
1253 iptr->sx.val.i = 25;
1254 else if (iptr->sx.val.l == 0x04000000)
1255 iptr->sx.val.i = 26;
1256 else if (iptr->sx.val.l == 0x08000000)
1257 iptr->sx.val.i = 27;
1258 else if (iptr->sx.val.l == 0x10000000)
1259 iptr->sx.val.i = 28;
1260 else if (iptr->sx.val.l == 0x20000000)
1261 iptr->sx.val.i = 29;
1262 else if (iptr->sx.val.l == 0x40000000)
1263 iptr->sx.val.i = 30;
1264 else if (iptr->sx.val.l == 0x80000000)
1265 iptr->sx.val.i = 31;
1269 iptr->opc = ICMD_LDIVPOW2;
1270 goto icmd_lconst_tail;
1271 #endif /* SUPPORT_LONG_DIV_POW2 */
1273 #if SUPPORT_LONG_REM_POW2
1275 if ((iptr->sx.val.l == 0x00000002) ||
1276 (iptr->sx.val.l == 0x00000004) ||
1277 (iptr->sx.val.l == 0x00000008) ||
1278 (iptr->sx.val.l == 0x00000010) ||
1279 (iptr->sx.val.l == 0x00000020) ||
1280 (iptr->sx.val.l == 0x00000040) ||
1281 (iptr->sx.val.l == 0x00000080) ||
1282 (iptr->sx.val.l == 0x00000100) ||
1283 (iptr->sx.val.l == 0x00000200) ||
1284 (iptr->sx.val.l == 0x00000400) ||
1285 (iptr->sx.val.l == 0x00000800) ||
1286 (iptr->sx.val.l == 0x00001000) ||
1287 (iptr->sx.val.l == 0x00002000) ||
1288 (iptr->sx.val.l == 0x00004000) ||
1289 (iptr->sx.val.l == 0x00008000) ||
1290 (iptr->sx.val.l == 0x00010000) ||
1291 (iptr->sx.val.l == 0x00020000) ||
1292 (iptr->sx.val.l == 0x00040000) ||
1293 (iptr->sx.val.l == 0x00080000) ||
1294 (iptr->sx.val.l == 0x00100000) ||
1295 (iptr->sx.val.l == 0x00200000) ||
1296 (iptr->sx.val.l == 0x00400000) ||
1297 (iptr->sx.val.l == 0x00800000) ||
1298 (iptr->sx.val.l == 0x01000000) ||
1299 (iptr->sx.val.l == 0x02000000) ||
1300 (iptr->sx.val.l == 0x04000000) ||
1301 (iptr->sx.val.l == 0x08000000) ||
1302 (iptr->sx.val.l == 0x10000000) ||
1303 (iptr->sx.val.l == 0x20000000) ||
1304 (iptr->sx.val.l == 0x40000000) ||
1305 (iptr->sx.val.l == 0x80000000))
1307 iptr->opc = ICMD_LREMPOW2;
1308 iptr->sx.val.l -= 1;
1309 goto icmd_lconst_tail;
1312 #endif /* SUPPORT_LONG_REM_POW2 */
1314 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
1317 iptr->opc = ICMD_LANDCONST;
1318 goto icmd_lconst_tail;
1321 iptr->opc = ICMD_LORCONST;
1322 goto icmd_lconst_tail;
1325 iptr->opc = ICMD_LXORCONST;
1326 goto icmd_lconst_tail;
1327 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
1329 #if SUPPORT_LONG_CMP_CONST
1331 if ((len <= 1) || (iptr[2].sx.val.i != 0))
1334 /* switch on the instruction after LCONST - LCMP */
1336 switch (iptr[2].opc) {
1338 iptr->opc = ICMD_IF_LEQ;
1341 icmd_lconst_lcmp_tail:
1342 /* convert LCONST, LCMP, IFXX to IF_LXX */
1343 iptr->dst.insindex = iptr[2].dst.insindex;
1344 iptr[1].opc = ICMD_NOP;
1345 iptr[2].opc = ICMD_NOP;
1347 OP1_BRANCH(TYPE_LNG);
1348 BRANCH(tbptr, copy);
1349 COUNT(count_pcmd_bra);
1350 COUNT(count_pcmd_op);
1354 iptr->opc = ICMD_IF_LNE;
1355 goto icmd_lconst_lcmp_tail;
1358 iptr->opc = ICMD_IF_LLT;
1359 goto icmd_lconst_lcmp_tail;
1362 iptr->opc = ICMD_IF_LGT;
1363 goto icmd_lconst_lcmp_tail;
1366 iptr->opc = ICMD_IF_LLE;
1367 goto icmd_lconst_lcmp_tail;
1370 iptr->opc = ICMD_IF_LGE;
1371 goto icmd_lconst_lcmp_tail;
1375 } /* end switch on opcode after LCONST - LCMP */
1377 #endif /* SUPPORT_LONG_CMP_CONST */
1379 #if SUPPORT_CONST_STORE
1381 IF_INTRP( goto normal_LCONST; )
1382 # if SUPPORT_CONST_STORE_ZERO_ONLY
1383 if (iptr->sx.val.l != 0)
1386 #if SIZEOF_VOID_P == 4
1387 /* the constant must fit into a ptrint */
1388 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1391 /* move the constant to s3 */
1392 iptr->sx.s23.s3.constval = iptr->sx.val.l;
1394 iptr->opc = ICMD_LASTORECONST;
1395 iptr->flags.bits |= INS_FLAG_CHECK;
1396 OP2_0(TYPE_ADR, TYPE_INT);
1398 iptr[1].opc = ICMD_NOP;
1399 COUNT(count_pcmd_op);
1402 case ICMD_PUTSTATIC:
1404 IF_INTRP( goto normal_LCONST; )
1405 # if SUPPORT_CONST_STORE_ZERO_ONLY
1406 if (iptr->sx.val.l != 0)
1409 #if SIZEOF_VOID_P == 4
1410 /* the constant must fit into a ptrint */
1411 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1414 /* XXX check field type? */
1416 /* copy the constant to s2 */
1417 /* XXX constval -> fieldconstval? */
1418 iptr->sx.s23.s2.constval = iptr->sx.val.l;
1422 #endif /* SUPPORT_CONST_STORE */
1426 } /* end switch opcode after LCONST */
1428 /* if we get here, the LCONST has been optimized */
1432 /* the normal case of an unoptimized LCONST */
1436 /************************ END OF LCONST OPTIMIZATIONS *********************/
1439 COUNT(count_pcmd_load);
1444 COUNT(count_pcmd_load);
1448 /************************** ACONST OPTIMIZATIONS **************************/
1451 last_pei_boundary = new;
1452 COUNT(count_pcmd_load);
1453 #if SUPPORT_CONST_STORE
1454 IF_INTRP( goto normal_ACONST; )
1456 /* We can only optimize if the ACONST is resolved
1457 * and there is an instruction after it. */
1459 if ((len == 0) || (iptr->flags.bits & INS_FLAG_UNRESOLVED))
1462 switch (iptr[1].opc) {
1464 /* We can only optimize for NULL values
1465 * here because otherwise a checkcast is
1467 if (iptr->sx.val.anyptr != NULL)
1470 /* copy the constant (NULL) to s3 */
1471 iptr->sx.s23.s3.constval = 0;
1472 iptr->opc = ICMD_AASTORECONST;
1473 iptr->flags.bits |= INS_FLAG_CHECK;
1474 OP2_0(TYPE_ADR, TYPE_INT);
1476 iptr[1].opc = ICMD_NOP;
1477 COUNT(count_pcmd_op);
1480 case ICMD_PUTSTATIC:
1482 # if SUPPORT_CONST_STORE_ZERO_ONLY
1483 if (iptr->sx.val.anyptr != NULL)
1486 /* XXX check field type? */
1487 /* copy the constant to s2 */
1488 /* XXX constval -> fieldconstval? */
1489 iptr->sx.s23.s2.constval = (ptrint) iptr->sx.val.anyptr;
1497 /* if we get here the ACONST has been optimized */
1501 #endif /* SUPPORT_CONST_STORE */
1506 /* pop 0 push 1 load */
1513 COUNT(count_load_instruction);
1514 i = opcode - ICMD_ILOAD;
1515 #if defined(NEW_VAR)
1517 jd->local_map[iptr->s1.varindex * 5 + i];
1519 LOAD(i, iptr->s1.varindex);
1522 IF_NO_INTRP( rd->locals[iptr->s1.localindex][i].type =
1524 LOAD(i, iptr->s1.localindex);
1534 last_pei_boundary = new;
1535 iptr->flags.bits |= INS_FLAG_CHECK;
1536 COUNT(count_check_null);
1537 COUNT(count_check_bound);
1538 COUNT(count_pcmd_mem);
1539 OP2_1(TYPE_ADR, TYPE_INT, opcode - ICMD_IALOAD);
1546 last_pei_boundary = new;
1547 iptr->flags.bits |= INS_FLAG_CHECK;
1548 COUNT(count_check_null);
1549 COUNT(count_check_bound);
1550 COUNT(count_pcmd_mem);
1551 OP2_1(TYPE_ADR, TYPE_INT, TYPE_INT);
1554 /* pop 0 push 0 iinc */
1557 STATISTICS_STACKDEPTH_DISTRIBUTION(count_store_depth);
1559 #if defined(NEW_VAR)
1561 jd->local_map[iptr->s1.varindex * 5 + i];
1563 last_store_boundary[iptr->s1.varindex] = new;
1565 last_store_boundary[iptr->s1.localindex] = new;
1571 if ((copy->varkind == LOCALVAR) &&
1572 (copy->varnum == iptr->s1.localindex))
1574 copy->varkind = TEMPVAR;
1575 #if defined(NEW_VAR)
1576 GET_NEW_INDEX(new_index);
1577 copy->varnum = new_index;
1586 #if defined(NEW_VAR)
1587 iptr->dst.varindex = iptr->s1.varindex;
1589 iptr->dst.localindex = iptr->s1.localindex;
1593 /* pop 1 push 0 store */
1602 i = opcode - ICMD_ISTORE; /* type */
1603 #if defined(NEW_VAR)
1604 j = iptr->dst.varindex =
1605 jd->local_map[iptr->dst.varindex * 5 + 1]:
1608 j = iptr->dst.localindex; /* index */
1610 IF_NO_INTRP( rd->locals[j][i].type = i; )
1613 #if defined(ENABLE_STATISTICS)
1618 count_store_length[20]++;
1620 count_store_length[i]++;
1623 count_store_depth[10]++;
1625 count_store_depth[i]++;
1628 /* check for conflicts as described in Figure 5.2 */
1630 copy = curstack->prev;
1633 if ((copy->varkind == LOCALVAR) &&
1634 (copy->varnum == j))
1636 copy->varkind = TEMPVAR;
1637 #if defined(NEW_VAR)
1638 GET_NEW_INDEX(new_index);
1639 copy->varnum = new_index;
1648 /* if the variable is already coalesced, don't bother */
1650 if (curstack->varkind == STACKVAR
1651 || (curstack->varkind == LOCALVAR
1652 && curstack->varnum != j))
1655 /* there is no STORE Lj while curstack is live */
1657 if (curstack < last_store_boundary[j])
1658 goto assume_conflict;
1660 /* there is no PEI while curstack is live */
1662 if (curstack < last_pei_boundary)
1663 goto assume_conflict;
1665 /* there is no non-consuming USE while curstack is live */
1667 if (curstack < last_dup_boundary)
1668 goto assume_conflict;
1670 /* there is no DEF LOCALVAR(j) while curstack is live */
1672 copy = new; /* most recent stackslot created + 1 */
1673 while (--copy > curstack) {
1674 if (copy->varkind == LOCALVAR && copy->varnum == j)
1675 goto assume_conflict;
1678 /* coalesce the temporary variable with Lj */
1679 #if defined(NEW_VAR)
1680 assert(currstack->varkind == TEMPVAR);
1681 RELEASE_INDEX(curstack->varnum);
1683 curstack->varkind = LOCALVAR;
1684 curstack->varnum = j;
1687 /* revert the coalescing, if it has been done earlier */
1689 if ((curstack->varkind == LOCALVAR)
1690 && (curstack->varnum == j))
1692 curstack->varkind = TEMPVAR;
1693 #if defined(NEW_VAR)
1694 GET_NEW_INDEX(new_index);
1695 curstack->varnum = new_index;
1697 curstack->varnum = stackdepth-1;
1701 /* remember the stack boundary at this store */
1703 last_store_boundary[j] = new;
1705 STORE(opcode - ICMD_ISTORE, j);
1711 last_pei_boundary = new;
1712 iptr->flags.bits |= INS_FLAG_CHECK;
1713 COUNT(count_check_null);
1714 COUNT(count_check_bound);
1715 COUNT(count_pcmd_mem);
1717 bte = builtintable_get_internal(BUILTIN_canstore);
1720 if (md->memuse > rd->memuse)
1721 rd->memuse = md->memuse;
1722 if (md->argintreguse > rd->argintreguse)
1723 rd->argintreguse = md->argintreguse;
1724 /* XXX non-leaf method? */
1726 /* make all stack variables saved */
1730 copy->flags |= SAVEDVAR;
1734 OP3_0(TYPE_ADR, TYPE_INT, TYPE_ADR);
1741 last_pei_boundary = new;
1742 iptr->flags.bits |= INS_FLAG_CHECK;
1743 COUNT(count_check_null);
1744 COUNT(count_check_bound);
1745 COUNT(count_pcmd_mem);
1746 OP3_0(TYPE_ADR, TYPE_INT, opcode - ICMD_IASTORE);
1753 last_pei_boundary = new;
1754 iptr->flags.bits |= INS_FLAG_CHECK;
1755 COUNT(count_check_null);
1756 COUNT(count_check_bound);
1757 COUNT(count_pcmd_mem);
1758 OP3_0(TYPE_ADR, TYPE_INT, TYPE_INT);
1764 #ifdef ENABLE_VERIFIER
1767 if (IS_2_WORD_TYPE(curstack->type))
1768 goto throw_stack_category_error;
1779 last_pei_boundary = new;
1780 IF_JIT( md_return_alloc(jd, curstack); )
1781 COUNT(count_pcmd_return);
1782 OP1_0(opcode - ICMD_IRETURN);
1783 superblockend = true;
1787 last_pei_boundary = new;
1788 COUNT(count_check_null);
1791 superblockend = true;
1794 case ICMD_PUTSTATIC:
1795 last_pei_boundary = new;
1796 COUNT(count_pcmd_mem);
1797 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1798 OP1_0(fmiref->parseddesc.fd->type);
1801 /* pop 1 push 0 branch */
1804 case ICMD_IFNONNULL:
1805 COUNT(count_pcmd_bra);
1806 OP1_BRANCH(TYPE_ADR);
1807 BRANCH(tbptr, copy);
1816 COUNT(count_pcmd_bra);
1817 /* iptr->sx.val.i is set implicitly in parse by
1818 clearing the memory or from IF_ICMPxx
1821 OP1_BRANCH(TYPE_INT);
1822 /* iptr->sx.val.i = 0; */
1823 BRANCH(tbptr, copy);
1826 /* pop 0 push 0 branch */
1829 COUNT(count_pcmd_bra);
1831 BRANCH(tbptr, copy);
1832 superblockend = true;
1835 /* pop 1 push 0 table branch */
1837 case ICMD_TABLESWITCH:
1838 COUNT(count_pcmd_table);
1839 OP1_BRANCH(TYPE_INT);
1841 table = iptr->dst.table;
1842 BRANCH_TARGET(*table, tbptr, copy);
1845 i = iptr->sx.s23.s3.tablehigh
1846 - iptr->sx.s23.s2.tablelow + 1;
1849 BRANCH_TARGET(*table, tbptr, copy);
1852 superblockend = true;
1855 /* pop 1 push 0 table branch */
1857 case ICMD_LOOKUPSWITCH:
1858 COUNT(count_pcmd_table);
1859 OP1_BRANCH(TYPE_INT);
1861 BRANCH_TARGET(iptr->sx.s23.s3.lookupdefault, tbptr, copy);
1863 lookup = iptr->dst.lookup;
1865 i = iptr->sx.s23.s2.lookupcount;
1868 BRANCH_TARGET(lookup->target, tbptr, copy);
1871 superblockend = true;
1874 case ICMD_MONITORENTER:
1875 case ICMD_MONITOREXIT:
1876 last_pei_boundary = new;
1877 COUNT(count_check_null);
1881 /* pop 2 push 0 branch */
1883 case ICMD_IF_ICMPEQ:
1884 case ICMD_IF_ICMPNE:
1885 case ICMD_IF_ICMPLT:
1886 case ICMD_IF_ICMPGE:
1887 case ICMD_IF_ICMPGT:
1888 case ICMD_IF_ICMPLE:
1889 COUNT(count_pcmd_bra);
1890 OP2_BRANCH(TYPE_INT, TYPE_INT);
1891 BRANCH(tbptr, copy);
1894 case ICMD_IF_ACMPEQ:
1895 case ICMD_IF_ACMPNE:
1896 COUNT(count_pcmd_bra);
1897 OP2_BRANCH(TYPE_ADR, TYPE_ADR);
1898 BRANCH(tbptr, copy);
1904 last_pei_boundary = new;
1905 COUNT(count_check_null);
1906 COUNT(count_pcmd_mem);
1907 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1908 OP2_0(TYPE_ADR, fmiref->parseddesc.fd->type);
1913 if (!IS_2_WORD_TYPE(curstack->type)) {
1915 #ifdef ENABLE_VERIFIER
1918 if (IS_2_WORD_TYPE(curstack->prev->type))
1919 goto throw_stack_category_error;
1922 OP2_0_ANY_ANY; /* pop two slots */
1925 iptr->opc = ICMD_POP;
1926 OP1_0_ANY; /* pop one (two-word) slot */
1930 /* pop 0 push 1 dup */
1933 #ifdef ENABLE_VERIFIER
1936 if (IS_2_WORD_TYPE(curstack->type))
1937 goto throw_stack_category_error;
1940 COUNT(count_dup_instruction);
1943 USE_S1_ANY; /* XXX live through */
1944 /* DUP_SLOT(iptr->s1.var); */
1946 last_dup_boundary = new - 1;
1947 #if defined(NEW_VAR)
1948 iptr->dst.varindex = curstack->varnum;
1950 iptr->dst.var = curstack;
1957 if (IS_2_WORD_TYPE(curstack->type)) {
1959 iptr->opc = ICMD_DUP;
1964 /* ..., ????, cat1 */
1965 #ifdef ENABLE_VERIFIER
1967 if (IS_2_WORD_TYPE(curstack->prev->type))
1968 goto throw_stack_category_error;
1971 iptr->dst.dupslots = DMNEW(stackptr, 2 + 2);
1972 iptr->dst.dupslots[0] = curstack->prev; /* XXX live through */
1973 iptr->dst.dupslots[1] = curstack; /* XXX live through */
1975 DUP_SLOT(iptr->dst.dupslots[0]);
1976 iptr->dst.dupslots[2+0] = curstack;
1977 DUP_SLOT(iptr->dst.dupslots[1]);
1978 iptr->dst.dupslots[2+1] = curstack;
1979 last_dup_boundary = new;
1984 /* pop 2 push 3 dup */
1987 #ifdef ENABLE_VERIFIER
1990 if (IS_2_WORD_TYPE(curstack->type) ||
1991 IS_2_WORD_TYPE(curstack->prev->type))
1992 goto throw_stack_category_error;
1997 iptr->dst.dupslots = DMNEW(stackptr, 2 + 3);
1998 iptr->dst.dupslots[0] = curstack->prev;
1999 iptr->dst.dupslots[1] = curstack;
2002 DUP_SLOT(iptr->dst.dupslots[1]);
2003 iptr->dst.dupslots[2+0] = curstack;
2004 DUP_SLOT(iptr->dst.dupslots[0]);
2005 iptr->dst.dupslots[2+1] = curstack;
2006 DUP_SLOT(iptr->dst.dupslots[1]);
2007 iptr->dst.dupslots[2+2] = curstack;
2008 last_dup_boundary = new;
2014 if (IS_2_WORD_TYPE(curstack->type)) {
2015 /* ..., ????, cat2 */
2016 #ifdef ENABLE_VERIFIER
2018 if (IS_2_WORD_TYPE(curstack->prev->type))
2019 goto throw_stack_category_error;
2022 iptr->opc = ICMD_DUP_X1;
2026 /* ..., ????, cat1 */
2027 #ifdef ENABLE_VERIFIER
2030 if (IS_2_WORD_TYPE(curstack->prev->type)
2031 || IS_2_WORD_TYPE(curstack->prev->prev->type))
2032 goto throw_stack_category_error;
2037 iptr->dst.dupslots = DMNEW(stackptr, 3 + 5);
2038 iptr->dst.dupslots[0] = curstack->prev->prev;
2039 iptr->dst.dupslots[1] = curstack->prev;
2040 iptr->dst.dupslots[2] = curstack;
2041 POPANY; POPANY; POPANY;
2043 DUP_SLOT(iptr->dst.dupslots[1]);
2044 iptr->dst.dupslots[3+0] = curstack;
2045 DUP_SLOT(iptr->dst.dupslots[2]);
2046 iptr->dst.dupslots[3+1] = curstack;
2047 DUP_SLOT(iptr->dst.dupslots[0]);
2048 iptr->dst.dupslots[3+2] = curstack;
2049 DUP_SLOT(iptr->dst.dupslots[1]);
2050 iptr->dst.dupslots[3+3] = curstack;
2051 DUP_SLOT(iptr->dst.dupslots[2]);
2052 iptr->dst.dupslots[3+4] = curstack;
2053 last_dup_boundary = new;
2058 /* pop 3 push 4 dup */
2062 if (IS_2_WORD_TYPE(curstack->prev->type)) {
2063 /* ..., cat2, ???? */
2064 #ifdef ENABLE_VERIFIER
2066 if (IS_2_WORD_TYPE(curstack->type))
2067 goto throw_stack_category_error;
2070 iptr->opc = ICMD_DUP_X1;
2074 /* ..., cat1, ???? */
2075 #ifdef ENABLE_VERIFIER
2078 if (IS_2_WORD_TYPE(curstack->type)
2079 || IS_2_WORD_TYPE(curstack->prev->prev->type))
2080 goto throw_stack_category_error;
2084 iptr->dst.dupslots = DMNEW(stackptr, 3 + 4);
2085 iptr->dst.dupslots[0] = curstack->prev->prev;
2086 iptr->dst.dupslots[1] = curstack->prev;
2087 iptr->dst.dupslots[2] = curstack;
2088 POPANY; POPANY; POPANY;
2090 DUP_SLOT(iptr->dst.dupslots[2]);
2091 iptr->dst.dupslots[3+0] = curstack;
2092 DUP_SLOT(iptr->dst.dupslots[0]);
2093 iptr->dst.dupslots[3+1] = curstack;
2094 DUP_SLOT(iptr->dst.dupslots[1]);
2095 iptr->dst.dupslots[3+2] = curstack;
2096 DUP_SLOT(iptr->dst.dupslots[2]);
2097 iptr->dst.dupslots[3+3] = curstack;
2098 last_dup_boundary = new;
2105 if (IS_2_WORD_TYPE(curstack->type)) {
2106 /* ..., ????, cat2 */
2107 if (IS_2_WORD_TYPE(curstack->prev->type)) {
2108 /* ..., cat2, cat2 */
2109 iptr->opc = ICMD_DUP_X1;
2113 /* ..., cat1, cat2 */
2114 #ifdef ENABLE_VERIFIER
2117 if (IS_2_WORD_TYPE(curstack->prev->prev->type))
2118 goto throw_stack_category_error;
2121 iptr->opc = ICMD_DUP_X2;
2127 /* ..., ????, ????, cat1 */
2129 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
2130 /* ..., cat2, ????, cat1 */
2131 #ifdef ENABLE_VERIFIER
2133 if (IS_2_WORD_TYPE(curstack->prev->type))
2134 goto throw_stack_category_error;
2137 iptr->opc = ICMD_DUP2_X1;
2141 /* ..., cat1, ????, cat1 */
2142 #ifdef ENABLE_VERIFIER
2145 if (IS_2_WORD_TYPE(curstack->prev->type)
2146 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
2147 goto throw_stack_category_error;
2150 iptr->dst.dupslots = DMNEW(stackptr, 4 + 6);
2151 iptr->dst.dupslots[0] = curstack->prev->prev->prev;
2152 iptr->dst.dupslots[1] = curstack->prev->prev;
2153 iptr->dst.dupslots[2] = curstack->prev;
2154 iptr->dst.dupslots[3] = curstack;
2155 POPANY; POPANY; POPANY; POPANY;
2157 DUP_SLOT(iptr->dst.dupslots[2]);
2158 iptr->dst.dupslots[4+0] = curstack;
2159 DUP_SLOT(iptr->dst.dupslots[3]);
2160 iptr->dst.dupslots[4+1] = curstack;
2161 DUP_SLOT(iptr->dst.dupslots[0]);
2162 iptr->dst.dupslots[4+2] = curstack;
2163 DUP_SLOT(iptr->dst.dupslots[1]);
2164 iptr->dst.dupslots[4+3] = curstack;
2165 DUP_SLOT(iptr->dst.dupslots[2]);
2166 iptr->dst.dupslots[4+4] = curstack;
2167 DUP_SLOT(iptr->dst.dupslots[3]);
2168 iptr->dst.dupslots[4+5] = curstack;
2169 last_dup_boundary = new;
2174 /* pop 2 push 2 swap */
2177 #ifdef ENABLE_VERIFIER
2180 if (IS_2_WORD_TYPE(curstack->type)
2181 || IS_2_WORD_TYPE(curstack->prev->type))
2182 goto throw_stack_category_error;
2185 iptr->dst.dupslots = DMNEW(stackptr, 2 + 2);
2186 iptr->dst.dupslots[0] = curstack->prev;
2187 iptr->dst.dupslots[1] = curstack;
2190 DUP_SLOT(iptr->dst.dupslots[1]);
2191 iptr->dst.dupslots[2+0] = curstack;
2192 DUP_SLOT(iptr->dst.dupslots[0]);
2193 iptr->dst.dupslots[2+1] = curstack;
2194 last_dup_boundary = new;
2201 last_pei_boundary = new;
2202 #if !SUPPORT_DIVISION
2203 bte = iptr->sx.s23.s3.bte;
2206 if (md->memuse > rd->memuse)
2207 rd->memuse = md->memuse;
2208 if (md->argintreguse > rd->argintreguse)
2209 rd->argintreguse = md->argintreguse;
2211 /* make all stack variables saved */
2215 copy->flags |= SAVEDVAR;
2220 #endif /* !SUPPORT_DIVISION */
2231 COUNT(count_pcmd_op);
2232 OP2_1(TYPE_INT, TYPE_INT, TYPE_INT);
2237 last_pei_boundary = new;
2238 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
2239 bte = iptr->sx.s23.s3.bte;
2242 if (md->memuse > rd->memuse)
2243 rd->memuse = md->memuse;
2244 if (md->argintreguse > rd->argintreguse)
2245 rd->argintreguse = md->argintreguse;
2246 /* XXX non-leaf method? */
2248 /* make all stack variables saved */
2252 copy->flags |= SAVEDVAR;
2257 #endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
2262 #if SUPPORT_LONG_LOGICAL
2266 #endif /* SUPPORT_LONG_LOGICAL */
2267 COUNT(count_pcmd_op);
2268 OP2_1(TYPE_LNG, TYPE_LNG, TYPE_LNG);
2274 COUNT(count_pcmd_op);
2275 OP2_1(TYPE_LNG, TYPE_INT, TYPE_LNG);
2283 COUNT(count_pcmd_op);
2284 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_FLT);
2292 COUNT(count_pcmd_op);
2293 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_DBL);
2297 COUNT(count_pcmd_op);
2298 #if SUPPORT_LONG_CMP_CONST
2299 if ((len == 0) || (iptr[1].sx.val.i != 0))
2302 switch (iptr[1].opc) {
2304 iptr->opc = ICMD_IF_LCMPEQ;
2306 iptr->dst.insindex = iptr[1].dst.insindex;
2307 iptr[1].opc = ICMD_NOP;
2309 OP2_BRANCH(TYPE_LNG, TYPE_LNG);
2310 BRANCH(tbptr, copy);
2312 COUNT(count_pcmd_bra);
2315 iptr->opc = ICMD_IF_LCMPNE;
2316 goto icmd_lcmp_if_tail;
2318 iptr->opc = ICMD_IF_LCMPLT;
2319 goto icmd_lcmp_if_tail;
2321 iptr->opc = ICMD_IF_LCMPGT;
2322 goto icmd_lcmp_if_tail;
2324 iptr->opc = ICMD_IF_LCMPLE;
2325 goto icmd_lcmp_if_tail;
2327 iptr->opc = ICMD_IF_LCMPGE;
2328 goto icmd_lcmp_if_tail;
2334 #endif /* SUPPORT_LONG_CMP_CONST */
2335 OP2_1(TYPE_LNG, TYPE_LNG, TYPE_INT);
2338 /* XXX why is this deactivated? */
2341 COUNT(count_pcmd_op);
2342 if ((len == 0) || (iptr[1].sx.val.i != 0))
2345 switch (iptr[1].opc) {
2347 iptr->opc = ICMD_IF_FCMPEQ;
2349 iptr->dst.insindex = iptr[1].dst.insindex;
2350 iptr[1].opc = ICMD_NOP;
2352 OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2353 BRANCH(tbptr, copy);
2355 COUNT(count_pcmd_bra);
2358 iptr->opc = ICMD_IF_FCMPNE;
2359 goto icmd_if_fcmpl_tail;
2361 iptr->opc = ICMD_IF_FCMPL_LT;
2362 goto icmd_if_fcmpl_tail;
2364 iptr->opc = ICMD_IF_FCMPL_GT;
2365 goto icmd_if_fcmpl_tail;
2367 iptr->opc = ICMD_IF_FCMPL_LE;
2368 goto icmd_if_fcmpl_tail;
2370 iptr->opc = ICMD_IF_FCMPL_GE;
2371 goto icmd_if_fcmpl_tail;
2378 OPTT2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2382 COUNT(count_pcmd_op);
2383 if ((len == 0) || (iptr[1].sx.val.i != 0))
2386 switch (iptr[1].opc) {
2388 iptr->opc = ICMD_IF_FCMPEQ;
2390 iptr->dst.insindex = iptr[1].dst.insindex;
2391 iptr[1].opc = ICMD_NOP;
2393 OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2394 BRANCH(tbptr, copy);
2396 COUNT(count_pcmd_bra);
2399 iptr->opc = ICMD_IF_FCMPNE;
2400 goto icmd_if_fcmpg_tail;
2402 iptr->opc = ICMD_IF_FCMPG_LT;
2403 goto icmd_if_fcmpg_tail;
2405 iptr->opc = ICMD_IF_FCMPG_GT;
2406 goto icmd_if_fcmpg_tail;
2408 iptr->opc = ICMD_IF_FCMPG_LE;
2409 goto icmd_if_fcmpg_tail;
2411 iptr->opc = ICMD_IF_FCMPG_GE;
2412 goto icmd_if_fcmpg_tail;
2419 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2423 COUNT(count_pcmd_op);
2424 if ((len == 0) || (iptr[1].sx.val.i != 0))
2427 switch (iptr[1].opc) {
2429 iptr->opc = ICMD_IF_DCMPEQ;
2431 iptr->dst.insindex = iptr[1].dst.insindex;
2432 iptr[1].opc = ICMD_NOP;
2434 OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2435 BRANCH(tbptr, copy);
2437 COUNT(count_pcmd_bra);
2440 iptr->opc = ICMD_IF_DCMPNE;
2441 goto icmd_if_dcmpl_tail;
2443 iptr->opc = ICMD_IF_DCMPL_LT;
2444 goto icmd_if_dcmpl_tail;
2446 iptr->opc = ICMD_IF_DCMPL_GT;
2447 goto icmd_if_dcmpl_tail;
2449 iptr->opc = ICMD_IF_DCMPL_LE;
2450 goto icmd_if_dcmpl_tail;
2452 iptr->opc = ICMD_IF_DCMPL_GE;
2453 goto icmd_if_dcmpl_tail;
2460 OPTT2_1(TYPE_DBL, TYPE_INT);
2464 COUNT(count_pcmd_op);
2465 if ((len == 0) || (iptr[1].sx.val.i != 0))
2468 switch (iptr[1].opc) {
2470 iptr->opc = ICMD_IF_DCMPEQ;
2472 iptr->dst.insindex = iptr[1].dst.insindex;
2473 iptr[1].opc = ICMD_NOP;
2475 OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2476 BRANCH(tbptr, copy);
2478 COUNT(count_pcmd_bra);
2481 iptr->opc = ICMD_IF_DCMPNE;
2482 goto icmd_if_dcmpg_tail;
2484 iptr->opc = ICMD_IF_DCMPG_LT;
2485 goto icmd_if_dcmpg_tail;
2487 iptr->opc = ICMD_IF_DCMPG_GT;
2488 goto icmd_if_dcmpg_tail;
2490 iptr->opc = ICMD_IF_DCMPG_LE;
2491 goto icmd_if_dcmpg_tail;
2493 iptr->opc = ICMD_IF_DCMPG_GE;
2494 goto icmd_if_dcmpg_tail;
2501 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2506 COUNT(count_pcmd_op);
2507 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2512 COUNT(count_pcmd_op);
2513 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2522 case ICMD_INT2SHORT:
2523 COUNT(count_pcmd_op);
2524 OP1_1(TYPE_INT, TYPE_INT);
2527 COUNT(count_pcmd_op);
2528 OP1_1(TYPE_LNG, TYPE_LNG);
2531 COUNT(count_pcmd_op);
2532 OP1_1(TYPE_FLT, TYPE_FLT);
2535 COUNT(count_pcmd_op);
2536 OP1_1(TYPE_DBL, TYPE_DBL);
2540 COUNT(count_pcmd_op);
2541 OP1_1(TYPE_INT, TYPE_LNG);
2544 COUNT(count_pcmd_op);
2545 OP1_1(TYPE_INT, TYPE_FLT);
2548 COUNT(count_pcmd_op);
2549 OP1_1(TYPE_INT, TYPE_DBL);
2552 COUNT(count_pcmd_op);
2553 OP1_1(TYPE_LNG, TYPE_INT);
2556 COUNT(count_pcmd_op);
2557 OP1_1(TYPE_LNG, TYPE_FLT);
2560 COUNT(count_pcmd_op);
2561 OP1_1(TYPE_LNG, TYPE_DBL);
2564 COUNT(count_pcmd_op);
2565 OP1_1(TYPE_FLT, TYPE_INT);
2568 COUNT(count_pcmd_op);
2569 OP1_1(TYPE_FLT, TYPE_LNG);
2572 COUNT(count_pcmd_op);
2573 OP1_1(TYPE_FLT, TYPE_DBL);
2576 COUNT(count_pcmd_op);
2577 OP1_1(TYPE_DBL, TYPE_INT);
2580 COUNT(count_pcmd_op);
2581 OP1_1(TYPE_DBL, TYPE_LNG);
2584 COUNT(count_pcmd_op);
2585 OP1_1(TYPE_DBL, TYPE_FLT);
2588 case ICMD_CHECKCAST:
2589 last_pei_boundary = new;
2590 if (iptr->flags.bits & INS_FLAG_ARRAY) {
2591 /* array type cast-check */
2593 bte = builtintable_get_internal(BUILTIN_arraycheckcast);
2596 if (md->memuse > rd->memuse)
2597 rd->memuse = md->memuse;
2598 if (md->argintreguse > rd->argintreguse)
2599 rd->argintreguse = md->argintreguse;
2601 /* make all stack variables saved */
2605 copy->flags |= SAVEDVAR;
2609 OP1_1(TYPE_ADR, TYPE_ADR);
2612 case ICMD_INSTANCEOF:
2613 case ICMD_ARRAYLENGTH:
2614 last_pei_boundary = new;
2615 OP1_1(TYPE_ADR, TYPE_INT);
2619 case ICMD_ANEWARRAY:
2620 last_pei_boundary = new;
2621 OP1_1(TYPE_INT, TYPE_ADR);
2625 last_pei_boundary = new;
2626 COUNT(count_check_null);
2627 COUNT(count_pcmd_mem);
2628 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2629 OP1_1(TYPE_ADR, fmiref->parseddesc.fd->type);
2634 case ICMD_GETSTATIC:
2635 last_pei_boundary = new;
2636 COUNT(count_pcmd_mem);
2637 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2638 OP0_1(fmiref->parseddesc.fd->type);
2642 last_pei_boundary = new;
2649 BRANCH_TARGET(iptr->sx.s23.s3.jsrtarget, tbptr, copy);
2651 tbptr->type = BBTYPE_SBR;
2653 /* We need to check for overflow right here because
2654 * the pushed value is poped afterwards */
2657 /* calculate stack after return */
2662 /* pop many push any */
2666 bte = iptr->sx.s23.s3.bte;
2670 case ICMD_INVOKESTATIC:
2671 case ICMD_INVOKESPECIAL:
2672 case ICMD_INVOKEVIRTUAL:
2673 case ICMD_INVOKEINTERFACE:
2674 COUNT(count_pcmd_met);
2676 /* Check for functions to replace with builtin
2679 if (builtintable_replace_function(iptr))
2682 INSTRUCTION_GET_METHODDESC(iptr, md);
2683 /* XXX resurrect this COUNT? */
2684 /* if (lm->flags & ACC_STATIC) */
2685 /* {COUNT(count_check_null);} */
2689 last_pei_boundary = new;
2693 if (md->memuse > rd->memuse)
2694 rd->memuse = md->memuse;
2695 if (md->argintreguse > rd->argintreguse)
2696 rd->argintreguse = md->argintreguse;
2697 if (md->argfltreguse > rd->argfltreguse)
2698 rd->argfltreguse = md->argfltreguse;
2702 /* XXX optimize for <= 2 args */
2703 /* XXX not for ICMD_BUILTIN */
2704 iptr->s1.argcount = stackdepth;
2705 iptr->sx.s23.s2.args = DMNEW(stackptr, stackdepth);
2708 for (i-- ; i >= 0; i--) {
2709 iptr->sx.s23.s2.args[i] = copy;
2711 /* do not change STACKVARs to ARGVAR ->
2712 won't help anyway */
2713 if (copy->varkind != STACKVAR) {
2715 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2716 /* If we pass float arguments in integer argument registers, we
2717 * are not allowed to precolor them here. Floats have to be moved
2718 * to this regs explicitly in codegen().
2719 * Only arguments that are passed by stack anyway can be precolored
2720 * (michi 2005/07/24) */
2721 if (!(copy->flags & SAVEDVAR) &&
2722 (!IS_FLT_DBL_TYPE(copy->type) || md->params[i].inmemory)) {
2724 if (!(copy->flags & SAVEDVAR)) {
2726 copy->varkind = ARGVAR;
2729 #if defined(ENABLE_INTRP)
2732 if (md->params[i].inmemory) {
2733 copy->flags = INMEMORY;
2734 copy->regoff = md->params[i].regoff;
2738 if (IS_FLT_DBL_TYPE(copy->type)) {
2739 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2740 assert(0); /* XXX is this assert ok? */
2743 rd->argfltregs[md->params[i].regoff];
2744 #endif /* SUPPORT_PASS_FLOATARGS_IN_INTREGS */
2747 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
2748 if (IS_2_WORD_TYPE(copy->type))
2749 copy->regoff = PACK_REGS(
2750 rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
2751 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
2753 #endif /* SUPPORT_COMBINE_INTEGER_REGISTERS */
2755 rd->argintregs[md->params[i].regoff];
2758 #if defined(ENABLE_INTRP)
2759 } /* end if (!opt_intrp) */
2766 /* deal with live-through stack slots "under" the arguments */
2767 /* XXX not for ICMD_BUILTIN */
2772 iptr->sx.s23.s2.args[i++] = copy;
2773 copy->flags |= SAVEDVAR;
2777 /* pop the arguments */
2786 /* push the return value */
2788 if (md->returntype.type != TYPE_VOID) {
2789 DST(md->returntype.type, stackdepth);
2794 case ICMD_INLINE_START:
2795 case ICMD_INLINE_END:
2800 case ICMD_MULTIANEWARRAY:
2801 last_pei_boundary = new;
2802 if (rd->argintreguse < 3)
2803 rd->argintreguse = 3;
2805 i = iptr->s1.argcount;
2809 iptr->sx.s23.s2.args = DMNEW(stackptr, i);
2811 #if defined(SPECIALMEMUSE)
2812 # if defined(__DARWIN__)
2813 if (rd->memuse < (i + INT_ARG_CNT + LA_SIZE_IN_POINTERS))
2814 rd->memuse = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2816 if (rd->memuse < (i + LA_SIZE_IN_POINTERS + 3))
2817 rd->memuse = i + LA_SIZE_IN_POINTERS + 3;
2820 # if defined(__I386__)
2821 if (rd->memuse < i + 3)
2822 rd->memuse = i + 3; /* n integer args spilled on stack */
2823 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2824 if (rd->memuse < i + 2)
2825 rd->memuse = i + 2; /* 4*4 bytes callee save space */
2828 rd->memuse = i; /* n integer args spilled on stack */
2829 # endif /* defined(__I386__) */
2833 /* check INT type here? Currently typecheck does this. */
2834 iptr->sx.s23.s2.args[i] = copy;
2835 if (!(copy->flags & SAVEDVAR)
2836 && (copy->varkind != STACKVAR)) {
2837 copy->varkind = ARGVAR;
2838 copy->varnum = i + INT_ARG_CNT;
2839 copy->flags |= INMEMORY;
2840 #if defined(SPECIALMEMUSE)
2841 # if defined(__DARWIN__)
2842 copy->regoff = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
2844 copy->regoff = i + LA_SIZE_IN_POINTERS + 3;
2847 # if defined(__I386__)
2848 copy->regoff = i + 3;
2849 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2850 copy->regoff = i + 2;
2853 # endif /* defined(__I386__) */
2854 #endif /* defined(SPECIALMEMUSE) */
2859 copy->flags |= SAVEDVAR;
2863 i = iptr->s1.argcount;
2868 DST(TYPE_ADR, stackdepth);
2874 new_internalerror("Unknown ICMD %d", opcode);
2880 } /* while instructions */
2882 /* set out-stack of block */
2884 bptr->outstack = curstack;
2885 bptr->outdepth = stackdepth;
2886 bptr->outvars = DMNEW(stackptr, stackdepth);
2887 for (i = stackdepth, copy = curstack; i--; copy = copy->prev)
2888 bptr->outvars[i] = copy;
2890 /* stack slots at basic block end become interfaces */
2893 for (copy = curstack; copy; i--, copy = copy->prev) {
2894 if ((copy->varkind == STACKVAR) && (copy->varnum > i)) {
2895 #if defined(NEW_VAR)
2896 /* with the new vars rd->interfaces will be removed */
2897 /* and all in and outvars have to be STACKVARS! */
2898 /* in the moment i.e. SWAP with in and out vars */
2899 /* an unresolvable conflict */
2902 copy->varkind = TEMPVAR;
2904 copy->varkind = STACKVAR;
2908 rd->interfaces[i][copy->type].type = copy->type;
2909 rd->interfaces[i][copy->type].flags |= copy->flags;
2913 /* check if interface slots at basic block begin must be saved */
2916 i = bptr->indepth - 1;
2917 for (copy = bptr->instack; copy; i--, copy = copy->prev) {
2918 rd->interfaces[i][copy->type].type = copy->type;
2919 if (copy->varkind == STACKVAR) {
2920 if (copy->flags & SAVEDVAR)
2921 rd->interfaces[i][copy->type].flags |= SAVEDVAR;
2928 superblockend = true;
2931 } /* while blocks */
2932 } while (repeat && !deadcode);
2934 /* gather statistics *****************************************************/
2936 #if defined(ENABLE_STATISTICS)
2938 if (jd->new_basicblockcount > count_max_basic_blocks)
2939 count_max_basic_blocks = jd->new_basicblockcount;
2940 count_basic_blocks += jd->new_basicblockcount;
2941 if (jd->new_instructioncount > count_max_javainstr)
2942 count_max_javainstr = jd->new_instructioncount;
2943 count_javainstr += jd->new_instructioncount;
2944 if (jd->new_stackcount > count_upper_bound_new_stack)
2945 count_upper_bound_new_stack = jd->new_stackcount;
2946 if ((new - jd->new_stack) > count_max_new_stack)
2947 count_max_new_stack = (new - jd->new_stack);
2949 b_count = jd->new_basicblockcount;
2950 bptr = jd->new_basicblocks;
2951 while (--b_count >= 0) {
2952 if (bptr->flags > BBREACHED) {
2953 if (bptr->indepth >= 10)
2954 count_block_stack[10]++;
2956 count_block_stack[bptr->indepth]++;
2959 count_block_size_distribution[len]++;
2961 count_block_size_distribution[10]++;
2963 count_block_size_distribution[11]++;
2965 count_block_size_distribution[12]++;
2967 count_block_size_distribution[13]++;
2969 count_block_size_distribution[14]++;
2971 count_block_size_distribution[15]++;
2973 count_block_size_distribution[16]++;
2975 count_block_size_distribution[17]++;
2980 if (iteration_count == 1)
2981 count_analyse_iterations[0]++;
2982 else if (iteration_count == 2)
2983 count_analyse_iterations[1]++;
2984 else if (iteration_count == 3)
2985 count_analyse_iterations[2]++;
2986 else if (iteration_count == 4)
2987 count_analyse_iterations[3]++;
2989 count_analyse_iterations[4]++;
2991 if (jd->new_basicblockcount <= 5)
2992 count_method_bb_distribution[0]++;
2993 else if (jd->new_basicblockcount <= 10)
2994 count_method_bb_distribution[1]++;
2995 else if (jd->new_basicblockcount <= 15)
2996 count_method_bb_distribution[2]++;
2997 else if (jd->new_basicblockcount <= 20)
2998 count_method_bb_distribution[3]++;
2999 else if (jd->new_basicblockcount <= 30)
3000 count_method_bb_distribution[4]++;
3001 else if (jd->new_basicblockcount <= 40)
3002 count_method_bb_distribution[5]++;
3003 else if (jd->new_basicblockcount <= 50)
3004 count_method_bb_distribution[6]++;
3005 else if (jd->new_basicblockcount <= 75)
3006 count_method_bb_distribution[7]++;
3008 count_method_bb_distribution[8]++;
3010 #endif /* defined(ENABLE_STATISTICS) */
3012 /* everything's ok *******************************************************/
3016 /* goto labels for throwing verifier exceptions **************************/
3018 #if defined(ENABLE_VERIFIER)
3020 throw_stack_underflow:
3021 exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
3024 throw_stack_overflow:
3025 exceptions_throw_verifyerror(m, "Stack size too large");
3028 throw_stack_depth_error:
3029 exceptions_throw_verifyerror(m,"Stack depth mismatch");
3032 throw_stack_type_error:
3033 exceptions_throw_verifyerror_for_stack(m, expectedtype);
3036 throw_stack_category_error:
3037 exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
3045 * These are local overrides for various environment variables in Emacs.
3046 * Please do not remove this and leave it at the end of the file, where
3047 * Emacs will automagically detect them.
3048 * ---------------------------------------------------------------------
3051 * indent-tabs-mode: t
3055 * vim:noexpandtab:sw=4:ts=4: