* src/vm/jit/cfg.h (CFG_UNKNOWN_PREDECESSORS): Defined.
[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 5216 2006-08-08 12:45:31Z twisti $
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->debug_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                                                 iptr->s1.argcount = i;
2515                                                 iptr->sx.s23.s2.args = DMNEW(stackptr, i);
2516
2517                                                 copy = curstack;
2518                                                 for (i-- ; i >= 0; i--) {
2519                                                         iptr->sx.s23.s2.args[i] = copy;
2520
2521 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2522                                                         /* If we pass float arguments in integer argument registers, we
2523                                                          * are not allowed to precolor them here. Floats have to be moved
2524                                                          * to this regs explicitly in codegen().
2525                                                          * Only arguments that are passed by stack anyway can be precolored
2526                                                          * (michi 2005/07/24) */
2527                                                         if (!(copy->flags & SAVEDVAR) &&
2528                                                            (!IS_FLT_DBL_TYPE(copy->type) || md->params[i].inmemory)) {
2529 #else
2530                                                         if (!(copy->flags & SAVEDVAR)) {
2531 #endif
2532                                                                 copy->varkind = ARGVAR;
2533                                                                 copy->varnum = i;
2534
2535 #if defined(ENABLE_INTRP)
2536                                                                 if (!opt_intrp) {
2537 #endif
2538                                                                         if (md->params[i].inmemory) {
2539                                                                                 copy->flags = INMEMORY;
2540                                                                                 copy->regoff = md->params[i].regoff;
2541                                                                         }
2542                                                                         else {
2543                                                                                 copy->flags = 0;
2544                                                                                 if (IS_FLT_DBL_TYPE(copy->type)) {
2545 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
2546                                                                                         assert(0); /* XXX is this assert ok? */
2547 #else
2548                                                                                         copy->regoff =
2549                                                                                                 rd->argfltregs[md->params[i].regoff];
2550 #endif /* SUPPORT_PASS_FLOATARGS_IN_INTREGS */
2551                                                                                 }
2552                                                                                 else {
2553 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
2554                                                                                         if (IS_2_WORD_TYPE(copy->type))
2555                                                                                                 copy->regoff = PACK_REGS(
2556                                                                                                         rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
2557                                                                                                         rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
2558                                                                                         else
2559 #endif /* SUPPORT_COMBINE_INTEGER_REGISTERS */
2560                                                                                                 copy->regoff =
2561                                                                                                         rd->argintregs[md->params[i].regoff];
2562                                                                                 }
2563                                                                         }
2564 #if defined(ENABLE_INTRP)
2565                                                                 } /* end if (!opt_intrp) */
2566 #endif
2567                                                         }
2568                                                         copy = copy->prev;
2569                                                 }
2570
2571                                                 while (copy) {
2572                                                         copy->flags |= SAVEDVAR;
2573                                                         copy = copy->prev;
2574                                                 }
2575
2576                                                 i = md->paramcount;
2577
2578                                                 stackdepth -= i;
2579                                                 while (--i >= 0) {
2580                                                         POPANY;
2581                                                 }
2582
2583                                                 if (md->returntype.type != TYPE_VOID) {
2584                                                         NEW_DST(md->returntype.type, stackdepth);
2585                                                         stackdepth++;
2586                                                 }
2587                                                 break;
2588
2589                                         case ICMD_INLINE_START:
2590                                         case ICMD_INLINE_END:
2591                                                 CLR_S1;
2592                                                 CLR_DST;
2593                                                 break;
2594
2595                                         case ICMD_MULTIANEWARRAY:
2596                                                 if (rd->argintreguse < 3)
2597                                                         rd->argintreguse = 3;
2598
2599                                                 i = iptr->s1.argcount;
2600
2601                                                 REQUIRE(i);
2602
2603                                                 iptr->sx.s23.s2.args = DMNEW(stackptr, i);
2604
2605 #if defined(SPECIALMEMUSE)
2606 # if defined(__DARWIN__)
2607                                                 if (rd->memuse < (i + INT_ARG_CNT + LA_WORD_SIZE))
2608                                                         rd->memuse = i + LA_WORD_SIZE + INT_ARG_CNT;
2609 # else
2610                                                 if (rd->memuse < (i + LA_WORD_SIZE + 3))
2611                                                         rd->memuse = i + LA_WORD_SIZE + 3;
2612 # endif
2613 #else
2614 # if defined(__I386__)
2615                                                 if (rd->memuse < i + 3)
2616                                                         rd->memuse = i + 3; /* n integer args spilled on stack */
2617 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2618                                                 if (rd->memuse < i + 2)
2619                                                         rd->memuse = i + 2; /* 4*4 bytes callee save space */
2620 # else
2621                                                 if (rd->memuse < i)
2622                                                         rd->memuse = i; /* n integer args spilled on stack */
2623 # endif /* defined(__I386__) */
2624 #endif
2625                                                 copy = curstack;
2626                                                 while (--i >= 0) {
2627                                                         /* check INT type here? Currently typecheck does this. */
2628                                                         iptr->sx.s23.s2.args[i] = copy;
2629                                                         if (!(copy->flags & SAVEDVAR)) {
2630                                                                 copy->varkind = ARGVAR;
2631                                                                 copy->varnum = i + INT_ARG_CNT;
2632                                                                 copy->flags |= INMEMORY;
2633 #if defined(SPECIALMEMUSE)
2634 # if defined(__DARWIN__)
2635                                                                 copy->regoff = i + LA_WORD_SIZE + INT_ARG_CNT;
2636 # else
2637                                                                 copy->regoff = i + LA_WORD_SIZE + 3;
2638 # endif
2639 #else
2640 # if defined(__I386__)
2641                                                                 copy->regoff = i + 3;
2642 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
2643                                                                 copy->regoff = i + 2;
2644 # else
2645                                                                 copy->regoff = i;
2646 # endif /* defined(__I386__) */
2647 #endif /* defined(SPECIALMEMUSE) */
2648                                                         }
2649                                                         copy = copy->prev;
2650                                                 }
2651                                                 while (copy) {
2652                                                         copy->flags |= SAVEDVAR;
2653                                                         copy = copy->prev;
2654                                                 }
2655
2656                                                 i = iptr->s1.argcount;
2657                                                 stackdepth -= i;
2658                                                 while (--i >= 0) {
2659                                                         POPANY;
2660                                                 }
2661                                                 NEW_DST(TYPE_ADR, stackdepth);
2662                                                 stackdepth++;
2663                                                 break;
2664
2665                                         default:
2666                                                 *exceptionptr =
2667                                                         new_internalerror("Unknown ICMD %d", opcode);
2668                                                 return false;
2669                                         } /* switch */
2670
2671                                         NEW_CHECKOVERFLOW;
2672                                         iptr++;
2673                                 } /* while instructions */
2674
2675                                 /* set out-stack of block */
2676
2677                                 bptr->outstack = curstack;
2678                                 bptr->outdepth = stackdepth;
2679
2680                                 /* stack slots at basic block end become interfaces */
2681
2682                                 i = stackdepth - 1;
2683                                 for (copy = curstack; copy; i--, copy = copy->prev) {
2684                                         if ((copy->varkind == STACKVAR) && (copy->varnum > i))
2685                                                 copy->varkind = TEMPVAR;
2686                                         else {
2687                                                 copy->varkind = STACKVAR;
2688                                                 copy->varnum = i;
2689                                         }
2690                                         IF_NO_INTRP(
2691                                                         rd->interfaces[i][copy->type].type = copy->type;
2692                                                         rd->interfaces[i][copy->type].flags |= copy->flags;
2693                                         );
2694                                 }
2695
2696                                 /* check if interface slots at basic block begin must be saved */
2697
2698                                 IF_NO_INTRP(
2699                                         i = bptr->indepth - 1;
2700                                         for (copy = bptr->instack; copy; i--, copy = copy->prev) {
2701                                                 rd->interfaces[i][copy->type].type = copy->type;
2702                                                 if (copy->varkind == STACKVAR) {
2703                                                         if (copy->flags & SAVEDVAR)
2704                                                                 rd->interfaces[i][copy->type].flags |= SAVEDVAR;
2705                                                 }
2706                                         }
2707                                 );
2708
2709                         } /* if */
2710                         else
2711                                 superblockend = true;
2712
2713                         bptr++;
2714                 } /* while blocks */
2715         } while (repeat && !deadcode);
2716
2717         /* gather statistics *****************************************************/
2718
2719 #if defined(ENABLE_STATISTICS)
2720         if (opt_stat) {
2721                 if (jd->new_basicblockcount > count_max_basic_blocks)
2722                         count_max_basic_blocks = jd->new_basicblockcount;
2723                 count_basic_blocks += jd->new_basicblockcount;
2724                 if (jd->new_instructioncount > count_max_javainstr)
2725                         count_max_javainstr = jd->new_instructioncount;
2726                 count_javainstr += jd->new_instructioncount;
2727                 if (jd->new_stackcount > count_upper_bound_new_stack)
2728                         count_upper_bound_new_stack = jd->new_stackcount;
2729                 if ((new - jd->new_stack) > count_max_new_stack)
2730                         count_max_new_stack = (new - jd->new_stack);
2731
2732                 b_count = jd->new_basicblockcount;
2733                 bptr = jd->new_basicblocks;
2734                 while (--b_count >= 0) {
2735                         if (bptr->flags > BBREACHED) {
2736                                 if (bptr->indepth >= 10)
2737                                         count_block_stack[10]++;
2738                                 else
2739                                         count_block_stack[bptr->indepth]++;
2740                                 len = bptr->icount;
2741                                 if (len < 10)
2742                                         count_block_size_distribution[len]++;
2743                                 else if (len <= 12)
2744                                         count_block_size_distribution[10]++;
2745                                 else if (len <= 14)
2746                                         count_block_size_distribution[11]++;
2747                                 else if (len <= 16)
2748                                         count_block_size_distribution[12]++;
2749                                 else if (len <= 18)
2750                                         count_block_size_distribution[13]++;
2751                                 else if (len <= 20)
2752                                         count_block_size_distribution[14]++;
2753                                 else if (len <= 25)
2754                                         count_block_size_distribution[15]++;
2755                                 else if (len <= 30)
2756                                         count_block_size_distribution[16]++;
2757                                 else
2758                                         count_block_size_distribution[17]++;
2759                         }
2760                         bptr++;
2761                 }
2762
2763                 if (iteration_count == 1)
2764                         count_analyse_iterations[0]++;
2765                 else if (iteration_count == 2)
2766                         count_analyse_iterations[1]++;
2767                 else if (iteration_count == 3)
2768                         count_analyse_iterations[2]++;
2769                 else if (iteration_count == 4)
2770                         count_analyse_iterations[3]++;
2771                 else
2772                         count_analyse_iterations[4]++;
2773
2774                 if (jd->new_basicblockcount <= 5)
2775                         count_method_bb_distribution[0]++;
2776                 else if (jd->new_basicblockcount <= 10)
2777                         count_method_bb_distribution[1]++;
2778                 else if (jd->new_basicblockcount <= 15)
2779                         count_method_bb_distribution[2]++;
2780                 else if (jd->new_basicblockcount <= 20)
2781                         count_method_bb_distribution[3]++;
2782                 else if (jd->new_basicblockcount <= 30)
2783                         count_method_bb_distribution[4]++;
2784                 else if (jd->new_basicblockcount <= 40)
2785                         count_method_bb_distribution[5]++;
2786                 else if (jd->new_basicblockcount <= 50)
2787                         count_method_bb_distribution[6]++;
2788                 else if (jd->new_basicblockcount <= 75)
2789                         count_method_bb_distribution[7]++;
2790                 else
2791                         count_method_bb_distribution[8]++;
2792         }
2793 #endif /* defined(ENABLE_STATISTICS) */
2794
2795         /* everything's ok *******************************************************/
2796
2797         return true;
2798
2799         /* goto labels for throwing verifier exceptions **************************/
2800
2801 #if defined(ENABLE_VERIFIER)
2802
2803 throw_stack_underflow:
2804         exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
2805         return false;
2806
2807 throw_stack_overflow:
2808         exceptions_throw_verifyerror(m, "Stack size too large");
2809         return false;
2810
2811 throw_stack_depth_error:
2812         exceptions_throw_verifyerror(m,"Stack depth mismatch");
2813         return false;
2814
2815 throw_stack_type_error:
2816         exceptions_throw_verifyerror_for_stack(m, expectedtype);
2817         return false;
2818
2819 throw_stack_category_error:
2820         exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
2821         return false;
2822
2823 #endif
2824 }
2825
2826 bool stack_analyse(jitdata *jd)
2827 {
2828         methodinfo   *m;
2829         codeinfo     *code;
2830         codegendata  *cd;
2831         registerdata *rd;
2832         int           b_count;
2833         int           b_index;
2834         int           stackdepth;
2835         stackptr      curstack;
2836         stackptr      new;
2837         stackptr      copy;
2838         int           opcode, i, j, len, loops;
2839         int           superblockend, repeat, deadcode;
2840         instruction  *iptr;
2841         basicblock   *bptr;
2842         basicblock   *tbptr;
2843         s4           *s4ptr;
2844         void        **tptr;
2845         s4           *last_store;/* instruction index of last XSTORE */
2846                                  /* [ local_index * 5 + type ] */
2847         s4            last_pei;  /* instruction index of last possible exception */
2848                                  /* used for conflict resolution for copy        */
2849                              /* elimination (XLOAD, IINC, XSTORE) */
2850         s4            last_dupx;
2851 #if defined(ENABLE_VERIFIER)
2852         int           expectedtype; /* used by CHECK_BASIC_TYPE */
2853 #endif
2854
2855         builtintable_entry *bte;
2856         methoddesc         *md;
2857
2858         /* get required compiler data */
2859
2860         m    = jd->m;
2861         code = jd->code;
2862         cd   = jd->cd;
2863         rd   = jd->rd;
2864
2865 #if defined(ENABLE_LSRA)
2866         m->maxlifetimes = 0;
2867 #endif
2868
2869         last_store = DMNEW(s4 , cd->maxlocals * 5);
2870         
2871         new = m->stack;
2872         loops = 0;
2873         m->basicblocks[0].flags = BBREACHED;
2874         m->basicblocks[0].instack = 0;
2875         m->basicblocks[0].indepth = 0;
2876
2877         for (i = 0; i < cd->exceptiontablelength; i++) {
2878                 bptr = &m->basicblocks[m->basicblockindex[cd->exceptiontable[i].handlerpc]];
2879                 bptr->flags = BBREACHED;
2880                 bptr->type = BBTYPE_EXH;
2881                 bptr->instack = new;
2882                 bptr->indepth = 1;
2883                 bptr->predecessorcount = CFG_UNKNOWN_PREDECESSORS;
2884                 STACKRESET;
2885                 NEWXSTACK;
2886         }
2887
2888         do {
2889                 loops++;
2890                 b_count = m->basicblockcount;
2891                 bptr = m->basicblocks;
2892                 superblockend = true;
2893                 repeat = false;
2894                 STACKRESET;
2895                 deadcode = true;
2896
2897                 while (--b_count >= 0) {
2898                         if (bptr->flags == BBDELETED) {
2899                                 /* do nothing */
2900                         } 
2901                         else if (superblockend && (bptr->flags < BBREACHED)) {
2902                                 repeat = true;
2903                         } 
2904                         else if (bptr->flags <= BBREACHED) {
2905                                 if (superblockend) {
2906                                         stackdepth = bptr->indepth;
2907                                 } 
2908                                 else if (bptr->flags < BBREACHED) {
2909                                         COPYCURSTACK(copy);
2910                                         bptr->instack = copy;
2911                                         bptr->indepth = stackdepth;
2912                                 } 
2913                                 else {
2914                                         CHECK_STACK_DEPTH(bptr->indepth, stackdepth);
2915                                 }
2916
2917                                 curstack = bptr->instack;
2918                                 deadcode = false;
2919                                 superblockend = false;
2920                                 bptr->flags = BBFINISHED;
2921                                 len = bptr->icount;
2922                                 iptr = bptr->iinstr;
2923                                 b_index = bptr - m->basicblocks;
2924
2925                                 last_pei = -1;
2926                                 last_dupx = -1;
2927                                 for( i = 0; i < cd->maxlocals; i++)
2928                                         for( j = 0; j < 5; j++)
2929                                                 last_store[5 * i + j] = -1;
2930
2931                                 bptr->stack = new;
2932
2933                                 while (--len >= 0)  {
2934                                         opcode = iptr->opc;
2935
2936 #if defined(USEBUILTINTABLE)
2937 # if defined(ENABLE_INTRP)
2938                                         if (!opt_intrp) {
2939 # endif
2940                                                 bte = builtintable_get_automatic(opcode);
2941
2942                                                 if (bte && bte->opcode == opcode) {
2943                                                         iptr->opc   = ICMD_BUILTIN;
2944                                                         iptr->op1   = false; /* don't check for exception */
2945                                                         iptr->val.a = bte;
2946                                                         jd->isleafmethod = false;
2947                                                         goto builtin;
2948                                                 }
2949 # if defined(ENABLE_INTRP)
2950                                         }
2951 # endif
2952 #endif /* defined(USEBUILTINTABLE) */
2953
2954                                         /* this is the main switch */
2955
2956                                         switch (opcode) {
2957
2958                                                 /* pop 0 push 0 */
2959
2960                                         case ICMD_CHECKNULL:
2961                                                 COUNT(count_check_null);
2962                                         case ICMD_NOP:
2963                                                 SETDST;
2964                                                 break;
2965
2966                                         case ICMD_RET:
2967 #if defined(ENABLE_INTRP)
2968                                                 if (!opt_intrp)
2969 #endif
2970                                                         rd->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
2971                                         case ICMD_RETURN:
2972                                                 COUNT(count_pcmd_return);
2973                                                 SETDST;
2974                                                 superblockend = true;
2975                                                 break;
2976
2977                                                 /* pop 0 push 1 const */
2978                                                 
2979                                         case ICMD_ICONST:
2980                                                 COUNT(count_pcmd_load);
2981                                                 if (len > 0) {
2982                                                         switch (iptr[1].opc) {
2983                                                         case ICMD_IADD:
2984                                                                 iptr[0].opc = ICMD_IADDCONST;
2985                                                         icmd_iconst_tail:
2986                                                                 iptr[1].opc = ICMD_NOP;
2987                                                                 OP1_1(TYPE_INT, TYPE_INT);
2988                                                                 COUNT(count_pcmd_op);
2989                                                                 break;
2990                                                         case ICMD_ISUB:
2991                                                                 iptr[0].opc = ICMD_ISUBCONST;
2992                                                                 goto icmd_iconst_tail;
2993 #if SUPPORT_CONST_MUL
2994                                                         case ICMD_IMUL:
2995                                                                 iptr[0].opc = ICMD_IMULCONST;
2996                                                                 goto icmd_iconst_tail;
2997 #else /* SUPPORT_CONST_MUL */
2998                                                         case ICMD_IMUL:
2999                                                                 if (iptr[0].val.i == 0x00000002)
3000                                                                         iptr[0].val.i = 1;
3001                                                                 else if (iptr[0].val.i == 0x00000004)
3002                                                                         iptr[0].val.i = 2;
3003                                                                 else if (iptr[0].val.i == 0x00000008)
3004                                                                         iptr[0].val.i = 3;
3005                                                                 else if (iptr[0].val.i == 0x00000010)
3006                                                                         iptr[0].val.i = 4;
3007                                                                 else if (iptr[0].val.i == 0x00000020)
3008                                                                         iptr[0].val.i = 5;
3009                                                                 else if (iptr[0].val.i == 0x00000040)
3010                                                                         iptr[0].val.i = 6;
3011                                                                 else if (iptr[0].val.i == 0x00000080)
3012                                                                         iptr[0].val.i = 7;
3013                                                                 else if (iptr[0].val.i == 0x00000100)
3014                                                                         iptr[0].val.i = 8;
3015                                                                 else if (iptr[0].val.i == 0x00000200)
3016                                                                         iptr[0].val.i = 9;
3017                                                                 else if (iptr[0].val.i == 0x00000400)
3018                                                                         iptr[0].val.i = 10;
3019                                                                 else if (iptr[0].val.i == 0x00000800)
3020                                                                         iptr[0].val.i = 11;
3021                                                                 else if (iptr[0].val.i == 0x00001000)
3022                                                                         iptr[0].val.i = 12;
3023                                                                 else if (iptr[0].val.i == 0x00002000)
3024                                                                         iptr[0].val.i = 13;
3025                                                                 else if (iptr[0].val.i == 0x00004000)
3026                                                                         iptr[0].val.i = 14;
3027                                                                 else if (iptr[0].val.i == 0x00008000)
3028                                                                         iptr[0].val.i = 15;
3029                                                                 else if (iptr[0].val.i == 0x00010000)
3030                                                                         iptr[0].val.i = 16;
3031                                                                 else if (iptr[0].val.i == 0x00020000)
3032                                                                         iptr[0].val.i = 17;
3033                                                                 else if (iptr[0].val.i == 0x00040000)
3034                                                                         iptr[0].val.i = 18;
3035                                                                 else if (iptr[0].val.i == 0x00080000)
3036                                                                         iptr[0].val.i = 19;
3037                                                                 else if (iptr[0].val.i == 0x00100000)
3038                                                                         iptr[0].val.i = 20;
3039                                                                 else if (iptr[0].val.i == 0x00200000)
3040                                                                         iptr[0].val.i = 21;
3041                                                                 else if (iptr[0].val.i == 0x00400000)
3042                                                                         iptr[0].val.i = 22;
3043                                                                 else if (iptr[0].val.i == 0x00800000)
3044                                                                         iptr[0].val.i = 23;
3045                                                                 else if (iptr[0].val.i == 0x01000000)
3046                                                                         iptr[0].val.i = 24;
3047                                                                 else if (iptr[0].val.i == 0x02000000)
3048                                                                         iptr[0].val.i = 25;
3049                                                                 else if (iptr[0].val.i == 0x04000000)
3050                                                                         iptr[0].val.i = 26;
3051                                                                 else if (iptr[0].val.i == 0x08000000)
3052                                                                         iptr[0].val.i = 27;
3053                                                                 else if (iptr[0].val.i == 0x10000000)
3054                                                                         iptr[0].val.i = 28;
3055                                                                 else if (iptr[0].val.i == 0x20000000)
3056                                                                         iptr[0].val.i = 29;
3057                                                                 else if (iptr[0].val.i == 0x40000000)
3058                                                                         iptr[0].val.i = 30;
3059                                                                 else if (iptr[0].val.i == 0x80000000)
3060                                                                         iptr[0].val.i = 31;
3061                                                                 else {
3062                                                                         PUSHCONST(TYPE_INT);
3063                                                                         break;
3064                                                                 }
3065                                                                 iptr[0].opc = ICMD_IMULPOW2;
3066                                                                 goto icmd_iconst_tail;
3067 #endif /* SUPPORT_CONST_MUL */
3068                                                         case ICMD_IDIV:
3069                                                                 if (iptr[0].val.i == 0x00000002)
3070                                                                         iptr[0].val.i = 1;
3071                                                                 else if (iptr[0].val.i == 0x00000004)
3072                                                                         iptr[0].val.i = 2;
3073                                                                 else if (iptr[0].val.i == 0x00000008)
3074                                                                         iptr[0].val.i = 3;
3075                                                                 else if (iptr[0].val.i == 0x00000010)
3076                                                                         iptr[0].val.i = 4;
3077                                                                 else if (iptr[0].val.i == 0x00000020)
3078                                                                         iptr[0].val.i = 5;
3079                                                                 else if (iptr[0].val.i == 0x00000040)
3080                                                                         iptr[0].val.i = 6;
3081                                                                 else if (iptr[0].val.i == 0x00000080)
3082                                                                         iptr[0].val.i = 7;
3083                                                                 else if (iptr[0].val.i == 0x00000100)
3084                                                                         iptr[0].val.i = 8;
3085                                                                 else if (iptr[0].val.i == 0x00000200)
3086                                                                         iptr[0].val.i = 9;
3087                                                                 else if (iptr[0].val.i == 0x00000400)
3088                                                                         iptr[0].val.i = 10;
3089                                                                 else if (iptr[0].val.i == 0x00000800)
3090                                                                         iptr[0].val.i = 11;
3091                                                                 else if (iptr[0].val.i == 0x00001000)
3092                                                                         iptr[0].val.i = 12;
3093                                                                 else if (iptr[0].val.i == 0x00002000)
3094                                                                         iptr[0].val.i = 13;
3095                                                                 else if (iptr[0].val.i == 0x00004000)
3096                                                                         iptr[0].val.i = 14;
3097                                                                 else if (iptr[0].val.i == 0x00008000)
3098                                                                         iptr[0].val.i = 15;
3099                                                                 else if (iptr[0].val.i == 0x00010000)
3100                                                                         iptr[0].val.i = 16;
3101                                                                 else if (iptr[0].val.i == 0x00020000)
3102                                                                         iptr[0].val.i = 17;
3103                                                                 else if (iptr[0].val.i == 0x00040000)
3104                                                                         iptr[0].val.i = 18;
3105                                                                 else if (iptr[0].val.i == 0x00080000)
3106                                                                         iptr[0].val.i = 19;
3107                                                                 else if (iptr[0].val.i == 0x00100000)
3108                                                                         iptr[0].val.i = 20;
3109                                                                 else if (iptr[0].val.i == 0x00200000)
3110                                                                         iptr[0].val.i = 21;
3111                                                                 else if (iptr[0].val.i == 0x00400000)
3112                                                                         iptr[0].val.i = 22;
3113                                                                 else if (iptr[0].val.i == 0x00800000)
3114                                                                         iptr[0].val.i = 23;
3115                                                                 else if (iptr[0].val.i == 0x01000000)
3116                                                                         iptr[0].val.i = 24;
3117                                                                 else if (iptr[0].val.i == 0x02000000)
3118                                                                         iptr[0].val.i = 25;
3119                                                                 else if (iptr[0].val.i == 0x04000000)
3120                                                                         iptr[0].val.i = 26;
3121                                                                 else if (iptr[0].val.i == 0x08000000)
3122                                                                         iptr[0].val.i = 27;
3123                                                                 else if (iptr[0].val.i == 0x10000000)
3124                                                                         iptr[0].val.i = 28;
3125                                                                 else if (iptr[0].val.i == 0x20000000)
3126                                                                         iptr[0].val.i = 29;
3127                                                                 else if (iptr[0].val.i == 0x40000000)
3128                                                                         iptr[0].val.i = 30;
3129                                                                 else if (iptr[0].val.i == 0x80000000)
3130                                                                         iptr[0].val.i = 31;
3131                                                                 else {
3132                                                                         PUSHCONST(TYPE_INT);
3133                                                                         break;
3134                                                                 }
3135                                                                 iptr[0].opc = ICMD_IDIVPOW2;
3136                                                                 goto icmd_iconst_tail;
3137                                                         case ICMD_IREM:
3138                                                                 /*log_text("stack.c: ICMD_ICONST/ICMD_IREM");*/
3139                                                                 if ((iptr[0].val.i == 0x00000002) ||
3140                                                                         (iptr[0].val.i == 0x00000004) ||
3141                                                                         (iptr[0].val.i == 0x00000008) ||
3142                                                                         (iptr[0].val.i == 0x00000010) ||
3143                                                                         (iptr[0].val.i == 0x00000020) ||
3144                                                                         (iptr[0].val.i == 0x00000040) ||
3145                                                                         (iptr[0].val.i == 0x00000080) ||
3146                                                                         (iptr[0].val.i == 0x00000100) ||
3147                                                                         (iptr[0].val.i == 0x00000200) ||
3148                                                                         (iptr[0].val.i == 0x00000400) ||
3149                                                                         (iptr[0].val.i == 0x00000800) ||
3150                                                                         (iptr[0].val.i == 0x00001000) ||
3151                                                                         (iptr[0].val.i == 0x00002000) ||
3152                                                                         (iptr[0].val.i == 0x00004000) ||
3153                                                                         (iptr[0].val.i == 0x00008000) ||
3154                                                                         (iptr[0].val.i == 0x00010000) ||
3155                                                                         (iptr[0].val.i == 0x00020000) ||
3156                                                                         (iptr[0].val.i == 0x00040000) ||
3157                                                                         (iptr[0].val.i == 0x00080000) ||
3158                                                                         (iptr[0].val.i == 0x00100000) ||
3159                                                                         (iptr[0].val.i == 0x00200000) ||
3160                                                                         (iptr[0].val.i == 0x00400000) ||
3161                                                                         (iptr[0].val.i == 0x00800000) ||
3162                                                                         (iptr[0].val.i == 0x01000000) ||
3163                                                                         (iptr[0].val.i == 0x02000000) ||
3164                                                                         (iptr[0].val.i == 0x04000000) ||
3165                                                                         (iptr[0].val.i == 0x08000000) ||
3166                                                                         (iptr[0].val.i == 0x10000000) ||
3167                                                                         (iptr[0].val.i == 0x20000000) ||
3168                                                                         (iptr[0].val.i == 0x40000000) ||
3169                                                                         (iptr[0].val.i == 0x80000000)) {
3170                                                                         iptr[0].opc = ICMD_IREMPOW2;
3171                                                                         iptr[0].val.i -= 1;
3172                                                                         goto icmd_iconst_tail;
3173                                                                 }
3174                                                                 PUSHCONST(TYPE_INT);
3175                                                                 break;
3176 #if SUPPORT_CONST_LOGICAL
3177                                                         case ICMD_IAND:
3178                                                                 iptr[0].opc = ICMD_IANDCONST;
3179                                                                 goto icmd_iconst_tail;
3180                                                         case ICMD_IOR:
3181                                                                 iptr[0].opc = ICMD_IORCONST;
3182                                                                 goto icmd_iconst_tail;
3183                                                         case ICMD_IXOR:
3184                                                                 iptr[0].opc = ICMD_IXORCONST;
3185                                                                 goto icmd_iconst_tail;
3186 #endif /* SUPPORT_CONST_LOGICAL */
3187                                                         case ICMD_ISHL:
3188                                                                 iptr[0].opc = ICMD_ISHLCONST;
3189                                                                 goto icmd_iconst_tail;
3190                                                         case ICMD_ISHR:
3191                                                                 iptr[0].opc = ICMD_ISHRCONST;
3192                                                                 goto icmd_iconst_tail;
3193                                                         case ICMD_IUSHR:
3194                                                                 iptr[0].opc = ICMD_IUSHRCONST;
3195                                                                 goto icmd_iconst_tail;
3196 #if SUPPORT_LONG_SHIFT
3197                                                         case ICMD_LSHL:
3198                                                                 iptr[0].opc = ICMD_LSHLCONST;
3199                                                                 goto icmd_lconst_tail;
3200                                                         case ICMD_LSHR:
3201                                                                 iptr[0].opc = ICMD_LSHRCONST;
3202                                                                 goto icmd_lconst_tail;
3203                                                         case ICMD_LUSHR:
3204                                                                 iptr[0].opc = ICMD_LUSHRCONST;
3205                                                                 goto icmd_lconst_tail;
3206 #endif /* SUPPORT_LONG_SHIFT */
3207                                                         case ICMD_IF_ICMPEQ:
3208                                                                 iptr[1].opc = ICMD_IFEQ;
3209                                                         icmd_if_icmp_tail:
3210 /*                                                              iptr[0].op1 = iptr[1].op1; */
3211                                                                 /* IF_ICMPxx is the last instruction in the  
3212                                                                    basic block, just remove it. */
3213                                                                 iptr[0].opc = ICMD_NOP;
3214                                                                 iptr[1].val.i = iptr[0].val.i;
3215                                                                 SETDST;
3216 /*                                                              bptr->icount--; */
3217 /*                                                              len--; */
3218 #if 0
3219                                                                 OP1_0(TYPE_INT);
3220                                                                 tbptr = m->basicblocks +
3221                                                                         m->basicblockindex[iptr[1].op1];
3222
3223                                                                 iptr[1].target = (void *) tbptr;
3224
3225                                                                 MARKREACHED(tbptr, copy);
3226                                                                 COUNT(count_pcmd_bra);
3227 #endif
3228                                                                 break;
3229                                                         case ICMD_IF_ICMPLT:
3230                                                                 iptr[1].opc = ICMD_IFLT;
3231                                                                 goto icmd_if_icmp_tail;
3232                                                         case ICMD_IF_ICMPLE:
3233                                                                 iptr[1].opc = ICMD_IFLE;
3234                                                                 goto icmd_if_icmp_tail;
3235                                                         case ICMD_IF_ICMPNE:
3236                                                                 iptr[1].opc = ICMD_IFNE;
3237                                                                 goto icmd_if_icmp_tail;
3238                                                         case ICMD_IF_ICMPGT:
3239                                                                 iptr[1].opc = ICMD_IFGT;
3240                                                                 goto icmd_if_icmp_tail;
3241                                                         case ICMD_IF_ICMPGE:
3242                                                                 iptr[1].opc = ICMD_IFGE;
3243                                                                 goto icmd_if_icmp_tail;
3244
3245 #if SUPPORT_CONST_STORE
3246                                                         case ICMD_IASTORE:
3247                                                         case ICMD_BASTORE:
3248                                                         case ICMD_CASTORE:
3249                                                         case ICMD_SASTORE:
3250 # if defined(ENABLE_INTRP)
3251                                                                 if (!opt_intrp) {
3252 # endif
3253 # if SUPPORT_CONST_STORE_ZERO_ONLY
3254                                                                         if (iptr[0].val.i == 0) {
3255 # endif
3256                                                                                 switch (iptr[1].opc) {
3257                                                                                 case ICMD_IASTORE:
3258                                                                                         iptr[0].opc = ICMD_IASTORECONST;
3259                                                                                         break;
3260                                                                                 case ICMD_BASTORE:
3261                                                                                         iptr[0].opc = ICMD_BASTORECONST;
3262                                                                                         break;
3263                                                                                 case ICMD_CASTORE:
3264                                                                                         iptr[0].opc = ICMD_CASTORECONST;
3265                                                                                         break;
3266                                                                                 case ICMD_SASTORE:
3267                                                                                         iptr[0].opc = ICMD_SASTORECONST;
3268                                                                                         break;
3269                                                                                 }
3270
3271                                                                                 iptr[1].opc = ICMD_NOP;
3272                                                                                 OPTT2_0(TYPE_INT, TYPE_ADR);
3273                                                                                 COUNT(count_pcmd_op);
3274 # if SUPPORT_CONST_STORE_ZERO_ONLY
3275                                                                         } 
3276                                                                         else
3277                                                                                 PUSHCONST(TYPE_INT);
3278 # endif
3279 # if defined(ENABLE_INTRP)
3280                                                                 } 
3281                                                                 else
3282                                                                         PUSHCONST(TYPE_INT);
3283 # endif
3284                                                                 break;
3285
3286                                                         case ICMD_PUTSTATIC:
3287                                                         case ICMD_PUTFIELD:
3288 # if defined(ENABLE_INTRP)
3289                                                                 if (!opt_intrp) {
3290 # endif
3291 # if SUPPORT_CONST_STORE_ZERO_ONLY
3292                                                                         if (iptr[0].val.i == 0) {
3293 # endif
3294                                                                                 switch (iptr[1].opc) {
3295                                                                                 case ICMD_PUTSTATIC:
3296                                                                                         iptr[0].opc = ICMD_PUTSTATICCONST;
3297                                                                                         SETDST;
3298                                                                                         break;
3299                                                                                 case ICMD_PUTFIELD:
3300                                                                                         iptr[0].opc = ICMD_PUTFIELDCONST;
3301                                                                                         OP1_0(TYPE_ADR);
3302                                                                                         break;
3303                                                                                 }
3304
3305                                                                                 iptr[1].opc = ICMD_NOP;
3306                                                                                 iptr[0].op1 = TYPE_INT;
3307                                                                                 COUNT(count_pcmd_op);
3308 # if SUPPORT_CONST_STORE_ZERO_ONLY
3309                                                                         } 
3310                                                                         else
3311                                                                                 PUSHCONST(TYPE_INT);
3312 # endif
3313 # if defined(ENABLE_INTRP)
3314                                                                 } 
3315                                                                 else
3316                                                                         PUSHCONST(TYPE_INT);
3317 # endif
3318                                                                 break;
3319 #endif /* SUPPORT_CONST_STORE */
3320                                                         default:
3321                                                                 PUSHCONST(TYPE_INT);
3322                                                         }
3323                                                 }
3324                                                 else
3325                                                         PUSHCONST(TYPE_INT);
3326                                                 break;
3327
3328                                         case ICMD_LCONST:
3329                                                 COUNT(count_pcmd_load);
3330                                                 if (len > 0) {
3331                                                         switch (iptr[1].opc) {
3332 #if SUPPORT_LONG_ADD
3333                                                         case ICMD_LADD:
3334                                                                 iptr[0].opc = ICMD_LADDCONST;
3335                                                         icmd_lconst_tail:
3336                                                                 iptr[1].opc = ICMD_NOP;
3337                                                                 OP1_1(TYPE_LNG,TYPE_LNG);
3338                                                                 COUNT(count_pcmd_op);
3339                                                                 break;
3340                                                         case ICMD_LSUB:
3341                                                                 iptr[0].opc = ICMD_LSUBCONST;
3342                                                                 goto icmd_lconst_tail;
3343 #endif /* SUPPORT_LONG_ADD */
3344 #if SUPPORT_LONG_MUL && SUPPORT_CONST_MUL
3345                                                         case ICMD_LMUL:
3346                                                                 iptr[0].opc = ICMD_LMULCONST;
3347                                                                 goto icmd_lconst_tail;
3348 #else /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
3349 # if SUPPORT_LONG_SHIFT
3350                                                         case ICMD_LMUL:
3351                                                                 if (iptr[0].val.l == 0x00000002)
3352                                                                         iptr[0].val.i = 1;
3353                                                                 else if (iptr[0].val.l == 0x00000004)
3354                                                                         iptr[0].val.i = 2;
3355                                                                 else if (iptr[0].val.l == 0x00000008)
3356                                                                         iptr[0].val.i = 3;
3357                                                                 else if (iptr[0].val.l == 0x00000010)
3358                                                                         iptr[0].val.i = 4;
3359                                                                 else if (iptr[0].val.l == 0x00000020)
3360                                                                         iptr[0].val.i = 5;
3361                                                                 else if (iptr[0].val.l == 0x00000040)
3362                                                                         iptr[0].val.i = 6;
3363                                                                 else if (iptr[0].val.l == 0x00000080)
3364                                                                         iptr[0].val.i = 7;
3365                                                                 else if (iptr[0].val.l == 0x00000100)
3366                                                                         iptr[0].val.i = 8;
3367                                                                 else if (iptr[0].val.l == 0x00000200)
3368                                                                         iptr[0].val.i = 9;
3369                                                                 else if (iptr[0].val.l == 0x00000400)
3370                                                                         iptr[0].val.i = 10;
3371                                                                 else if (iptr[0].val.l == 0x00000800)
3372                                                                         iptr[0].val.i = 11;
3373                                                                 else if (iptr[0].val.l == 0x00001000)
3374                                                                         iptr[0].val.i = 12;
3375                                                                 else if (iptr[0].val.l == 0x00002000)
3376                                                                         iptr[0].val.i = 13;
3377                                                                 else if (iptr[0].val.l == 0x00004000)
3378                                                                         iptr[0].val.i = 14;
3379                                                                 else if (iptr[0].val.l == 0x00008000)
3380                                                                         iptr[0].val.i = 15;
3381                                                                 else if (iptr[0].val.l == 0x00010000)
3382                                                                         iptr[0].val.i = 16;
3383                                                                 else if (iptr[0].val.l == 0x00020000)
3384                                                                         iptr[0].val.i = 17;
3385                                                                 else if (iptr[0].val.l == 0x00040000)
3386                                                                         iptr[0].val.i = 18;
3387                                                                 else if (iptr[0].val.l == 0x00080000)
3388                                                                         iptr[0].val.i = 19;
3389                                                                 else if (iptr[0].val.l == 0x00100000)
3390                                                                         iptr[0].val.i = 20;
3391                                                                 else if (iptr[0].val.l == 0x00200000)
3392                                                                         iptr[0].val.i = 21;
3393                                                                 else if (iptr[0].val.l == 0x00400000)
3394                                                                         iptr[0].val.i = 22;
3395                                                                 else if (iptr[0].val.l == 0x00800000)
3396                                                                         iptr[0].val.i = 23;
3397                                                                 else if (iptr[0].val.l == 0x01000000)
3398                                                                         iptr[0].val.i = 24;
3399                                                                 else if (iptr[0].val.l == 0x02000000)
3400                                                                         iptr[0].val.i = 25;
3401                                                                 else if (iptr[0].val.l == 0x04000000)
3402                                                                         iptr[0].val.i = 26;
3403                                                                 else if (iptr[0].val.l == 0x08000000)
3404                                                                         iptr[0].val.i = 27;
3405                                                                 else if (iptr[0].val.l == 0x10000000)
3406                                                                         iptr[0].val.i = 28;
3407                                                                 else if (iptr[0].val.l == 0x20000000)
3408                                                                         iptr[0].val.i = 29;
3409                                                                 else if (iptr[0].val.l == 0x40000000)
3410                                                                         iptr[0].val.i = 30;
3411                                                                 else if (iptr[0].val.l == 0x80000000)
3412                                                                         iptr[0].val.i = 31;
3413                                                                 else {
3414                                                                         PUSHCONST(TYPE_LNG);
3415                                                                         break;
3416                                                                 }
3417                                                                 iptr[0].opc = ICMD_LMULPOW2;
3418                                                                 goto icmd_lconst_tail;
3419 # endif /* SUPPORT_LONG_SHIFT */
3420 #endif /* SUPPORT_LONG_MUL && SUPPORT_CONST_MUL */
3421
3422 #if SUPPORT_LONG_DIV_POW2
3423                                                         case ICMD_LDIV:
3424                                                                 if (iptr[0].val.l == 0x00000002)
3425                                                                         iptr[0].val.i = 1;
3426                                                                 else if (iptr[0].val.l == 0x00000004)
3427                                                                         iptr[0].val.i = 2;
3428                                                                 else if (iptr[0].val.l == 0x00000008)
3429                                                                         iptr[0].val.i = 3;
3430                                                                 else if (iptr[0].val.l == 0x00000010)
3431                                                                         iptr[0].val.i = 4;
3432                                                                 else if (iptr[0].val.l == 0x00000020)
3433                                                                         iptr[0].val.i = 5;
3434                                                                 else if (iptr[0].val.l == 0x00000040)
3435                                                                         iptr[0].val.i = 6;
3436                                                                 else if (iptr[0].val.l == 0x00000080)
3437                                                                         iptr[0].val.i = 7;
3438                                                                 else if (iptr[0].val.l == 0x00000100)
3439                                                                         iptr[0].val.i = 8;
3440                                                                 else if (iptr[0].val.l == 0x00000200)
3441                                                                         iptr[0].val.i = 9;
3442                                                                 else if (iptr[0].val.l == 0x00000400)
3443                                                                         iptr[0].val.i = 10;
3444                                                                 else if (iptr[0].val.l == 0x00000800)
3445                                                                         iptr[0].val.i = 11;
3446                                                                 else if (iptr[0].val.l == 0x00001000)
3447                                                                         iptr[0].val.i = 12;
3448                                                                 else if (iptr[0].val.l == 0x00002000)
3449                                                                         iptr[0].val.i = 13;
3450                                                                 else if (iptr[0].val.l == 0x00004000)
3451                                                                         iptr[0].val.i = 14;
3452                                                                 else if (iptr[0].val.l == 0x00008000)
3453                                                                         iptr[0].val.i = 15;
3454                                                                 else if (iptr[0].val.l == 0x00010000)
3455                                                                         iptr[0].val.i = 16;
3456                                                                 else if (iptr[0].val.l == 0x00020000)
3457                                                                         iptr[0].val.i = 17;
3458                                                                 else if (iptr[0].val.l == 0x00040000)
3459                                                                         iptr[0].val.i = 18;
3460                                                                 else if (iptr[0].val.l == 0x00080000)
3461                                                                         iptr[0].val.i = 19;
3462                                                                 else if (iptr[0].val.l == 0x00100000)
3463                                                                         iptr[0].val.i = 20;
3464                                                                 else if (iptr[0].val.l == 0x00200000)
3465                                                                         iptr[0].val.i = 21;
3466                                                                 else if (iptr[0].val.l == 0x00400000)
3467                                                                         iptr[0].val.i = 22;
3468                                                                 else if (iptr[0].val.l == 0x00800000)
3469                                                                         iptr[0].val.i = 23;
3470                                                                 else if (iptr[0].val.l == 0x01000000)
3471                                                                         iptr[0].val.i = 24;
3472                                                                 else if (iptr[0].val.l == 0x02000000)
3473                                                                         iptr[0].val.i = 25;
3474                                                                 else if (iptr[0].val.l == 0x04000000)
3475                                                                         iptr[0].val.i = 26;
3476                                                                 else if (iptr[0].val.l == 0x08000000)
3477                                                                         iptr[0].val.i = 27;
3478                                                                 else if (iptr[0].val.l == 0x10000000)
3479                                                                         iptr[0].val.i = 28;
3480                                                                 else if (iptr[0].val.l == 0x20000000)
3481                                                                         iptr[0].val.i = 29;
3482                                                                 else if (iptr[0].val.l == 0x40000000)
3483                                                                         iptr[0].val.i = 30;
3484                                                                 else if (iptr[0].val.l == 0x80000000)
3485                                                                         iptr[0].val.i = 31;
3486                                                                 else {
3487                                                                         PUSHCONST(TYPE_LNG);
3488                                                                         break;
3489                                                                 }
3490                                                                 iptr[0].opc = ICMD_LDIVPOW2;
3491                                                                 goto icmd_lconst_tail;
3492 #endif /* SUPPORT_LONG_DIV_POW2 */
3493
3494 #if SUPPORT_LONG_REM_POW2
3495                                                         case ICMD_LREM:
3496                                                                 if ((iptr[0].val.l == 0x00000002) ||
3497                                                                         (iptr[0].val.l == 0x00000004) ||
3498                                                                         (iptr[0].val.l == 0x00000008) ||
3499                                                                         (iptr[0].val.l == 0x00000010) ||
3500                                                                         (iptr[0].val.l == 0x00000020) ||
3501                                                                         (iptr[0].val.l == 0x00000040) ||
3502                                                                         (iptr[0].val.l == 0x00000080) ||
3503                                                                         (iptr[0].val.l == 0x00000100) ||
3504                                                                         (iptr[0].val.l == 0x00000200) ||
3505                                                                         (iptr[0].val.l == 0x00000400) ||
3506                                                                         (iptr[0].val.l == 0x00000800) ||
3507                                                                         (iptr[0].val.l == 0x00001000) ||
3508                                                                         (iptr[0].val.l == 0x00002000) ||
3509                                                                         (iptr[0].val.l == 0x00004000) ||
3510                                                                         (iptr[0].val.l == 0x00008000) ||
3511                                                                         (iptr[0].val.l == 0x00010000) ||
3512                                                                         (iptr[0].val.l == 0x00020000) ||
3513                                                                         (iptr[0].val.l == 0x00040000) ||
3514                                                                         (iptr[0].val.l == 0x00080000) ||
3515                                                                         (iptr[0].val.l == 0x00100000) ||
3516                                                                         (iptr[0].val.l == 0x00200000) ||
3517                                                                         (iptr[0].val.l == 0x00400000) ||
3518                                                                         (iptr[0].val.l == 0x00800000) ||
3519                                                                         (iptr[0].val.l == 0x01000000) ||
3520                                                                         (iptr[0].val.l == 0x02000000) ||
3521                                                                         (iptr[0].val.l == 0x04000000) ||
3522                                                                         (iptr[0].val.l == 0x08000000) ||
3523                                                                         (iptr[0].val.l == 0x10000000) ||
3524                                                                         (iptr[0].val.l == 0x20000000) ||
3525                                                                         (iptr[0].val.l == 0x40000000) ||
3526                                                                         (iptr[0].val.l == 0x80000000)) {
3527                                                                         iptr[0].opc = ICMD_LREMPOW2;
3528                                                                         iptr[0].val.l -= 1;
3529                                                                         goto icmd_lconst_tail;
3530                                                                 }
3531                                                                 PUSHCONST(TYPE_LNG);
3532                                                                 break;
3533 #endif /* SUPPORT_LONG_REM_POW2 */
3534
3535 #if SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL
3536
3537                                                         case ICMD_LAND:
3538                                                                 iptr[0].opc = ICMD_LANDCONST;
3539                                                                 goto icmd_lconst_tail;
3540                                                         case ICMD_LOR:
3541                                                                 iptr[0].opc = ICMD_LORCONST;
3542                                                                 goto icmd_lconst_tail;
3543                                                         case ICMD_LXOR:
3544                                                                 iptr[0].opc = ICMD_LXORCONST;
3545                                                                 goto icmd_lconst_tail;
3546 #endif /* SUPPORT_LONG_LOGICAL && SUPPORT_CONST_LOGICAL */
3547
3548 #if SUPPORT_LONG_CMP_CONST
3549                                                         case ICMD_LCMP:
3550                                                                 if ((len > 1) && (iptr[2].val.i == 0)) {
3551                                                                         switch (iptr[2].opc) {
3552                                                                         case ICMD_IFEQ:
3553                                                                                 iptr[0].opc = ICMD_IF_LEQ;
3554                                                                         icmd_lconst_lcmp_tail:
3555                                                                                 iptr[0].op1 = iptr[2].op1;
3556                                                                                 iptr[1].opc = ICMD_NOP;
3557                                                                                 iptr[2].opc = ICMD_NOP;
3558
3559 /*                                                                              bptr->icount -= 2; */
3560 /*                                                                              len -= 2; */
3561
3562                                                                                 OP1_0(TYPE_LNG);
3563                                                                                 tbptr = m->basicblocks +
3564                                                                                         m->basicblockindex[iptr[0].op1];
3565
3566                                                                                 iptr[0].target = (void *) tbptr;
3567
3568                                                                                 MARKREACHED(tbptr, copy);
3569                                                                                 COUNT(count_pcmd_bra);
3570                                                                                 COUNT(count_pcmd_op);
3571                                                                                 break;
3572                                                                         case ICMD_IFNE:
3573                                                                                 iptr[0].opc = ICMD_IF_LNE;
3574                                                                                 goto icmd_lconst_lcmp_tail;
3575                                                                         case ICMD_IFLT:
3576                                                                                 iptr[0].opc = ICMD_IF_LLT;
3577                                                                                 goto icmd_lconst_lcmp_tail;
3578                                                                         case ICMD_IFGT:
3579                                                                                 iptr[0].opc = ICMD_IF_LGT;
3580                                                                                 goto icmd_lconst_lcmp_tail;
3581                                                                         case ICMD_IFLE:
3582                                                                                 iptr[0].opc = ICMD_IF_LLE;
3583                                                                                 goto icmd_lconst_lcmp_tail;
3584                                                                         case ICMD_IFGE:
3585                                                                                 iptr[0].opc = ICMD_IF_LGE;
3586                                                                                 goto icmd_lconst_lcmp_tail;
3587                                                                         default:
3588                                                                                 PUSHCONST(TYPE_LNG);
3589                                                                         } /* switch (iptr[2].opc) */
3590                                                                 } /* if (iptr[2].val.i == 0) */
3591                                                                 else
3592                                                                         PUSHCONST(TYPE_LNG);
3593                                                                 break;
3594 #endif /* SUPPORT_LONG_CMP_CONST */
3595
3596 #if SUPPORT_CONST_STORE
3597                                                         case ICMD_LASTORE:
3598 # if defined(ENABLE_INTRP)
3599                                                                 if (!opt_intrp) {
3600 # endif
3601 # if SUPPORT_CONST_STORE_ZERO_ONLY
3602                                                                         if (iptr[0].val.l == 0) {
3603 # endif
3604                                                                                 iptr[0].opc = ICMD_LASTORECONST;
3605                                                                                 iptr[1].opc = ICMD_NOP;
3606                                                                                 OPTT2_0(TYPE_INT, TYPE_ADR);
3607                                                                                 COUNT(count_pcmd_op);
3608 # if SUPPORT_CONST_STORE_ZERO_ONLY
3609                                                                         } 
3610                                                                         else
3611                                                                                 PUSHCONST(TYPE_LNG);
3612 # endif
3613 # if defined(ENABLE_INTRP)
3614                                                                 } 
3615                                                                 else
3616                                                                         PUSHCONST(TYPE_LNG);
3617 # endif
3618                                                                 break;
3619
3620                                                         case ICMD_PUTSTATIC:
3621                                                         case ICMD_PUTFIELD:
3622 # if defined(ENABLE_INTRP)
3623                                                                 if (!opt_intrp) {
3624 # endif
3625 # if SUPPORT_CONST_STORE_ZERO_ONLY
3626                                                                         if (iptr[0].val.l == 0) {
3627 # endif
3628                                                                                 switch (iptr[1].opc) {
3629                                                                                 case ICMD_PUTSTATIC:
3630                                                                                         iptr[0].opc = ICMD_PUTSTATICCONST;
3631                                                                                         SETDST;
3632                                                                                         break;
3633                                                                                 case ICMD_PUTFIELD:
3634                                                                                         iptr[0].opc = ICMD_PUTFIELDCONST;
3635                                                                                         OP1_0(TYPE_ADR);
3636                                                                                         break;
3637                                                                                 }
3638
3639                                                                                 iptr[1].opc = ICMD_NOP;
3640                                                                                 iptr[0].op1 = TYPE_LNG;
3641                                                                                 COUNT(count_pcmd_op);
3642 # if SUPPORT_CONST_STORE_ZERO_ONLY
3643                                                                         } 
3644                                                                         else
3645                                                                                 PUSHCONST(TYPE_LNG);
3646 # endif
3647 # if defined(ENABLE_INTRP)
3648                                                                 } 
3649                                                                 else
3650                                                                         PUSHCONST(TYPE_LNG);
3651 # endif
3652                                                                 break;
3653 #endif /* SUPPORT_CONST_STORE */
3654                                                         default:
3655                                                                 PUSHCONST(TYPE_LNG);
3656                                                         }
3657                                                 }
3658                                                 else
3659                                                         PUSHCONST(TYPE_LNG);
3660                                                 break;
3661
3662                                         case ICMD_FCONST:
3663                                                 COUNT(count_pcmd_load);
3664                                                 PUSHCONST(TYPE_FLT);
3665                                                 break;
3666
3667                                         case ICMD_DCONST:
3668                                                 COUNT(count_pcmd_load);
3669                                                 PUSHCONST(TYPE_DBL);
3670                                                 break;
3671
3672                                         case ICMD_ACONST:
3673                                                 COUNT(count_pcmd_load);
3674 #if SUPPORT_CONST_STORE
3675 # if defined(ENABLE_INTRP)
3676                                                 if (!opt_intrp) {
3677 # endif
3678                                                         /* We can only optimize if the ACONST is resolved
3679                                                          * and there is an instruction after it. */
3680
3681                                                         if ((len > 0) && INSTRUCTION_IS_RESOLVED(iptr))
3682                                                         {
3683                                                                 switch (iptr[1].opc) {
3684                                                                 case ICMD_AASTORE:
3685                                                                         /* We can only optimize for NULL values
3686                                                                          * here because otherwise a checkcast is
3687                                                                          * required. */
3688                                                                         if (iptr->val.a != NULL)
3689                                                                                 goto aconst_no_transform;
3690
3691                                                                         iptr[0].opc = ICMD_AASTORECONST;
3692                                                                         OPTT2_0(TYPE_INT, TYPE_ADR);
3693
3694                                                                         iptr[1].opc = ICMD_NOP;
3695                                                                         COUNT(count_pcmd_op);
3696                                                                         break;
3697
3698                                                                 case ICMD_PUTSTATIC:
3699                                                                 case ICMD_PUTFIELD:
3700 # if SUPPORT_CONST_STORE_ZERO_ONLY
3701                                                                         if (iptr->val.a == 0) {
3702 # endif
3703
3704                                                                                 switch (iptr[1].opc) {
3705                                                                                 case ICMD_PUTSTATIC:
3706                                                                                         iptr[0].opc = ICMD_PUTSTATICCONST;
3707                                                                                         iptr[0].op1 = TYPE_ADR;
3708                                                                                         SETDST;
3709                                                                                         break;
3710                                                                                 case ICMD_PUTFIELD:
3711                                                                                         iptr[0].opc = ICMD_PUTFIELDCONST;
3712                                                                                         iptr[0].op1 = TYPE_ADR;
3713                                                                                         OP1_0(TYPE_ADR);
3714                                                                                         break;
3715                                                                                 }
3716
3717                                                                                 iptr[1].opc = ICMD_NOP;
3718                                                                                 COUNT(count_pcmd_op);
3719
3720 # if SUPPORT_CONST_STORE_ZERO_ONLY
3721                                                                         }
3722                                                                         else
3723                                                                                 /* no transformation */
3724                                                                                 PUSHCONST(TYPE_ADR);
3725 # endif
3726                                                                         break;
3727
3728                                                                 default:
3729                                                                 aconst_no_transform:
3730                                                                         /* no transformation */
3731                                                                         PUSHCONST(TYPE_ADR);
3732                                                                 }
3733                                                         }
3734                                                         else {
3735                                                                 /* no transformation */
3736                                                                 PUSHCONST(TYPE_ADR);
3737                                                         }
3738 # if defined(ENABLE_INTRP)
3739                                                 }
3740                                                 else
3741                                                         PUSHCONST(TYPE_ADR);
3742 # endif
3743 #else /* SUPPORT_CONST_STORE */
3744                                                 PUSHCONST(TYPE_ADR);
3745 #endif /* SUPPORT_CONST_STORE */
3746                                                 break;
3747
3748                                                 /* pop 0 push 1 load */
3749                                                 
3750                                         case ICMD_ILOAD:
3751                                         case ICMD_LLOAD:
3752                                         case ICMD_FLOAD:
3753                                         case ICMD_DLOAD:
3754                                         case ICMD_ALOAD:
3755                                                 COUNT(count_load_instruction);
3756                                                 i = opcode - ICMD_ILOAD;
3757 #if defined(ENABLE_INTRP)
3758                                                 if (!opt_intrp)
3759 #endif
3760                                                         rd->locals[iptr->op1][i].type = i;
3761                                                 LOAD(i, LOCALVAR, iptr->op1);
3762                                                 break;
3763
3764                                                 /* pop 2 push 1 */
3765
3766                                         case ICMD_LALOAD:
3767                                         case ICMD_IALOAD:
3768                                         case ICMD_FALOAD:
3769                                         case ICMD_DALOAD:
3770                                         case ICMD_AALOAD:
3771                                                 COUNT(count_check_null);
3772                                                 COUNT(count_check_bound);
3773                                                 COUNT(count_pcmd_mem);
3774                                                 OP2IAT_1(opcode - ICMD_IALOAD);
3775                                                 break;
3776
3777                                         case ICMD_BALOAD:
3778                                         case ICMD_CALOAD:
3779                                         case ICMD_SALOAD:
3780                                                 COUNT(count_check_null);
3781                                                 COUNT(count_check_bound);
3782                                                 COUNT(count_pcmd_mem);
3783                                                 OP2IAT_1(TYPE_INT);
3784                                                 break;
3785
3786                                                 /* pop 0 push 0 iinc */
3787
3788                                         case ICMD_IINC:
3789 #if defined(ENABLE_STATISTICS)
3790                                                 if (opt_stat) {
3791                                                         i = stackdepth;
3792                                                         if (i >= 10)
3793                                                                 count_store_depth[10]++;
3794                                                         else
3795                                                                 count_store_depth[i]++;
3796                                                 }
3797 #endif
3798                                                 last_store[5 * iptr->op1 + TYPE_INT] = bptr->icount - len - 1;
3799
3800                                                 copy = curstack;
3801                                                 i = stackdepth - 1;
3802                                                 while (copy) {
3803                                                         if ((copy->varkind == LOCALVAR) &&
3804                                                                 (copy->varnum == iptr->op1)) {
3805                                                                 copy->varkind = TEMPVAR;
3806                                                                 copy->varnum = i;
3807                                                         }
3808                                                         i--;
3809                                                         copy = copy->prev;
3810                                                 }
3811                                                 
3812                                                 SETDST;
3813                                                 break;
3814
3815                                                 /* pop 1 push 0 store */
3816
3817                                         case ICMD_ISTORE:
3818                                         case ICMD_LSTORE:
3819                                         case ICMD_FSTORE:
3820                                         case ICMD_DSTORE:
3821                                         case ICMD_ASTORE:
3822                                                 REQUIRE_1;
3823
3824                                         i = opcode - ICMD_ISTORE;
3825 #if defined(ENABLE_INTRP)
3826                                                 if (!opt_intrp)
3827 #endif
3828                                                         rd->locals[iptr->op1][i].type = i;
3829 #if defined(ENABLE_STATISTICS)
3830                                         if (opt_stat) {
3831                                                 count_pcmd_store++;
3832                                                 i = new - curstack;
3833                                                 if (i >= 20)
3834                                                         count_store_length[20]++;
3835                                                 else
3836                                                         count_store_length[i]++;
3837                                                 i = stackdepth - 1;
3838                                                 if (i >= 10)
3839                                                         count_store_depth[10]++;
3840                                                 else
3841                                                         count_store_depth[i]++;
3842                                         }
3843 #endif
3844                                         /* check for conflicts as described in Figure 5.2 */
3845                                         copy = curstack->prev;
3846                                         i = stackdepth - 2;
3847                                         while (copy) {
3848                                                 if ((copy->varkind == LOCALVAR) &&
3849                                                         (copy->varnum == iptr->op1)) {
3850                                                         copy->varkind = TEMPVAR;
3851                                                         copy->varnum = i;
3852                                                 }
3853                                                 i--;
3854                                                 copy = copy->prev;
3855                                         }
3856
3857                                         /* do not change instack Stackslots */
3858                                         /* it won't improve performance if we copy the interface */
3859                                         /* at the BB begin or here, and lsra relies that no      */
3860                                         /* instack stackslot is marked LOCALVAR */
3861                                         if (curstack->varkind == STACKVAR)
3862                                                 goto _possible_conflict;
3863
3864                                         /* check for a DUPX,SWAP while the lifetime of curstack */
3865                                         /* and as creator curstack */
3866                                         if (last_dupx != -1) { 
3867                                                 /* we have to look at the dst stack of DUPX */
3868                                                 /* == src Stack of PEI */
3869                                                 copy = bptr->iinstr[last_dupx].dst;
3870                                                 /*
3871                                                 if (last_pei == 0)
3872                                                         copy = bptr->instack;
3873                                                 else
3874                                                         copy = bptr->iinstr[last_pei-1].dst;
3875                                                 */
3876                                                 if ((copy != NULL) && (curstack <= copy)) {
3877                                                         /* curstack alive at or created by DUPX */
3878
3879                                                         /* TODO:.... */
3880                                                         /* now look, if there is a LOCALVAR at anyone of */
3881                                                         /* the src stacklots used by DUPX */
3882
3883                                                         goto _possible_conflict;
3884                                                 }
3885                                         }
3886
3887                                         /* check for a PEI while the lifetime of curstack */
3888                                         if (last_pei != -1) { 
3889                                                 /* && there are exception handler in this method */
3890                                                 /* when this is checked prevent ARGVAR from      */
3891                                                 /* overwriting LOCALVAR!!! */
3892
3893                                                 /* we have to look at the stack _before_ the PEI! */
3894                                                 /* == src Stack of PEI */
3895                                                 if (last_pei == 0)
3896                                                         copy = bptr->instack;
3897                                                 else
3898                                                         copy = bptr->iinstr[last_pei-1].dst;
3899                                                 if ((copy != NULL) && (curstack <= copy)) {
3900                                                         /* curstack alive at PEI */
3901                                                         goto _possible_conflict;
3902                                                 }
3903                                         }
3904                                         
3905                                         /* check if there is a possible conflicting XSTORE */
3906                                         if (last_store[5 * iptr->op1 + opcode - ICMD_ISTORE] != -1) {
3907                                                 /* we have to look at the stack _before_ the XSTORE! */
3908                                                 /* == src Stack of XSTORE */
3909                                                 if (last_store[5 * iptr->op1 + opcode - ICMD_ISTORE] == 0)
3910                                                         copy = bptr->instack;
3911                                                 else
3912                                                         copy = bptr->iinstr[last_store[5 * iptr->op1 + opcode - ICMD_ISTORE] - 1].dst;
3913                                                 if ((copy != NULL) && (curstack <= copy)) {
3914                                                         /* curstack alive at Last Store */
3915                                                         goto _possible_conflict;
3916                                                 }
3917                                         }
3918
3919                                         /* check if there is a conflict with a XLOAD */
3920                                         /* this is done indirectly by looking if a Stackslot is */
3921                                         /* marked LOCALVAR and is live while curstack is live   */
3922                                         /* see figure 5.3 */
3923
3924                                         /* First check "above" stackslots of the instack */
3925                                         copy = curstack + 1;
3926                                         for(;(copy <= bptr->instack); copy++)
3927                                                 if ((copy->varkind == LOCALVAR) && (copy->varnum == iptr->op1)) {
3928                                                         goto _possible_conflict;
3929                                                 }
3930                                         
3931                                         /* "intra" Basic Block Stackslots are allocated above    */
3932                                         /* bptr->stack (see doc/stack.txt), so if curstack + 1   */
3933                                         /* is an instack, copy could point now to the stackslots */
3934                                         /* of an inbetween analysed Basic Block */
3935                                         if (copy < bptr->stack)
3936                                                 copy = bptr->stack;
3937                                         while (copy < new) {
3938                                                 if ((copy->varkind == LOCALVAR) && (copy->varnum == iptr->op1)) {
3939                                                         goto _possible_conflict;
3940                                                 }
3941                                                 copy++;
3942                                         }
3943                                         /* If Stackslot is already marked as LOCALVAR, do not    */
3944                                         /* change it! Conflict resolution works only, if xLOAD   */
3945                                         /* has priority! */
3946                                         if (curstack->varkind == LOCALVAR)
3947                                                 goto _possible_conflict;
3948                                         /* no conflict - mark the Stackslot as LOCALVAR */
3949                                         curstack->varkind = LOCALVAR;
3950                                         curstack->varnum = iptr->op1;
3951                                         
3952                                         goto _local_join;
3953                                 _possible_conflict:
3954                                         if ((curstack->varkind == LOCALVAR) 
3955                                                 && (curstack->varnum == iptr->op1)) {
3956                                                 curstack->varkind = TEMPVAR;
3957                                                 curstack->varnum = stackdepth-1;
3958                                         }
3959                                 _local_join:
3960                                         last_store[5 * iptr->op1 + opcode - ICMD_ISTORE] = bptr->icount - len - 1;
3961
3962                                         STORE(opcode - ICMD_ISTORE);
3963                                         break;
3964
3965                                         /* pop 3 push 0 */
3966
3967                                         case ICMD_AASTORE:
3968                                                 COUNT(count_check_null);
3969                                                 COUNT(count_check_bound);
3970                                                 COUNT(count_pcmd_mem);
3971
3972                                                 bte = builtintable_get_internal(BUILTIN_canstore);
3973                                                 md = bte->md;
3974
3975                                                 if (md->memuse > rd->memuse)
3976                                                         rd->memuse = md->memuse;
3977                                                 if (md->argintreguse > rd->argintreguse)
3978                                                         rd->argintreguse = md->argintreguse;
3979
3980                                                 /* make all stack variables saved */
3981
3982                                                 copy = curstack;
3983                                                 while (copy) {
3984                                                         copy->flags |= SAVEDVAR;
3985                                                         copy = copy->prev;
3986                                                 }
3987
3988                                                 OP3TIA_0(TYPE_ADR);
3989                                                 break;
3990
3991                                         case ICMD_IASTORE:
3992                                         case ICMD_LASTORE:
3993                                         case ICMD_FASTORE:
3994                                         case ICMD_DASTORE:
3995                                                 COUNT(count_check_null);
3996                                                 COUNT(count_check_bound);
3997                                                 COUNT(count_pcmd_mem);
3998                                                 OP3TIA_0(opcode - ICMD_IASTORE);
3999                                                 break;
4000
4001                                         case ICMD_BASTORE:
4002                                         case ICMD_CASTORE:
4003                                         case ICMD_SASTORE:
4004                                                 COUNT(count_check_null);
4005                                                 COUNT(count_check_bound);
4006                                                 COUNT(count_pcmd_mem);
4007                                                 OP3TIA_0(TYPE_INT);
4008                                                 break;
4009
4010                                                 /* pop 1 push 0 */
4011
4012                                         case ICMD_POP:
4013 #ifdef ENABLE_VERIFIER
4014                                                 if (opt_verify) {
4015                                                         REQUIRE_1;
4016                                                         if (IS_2_WORD_TYPE(curstack->type))
4017                                                                 goto throw_stack_category_error;
4018                                                 }
4019 #endif
4020                                                 OP1_0ANY;
4021                                                 break;
4022
4023                                         case ICMD_IRETURN:
4024                                         case ICMD_LRETURN:
4025                                         case ICMD_FRETURN:
4026                                         case ICMD_DRETURN:
4027                                         case ICMD_ARETURN:
4028 #if defined(ENABLE_JIT)
4029 # if defined(ENABLE_INTRP)
4030                                                 if (!opt_intrp)
4031 # endif
4032                                                         md_return_alloc(jd, curstack);
4033 #endif
4034                                                 COUNT(count_pcmd_return);
4035                                                 OP1_0(opcode - ICMD_IRETURN);
4036                                                 superblockend = true;
4037                                                 break;
4038
4039                                         case ICMD_ATHROW:
4040                                                 COUNT(count_check_null);
4041                                                 OP1_0(TYPE_ADR);
4042                                                 STACKRESET;
4043                                                 SETDST;
4044                                                 superblockend = true;
4045                                                 break;
4046
4047                                         case ICMD_PUTSTATIC:
4048                                                 COUNT(count_pcmd_mem);
4049                                                 OP1_0(iptr->op1);
4050                                                 break;
4051
4052                                                 /* pop 1 push 0 branch */
4053
4054                                         case ICMD_IFNULL:
4055                                         case ICMD_IFNONNULL:
4056                                                 COUNT(count_pcmd_bra);
4057                                                 OP1_0(TYPE_ADR);
4058                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4059
4060                                                 iptr[0].target = (void *) tbptr;
4061
4062                                                 MARKREACHED(tbptr, copy);
4063                                                 break;
4064
4065                                         case ICMD_IFEQ:
4066                                         case ICMD_IFNE:
4067                                         case ICMD_IFLT:
4068                                         case ICMD_IFGE:
4069                                         case ICMD_IFGT:
4070                                         case ICMD_IFLE:
4071                                                 COUNT(count_pcmd_bra);
4072
4073                                                 /* iptr->val.i is set implicitly in parse by
4074                                                    clearing the memory or from IF_ICMPxx
4075                                                    optimization. */
4076
4077                                                 OP1_0(TYPE_INT);
4078 /*                                              iptr->val.i = 0; */
4079                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4080
4081                                                 iptr[0].target = (void *) tbptr;
4082
4083                                                 MARKREACHED(tbptr, copy);
4084                                                 break;
4085
4086                                                 /* pop 0 push 0 branch */
4087
4088                                         case ICMD_GOTO:
4089                                                 COUNT(count_pcmd_bra);
4090                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4091
4092                                                 iptr[0].target = (void *) tbptr;
4093
4094                                                 MARKREACHED(tbptr, copy);
4095                                                 SETDST;
4096                                                 superblockend = true;
4097                                                 break;
4098
4099                                                 /* pop 1 push 0 table branch */
4100
4101                                         case ICMD_TABLESWITCH:
4102                                                 COUNT(count_pcmd_table);
4103                                                 OP1_0(TYPE_INT);
4104                                                 s4ptr = iptr->val.a;
4105                                                 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
4106                                                 MARKREACHED(tbptr, copy);
4107                                                 i = *s4ptr++;                          /* low     */
4108                                                 i = *s4ptr++ - i + 1;                  /* high    */
4109
4110                                                 tptr = DMNEW(void*, i+1);
4111                                                 iptr->target = (void *) tptr;
4112
4113                                                 tptr[0] = (void *) tbptr;
4114                                                 tptr++;
4115
4116                                                 while (--i >= 0) {
4117                                                         tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
4118
4119                                                         tptr[0] = (void *) tbptr;
4120                                                         tptr++;
4121
4122                                                         MARKREACHED(tbptr, copy);
4123                                                 }
4124                                                 SETDST;
4125                                                 superblockend = true;
4126                                                 break;
4127                                                         
4128                                                 /* pop 1 push 0 table branch */
4129
4130                                         case ICMD_LOOKUPSWITCH:
4131                                                 COUNT(count_pcmd_table);
4132                                                 OP1_0(TYPE_INT);
4133                                                 s4ptr = iptr->val.a;
4134                                                 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
4135                                                 MARKREACHED(tbptr, copy);
4136                                                 i = *s4ptr++;                          /* count   */
4137
4138                                                 tptr = DMNEW(void*, i+1);
4139                                                 iptr->target = (void *) tptr;
4140
4141                                                 tptr[0] = (void *) tbptr;
4142                                                 tptr++;
4143
4144                                                 while (--i >= 0) {
4145                                                         tbptr = m->basicblocks + m->basicblockindex[s4ptr[1]];
4146
4147                                                         tptr[0] = (void *) tbptr;
4148                                                         tptr++;
4149                                                                 
4150                                                         MARKREACHED(tbptr, copy);
4151                                                         s4ptr += 2;
4152                                                 }
4153                                                 SETDST;
4154                                                 superblockend = true;
4155                                                 break;
4156
4157                                         case ICMD_MONITORENTER:
4158                                                 COUNT(count_check_null);
4159                                         case ICMD_MONITOREXIT:
4160                                                 OP1_0(TYPE_ADR);
4161                                                 break;
4162
4163                                                 /* pop 2 push 0 branch */
4164
4165                                         case ICMD_IF_ICMPEQ:
4166                                         case ICMD_IF_ICMPNE:
4167                                         case ICMD_IF_ICMPLT:
4168                                         case ICMD_IF_ICMPGE:
4169                                         case ICMD_IF_ICMPGT:
4170                                         case ICMD_IF_ICMPLE:
4171                                                 COUNT(count_pcmd_bra);
4172                                                 OP2_0(TYPE_INT);
4173                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4174                                                         
4175                                                 iptr[0].target = (void *) tbptr;
4176
4177                                                 MARKREACHED(tbptr, copy);
4178                                                 break;
4179
4180                                         case ICMD_IF_ACMPEQ:
4181                                         case ICMD_IF_ACMPNE:
4182                                                 COUNT(count_pcmd_bra);
4183                                                 OP2_0(TYPE_ADR);
4184                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4185
4186                                                 iptr[0].target = (void *) tbptr;
4187
4188                                                 MARKREACHED(tbptr, copy);
4189                                                 break;
4190
4191                                                 /* pop 2 push 0 */
4192
4193                                         case ICMD_PUTFIELD:
4194                                                 COUNT(count_check_null);
4195                                                 COUNT(count_pcmd_mem);
4196                                                 OPTT2_0(iptr->op1,TYPE_ADR);
4197                                                 break;
4198
4199                                         case ICMD_POP2:
4200                                                 REQUIRE_1;
4201                                                 if (!IS_2_WORD_TYPE(curstack->type)) {
4202                                                         /* ..., cat1 */
4203 #ifdef ENABLE_VERIFIER
4204                                                         if (opt_verify) {
4205                                                                 REQUIRE_2;
4206                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
4207                                                                         goto throw_stack_category_error;
4208                                                         }
4209 #endif
4210                                                         OP1_0ANY;                /* second pop */
4211                                                 }
4212                                                 else
4213                                                         iptr->opc = ICMD_POP;
4214                                                 OP1_0ANY;
4215                                                 break;
4216
4217                                                 /* pop 0 push 1 dup */
4218                                                 
4219                                         case ICMD_DUP:
4220 #ifdef ENABLE_VERIFIER
4221                                                 if (opt_verify) {
4222                                                         REQUIRE_1;
4223                                                         if (IS_2_WORD_TYPE(curstack->type))
4224                                                                 goto throw_stack_category_error;
4225                                                 }
4226 #endif
4227                                                 last_dupx = bptr->icount - len - 1;
4228                                                 COUNT(count_dup_instruction);
4229                                                 DUP;
4230                                                 break;
4231
4232                                         case ICMD_DUP2:
4233                                                 last_dupx = bptr->icount - len - 1;
4234                                                 REQUIRE_1;
4235                                                 if (IS_2_WORD_TYPE(curstack->type)) {
4236                                                         /* ..., cat2 */
4237                                                         iptr->opc = ICMD_DUP;
4238                                                         DUP;
4239                                                 }
4240                                                 else {
4241                                                         REQUIRE_2;
4242                                                         /* ..., ????, cat1 */
4243 #ifdef ENABLE_VERIFIER
4244                                                         if (opt_verify) {
4245                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
4246                                                                         goto throw_stack_category_error;
4247                                                         }
4248 #endif
4249                                                         copy = curstack;
4250                                                         NEWSTACK(copy->prev->type, copy->prev->varkind,
4251                                                                          copy->prev->varnum);
4252                                                         NEWSTACK(copy->type, copy->varkind,
4253                                                                          copy->varnum);
4254                                                         SETDST;
4255                                                         stackdepth += 2;
4256                                                 }
4257                                                 break;
4258
4259                                                 /* pop 2 push 3 dup */
4260                                                 
4261                                         case ICMD_DUP_X1:
4262 #ifdef ENABLE_VERIFIER
4263                                                 if (opt_verify) {
4264                                                         REQUIRE_2;
4265                                                         if (IS_2_WORD_TYPE(curstack->type) ||
4266                                                                 IS_2_WORD_TYPE(curstack->prev->type))
4267                                                                         goto throw_stack_category_error;
4268                                                 }
4269 #endif
4270                                                 last_dupx = bptr->icount - len - 1;
4271                                                 DUP_X1;
4272                                                 break;
4273
4274                                         case ICMD_DUP2_X1:
4275                                                 last_dupx = bptr->icount - len - 1;
4276                                                 REQUIRE_2;
4277                                                 if (IS_2_WORD_TYPE(curstack->type)) {
4278                                                         /* ..., ????, cat2 */
4279 #ifdef ENABLE_VERIFIER
4280                                                         if (opt_verify) {
4281                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
4282                                                                         goto throw_stack_category_error;
4283                                                         }
4284 #endif
4285                                                         iptr->opc = ICMD_DUP_X1;
4286                                                         DUP_X1;
4287                                                 }
4288                                                 else {
4289                                                         /* ..., ????, cat1 */
4290 #ifdef ENABLE_VERIFIER
4291                                                         if (opt_verify) {
4292                                                                 REQUIRE_3;
4293                                                                 if (IS_2_WORD_TYPE(curstack->prev->type)
4294                                                                         || IS_2_WORD_TYPE(curstack->prev->prev->type))
4295                                                                                 goto throw_stack_category_error;
4296                                                         }
4297 #endif
4298                                                         DUP2_X1;
4299                                                 }
4300                                                 break;
4301
4302                                                 /* pop 3 push 4 dup */
4303                                                 
4304                                         case ICMD_DUP_X2:
4305                                                 last_dupx = bptr->icount - len - 1;
4306                                                 REQUIRE_2;
4307                                                 if (IS_2_WORD_TYPE(curstack->prev->type)) {
4308                                                         /* ..., cat2, ???? */
4309 #ifdef ENABLE_VERIFIER
4310                                                         if (opt_verify) {
4311                                                                 if (IS_2_WORD_TYPE(curstack->type))
4312                                                                         goto throw_stack_category_error;
4313                                                         }
4314 #endif
4315                                                         iptr->opc = ICMD_DUP_X1;
4316                                                         DUP_X1;
4317                                                 }
4318                                                 else {
4319                                                         /* ..., cat1, ???? */
4320 #ifdef ENABLE_VERIFIER
4321                                                         if (opt_verify) {
4322                                                                 REQUIRE_3;
4323                                                                 if (IS_2_WORD_TYPE(curstack->type)
4324                                                                         || IS_2_WORD_TYPE(curstack->prev->prev->type))
4325                                                                                         goto throw_stack_category_error;
4326                                                         }
4327 #endif
4328                                                         DUP_X2;
4329                                                 }
4330                                                 break;
4331
4332                                         case ICMD_DUP2_X2:
4333                                                 last_dupx = bptr->icount - len - 1;
4334                                                 REQUIRE_2;
4335                                                 if (IS_2_WORD_TYPE(curstack->type)) {
4336                                                         /* ..., ????, cat2 */
4337                                                         if (IS_2_WORD_TYPE(curstack->prev->type)) {
4338                                                                 /* ..., cat2, cat2 */
4339                                                                 iptr->opc = ICMD_DUP_X1;
4340                                                                 DUP_X1;
4341                                                         }
4342                                                         else {
4343                                                                 /* ..., cat1, cat2 */
4344 #ifdef ENABLE_VERIFIER
4345                                                                 if (opt_verify) {
4346                                                                         REQUIRE_3;
4347                                                                         if (IS_2_WORD_TYPE(curstack->prev->prev->type))
4348                                                                                         goto throw_stack_category_error;
4349                                                                 }
4350 #endif
4351                                                                 iptr->opc = ICMD_DUP_X2;
4352                                                                 DUP_X2;
4353                                                         }
4354                                                 }
4355                                                 else {
4356                                                         REQUIRE_3;
4357                                                         /* ..., ????, ????, cat1 */
4358                                                         if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
4359                                                                 /* ..., cat2, ????, cat1 */
4360 #ifdef ENABLE_VERIFIER
4361                                                                 if (opt_verify) {
4362                                                                         if (IS_2_WORD_TYPE(curstack->prev->type))
4363                                                                                 goto throw_stack_category_error;
4364                                                                 }
4365 #endif
4366                                                                 iptr->opc = ICMD_DUP2_X1;
4367                                                                 DUP2_X1;
4368                                                         }
4369                                                         else {
4370                                                                 /* ..., cat1, ????, cat1 */
4371 #ifdef ENABLE_VERIFIER
4372                                                                 if (opt_verify) {
4373                                                                         REQUIRE_4;
4374                                                                         if (IS_2_WORD_TYPE(curstack->prev->type)
4375                                                                                 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
4376                                                                                 goto throw_stack_category_error;
4377                                                                 }
4378 #endif
4379                                                                 DUP2_X2;
4380                                                         }
4381                                                 }
4382                                                 break;
4383
4384                                                 /* pop 2 push 2 swap */
4385                                                 
4386                                         case ICMD_SWAP:
4387                                                 last_dupx = bptr->icount - len - 1;
4388 #ifdef ENABLE_VERIFIER
4389                                                 if (opt_verify) {
4390                                                         REQUIRE_2;
4391                                                         if (IS_2_WORD_TYPE(curstack->type)
4392                                                                 || IS_2_WORD_TYPE(curstack->prev->type))
4393                                                                 goto throw_stack_category_error;
4394                                                 }
4395 #endif
4396                                                 SWAP;
4397                                                 break;
4398
4399                                                 /* pop 2 push 1 */
4400
4401                                         case ICMD_IDIV:
4402                                         case ICMD_IREM:
4403 #if !SUPPORT_DIVISION
4404                                                 bte = (builtintable_entry *) iptr->val.a;
4405                                                 md = bte->md;
4406                                                 i = iptr->op1;
4407
4408                                                 if (md->memuse > rd->memuse)
4409                                                         rd->memuse = md->memuse;
4410                                                 if (md->argintreguse > rd->argintreguse)
4411                                                         rd->argintreguse = md->argintreguse;
4412
4413                                                 /* make all stack variables saved */
4414
4415                                                 copy = curstack;
4416                                                 while (copy) {
4417                                                         copy->flags |= SAVEDVAR;
4418                                                         copy = copy->prev;
4419                                                 }
4420
4421                                                 /* fall through */
4422 #endif /* !SUPPORT_DIVISION */
4423
4424                                         case ICMD_ISHL:
4425                                         case ICMD_ISHR:
4426                                         case ICMD_IUSHR:
4427                                         case ICMD_IADD:
4428                                         case ICMD_ISUB:
4429                                         case ICMD_IMUL:
4430                                         case ICMD_IAND:
4431                                         case ICMD_IOR:
4432                                         case ICMD_IXOR:
4433                                                 COUNT(count_pcmd_op);
4434                                                 OP2_1(TYPE_INT);
4435                                                 break;
4436
4437                                         case ICMD_LDIV:
4438                                         case ICMD_LREM:
4439 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
4440                                                 bte = (builtintable_entry *) iptr->val.a;
4441                                                 md = bte->md;
4442                                                 i = iptr->op1;
4443
4444                                                 if (md->memuse > rd->memuse)
4445                                                         rd->memuse = md->memuse;
4446                                                 if (md->argintreguse > rd->argintreguse)
4447                                                         rd->argintreguse = md->argintreguse;
4448
4449                                                 /* make all stack variables saved */
4450
4451                                                 copy = curstack;
4452                                                 while (copy) {
4453                                                         copy->flags |= SAVEDVAR;
4454                                                         copy = copy->prev;
4455                                                 }
4456
4457                                                 /* fall through */
4458 #endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
4459
4460                                         case ICMD_LMUL:
4461                                         case ICMD_LADD:
4462                                         case ICMD_LSUB:
4463 #if SUPPORT_LONG_LOGICAL
4464                                         case ICMD_LAND:
4465                                         case ICMD_LOR:
4466                                         case ICMD_LXOR:
4467 #endif /* SUPPORT_LONG_LOGICAL */
4468                                                 COUNT(count_pcmd_op);
4469                                                 OP2_1(TYPE_LNG);
4470                                                 break;
4471
4472                                         case ICMD_LSHL:
4473                                         case ICMD_LSHR:
4474                                         case ICMD_LUSHR:
4475                                                 COUNT(count_pcmd_op);
4476                                                 OP2IT_1(TYPE_LNG);
4477                                                 break;
4478
4479                                         case ICMD_FADD:
4480                                         case ICMD_FSUB:
4481                                         case ICMD_FMUL:
4482                                         case ICMD_FDIV:
4483                                         case ICMD_FREM:
4484                                                 COUNT(count_pcmd_op);
4485                                                 OP2_1(TYPE_FLT);
4486                                                 break;
4487
4488                                         case ICMD_DADD:
4489                                         case ICMD_DSUB:
4490                                         case ICMD_DMUL:
4491                                         case ICMD_DDIV:
4492                                         case ICMD_DREM:
4493                                                 COUNT(count_pcmd_op);
4494                                                 OP2_1(TYPE_DBL);
4495                                                 break;
4496
4497                                         case ICMD_LCMP:
4498                                                 COUNT(count_pcmd_op);
4499 #if SUPPORT_LONG_CMP_CONST
4500                                                 if ((len > 0) && (iptr[1].val.i == 0)) {
4501                                                         switch (iptr[1].opc) {
4502                                                         case ICMD_IFEQ:
4503                                                                 iptr[0].opc = ICMD_IF_LCMPEQ;
4504                                                         icmd_lcmp_if_tail:
4505                                                                 iptr[0].op1 = iptr[1].op1;
4506                                                                 iptr[1].opc = ICMD_NOP;
4507 /*                                                              len--; */
4508 /*                                                              bptr->icount--; */
4509
4510                                                                 OP2_0(TYPE_LNG);
4511                                                                 tbptr = m->basicblocks +
4512                                                                         m->basicblockindex[iptr[0].op1];
4513                         
4514                                                                 iptr[0].target = (void *) tbptr;
4515
4516                                                                 MARKREACHED(tbptr, copy);
4517                                                                 COUNT(count_pcmd_bra);
4518                                                                 break;
4519                                                         case ICMD_IFNE:
4520                                                                 iptr[0].opc = ICMD_IF_LCMPNE;
4521                                                                 goto icmd_lcmp_if_tail;
4522                                                         case ICMD_IFLT:
4523                                                                 iptr[0].opc = ICMD_IF_LCMPLT;
4524                                                                 goto icmd_lcmp_if_tail;
4525                                                         case ICMD_IFGT:
4526                                                                 iptr[0].opc = ICMD_IF_LCMPGT;
4527                                                                 goto icmd_lcmp_if_tail;
4528                                                         case ICMD_IFLE:
4529                                                                 iptr[0].opc = ICMD_IF_LCMPLE;
4530                                                                 goto icmd_lcmp_if_tail;
4531                                                         case ICMD_IFGE:
4532                                                                 iptr[0].opc = ICMD_IF_LCMPGE;
4533                                                                 goto icmd_lcmp_if_tail;
4534                                                         default:
4535                                                                 OPTT2_1(TYPE_LNG, TYPE_INT);
4536                                                         }
4537                                                 }
4538                                                 else
4539 #endif /* SUPPORT_LONG_CMP_CONST */
4540                                                         OPTT2_1(TYPE_LNG, TYPE_INT);
4541                                                 break;
4542
4543 #if 0
4544                                         case ICMD_FCMPL:
4545                                                 COUNT(count_pcmd_op);
4546                                                 if ((len > 0) && (iptr[1].val.i == 0)) {
4547                                                         switch (iptr[1].opc) {
4548                                                         case ICMD_IFEQ:
4549                                                                 iptr[0].opc = ICMD_IF_FCMPEQ;
4550                                                         icmd_if_fcmpl_tail:
4551                                                                 iptr[0].op1 = iptr[1].op1;
4552                                                                 iptr[1].opc = ICMD_NOP;
4553
4554                                                                 OP2_0(TYPE_FLT);
4555                                                                 tbptr = m->basicblocks +
4556                                                                         m->basicblockindex[iptr[0].op1];
4557                         
4558                                                                 iptr[0].target = (void *) tbptr;
4559
4560                                                                 MARKREACHED(tbptr, copy);
4561                                                                 COUNT(count_pcmd_bra);
4562                                                                 break;
4563                                                         case ICMD_IFNE:
4564                                                                 iptr[0].opc = ICMD_IF_FCMPNE;
4565                                                                 goto icmd_if_fcmpl_tail;
4566                                                         case ICMD_IFLT:
4567                                                                 iptr[0].opc = ICMD_IF_FCMPL_LT;
4568                                                                 goto icmd_if_fcmpl_tail;
4569                                                         case ICMD_IFGT:
4570                                                                 iptr[0].opc = ICMD_IF_FCMPL_GT;
4571                                                                 goto icmd_if_fcmpl_tail;
4572                                                         case ICMD_IFLE:
4573                                                                 iptr[0].opc = ICMD_IF_FCMPL_LE;
4574                                                                 goto icmd_if_fcmpl_tail;
4575                                                         case ICMD_IFGE:
4576                                                                 iptr[0].opc = ICMD_IF_FCMPL_GE;
4577                                                                 goto icmd_if_fcmpl_tail;
4578                                                         default:
4579                                                                 OPTT2_1(TYPE_FLT, TYPE_INT);
4580                                                         }
4581                                                 }
4582                                                 else
4583                                                         OPTT2_1(TYPE_FLT, TYPE_INT);
4584                                                 break;
4585
4586                                         case ICMD_FCMPG:
4587                                                 COUNT(count_pcmd_op);
4588                                                 if ((len > 0) && (iptr[1].val.i == 0)) {
4589                                                         switch (iptr[1].opc) {
4590                                                         case ICMD_IFEQ:
4591                                                                 iptr[0].opc = ICMD_IF_FCMPEQ;
4592                                                         icmd_if_fcmpg_tail:
4593                                                                 iptr[0].op1 = iptr[1].op1;
4594                                                                 iptr[1].opc = ICMD_NOP;
4595
4596                                                                 OP2_0(TYPE_FLT);
4597                                                                 tbptr = m->basicblocks +
4598                                                                         m->basicblockindex[iptr[0].op1];
4599                         
4600                                                                 iptr[0].target = (void *) tbptr;
4601
4602                                                                 MARKREACHED(tbptr, copy);
4603                                                                 COUNT(count_pcmd_bra);
4604                                                                 break;
4605                                                         case ICMD_IFNE:
4606                                                                 iptr[0].opc = ICMD_IF_FCMPNE;
4607                                                                 goto icmd_if_fcmpg_tail;
4608                                                         case ICMD_IFLT:
4609                                                                 iptr[0].opc = ICMD_IF_FCMPG_LT;
4610                                                                 goto icmd_if_fcmpg_tail;
4611                                                         case ICMD_IFGT:
4612                                                                 iptr[0].opc = ICMD_IF_FCMPG_GT;
4613                                                                 goto icmd_if_fcmpg_tail;
4614                                                         case ICMD_IFLE:
4615                                                                 iptr[0].opc = ICMD_IF_FCMPG_LE;
4616                                                                 goto icmd_if_fcmpg_tail;
4617                                                         case ICMD_IFGE:
4618                                                                 iptr[0].opc = ICMD_IF_FCMPG_GE;
4619                                                                 goto icmd_if_fcmpg_tail;
4620                                                         default:
4621                                                                 OPTT2_1(TYPE_FLT, TYPE_INT);
4622                                                         }
4623                                                 }
4624                                                 else
4625                                                         OPTT2_1(TYPE_FLT, TYPE_INT);
4626                                                 break;
4627
4628                                         case ICMD_DCMPL:
4629                                                 COUNT(count_pcmd_op);
4630                                                 if ((len > 0) && (iptr[1].val.i == 0)) {
4631                                                         switch (iptr[1].opc) {
4632                                                         case ICMD_IFEQ:
4633                                                                 iptr[0].opc = ICMD_IF_DCMPEQ;
4634                                                         icmd_if_dcmpl_tail:
4635                                                                 iptr[0].op1 = iptr[1].op1;
4636                                                                 iptr[1].opc = ICMD_NOP;
4637
4638                                                                 OP2_0(TYPE_DBL);
4639                                                                 tbptr = m->basicblocks +
4640                                                                         m->basicblockindex[iptr[0].op1];
4641                         
4642                                                                 iptr[0].target = (void *) tbptr;
4643
4644                                                                 MARKREACHED(tbptr, copy);
4645                                                                 COUNT(count_pcmd_bra);
4646                                                                 break;
4647                                                         case ICMD_IFNE:
4648                                                                 iptr[0].opc = ICMD_IF_DCMPNE;
4649                                                                 goto icmd_if_dcmpl_tail;
4650                                                         case ICMD_IFLT:
4651                                                                 iptr[0].opc = ICMD_IF_DCMPL_LT;
4652                                                                 goto icmd_if_dcmpl_tail;
4653                                                         case ICMD_IFGT:
4654                                                                 iptr[0].opc = ICMD_IF_DCMPL_GT;
4655                                                                 goto icmd_if_dcmpl_tail;
4656                                                         case ICMD_IFLE:
4657                                                                 iptr[0].opc = ICMD_IF_DCMPL_LE;
4658                                                                 goto icmd_if_dcmpl_tail;
4659                                                         case ICMD_IFGE:
4660                                                                 iptr[0].opc = ICMD_IF_DCMPL_GE;
4661                                                                 goto icmd_if_dcmpl_tail;
4662                                                         default:
4663                                                                 OPTT2_1(TYPE_DBL, TYPE_INT);
4664                                                         }
4665                                                 }
4666                                                 else
4667                                                         OPTT2_1(TYPE_DBL, TYPE_INT);
4668                                                 break;
4669
4670                                         case ICMD_DCMPG:
4671                                                 COUNT(count_pcmd_op);
4672                                                 if ((len > 0) && (iptr[1].val.i == 0)) {
4673                                                         switch (iptr[1].opc) {
4674                                                         case ICMD_IFEQ:
4675                                                                 iptr[0].opc = ICMD_IF_DCMPEQ;
4676                                                         icmd_if_dcmpg_tail:
4677                                                                 iptr[0].op1 = iptr[1].op1;
4678                                                                 iptr[1].opc = ICMD_NOP;
4679
4680                                                                 OP2_0(TYPE_DBL);
4681                                                                 tbptr = m->basicblocks +
4682                                                                         m->basicblockindex[iptr[0].op1];
4683                         
4684                                                                 iptr[0].target = (void *) tbptr;
4685
4686                                                                 MARKREACHED(tbptr, copy);
4687                                                                 COUNT(count_pcmd_bra);
4688                                                                 break;
4689                                                         case ICMD_IFNE:
4690                                                                 iptr[0].opc = ICMD_IF_DCMPNE;
4691                                                                 goto icmd_if_dcmpg_tail;
4692                                                         case ICMD_IFLT:
4693                                                                 iptr[0].opc = ICMD_IF_DCMPG_LT;
4694                                                                 goto icmd_if_dcmpg_tail;
4695                                                         case ICMD_IFGT:
4696                                                                 iptr[0].opc = ICMD_IF_DCMPG_GT;
4697                                                                 goto icmd_if_dcmpg_tail;
4698                                                         case ICMD_IFLE:
4699                                                                 iptr[0].opc = ICMD_IF_DCMPG_LE;
4700                                                                 goto icmd_if_dcmpg_tail;
4701                                                         case ICMD_IFGE:
4702                                                                 iptr[0].opc = ICMD_IF_DCMPG_GE;
4703                                                                 goto icmd_if_dcmpg_tail;
4704                                                         default:
4705                                                                 OPTT2_1(TYPE_DBL, TYPE_INT);
4706                                                         }
4707                                                 }
4708                                                 else
4709                                                         OPTT2_1(TYPE_DBL, TYPE_INT);
4710                                                 break;
4711 #else
4712                                         case ICMD_FCMPL:
4713                                         case ICMD_FCMPG:
4714                                                 COUNT(count_pcmd_op);
4715                                                 OPTT2_1(TYPE_FLT, TYPE_INT);
4716                                                 break;
4717
4718                                         case ICMD_DCMPL:
4719                                         case ICMD_DCMPG:
4720                                                 COUNT(count_pcmd_op);
4721                                                 OPTT2_1(TYPE_DBL, TYPE_INT);
4722                                                 break;
4723 #endif
4724
4725                                                 /* pop 1 push 1 */
4726                                                 
4727                                         case ICMD_INEG:
4728                                         case ICMD_INT2BYTE:
4729                                         case ICMD_INT2CHAR:
4730                                         case ICMD_INT2SHORT:
4731                                                 COUNT(count_pcmd_op);
4732                                                 OP1_1(TYPE_INT, TYPE_INT);
4733                                                 break;
4734                                         case ICMD_LNEG:
4735                                                 COUNT(count_pcmd_op);
4736                                                 OP1_1(TYPE_LNG, TYPE_LNG);
4737                                                 break;
4738                                         case ICMD_FNEG:
4739                                                 COUNT(count_pcmd_op);
4740                                                 OP1_1(TYPE_FLT, TYPE_FLT);
4741                                                 break;
4742                                         case ICMD_DNEG:
4743                                                 COUNT(count_pcmd_op);
4744                                                 OP1_1(TYPE_DBL, TYPE_DBL);
4745                                                 break;
4746
4747                                         case ICMD_I2L:
4748                                                 COUNT(count_pcmd_op);
4749                                                 OP1_1(TYPE_INT, TYPE_LNG);
4750                                                 break;
4751                                         case ICMD_I2F:
4752                                                 COUNT(count_pcmd_op);
4753                                                 OP1_1(TYPE_INT, TYPE_FLT);
4754                                                 break;
4755                                         case ICMD_I2D:
4756                                                 COUNT(count_pcmd_op);
4757                                                 OP1_1(TYPE_INT, TYPE_DBL);
4758                                                 break;
4759                                         case ICMD_L2I:
4760                                                 COUNT(count_pcmd_op);
4761                                                 OP1_1(TYPE_LNG, TYPE_INT);
4762                                                 break;
4763                                         case ICMD_L2F:
4764                                                 COUNT(count_pcmd_op);
4765                                                 OP1_1(TYPE_LNG, TYPE_FLT);
4766                                                 break;
4767                                         case ICMD_L2D:
4768                                                 COUNT(count_pcmd_op);
4769                                                 OP1_1(TYPE_LNG, TYPE_DBL);
4770                                                 break;
4771                                         case ICMD_F2I:
4772                                                 COUNT(count_pcmd_op);
4773                                                 OP1_1(TYPE_FLT, TYPE_INT);
4774                                                 break;
4775                                         case ICMD_F2L:
4776                                                 COUNT(count_pcmd_op);
4777                                                 OP1_1(TYPE_FLT, TYPE_LNG);
4778                                                 break;
4779                                         case ICMD_F2D:
4780                                                 COUNT(count_pcmd_op);
4781                                                 OP1_1(TYPE_FLT, TYPE_DBL);
4782                                                 break;
4783                                         case ICMD_D2I:
4784                                                 COUNT(count_pcmd_op);
4785                                                 OP1_1(TYPE_DBL, TYPE_INT);
4786                                                 break;
4787                                         case ICMD_D2L:
4788                                                 COUNT(count_pcmd_op);
4789                                                 OP1_1(TYPE_DBL, TYPE_LNG);
4790                                                 break;
4791                                         case ICMD_D2F:
4792                                                 COUNT(count_pcmd_op);
4793                                                 OP1_1(TYPE_DBL, TYPE_FLT);
4794                                                 break;
4795
4796                                         case ICMD_CHECKCAST:
4797                                                 if (iptr->op1 == 0) {
4798                                                         /* array type cast-check */
4799
4800                                                         bte = builtintable_get_internal(BUILTIN_arraycheckcast);
4801                                                         md = bte->md;
4802
4803                                                         if (md->memuse > rd->memuse)
4804                                                                 rd->memuse = md->memuse;
4805                                                         if (md->argintreguse > rd->argintreguse)
4806                                                                 rd->argintreguse = md->argintreguse;
4807
4808                                                         /* make all stack variables saved */
4809
4810                                                         copy = curstack;
4811                                                         while (copy) {
4812                                                                 copy->flags |= SAVEDVAR;
4813                                                                 copy = copy->prev;
4814                                                         }
4815                                                 }
4816                                                 OP1_1(TYPE_ADR, TYPE_ADR);
4817                                                 break;
4818
4819                                         case ICMD_INSTANCEOF:
4820                                         case ICMD_ARRAYLENGTH:
4821                                                 OP1_1(TYPE_ADR, TYPE_INT);
4822                                                 break;
4823
4824                                         case ICMD_NEWARRAY:
4825                                         case ICMD_ANEWARRAY:
4826                                                 OP1_1(TYPE_INT, TYPE_ADR);
4827                                                 break;
4828
4829                                         case ICMD_GETFIELD:
4830                                                 COUNT(count_check_null);
4831                                                 COUNT(count_pcmd_mem);
4832                                                 OP1_1(TYPE_ADR, iptr->op1);
4833                                                 break;
4834
4835                                                 /* pop 0 push 1 */
4836                                                 
4837                                         case ICMD_GETSTATIC:
4838                                                 COUNT(count_pcmd_mem);
4839                                                 OP0_1(iptr->op1);
4840                                                 break;
4841
4842                                         case ICMD_NEW:
4843                                                 OP0_1(TYPE_ADR);
4844                                                 break;
4845
4846                                         case ICMD_JSR:
4847                                                 OP0_1(TYPE_ADR);
4848                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
4849
4850                                                 iptr[0].target = (void *) tbptr;
4851
4852                                                 /* This is a dirty hack. The typechecker
4853                                                  * needs it because the OP1_0ANY below
4854                                                  * overwrites iptr->dst.
4855                                                  */
4856                                                 iptr->val.a = (void *) iptr->dst;
4857
4858                                                 tbptr->type = BBTYPE_SBR;
4859
4860                                                 /* We need to check for overflow right here because
4861                                                  * the pushed value is poped after MARKREACHED. */
4862                                                 CHECKOVERFLOW;
4863                                                 MARKREACHED(tbptr, copy);
4864                                                 OP1_0ANY;
4865                                                 break;
4866
4867                                         /* pop many push any */
4868
4869                                         case ICMD_BUILTIN:
4870 #if defined(USEBUILTINTABLE)
4871                                         builtin:
4872 #endif
4873                                                 bte = (builtintable_entry *) iptr->val.a;
4874                                                 md = bte->md;
4875                                                 goto _callhandling;
4876
4877                                         case ICMD_INVOKESTATIC:
4878                                         case ICMD_INVOKESPECIAL:
4879                                         case ICMD_INVOKEVIRTUAL:
4880                                         case ICMD_INVOKEINTERFACE:
4881                                                 COUNT(count_pcmd_met);
4882                                                 INSTRUCTION_GET_METHODDESC(iptr,md);
4883 /*                          if (lm->flags & ACC_STATIC) */
4884 /*                              {COUNT(count_check_null);} */    
4885
4886                                         _callhandling:
4887
4888                                                 last_pei = bptr->icount - len - 1;
4889
4890                                                 i = md->paramcount;
4891
4892                                                 if (md->memuse > rd->memuse)
4893                                                         rd->memuse = md->memuse;
4894                                                 if (md->argintreguse > rd->argintreguse)
4895                                                         rd->argintreguse = md->argintreguse;
4896                                                 if (md->argfltreguse > rd->argfltreguse)
4897                                                         rd->argfltreguse = md->argfltreguse;
4898
4899                                                 REQUIRE(i);
4900
4901                                                 copy = curstack;
4902                                                 for (i-- ; i >= 0; i--) {
4903 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
4904                                                 /* If we pass float arguments in integer argument registers, we
4905                                                  * are not allowed to precolor them here. Floats have to be moved
4906                                                  * to this regs explicitly in codegen().
4907                                                  * Only arguments that are passed by stack anyway can be precolored
4908                                                  * (michi 2005/07/24) */
4909                                                         if (!(copy->flags & SAVEDVAR) &&
4910                                                            (!IS_FLT_DBL_TYPE(copy->type) || md->params[i].inmemory)) {
4911 #else
4912                                                         if (!(copy->flags & SAVEDVAR)) {
4913 #endif
4914                                                                 copy->varkind = ARGVAR;
4915                                                                 copy->varnum = i;
4916
4917 #if defined(ENABLE_INTRP)
4918                                                                 if (!opt_intrp) {
4919 #endif
4920                                                                         if (md->params[i].inmemory) {
4921                                                                                 copy->flags = INMEMORY;
4922                                                                                 copy->regoff = md->params[i].regoff;
4923                                                                         } 
4924                                                                         else {
4925                                                                                 copy->flags = 0;
4926                                                                                 if (IS_FLT_DBL_TYPE(copy->type))
4927 #if defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
4928                                                                                         assert(0); /* XXX is this assert ok? */
4929 #else
4930                                                                                 copy->regoff =
4931                                                                                         rd->argfltregs[md->params[i].regoff];
4932 #endif
4933                                                                                 else {
4934 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
4935                                                                                         if (IS_2_WORD_TYPE(copy->type))
4936                                                                                                 copy->regoff = PACK_REGS(
4937                                                                                                                                                  rd->argintregs[GET_LOW_REG(md->params[i].regoff)],
4938                                                                                                                                                  rd->argintregs[GET_HIGH_REG(md->params[i].regoff)]);
4939                                                                                         else
4940 #endif
4941                                                                                                 copy->regoff =
4942                                                                                                         rd->argintregs[md->params[i].regoff];
4943                                                                                 }
4944                                                                         }
4945 #if defined(ENABLE_INTRP)
4946                                                                 }
4947 #endif
4948                                                         }
4949                                                         copy = copy->prev;
4950                                                 }
4951
4952                                                 while (copy) {
4953                                                         copy->flags |= SAVEDVAR;
4954                                                         copy = copy->prev;
4955                                                 }
4956
4957                                                 i = md->paramcount;
4958                                                 POPMANY(i);
4959                                                 if (md->returntype.type != TYPE_VOID)
4960                                                         OP0_1(md->returntype.type);
4961                                                 break;
4962
4963                                         case ICMD_INLINE_START:
4964                                         case ICMD_INLINE_END:
4965                                                 SETDST;
4966                                                 break;
4967
4968                                         case ICMD_MULTIANEWARRAY:
4969                                                 if (rd->argintreguse < 3)
4970                                                         rd->argintreguse = 3;
4971
4972                                                 i = iptr->op1;
4973
4974                                                 REQUIRE(i);
4975 #if defined(SPECIALMEMUSE)
4976 # if defined(__DARWIN__)
4977                                                 if (rd->memuse < (i + INT_ARG_CNT + LA_WORD_SIZE))
4978                                                         rd->memuse = i + LA_WORD_SIZE + INT_ARG_CNT;
4979 # else
4980                                                 if (rd->memuse < (i + LA_WORD_SIZE + 3))
4981                                                         rd->memuse = i + LA_WORD_SIZE + 3;
4982 # endif
4983 #else
4984 # if defined(__I386__)
4985                                                 if (rd->memuse < i + 3)
4986                                                         rd->memuse = i + 3; /* n integer args spilled on stack */
4987 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
4988                                                 if (rd->memuse < i + 2)
4989                                                         rd->memuse = i + 2; /* 4*4 bytes callee save space */
4990 # else
4991                                                 if (rd->memuse < i)
4992                                                         rd->memuse = i; /* n integer args spilled on stack */
4993 # endif /* defined(__I386__) */
4994 #endif
4995                                                 copy = curstack;
4996                                                 while (--i >= 0) {
4997                                                         /* check INT type here? Currently typecheck does this. */
4998                                                         if (!(copy->flags & SAVEDVAR)) {
4999                                                                 copy->varkind = ARGVAR;
5000                                                                 copy->varnum = i + INT_ARG_CNT;
5001                                                                 copy->flags |= INMEMORY;
5002 #if defined(SPECIALMEMUSE)
5003 # if defined(__DARWIN__)
5004                                                                 copy->regoff = i + LA_WORD_SIZE + INT_ARG_CNT;
5005 # else
5006                                                                 copy->regoff = i + LA_WORD_SIZE + 3;
5007 # endif
5008 #else
5009 # if defined(__I386__)
5010                                                                 copy->regoff = i + 3;
5011 # elif defined(__MIPS__) && SIZEOF_VOID_P == 4
5012                                                                 copy->regoff = i + 2;
5013 # else
5014                                                                 copy->regoff = i;
5015 # endif /* defined(__I386__) */
5016 #endif /* defined(SPECIALMEMUSE) */
5017                                                         }
5018                                                         copy = copy->prev;
5019                                                 }
5020                                                 while (copy) {
5021                                                         copy->flags |= SAVEDVAR;
5022                                                         copy = copy->prev;
5023                                                 }
5024                                                 i = iptr->op1;
5025                                                 POPMANY(i);
5026                                                 OP0_1(TYPE_ADR);
5027                                                 break;
5028
5029                                         default:
5030                                                 *exceptionptr =
5031                                                         new_internalerror("Unknown ICMD %d", opcode);
5032                                                 return false;
5033                                         } /* switch */
5034
5035                                         CHECKOVERFLOW;
5036                                         iptr++;
5037                                 } /* while instructions */
5038
5039                                 /* set out-stack of block */
5040
5041                                 bptr->outstack = curstack;
5042                                 bptr->outdepth = stackdepth;
5043
5044                                 /* stack slots at basic block end become interfaces */
5045
5046                                 i = stackdepth - 1;
5047                                 for (copy = curstack; copy; i--, copy = copy->prev) {
5048                                         if ((copy->varkind == STACKVAR) && (copy->varnum > i))
5049                                                 copy->varkind = TEMPVAR;
5050                                         else {
5051                                                 copy->varkind = STACKVAR;
5052                                                 copy->varnum = i;
5053                                         }
5054                                         IF_NO_INTRP(
5055                                                         rd->interfaces[i][copy->type].type = copy->type;
5056                                                         rd->interfaces[i][copy->type].flags |= copy->flags;
5057                                         );
5058                                 }
5059
5060                                 /* check if interface slots at basic block begin must be saved */
5061
5062                                 IF_NO_INTRP(
5063                                         i = bptr->indepth - 1;
5064                                         for (copy = bptr->instack; copy; i--, copy = copy->prev) {
5065                                                 rd->interfaces[i][copy->type].type = copy->type;
5066                                                 if (copy->varkind == STACKVAR) {
5067                                                         if (copy->flags & SAVEDVAR)
5068                                                                 rd->interfaces[i][copy->type].flags |= SAVEDVAR;
5069                                                 }
5070                                         }
5071                                 );
5072
5073                         } /* if */
5074                         else
5075                                 superblockend = true;
5076
5077                         bptr++;
5078                 } /* while blocks */
5079         } while (repeat && !deadcode);
5080
5081 #if defined(ENABLE_STATISTICS)
5082         if (opt_stat) {
5083                 if (m->basicblockcount > count_max_basic_blocks)
5084                         count_max_basic_blocks = m->basicblockcount;
5085                 count_basic_blocks += m->basicblockcount;
5086                 if (m->instructioncount > count_max_javainstr)                  count_max_javainstr = m->instructioncount;
5087                 count_javainstr += m->instructioncount;
5088                 if (m->stackcount > count_upper_bound_new_stack)
5089                         count_upper_bound_new_stack = m->stackcount;
5090                 if ((new - m->stack) > count_max_new_stack)
5091                         count_max_new_stack = (new - m->stack);
5092
5093                 b_count = m->basicblockcount;
5094                 bptr = m->basicblocks;
5095                 while (--b_count >= 0) {
5096                         if (bptr->flags > BBREACHED) {
5097                                 if (bptr->indepth >= 10)
5098                                         count_block_stack[10]++;
5099                                 else
5100                                         count_block_stack[bptr->indepth]++;
5101                                 len = bptr->icount;
5102                                 if (len < 10) 
5103                                         count_block_size_distribution[len]++;
5104                                 else if (len <= 12)
5105                                         count_block_size_distribution[10]++;
5106                                 else if (len <= 14)
5107                                         count_block_size_distribution[11]++;
5108                                 else if (len <= 16)
5109                                         count_block_size_distribution[12]++;
5110                                 else if (len <= 18)
5111                                         count_block_size_distribution[13]++;
5112                                 else if (len <= 20)
5113                                         count_block_size_distribution[14]++;
5114                                 else if (len <= 25)
5115                                         count_block_size_distribution[15]++;
5116                                 else if (len <= 30)
5117                                         count_block_size_distribution[16]++;
5118                                 else
5119                                         count_block_size_distribution[17]++;
5120                         }
5121                         bptr++;
5122                 }
5123
5124                 if (loops == 1)
5125                         count_analyse_iterations[0]++;
5126                 else if (loops == 2)
5127                         count_analyse_iterations[1]++;
5128                 else if (loops == 3)
5129                         count_analyse_iterations[2]++;
5130                 else if (loops == 4)
5131                         count_analyse_iterations[3]++;
5132                 else
5133                         count_analyse_iterations[4]++;
5134
5135                 if (m->basicblockcount <= 5)
5136                         count_method_bb_distribution[0]++;
5137                 else if (m->basicblockcount <= 10)
5138                         count_method_bb_distribution[1]++;
5139                 else if (m->basicblockcount <= 15)
5140                         count_method_bb_distribution[2]++;
5141                 else if (m->basicblockcount <= 20)
5142                         count_method_bb_distribution[3]++;
5143                 else if (m->basicblockcount <= 30)
5144                         count_method_bb_distribution[4]++;
5145                 else if (m->basicblockcount <= 40)
5146                         count_method_bb_distribution[5]++;
5147                 else if (m->basicblockcount <= 50)
5148                         count_method_bb_distribution[6]++;
5149                 else if (m->basicblockcount <= 75)
5150                         count_method_bb_distribution[7]++;
5151                 else
5152                         count_method_bb_distribution[8]++;
5153         }
5154 #endif /* defined(ENABLE_STATISTICS) */
5155
5156         /* everything's ok */
5157
5158         return true;
5159
5160 #if defined(ENABLE_VERIFIER)
5161
5162 throw_stack_underflow:
5163         exceptions_throw_verifyerror(m, "Unable to pop operand off an empty stack");
5164         return false;
5165
5166 throw_stack_overflow:
5167         exceptions_throw_verifyerror(m, "Stack size too large");
5168         return false;
5169
5170 throw_stack_depth_error:
5171         exceptions_throw_verifyerror(m,"Stack depth mismatch");
5172         return false;
5173
5174 throw_stack_type_error:
5175         exceptions_throw_verifyerror_for_stack(m, expectedtype);
5176         return false;
5177
5178 throw_stack_category_error:
5179         exceptions_throw_verifyerror(m, "Attempt to split long or double on the stack");
5180         return false;
5181
5182 #endif
5183 }
5184
5185
5186
5187 /*
5188  * These are local overrides for various environment variables in Emacs.
5189  * Please do not remove this and leave it at the end of the file, where
5190  * Emacs will automagically detect them.
5191  * ---------------------------------------------------------------------
5192  * Local variables:
5193  * mode: c
5194  * indent-tabs-mode: t
5195  * c-basic-offset: 4
5196  * tab-width: 4
5197  * End:
5198  * vim:noexpandtab:sw=4:ts=4:
5199  */