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