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