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