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