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