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