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