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