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