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