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