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