* src/vm/jit/stack.c (DUP_SLOT): Removed code for direct coalescing.
[cacao.git] / src / vm / jit / stack.c
1 /* src/vm/jit/stack.c - stack analysis
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Andreas Krall
28
29    Changes: Edwin Steiner
30             Christian Thalinger
31             Christian Ullrich
32
33    $Id: stack.c 5454 2006-09-10 11:20:40Z edwin $
34
35 */
36
37
38 #include "config.h"
39
40 #include <assert.h>
41 #include <stdio.h>
42 #include <string.h>
43
44 #include "vm/types.h"
45
46 #include "arch.h"
47 #include "md-abi.h"
48
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"
62
63 #if defined(ENABLE_DISASSEMBLER)
64 # include "vm/jit/disass.h"
65 #endif
66
67 #include "vm/jit/jit.h"
68 #include "vm/jit/stack.h"
69
70 #if defined(ENABLE_LSRA)
71 # include "vm/jit/allocator/lsra.h"
72 #endif
73
74 /*#define STACK_VERBOSE*/
75
76
77 /* macro for saving #ifdefs ***************************************************/
78
79 #if defined(ENABLE_INTRP)
80 #define IF_INTRP(x) if (opt_intrp) { x }
81 #define IF_NO_INTRP(x) if (!opt_intrp) { x }
82 #else
83 #define IF_INTRP(x)
84 #define IF_NO_INTRP(x) { x }
85 #endif
86
87 #if defined(ENABLE_INTRP)
88 #if defined(ENABLE_JIT)
89 #define IF_JIT(x) if (!opt_intrp) { x }
90 #else
91 #define IF_JIT(x)
92 #endif
93 #else /* !defined(ENABLE_INTRP) */
94 #define IF_JIT(x) { x }
95 #endif /* defined(ENABLE_INTRP) */
96
97 #if defined(ENABLE_STATISTICS)
98 #define STATISTICS_STACKDEPTH_DISTRIBUTION(distr)                    \
99     do {                                                             \
100         if (opt_stat) {                                              \
101             if (stackdepth >= 10)                                    \
102                 count_store_depth[10]++;                             \
103             else                                                     \
104                 count_store_depth[stackdepth]++;                     \
105         }                                                            \
106     } while (0)
107 #else /* !defined(ENABLE_STATISTICS) */
108 #define STATISTICS_STACKDEPTH_DISTRIBUTION(distr)
109 #endif
110
111 /* stackdata_t ****************************************************************/
112
113 typedef struct stackdata_t stackdata_t;
114
115 struct stackdata_t {
116     basicblock *bptr;
117     stackptr new;
118     s4 vartop;
119     s4 localcount;
120     s4 varcount;
121     varinfo *var;
122         methodinfo *m;
123 };
124
125
126 /* macros for allocating/releasing variable indices */
127
128 #define GET_NEW_INDEX(sd, new_varindex)                              \
129     do {                                                             \
130         assert((sd).vartop < (sd).varcount);                         \
131         (new_varindex) = ((sd).vartop)++;                            \
132     } while (0)
133
134 /* not implemented now, can be used to reuse varindices          */
135 /* pay attention to not release a localvar once implementing it! */
136 #define RELEASE_INDEX(sd, varindex)
137
138 #define GET_NEW_VAR(sd, new_varindex, newtype)                       \
139     do {                                                             \
140         GET_NEW_INDEX((sd), (new_varindex));                         \
141         (sd).var[new_index].type = (newtype);                        \
142     } while (0)
143
144 /* macros for querying variable properties **************************/
145
146 #define IS_OUTVAR(sp)                                                \
147     (sd.var[(sp)->varnum].flags & OUTVAR)
148
149 #define IS_PREALLOC(sp)                                              \
150     (sd.var[(sp)->varnum].flags & PREALLOC)
151
152 #define IS_TEMPVAR(sp)                                               \
153     ( ((sp)->varnum >= sd.localcount)                                \
154       && !(sd.var[(sp)->varnum].flags & (OUTVAR | PREALLOC)) )
155
156 #define IS_LOCALVAR_SD(sd, sp)                                       \
157          ((sp)->varnum < (sd).localcount)
158
159 #define IS_LOCALVAR(sp)                                              \
160     IS_LOCALVAR_SD(sd, (sp))
161
162
163 /* macros for setting variable properties ****************************/
164
165 #define SET_TEMPVAR(sp)                                              \
166     do {                                                             \
167         if (IS_LOCALVAR((sp))) {                                     \
168             GET_NEW_VAR(sd, new_index, (sp)->type);                  \
169             sd.var[new_index].flags = (sp)->flags;                   \
170             (sp)->varnum = new_index;                                \
171             (sp)->varkind = TEMPVAR;                                 \
172             if ((sp)->creator)                                       \
173                 (sp)->creator->dst.varindex = new_index;             \
174         }                                                            \
175         sd.var[(sp)->varnum].flags &= ~(OUTVAR | PREALLOC);          \
176     } while (0);
177
178 #define SET_PREALLOC(sp)                                             \
179     do {                                                             \
180         assert(!IS_LOCALVAR((sp)));                                  \
181         sd.var[(sp)->varnum].flags |= PREALLOC;                      \
182     } while (0);
183
184 /* macros for source operands ***************************************/
185
186 #define CLR_S1                                                       \
187     (iptr->s1.varindex = -1)
188
189 #define USE_S1_LOCAL(type1)
190
191 #define USE_S1(type1)                                                \
192     do {                                                             \
193         REQUIRE(1);                                                  \
194         CHECK_BASIC_TYPE(type1, curstack->type);                     \
195         iptr->s1.varindex = curstack->varnum;                        \
196     } while (0)
197
198 #define USE_S1_ANY                                                   \
199     do {                                                             \
200         REQUIRE(1);                                                  \
201         iptr->s1.varindex = curstack->varnum;                        \
202     } while (0)
203
204 #define USE_S1_S2(type1, type2)                                      \
205     do {                                                             \
206         REQUIRE(2);                                                  \
207         CHECK_BASIC_TYPE(type1, curstack->prev->type);               \
208         CHECK_BASIC_TYPE(type2, curstack->type);                     \
209         iptr->sx.s23.s2.varindex = curstack->varnum;                 \
210         iptr->s1.varindex = curstack->prev->varnum;                  \
211     } while (0)
212
213 #define USE_S1_S2_ANY_ANY                                            \
214     do {                                                             \
215         REQUIRE(2);                                                  \
216         iptr->sx.s23.s2.varindex = curstack->varnum;                 \
217         iptr->s1.varindex = curstack->prev->varnum;                  \
218     } while (0)
219
220 #define USE_S1_S2_S3(type1, type2, type3)                            \
221     do {                                                             \
222         REQUIRE(3);                                                  \
223         CHECK_BASIC_TYPE(type1, curstack->prev->prev->type);         \
224         CHECK_BASIC_TYPE(type2, curstack->prev->type);               \
225         CHECK_BASIC_TYPE(type3, curstack->type);                     \
226         iptr->sx.s23.s3.varindex = curstack->varnum;                 \
227         iptr->sx.s23.s2.varindex = curstack->prev->varnum;           \
228         iptr->s1.varindex = curstack->prev->prev->varnum;            \
229     } while (0)
230
231 /* The POPANY macro does NOT check stackdepth, or set stackdepth!   */
232 #define POPANY                                                       \
233     do {                                                             \
234         if (curstack->varkind == UNDEFVAR)                           \
235             curstack->varkind = TEMPVAR;                             \
236         curstack = curstack->prev;                                   \
237     } while (0)
238
239 #define POP_S1(type1)                                                \
240     do {                                                             \
241         USE_S1(type1);                                               \
242         if (curstack->varkind == UNDEFVAR)                           \
243             curstack->varkind = TEMPVAR;                             \
244         curstack = curstack->prev;                                   \
245     } while (0)
246
247 #define POP_S1_ANY                                                   \
248     do {                                                             \
249         USE_S1_ANY;                                                  \
250         if (curstack->varkind == UNDEFVAR)                           \
251             curstack->varkind = TEMPVAR;                             \
252         curstack = curstack->prev;                                   \
253     } while (0)
254
255 #define POP_S1_S2(type1, type2)                                      \
256     do {                                                             \
257         USE_S1_S2(type1, type2);                                     \
258         if (curstack->varkind == UNDEFVAR)                           \
259             curstack->varkind = TEMPVAR;                             \
260         if (curstack->prev->varkind == UNDEFVAR)                     \
261             curstack->prev->varkind = TEMPVAR;                       \
262         curstack = curstack->prev->prev;                             \
263     } while (0)
264
265 #define POP_S1_S2_ANY_ANY                                            \
266     do {                                                             \
267         USE_S1_S2_ANY_ANY;                                           \
268         if (curstack->varkind == UNDEFVAR)                           \
269             curstack->varkind = TEMPVAR;                             \
270         if (curstack->prev->varkind == UNDEFVAR)                     \
271             curstack->prev->varkind = TEMPVAR;                       \
272         curstack = curstack->prev->prev;                             \
273     } while (0)
274
275 #define POP_S1_S2_S3(type1, type2, type3)                            \
276     do {                                                             \
277         USE_S1_S2_S3(type1, type2, type3);                           \
278         if (curstack->varkind == UNDEFVAR)                           \
279             curstack->varkind = TEMPVAR;                             \
280         if (curstack->prev->varkind == UNDEFVAR)                     \
281             curstack->prev->varkind = TEMPVAR;                       \
282         if (curstack->prev->prev->varkind == UNDEFVAR)               \
283             curstack->prev->prev->varkind = TEMPVAR;                 \
284         curstack = curstack->prev->prev->prev;                       \
285     } while (0)
286
287 #define CLR_SX                                                       \
288     (iptr->sx.val.l = 0)
289
290
291 /* macros for setting the destination operand ***********************/
292
293 #define CLR_DST                                                      \
294     (iptr->dst.varindex = -1)
295
296 #define DST(typed, index)                                            \
297     do {                                                             \
298         NEWSTACKn((typed),(index));                                  \
299         curstack->creator = iptr;                                    \
300         iptr->dst.varindex = (index);                                \
301     } while (0)
302
303 #define DST_LOCALVAR(typed, index)                                   \
304     do {                                                             \
305         NEWSTACK((typed), LOCALVAR, (index));                        \
306         curstack->creator = iptr;                                    \
307         iptr->dst.varindex = (index);                                \
308     } while (0)
309
310
311 /* stack modelling macros *******************************************/
312
313 #define OP0_1(typed)                                                 \
314     do {                                                             \
315         CLR_S1;                                                      \
316         GET_NEW_VAR(sd, new_index, (typed));                         \
317         DST(typed, new_index);                                       \
318         stackdepth++;                                                \
319     } while (0)
320
321 #define OP1_0_ANY                                                    \
322     do {                                                             \
323         POP_S1_ANY;                                                  \
324         CLR_DST;                                                     \
325         stackdepth--;                                                \
326     } while (0)
327
328 #define OP1_BRANCH(type1)                                            \
329     do {                                                             \
330         POP_S1(type1);                                               \
331         stackdepth--;                                                \
332     } while (0)
333
334 #define OP1_1(type1, typed)                                          \
335     do {                                                             \
336         POP_S1(type1);                                               \
337         GET_NEW_VAR(sd, new_index, (typed));                         \
338         DST(typed, new_index);                                       \
339     } while (0)
340
341 #define OP2_1(type1, type2, typed)                                   \
342     do {                                                             \
343         POP_S1_S2(type1, type2);                                     \
344         GET_NEW_VAR(sd, new_index, (typed));                         \
345         DST(typed, new_index);                                       \
346         stackdepth--;                                                \
347     } while (0)
348
349 #define OP0_0                                                        \
350     do {                                                             \
351         CLR_S1;                                                      \
352         CLR_DST;                                                     \
353     } while (0)
354
355 #define OP0_BRANCH                                                   \
356     do {                                                             \
357         CLR_S1;                                                      \
358     } while (0)
359
360 #define OP1_0(type1)                                                 \
361     do {                                                             \
362         POP_S1(type1);                                               \
363         CLR_DST;                                                     \
364         stackdepth--;                                                \
365     } while (0)
366
367 #define OP2_0(type1, type2)                                          \
368     do {                                                             \
369         POP_S1_S2(type1, type2);                                     \
370         CLR_DST;                                                     \
371         stackdepth -= 2;                                             \
372     } while (0)
373
374 #define OP2_BRANCH(type1, type2)                                     \
375     do {                                                             \
376         POP_S1_S2(type1, type2);                                     \
377         stackdepth -= 2;                                             \
378     } while (0)
379
380 #define OP2_0_ANY_ANY                                                \
381     do {                                                             \
382         POP_S1_S2_ANY_ANY;                                           \
383         CLR_DST;                                                     \
384         stackdepth -= 2;                                             \
385     } while (0)
386
387 #define OP3_0(type1, type2, type3)                                   \
388     do {                                                             \
389         POP_S1_S2_S3(type1, type2, type3);                           \
390         CLR_DST;                                                     \
391         stackdepth -= 3;                                             \
392     } while (0)
393
394 #define LOAD(type1, index)                                           \
395     do {                                                             \
396         DST_LOCALVAR(type1, index);                                  \
397         stackdepth++;                                                \
398     } while (0)
399
400 #define STORE(type1, index)                                          \
401     do {                                                             \
402         POP_S1(type1);                                               \
403         stackdepth--;                                                \
404     } while (0)
405
406
407 /* macros for DUP elimination ***************************************/
408
409 #define DUP_SLOT(sp)                                                 \
410     do {                                                             \
411             GET_NEW_VAR(sd, new_index, (sp)->type);                  \
412             NEWSTACK((sp)->type, TEMPVAR, new_index);                \
413     } while(0)
414
415 /* does not check input stackdepth */
416 #define MOVE_UP(sp)                                                  \
417     do {                                                             \
418         iptr->opc = ICMD_MOVE;                                       \
419         iptr->s1.varindex = (sp)->varnum;                            \
420         DUP_SLOT(sp);                                                \
421         curstack->creator = iptr;                                    \
422         iptr->dst.varindex = curstack->varnum;                       \
423         stackdepth++;                                                \
424     } while (0)
425
426 /* does not check input stackdepth */
427 #define COPY_UP(sp)                                                  \
428     do {                                                             \
429         SET_TEMPVAR((sp));                                           \
430         iptr->opc = ICMD_COPY;                                       \
431         iptr->s1.varindex = (sp)->varnum;                            \
432         DUP_SLOT(sp);                                                \
433         curstack->creator = iptr;                                    \
434         iptr->dst.varindex = curstack->varnum;                       \
435         stackdepth++;                                                \
436     } while (0)
437
438 #define COPY_DOWN(s, d)                                              \
439     do {                                                             \
440         SET_TEMPVAR((s));                                            \
441         iptr->opc = ICMD_COPY;                                       \
442         iptr->s1.varindex = (s)->varnum;                             \
443         iptr->dst.varindex = (d)->varnum;                            \
444         (d)->creator = iptr;                                         \
445     } while (0)
446
447
448 /* macros for branching / reaching basic blocks *********************/
449
450 #if defined(ENABLE_VERIFIER)
451 #define MARKREACHED(b, c)                                            \
452     do {                                                             \
453         if (!stack_mark_reached(&sd, (b), curstack, stackdepth))     \
454             return false;                                            \
455     } while (0)
456 #else
457 #define MARKREACHED(b, c)                                            \
458     do {                                                             \
459         (void) stack_mark_reached(&sd, (b), curstack, stackdepth);   \
460     } while (0)
461 #endif
462
463 #define BRANCH_TARGET(bt, tempbptr, tempsp)                          \
464     do {                                                             \
465         (bt).block = tempbptr = BLOCK_OF((bt).insindex);             \
466         MARKREACHED(tempbptr, tempsp);                               \
467     } while (0)
468
469 #define BRANCH(tempbptr, tempsp)                                     \
470     do {                                                             \
471         iptr->dst.block = tempbptr = BLOCK_OF(iptr->dst.insindex);   \
472         MARKREACHED(tempbptr, tempsp);                               \
473     } while (0)
474
475
476 /* stack_init ******************************************************************
477
478    Initialized the stack analysis subsystem (called by jit_init).
479
480 *******************************************************************************/
481
482 bool stack_init(void)
483 {
484         return true;
485 }
486
487
488 /* stack_create_invars *********************************************************
489
490    Create the invars for the given basic block.
491
492    IN:
493       sd...........stack analysis data
494           b............block to create the invars for
495           curstack.....current stack top
496           stackdepth...current stack depth
497
498    This function creates STACKDEPTH invars and sets their types to the
499    types to the types of the corresponding slot in the current stack.
500
501 *******************************************************************************/
502
503 static void stack_create_invars(stackdata_t *sd, basicblock *b, 
504                                                                 stackptr curstack, int stackdepth)
505 {
506         stackptr sp;
507         int i;
508         int index;
509         varinfo *v;
510
511         assert(sd->vartop + stackdepth <= sd->varcount);
512
513         b->indepth = stackdepth;
514         b->invars = DMNEW(s4, stackdepth);
515
516         /* allocate the variable indices */
517         index = (sd->vartop += stackdepth);
518
519         i = stackdepth;
520         for (sp = curstack; i--; sp = sp->prev) {
521                 b->invars[i] = --index;
522                 v = sd->var + index;
523                 v->type = sp->type;
524                 v->flags = OUTVAR;
525         }
526 }
527
528
529 /* stack_check_invars **********************************************************
530
531    Check the current stack against the invars of the given basic block.
532    Depth and types must match.
533
534    IN:
535       sd...........stack analysis data
536           b............block which invars to check against
537           curstack.....current stack top
538           stackdepth...current stack depth
539
540    RETURN VALUE:
541       true.........everything ok
542           false........a VerifyError has been thrown
543
544 *******************************************************************************/
545
546 /* XXX only if ENABLE_VERIFIER */
547 static bool stack_check_invars(stackdata_t *sd, basicblock *b,
548                                                            stackptr curstack, int stackdepth)
549 {
550         int depth;
551
552         depth = b->indepth;
553
554         if (depth != stackdepth) {
555                 exceptions_throw_verifyerror(sd->m, "Stack depth mismatch");
556                 return false;
557         }
558
559         while (depth--) {
560                 if (sd->var[b->invars[depth]].type != curstack->type) {
561                         exceptions_throw_verifyerror_for_stack(sd->m, 
562                                         sd->var[b->invars[depth]].type);
563                         return false;
564                 }
565                 curstack = curstack->prev;
566         }
567
568         return true;
569 }
570
571
572 /* stack_create_instack ********************************************************
573
574    Create the instack of the current basic block.
575
576    IN:
577       sd...........stack analysis data
578
579    RETURN VALUE:
580       the current stack top at the start of the basic block.
581
582 *******************************************************************************/
583
584 static stackptr stack_create_instack(stackdata_t *sd)
585 {
586     stackptr sp;
587         int depth;
588         int index;
589
590         if ((depth = sd->bptr->indepth) == 0)
591                 return NULL;
592
593     sp = (sd->new += depth);
594
595         while (depth--) {
596                 sp--;
597                 index = sd->bptr->invars[depth];
598                 sp->varnum = index;
599                 sp->type = sd->var[index].type;
600                 sp->prev = sp - 1;
601                 sp->creator = NULL;
602                 sp->flags = 0;
603                 sp->varkind = STACKVAR;
604         }
605         sp->prev = NULL;
606
607         /* return the top of the created stack */
608         return sd->new - 1;
609 }
610
611
612 /* MARKREACHED marks the destination block <b> as reached. If this
613  * block has been reached before we check if stack depth and types
614  * match. Otherwise the destination block receives a copy of the
615  * current stack as its input stack.
616  *
617  * b...destination block
618  * c...current stack
619  */
620
621 static bool stack_mark_reached(stackdata_t *sd, basicblock *b, stackptr curstack, int stackdepth) 
622 {
623         /* mark targets of backward branches */
624         if (b <= sd->bptr)
625                 b->bitflags |= BBFLAG_REPLACEMENT;
626
627         if (b->flags < BBREACHED) {
628                 /* b is reached for the first time. Create its instack */
629                 stack_create_invars(sd, b, curstack, stackdepth);
630
631                 b->flags = BBREACHED;
632         } 
633         else {
634                 /* b has been reached before. Check that its instack matches */
635                 if (!stack_check_invars(sd, b, curstack, stackdepth))
636                         return false;
637         }
638
639         return true;
640 }
641
642
643 /* stack_analyse ***************************************************************
644
645    Analyse_stack uses the intermediate code created by parse.c to
646    build a model of the JVM operand stack for the current method.
647    
648    The following checks are performed:
649      - check for operand stack underflow (before each instruction)
650      - check for operand stack overflow (after[1] each instruction)
651      - check for matching stack depth at merging points
652      - check for matching basic types[2] at merging points
653      - check basic types for instruction input (except for BUILTIN*
654            opcodes, INVOKE* opcodes and MULTIANEWARRAY)
655    
656    [1]) Checking this after the instruction should be ok. parse.c
657    counts the number of required stack slots in such a way that it is
658    only vital that we don't exceed `maxstack` at basic block
659    boundaries.
660    
661    [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
662    DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
663    types are not discerned.
664
665 *******************************************************************************/
666
667 bool new_stack_analyse(jitdata *jd)
668 {
669         methodinfo   *m;              /* method being analyzed                    */
670         codeinfo     *code;
671         codegendata  *cd;
672         registerdata *rd;
673         stackdata_t   sd;
674         int           b_count;        /* basic block counter                      */
675         int           b_index;        /* basic block index                        */
676         int           stackdepth;
677         stackptr      curstack;       /* current stack top                        */
678         stackptr      copy;
679         int           opcode;         /* opcode of current instruction            */
680         int           i, j;
681         int           javaindex;
682         int           len;            /* # of instructions after the current one  */
683         bool          superblockend;  /* if true, no fallthrough to next block    */
684         bool          repeat;         /* if true, outermost loop must run again   */
685         bool          deadcode;       /* true if no live code has been reached    */
686         instruction  *iptr;           /* the current instruction                  */
687         basicblock   *tbptr;
688
689         stackptr     *last_store_boundary;
690         stackptr      coalescing_boundary;
691
692         stackptr      src1, src2, src3, src4, dst1, dst2;
693
694         branch_target_t *table;
695         lookup_target_t *lookup;
696 #if defined(ENABLE_VERIFIER)
697         int           expectedtype;   /* used by CHECK_BASIC_TYPE                 */
698 #endif
699         builtintable_entry *bte;
700         methoddesc         *md;
701         constant_FMIref    *fmiref;
702 #if defined(ENABLE_STATISTICS)
703         int           iteration_count;  /* number of iterations of analysis       */
704 #endif
705         int           new_index; /* used to get a new var index with GET_NEW_INDEX*/
706
707 #if defined(STACK_VERBOSE)
708         new_show_method(jd, SHOW_PARSE);
709 #endif
710
711         /* get required compiler data - initialization */
712
713         m    = jd->m;
714         code = jd->code;
715         cd   = jd->cd;
716         rd   = jd->rd;
717
718         /* initialize the stackdata_t struct */
719
720         sd.m = m;
721         sd.varcount = jd->varcount;
722         sd.vartop =  jd->vartop;
723         sd.localcount = jd->localcount;
724         sd.var = jd->var;
725
726 #if defined(ENABLE_LSRA)
727         m->maxlifetimes = 0;
728 #endif
729
730 #if defined(ENABLE_STATISTICS)
731         iteration_count = 0;
732 #endif
733
734         /* init jd->interface_map */
735
736         jd->interface_map = DMNEW(interface_info, m->maxstack * 5);
737         for (i = 0; i < m->maxstack * 5; i++)
738                 jd->interface_map[i].flags = UNUSED;
739
740         last_store_boundary = DMNEW(stackptr, cd->maxlocals);
741
742         /* initialize flags and invars (none) of first block */
743
744         jd->new_basicblocks[0].flags = BBREACHED;
745         jd->new_basicblocks[0].invars = NULL;
746         jd->new_basicblocks[0].indepth = 0;
747
748         /* initialize invars of exception handlers */
749
750         for (i = 0; i < cd->exceptiontablelength; i++) {
751                 sd.bptr = BLOCK_OF(cd->exceptiontable[i].handlerpc);
752                 sd.bptr->flags = BBREACHED;
753                 sd.bptr->type = BBTYPE_EXH;
754                 sd.bptr->predecessorcount = CFG_UNKNOWN_PREDECESSORS;
755
756                 GET_NEW_VAR(sd, new_index, TYPE_ADR);
757                 sd.bptr->invars = DMNEW(s4, 1);
758                 sd.bptr->invars[0] = new_index;
759                 sd.bptr->indepth = 1;
760                 sd.var[new_index].flags |= OUTVAR;
761
762                 /* mark this interface variable used */
763                 jd->interface_map[0 * 5 + TYPE_ADR].flags = 0;
764         }
765
766         /* stack analysis loop (until fixpoint reached) **************************/
767
768         do {
769 #if defined(ENABLE_STATISTICS)
770                 iteration_count++;
771 #endif
772
773                 /* initialize loop over basic blocks */
774
775                 b_count = jd->new_basicblockcount;
776                 sd.bptr = jd->new_basicblocks;
777                 superblockend = true;
778                 repeat = false;
779                 curstack = NULL; stackdepth = 0;
780                 deadcode = true;
781
782                 /* iterate over basic blocks *****************************************/
783
784                 for (; --b_count >= 0; ++sd.bptr) {
785
786 #if defined(STACK_VERBOSE)
787                         printf("----\nANALYZING BLOCK L%03d ", sd.bptr->nr);
788                         if (sd.bptr->type == BBTYPE_EXH) printf("EXH\n");
789                         else if (sd.bptr->type == BBTYPE_SBR) printf("SBR\n");
790                         else printf("STD\n");
791 #endif
792
793                         if (sd.bptr->flags == BBDELETED) {
794                                 /* This block has been deleted - do nothing. */
795
796                                 continue;
797                         }
798
799                         if (superblockend && (sd.bptr->flags < BBREACHED)) {
800                                 /* This block has not been reached so far, and we      */
801                                 /* don't fall into it, so we'll have to iterate again. */
802
803                                 repeat = true;
804                                 continue;
805                         }
806
807                         if (sd.bptr->flags > BBREACHED) {
808                                 /* This block is already finished. */
809
810                                 superblockend = true;
811                                 continue;
812                         }
813
814                         /* This block has to be analysed now. */
815
816                         /* XXX The rest of this block is still indented one level too */
817                         /* much in order to avoid a giant diff by changing that.      */
818
819                                 if (superblockend) {
820                                         /* We know that sd.bptr->flags == BBREACHED. */
821                                         /* This block has been reached before.    */
822
823                                         stackdepth = sd.bptr->indepth;
824                                 }
825                                 else if (sd.bptr->flags < BBREACHED) {
826                                         /* This block is reached for the first time now */
827                                         /* by falling through from the previous block.  */
828                                         /* Create the instack (propagated).             */
829
830                                         stack_create_invars(&sd, sd.bptr, curstack, stackdepth);
831                                 }
832                                 else {
833                                         /* This block has been reached before. now we are */
834                                         /* falling into it from the previous block.       */
835                                         /* Check that stack depth is well-defined.        */
836
837                                         if (!stack_check_invars(&sd, sd.bptr, curstack, stackdepth))
838                                                 return false;
839                                 }
840
841                                 /* reset the new pointer for allocating stackslots */
842
843                                 sd.new = jd->new_stack;
844
845                                 /* create the instack of this block */
846
847                                 curstack = stack_create_instack(&sd);
848
849                                 /* set up local variables for analyzing this block */
850
851                                 deadcode = false;
852                                 superblockend = false;
853                                 len = sd.bptr->icount;
854                                 iptr = sd.bptr->iinstr;
855                                 b_index = sd.bptr - jd->new_basicblocks;
856
857                                 /* mark the block as analysed */
858
859                                 sd.bptr->flags = BBFINISHED;
860
861                                 /* reset variables for dependency checking */
862
863                                 coalescing_boundary = sd.new;
864                                 for( i = 0; i < cd->maxlocals; i++)
865                                         last_store_boundary[i] = sd.new;
866
867                                 /* remember the start of this block's variables */
868   
869                                 sd.bptr->varstart = sd.vartop;
870   
871 #if defined(STACK_VERBOSE)
872                                         printf("INVARS - indices:\t\n");
873                                         for (i=0; i<sd.bptr->indepth; ++i) {
874                                                 printf("%d ", sd.bptr->invars[i]);
875                                         }
876                                         printf("\n\n");
877 #endif
878
879                                 /* iterate over ICMDs ****************************************/
880
881                                 while (--len >= 0)  {
882
883 #if defined(STACK_VERBOSE)
884                                         new_show_icmd(jd, iptr, false, SHOW_PARSE); printf("\n");
885                                         for( copy = curstack; copy; copy = copy->prev ) {
886                                                 printf("%2d(%d", copy->varnum, copy->type);
887                                                 if (IS_OUTVAR(copy))
888                                                         printf("S");
889                                                 if (IS_PREALLOC(copy))
890                                                         printf("A");
891                                                 printf(") ");
892                                         }
893                                         printf("\n");
894 #endif
895
896                                         /* fetch the current opcode */
897
898                                         opcode = iptr->opc;
899
900                                         /* automatically replace some ICMDs with builtins */
901
902 #if defined(USEBUILTINTABLE)
903                                         IF_NO_INTRP(
904                                                 bte = builtintable_get_automatic(opcode);
905
906                                                 if (bte && bte->opcode == opcode) {
907                                                         iptr->opc           = ICMD_BUILTIN;
908                                                         iptr->flags.bits    = 0;
909                                                         iptr->sx.s23.s3.bte = bte;
910                                                         /* iptr->line is already set */
911                                                         jd->isleafmethod = false;
912                                                         goto icmd_BUILTIN;
913                                                 }
914                                         );
915 #endif /* defined(USEBUILTINTABLE) */
916
917                                         /* main opcode switch *************************************/
918
919                                         switch (opcode) {
920
921                                                 /* pop 0 push 0 */
922
923                                         case ICMD_NOP:
924 icmd_NOP:
925                                                 CLR_SX;
926                                                 OP0_0;
927                                                 break;
928
929                                         case ICMD_CHECKNULL:
930                                                 coalescing_boundary = sd.new;
931                                                 COUNT(count_check_null);
932                                                 USE_S1(TYPE_ADR);
933                                                 CLR_SX;
934                                                 CLR_DST; /* XXX live through? */
935                                                 break;
936
937                                         case ICMD_RET:
938                                                 iptr->s1.varindex = 
939                                                         jd->local_map[iptr->s1.varindex * 5 + TYPE_ADR];
940                 
941                                                 USE_S1_LOCAL(TYPE_ADR);
942                                                 CLR_SX;
943                                                 CLR_DST;
944 #if 0
945                                                 IF_NO_INTRP( rd->locals[iptr->s1.localindex/*XXX invalid here*/][TYPE_ADR].type = TYPE_ADR; );
946 #endif
947                                                 superblockend = true;
948                                                 break;
949
950                                         case ICMD_RETURN:
951                                                 COUNT(count_pcmd_return);
952                                                 CLR_SX;
953                                                 OP0_0;
954                                                 superblockend = true;
955                                                 break;
956
957
958                                                 /* pop 0 push 1 const */
959
960         /************************** ICONST OPTIMIZATIONS **************************/
961
962                                         case ICMD_ICONST:
963                                                 COUNT(count_pcmd_load);
964                                                 if (len == 0)
965                                                         goto normal_ICONST;
966
967                                                 switch (iptr[1].opc) {
968                                                         case ICMD_IADD:
969                                                                 iptr->opc = ICMD_IADDCONST;
970                                                                 /* FALLTHROUGH */
971
972                                                         icmd_iconst_tail:
973                                                                 iptr[1].opc = ICMD_NOP;
974                                                                 OP1_1(TYPE_INT, TYPE_INT);
975                                                                 COUNT(count_pcmd_op);
976                                                                 break;
977
978                                                         case ICMD_ISUB:
979                                                                 iptr->opc = ICMD_ISUBCONST;
980                                                                 goto icmd_iconst_tail;
981 #if SUPPORT_CONST_MUL
982                                                         case ICMD_IMUL:
983                                                                 iptr->opc = ICMD_IMULCONST;
984                                                                 goto icmd_iconst_tail;
985 #else /* SUPPORT_CONST_MUL */
986                                                         case ICMD_IMUL:
987                                                                 if (iptr->sx.val.i == 0x00000002)
988                                                                         iptr->sx.val.i = 1;
989                                                                 else if (iptr->sx.val.i == 0x00000004)
990                                                                         iptr->sx.val.i = 2;
991                                                                 else if (iptr->sx.val.i == 0x00000008)
992                                                                         iptr->sx.val.i = 3;
993                                                                 else if (iptr->sx.val.i == 0x00000010)
994                                                                         iptr->sx.val.i = 4;
995                                                                 else if (iptr->sx.val.i == 0x00000020)
996                                                                         iptr->sx.val.i = 5;
997                                                                 else if (iptr->sx.val.i == 0x00000040)
998                                                                         iptr->sx.val.i = 6;
999                                                                 else if (iptr->sx.val.i == 0x00000080)
1000                                                                         iptr->sx.val.i = 7;
1001                                                                 else if (iptr->sx.val.i == 0x00000100)
1002                                                                         iptr->sx.val.i = 8;
1003                                                                 else if (iptr->sx.val.i == 0x00000200)
1004                                                                         iptr->sx.val.i = 9;
1005                                                                 else if (iptr->sx.val.i == 0x00000400)
1006                                                                         iptr->sx.val.i = 10;
1007                                                                 else if (iptr->sx.val.i == 0x00000800)
1008                                                                         iptr->sx.val.i = 11;
1009                                                                 else if (iptr->sx.val.i == 0x00001000)
1010                                                                         iptr->sx.val.i = 12;
1011                                                                 else if (iptr->sx.val.i == 0x00002000)
1012                                                                         iptr->sx.val.i = 13;
1013                                                                 else if (iptr->sx.val.i == 0x00004000)
1014                                                                         iptr->sx.val.i = 14;
1015                                                                 else if (iptr->sx.val.i == 0x00008000)
1016                                                                         iptr->sx.val.i = 15;
1017                                                                 else if (iptr->sx.val.i == 0x00010000)
1018                                                                         iptr->sx.val.i = 16;
1019                                                                 else if (iptr->sx.val.i == 0x00020000)
1020                                                                         iptr->sx.val.i = 17;
1021                                                                 else if (iptr->sx.val.i == 0x00040000)
1022                                                                         iptr->sx.val.i = 18;
1023                                                                 else if (iptr->sx.val.i == 0x00080000)
1024                                                                         iptr->sx.val.i = 19;
1025                                                                 else if (iptr->sx.val.i == 0x00100000)
1026                                                                         iptr->sx.val.i = 20;
1027                                                                 else if (iptr->sx.val.i == 0x00200000)
1028                                                                         iptr->sx.val.i = 21;
1029                                                                 else if (iptr->sx.val.i == 0x00400000)
1030                                                                         iptr->sx.val.i = 22;
1031                                                                 else if (iptr->sx.val.i == 0x00800000)
1032                                                                         iptr->sx.val.i = 23;
1033                                                                 else if (iptr->sx.val.i == 0x01000000)
1034                                                                         iptr->sx.val.i = 24;
1035                                                                 else if (iptr->sx.val.i == 0x02000000)
1036                                                                         iptr->sx.val.i = 25;
1037                                                                 else if (iptr->sx.val.i == 0x04000000)
1038                                                                         iptr->sx.val.i = 26;
1039                                                                 else if (iptr->sx.val.i == 0x08000000)
1040                                                                         iptr->sx.val.i = 27;
1041                                                                 else if (iptr->sx.val.i == 0x10000000)
1042                                                                         iptr->sx.val.i = 28;
1043                                                                 else if (iptr->sx.val.i == 0x20000000)
1044                                                                         iptr->sx.val.i = 29;
1045                                                                 else if (iptr->sx.val.i == 0x40000000)
1046                                                                         iptr->sx.val.i = 30;
1047                                                                 else if (iptr->sx.val.i == 0x80000000)
1048                                                                         iptr->sx.val.i = 31;
1049                                                                 else
1050                                                                         goto normal_ICONST;
1051
1052                                                                 iptr->opc = ICMD_IMULPOW2;
1053                                                                 goto icmd_iconst_tail;
1054 #endif /* SUPPORT_CONST_MUL */
1055                                                         case ICMD_IDIV:
1056                                                                 if (iptr->sx.val.i == 0x00000002)
1057                                                                         iptr->sx.val.i = 1;
1058                                                                 else if (iptr->sx.val.i == 0x00000004)
1059                                                                         iptr->sx.val.i = 2;
1060                                                                 else if (iptr->sx.val.i == 0x00000008)
1061                                                                         iptr->sx.val.i = 3;
1062                                                                 else if (iptr->sx.val.i == 0x00000010)
1063                                                                         iptr->sx.val.i = 4;
1064                                                                 else if (iptr->sx.val.i == 0x00000020)
1065                                                                         iptr->sx.val.i = 5;
1066                                                                 else if (iptr->sx.val.i == 0x00000040)
1067                                                                         iptr->sx.val.i = 6;
1068                                                                 else if (iptr->sx.val.i == 0x00000080)
1069                                                                         iptr->sx.val.i = 7;
1070                                                                 else if (iptr->sx.val.i == 0x00000100)
1071                                                                         iptr->sx.val.i = 8;
1072                                                                 else if (iptr->sx.val.i == 0x00000200)
1073                                                                         iptr->sx.val.i = 9;
1074                                                                 else if (iptr->sx.val.i == 0x00000400)
1075                                                                         iptr->sx.val.i = 10;
1076                                                                 else if (iptr->sx.val.i == 0x00000800)
1077                                                                         iptr->sx.val.i = 11;
1078                                                                 else if (iptr->sx.val.i == 0x00001000)
1079                                                                         iptr->sx.val.i = 12;
1080                                                                 else if (iptr->sx.val.i == 0x00002000)
1081                                                                         iptr->sx.val.i = 13;
1082                                                                 else if (iptr->sx.val.i == 0x00004000)
1083                                                                         iptr->sx.val.i = 14;
1084                                                                 else if (iptr->sx.val.i == 0x00008000)
1085                                                                         iptr->sx.val.i = 15;
1086                                                                 else if (iptr->sx.val.i == 0x00010000)
1087                                                                         iptr->sx.val.i = 16;
1088                                                                 else if (iptr->sx.val.i == 0x00020000)
1089                                                                         iptr->sx.val.i = 17;
1090                                                                 else if (iptr->sx.val.i == 0x00040000)
1091                                                                         iptr->sx.val.i = 18;
1092                                                                 else if (iptr->sx.val.i == 0x00080000)
1093                                                                         iptr->sx.val.i = 19;
1094                                                                 else if (iptr->sx.val.i == 0x00100000)
1095                                                                         iptr->sx.val.i = 20;
1096                                                                 else if (iptr->sx.val.i == 0x00200000)
1097                                                                         iptr->sx.val.i = 21;
1098                                                                 else if (iptr->sx.val.i == 0x00400000)
1099                                                                         iptr->sx.val.i = 22;
1100                                                                 else if (iptr->sx.val.i == 0x00800000)
1101                                                                         iptr->sx.val.i = 23;
1102                                                                 else if (iptr->sx.val.i == 0x01000000)
1103                                                                         iptr->sx.val.i = 24;
1104                                                                 else if (iptr->sx.val.i == 0x02000000)
1105                                                                         iptr->sx.val.i = 25;
1106                                                                 else if (iptr->sx.val.i == 0x04000000)
1107                                                                         iptr->sx.val.i = 26;
1108                                                                 else if (iptr->sx.val.i == 0x08000000)
1109                                                                         iptr->sx.val.i = 27;
1110                                                                 else if (iptr->sx.val.i == 0x10000000)
1111                                                                         iptr->sx.val.i = 28;
1112                                                                 else if (iptr->sx.val.i == 0x20000000)
1113                                                                         iptr->sx.val.i = 29;
1114                                                                 else if (iptr->sx.val.i == 0x40000000)
1115                                                                         iptr->sx.val.i = 30;
1116                                                                 else if (iptr->sx.val.i == 0x80000000)
1117                                                                         iptr->sx.val.i = 31;
1118                                                                 else
1119                                                                         goto normal_ICONST;
1120
1121                                                                 iptr->opc = ICMD_IDIVPOW2;
1122                                                                 goto icmd_iconst_tail;
1123
1124                                                         case ICMD_IREM:
1125                                                                 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
1126                                                                 if ((iptr->sx.val.i == 0x00000002) ||
1127                                                                         (iptr->sx.val.i == 0x00000004) ||
1128                                                                         (iptr->sx.val.i == 0x00000008) ||
1129                                                                         (iptr->sx.val.i == 0x00000010) ||
1130                                                                         (iptr->sx.val.i == 0x00000020) ||
1131                                                                         (iptr->sx.val.i == 0x00000040) ||
1132                                                                         (iptr->sx.val.i == 0x00000080) ||
1133                                                                         (iptr->sx.val.i == 0x00000100) ||
1134                                                                         (iptr->sx.val.i == 0x00000200) ||
1135                                                                         (iptr->sx.val.i == 0x00000400) ||
1136                                                                         (iptr->sx.val.i == 0x00000800) ||
1137                                                                         (iptr->sx.val.i == 0x00001000) ||
1138                                                                         (iptr->sx.val.i == 0x00002000) ||
1139                                                                         (iptr->sx.val.i == 0x00004000) ||
1140                                                                         (iptr->sx.val.i == 0x00008000) ||
1141                                                                         (iptr->sx.val.i == 0x00010000) ||
1142                                                                         (iptr->sx.val.i == 0x00020000) ||
1143                                                                         (iptr->sx.val.i == 0x00040000) ||
1144                                                                         (iptr->sx.val.i == 0x00080000) ||
1145                                                                         (iptr->sx.val.i == 0x00100000) ||
1146                                                                         (iptr->sx.val.i == 0x00200000) ||
1147                                                                         (iptr->sx.val.i == 0x00400000) ||
1148                                                                         (iptr->sx.val.i == 0x00800000) ||
1149                                                                         (iptr->sx.val.i == 0x01000000) ||
1150                                                                         (iptr->sx.val.i == 0x02000000) ||
1151                                                                         (iptr->sx.val.i == 0x04000000) ||
1152                                                                         (iptr->sx.val.i == 0x08000000) ||
1153                                                                         (iptr->sx.val.i == 0x10000000) ||
1154                                                                         (iptr->sx.val.i == 0x20000000) ||
1155                                                                         (iptr->sx.val.i == 0x40000000) ||
1156                                                                         (iptr->sx.val.i == 0x80000000))
1157                                                                 {
1158                                                                         iptr->opc = ICMD_IREMPOW2;
1159                                                                         iptr->sx.val.i -= 1;
1160                                                                         goto icmd_iconst_tail;
1161                                                                 }
1162                                                                 goto normal_ICONST;
1163 #if SUPPORT_CONST_LOGICAL
1164                                                         case ICMD_IAND:
1165                                                                 iptr->opc = ICMD_IANDCONST;
1166                                                                 goto icmd_iconst_tail;
1167
1168                                                         case ICMD_IOR:
1169                                                                 iptr->opc = ICMD_IORCONST;
1170                                                                 goto icmd_iconst_tail;
1171
1172                                                         case ICMD_IXOR:
1173                                                                 iptr->opc = ICMD_IXORCONST;
1174                                                                 goto icmd_iconst_tail;
1175
1176 #endif /* SUPPORT_CONST_LOGICAL */
1177                                                         case ICMD_ISHL:
1178                                                                 iptr->opc = ICMD_ISHLCONST;
1179                                                                 goto icmd_iconst_tail;
1180
1181                                                         case ICMD_ISHR:
1182                                                                 iptr->opc = ICMD_ISHRCONST;
1183                                                                 goto icmd_iconst_tail;
1184
1185                                                         case ICMD_IUSHR:
1186                                                                 iptr->opc = ICMD_IUSHRCONST;
1187                                                                 goto icmd_iconst_tail;
1188 #if SUPPORT_LONG_SHIFT
1189                                                         case ICMD_LSHL:
1190                                                                 iptr->opc = ICMD_LSHLCONST;
1191                                                                 goto icmd_lconst_tail;
1192
1193                                                         case ICMD_LSHR:
1194                                                                 iptr->opc = ICMD_LSHRCONST;
1195                                                                 goto icmd_lconst_tail;
1196
1197                                                         case ICMD_LUSHR:
1198                                                                 iptr->opc = ICMD_LUSHRCONST;
1199                                                                 goto icmd_lconst_tail;
1200 #endif /* SUPPORT_LONG_SHIFT */
1201                                                         case ICMD_IF_ICMPEQ:
1202                                                                 iptr[1].opc = ICMD_IFEQ;
1203                                                                 /* FALLTHROUGH */
1204
1205                                                         icmd_if_icmp_tail:
1206                                                                 /* set the constant for the following icmd */
1207                                                                 iptr[1].sx.val.i = iptr->sx.val.i;
1208
1209                                                                 /* this instruction becomes a nop */
1210                                                                 iptr->opc = ICMD_NOP;
1211                                                                 goto icmd_NOP;
1212
1213                                                         case ICMD_IF_ICMPLT:
1214                                                                 iptr[1].opc = ICMD_IFLT;
1215                                                                 goto icmd_if_icmp_tail;
1216
1217                                                         case ICMD_IF_ICMPLE:
1218                                                                 iptr[1].opc = ICMD_IFLE;
1219                                                                 goto icmd_if_icmp_tail;
1220
1221                                                         case ICMD_IF_ICMPNE:
1222                                                                 iptr[1].opc = ICMD_IFNE;
1223                                                                 goto icmd_if_icmp_tail;
1224
1225                                                         case ICMD_IF_ICMPGT:
1226                                                                 iptr[1].opc = ICMD_IFGT;
1227                                                                 goto icmd_if_icmp_tail;
1228
1229                                                         case ICMD_IF_ICMPGE:
1230                                                                 iptr[1].opc = ICMD_IFGE;
1231                                                                 goto icmd_if_icmp_tail;
1232
1233 #if SUPPORT_CONST_STORE
1234                                                         case ICMD_IASTORE:
1235                                                         case ICMD_BASTORE:
1236                                                         case ICMD_CASTORE:
1237                                                         case ICMD_SASTORE:
1238                                                                 IF_INTRP( goto normal_ICONST; )
1239 # if SUPPORT_CONST_STORE_ZERO_ONLY
1240                                                                 if (iptr->sx.val.i != 0)
1241                                                                         goto normal_ICONST;
1242 # endif
1243                                                                 switch (iptr[1].opc) {
1244                                                                         case ICMD_IASTORE:
1245                                                                                 iptr->opc = ICMD_IASTORECONST;
1246                                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
1247                                                                                 break;
1248                                                                         case ICMD_BASTORE:
1249                                                                                 iptr->opc = ICMD_BASTORECONST;
1250                                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
1251                                                                                 break;
1252                                                                         case ICMD_CASTORE:
1253                                                                                 iptr->opc = ICMD_CASTORECONST;
1254                                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
1255                                                                                 break;
1256                                                                         case ICMD_SASTORE:
1257                                                                                 iptr->opc = ICMD_SASTORECONST;
1258                                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
1259                                                                                 break;
1260                                                                 }
1261
1262                                                                 iptr[1].opc = ICMD_NOP;
1263
1264                                                                 /* copy the constant to s3 */
1265                                                                 /* XXX constval -> astoreconstval? */
1266                                                                 iptr->sx.s23.s3.constval = iptr->sx.val.i;
1267                                                                 OP2_0(TYPE_ADR, TYPE_INT);
1268                                                                 COUNT(count_pcmd_op);
1269                                                                 break;
1270
1271                                                         case ICMD_PUTSTATIC:
1272                                                         case ICMD_PUTFIELD:
1273                                                                 IF_INTRP( goto normal_ICONST; )
1274 # if SUPPORT_CONST_STORE_ZERO_ONLY
1275                                                                 if (iptr->sx.val.i != 0)
1276                                                                         goto normal_ICONST;
1277 # endif
1278                                                                 /* XXX check field type? */
1279
1280                                                                 /* copy the constant to s2 */
1281                                                                 /* XXX constval -> fieldconstval? */
1282                                                                 iptr->sx.s23.s2.constval = iptr->sx.val.i;
1283
1284 putconst_tail:
1285                                                                 /* set the field reference (s3) */
1286                                                                 if (iptr[1].flags.bits & INS_FLAG_UNRESOLVED) {
1287                                                                         iptr->sx.s23.s3.uf = iptr[1].sx.s23.s3.uf;
1288                                                                         iptr->flags.bits |= INS_FLAG_UNRESOLVED;
1289                                                                 }
1290                                                                 else {
1291                                                                         iptr->sx.s23.s3.fmiref = iptr[1].sx.s23.s3.fmiref;
1292                                                                 }
1293                                                                 
1294                                                                 switch (iptr[1].opc) {
1295                                                                         case ICMD_PUTSTATIC:
1296                                                                                 iptr->opc = ICMD_PUTSTATICCONST;
1297                                                                                 OP0_0;
1298                                                                                 break;
1299                                                                         case ICMD_PUTFIELD:
1300                                                                                 iptr->opc = ICMD_PUTFIELDCONST;
1301                                                                                 OP1_0(TYPE_ADR);
1302                                                                                 break;
1303                                                                 }
1304
1305                                                                 iptr[1].opc = ICMD_NOP;
1306                                                                 COUNT(count_pcmd_op);
1307                                                                 break;
1308 #endif /* SUPPORT_CONST_STORE */
1309
1310                                                         default:
1311                                                                 goto normal_ICONST;
1312                                                 }
1313
1314                                                 /* if we get here, the ICONST has been optimized */
1315                                                 break;
1316
1317 normal_ICONST:
1318                                                 /* normal case of an unoptimized ICONST */
1319                                                 OP0_1(TYPE_INT);
1320                                                 break;
1321
1322         /************************** LCONST OPTIMIZATIONS **************************/
1323
1324                                         case ICMD_LCONST:
1325                                                 COUNT(count_pcmd_load);
1326                                                 if (len == 0)
1327                                                         goto normal_LCONST;
1328
1329                                                 /* switch depending on the following instruction */
1330
1331                                                 switch (iptr[1].opc) {
1332 #if SUPPORT_LONG_ADD
1333                                                         case ICMD_LADD:
1334                                                                 iptr->opc = ICMD_LADDCONST;
1335                                                                 /* FALLTHROUGH */
1336
1337                                                         icmd_lconst_tail:
1338                                                                 /* instruction of type LONG -> LONG */
1339                                                                 iptr[1].opc = ICMD_NOP;
1340                                                                 OP1_1(TYPE_LNG, TYPE_LNG);
1341                                                                 COUNT(count_pcmd_op);
1342                                                                 break;
1343
1344                                                         case ICMD_LSUB:
1345                                                                 iptr->opc = ICMD_LSUBCONST;
1346                                                                 goto icmd_lconst_tail;
1347
1348 #endif /* SUPPORT_LONG_ADD */
1349 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
1350                                                         case ICMD_LMUL:
1351                                                                 iptr->opc = ICMD_LMULCONST;
1352                                                                 goto icmd_lconst_tail;
1353 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1354 # if SUPPORT_LONG_SHIFT
1355                                                         case ICMD_LMUL:
1356                                                                 if (iptr->sx.val.l == 0x00000002)
1357                                                                         iptr->sx.val.i = 1;
1358                                                                 else if (iptr->sx.val.l == 0x00000004)
1359                                                                         iptr->sx.val.i = 2;
1360                                                                 else if (iptr->sx.val.l == 0x00000008)
1361                                                                         iptr->sx.val.i = 3;
1362                                                                 else if (iptr->sx.val.l == 0x00000010)
1363                                                                         iptr->sx.val.i = 4;
1364                                                                 else if (iptr->sx.val.l == 0x00000020)
1365                                                                         iptr->sx.val.i = 5;
1366                                                                 else if (iptr->sx.val.l == 0x00000040)
1367                                                                         iptr->sx.val.i = 6;
1368                                                                 else if (iptr->sx.val.l == 0x00000080)
1369                                                                         iptr->sx.val.i = 7;
1370                                                                 else if (iptr->sx.val.l == 0x00000100)
1371                                                                         iptr->sx.val.i = 8;
1372                                                                 else if (iptr->sx.val.l == 0x00000200)
1373                                                                         iptr->sx.val.i = 9;
1374                                                                 else if (iptr->sx.val.l == 0x00000400)
1375                                                                         iptr->sx.val.i = 10;
1376                                                                 else if (iptr->sx.val.l == 0x00000800)
1377                                                                         iptr->sx.val.i = 11;
1378                                                                 else if (iptr->sx.val.l == 0x00001000)
1379                                                                         iptr->sx.val.i = 12;
1380                                                                 else if (iptr->sx.val.l == 0x00002000)
1381                                                                         iptr->sx.val.i = 13;
1382                                                                 else if (iptr->sx.val.l == 0x00004000)
1383                                                                         iptr->sx.val.i = 14;
1384                                                                 else if (iptr->sx.val.l == 0x00008000)
1385                                                                         iptr->sx.val.i = 15;
1386                                                                 else if (iptr->sx.val.l == 0x00010000)
1387                                                                         iptr->sx.val.i = 16;
1388                                                                 else if (iptr->sx.val.l == 0x00020000)
1389                                                                         iptr->sx.val.i = 17;
1390                                                                 else if (iptr->sx.val.l == 0x00040000)
1391                                                                         iptr->sx.val.i = 18;
1392                                                                 else if (iptr->sx.val.l == 0x00080000)
1393                                                                         iptr->sx.val.i = 19;
1394                                                                 else if (iptr->sx.val.l == 0x00100000)
1395                                                                         iptr->sx.val.i = 20;
1396                                                                 else if (iptr->sx.val.l == 0x00200000)
1397                                                                         iptr->sx.val.i = 21;
1398                                                                 else if (iptr->sx.val.l == 0x00400000)
1399                                                                         iptr->sx.val.i = 22;
1400                                                                 else if (iptr->sx.val.l == 0x00800000)
1401                                                                         iptr->sx.val.i = 23;
1402                                                                 else if (iptr->sx.val.l == 0x01000000)
1403                                                                         iptr->sx.val.i = 24;
1404                                                                 else if (iptr->sx.val.l == 0x02000000)
1405                                                                         iptr->sx.val.i = 25;
1406                                                                 else if (iptr->sx.val.l == 0x04000000)
1407                                                                         iptr->sx.val.i = 26;
1408                                                                 else if (iptr->sx.val.l == 0x08000000)
1409                                                                         iptr->sx.val.i = 27;
1410                                                                 else if (iptr->sx.val.l == 0x10000000)
1411                                                                         iptr->sx.val.i = 28;
1412                                                                 else if (iptr->sx.val.l == 0x20000000)
1413                                                                         iptr->sx.val.i = 29;
1414                                                                 else if (iptr->sx.val.l == 0x40000000)
1415                                                                         iptr->sx.val.i = 30;
1416                                                                 else if (iptr->sx.val.l == 0x80000000)
1417                                                                         iptr->sx.val.i = 31;
1418                                                                 else {
1419                                                                         goto normal_LCONST;
1420                                                                 }
1421                                                                 iptr->opc = ICMD_LMULPOW2;
1422                                                                 goto icmd_lconst_tail;
1423 # endif /* SUPPORT_LONG_SHIFT */
1424 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
1425 #if SUPPORT_LONG_DIV_POW2
1426                                                         case ICMD_LDIV:
1427                                                                 if (iptr->sx.val.l == 0x00000002)
1428                                                                         iptr->sx.val.i = 1;
1429                                                                 else if (iptr->sx.val.l == 0x00000004)
1430                                                                         iptr->sx.val.i = 2;
1431                                                                 else if (iptr->sx.val.l == 0x00000008)
1432                                                                         iptr->sx.val.i = 3;
1433                                                                 else if (iptr->sx.val.l == 0x00000010)
1434                                                                         iptr->sx.val.i = 4;
1435                                                                 else if (iptr->sx.val.l == 0x00000020)
1436                                                                         iptr->sx.val.i = 5;
1437                                                                 else if (iptr->sx.val.l == 0x00000040)
1438                                                                         iptr->sx.val.i = 6;
1439                                                                 else if (iptr->sx.val.l == 0x00000080)
1440                                                                         iptr->sx.val.i = 7;
1441                                                                 else if (iptr->sx.val.l == 0x00000100)
1442                                                                         iptr->sx.val.i = 8;
1443                                                                 else if (iptr->sx.val.l == 0x00000200)
1444                                                                         iptr->sx.val.i = 9;
1445                                                                 else if (iptr->sx.val.l == 0x00000400)
1446                                                                         iptr->sx.val.i = 10;
1447                                                                 else if (iptr->sx.val.l == 0x00000800)
1448                                                                         iptr->sx.val.i = 11;
1449                                                                 else if (iptr->sx.val.l == 0x00001000)
1450                                                                         iptr->sx.val.i = 12;
1451                                                                 else if (iptr->sx.val.l == 0x00002000)
1452                                                                         iptr->sx.val.i = 13;
1453                                                                 else if (iptr->sx.val.l == 0x00004000)
1454                                                                         iptr->sx.val.i = 14;
1455                                                                 else if (iptr->sx.val.l == 0x00008000)
1456                                                                         iptr->sx.val.i = 15;
1457                                                                 else if (iptr->sx.val.l == 0x00010000)
1458                                                                         iptr->sx.val.i = 16;
1459                                                                 else if (iptr->sx.val.l == 0x00020000)
1460                                                                         iptr->sx.val.i = 17;
1461                                                                 else if (iptr->sx.val.l == 0x00040000)
1462                                                                         iptr->sx.val.i = 18;
1463                                                                 else if (iptr->sx.val.l == 0x00080000)
1464                                                                         iptr->sx.val.i = 19;
1465                                                                 else if (iptr->sx.val.l == 0x00100000)
1466                                                                         iptr->sx.val.i = 20;
1467                                                                 else if (iptr->sx.val.l == 0x00200000)
1468                                                                         iptr->sx.val.i = 21;
1469                                                                 else if (iptr->sx.val.l == 0x00400000)
1470                                                                         iptr->sx.val.i = 22;
1471                                                                 else if (iptr->sx.val.l == 0x00800000)
1472                                                                         iptr->sx.val.i = 23;
1473                                                                 else if (iptr->sx.val.l == 0x01000000)
1474                                                                         iptr->sx.val.i = 24;
1475                                                                 else if (iptr->sx.val.l == 0x02000000)
1476                                                                         iptr->sx.val.i = 25;
1477                                                                 else if (iptr->sx.val.l == 0x04000000)
1478                                                                         iptr->sx.val.i = 26;
1479                                                                 else if (iptr->sx.val.l == 0x08000000)
1480                                                                         iptr->sx.val.i = 27;
1481                                                                 else if (iptr->sx.val.l == 0x10000000)
1482                                                                         iptr->sx.val.i = 28;
1483                                                                 else if (iptr->sx.val.l == 0x20000000)
1484                                                                         iptr->sx.val.i = 29;
1485                                                                 else if (iptr->sx.val.l == 0x40000000)
1486                                                                         iptr->sx.val.i = 30;
1487                                                                 else if (iptr->sx.val.l == 0x80000000)
1488                                                                         iptr->sx.val.i = 31;
1489                                                                 else {
1490                                                                         goto normal_LCONST;
1491                                                                 }
1492                                                                 iptr->opc = ICMD_LDIVPOW2;
1493                                                                 goto icmd_lconst_tail;
1494 #endif /* SUPPORT_LONG_DIV_POW2 */
1495
1496 #if SUPPORT_LONG_REM_POW2
1497                                                         case ICMD_LREM:
1498                                                                 if ((iptr->sx.val.l == 0x00000002) ||
1499                                                                         (iptr->sx.val.l == 0x00000004) ||
1500                                                                         (iptr->sx.val.l == 0x00000008) ||
1501                                                                         (iptr->sx.val.l == 0x00000010) ||
1502                                                                         (iptr->sx.val.l == 0x00000020) ||
1503                                                                         (iptr->sx.val.l == 0x00000040) ||
1504                                                                         (iptr->sx.val.l == 0x00000080) ||
1505                                                                         (iptr->sx.val.l == 0x00000100) ||
1506                                                                         (iptr->sx.val.l == 0x00000200) ||
1507                                                                         (iptr->sx.val.l == 0x00000400) ||
1508                                                                         (iptr->sx.val.l == 0x00000800) ||
1509                                                                         (iptr->sx.val.l == 0x00001000) ||
1510                                                                         (iptr->sx.val.l == 0x00002000) ||
1511                                                                         (iptr->sx.val.l == 0x00004000) ||
1512                                                                         (iptr->sx.val.l == 0x00008000) ||
1513                                                                         (iptr->sx.val.l == 0x00010000) ||
1514                                                                         (iptr->sx.val.l == 0x00020000) ||
1515                                                                         (iptr->sx.val.l == 0x00040000) ||
1516                                                                         (iptr->sx.val.l == 0x00080000) ||
1517                                                                         (iptr->sx.val.l == 0x00100000) ||
1518                                                                         (iptr->sx.val.l == 0x00200000) ||
1519                                                                         (iptr->sx.val.l == 0x00400000) ||
1520                                                                         (iptr->sx.val.l == 0x00800000) ||
1521                                                                         (iptr->sx.val.l == 0x01000000) ||
1522                                                                         (iptr->sx.val.l == 0x02000000) ||
1523                                                                         (iptr->sx.val.l == 0x04000000) ||
1524                                                                         (iptr->sx.val.l == 0x08000000) ||
1525                                                                         (iptr->sx.val.l == 0x10000000) ||
1526                                                                         (iptr->sx.val.l == 0x20000000) ||
1527                                                                         (iptr->sx.val.l == 0x40000000) ||
1528                                                                         (iptr->sx.val.l == 0x80000000))
1529                                                                 {
1530                                                                         iptr->opc = ICMD_LREMPOW2;
1531                                                                         iptr->sx.val.l -= 1;
1532                                                                         goto icmd_lconst_tail;
1533                                                                 }
1534                                                                 goto normal_LCONST;
1535 #endif /* SUPPORT_LONG_REM_POW2 */
1536
1537 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
1538
1539                                                         case ICMD_LAND:
1540                                                                 iptr->opc = ICMD_LANDCONST;
1541                                                                 goto icmd_lconst_tail;
1542
1543                                                         case ICMD_LOR:
1544                                                                 iptr->opc = ICMD_LORCONST;
1545                                                                 goto icmd_lconst_tail;
1546
1547                                                         case ICMD_LXOR:
1548                                                                 iptr->opc = ICMD_LXORCONST;
1549                                                                 goto icmd_lconst_tail;
1550 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
1551
1552 #if SUPPORT_LONG_CMP_CONST
1553                                                         case ICMD_LCMP:
1554                                                                 if ((len <= 1) || (iptr[2].sx.val.i != 0))
1555                                                                         goto normal_LCONST;
1556
1557                                                                 /* switch on the instruction after LCONST - LCMP */
1558
1559                                                                 switch (iptr[2].opc) {
1560                                                                         case ICMD_IFEQ:
1561                                                                                 iptr->opc = ICMD_IF_LEQ;
1562                                                                                 /* FALLTHROUGH */
1563
1564                                                                         icmd_lconst_lcmp_tail:
1565                                                                                 /* convert LCONST, LCMP, IFXX to IF_LXX */
1566                                                                                 iptr->dst.insindex = iptr[2].dst.insindex;
1567                                                                                 iptr[1].opc = ICMD_NOP;
1568                                                                                 iptr[2].opc = ICMD_NOP;
1569
1570                                                                                 OP1_BRANCH(TYPE_LNG);
1571                                                                                 BRANCH(tbptr, copy);
1572                                                                                 COUNT(count_pcmd_bra);
1573                                                                                 COUNT(count_pcmd_op);
1574                                                                                 break;
1575
1576                                                                         case ICMD_IFNE:
1577                                                                                 iptr->opc = ICMD_IF_LNE;
1578                                                                                 goto icmd_lconst_lcmp_tail;
1579
1580                                                                         case ICMD_IFLT:
1581                                                                                 iptr->opc = ICMD_IF_LLT;
1582                                                                                 goto icmd_lconst_lcmp_tail;
1583
1584                                                                         case ICMD_IFGT:
1585                                                                                 iptr->opc = ICMD_IF_LGT;
1586                                                                                 goto icmd_lconst_lcmp_tail;
1587
1588                                                                         case ICMD_IFLE:
1589                                                                                 iptr->opc = ICMD_IF_LLE;
1590                                                                                 goto icmd_lconst_lcmp_tail;
1591
1592                                                                         case ICMD_IFGE:
1593                                                                                 iptr->opc = ICMD_IF_LGE;
1594                                                                                 goto icmd_lconst_lcmp_tail;
1595
1596                                                                         default:
1597                                                                                 goto normal_LCONST;
1598                                                                 } /* end switch on opcode after LCONST - LCMP */
1599                                                                 break;
1600 #endif /* SUPPORT_LONG_CMP_CONST */
1601
1602 #if SUPPORT_CONST_STORE
1603                                                         case ICMD_LASTORE:
1604                                                                 IF_INTRP( goto normal_LCONST; )
1605 # if SUPPORT_CONST_STORE_ZERO_ONLY
1606                                                                 if (iptr->sx.val.l != 0)
1607                                                                         goto normal_LCONST;
1608 # endif
1609 #if SIZEOF_VOID_P == 4
1610                                                                 /* the constant must fit into a ptrint */
1611                                                                 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1612                                                                         goto normal_LCONST;
1613 #endif
1614                                                                 /* move the constant to s3 */
1615                                                                 iptr->sx.s23.s3.constval = iptr->sx.val.l;
1616
1617                                                                 iptr->opc = ICMD_LASTORECONST;
1618                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
1619                                                                 OP2_0(TYPE_ADR, TYPE_INT);
1620
1621                                                                 iptr[1].opc = ICMD_NOP;
1622                                                                 COUNT(count_pcmd_op);
1623                                                                 break;
1624
1625                                                         case ICMD_PUTSTATIC:
1626                                                         case ICMD_PUTFIELD:
1627                                                                 IF_INTRP( goto normal_LCONST; )
1628 # if SUPPORT_CONST_STORE_ZERO_ONLY
1629                                                                 if (iptr->sx.val.l != 0)
1630                                                                         goto normal_LCONST;
1631 # endif
1632 #if SIZEOF_VOID_P == 4
1633                                                                 /* the constant must fit into a ptrint */
1634                                                                 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
1635                                                                         goto normal_LCONST;
1636 #endif
1637                                                                 /* XXX check field type? */
1638
1639                                                                 /* copy the constant to s2 */
1640                                                                 /* XXX constval -> fieldconstval? */
1641                                                                 iptr->sx.s23.s2.constval = iptr->sx.val.l;
1642
1643                                                                 goto putconst_tail;
1644
1645 #endif /* SUPPORT_CONST_STORE */
1646
1647                                                         default:
1648                                                                 goto normal_LCONST;
1649                                                 } /* end switch opcode after LCONST */
1650
1651                                                 /* if we get here, the LCONST has been optimized */
1652                                                 break;
1653
1654 normal_LCONST:
1655                                                 /* the normal case of an unoptimized LCONST */
1656                                                 OP0_1(TYPE_LNG);
1657                                                 break;
1658
1659         /************************ END OF LCONST OPTIMIZATIONS *********************/
1660
1661                                         case ICMD_FCONST:
1662                                                 COUNT(count_pcmd_load);
1663                                                 OP0_1(TYPE_FLT);
1664                                                 break;
1665
1666                                         case ICMD_DCONST:
1667                                                 COUNT(count_pcmd_load);
1668                                                 OP0_1(TYPE_DBL);
1669                                                 break;
1670
1671         /************************** ACONST OPTIMIZATIONS **************************/
1672
1673                                         case ICMD_ACONST:
1674                                                 coalescing_boundary = sd.new;
1675                                                 COUNT(count_pcmd_load);
1676 #if SUPPORT_CONST_STORE
1677                                                 IF_INTRP( goto normal_ACONST; )
1678
1679                                                 /* We can only optimize if the ACONST is resolved
1680                                                  * and there is an instruction after it. */
1681
1682                                                 if ((len == 0) || (iptr->flags.bits & INS_FLAG_UNRESOLVED))
1683                                                         goto normal_ACONST;
1684
1685                                                 switch (iptr[1].opc) {
1686                                                         case ICMD_AASTORE:
1687                                                                 /* We can only optimize for NULL values
1688                                                                  * here because otherwise a checkcast is
1689                                                                  * required. */
1690                                                                 if (iptr->sx.val.anyptr != NULL)
1691                                                                         goto normal_ACONST;
1692
1693                                                                 /* copy the constant (NULL) to s3 */
1694                                                                 iptr->sx.s23.s3.constval = 0;
1695                                                                 iptr->opc = ICMD_AASTORECONST;
1696                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
1697                                                                 OP2_0(TYPE_ADR, TYPE_INT);
1698
1699                                                                 iptr[1].opc = ICMD_NOP;
1700                                                                 COUNT(count_pcmd_op);
1701                                                                 break;
1702
1703                                                         case ICMD_PUTSTATIC:
1704                                                         case ICMD_PUTFIELD:
1705 # if SUPPORT_CONST_STORE_ZERO_ONLY
1706                                                                 if (iptr->sx.val.anyptr != NULL)
1707                                                                         goto normal_ACONST;
1708 # endif
1709                                                                 /* XXX check field type? */
1710                                                                 /* copy the constant to s2 */
1711                                                                 /* XXX constval -> fieldconstval? */
1712                                                                 iptr->sx.s23.s2.constval = (ptrint) iptr->sx.val.anyptr;
1713
1714                                                                 goto putconst_tail;
1715
1716                                                         default:
1717                                                                 goto normal_ACONST;
1718                                                 }
1719
1720                                                 /* if we get here the ACONST has been optimized */
1721                                                 break;
1722
1723 normal_ACONST:
1724 #endif /* SUPPORT_CONST_STORE */
1725                                                 OP0_1(TYPE_ADR);
1726                                                 break;
1727
1728
1729                                                 /* pop 0 push 1 load */
1730
1731                                         case ICMD_ILOAD:
1732                                         case ICMD_LLOAD:
1733                                         case ICMD_FLOAD:
1734                                         case ICMD_DLOAD:
1735                                         case ICMD_ALOAD:
1736                                                 COUNT(count_load_instruction);
1737                                                 i = opcode - ICMD_ILOAD; /* type */
1738
1739                                                 iptr->s1.varindex = 
1740                                                         jd->local_map[iptr->s1.varindex * 5 + i];
1741                 
1742                                                 LOAD(i, iptr->s1.varindex);
1743                                                 break;
1744
1745                                                 /* pop 2 push 1 */
1746
1747                                         case ICMD_LALOAD:
1748                                         case ICMD_FALOAD:
1749                                         case ICMD_DALOAD:
1750                                         case ICMD_AALOAD:
1751                                                 coalescing_boundary = sd.new;
1752                                                 iptr->flags.bits |= INS_FLAG_CHECK;
1753                                                 COUNT(count_check_null);
1754                                                 COUNT(count_check_bound);
1755                                                 COUNT(count_pcmd_mem);
1756                                                 OP2_1(TYPE_ADR, TYPE_INT, opcode - ICMD_IALOAD);
1757                                                 break;
1758
1759                                         case ICMD_IALOAD:
1760                                         case ICMD_BALOAD:
1761                                         case ICMD_CALOAD:
1762                                         case ICMD_SALOAD:
1763                                                 coalescing_boundary = sd.new;
1764                                                 iptr->flags.bits |= INS_FLAG_CHECK;
1765                                                 COUNT(count_check_null);
1766                                                 COUNT(count_check_bound);
1767                                                 COUNT(count_pcmd_mem);
1768                                                 OP2_1(TYPE_ADR, TYPE_INT, TYPE_INT);
1769                                                 break;
1770
1771                                                 /* pop 0 push 0 iinc */
1772
1773                                         case ICMD_IINC:
1774                                                 STATISTICS_STACKDEPTH_DISTRIBUTION(count_store_depth);
1775
1776                                                 last_store_boundary[iptr->s1.varindex] = sd.new;
1777
1778                                                 iptr->s1.varindex = 
1779                                                         jd->local_map[iptr->s1.varindex * 5 + TYPE_INT];
1780
1781                                                 copy = curstack;
1782                                                 i = stackdepth - 1;
1783                                                 while (copy) {
1784                                                         if ((copy->varkind == LOCALVAR) &&
1785                                                                 (copy->varnum == iptr->s1.varindex))
1786                                                         {
1787                                                                 assert(IS_LOCALVAR(copy));
1788                                                                 SET_TEMPVAR(copy);
1789                                                         }
1790                                                         i--;
1791                                                         copy = copy->prev;
1792                                                 }
1793
1794                                                 iptr->dst.varindex = iptr->s1.varindex;
1795                                                 break;
1796
1797                                                 /* pop 1 push 0 store */
1798
1799                                         case ICMD_ISTORE:
1800                                         case ICMD_LSTORE:
1801                                         case ICMD_FSTORE:
1802                                         case ICMD_DSTORE:
1803                                         case ICMD_ASTORE:
1804                                                 REQUIRE(1);
1805
1806                                                 i = opcode - ICMD_ISTORE; /* type */
1807                                                 javaindex = iptr->dst.varindex;
1808                                                 j = iptr->dst.varindex = 
1809                                                         jd->local_map[javaindex * 5 + i];
1810
1811
1812 #if defined(ENABLE_STATISTICS)
1813                                                 if (opt_stat) {
1814                                                         count_pcmd_store++;
1815                                                         i = sd.new - curstack;
1816                                                         if (i >= 20)
1817                                                                 count_store_length[20]++;
1818                                                         else
1819                                                                 count_store_length[i]++;
1820                                                         i = stackdepth - 1;
1821                                                         if (i >= 10)
1822                                                                 count_store_depth[10]++;
1823                                                         else
1824                                                                 count_store_depth[i]++;
1825                                                 }
1826 #endif
1827                                                 /* check for conflicts as described in Figure 5.2 */
1828
1829                                                 copy = curstack->prev;
1830                                                 i = stackdepth - 2;
1831                                                 while (copy) {
1832                                                         if ((copy->varkind == LOCALVAR) &&
1833                                                                 (copy->varnum == j))
1834                                                         {
1835                                                                 copy->varkind = TEMPVAR;
1836                                                                 assert(IS_LOCALVAR(copy));
1837                                                                 SET_TEMPVAR(copy);
1838                                                         }
1839                                                         i--;
1840                                                         copy = copy->prev;
1841                                                 }
1842
1843                                                 /* if the variable is already coalesced, don't bother */
1844
1845                                                 if (IS_OUTVAR(curstack)
1846                                                         || (curstack->varkind == LOCALVAR 
1847                                                                 && curstack->varnum != j))
1848                                                         goto store_tail;
1849
1850                                                 /* there is no STORE Lj while curstack is live */
1851
1852                                                 if (curstack < last_store_boundary[javaindex])
1853                                                         goto assume_conflict;
1854
1855                                                 /* curstack must be after the coalescing boundary */
1856
1857                                                 if (curstack < coalescing_boundary)
1858                                                         goto assume_conflict;
1859
1860                                                 /* there is no DEF LOCALVAR(j) while curstack is live */
1861
1862                                                 copy = sd.new; /* most recent stackslot created + 1 */
1863                                                 while (--copy > curstack) {
1864                                                         if (copy->varkind == LOCALVAR && copy->varnum == j)
1865                                                                 goto assume_conflict;
1866                                                 }
1867
1868                                                 /* coalesce the temporary variable with Lj */
1869                                                 assert((curstack->varkind == TEMPVAR)
1870                                                                         || (curstack->varkind == UNDEFVAR));
1871                                                 assert(!IS_LOCALVAR(curstack));
1872                                                 assert(!IS_OUTVAR(curstack));
1873                                                 assert(!IS_PREALLOC(curstack));
1874
1875                                                 assert(curstack->creator);
1876                                                 assert(curstack->creator->dst.varindex == curstack->varnum);
1877                                                 RELEASE_INDEX(sd, curstack);
1878                                                 curstack->varkind = LOCALVAR;
1879                                                 curstack->varnum = j;
1880                                                 curstack->creator->dst.varindex = j;
1881                                                 goto store_tail;
1882
1883                                                 /* revert the coalescing, if it has been done earlier */
1884 assume_conflict:
1885                                                 if ((curstack->varkind == LOCALVAR)
1886                                                         && (curstack->varnum == j))
1887                                                 {
1888                                                         assert(IS_LOCALVAR(curstack));
1889                                                         SET_TEMPVAR(curstack);
1890                                                 }
1891
1892                                                 /* remember the stack boundary at this store */
1893 store_tail:
1894                                                 last_store_boundary[javaindex] = sd.new;
1895
1896                                                 STORE(opcode - ICMD_ISTORE, j);
1897                                                 break;
1898
1899                                         /* pop 3 push 0 */
1900
1901                                         case ICMD_AASTORE:
1902                                                 coalescing_boundary = sd.new;
1903                                                 iptr->flags.bits |= INS_FLAG_CHECK;
1904                                                 COUNT(count_check_null);
1905                                                 COUNT(count_check_bound);
1906                                                 COUNT(count_pcmd_mem);
1907
1908                                                 bte = builtintable_get_internal(BUILTIN_canstore);
1909                                                 md = bte->md;
1910
1911                                                 if (md->memuse > rd->memuse)
1912                                                         rd->memuse = md->memuse;
1913                                                 if (md->argintreguse > rd->argintreguse)
1914                                                         rd->argintreguse = md->argintreguse;
1915                                                 /* XXX non-leaf method? */
1916
1917                                                 /* make all stack variables saved */
1918
1919                                                 copy = curstack;
1920                                                 while (copy) {
1921                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
1922                                                         /* in case copy->varnum is/will be a LOCALVAR */
1923                                                         /* once and set back to a non LOCALVAR        */
1924                                                         /* the correct SAVEDVAR flag has to be        */
1925                                                         /* remembered in copy->flags, too             */
1926                                                         copy->flags |= SAVEDVAR;
1927                                                         copy = copy->prev;
1928                                                 }
1929
1930                                                 OP3_0(TYPE_ADR, TYPE_INT, TYPE_ADR);
1931                                                 break;
1932
1933
1934                                         case ICMD_LASTORE:
1935                                         case ICMD_FASTORE:
1936                                         case ICMD_DASTORE:
1937                                                 coalescing_boundary = sd.new;
1938                                                 iptr->flags.bits |= INS_FLAG_CHECK;
1939                                                 COUNT(count_check_null);
1940                                                 COUNT(count_check_bound);
1941                                                 COUNT(count_pcmd_mem);
1942                                                 OP3_0(TYPE_ADR, TYPE_INT, opcode - ICMD_IASTORE);
1943                                                 break;
1944
1945                                         case ICMD_IASTORE:
1946                                         case ICMD_BASTORE:
1947                                         case ICMD_CASTORE:
1948                                         case ICMD_SASTORE:
1949                                                 coalescing_boundary = sd.new;
1950                                                 iptr->flags.bits |= INS_FLAG_CHECK;
1951                                                 COUNT(count_check_null);
1952                                                 COUNT(count_check_bound);
1953                                                 COUNT(count_pcmd_mem);
1954                                                 OP3_0(TYPE_ADR, TYPE_INT, TYPE_INT);
1955                                                 break;
1956
1957                                                 /* pop 1 push 0 */
1958
1959                                         case ICMD_POP:
1960 #ifdef ENABLE_VERIFIER
1961                                                 if (opt_verify) {
1962                                                         REQUIRE(1);
1963                                                         if (IS_2_WORD_TYPE(curstack->type))
1964                                                                 goto throw_stack_category_error;
1965                                                 }
1966 #endif
1967                                                 OP1_0_ANY;
1968                                                 break;
1969
1970                                         case ICMD_IRETURN:
1971                                         case ICMD_LRETURN:
1972                                         case ICMD_FRETURN:
1973                                         case ICMD_DRETURN:
1974                                         case ICMD_ARETURN:
1975                                                 coalescing_boundary = sd.new;
1976                                                 IF_JIT( md_return_alloc(jd, curstack); )
1977                                                 COUNT(count_pcmd_return);
1978                                                 OP1_0(opcode - ICMD_IRETURN);
1979                                                 superblockend = true;
1980                                                 break;
1981
1982                                         case ICMD_ATHROW:
1983                                                 coalescing_boundary = sd.new;
1984                                                 COUNT(count_check_null);
1985                                                 OP1_0(TYPE_ADR);
1986                                                 curstack = NULL; stackdepth = 0;
1987                                                 superblockend = true;
1988                                                 break;
1989
1990                                         case ICMD_PUTSTATIC:
1991                                                 coalescing_boundary = sd.new;
1992                                                 COUNT(count_pcmd_mem);
1993                                                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1994                                                 OP1_0(fmiref->parseddesc.fd->type);
1995                                                 break;
1996
1997                                                 /* pop 1 push 0 branch */
1998
1999                                         case ICMD_IFNULL:
2000                                         case ICMD_IFNONNULL:
2001                                                 COUNT(count_pcmd_bra);
2002                                                 OP1_BRANCH(TYPE_ADR);
2003                                                 BRANCH(tbptr, copy);
2004                                                 break;
2005
2006                                         case ICMD_IFEQ:
2007                                         case ICMD_IFNE:
2008                                         case ICMD_IFLT:
2009                                         case ICMD_IFGE:
2010                                         case ICMD_IFGT:
2011                                         case ICMD_IFLE:
2012                                                 COUNT(count_pcmd_bra);
2013                                                 /* iptr->sx.val.i is set implicitly in parse by
2014                                                    clearing the memory or from IF_ICMPxx
2015                                                    optimization. */
2016
2017                                                 OP1_BRANCH(TYPE_INT);
2018 /*                                              iptr->sx.val.i = 0; */
2019                                                 BRANCH(tbptr, copy);
2020                                                 break;
2021
2022                                                 /* pop 0 push 0 branch */
2023
2024                                         case ICMD_GOTO:
2025                                                 COUNT(count_pcmd_bra);
2026                                                 OP0_BRANCH;
2027                                                 BRANCH(tbptr, copy);
2028                                                 superblockend = true;
2029                                                 break;
2030
2031                                                 /* pop 1 push 0 table branch */
2032
2033                                         case ICMD_TABLESWITCH:
2034                                                 COUNT(count_pcmd_table);
2035                                                 OP1_BRANCH(TYPE_INT);
2036
2037                                                 table = iptr->dst.table;
2038                                                 BRANCH_TARGET(*table, tbptr, copy);
2039                                                 table++;
2040
2041                                                 i = iptr->sx.s23.s3.tablehigh
2042                                                   - iptr->sx.s23.s2.tablelow + 1;
2043
2044                                                 while (--i >= 0) {
2045                                                         BRANCH_TARGET(*table, tbptr, copy);
2046                                                         table++;
2047                                                 }
2048                                                 superblockend = true;
2049                                                 break;
2050
2051                                                 /* pop 1 push 0 table branch */
2052
2053                                         case ICMD_LOOKUPSWITCH:
2054                                                 COUNT(count_pcmd_table);
2055                                                 OP1_BRANCH(TYPE_INT);
2056
2057                                                 BRANCH_TARGET(iptr->sx.s23.s3.lookupdefault, tbptr, copy);
2058
2059                                                 lookup = iptr->dst.lookup;
2060
2061                                                 i = iptr->sx.s23.s2.lookupcount;
2062
2063                                                 while (--i >= 0) {
2064                                                         BRANCH_TARGET(lookup->target, tbptr, copy);
2065                                                         lookup++;
2066                                                 }
2067                                                 superblockend = true;
2068                                                 break;
2069
2070                                         case ICMD_MONITORENTER:
2071                                         case ICMD_MONITOREXIT:
2072                                                 coalescing_boundary = sd.new;
2073                                                 COUNT(count_check_null);
2074                                                 OP1_0(TYPE_ADR);
2075                                                 break;
2076
2077                                                 /* pop 2 push 0 branch */
2078
2079                                         case ICMD_IF_ICMPEQ:
2080                                         case ICMD_IF_ICMPNE:
2081                                         case ICMD_IF_ICMPLT:
2082                                         case ICMD_IF_ICMPGE:
2083                                         case ICMD_IF_ICMPGT:
2084                                         case ICMD_IF_ICMPLE:
2085                                                 COUNT(count_pcmd_bra);
2086                                                 OP2_BRANCH(TYPE_INT, TYPE_INT);
2087                                                 BRANCH(tbptr, copy);
2088                                                 break;
2089
2090                                         case ICMD_IF_ACMPEQ:
2091                                         case ICMD_IF_ACMPNE:
2092                                                 COUNT(count_pcmd_bra);
2093                                                 OP2_BRANCH(TYPE_ADR, TYPE_ADR);
2094                                                 BRANCH(tbptr, copy);
2095                                                 break;
2096
2097                                                 /* pop 2 push 0 */
2098
2099                                         case ICMD_PUTFIELD:
2100                                                 coalescing_boundary = sd.new;
2101                                                 COUNT(count_check_null);
2102                                                 COUNT(count_pcmd_mem);
2103                                                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2104                                                 OP2_0(TYPE_ADR, fmiref->parseddesc.fd->type);
2105                                                 break;
2106
2107                                         case ICMD_POP2:
2108                                                 REQUIRE(1);
2109                                                 if (!IS_2_WORD_TYPE(curstack->type)) {
2110                                                         /* ..., cat1 */
2111 #ifdef ENABLE_VERIFIER
2112                                                         if (opt_verify) {
2113                                                                 REQUIRE(2);
2114                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
2115                                                                         goto throw_stack_category_error;
2116                                                         }
2117 #endif
2118                                                         OP2_0_ANY_ANY; /* pop two slots */
2119                                                 }
2120                                                 else {
2121                                                         iptr->opc = ICMD_POP;
2122                                                         OP1_0_ANY; /* pop one (two-word) slot */
2123                                                 }
2124                                                 break;
2125
2126                                                 /* pop 0 push 1 dup */
2127
2128                                         case ICMD_DUP:
2129 #ifdef ENABLE_VERIFIER
2130                                                 if (opt_verify) {
2131                                                         REQUIRE(1);
2132                                                         if (IS_2_WORD_TYPE(curstack->type))
2133                                                                 goto throw_stack_category_error;
2134                                                 }
2135 #endif
2136                                                 COUNT(count_dup_instruction);
2137
2138 icmd_DUP:
2139                                                 src1 = curstack;
2140
2141                                                 COPY_UP(src1);
2142                                                 coalescing_boundary = sd.new - 1;
2143                                                 break;
2144
2145                                         case ICMD_DUP2:
2146                                                 REQUIRE(1);
2147                                                 if (IS_2_WORD_TYPE(curstack->type)) {
2148                                                         /* ..., cat2 */
2149                                                         iptr->opc = ICMD_DUP;
2150                                                         goto icmd_DUP;
2151                                                 }
2152                                                 else {
2153                                                         REQUIRE(2);
2154                                                         /* ..., ????, cat1 */
2155 #ifdef ENABLE_VERIFIER
2156                                                         if (opt_verify) {
2157                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
2158                                                                         goto throw_stack_category_error;
2159                                                         }
2160 #endif
2161                                                         src1 = curstack->prev;
2162                                                         src2 = curstack;
2163
2164                                                         COPY_UP(src1); iptr++; len--;
2165                                                         COPY_UP(src2);
2166
2167                                                         coalescing_boundary = sd.new;
2168                                                 }
2169                                                 break;
2170
2171                                                 /* pop 2 push 3 dup */
2172
2173                                         case ICMD_DUP_X1:
2174 #ifdef ENABLE_VERIFIER
2175                                                 if (opt_verify) {
2176                                                         REQUIRE(2);
2177                                                         if (IS_2_WORD_TYPE(curstack->type) ||
2178                                                                 IS_2_WORD_TYPE(curstack->prev->type))
2179                                                                         goto throw_stack_category_error;
2180                                                 }
2181 #endif
2182
2183 icmd_DUP_X1:
2184                                                 src1 = curstack->prev;
2185                                                 src2 = curstack;
2186                                                 POPANY; POPANY;
2187                                                 stackdepth -= 2;
2188
2189                                                 DUP_SLOT(src2); dst1 = curstack; stackdepth++;
2190
2191                                                 MOVE_UP(src1); iptr++; len--;
2192                                                 MOVE_UP(src2); iptr++; len--;
2193
2194                                                 COPY_DOWN(curstack, dst1);
2195
2196                                                 coalescing_boundary = sd.new;
2197                                                 break;
2198
2199                                         case ICMD_DUP2_X1:
2200                                                 REQUIRE(2);
2201                                                 if (IS_2_WORD_TYPE(curstack->type)) {
2202                                                         /* ..., ????, cat2 */
2203 #ifdef ENABLE_VERIFIER
2204                                                         if (opt_verify) {
2205                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
2206                                                                         goto throw_stack_category_error;
2207                                                         }
2208 #endif
2209                                                         iptr->opc = ICMD_DUP_X1;
2210                                                         goto icmd_DUP_X1;
2211                                                 }
2212                                                 else {
2213                                                         /* ..., ????, cat1 */
2214 #ifdef ENABLE_VERIFIER
2215                                                         if (opt_verify) {
2216                                                                 REQUIRE(3);
2217                                                                 if (IS_2_WORD_TYPE(curstack->prev->type)
2218                                                                         || IS_2_WORD_TYPE(curstack->prev->prev->type))
2219                                                                                 goto throw_stack_category_error;
2220                                                         }
2221 #endif
2222
2223 icmd_DUP2_X1:
2224                                                         src1 = curstack->prev->prev;
2225                                                         src2 = curstack->prev;
2226                                                         src3 = curstack;
2227                                                         POPANY; POPANY; POPANY;
2228                                                         stackdepth -= 3;
2229
2230                                                         DUP_SLOT(src2); dst1 = curstack; stackdepth++;
2231                                                         DUP_SLOT(src3); dst2 = curstack; stackdepth++;
2232
2233                                                         MOVE_UP(src1); iptr++; len--;
2234                                                         MOVE_UP(src2); iptr++; len--;
2235                                                         MOVE_UP(src3); iptr++; len--;
2236
2237                                                         COPY_DOWN(curstack, dst2); iptr++; len--;
2238                                                         COPY_DOWN(curstack->prev, dst1);
2239
2240                                                         coalescing_boundary = sd.new;
2241                                                 }
2242                                                 break;
2243
2244                                                 /* pop 3 push 4 dup */
2245
2246                                         case ICMD_DUP_X2:
2247                                                 REQUIRE(2);
2248                                                 if (IS_2_WORD_TYPE(curstack->prev->type)) {
2249                                                         /* ..., cat2, ???? */
2250 #ifdef ENABLE_VERIFIER
2251                                                         if (opt_verify) {
2252                                                                 if (IS_2_WORD_TYPE(curstack->type))
2253                                                                         goto throw_stack_category_error;
2254                                                         }
2255 #endif
2256                                                         iptr->opc = ICMD_DUP_X1;
2257                                                         goto icmd_DUP_X1;
2258                                                 }
2259                                                 else {
2260                                                         /* ..., cat1, ???? */
2261 #ifdef ENABLE_VERIFIER
2262                                                         if (opt_verify) {
2263                                                                 REQUIRE(3);
2264                                                                 if (IS_2_WORD_TYPE(curstack->type)
2265                                                                         || IS_2_WORD_TYPE(curstack->prev->prev->type))
2266                                                                                         goto throw_stack_category_error;
2267                                                         }
2268 #endif
2269 icmd_DUP_X2:
2270                                                         src1 = curstack->prev->prev;
2271                                                         src2 = curstack->prev;
2272                                                         src3 = curstack;
2273                                                         POPANY; POPANY; POPANY;
2274                                                         stackdepth -= 3;
2275
2276                                                         DUP_SLOT(src3); dst1 = curstack; stackdepth++;
2277
2278                                                         MOVE_UP(src1); iptr++; len--;
2279                                                         MOVE_UP(src2); iptr++; len--;
2280                                                         MOVE_UP(src3); iptr++; len--;
2281
2282                                                         COPY_DOWN(curstack, dst1);
2283
2284                                                         coalescing_boundary = sd.new;
2285                                                 }
2286                                                 break;
2287
2288                                         case ICMD_DUP2_X2:
2289                                                 REQUIRE(2);
2290                                                 if (IS_2_WORD_TYPE(curstack->type)) {
2291                                                         /* ..., ????, cat2 */
2292                                                         if (IS_2_WORD_TYPE(curstack->prev->type)) {
2293                                                                 /* ..., cat2, cat2 */
2294                                                                 iptr->opc = ICMD_DUP_X1;
2295                                                                 goto icmd_DUP_X1;
2296                                                         }
2297                                                         else {
2298                                                                 /* ..., cat1, cat2 */
2299 #ifdef ENABLE_VERIFIER
2300                                                                 if (opt_verify) {
2301                                                                         REQUIRE(3);
2302                                                                         if (IS_2_WORD_TYPE(curstack->prev->prev->type))
2303                                                                                         goto throw_stack_category_error;
2304                                                                 }
2305 #endif
2306                                                                 iptr->opc = ICMD_DUP_X2;
2307                                                                 goto icmd_DUP_X2;
2308                                                         }
2309                                                 }
2310
2311                                                 REQUIRE(3);
2312                                                 /* ..., ????, ????, cat1 */
2313
2314                                                 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
2315                                                         /* ..., cat2, ????, cat1 */
2316 #ifdef ENABLE_VERIFIER
2317                                                         if (opt_verify) {
2318                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
2319                                                                         goto throw_stack_category_error;
2320                                                         }
2321 #endif
2322                                                         iptr->opc = ICMD_DUP2_X1;
2323                                                         goto icmd_DUP2_X1;
2324                                                 }
2325                                                 else {
2326                                                         /* ..., cat1, ????, cat1 */
2327 #ifdef ENABLE_VERIFIER
2328                                                         if (opt_verify) {
2329                                                                 REQUIRE(4);
2330                                                                 if (IS_2_WORD_TYPE(curstack->prev->type)
2331                                                                         || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
2332                                                                         goto throw_stack_category_error;
2333                                                         }
2334 #endif
2335
2336                                                         src1 = curstack->prev->prev->prev;
2337                                                         src2 = curstack->prev->prev;
2338                                                         src3 = curstack->prev;
2339                                                         src4 = curstack;
2340                                                         POPANY; POPANY; POPANY; POPANY;
2341                                                         stackdepth -= 4;
2342
2343                                                         DUP_SLOT(src3); dst1 = curstack; stackdepth++;
2344                                                         DUP_SLOT(src4); dst2 = curstack; stackdepth++;
2345
2346                                                         MOVE_UP(src1); iptr++; len--;
2347                                                         MOVE_UP(src2); iptr++; len--;
2348                                                         MOVE_UP(src3); iptr++; len--;
2349                                                         MOVE_UP(src4); iptr++; len--;
2350
2351                                                         COPY_DOWN(curstack, dst2); iptr++; len--;
2352                                                         COPY_DOWN(curstack->prev, dst1);
2353
2354                                                         coalescing_boundary = sd.new;
2355                                                 }
2356                                                 break;
2357
2358                                                 /* pop 2 push 2 swap */
2359
2360                                         case ICMD_SWAP:
2361 #ifdef ENABLE_VERIFIER
2362                                                 if (opt_verify) {
2363                                                         REQUIRE(2);
2364                                                         if (IS_2_WORD_TYPE(curstack->type)
2365                                                                 || IS_2_WORD_TYPE(curstack->prev->type))
2366                                                                 goto throw_stack_category_error;
2367                                                 }
2368 #endif
2369
2370                                                 src1 = curstack->prev;
2371                                                 src2 = curstack;
2372                                                 POPANY; POPANY;
2373                                                 stackdepth -= 2;
2374
2375                                                 MOVE_UP(src2); iptr++; len--;
2376                                                 MOVE_UP(src1);
2377
2378                                                 coalescing_boundary = sd.new;
2379                                                 break;
2380
2381                                                 /* pop 2 push 1 */
2382
2383                                         case ICMD_IDIV:
2384                                         case ICMD_IREM:
2385                                                 coalescing_boundary = sd.new;
2386 #if !SUPPORT_DIVISION
2387                                                 bte = iptr->sx.s23.s3.bte;
2388                                                 md = bte->md;
2389
2390                                                 if (md->memuse > rd->memuse)
2391                                                         rd->memuse = md->memuse;
2392                                                 if (md->argintreguse > rd->argintreguse)
2393                                                         rd->argintreguse = md->argintreguse;
2394
2395                                                 /* make all stack variables saved */
2396
2397                                                 copy = curstack;
2398                                                 while (copy) {
2399                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
2400                                                         copy->flags |= SAVEDVAR;
2401                                                         copy = copy->prev;
2402                                                 }
2403                                                 /* FALLTHROUGH */
2404
2405 #endif /* !SUPPORT_DIVISION */
2406
2407                                         case ICMD_ISHL:
2408                                         case ICMD_ISHR:
2409                                         case ICMD_IUSHR:
2410                                         case ICMD_IADD:
2411                                         case ICMD_ISUB:
2412                                         case ICMD_IMUL:
2413                                         case ICMD_IAND:
2414                                         case ICMD_IOR:
2415                                         case ICMD_IXOR:
2416                                                 COUNT(count_pcmd_op);
2417                                                 OP2_1(TYPE_INT, TYPE_INT, TYPE_INT);
2418                                                 break;
2419
2420                                         case ICMD_LDIV:
2421                                         case ICMD_LREM:
2422                                                 coalescing_boundary = sd.new;
2423 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
2424                                                 bte = iptr->sx.s23.s3.bte;
2425                                                 md = bte->md;
2426
2427                                                 if (md->memuse > rd->memuse)
2428                                                         rd->memuse = md->memuse;
2429                                                 if (md->argintreguse > rd->argintreguse)
2430                                                         rd->argintreguse = md->argintreguse;
2431                                                 /* XXX non-leaf method? */
2432
2433                                                 /* make all stack variables saved */
2434
2435                                                 copy = curstack;
2436                                                 while (copy) {
2437                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
2438                                                         copy->flags |= SAVEDVAR;
2439                                                         copy = copy->prev;
2440                                                 }
2441                                                 /* FALLTHROUGH */
2442
2443 #endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
2444
2445                                         case ICMD_LMUL:
2446                                         case ICMD_LADD:
2447                                         case ICMD_LSUB:
2448 #if SUPPORT_LONG_LOGICAL
2449                                         case ICMD_LAND:
2450                                         case ICMD_LOR:
2451                                         case ICMD_LXOR:
2452 #endif /* SUPPORT_LONG_LOGICAL */
2453                                                 COUNT(count_pcmd_op);
2454                                                 OP2_1(TYPE_LNG, TYPE_LNG, TYPE_LNG);
2455                                                 break;
2456
2457                                         case ICMD_LSHL:
2458                                         case ICMD_LSHR:
2459                                         case ICMD_LUSHR:
2460                                                 COUNT(count_pcmd_op);
2461                                                 OP2_1(TYPE_LNG, TYPE_INT, TYPE_LNG);
2462                                                 break;
2463
2464                                         case ICMD_FADD:
2465                                         case ICMD_FSUB:
2466                                         case ICMD_FMUL:
2467                                         case ICMD_FDIV:
2468                                         case ICMD_FREM:
2469                                                 COUNT(count_pcmd_op);
2470                                                 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_FLT);
2471                                                 break;
2472
2473                                         case ICMD_DADD:
2474                                         case ICMD_DSUB:
2475                                         case ICMD_DMUL:
2476                                         case ICMD_DDIV:
2477                                         case ICMD_DREM:
2478                                                 COUNT(count_pcmd_op);
2479                                                 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_DBL);
2480                                                 break;
2481
2482                                         case ICMD_LCMP:
2483                                                 COUNT(count_pcmd_op);
2484 #if SUPPORT_LONG_CMP_CONST
2485                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
2486                                                         goto normal_LCMP;
2487
2488                                                 switch (iptr[1].opc) {
2489                                                 case ICMD_IFEQ:
2490                                                         iptr->opc = ICMD_IF_LCMPEQ;
2491                                                 icmd_lcmp_if_tail:
2492                                                         iptr->dst.insindex = iptr[1].dst.insindex;
2493                                                         iptr[1].opc = ICMD_NOP;
2494
2495                                                         OP2_BRANCH(TYPE_LNG, TYPE_LNG);
2496                                                         BRANCH(tbptr, copy);
2497
2498                                                         COUNT(count_pcmd_bra);
2499                                                         break;
2500                                                 case ICMD_IFNE:
2501                                                         iptr->opc = ICMD_IF_LCMPNE;
2502                                                         goto icmd_lcmp_if_tail;
2503                                                 case ICMD_IFLT:
2504                                                         iptr->opc = ICMD_IF_LCMPLT;
2505                                                         goto icmd_lcmp_if_tail;
2506                                                 case ICMD_IFGT:
2507                                                         iptr->opc = ICMD_IF_LCMPGT;
2508                                                         goto icmd_lcmp_if_tail;
2509                                                 case ICMD_IFLE:
2510                                                         iptr->opc = ICMD_IF_LCMPLE;
2511                                                         goto icmd_lcmp_if_tail;
2512                                                 case ICMD_IFGE:
2513                                                         iptr->opc = ICMD_IF_LCMPGE;
2514                                                         goto icmd_lcmp_if_tail;
2515                                                 default:
2516                                                         goto normal_LCMP;
2517                                                 }
2518                                                 break;
2519 normal_LCMP:
2520 #endif /* SUPPORT_LONG_CMP_CONST */
2521                                                         OP2_1(TYPE_LNG, TYPE_LNG, TYPE_INT);
2522                                                 break;
2523
2524                                                 /* XXX why is this deactivated? */
2525 #if 0
2526                                         case ICMD_FCMPL:
2527                                                 COUNT(count_pcmd_op);
2528                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
2529                                                         goto normal_FCMPL;
2530
2531                                                 switch (iptr[1].opc) {
2532                                                 case ICMD_IFEQ:
2533                                                         iptr->opc = ICMD_IF_FCMPEQ;
2534                                                 icmd_if_fcmpl_tail:
2535                                                         iptr->dst.insindex = iptr[1].dst.insindex;
2536                                                         iptr[1].opc = ICMD_NOP;
2537
2538                                                         OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2539                                                         BRANCH(tbptr, copy);
2540
2541                                                         COUNT(count_pcmd_bra);
2542                                                         break;
2543                                                 case ICMD_IFNE:
2544                                                         iptr->opc = ICMD_IF_FCMPNE;
2545                                                         goto icmd_if_fcmpl_tail;
2546                                                 case ICMD_IFLT:
2547                                                         iptr->opc = ICMD_IF_FCMPL_LT;
2548                                                         goto icmd_if_fcmpl_tail;
2549                                                 case ICMD_IFGT:
2550                                                         iptr->opc = ICMD_IF_FCMPL_GT;
2551                                                         goto icmd_if_fcmpl_tail;
2552                                                 case ICMD_IFLE:
2553                                                         iptr->opc = ICMD_IF_FCMPL_LE;
2554                                                         goto icmd_if_fcmpl_tail;
2555                                                 case ICMD_IFGE:
2556                                                         iptr->opc = ICMD_IF_FCMPL_GE;
2557                                                         goto icmd_if_fcmpl_tail;
2558                                                 default:
2559                                                         goto normal_FCMPL;
2560                                                 }
2561                                                 break;
2562
2563 normal_FCMPL:
2564                                                 OPTT2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2565                                                 break;
2566
2567                                         case ICMD_FCMPG:
2568                                                 COUNT(count_pcmd_op);
2569                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
2570                                                         goto normal_FCMPG;
2571
2572                                                 switch (iptr[1].opc) {
2573                                                 case ICMD_IFEQ:
2574                                                         iptr->opc = ICMD_IF_FCMPEQ;
2575                                                 icmd_if_fcmpg_tail:
2576                                                         iptr->dst.insindex = iptr[1].dst.insindex;
2577                                                         iptr[1].opc = ICMD_NOP;
2578
2579                                                         OP2_BRANCH(TYPE_FLT, TYPE_FLT);
2580                                                         BRANCH(tbptr, copy);
2581
2582                                                         COUNT(count_pcmd_bra);
2583                                                         break;
2584                                                 case ICMD_IFNE:
2585                                                         iptr->opc = ICMD_IF_FCMPNE;
2586                                                         goto icmd_if_fcmpg_tail;
2587                                                 case ICMD_IFLT:
2588                                                         iptr->opc = ICMD_IF_FCMPG_LT;
2589                                                         goto icmd_if_fcmpg_tail;
2590                                                 case ICMD_IFGT:
2591                                                         iptr->opc = ICMD_IF_FCMPG_GT;
2592                                                         goto icmd_if_fcmpg_tail;
2593                                                 case ICMD_IFLE:
2594                                                         iptr->opc = ICMD_IF_FCMPG_LE;
2595                                                         goto icmd_if_fcmpg_tail;
2596                                                 case ICMD_IFGE:
2597                                                         iptr->opc = ICMD_IF_FCMPG_GE;
2598                                                         goto icmd_if_fcmpg_tail;
2599                                                 default:
2600                                                         goto normal_FCMPG;
2601                                                 }
2602                                                 break;
2603
2604 normal_FCMPG:
2605                                                 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2606                                                 break;
2607
2608                                         case ICMD_DCMPL:
2609                                                 COUNT(count_pcmd_op);
2610                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
2611                                                         goto normal_DCMPL;
2612
2613                                                 switch (iptr[1].opc) {
2614                                                 case ICMD_IFEQ:
2615                                                         iptr->opc = ICMD_IF_DCMPEQ;
2616                                                 icmd_if_dcmpl_tail:
2617                                                         iptr->dst.insindex = iptr[1].dst.insindex;
2618                                                         iptr[1].opc = ICMD_NOP;
2619
2620                                                         OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2621                                                         BRANCH(tbptr, copy);
2622
2623                                                         COUNT(count_pcmd_bra);
2624                                                         break;
2625                                                 case ICMD_IFNE:
2626                                                         iptr->opc = ICMD_IF_DCMPNE;
2627                                                         goto icmd_if_dcmpl_tail;
2628                                                 case ICMD_IFLT:
2629                                                         iptr->opc = ICMD_IF_DCMPL_LT;
2630                                                         goto icmd_if_dcmpl_tail;
2631                                                 case ICMD_IFGT:
2632                                                         iptr->opc = ICMD_IF_DCMPL_GT;
2633                                                         goto icmd_if_dcmpl_tail;
2634                                                 case ICMD_IFLE:
2635                                                         iptr->opc = ICMD_IF_DCMPL_LE;
2636                                                         goto icmd_if_dcmpl_tail;
2637                                                 case ICMD_IFGE:
2638                                                         iptr->opc = ICMD_IF_DCMPL_GE;
2639                                                         goto icmd_if_dcmpl_tail;
2640                                                 default:
2641                                                         goto normal_DCMPL;
2642                                                 }
2643                                                 break;
2644
2645 normal_DCMPL:
2646                                                 OPTT2_1(TYPE_DBL, TYPE_INT);
2647                                                 break;
2648
2649                                         case ICMD_DCMPG:
2650                                                 COUNT(count_pcmd_op);
2651                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
2652                                                         goto normal_DCMPG;
2653
2654                                                 switch (iptr[1].opc) {
2655                                                 case ICMD_IFEQ:
2656                                                         iptr->opc = ICMD_IF_DCMPEQ;
2657                                                 icmd_if_dcmpg_tail:
2658                                                         iptr->dst.insindex = iptr[1].dst.insindex;
2659                                                         iptr[1].opc = ICMD_NOP;
2660
2661                                                         OP2_BRANCH(TYPE_DBL, TYPE_DBL);
2662                                                         BRANCH(tbptr, copy);
2663
2664                                                         COUNT(count_pcmd_bra);
2665                                                         break;
2666                                                 case ICMD_IFNE:
2667                                                         iptr->opc = ICMD_IF_DCMPNE;
2668                                                         goto icmd_if_dcmpg_tail;
2669                                                 case ICMD_IFLT:
2670                                                         iptr->opc = ICMD_IF_DCMPG_LT;
2671                                                         goto icmd_if_dcmpg_tail;
2672                                                 case ICMD_IFGT:
2673                                                         iptr->opc = ICMD_IF_DCMPG_GT;
2674                                                         goto icmd_if_dcmpg_tail;
2675                                                 case ICMD_IFLE:
2676                                                         iptr->opc = ICMD_IF_DCMPG_LE;
2677                                                         goto icmd_if_dcmpg_tail;
2678                                                 case ICMD_IFGE:
2679                                                         iptr->opc = ICMD_IF_DCMPG_GE;
2680                                                         goto icmd_if_dcmpg_tail;
2681                                                 default:
2682                                                         goto normal_DCMPG;
2683                                                 }
2684                                                 break;
2685
2686 normal_DCMPG:
2687                                                 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2688                                                 break;
2689 #else
2690                                         case ICMD_FCMPL:
2691                                         case ICMD_FCMPG:
2692                                                 COUNT(count_pcmd_op);
2693                                                 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
2694                                                 break;
2695
2696                                         case ICMD_DCMPL:
2697                                         case ICMD_DCMPG:
2698                                                 COUNT(count_pcmd_op);
2699                                                 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
2700                                                 break;
2701 #endif
2702
2703                                                 /* pop 1 push 1 */
2704
2705                                         case ICMD_INEG:
2706                                         case ICMD_INT2BYTE:
2707                                         case ICMD_INT2CHAR:
2708                                         case ICMD_INT2SHORT:
2709                                                 COUNT(count_pcmd_op);
2710                                                 OP1_1(TYPE_INT, TYPE_INT);
2711                                                 break;
2712                                         case ICMD_LNEG:
2713                                                 COUNT(count_pcmd_op);
2714                                                 OP1_1(TYPE_LNG, TYPE_LNG);
2715                                                 break;
2716                                         case ICMD_FNEG:
2717                                                 COUNT(count_pcmd_op);
2718                                                 OP1_1(TYPE_FLT, TYPE_FLT);
2719                                                 break;
2720                                         case ICMD_DNEG:
2721                                                 COUNT(count_pcmd_op);
2722                                                 OP1_1(TYPE_DBL, TYPE_DBL);
2723                                                 break;
2724
2725                                         case ICMD_I2L:
2726                                                 COUNT(count_pcmd_op);
2727                                                 OP1_1(TYPE_INT, TYPE_LNG);
2728                                                 break;
2729                                         case ICMD_I2F:
2730                                                 COUNT(count_pcmd_op);
2731                                                 OP1_1(TYPE_INT, TYPE_FLT);
2732                                                 break;
2733                                         case ICMD_I2D:
2734                                                 COUNT(count_pcmd_op);
2735                                                 OP1_1(TYPE_INT, TYPE_DBL);
2736                                                 break;
2737                                         case ICMD_L2I:
2738                                                 COUNT(count_pcmd_op);
2739                                                 OP1_1(TYPE_LNG, TYPE_INT);
2740                                                 break;
2741                                         case ICMD_L2F:
2742                                                 COUNT(count_pcmd_op);
2743                                                 OP1_1(TYPE_LNG, TYPE_FLT);
2744                                                 break;
2745                                         case ICMD_L2D:
2746                                                 COUNT(count_pcmd_op);
2747                                                 OP1_1(TYPE_LNG, TYPE_DBL);
2748                                                 break;
2749                                         case ICMD_F2I:
2750                                                 COUNT(count_pcmd_op);
2751                                                 OP1_1(TYPE_FLT, TYPE_INT);
2752                                                 break;
2753                                         case ICMD_F2L:
2754                                                 COUNT(count_pcmd_op);
2755                                                 OP1_1(TYPE_FLT, TYPE_LNG);
2756                                                 break;
2757                                         case ICMD_F2D:
2758                                                 COUNT(count_pcmd_op);
2759                                                 OP1_1(TYPE_FLT, TYPE_DBL);
2760                                                 break;
2761                                         case ICMD_D2I:
2762                                                 COUNT(count_pcmd_op);
2763                                                 OP1_1(TYPE_DBL, TYPE_INT);
2764                                                 break;
2765                                         case ICMD_D2L:
2766                                                 COUNT(count_pcmd_op);
2767                                                 OP1_1(TYPE_DBL, TYPE_LNG);
2768                                                 break;
2769                                         case ICMD_D2F:
2770                                                 COUNT(count_pcmd_op);
2771                                                 OP1_1(TYPE_DBL, TYPE_FLT);
2772                                                 break;
2773
2774                                         case ICMD_CHECKCAST:
2775                                                 coalescing_boundary = sd.new;
2776                                                 if (iptr->flags.bits & INS_FLAG_ARRAY) {
2777                                                         /* array type cast-check */
2778
2779                                                         bte = builtintable_get_internal(BUILTIN_arraycheckcast);
2780                                                         md = bte->md;
2781
2782                                                         if (md->memuse > rd->memuse)
2783                                                                 rd->memuse = md->memuse;
2784                                                         if (md->argintreguse > rd->argintreguse)
2785                                                                 rd->argintreguse = md->argintreguse;
2786
2787                                                         /* make all stack variables saved */
2788
2789                                                         copy = curstack;
2790                                                         while (copy) {
2791                                                                 sd.var[copy->varnum].flags |= SAVEDVAR;
2792                                                                 copy->flags |= SAVEDVAR;
2793                                                                 copy = copy->prev;
2794                                                         }
2795                                                 }
2796                                                 OP1_1(TYPE_ADR, TYPE_ADR);
2797                                                 break;
2798
2799                                         case ICMD_INSTANCEOF:
2800                                         case ICMD_ARRAYLENGTH:
2801                                                 coalescing_boundary = sd.new;
2802                                                 OP1_1(TYPE_ADR, TYPE_INT);
2803                                                 break;
2804
2805                                         case ICMD_NEWARRAY:
2806                                         case ICMD_ANEWARRAY:
2807                                                 coalescing_boundary = sd.new;
2808                                                 OP1_1(TYPE_INT, TYPE_ADR);
2809                                                 break;
2810
2811                                         case ICMD_GETFIELD:
2812                                                 coalescing_boundary = sd.new;
2813                                                 COUNT(count_check_null);
2814                                                 COUNT(count_pcmd_mem);
2815                                                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2816                                                 OP1_1(TYPE_ADR, fmiref->parseddesc.fd->type);
2817                                                 break;
2818
2819                                                 /* pop 0 push 1 */
2820
2821                                         case ICMD_GETSTATIC:
2822                                                 coalescing_boundary = sd.new;
2823                                                 COUNT(count_pcmd_mem);
2824                                                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
2825                                                 OP0_1(fmiref->parseddesc.fd->type);
2826                                                 break;
2827
2828                                         case ICMD_NEW:
2829                                                 coalescing_boundary = sd.new;
2830                                                 OP0_1(TYPE_ADR);
2831                                                 break;
2832
2833                                         case ICMD_JSR:
2834                                                 OP0_1(TYPE_ADR);
2835
2836                                                 BRANCH_TARGET(iptr->sx.s23.s3.jsrtarget, tbptr, copy);
2837
2838                                                 tbptr->type = BBTYPE_SBR;
2839
2840                                                 /* We need to check for overflow right here because
2841                                                  * the pushed value is poped afterwards */
2842                                                 CHECKOVERFLOW;
2843
2844                                                 /* calculate stack after return */
2845                                                 POPANY;
2846                                                 stackdepth--;
2847                                                 break;
2848
2849                                         /* pop many push any */
2850
2851                                         case ICMD_BUILTIN:
2852 icmd_BUILTIN:
2853                                                 bte = iptr->sx.s23.s3.bte;
2854                                                 md = bte->md;
2855                                                 goto _callhandling;
2856
2857                                         case ICMD_INVOKESTATIC:
2858                                         case ICMD_INVOKESPECIAL:
2859                                         case ICMD_INVOKEVIRTUAL:
2860                                         case ICMD_INVOKEINTERFACE:
2861                                                 COUNT(count_pcmd_met);
2862
2863                                                 /* Check for functions to replace with builtin
2864                                                  * functions. */
2865
2866                                                 if (builtintable_replace_function(iptr))
2867                                                         goto icmd_BUILTIN;
2868
2869                                                 INSTRUCTION_GET_METHODDESC(iptr, md);
2870                                                 /* XXX resurrect this COUNT? */
2871 /*                          if (lm->flags & ACC_STATIC) */
2872 /*                              {COUNT(count_check_null);} */
2873
2874                                         _callhandling:
2875
2876                                                 coalescing_boundary = sd.new;
2877
2878                                                 i = md->paramcount;
2879
2880                                                 if (md->memuse > rd->memuse)
2881                                                         rd->memuse = md->memuse;
2882                                                 if (md->argintreguse > rd->argintreguse)
2883                                                         rd->argintreguse = md->argintreguse;
2884                                                 if (md->argfltreguse > rd->argfltreguse)
2885                                                         rd->argfltreguse = md->argfltreguse;
2886
2887                                                 REQUIRE(i);
2888
2889                                                 /* XXX optimize for <= 2 args */
2890                                                 /* XXX not for ICMD_BUILTIN */
2891                                                 iptr->s1.argcount = stackdepth;
2892                                                 iptr->sx.s23.s2.args = DMNEW(s4, stackdepth);
2893
2894                                                 copy = curstack;
2895                                                 for (i-- ; i >= 0; i--) {
2896                                                         iptr->sx.s23.s2.args[i] = copy->varnum;
2897
2898                                                         /* do not change STACKVARs or LOCALVARS to ARGVAR*/
2899                                                         /* ->  won't help anyway */
2900                                                         if (!(IS_OUTVAR(copy) || IS_LOCALVAR(copy))) {
2901
2902 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2903                         /* If we pass float arguments in integer argument registers, we
2904                          * are not allowed to precolor them here. Floats have to be moved
2905                          * to this regs explicitly in codegen().
2906                          * Only arguments that are passed by stack anyway can be precolored
2907                          * (michi 2005/07/24) */
2908                                                         if (!(sd.var[copy->varnum].flags & SAVEDVAR) &&
2909                                                            (!IS_FLT_DBL_TYPE(copy->type) 
2910                                                                 || md->params[i].inmemory)) {
2911 #else
2912                                                         if (!(sd.var[copy->varnum].flags & SAVEDVAR)) {
2913 #endif
2914
2915                                                                 SET_PREALLOC(copy);
2916
2917 #if defined(ENABLE_INTRP)
2918                                                                 if (!opt_intrp) {
2919 #endif
2920                                                                         if (md->params[i].inmemory) {
2921                                                                                 sd.var[copy->varnum].regoff =
2922                                                                                         md->params[i].regoff;
2923                                                                                 sd.var[copy->varnum].flags |= 
2924                                                                                         INMEMORY;
2925                                                                         }
2926                                                                         else {
2927                                                                                 if (IS_FLT_DBL_TYPE(copy->type)) {
2928 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2929                                                                                         assert(0); /* XXX is this assert ok? */
2930 #else
2931                                                                                         sd.var[copy->varnum].regoff = 
2932                                                                                 rd->argfltregs[md->params[i].regoff];
2933 #endif /* SUPPORT_PASS_FLOATARGS_IN_INTREGS */
2934                                                                                 }
2935                                                                                 else {
2936 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
2937                                                                                         if (IS_2_WORD_TYPE(copy->type))
2938                                                                                                 sd.var[copy->varnum].regoff = 
2939                                 PACK_REGS( rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
2940                                                    rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
2941
2942                                                                                         else
2943 #endif /* SUPPORT_COMBINE_INTEGER_REGISTERS */
2944                                                                                                 sd.var[copy->varnum].regoff = 
2945                                                                                 rd->argintregs[md->params[i].regoff];
2946                                                                                 }
2947                                                                         }
2948 #if defined(ENABLE_INTRP)
2949                                                                 } /* end if (!opt_intrp) */
2950 #endif
2951                                                         }
2952                                                         }
2953                                                         copy = copy->prev;
2954                                                 }
2955
2956                                                 /* deal with live-through stack slots "under" the */
2957                                                 /* arguments */
2958                                                 /* XXX not for ICMD_BUILTIN */
2959
2960                                                 i = md->paramcount;
2961
2962                                                 while (copy) {
2963                                                         SET_TEMPVAR(copy);
2964                                                         iptr->sx.s23.s2.args[i++] = copy->varnum;
2965                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
2966                                                         copy = copy->prev;
2967                                                 }
2968
2969                                                 /* pop the arguments */
2970
2971                                                 i = md->paramcount;
2972
2973                                                 stackdepth -= i;
2974                                                 while (--i >= 0) {
2975                                                         POPANY;
2976                                                 }
2977
2978                                                 /* push the return value */
2979
2980                                                 if (md->returntype.type != TYPE_VOID) {
2981                                                         GET_NEW_VAR(sd, new_index, md->returntype.type);
2982                                                         DST(md->returntype.type, new_index);
2983                                                         stackdepth++;
2984                                                 }
2985                                                 break;
2986
2987                                         case ICMD_INLINE_START:
2988                                         case ICMD_INLINE_END:
2989                                                 CLR_S1;
2990                                                 CLR_DST;
2991                                                 break;
2992
2993                                         case ICMD_MULTIANEWARRAY:
2994                                                 coalescing_boundary = sd.new;
2995                                                 if (rd->argintreguse < 3)
2996                                                         rd->argintreguse = 3;
2997
2998                                                 i = iptr->s1.argcount;
2999
3000                                                 REQUIRE(i);
3001
3002                                                 iptr->sx.s23.s2.args = DMNEW(s4, i);
3003
3004 #if defined(SPECIALMEMUSE)
3005 # if defined(__DARWIN__)
3006                                                 if (rd->memuse < (i + INT_ARG_CNT +LA_SIZE_IN_POINTERS))
3007                                                         rd->memuse = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
3008 # else
3009                                                 if (rd->memuse < (i + LA_SIZE_IN_POINTERS + 3))
3010                                                         rd->memuse = i + LA_SIZE_IN_POINTERS + 3;
3011 # endif
3012 #else
3013 # if defined(__I386__)
3014                                                 if (rd->memuse < i + 3)
3015                                                         rd->memuse = i + 3; /* n integer args spilled on stack */
3016 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
3017                                                 if (rd->memuse < i + 2)
3018                                                         rd->memuse = i + 2; /* 4*4 bytes callee save space */
3019 # else
3020                                                 if (rd->memuse < i)
3021                                                         rd->memuse = i; /* n integer args spilled on stack */
3022 # endif /* defined(__I386__) */
3023 #endif
3024                                                 copy = curstack;
3025                                                 while (--i >= 0) {
3026                                         /* check INT type here? Currently typecheck does this. */
3027                                                         iptr->sx.s23.s2.args[i] = copy->varnum;
3028                                                         if (!(sd.var[copy->varnum].flags & SAVEDVAR)
3029                                                                 && (!IS_OUTVAR(copy))
3030                                                                 && (!IS_LOCALVAR(copy)) ) {
3031                                                                 copy->varkind = ARGVAR;
3032                                                                 sd.var[copy->varnum].flags |=
3033                                                                         INMEMORY & PREALLOC;
3034 #if defined(SPECIALMEMUSE)
3035 # if defined(__DARWIN__)
3036                                                                 sd.var[copy->varnum].regoff = i + 
3037                                                                         LA_SIZE_IN_POINTERS + INT_ARG_CNT;
3038 # else
3039                                                                 sd.var[copy->varnum].regoff = i + 
3040                                                                         LA_SIZE_IN_POINTERS + 3;
3041 # endif
3042 #else
3043 # if defined(__I386__)
3044                                                                 sd.var[copy->varnum].regoff = i + 3;
3045 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
3046                                                                 sd.var[copy->varnum].regoff = i + 2;
3047 # else
3048                                                                 sd.var[copy->varnum].regoff = i;
3049 # endif /* defined(__I386__) */
3050 #endif /* defined(SPECIALMEMUSE) */
3051                                                         }
3052                                                         copy = copy->prev;
3053                                                 }
3054                                                 while (copy) {
3055                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
3056                                                         copy = copy->prev;
3057                                                 }
3058
3059                                                 i = iptr->s1.argcount;
3060                                                 stackdepth -= i;
3061                                                 while (--i >= 0) {
3062                                                         POPANY;
3063                                                 }
3064                                                 GET_NEW_VAR(sd, new_index, TYPE_ADR);
3065                                                 DST(TYPE_ADR, new_index);
3066                                                 stackdepth++;
3067                                                 break;
3068
3069                                         default:
3070                                                 *exceptionptr =
3071                                                         new_internalerror("Unknown ICMD %d", opcode);
3072                                                 return false;
3073                                         } /* switch */
3074
3075                                         CHECKOVERFLOW;
3076                                         iptr++;
3077                                 } /* while instructions */
3078
3079                                 /* stack slots at basic block end become interfaces */
3080
3081                                 sd.bptr->outdepth = stackdepth;
3082                                 sd.bptr->outvars = DMNEW(s4, stackdepth);
3083
3084                                 i = stackdepth - 1;
3085                                 for (copy = curstack; copy; i--, copy = copy->prev) {
3086                                         varinfo *v;
3087
3088                                         /* with the new vars rd->interfaces will be removed */
3089                                         /* and all in and outvars have to be STACKVARS!     */
3090                                         /* in the moment i.e. SWAP with in and out vars can */
3091                                         /* create an unresolvable conflict */
3092
3093                                         SET_TEMPVAR(copy);
3094
3095                                         v = sd.var + copy->varnum;
3096                                         v->flags |= OUTVAR;
3097
3098                                         if (jd->interface_map[i*5 + copy->type].flags == UNUSED) {
3099                                                 /* no interface var until now for this depth and */
3100                                                 /* type */
3101                                                 jd->interface_map[i*5 + copy->type].flags = v->flags;
3102                                         }
3103                                         else {
3104                                                 jd->interface_map[i*5 + copy->type].flags |= v->flags;
3105                                         }
3106
3107                                         sd.bptr->outvars[i] = copy->varnum;
3108                                 }
3109
3110                                 /* check if interface slots at basic block begin must be saved */
3111                                 IF_NO_INTRP(
3112                                         for (i=0; i<sd.bptr->indepth; ++i) {
3113                                                 varinfo *v = sd.var + sd.bptr->invars[i];
3114
3115                                                 if (jd->interface_map[i*5 + v->type].flags == UNUSED) {
3116                                                         /* no interface var until now for this depth and */
3117                                                         /* type */
3118                                                         jd->interface_map[i*5 + v->type].flags = v->flags;
3119                                                 }
3120                                                 else {
3121                                                         jd->interface_map[i*5 + v->type].flags |= v->flags;
3122                                                 }
3123                                         }
3124                                 );
3125
3126                                 /* store the number of this block's variables */
3127
3128                                 sd.bptr->varcount = sd.vartop - sd.bptr->varstart;
3129
3130 #if defined(STACK_VERBOSE)
3131                                 printf("OUTVARS\n");
3132                                 /* XXX print something useful here */
3133                                 printf("\n");
3134 #endif
3135
3136                 } /* for blocks */
3137
3138         } while (repeat && !deadcode);
3139
3140         /* gather statistics *****************************************************/
3141
3142 #if defined(ENABLE_STATISTICS)
3143         if (opt_stat) {
3144                 if (jd->new_basicblockcount > count_max_basic_blocks)
3145                         count_max_basic_blocks = jd->new_basicblockcount;
3146                 count_basic_blocks += jd->new_basicblockcount;
3147                 if (jd->new_instructioncount > count_max_javainstr)
3148                         count_max_javainstr = jd->new_instructioncount;
3149                 count_javainstr += jd->new_instructioncount;
3150                 if (jd->new_stackcount > count_upper_bound_new_stack)
3151                         count_upper_bound_new_stack = jd->new_stackcount;
3152                 if ((sd.new - jd->new_stack) > count_max_new_stack)
3153                         count_max_new_stack = (sd.new - jd->new_stack);
3154
3155                 b_count = jd->new_basicblockcount;
3156                 sd.bptr = jd->new_basicblocks;
3157                 while (--b_count >= 0) {
3158                         if (sd.bptr->flags > BBREACHED) {
3159                                 if (sd.bptr->indepth >= 10)
3160                                         count_block_stack[10]++;
3161                                 else
3162                                         count_block_stack[sd.bptr->indepth]++;
3163                                 len = sd.bptr->icount;
3164                                 if (len < 10)
3165                                         count_block_size_distribution[len]++;
3166                                 else if (len <= 12)
3167                                         count_block_size_distribution[10]++;
3168                                 else if (len <= 14)
3169                                         count_block_size_distribution[11]++;
3170                                 else if (len <= 16)
3171                                         count_block_size_distribution[12]++;
3172                                 else if (len <= 18)
3173                                         count_block_size_distribution[13]++;
3174                                 else if (len <= 20)
3175                                         count_block_size_distribution[14]++;
3176                                 else if (len <= 25)
3177                                         count_block_size_distribution[15]++;
3178                                 else if (len <= 30)
3179                                         count_block_size_distribution[16]++;
3180                                 else
3181                                         count_block_size_distribution[17]++;
3182                         }
3183                         sd.bptr++;
3184                 }
3185
3186                 if (iteration_count == 1)
3187                         count_analyse_iterations[0]++;
3188                 else if (iteration_count == 2)
3189                         count_analyse_iterations[1]++;
3190                 else if (iteration_count == 3)
3191                         count_analyse_iterations[2]++;
3192                 else if (iteration_count == 4)
3193                         count_analyse_iterations[3]++;
3194                 else
3195                         count_analyse_iterations[4]++;
3196
3197                 if (jd->new_basicblockcount <= 5)
3198                         count_method_bb_distribution[0]++;
3199                 else if (jd->new_basicblockcount <= 10)
3200                         count_method_bb_distribution[1]++;
3201                 else if (jd->new_basicblockcount <= 15)
3202                         count_method_bb_distribution[2]++;
3203                 else if (jd->new_basicblockcount <= 20)
3204                         count_method_bb_distribution[3]++;
3205                 else if (jd->new_basicblockcount <= 30)
3206                         count_method_bb_distribution[4]++;
3207                 else if (jd->new_basicblockcount <= 40)
3208                         count_method_bb_distribution[5]++;
3209                 else if (jd->new_basicblockcount <= 50)
3210                         count_method_bb_distribution[6]++;
3211                 else if (jd->new_basicblockcount <= 75)
3212                         count_method_bb_distribution[7]++;
3213                 else
3214                         count_method_bb_distribution[8]++;
3215         }
3216 #endif /* defined(ENABLE_STATISTICS) */
3217
3218         /* everything's ok *******************************************************/
3219
3220         return true;
3221
3222         /* goto labels for throwing verifier exceptions **************************/
3223
3224 #if defined(ENABLE_VERIFIER)
3225
3226 throw_stack_underflow:
3227         exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
3228         return false;
3229
3230 throw_stack_overflow:
3231         exceptions_throw_verifyerror(m, "Stack size too large");
3232         return false;
3233
3234 throw_stack_depth_error:
3235         exceptions_throw_verifyerror(m,"Stack depth mismatch");
3236         return false;
3237
3238 throw_stack_type_error:
3239         exceptions_throw_verifyerror_for_stack(m, expectedtype);
3240         return false;
3241
3242 throw_stack_category_error:
3243         exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
3244         return false;
3245
3246 #endif
3247 }
3248
3249
3250 /*
3251  * These are local overrides for various environment variables in Emacs.
3252  * Please do not remove this and leave it at the end of the file, where
3253  * Emacs will automagically detect them.
3254  * ---------------------------------------------------------------------
3255  * Local variables:
3256  * mode: c
3257  * indent-tabs-mode: t
3258  * c-basic-offset: 4
3259  * tab-width: 4
3260  * End:
3261  * vim:noexpandtab:sw=4:ts=4:
3262  */