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