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