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