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