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