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