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