* src/vm/jit/stack.c (stack_reanalyse_block): Removed bogus cases
[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 6055 2006-11-27 14:39:58Z 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                 b->iinstr = iptr;
1341                 b->icount = ++len;
1342
1343                 /* reserve space for the clone's block variables */
1344
1345                 stack_grow_variable_array(sd, orig->varcount);
1346
1347                 /* we already have the invars set */
1348
1349                 assert(b->indepth == orig->indepth);
1350
1351                 /* calculate relocation shifts for invars and block variables */
1352
1353                 if (orig->indepth) {
1354                         invarstart = orig->invars[0];
1355                         invarshift = b->invars[0] - invarstart;
1356                 }
1357                 else {
1358                         invarstart = INT_MAX;
1359                         invarshift = 0;
1360                 }
1361                 blockvarstart = orig->varstart;
1362                 blockvarshift = sd->vartop - blockvarstart;
1363
1364                 /* copy block variables */
1365
1366                 b->varstart = sd->vartop;
1367                 b->varcount = orig->varcount;
1368                 sd->vartop += b->varcount;
1369                 MCOPY(sd->var + b->varstart, sd->var + orig->varstart, varinfo, b->varcount);
1370
1371                 /* copy outvars */
1372
1373                 b->outdepth = orig->outdepth;
1374                 b->outvars = DMNEW(s4, orig->outdepth);
1375                 MCOPY(b->outvars, orig->outvars, s4, orig->outdepth);
1376
1377                 /* clone exception handlers */
1378
1379                 for (i=0; sd->handlers[i]; ++i) {
1380                         ex = DNEW(exception_entry);
1381                         ex->handler = sd->handlers[i]->handler;
1382                         ex->start = b;
1383                         ex->end = b; /* XXX hack, see end of stack_analyse */
1384                         ex->catchtype = sd->handlers[i]->catchtype;
1385                         ex->down = NULL;
1386
1387                         assert(sd->extableend->down == NULL);
1388                         sd->extableend->down = ex;
1389                         sd->extableend = ex;
1390                         sd->jd->exceptiontablelength++;
1391
1392                         sd->handlers[i] = ex;
1393                 }
1394         }
1395         else {
1396                 cloneinstructions = false;
1397                 invarshift = 0;
1398                 blockvarshift = 0;
1399                 invarstart = sd->vartop;
1400                 blockvarstart = sd->vartop;
1401                 iptr = b->iinstr;
1402         }
1403
1404         if (b->original) {
1405                 /* find exception handlers for the cloned block */
1406                 len = 0;
1407                 ex = sd->jd->exceptiontable;
1408                 for (; ex != NULL; ex = ex->down) {
1409                         /* XXX the cloned exception handlers have identical */
1410                         /* start end end blocks.                            */
1411                         if ((ex->start == b) && (ex->end == b)) {
1412                                 sd->handlers[len++] = ex;
1413                         }
1414                 }
1415                 sd->handlers[len] = NULL;
1416         }
1417
1418 #if defined(STACK_VERBOSE)
1419         printf("invarstart = %d, blockvarstart = %d\n", invarstart, blockvarstart);
1420         printf("invarshift = %d, blockvarshift = %d\n", invarshift, blockvarshift);
1421 #endif
1422
1423         /* mark block as finished */
1424
1425         b->flags = BBFINISHED;
1426
1427         /* initialize locals at the start of this block */
1428
1429         if (b->inlocals)
1430                 MCOPY(sd->var, b->inlocals, varinfo, sd->localcount);
1431
1432         MCOPY(sd->javalocals, b->javalocals, s4, sd->maxlocals);
1433
1434         /* reach exception handlers for this block */
1435
1436         if (!stack_reach_handlers(sd))
1437                 return false;
1438
1439         superblockend = false;
1440
1441         for (len = b->icount; len--; iptr++) {
1442 #if defined(STACK_VERBOSE)
1443                 show_icmd(sd->jd, iptr, false, SHOW_STACK);
1444                 printf("\n");
1445 #endif
1446
1447                 switch (iptr->opc) {
1448                         case ICMD_RET:
1449                                 j = iptr->s1.varindex;
1450
1451 #if defined(ENABLE_VERIFIER)
1452                                 if (sd->var[j].type != TYPE_RET) {
1453                                         exceptions_throw_verifyerror(sd->m, "RET with non-returnAddress value");
1454                                         return false;
1455                                 }
1456 #endif
1457
1458                                 iptr->dst.block = stack_mark_reached_from_outvars(sd, sd->var[j].vv.retaddr);
1459                                 superblockend = true;
1460                                 break;
1461
1462                         case ICMD_JSR:
1463                                 iptr->sx.s23.s3.jsrtarget.block = stack_mark_reached_from_outvars(sd, iptr->sx.s23.s3.jsrtarget.block);
1464                                 RELOCATE(iptr->dst.varindex);
1465                                 superblockend = true;
1466                                 break;
1467
1468                         case ICMD_RETURN:
1469                                 superblockend = true;
1470                                 break;
1471
1472                         case ICMD_CHECKNULL:
1473                         case ICMD_PUTSTATICCONST:
1474                                 break;
1475
1476                         case ICMD_NOP:
1477                         case ICMD_IINC:
1478                                 break;
1479
1480                         case ICMD_GOTO:
1481                                 iptr->dst.block = stack_mark_reached_from_outvars(sd, iptr->dst.block);
1482                                 superblockend = true;
1483                                 break;
1484
1485                                 /* pop 0 push 1 const */
1486
1487                         case ICMD_ACONST:
1488                         case ICMD_ICONST:
1489                         case ICMD_LCONST:
1490                         case ICMD_FCONST:
1491                         case ICMD_DCONST:
1492
1493                                 /* pop 0 push 1 load */
1494
1495                         case ICMD_ILOAD:
1496                         case ICMD_LLOAD:
1497                         case ICMD_FLOAD:
1498                         case ICMD_DLOAD:
1499                         case ICMD_ALOAD:
1500                                 RELOCATE(iptr->dst.varindex);
1501                                 break;
1502
1503                                 /* pop 2 push 1 */
1504
1505                         case ICMD_IALOAD:
1506                         case ICMD_LALOAD:
1507                         case ICMD_FALOAD:
1508                         case ICMD_DALOAD:
1509                         case ICMD_AALOAD:
1510                         case ICMD_BALOAD:
1511                         case ICMD_CALOAD:
1512                         case ICMD_SALOAD:
1513                                 RELOCATE(iptr->sx.s23.s2.varindex);
1514                                 RELOCATE(iptr->s1.varindex);
1515                                 RELOCATE(iptr->dst.varindex);
1516                                 break;
1517
1518                                 /* pop 3 push 0 */
1519
1520                         case ICMD_IASTORE:
1521                         case ICMD_LASTORE:
1522                         case ICMD_FASTORE:
1523                         case ICMD_DASTORE:
1524                         case ICMD_AASTORE:
1525                         case ICMD_BASTORE:
1526                         case ICMD_CASTORE:
1527                         case ICMD_SASTORE:
1528                                 RELOCATE(iptr->sx.s23.s3.varindex);
1529                                 RELOCATE(iptr->sx.s23.s2.varindex);
1530                                 RELOCATE(iptr->s1.varindex);
1531                                 break;
1532
1533                                 /* pop 1 push 0 store */
1534
1535                         case ICMD_ISTORE:
1536                         case ICMD_LSTORE:
1537                         case ICMD_FSTORE:
1538                         case ICMD_DSTORE:
1539                         case ICMD_ASTORE:
1540                                 RELOCATE(iptr->s1.varindex);
1541
1542                                 j = iptr->dst.varindex;
1543                                 COPY_VAL_AND_TYPE(*sd, iptr->s1.varindex, j);
1544                                 i = iptr->sx.s23.s3.javaindex;
1545                                 if (iptr->flags.bits & INS_FLAG_RETADDR) {
1546                                         iptr->sx.s23.s2.retaddrnr =
1547                                                 UNUSED - (1 + sd->var[j].vv.retaddr->nr);
1548                                         sd->javalocals[i] = iptr->sx.s23.s2.retaddrnr;
1549                                 }
1550                                 else
1551                                         sd->javalocals[i] = j;
1552                                 if (iptr->flags.bits & INS_FLAG_KILL_PREV)
1553                                         sd->javalocals[i-1] = UNUSED;
1554                                 if (iptr->flags.bits & INS_FLAG_KILL_NEXT)
1555                                         sd->javalocals[i+1] = UNUSED;
1556                                 break;
1557
1558                                 /* pop 1 push 0 */
1559
1560                         case ICMD_ARETURN:
1561                         case ICMD_ATHROW:
1562                         case ICMD_IRETURN:
1563                         case ICMD_LRETURN:
1564                         case ICMD_FRETURN:
1565                         case ICMD_DRETURN:
1566                                 RELOCATE(iptr->s1.varindex);
1567                                 superblockend = true;
1568                                 break;
1569
1570                         case ICMD_PUTSTATIC:
1571                         case ICMD_PUTFIELDCONST:
1572                         case ICMD_POP:
1573                                 RELOCATE(iptr->s1.varindex);
1574                                 break;
1575
1576                                 /* pop 1 push 0 branch */
1577
1578                         case ICMD_IFNULL:
1579                         case ICMD_IFNONNULL:
1580
1581                         case ICMD_IFEQ:
1582                         case ICMD_IFNE:
1583                         case ICMD_IFLT:
1584                         case ICMD_IFGE:
1585                         case ICMD_IFGT:
1586                         case ICMD_IFLE:
1587
1588                         case ICMD_IF_LEQ:
1589                         case ICMD_IF_LNE:
1590                         case ICMD_IF_LLT:
1591                         case ICMD_IF_LGE:
1592                         case ICMD_IF_LGT:
1593                         case ICMD_IF_LLE:
1594                                 RELOCATE(iptr->s1.varindex);
1595                                 iptr->dst.block = stack_mark_reached_from_outvars(sd, iptr->dst.block);
1596                                 break;
1597
1598                                 /* pop 1 push 0 table branch */
1599
1600                         case ICMD_TABLESWITCH:
1601                                 i = iptr->sx.s23.s3.tablehigh - iptr->sx.s23.s2.tablelow + 1 + 1;
1602
1603                                 if (cloneinstructions) {
1604                                         table = DMNEW(branch_target_t, i);
1605                                         MCOPY(table, iptr->dst.table, branch_target_t, i);
1606                                         iptr->dst.table = table;
1607                                 }
1608                                 else {
1609                                         table = iptr->dst.table;
1610                                 }
1611
1612                                 RELOCATE(iptr->s1.varindex);
1613                                 while (i--) {
1614                                         table->block = stack_mark_reached_from_outvars(sd, table->block);
1615                                         table++;
1616                                 }
1617                                 superblockend = true;
1618                                 break;
1619
1620                         case ICMD_LOOKUPSWITCH:
1621                                 i = iptr->sx.s23.s2.lookupcount;
1622                                 if (cloneinstructions) {
1623                                         lookup = DMNEW(lookup_target_t, i);
1624                                         MCOPY(lookup, iptr->dst.lookup, lookup_target_t, i);
1625                                         iptr->dst.lookup = lookup;
1626                                 }
1627                                 else {
1628                                         lookup = iptr->dst.lookup;
1629                                 }
1630                                 RELOCATE(iptr->s1.varindex);
1631                                 while (i--) {
1632                                         lookup->target.block = stack_mark_reached_from_outvars(sd, lookup->target.block);
1633                                         lookup++;
1634                                 }
1635                                 iptr->sx.s23.s3.lookupdefault.block = stack_mark_reached_from_outvars(sd, iptr->sx.s23.s3.lookupdefault.block);
1636                                 superblockend = true;
1637                                 break;
1638
1639                         case ICMD_MONITORENTER:
1640                         case ICMD_MONITOREXIT:
1641                                 RELOCATE(iptr->s1.varindex);
1642                                 break;
1643
1644                                 /* pop 2 push 0 branch */
1645
1646                         case ICMD_IF_ICMPEQ:
1647                         case ICMD_IF_ICMPNE:
1648                         case ICMD_IF_ICMPLT:
1649                         case ICMD_IF_ICMPGE:
1650                         case ICMD_IF_ICMPGT:
1651                         case ICMD_IF_ICMPLE:
1652
1653                         case ICMD_IF_LCMPEQ:
1654                         case ICMD_IF_LCMPNE:
1655                         case ICMD_IF_LCMPLT:
1656                         case ICMD_IF_LCMPGE:
1657                         case ICMD_IF_LCMPGT:
1658                         case ICMD_IF_LCMPLE:
1659
1660                         case ICMD_IF_FCMPEQ:
1661                         case ICMD_IF_FCMPNE:
1662
1663                         case ICMD_IF_FCMPL_LT:
1664                         case ICMD_IF_FCMPL_GE:
1665                         case ICMD_IF_FCMPL_GT:
1666                         case ICMD_IF_FCMPL_LE:
1667
1668                         case ICMD_IF_FCMPG_LT:
1669                         case ICMD_IF_FCMPG_GE:
1670                         case ICMD_IF_FCMPG_GT:
1671                         case ICMD_IF_FCMPG_LE:
1672
1673                         case ICMD_IF_DCMPEQ:
1674                         case ICMD_IF_DCMPNE:
1675
1676                         case ICMD_IF_DCMPL_LT:
1677                         case ICMD_IF_DCMPL_GE:
1678                         case ICMD_IF_DCMPL_GT:
1679                         case ICMD_IF_DCMPL_LE:
1680
1681                         case ICMD_IF_DCMPG_LT:
1682                         case ICMD_IF_DCMPG_GE:
1683                         case ICMD_IF_DCMPG_GT:
1684                         case ICMD_IF_DCMPG_LE:
1685
1686                         case ICMD_IF_ACMPEQ:
1687                         case ICMD_IF_ACMPNE:
1688                                 RELOCATE(iptr->sx.s23.s2.varindex);
1689                                 RELOCATE(iptr->s1.varindex);
1690                                 iptr->dst.block = stack_mark_reached_from_outvars(sd, iptr->dst.block);
1691                                 break;
1692
1693                                 /* pop 2 push 0 */
1694
1695                         case ICMD_PUTFIELD:
1696                         case ICMD_IASTORECONST:
1697                         case ICMD_LASTORECONST:
1698                         case ICMD_AASTORECONST:
1699                         case ICMD_BASTORECONST:
1700                         case ICMD_CASTORECONST:
1701                         case ICMD_SASTORECONST:
1702                         case ICMD_POP2:
1703                                 RELOCATE(iptr->sx.s23.s2.varindex);
1704                                 RELOCATE(iptr->s1.varindex);
1705                                 break;
1706
1707                                 /* pop 0 push 1 copy */
1708
1709                         case ICMD_COPY:
1710                         case ICMD_MOVE:
1711                                 RELOCATE(iptr->dst.varindex);
1712                                 RELOCATE(iptr->s1.varindex);
1713                                 COPY_VAL_AND_TYPE(*sd, iptr->s1.varindex, iptr->dst.varindex);
1714                                 break;
1715
1716                                 /* pop 2 push 1 */
1717
1718                         case ICMD_IDIV:
1719                         case ICMD_IREM:
1720                         case ICMD_LDIV:
1721                         case ICMD_LREM:
1722                         case ICMD_IADD:
1723                         case ICMD_ISUB:
1724                         case ICMD_IMUL:
1725                         case ICMD_ISHL:
1726                         case ICMD_ISHR:
1727                         case ICMD_IUSHR:
1728                         case ICMD_IAND:
1729                         case ICMD_IOR:
1730                         case ICMD_IXOR:
1731                         case ICMD_LADD:
1732                         case ICMD_LSUB:
1733                         case ICMD_LMUL:
1734                         case ICMD_LOR:
1735                         case ICMD_LAND:
1736                         case ICMD_LXOR:
1737                         case ICMD_LSHL:
1738                         case ICMD_LSHR:
1739                         case ICMD_LUSHR:
1740                         case ICMD_FADD:
1741                         case ICMD_FSUB:
1742                         case ICMD_FMUL:
1743                         case ICMD_FDIV:
1744                         case ICMD_FREM:
1745                         case ICMD_DADD:
1746                         case ICMD_DSUB:
1747                         case ICMD_DMUL:
1748                         case ICMD_DDIV:
1749                         case ICMD_DREM:
1750                         case ICMD_LCMP:
1751                         case ICMD_FCMPL:
1752                         case ICMD_FCMPG:
1753                         case ICMD_DCMPL:
1754                         case ICMD_DCMPG:
1755                                 RELOCATE(iptr->sx.s23.s2.varindex);
1756                                 RELOCATE(iptr->s1.varindex);
1757                                 RELOCATE(iptr->dst.varindex);
1758                                 break;
1759
1760                                 /* pop 1 push 1 */
1761
1762                         case ICMD_CHECKCAST:
1763                         case ICMD_ARRAYLENGTH:
1764                         case ICMD_INSTANCEOF:
1765                         case ICMD_NEWARRAY:
1766                         case ICMD_ANEWARRAY:
1767                         case ICMD_GETFIELD:
1768                         case ICMD_IADDCONST:
1769                         case ICMD_ISUBCONST:
1770                         case ICMD_IMULCONST:
1771                         case ICMD_IMULPOW2:
1772                         case ICMD_IDIVPOW2:
1773                         case ICMD_IREMPOW2:
1774                         case ICMD_IANDCONST:
1775                         case ICMD_IORCONST:
1776                         case ICMD_IXORCONST:
1777                         case ICMD_ISHLCONST:
1778                         case ICMD_ISHRCONST:
1779                         case ICMD_IUSHRCONST:
1780                         case ICMD_LADDCONST:
1781                         case ICMD_LSUBCONST:
1782                         case ICMD_LMULCONST:
1783                         case ICMD_LMULPOW2:
1784                         case ICMD_LDIVPOW2:
1785                         case ICMD_LREMPOW2:
1786                         case ICMD_LANDCONST:
1787                         case ICMD_LORCONST:
1788                         case ICMD_LXORCONST:
1789                         case ICMD_LSHLCONST:
1790                         case ICMD_LSHRCONST:
1791                         case ICMD_LUSHRCONST:
1792                         case ICMD_INEG:
1793                         case ICMD_INT2BYTE:
1794                         case ICMD_INT2CHAR:
1795                         case ICMD_INT2SHORT:
1796                         case ICMD_LNEG:
1797                         case ICMD_FNEG:
1798                         case ICMD_DNEG:
1799                         case ICMD_I2L:
1800                         case ICMD_I2F:
1801                         case ICMD_I2D:
1802                         case ICMD_L2I:
1803                         case ICMD_L2F:
1804                         case ICMD_L2D:
1805                         case ICMD_F2I:
1806                         case ICMD_F2L:
1807                         case ICMD_F2D:
1808                         case ICMD_D2I:
1809                         case ICMD_D2L:
1810                         case ICMD_D2F:
1811                                 RELOCATE(iptr->s1.varindex);
1812                                 RELOCATE(iptr->dst.varindex);
1813                                 break;
1814
1815                                 /* pop 0 push 1 */
1816
1817                         case ICMD_GETSTATIC:
1818                         case ICMD_NEW:
1819                                 RELOCATE(iptr->dst.varindex);
1820                                 break;
1821
1822                                 /* pop many push any */
1823
1824                         case ICMD_INVOKESTATIC:
1825                         case ICMD_INVOKESPECIAL:
1826                         case ICMD_INVOKEVIRTUAL:
1827                         case ICMD_INVOKEINTERFACE:
1828                         case ICMD_BUILTIN:
1829                         case ICMD_MULTIANEWARRAY:
1830                                 i = iptr->s1.argcount;
1831                                 if (cloneinstructions) {
1832                                         argp = DMNEW(s4, i);
1833                                         MCOPY(argp, iptr->sx.s23.s2.args, s4, i);
1834                                         iptr->sx.s23.s2.args = argp;
1835                                 }
1836                                 else {
1837                                         argp = iptr->sx.s23.s2.args;
1838                                 }
1839
1840                                 while (--i >= 0) {
1841                                         RELOCATE(*argp);
1842                                         argp++;
1843                                 }
1844                                 RELOCATE(iptr->dst.varindex);
1845                                 break;
1846
1847                         default:
1848                                 *exceptionptr =
1849                                         new_internalerror("Unknown ICMD %d during stack re-analysis",
1850                                                         iptr->opc);
1851                                 return false;
1852                 } /* switch */
1853
1854 #if defined(STACK_VERBOSE)
1855                 show_icmd(sd->jd, iptr, false, SHOW_STACK);
1856                 printf("\n");
1857 #endif
1858         }
1859
1860         /* relocate outvars */
1861
1862         for (i=0; i<b->outdepth; ++i) {
1863                 RELOCATE(b->outvars[i]);
1864         }
1865
1866 #if defined(STACK_VERBOSE)
1867         stack_verbose_block_exit(sd, superblockend);
1868 #endif
1869
1870         /* propagate to the next block */
1871
1872         if (!superblockend)
1873                 if (!stack_reach_next_block(sd))
1874                         return false;
1875
1876         return true;
1877 }
1878
1879
1880 /* stack_change_to_tempvar *****************************************************
1881
1882    Change the given stackslot to a TEMPVAR. This includes creating a new
1883    temporary variable and changing the dst.varindex of the creator of the
1884    stacklot to the new variable index. If this stackslot has been passed
1885    through ICMDs between the point of its creation and the current point,
1886    then the variable index is also changed in these ICMDs.
1887
1888    IN:
1889       sd...........stack analysis data
1890           sp...........stackslot to change
1891           ilimit.......instruction up to which to look for ICMDs passing-through
1892                        the stackslot (exclusive). This may point exactly after the 
1893                                    last instruction, in which case the search is done to the
1894                                    basic block end.
1895
1896 *******************************************************************************/
1897
1898 static void stack_change_to_tempvar(stackdata_t *sd, stackptr sp, 
1899                                                                         instruction *ilimit)
1900 {
1901         s4 newindex;
1902         s4 oldindex;
1903         instruction *iptr;
1904         s4 depth;
1905         s4 i;
1906
1907         oldindex = sp->varnum;
1908
1909         /* create a new temporary variable */
1910
1911         GET_NEW_VAR(*sd, newindex, sp->type);
1912
1913         sd->var[newindex].flags = sp->flags;
1914
1915         /* change the stackslot */
1916
1917         sp->varnum = newindex;
1918         sp->varkind = TEMPVAR;
1919
1920         /* change the dst.varindex of the stackslot's creator */
1921
1922         if (sp->creator)
1923                 sp->creator->dst.varindex = newindex;
1924
1925         /* handle ICMDs this stackslot passed through, if any */
1926
1927         if (sp->flags & PASSTHROUGH) {
1928                 iptr = (sp->creator) ? (sp->creator + 1) : sd->bptr->iinstr;
1929
1930                 /* assert that the limit points to an ICMD, or after the last one */
1931
1932                 assert(ilimit >= sd->bptr->iinstr);
1933                 assert(ilimit <= sd->bptr->iinstr + sd->bptr->icount);
1934
1935                 /* find the stackdepth under sp plus one */
1936                 /* Note: This number is usually known when this function is called, */
1937                 /* but calculating it here is less error-prone and should not be    */
1938                 /* a performance problem.                                           */
1939
1940                 for (depth = 0; sp != NULL; sp = sp->prev)
1941                         depth++;
1942
1943                 /* iterate over all instructions in the range and replace */
1944
1945                 for (; iptr < ilimit; ++iptr) {
1946                         switch (iptr->opc) {
1947                                 case ICMD_INVOKESTATIC:
1948                                 case ICMD_INVOKESPECIAL:
1949                                 case ICMD_INVOKEVIRTUAL:
1950                                 case ICMD_INVOKEINTERFACE:
1951                                 case ICMD_BUILTIN:
1952                                         i = iptr->s1.argcount - depth;
1953                                         if (iptr->sx.s23.s2.args[i] == oldindex) {
1954                                                 iptr->sx.s23.s2.args[i] = newindex;
1955                                         }
1956                                         break;
1957                                 /* IMPORTANT: If any ICMD sets the PASSTHROUGH flag of a */
1958                                 /* stackslot, it must be added in this switch!           */
1959                         }
1960                 }
1961         }
1962 }
1963
1964
1965 /* stack_init_javalocals *******************************************************
1966  
1967    Initialize the mapping from Java locals to cacao variables at method entry.
1968
1969    IN:
1970       sd...........stack analysis data
1971
1972 *******************************************************************************/
1973
1974 static void stack_init_javalocals(stackdata_t *sd)
1975 {
1976         s4         *jl;
1977         s4          t,i,j;
1978         methoddesc *md;
1979         jitdata    *jd;
1980
1981         jd = sd->jd;
1982
1983         jl = DMNEW(s4, sd->maxlocals);
1984         jd->basicblocks[0].javalocals = jl;
1985
1986         for (i=0; i<sd->maxlocals; ++i)
1987                 jl[i] = UNUSED;
1988
1989         md = jd->m->parseddesc;
1990         j = 0;
1991         for (i=0; i<md->paramcount; ++i) {
1992                 t = md->paramtypes[i].type;
1993                 jl[j] = jd->local_map[5*j + t];
1994                 j++;
1995                 if (IS_2_WORD_TYPE(t))
1996                         j++;
1997         }
1998 }
1999
2000
2001 /* stack_analyse ***************************************************************
2002
2003    Analyse_stack uses the intermediate code created by parse.c to
2004    build a model of the JVM operand stack for the current method.
2005    
2006    The following checks are performed:
2007      - check for operand stack underflow (before each instruction)
2008      - check for operand stack overflow (after[1] each instruction)
2009      - check for matching stack depth at merging points
2010      - check for matching basic types[2] at merging points
2011      - check basic types for instruction input (except for BUILTIN*
2012            opcodes, INVOKE* opcodes and MULTIANEWARRAY)
2013    
2014    [1]) Checking this after the instruction should be ok. parse.c
2015    counts the number of required stack slots in such a way that it is
2016    only vital that we don't exceed `maxstack` at basic block
2017    boundaries.
2018    
2019    [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
2020    DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
2021    types are not discerned.
2022
2023 *******************************************************************************/
2024
2025 bool stack_analyse(jitdata *jd)
2026 {
2027         methodinfo   *m;              /* method being analyzed                    */
2028         registerdata *rd;
2029         stackdata_t   sd;
2030 #if defined(ENABLE_SSA)
2031         lsradata     *ls;
2032 #endif
2033         int           stackdepth;
2034         stackptr      curstack;       /* current stack top                        */
2035         stackptr      copy;
2036         int           opcode;         /* opcode of current instruction            */
2037         int           i, j;
2038         int           javaindex;
2039         int           len;            /* # of instructions after the current one  */
2040         bool          superblockend;  /* if true, no fallthrough to next block    */
2041         bool          deadcode;       /* true if no live code has been reached    */
2042         instruction  *iptr;           /* the current instruction                  */
2043         basicblock   *tbptr;
2044         basicblock   *original;
2045         exception_entry *ex;
2046
2047         stackptr     *last_store_boundary;
2048         stackptr      coalescing_boundary;
2049
2050         stackptr      src1, src2, src3, src4, dst1, dst2;
2051
2052         branch_target_t *table;
2053         lookup_target_t *lookup;
2054 #if defined(ENABLE_VERIFIER)
2055         int           expectedtype;   /* used by CHECK_BASIC_TYPE                 */
2056 #endif
2057         builtintable_entry *bte;
2058         methoddesc         *md;
2059         constant_FMIref    *fmiref;
2060 #if defined(ENABLE_STATISTICS)
2061         int           iteration_count;  /* number of iterations of analysis       */
2062 #endif
2063         int           new_index; /* used to get a new var index with GET_NEW_INDEX*/
2064
2065 #if defined(STACK_VERBOSE)
2066         show_method(jd, SHOW_PARSE);
2067 #endif
2068
2069         /* get required compiler data - initialization */
2070
2071         m    = jd->m;
2072         rd   = jd->rd;
2073 #if defined(ENABLE_SSA)
2074         ls   = jd->ls;
2075 #endif
2076
2077         /* initialize the stackdata_t struct */
2078
2079         sd.m = m;
2080         sd.jd = jd;
2081         sd.varcount = jd->varcount;
2082         sd.vartop =  jd->vartop;
2083         sd.localcount = jd->localcount;
2084         sd.var = jd->var;
2085         sd.varsallocated = sd.varcount;
2086         sd.maxlocals = m->maxlocals;
2087         sd.javalocals = DMNEW(s4, sd.maxlocals);
2088         sd.handlers = DMNEW(exception_entry *, jd->exceptiontablelength + 1);
2089
2090         /* prepare the variable for exception handler stacks               */
2091         /* (has been reserved by STACK_EXTRA_VARS, or VERIFIER_EXTRA_VARS) */
2092
2093         sd.exstack.type = TYPE_ADR;
2094         sd.exstack.prev = NULL;
2095         sd.exstack.varnum = sd.localcount;
2096         sd.var[sd.exstack.varnum].type = TYPE_ADR;
2097
2098 #if defined(ENABLE_LSRA)
2099         m->maxlifetimes = 0;
2100 #endif
2101
2102 #if defined(ENABLE_STATISTICS)
2103         iteration_count = 0;
2104 #endif
2105
2106         /* find the last real basic block */
2107         
2108         sd.last_real_block = NULL;
2109         tbptr = jd->basicblocks;
2110         while (tbptr->next) {
2111                 sd.last_real_block = tbptr;
2112                 tbptr = tbptr->next;
2113         }
2114         assert(sd.last_real_block);
2115
2116         /* find the last exception handler */
2117
2118         if (jd->exceptiontablelength)
2119                 sd.extableend = jd->exceptiontable + jd->exceptiontablelength - 1;
2120         else
2121                 sd.extableend = NULL;
2122
2123         /* init jd->interface_map */
2124
2125         jd->maxinterfaces = m->maxstack;
2126         jd->interface_map = DMNEW(interface_info, m->maxstack * 5);
2127         for (i = 0; i < m->maxstack * 5; i++)
2128                 jd->interface_map[i].flags = UNUSED;
2129
2130         last_store_boundary = DMNEW(stackptr, m->maxlocals);
2131
2132         /* initialize flags and invars (none) of first block */
2133
2134         jd->basicblocks[0].flags = BBREACHED;
2135         jd->basicblocks[0].invars = NULL;
2136         jd->basicblocks[0].indepth = 0;
2137         jd->basicblocks[0].inlocals = 
2138                 DMNEW(varinfo, jd->localcount + VERIFIER_EXTRA_LOCALS);
2139         MCOPY(jd->basicblocks[0].inlocals, jd->var, varinfo, 
2140                         jd->localcount + VERIFIER_EXTRA_LOCALS);
2141
2142         /* initialize java local mapping of first block */
2143
2144         stack_init_javalocals(&sd);
2145
2146         /* stack analysis loop (until fixpoint reached) **************************/
2147
2148         do {
2149 #if defined(ENABLE_STATISTICS)
2150                 iteration_count++;
2151 #endif
2152
2153                 /* initialize loop over basic blocks */
2154
2155                 sd.bptr = jd->basicblocks;
2156                 superblockend = true;
2157                 sd.repeat = false;
2158                 curstack = NULL; stackdepth = 0;
2159                 deadcode = true;
2160
2161                 /* iterate over basic blocks *****************************************/
2162
2163                 for (; sd.bptr; sd.bptr = sd.bptr->next) {
2164
2165                         if (sd.bptr->flags == BBDELETED) {
2166                                 /* This block has been deleted - do nothing. */
2167
2168                                 continue;
2169                         }
2170
2171                         if (sd.bptr->flags == BBTYPECHECK_REACHED) {
2172                                 /* re-analyse a block because its input changed */
2173                                 deadcode = false;
2174                                 if (!stack_reanalyse_block(&sd))
2175                                         return false;
2176                                 superblockend = true; /* XXX */
2177                                 continue;
2178                         }
2179
2180                         if (superblockend && (sd.bptr->flags < BBREACHED)) {
2181                                 /* This block has not been reached so far, and we      */
2182                                 /* don't fall into it, so we'll have to iterate again. */
2183
2184                                 sd.repeat = true;
2185                                 continue;
2186                         }
2187
2188                         if (sd.bptr->flags > BBREACHED) {
2189                                 /* This block is already finished. */
2190
2191                                 superblockend = true;
2192                                 continue;
2193                         }
2194
2195                         if (sd.bptr->original && sd.bptr->original->flags < BBFINISHED) {
2196                                 /* This block is a clone and the original has not been */
2197                                 /* analysed, yet. Analyse it on the next iteration.    */
2198
2199                                 sd.repeat = true;
2200                                 /* XXX superblockend? */
2201                                 continue;
2202                         }
2203
2204                         /* This block has to be analysed now. */
2205
2206                         deadcode = false;
2207
2208                         /* XXX The rest of this block is still indented one level too */
2209                         /* much in order to avoid a giant diff by changing that.      */
2210
2211                                 /* We know that sd.bptr->flags == BBREACHED. */
2212                                 /* This block has been reached before.    */
2213
2214                                 assert(sd.bptr->flags == BBREACHED);
2215                                 stackdepth = sd.bptr->indepth;
2216
2217                                 /* find exception handlers for this block */
2218
2219                                 /* determine the active exception handlers for this block */
2220                                 /* XXX could use a faster algorithm with sorted lists or  */
2221                                 /* something?                                             */
2222
2223                                 original = (sd.bptr->original) ? sd.bptr->original : sd.bptr;
2224
2225                                 len = 0;
2226                                 ex = jd->exceptiontable;
2227                                 for (; ex != NULL; ex = ex->down) {
2228                                         if ((ex->start <= original) && (ex->end > original)) {
2229                                                 sd.handlers[len++] = ex;
2230                                         }
2231                                 }
2232                                 sd.handlers[len] = NULL;
2233
2234
2235                                 /* reanalyse cloned block */
2236
2237                                 if (sd.bptr->original) {
2238                                         if (!stack_reanalyse_block(&sd))
2239                                                 return false;
2240                                         continue;
2241                                 }
2242
2243                                 /* reset the new pointer for allocating stackslots */
2244
2245                                 sd.new = jd->stack;
2246
2247                                 /* create the instack of this block */
2248
2249                                 curstack = stack_create_instack(&sd);
2250
2251                                 /* initialize locals at the start of this block */
2252
2253                                 if (sd.bptr->inlocals)
2254                                         MCOPY(sd.var, sd.bptr->inlocals, varinfo, sd.localcount);
2255
2256                                 MCOPY(sd.javalocals, sd.bptr->javalocals, s4, sd.maxlocals);
2257
2258                                 /* set up local variables for analyzing this block */
2259
2260                                 superblockend = false;
2261                                 len = sd.bptr->icount;
2262                                 iptr = sd.bptr->iinstr;
2263
2264                                 /* mark the block as analysed */
2265
2266                                 sd.bptr->flags = BBFINISHED;
2267
2268                                 /* reset variables for dependency checking */
2269
2270                                 coalescing_boundary = sd.new;
2271                                 for( i = 0; i < m->maxlocals; i++)
2272                                         last_store_boundary[i] = sd.new;
2273
2274                                 /* remember the start of this block's variables */
2275   
2276                                 sd.bptr->varstart = sd.vartop;
2277
2278 #if defined(STACK_VERBOSE)
2279                                 stack_verbose_block_enter(&sd, false);
2280 #endif
2281   
2282                                 /* reach exception handlers for this block */
2283
2284                                 if (!stack_reach_handlers(&sd))
2285                                         return false;
2286
2287                                 /* iterate over ICMDs ****************************************/
2288
2289                                 while (--len >= 0)  {
2290
2291 #if defined(STACK_VERBOSE)
2292                                         stack_verbose_show_state(&sd, iptr, curstack);
2293 #endif
2294
2295                                         /* fetch the current opcode */
2296
2297                                         opcode = iptr->opc;
2298
2299                                         /* automatically replace some ICMDs with builtins */
2300
2301 #if defined(USEBUILTINTABLE)
2302                                         bte = builtintable_get_automatic(opcode);
2303
2304                                         if (bte && bte->opcode == opcode) {
2305                                                 iptr->opc           = ICMD_BUILTIN;
2306                                                 iptr->flags.bits    &= INS_FLAG_ID_MASK;
2307                                                 iptr->sx.s23.s3.bte = bte;
2308                                                 /* iptr->line is already set */
2309                                                 jd->isleafmethod = false;
2310                                                 goto icmd_BUILTIN;
2311                                         }
2312 #endif /* defined(USEBUILTINTABLE) */
2313
2314                                         /* main opcode switch *************************************/
2315
2316                                         switch (opcode) {
2317
2318                                                 /* pop 0 push 0 */
2319
2320                                         case ICMD_NOP:
2321 icmd_NOP:
2322                                                 CLR_SX;
2323                                                 OP0_0;
2324                                                 break;
2325
2326                                         case ICMD_CHECKNULL:
2327                                                 coalescing_boundary = sd.new;
2328                                                 COUNT(count_check_null);
2329                                                 USE_S1(TYPE_ADR);
2330                                                 CLR_SX;
2331                                                 iptr->dst.varindex = iptr->s1.varindex;
2332                                                 break;
2333
2334                                         case ICMD_RET:
2335                                                 j = iptr->s1.varindex = 
2336                                                         jd->local_map[iptr->s1.varindex * 5 + TYPE_ADR];
2337
2338 #if defined(ENABLE_VERIFIER)
2339                                                 if (sd.var[j].type != TYPE_RET) {
2340                                                         exceptions_throw_verifyerror(m, "RET with non-returnAddress value");
2341                                                         return false;
2342                                                 }
2343 #endif
2344                 
2345                                                 CLR_SX;
2346
2347                                                 iptr->dst.block = stack_mark_reached(&sd, sd.var[j].vv.retaddr, curstack, stackdepth);
2348                                                 superblockend = true;
2349                                                 break;
2350
2351                                         case ICMD_RETURN:
2352                                                 COUNT(count_pcmd_return);
2353                                                 CLR_SX;
2354                                                 OP0_0;
2355                                                 superblockend = true;
2356                                                 sd.jd->returncount++;
2357                                                 sd.jd->returnblock = sd.bptr;
2358                                                 break;
2359
2360
2361                                                 /* pop 0 push 1 const */
2362
2363         /************************** ICONST OPTIMIZATIONS **************************/
2364
2365                                         case ICMD_ICONST:
2366                                                 COUNT(count_pcmd_load);
2367                                                 if (len == 0)
2368                                                         goto normal_ICONST;
2369
2370                                                 switch (iptr[1].opc) {
2371                                                         case ICMD_IADD:
2372                                                                 iptr->opc = ICMD_IADDCONST;
2373                                                                 /* FALLTHROUGH */
2374
2375                                                         icmd_iconst_tail:
2376                                                                 iptr[1].opc = ICMD_NOP;
2377                                                                 OP1_1(TYPE_INT, TYPE_INT);
2378                                                                 COUNT(count_pcmd_op);
2379                                                                 break;
2380
2381                                                         case ICMD_ISUB:
2382                                                                 iptr->opc = ICMD_ISUBCONST;
2383                                                                 goto icmd_iconst_tail;
2384 #if SUPPORT_CONST_MUL
2385                                                         case ICMD_IMUL:
2386                                                                 iptr->opc = ICMD_IMULCONST;
2387                                                                 goto icmd_iconst_tail;
2388 #else /* SUPPORT_CONST_MUL */
2389                                                         case ICMD_IMUL:
2390                                                                 if (iptr->sx.val.i == 0x00000002)
2391                                                                         iptr->sx.val.i = 1;
2392                                                                 else if (iptr->sx.val.i == 0x00000004)
2393                                                                         iptr->sx.val.i = 2;
2394                                                                 else if (iptr->sx.val.i == 0x00000008)
2395                                                                         iptr->sx.val.i = 3;
2396                                                                 else if (iptr->sx.val.i == 0x00000010)
2397                                                                         iptr->sx.val.i = 4;
2398                                                                 else if (iptr->sx.val.i == 0x00000020)
2399                                                                         iptr->sx.val.i = 5;
2400                                                                 else if (iptr->sx.val.i == 0x00000040)
2401                                                                         iptr->sx.val.i = 6;
2402                                                                 else if (iptr->sx.val.i == 0x00000080)
2403                                                                         iptr->sx.val.i = 7;
2404                                                                 else if (iptr->sx.val.i == 0x00000100)
2405                                                                         iptr->sx.val.i = 8;
2406                                                                 else if (iptr->sx.val.i == 0x00000200)
2407                                                                         iptr->sx.val.i = 9;
2408                                                                 else if (iptr->sx.val.i == 0x00000400)
2409                                                                         iptr->sx.val.i = 10;
2410                                                                 else if (iptr->sx.val.i == 0x00000800)
2411                                                                         iptr->sx.val.i = 11;
2412                                                                 else if (iptr->sx.val.i == 0x00001000)
2413                                                                         iptr->sx.val.i = 12;
2414                                                                 else if (iptr->sx.val.i == 0x00002000)
2415                                                                         iptr->sx.val.i = 13;
2416                                                                 else if (iptr->sx.val.i == 0x00004000)
2417                                                                         iptr->sx.val.i = 14;
2418                                                                 else if (iptr->sx.val.i == 0x00008000)
2419                                                                         iptr->sx.val.i = 15;
2420                                                                 else if (iptr->sx.val.i == 0x00010000)
2421                                                                         iptr->sx.val.i = 16;
2422                                                                 else if (iptr->sx.val.i == 0x00020000)
2423                                                                         iptr->sx.val.i = 17;
2424                                                                 else if (iptr->sx.val.i == 0x00040000)
2425                                                                         iptr->sx.val.i = 18;
2426                                                                 else if (iptr->sx.val.i == 0x00080000)
2427                                                                         iptr->sx.val.i = 19;
2428                                                                 else if (iptr->sx.val.i == 0x00100000)
2429                                                                         iptr->sx.val.i = 20;
2430                                                                 else if (iptr->sx.val.i == 0x00200000)
2431                                                                         iptr->sx.val.i = 21;
2432                                                                 else if (iptr->sx.val.i == 0x00400000)
2433                                                                         iptr->sx.val.i = 22;
2434                                                                 else if (iptr->sx.val.i == 0x00800000)
2435                                                                         iptr->sx.val.i = 23;
2436                                                                 else if (iptr->sx.val.i == 0x01000000)
2437                                                                         iptr->sx.val.i = 24;
2438                                                                 else if (iptr->sx.val.i == 0x02000000)
2439                                                                         iptr->sx.val.i = 25;
2440                                                                 else if (iptr->sx.val.i == 0x04000000)
2441                                                                         iptr->sx.val.i = 26;
2442                                                                 else if (iptr->sx.val.i == 0x08000000)
2443                                                                         iptr->sx.val.i = 27;
2444                                                                 else if (iptr->sx.val.i == 0x10000000)
2445                                                                         iptr->sx.val.i = 28;
2446                                                                 else if (iptr->sx.val.i == 0x20000000)
2447                                                                         iptr->sx.val.i = 29;
2448                                                                 else if (iptr->sx.val.i == 0x40000000)
2449                                                                         iptr->sx.val.i = 30;
2450                                                                 else if (iptr->sx.val.i == 0x80000000)
2451                                                                         iptr->sx.val.i = 31;
2452                                                                 else
2453                                                                         goto normal_ICONST;
2454
2455                                                                 iptr->opc = ICMD_IMULPOW2;
2456                                                                 goto icmd_iconst_tail;
2457 #endif /* SUPPORT_CONST_MUL */
2458                                                         case ICMD_IDIV:
2459                                                                 if (iptr->sx.val.i == 0x00000002)
2460                                                                         iptr->sx.val.i = 1;
2461                                                                 else if (iptr->sx.val.i == 0x00000004)
2462                                                                         iptr->sx.val.i = 2;
2463                                                                 else if (iptr->sx.val.i == 0x00000008)
2464                                                                         iptr->sx.val.i = 3;
2465                                                                 else if (iptr->sx.val.i == 0x00000010)
2466                                                                         iptr->sx.val.i = 4;
2467                                                                 else if (iptr->sx.val.i == 0x00000020)
2468                                                                         iptr->sx.val.i = 5;
2469                                                                 else if (iptr->sx.val.i == 0x00000040)
2470                                                                         iptr->sx.val.i = 6;
2471                                                                 else if (iptr->sx.val.i == 0x00000080)
2472                                                                         iptr->sx.val.i = 7;
2473                                                                 else if (iptr->sx.val.i == 0x00000100)
2474                                                                         iptr->sx.val.i = 8;
2475                                                                 else if (iptr->sx.val.i == 0x00000200)
2476                                                                         iptr->sx.val.i = 9;
2477                                                                 else if (iptr->sx.val.i == 0x00000400)
2478                                                                         iptr->sx.val.i = 10;
2479                                                                 else if (iptr->sx.val.i == 0x00000800)
2480                                                                         iptr->sx.val.i = 11;
2481                                                                 else if (iptr->sx.val.i == 0x00001000)
2482                                                                         iptr->sx.val.i = 12;
2483                                                                 else if (iptr->sx.val.i == 0x00002000)
2484                                                                         iptr->sx.val.i = 13;
2485                                                                 else if (iptr->sx.val.i == 0x00004000)
2486                                                                         iptr->sx.val.i = 14;
2487                                                                 else if (iptr->sx.val.i == 0x00008000)
2488                                                                         iptr->sx.val.i = 15;
2489                                                                 else if (iptr->sx.val.i == 0x00010000)
2490                                                                         iptr->sx.val.i = 16;
2491                                                                 else if (iptr->sx.val.i == 0x00020000)
2492                                                                         iptr->sx.val.i = 17;
2493                                                                 else if (iptr->sx.val.i == 0x00040000)
2494                                                                         iptr->sx.val.i = 18;
2495                                                                 else if (iptr->sx.val.i == 0x00080000)
2496                                                                         iptr->sx.val.i = 19;
2497                                                                 else if (iptr->sx.val.i == 0x00100000)
2498                                                                         iptr->sx.val.i = 20;
2499                                                                 else if (iptr->sx.val.i == 0x00200000)
2500                                                                         iptr->sx.val.i = 21;
2501                                                                 else if (iptr->sx.val.i == 0x00400000)
2502                                                                         iptr->sx.val.i = 22;
2503                                                                 else if (iptr->sx.val.i == 0x00800000)
2504                                                                         iptr->sx.val.i = 23;
2505                                                                 else if (iptr->sx.val.i == 0x01000000)
2506                                                                         iptr->sx.val.i = 24;
2507                                                                 else if (iptr->sx.val.i == 0x02000000)
2508                                                                         iptr->sx.val.i = 25;
2509                                                                 else if (iptr->sx.val.i == 0x04000000)
2510                                                                         iptr->sx.val.i = 26;
2511                                                                 else if (iptr->sx.val.i == 0x08000000)
2512                                                                         iptr->sx.val.i = 27;
2513                                                                 else if (iptr->sx.val.i == 0x10000000)
2514                                                                         iptr->sx.val.i = 28;
2515                                                                 else if (iptr->sx.val.i == 0x20000000)
2516                                                                         iptr->sx.val.i = 29;
2517                                                                 else if (iptr->sx.val.i == 0x40000000)
2518                                                                         iptr->sx.val.i = 30;
2519                                                                 else if (iptr->sx.val.i == 0x80000000)
2520                                                                         iptr->sx.val.i = 31;
2521                                                                 else
2522                                                                         goto normal_ICONST;
2523
2524                                                                 iptr->opc = ICMD_IDIVPOW2;
2525                                                                 goto icmd_iconst_tail;
2526
2527                                                         case ICMD_IREM:
2528                                                                 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
2529                                                                 if ((iptr->sx.val.i == 0x00000002) ||
2530                                                                         (iptr->sx.val.i == 0x00000004) ||
2531                                                                         (iptr->sx.val.i == 0x00000008) ||
2532                                                                         (iptr->sx.val.i == 0x00000010) ||
2533                                                                         (iptr->sx.val.i == 0x00000020) ||
2534                                                                         (iptr->sx.val.i == 0x00000040) ||
2535                                                                         (iptr->sx.val.i == 0x00000080) ||
2536                                                                         (iptr->sx.val.i == 0x00000100) ||
2537                                                                         (iptr->sx.val.i == 0x00000200) ||
2538                                                                         (iptr->sx.val.i == 0x00000400) ||
2539                                                                         (iptr->sx.val.i == 0x00000800) ||
2540                                                                         (iptr->sx.val.i == 0x00001000) ||
2541                                                                         (iptr->sx.val.i == 0x00002000) ||
2542                                                                         (iptr->sx.val.i == 0x00004000) ||
2543                                                                         (iptr->sx.val.i == 0x00008000) ||
2544                                                                         (iptr->sx.val.i == 0x00010000) ||
2545                                                                         (iptr->sx.val.i == 0x00020000) ||
2546                                                                         (iptr->sx.val.i == 0x00040000) ||
2547                                                                         (iptr->sx.val.i == 0x00080000) ||
2548                                                                         (iptr->sx.val.i == 0x00100000) ||
2549                                                                         (iptr->sx.val.i == 0x00200000) ||
2550                                                                         (iptr->sx.val.i == 0x00400000) ||
2551                                                                         (iptr->sx.val.i == 0x00800000) ||
2552                                                                         (iptr->sx.val.i == 0x01000000) ||
2553                                                                         (iptr->sx.val.i == 0x02000000) ||
2554                                                                         (iptr->sx.val.i == 0x04000000) ||
2555                                                                         (iptr->sx.val.i == 0x08000000) ||
2556                                                                         (iptr->sx.val.i == 0x10000000) ||
2557                                                                         (iptr->sx.val.i == 0x20000000) ||
2558                                                                         (iptr->sx.val.i == 0x40000000) ||
2559                                                                         (iptr->sx.val.i == 0x80000000))
2560                                                                 {
2561                                                                         iptr->opc = ICMD_IREMPOW2;
2562                                                                         iptr->sx.val.i -= 1;
2563                                                                         goto icmd_iconst_tail;
2564                                                                 }
2565                                                                 goto normal_ICONST;
2566 #if SUPPORT_CONST_LOGICAL
2567                                                         case ICMD_IAND:
2568                                                                 iptr->opc = ICMD_IANDCONST;
2569                                                                 goto icmd_iconst_tail;
2570
2571                                                         case ICMD_IOR:
2572                                                                 iptr->opc = ICMD_IORCONST;
2573                                                                 goto icmd_iconst_tail;
2574
2575                                                         case ICMD_IXOR:
2576                                                                 iptr->opc = ICMD_IXORCONST;
2577                                                                 goto icmd_iconst_tail;
2578
2579 #endif /* SUPPORT_CONST_LOGICAL */
2580                                                         case ICMD_ISHL:
2581                                                                 iptr->opc = ICMD_ISHLCONST;
2582                                                                 goto icmd_iconst_tail;
2583
2584                                                         case ICMD_ISHR:
2585                                                                 iptr->opc = ICMD_ISHRCONST;
2586                                                                 goto icmd_iconst_tail;
2587
2588                                                         case ICMD_IUSHR:
2589                                                                 iptr->opc = ICMD_IUSHRCONST;
2590                                                                 goto icmd_iconst_tail;
2591 #if SUPPORT_LONG_SHIFT
2592                                                         case ICMD_LSHL:
2593                                                                 iptr->opc = ICMD_LSHLCONST;
2594                                                                 goto icmd_lconst_tail;
2595
2596                                                         case ICMD_LSHR:
2597                                                                 iptr->opc = ICMD_LSHRCONST;
2598                                                                 goto icmd_lconst_tail;
2599
2600                                                         case ICMD_LUSHR:
2601                                                                 iptr->opc = ICMD_LUSHRCONST;
2602                                                                 goto icmd_lconst_tail;
2603 #endif /* SUPPORT_LONG_SHIFT */
2604                                                         case ICMD_IF_ICMPEQ:
2605                                                                 iptr[1].opc = ICMD_IFEQ;
2606                                                                 /* FALLTHROUGH */
2607
2608                                                         icmd_if_icmp_tail:
2609                                                                 /* set the constant for the following icmd */
2610                                                                 iptr[1].sx.val.i = iptr->sx.val.i;
2611
2612                                                                 /* this instruction becomes a nop */
2613                                                                 iptr->opc = ICMD_NOP;
2614                                                                 goto icmd_NOP;
2615
2616                                                         case ICMD_IF_ICMPLT:
2617                                                                 iptr[1].opc = ICMD_IFLT;
2618                                                                 goto icmd_if_icmp_tail;
2619
2620                                                         case ICMD_IF_ICMPLE:
2621                                                                 iptr[1].opc = ICMD_IFLE;
2622                                                                 goto icmd_if_icmp_tail;
2623
2624                                                         case ICMD_IF_ICMPNE:
2625                                                                 iptr[1].opc = ICMD_IFNE;
2626                                                                 goto icmd_if_icmp_tail;
2627
2628                                                         case ICMD_IF_ICMPGT:
2629                                                                 iptr[1].opc = ICMD_IFGT;
2630                                                                 goto icmd_if_icmp_tail;
2631
2632                                                         case ICMD_IF_ICMPGE:
2633                                                                 iptr[1].opc = ICMD_IFGE;
2634                                                                 goto icmd_if_icmp_tail;
2635
2636 #if SUPPORT_CONST_STORE
2637                                                         case ICMD_IASTORE:
2638                                                         case ICMD_BASTORE:
2639                                                         case ICMD_CASTORE:
2640                                                         case ICMD_SASTORE:
2641 # if SUPPORT_CONST_STORE_ZERO_ONLY
2642                                                                 if (iptr->sx.val.i != 0)
2643                                                                         goto normal_ICONST;
2644 # endif
2645                                                                 switch (iptr[1].opc) {
2646                                                                         case ICMD_IASTORE:
2647                                                                                 iptr->opc = ICMD_IASTORECONST;
2648                                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
2649                                                                                 break;
2650                                                                         case ICMD_BASTORE:
2651                                                                                 iptr->opc = ICMD_BASTORECONST;
2652                                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
2653                                                                                 break;
2654                                                                         case ICMD_CASTORE:
2655                                                                                 iptr->opc = ICMD_CASTORECONST;
2656                                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
2657                                                                                 break;
2658                                                                         case ICMD_SASTORE:
2659                                                                                 iptr->opc = ICMD_SASTORECONST;
2660                                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
2661                                                                                 break;
2662                                                                 }
2663
2664                                                                 iptr[1].opc = ICMD_NOP;
2665
2666                                                                 /* copy the constant to s3 */
2667                                                                 /* XXX constval -> astoreconstval? */
2668                                                                 iptr->sx.s23.s3.constval = iptr->sx.val.i;
2669                                                                 OP2_0(TYPE_ADR, TYPE_INT);
2670                                                                 COUNT(count_pcmd_op);
2671                                                                 break;
2672
2673                                                         case ICMD_PUTSTATIC:
2674                                                         case ICMD_PUTFIELD:
2675 # if SUPPORT_CONST_STORE_ZERO_ONLY
2676                                                                 if (iptr->sx.val.i != 0)
2677                                                                         goto normal_ICONST;
2678 # endif
2679                                                                 /* XXX check field type? */
2680
2681                                                                 /* copy the constant to s2 */
2682                                                                 /* XXX constval -> fieldconstval? */
2683                                                                 iptr->sx.s23.s2.constval = iptr->sx.val.i;
2684
2685 putconst_tail:
2686                                                                 /* set the field reference (s3) */
2687                                                                 if (iptr[1].flags.bits & INS_FLAG_UNRESOLVED) {
2688                                                                         iptr->sx.s23.s3.uf = iptr[1].sx.s23.s3.uf;
2689                                                                         iptr->flags.bits |= INS_FLAG_UNRESOLVED;
2690                                                                         fmiref = iptr->sx.s23.s3.uf->fieldref;
2691                                                                 }
2692                                                                 else {
2693                                                                         fmiref = iptr[1].sx.s23.s3.fmiref;
2694                                                                         iptr->sx.s23.s3.fmiref = fmiref;
2695                                                                 }
2696
2697 #if defined(ENABLE_VERIFIER)
2698                                                                 expectedtype = fmiref->parseddesc.fd->type;
2699                                                                 switch (iptr[0].opc) {
2700                                                                         case ICMD_ICONST:
2701                                                                                 if (expectedtype != TYPE_INT)
2702                                                                                         goto throw_stack_type_error;
2703                                                                                 break;
2704                                                                         case ICMD_LCONST:
2705                                                                                 if (expectedtype != TYPE_LNG)
2706                                                                                         goto throw_stack_type_error;
2707                                                                                 break;
2708                                                                         case ICMD_ACONST:
2709                                                                                 if (expectedtype != TYPE_ADR)
2710                                                                                         goto throw_stack_type_error;
2711                                                                                 break;
2712                                                                         default:
2713                                                                                 assert(0);
2714                                                                 }
2715 #endif /* defined(ENABLE_VERIFIER) */
2716                                                                 
2717                                                                 switch (iptr[1].opc) {
2718                                                                         case ICMD_PUTSTATIC:
2719                                                                                 iptr->opc = ICMD_PUTSTATICCONST;
2720                                                                                 OP0_0;
2721                                                                                 break;
2722                                                                         case ICMD_PUTFIELD:
2723                                                                                 iptr->opc = ICMD_PUTFIELDCONST;
2724                                                                                 OP1_0(TYPE_ADR);
2725                                                                                 break;
2726                                                                 }
2727
2728                                                                 iptr[1].opc = ICMD_NOP;
2729                                                                 COUNT(count_pcmd_op);
2730                                                                 break;
2731 #endif /* SUPPORT_CONST_STORE */
2732
2733                                                         default:
2734                                                                 goto normal_ICONST;
2735                                                 }
2736
2737                                                 /* if we get here, the ICONST has been optimized */
2738                                                 break;
2739
2740 normal_ICONST:
2741                                                 /* normal case of an unoptimized ICONST */
2742                                                 OP0_1(TYPE_INT);
2743                                                 break;
2744
2745         /************************** LCONST OPTIMIZATIONS **************************/
2746
2747                                         case ICMD_LCONST:
2748                                                 COUNT(count_pcmd_load);
2749                                                 if (len == 0)
2750                                                         goto normal_LCONST;
2751
2752                                                 /* switch depending on the following instruction */
2753
2754                                                 switch (iptr[1].opc) {
2755 #if SUPPORT_LONG_ADD
2756                                                         case ICMD_LADD:
2757                                                                 iptr->opc = ICMD_LADDCONST;
2758                                                                 /* FALLTHROUGH */
2759
2760                                                         icmd_lconst_tail:
2761                                                                 /* instruction of type LONG -> LONG */
2762                                                                 iptr[1].opc = ICMD_NOP;
2763                                                                 OP1_1(TYPE_LNG, TYPE_LNG);
2764                                                                 COUNT(count_pcmd_op);
2765                                                                 break;
2766
2767                                                         case ICMD_LSUB:
2768                                                                 iptr->opc = ICMD_LSUBCONST;
2769                                                                 goto icmd_lconst_tail;
2770
2771 #endif /* SUPPORT_LONG_ADD */
2772 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
2773                                                         case ICMD_LMUL:
2774                                                                 iptr->opc = ICMD_LMULCONST;
2775                                                                 goto icmd_lconst_tail;
2776 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
2777 # if SUPPORT_LONG_SHIFT
2778                                                         case ICMD_LMUL:
2779                                                                 if (iptr->sx.val.l == 0x00000002)
2780                                                                         iptr->sx.val.i = 1;
2781                                                                 else if (iptr->sx.val.l == 0x00000004)
2782                                                                         iptr->sx.val.i = 2;
2783                                                                 else if (iptr->sx.val.l == 0x00000008)
2784                                                                         iptr->sx.val.i = 3;
2785                                                                 else if (iptr->sx.val.l == 0x00000010)
2786                                                                         iptr->sx.val.i = 4;
2787                                                                 else if (iptr->sx.val.l == 0x00000020)
2788                                                                         iptr->sx.val.i = 5;
2789                                                                 else if (iptr->sx.val.l == 0x00000040)
2790                                                                         iptr->sx.val.i = 6;
2791                                                                 else if (iptr->sx.val.l == 0x00000080)
2792                                                                         iptr->sx.val.i = 7;
2793                                                                 else if (iptr->sx.val.l == 0x00000100)
2794                                                                         iptr->sx.val.i = 8;
2795                                                                 else if (iptr->sx.val.l == 0x00000200)
2796                                                                         iptr->sx.val.i = 9;
2797                                                                 else if (iptr->sx.val.l == 0x00000400)
2798                                                                         iptr->sx.val.i = 10;
2799                                                                 else if (iptr->sx.val.l == 0x00000800)
2800                                                                         iptr->sx.val.i = 11;
2801                                                                 else if (iptr->sx.val.l == 0x00001000)
2802                                                                         iptr->sx.val.i = 12;
2803                                                                 else if (iptr->sx.val.l == 0x00002000)
2804                                                                         iptr->sx.val.i = 13;
2805                                                                 else if (iptr->sx.val.l == 0x00004000)
2806                                                                         iptr->sx.val.i = 14;
2807                                                                 else if (iptr->sx.val.l == 0x00008000)
2808                                                                         iptr->sx.val.i = 15;
2809                                                                 else if (iptr->sx.val.l == 0x00010000)
2810                                                                         iptr->sx.val.i = 16;
2811                                                                 else if (iptr->sx.val.l == 0x00020000)
2812                                                                         iptr->sx.val.i = 17;
2813                                                                 else if (iptr->sx.val.l == 0x00040000)
2814                                                                         iptr->sx.val.i = 18;
2815                                                                 else if (iptr->sx.val.l == 0x00080000)
2816                                                                         iptr->sx.val.i = 19;
2817                                                                 else if (iptr->sx.val.l == 0x00100000)
2818                                                                         iptr->sx.val.i = 20;
2819                                                                 else if (iptr->sx.val.l == 0x00200000)
2820                                                                         iptr->sx.val.i = 21;
2821                                                                 else if (iptr->sx.val.l == 0x00400000)
2822                                                                         iptr->sx.val.i = 22;
2823                                                                 else if (iptr->sx.val.l == 0x00800000)
2824                                                                         iptr->sx.val.i = 23;
2825                                                                 else if (iptr->sx.val.l == 0x01000000)
2826                                                                         iptr->sx.val.i = 24;
2827                                                                 else if (iptr->sx.val.l == 0x02000000)
2828                                                                         iptr->sx.val.i = 25;
2829                                                                 else if (iptr->sx.val.l == 0x04000000)
2830                                                                         iptr->sx.val.i = 26;
2831                                                                 else if (iptr->sx.val.l == 0x08000000)
2832                                                                         iptr->sx.val.i = 27;
2833                                                                 else if (iptr->sx.val.l == 0x10000000)
2834                                                                         iptr->sx.val.i = 28;
2835                                                                 else if (iptr->sx.val.l == 0x20000000)
2836                                                                         iptr->sx.val.i = 29;
2837                                                                 else if (iptr->sx.val.l == 0x40000000)
2838                                                                         iptr->sx.val.i = 30;
2839                                                                 else if (iptr->sx.val.l == 0x80000000)
2840                                                                         iptr->sx.val.i = 31;
2841                                                                 else {
2842                                                                         goto normal_LCONST;
2843                                                                 }
2844                                                                 iptr->opc = ICMD_LMULPOW2;
2845                                                                 goto icmd_lconst_tail;
2846 # endif /* SUPPORT_LONG_SHIFT */
2847 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
2848 #if SUPPORT_LONG_DIV_POW2
2849                                                         case ICMD_LDIV:
2850                                                                 if (iptr->sx.val.l == 0x00000002)
2851                                                                         iptr->sx.val.i = 1;
2852                                                                 else if (iptr->sx.val.l == 0x00000004)
2853                                                                         iptr->sx.val.i = 2;
2854                                                                 else if (iptr->sx.val.l == 0x00000008)
2855                                                                         iptr->sx.val.i = 3;
2856                                                                 else if (iptr->sx.val.l == 0x00000010)
2857                                                                         iptr->sx.val.i = 4;
2858                                                                 else if (iptr->sx.val.l == 0x00000020)
2859                                                                         iptr->sx.val.i = 5;
2860                                                                 else if (iptr->sx.val.l == 0x00000040)
2861                                                                         iptr->sx.val.i = 6;
2862                                                                 else if (iptr->sx.val.l == 0x00000080)
2863                                                                         iptr->sx.val.i = 7;
2864                                                                 else if (iptr->sx.val.l == 0x00000100)
2865                                                                         iptr->sx.val.i = 8;
2866                                                                 else if (iptr->sx.val.l == 0x00000200)
2867                                                                         iptr->sx.val.i = 9;
2868                                                                 else if (iptr->sx.val.l == 0x00000400)
2869                                                                         iptr->sx.val.i = 10;
2870                                                                 else if (iptr->sx.val.l == 0x00000800)
2871                                                                         iptr->sx.val.i = 11;
2872                                                                 else if (iptr->sx.val.l == 0x00001000)
2873                                                                         iptr->sx.val.i = 12;
2874                                                                 else if (iptr->sx.val.l == 0x00002000)
2875                                                                         iptr->sx.val.i = 13;
2876                                                                 else if (iptr->sx.val.l == 0x00004000)
2877                                                                         iptr->sx.val.i = 14;
2878                                                                 else if (iptr->sx.val.l == 0x00008000)
2879                                                                         iptr->sx.val.i = 15;
2880                                                                 else if (iptr->sx.val.l == 0x00010000)
2881                                                                         iptr->sx.val.i = 16;
2882                                                                 else if (iptr->sx.val.l == 0x00020000)
2883                                                                         iptr->sx.val.i = 17;
2884                                                                 else if (iptr->sx.val.l == 0x00040000)
2885                                                                         iptr->sx.val.i = 18;
2886                                                                 else if (iptr->sx.val.l == 0x00080000)
2887                                                                         iptr->sx.val.i = 19;
2888                                                                 else if (iptr->sx.val.l == 0x00100000)
2889                                                                         iptr->sx.val.i = 20;
2890                                                                 else if (iptr->sx.val.l == 0x00200000)
2891                                                                         iptr->sx.val.i = 21;
2892                                                                 else if (iptr->sx.val.l == 0x00400000)
2893                                                                         iptr->sx.val.i = 22;
2894                                                                 else if (iptr->sx.val.l == 0x00800000)
2895                                                                         iptr->sx.val.i = 23;
2896                                                                 else if (iptr->sx.val.l == 0x01000000)
2897                                                                         iptr->sx.val.i = 24;
2898                                                                 else if (iptr->sx.val.l == 0x02000000)
2899                                                                         iptr->sx.val.i = 25;
2900                                                                 else if (iptr->sx.val.l == 0x04000000)
2901                                                                         iptr->sx.val.i = 26;
2902                                                                 else if (iptr->sx.val.l == 0x08000000)
2903                                                                         iptr->sx.val.i = 27;
2904                                                                 else if (iptr->sx.val.l == 0x10000000)
2905                                                                         iptr->sx.val.i = 28;
2906                                                                 else if (iptr->sx.val.l == 0x20000000)
2907                                                                         iptr->sx.val.i = 29;
2908                                                                 else if (iptr->sx.val.l == 0x40000000)
2909                                                                         iptr->sx.val.i = 30;
2910                                                                 else if (iptr->sx.val.l == 0x80000000)
2911                                                                         iptr->sx.val.i = 31;
2912                                                                 else {
2913                                                                         goto normal_LCONST;
2914                                                                 }
2915                                                                 iptr->opc = ICMD_LDIVPOW2;
2916                                                                 goto icmd_lconst_tail;
2917 #endif /* SUPPORT_LONG_DIV_POW2 */
2918
2919 #if SUPPORT_LONG_REM_POW2
2920                                                         case ICMD_LREM:
2921                                                                 if ((iptr->sx.val.l == 0x00000002) ||
2922                                                                         (iptr->sx.val.l == 0x00000004) ||
2923                                                                         (iptr->sx.val.l == 0x00000008) ||
2924                                                                         (iptr->sx.val.l == 0x00000010) ||
2925                                                                         (iptr->sx.val.l == 0x00000020) ||
2926                                                                         (iptr->sx.val.l == 0x00000040) ||
2927                                                                         (iptr->sx.val.l == 0x00000080) ||
2928                                                                         (iptr->sx.val.l == 0x00000100) ||
2929                                                                         (iptr->sx.val.l == 0x00000200) ||
2930                                                                         (iptr->sx.val.l == 0x00000400) ||
2931                                                                         (iptr->sx.val.l == 0x00000800) ||
2932                                                                         (iptr->sx.val.l == 0x00001000) ||
2933                                                                         (iptr->sx.val.l == 0x00002000) ||
2934                                                                         (iptr->sx.val.l == 0x00004000) ||
2935                                                                         (iptr->sx.val.l == 0x00008000) ||
2936                                                                         (iptr->sx.val.l == 0x00010000) ||
2937                                                                         (iptr->sx.val.l == 0x00020000) ||
2938                                                                         (iptr->sx.val.l == 0x00040000) ||
2939                                                                         (iptr->sx.val.l == 0x00080000) ||
2940                                                                         (iptr->sx.val.l == 0x00100000) ||
2941                                                                         (iptr->sx.val.l == 0x00200000) ||
2942                                                                         (iptr->sx.val.l == 0x00400000) ||
2943                                                                         (iptr->sx.val.l == 0x00800000) ||
2944                                                                         (iptr->sx.val.l == 0x01000000) ||
2945                                                                         (iptr->sx.val.l == 0x02000000) ||
2946                                                                         (iptr->sx.val.l == 0x04000000) ||
2947                                                                         (iptr->sx.val.l == 0x08000000) ||
2948                                                                         (iptr->sx.val.l == 0x10000000) ||
2949                                                                         (iptr->sx.val.l == 0x20000000) ||
2950                                                                         (iptr->sx.val.l == 0x40000000) ||
2951                                                                         (iptr->sx.val.l == 0x80000000))
2952                                                                 {
2953                                                                         iptr->opc = ICMD_LREMPOW2;
2954                                                                         iptr->sx.val.l -= 1;
2955                                                                         goto icmd_lconst_tail;
2956                                                                 }
2957                                                                 goto normal_LCONST;
2958 #endif /* SUPPORT_LONG_REM_POW2 */
2959
2960 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
2961
2962                                                         case ICMD_LAND:
2963                                                                 iptr->opc = ICMD_LANDCONST;
2964                                                                 goto icmd_lconst_tail;
2965
2966                                                         case ICMD_LOR:
2967                                                                 iptr->opc = ICMD_LORCONST;
2968                                                                 goto icmd_lconst_tail;
2969
2970                                                         case ICMD_LXOR:
2971                                                                 iptr->opc = ICMD_LXORCONST;
2972                                                                 goto icmd_lconst_tail;
2973 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
2974
2975 #if SUPPORT_LONG_CMP_CONST
2976                                                         case ICMD_LCMP:
2977                                                                 if ((len <= 1) || (iptr[2].sx.val.i != 0))
2978                                                                         goto normal_LCONST;
2979
2980                                                                 /* switch on the instruction after LCONST - LCMP */
2981
2982                                                                 switch (iptr[2].opc) {
2983                                                                         case ICMD_IFEQ:
2984                                                                                 iptr->opc = ICMD_IF_LEQ;
2985                                                                                 /* FALLTHROUGH */
2986
2987                                                                         icmd_lconst_lcmp_tail:
2988                                                                                 /* convert LCONST, LCMP, IFXX to IF_LXX */
2989                                                                                 iptr->dst.insindex = iptr[2].dst.insindex;
2990                                                                                 iptr[1].opc = ICMD_NOP;
2991                                                                                 iptr[2].opc = ICMD_NOP;
2992
2993                                                                                 OP1_BRANCH(TYPE_LNG);
2994                                                                                 BRANCH(tbptr);
2995                                                                                 COUNT(count_pcmd_bra);
2996                                                                                 COUNT(count_pcmd_op);
2997                                                                                 break;
2998
2999                                                                         case ICMD_IFNE:
3000                                                                                 iptr->opc = ICMD_IF_LNE;
3001                                                                                 goto icmd_lconst_lcmp_tail;
3002
3003                                                                         case ICMD_IFLT:
3004                                                                                 iptr->opc = ICMD_IF_LLT;
3005                                                                                 goto icmd_lconst_lcmp_tail;
3006
3007                                                                         case ICMD_IFGT:
3008                                                                                 iptr->opc = ICMD_IF_LGT;
3009                                                                                 goto icmd_lconst_lcmp_tail;
3010
3011                                                                         case ICMD_IFLE:
3012                                                                                 iptr->opc = ICMD_IF_LLE;
3013                                                                                 goto icmd_lconst_lcmp_tail;
3014
3015                                                                         case ICMD_IFGE:
3016                                                                                 iptr->opc = ICMD_IF_LGE;
3017                                                                                 goto icmd_lconst_lcmp_tail;
3018
3019                                                                         default:
3020                                                                                 goto normal_LCONST;
3021                                                                 } /* end switch on opcode after LCONST - LCMP */
3022                                                                 break;
3023 #endif /* SUPPORT_LONG_CMP_CONST */
3024
3025 #if SUPPORT_CONST_STORE
3026                                                         case ICMD_LASTORE:
3027 # if SUPPORT_CONST_STORE_ZERO_ONLY
3028                                                                 if (iptr->sx.val.l != 0)
3029                                                                         goto normal_LCONST;
3030 # endif
3031 #if SIZEOF_VOID_P == 4
3032                                                                 /* the constant must fit into a ptrint */
3033                                                                 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
3034                                                                         goto normal_LCONST;
3035 #endif
3036                                                                 /* move the constant to s3 */
3037                                                                 iptr->sx.s23.s3.constval = iptr->sx.val.l;
3038
3039                                                                 iptr->opc = ICMD_LASTORECONST;
3040                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3041                                                                 OP2_0(TYPE_ADR, TYPE_INT);
3042
3043                                                                 iptr[1].opc = ICMD_NOP;
3044                                                                 COUNT(count_pcmd_op);
3045                                                                 break;
3046
3047                                                         case ICMD_PUTSTATIC:
3048                                                         case ICMD_PUTFIELD:
3049 # if SUPPORT_CONST_STORE_ZERO_ONLY
3050                                                                 if (iptr->sx.val.l != 0)
3051                                                                         goto normal_LCONST;
3052 # endif
3053 #if SIZEOF_VOID_P == 4
3054                                                                 /* the constant must fit into a ptrint */
3055                                                                 if (iptr->sx.val.l < -0x80000000L || iptr->sx.val.l >= 0x80000000L)
3056                                                                         goto normal_LCONST;
3057 #endif
3058                                                                 /* XXX check field type? */
3059
3060                                                                 /* copy the constant to s2 */
3061                                                                 /* XXX constval -> fieldconstval? */
3062                                                                 iptr->sx.s23.s2.constval = iptr->sx.val.l;
3063
3064                                                                 goto putconst_tail;
3065
3066 #endif /* SUPPORT_CONST_STORE */
3067
3068                                                         default:
3069                                                                 goto normal_LCONST;
3070                                                 } /* end switch opcode after LCONST */
3071
3072                                                 /* if we get here, the LCONST has been optimized */
3073                                                 break;
3074
3075 normal_LCONST:
3076                                                 /* the normal case of an unoptimized LCONST */
3077                                                 OP0_1(TYPE_LNG);
3078                                                 break;
3079
3080         /************************ END OF LCONST OPTIMIZATIONS *********************/
3081
3082                                         case ICMD_FCONST:
3083                                                 COUNT(count_pcmd_load);
3084                                                 OP0_1(TYPE_FLT);
3085                                                 break;
3086
3087                                         case ICMD_DCONST:
3088                                                 COUNT(count_pcmd_load);
3089                                                 OP0_1(TYPE_DBL);
3090                                                 break;
3091
3092         /************************** ACONST OPTIMIZATIONS **************************/
3093
3094                                         case ICMD_ACONST:
3095                                                 coalescing_boundary = sd.new;
3096                                                 COUNT(count_pcmd_load);
3097 #if SUPPORT_CONST_STORE
3098                                                 /* We can only optimize if the ACONST is resolved
3099                                                  * and there is an instruction after it. */
3100
3101                                                 if ((len == 0) || (iptr->flags.bits & INS_FLAG_UNRESOLVED))
3102                                                         goto normal_ACONST;
3103
3104                                                 switch (iptr[1].opc) {
3105                                                         case ICMD_AASTORE:
3106                                                                 /* We can only optimize for NULL values
3107                                                                  * here because otherwise a checkcast is
3108                                                                  * required. */
3109                                                                 if (iptr->sx.val.anyptr != NULL)
3110                                                                         goto normal_ACONST;
3111
3112                                                                 /* copy the constant (NULL) to s3 */
3113                                                                 iptr->sx.s23.s3.constval = 0;
3114                                                                 iptr->opc = ICMD_AASTORECONST;
3115                                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3116                                                                 OP2_0(TYPE_ADR, TYPE_INT);
3117
3118                                                                 iptr[1].opc = ICMD_NOP;
3119                                                                 COUNT(count_pcmd_op);
3120                                                                 break;
3121
3122                                                         case ICMD_PUTSTATIC:
3123                                                         case ICMD_PUTFIELD:
3124 # if SUPPORT_CONST_STORE_ZERO_ONLY
3125                                                                 if (iptr->sx.val.anyptr != NULL)
3126                                                                         goto normal_ACONST;
3127 # endif
3128                                                                 /* XXX check field type? */
3129                                                                 /* copy the constant to s2 */
3130                                                                 /* XXX constval -> fieldconstval? */
3131                                                                 iptr->sx.s23.s2.constval = (ptrint) iptr->sx.val.anyptr;
3132
3133                                                                 goto putconst_tail;
3134
3135                                                         default:
3136                                                                 goto normal_ACONST;
3137                                                 }
3138
3139                                                 /* if we get here the ACONST has been optimized */
3140                                                 break;
3141
3142 normal_ACONST:
3143 #endif /* SUPPORT_CONST_STORE */
3144                                                 OP0_1(TYPE_ADR);
3145                                                 break;
3146
3147
3148                                                 /* pop 0 push 1 load */
3149
3150                                         case ICMD_ILOAD:
3151                                         case ICMD_LLOAD:
3152                                         case ICMD_FLOAD:
3153                                         case ICMD_DLOAD:
3154                                         case ICMD_ALOAD:
3155                                                 COUNT(count_load_instruction);
3156                                                 i = opcode - ICMD_ILOAD; /* type */
3157
3158                                                 j = iptr->s1.varindex = 
3159                                                         jd->local_map[iptr->s1.varindex * 5 + i];
3160
3161 #if defined(ENABLE_VERIFIER)
3162                                                 if (sd.var[j].type == TYPE_RET) {
3163                                                         exceptions_throw_verifyerror(m, "forbidden load of returnAddress");
3164                                                         return false;
3165                                                 }
3166 #endif
3167                 
3168 #if defined(ENABLE_SSA)
3169                                                 if (ls != NULL) {
3170                                                         GET_NEW_VAR(sd, new_index, i);
3171                                                         DST(i, new_index);
3172                                                         stackdepth++;
3173                                                 }
3174                                                 else
3175
3176 #else
3177                                                 LOAD(i, j);
3178 #endif
3179                                                 break;
3180
3181                                                 /* pop 2 push 1 */
3182
3183                                         case ICMD_LALOAD:
3184                                         case ICMD_FALOAD:
3185                                         case ICMD_DALOAD:
3186                                         case ICMD_AALOAD:
3187                                                 coalescing_boundary = sd.new;
3188                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3189                                                 COUNT(count_check_null);
3190                                                 COUNT(count_check_bound);
3191                                                 COUNT(count_pcmd_mem);
3192                                                 OP2_1(TYPE_ADR, TYPE_INT, opcode - ICMD_IALOAD);
3193                                                 break;
3194
3195                                         case ICMD_IALOAD:
3196                                         case ICMD_BALOAD:
3197                                         case ICMD_CALOAD:
3198                                         case ICMD_SALOAD:
3199                                                 coalescing_boundary = sd.new;
3200                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3201                                                 COUNT(count_check_null);
3202                                                 COUNT(count_check_bound);
3203                                                 COUNT(count_pcmd_mem);
3204                                                 OP2_1(TYPE_ADR, TYPE_INT, TYPE_INT);
3205                                                 break;
3206
3207                                                 /* pop 0 push 0 iinc */
3208
3209                                         case ICMD_IINC:
3210                                                 STATISTICS_STACKDEPTH_DISTRIBUTION(count_store_depth);
3211 #if defined(ENABLE_SSA)
3212                                                 if (ls != NULL) {
3213                                                         iptr->s1.varindex = 
3214                                                                 jd->local_map[iptr->s1.varindex * 5 +TYPE_INT];
3215                                                 }
3216                                                 else {
3217 #endif
3218                                                 last_store_boundary[iptr->s1.varindex] = sd.new;
3219
3220                                                 iptr->s1.varindex = 
3221                                                         jd->local_map[iptr->s1.varindex * 5 + TYPE_INT];
3222
3223                                                 copy = curstack;
3224                                                 i = stackdepth - 1;
3225                                                 while (copy) {
3226                                                         if ((copy->varkind == LOCALVAR) &&
3227                                                                 (copy->varnum == iptr->s1.varindex))
3228                                                         {
3229                                                                 assert(IS_LOCALVAR(copy));
3230                                                                 SET_TEMPVAR(copy);
3231                                                         }
3232                                                         i--;
3233                                                         copy = copy->prev;
3234                                                 }
3235 #if defined(ENABLE_SSA)
3236                                                 }
3237 #endif
3238
3239                                                 iptr->dst.varindex = iptr->s1.varindex;
3240                                                 break;
3241
3242                                                 /* pop 1 push 0 store */
3243
3244                                         case ICMD_ISTORE:
3245                                         case ICMD_LSTORE:
3246                                         case ICMD_FSTORE:
3247                                         case ICMD_DSTORE:
3248                                         case ICMD_ASTORE:
3249                                                 REQUIRE(1);
3250
3251                                                 i = opcode - ICMD_ISTORE; /* type */
3252                                                 javaindex = iptr->dst.varindex;
3253                                                 j = iptr->dst.varindex = 
3254                                                         jd->local_map[javaindex * 5 + i];
3255
3256                                                 COPY_VAL_AND_TYPE(sd, curstack->varnum, j);
3257
3258                                                 iptr->sx.s23.s3.javaindex = javaindex;
3259
3260                                                 if (curstack->type == TYPE_RET) {
3261                                                         iptr->flags.bits |= INS_FLAG_RETADDR;
3262                                                         iptr->sx.s23.s2.retaddrnr = 
3263                                                                 UNUSED - (1 + sd.var[j].vv.retaddr->nr);
3264                                                         sd.javalocals[javaindex] = iptr->sx.s23.s2.retaddrnr;
3265                                                 }
3266                                                 else
3267                                                         sd.javalocals[javaindex] = j;
3268
3269                                                 /* invalidate the following javalocal for 2-word types */
3270
3271                                                 if (IS_2_WORD_TYPE(i)) {
3272                                                         sd.javalocals[javaindex+1] = UNUSED;
3273                                                         iptr->flags.bits |= INS_FLAG_KILL_NEXT;
3274                                                 }
3275
3276                                                 /* invalidate 2-word types if second half was overwritten */
3277
3278                                                 if (javaindex > 0 && (i = sd.javalocals[javaindex-1]) != UNUSED) {
3279                                                         if (IS_2_WORD_TYPE(sd.var[i].type)) {
3280                                                                 sd.javalocals[javaindex-1] = UNUSED;
3281                                                                 iptr->flags.bits |= INS_FLAG_KILL_PREV;
3282                                                         }
3283                                                 }
3284
3285 #if defined(ENABLE_STATISTICS)
3286                                                 if (opt_stat) {
3287                                                         count_pcmd_store++;
3288                                                         i = sd.new - curstack;
3289                                                         if (i >= 20)
3290                                                                 count_store_length[20]++;
3291                                                         else
3292                                                                 count_store_length[i]++;
3293                                                         i = stackdepth - 1;
3294                                                         if (i >= 10)
3295                                                                 count_store_depth[10]++;
3296                                                         else
3297                                                                 count_store_depth[i]++;
3298                                                 }
3299 #endif
3300
3301 #if defined(ENABLE_SSA)
3302                                                 if (ls != NULL) {
3303 #endif
3304                                                 /* check for conflicts as described in Figure 5.2 */
3305
3306                                                 copy = curstack->prev;
3307                                                 i = stackdepth - 2;
3308                                                 while (copy) {
3309                                                         if ((copy->varkind == LOCALVAR) &&
3310                                                                 (copy->varnum == j))
3311                                                         {
3312                                                                 copy->varkind = TEMPVAR;
3313                                                                 assert(IS_LOCALVAR(copy));
3314                                                                 SET_TEMPVAR(copy);
3315                                                         }
3316                                                         i--;
3317                                                         copy = copy->prev;
3318                                                 }
3319
3320                                                 /* if the variable is already coalesced, don't bother */
3321
3322                                                 /* We do not need to check against INOUT, as invars */
3323                                                 /* are always before the coalescing boundary.        */
3324
3325                                                 if (curstack->varkind == LOCALVAR)
3326                                                         goto store_tail;
3327
3328                                                 /* there is no STORE Lj while curstack is live */
3329
3330                                                 if (curstack < last_store_boundary[javaindex])
3331                                                         goto assume_conflict;
3332
3333                                                 /* curstack must be after the coalescing boundary */
3334
3335                                                 if (curstack < coalescing_boundary)
3336                                                         goto assume_conflict;
3337
3338                                                 /* there is no DEF LOCALVAR(j) while curstack is live */
3339
3340                                                 copy = sd.new; /* most recent stackslot created + 1 */
3341                                                 while (--copy > curstack) {
3342                                                         if (copy->varkind == LOCALVAR && copy->varnum == j)
3343                                                                 goto assume_conflict;
3344                                                 }
3345
3346                                                 /* coalesce the temporary variable with Lj */
3347                                                 assert((curstack->varkind == TEMPVAR)
3348                                                                         || (curstack->varkind == UNDEFVAR));
3349                                                 assert(!IS_LOCALVAR(curstack)); /* XXX correct? */
3350                                                 assert(!IS_INOUT(curstack));
3351                                                 assert(!IS_PREALLOC(curstack));
3352
3353                                                 assert(curstack->creator);
3354                                                 assert(curstack->creator->dst.varindex == curstack->varnum);
3355                                                 assert(!(curstack->flags & PASSTHROUGH));
3356                                                 RELEASE_INDEX(sd, curstack);
3357                                                 curstack->varkind = LOCALVAR;
3358                                                 curstack->varnum = j;
3359                                                 curstack->creator->dst.varindex = j;
3360                                                 goto store_tail;
3361
3362                                                 /* revert the coalescing, if it has been done earlier */
3363 assume_conflict:
3364                                                 if ((curstack->varkind == LOCALVAR)
3365                                                         && (curstack->varnum == j))
3366                                                 {
3367                                                         assert(IS_LOCALVAR(curstack));
3368                                                         SET_TEMPVAR(curstack);
3369                                                 }
3370
3371                                                 /* remember the stack boundary at this store */
3372 store_tail:
3373                                                 last_store_boundary[javaindex] = sd.new;
3374 #if defined(ENABLE_SSA)
3375                                                 } /* if (ls != NULL) */
3376 #endif
3377
3378                                                 if (opcode == ICMD_ASTORE && curstack->type == TYPE_RET)
3379                                                         STORE(TYPE_RET, j);
3380                                                 else
3381                                                         STORE(opcode - ICMD_ISTORE, j);
3382                                                 break;
3383
3384                                         /* pop 3 push 0 */
3385
3386                                         case ICMD_AASTORE:
3387                                                 coalescing_boundary = sd.new;
3388                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3389                                                 COUNT(count_check_null);
3390                                                 COUNT(count_check_bound);
3391                                                 COUNT(count_pcmd_mem);
3392
3393                                                 bte = builtintable_get_internal(BUILTIN_canstore);
3394                                                 md = bte->md;
3395
3396                                                 if (md->memuse > rd->memuse)
3397                                                         rd->memuse = md->memuse;
3398                                                 if (md->argintreguse > rd->argintreguse)
3399                                                         rd->argintreguse = md->argintreguse;
3400                                                 /* XXX non-leaf method? */
3401
3402                                                 /* make all stack variables saved */
3403
3404                                                 copy = curstack;
3405                                                 while (copy) {
3406                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
3407                                                         /* in case copy->varnum is/will be a LOCALVAR */
3408                                                         /* once and set back to a non LOCALVAR        */
3409                                                         /* the correct SAVEDVAR flag has to be        */
3410                                                         /* remembered in copy->flags, too             */
3411                                                         copy->flags |= SAVEDVAR;
3412                                                         copy = copy->prev;
3413                                                 }
3414
3415                                                 OP3_0(TYPE_ADR, TYPE_INT, TYPE_ADR);
3416                                                 break;
3417
3418
3419                                         case ICMD_LASTORE:
3420                                         case ICMD_FASTORE:
3421                                         case ICMD_DASTORE:
3422                                                 coalescing_boundary = sd.new;
3423                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3424                                                 COUNT(count_check_null);
3425                                                 COUNT(count_check_bound);
3426                                                 COUNT(count_pcmd_mem);
3427                                                 OP3_0(TYPE_ADR, TYPE_INT, opcode - ICMD_IASTORE);
3428                                                 break;
3429
3430                                         case ICMD_IASTORE:
3431                                         case ICMD_BASTORE:
3432                                         case ICMD_CASTORE:
3433                                         case ICMD_SASTORE:
3434                                                 coalescing_boundary = sd.new;
3435                                                 iptr->flags.bits |= INS_FLAG_CHECK;
3436                                                 COUNT(count_check_null);
3437                                                 COUNT(count_check_bound);
3438                                                 COUNT(count_pcmd_mem);
3439                                                 OP3_0(TYPE_ADR, TYPE_INT, TYPE_INT);
3440                                                 break;
3441
3442                                                 /* pop 1 push 0 */
3443
3444                                         case ICMD_POP:
3445 #ifdef ENABLE_VERIFIER
3446                                                 if (opt_verify) {
3447                                                         REQUIRE(1);
3448                                                         if (IS_2_WORD_TYPE(curstack->type))
3449                                                                 goto throw_stack_category_error;
3450                                                 }
3451 #endif
3452                                                 OP1_0_ANY;
3453                                                 break;
3454
3455                                         case ICMD_IRETURN:
3456                                         case ICMD_LRETURN:
3457                                         case ICMD_FRETURN:
3458                                         case ICMD_DRETURN:
3459                                         case ICMD_ARETURN:
3460                                                 coalescing_boundary = sd.new;
3461                                                 /* Assert here that no LOCAL or INOUTS get */
3462                                                 /* preallocated, since tha macros are not   */
3463                                                 /* available in md-abi.c! */
3464                                                 if (IS_TEMPVAR(curstack))
3465                                                         md_return_alloc(jd, curstack);
3466                                                 COUNT(count_pcmd_return);
3467                                                 OP1_0(opcode - ICMD_IRETURN);
3468                                                 superblockend = true;
3469                                                 sd.jd->returncount++;
3470                                                 sd.jd->returnblock = sd.bptr;
3471                                                 break;
3472
3473                                         case ICMD_ATHROW:
3474                                                 coalescing_boundary = sd.new;
3475                                                 COUNT(count_check_null);
3476                                                 OP1_0(TYPE_ADR);
3477                                                 curstack = NULL; stackdepth = 0;
3478                                                 superblockend = true;
3479                                                 break;
3480
3481                                         case ICMD_PUTSTATIC:
3482                                                 coalescing_boundary = sd.new;
3483                                                 COUNT(count_pcmd_mem);
3484                                                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
3485                                                 OP1_0(fmiref->parseddesc.fd->type);
3486                                                 break;
3487
3488                                                 /* pop 1 push 0 branch */
3489
3490                                         case ICMD_IFNULL:
3491                                         case ICMD_IFNONNULL:
3492                                                 COUNT(count_pcmd_bra);
3493                                                 OP1_BRANCH(TYPE_ADR);
3494                                                 BRANCH(tbptr);
3495                                                 break;
3496
3497                                         case ICMD_IFEQ:
3498                                         case ICMD_IFNE:
3499                                         case ICMD_IFLT:
3500                                         case ICMD_IFGE:
3501                                         case ICMD_IFGT:
3502                                         case ICMD_IFLE:
3503                                                 COUNT(count_pcmd_bra);
3504                                                 /* iptr->sx.val.i is set implicitly in parse by
3505                                                    clearing the memory or from IF_ICMPxx
3506                                                    optimization. */
3507
3508                                                 OP1_BRANCH(TYPE_INT);
3509 /*                                              iptr->sx.val.i = 0; */
3510                                                 BRANCH(tbptr);
3511                                                 break;
3512
3513                                                 /* pop 0 push 0 branch */
3514
3515                                         case ICMD_GOTO:
3516                                                 COUNT(count_pcmd_bra);
3517                                                 OP0_BRANCH;
3518                                                 BRANCH(tbptr);
3519                                                 superblockend = true;
3520                                                 break;
3521
3522                                                 /* pop 1 push 0 table branch */
3523
3524                                         case ICMD_TABLESWITCH:
3525                                                 COUNT(count_pcmd_table);
3526                                                 OP1_BRANCH(TYPE_INT);
3527
3528                                                 table = iptr->dst.table;
3529                                                 BRANCH_TARGET(*table, tbptr);
3530                                                 table++;
3531
3532                                                 i = iptr->sx.s23.s3.tablehigh
3533                                                   - iptr->sx.s23.s2.tablelow + 1;
3534
3535                                                 while (--i >= 0) {
3536                                                         BRANCH_TARGET(*table, tbptr);
3537                                                         table++;
3538                                                 }
3539                                                 superblockend = true;
3540                                                 break;
3541
3542                                                 /* pop 1 push 0 table branch */
3543
3544                                         case ICMD_LOOKUPSWITCH:
3545                                                 COUNT(count_pcmd_table);
3546                                                 OP1_BRANCH(TYPE_INT);
3547
3548                                                 BRANCH_TARGET(iptr->sx.s23.s3.lookupdefault, tbptr);
3549
3550                                                 lookup = iptr->dst.lookup;
3551
3552                                                 i = iptr->sx.s23.s2.lookupcount;
3553
3554                                                 while (--i >= 0) {
3555                                                         BRANCH_TARGET(lookup->target, tbptr);
3556                                                         lookup++;
3557                                                 }
3558                                                 superblockend = true;
3559                                                 break;
3560
3561                                         case ICMD_MONITORENTER:
3562                                         case ICMD_MONITOREXIT:
3563                                                 coalescing_boundary = sd.new;
3564                                                 COUNT(count_check_null);
3565                                                 OP1_0(TYPE_ADR);
3566                                                 break;
3567
3568                                                 /* pop 2 push 0 branch */
3569
3570                                         case ICMD_IF_ICMPEQ:
3571                                         case ICMD_IF_ICMPNE:
3572                                         case ICMD_IF_ICMPLT:
3573                                         case ICMD_IF_ICMPGE:
3574                                         case ICMD_IF_ICMPGT:
3575                                         case ICMD_IF_ICMPLE:
3576                                                 COUNT(count_pcmd_bra);
3577                                                 OP2_BRANCH(TYPE_INT, TYPE_INT);
3578                                                 BRANCH(tbptr);
3579                                                 break;
3580
3581                                         case ICMD_IF_ACMPEQ:
3582                                         case ICMD_IF_ACMPNE:
3583                                                 COUNT(count_pcmd_bra);
3584                                                 OP2_BRANCH(TYPE_ADR, TYPE_ADR);
3585                                                 BRANCH(tbptr);
3586                                                 break;
3587
3588                                                 /* pop 2 push 0 */
3589
3590                                         case ICMD_PUTFIELD:
3591                                                 coalescing_boundary = sd.new;
3592                                                 COUNT(count_check_null);
3593                                                 COUNT(count_pcmd_mem);
3594                                                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
3595                                                 OP2_0(TYPE_ADR, fmiref->parseddesc.fd->type);
3596                                                 break;
3597
3598                                         case ICMD_POP2:
3599                                                 REQUIRE(1);
3600                                                 if (!IS_2_WORD_TYPE(curstack->type)) {
3601                                                         /* ..., cat1 */
3602 #ifdef ENABLE_VERIFIER
3603                                                         if (opt_verify) {
3604                                                                 REQUIRE(2);
3605                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
3606                                                                         goto throw_stack_category_error;
3607                                                         }
3608 #endif
3609                                                         OP2_0_ANY_ANY; /* pop two slots */
3610                                                 }
3611                                                 else {
3612                                                         iptr->opc = ICMD_POP;
3613                                                         OP1_0_ANY; /* pop one (two-word) slot */
3614                                                 }
3615                                                 break;
3616
3617                                                 /* pop 0 push 1 dup */
3618
3619                                         case ICMD_DUP:
3620 #ifdef ENABLE_VERIFIER
3621                                                 if (opt_verify) {
3622                                                         REQUIRE(1);
3623                                                         if (IS_2_WORD_TYPE(curstack->type))
3624                                                                 goto throw_stack_category_error;
3625                                                 }
3626 #endif
3627                                                 COUNT(count_dup_instruction);
3628
3629 icmd_DUP:
3630                                                 src1 = curstack;
3631
3632                                                 COPY_UP(src1);
3633                                                 coalescing_boundary = sd.new - 1;
3634                                                 break;
3635
3636                                         case ICMD_DUP2:
3637                                                 REQUIRE(1);
3638                                                 if (IS_2_WORD_TYPE(curstack->type)) {
3639                                                         /* ..., cat2 */
3640                                                         iptr->opc = ICMD_DUP;
3641                                                         goto icmd_DUP;
3642                                                 }
3643                                                 else {
3644                                                         REQUIRE(2);
3645                                                         /* ..., ????, cat1 */
3646 #ifdef ENABLE_VERIFIER
3647                                                         if (opt_verify) {
3648                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
3649                                                                         goto throw_stack_category_error;
3650                                                         }
3651 #endif
3652                                                         src1 = curstack->prev;
3653                                                         src2 = curstack;
3654
3655                                                         COPY_UP(src1); iptr++; len--;
3656                                                         COPY_UP(src2);
3657
3658                                                         coalescing_boundary = sd.new;
3659                                                 }
3660                                                 break;
3661
3662                                                 /* pop 2 push 3 dup */
3663
3664                                         case ICMD_DUP_X1:
3665 #ifdef ENABLE_VERIFIER
3666                                                 if (opt_verify) {
3667                                                         REQUIRE(2);
3668                                                         if (IS_2_WORD_TYPE(curstack->type) ||
3669                                                                 IS_2_WORD_TYPE(curstack->prev->type))
3670                                                                         goto throw_stack_category_error;
3671                                                 }
3672 #endif
3673
3674 icmd_DUP_X1:
3675                                                 src1 = curstack->prev;
3676                                                 src2 = curstack;
3677                                                 POPANY; POPANY;
3678                                                 stackdepth -= 2;
3679
3680                                                 /* move non-temporary sources out of the way */
3681                                                 if (!IS_TEMPVAR(src2)) {
3682                                                         MOVE_TO_TEMP(src2); iptr++; len--;
3683                                                 }
3684
3685                                                 DUP_SLOT(src2); dst1 = curstack; stackdepth++;
3686
3687                                                 MOVE_UP(src1); iptr++; len--;
3688                                                 MOVE_UP(src2); iptr++; len--;
3689
3690                                                 COPY_DOWN(curstack, dst1);
3691
3692                                                 coalescing_boundary = sd.new;
3693                                                 break;
3694
3695                                         case ICMD_DUP2_X1:
3696                                                 REQUIRE(2);
3697                                                 if (IS_2_WORD_TYPE(curstack->type)) {
3698                                                         /* ..., ????, cat2 */
3699 #ifdef ENABLE_VERIFIER
3700                                                         if (opt_verify) {
3701                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
3702                                                                         goto throw_stack_category_error;
3703                                                         }
3704 #endif
3705                                                         iptr->opc = ICMD_DUP_X1;
3706                                                         goto icmd_DUP_X1;
3707                                                 }
3708                                                 else {
3709                                                         /* ..., ????, cat1 */
3710 #ifdef ENABLE_VERIFIER
3711                                                         if (opt_verify) {
3712                                                                 REQUIRE(3);
3713                                                                 if (IS_2_WORD_TYPE(curstack->prev->type)
3714                                                                         || IS_2_WORD_TYPE(curstack->prev->prev->type))
3715                                                                                 goto throw_stack_category_error;
3716                                                         }
3717 #endif
3718
3719 icmd_DUP2_X1:
3720                                                         src1 = curstack->prev->prev;
3721                                                         src2 = curstack->prev;
3722                                                         src3 = curstack;
3723                                                         POPANY; POPANY; POPANY;
3724                                                         stackdepth -= 3;
3725
3726                                                         /* move non-temporary sources out of the way */
3727                                                         if (!IS_TEMPVAR(src2)) {
3728                                                                 MOVE_TO_TEMP(src2); iptr++; len--;
3729                                                         }
3730                                                         if (!IS_TEMPVAR(src3)) {
3731                                                                 MOVE_TO_TEMP(src3); iptr++; len--;
3732                                                         }
3733
3734                                                         DUP_SLOT(src2); dst1 = curstack; stackdepth++;
3735                                                         DUP_SLOT(src3); dst2 = curstack; stackdepth++;
3736
3737                                                         MOVE_UP(src1); iptr++; len--;
3738                                                         MOVE_UP(src2); iptr++; len--;
3739                                                         MOVE_UP(src3); iptr++; len--;
3740
3741                                                         COPY_DOWN(curstack, dst2); iptr++; len--;
3742                                                         COPY_DOWN(curstack->prev, dst1);
3743
3744                                                         coalescing_boundary = sd.new;
3745                                                 }
3746                                                 break;
3747
3748                                                 /* pop 3 push 4 dup */
3749
3750                                         case ICMD_DUP_X2:
3751                                                 REQUIRE(2);
3752                                                 if (IS_2_WORD_TYPE(curstack->prev->type)) {
3753                                                         /* ..., cat2, ???? */
3754 #ifdef ENABLE_VERIFIER
3755                                                         if (opt_verify) {
3756                                                                 if (IS_2_WORD_TYPE(curstack->type))
3757                                                                         goto throw_stack_category_error;
3758                                                         }
3759 #endif
3760                                                         iptr->opc = ICMD_DUP_X1;
3761                                                         goto icmd_DUP_X1;
3762                                                 }
3763                                                 else {
3764                                                         /* ..., cat1, ???? */
3765 #ifdef ENABLE_VERIFIER
3766                                                         if (opt_verify) {
3767                                                                 REQUIRE(3);
3768                                                                 if (IS_2_WORD_TYPE(curstack->type)
3769                                                                         || IS_2_WORD_TYPE(curstack->prev->prev->type))
3770                                                                                         goto throw_stack_category_error;
3771                                                         }
3772 #endif
3773 icmd_DUP_X2:
3774                                                         src1 = curstack->prev->prev;
3775                                                         src2 = curstack->prev;
3776                                                         src3 = curstack;
3777                                                         POPANY; POPANY; POPANY;
3778                                                         stackdepth -= 3;
3779
3780                                                         /* move non-temporary sources out of the way */
3781                                                         if (!IS_TEMPVAR(src2)) {
3782                                                                 MOVE_TO_TEMP(src2); iptr++; len--;
3783                                                         }
3784                                                         if (!IS_TEMPVAR(src3)) {
3785                                                                 MOVE_TO_TEMP(src3); iptr++; len--;
3786                                                         }
3787
3788                                                         DUP_SLOT(src3); dst1 = curstack; stackdepth++;
3789
3790                                                         MOVE_UP(src1); iptr++; len--;
3791                                                         MOVE_UP(src2); iptr++; len--;
3792                                                         MOVE_UP(src3); iptr++; len--;
3793
3794                                                         COPY_DOWN(curstack, dst1);
3795
3796                                                         coalescing_boundary = sd.new;
3797                                                 }
3798                                                 break;
3799
3800                                         case ICMD_DUP2_X2:
3801                                                 REQUIRE(2);
3802                                                 if (IS_2_WORD_TYPE(curstack->type)) {
3803                                                         /* ..., ????, cat2 */
3804                                                         if (IS_2_WORD_TYPE(curstack->prev->type)) {
3805                                                                 /* ..., cat2, cat2 */
3806                                                                 iptr->opc = ICMD_DUP_X1;
3807                                                                 goto icmd_DUP_X1;
3808                                                         }
3809                                                         else {
3810                                                                 /* ..., cat1, cat2 */
3811 #ifdef ENABLE_VERIFIER
3812                                                                 if (opt_verify) {
3813                                                                         REQUIRE(3);
3814                                                                         if (IS_2_WORD_TYPE(curstack->prev->prev->type))
3815                                                                                         goto throw_stack_category_error;
3816                                                                 }
3817 #endif
3818                                                                 iptr->opc = ICMD_DUP_X2;
3819                                                                 goto icmd_DUP_X2;
3820                                                         }
3821                                                 }
3822
3823                                                 REQUIRE(3);
3824                                                 /* ..., ????, ????, cat1 */
3825
3826                                                 if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
3827                                                         /* ..., cat2, ????, cat1 */
3828 #ifdef ENABLE_VERIFIER
3829                                                         if (opt_verify) {
3830                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
3831                                                                         goto throw_stack_category_error;
3832                                                         }
3833 #endif
3834                                                         iptr->opc = ICMD_DUP2_X1;
3835                                                         goto icmd_DUP2_X1;
3836                                                 }
3837                                                 else {
3838                                                         /* ..., cat1, ????, cat1 */
3839 #ifdef ENABLE_VERIFIER
3840                                                         if (opt_verify) {
3841                                                                 REQUIRE(4);
3842                                                                 if (IS_2_WORD_TYPE(curstack->prev->type)
3843                                                                         || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
3844                                                                         goto throw_stack_category_error;
3845                                                         }
3846 #endif
3847
3848                                                         src1 = curstack->prev->prev->prev;
3849                                                         src2 = curstack->prev->prev;
3850                                                         src3 = curstack->prev;
3851                                                         src4 = curstack;
3852                                                         POPANY; POPANY; POPANY; POPANY;
3853                                                         stackdepth -= 4;
3854
3855                                                         /* move non-temporary sources out of the way */
3856                                                         if (!IS_TEMPVAR(src2)) {
3857                                                                 MOVE_TO_TEMP(src2); iptr++; len--;
3858                                                         }
3859                                                         if (!IS_TEMPVAR(src3)) {
3860                                                                 MOVE_TO_TEMP(src3); iptr++; len--;
3861                                                         }
3862                                                         if (!IS_TEMPVAR(src4)) {
3863                                                                 MOVE_TO_TEMP(src4); iptr++; len--;
3864                                                         }
3865
3866                                                         DUP_SLOT(src3); dst1 = curstack; stackdepth++;
3867                                                         DUP_SLOT(src4); dst2 = curstack; stackdepth++;
3868
3869                                                         MOVE_UP(src1); iptr++; len--;
3870                                                         MOVE_UP(src2); iptr++; len--;
3871                                                         MOVE_UP(src3); iptr++; len--;
3872                                                         MOVE_UP(src4); iptr++; len--;
3873
3874                                                         COPY_DOWN(curstack, dst2); iptr++; len--;
3875                                                         COPY_DOWN(curstack->prev, dst1);
3876
3877                                                         coalescing_boundary = sd.new;
3878                                                 }
3879                                                 break;
3880
3881                                                 /* pop 2 push 2 swap */
3882
3883                                         case ICMD_SWAP:
3884 #ifdef ENABLE_VERIFIER
3885                                                 if (opt_verify) {
3886                                                         REQUIRE(2);
3887                                                         if (IS_2_WORD_TYPE(curstack->type)
3888                                                                 || IS_2_WORD_TYPE(curstack->prev->type))
3889                                                                 goto throw_stack_category_error;
3890                                                 }
3891 #endif
3892
3893                                                 src1 = curstack->prev;
3894                                                 src2 = curstack;
3895                                                 POPANY; POPANY;
3896                                                 stackdepth -= 2;
3897
3898                                                 /* move non-temporary sources out of the way */
3899                                                 if (!IS_TEMPVAR(src1)) {
3900                                                         MOVE_TO_TEMP(src1); iptr++; len--;
3901                                                 }
3902
3903                                                 MOVE_UP(src2); iptr++; len--;
3904                                                 MOVE_UP(src1);
3905
3906                                                 coalescing_boundary = sd.new;
3907                                                 break;
3908
3909                                                 /* pop 2 push 1 */
3910
3911                                         case ICMD_IDIV:
3912                                         case ICMD_IREM:
3913                                                 coalescing_boundary = sd.new;
3914 #if !SUPPORT_DIVISION
3915                                                 bte = iptr->sx.s23.s3.bte;
3916                                                 md = bte->md;
3917
3918                                                 if (md->memuse > rd->memuse)
3919                                                         rd->memuse = md->memuse;
3920                                                 if (md->argintreguse > rd->argintreguse)
3921                                                         rd->argintreguse = md->argintreguse;
3922
3923                                                 /* make all stack variables saved */
3924
3925                                                 copy = curstack;
3926                                                 while (copy) {
3927                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
3928                                                         copy->flags |= SAVEDVAR;
3929                                                         copy = copy->prev;
3930                                                 }
3931                                                 /* FALLTHROUGH */
3932
3933 #endif /* !SUPPORT_DIVISION */
3934
3935                                         case ICMD_ISHL:
3936                                         case ICMD_ISHR:
3937                                         case ICMD_IUSHR:
3938                                         case ICMD_IADD:
3939                                         case ICMD_ISUB:
3940                                         case ICMD_IMUL:
3941                                         case ICMD_IAND:
3942                                         case ICMD_IOR:
3943                                         case ICMD_IXOR:
3944                                                 COUNT(count_pcmd_op);
3945                                                 OP2_1(TYPE_INT, TYPE_INT, TYPE_INT);
3946                                                 break;
3947
3948                                         case ICMD_LDIV:
3949                                         case ICMD_LREM:
3950                                                 coalescing_boundary = sd.new;
3951 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
3952                                                 bte = iptr->sx.s23.s3.bte;
3953                                                 md = bte->md;
3954
3955                                                 if (md->memuse > rd->memuse)
3956                                                         rd->memuse = md->memuse;
3957                                                 if (md->argintreguse > rd->argintreguse)
3958                                                         rd->argintreguse = md->argintreguse;
3959                                                 /* XXX non-leaf method? */
3960
3961                                                 /* make all stack variables saved */
3962
3963                                                 copy = curstack;
3964                                                 while (copy) {
3965                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
3966                                                         copy->flags |= SAVEDVAR;
3967                                                         copy = copy->prev;
3968                                                 }
3969                                                 /* FALLTHROUGH */
3970
3971 #endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
3972
3973                                         case ICMD_LMUL:
3974                                         case ICMD_LADD:
3975                                         case ICMD_LSUB:
3976 #if SUPPORT_LONG_LOGICAL
3977                                         case ICMD_LAND:
3978                                         case ICMD_LOR:
3979                                         case ICMD_LXOR:
3980 #endif /* SUPPORT_LONG_LOGICAL */
3981                                                 COUNT(count_pcmd_op);
3982                                                 OP2_1(TYPE_LNG, TYPE_LNG, TYPE_LNG);
3983                                                 break;
3984
3985                                         case ICMD_LSHL:
3986                                         case ICMD_LSHR:
3987                                         case ICMD_LUSHR:
3988                                                 COUNT(count_pcmd_op);
3989                                                 OP2_1(TYPE_LNG, TYPE_INT, TYPE_LNG);
3990                                                 break;
3991
3992                                         case ICMD_FADD:
3993                                         case ICMD_FSUB:
3994                                         case ICMD_FMUL:
3995                                         case ICMD_FDIV:
3996                                         case ICMD_FREM:
3997                                                 COUNT(count_pcmd_op);
3998                                                 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_FLT);
3999                                                 break;
4000
4001                                         case ICMD_DADD:
4002                                         case ICMD_DSUB:
4003                                         case ICMD_DMUL:
4004                                         case ICMD_DDIV:
4005                                         case ICMD_DREM:
4006                                                 COUNT(count_pcmd_op);
4007                                                 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_DBL);
4008                                                 break;
4009
4010                                         case ICMD_LCMP:
4011                                                 COUNT(count_pcmd_op);
4012 #if SUPPORT_LONG_CMP_CONST
4013                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
4014                                                         goto normal_LCMP;
4015
4016                                                 switch (iptr[1].opc) {
4017                                                 case ICMD_IFEQ:
4018                                                         iptr->opc = ICMD_IF_LCMPEQ;
4019                                                 icmd_lcmp_if_tail:
4020                                                         iptr->dst.insindex = iptr[1].dst.insindex;
4021                                                         iptr[1].opc = ICMD_NOP;
4022
4023                                                         OP2_BRANCH(TYPE_LNG, TYPE_LNG);
4024                                                         BRANCH(tbptr);
4025
4026                                                         COUNT(count_pcmd_bra);
4027                                                         break;
4028                                                 case ICMD_IFNE:
4029                                                         iptr->opc = ICMD_IF_LCMPNE;
4030                                                         goto icmd_lcmp_if_tail;
4031                                                 case ICMD_IFLT:
4032                                                         iptr->opc = ICMD_IF_LCMPLT;
4033                                                         goto icmd_lcmp_if_tail;
4034                                                 case ICMD_IFGT:
4035                                                         iptr->opc = ICMD_IF_LCMPGT;
4036                                                         goto icmd_lcmp_if_tail;
4037                                                 case ICMD_IFLE:
4038                                                         iptr->opc = ICMD_IF_LCMPLE;
4039                                                         goto icmd_lcmp_if_tail;
4040                                                 case ICMD_IFGE:
4041                                                         iptr->opc = ICMD_IF_LCMPGE;
4042                                                         goto icmd_lcmp_if_tail;
4043                                                 default:
4044                                                         goto normal_LCMP;
4045                                                 }
4046                                                 break;
4047 normal_LCMP:
4048 #endif /* SUPPORT_LONG_CMP_CONST */
4049                                                         OP2_1(TYPE_LNG, TYPE_LNG, TYPE_INT);
4050                                                 break;
4051
4052                                                 /* XXX why is this deactivated? */
4053 #if 0
4054                                         case ICMD_FCMPL:
4055                                                 COUNT(count_pcmd_op);
4056                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
4057                                                         goto normal_FCMPL;
4058
4059                                                 switch (iptr[1].opc) {
4060                                                 case ICMD_IFEQ:
4061                                                         iptr->opc = ICMD_IF_FCMPEQ;
4062                                                 icmd_if_fcmpl_tail:
4063                                                         iptr->dst.insindex = iptr[1].dst.insindex;
4064                                                         iptr[1].opc = ICMD_NOP;
4065
4066                                                         OP2_BRANCH(TYPE_FLT, TYPE_FLT);
4067                                                         BRANCH(tbptr);
4068
4069                                                         COUNT(count_pcmd_bra);
4070                                                         break;
4071                                                 case ICMD_IFNE:
4072                                                         iptr->opc = ICMD_IF_FCMPNE;
4073                                                         goto icmd_if_fcmpl_tail;
4074                                                 case ICMD_IFLT:
4075                                                         iptr->opc = ICMD_IF_FCMPL_LT;
4076                                                         goto icmd_if_fcmpl_tail;
4077                                                 case ICMD_IFGT:
4078                                                         iptr->opc = ICMD_IF_FCMPL_GT;
4079                                                         goto icmd_if_fcmpl_tail;
4080                                                 case ICMD_IFLE:
4081                                                         iptr->opc = ICMD_IF_FCMPL_LE;
4082                                                         goto icmd_if_fcmpl_tail;
4083                                                 case ICMD_IFGE:
4084                                                         iptr->opc = ICMD_IF_FCMPL_GE;
4085                                                         goto icmd_if_fcmpl_tail;
4086                                                 default:
4087                                                         goto normal_FCMPL;
4088                                                 }
4089                                                 break;
4090
4091 normal_FCMPL:
4092                                                 OPTT2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
4093                                                 break;
4094
4095                                         case ICMD_FCMPG:
4096                                                 COUNT(count_pcmd_op);
4097                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
4098                                                         goto normal_FCMPG;
4099
4100                                                 switch (iptr[1].opc) {
4101                                                 case ICMD_IFEQ:
4102                                                         iptr->opc = ICMD_IF_FCMPEQ;
4103                                                 icmd_if_fcmpg_tail:
4104                                                         iptr->dst.insindex = iptr[1].dst.insindex;
4105                                                         iptr[1].opc = ICMD_NOP;
4106
4107                                                         OP2_BRANCH(TYPE_FLT, TYPE_FLT);
4108                                                         BRANCH(tbptr);
4109
4110                                                         COUNT(count_pcmd_bra);
4111                                                         break;
4112                                                 case ICMD_IFNE:
4113                                                         iptr->opc = ICMD_IF_FCMPNE;
4114                                                         goto icmd_if_fcmpg_tail;
4115                                                 case ICMD_IFLT:
4116                                                         iptr->opc = ICMD_IF_FCMPG_LT;
4117                                                         goto icmd_if_fcmpg_tail;
4118                                                 case ICMD_IFGT:
4119                                                         iptr->opc = ICMD_IF_FCMPG_GT;
4120                                                         goto icmd_if_fcmpg_tail;
4121                                                 case ICMD_IFLE:
4122                                                         iptr->opc = ICMD_IF_FCMPG_LE;
4123                                                         goto icmd_if_fcmpg_tail;
4124                                                 case ICMD_IFGE:
4125                                                         iptr->opc = ICMD_IF_FCMPG_GE;
4126                                                         goto icmd_if_fcmpg_tail;
4127                                                 default:
4128                                                         goto normal_FCMPG;
4129                                                 }
4130                                                 break;
4131
4132 normal_FCMPG:
4133                                                 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
4134                                                 break;
4135
4136                                         case ICMD_DCMPL:
4137                                                 COUNT(count_pcmd_op);
4138                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
4139                                                         goto normal_DCMPL;
4140
4141                                                 switch (iptr[1].opc) {
4142                                                 case ICMD_IFEQ:
4143                                                         iptr->opc = ICMD_IF_DCMPEQ;
4144                                                 icmd_if_dcmpl_tail:
4145                                                         iptr->dst.insindex = iptr[1].dst.insindex;
4146                                                         iptr[1].opc = ICMD_NOP;
4147
4148                                                         OP2_BRANCH(TYPE_DBL, TYPE_DBL);
4149                                                         BRANCH(tbptr);
4150
4151                                                         COUNT(count_pcmd_bra);
4152                                                         break;
4153                                                 case ICMD_IFNE:
4154                                                         iptr->opc = ICMD_IF_DCMPNE;
4155                                                         goto icmd_if_dcmpl_tail;
4156                                                 case ICMD_IFLT:
4157                                                         iptr->opc = ICMD_IF_DCMPL_LT;
4158                                                         goto icmd_if_dcmpl_tail;
4159                                                 case ICMD_IFGT:
4160                                                         iptr->opc = ICMD_IF_DCMPL_GT;
4161                                                         goto icmd_if_dcmpl_tail;
4162                                                 case ICMD_IFLE:
4163                                                         iptr->opc = ICMD_IF_DCMPL_LE;
4164                                                         goto icmd_if_dcmpl_tail;
4165                                                 case ICMD_IFGE:
4166                                                         iptr->opc = ICMD_IF_DCMPL_GE;
4167                                                         goto icmd_if_dcmpl_tail;
4168                                                 default:
4169                                                         goto normal_DCMPL;
4170                                                 }
4171                                                 break;
4172
4173 normal_DCMPL:
4174                                                 OPTT2_1(TYPE_DBL, TYPE_INT);
4175                                                 break;
4176
4177                                         case ICMD_DCMPG:
4178                                                 COUNT(count_pcmd_op);
4179                                                 if ((len == 0) || (iptr[1].sx.val.i != 0))
4180                                                         goto normal_DCMPG;
4181
4182                                                 switch (iptr[1].opc) {
4183                                                 case ICMD_IFEQ:
4184                                                         iptr->opc = ICMD_IF_DCMPEQ;
4185                                                 icmd_if_dcmpg_tail:
4186                                                         iptr->dst.insindex = iptr[1].dst.insindex;
4187                                                         iptr[1].opc = ICMD_NOP;
4188
4189                                                         OP2_BRANCH(TYPE_DBL, TYPE_DBL);
4190                                                         BRANCH(tbptr);
4191
4192                                                         COUNT(count_pcmd_bra);
4193                                                         break;
4194                                                 case ICMD_IFNE:
4195                                                         iptr->opc = ICMD_IF_DCMPNE;
4196                                                         goto icmd_if_dcmpg_tail;
4197                                                 case ICMD_IFLT:
4198                                                         iptr->opc = ICMD_IF_DCMPG_LT;
4199                                                         goto icmd_if_dcmpg_tail;
4200                                                 case ICMD_IFGT:
4201                                                         iptr->opc = ICMD_IF_DCMPG_GT;
4202                                                         goto icmd_if_dcmpg_tail;
4203                                                 case ICMD_IFLE:
4204                                                         iptr->opc = ICMD_IF_DCMPG_LE;
4205                                                         goto icmd_if_dcmpg_tail;
4206                                                 case ICMD_IFGE:
4207                                                         iptr->opc = ICMD_IF_DCMPG_GE;
4208                                                         goto icmd_if_dcmpg_tail;
4209                                                 default:
4210                                                         goto normal_DCMPG;
4211                                                 }
4212                                                 break;
4213
4214 normal_DCMPG:
4215                                                 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
4216                                                 break;
4217 #else
4218                                         case ICMD_FCMPL:
4219                                         case ICMD_FCMPG:
4220                                                 COUNT(count_pcmd_op);
4221                                                 OP2_1(TYPE_FLT, TYPE_FLT, TYPE_INT);
4222                                                 break;
4223
4224                                         case ICMD_DCMPL:
4225                                         case ICMD_DCMPG:
4226                                                 COUNT(count_pcmd_op);
4227                                                 OP2_1(TYPE_DBL, TYPE_DBL, TYPE_INT);
4228                                                 break;
4229 #endif
4230
4231                                                 /* pop 1 push 1 */
4232
4233                                         case ICMD_INEG:
4234                                         case ICMD_INT2BYTE:
4235                                         case ICMD_INT2CHAR:
4236                                         case ICMD_INT2SHORT:
4237                                                 COUNT(count_pcmd_op);
4238                                                 OP1_1(TYPE_INT, TYPE_INT);
4239                                                 break;
4240                                         case ICMD_LNEG:
4241                                                 COUNT(count_pcmd_op);
4242                                                 OP1_1(TYPE_LNG, TYPE_LNG);
4243                                                 break;
4244                                         case ICMD_FNEG:
4245                                                 COUNT(count_pcmd_op);
4246                                                 OP1_1(TYPE_FLT, TYPE_FLT);
4247                                                 break;
4248                                         case ICMD_DNEG:
4249                                                 COUNT(count_pcmd_op);
4250                                                 OP1_1(TYPE_DBL, TYPE_DBL);
4251                                                 break;
4252
4253                                         case ICMD_I2L:
4254                                                 COUNT(count_pcmd_op);
4255                                                 OP1_1(TYPE_INT, TYPE_LNG);
4256                                                 break;
4257                                         case ICMD_I2F:
4258                                                 COUNT(count_pcmd_op);
4259                                                 OP1_1(TYPE_INT, TYPE_FLT);
4260                                                 break;
4261                                         case ICMD_I2D:
4262                                                 COUNT(count_pcmd_op);
4263                                                 OP1_1(TYPE_INT, TYPE_DBL);
4264                                                 break;
4265                                         case ICMD_L2I:
4266                                                 COUNT(count_pcmd_op);
4267                                                 OP1_1(TYPE_LNG, TYPE_INT);
4268                                                 break;
4269                                         case ICMD_L2F:
4270                                                 COUNT(count_pcmd_op);
4271                                                 OP1_1(TYPE_LNG, TYPE_FLT);
4272                                                 break;
4273                                         case ICMD_L2D:
4274                                                 COUNT(count_pcmd_op);
4275                                                 OP1_1(TYPE_LNG, TYPE_DBL);
4276                                                 break;
4277                                         case ICMD_F2I:
4278                                                 COUNT(count_pcmd_op);
4279                                                 OP1_1(TYPE_FLT, TYPE_INT);
4280                                                 break;
4281                                         case ICMD_F2L:
4282                                                 COUNT(count_pcmd_op);
4283                                                 OP1_1(TYPE_FLT, TYPE_LNG);
4284                                                 break;
4285                                         case ICMD_F2D:
4286                                                 COUNT(count_pcmd_op);
4287                                                 OP1_1(TYPE_FLT, TYPE_DBL);
4288                                                 break;
4289                                         case ICMD_D2I:
4290                                                 COUNT(count_pcmd_op);
4291                                                 OP1_1(TYPE_DBL, TYPE_INT);
4292                                                 break;
4293                                         case ICMD_D2L:
4294                                                 COUNT(count_pcmd_op);
4295                                                 OP1_1(TYPE_DBL, TYPE_LNG);
4296                                                 break;
4297                                         case ICMD_D2F:
4298                                                 COUNT(count_pcmd_op);
4299                                                 OP1_1(TYPE_DBL, TYPE_FLT);
4300                                                 break;
4301
4302                                         case ICMD_CHECKCAST:
4303                                                 coalescing_boundary = sd.new;
4304                                                 if (iptr->flags.bits & INS_FLAG_ARRAY) {
4305                                                         /* array type cast-check */
4306
4307                                                         bte = builtintable_get_internal(BUILTIN_arraycheckcast);
4308                                                         md = bte->md;
4309
4310                                                         if (md->memuse > rd->memuse)
4311                                                                 rd->memuse = md->memuse;
4312                                                         if (md->argintreguse > rd->argintreguse)
4313                                                                 rd->argintreguse = md->argintreguse;
4314
4315                                                         /* make all stack variables saved */
4316
4317                                                         copy = curstack;
4318                                                         while (copy) {
4319                                                                 sd.var[copy->varnum].flags |= SAVEDVAR;
4320                                                                 copy->flags |= SAVEDVAR;
4321                                                                 copy = copy->prev;
4322                                                         }
4323                                                 }
4324                                                 OP1_1(TYPE_ADR, TYPE_ADR);
4325                                                 break;
4326
4327                                         case ICMD_INSTANCEOF:
4328                                         case ICMD_ARRAYLENGTH:
4329                                                 coalescing_boundary = sd.new;
4330                                                 OP1_1(TYPE_ADR, TYPE_INT);
4331                                                 break;
4332
4333                                         case ICMD_NEWARRAY:
4334                                         case ICMD_ANEWARRAY:
4335                                                 coalescing_boundary = sd.new;
4336                                                 OP1_1(TYPE_INT, TYPE_ADR);
4337                                                 break;
4338
4339                                         case ICMD_GETFIELD:
4340                                                 coalescing_boundary = sd.new;
4341                                                 COUNT(count_check_null);
4342                                                 COUNT(count_pcmd_mem);
4343                                                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
4344                                                 OP1_1(TYPE_ADR, fmiref->parseddesc.fd->type);
4345                                                 break;
4346
4347                                                 /* pop 0 push 1 */
4348
4349                                         case ICMD_GETSTATIC:
4350                                                 coalescing_boundary = sd.new;
4351                                                 COUNT(count_pcmd_mem);
4352                                                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
4353                                                 OP0_1(fmiref->parseddesc.fd->type);
4354                                                 break;
4355
4356                                         case ICMD_NEW:
4357                                                 coalescing_boundary = sd.new;
4358                                                 OP0_1(TYPE_ADR);
4359                                                 break;
4360
4361                                         case ICMD_JSR:
4362                                                 OP0_1(TYPE_RET);
4363
4364                                                 tbptr = BLOCK_OF(iptr->sx.s23.s3.jsrtarget.insindex);
4365                                                 tbptr->type = BBTYPE_SBR;
4366
4367                                                 assert(sd.bptr->next);  /* XXX exception */
4368                                                 sd.var[curstack->varnum].vv.retaddr = sd.bptr->next;
4369 #if defined(ENABLE_VERIFIER)
4370                                                 sd.var[curstack->varnum].SBRSTART = (void*) tbptr;
4371 #endif
4372
4373                                                 tbptr = stack_mark_reached(&sd, tbptr, curstack, stackdepth);
4374                                                 if (!tbptr)
4375                                                         return false;
4376
4377                                                 iptr->sx.s23.s3.jsrtarget.block = tbptr;
4378
4379                                                 /* We need to check for overflow right here because
4380                                                  * the pushed value is poped afterwards */
4381                                                 CHECKOVERFLOW;
4382
4383                                                 superblockend = true;
4384                                                 /* XXX should not be marked as interface, as it does not need to be */
4385                                                 /* allocated. Same for the invar of the target. */
4386                                                 break;
4387
4388                                         /* pop many push any */
4389
4390                                         case ICMD_BUILTIN:
4391 icmd_BUILTIN:
4392                                                 bte = iptr->sx.s23.s3.bte;
4393                                                 md = bte->md;
4394                                                 goto _callhandling;
4395
4396                                         case ICMD_INVOKESTATIC:
4397                                         case ICMD_INVOKESPECIAL:
4398                                         case ICMD_INVOKEVIRTUAL:
4399                                         case ICMD_INVOKEINTERFACE:
4400                                                 COUNT(count_pcmd_met);
4401
4402                                                 /* Check for functions to replace with builtin
4403                                                  * functions. */
4404
4405                                                 if (builtintable_replace_function(iptr))
4406                                                         goto icmd_BUILTIN;
4407
4408                                                 INSTRUCTION_GET_METHODDESC(iptr, md);
4409                                                 /* XXX resurrect this COUNT? */
4410 /*                          if (lm->flags & ACC_STATIC) */
4411 /*                              {COUNT(count_check_null);} */
4412
4413                                         _callhandling:
4414
4415                                                 coalescing_boundary = sd.new;
4416
4417                                                 i = md->paramcount;
4418
4419                                                 if (md->memuse > rd->memuse)
4420                                                         rd->memuse = md->memuse;
4421                                                 if (md->argintreguse > rd->argintreguse)
4422                                                         rd->argintreguse = md->argintreguse;
4423                                                 if (md->argfltreguse > rd->argfltreguse)
4424                                                         rd->argfltreguse = md->argfltreguse;
4425
4426                                                 REQUIRE(i);
4427
4428                                                 iptr->s1.argcount = stackdepth;
4429                                                 iptr->sx.s23.s2.args = DMNEW(s4, stackdepth);
4430
4431                                                 copy = curstack;
4432                                                 for (i-- ; i >= 0; i--) {
4433                                                         iptr->sx.s23.s2.args[i] = copy->varnum;
4434
4435                                                         /* do not change STACKVARs or LOCALVARS to ARGVAR*/
4436                                                         /* ->  won't help anyway */
4437                                                         if (!(IS_INOUT(copy) || IS_LOCALVAR(copy))) {
4438
4439 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
4440                         /* If we pass float arguments in integer argument registers, we
4441                          * are not allowed to precolor them here. Floats have to be moved
4442                          * to this regs explicitly in codegen().
4443                          * Only arguments that are passed by stack anyway can be precolored
4444                          * (michi 2005/07/24) */
4445                                                         if (!(sd.var[copy->varnum].flags & SAVEDVAR) &&
4446                                                            (!IS_FLT_DBL_TYPE(copy->type) 
4447                                                                 || md->params[i].inmemory)) {
4448 #else
4449                                                         if (!(sd.var[copy->varnum].flags & SAVEDVAR)) {
4450 #endif
4451
4452                                                                 SET_PREALLOC(copy);
4453
4454                                                                 if (md->params[i].inmemory) {
4455                                                                         sd.var[copy->varnum].vv.regoff =
4456                                                                                 md->params[i].regoff;
4457                                                                         sd.var[copy->varnum].flags |= 
4458                                                                                 INMEMORY;
4459                                                                 }
4460                                                                 else {
4461                                                                         if (IS_FLT_DBL_TYPE(copy->type)) {
4462 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
4463                                                                                 assert(0); /* XXX is this assert ok? */
4464 #else
4465                                                                                 sd.var[copy->varnum].vv.regoff = 
4466                                                                         rd->argfltregs[md->params[i].regoff];
4467 #endif /* SUPPORT_PASS_FLOATARGS_IN_INTREGS */
4468                                                                         }
4469                                                                         else {
4470 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
4471                                                                                 if (IS_2_WORD_TYPE(copy->type))
4472                                                                                         sd.var[copy->varnum].vv.regoff = 
4473                         PACK_REGS( rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
4474                                            rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
4475
4476                                                                                 else
4477 #endif /* SUPPORT_COMBINE_INTEGER_REGISTERS */
4478                                                                                         sd.var[copy->varnum].vv.regoff = 
4479                                                                         rd->argintregs[md->params[i].regoff];
4480                                                                         }
4481                                                                 }
4482                                                         }
4483                                                         }
4484                                                         copy = copy->prev;
4485                                                 }
4486
4487                                                 /* deal with live-through stack slots "under" the */
4488                                                 /* arguments */
4489
4490                                                 i = md->paramcount;
4491
4492                                                 while (copy) {
4493                                                         iptr->sx.s23.s2.args[i++] = copy->varnum;
4494                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
4495                                                         copy->flags |= SAVEDVAR | PASSTHROUGH;
4496                                                         copy = copy->prev;
4497                                                 }
4498
4499                                                 /* pop the arguments */
4500
4501                                                 i = md->paramcount;
4502
4503                                                 stackdepth -= i;
4504                                                 while (--i >= 0) {
4505                                                         POPANY;
4506                                                 }
4507
4508                                                 /* push the return value */
4509
4510                                                 if (md->returntype.type != TYPE_VOID) {
4511                                                         GET_NEW_VAR(sd, new_index, md->returntype.type);
4512                                                         DST(md->returntype.type, new_index);
4513                                                         stackdepth++;
4514                                                 }
4515                                                 break;
4516
4517                                         case ICMD_MULTIANEWARRAY:
4518                                                 coalescing_boundary = sd.new;
4519                                                 if (rd->argintreguse < MIN(3, INT_ARG_CNT))
4520                                                         rd->argintreguse = MIN(3, INT_ARG_CNT);
4521
4522                                                 i = iptr->s1.argcount;
4523
4524                                                 REQUIRE(i);
4525
4526                                                 iptr->sx.s23.s2.args = DMNEW(s4, i);
4527
4528 #if defined(SPECIALMEMUSE)
4529 # if defined(__DARWIN__)
4530                                                 if (rd->memuse < (i + INT_ARG_CNT +LA_SIZE_IN_POINTERS))
4531                                                         rd->memuse = i + LA_SIZE_IN_POINTERS + INT_ARG_CNT;
4532 # else
4533                                                 if (rd->memuse < (i + LA_SIZE_IN_POINTERS + 3))
4534                                                         rd->memuse = i + LA_SIZE_IN_POINTERS + 3;
4535 # endif
4536 #else
4537 # if defined(__I386__)
4538                                                 if (rd->memuse < i + 3)
4539                                                         rd->memuse = i + 3; /* n integer args spilled on stack */
4540 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
4541                                                 if (rd->memuse < i + 2)
4542                                                         rd->memuse = i + 2; /* 4*4 bytes callee save space */
4543 # else
4544                                                 if (rd->memuse < i)
4545                                                         rd->memuse = i; /* n integer args spilled on stack */
4546 # endif /* defined(__I386__) */
4547 #endif
4548                                                 copy = curstack;
4549                                                 while (--i >= 0) {
4550                                         /* check INT type here? Currently typecheck does this. */
4551                                                         iptr->sx.s23.s2.args[i] = copy->varnum;
4552                                                         if (!(sd.var[copy->varnum].flags & SAVEDVAR)
4553                                                                 && (!IS_INOUT(copy))
4554                                                                 && (!IS_LOCALVAR(copy)) ) {
4555                                                                 copy->varkind = ARGVAR;
4556                                                                 sd.var[copy->varnum].flags |=
4557                                                                         INMEMORY & PREALLOC;
4558 #if defined(SPECIALMEMUSE)
4559 # if defined(__DARWIN__)
4560                                                                 sd.var[copy->varnum].vv.regoff = i + 
4561                                                                         LA_SIZE_IN_POINTERS + INT_ARG_CNT;
4562 # else
4563                                                                 sd.var[copy->varnum].vv.regoff = i + 
4564                                                                         LA_SIZE_IN_POINTERS + 3;
4565 # endif
4566 #else
4567 # if defined(__I386__)
4568                                                                 sd.var[copy->varnum].vv.regoff = i + 3;
4569 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
4570                                                                 sd.var[copy->varnum].vv.regoff = i + 2;
4571 # else
4572                                                                 sd.var[copy->varnum].vv.regoff = i;
4573 # endif /* defined(__I386__) */
4574 #endif /* defined(SPECIALMEMUSE) */
4575                                                         }
4576                                                         copy = copy->prev;
4577                                                 }
4578                                                 while (copy) {
4579                                                         sd.var[copy->varnum].flags |= SAVEDVAR;
4580                                                         copy->flags |= SAVEDVAR;
4581                                                         copy = copy->prev;
4582                                                 }
4583
4584                                                 i = iptr->s1.argcount;
4585                                                 stackdepth -= i;
4586                                                 while (--i >= 0) {
4587                                                         POPANY;
4588                                                 }
4589                                                 GET_NEW_VAR(sd, new_index, TYPE_ADR);
4590                                                 DST(TYPE_ADR, new_index);
4591                                                 stackdepth++;
4592                                                 break;
4593
4594                                         default:
4595                                                 *exceptionptr =
4596                                                         new_internalerror("Unknown ICMD %d", opcode);
4597                                                 return false;
4598                                         } /* switch */
4599
4600                                         CHECKOVERFLOW;
4601                                         iptr++;
4602                                 } /* while instructions */
4603
4604                                 /* show state after last instruction */
4605
4606 #if defined(STACK_VERBOSE)
4607                                 stack_verbose_show_state(&sd, NULL, curstack);
4608 #endif
4609
4610                                 /* stack slots at basic block end become interfaces */
4611
4612                                 sd.bptr->outdepth = stackdepth;
4613                                 sd.bptr->outvars = DMNEW(s4, stackdepth);
4614
4615                                 i = stackdepth - 1;
4616                                 for (copy = curstack; copy; i--, copy = copy->prev) {
4617                                         varinfo *v;
4618                                         s4 t;
4619
4620                                         /* with the new vars rd->interfaces will be removed */
4621                                         /* and all in and outvars have to be STACKVARS!     */
4622                                         /* in the moment i.e. SWAP with in and out vars can */
4623                                         /* create an unresolvable conflict */
4624
4625                                         SET_TEMPVAR(copy);
4626                                         t = copy->type;
4627
4628                                         v = sd.var + copy->varnum;
4629                                         v->flags |= INOUT;
4630
4631                                         /* do not allocate variables for returnAddresses */
4632
4633                                         if (t != TYPE_RET) {
4634                                                 if (jd->interface_map[i*5 + t].flags == UNUSED) {
4635                                                         /* no interface var until now for this depth and */
4636                                                         /* type */
4637                                                         jd->interface_map[i*5 + t].flags = v->flags;
4638                                                 }
4639                                                 else {
4640                                                         jd->interface_map[i*5 + t].flags |= v->flags;
4641                                                 }
4642                                         }
4643
4644                                         sd.bptr->outvars[i] = copy->varnum;
4645                                 }
4646
4647                                 /* check if interface slots at basic block begin must be saved */
4648
4649                                 for (i=0; i<sd.bptr->indepth; ++i) {
4650                                         varinfo *v = sd.var + sd.bptr->invars[i];
4651                                         s4 t;
4652
4653                                         t = v->type;
4654
4655                                         if (t != TYPE_RET) {
4656                                                 if (jd->interface_map[i*5 + t].flags == UNUSED) {
4657                                                         /* no interface var until now for this depth and */
4658                                                         /* type */
4659                                                         jd->interface_map[i*5 + t].flags = v->flags;
4660                                                 }
4661                                                 else {
4662                                                         jd->interface_map[i*5 + t].flags |= v->flags;
4663                                                 }
4664                                         }
4665                                 }
4666
4667                                 /* store the number of this block's variables */
4668
4669                                 sd.bptr->varcount = sd.vartop - sd.bptr->varstart;
4670
4671 #if defined(STACK_VERBOSE)
4672                                 stack_verbose_block_exit(&sd, superblockend);
4673 #endif
4674
4675                                 /* reach the following block, if any */
4676
4677                                 if (!superblockend)
4678                                         if (!stack_reach_next_block(&sd))
4679                                                 return false;
4680
4681                 } /* for blocks */
4682
4683         } while (sd.repeat && !deadcode);
4684
4685         /* reset locals of TYPE_RET to TYPE_ADR */
4686
4687         for (i=0; i<sd.localcount; ++i) {
4688                 if (sd.var[i].type == TYPE_RET)
4689                         sd.var[i].type = TYPE_ADR;
4690         }
4691
4692         /* mark temporaries of TYPE_RET as PREALLOC to avoid allocation */
4693
4694         for (i=sd.localcount; i<sd.vartop; ++i) {
4695                 if (sd.var[i].type == TYPE_RET)
4696                         sd.var[i].flags |= PREALLOC;
4697         }
4698
4699         /* XXX hack to fix up the ranges of the cloned single-block handlers */
4700
4701         ex = jd->exceptiontable;
4702         for (; ex != NULL; ex = ex->down) {
4703                 if (ex->start == ex->end) {
4704                         assert(ex->end->next);
4705                         ex->end = ex->end->next;
4706                 }
4707         }
4708
4709         /* store number of created variables */
4710
4711         jd->vartop = sd.vartop;
4712
4713         /* gather statistics *****************************************************/
4714
4715 #if defined(ENABLE_STATISTICS)
4716         if (opt_stat) {
4717                 if (jd->basicblockcount > count_max_basic_blocks)
4718                         count_max_basic_blocks = jd->basicblockcount;
4719                 count_basic_blocks += jd->basicblockcount;
4720                 if (jd->instructioncount > count_max_javainstr)
4721                         count_max_javainstr = jd->instructioncount;
4722                 count_javainstr += jd->instructioncount;
4723                 if (jd->stackcount > count_upper_bound_new_stack)
4724                         count_upper_bound_new_stack = jd->stackcount;
4725                 if ((sd.new - jd->stack) > count_max_new_stack)
4726                         count_max_new_stack = (sd.new - jd->stack);
4727
4728                 sd.bptr = jd->basicblocks;
4729                 for (; sd.bptr; sd.bptr = sd.bptr->next) {
4730                         if (sd.bptr->flags > BBREACHED) {
4731                                 if (sd.bptr->indepth >= 10)
4732                                         count_block_stack[10]++;
4733                                 else
4734                                         count_block_stack[sd.bptr->indepth]++;
4735                                 len = sd.bptr->icount;
4736                                 if (len < 10)
4737                                         count_block_size_distribution[len]++;
4738                                 else if (len <= 12)
4739                                         count_block_size_distribution[10]++;
4740                                 else if (len <= 14)
4741                                         count_block_size_distribution[11]++;
4742                                 else if (len <= 16)
4743                                         count_block_size_distribution[12]++;
4744                                 else if (len <= 18)
4745                                         count_block_size_distribution[13]++;
4746                                 else if (len <= 20)
4747                                         count_block_size_distribution[14]++;
4748                                 else if (len <= 25)
4749                                         count_block_size_distribution[15]++;
4750                                 else if (len <= 30)
4751                                         count_block_size_distribution[16]++;
4752                                 else
4753                                         count_block_size_distribution[17]++;
4754                         }
4755                 }
4756
4757                 if (iteration_count == 1)
4758                         count_analyse_iterations[0]++;
4759                 else if (iteration_count == 2)
4760                         count_analyse_iterations[1]++;
4761                 else if (iteration_count == 3)
4762                         count_analyse_iterations[2]++;
4763                 else if (iteration_count == 4)
4764                         count_analyse_iterations[3]++;
4765                 else
4766                         count_analyse_iterations[4]++;
4767
4768                 if (jd->basicblockcount <= 5)
4769                         count_method_bb_distribution[0]++;
4770                 else if (jd->basicblockcount <= 10)
4771                         count_method_bb_distribution[1]++;
4772                 else if (jd->basicblockcount <= 15)
4773                         count_method_bb_distribution[2]++;
4774                 else if (jd->basicblockcount <= 20)
4775                         count_method_bb_distribution[3]++;
4776                 else if (jd->basicblockcount <= 30)
4777                         count_method_bb_distribution[4]++;
4778                 else if (jd->basicblockcount <= 40)
4779                         count_method_bb_distribution[5]++;
4780                 else if (jd->basicblockcount <= 50)
4781                         count_method_bb_distribution[6]++;
4782                 else if (jd->basicblockcount <= 75)
4783                         count_method_bb_distribution[7]++;
4784                 else
4785                         count_method_bb_distribution[8]++;
4786         }
4787 #endif /* defined(ENABLE_STATISTICS) */
4788
4789         /* everything's ok *******************************************************/
4790
4791         return true;
4792
4793         /* goto labels for throwing verifier exceptions **************************/
4794
4795 #if defined(ENABLE_VERIFIER)
4796
4797 throw_stack_underflow:
4798         exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
4799         return false;
4800
4801 throw_stack_overflow:
4802         exceptions_throw_verifyerror(m, "Stack size too large");
4803         return false;
4804
4805 throw_stack_type_error:
4806         exceptions_throw_verifyerror_for_stack(m, expectedtype);
4807         return false;
4808
4809 throw_stack_category_error:
4810         exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
4811         return false;
4812
4813 #endif
4814 }
4815
4816
4817 /* functions for verbose stack analysis output ********************************/
4818
4819 #if defined(STACK_VERBOSE)
4820 static void stack_verbose_show_varinfo(stackdata_t *sd, varinfo *v)
4821 {
4822         printf("%c", show_jit_type_letters[v->type]);
4823         if (v->type == TYPE_RET)
4824                 printf("{L%03d}", v->vv.retaddr->nr);
4825 }
4826
4827
4828 static void stack_verbose_show_variable(stackdata_t *sd, s4 index)
4829 {
4830         assert(index >= 0 && index < sd->vartop);
4831         stack_verbose_show_varinfo(sd, sd->var + index);
4832 }
4833
4834
4835 static void stack_verbose_show_block(stackdata_t *sd, basicblock *bptr)
4836 {
4837         s4 i;
4838
4839         printf("L%03d type:%d in:%d [", bptr->nr, bptr->type, bptr->indepth);
4840         if (bptr->invars) {
4841                 for (i=0; i<bptr->indepth; ++i) {
4842                         if (i)
4843                                 putchar(' ');
4844                         stack_verbose_show_variable(sd, bptr->invars[i]);
4845                 }
4846         }
4847         else
4848                 putchar('-');
4849         printf("] javalocals ");
4850         show_javalocals_array(sd->jd, sd->javalocals, sd->maxlocals, SHOW_STACK);
4851         printf(" inlocals [");
4852         if (bptr->inlocals) {
4853                 for (i=0; i<sd->localcount; ++i) {
4854                         if (i)
4855                                 putchar(' ');
4856                         stack_verbose_show_varinfo(sd, bptr->inlocals + i);
4857                 }
4858         }
4859         else
4860                 putchar('-');
4861         printf("] out:%d [", bptr->outdepth);
4862         if (bptr->outvars) {
4863                 for (i=0; i<bptr->outdepth; ++i) {
4864                         if (i)
4865                                 putchar(' ');
4866                         stack_verbose_show_variable(sd, bptr->outvars[i]);
4867                 }
4868         }
4869         else
4870                 putchar('-');
4871         printf("]");
4872
4873         if (bptr->original)
4874                 printf(" (clone of L%03d)", bptr->original->nr);
4875         else {
4876                 basicblock *b = bptr->copied_to;
4877                 if (b) {
4878                         printf(" (copied to ");
4879                         for (; b; b = b->copied_to)
4880                                 printf("L%03d ", b->nr);
4881                         printf(")");
4882                 }
4883         }
4884 }
4885
4886
4887 static void stack_verbose_block_enter(stackdata_t *sd, bool reanalyse)
4888 {
4889         int i;
4890
4891         printf("======================================== STACK %sANALYSE BLOCK ", 
4892                         (reanalyse) ? ((sd->bptr->iinstr == NULL) ? "CLONE-" : "RE-") : "");
4893         stack_verbose_show_block(sd, sd->bptr);
4894         printf("\n");
4895
4896         if (sd->handlers[0]) {
4897                 printf("HANDLERS: ");
4898                 for (i=0; sd->handlers[i]; ++i) {
4899                         printf("L%03d ", sd->handlers[i]->handler->nr);
4900                 }
4901                 printf("\n");
4902         }
4903         printf("\n");
4904 }
4905
4906
4907 static void stack_verbose_block_exit(stackdata_t *sd, bool superblockend)
4908 {
4909         printf("%s ", (superblockend) ? "SUPERBLOCKEND" : "END");
4910         stack_verbose_show_block(sd, sd->bptr);
4911         printf("\n");
4912 }
4913
4914 static void stack_verbose_show_state(stackdata_t *sd, instruction *iptr, stackptr curstack)
4915 {
4916         stackptr sp;
4917         s4       i;
4918         s4       depth;
4919         varinfo *v;
4920         stackptr *stack;
4921
4922         printf("    javalocals ");
4923         show_javalocals_array(sd->jd, sd->javalocals, sd->maxlocals, SHOW_STACK);
4924         printf(" stack [");
4925
4926         for(i = 0, sp = curstack; sp; sp = sp->prev)
4927                 i++;
4928         depth = i;
4929
4930         stack = MNEW(stackptr, depth);
4931         for(sp = curstack; sp; sp = sp->prev)
4932                 stack[--i] = sp;
4933
4934         for(i=0; i<depth; ++i) {
4935                 if (i)
4936                         putchar(' ');
4937                 sp = stack[i];
4938                 v = &(sd->var[sp->varnum]);
4939
4940                 if (v->flags & INOUT)
4941                         putchar('I');
4942                 if (v->flags & PREALLOC)
4943                         putchar('A');
4944                 printf("%d:%c", sp->varnum, show_jit_type_letters[sp->type]);
4945                 if (v->type == TYPE_RET) {
4946                         printf("(L%03d)", v->vv.retaddr->nr);
4947                 }
4948         }
4949         printf("] ... ");
4950         if (iptr)
4951                 show_icmd(sd->jd, iptr, false, SHOW_PARSE); 
4952         printf("\n");
4953 }
4954 #endif
4955
4956
4957 /*
4958  * These are local overrides for various environment variables in Emacs.
4959  * Please do not remove this and leave it at the end of the file, where
4960  * Emacs will automagically detect them.
4961  * ---------------------------------------------------------------------
4962  * Local variables:
4963  * mode: c
4964  * indent-tabs-mode: t
4965  * c-basic-offset: 4
4966  * tab-width: 4
4967  * End:
4968  * vim:noexpandtab:sw=4:ts=4:
4969  */