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