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