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