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