* src/vm/jit/stack.c (stack_reanalyse_block): Zero line and flags of
[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             Edwin Steiner
29             Christian Thalinger
30             Christian Ullrich
31
32    $Id: stack.c 6206 2006-12-16 20:59:26Z edwin $
33
34 */
35
36
37 #include "config.h"
38
39 #include <assert.h>
40 #include <stdio.h>
41 #include <string.h>
42 #include <limits.h>
43
44 #include "arch.h"
45 #include "md-abi.h"
46
47 #include "mm/memory.h"
48
49 #include "native/native.h"
50
51 #include "toolbox/logging.h"
52
53 #include "vm/global.h"
54 #include "vm/builtin.h"
55 #include "vm/options.h"
56 #include "vm/resolve.h"
57 #include "vm/statistics.h"
58 #include "vm/stringlocal.h"
59 #include "vm/types.h"
60
61 #include "vm/jit/abi.h"
62 #include "vm/jit/cfg.h"
63 #include "vm/jit/codegen-common.h"
64 #include "vm/jit/parse.h"
65 #include "vm/jit/show.h"
66
67 #if defined(ENABLE_DISASSEMBLER)
68 # include "vm/jit/disass.h"
69 #endif
70
71 #include "vm/jit/jit.h"
72 #include "vm/jit/stack.h"
73
74 #if defined(ENABLE_SSA)
75 # include "vm/jit/optimizing/lsra.h"
76 # include "vm/jit/optimizing/ssa.h"
77 #elif defined(ENABLE_LSRA)
78 # include "vm/jit/allocator/lsra.h"
79 #endif
80
81 /*#define STACK_VERBOSE*/
82
83
84 /* macro for saving #ifdefs ***************************************************/
85
86 #if defined(ENABLE_STATISTICS)
87 #define STATISTICS_STACKDEPTH_DISTRIBUTION(distr)                    \
88     do {                                                             \
89         if (opt_stat) {                                              \
90             if (stackdepth >= 10)                                    \
91                 count_store_depth[10]++;                             \
92             else                                                     \
93                 count_store_depth[stackdepth]++;                     \
94         }                                                            \
95     } while (0)
96 #else /* !defined(ENABLE_STATISTICS) */
97 #define STATISTICS_STACKDEPTH_DISTRIBUTION(distr)
98 #endif
99
100
101 #define MIN(a,b)  (((a) < (b)) ? (a) : (b))
102
103
104 /* For returnAddresses we use a field of the typeinfo to store from which  */
105 /* subroutine the returnAddress will return, if used.                      */
106 /* XXX It would be nicer to use typeinfo.typeclass, but the verifier seems */
107 /* to need it initialised to NULL. This should be investigated.            */
108
109 #if defined(ENABLE_VERIFIER)
110 #define SBRSTART  typeinfo.elementclass.any
111 #endif
112
113
114 /* stackdata_t *****************************************************************
115
116    This struct holds internal data during stack analysis.
117
118 *******************************************************************************/
119
120 typedef struct stackdata_t stackdata_t;
121
122 struct stackdata_t {
123     basicblock *bptr;             /* the current basic block being analysed   */
124     stackptr new;                 /* next free stackelement                   */
125     s4 vartop;                    /* next free variable index                 */
126     s4 localcount;                /* number of locals (at the start of var)   */
127     s4 varcount;                  /* maximum number of variables expected     */
128         s4 varsallocated;             /* total number of variables allocated      */
129         s4 maxlocals;                 /* max. number of Java locals               */
130     varinfo *var;                 /* variable array (same as jd->var)         */
131         s4 *javalocals;               /* map from Java locals to jd->var indices  */
132         methodinfo *m;                /* the method being analysed                */
133         jitdata *jd;                  /* current jitdata                          */
134         basicblock *last_real_block;  /* the last block before the empty one      */
135         bool repeat;                  /* if true, iterate the analysis again      */
136         exception_entry **handlers;   /* exception handlers for the current block */
137         exception_entry *extableend;  /* points to the last exception entry       */
138         stackelement exstack;         /* instack for exception handlers           */
139 };
140
141
142 /* macros for allocating/releasing variable indices *****************/
143
144 #define GET_NEW_INDEX(sd, new_varindex)                              \
145     do {                                                             \
146         assert((sd).vartop < (sd).varcount);                         \
147         (new_varindex) = ((sd).vartop)++;                            \
148     } while (0)
149
150 /* Not implemented now - could be used to reuse varindices.         */
151 /* Pay attention to not release a localvar once implementing it!    */
152 #define RELEASE_INDEX(sd, varindex)
153
154 #define GET_NEW_VAR(sd, newvarindex, newtype)                        \
155     do {                                                             \
156         GET_NEW_INDEX((sd), (newvarindex));                          \
157         (sd).var[newvarindex].type = (newtype);                      \
158     } while (0)
159
160
161 /* macros for querying variable properties **************************/
162
163 #define IS_INOUT(sp)                                                 \
164     (sd.var[(sp)->varnum].flags & INOUT)
165
166 #define IS_PREALLOC(sp)                                              \
167     (sd.var[(sp)->varnum].flags & PREALLOC)
168
169 #define IS_TEMPVAR(sp)                                                                                           \
170     ( ((sp)->varnum >= sd.localcount)                                                            \
171       && !(sd.var[(sp)->varnum].flags & (INOUT | PREALLOC)) )
172
173
174 #define IS_LOCALVAR_SD(sd, sp)                                       \
175          ((sp)->varnum < (sd).localcount)
176
177 #define IS_LOCALVAR(sp)                                              \
178     IS_LOCALVAR_SD(sd, (sp))
179
180
181 /* macros for setting variable properties ****************************/
182
183 #define SET_TEMPVAR(sp)                                              \
184     do {                                                             \
185         if (IS_LOCALVAR((sp))) {                                     \
186             stack_change_to_tempvar(&sd, (sp), iptr);                \
187         }                                                            \
188         sd.var[(sp)->varnum].flags &= ~(INOUT | PREALLOC);           \
189     } while (0);
190
191 #define SET_PREALLOC(sp)                                             \
192     do {                                                             \
193         assert(!IS_LOCALVAR((sp)));                                  \
194         sd.var[(sp)->varnum].flags |= PREALLOC;                      \
195     } while (0);
196
197
198 /* macros for source operands ***************************************/
199
200 #define CLR_S1                                                       \
201     (iptr->s1.varindex = -1)
202
203 #define USE_S1(type1)                                                \
204     do {                                                             \
205         REQUIRE(1);                                                  \
206         CHECK_BASIC_TYPE(type1, curstack->type);                     \
207         iptr->s1.varindex = curstack->varnum;                        \
208     } while (0)
209
210 #define USE_S1_ANY                                                   \
211     do {                                                             \
212         REQUIRE(1);                                                  \
213         iptr->s1.varindex = curstack->varnum;                        \
214     } while (0)
215
216 #define USE_S1_S2(type1, type2)                                      \
217     do {                                                             \
218         REQUIRE(2);                                                  \
219         CHECK_BASIC_TYPE(type1, curstack->prev->type);               \
220         CHECK_BASIC_TYPE(type2, curstack->type);                     \
221         iptr->sx.s23.s2.varindex = curstack->varnum;                 \
222         iptr->s1.varindex = curstack->prev->varnum;                  \
223     } while (0)
224
225 #define USE_S1_S2_ANY_ANY                                            \
226     do {                                                             \
227         REQUIRE(2);                                                  \
228         iptr->sx.s23.s2.varindex = curstack->varnum;                 \
229         iptr->s1.varindex = curstack->prev->varnum;                  \
230     } while (0)
231
232 #define USE_S1_S2_S3(type1, type2, type3)                            \
233     do {                                                             \
234         REQUIRE(3);                                                  \
235         CHECK_BASIC_TYPE(type1, curstack->prev->prev->type);         \
236         CHECK_BASIC_TYPE(type2, curstack->prev->type);               \
237         CHECK_BASIC_TYPE(type3, curstack->type);                     \
238         iptr->sx.s23.s3.varindex = curstack->varnum;                 \
239         iptr->sx.s23.s2.varindex = curstack->prev->varnum;           \
240         iptr->s1.varindex = curstack->prev->prev->varnum;            \
241     } while (0)
242
243 /* The POPANY macro does NOT check stackdepth, or set stackdepth!   */
244 #define POPANY                                                       \
245     do {                                                             \
246         if (curstack->varkind == UNDEFVAR)                           \
247             curstack->varkind = TEMPVAR;                             \
248         curstack = curstack->prev;                                   \
249     } while (0)
250
251 #define POP_S1(type1)                                                \
252     do {                                                             \
253         USE_S1(type1);                                               \
254         if (curstack->varkind == UNDEFVAR)                           \
255             curstack->varkind = TEMPVAR;                             \
256         curstack = curstack->prev;                                   \
257     } while (0)
258
259 #define POP_S1_ANY                                                   \
260     do {                                                             \
261         USE_S1_ANY;                                                  \
262         if (curstack->varkind == UNDEFVAR)                           \
263             curstack->varkind = TEMPVAR;                             \
264         curstack = curstack->prev;                                   \
265     } while (0)
266
267 #define POP_S1_S2(type1, type2)                                      \
268     do {                                                             \
269         USE_S1_S2(type1, type2);                                     \
270         if (curstack->varkind == UNDEFVAR)                           \
271             curstack->varkind = TEMPVAR;                             \
272         if (curstack->prev->varkind == UNDEFVAR)                     \
273             curstack->prev->varkind = TEMPVAR;                       \
274         curstack = curstack->prev->prev;                             \
275     } while (0)
276
277 #define POP_S1_S2_ANY_ANY                                            \
278     do {                                                             \
279         USE_S1_S2_ANY_ANY;                                           \
280         if (curstack->varkind == UNDEFVAR)                           \
281             curstack->varkind = TEMPVAR;                             \
282         if (curstack->prev->varkind == UNDEFVAR)                     \
283             curstack->prev->varkind = TEMPVAR;                       \
284         curstack = curstack->prev->prev;                             \
285     } while (0)
286
287 #define POP_S1_S2_S3(type1, type2, type3)                            \
288     do {                                                             \
289         USE_S1_S2_S3(type1, type2, type3);                           \
290         if (curstack->varkind == UNDEFVAR)                           \
291             curstack->varkind = TEMPVAR;                             \
292         if (curstack->prev->varkind == UNDEFVAR)                     \
293             curstack->prev->varkind = TEMPVAR;                       \
294         if (curstack->prev->prev->varkind == UNDEFVAR)               \
295             curstack->prev->prev->varkind = TEMPVAR;                 \
296         curstack = curstack->prev->prev->prev;                       \
297     } while (0)
298
299 #define CLR_SX                                                       \
300     (iptr->sx.val.l = 0)
301
302
303 /* macros for setting the destination operand ***********************/
304
305 #define CLR_DST                                                      \
306     (iptr->dst.varindex = -1)
307
308 #define DST(typed, index)                                            \
309     do {                                                             \
310         NEWSTACKn((typed),(index));                                  \
311         curstack->creator = iptr;                                    \
312         iptr->dst.varindex = (index);                                \
313     } while (0)
314
315 #define DST_LOCALVAR(typed, index)                                   \
316     do {                                                             \
317         NEWSTACK((typed), LOCALVAR, (index));                        \
318         curstack->creator = iptr;                                    \
319         iptr->dst.varindex = (index);                                \
320     } while (0)
321
322
323 /* macro for propagating constant values ****************************/
324
325 #if defined(ENABLE_VERIFIER)
326 #define COPY_VAL_AND_TYPE_VAR(sv, dv)                                \
327     do {                                                             \
328         if (((dv)->type = (sv)->type) == TYPE_RET) {                 \
329             (dv)->vv  = (sv)->vv;                                    \
330             (dv)->SBRSTART = (sv)->SBRSTART;                         \
331         }                                                            \
332     } while (0)
333 #else
334 #define COPY_VAL_AND_TYPE_VAR(sv, dv)                                \
335     do {                                                             \
336         (dv)->type = (sv)->type;                                     \
337         if (((dv)->type = (sv)->type) == TYPE_RET) {                 \
338             (dv)->vv  = (sv)->vv;                                    \
339         }                                                            \
340     } while (0)
341 #endif
342
343 #define COPY_VAL_AND_TYPE(sd, sindex, dindex)                        \
344         COPY_VAL_AND_TYPE_VAR((sd).var + (sindex), (sd).var + (dindex))
345
346
347 /* stack modelling macros *******************************************/
348
349 #define OP0_1(typed)                                                 \
350     do {                                                             \
351         CLR_S1;                                                      \
352         GET_NEW_VAR(sd, new_index, (typed));                         \
353         DST((typed), new_index);                                                                         \
354         stackdepth++;                                                \
355     } while (0)
356
357 #define OP1_0_ANY                                                    \
358     do {                                                             \
359         POP_S1_ANY;                                                  \
360         CLR_DST;                                                     \
361         stackdepth--;                                                \
362     } while (0)
363
364 #define OP1_BRANCH(type1)                                            \
365     do {                                                             \
366         POP_S1(type1);                                               \
367         stackdepth--;                                                \
368     } while (0)
369
370 #define OP1_1(type1, typed)                                          \
371     do {                                                             \
372         POP_S1(type1);                                               \
373         GET_NEW_VAR(sd, new_index, (typed));                         \
374         DST(typed, new_index);                                       \
375     } while (0)
376
377 #define OP2_1(type1, type2, typed)                                   \
378     do {                                                             \
379         POP_S1_S2(type1, type2);                                     \
380         GET_NEW_VAR(sd, new_index, (typed));                         \
381         DST(typed, new_index);                                       \
382         stackdepth--;                                                \
383     } while (0)
384
385 #define OP0_0                                                        \
386     do {                                                             \
387         CLR_S1;                                                      \
388         CLR_DST;                                                     \
389     } while (0)
390
391 #define OP0_BRANCH                                                   \
392     do {                                                             \
393         CLR_S1;                                                      \
394     } while (0)
395
396 #define OP1_0(type1)                                                 \
397     do {                                                             \
398         POP_S1(type1);                                               \
399         CLR_DST;                                                     \
400         stackdepth--;                                                \
401     } while (0)
402
403 #define OP2_0(type1, type2)                                          \
404     do {                                                             \
405         POP_S1_S2(type1, type2);                                     \
406         CLR_DST;                                                     \
407         stackdepth -= 2;                                             \
408     } while (0)
409
410 #define OP2_BRANCH(type1, type2)                                     \
411     do {                                                             \
412         POP_S1_S2(type1, type2);                                     \
413         stackdepth -= 2;                                             \
414     } while (0)
415
416 #define OP2_0_ANY_ANY                                                \
417     do {                                                             \
418         POP_S1_S2_ANY_ANY;                                           \
419         CLR_DST;                                                     \
420         stackdepth -= 2;                                             \
421     } while (0)
422
423 #define OP3_0(type1, type2, type3)                                   \
424     do {                                                             \
425         POP_S1_S2_S3(type1, type2, type3);                           \
426         CLR_DST;                                                     \
427         stackdepth -= 3;                                             \
428     } while (0)
429
430 #define LOAD(type1, index)                                           \
431     do {                                                             \
432         DST_LOCALVAR(type1, index);                                  \
433         stackdepth++;                                                \
434     } while (0)
435
436 #define STORE(type1, index)                                          \
437     do {                                                             \
438         POP_S1(type1);                                               \
439         stackdepth--;                                                \
440     } while (0)
441
442
443 /* macros for DUP elimination ***************************************/
444
445 /* XXX replace NEW_VAR with NEW_INDEX */
446 #define DUP_SLOT(sp)                                                 \
447     do {                                                             \
448         GET_NEW_VAR(sd, new_index, (sp)->type);                      \
449         COPY_VAL_AND_TYPE(sd, (sp)->varnum, new_index);              \
450         NEWSTACK((sp)->type, TEMPVAR, new_index);                    \
451     } while(0)
452
453 /* does not check input stackdepth */
454 #define MOVE_UP(sp)                                                  \
455     do {                                                             \
456         iptr->opc = ICMD_MOVE;                                       \
457         iptr->s1.varindex = (sp)->varnum;                            \
458         DUP_SLOT(sp);                                                \
459         curstack->creator = iptr;                                    \
460         iptr->dst.varindex = curstack->varnum;                       \
461         stackdepth++;                                                \
462     } while (0)
463
464 /* does not check input stackdepth */
465 #define COPY_UP(sp)                                                  \
466     do {                                                             \
467         SET_TEMPVAR((sp));                                           \
468         iptr->opc = ICMD_COPY;                                       \
469         iptr->s1.varindex = (sp)->varnum;                            \
470         DUP_SLOT(sp);                                                \
471         curstack->creator = iptr;                                    \
472         iptr->dst.varindex = curstack->varnum;                       \
473         stackdepth++;                                                \
474     } while (0)
475
476 #define COPY_DOWN(s, d)                                              \
477     do {                                                             \
478         SET_TEMPVAR((s));                                            \
479         iptr->opc = ICMD_COPY;                                       \
480         iptr->s1.varindex = (s)->varnum;                             \
481         iptr->dst.varindex = (d)->varnum;                            \
482         (d)->creator = iptr;                                         \
483     } while (0)
484
485 #define MOVE_TO_TEMP(sp)                                             \
486     do {                                                             \
487         GET_NEW_INDEX(sd, new_index);                                \
488         iptr->opc = ICMD_MOVE;                                       \
489         iptr->s1.varindex = (sp)->varnum;                            \
490         iptr->dst.varindex = new_index;                              \
491         COPY_VAL_AND_TYPE(sd, (sp)->varnum, new_index);              \
492         (sp)->varnum = new_index;                                    \
493                 (sp)->varkind = TEMPVAR;                                     \
494     } while (0)
495
496 /* macros for branching / reaching basic blocks *********************/
497
498 #define BRANCH_TARGET(bt, tempbptr)                                  \
499     do {                                                             \
500         tempbptr = BLOCK_OF((bt).insindex);                          \
501         tempbptr = stack_mark_reached(&sd, tempbptr, curstack,       \
502                                       stackdepth);                   \
503         if (tempbptr == NULL)                                        \
504             return false;                                            \
505         (bt).block = tempbptr;                                       \
506     } while (0)
507
508 #define BRANCH(tempbptr)                                             \
509     BRANCH_TARGET(iptr->dst, tempbptr)
510
511
512 /* forward declarations *******************************************************/
513
514 static void stack_create_invars(stackdata_t *sd, basicblock *b, 
515                                                                 stackptr curstack, int stackdepth);
516 static void stack_create_invars_from_outvars(stackdata_t *sd, basicblock *b);
517
518 #if defined(STACK_VERBOSE)
519 static void stack_verbose_show_varinfo(stackdata_t *sd, varinfo *v);
520 static void stack_verbose_show_variable(stackdata_t *sd, s4 index);
521 static void stack_verbose_show_block(stackdata_t *sd, basicblock *bptr);
522 static void stack_verbose_block_enter(stackdata_t *sd, bool reanalyse);
523 static void stack_verbose_block_exit(stackdata_t *sd, bool superblockend);
524 static void stack_verbose_show_state(stackdata_t *sd, instruction *iptr, 
525                                                                          stackptr curstack);
526 #endif
527
528
529 /* stack_init ******************************************************************
530
531    Initialized the stack analysis subsystem (called by jit_init).
532
533 *******************************************************************************/
534
535 bool stack_init(void)
536 {
537         return true;
538 }
539
540
541 /* stack_grow_variable_array ***************************************************
542
543    Grow the variable array so the given number of additional variables fits in.
544    The number is added to `varcount`, which is the maximum number of variables
545    we expect to need at this point. The actual number of variables
546    (`varsallocated`) may be larger than that, in order to avoid too many
547    reallocations.
548
549    IN:
550       sd...........stack analysis data
551           num..........number of additional variables
552
553 *******************************************************************************/
554
555 static void stack_grow_variable_array(stackdata_t *sd, s4 num)
556 {
557         s4 newsize;
558
559         assert(num >= 0);
560
561         if (sd->varcount + num > sd->varsallocated) {
562                 newsize = 2*sd->varsallocated + num;
563
564                 sd->var = DMREALLOC(sd->var, varinfo, sd->varsallocated, newsize);
565                 MZERO(sd->var + sd->varsallocated, varinfo, (newsize - sd->varsallocated));
566                 sd->varsallocated = newsize;
567                 sd->jd->var = sd->var;
568         }
569
570         sd->varcount += num;
571         sd->jd->varcount += num;
572
573         assert(sd->varcount <= sd->varsallocated);
574 }
575
576
577 /* stack_append_block **********************************************************
578
579    Append the given block after the last real block of the method (before
580    the pseudo-block at the end).
581
582    IN:
583       sd...........stack analysis data
584           b............the block to append
585
586 *******************************************************************************/
587
588 static void stack_append_block(stackdata_t *sd, basicblock *b)
589 {
590 #if defined(STACK_VERBOSE)
591         printf("APPENDING BLOCK L%0d\n", b->nr);
592 #endif
593
594         b->next = sd->last_real_block->next;
595         sd->last_real_block->next = b;
596         sd->last_real_block = b;
597         b->nr = sd->jd->basicblockcount++;
598         b->next->nr = b->nr + 1;
599 }
600
601
602 /* stack_clone_block ***********************************************************
603
604    Create a copy of the given block and insert it at the end of the method.
605
606    CAUTION: This function does not copy the any variables or the instruction
607    list. It _does_, however, reserve space for the block's invars in the
608    variable array.
609
610    IN:
611       sd...........stack analysis data
612           b............the block to clone
613
614    RETURN VALUE:
615       a pointer to the copy
616
617 *******************************************************************************/
618
619 static basicblock * stack_clone_block(stackdata_t *sd, basicblock *b)
620 {
621         basicblock *clone;
622
623         clone = DNEW(basicblock);
624         *clone  = *b;
625
626         clone->iinstr = NULL;
627         clone->inlocals = NULL;
628         clone->javalocals = NULL;
629         clone->invars = NULL;
630
631         clone->original = (b->original) ? b->original : b;
632         clone->copied_to = clone->original->copied_to;
633         clone->original->copied_to = clone;
634         clone->next = NULL;
635         clone->flags = BBREACHED;
636
637         stack_append_block(sd, clone);
638
639         /* reserve space for the invars of the clone */
640
641         stack_grow_variable_array(sd, b->indepth);
642
643 #if defined(STACK_VERBOSE)
644         printf("cloning block L%03d ------> L%03d\n", b->nr, clone->nr);
645 #endif
646
647         return clone;
648 }
649
650
651 /* stack_create_locals *********************************************************
652  
653    Create the local variables for the start of the given basic block.
654
655    IN:
656       sd...........stack analysis data
657           b............block to create the locals for
658
659 *******************************************************************************/
660
661 static void stack_create_locals(stackdata_t *sd, basicblock *b)
662 {
663         s4       i;
664         s4      *jl;
665         varinfo *dv;
666
667         /* copy the current state of the local variables */
668         /* (one extra local is needed by the verifier)   */
669
670         dv = DMNEW(varinfo, sd->localcount + VERIFIER_EXTRA_LOCALS);
671         b->inlocals = dv;
672         for (i=0; i<sd->localcount; ++i)
673                 *dv++ = sd->var[i];
674
675         /* the current map from java locals to cacao variables */
676
677         jl = DMNEW(s4, sd->maxlocals);
678         b->javalocals = jl;
679         MCOPY(jl, sd->javalocals, s4, sd->maxlocals);
680 }
681
682
683 /* stack_merge_locals **********************************************************
684  
685    Merge local variables at the beginning of the given basic block.
686
687    IN:
688       sd...........stack analysis data
689           b............the block that is reached
690
691 *******************************************************************************/
692
693 static void stack_merge_locals(stackdata_t *sd, basicblock *b)
694 {
695         s4 i;
696         varinfo *dv;
697         varinfo *sv;
698
699         /* If a javalocal is mapped to different cacao locals along the */
700         /* incoming control-flow edges, it becomes undefined.           */
701
702         for (i=0; i<sd->maxlocals; ++i) {
703                 if (b->javalocals[i] != UNUSED && b->javalocals[i] != sd->javalocals[i]) {
704                         b->javalocals[i] = UNUSED;
705                         if (b->flags >= BBFINISHED)
706                                 b->flags = BBTYPECHECK_REACHED;
707                         if (b->nr <= sd->bptr->nr)
708                                 sd->repeat = true;
709                 }
710         }
711
712 #if defined(ENABLE_VERIFIER)
713         if (b->inlocals) {
714                 for (i=0; i<sd->localcount; ++i) {
715                         dv = b->inlocals + i;
716                         sv = sd->var + i;
717                         if ((sv->type == TYPE_RET && dv->type == TYPE_RET)
718                                         && (sv->SBRSTART != dv->SBRSTART))
719                         {
720                                 dv->type = TYPE_VOID;
721                                 if (b->flags >= BBFINISHED)
722                                         b->flags = BBTYPECHECK_REACHED;
723                                 sd->repeat = true; /* This is very rare, so just repeat */
724                         }
725                 }
726         }
727 #endif /* defined(ENABLE_VERIFIER) */
728 }
729
730
731 /* stack_create_invars *********************************************************
732
733    Create the invars for the given basic block. Also make a copy of the locals.
734
735    IN:
736       sd...........stack analysis data
737           b............block to create the invars for
738           curstack.....current stack top
739           stackdepth...current stack depth
740
741    This function creates STACKDEPTH invars and sets their types to the
742    types to the types of the corresponding slot in the current stack.
743
744 *******************************************************************************/
745
746 static void stack_create_invars(stackdata_t *sd, basicblock *b, 
747                                                                 stackptr curstack, int stackdepth)
748 {
749         stackptr sp;
750         int i;
751         int index;
752         varinfo *dv;
753         varinfo *sv;
754
755         assert(sd->vartop + stackdepth <= sd->varcount);
756
757         b->indepth = stackdepth;
758         b->invars = DMNEW(s4, stackdepth);
759
760         /* allocate the variable indices */
761         index = (sd->vartop += stackdepth);
762
763         i = stackdepth;
764         for (sp = curstack; i--; sp = sp->prev) {
765                 b->invars[i] = --index;
766                 dv = sd->var + index;
767                 sv = sd->var + sp->varnum;
768                 dv->flags = INOUT;
769                 COPY_VAL_AND_TYPE_VAR(sv, dv);
770         }
771
772         stack_create_locals(sd, b);
773 }
774
775
776 /* stack_create_invars_from_outvars ********************************************
777
778    Create the invars for the given basic block. Also make a copy of the locals.
779    Types are propagated from the outvars of the current block.
780
781    IN:
782       sd...........stack analysis data
783           b............block to create the invars for
784
785 *******************************************************************************/
786
787 static void stack_create_invars_from_outvars(stackdata_t *sd, basicblock *b)
788 {
789         int i;
790         int n;
791         varinfo *sv, *dv;
792
793         n = sd->bptr->outdepth;
794         assert(sd->vartop + n <= sd->varcount);
795
796         b->indepth = n;
797         b->invars = DMNEW(s4, n);
798
799         if (n) {
800                 dv = sd->var + sd->vartop;
801
802                 /* allocate the invars */
803
804                 for (i=0; i<n; ++i, ++dv) {
805                         sv = sd->var + sd->bptr->outvars[i];
806                         b->invars[i] = sd->vartop++;
807                         dv->flags = INOUT;
808                         COPY_VAL_AND_TYPE_VAR(sv, dv);
809                 }
810         }
811
812         stack_create_locals(sd, b);
813 }
814
815
816 /* stack_check_invars **********************************************************
817
818    Check the current stack against the invars of the given basic block.
819    Depth and types must match.
820
821    IN:
822       sd...........stack analysis data
823           b............block which invars to check against
824           curstack.....current stack top
825           stackdepth...current stack depth
826
827    RETURN VALUE:
828       the destinaton block
829           NULL.........a VerifyError has been thrown
830
831 *******************************************************************************/
832
833 static basicblock * stack_check_invars(stackdata_t *sd, basicblock *b,
834                                                                            stackptr curstack, int stackdepth)
835 {
836         int i;
837         stackptr sp;
838         basicblock *orig;
839         bool separable;
840         varinfo *sv;
841         varinfo *dv;
842
843 #if defined(STACK_VERBOSE)
844         printf("stack_check_invars(L%03d)\n", b->nr);
845 #endif
846
847         /* find original of b */
848         if (b->original)
849                 b = b->original;
850         orig = b;
851
852 #if defined(STACK_VERBOSE)
853         printf("original is L%03d\n", orig->nr);
854 #endif
855
856         i = orig->indepth;
857
858 #if defined(ENABLE_VERIFIER)
859         if (i != stackdepth) {
860                 exceptions_throw_verifyerror(sd->m, "Stack depth mismatch");
861                 return NULL;
862         }
863 #endif
864
865         do {
866                 separable = false;
867
868 #if defined(STACK_VERBOSE)
869                 printf("checking against ");
870                 stack_verbose_show_block(sd, b); printf("\n");
871 #endif
872
873                 sp = curstack;
874                 for (i = orig->indepth; i--; sp = sp->prev) {
875                         dv = sd->var + b->invars[i];
876                         sv = sd->var + sp->varnum;
877
878 #if defined(ENABLE_VERIFIER)
879                         if (dv->type != sp->type) {
880                                 exceptions_throw_verifyerror_for_stack(sd->m, dv->type);
881                                 return NULL;
882                         }
883 #endif
884
885                         if (sp->type == TYPE_RET) {
886 #if defined(ENABLE_VERIFIER)
887                                 if (dv->SBRSTART != sv->SBRSTART) {
888                                         exceptions_throw_verifyerror(sd->m, "Mismatched stack types");
889                                         return NULL;
890                                 }
891 #endif
892                                 if (dv->vv.retaddr != sv->vv.retaddr) {
893                                         separable = true;
894                                         /* don't break! have to check the remaining stackslots */
895                                 }
896                         }
897                 }
898
899                 if (b->inlocals) {
900                         for (i=0; i<sd->localcount; ++i) {
901                                 dv = b->inlocals + i;
902                                 sv = sd->var + i;
903                                 if (sv->type == TYPE_RET && dv->type == TYPE_RET) {
904                                         if (
905 #if defined(ENABLE_VERIFIER)
906                                                         (sv->SBRSTART == dv->SBRSTART) &&
907 #endif
908                                                         (sv->vv.retaddr != dv->vv.retaddr)) 
909                                         {
910                                                 separable = true;
911                                                 break;
912                                         }
913                                 }
914                         }
915                 }
916
917                 if (!separable) {
918                         /* XXX cascading collapse? */
919
920                         stack_merge_locals(sd, b);
921
922 #if defined(STACK_VERBOSE)
923                         printf("------> using L%03d\n", b->nr);
924 #endif
925                         return b;
926                 }
927         } while ((b = b->copied_to) != NULL);
928
929         b = stack_clone_block(sd, orig);
930         if (!b)
931                 return NULL;
932
933         stack_create_invars(sd, b, curstack, stackdepth);
934         return b;
935 }
936
937
938 /* stack_check_invars_from_outvars *********************************************
939
940    Check the outvars of the current block against the invars of the given block.
941    Depth and types must match.
942
943    IN:
944       sd...........stack analysis data
945           b............block which invars to check against
946
947    RETURN VALUE:
948       the destinaton block
949           NULL.........a VerifyError has been thrown
950
951 *******************************************************************************/
952
953 static basicblock * stack_check_invars_from_outvars(stackdata_t *sd, basicblock *b)
954 {
955         int i;
956         int n;
957         varinfo *sv, *dv;
958         basicblock *orig;
959         bool separable;
960
961 #if defined(STACK_VERBOSE)
962         printf("stack_check_invars_from_outvars(L%03d)\n", b->nr);
963 #endif
964
965         /* find original of b */
966         if (b->original)
967                 b = b->original;
968         orig = b;
969
970 #if defined(STACK_VERBOSE)
971         printf("original is L%03d\n", orig->nr);
972 #endif
973
974         i = orig->indepth;
975         n = sd->bptr->outdepth;
976
977 #if defined(ENABLE_VERIFIER)
978         if (i != n) {
979                 exceptions_throw_verifyerror(sd->m, "Stack depth mismatch");
980                 return NULL;
981         }
982 #endif
983
984         do {
985                 separable = false;
986
987 #if defined(STACK_VERBOSE)
988                 printf("checking against ");
989                 stack_verbose_show_block(sd, b); printf("\n");
990 #endif
991
992                 if (n) {
993                         dv = sd->var + b->invars[0];
994
995                         for (i=0; i<n; ++i, ++dv) {
996                                 sv = sd->var + sd->bptr->outvars[i];
997
998 #if defined(ENABLE_VERIFIER)
999                                 if (sv->type != dv->type) {
1000                                         exceptions_throw_verifyerror_for_stack(sd->m, dv->type);
1001                                         return NULL;
1002                                 }
1003 #endif
1004
1005                                 if (dv->type == TYPE_RET) {
1006 #if defined(ENABLE_VERIFIER)
1007                                         if (sv->SBRSTART != dv->SBRSTART) {
1008                                                 exceptions_throw_verifyerror(sd->m, "Mismatched stack types");
1009                                                 return NULL;
1010                                         }
1011 #endif
1012                                         if (sv->vv.retaddr != dv->vv.retaddr) {
1013                                                 separable = true;
1014                                                 /* don't break! have to check the remaining stackslots */
1015                                         }
1016                                 }
1017                         }
1018                 }
1019
1020                 if (b->inlocals) {
1021                         for (i=0; i<sd->localcount; ++i) {
1022                                 dv = b->inlocals + i;
1023                                 sv = sd->var + i;
1024                                 if (
1025 #if defined(ENABLE_VERIFIER)
1026                                                 (sv->SBRSTART == dv->SBRSTART) &&
1027 #endif
1028                                                 (sv->type == TYPE_RET && dv->type == TYPE_RET))
1029                                 {
1030                                         if (sv->vv.retaddr != dv->vv.retaddr) {
1031                                                 separable = true;
1032                                                 break;
1033                                         }
1034                                 }
1035                         }
1036                 }
1037
1038                 if (!separable) {
1039                         /* XXX cascading collapse? */
1040
1041                         stack_merge_locals(sd, b);
1042
1043 #if defined(STACK_VERBOSE)
1044                         printf("------> using L%03d\n", b->nr);
1045 #endif
1046                         return b;
1047                 }
1048         } while ((b = b->copied_to) != NULL);
1049
1050         b = stack_clone_block(sd, orig);
1051         if (!b)
1052                 return NULL;
1053
1054         stack_create_invars_from_outvars(sd, b);
1055         return b;
1056 }
1057
1058
1059 /* stack_create_instack ********************************************************
1060
1061    Create the instack of the current basic block.
1062
1063    IN:
1064       sd...........stack analysis data
1065
1066    RETURN VALUE:
1067       the current stack top at the start of the basic block.
1068
1069 *******************************************************************************/
1070
1071 static stackptr stack_create_instack(stackdata_t *sd)
1072 {
1073     stackptr sp;
1074         int depth;
1075         int index;
1076
1077         if ((depth = sd->bptr->indepth) == 0)
1078                 return NULL;
1079
1080     sp = (sd->new += depth);
1081
1082         while (depth--) {
1083                 sp--;
1084                 index = sd->bptr->invars[depth];
1085                 sp->varnum = index;
1086                 sp->type = sd->var[index].type;
1087                 sp->prev = sp - 1;
1088                 sp->creator = NULL;
1089                 sp->flags = 0;
1090                 sp->varkind = STACKVAR;
1091         }
1092         sp->prev = NULL;
1093
1094         /* return the top of the created stack */
1095         return sd->new - 1;
1096 }
1097
1098
1099 /* stack_mark_reached **********************************************************
1100
1101    Mark the given block reached and propagate the current stack and locals to
1102    it. This function specializes the target block, if necessary, and returns
1103    a pointer to the specialized target.
1104
1105    IN:
1106       sd...........stack analysis data
1107           b............the block to reach
1108           curstack.....the current stack top
1109           stackdepth...the current stack depth
1110
1111    RETURN VALUE:
1112       a pointer to (a specialized version of) the target
1113           NULL.........a VerifyError has been thrown
1114
1115 *******************************************************************************/
1116
1117 static basicblock *stack_mark_reached(stackdata_t *sd, basicblock *b, stackptr curstack, int stackdepth) 
1118 {
1119 #if defined(STACK_VERBOSE)
1120         printf("stack_mark_reached(L%03d from L%03d)\n", b->nr, sd->bptr->nr);
1121 #endif
1122         /* mark targets of backward branches */
1123         if (b->nr <= sd->bptr->nr)
1124                 b->bitflags |= BBFLAG_REPLACEMENT;
1125
1126         if (b->flags < BBREACHED) {
1127                 /* b is reached for the first time. Create its invars. */
1128
1129 #if defined(STACK_VERBOSE)
1130                 printf("reached L%03d for the first time\n", b->nr);
1131 #endif
1132
1133                 stack_create_invars(sd, b, curstack, stackdepth);
1134
1135                 b->flags = BBREACHED;
1136
1137                 return b;
1138         } 
1139         else {
1140                 /* b has been reached before. Check that its invars match. */
1141
1142                 return stack_check_invars(sd, b, curstack, stackdepth);
1143         }
1144 }
1145
1146
1147 /* stack_mark_reached_from_outvars *********************************************
1148
1149    Mark the given block reached and propagate the outvars of the current block
1150    and the current locals to it. This function specializes the target block, 
1151    if necessary, and returns a pointer to the specialized target.
1152
1153    IN:
1154       sd...........stack analysis data
1155           b............the block to reach
1156
1157    RETURN VALUE:
1158       a pointer to (a specialized version of) the target
1159           NULL.........a VerifyError has been thrown
1160
1161 *******************************************************************************/
1162
1163 static basicblock *stack_mark_reached_from_outvars(stackdata_t *sd, basicblock *b)
1164 {
1165 #if defined(STACK_VERBOSE)
1166         printf("stack_mark_reached_from_outvars(L%03d from L%03d)\n", b->nr, sd->bptr->nr);
1167 #endif
1168         /* mark targets of backward branches */
1169         if (b->nr <= sd->bptr->nr)
1170                 b->bitflags |= BBFLAG_REPLACEMENT;
1171
1172         if (b->flags < BBREACHED) {
1173                 /* b is reached for the first time. Create its invars. */
1174
1175 #if defined(STACK_VERBOSE)
1176                 printf("reached L%03d for the first time\n", b->nr);
1177 #endif
1178
1179                 stack_create_invars_from_outvars(sd, b);
1180
1181                 b->flags = BBREACHED;
1182
1183                 return b;
1184         } 
1185         else {
1186                 /* b has been reached before. Check that its invars match. */
1187
1188                 return stack_check_invars_from_outvars(sd, b);
1189         }
1190 }
1191
1192
1193 /* stack_reach_next_block ******************************************************
1194
1195    Mark the following block reached and propagate the outvars of the current block
1196    and the current locals to it. This function specializes the target block, 
1197    if necessary, and returns a pointer to the specialized target.
1198
1199    IN:
1200       sd...........stack analysis data
1201
1202    RETURN VALUE:
1203       a pointer to (a specialized version of) the following block
1204           NULL.........a VerifyError has been thrown
1205
1206 *******************************************************************************/
1207
1208 static bool stack_reach_next_block(stackdata_t *sd)
1209 {
1210         basicblock *tbptr;
1211         instruction *iptr;
1212
1213         tbptr = (sd->bptr->original) ? sd->bptr->original : sd->bptr;
1214         tbptr = stack_mark_reached_from_outvars(sd, tbptr->next);
1215         if (!tbptr)
1216                 return false;
1217
1218         if (tbptr != sd->bptr->next) {
1219 #if defined(STACK_VERBOSE)
1220                 printf("NEXT IS NON-CONSEQUITIVE L%03d\n", tbptr->nr);
1221 #endif
1222                 iptr = sd->bptr->iinstr + sd->bptr->icount - 1;
1223                 assert(iptr->opc == ICMD_NOP);
1224                 iptr->opc = ICMD_GOTO;
1225                 iptr->dst.block = tbptr;
1226
1227                 if (tbptr->flags < BBFINISHED)
1228                         sd->repeat = true; /* XXX check if we really need to repeat */
1229         }
1230
1231         return true;
1232 }
1233
1234
1235 /* stack_reach_handlers ********************************************************
1236
1237    Reach the exception handlers for the current block.
1238
1239    IN:
1240       sd...........stack analysis data
1241
1242    RETURN VALUE:
1243      true.........everything ok
1244          false........a VerifyError has been thrown
1245
1246 *******************************************************************************/
1247
1248 static bool stack_reach_handlers(stackdata_t *sd)
1249 {
1250         s4 i;
1251         basicblock *tbptr;
1252
1253 #if defined(STACK_VERBOSE)
1254         printf("reaching exception handlers...\n");
1255 #endif
1256
1257         for (i=0; sd->handlers[i]; ++i) {
1258                 tbptr = sd->handlers[i]->handler;
1259
1260                 tbptr->type = BBTYPE_EXH;
1261                 tbptr->predecessorcount = CFG_UNKNOWN_PREDECESSORS;
1262
1263                 /* reach (and specialize) the handler block */
1264
1265                 tbptr = stack_mark_reached(sd, tbptr, &(sd->exstack), 1);
1266
1267                 if (tbptr == NULL)
1268                         return false;
1269
1270                 sd->handlers[i]->handler = tbptr;
1271         }
1272
1273         return true;
1274 }
1275
1276
1277 /* stack_reanalyse_block  ******************************************************
1278
1279    Re-analyse the current block. This is called if either the block itself
1280    has already been analysed before, or the current block is a clone of an
1281    already analysed block, and this clone is reached for the first time.
1282    In the latter case, this function does all that is necessary for fully
1283    cloning the block (cloning the instruction list and variables, etc.).
1284
1285    IN:
1286       sd...........stack analysis data
1287
1288    RETURN VALUE:
1289      true.........everything ok
1290          false........a VerifyError has been thrown
1291
1292 *******************************************************************************/
1293
1294 #define RELOCATE(index)                                              \
1295     do {                                                             \
1296         if ((index) >= blockvarstart)                                \
1297             (index) += blockvarshift;                                \
1298         else if ((index) >= invarstart)                              \
1299             (index) += invarshift;                                   \
1300     } while (0)
1301
1302 bool stack_reanalyse_block(stackdata_t *sd)
1303 {
1304         instruction *iptr;
1305         basicblock *b;
1306         basicblock *orig;
1307         s4 len;
1308         s4 invarstart;
1309         s4 blockvarstart;
1310         s4 invarshift;
1311         s4 blockvarshift;
1312         s4 i, j;
1313         s4 *argp;
1314         branch_target_t *table;
1315         lookup_target_t *lookup;
1316         bool superblockend;
1317         bool cloneinstructions;
1318         exception_entry *ex;
1319
1320 #if defined(STACK_VERBOSE)
1321         stack_verbose_block_enter(sd, true);
1322 #endif
1323
1324         b = sd->bptr;
1325
1326         if (!b->iinstr) {
1327                 orig = b->original;
1328                 assert(orig != NULL);
1329
1330                 /* clone the instruction list */
1331
1332                 cloneinstructions = true;
1333
1334                 assert(orig->iinstr);
1335                 len = orig->icount;
1336                 iptr = DMNEW(instruction, len + 1);
1337
1338                 MCOPY(iptr, orig->iinstr, instruction, len);
1339                 iptr[len].opc = ICMD_NOP;
1340                 iptr[len].line = 0;
1341                 iptr[len].flags.bits = 0;
1342                 b->iinstr = iptr;
1343                 b->icount = ++len;
1344
1345                 /* reserve space for the clone's block variables */
1346
1347                 stack_grow_variable_array(sd, orig->varcount);
1348
1349                 /* we already have the invars set */
1350
1351                 assert(b->indepth == orig->indepth);
1352
1353                 /* calculate relocation shifts for invars and block variables */
1354
1355                 if (orig->indepth) {
1356                         invarstart = orig->invars[0];
1357                         invarshift = b->invars[0] - invarstart;
1358                 }
1359                 else {
1360                         invarstart = INT_MAX;
1361                         invarshift = 0;
1362                 }
1363                 blockvarstart = orig->varstart;
1364                 blockvarshift = sd->vartop - blockvarstart;
1365
1366                 /* copy block variables */
1367
1368                 b->varstart = sd->vartop;
1369                 b->varcount = orig->varcount;
1370                 sd->vartop += b->varcount;
1371                 MCOPY(sd->var + b->varstart, sd->var + orig->varstart, varinfo, b->varcount);
1372
1373                 /* copy outvars */
1374
1375                 b->outdepth = orig->outdepth;
1376                 b->outvars = DMNEW(s4, orig->outdepth);
1377                 MCOPY(b->outvars, orig->outvars, s4, orig->outdepth);
1378
1379                 /* clone exception handlers */
1380
1381                 for (i=0; sd->handlers[i]; ++i) {
1382                         ex = DNEW(exception_entry);
1383                         ex->handler = sd->handlers[i]->handler;
1384                         ex->start = b;
1385                         ex->end = b; /* XXX hack, see end of stack_analyse */
1386                         ex->catchtype = sd->handlers[i]->catchtype;
1387                         ex->down = NULL;
1388
1389                         assert(sd->extableend->down == NULL);
1390                         sd->extableend->down = ex;
1391                         sd->extableend = ex;
1392                         sd->jd->exceptiontablelength++;
1393
1394                         sd->handlers[i] = ex;
1395                 }
1396         }
1397         else {
1398                 cloneinstructions = false;
1399                 invarshift = 0;
1400                 blockvarshift = 0;
1401                 invarstart = sd->vartop;
1402                 blockvarstart = sd->vartop;
1403                 iptr = b->iinstr;
1404         }
1405
1406         if (b->original) {
1407                 /* find exception handlers for the cloned block */
1408                 len = 0;
1409                 ex = sd->jd->exceptiontable;
1410                 for (; ex != NULL; ex = ex->down) {
1411                         /* XXX the cloned exception handlers have identical */
1412                         /* start end end blocks.                            */
1413                         if ((ex->start == b) && (ex->end == b)) {
1414                                 sd->handlers[len++] = ex;
1415                         }
1416                 }
1417                 sd->handlers[len] = NULL;
1418         }
1419
1420 #if defined(STACK_VERBOSE)
1421         printf("invarstart = %d, blockvarstart = %d\n", invarstart, blockvarstart);
1422         printf("invarshift = %d, blockvarshift = %d\n", invarshift, blockvarshift);
1423 #endif
1424
1425         /* mark block as finished */
1426
1427         b->flags = BBFINISHED;
1428
1429         /* initialize locals at the start of this block */
1430
1431         if (b->inlocals)
1432                 MCOPY(sd->var, b->inlocals, varinfo, sd->localcount);
1433
1434         MCOPY(sd->javalocals, b->javalocals, s4, sd->maxlocals);
1435
1436         /* reach exception handlers for this block */
1437
1438         if (!stack_reach_handlers(sd))
1439                 return false;
1440
1441         superblockend = false;
1442
1443         for (len = b->icount; len--; iptr++) {
1444 #if defined(STACK_VERBOSE)
1445                 show_icmd(sd->jd, iptr, false, SHOW_STACK);
1446                 printf("\n");
1447 #endif
1448
1449                 switch (iptr->opc) {
1450                         case ICMD_RET:
1451                                 j = iptr->s1.varindex;
1452
1453 #if defined(ENABLE_VERIFIER)
1454                                 if (sd->var[j].type != TYPE_RET) {
1455                                         exceptions_throw_verifyerror(sd->m, "RET with non-returnAddress value");
1456                                         return false;
1457                                 }
1458 #endif
1459
1460                                 iptr->dst.block = stack_mark_reached_from_outvars(sd, sd->var[j].vv.retaddr);
1461                                 superblockend = true;
1462                                 break;
1463
1464                         case ICMD_JSR:
1465                                 iptr->sx.s23.s3.jsrtarget.block = stack_mark_reached_from_outvars(sd, iptr->sx.s23.s3.jsrtarget.block);
1466                                 RELOCATE(iptr->dst.varindex);
1467                                 superblockend = true;
1468                                 break;
1469
1470                         case ICMD_RETURN:
1471                                 superblockend = true;
1472                                 break;
1473
1474                         case ICMD_CHECKNULL:
1475                         case ICMD_PUTSTATICCONST:
1476                                 break;
1477
1478                         case ICMD_NOP:
1479                         case ICMD_IINC:
1480                                 break;
1481
1482                         case ICMD_GOTO:
1483                                 iptr->dst.block = stack_mark_reached_from_outvars(sd, iptr->dst.block);
1484                                 superblockend = true;
1485                                 break;
1486
1487                                 /* pop 0 push 1 const */
1488
1489                         case ICMD_ACONST:
1490                         case ICMD_ICONST:
1491                         case ICMD_LCONST:
1492                         case ICMD_FCONST:
1493                         case ICMD_DCONST:
1494
1495                                 /* pop 0 push 1 load */
1496
1497                         case ICMD_ILOAD:
1498                         case ICMD_LLOAD:
1499                         case ICMD_FLOAD:
1500                         case ICMD_DLOAD:
1501                         case ICMD_ALOAD:
1502                                 RELOCATE(iptr->dst.varindex);
1503                                 break;
1504
1505                                 /* pop 2 push 1 */
1506
1507                         case ICMD_IALOAD:
1508                         case ICMD_LALOAD:
1509                         case ICMD_FALOAD:
1510                         case ICMD_DALOAD:
1511                         case ICMD_AALOAD:
1512                         case ICMD_BALOAD:
1513                         case ICMD_CALOAD:
1514                         case ICMD_SALOAD:
1515                                 RELOCATE(iptr->sx.s23.s2.varindex);
1516                                 RELOCATE(iptr->s1.varindex);
1517                                 RELOCATE(iptr->dst.varindex);
1518                                 break;
1519
1520                                 /* pop 3 push 0 */
1521
1522                         case ICMD_IASTORE:
1523                         case ICMD_LASTORE:
1524                         case ICMD_FASTORE:
1525                         case ICMD_DASTORE:
1526                         case ICMD_AASTORE:
1527                         case ICMD_BASTORE:
1528                         case ICMD_CASTORE:
1529                         case ICMD_SASTORE:
1530                                 RELOCATE(iptr->sx.s23.s3.varindex);
1531                                 RELOCATE(iptr->sx.s23.s2.varindex);
1532                                 RELOCATE(iptr->s1.varindex);
1533                                 break;
1534
1535                                 /* pop 1 push 0 store */
1536
1537                         case ICMD_ISTORE:
1538                         case ICMD_LSTORE:
1539                         case ICMD_FSTORE:
1540                         case ICMD_DSTORE:
1541                         case ICMD_ASTORE:
1542                                 RELOCATE(iptr->s1.varindex);
1543
1544                                 j = iptr->dst.varindex;
1545                                 COPY_VAL_AND_TYPE(*sd, iptr->s1.varindex, j);
1546                                 i = iptr->sx.s23.s3.javaindex;
1547                                 if (iptr->flags.bits & INS_FLAG_RETADDR) {
1548                                         iptr->sx.s23.s2.retaddrnr =
1549                                                 UNUSED - (1 + sd->var[j].vv.retaddr->nr);
1550                                         sd->javalocals[i] = iptr->sx.s23.s2.retaddrnr;
1551                                 }
1552                                 else
1553                                         sd->javalocals[i] = j;
1554                                 if (iptr->flags.bits & INS_FLAG_KILL_PREV)
1555                                         sd->javalocals[i-1] = UNUSED;
1556                                 if (iptr->flags.bits & INS_FLAG_KILL_NEXT)
1557                                         sd->javalocals[i+1] = UNUSED;
1558                                 break;
1559
1560                                 /* pop 1 push 0 */
1561
1562                         case ICMD_ARETURN:
1563                         case ICMD_ATHROW:
1564                         case ICMD_IRETURN:
1565                         case ICMD_LRETURN:
1566                         case ICMD_FRETURN:
1567                         case ICMD_DRETURN:
1568                                 RELOCATE(iptr->s1.varindex);
1569                                 superblockend = true;
1570                                 break;
1571
1572                         case ICMD_PUTSTATIC:
1573                         case ICMD_PUTFIELDCONST:
1574                         case ICMD_POP:
1575                                 RELOCATE(iptr->s1.varindex);
1576                                 break;
1577
1578                                 /* pop 1 push 0 branch */
1579
1580                         case ICMD_IFNULL:
1581                         case ICMD_IFNONNULL:
1582
1583                         case ICMD_IFEQ:
1584                         case ICMD_IFNE:
1585                         case ICMD_IFLT:
1586                         case ICMD_IFGE:
1587                         case ICMD_IFGT:
1588                         case ICMD_IFLE:
1589
1590                         case ICMD_IF_LEQ:
1591                         case ICMD_IF_LNE:
1592                         case ICMD_IF_LLT:
1593                         case ICMD_IF_LGE:
1594                         case ICMD_IF_LGT:
1595                         case ICMD_IF_LLE:
1596                                 RELOCATE(iptr->s1.varindex);
1597                                 iptr->dst.block = stack_mark_reached_from_outvars(sd, iptr->dst.block);
1598                                 break;
1599
1600                                 /* pop 1 push 0 table branch */
1601
1602                         case ICMD_TABLESWITCH:
1603                                 i = iptr->sx.s23.s3.tablehigh - iptr->sx.s23.s2.tablelow + 1 + 1;
1604
1605                                 if (cloneinstructions) {
1606                                         table = DMNEW(branch_target_t, i);
1607                                         MCOPY(table, iptr->dst.table, branch_target_t, i);
1608                                         iptr->dst.table = table;
1609                                 }
1610                                 else {
1611                                         table = iptr->dst.table;
1612                                 }
1613
1614                                 RELOCATE(iptr->s1.varindex);
1615                                 while (i--) {
1616                                         table->block = stack_mark_reached_from_outvars(sd, table->block);
1617                                         table++;
1618                                 }
1619                                 superblockend = true;
1620                                 break;
1621
1622                         case ICMD_LOOKUPSWITCH:
1623                                 i = iptr->sx.s23.s2.lookupcount;
1624                                 if (cloneinstructions) {
1625                                         lookup = DMNEW(lookup_target_t, i);
1626                                         MCOPY(lookup, iptr->dst.lookup, lookup_target_t, i);
1627                                         iptr->dst.lookup = lookup;
1628                                 }
1629                                 else {
1630                                         lookup = iptr->dst.lookup;
1631                                 }
1632                                 RELOCATE(iptr->s1.varindex);
1633                                 while (i--) {
1634                                         lookup->target.block = stack_mark_reached_from_outvars(sd, lookup->target.block);
1635                                         lookup++;
1636                                 }
1637                                 iptr->sx.s23.s3.lookupdefault.block = stack_mark_reached_from_outvars(sd, iptr->sx.s23.s3.lookupdefault.block);
1638                                 superblockend = true;
1639                                 break;
1640
1641                         case ICMD_MONITORENTER:
1642                         case ICMD_MONITOREXIT:
1643                                 RELOCATE(iptr->s1.varindex);
1644                                 break;
1645
1646                                 /* pop 2 push 0 branch */
1647
1648                         case ICMD_IF_ICMPEQ:
1649                         case ICMD_IF_ICMPNE:
1650                         case ICMD_IF_ICMPLT:
1651                         case ICMD_IF_ICMPGE:
1652                         case ICMD_IF_ICMPGT:
1653                         case ICMD_IF_ICMPLE:
1654
1655                         case ICMD_IF_LCMPEQ:
1656                         case ICMD_IF_LCMPNE:
1657                         case ICMD_IF_LCMPLT:
1658                         case ICMD_IF_LCMPGE:
1659                         case ICMD_IF_LCMPGT:
1660                         case ICMD_IF_LCMPLE:
1661
1662                         case ICMD_IF_FCMPEQ:
1663                         case ICMD_IF_FCMPNE:
1664
1665                         case ICMD_IF_FCMPL_LT:
1666                         case ICMD_IF_FCMPL_GE:
1667                         case ICMD_IF_FCMPL_GT:
1668                         case ICMD_IF_FCMPL_LE:
1669
1670                         case ICMD_IF_FCMPG_LT:
1671                         case ICMD_IF_FCMPG_GE:
1672                         case ICMD_IF_FCMPG_GT:
1673                         case ICMD_IF_FCMPG_LE:
1674
1675                         case ICMD_IF_DCMPEQ:
1676                         case ICMD_IF_DCMPNE:
1677
1678                         case ICMD_IF_DCMPL_LT:
1679                         case ICMD_IF_DCMPL_GE:
1680                         case ICMD_IF_DCMPL_GT:
1681                         case ICMD_IF_DCMPL_LE:
1682
1683                         case ICMD_IF_DCMPG_LT:
1684                         case ICMD_IF_DCMPG_GE:
1685                         case ICMD_IF_DCMPG_GT:
1686                         case ICMD_IF_DCMPG_LE:
1687
1688                         case ICMD_IF_ACMPEQ:
1689                         case ICMD_IF_ACMPNE:
1690                                 RELOCATE(iptr->sx.s23.s2.varindex);
1691                                 RELOCATE(iptr->s1.varindex);
1692                                 iptr->dst.block = stack_mark_reached_from_outvars(sd, iptr->dst.block);
1693                                 break;
1694
1695                                 /* pop 2 push 0 */
1696
1697                         case ICMD_PUTFIELD:
1698                         case ICMD_IASTORECONST:
1699                         case ICMD_LASTORECONST:
1700                         case ICMD_AASTORECONST:
1701                         case ICMD_BASTORECONST:
1702                         case ICMD_CASTORECONST:
1703                         case ICMD_SASTORECONST:
1704                         case ICMD_POP2:
1705                                 RELOCATE(iptr->sx.s23.s2.varindex);
1706                                 RELOCATE(iptr->s1.varindex);
1707                                 break;
1708
1709                                 /* pop 0 push 1 copy */
1710
1711                         case ICMD_COPY:
1712                         case ICMD_MOVE:
1713                                 RELOCATE(iptr->dst.varindex);
1714                                 RELOCATE(iptr->s1.varindex);
1715                                 COPY_VAL_AND_TYPE(*sd, iptr->s1.varindex, iptr->dst.varindex);
1716                                 break;
1717
1718                                 /* pop 2 push 1 */
1719
1720                         case ICMD_IDIV:
1721                         case ICMD_IREM:
1722                         case ICMD_LDIV:
1723                         case ICMD_LREM:
1724                         case ICMD_IADD:
1725                         case ICMD_ISUB:
1726                         case ICMD_IMUL:
1727                         case ICMD_ISHL:
1728                         case ICMD_ISHR:
1729                         case ICMD_IUSHR:
1730                         case ICMD_IAND:
1731                         case ICMD_IOR:
1732                         case ICMD_IXOR:
1733                         case ICMD_LADD:
1734                         case ICMD_LSUB:
1735                         case ICMD_LMUL:
1736                         case ICMD_LOR:
1737                         case ICMD_LAND:
1738                         case ICMD_LXOR:
1739                         case ICMD_LSHL:
1740                         case ICMD_LSHR:
1741                         case ICMD_LUSHR:
1742                         case ICMD_FADD:
1743                         case ICMD_FSUB:
1744                         case ICMD_FMUL:
1745                         case ICMD_FDIV:
1746                         case ICMD_FREM:
1747                         case ICMD_DADD:
1748                         case ICMD_DSUB:
1749                         case ICMD_DMUL:
1750                         case ICMD_DDIV:
1751                         case ICMD_DREM:
1752                         case ICMD_LCMP:
1753                         case ICMD_FCMPL:
1754                         case ICMD_FCMPG:
1755                         case ICMD_DCMPL:
1756                         case ICMD_DCMPG:
1757                                 RELOCATE(iptr->sx.s23.s2.varindex);
1758                                 RELOCATE(iptr->s1.varindex);
1759                                 RELOCATE(iptr->dst.varindex);
1760                                 break;
1761
1762                                 /* pop 1 push 1 */
1763
1764                         case ICMD_CHECKCAST:
1765                         case ICMD_ARRAYLENGTH:
1766                         case ICMD_INSTANCEOF:
1767                         case ICMD_NEWARRAY:
1768                         case ICMD_ANEWARRAY:
1769                         case ICMD_GETFIELD:
1770                         case ICMD_IADDCONST:
1771                         case ICMD_ISUBCONST:
1772                         case ICMD_IMULCONST:
1773                         case ICMD_IMULPOW2:
1774                         case ICMD_IDIVPOW2:
1775                         case ICMD_IREMPOW2:
1776                         case ICMD_IANDCONST:
1777                         case ICMD_IORCONST:
1778                         case ICMD_IXORCONST:
1779                         case ICMD_ISHLCONST:
1780                         case ICMD_ISHRCONST:
1781                         case ICMD_IUSHRCONST:
1782                         case ICMD_LADDCONST:
1783                         case ICMD_LSUBCONST:
1784                         case ICMD_LMULCONST:
1785                         case ICMD_LMULPOW2:
1786                         case ICMD_LDIVPOW2:
1787                         case ICMD_LREMPOW2:
1788                         case ICMD_LANDCONST:
1789                         case ICMD_LORCONST:
1790                         case ICMD_LXORCONST:
1791                         case ICMD_LSHLCONST:
1792                         case ICMD_LSHRCONST:
1793                         case ICMD_LUSHRCONST:
1794                         case ICMD_INEG:
1795                         case ICMD_INT2BYTE:
1796                         case ICMD_INT2CHAR:
1797                         case ICMD_INT2SHORT:
1798                         case ICMD_LNEG:
1799                         case ICMD_FNEG:
1800                         case ICMD_DNEG:
1801                         case ICMD_I2L:
1802                         case ICMD_I2F:
1803                         case ICMD_I2D:
1804                         case ICMD_L2I:
1805                         case ICMD_L2F:
1806                         case ICMD_L2D:
1807                         case ICMD_F2I:
1808                         case ICMD_F2L:
1809                         case ICMD_F2D:
1810                         case ICMD_D2I:
1811                         case ICMD_D2L:
1812                         case ICMD_D2F:
1813                                 RELOCATE(iptr->s1.varindex);
1814                                 RELOCATE(iptr->dst.varindex);
1815                                 break;
1816
1817                                 /* pop 0 push 1 */
1818
1819                         case ICMD_GETSTATIC:
1820                         case ICMD_NEW:
1821                                 RELOCATE(iptr->dst.varindex);
1822                                 break;
1823
1824                                 /* pop many push any */
1825
1826                         case ICMD_INVOKESTATIC:
1827                         case ICMD_INVOKESPECIAL:
1828                         case ICMD_INVOKEVIRTUAL:
1829                         case ICMD_INVOKEINTERFACE:
1830                         case ICMD_BUILTIN:
1831                         case ICMD_MULTIANEWARRAY:
1832                                 i = iptr->s1.argcount;
1833                                 if (cloneinstructions) {
1834                                         argp = DMNEW(s4, i);
1835                                         MCOPY(argp, iptr->sx.s23.s2.args, s4, i);
1836                                         iptr->sx.s23.s2.args = argp;
1837                                 }
1838                                 else {
1839                                         argp = iptr->sx.s23.s2.args;
1840                                 }
1841
1842                                 while (--i >= 0) {
1843                                         RELOCATE(*argp);
1844                                         argp++;
1845                                 }
1846                                 RELOCATE(iptr->dst.varindex);
1847                                 break;
1848
1849                         default:
1850                                 *exceptionptr =
1851                                         new_internalerror("Unknown ICMD %d during stack re-analysis",
1852                                                         iptr->opc);
1853                                 return false;
1854                 } /* switch */
1855
1856 #if defined(STACK_VERBOSE)
1857                 show_icmd(sd->jd, iptr, false, SHOW_STACK);
1858                 printf("\n");
1859 #endif
1860         }
1861
1862         /* relocate outvars */
1863
1864         for (i=0; i<b->outdepth; ++i) {
1865                 RELOCATE(b->outvars[i]);
1866         }
1867
1868 #if defined(STACK_VERBOSE)
1869         stack_verbose_block_exit(sd, superblockend);
1870 #endif
1871
1872         /* propagate to the next block */
1873
1874         if (!superblockend)
1875                 if (!stack_reach_next_block(sd))
1876                         return false;
1877
1878         return true;
1879 }
1880
1881
1882 /* stack_change_to_tempvar *****************************************************
1883
1884    Change the given stackslot to a TEMPVAR. This includes creating a new
1885    temporary variable and changing the dst.varindex of the creator of the
1886    stacklot to the new variable index. If this stackslot has been passed
1887    through ICMDs between the point of its creation and the current point,
1888    then the variable index is also changed in these ICMDs.
1889
1890    IN:
1891       sd...........stack analysis data
1892           sp...........stackslot to change
1893           ilimit.......instruction up to which to look for ICMDs passing-through
1894                        the stackslot (exclusive). This may point exactly after the 
1895                                    last instruction, in which case the search is done to the
1896                                    basic block end.
1897
1898 *******************************************************************************/
1899
1900 static void stack_change_to_tempvar(stackdata_t *sd, stackptr sp, 
1901                                                                         instruction *ilimit)
1902 {
1903         s4 newindex;
1904         s4 oldindex;
1905         instruction *iptr;
1906         s4 depth;
1907         s4 i;
1908
1909         oldindex = sp->varnum;
1910
1911         /* create a new temporary variable */
1912
1913         GET_NEW_VAR(*sd, newindex, sp->type);
1914
1915         sd->var[newindex].flags = sp->flags;
1916
1917         /* change the stackslot */
1918
1919         sp->varnum = newindex;
1920         sp->varkind = TEMPVAR;
1921
1922         /* change the dst.varindex of the stackslot's creator */
1923
1924         if (sp->creator)
1925                 sp->creator->dst.varindex = newindex;
1926
1927         /* handle ICMDs this stackslot passed through, if any */
1928
1929         if (sp->flags & PASSTHROUGH) {
1930                 iptr = (sp->creator) ? (sp->creator + 1) : sd->bptr->iinstr;
1931
1932                 /* assert that the limit points to an ICMD, or after the last one */
1933
1934                 assert(ilimit >= sd->bptr->iinstr);
1935                 assert(ilimit <= sd->bptr->iinstr + sd->bptr->icount);
1936
1937                 /* find the stackdepth under sp plus one */
1938                 /* Note: This number is usually known when this function is called, */
1939                 /* but calculating it here is less error-prone and should not be    */
1940                 /* a performance problem.                                           */
1941
1942                 for (depth = 0; sp != NULL; sp = sp->prev)
1943                         depth++;
1944
1945                 /* iterate over all instructions in the range and replace */
1946
1947                 for (; iptr < ilimit; ++iptr) {
1948                         switch (iptr->opc) {
1949                                 case ICMD_INVOKESTATIC:
1950                                 case ICMD_INVOKESPECIAL:
1951                                 case ICMD_INVOKEVIRTUAL:
1952                                 case ICMD_INVOKEINTERFACE:
1953                                 case ICMD_BUILTIN:
1954                                         i = iptr->s1.argcount - depth;
1955                                         if (iptr->sx.s23.s2.args[i] == oldindex) {
1956                                                 iptr->sx.s23.s2.args[i] = newindex;
1957                                         }
1958                                         break;
1959                                 /* IMPORTANT: If any ICMD sets the PASSTHROUGH flag of a */
1960                                 /* stackslot, it must be added in this switch!           */
1961                         }
1962                 }
1963         }
1964 }
1965
1966
1967 /* stack_init_javalocals *******************************************************
1968  
1969    Initialize the mapping from Java locals to cacao variables at method entry.
1970
1971    IN:
1972       sd...........stack analysis data
1973
1974 *******************************************************************************/
1975
1976 static void stack_init_javalocals(stackdata_t *sd)
1977 {
1978         s4         *jl;
1979         s4          t,i,j;
1980         methoddesc *md;
1981         jitdata    *jd;
1982
1983         jd = sd->jd;
1984
1985         jl = DMNEW(s4, sd->maxlocals);
1986         jd->basicblocks[0].javalocals = jl;
1987
1988         for (i=0; i<sd->maxlocals; ++i)
1989                 jl[i] = UNUSED;
1990
1991         md = jd->m->parseddesc;
1992         j = 0;
1993         for (i=0; i<md->paramcount; ++i) {
1994                 t = md->paramtypes[i].type;
1995                 jl[j] = jd->local_map[5*j + t];
1996                 j++;
1997                 if (IS_2_WORD_TYPE(t))
1998                         j++;
1999         }
2000 }
2001
2002
2003 /* stack_analyse ***************************************************************
2004
2005    Analyse_stack uses the intermediate code created by parse.c to
2006    build a model of the JVM operand stack for the current method.
2007    
2008    The following checks are performed:
2009      - check for operand stack underflow (before each instruction)
2010      - check for operand stack overflow (after[1] each instruction)
2011      - check for matching stack depth at merging points
2012      - check for matching basic types[2] at merging points
2013      - check basic types for instruction input (except for BUILTIN*
2014            opcodes, INVOKE* opcodes and MULTIANEWARRAY)
2015    
2016    [1]) Checking this after the instruction should be ok. parse.c
2017    counts the number of required stack slots in such a way that it is
2018    only vital that we don't exceed `maxstack` at basic block
2019    boundaries.
2020    
2021    [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
2022    DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
2023    types are not discerned.
2024
2025 *******************************************************************************/
2026
2027 bool stack_analyse(jitdata *jd)
2028 {
2029         methodinfo   *m;              /* method being analyzed                    */
2030         registerdata *rd;
2031         stackdata_t   sd;
2032 #if defined(ENABLE_SSA)
2033         lsradata     *ls;
2034 #endif
2035         int           stackdepth;
2036         stackptr      curstack;       /* current stack top                        */
2037         stackptr      copy;
2038         int           opcode;         /* opcode of current instruction            */
2039         int           i, j;
2040         int           javaindex;
2041         int           len;            /* # of instructions after the current one  */
2042         bool          superblockend;  /* if true, no fallthrough to next block    */
2043         bool          deadcode;       /* true if no live code has been reached    */
2044         instruction  *iptr;           /* the current instruction                  */
2045         basicblock   *tbptr;
2046         basicblock   *original;
2047         exception_entry *ex;
2048
2049         stackptr     *last_store_boundary;
2050         stackptr      coalescing_boundary;
2051
2052         stackptr      src1, src2, src3, src4, dst1, dst2;
2053
2054         branch_target_t *table;
2055         lookup_target_t *lookup;
2056 #if defined(ENABLE_VERIFIER)
2057         int           expectedtype;   /* used by CHECK_BASIC_TYPE                 */
2058 #endif
2059         builtintable_entry *bte;
2060         methoddesc         *md;
2061         constant_FMIref    *fmiref;
2062 #if defined(ENABLE_STATISTICS)
2063         int           iteration_count;  /* number of iterations of analysis       */
2064 #endif
2065         int           new_index; /* used to get a new var index with GET_NEW_INDEX*/
2066
2067 #if defined(STACK_VERBOSE)
2068         show_method(jd, SHOW_PARSE);
2069 #endif
2070
2071         /* get required compiler data - initialization */
2072
2073         m    = jd->m;
2074         rd   = jd->rd;
2075 #if defined(ENABLE_SSA)
2076         ls   = jd->ls;
2077 #endif
2078
2079         /* initialize the stackdata_t struct */
2080
2081         sd.m = m;
2082         sd.jd = jd;
2083         sd.varcount = jd->varcount;
2084         sd.vartop =  jd->vartop;
2085         sd.localcount = jd->localcount;
2086         sd.var = jd->var;
2087         sd.varsallocated = sd.varcount;
2088         sd.maxlocals = m->maxlocals;
2089         sd.javalocals = DMNEW(s4, sd.maxlocals);
2090         sd.handlers = DMNEW(exception_entry *, jd->exceptiontablelength + 1);
2091
2092         /* prepare the variable for exception handler stacks               */
2093         /* (has been reserved by STACK_EXTRA_VARS, or VERIFIER_EXTRA_VARS) */
2094
2095         sd.exstack.type = TYPE_ADR;
2096         sd.exstack.prev = NULL;
2097         sd.exstack.varnum = sd.localcount;
2098         sd.var[sd.exstack.varnum].type = TYPE_ADR;
2099
2100 #if defined(ENABLE_LSRA)
2101         m->maxlifetimes = 0;
2102 #endif
2103
2104 #if defined(ENABLE_STATISTICS)
2105         iteration_count = 0;
2106 #endif
2107
2108         /* find the last real basic block */
2109         
2110         sd.last_real_block = NULL;
2111         tbptr = jd->basicblocks;
2112         while (tbptr->next) {
2113                 sd.last_real_block = tbptr;
2114                 tbptr = tbptr->next;
2115         }
2116         assert(sd.last_real_block);
2117
2118         /* find the last exception handler */
2119
2120         if (jd->exceptiontablelength)
2121                 sd.extableend = jd->exceptiontable + jd->exceptiontablelength - 1;
2122         else
2123                 sd.extableend = NULL;
2124
2125         /* init jd->interface_map */
2126
2127         jd->maxinterfaces = m->maxstack;
2128         jd->interface_map = DMNEW(interface_info, m->maxstack * 5);
2129         for (i = 0; i < m->maxstack * 5; i++)
2130                 jd->interface_map[i].flags = UNUSED;
2131
2132         last_store_boundary = DMNEW(stackptr, m->maxlocals);
2133
2134         /* initialize flags and invars (none) of first block */
2135
2136         jd->basicblocks[0].flags = BBREACHED;
2137         jd->basicblocks[0].invars = NULL;
2138         jd->basicblocks[0].indepth = 0;
2139         jd->basicblocks[0].inlocals = 
2140                 DMNEW(varinfo, jd->localcount + VERIFIER_EXTRA_LOCALS);
2141         MCOPY(jd->basicblocks[0].inlocals, jd->var, varinfo, 
2142                         jd->localcount + VERIFIER_EXTRA_LOCALS);
2143
2144         /* initialize java local mapping of first block */
2145
2146         stack_init_javalocals(&sd);
2147
2148         /* stack analysis loop (until fixpoint reached) **************************/
2149
2150         do {
2151 #if defined(ENABLE_STATISTICS)
2152                 iteration_count++;
2153 #endif
2154
2155                 /* initialize loop over basic blocks */
2156
2157                 sd.bptr = jd->basicblocks;
2158                 superblockend = true;
2159                 sd.repeat = false;
2160                 curstack = NULL; stackdepth = 0;
2161                 deadcode = true;
2162
2163                 /* iterate over basic blocks *****************************************/
2164
2165                 for (; sd.bptr; sd.bptr = sd.bptr->next) {
2166
2167                         if (sd.bptr->flags == BBDELETED) {
2168                                 /* This block has been deleted - do nothing. */
2169
2170                                 continue;
2171                         }
2172
2173                         if (sd.bptr->flags == BBTYPECHECK_REACHED) {
2174                                 /* re-analyse a block because its input changed */
2175                                 deadcode = false;
2176                                 if (!stack_reanalyse_block(&sd))
2177                                         return false;
2178                                 superblockend = true; /* XXX */
2179                                 continue;
2180                         }
2181
2182                         if (superblockend && (sd.bptr->flags < BBREACHED)) {
2183                                 /* This block has not been reached so far, and we      */
2184                                 /* don't fall into it, so we'll have to iterate again. */
2185
2186                                 sd.repeat = true;
2187                                 continue;
2188                         }
2189
2190                         if (sd.bptr->flags > BBREACHED) {
2191                                 /* This block is already finished. */
2192
2193                                 superblockend = true;
2194                                 continue;
2195                         }
2196
2197                         if (sd.bptr->original && sd.bptr->original->flags < BBFINISHED) {
2198                                 /* This block is a clone and the original has not been */
2199                                 /* analysed, yet. Analyse it on the next iteration.    */
2200
2201                                 sd.repeat = true;
2202                                 /* XXX superblockend? */
2203                                 continue;
2204                         }
2205
2206                         /* This block has to be analysed now. */
2207
2208                         deadcode = false;
2209
2210                         /* XXX The rest of this block is still indented one level too */
2211                         /* much in order to avoid a giant diff by changing that.      */
2212
2213                                 /* We know that sd.bptr->flags == BBREACHED. */
2214                                 /* This block has been reached before.    */
2215
2216                                 assert(sd.bptr->flags == BBREACHED);
2217                                 stackdepth = sd.bptr->indepth;
2218
2219                                 /* find exception handlers for this block */
2220
2221                                 /* determine the active exception handlers for this block */
2222                                 /* XXX could use a faster algorithm with sorted lists or  */
2223                                 /* something?                                             */
2224
2225                                 original = (sd.bptr->original) ? sd.bptr->original : sd.bptr;
2226
2227                                 len = 0;
2228                                 ex = jd->exceptiontable;
2229                                 for (; ex != NULL; ex = ex->down) {
2230                                         if ((ex->start <= original) && (ex->end > original)) {
2231                                                 sd.handlers[len++] = ex;
2232                                         }
2233                                 }
2234                                 sd.handlers[len] = NULL;
2235
2236
2237                                 /* reanalyse cloned block */
2238
2239                                 if (sd.bptr->original) {
2240                                         if (!stack_reanalyse_block(&sd))
2241                                                 return false;
2242                                         continue;
2243                                 }
2244
2245                                 /* reset the new pointer for allocating stackslots */
2246
2247                                 sd.new = jd->stack;
2248
2249                                 /* create the instack of this block */
2250
2251                                 curstack = stack_create_instack(&sd);
2252
2253                                 /* initialize locals at the start of this block */
2254
2255                                 if (sd.bptr->inlocals)
2256                                         MCOPY(sd.var, sd.bptr->inlocals, varinfo, sd.localcount);
2257
2258                                 MCOPY(sd.javalocals, sd.bptr->javalocals, s4, sd.maxlocals);
2259
2260                                 /* set up local variables for analyzing this block */
2261
2262                                 superblockend = false;
2263                                 len = sd.bptr->icount;
2264                                 iptr = sd.bptr->iinstr;
2265
2266                                 /* mark the block as analysed */
2267
2268                                 sd.bptr->flags = BBFINISHED;
2269
2270                                 /* reset variables for dependency checking */
2271
2272                                 coalescing_boundary = sd.new;
2273                                 for( i = 0; i < m->maxlocals; i++)
2274                                         last_store_boundary[i] = sd.new;
2275
2276                                 /* remember the start of this block's variables */
2277   
2278                                 sd.bptr->varstart = sd.vartop;
2279
2280 #if defined(STACK_VERBOSE)
2281                                 stack_verbose_block_enter(&sd, false);
2282 #endif
2283   
2284                                 /* reach exception handlers for this block */
2285
2286                                 if (!stack_reach_handlers(&sd))
2287                                         return false;
2288
2289                                 /* iterate over ICMDs ****************************************/
2290
2291                                 while (--len >= 0)  {
2292
2293 #if defined(STACK_VERBOSE)
2294                                         stack_verbose_show_state(&sd, iptr, curstack);
2295 #endif
2296
2297                                         /* fetch the current opcode */
2298
2299                                         opcode = iptr->opc;
2300
2301                                         /* automatically replace some ICMDs with builtins */
2302
2303 #if defined(USEBUILTINTABLE)
2304                                         bte = builtintable_get_automatic(opcode);
2305
2306                                         if (bte && bte->opcode == opcode) {
2307                                                 iptr->opc           = ICMD_BUILTIN;
2308                                                 iptr->flags.bits    &= INS_FLAG_ID_MASK;
2309                                                 iptr->sx.s23.s3.bte = bte;
2310                                                 /* iptr->line is already set */
2311                                                 jd->isleafmethod = false;
2312                                                 goto icmd_BUILTIN;
2313                                         }
2314 #endif /* defined(USEBUILTINTABLE) */
2315
2316                                         /* main opcode switch *************************************/
2317
2318                                         switch (opcode) {
2319
2320                                                 /* pop 0 push 0 */
2321
2322                                         case ICMD_NOP:
2323 icmd_NOP:
2324                                                 CLR_SX;
2325                                                 OP0_0;
2326                                                 break;
2327
2328                                         case ICMD_CHECKNULL:
2329                                                 coalescing_boundary = sd.new;
2330                                                 COUNT(count_check_null);
2331                                                 USE_S1(TYPE_ADR);
2332                                                 CLR_SX;
2333                                                 iptr->dst.varindex = iptr->s1.varindex;
2334                                                 break;
2335
2336                                         case ICMD_RET:
2337                                                 j = iptr->s1.varindex = 
2338                                                         jd->local_map[iptr->s1.varindex * 5 + TYPE_ADR];
2339
2340 #if defined(ENABLE_VERIFIER)
2341                                                 if (sd.var[j].type != TYPE_RET) {
2342                                                         exceptions_throw_verifyerror(m, "RET with non-returnAddress value");
2343                                                         return false;
2344                                                 }
2345 #endif
2346                 
2347                                                 CLR_SX;
2348
2349                                                 iptr->dst.block = stack_mark_reached(&sd, sd.var[j].vv.retaddr, curstack, stackdepth);
2350                                                 superblockend = true;
2351                                                 break;
2352
2353                                         case ICMD_RETURN:
2354                                                 COUNT(count_pcmd_return);
2355                                                 CLR_SX;
2356                                                 OP0_0;
2357                                                 superblockend = true;
2358                                                 sd.jd->returncount++;
2359                                                 sd.jd->returnblock = sd.bptr;
2360                                                 break;
2361
2362
2363                                                 /* pop 0 push 1 const */
2364
2365         /************************** ICONST OPTIMIZATIONS **************************/
2366
2367                                         case ICMD_ICONST:
2368                                                 COUNT(count_pcmd_load);
2369                                                 if (len == 0)
2370                                                         goto normal_ICONST;
2371
2372                                                 switch (iptr[1].opc) {
2373                                                         case ICMD_IADD:
2374                                                                 iptr->opc = ICMD_IADDCONST;
2375                                                                 /* FALLTHROUGH */
2376
2377                                                         icmd_iconst_tail:
2378                                                                 iptr[1].opc = ICMD_NOP;
2379                                                                 OP1_1(TYPE_INT, TYPE_INT);
2380                                                                 COUNT(count_pcmd_op);
2381                                                                 break;
2382
2383                                                         case ICMD_ISUB:
2384                                                                 iptr->opc = ICMD_ISUBCONST;
2385                                                                 goto icmd_iconst_tail;
2386 #if SUPPORT_CONST_MUL
2387                                                         case ICMD_IMUL:
2388                                                                 iptr->opc = ICMD_IMULCONST;
2389                                                                 goto icmd_iconst_tail;
2390 #else /* SUPPORT_CONST_MUL */
2391                                                         case ICMD_IMUL:
2392                                                                 if (iptr->sx.val.i == 0x00000002)
2393                                                                         iptr->sx.val.i = 1;
2394                                                                 else if (iptr->sx.val.i == 0x00000004)
2395                                                                         iptr->sx.val.i = 2;
2396                                                                 else if (iptr->sx.val.i == 0x00000008)
2397                                                                         iptr->sx.val.i = 3;
2398                                                                 else if (iptr->sx.val.i == 0x00000010)
2399                                                                         iptr->sx.val.i = 4;
2400                                                                 else if (iptr->sx.val.i == 0x00000020)
2401                                                                         iptr->sx.val.i = 5;
2402                                                                 else if (iptr->sx.val.i == 0x00000040)
2403                                                                         iptr->sx.val.i = 6;
2404                                                                 else if (iptr->sx.val.i == 0x00000080)
2405                                                                         iptr->sx.val.i = 7;
2406                                                                 else if (iptr->sx.val.i == 0x00000100)
2407                                                                         iptr->sx.val.i = 8;
2408                                                                 else if (iptr->sx.val.i == 0x00000200)
2409                                                                         iptr->sx.val.i = 9;
2410                                                                 else if (iptr->sx.val.i == 0x00000400)
2411                                                                         iptr->sx.val.i = 10;
2412                                                                 else if (iptr->sx.val.i == 0x00000800)
2413                                                                         iptr->sx.val.i = 11;
2414                                                                 else if (iptr->sx.val.i == 0x00001000)
2415                                                                         iptr->sx.val.i = 12;
2416                                                                 else if (iptr->sx.val.i == 0x00002000)
2417                                                                         iptr->sx.val.i = 13;
2418                                                                 else if (iptr->sx.val.i == 0x00004000)
2419                                                                         iptr->sx.val.i = 14;
2420                                                                 else if (iptr->sx.val.i == 0x00008000)
2421                                                                         iptr->sx.val.i = 15;
2422                                                                 else if (iptr->sx.val.i == 0x00010000)
2423                                                                         iptr->sx.val.i = 16;
2424                                                                 else if (iptr->sx.val.i == 0x00020000)
2425                                                                         iptr->sx.val.i = 17;
2426                                                                 else if (iptr->sx.val.i == 0x00040000)
2427                                                                         iptr->sx.val.i = 18;
2428                                                                 else if (iptr->sx.val.i == 0x00080000)
2429                                                                         iptr->sx.val.i = 19;
2430                                                                 else if (iptr->sx.val.i == 0x00100000)
2431                                                                         iptr->sx.val.i = 20;
2432                                                                 else if (iptr->sx.val.i == 0x00200000)
2433                                                                         iptr->sx.val.i = 21;
2434                                                                 else if (iptr->sx.val.i == 0x00400000)
2435                                                                         iptr->sx.val.i = 22;
2436                                                                 else if (iptr->sx.val.i == 0x00800000)
2437                                                                         iptr->sx.val.i = 23;
2438                                                                 else if (iptr->sx.val.i == 0x01000000)
2439                                                                         iptr->sx.val.i = 24;
2440                                                                 else if (iptr->sx.val.i == 0x02000000)
2441                                                                         iptr->sx.val.i = 25;
2442                                                                 else if (iptr->sx.val.i == 0x04000000)
2443                                                                         iptr->sx.val.i = 26;
2444                                                                 else if (iptr->sx.val.i == 0x08000000)
2445                                                                         iptr->sx.val.i = 27;
2446                                                                 else if (iptr->sx.val.i == 0x10000000)
2447                                                                         iptr->sx.val.i = 28;
2448                                                                 else if (iptr->sx.val.i == 0x20000000)
2449                                                                         iptr->sx.val.i = 29;
2450                                                                 else if (iptr->sx.val.i == 0x40000000)
2451                                                                         iptr->sx.val.i = 30;
2452                                                                 else if (iptr->sx.val.i == 0x80000000)
2453                                                                         iptr->sx.val.i = 31;
2454                                                                 else
2455                                                                         goto normal_ICONST;
2456
2457                                                                 iptr->opc = ICMD_IMULPOW2;
2458                                                                 goto icmd_iconst_tail;
2459 #endif /* SUPPORT_CONST_MUL */
2460                                                         case ICMD_IDIV:
2461                                                                 if (iptr->sx.val.i == 0x00000002)
2462                                                                         iptr->sx.val.i = 1;
2463                                                                 else if (iptr->sx.val.i == 0x00000004)
2464                                                                         iptr->sx.val.i = 2;
2465                                                                 else if (iptr->sx.val.i == 0x00000008)
2466                                                                         iptr->sx.val.i = 3;
2467                                                                 else if (iptr->sx.val.i == 0x00000010)
2468                                                                         iptr->sx.val.i = 4;
2469                                                                 else if (iptr->sx.val.i == 0x00000020)
2470                                                                         iptr->sx.val.i = 5;
2471                                                                 else if (iptr->sx.val.i == 0x00000040)
2472                                                                         iptr->sx.val.i = 6;
2473                                                                 else if (iptr->sx.val.i == 0x00000080)
2474                                                                         iptr->sx.val.i = 7;
2475                                                                 else if (iptr->sx.val.i == 0x00000100)
2476                                                                         iptr->sx.val.i = 8;
2477                                                                 else if (iptr->sx.val.i == 0x00000200)
2478                                                                         iptr->sx.val.i = 9;
2479                                                                 else if (iptr->sx.val.i == 0x00000400)
2480                                                                         iptr->sx.val.i = 10;
2481                                                                 else if (iptr->sx.val.i == 0x00000800)
2482                                                                         iptr->sx.val.i = 11;
2483                                                                 else if (iptr->sx.val.i == 0x00001000)
2484                                                                         iptr->sx.val.i = 12;
2485                                                                 else if (iptr->sx.val.i == 0x00002000)
2486                                                                         iptr->sx.val.i = 13;
2487                                                                 else if (iptr->sx.val.i == 0x00004000)
2488                                                                         iptr->sx.val.i = 14;
2489                                                                 else if (iptr->sx.val.i == 0x00008000)
2490                                                                         iptr->sx.val.i = 15;
2491                                                                 else if (iptr->sx.val.i == 0x00010000)
2492                                                                         iptr->sx.val.i = 16;
2493                                                                 else if (iptr->sx.val.i == 0x00020000)
2494                                                                         iptr->sx.val.i = 17;
2495                                                                 else if (iptr->sx.val.i == 0x00040000)
2496                                                                         iptr->sx.val.i = 18;
2497                                                                 else if (iptr->sx.val.i == 0x00080000)
2498                                                                         iptr->sx.val.i = 19;
2499                                                                 else if (iptr->sx.val.i == 0x00100000)
2500                                                                         iptr->sx.val.i = 20;
2501                                                                 else if (iptr->sx.val.i == 0x00200000)
2502                                                                         iptr->sx.val.i = 21;
2503                                                                 else if (iptr->sx.val.i == 0x00400000)
2504                                                                         iptr->sx.val.i = 22;
2505                                                                 else if (iptr->sx.val.i == 0x00800000)
2506                                                                         iptr->sx.val.i = 23;
2507                                                                 else if (iptr->sx.val.i == 0x01000000)
2508                                                                         iptr->sx.val.i = 24;
2509                                                                 else if (iptr->sx.val.i == 0x02000000)
2510                                                                         iptr->sx.val.i = 25;
2511                                                                 else if (iptr->sx.val.i == 0x04000000)
2512                                                                         iptr->sx.val.i = 26;
2513                                                                 else if (iptr->sx.val.i == 0x08000000)
2514                                                                         iptr->sx.val.i = 27;
2515                                                                 else if (iptr->sx.val.i == 0x10000000)
2516                                                                         iptr->sx.val.i = 28;
2517                                                                 else if (iptr->sx.val.i == 0x20000000)
2518                                                                         iptr->sx.val.i = 29;
2519                                                                 else if (iptr->sx.val.i == 0x40000000)
2520                                                                         iptr->sx.val.i = 30;
2521                                                                 else if (iptr->sx.val.i == 0x80000000)
2522                                                                         iptr->sx.val.i = 31;
2523                                                                 else
2524                                                                         goto normal_ICONST;
2525
2526                                                                 iptr->opc = ICMD_IDIVPOW2;
2527                                                                 goto icmd_iconst_tail;
2528
2529                                                         case ICMD_IREM:
2530                                                                 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
2531                                                                 if ((iptr->sx.val.i == 0x00000002) ||
2532                                                                         (iptr->sx.val.i == 0x00000004) ||
2533                                                                         (iptr->sx.val.i == 0x00000008) ||
2534                                                                         (iptr->sx.val.i == 0x00000010) ||
2535                                                                         (iptr->sx.val.i == 0x00000020) ||
2536                                                                         (iptr->sx.val.i == 0x00000040) ||
2537                                                                         (iptr->sx.val.i == 0x00000080) ||
2538                                                                         (iptr->sx.val.i == 0x00000100) ||
2539                                                                         (iptr->sx.val.i == 0x00000200) ||
2540                                                                         (iptr->sx.val.i == 0x00000400) ||
2541                                                                         (iptr->sx.val.i == 0x00000800) ||
2542                                                                         (iptr->sx.val.i == 0x00001000) ||
2543                                                                         (iptr->sx.val.i == 0x00002000) ||
2544                                                                         (iptr->sx.val.i == 0x00004000) ||
2545                                                                         (iptr->sx.val.i == 0x00008000) ||
2546                                                                         (iptr->sx.val.i == 0x00010000) ||
2547                                                                         (iptr->sx.val.i == 0x00020000) ||
2548                                                                         (iptr->sx.val.i == 0x00040000) ||
2549                                                                         (iptr->sx.val.i == 0x00080000) ||
2550                                                                         (iptr->sx.val.i == 0x00100000) ||
2551                                                                         (iptr->sx.val.i == 0x00200000) ||
2552                                                                         (iptr->sx.val.i == 0x00400000) ||
2553                                                                         (iptr->sx.val.i == 0x00800000) ||
2554                                                                         (iptr->sx.val.i == 0x01000000) ||
2555                                                                         (iptr->sx.val.i == 0x02000000) ||
2556                                                                         (iptr->sx.val.i == 0x04000000) ||
2557                                                                         (iptr->sx.val.i == 0x08000000) ||
2558                                                                         (iptr->sx.val.i == 0x10000000) ||
2559                                                                         (iptr->sx.val.i == 0x20000000) ||
2560                                                                         (iptr->sx.val.i == 0x40000000) ||
2561                                                                         (iptr->sx.val.i == 0x80000000))
2562                                                                 {
2563                                                                         iptr->opc = ICMD_IREMPOW2;
2564                                                                         iptr->sx.val.i -= 1;
2565                                                                         goto icmd_iconst_tail;
2566                                                                 }
2567                                                                 goto normal_ICONST;
2568 #if SUPPORT_CONST_LOGICAL
2569                                                         case ICMD_IAND:
2570                                                                 iptr->opc = ICMD_IANDCONST;
2571                                                                 goto icmd_iconst_tail;
2572
2573                                                         case ICMD_IOR:
2574                                                                 iptr->opc = ICMD_IORCONST;
2575                                                                 goto icmd_iconst_tail;
2576
2577                                                         case ICMD_IXOR:
2578                                                                 iptr->opc = ICMD_IXORCONST;
2579                                                                 goto icmd_iconst_tail;
2580
2581 #endif /* SUPPORT_CONST_LOGICAL */
2582                                                         case ICMD_ISHL:
2583                                                                 iptr->opc = ICMD_ISHLCONST;
2584                                                                 goto icmd_iconst_tail;
2585
2586                                                         case ICMD_ISHR:
2587                                                                 iptr->opc = ICMD_ISHRCONST;
2588                                                                 goto icmd_iconst_tail;
2589
2590                                                         case ICMD_IUSHR:
2591                                                                 iptr->opc = ICMD_IUSHRCONST;
2592                                                                 goto icmd_iconst_tail;
2593 #if SUPPORT_LONG_SHIFT
2594                                                         case ICMD_LSHL:
2595                                                                 iptr->opc = ICMD_LSHLCONST;
2596                                                                 goto icmd_lconst_tail;
2597
2598                                                         case ICMD_LSHR:
2599                                                                 iptr->opc = ICMD_LSHRCONST;
2600                                                                 goto icmd_lconst_tail;
2601
2602                                                         case ICMD_LUSHR:
2603                                                                 iptr->opc = ICMD_LUSHRCONST;
2604                                                                 goto icmd_lconst_tail;
2605 #endif /* SUPPORT_LONG_SHIFT */
2606                                                         case ICMD_IF_ICMPEQ:
2607                                                                 iptr[1].opc = ICMD_IFEQ;
2608                                                                 /* FALLTHROUGH */
2609
2610                                                         icmd_if_icmp_tail:
2611                                                                 /* set the constant for the following icmd */
2612                                                                 iptr[1].sx.val.i = iptr->sx.val.i;
2613
2614                                                                 /* this instruction becomes a nop */
2615                                                                 iptr->opc = ICMD_NOP;
2616                                                                 goto icmd_NOP;
2617
2618                                                         case ICMD_IF_ICMPLT:
2619                                                                 iptr[1].opc = ICMD_IFLT;
2620                                                                 goto icmd_if_icmp_tail;
2621
2622                                                         case ICMD_IF_ICMPLE:
2623                                                                 iptr[1].opc = ICMD_IFLE;
2624                                                                 goto icmd_if_icmp_tail;
2625
2626                                                         case ICMD_IF_ICMPNE:
2627                                                                 iptr[1].opc = ICMD_IFNE;
2628                                                                 goto icmd_if_icmp_tail;
2629
2630                                                         case ICMD_IF_ICMPGT:
2631                                                                 iptr[1].opc = ICMD_IFGT;
2632                                                                 goto icmd_if_icmp_tail;
2633
2634                                                         case ICMD_IF_ICMPGE:
2635                                                                 iptr[1].opc = ICMD_IFGE;
2636                                                                 goto icmd_if_icmp_tail;
2637
2638 #if SUPPORT_CONST_STORE
2639                                                         case ICMD_IASTORE:
2640                                                         case ICMD_BASTORE:
2641                                                         case ICMD_CASTORE:
2642                                                         case ICMD_SASTORE:
2643 # if SUPPORT_CONST_STORE_ZERO_ONLY
2644                                                                 if (iptr->sx.val.i != 0)
2645                                                                         goto normal_ICONST;
2646 # endif
2647                                                                 switch (iptr[1].opc) {
2648                                                                         case ICMD_IASTORE:
2649                                                                                 iptr->opc = ICMD_IASTORECONST;
2650                                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
2651                                                                                 break;
2652                                                                         case ICMD_BASTORE:
2653                                                                                 iptr->opc = ICMD_BASTORECONST;
2654                                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
2655                                                                                 break;
2656                                                                         case ICMD_CASTORE:
2657                                                                                 iptr->opc = ICMD_CASTORECONST;
2658                                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
2659                                                                                 break;
2660                                                                         case ICMD_SASTORE:
2661                                                                                 iptr->opc = ICMD_SASTORECONST;
2662                                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
2663                                                                                 break;
2664                                                                 }
2665
2666                                                                 iptr[1].opc = ICMD_NOP;
2667
2668                                                                 /* copy the constant to s3 */
2669                                                                 /* XXX constval -> astoreconstval? */
2670                                                                 iptr->sx.s23.s3.constval = iptr->sx.val.i;
2671                                                                 OP2_0(TYPE_ADR, TYPE_INT);
2672                                                                 COUNT(count_pcmd_op);
2673                                                                 break;
2674
2675                                                         case ICMD_PUTSTATIC:
2676                                                         case ICMD_PUTFIELD:
2677 # if SUPPORT_CONST_STORE_ZERO_ONLY
2678                                                                 if (iptr->sx.val.i != 0)
2679                                                                         goto normal_ICONST;
2680 # endif
2681                                                                 /* XXX check field type? */
2682
2683                                                                 /* copy the constant to s2 */
2684                                                                 /* XXX constval -> fieldconstval? */
2685                                                                 iptr->sx.s23.s2.constval = iptr->sx.val.i;
2686
2687 putconst_tail:
2688                                                                 /* set the field reference (s3) */
2689                                                                 if (iptr[1].flags.bits & INS_FLAG_UNRESOLVED) {
2690                                                                         iptr->sx.s23.s3.uf = iptr[1].sx.s23.s3.uf;
2691                                                                         iptr->flags.bits |= INS_FLAG_UNRESOLVED;
2692                                                                         fmiref = iptr->sx.s23.s3.uf->fieldref;
2693                                                                 }
2694                                                                 else {
2695                                                                         fmiref = iptr[1].sx.s23.s3.fmiref;
2696                                                                         iptr->sx.s23.s3.fmiref = fmiref;
2697                                                                 }
2698
2699 #if defined(ENABLE_VERIFIER)
2700                                                                 expectedtype = fmiref->parseddesc.fd->type;
2701                                                                 switch (iptr[0].opc) {
2702                                                                         case ICMD_ICONST:
2703                                                                                 if (expectedtype != TYPE_INT)
2704                                                                                         goto throw_stack_type_error;
2705                                                                                 break;
2706                                                                         case ICMD_LCONST:
2707                                                                                 if (expectedtype != TYPE_LNG)
2708                                                                                         goto throw_stack_type_error;
2709                                                                                 break;
2710                                                                         case ICMD_ACONST:
2711                                                                                 if (expectedtype != TYPE_ADR)
2712                                                                                         goto throw_stack_type_error;
2713                                                                                 break;
2714                                                                         default:
2715                                                                                 assert(0);
2716                                                                 }
2717 #endif /* defined(ENABLE_VERIFIER) */
2718                                                                 
2719                                                                 switch (iptr[1].opc) {
2720                                                                         case ICMD_PUTSTATIC:
2721                                                                                 iptr->opc = ICMD_PUTSTATICCONST;
2722                                                                                 OP0_0;
2723                                                                                 break;
2724                                                                         case ICMD_PUTFIELD:
2725                                                                                 iptr->opc = ICMD_PUTFIELDCONST;
2726                                                                                 OP1_0(TYPE_ADR);
2727                                                                                 break;
2728                                                                 }
2729
2730                                                                 iptr[1].opc = ICMD_NOP;
2731                                                                 COUNT(count_pcmd_op);
2732                                                                 break;
2733 #endif /* SUPPORT_CONST_STORE */
2734
2735                                                         default:
2736                                                                 goto normal_ICONST;
2737                                                 }
2738
2739                                                 /* if we get here, the ICONST has been optimized */
2740                                                 break;
2741
2742 normal_ICONST:
2743                                                 /* normal case of an unoptimized ICONST */
2744                                                 OP0_1(TYPE_INT);
2745                                                 break;
2746
2747         /************************** LCONST OPTIMIZATIONS **************************/
2748
2749                                         case ICMD_LCONST:
2750                                                 COUNT(count_pcmd_load);
2751                                                 if (len == 0)
2752                                                         goto normal_LCONST;
2753
2754                                                 /* switch depending on the following instruction */
2755
2756                                                 switch (iptr[1].opc) {
2757 #if SUPPORT_LONG_ADD
2758                                                         case ICMD_LADD:
2759                                                                 iptr->opc = ICMD_LADDCONST;
2760                                                                 /* FALLTHROUGH */
2761
2762                                                         icmd_lconst_tail:
2763                                                                 /* instruction of type LONG -> LONG */
2764                                                                 iptr[1].opc = ICMD_NOP;
2765                                                                 OP1_1(TYPE_LNG, TYPE_LNG);
2766                                                                 COUNT(count_pcmd_op);
2767                                                                 break;
2768
2769                                                         case ICMD_LSUB:
2770                                                                 iptr->opc = ICMD_LSUBCONST;
2771                                                                 goto icmd_lconst_tail;
2772
2773 #endif /* SUPPORT_LONG_ADD */
2774 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
2775                                                         case ICMD_LMUL:
2776                                                                 iptr->opc = ICMD_LMULCONST;
2777                                                                 goto icmd_lconst_tail;
2778 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
2779 # if SUPPORT_LONG_SHIFT
2780                                                         case ICMD_LMUL:
2781                                                                 if (iptr->sx.val.l == 0x00000002)
2782                                                                         iptr->sx.val.i = 1;
2783                                                                 else if (iptr->sx.val.l == 0x00000004)
2784                                                                         iptr->sx.val.i = 2;
2785                                                                 else if (iptr->sx.val.l == 0x00000008)
2786                                                                         iptr->sx.val.i = 3;
2787                                                                 else if (iptr->sx.val.l == 0x00000010)
2788                                                                         iptr->sx.val.i = 4;
2789                                                                 else if (iptr->sx.val.l == 0x00000020)
2790                                                                         iptr->sx.val.i = 5;
2791                                                                 else if (iptr->sx.val.l == 0x00000040)
2792                                                                         iptr->sx.val.i = 6;
2793                                                                 else if (iptr->sx.val.l == 0x00000080)
2794                                                                         iptr->sx.val.i = 7;
2795                                                                 else if (iptr->sx.val.l == 0x00000100)
2796                                                                         iptr->sx.val.i = 8;
2797                                                                 else if (iptr->sx.val.l == 0x00000200)
2798                                                                         iptr->sx.val.i = 9;
2799                                                                 else if (iptr->sx.val.l == 0x00000400)
2800                                                                         iptr->sx.val.i = 10;
2801                                                                 else if (iptr->sx.val.l == 0x00000800)
2802                                                                         iptr->sx.val.i = 11;
2803                                                                 else if (iptr->sx.val.l == 0x00001000)
2804                                                                         iptr->sx.val.i = 12;
2805                                                                 else if (iptr->sx.val.l == 0x00002000)
2806                                                                         iptr->sx.val.i = 13;
2807                                                                 else if (iptr->sx.val.l == 0x00004000)
2808                                                                         iptr->sx.val.i = 14;
2809                                                                 else if (iptr->sx.val.l == 0x00008000)
2810                                                                         iptr->sx.val.i = 15;
2811                                                                 else if (iptr->sx.val.l == 0x00010000)
2812                                                                         iptr->sx.val.i = 16;
2813                                                                 else if (iptr->sx.val.l == 0x00020000)
2814                                                                         iptr->sx.val.i = 17;
2815                                                                 else if (iptr->sx.val.l == 0x00040000)
2816                                                                         iptr->sx.val.i = 18;
2817                                                                 else if (iptr->sx.val.l == 0x00080000)
2818                                                                         iptr->sx.val.i = 19;
2819                                                                 else if (iptr->sx.val.l == 0x00100000)
2820                                                                         iptr->sx.val.i = 20;
2821                                                                 else if (iptr->sx.val.l == 0x00200000)
2822                                                                         iptr->sx.val.i = 21;
2823                                                                 else if (iptr->sx.val.l == 0x00400000)
2824                                                                         iptr->sx.val.i = 22;
2825                                                                 else if (iptr->sx.val.l == 0x00800000)
2826                                                                         iptr->sx.val.i = 23;
2827                                                                 else if (iptr->sx.val.l == 0x01000000)
2828                                                                         iptr->sx.val.i = 24;
2829                                                                 else if (iptr->sx.val.l == 0x02000000)
2830                                                                         iptr->sx.val.i = 25;
2831                                                                 else if (iptr->sx.val.l == 0x04000000)
2832                                                                         iptr->sx.val.i = 26;
2833                                                                 else if (iptr->sx.val.l == 0x08000000)
2834                                                                         iptr->sx.val.i = 27;
2835                                                                 else if (iptr->sx.val.l == 0x10000000)
2836                                                                         iptr->sx.val.i = 28;
2837                                                                 else if (iptr->sx.val.l == 0x20000000)
2838                                                                         iptr->sx.val.i = 29;
2839                                                                 else if (iptr->sx.val.l == 0x40000000)
2840                                                                         iptr->sx.val.i = 30;
2841                                                                 else if (iptr->sx.val.l == 0x80000000)
2842                                                                         iptr->sx.val.i = 31;
2843                                                                 else {
2844                                                                         goto normal_LCONST;
2845                                                                 }
2846                                                                 iptr->opc = ICMD_LMULPOW2;
2847                                                                 goto icmd_lconst_tail;
2848 # endif /* SUPPORT_LONG_SHIFT */
2849 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
2850 #if SUPPORT_LONG_DIV_POW2
2851                                                         case ICMD_LDIV:
2852                                                                 if (iptr->sx.val.l == 0x00000002)
2853                                                                         iptr->sx.val.i = 1;
2854                                                                 else if (iptr->sx.val.l == 0x00000004)
2855                                                                         iptr->sx.val.i = 2;
2856                                                                 else if (iptr->sx.val.l == 0x00000008)
2857                                                                         iptr->sx.val.i = 3;
2858                                                                 else if (iptr->sx.val.l == 0x00000010)
2859                                                                         iptr->sx.val.i = 4;
2860                                                                 else if (iptr->sx.val.l == 0x00000020)
2861                                                                         iptr->sx.val.i = 5;
2862                                                                 else if (iptr->sx.val.l == 0x00000040)
2863                                                                         iptr->sx.val.i = 6;
2864                                                                 else if (iptr->sx.val.l == 0x00000080)
2865                                                                         iptr->sx.val.i = 7;
2866                                                                 else if (iptr->sx.val.l == 0x00000100)
2867                                                                         iptr->sx.val.i = 8;
2868                                                                 else if (iptr->sx.val.l == 0x00000200)
2869                                                                         iptr->sx.val.i = 9;
2870                                                                 else if (iptr->sx.val.l == 0x00000400)
2871                                                                         iptr->sx.val.i = 10;
2872                                                                 else if (iptr->sx.val.l == 0x00000800)
2873                                                                         iptr->sx.val.i = 11;
2874                                                                 else if (iptr->sx.val.l == 0x00001000)
2875                                                                         iptr->sx.val.i = 12;
2876                                                                 else if (iptr->sx.val.l == 0x00002000)
2877                                                                         iptr->sx.val.i = 13;
2878                                                                 else if (iptr->sx.val.l == 0x00004000)
2879                                                                         iptr->sx.val.i = 14;
2880                                                                 else if (iptr->sx.val.l == 0x00008000)
2881                                                                         iptr->sx.val.i = 15;
2882                                                                 else if (iptr->sx.val.l == 0x00010000)
2883                                                                         iptr->sx.val.i = 16;
2884                                                                 else if (iptr->sx.val.l == 0x00020000)
2885                                                                         iptr->sx.val.i = 17;
2886                                                                 else if (iptr->sx.val.l == 0x00040000)
2887                                                                         iptr->sx.val.i = 18;
2888                                                                 else if (iptr->sx.val.l == 0x00080000)
2889                                                                         iptr->sx.val.i = 19;
2890                                                                 else if (iptr->sx.val.l == 0x00100000)
2891                                                                         iptr->sx.val.i = 20;
2892                                                                 else if (iptr->sx.val.l == 0x00200000)
2893                                                                         iptr->sx.val.i = 21;
2894                                                                 else if (iptr->sx.val.l == 0x00400000)
2895                                                                         iptr->sx.val.i = 22;
2896                                                                 else if (iptr->sx.val.l == 0x00800000)
2897                                                                         iptr->sx.val.i = 23;
2898                                                                 else if (iptr->sx.val.l == 0x01000000)
2899                                                                         iptr->sx.val.i = 24;
2900                                                                 else if (iptr->sx.val.l == 0x02000000)
2901                                                                         iptr->sx.val.i = 25;
2902                                                                 else if (iptr->sx.val.l == 0x04000000)
2903                                                                         iptr->sx.val.i = 26;
2904                                                                 else if (iptr->sx.val.l == 0x08000000)
2905                                                                         iptr->sx.val.i = 27;
2906                                                                 else if (iptr->sx.val.l == 0x10000000)
2907                                                                         iptr->sx.val.i = 28;
2908                                                                 else if (iptr->sx.val.l == 0x20000000)
2909                                                                         iptr->sx.val.i = 29;
2910                                                                 else if (iptr->sx.val.l == 0x40000000)
2911                                                                         iptr->sx.val.i = 30;
2912                                                                 else if (iptr->sx.val.l == 0x80000000)
2913                                                                         iptr->sx.val.i = 31;
2914                                                                 else {
2915                                                                         goto normal_LCONST;
2916                                                                 }
2917                                                                 iptr->opc = ICMD_LDIVPOW2;
2918                                                                 goto icmd_lconst_tail;
2919 #endif /* SUPPORT_LONG_DIV_POW2 */
2920
2921 #if SUPPORT_LONG_REM_POW2
2922                                                         case ICMD_LREM:
2923                                                                 if ((iptr->sx.val.l == 0x00000002) ||
2924                                                                         (iptr->sx.val.l == 0x00000004) ||
2925                                                                         (iptr->sx.val.l == 0x00000008) ||
2926                                                                         (iptr->sx.val.l == 0x00000010) ||
2927                                                                         (iptr->sx.val.l == 0x00000020) ||
2928                                                                         (iptr->sx.val.l == 0x00000040) ||
2929                                                                         (iptr->sx.val.l == 0x00000080) ||
2930                                                                         (iptr->sx.val.l == 0x00000100) ||
2931                                                                         (iptr->sx.val.l == 0x00000200) ||
2932                                                                         (iptr->sx.val.l == 0x00000400) ||
2933                                                                         (iptr->sx.val.l == 0x00000800) ||
2934                                                                         (iptr->sx.val.l == 0x00001000) ||
2935                                                                         (iptr->sx.val.l == 0x00002000) ||
2936                                                                         (iptr->sx.val.l == 0x00004000) ||
2937                                                                         (iptr->sx.val.l == 0x00008000) ||
2938                                                                         (iptr->sx.val.l == 0x00010000) ||
2939                                                                         (iptr->sx.val.l == 0x00020000) ||
2940                                                                         (iptr->sx.val.l == 0x00040000) ||
2941                                                                         (iptr->sx.val.l == 0x00080000) ||
2942                                                                         (iptr->sx.val.l == 0x00100000) ||
2943                                                                         (iptr->sx.val.l == 0x00200000) ||
2944                                                                         (iptr->sx.val.l == 0x00400000) ||
2945                                                                         (iptr->sx.val.l == 0x00800000) ||
2946                                                                         (iptr->sx.val.l == 0x01000000) ||
2947                                                                         (iptr->sx.val.l == 0x02000000) ||
2948                                                                         (iptr->sx.val.l == 0x04000000) ||
2949                                                                         (iptr->sx.val.l == 0x08000000) ||
2950                                                                         (iptr->sx.val.l == 0x10000000) ||
2951                                                                         (iptr->sx.val.l == 0x20000000) ||
2952                                                                         (iptr->sx.val.l == 0x40000000) ||
2953                                                                         (iptr->sx.val.l == 0x80000000))
2954                                                                 {
2955                                                                         iptr->opc = ICMD_LREMPOW2;
2956                                                                         iptr->sx.val.l -= 1;
2957                                                                         goto icmd_lconst_tail;
2958                                                                 }
2959                                                                 goto normal_LCONST;
2960 #endif /* SUPPORT_LONG_REM_POW2 */
2961
2962 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
2963
2964                                                         case ICMD_LAND:
2965                                                                 iptr->opc = ICMD_LANDCONST;
2966                                                                 goto icmd_lconst_tail;
2967
2968                                                         case ICMD_LOR:
2969                                                                 iptr->opc = ICMD_LORCONST;
2970                                                                 goto icmd_lconst_tail;
2971
2972                                                         case ICMD_LXOR:
2973                                                                 iptr->opc = ICMD_LXORCONST;
2974                                                                 goto icmd_lconst_tail;
2975 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
2976
2977 #if SUPPORT_LONG_CMP_CONST
2978                                                         case ICMD_LCMP:
2979                                                                 if ((len <= 1) || (iptr[2].sx.val.i != 0))
2980                                                                         goto normal_LCONST;
2981
2982                                                                 /* switch on the instruction after LCONST - LCMP */
2983
2984                                                                 switch (iptr[2].opc) {
2985                                                                         case ICMD_IFEQ:
2986                                                                                 iptr->opc = ICMD_IF_LEQ;
2987                                                                                 /* FALLTHROUGH */
2988
2989                                                                         icmd_lconst_lcmp_tail:
2990                                                                                 /* convert LCONST, LCMP, IFXX to IF_LXX */
2991                                                                                 iptr->dst.insindex = iptr[2].dst.insindex;
2992                                                                                 iptr[1].opc = ICMD_NOP;
2993                                                                                 iptr[2].opc = ICMD_NOP;
2994
2995                                                                                 OP1_BRANCH(TYPE_LNG);
2996                                                                                 BRANCH(tbptr);
2997                                                                                 COUNT(count_pcmd_bra);
2998                                                                                 COUNT(count_pcmd_op);
2999                                                                                 break;
3000
3001                                                                         case ICMD_IFNE:
3002                                                                                 iptr->opc = ICMD_IF_LNE;
3003                                                                                 goto icmd_lconst_lcmp_tail;
3004
3005                                                                         case ICMD_IFLT:
3006                                                                                 iptr->opc = ICMD_IF_LLT;
3007                                                                                 goto icmd_lconst_lcmp_tail;
3008
3009                                                                         case ICMD_IFGT:
3010                                                                                 iptr->opc = ICMD_IF_LGT;
3011                                                                                 goto icmd_lconst_lcmp_tail;
3012
3013                                                                         case ICMD_IFLE:
3014                                                                                 iptr->opc = ICMD_IF_LLE;
3015                                                                                 goto icmd_lconst_lcmp_tail;
3016
3017                                                                         case ICMD_IFGE:
3018                                                                                 iptr->opc = ICMD_IF_LGE;
3019                                                                                 goto icmd_lconst_lcmp_tail;
3020
3021                                                                         default:
3022                                                                                 goto normal_LCONST;
3023                                                                 } /* end switch on opcode after LCONST - LCMP */
3024                                                                 break;
3025 #endif /* SUPPORT_LONG_CMP_CONST */
3026
3027 #if SUPPORT_CONST_STORE
3028                                                         case ICMD_LASTORE:
3029 # if SUPPORT_CONST_STORE_ZERO_ONLY
3030                                                                 if (iptr->sx.val.l != 0)
3031                                                                         goto normal_LCONST;
3032 # endif
3033 #if SIZEOF_VOID_P == 4
3034                                                                 /* the constant must fit into a ptrint */
3035                                                                 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
3036                                                                         goto normal_LCONST;
3037 #endif
3038                                                                 /* move the constant to s3 */
3039                                                                 iptr->sx.s23.s3.constval = iptr->sx.val.l;
3040
3041                                                                 iptr->opc = ICMD_LASTORECONST;
3042                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3043                                                                 OP2_0(TYPE_ADR, TYPE_INT);
3044
3045                                                                 iptr[1].opc = ICMD_NOP;
3046                                                                 COUNT(count_pcmd_op);
3047                                                                 break;
3048
3049                                                         case ICMD_PUTSTATIC:
3050                                                         case ICMD_PUTFIELD:
3051 # if SUPPORT_CONST_STORE_ZERO_ONLY
3052                                                                 if (iptr->sx.val.l != 0)
3053                                                                         goto normal_LCONST;
3054 # endif
3055 #if SIZEOF_VOID_P == 4
3056                                                                 /* the constant must fit into a ptrint */
3057                                                                 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
3058                                                                         goto normal_LCONST;
3059 #endif
3060                                                                 /* XXX check field type? */
3061
3062                                                                 /* copy the constant to s2 */
3063                                                                 /* XXX constval -> fieldconstval? */
3064                                                                 iptr->sx.s23.s2.constval = iptr->sx.val.l;
3065
3066                                                                 goto putconst_tail;
3067
3068 #endif /* SUPPORT_CONST_STORE */
3069
3070                                                         default:
3071                                                                 goto normal_LCONST;
3072                                                 } /* end switch opcode after LCONST */
3073
3074                                                 /* if we get here, the LCONST has been optimized */
3075                                                 break;
3076
3077 normal_LCONST:
3078                                                 /* the normal case of an unoptimized LCONST */
3079                                                 OP0_1(TYPE_LNG);
3080                                                 break;
3081
3082         /************************ END OF LCONST OPTIMIZATIONS *********************/
3083
3084                                         case ICMD_FCONST:
3085                                                 COUNT(count_pcmd_load);
3086                                                 OP0_1(TYPE_FLT);
3087                                                 break;
3088
3089                                         case ICMD_DCONST:
3090                                                 COUNT(count_pcmd_load);
3091                                                 OP0_1(TYPE_DBL);
3092                                                 break;
3093
3094         /************************** ACONST OPTIMIZATIONS **************************/
3095
3096                                         case ICMD_ACONST:
3097                                                 coalescing_boundary = sd.new;
3098                                                 COUNT(count_pcmd_load);
3099 #if SUPPORT_CONST_STORE
3100                                                 /* We can only optimize if the ACONST is resolved
3101                                                  * and there is an instruction after it. */
3102
3103                                                 if ((len == 0) || (iptr->flags.bits & INS_FLAG_UNRESOLVED))
3104                                                         goto normal_ACONST;
3105
3106                                                 switch (iptr[1].opc) {
3107                                                         case ICMD_AASTORE:
3108                                                                 /* We can only optimize for NULL values
3109                                                                  * here because otherwise a checkcast is
3110                                                                  * required. */
3111                                                                 if (iptr->sx.val.anyptr != NULL)
3112                                                                         goto normal_ACONST;
3113
3114                                                                 /* copy the constant (NULL) to s3 */
3115                                                                 iptr->sx.s23.s3.constval = 0;
3116                                                                 iptr->opc = ICMD_AASTORECONST;
3117                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3118                                                                 OP2_0(TYPE_ADR, TYPE_INT);
3119
3120                                                                 iptr[1].opc = ICMD_NOP;
3121                                                                 COUNT(count_pcmd_op);
3122                                                                 break;
3123
3124                                                         case ICMD_PUTSTATIC:
3125                                                         case ICMD_PUTFIELD:
3126 # if SUPPORT_CONST_STORE_ZERO_ONLY
3127                                                                 if (iptr->sx.val.anyptr != NULL)
3128                                                                         goto normal_ACONST;
3129 # endif
3130                                                                 /* XXX check field type? */
3131                                                                 /* copy the constant to s2 */
3132                                                                 /* XXX constval -> fieldconstval? */
3133                                                                 iptr->sx.s23.s2.constval = (ptrint) iptr->sx.val.anyptr;
3134
3135                                                                 goto putconst_tail;
3136
3137                                                         default:
3138                                                                 goto normal_ACONST;
3139                                                 }
3140
3141                                                 /* if we get here the ACONST has been optimized */
3142                                                 break;
3143
3144 normal_ACONST:
3145 #endif /* SUPPORT_CONST_STORE */
3146                                                 OP0_1(TYPE_ADR);
3147                                                 break;
3148
3149
3150                                                 /* pop 0 push 1 load */
3151
3152                                         case ICMD_ILOAD:
3153                                         case ICMD_LLOAD:
3154                                         case ICMD_FLOAD:
3155                                         case ICMD_DLOAD:
3156                                         case ICMD_ALOAD:
3157                                                 COUNT(count_load_instruction);
3158                                                 i = opcode - ICMD_ILOAD; /* type */
3159
3160                                                 j = iptr->s1.varindex = 
3161                                                         jd->local_map[iptr->s1.varindex * 5 + i];
3162
3163 #if defined(ENABLE_VERIFIER)
3164                                                 if (sd.var[j].type == TYPE_RET) {
3165                                                         exceptions_throw_verifyerror(m, "forbidden load of returnAddress");
3166                                                         return false;
3167                                                 }
3168 #endif
3169                 
3170 #if defined(ENABLE_SSA)
3171                                                 if (ls != NULL) {
3172                                                         GET_NEW_VAR(sd, new_index, i);
3173                                                         DST(i, new_index);
3174                                                         stackdepth++;
3175                                                 }
3176                                                 else
3177
3178 #else
3179                                                 LOAD(i, j);
3180 #endif
3181                                                 break;
3182
3183                                                 /* pop 2 push 1 */
3184
3185                                         case ICMD_LALOAD:
3186                                         case ICMD_FALOAD:
3187                                         case ICMD_DALOAD:
3188                                         case ICMD_AALOAD:
3189                                                 coalescing_boundary = sd.new;
3190                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3191                                                 COUNT(count_check_null);
3192                                                 COUNT(count_check_bound);
3193                                                 COUNT(count_pcmd_mem);
3194                                                 OP2_1(TYPE_ADR, TYPE_INT, opcode - ICMD_IALOAD);
3195                                                 break;
3196
3197                                         case ICMD_IALOAD:
3198                                         case ICMD_BALOAD:
3199                                         case ICMD_CALOAD:
3200                                         case ICMD_SALOAD:
3201                                                 coalescing_boundary = sd.new;
3202                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3203                                                 COUNT(count_check_null);
3204                                                 COUNT(count_check_bound);
3205                                                 COUNT(count_pcmd_mem);
3206                                                 OP2_1(TYPE_ADR, TYPE_INT, TYPE_INT);
3207                                                 break;
3208
3209                                                 /* pop 0 push 0 iinc */
3210
3211                                         case ICMD_IINC:
3212                                                 STATISTICS_STACKDEPTH_DISTRIBUTION(count_store_depth);
3213 #if defined(ENABLE_SSA)
3214                                                 if (ls != NULL) {
3215                                                         iptr->s1.varindex = 
3216                                                                 jd->local_map[iptr->s1.varindex * 5 +TYPE_INT];
3217                                                 }
3218                                                 else {
3219 #endif
3220                                                 last_store_boundary[iptr->s1.varindex] = sd.new;
3221
3222                                                 iptr->s1.varindex = 
3223                                                         jd->local_map[iptr->s1.varindex * 5 + TYPE_INT];
3224
3225                                                 copy = curstack;
3226                                                 i = stackdepth - 1;
3227                                                 while (copy) {
3228                                                         if ((copy->varkind == LOCALVAR) &&
3229                                                                 (copy->varnum == iptr->s1.varindex))
3230                                                         {
3231                                                                 assert(IS_LOCALVAR(copy));
3232                                                                 SET_TEMPVAR(copy);
3233                                                         }
3234                                                         i--;
3235                                                         copy = copy->prev;
3236                                                 }
3237 #if defined(ENABLE_SSA)
3238                                                 }
3239 #endif
3240
3241                                                 iptr->dst.varindex = iptr->s1.varindex;
3242                                                 break;
3243
3244                                                 /* pop 1 push 0 store */
3245
3246                                         case ICMD_ISTORE:
3247                                         case ICMD_LSTORE:
3248                                         case ICMD_FSTORE:
3249                                         case ICMD_DSTORE:
3250                                         case ICMD_ASTORE:
3251                                                 REQUIRE(1);
3252
3253                                                 i = opcode - ICMD_ISTORE; /* type */
3254                                                 javaindex = iptr->dst.varindex;
3255                                                 j = iptr->dst.varindex = 
3256                                                         jd->local_map[javaindex * 5 + i];
3257
3258                                                 COPY_VAL_AND_TYPE(sd, curstack->varnum, j);
3259
3260                                                 iptr->sx.s23.s3.javaindex = javaindex;
3261
3262                                                 if (curstack->type == TYPE_RET) {
3263                                                         iptr->flags.bits |= INS_FLAG_RETADDR;
3264                                                         iptr->sx.s23.s2.retaddrnr = 
3265                                                                 UNUSED - (1 + sd.var[j].vv.retaddr->nr);
3266                                                         sd.javalocals[javaindex] = iptr->sx.s23.s2.retaddrnr;
3267                                                 }
3268                                                 else
3269                                                         sd.javalocals[javaindex] = j;
3270
3271                                                 /* invalidate the following javalocal for 2-word types */
3272
3273                                                 if (IS_2_WORD_TYPE(i)) {
3274                                                         sd.javalocals[javaindex+1] = UNUSED;
3275                                                         iptr->flags.bits |= INS_FLAG_KILL_NEXT;
3276                                                 }
3277
3278                                                 /* invalidate 2-word types if second half was overwritten */
3279
3280                                                 if (javaindex > 0 && (i = sd.javalocals[javaindex-1]) != UNUSED) {
3281                                                         if (IS_2_WORD_TYPE(sd.var[i].type)) {
3282                                                                 sd.javalocals[javaindex-1] = UNUSED;
3283                                                                 iptr->flags.bits |= INS_FLAG_KILL_PREV;
3284                                                         }
3285                                                 }
3286
3287 #if defined(ENABLE_STATISTICS)
3288                                                 if (opt_stat) {
3289                                                         count_pcmd_store++;
3290                                                         i = sd.new - curstack;
3291                                                         if (i >= 20)
3292                                                                 count_store_length[20]++;
3293                                                         else
3294                                                                 count_store_length[i]++;
3295                                                         i = stackdepth - 1;
3296                                                         if (i >= 10)
3297                                                                 count_store_depth[10]++;
3298                                                         else
3299                                                                 count_store_depth[i]++;
3300                                                 }
3301 #endif
3302
3303 #if defined(ENABLE_SSA)
3304                                                 if (ls != NULL) {
3305 #endif
3306                                                 /* check for conflicts as described in Figure 5.2 */
3307
3308                                                 copy = curstack->prev;
3309                                                 i = stackdepth - 2;
3310                                                 while (copy) {
3311                                                         if ((copy->varkind == LOCALVAR) &&
3312                                                                 (copy->varnum == j))
3313                                                         {
3314                                                                 copy->varkind = TEMPVAR;
3315                                                                 assert(IS_LOCALVAR(copy));
3316                                                                 SET_TEMPVAR(copy);
3317                                                         }
3318                                                         i--;
3319                                                         copy = copy->prev;
3320                                                 }
3321
3322                                                 /* if the variable is already coalesced, don't bother */
3323
3324                                                 /* We do not need to check against INOUT, as invars */
3325                                                 /* are always before the coalescing boundary.        */
3326
3327                                                 if (curstack->varkind == LOCALVAR)
3328                                                         goto store_tail;
3329
3330                                                 /* there is no STORE Lj while curstack is live */
3331
3332                                                 if (curstack < last_store_boundary[javaindex])
3333                                                         goto assume_conflict;
3334
3335                                                 /* curstack must be after the coalescing boundary */
3336
3337                                                 if (curstack < coalescing_boundary)
3338                                                         goto assume_conflict;
3339
3340                                                 /* there is no DEF LOCALVAR(j) while curstack is live */
3341
3342                                                 copy = sd.new; /* most recent stackslot created + 1 */
3343                                                 while (--copy > curstack) {
3344                                                         if (copy->varkind == LOCALVAR && copy->varnum == j)
3345                                                                 goto assume_conflict;
3346                                                 }
3347
3348                                                 /* coalesce the temporary variable with Lj */
3349                                                 assert((curstack->varkind == TEMPVAR)
3350                                                                         || (curstack->varkind == UNDEFVAR));
3351                                                 assert(!IS_LOCALVAR(curstack)); /* XXX correct? */
3352                                                 assert(!IS_INOUT(curstack));
3353                                                 assert(!IS_PREALLOC(curstack));
3354
3355                                                 assert(curstack->creator);
3356                                                 assert(curstack->creator->dst.varindex == curstack->varnum);
3357                                                 assert(!(curstack->flags & PASSTHROUGH));
3358                                                 RELEASE_INDEX(sd, curstack);
3359                                                 curstack->varkind = LOCALVAR;
3360                                                 curstack->varnum = j;
3361                                                 curstack->creator->dst.varindex = j;
3362                                                 goto store_tail;
3363
3364                                                 /* revert the coalescing, if it has been done earlier */
3365 assume_conflict:
3366                                                 if ((curstack->varkind == LOCALVAR)
3367                                                         && (curstack->varnum == j))
3368                                                 {
3369                                                         assert(IS_LOCALVAR(curstack));
3370                                                         SET_TEMPVAR(curstack);
3371                                                 }
3372
3373                                                 /* remember the stack boundary at this store */
3374 store_tail:
3375                                                 last_store_boundary[javaindex] = sd.new;
3376 #if defined(ENABLE_SSA)
3377                                                 } /* if (ls != NULL) */
3378 #endif
3379
3380                                                 if (opcode == ICMD_ASTORE && curstack->type == TYPE_RET)
3381                                                         STORE(TYPE_RET, j);
3382                                                 else
3383                                                         STORE(opcode - ICMD_ISTORE, j);
3384                                                 break;
3385
3386                                         /* pop 3 push 0 */
3387
3388                                         case ICMD_AASTORE:
3389                                                 coalescing_boundary = sd.new;
3390                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3391                                                 COUNT(count_check_null);
3392                                                 COUNT(count_check_bound);
3393                                                 COUNT(count_pcmd_mem);
3394
3395                                                 bte = builtintable_get_internal(BUILTIN_canstore);
3396                                                 md = bte->md;
3397
3398                                                 if (md->memuse > rd->memuse)
3399                                                         rd->memuse = md->memuse;
3400                                                 if (md->argintreguse > rd->argintreguse)
3401                                                         rd->argintreguse = md->argintreguse;
3402                                                 /* XXX non-leaf method? */
3403
3404                                                 /* make all stack variables saved */
3405
3406                                                 copy = curstack;
3407                                                 while (copy) {
3408                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
3409                                                         /* in case copy->varnum is/will be a LOCALVAR */
3410                                                         /* once and set back to a non LOCALVAR        */
3411                                                         /* the correct SAVEDVAR flag has to be        */
3412                                                         /* remembered in copy->flags, too             */
3413                                                         copy->flags |= SAVEDVAR;
3414                                                         copy = copy->prev;
3415                                                 }
3416
3417                                                 OP3_0(TYPE_ADR, TYPE_INT, TYPE_ADR);
3418                                                 break;
3419
3420
3421                                         case ICMD_LASTORE:
3422                                         case ICMD_FASTORE:
3423                                         case ICMD_DASTORE:
3424                                                 coalescing_boundary = sd.new;
3425                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3426                                                 COUNT(count_check_null);
3427                                                 COUNT(count_check_bound);
3428                                                 COUNT(count_pcmd_mem);
3429                                                 OP3_0(TYPE_ADR, TYPE_INT, opcode - ICMD_IASTORE);
3430                                                 break;
3431
3432                                         case ICMD_IASTORE:
3433                                         case ICMD_BASTORE:
3434                                         case ICMD_CASTORE:
3435                                         case ICMD_SASTORE:
3436                                                 coalescing_boundary = sd.new;
3437                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3438                                                 COUNT(count_check_null);
3439                                                 COUNT(count_check_bound);
3440                                                 COUNT(count_pcmd_mem);
3441                                                 OP3_0(TYPE_ADR, TYPE_INT, TYPE_INT);
3442                                                 break;
3443
3444                                                 /* pop 1 push 0 */
3445
3446                                         case ICMD_POP:
3447 #ifdef ENABLE_VERIFIER
3448                                                 if (opt_verify) {
3449                                                         REQUIRE(1);
3450                                                         if (IS_2_WORD_TYPE(curstack->type))
3451                                                                 goto throw_stack_category_error;
3452                                                 }
3453 #endif
3454                                                 OP1_0_ANY;
3455                                                 break;
3456
3457                                         case ICMD_IRETURN:
3458                                         case ICMD_LRETURN:
3459                                         case ICMD_FRETURN:
3460                                         case ICMD_DRETURN:
3461                                         case ICMD_ARETURN:
3462                                                 coalescing_boundary = sd.new;
3463                                                 /* Assert here that no LOCAL or INOUTS get */
3464                                                 /* preallocated, since tha macros are not   */
3465                                                 /* available in md-abi.c! */
3466                                                 if (IS_TEMPVAR(curstack))
3467                                                         md_return_alloc(jd, curstack);
3468                                                 COUNT(count_pcmd_return);
3469                                                 OP1_0(opcode - ICMD_IRETURN);
3470                                                 superblockend = true;
3471                                                 sd.jd->returncount++;
3472                                                 sd.jd->returnblock = sd.bptr;
3473                                                 break;
3474
3475                                         case ICMD_ATHROW:
3476                                                 coalescing_boundary = sd.new;
3477                                                 COUNT(count_check_null);
3478                                                 OP1_0(TYPE_ADR);
3479                                                 curstack = NULL; stackdepth = 0;
3480                                                 superblockend = true;
3481                                                 break;
3482
3483                                         case ICMD_PUTSTATIC:
3484                                                 coalescing_boundary = sd.new;
3485                                                 COUNT(count_pcmd_mem);
3486                                                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
3487                                                 OP1_0(fmiref->parseddesc.fd->type);
3488                                                 break;
3489
3490                                                 /* pop 1 push 0 branch */
3491
3492                                         case ICMD_IFNULL:
3493                                         case ICMD_IFNONNULL:
3494                                                 COUNT(count_pcmd_bra);
3495                                                 OP1_BRANCH(TYPE_ADR);
3496                                                 BRANCH(tbptr);
3497                                                 break;
3498
3499                                         case ICMD_IFEQ:
3500                                         case ICMD_IFNE:
3501                                         case ICMD_IFLT:
3502                                         case ICMD_IFGE:
3503                                         case ICMD_IFGT:
3504                                         case ICMD_IFLE:
3505                                                 COUNT(count_pcmd_bra);
3506                                                 /* iptr->sx.val.i is set implicitly in parse by
3507                                                    clearing the memory or from IF_ICMPxx
3508                                                    optimization. */
3509
3510                                                 OP1_BRANCH(TYPE_INT);
3511 /*                                              iptr->sx.val.i = 0; */
3512                                                 BRANCH(tbptr);
3513                                                 break;
3514
3515                                                 /* pop 0 push 0 branch */
3516
3517                                         case ICMD_GOTO:
3518                                                 COUNT(count_pcmd_bra);
3519                                                 OP0_BRANCH;
3520                                                 BRANCH(tbptr);
3521                                                 superblockend = true;
3522                                                 break;
3523
3524                                                 /* pop 1 push 0 table branch */
3525
3526                                         case ICMD_TABLESWITCH:
3527                                                 COUNT(count_pcmd_table);
3528                                                 OP1_BRANCH(TYPE_INT);
3529
3530                                                 table = iptr->dst.table;
3531                                                 BRANCH_TARGET(*table, tbptr);
3532                                                 table++;
3533
3534                                                 i = iptr->sx.s23.s3.tablehigh
3535                                                   - iptr->sx.s23.s2.tablelow + 1;
3536
3537                                                 while (--i >= 0) {
3538                                                         BRANCH_TARGET(*table, tbptr);
3539                                                         table++;
3540                                                 }
3541                                                 superblockend = true;
3542                                                 break;
3543
3544                                                 /* pop 1 push 0 table branch */
3545
3546                                         case ICMD_LOOKUPSWITCH:
3547                                                 COUNT(count_pcmd_table);
3548                                                 OP1_BRANCH(TYPE_INT);
3549
3550                                                 BRANCH_TARGET(iptr->sx.s23.s3.lookupdefault, tbptr);
3551
3552                                                 lookup = iptr->dst.lookup;
3553
3554                                                 i = iptr->sx.s23.s2.lookupcount;
3555
3556                                                 while (--i >= 0) {
3557                                                         BRANCH_TARGET(lookup->target, tbptr);
3558                                                         lookup++;
3559                                                 }
3560                                                 superblockend = true;
3561                                                 break;
3562
3563                                         case ICMD_MONITORENTER:
3564                                         case ICMD_MONITOREXIT:
3565                                                 coalescing_boundary = sd.new;
3566                                                 COUNT(count_check_null);
3567                                                 OP1_0(TYPE_ADR);
3568                                                 break;
3569
3570                                                 /* pop 2 push 0 branch */
3571
3572                                         case ICMD_IF_ICMPEQ:
3573                                         case ICMD_IF_ICMPNE:
3574                                         case ICMD_IF_ICMPLT:
3575                                         case ICMD_IF_ICMPGE:
3576                                         case ICMD_IF_ICMPGT:
3577                                         case ICMD_IF_ICMPLE:
3578                                                 COUNT(count_pcmd_bra);
3579                                                 OP2_BRANCH(TYPE_INT, TYPE_INT);
3580                                                 BRANCH(tbptr);
3581                                                 break;
3582
3583                                         case ICMD_IF_ACMPEQ:
3584                                         case ICMD_IF_ACMPNE:
3585                                                 COUNT(count_pcmd_bra);
3586                                                 OP2_BRANCH(TYPE_ADR, TYPE_ADR);
3587                                                 BRANCH(tbptr);
3588                                                 break;
3589
3590                                                 /* pop 2 push 0 */
3591
3592                                         case ICMD_PUTFIELD:
3593                                                 coalescing_boundary = sd.new;
3594                                                 COUNT(count_check_null);
3595                                                 COUNT(count_pcmd_mem);
3596                                                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
3597                                                 OP2_0(TYPE_ADR, fmiref->parseddesc.fd->type);
3598                                                 break;
3599
3600                                         case ICMD_POP2:
3601                                                 REQUIRE(1);
3602                                                 if (!IS_2_WORD_TYPE(curstack->type)) {
3603                                                         /* ..., cat1 */
3604 #ifdef ENABLE_VERIFIER
3605                                                         if (opt_verify) {
3606                                                                 REQUIRE(2);
3607                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
3608                                                                         goto throw_stack_category_error;
3609                                                         }
3610 #endif
3611                                                         OP2_0_ANY_ANY; /* pop two slots */
3612                                                 }
3613                                                 else {
3614                                                         iptr->opc = ICMD_POP;
3615                                                         OP1_0_ANY; /* pop one (two-word) slot */
3616                                                 }
3617                                                 break;
3618
3619                                                 /* pop 0 push 1 dup */
3620
3621                                         case ICMD_DUP:
3622 #ifdef ENABLE_VERIFIER
3623                                                 if (opt_verify) {
3624                                                         REQUIRE(1);
3625                                                         if (IS_2_WORD_TYPE(curstack->type))
3626                                                                 goto throw_stack_category_error;
3627                                                 }
3628 #endif
3629                                                 COUNT(count_dup_instruction);
3630
3631 icmd_DUP:
3632                                                 src1 = curstack;
3633
3634                                                 COPY_UP(src1);
3635                                                 coalescing_boundary = sd.new - 1;
3636                                                 break;
3637
3638                                         case ICMD_DUP2:
3639                                                 REQUIRE(1);
3640                                                 if (IS_2_WORD_TYPE(curstack->type)) {
3641                                                         /* ..., cat2 */
3642                                                         iptr->opc = ICMD_DUP;
3643                                                         goto icmd_DUP;
3644                                                 }
3645                                                 else {
3646                                                         REQUIRE(2);
3647                                                         /* ..., ????, cat1 */
3648 #ifdef ENABLE_VERIFIER
3649                                                         if (opt_verify) {
3650                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
3651                                                                         goto throw_stack_category_error;
3652                                                         }
3653 #endif
3654                                                         src1 = curstack->prev;
3655                                                         src2 = curstack;
3656
3657                                                         COPY_UP(src1); iptr++; len--;
3658                                                         COPY_UP(src2);
3659
3660                                                         coalescing_boundary = sd.new;
3661                                                 }
3662                                                 break;
3663
3664                                                 /* pop 2 push 3 dup */
3665
3666                                         case ICMD_DUP_X1:
3667 #ifdef ENABLE_VERIFIER
3668                                                 if (opt_verify) {
3669                                                         REQUIRE(2);
3670                                                         if (IS_2_WORD_TYPE(curstack->type) ||
3671                                                                 IS_2_WORD_TYPE(curstack->prev->type))
3672                                                                         goto throw_stack_category_error;
3673                                                 }
3674 #endif
3675
3676 icmd_DUP_X1:
3677                                                 src1 = curstack->prev;
3678                                                 src2 = curstack;
3679                                                 POPANY; POPANY;
3680                                                 stackdepth -= 2;
3681
3682                                                 /* move non-temporary sources out of the way */
3683                                                 if (!IS_TEMPVAR(src2)) {
3684                                                         MOVE_TO_TEMP(src2); iptr++; len--;
3685                                                 }
3686
3687                                                 DUP_SLOT(src2); dst1 = curstack; stackdepth++;
3688
3689                                                 MOVE_UP(src1); iptr++; len--;
3690                                                 MOVE_UP(src2); iptr++; len--;
3691
3692                                                 COPY_DOWN(curstack, dst1);
3693
3694                                                 coalescing_boundary = sd.new;
3695                                                 break;
3696
3697                                         case ICMD_DUP2_X1:
3698                                                 REQUIRE(2);
3699                                                 if (IS_2_WORD_TYPE(curstack->type)) {
3700                                                         /* ..., ????, cat2 */
3701 #ifdef ENABLE_VERIFIER
3702                                                         if (opt_verify) {
3703                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
3704                                                                         goto throw_stack_category_error;
3705                                                         }
3706 #endif
3707                                                         iptr->opc = ICMD_DUP_X1;
3708                                                         goto icmd_DUP_X1;
3709                                                 }
3710                                                 else {
3711                                                         /* ..., ????, cat1 */
3712 #ifdef ENABLE_VERIFIER
3713                                                         if (opt_verify) {
3714                                                                 REQUIRE(3);
3715                                                                 if (IS_2_WORD_TYPE(curstack->prev->type)
3716                                                                         || IS_2_WORD_TYPE(curstack->prev->prev->type))
3717                                                                                 goto throw_stack_category_error;
3718                                                         }
3719 #endif
3720
3721 icmd_DUP2_X1:
3722                                                         src1 = curstack->prev->prev;
3723                                                         src2 = curstack->prev;
3724                                                         src3 = curstack;
3725                                                         POPANY; POPANY; POPANY;
3726                                                         stackdepth -= 3;
3727
3728                                                         /* move non-temporary sources out of the way */
3729                                                         if (!IS_TEMPVAR(src2)) {
3730                                                                 MOVE_TO_TEMP(src2); iptr++; len--;
3731                                                         }
3732                                                         if (!IS_TEMPVAR(src3)) {
3733                                                                 MOVE_TO_TEMP(src3); iptr++; len--;
3734                                                         }
3735
3736                                                         DUP_SLOT(src2); dst1 = curstack; stackdepth++;
3737                                                         DUP_SLOT(src3); dst2 = curstack; stackdepth++;
3738
3739                                                         MOVE_UP(src1); iptr++; len--;
3740                                                         MOVE_UP(src2); iptr++; len--;
3741                                                         MOVE_UP(src3); iptr++; len--;
3742
3743                                                         COPY_DOWN(curstack, dst2); iptr++; len--;
3744                                                         COPY_DOWN(curstack->prev, dst1);
3745
3746                                                         coalescing_boundary = sd.new;
3747                                                 }
3748                                                 break;
3749
3750                                                 /* pop 3 push 4 dup */
3751
3752                                         case ICMD_DUP_X2:
3753                                                 REQUIRE(2);
3754                                                 if (IS_2_WORD_TYPE(curstack->prev->type)) {
3755                                                         /* ..., cat2, ???? */
3756 #ifdef ENABLE_VERIFIER
3757                                                         if (opt_verify) {
3758                                                                 if (IS_2_WORD_TYPE(curstack->type))
3759                                                                         goto throw_stack_category_error;
3760                                                         }
3761 #endif
3762                                                         iptr->opc = ICMD_DUP_X1;
3763                                                         goto icmd_DUP_X1;
3764                                                 }
3765                                                 else {
3766                                                         /* ..., cat1, ???? */
3767 #ifdef ENABLE_VERIFIER
3768                                                         if (opt_verify) {
3769                                                                 REQUIRE(3);
3770                                                                 if (IS_2_WORD_TYPE(curstack->type)
3771                                                                         || IS_2_WORD_TYPE(curstack->prev->prev->type))
3772                                                                                         goto throw_stack_category_error;
3773                                                         }
3774 #endif
3775 icmd_DUP_X2:
3776                                                         src1 = curstack->prev->prev;
3777                                                         src2 = curstack->prev;
3778                                                         src3 = curstack;
3779                                                         POPANY; POPANY; POPANY;
3780                                                         stackdepth -= 3;
3781
3782                                                         /* move non-temporary sources out of the way */
3783                                                         if (!IS_TEMPVAR(src2)) {
3784                                                                 MOVE_TO_TEMP(src2); iptr++; len--;
3785                                                         }
3786                                                         if (!IS_TEMPVAR(src3)) {
3787                                                                 MOVE_TO_TEMP(src3); iptr++; len--;
3788                                                         }
3789
3790                                                         DUP_SLOT(src3); dst1 = curstack; stackdepth++;
3791
3792                                                         MOVE_UP(src1); iptr++; len--;
3793                                                         MOVE_UP(src2); iptr++; len--;
3794                                                         MOVE_UP(src3); iptr++; len--;
3795
3796                                                         COPY_DOWN(curstack, dst1);
3797
3798                                                         coalescing_boundary = sd.new;
3799                                                 }
3800                                                 break;
3801
3802                                         case ICMD_DUP2_X2:
3803                                                 REQUIRE(2);
3804                                                 if (IS_2_WORD_TYPE(curstack->type)) {
3805                                                         /* ..., ????, cat2 */
3806                                                         if (IS_2_WORD_TYPE(curstack->prev->type)) {
3807                                                                 /* ..., cat2, cat2 */
3808                                                                 iptr->opc = ICMD_DUP_X1;
3809                                                                 goto icmd_DUP_X1;
3810                                                         }
3811                                                         else {
3812                                                                 /* ..., cat1, cat2 */
3813 #ifdef ENABLE_VERIFIER
3814                                                                 if (opt_verify) {
3815                                                                         REQUIRE(3);
3816                                                                         if (IS_2_WORD_TYPE(curstack->prev->prev->type))
3817                                                                                         goto throw_stack_category_error;
3818                                                                 }
3819 #endif
3820                                                                 iptr->opc = ICMD_DUP_X2;
3821                                                                 goto icmd_DUP_X2;
3822                                                         }
3823                                                 }
3824
3825                                                 REQUIRE(3);
3826                                                 /* ..., ????, ????, cat1 */
3827
3828                                                 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
3829                                                         /* ..., cat2, ????, cat1 */
3830 #ifdef ENABLE_VERIFIER
3831                                                         if (opt_verify) {
3832                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
3833                                                                         goto throw_stack_category_error;
3834                                                         }
3835 #endif
3836                                                         iptr->opc = ICMD_DUP2_X1;
3837                                                         goto icmd_DUP2_X1;
3838                                                 }
3839                                                 else {
3840                                                         /* ..., cat1, ????, cat1 */
3841 #ifdef ENABLE_VERIFIER
3842                                                         if (opt_verify) {
3843                                                                 REQUIRE(4);
3844                                                                 if (IS_2_WORD_TYPE(curstack->prev->type)
3845                                                                         || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
3846                                                                         goto throw_stack_category_error;
3847                                                         }
3848 #endif
3849
3850                                                         src1 = curstack->prev->prev->prev;
3851                                                         src2 = curstack->prev->prev;
3852                                                         src3 = curstack->prev;
3853                                                         src4 = curstack;
3854                                                         POPANY; POPANY; POPANY; POPANY;
3855                                                         stackdepth -= 4;
3856
3857                                                         /* move non-temporary sources out of the way */
3858                                                         if (!IS_TEMPVAR(src2)) {
3859                                                                 MOVE_TO_TEMP(src2); iptr++; len--;
3860                                                         }
3861                                                         if (!IS_TEMPVAR(src3)) {
3862                                                                 MOVE_TO_TEMP(src3); iptr++; len--;
3863                                                         }
3864                                                         if (!IS_TEMPVAR(src4)) {
3865                                                                 MOVE_TO_TEMP(src4); iptr++; len--;
3866                                                         }
3867
3868                                                         DUP_SLOT(src3); dst1 = curstack; stackdepth++;
3869                                                         DUP_SLOT(src4); dst2 = curstack; stackdepth++;
3870
3871                                                         MOVE_UP(src1); iptr++; len--;
3872                                                         MOVE_UP(src2); iptr++; len--;
3873                                                         MOVE_UP(src3); iptr++; len--;
3874                                                         MOVE_UP(src4); iptr++; len--;
3875
3876                                                         COPY_DOWN(curstack, dst2); iptr++; len--;
3877                                                         COPY_DOWN(curstack->prev, dst1);
3878
3879                                                         coalescing_boundary = sd.new;
3880                                                 }
3881                                                 break;
3882
3883                                                 /* pop 2 push 2 swap */
3884
3885                                         case ICMD_SWAP:
3886 #ifdef ENABLE_VERIFIER
3887                                                 if (opt_verify) {
3888                                                         REQUIRE(2);
3889                                                         if (IS_2_WORD_TYPE(curstack->type)
3890                                                                 || IS_2_WORD_TYPE(curstack->prev->type))
3891                                                                 goto throw_stack_category_error;
3892                                                 }
3893 #endif
3894
3895                                                 src1 = curstack->prev;
3896                                                 src2 = curstack;
3897                                                 POPANY; POPANY;
3898                                                 stackdepth -= 2;
3899
3900                                                 /* move non-temporary sources out of the way */
3901                                                 if (!IS_TEMPVAR(src1)) {
3902                                                         MOVE_TO_TEMP(src1); iptr++; len--;
3903                                                 }
3904
3905                                                 MOVE_UP(src2); iptr++; len--;
3906                                                 MOVE_UP(src1);
3907
3908                                                 coalescing_boundary = sd.new;
3909                                                 break;
3910
3911                                                 /* pop 2 push 1 */
3912
3913                                         case ICMD_IDIV:
3914                                         case ICMD_IREM:
3915                                                 coalescing_boundary = sd.new;
3916 #if !SUPPORT_DIVISION
3917                                                 bte = iptr->sx.s23.s3.bte;
3918                                                 md = bte->md;
3919
3920                                                 if (md->memuse > rd->memuse)
3921                                                         rd->memuse = md->memuse;
3922                                                 if (md->argintreguse > rd->argintreguse)
3923                                                         rd->argintreguse = md->argintreguse;
3924
3925                                                 /* make all stack variables saved */
3926
3927                                                 copy = curstack;
3928                                                 while (copy) {
3929                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
3930                                                         copy->flags |= SAVEDVAR;
3931                                                         copy = copy->prev;
3932                                                 }
3933                                                 /* FALLTHROUGH */
3934
3935 #endif /* !SUPPORT_DIVISION */
3936
3937                                         case ICMD_ISHL:
3938                                         case ICMD_ISHR:
3939                                         case ICMD_IUSHR:
3940                                         case ICMD_IADD:
3941                                         case ICMD_ISUB:
3942                                         case ICMD_IMUL:
3943                                         case ICMD_IAND:
3944                                         case ICMD_IOR:
3945                                         case ICMD_IXOR:
3946                                                 COUNT(count_pcmd_op);
3947                                                 OP2_1(TYPE_INT, TYPE_INT, TYPE_INT);
3948                                                 break;
3949
3950                                         case ICMD_LDIV:
3951                                         case ICMD_LREM:
3952                                                 coalescing_boundary = sd.new;
3953 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
3954                                                 bte = iptr->sx.s23.s3.bte;
3955                                                 md = bte->md;
3956
3957                                                 if (md->memuse > rd->memuse)
3958                                                         rd->memuse = md->memuse;
3959                                                 if (md->argintreguse > rd->argintreguse)
3960                                                         rd->argintreguse = md->argintreguse;
3961                                                 /* XXX non-leaf method? */
3962
3963                                                 /* make all stack variables saved */
3964
3965                                                 copy = curstack;
3966                                                 while (copy) {
3967                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
3968                                                         copy->flags |= SAVEDVAR;
3969                                                         copy = copy->prev;
3970                                                 }
3971                                                 /* FALLTHROUGH */
3972
3973 #endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
3974
3975                                         case ICMD_LMUL:
3976                                         case ICMD_LADD:
3977                                         case ICMD_LSUB:
3978 #if SUPPORT_LONG_LOGICAL
3979                                         case ICMD_LAND:
3980                                         case ICMD_LOR:
3981                                         case ICMD_LXOR:
3982 #endif /* SUPPORT_LONG_LOGICAL */
3983                                                 COUNT(count_pcmd_op);
3984                                                 OP2_1(TYPE_LNG, TYPE_LNG, TYPE_LNG);
3985                                                 break;
3986
3987                                         case ICMD_LSHL:
3988                                         case ICMD_LSHR:
3989                                         case ICMD_LUSHR:
3990                                                 COUNT(count_pcmd_op);
3991                                                 OP2_1(TYPE_LNG, TYPE_INT, TYPE_LNG);
3992                                                 break;
3993
3994                                         case ICMD_FADD:
3995                                         case ICMD_FSUB:
3996                                         case ICMD_FMUL:
3997                                         case ICMD_FDIV:
3998                                         case ICMD_FREM:
3999                                                 COUNT(count_pcmd_op);
4000                                                 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_FLT);
4001                                                 break;
4002
4003                                         case ICMD_DADD:
4004                                         case ICMD_DSUB:
4005                                         case ICMD_DMUL:
4006                                         case ICMD_DDIV:
4007                                         case ICMD_DREM:
4008                                                 COUNT(count_pcmd_op);
4009                                                 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_DBL);
4010                                                 break;
4011
4012                                         case ICMD_LCMP:
4013                                                 COUNT(count_pcmd_op);
4014 #if SUPPORT_LONG_CMP_CONST
4015                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
4016                                                         goto normal_LCMP;
4017
4018                                                 switch (iptr[1].opc) {
4019                                                 case ICMD_IFEQ:
4020                                                         iptr->opc = ICMD_IF_LCMPEQ;
4021                                                 icmd_lcmp_if_tail:
4022                                                         iptr->dst.insindex = iptr[1].dst.insindex;
4023                                                         iptr[1].opc = ICMD_NOP;
4024
4025                                                         OP2_BRANCH(TYPE_LNG, TYPE_LNG);
4026                                                         BRANCH(tbptr);
4027
4028                                                         COUNT(count_pcmd_bra);
4029                                                         break;
4030                                                 case ICMD_IFNE:
4031                                                         iptr->opc = ICMD_IF_LCMPNE;
4032                                                         goto icmd_lcmp_if_tail;
4033                                                 case ICMD_IFLT:
4034                                                         iptr->opc = ICMD_IF_LCMPLT;
4035                                                         goto icmd_lcmp_if_tail;
4036                                                 case ICMD_IFGT:
4037                                                         iptr->opc = ICMD_IF_LCMPGT;
4038                                                         goto icmd_lcmp_if_tail;
4039                                                 case ICMD_IFLE:
4040                                                         iptr->opc = ICMD_IF_LCMPLE;
4041                                                         goto icmd_lcmp_if_tail;
4042                                                 case ICMD_IFGE:
4043                                                         iptr->opc = ICMD_IF_LCMPGE;
4044                                                         goto icmd_lcmp_if_tail;
4045                                                 default:
4046                                                         goto normal_LCMP;
4047                                                 }
4048                                                 break;
4049 normal_LCMP:
4050 #endif /* SUPPORT_LONG_CMP_CONST */
4051                                                         OP2_1(TYPE_LNG, TYPE_LNG, TYPE_INT);
4052                                                 break;
4053
4054                                                 /* XXX why is this deactivated? */
4055 #if 0
4056                                         case ICMD_FCMPL:
4057                                                 COUNT(count_pcmd_op);
4058                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
4059                                                         goto normal_FCMPL;
4060
4061                                                 switch (iptr[1].opc) {
4062                                                 case ICMD_IFEQ:
4063                                                         iptr->opc = ICMD_IF_FCMPEQ;
4064                                                 icmd_if_fcmpl_tail:
4065                                                         iptr->dst.insindex = iptr[1].dst.insindex;
4066                                                         iptr[1].opc = ICMD_NOP;
4067
4068                                                         OP2_BRANCH(TYPE_FLT, TYPE_FLT);
4069                                                         BRANCH(tbptr);
4070
4071                                                         COUNT(count_pcmd_bra);
4072                                                         break;
4073                                                 case ICMD_IFNE:
4074                                                         iptr->opc = ICMD_IF_FCMPNE;
4075                                                         goto icmd_if_fcmpl_tail;
4076                                                 case ICMD_IFLT:
4077                                                         iptr->opc = ICMD_IF_FCMPL_LT;
4078                                                         goto icmd_if_fcmpl_tail;
4079                                                 case ICMD_IFGT:
4080                                                         iptr->opc = ICMD_IF_FCMPL_GT;
4081                                                         goto icmd_if_fcmpl_tail;
4082                                                 case ICMD_IFLE:
4083                                                         iptr->opc = ICMD_IF_FCMPL_LE;
4084                                                         goto icmd_if_fcmpl_tail;
4085                                                 case ICMD_IFGE:
4086                                                         iptr->opc = ICMD_IF_FCMPL_GE;
4087                                                         goto icmd_if_fcmpl_tail;
4088                                                 default:
4089                                                         goto normal_FCMPL;
4090                                                 }
4091                                                 break;
4092
4093 normal_FCMPL:
4094                                                 OPTT2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
4095                                                 break;
4096
4097                                         case ICMD_FCMPG:
4098                                                 COUNT(count_pcmd_op);
4099                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
4100                                                         goto normal_FCMPG;
4101
4102                                                 switch (iptr[1].opc) {
4103                                                 case ICMD_IFEQ:
4104                                                         iptr->opc = ICMD_IF_FCMPEQ;
4105                                                 icmd_if_fcmpg_tail:
4106                                                         iptr->dst.insindex = iptr[1].dst.insindex;
4107                                                         iptr[1].opc = ICMD_NOP;
4108
4109                                                         OP2_BRANCH(TYPE_FLT, TYPE_FLT);
4110                                                         BRANCH(tbptr);
4111
4112                                                         COUNT(count_pcmd_bra);
4113                                                         break;
4114                                                 case ICMD_IFNE:
4115                                                         iptr->opc = ICMD_IF_FCMPNE;
4116                                                         goto icmd_if_fcmpg_tail;
4117                                                 case ICMD_IFLT:
4118                                                         iptr->opc = ICMD_IF_FCMPG_LT;
4119                                                         goto icmd_if_fcmpg_tail;
4120                                                 case ICMD_IFGT:
4121                                                         iptr->opc = ICMD_IF_FCMPG_GT;
4122                                                         goto icmd_if_fcmpg_tail;
4123                                                 case ICMD_IFLE:
4124                                                         iptr->opc = ICMD_IF_FCMPG_LE;
4125                                                         goto icmd_if_fcmpg_tail;
4126                                                 case ICMD_IFGE:
4127                                                         iptr->opc = ICMD_IF_FCMPG_GE;
4128                                                         goto icmd_if_fcmpg_tail;
4129                                                 default:
4130                                                         goto normal_FCMPG;
4131                                                 }
4132                                                 break;
4133
4134 normal_FCMPG:
4135                                                 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
4136                                                 break;
4137
4138                                         case ICMD_DCMPL:
4139                                                 COUNT(count_pcmd_op);
4140                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
4141                                                         goto normal_DCMPL;
4142
4143                                                 switch (iptr[1].opc) {
4144                                                 case ICMD_IFEQ:
4145                                                         iptr->opc = ICMD_IF_DCMPEQ;
4146                                                 icmd_if_dcmpl_tail:
4147                                                         iptr->dst.insindex = iptr[1].dst.insindex;
4148                                                         iptr[1].opc = ICMD_NOP;
4149
4150                                                         OP2_BRANCH(TYPE_DBL, TYPE_DBL);
4151                                                         BRANCH(tbptr);
4152
4153                                                         COUNT(count_pcmd_bra);
4154                                                         break;
4155                                                 case ICMD_IFNE:
4156                                                         iptr->opc = ICMD_IF_DCMPNE;
4157                                                         goto icmd_if_dcmpl_tail;
4158                                                 case ICMD_IFLT:
4159                                                         iptr->opc = ICMD_IF_DCMPL_LT;
4160                                                         goto icmd_if_dcmpl_tail;
4161                                                 case ICMD_IFGT:
4162                                                         iptr->opc = ICMD_IF_DCMPL_GT;
4163                                                         goto icmd_if_dcmpl_tail;
4164                                                 case ICMD_IFLE:
4165                                                         iptr->opc = ICMD_IF_DCMPL_LE;
4166                                                         goto icmd_if_dcmpl_tail;
4167                                                 case ICMD_IFGE:
4168                                                         iptr->opc = ICMD_IF_DCMPL_GE;
4169                                                         goto icmd_if_dcmpl_tail;
4170                                                 default:
4171                                                         goto normal_DCMPL;
4172                                                 }
4173                                                 break;
4174
4175 normal_DCMPL:
4176                                                 OPTT2_1(TYPE_DBL, TYPE_INT);
4177                                                 break;
4178
4179                                         case ICMD_DCMPG:
4180                                                 COUNT(count_pcmd_op);
4181                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
4182                                                         goto normal_DCMPG;
4183
4184                                                 switch (iptr[1].opc) {
4185                                                 case ICMD_IFEQ:
4186                                                         iptr->opc = ICMD_IF_DCMPEQ;
4187                                                 icmd_if_dcmpg_tail:
4188                                                         iptr->dst.insindex = iptr[1].dst.insindex;
4189                                                         iptr[1].opc = ICMD_NOP;
4190
4191                                                         OP2_BRANCH(TYPE_DBL, TYPE_DBL);
4192                                                         BRANCH(tbptr);
4193
4194                                                         COUNT(count_pcmd_bra);
4195                                                         break;
4196                                                 case ICMD_IFNE:
4197                                                         iptr->opc = ICMD_IF_DCMPNE;
4198                                                         goto icmd_if_dcmpg_tail;
4199                                                 case ICMD_IFLT:
4200                                                         iptr->opc = ICMD_IF_DCMPG_LT;
4201                                                         goto icmd_if_dcmpg_tail;
4202                                                 case ICMD_IFGT:
4203                                                         iptr->opc = ICMD_IF_DCMPG_GT;
4204                                                         goto icmd_if_dcmpg_tail;
4205                                                 case ICMD_IFLE:
4206                                                         iptr->opc = ICMD_IF_DCMPG_LE;
4207                                                         goto icmd_if_dcmpg_tail;
4208                                                 case ICMD_IFGE:
4209                                                         iptr->opc = ICMD_IF_DCMPG_GE;
4210                                                         goto icmd_if_dcmpg_tail;
4211                                                 default:
4212                                                         goto normal_DCMPG;
4213                                                 }
4214                                                 break;
4215
4216 normal_DCMPG:
4217                                                 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
4218                                                 break;
4219 #else
4220                                         case ICMD_FCMPL:
4221                                         case ICMD_FCMPG:
4222                                                 COUNT(count_pcmd_op);
4223                                                 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
4224                                                 break;
4225
4226                                         case ICMD_DCMPL:
4227                                         case ICMD_DCMPG:
4228                                                 COUNT(count_pcmd_op);
4229                                                 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
4230                                                 break;
4231 #endif
4232
4233                                                 /* pop 1 push 1 */
4234
4235                                         case ICMD_INEG:
4236                                         case ICMD_INT2BYTE:
4237                                         case ICMD_INT2CHAR:
4238                                         case ICMD_INT2SHORT:
4239                                                 COUNT(count_pcmd_op);
4240                                                 OP1_1(TYPE_INT, TYPE_INT);
4241                                                 break;
4242                                         case ICMD_LNEG:
4243                                                 COUNT(count_pcmd_op);
4244                                                 OP1_1(TYPE_LNG, TYPE_LNG);
4245                                                 break;
4246                                         case ICMD_FNEG:
4247                                                 COUNT(count_pcmd_op);
4248                                                 OP1_1(TYPE_FLT, TYPE_FLT);
4249                                                 break;
4250                                         case ICMD_DNEG:
4251                                                 COUNT(count_pcmd_op);
4252                                                 OP1_1(TYPE_DBL, TYPE_DBL);
4253                                                 break;
4254
4255                                         case ICMD_I2L:
4256                                                 COUNT(count_pcmd_op);
4257                                                 OP1_1(TYPE_INT, TYPE_LNG);
4258                                                 break;
4259                                         case ICMD_I2F:
4260                                                 COUNT(count_pcmd_op);
4261                                                 OP1_1(TYPE_INT, TYPE_FLT);
4262                                                 break;
4263                                         case ICMD_I2D:
4264                                                 COUNT(count_pcmd_op);
4265                                                 OP1_1(TYPE_INT, TYPE_DBL);
4266                                                 break;
4267                                         case ICMD_L2I:
4268                                                 COUNT(count_pcmd_op);
4269                                                 OP1_1(TYPE_LNG, TYPE_INT);
4270                                                 break;
4271                                         case ICMD_L2F:
4272                                                 COUNT(count_pcmd_op);
4273                                                 OP1_1(TYPE_LNG, TYPE_FLT);
4274                                                 break;
4275                                         case ICMD_L2D:
4276                                                 COUNT(count_pcmd_op);
4277                                                 OP1_1(TYPE_LNG, TYPE_DBL);
4278                                                 break;
4279                                         case ICMD_F2I:
4280                                                 COUNT(count_pcmd_op);
4281                                                 OP1_1(TYPE_FLT, TYPE_INT);
4282                                                 break;
4283                                         case ICMD_F2L:
4284                                                 COUNT(count_pcmd_op);
4285                                                 OP1_1(TYPE_FLT, TYPE_LNG);
4286                                                 break;
4287                                         case ICMD_F2D:
4288                                                 COUNT(count_pcmd_op);
4289                                                 OP1_1(TYPE_FLT, TYPE_DBL);
4290                                                 break;
4291                                         case ICMD_D2I:
4292                                                 COUNT(count_pcmd_op);
4293                                                 OP1_1(TYPE_DBL, TYPE_INT);
4294                                                 break;
4295                                         case ICMD_D2L:
4296                                                 COUNT(count_pcmd_op);
4297                                                 OP1_1(TYPE_DBL, TYPE_LNG);
4298                                                 break;
4299                                         case ICMD_D2F:
4300                                                 COUNT(count_pcmd_op);
4301                                                 OP1_1(TYPE_DBL, TYPE_FLT);
4302                                                 break;
4303
4304                                         case ICMD_CHECKCAST:
4305                                                 coalescing_boundary = sd.new;
4306                                                 if (iptr->flags.bits & INS_FLAG_ARRAY) {
4307                                                         /* array type cast-check */
4308
4309                                                         bte = builtintable_get_internal(BUILTIN_arraycheckcast);
4310                                                         md = bte->md;
4311
4312                                                         if (md->memuse > rd->memuse)
4313                                                                 rd->memuse = md->memuse;
4314                                                         if (md->argintreguse > rd->argintreguse)
4315                                                                 rd->argintreguse = md->argintreguse;
4316
4317                                                         /* make all stack variables saved */
4318
4319                                                         copy = curstack;
4320                                                         while (copy) {
4321                                                                 sd.var[copy->varnum].flags |= SAVEDVAR;
4322                                                                 copy->flags |= SAVEDVAR;
4323                                                                 copy = copy->prev;
4324                                                         }
4325                                                 }
4326                                                 OP1_1(TYPE_ADR, TYPE_ADR);
4327                                                 break;
4328
4329                                         case ICMD_INSTANCEOF:
4330                                         case ICMD_ARRAYLENGTH:
4331                                                 coalescing_boundary = sd.new;
4332                                                 OP1_1(TYPE_ADR, TYPE_INT);
4333                                                 break;
4334
4335                                         case ICMD_NEWARRAY:
4336                                         case ICMD_ANEWARRAY:
4337                                                 coalescing_boundary = sd.new;
4338                                                 OP1_1(TYPE_INT, TYPE_ADR);
4339                                                 break;
4340
4341                                         case ICMD_GETFIELD:
4342                                                 coalescing_boundary = sd.new;
4343                                                 COUNT(count_check_null);
4344                                                 COUNT(count_pcmd_mem);
4345                                                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
4346                                                 OP1_1(TYPE_ADR, fmiref->parseddesc.fd->type);
4347                                                 break;
4348
4349                                                 /* pop 0 push 1 */
4350
4351                                         case ICMD_GETSTATIC:
4352                                                 coalescing_boundary = sd.new;
4353                                                 COUNT(count_pcmd_mem);
4354                                                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
4355                                                 OP0_1(fmiref->parseddesc.fd->type);
4356                                                 break;
4357
4358                                         case ICMD_NEW:
4359                                                 coalescing_boundary = sd.new;
4360                                                 OP0_1(TYPE_ADR);
4361                                                 break;
4362
4363                                         case ICMD_JSR:
4364                                                 OP0_1(TYPE_RET);
4365
4366                                                 tbptr = BLOCK_OF(iptr->sx.s23.s3.jsrtarget.insindex);
4367                                                 tbptr->type = BBTYPE_SBR;
4368
4369                                                 assert(sd.bptr->next);  /* XXX exception */
4370                                                 sd.var[curstack->varnum].vv.retaddr = sd.bptr->next;
4371 #if defined(ENABLE_VERIFIER)
4372                                                 sd.var[curstack->varnum].SBRSTART = (void*) tbptr;
4373 #endif
4374
4375                                                 tbptr = stack_mark_reached(&sd, tbptr, curstack, stackdepth);
4376                                                 if (!tbptr)
4377                                                         return false;
4378
4379                                                 iptr->sx.s23.s3.jsrtarget.block = tbptr;
4380
4381                                                 /* We need to check for overflow right here because
4382                                                  * the pushed value is poped afterwards */
4383                                                 CHECKOVERFLOW;
4384
4385                                                 superblockend = true;
4386                                                 /* XXX should not be marked as interface, as it does not need to be */
4387                                                 /* allocated. Same for the invar of the target. */
4388                                                 break;
4389
4390                                         /* pop many push any */
4391
4392                                         case ICMD_BUILTIN:
4393 icmd_BUILTIN:
4394                                                 bte = iptr->sx.s23.s3.bte;
4395                                                 md = bte->md;
4396                                                 goto _callhandling;
4397
4398                                         case ICMD_INVOKESTATIC:
4399                                         case ICMD_INVOKESPECIAL:
4400                                         case ICMD_INVOKEVIRTUAL:
4401                                         case ICMD_INVOKEINTERFACE:
4402                                                 COUNT(count_pcmd_met);
4403
4404                                                 /* Check for functions to replace with builtin
4405                                                  * functions. */
4406
4407                                                 if (builtintable_replace_function(iptr))
4408                                                         goto icmd_BUILTIN;
4409
4410                                                 INSTRUCTION_GET_METHODDESC(iptr, md);
4411                                                 /* XXX resurrect this COUNT? */
4412 /*                          if (lm->flags & ACC_STATIC) */
4413 /*                              {COUNT(count_check_null);} */
4414
4415                                         _callhandling:
4416
4417                                                 coalescing_boundary = sd.new;
4418
4419                                                 i = md->paramcount;
4420
4421                                                 if (md->memuse > rd->memuse)
4422                                                         rd->memuse = md->memuse;
4423                                                 if (md->argintreguse > rd->argintreguse)
4424                                                         rd->argintreguse = md->argintreguse;
4425                                                 if (md->argfltreguse > rd->argfltreguse)
4426                                                         rd->argfltreguse = md->argfltreguse;
4427
4428                                                 REQUIRE(i);
4429
4430                                                 iptr->s1.argcount = stackdepth;
4431                                                 iptr->sx.s23.s2.args = DMNEW(s4, stackdepth);
4432
4433                                                 copy = curstack;
4434                                                 for (i-- ; i >= 0; i--) {
4435                                                         iptr->sx.s23.s2.args[i] = copy->varnum;
4436
4437                                                         /* do not change STACKVARs or LOCALVARS to ARGVAR*/
4438                                                         /* ->  won't help anyway */
4439                                                         if (!(IS_INOUT(copy) || IS_LOCALVAR(copy))) {
4440
4441 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
4442                         /* If we pass float arguments in integer argument registers, we
4443                          * are not allowed to precolor them here. Floats have to be moved
4444                          * to this regs explicitly in codegen().
4445                          * Only arguments that are passed by stack anyway can be precolored
4446                          * (michi 2005/07/24) */
4447                                                         if (!(sd.var[copy->varnum].flags & SAVEDVAR) &&
4448                                                            (!IS_FLT_DBL_TYPE(copy->type) 
4449                                                                 || md->params[i].inmemory)) {
4450 #else
4451                                                         if (!(sd.var[copy->varnum].flags & SAVEDVAR)) {
4452 #endif
4453
4454                                                                 SET_PREALLOC(copy);
4455
4456                                                                 if (md->params[i].inmemory) {
4457                                                                         sd.var[copy->varnum].vv.regoff =
4458                                                                                 md->params[i].regoff;
4459                                                                         sd.var[copy->varnum].flags |= 
4460                                                                                 INMEMORY;
4461                                                                 }
4462                                                                 else {
4463                                                                         if (IS_FLT_DBL_TYPE(copy->type)) {
4464 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
4465                                                                                 assert(0); /* XXX is this assert ok? */
4466 #else
4467                                                                                 sd.var[copy->varnum].vv.regoff = 
4468                                                                         rd->argfltregs[md->params[i].regoff];
4469 #endif /* SUPPORT_PASS_FLOATARGS_IN_INTREGS */
4470                                                                         }
4471                                                                         else {
4472 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
4473                                                                                 if (IS_2_WORD_TYPE(copy->type))
4474                                                                                         sd.var[copy->varnum].vv.regoff = 
4475                         PACK_REGS( rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
4476                                            rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
4477
4478                                                                                 else
4479 #endif /* SUPPORT_COMBINE_INTEGER_REGISTERS */
4480                                                                                         sd.var[copy->varnum].vv.regoff = 
4481                                                                         rd->argintregs[md->params[i].regoff];
4482                                                                         }
4483                                                                 }
4484                                                         }
4485                                                         }
4486                                                         copy = copy->prev;
4487                                                 }
4488
4489                                                 /* deal with live-through stack slots "under" the */
4490                                                 /* arguments */
4491
4492                                                 i = md->paramcount;
4493
4494                                                 while (copy) {
4495                                                         iptr->sx.s23.s2.args[i++] = copy->varnum;
4496                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
4497                                                         copy->flags |= SAVEDVAR | PASSTHROUGH;
4498                                                         copy = copy->prev;
4499                                                 }
4500
4501                                                 /* pop the arguments */
4502
4503                                                 i = md->paramcount;
4504
4505                                                 stackdepth -= i;
4506                                                 while (--i >= 0) {
4507                                                         POPANY;
4508                                                 }
4509
4510                                                 /* push the return value */
4511
4512                                                 if (md->returntype.type != TYPE_VOID) {
4513                                                         GET_NEW_VAR(sd, new_index, md->returntype.type);
4514                                                         DST(md->returntype.type, new_index);
4515                                                         stackdepth++;
4516                                                 }
4517                                                 break;
4518
4519                                         case ICMD_MULTIANEWARRAY:
4520                                                 coalescing_boundary = sd.new;
4521                                                 if (rd->argintreguse < MIN(3, INT_ARG_CNT))
4522                                                         rd->argintreguse = MIN(3, INT_ARG_CNT);
4523
4524                                                 i = iptr->s1.argcount;
4525
4526                                                 REQUIRE(i);
4527
4528                                                 iptr->sx.s23.s2.args = DMNEW(s4, i);
4529
4530 #if defined(SPECIALMEMUSE)
4531 # if defined(__DARWIN__)
4532                                                 if (rd->memuse < (i + INT_ARG_CNT +LA_SIZE_IN_POINTERS))
4533                                                         rd->memuse = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
4534 # else
4535                                                 if (rd->memuse < (i + LA_SIZE_IN_POINTERS + 3))
4536                                                         rd->memuse = i + LA_SIZE_IN_POINTERS + 3;
4537 # endif
4538 #else
4539 # if defined(__I386__)
4540                                                 if (rd->memuse < i + 3)
4541                                                         rd->memuse = i + 3; /* n integer args spilled on stack */
4542 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
4543                                                 if (rd->memuse < i + 2)
4544                                                         rd->memuse = i + 2; /* 4*4 bytes callee save space */
4545 # else
4546                                                 if (rd->memuse < i)
4547                                                         rd->memuse = i; /* n integer args spilled on stack */
4548 # endif /* defined(__I386__) */
4549 #endif
4550                                                 copy = curstack;
4551                                                 while (--i >= 0) {
4552                                         /* check INT type here? Currently typecheck does this. */
4553                                                         iptr->sx.s23.s2.args[i] = copy->varnum;
4554                                                         if (!(sd.var[copy->varnum].flags & SAVEDVAR)
4555                                                                 && (!IS_INOUT(copy))
4556                                                                 && (!IS_LOCALVAR(copy)) ) {
4557                                                                 copy->varkind = ARGVAR;
4558                                                                 sd.var[copy->varnum].flags |=
4559                                                                         INMEMORY & PREALLOC;
4560 #if defined(SPECIALMEMUSE)
4561 # if defined(__DARWIN__)
4562                                                                 sd.var[copy->varnum].vv.regoff = i + 
4563                                                                         LA_SIZE_IN_POINTERS + INT_ARG_CNT;
4564 # else
4565                                                                 sd.var[copy->varnum].vv.regoff = i + 
4566                                                                         LA_SIZE_IN_POINTERS + 3;
4567 # endif
4568 #else
4569 # if defined(__I386__)
4570                                                                 sd.var[copy->varnum].vv.regoff = i + 3;
4571 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
4572                                                                 sd.var[copy->varnum].vv.regoff = i + 2;
4573 # else
4574                                                                 sd.var[copy->varnum].vv.regoff = i;
4575 # endif /* defined(__I386__) */
4576 #endif /* defined(SPECIALMEMUSE) */
4577                                                         }
4578                                                         copy = copy->prev;
4579                                                 }
4580                                                 while (copy) {
4581                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
4582                                                         copy->flags |= SAVEDVAR;
4583                                                         copy = copy->prev;
4584                                                 }
4585
4586                                                 i = iptr->s1.argcount;
4587                                                 stackdepth -= i;
4588                                                 while (--i >= 0) {
4589                                                         POPANY;
4590                                                 }
4591                                                 GET_NEW_VAR(sd, new_index, TYPE_ADR);
4592                                                 DST(TYPE_ADR, new_index);
4593                                                 stackdepth++;
4594                                                 break;
4595
4596                                         default:
4597                                                 *exceptionptr =
4598                                                         new_internalerror("Unknown ICMD %d", opcode);
4599                                                 return false;
4600                                         } /* switch */
4601
4602                                         CHECKOVERFLOW;
4603                                         iptr++;
4604                                 } /* while instructions */
4605
4606                                 /* show state after last instruction */
4607
4608 #if defined(STACK_VERBOSE)
4609                                 stack_verbose_show_state(&sd, NULL, curstack);
4610 #endif
4611
4612                                 /* stack slots at basic block end become interfaces */
4613
4614                                 sd.bptr->outdepth = stackdepth;
4615                                 sd.bptr->outvars = DMNEW(s4, stackdepth);
4616
4617                                 i = stackdepth - 1;
4618                                 for (copy = curstack; copy; i--, copy = copy->prev) {
4619                                         varinfo *v;
4620                                         s4 t;
4621
4622                                         /* with the new vars rd->interfaces will be removed */
4623                                         /* and all in and outvars have to be STACKVARS!     */
4624                                         /* in the moment i.e. SWAP with in and out vars can */
4625                                         /* create an unresolvable conflict */
4626
4627                                         SET_TEMPVAR(copy);
4628                                         t = copy->type;
4629
4630                                         v = sd.var + copy->varnum;
4631                                         v->flags |= INOUT;
4632
4633                                         /* do not allocate variables for returnAddresses */
4634
4635                                         if (t != TYPE_RET) {
4636                                                 if (jd->interface_map[i*5 + t].flags == UNUSED) {
4637                                                         /* no interface var until now for this depth and */
4638                                                         /* type */
4639                                                         jd->interface_map[i*5 + t].flags = v->flags;
4640                                                 }
4641                                                 else {
4642                                                         jd->interface_map[i*5 + t].flags |= v->flags;
4643                                                 }
4644                                         }
4645
4646                                         sd.bptr->outvars[i] = copy->varnum;
4647                                 }
4648
4649                                 /* check if interface slots at basic block begin must be saved */
4650
4651                                 for (i=0; i<sd.bptr->indepth; ++i) {
4652                                         varinfo *v = sd.var + sd.bptr->invars[i];
4653                                         s4 t;
4654
4655                                         t = v->type;
4656
4657                                         if (t != TYPE_RET) {
4658                                                 if (jd->interface_map[i*5 + t].flags == UNUSED) {
4659                                                         /* no interface var until now for this depth and */
4660                                                         /* type */
4661                                                         jd->interface_map[i*5 + t].flags = v->flags;
4662                                                 }
4663                                                 else {
4664                                                         jd->interface_map[i*5 + t].flags |= v->flags;
4665                                                 }
4666                                         }
4667                                 }
4668
4669                                 /* store the number of this block's variables */
4670
4671                                 sd.bptr->varcount = sd.vartop - sd.bptr->varstart;
4672
4673 #if defined(STACK_VERBOSE)
4674                                 stack_verbose_block_exit(&sd, superblockend);
4675 #endif
4676
4677                                 /* reach the following block, if any */
4678
4679                                 if (!superblockend)
4680                                         if (!stack_reach_next_block(&sd))
4681                                                 return false;
4682
4683                 } /* for blocks */
4684
4685         } while (sd.repeat && !deadcode);
4686
4687         /* reset locals of TYPE_RET to TYPE_ADR */
4688
4689         for (i=0; i<sd.localcount; ++i) {
4690                 if (sd.var[i].type == TYPE_RET)
4691                         sd.var[i].type = TYPE_ADR;
4692         }
4693
4694         /* mark temporaries of TYPE_RET as PREALLOC to avoid allocation */
4695
4696         for (i=sd.localcount; i<sd.vartop; ++i) {
4697                 if (sd.var[i].type == TYPE_RET)
4698                         sd.var[i].flags |= PREALLOC;
4699         }
4700
4701         /* XXX hack to fix up the ranges of the cloned single-block handlers */
4702
4703         ex = jd->exceptiontable;
4704         for (; ex != NULL; ex = ex->down) {
4705                 if (ex->start == ex->end) {
4706                         assert(ex->end->next);
4707                         ex->end = ex->end->next;
4708                 }
4709         }
4710
4711         /* store number of created variables */
4712
4713         jd->vartop = sd.vartop;
4714
4715         /* gather statistics *****************************************************/
4716
4717 #if defined(ENABLE_STATISTICS)
4718         if (opt_stat) {
4719                 if (jd->basicblockcount > count_max_basic_blocks)
4720                         count_max_basic_blocks = jd->basicblockcount;
4721                 count_basic_blocks += jd->basicblockcount;
4722                 if (jd->instructioncount > count_max_javainstr)
4723                         count_max_javainstr = jd->instructioncount;
4724                 count_javainstr += jd->instructioncount;
4725                 if (jd->stackcount > count_upper_bound_new_stack)
4726                         count_upper_bound_new_stack = jd->stackcount;
4727                 if ((sd.new - jd->stack) > count_max_new_stack)
4728                         count_max_new_stack = (sd.new - jd->stack);
4729
4730                 sd.bptr = jd->basicblocks;
4731                 for (; sd.bptr; sd.bptr = sd.bptr->next) {
4732                         if (sd.bptr->flags > BBREACHED) {
4733                                 if (sd.bptr->indepth >= 10)
4734                                         count_block_stack[10]++;
4735                                 else
4736                                         count_block_stack[sd.bptr->indepth]++;
4737                                 len = sd.bptr->icount;
4738                                 if (len < 10)
4739                                         count_block_size_distribution[len]++;
4740                                 else if (len <= 12)
4741                                         count_block_size_distribution[10]++;
4742                                 else if (len <= 14)
4743                                         count_block_size_distribution[11]++;
4744                                 else if (len <= 16)
4745                                         count_block_size_distribution[12]++;
4746                                 else if (len <= 18)
4747                                         count_block_size_distribution[13]++;
4748                                 else if (len <= 20)
4749                                         count_block_size_distribution[14]++;
4750                                 else if (len <= 25)
4751                                         count_block_size_distribution[15]++;
4752                                 else if (len <= 30)
4753                                         count_block_size_distribution[16]++;
4754                                 else
4755                                         count_block_size_distribution[17]++;
4756                         }
4757                 }
4758
4759                 if (iteration_count == 1)
4760                         count_analyse_iterations[0]++;
4761                 else if (iteration_count == 2)
4762                         count_analyse_iterations[1]++;
4763                 else if (iteration_count == 3)
4764                         count_analyse_iterations[2]++;
4765                 else if (iteration_count == 4)
4766                         count_analyse_iterations[3]++;
4767                 else
4768                         count_analyse_iterations[4]++;
4769
4770                 if (jd->basicblockcount <= 5)
4771                         count_method_bb_distribution[0]++;
4772                 else if (jd->basicblockcount <= 10)
4773                         count_method_bb_distribution[1]++;
4774                 else if (jd->basicblockcount <= 15)
4775                         count_method_bb_distribution[2]++;
4776                 else if (jd->basicblockcount <= 20)
4777                         count_method_bb_distribution[3]++;
4778                 else if (jd->basicblockcount <= 30)
4779                         count_method_bb_distribution[4]++;
4780                 else if (jd->basicblockcount <= 40)
4781                         count_method_bb_distribution[5]++;
4782                 else if (jd->basicblockcount <= 50)
4783                         count_method_bb_distribution[6]++;
4784                 else if (jd->basicblockcount <= 75)
4785                         count_method_bb_distribution[7]++;
4786                 else
4787                         count_method_bb_distribution[8]++;
4788         }
4789 #endif /* defined(ENABLE_STATISTICS) */
4790
4791         /* everything's ok *******************************************************/
4792
4793         return true;
4794
4795         /* goto labels for throwing verifier exceptions **************************/
4796
4797 #if defined(ENABLE_VERIFIER)
4798
4799 throw_stack_underflow:
4800         exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
4801         return false;
4802
4803 throw_stack_overflow:
4804         exceptions_throw_verifyerror(m, "Stack size too large");
4805         return false;
4806
4807 throw_stack_type_error:
4808         exceptions_throw_verifyerror_for_stack(m, expectedtype);
4809         return false;
4810
4811 throw_stack_category_error:
4812         exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
4813         return false;
4814
4815 #endif
4816 }
4817
4818
4819 /* stack_javalocals_store ******************************************************
4820  
4821    Model the effect of a ?STORE instruction upon the given javalocals array.
4822   
4823    IN:
4824        iptr.............the ?STORE instruction
4825            javalocals.......the javalocals array to modify
4826   
4827 *******************************************************************************/
4828
4829 void stack_javalocals_store(instruction *iptr, s4 *javalocals)
4830 {
4831         s4 idx;  /* index into the jd->var array */
4832         s4 j;    /* java local index             */
4833
4834         idx = iptr->dst.varindex;
4835         j = iptr->sx.s23.s3.javaindex;
4836
4837         if (j != UNUSED) {
4838                 if (iptr->flags.bits & INS_FLAG_RETADDR)
4839                         javalocals[j] = iptr->sx.s23.s2.retaddrnr;
4840                 else
4841                         javalocals[j] = idx;
4842
4843                 if (iptr->flags.bits & INS_FLAG_KILL_PREV)
4844                         javalocals[j-1] = UNUSED;
4845
4846                 if (iptr->flags.bits & INS_FLAG_KILL_NEXT)
4847                         javalocals[j+1] = UNUSED;
4848         }
4849 }
4850
4851
4852 /* functions for verbose stack analysis output ********************************/
4853
4854 #if defined(STACK_VERBOSE)
4855 static void stack_verbose_show_varinfo(stackdata_t *sd, varinfo *v)
4856 {
4857         printf("%c", show_jit_type_letters[v->type]);
4858         if (v->type == TYPE_RET)
4859                 printf("{L%03d}", v->vv.retaddr->nr);
4860 }
4861
4862
4863 static void stack_verbose_show_variable(stackdata_t *sd, s4 index)
4864 {
4865         assert(index >= 0 && index < sd->vartop);
4866         stack_verbose_show_varinfo(sd, sd->var + index);
4867 }
4868
4869
4870 static void stack_verbose_show_block(stackdata_t *sd, basicblock *bptr)
4871 {
4872         s4 i;
4873
4874         printf("L%03d type:%d in:%d [", bptr->nr, bptr->type, bptr->indepth);
4875         if (bptr->invars) {
4876                 for (i=0; i<bptr->indepth; ++i) {
4877                         if (i)
4878                                 putchar(' ');
4879                         stack_verbose_show_variable(sd, bptr->invars[i]);
4880                 }
4881         }
4882         else
4883                 putchar('-');
4884         printf("] javalocals ");
4885         show_javalocals_array(sd->jd, sd->javalocals, sd->maxlocals, SHOW_STACK);
4886         printf(" inlocals [");
4887         if (bptr->inlocals) {
4888                 for (i=0; i<sd->localcount; ++i) {
4889                         if (i)
4890                                 putchar(' ');
4891                         stack_verbose_show_varinfo(sd, bptr->inlocals + i);
4892                 }
4893         }
4894         else
4895                 putchar('-');
4896         printf("] out:%d [", bptr->outdepth);
4897         if (bptr->outvars) {
4898                 for (i=0; i<bptr->outdepth; ++i) {
4899                         if (i)
4900                                 putchar(' ');
4901                         stack_verbose_show_variable(sd, bptr->outvars[i]);
4902                 }
4903         }
4904         else
4905                 putchar('-');
4906         printf("]");
4907
4908         if (bptr->original)
4909                 printf(" (clone of L%03d)", bptr->original->nr);
4910         else {
4911                 basicblock *b = bptr->copied_to;
4912                 if (b) {
4913                         printf(" (copied to ");
4914                         for (; b; b = b->copied_to)
4915                                 printf("L%03d ", b->nr);
4916                         printf(")");
4917                 }
4918         }
4919 }
4920
4921
4922 static void stack_verbose_block_enter(stackdata_t *sd, bool reanalyse)
4923 {
4924         int i;
4925
4926         printf("======================================== STACK %sANALYSE BLOCK ", 
4927                         (reanalyse) ? ((sd->bptr->iinstr == NULL) ? "CLONE-" : "RE-") : "");
4928         stack_verbose_show_block(sd, sd->bptr);
4929         printf("\n");
4930
4931         if (sd->handlers[0]) {
4932                 printf("HANDLERS: ");
4933                 for (i=0; sd->handlers[i]; ++i) {
4934                         printf("L%03d ", sd->handlers[i]->handler->nr);
4935                 }
4936                 printf("\n");
4937         }
4938         printf("\n");
4939 }
4940
4941
4942 static void stack_verbose_block_exit(stackdata_t *sd, bool superblockend)
4943 {
4944         printf("%s ", (superblockend) ? "SUPERBLOCKEND" : "END");
4945         stack_verbose_show_block(sd, sd->bptr);
4946         printf("\n");
4947 }
4948
4949 static void stack_verbose_show_state(stackdata_t *sd, instruction *iptr, stackptr curstack)
4950 {
4951         stackptr sp;
4952         s4       i;
4953         s4       depth;
4954         varinfo *v;
4955         stackptr *stack;
4956
4957         printf("    javalocals ");
4958         show_javalocals_array(sd->jd, sd->javalocals, sd->maxlocals, SHOW_STACK);
4959         printf(" stack [");
4960
4961         for(i = 0, sp = curstack; sp; sp = sp->prev)
4962                 i++;
4963         depth = i;
4964
4965         stack = MNEW(stackptr, depth);
4966         for(sp = curstack; sp; sp = sp->prev)
4967                 stack[--i] = sp;
4968
4969         for(i=0; i<depth; ++i) {
4970                 if (i)
4971                         putchar(' ');
4972                 sp = stack[i];
4973                 v = &(sd->var[sp->varnum]);
4974
4975                 if (v->flags & INOUT)
4976                         putchar('I');
4977                 if (v->flags & PREALLOC)
4978                         putchar('A');
4979                 printf("%d:%c", sp->varnum, show_jit_type_letters[sp->type]);
4980                 if (v->type == TYPE_RET) {
4981                         printf("(L%03d)", v->vv.retaddr->nr);
4982                 }
4983         }
4984         printf("] ... ");
4985         if (iptr)
4986                 show_icmd(sd->jd, iptr, false, SHOW_PARSE); 
4987         printf("\n");
4988 }
4989 #endif
4990
4991
4992 /*
4993  * These are local overrides for various environment variables in Emacs.
4994  * Please do not remove this and leave it at the end of the file, where
4995  * Emacs will automagically detect them.
4996  * ---------------------------------------------------------------------
4997  * Local variables:
4998  * mode: c
4999  * indent-tabs-mode: t
5000  * c-basic-offset: 4
5001  * tab-width: 4
5002  * End:
5003  * vim:noexpandtab:sw=4:ts=4:
5004  */