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