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