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