SUPPORT_ONLY_ZERO_ASTORE bugfix.
[cacao.git] / src / vm / jit / stack.c
1 /* jit/stack.c - stack analysis
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Andreas Krall
28
29    Changes: Edwin Steiner
30
31    $Id: stack.c 1318 2004-07-16 13:30:51Z twisti $
32
33 */
34
35
36 #include <stdio.h>
37 #include <string.h>
38 #include "global.h"
39 #include "native.h"
40 #include "builtin.h"
41 #include "disass.h"
42 #include "tables.h"
43 #include "types.h"
44 #include "options.h"
45 #include "statistics.h"
46 #include "jit/jit.h"
47 #include "jit/stack.h"
48 #include "jit/reg.h"
49 #include "toolbox/logging.h"
50 #include "toolbox/memory.h"
51
52
53 /* from codegen.inc */
54 extern int dseglen;
55
56 /**********************************************************************/
57 /* Macros used internally by analyse_stack                            */
58 /**********************************************************************/
59
60 #ifdef STATISTICS
61 #define COUNT(cnt) cnt++
62 #else
63 #define COUNT(cnt)
64 #endif
65  
66 /* convenient abbreviations */
67 #define CURKIND    curstack->varkind
68 #define CURTYPE    curstack->type
69
70 /*--------------------------------------------------*/
71 /* SIGNALING ERRORS                                 */
72 /*--------------------------------------------------*/
73
74 #define TYPEPANIC  {panic("Stack type mismatch");}
75
76
77 /*--------------------------------------------------*/
78 /* STACK UNDERFLOW/OVERFLOW CHECKS                  */
79 /*--------------------------------------------------*/
80
81 /* underflow checks */
82
83 #define REQUIRE(num) \
84     do { \
85         if (stackdepth < (num)) { \
86             sprintf(msg, "(class: "); \
87             utf_sprint(msg + strlen(msg), m->class->name); \
88             sprintf(msg + strlen(msg), ", method: "); \
89             utf_sprint(msg + strlen(msg), m->name); \
90             sprintf(msg + strlen(msg), ", signature: "); \
91             utf_sprint(msg + strlen(msg), m->descriptor); \
92             sprintf(msg + strlen(msg), ") Unable to pop operand off an empty stack"); \
93             *exceptionptr = \
94                 new_exception_message(string_java_lang_VerifyError, msg); \
95             return NULL; \
96         } \
97     } while(0)
98
99 #define REQUIRE_1     REQUIRE(1)
100 #define REQUIRE_2     REQUIRE(2)
101 #define REQUIRE_3     REQUIRE(3)
102 #define REQUIRE_4     REQUIRE(4)
103
104
105 /* overflow check */
106 /* We allow ACONST instructions inserted as arguments to builtin
107  * functions to exceed the maximum stack depth.  Maybe we should check
108  * against maximum stack depth only at block boundaries?
109  */
110
111 #define CHECKOVERFLOW \
112         do { \
113                 if (stackdepth > m->maxstack) { \
114                         if (iptr[0].opc != ICMD_ACONST \
115                 || iptr[0].op1 == 0) { \
116                 sprintf(msg, "(class: "); \
117                 utf_sprint_classname(msg + strlen(msg), m->class->name); \
118                 sprintf(msg + strlen(msg), ", method: "); \
119                 utf_sprint(msg + strlen(msg), m->name); \
120                 sprintf(msg + strlen(msg), ", signature: "); \
121                 utf_sprint(msg + strlen(msg), m->descriptor); \
122                 sprintf(msg + strlen(msg), ") Stack size too large"); \
123                 *exceptionptr = \
124                     new_exception_message(string_java_lang_VerifyError, msg); \
125                 return NULL; \
126             } \
127                 } \
128         } while(0)
129
130
131 /*--------------------------------------------------*/
132 /* ALLOCATING STACK SLOTS                           */
133 /*--------------------------------------------------*/
134
135 #define NEWSTACK(s,v,n) {new->prev=curstack;new->type=s;new->flags=0;   \
136                         new->varkind=v;new->varnum=n;curstack=new;new++;}
137 #define NEWSTACKn(s,n)  NEWSTACK(s,UNDEFVAR,n)
138 #define NEWSTACK0(s)    NEWSTACK(s,UNDEFVAR,0)
139
140 /* allocate the input stack for an exception handler */
141 #define NEWXSTACK   {NEWSTACK(TYPE_ADR,STACKVAR,0);curstack=0;}
142
143
144 /*--------------------------------------------------*/
145 /* STACK MANIPULATION                               */
146 /*--------------------------------------------------*/
147
148 /* resetting to an empty operand stack */
149 #define STACKRESET {curstack=0;stackdepth=0;}
150
151 /* set the output stack of the current instruction */
152 #define SETDST      {iptr->dst=curstack;}
153
154 /* The following macros do NOT check stackdepth, set stackdepth or iptr->dst */
155 #define POP(s)      {if(s!=curstack->type){TYPEPANIC;}                                                                          \
156                      if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR;\
157                      curstack=curstack->prev;}
158 #define POPANY      {if(curstack->varkind==UNDEFVAR)curstack->varkind=TEMPVAR;  \
159                      curstack=curstack->prev;}
160 #define COPY(s,d)   {(d)->flags=0;(d)->type=(s)->type;\
161                      (d)->varkind=(s)->varkind;(d)->varnum=(s)->varnum;}
162
163
164 /*--------------------------------------------------*/
165 /* STACK OPERATIONS MODELING                        */
166 /*--------------------------------------------------*/
167
168 /* The following macros are used to model the stack manipulations of
169  * different kinds of instructions.
170  *
171  * These macros check the input stackdepth and they set the output
172  * stackdepth and the output stack of the instruction (iptr->dst).
173  *
174  * These macros do *not* check for stack overflows!
175  */
176    
177 #define PUSHCONST(s){NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
178 #define LOAD(s,v,n) {NEWSTACK(s,v,n);SETDST;stackdepth++;}
179 #define STORE(s)    {REQUIRE_1;POP(s);SETDST;stackdepth--;}
180 #define OP1_0(s)    {REQUIRE_1;POP(s);SETDST;stackdepth--;}
181 #define OP1_0ANY    {REQUIRE_1;POPANY;SETDST;stackdepth--;}
182 #define OP0_1(s)    {NEWSTACKn(s,stackdepth);SETDST;stackdepth++;}
183 #define OP1_1(s,d)  {REQUIRE_1;POP(s);NEWSTACKn(d,stackdepth-1);SETDST;}
184 #define OP2_0(s)    {REQUIRE_2;POP(s);POP(s);SETDST;stackdepth-=2;}
185 #define OPTT2_0(t,b){REQUIRE_2;POP(t);POP(b);SETDST;stackdepth-=2;}
186 #define OP2_1(s)    {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);SETDST;stackdepth--;}
187 #define OP2IAT_1(s) {REQUIRE_2;POP(TYPE_INT);POP(TYPE_ADR);NEWSTACKn(s,stackdepth-2);\
188                      SETDST;stackdepth--;}
189 #define OP2IT_1(s)  {REQUIRE_2;POP(TYPE_INT);POP(s);NEWSTACKn(s,stackdepth-2);\
190                      SETDST;stackdepth--;}
191 #define OPTT2_1(s,d){REQUIRE_2;POP(s);POP(s);NEWSTACKn(d,stackdepth-2);SETDST;stackdepth--;}
192 #define OP2_2(s)    {REQUIRE_2;POP(s);POP(s);NEWSTACKn(s,stackdepth-2);\
193                      NEWSTACKn(s,stackdepth-1);SETDST;}
194 #define OP3TIA_0(s) {REQUIRE_3;POP(s);POP(TYPE_INT);POP(TYPE_ADR);SETDST;stackdepth-=3;}
195 #define OP3_0(s)    {REQUIRE_3;POP(s);POP(s);POP(s);SETDST;stackdepth-=3;}
196 #define POPMANY(i)  {REQUIRE(i);stackdepth-=i;while(--i>=0){POPANY;}SETDST;}
197 #define DUP         {REQUIRE_1;NEWSTACK(CURTYPE,CURKIND,curstack->varnum);SETDST; \
198                     stackdepth++;}
199 #define SWAP        {REQUIRE_2;COPY(curstack,new);POPANY;COPY(curstack,new+1);POPANY;\
200                     new[0].prev=curstack;new[1].prev=new;\
201                     curstack=new+1;new+=2;SETDST;}
202 #define DUP_X1      {REQUIRE_2;COPY(curstack,new);COPY(curstack,new+2);POPANY;\
203                     COPY(curstack,new+1);POPANY;new[0].prev=curstack;\
204                     new[1].prev=new;new[2].prev=new+1;\
205                     curstack=new+2;new+=3;SETDST;stackdepth++;}
206 #define DUP2_X1     {REQUIRE_3;COPY(curstack,new+1);COPY(curstack,new+4);POPANY;\
207                     COPY(curstack,new);COPY(curstack,new+3);POPANY;\
208                     COPY(curstack,new+2);POPANY;new[0].prev=curstack;\
209                     new[1].prev=new;new[2].prev=new+1;\
210                     new[3].prev=new+2;new[4].prev=new+3;\
211                     curstack=new+4;new+=5;SETDST;stackdepth+=2;}
212 #define DUP_X2      {REQUIRE_3;COPY(curstack,new);COPY(curstack,new+3);POPANY;\
213                     COPY(curstack,new+2);POPANY;COPY(curstack,new+1);POPANY;\
214                     new[0].prev=curstack;new[1].prev=new;\
215                     new[2].prev=new+1;new[3].prev=new+2;\
216                     curstack=new+3;new+=4;SETDST;stackdepth++;}
217 #define DUP2_X2     {REQUIRE_4;COPY(curstack,new+1);COPY(curstack,new+5);POPANY;\
218                     COPY(curstack,new);COPY(curstack,new+4);POPANY;\
219                     COPY(curstack,new+3);POPANY;COPY(curstack,new+2);POPANY;\
220                     new[0].prev=curstack;new[1].prev=new;\
221                     new[2].prev=new+1;new[3].prev=new+2;\
222                     new[4].prev=new+3;new[5].prev=new+4;\
223                     curstack=new+5;new+=6;SETDST;stackdepth+=2;}
224
225
226 /*--------------------------------------------------*/
227 /* MACROS FOR HANDLING BASIC BLOCKS                 */
228 /*--------------------------------------------------*/
229
230 /* COPYCURSTACK makes a copy of the current operand stack (curstack)
231  * and returns it in the variable copy.
232  *
233  * This macro is used to propagate the operand stack from one basic
234  * block to another. The destination block receives the copy as its
235  * input stack.
236  */
237 #define COPYCURSTACK(copy) {\
238         int d;\
239         stackptr s;\
240         if(curstack){\
241                 s=curstack;\
242                 new+=stackdepth;\
243                 d=stackdepth;\
244                 copy=new;\
245                 while(s){\
246                         copy--;d--;\
247                         copy->prev=copy-1;\
248                         copy->type=s->type;\
249                         copy->flags=0;\
250                         copy->varkind=STACKVAR;\
251                         copy->varnum=d;\
252                         s=s->prev;\
253                         }\
254                 copy->prev=NULL;\
255                 copy=new-1;\
256                 }\
257         else\
258                 copy=NULL;\
259 }
260
261 /* BBEND is called at the end of each basic block (after the last
262  * instruction of the block has been processed).
263  */
264
265 #define BBEND(s,i){ \
266         i = stackdepth - 1; \
267         copy = s; \
268         while (copy) { \
269                 if ((copy->varkind == STACKVAR) && (copy->varnum > i)) \
270                         copy->varkind = TEMPVAR; \
271                 else { \
272                         copy->varkind = STACKVAR; \
273                         copy->varnum = i;\
274                 } \
275                 m->registerdata->interfaces[i][copy->type].type = copy->type; \
276                 m->registerdata->interfaces[i][copy->type].flags |= copy->flags; \
277                 i--; copy = copy->prev; \
278         } \
279         i = bptr->indepth - 1; \
280         copy = bptr->instack; \
281         while (copy) { \
282                 m->registerdata->interfaces[i][copy->type].type = copy->type; \
283                 if (copy->varkind == STACKVAR) { \
284                         if (copy->flags & SAVEDVAR) \
285                                 m->registerdata->interfaces[i][copy->type].flags |= SAVEDVAR; \
286                 } \
287                 i--; copy = copy->prev; \
288         } \
289 }
290
291
292 /* MARKREACHED marks the destination block <b> as reached. If this
293  * block has been reached before we check if stack depth and types
294  * match. Otherwise the destination block receives a copy of the
295  * current stack as its input stack.
296  *
297  * b...destination block
298  * c...current stack
299  */
300 #define MARKREACHED(b,c) {                                                                                              \
301         if(b->flags<0)                                                                                                          \
302                 {COPYCURSTACK(c);b->flags=0;b->instack=c;b->indepth=stackdepth;} \
303         else {stackptr s=curstack;stackptr t=b->instack;                                        \
304                 if(b->indepth!=stackdepth)                                                                              \
305                         {show_icmd_method(m);panic("Stack depth mismatch");}                    \
306                 while(s){if (s->type!=t->type)                                                                  \
307                                 TYPEPANIC                                                                                               \
308                         s=s->prev;t=t->prev;                                                                            \
309                         }                                                                                                                       \
310                 }                                                                                                                               \
311 }
312
313
314 /**********************************************************************/
315 /* analyse_stack                                                      */
316 /**********************************************************************/
317
318 /* analyse_stack uses the intermediate code created by parse.c to
319  * build a model of the JVM operand stack for the current method.
320  *
321  * The following checks are performed:
322  *   - check for operand stack underflow (before each instruction)
323  *   - check for operand stack overflow (after[1] each instruction)
324  *   - check for matching stack depth at merging points
325  *   - check for matching basic types[2] at merging points
326  *   - check basic types for instruction input (except for BUILTIN*
327  *         opcodes, INVOKE* opcodes and MULTIANEWARRAY)
328  *
329  * [1]) Checking this after the instruction should be ok. parse.c
330  * counts the number of required stack slots in such a way that it is
331  * only vital that we don't exceed `maxstack` at basic block
332  * boundaries.
333  *
334  * [2]) 'basic types' means the distinction between INT, LONG, FLOAT,
335  * DOUBLE and ADDRESS types. Subtypes of INT and different ADDRESS
336  * types are not discerned.
337  */
338
339 methodinfo *analyse_stack(methodinfo *m)
340 {
341         int b_count;
342         int b_index;
343         int stackdepth;
344         stackptr curstack;
345         stackptr new;
346         stackptr copy;
347         int opcode, i, len, loops;
348         int superblockend, repeat, deadcode;
349         instruction *iptr;
350         basicblock *bptr;
351         basicblock *tbptr;
352         s4 *s4ptr;
353         void* *tptr;
354         int *argren;
355         char msg[MAXLOGTEXT];               /* maybe we get an exception          */
356
357         argren = DMNEW(int, m->maxlocals);
358         /*int *argren = (int *)alloca(m->maxlocals * sizeof(int));*/ /* table for argument renaming */
359         for (i = 0; i < m->maxlocals; i++)
360                 argren[i] = i;
361         
362         m->registerdata->arguments_num = 0;
363         new = m->stack;
364         loops = 0;
365         m->basicblocks[0].flags = BBREACHED;
366         m->basicblocks[0].instack = 0;
367         m->basicblocks[0].indepth = 0;
368
369         for (i = 0; i < m->exceptiontablelength; i++) {
370                 bptr = &m->basicblocks[m->basicblockindex[m->exceptiontable[i].handlerpc]];
371                 bptr->flags = BBREACHED;
372                 bptr->type = BBTYPE_EXH;
373                 bptr->instack = new;
374                 bptr->indepth = 1;
375                 bptr->pre_count = 10000;
376                 STACKRESET;
377                 NEWXSTACK;
378         }
379
380 #ifdef CONDITIONAL_LOADCONST
381         b_count = m->basicblockcount;
382         bptr = m->basicblocks;
383         while (--b_count >= 0) {
384                 if (bptr->icount != 0) {
385                         iptr = bptr->iinstr + bptr->icount - 1;
386                         switch (iptr->opc) {
387                         case ICMD_RET:
388                         case ICMD_RETURN:
389                         case ICMD_IRETURN:
390                         case ICMD_LRETURN:
391                         case ICMD_FRETURN:
392                         case ICMD_DRETURN:
393                         case ICMD_ARETURN:
394                         case ICMD_ATHROW:
395                                 break;
396
397                         case ICMD_IFEQ:
398                         case ICMD_IFNE:
399                         case ICMD_IFLT:
400                         case ICMD_IFGE:
401                         case ICMD_IFGT:
402                         case ICMD_IFLE:
403
404                         case ICMD_IFNULL:
405                         case ICMD_IFNONNULL:
406
407                         case ICMD_IF_ICMPEQ:
408                         case ICMD_IF_ICMPNE:
409                         case ICMD_IF_ICMPLT:
410                         case ICMD_IF_ICMPGE:
411                         case ICMD_IF_ICMPGT:
412                         case ICMD_IF_ICMPLE:
413
414                         case ICMD_IF_ACMPEQ:
415                         case ICMD_IF_ACMPNE:
416                                 bptr[1].pre_count++;
417                         case ICMD_GOTO:
418                                 m->basicblocks[m->basicblockindex[iptr->op1]].pre_count++;
419                                 break;
420
421                         case ICMD_TABLESWITCH:
422                                 s4ptr = iptr->val.a;
423                                 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
424                                 i = *s4ptr++;                               /* low     */
425                                 i = *s4ptr++ - i + 1;                       /* high    */
426                                 while (--i >= 0) {
427                                         m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
428                                 }
429                                 break;
430                                         
431                         case ICMD_LOOKUPSWITCH:
432                                 s4ptr = iptr->val.a;
433                                 m->basicblocks[m->basicblockindex[*s4ptr++]].pre_count++;
434                                 i = *s4ptr++;                               /* count   */
435                                 while (--i >= 0) {
436                                         m->basicblocks[m->basicblockindex[s4ptr[1]]].pre_count++;
437                                         s4ptr += 2;
438                                 }
439                                 break;
440                         default:
441                                 bptr[1].pre_count++;
442                                 break;
443                         }
444                 }
445                 bptr++;
446         }
447 #endif
448
449
450         do {
451                 loops++;
452                 b_count = m->basicblockcount;
453                 bptr = m->basicblocks;
454                 superblockend = true;
455                 repeat = false;
456                 STACKRESET;
457                 deadcode = true;
458                 while (--b_count >= 0) {
459                         if (bptr->flags == BBDELETED) {
460                                 /* do nothing */
461                         }
462                         else if (superblockend && (bptr->flags < BBREACHED))
463                                 repeat = true;
464                         else if (bptr->flags <= BBREACHED) {
465                                 if (superblockend)
466                                         stackdepth = bptr->indepth;
467                                 else if (bptr->flags < BBREACHED) {
468                                         COPYCURSTACK(copy);
469                                         bptr->instack = copy;
470                                         bptr->indepth = stackdepth;
471                                 }
472                                 else if (bptr->indepth != stackdepth) {
473                                         show_icmd_method(m);
474                                         panic("Stack depth mismatch");
475                                         
476                                 }
477                                 curstack = bptr->instack;
478                                 deadcode = false;
479                                 superblockend = false;
480                                 bptr->flags = BBFINISHED;
481                                 len = bptr->icount;
482                                 iptr = bptr->iinstr;
483                                 b_index = bptr - m->basicblocks;
484                                 while (--len >= 0)  {
485                                         opcode = iptr->opc;
486                                         iptr->target = NULL;
487
488 /*                                      dolog("p: %04d op: %s stack: %p", iptr - instr, icmd_names[opcode], curstack); */
489
490 #ifdef USEBUILTINTABLE
491                                         {
492 #if 0
493                                                 stdopdescriptor *breplace;
494                                                 breplace = find_builtin(opcode);
495
496                                                 if (breplace && opcode == breplace->opcode) {
497                                                         iptr[0].opc = breplace->icmd;
498                                                         iptr[0].op1 = breplace->type_d;
499                                                         iptr[0].val.a = breplace->builtin;
500                                                         m->isleafmethod = false;
501                                                         switch (breplace->icmd) {
502                                                         case ICMD_BUILTIN1:
503                                                                 goto builtin1;
504                                                         case ICMD_BUILTIN2:
505                                                                 goto builtin2;
506                                                         }
507                                                 }
508 #endif
509                                                 builtin_descriptor *breplace;
510                                                 breplace = find_builtin(opcode);
511
512                                                 if (breplace && opcode == breplace->opcode) {
513                                                         iptr[0].opc = breplace->icmd;
514                                                         iptr[0].op1 = breplace->type_d;
515                                                         iptr[0].val.a = breplace->builtin;
516                                                         m->isleafmethod = false;
517                                                         switch (breplace->icmd) {
518                                                         case ICMD_BUILTIN1:
519                                                                 goto builtin1;
520                                                         case ICMD_BUILTIN2:
521                                                                 goto builtin2;
522                                                         }
523                                                 }
524                                         }
525 #endif
526                                         
527                                         switch (opcode) {
528
529                                                 /* pop 0 push 0 */
530
531                                         case ICMD_NOP:
532                                         case ICMD_CHECKASIZE:
533                                         case ICMD_CHECKEXCEPTION:
534
535                                         case ICMD_IFEQ_ICONST:
536                                         case ICMD_IFNE_ICONST:
537                                         case ICMD_IFLT_ICONST:
538                                         case ICMD_IFGE_ICONST:
539                                         case ICMD_IFGT_ICONST:
540                                         case ICMD_IFLE_ICONST:
541                                         case ICMD_ELSE_ICONST:
542                                                 SETDST;
543                                                 break;
544
545                                         case ICMD_RET:
546                                                 m->registerdata->locals[iptr->op1][TYPE_ADR].type = TYPE_ADR;
547                                         case ICMD_RETURN:
548                                                 COUNT(count_pcmd_return);
549                                                 SETDST;
550                                                 superblockend = true;
551                                                 break;
552
553                                                 /* pop 0 push 1 const */
554                                                 
555                                         case ICMD_ICONST:
556                                                 COUNT(count_pcmd_load);
557                                                 if (len > 0) {
558                                                         switch (iptr[1].opc) {
559                                                         case ICMD_IADD:
560                                                                 iptr[0].opc = ICMD_IADDCONST;
561                                                         icmd_iconst_tail:
562                                                                 iptr[1].opc = ICMD_NOP;
563                                                                 OP1_1(TYPE_INT,TYPE_INT);
564                                                                 COUNT(count_pcmd_op);
565                                                                 break;
566                                                         case ICMD_ISUB:
567                                                                 iptr[0].opc = ICMD_ISUBCONST;
568                                                                 goto icmd_iconst_tail;
569                                                         case ICMD_IMUL:
570                                                                 iptr[0].opc = ICMD_IMULCONST;
571                                                                 goto icmd_iconst_tail;
572                                                         case ICMD_IDIV:
573                                                                 if (iptr[0].val.i == 0x00000002)
574                                                                         iptr[0].val.i = 1;
575                                                                 else if (iptr[0].val.i == 0x00000004)
576                                                                         iptr[0].val.i = 2;
577                                                                 else if (iptr[0].val.i == 0x00000008)
578                                                                         iptr[0].val.i = 3;
579                                                                 else if (iptr[0].val.i == 0x00000010)
580                                                                         iptr[0].val.i = 4;
581                                                                 else if (iptr[0].val.i == 0x00000020)
582                                                                         iptr[0].val.i = 5;
583                                                                 else if (iptr[0].val.i == 0x00000040)
584                                                                         iptr[0].val.i = 6;
585                                                                 else if (iptr[0].val.i == 0x00000080)
586                                                                         iptr[0].val.i = 7;
587                                                                 else if (iptr[0].val.i == 0x00000100)
588                                                                         iptr[0].val.i = 8;
589                                                                 else if (iptr[0].val.i == 0x00000200)
590                                                                         iptr[0].val.i = 9;
591                                                                 else if (iptr[0].val.i == 0x00000400)
592                                                                         iptr[0].val.i = 10;
593                                                                 else if (iptr[0].val.i == 0x00000800)
594                                                                         iptr[0].val.i = 11;
595                                                                 else if (iptr[0].val.i == 0x00001000)
596                                                                         iptr[0].val.i = 12;
597                                                                 else if (iptr[0].val.i == 0x00002000)
598                                                                         iptr[0].val.i = 13;
599                                                                 else if (iptr[0].val.i == 0x00004000)
600                                                                         iptr[0].val.i = 14;
601                                                                 else if (iptr[0].val.i == 0x00008000)
602                                                                         iptr[0].val.i = 15;
603                                                                 else if (iptr[0].val.i == 0x00010000)
604                                                                         iptr[0].val.i = 16;
605                                                                 else if (iptr[0].val.i == 0x00020000)
606                                                                         iptr[0].val.i = 17;
607                                                                 else if (iptr[0].val.i == 0x00040000)
608                                                                         iptr[0].val.i = 18;
609                                                                 else if (iptr[0].val.i == 0x00080000)
610                                                                         iptr[0].val.i = 19;
611                                                                 else if (iptr[0].val.i == 0x00100000)
612                                                                         iptr[0].val.i = 20;
613                                                                 else if (iptr[0].val.i == 0x00200000)
614                                                                         iptr[0].val.i = 21;
615                                                                 else if (iptr[0].val.i == 0x00400000)
616                                                                         iptr[0].val.i = 22;
617                                                                 else if (iptr[0].val.i == 0x00800000)
618                                                                         iptr[0].val.i = 23;
619                                                                 else if (iptr[0].val.i == 0x01000000)
620                                                                         iptr[0].val.i = 24;
621                                                                 else if (iptr[0].val.i == 0x02000000)
622                                                                         iptr[0].val.i = 25;
623                                                                 else if (iptr[0].val.i == 0x04000000)
624                                                                         iptr[0].val.i = 26;
625                                                                 else if (iptr[0].val.i == 0x08000000)
626                                                                         iptr[0].val.i = 27;
627                                                                 else if (iptr[0].val.i == 0x10000000)
628                                                                         iptr[0].val.i = 28;
629                                                                 else if (iptr[0].val.i == 0x20000000)
630                                                                         iptr[0].val.i = 29;
631                                                                 else if (iptr[0].val.i == 0x40000000)
632                                                                         iptr[0].val.i = 30;
633                                                                 else if (iptr[0].val.i == 0x80000000)
634                                                                         iptr[0].val.i = 31;
635                                                                 else {
636                                                                         PUSHCONST(TYPE_INT);
637                                                                         break;
638                                                                 }
639                                                                 iptr[0].opc = ICMD_IDIVPOW2;
640                                                                 goto icmd_iconst_tail;
641                                                         case ICMD_IREM:
642                                                                 if ((iptr[0].val.i == 0x00000002) ||
643                                                                         (iptr[0].val.i == 0x00000004) ||
644                                                                         (iptr[0].val.i == 0x00000008) ||
645                                                                         (iptr[0].val.i == 0x00000010) ||
646                                                                         (iptr[0].val.i == 0x00000020) ||
647                                                                         (iptr[0].val.i == 0x00000040) ||
648                                                                         (iptr[0].val.i == 0x00000080) ||
649                                                                         (iptr[0].val.i == 0x00000100) ||
650                                                                         (iptr[0].val.i == 0x00000200) ||
651                                                                         (iptr[0].val.i == 0x00000400) ||
652                                                                         (iptr[0].val.i == 0x00000800) ||
653                                                                         (iptr[0].val.i == 0x00001000) ||
654                                                                         (iptr[0].val.i == 0x00002000) ||
655                                                                         (iptr[0].val.i == 0x00004000) ||
656                                                                         (iptr[0].val.i == 0x00008000) ||
657                                                                         (iptr[0].val.i == 0x00010000) ||
658                                                                         (iptr[0].val.i == 0x00020000) ||
659                                                                         (iptr[0].val.i == 0x00040000) ||
660                                                                         (iptr[0].val.i == 0x00080000) ||
661                                                                         (iptr[0].val.i == 0x00100000) ||
662                                                                         (iptr[0].val.i == 0x00200000) ||
663                                                                         (iptr[0].val.i == 0x00400000) ||
664                                                                         (iptr[0].val.i == 0x00800000) ||
665                                                                         (iptr[0].val.i == 0x01000000) ||
666                                                                         (iptr[0].val.i == 0x02000000) ||
667                                                                         (iptr[0].val.i == 0x04000000) ||
668                                                                         (iptr[0].val.i == 0x08000000) ||
669                                                                         (iptr[0].val.i == 0x10000000) ||
670                                                                         (iptr[0].val.i == 0x20000000) ||
671                                                                         (iptr[0].val.i == 0x40000000) ||
672                                                                         (iptr[0].val.i == 0x80000000)) {
673                                                                         iptr[0].opc = ICMD_IREMPOW2;
674                                                                         iptr[0].val.i -= 1;
675 #if defined(__I386__)
676                                                                         method_uses_ecx = true;
677 #endif
678                                                                         goto icmd_iconst_tail;
679                                                                 }
680                                                                 PUSHCONST(TYPE_INT);
681                                                                 break;
682                                                         case ICMD_IAND:
683                                                                 iptr[0].opc = ICMD_IANDCONST;
684                                                                 goto icmd_iconst_tail;
685                                                         case ICMD_IOR:
686                                                                 iptr[0].opc = ICMD_IORCONST;
687                                                                 goto icmd_iconst_tail;
688                                                         case ICMD_IXOR:
689                                                                 iptr[0].opc = ICMD_IXORCONST;
690                                                                 goto icmd_iconst_tail;
691                                                         case ICMD_ISHL:
692                                                                 iptr[0].opc = ICMD_ISHLCONST;
693                                                                 goto icmd_iconst_tail;
694                                                         case ICMD_ISHR:
695                                                                 iptr[0].opc = ICMD_ISHRCONST;
696                                                                 goto icmd_iconst_tail;
697                                                         case ICMD_IUSHR:
698                                                                 iptr[0].opc = ICMD_IUSHRCONST;
699                                                                 goto icmd_iconst_tail;
700 #if SUPPORT_LONG_SHIFT
701                                                         case ICMD_LSHL:
702                                                                 iptr[0].opc = ICMD_LSHLCONST;
703 #if defined(__I386__)
704                                                                 method_uses_ecx = true;
705 #endif
706                                                                 goto icmd_lconst_tail;
707                                                         case ICMD_LSHR:
708                                                                 iptr[0].opc = ICMD_LSHRCONST;
709 #if defined(__I386__)
710                                                                 method_uses_ecx = true;
711 #endif
712                                                                 goto icmd_lconst_tail;
713                                                         case ICMD_LUSHR:
714                                                                 iptr[0].opc = ICMD_LUSHRCONST;
715 #if defined(__I386__)
716                                                                 method_uses_ecx = true;
717 #endif
718                                                                 goto icmd_lconst_tail;
719 #endif
720                                                         case ICMD_IF_ICMPEQ:
721                                                                 iptr[0].opc = ICMD_IFEQ;
722                                                         icmd_if_icmp_tail:
723                                                                 iptr[0].op1 = iptr[1].op1;
724                                                                 bptr->icount--;
725                                                                 len--;
726                                                                 /* iptr[1].opc = ICMD_NOP; */
727                                                                 OP1_0(TYPE_INT);
728                                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
729
730                                                                 iptr[0].target = (void *) tbptr;
731
732                                                                 MARKREACHED(tbptr, copy);
733                                                                 COUNT(count_pcmd_bra);
734                                                                 break;
735                                                         case ICMD_IF_ICMPLT:
736                                                                 iptr[0].opc = ICMD_IFLT;
737                                                                 goto icmd_if_icmp_tail;
738                                                         case ICMD_IF_ICMPLE:
739                                                                 iptr[0].opc = ICMD_IFLE;
740                                                                 goto icmd_if_icmp_tail;
741                                                         case ICMD_IF_ICMPNE:
742                                                                 iptr[0].opc = ICMD_IFNE;
743                                                                 goto icmd_if_icmp_tail;
744                                                         case ICMD_IF_ICMPGT:
745                                                                 iptr[0].opc = ICMD_IFGT;
746                                                                 goto icmd_if_icmp_tail;
747                                                         case ICMD_IF_ICMPGE:
748                                                                 iptr[0].opc = ICMD_IFGE;
749                                                                 goto icmd_if_icmp_tail;
750
751 #if SUPPORT_CONST_ASTORE
752                                                         case ICMD_IASTORE:
753                                                         case ICMD_BASTORE:
754                                                         case ICMD_CASTORE:
755                                                         case ICMD_SASTORE:
756 #if SUPPORT_ONLY_ZERO_ASTORE
757                                                                 if (iptr[0].val.i == 0) {
758 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
759                                                                         switch (iptr[1].opc) {
760                                                                         case ICMD_IASTORE:
761                                                                                 iptr[0].opc = ICMD_IASTORECONST;
762                                                                                 break;
763                                                                         case ICMD_BASTORE:
764                                                                                 iptr[0].opc = ICMD_BASTORECONST;
765                                                                                 break;
766                                                                         case ICMD_CASTORE:
767                                                                                 iptr[0].opc = ICMD_CASTORECONST;
768                                                                                 break;
769                                                                         case ICMD_SASTORE:
770                                                                                 iptr[0].opc = ICMD_SASTORECONST;
771                                                                                 break;
772                                                                         }
773
774                                                                         iptr[1].opc = ICMD_NOP;
775                                                                         OPTT2_0(TYPE_INT, TYPE_ADR);
776                                                                         COUNT(count_pcmd_op);
777 #if SUPPORT_ONLY_ZERO_ASTORE
778                                                                 } else
779                                                                         PUSHCONST(TYPE_INT);
780 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
781                                                                 break;
782 #endif /* SUPPORT_CONST_ASTORE */
783
784                                                         default:
785                                                                 PUSHCONST(TYPE_INT);
786                                                         }
787                                                 }
788                                                 else
789                                                         PUSHCONST(TYPE_INT);
790                                                 break;
791
792                                         case ICMD_LCONST:
793                                                 COUNT(count_pcmd_load);
794                                                 if (len > 0) {
795                                                         switch (iptr[1].opc) {
796 #if SUPPORT_LONG_ADD
797                                                         case ICMD_LADD:
798                                                                 iptr[0].opc = ICMD_LADDCONST;
799                                                         icmd_lconst_tail:
800                                                                 iptr[1].opc = ICMD_NOP;
801                                                                 OP1_1(TYPE_LNG,TYPE_LNG);
802                                                                 COUNT(count_pcmd_op);
803                                                                 break;
804                                                         case ICMD_LSUB:
805                                                                 iptr[0].opc = ICMD_LSUBCONST;
806                                                                 goto icmd_lconst_tail;
807 #endif
808 #if SUPPORT_LONG_MUL
809                                                         case ICMD_LMUL:
810                                                                 iptr[0].opc = ICMD_LMULCONST;
811 #if defined(__I386__)
812                                                                 method_uses_ecx = true;
813                                                                 method_uses_edx = true;
814 #endif
815                                                                 goto icmd_lconst_tail;
816 #endif
817 #if SUPPORT_LONG_DIV
818                                                         case ICMD_LDIV:
819                                                                 if (iptr[0].val.l == 0x00000002)
820                                                                         iptr[0].val.i = 1;
821                                                                 else if (iptr[0].val.l == 0x00000004)
822                                                                         iptr[0].val.i = 2;
823                                                                 else if (iptr[0].val.l == 0x00000008)
824                                                                         iptr[0].val.i = 3;
825                                                                 else if (iptr[0].val.l == 0x00000010)
826                                                                         iptr[0].val.i = 4;
827                                                                 else if (iptr[0].val.l == 0x00000020)
828                                                                         iptr[0].val.i = 5;
829                                                                 else if (iptr[0].val.l == 0x00000040)
830                                                                         iptr[0].val.i = 6;
831                                                                 else if (iptr[0].val.l == 0x00000080)
832                                                                         iptr[0].val.i = 7;
833                                                                 else if (iptr[0].val.l == 0x00000100)
834                                                                         iptr[0].val.i = 8;
835                                                                 else if (iptr[0].val.l == 0x00000200)
836                                                                         iptr[0].val.i = 9;
837                                                                 else if (iptr[0].val.l == 0x00000400)
838                                                                         iptr[0].val.i = 10;
839                                                                 else if (iptr[0].val.l == 0x00000800)
840                                                                         iptr[0].val.i = 11;
841                                                                 else if (iptr[0].val.l == 0x00001000)
842                                                                         iptr[0].val.i = 12;
843                                                                 else if (iptr[0].val.l == 0x00002000)
844                                                                         iptr[0].val.i = 13;
845                                                                 else if (iptr[0].val.l == 0x00004000)
846                                                                         iptr[0].val.i = 14;
847                                                                 else if (iptr[0].val.l == 0x00008000)
848                                                                         iptr[0].val.i = 15;
849                                                                 else if (iptr[0].val.l == 0x00010000)
850                                                                         iptr[0].val.i = 16;
851                                                                 else if (iptr[0].val.l == 0x00020000)
852                                                                         iptr[0].val.i = 17;
853                                                                 else if (iptr[0].val.l == 0x00040000)
854                                                                         iptr[0].val.i = 18;
855                                                                 else if (iptr[0].val.l == 0x00080000)
856                                                                         iptr[0].val.i = 19;
857                                                                 else if (iptr[0].val.l == 0x00100000)
858                                                                         iptr[0].val.i = 20;
859                                                                 else if (iptr[0].val.l == 0x00200000)
860                                                                         iptr[0].val.i = 21;
861                                                                 else if (iptr[0].val.l == 0x00400000)
862                                                                         iptr[0].val.i = 22;
863                                                                 else if (iptr[0].val.l == 0x00800000)
864                                                                         iptr[0].val.i = 23;
865                                                                 else if (iptr[0].val.l == 0x01000000)
866                                                                         iptr[0].val.i = 24;
867                                                                 else if (iptr[0].val.l == 0x02000000)
868                                                                         iptr[0].val.i = 25;
869                                                                 else if (iptr[0].val.l == 0x04000000)
870                                                                         iptr[0].val.i = 26;
871                                                                 else if (iptr[0].val.l == 0x08000000)
872                                                                         iptr[0].val.i = 27;
873                                                                 else if (iptr[0].val.l == 0x10000000)
874                                                                         iptr[0].val.i = 28;
875                                                                 else if (iptr[0].val.l == 0x20000000)
876                                                                         iptr[0].val.i = 29;
877                                                                 else if (iptr[0].val.l == 0x40000000)
878                                                                         iptr[0].val.i = 30;
879                                                                 else if (iptr[0].val.l == 0x80000000)
880                                                                         iptr[0].val.i = 31;
881                                                                 else {
882                                                                         PUSHCONST(TYPE_LNG);
883                                                                         break;
884                                                                 }
885                                                                 iptr[0].opc = ICMD_LDIVPOW2;
886 #if defined(__I386__)
887                                                                 method_uses_ecx = true;
888 #endif
889                                                                 goto icmd_lconst_tail;
890                                                         case ICMD_LREM:
891                                                                 if ((iptr[0].val.l == 0x00000002) ||
892                                                                         (iptr[0].val.l == 0x00000004) ||
893                                                                         (iptr[0].val.l == 0x00000008) ||
894                                                                         (iptr[0].val.l == 0x00000010) ||
895                                                                         (iptr[0].val.l == 0x00000020) ||
896                                                                         (iptr[0].val.l == 0x00000040) ||
897                                                                         (iptr[0].val.l == 0x00000080) ||
898                                                                         (iptr[0].val.l == 0x00000100) ||
899                                                                         (iptr[0].val.l == 0x00000200) ||
900                                                                         (iptr[0].val.l == 0x00000400) ||
901                                                                         (iptr[0].val.l == 0x00000800) ||
902                                                                         (iptr[0].val.l == 0x00001000) ||
903                                                                         (iptr[0].val.l == 0x00002000) ||
904                                                                         (iptr[0].val.l == 0x00004000) ||
905                                                                         (iptr[0].val.l == 0x00008000) ||
906                                                                         (iptr[0].val.l == 0x00010000) ||
907                                                                         (iptr[0].val.l == 0x00020000) ||
908                                                                         (iptr[0].val.l == 0x00040000) ||
909                                                                         (iptr[0].val.l == 0x00080000) ||
910                                                                         (iptr[0].val.l == 0x00100000) ||
911                                                                         (iptr[0].val.l == 0x00200000) ||
912                                                                         (iptr[0].val.l == 0x00400000) ||
913                                                                         (iptr[0].val.l == 0x00800000) ||
914                                                                         (iptr[0].val.l == 0x01000000) ||
915                                                                         (iptr[0].val.l == 0x02000000) ||
916                                                                         (iptr[0].val.l == 0x04000000) ||
917                                                                         (iptr[0].val.l == 0x08000000) ||
918                                                                         (iptr[0].val.l == 0x10000000) ||
919                                                                         (iptr[0].val.l == 0x20000000) ||
920                                                                         (iptr[0].val.l == 0x40000000) ||
921                                                                         (iptr[0].val.l == 0x80000000)) {
922                                                                         iptr[0].opc = ICMD_LREMPOW2;
923                                                                         iptr[0].val.l -= 1;
924 #if defined(__I386__)
925                                                                         method_uses_ecx = true;
926 #endif
927                                                                         goto icmd_lconst_tail;
928                                                                 }
929                                                                 PUSHCONST(TYPE_LNG);
930                                                                 break;
931 #endif
932 #if SUPPORT_LONG_LOG
933                                                         case ICMD_LAND:
934                                                                 iptr[0].opc = ICMD_LANDCONST;
935                                                                 goto icmd_lconst_tail;
936                                                         case ICMD_LOR:
937                                                                 iptr[0].opc = ICMD_LORCONST;
938                                                                 goto icmd_lconst_tail;
939                                                         case ICMD_LXOR:
940                                                                 iptr[0].opc = ICMD_LXORCONST;
941                                                                 goto icmd_lconst_tail;
942 #endif
943 #if !defined(NOLONG_CONDITIONAL)
944                                                         case ICMD_LCMP:
945                                                                 if ((len > 1) && (iptr[2].val.i == 0)) {
946                                                                         switch (iptr[2].opc) {
947                                                                         case ICMD_IFEQ:
948                                                                                 iptr[0].opc = ICMD_IF_LEQ;
949 #if defined(__I386__)
950                                                                                 method_uses_ecx = true;
951 #endif
952                                                                         icmd_lconst_lcmp_tail:
953                                                                                 iptr[0].op1 = iptr[2].op1;
954                                                                                 bptr->icount -= 2;
955                                                                                 len -= 2;
956                                                                                 /* iptr[1].opc = ICMD_NOP;
957                                                                                    iptr[2].opc = ICMD_NOP; */
958                                                                                 OP1_0(TYPE_LNG);
959                                                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
960
961                                                                                 iptr[0].target = (void *) tbptr;
962
963                                                                                 MARKREACHED(tbptr, copy);
964                                                                                 COUNT(count_pcmd_bra);
965                                                                                 COUNT(count_pcmd_op);
966                                                                                 break;
967                                                                         case ICMD_IFNE:
968                                                                                 iptr[0].opc = ICMD_IF_LNE;
969 #if defined(__I386__)
970                                                                                 method_uses_ecx = true;
971 #endif
972                                                                                 goto icmd_lconst_lcmp_tail;
973                                                                         case ICMD_IFLT:
974                                                                                 iptr[0].opc = ICMD_IF_LLT;
975                                                                                 goto icmd_lconst_lcmp_tail;
976                                                                         case ICMD_IFGT:
977                                                                                 iptr[0].opc = ICMD_IF_LGT;
978                                                                                 goto icmd_lconst_lcmp_tail;
979                                                                         case ICMD_IFLE:
980                                                                                 iptr[0].opc = ICMD_IF_LLE;
981                                                                                 goto icmd_lconst_lcmp_tail;
982                                                                         case ICMD_IFGE:
983                                                                                 iptr[0].opc = ICMD_IF_LGE;
984                                                                                 goto icmd_lconst_lcmp_tail;
985                                                                         default:
986                                                                                 PUSHCONST(TYPE_LNG);
987                                                                         } /* switch (iptr[2].opc) */
988                                                                 } /* if (iptr[2].val.i == 0) */
989                                                                 else
990                                                                         PUSHCONST(TYPE_LNG);
991                                                                 break;
992 #endif
993
994 #if SUPPORT_CONST_ASTORE
995                                                         case ICMD_LASTORE:
996 #if SUPPORT_ONLY_ZERO_ASTORE
997                                                                 if (iptr[0].val.l == 0) {
998 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
999                                                                         iptr[0].opc = ICMD_LASTORECONST;
1000                                                                         iptr[1].opc = ICMD_NOP;
1001                                                                         OPTT2_0(TYPE_INT, TYPE_ADR);
1002                                                                         COUNT(count_pcmd_op);
1003 #if SUPPORT_ONLY_ZERO_ASTORE
1004                                                                 } else
1005                                                                         PUSHCONST(TYPE_LNG);
1006 #endif /* SUPPORT_ONLY_ZERO_ASTORE */
1007                                                                 break;
1008 #endif /* SUPPORT_CONST_ASTORE */
1009
1010                                                         default:
1011                                                                 PUSHCONST(TYPE_LNG);
1012                                                         }
1013                                                 }
1014                                                 else
1015                                                         PUSHCONST(TYPE_LNG);
1016                                                 break;
1017
1018                                         case ICMD_FCONST:
1019                                                 COUNT(count_pcmd_load);
1020                                                 PUSHCONST(TYPE_FLT);
1021                                                 break;
1022
1023                                         case ICMD_DCONST:
1024                                                 COUNT(count_pcmd_load);
1025                                                 PUSHCONST(TYPE_DBL);
1026                                                 break;
1027
1028                                         case ICMD_ACONST:
1029                                                 COUNT(count_pcmd_load);
1030 #if SUPPORT_CONST_ASTORE
1031                                                 if (len > 0 && iptr->val.a == 0) {
1032                                                         if (iptr[1].opc == ICMD_BUILTIN3 &&
1033                                                                 iptr[1].val.a == BUILTIN_aastore) {
1034                                                                 iptr[0].opc = ICMD_AASTORECONST;
1035                                                                 iptr[1].opc = ICMD_NOP;
1036                                                                 OPTT2_0(TYPE_INT, TYPE_ADR);
1037                                                                 COUNT(count_pcmd_op);
1038
1039                                                         } else {
1040                                                                 PUSHCONST(TYPE_ADR);
1041                                                         }
1042
1043                                                 } else
1044 #endif /* SUPPORT_CONST_ASTORE */
1045                                                         PUSHCONST(TYPE_ADR);
1046                                                 break;
1047
1048                                                 /* pop 0 push 1 load */
1049                                                 
1050                                         case ICMD_ILOAD:
1051                                         case ICMD_LLOAD:
1052                                         case ICMD_FLOAD:
1053                                         case ICMD_DLOAD:
1054                                         case ICMD_ALOAD:
1055                                                 COUNT(count_load_instruction);
1056                                                 i = opcode-ICMD_ILOAD;
1057                                                 iptr->op1 = argren[iptr->op1];
1058                                                 m->registerdata->locals[iptr->op1][i].type = i;
1059                                                 LOAD(i, LOCALVAR, iptr->op1);
1060                                                 break;
1061
1062                                                 /* pop 2 push 1 */
1063
1064                                         case ICMD_LALOAD:
1065 #if defined(__I386__)
1066                                                 method_uses_ecx = true;
1067                                                 method_uses_edx = true;
1068 #endif
1069                                         case ICMD_IALOAD:
1070                                         case ICMD_FALOAD:
1071                                         case ICMD_DALOAD:
1072                                         case ICMD_AALOAD:
1073                                                 COUNT(count_check_null);
1074                                                 COUNT(count_check_bound);
1075                                                 COUNT(count_pcmd_mem);
1076                                                 OP2IAT_1(opcode-ICMD_IALOAD);
1077 #if defined(__I386__)
1078                                                 method_uses_ecx = true;
1079 #endif
1080                                                 break;
1081
1082                                         case ICMD_BALOAD:
1083                                         case ICMD_CALOAD:
1084                                         case ICMD_SALOAD:
1085                                                 COUNT(count_check_null);
1086                                                 COUNT(count_check_bound);
1087                                                 COUNT(count_pcmd_mem);
1088                                                 OP2IAT_1(TYPE_INT);
1089 #if defined(__I386__)
1090                                                 method_uses_ecx = true;
1091 #endif
1092                                                 break;
1093
1094                                                 /* pop 0 push 0 iinc */
1095
1096                                         case ICMD_IINC:
1097 #ifdef STATISTICS
1098                                                 i = stackdepth;
1099                                                 if (i >= 10)
1100                                                         count_store_depth[10]++;
1101                                                 else
1102                                                         count_store_depth[i]++;
1103 #endif
1104                                                 copy = curstack;
1105                                                 i = stackdepth - 1;
1106                                                 while (copy) {
1107                                                         if ((copy->varkind == LOCALVAR) &&
1108                                                                 (copy->varnum == iptr->op1)) {
1109                                                                 copy->varkind = TEMPVAR;
1110                                                                 copy->varnum = i;
1111                                                         }
1112                                                         i--;
1113                                                         copy = copy->prev;
1114                                                 }
1115                                                 SETDST;
1116                                                 break;
1117
1118                                                 /* pop 1 push 0 store */
1119
1120                                         case ICMD_ISTORE:
1121                                         case ICMD_LSTORE:
1122                                         case ICMD_FSTORE:
1123                                         case ICMD_DSTORE:
1124                                         case ICMD_ASTORE:
1125                                         icmd_store:
1126                                                 REQUIRE_1;
1127
1128                                         i = opcode - ICMD_ISTORE;
1129                                         m->registerdata->locals[iptr->op1][i].type = i;
1130 #ifdef STATISTICS
1131                                         count_pcmd_store++;
1132                                         i = new - curstack;
1133                                         if (i >= 20)
1134                                                 count_store_length[20]++;
1135                                         else
1136                                                 count_store_length[i]++;
1137                                         i = stackdepth - 1;
1138                                         if (i >= 10)
1139                                                 count_store_depth[10]++;
1140                                         else
1141                                                 count_store_depth[i]++;
1142 #endif
1143                                         copy = curstack->prev;
1144                                         i = stackdepth - 2;
1145                                         while (copy) {
1146                                                 if ((copy->varkind == LOCALVAR) &&
1147                                                         (copy->varnum == iptr->op1)) {
1148                                                         copy->varkind = TEMPVAR;
1149                                                         copy->varnum = i;
1150                                                 }
1151                                                 i--;
1152                                                 copy = copy->prev;
1153                                         }
1154                                         if ((new - curstack) == 1) {
1155                                                 curstack->varkind = LOCALVAR;
1156                                                 curstack->varnum = iptr->op1;
1157                                         };
1158                                         STORE(opcode-ICMD_ISTORE);
1159                                         break;
1160
1161                                         /* pop 3 push 0 */
1162
1163                                         case ICMD_IASTORE:
1164                                         case ICMD_AASTORE:
1165                                         case ICMD_LASTORE:
1166 #if defined(__I386__)
1167                                                 method_uses_ecx = true;
1168                                                 method_uses_edx = true;
1169 #endif
1170                                         case ICMD_FASTORE:
1171                                         case ICMD_DASTORE:
1172                                                 COUNT(count_check_null);
1173                                                 COUNT(count_check_bound);
1174                                                 COUNT(count_pcmd_mem);
1175                                                 OP3TIA_0(opcode-ICMD_IASTORE);
1176                                                 break;
1177
1178                                         case ICMD_BASTORE:
1179                                         case ICMD_CASTORE:
1180                                         case ICMD_SASTORE:
1181                                                 COUNT(count_check_null);
1182                                                 COUNT(count_check_bound);
1183                                                 COUNT(count_pcmd_mem);
1184                                                 OP3TIA_0(TYPE_INT);
1185 #if defined(__I386__)
1186                                                 method_uses_ecx = true;
1187                                                 method_uses_edx = true;
1188 #endif
1189                                                 break;
1190
1191                                                 /* pop 1 push 0 */
1192
1193                                         case ICMD_POP:
1194 #ifdef TYPECHECK_STACK_COMPCAT
1195                                                 if (opt_verify) {
1196                                                         REQUIRE_1;
1197                                                         if (IS_2_WORD_TYPE(curstack->type))
1198                                                                 panic("Illegal instruction: POP on category 2 type");
1199                                                 }
1200 #endif
1201                                                 OP1_0ANY;
1202                                                 break;
1203
1204                                         case ICMD_IRETURN:
1205                                         case ICMD_LRETURN:
1206                                         case ICMD_FRETURN:
1207                                         case ICMD_DRETURN:
1208                                         case ICMD_ARETURN:
1209                                                 COUNT(count_pcmd_return);
1210                                                 OP1_0(opcode-ICMD_IRETURN);
1211                                                 superblockend = true;
1212                                                 break;
1213
1214                                         case ICMD_ATHROW:
1215                                                 COUNT(count_check_null);
1216                                                 OP1_0(TYPE_ADR);
1217                                                 STACKRESET;
1218                                                 SETDST;
1219                                                 superblockend = true;
1220                                                 break;
1221
1222                                         case ICMD_PUTSTATIC:
1223                                                 COUNT(count_pcmd_mem);
1224                                                 OP1_0(iptr->op1);
1225 #if defined(__I386__)
1226                                                 method_uses_ecx = true;
1227 #endif
1228                                                 break;
1229
1230                                                 /* pop 1 push 0 branch */
1231
1232                                         case ICMD_IFNULL:
1233                                         case ICMD_IFNONNULL:
1234                                                 COUNT(count_pcmd_bra);
1235                                                 OP1_0(TYPE_ADR);
1236                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1237
1238                                                 iptr[0].target = (void *) tbptr;
1239
1240                                                 MARKREACHED(tbptr, copy);
1241                                                 break;
1242
1243                                         case ICMD_IFEQ:
1244                                         case ICMD_IFNE:
1245                                         case ICMD_IFLT:
1246                                         case ICMD_IFGE:
1247                                         case ICMD_IFGT:
1248                                         case ICMD_IFLE:
1249                                                 COUNT(count_pcmd_bra);
1250 #ifdef CONDITIONAL_LOADCONST
1251                                                 {
1252                                                         tbptr = m->basicblocks + b_index;
1253                                                         if ((b_count >= 3) &&
1254                                                             ((b_index + 2) == m->basicblockindex[iptr[0].op1]) &&
1255                                                             (tbptr[1].pre_count == 1) &&
1256                                                             (iptr[1].opc == ICMD_ICONST) &&
1257                                                             (iptr[2].opc == ICMD_GOTO)   &&
1258                                                             ((b_index + 3) == m->basicblockindex[iptr[2].op1]) &&
1259                                                             (tbptr[2].pre_count == 1) &&
1260                                                             (iptr[3].opc == ICMD_ICONST)) {
1261                                                                 OP1_1(TYPE_INT, TYPE_INT);
1262                                                                 switch (iptr[0].opc) {
1263                                                                 case ICMD_IFEQ:
1264                                                                         iptr[0].opc = ICMD_IFNE_ICONST;
1265                                                                         break;
1266                                                                 case ICMD_IFNE:
1267                                                                         iptr[0].opc = ICMD_IFEQ_ICONST;
1268                                                                         break;
1269                                                                 case ICMD_IFLT:
1270                                                                         iptr[0].opc = ICMD_IFGE_ICONST;
1271                                                                         break;
1272                                                                 case ICMD_IFGE:
1273                                                                         iptr[0].opc = ICMD_IFLT_ICONST;
1274                                                                         break;
1275                                                                 case ICMD_IFGT:
1276                                                                         iptr[0].opc = ICMD_IFLE_ICONST;
1277                                                                         break;
1278                                                                 case ICMD_IFLE:
1279                                                                         iptr[0].opc = ICMD_IFGT_ICONST;
1280                                                                         break;
1281                                                                 }
1282                                                                 iptr[0].val.i = iptr[1].val.i;
1283                                                                 iptr[1].opc = ICMD_ELSE_ICONST;
1284                                                                 iptr[1].val.i = iptr[3].val.i;
1285                                                                 iptr[2].opc = ICMD_NOP;
1286                                                                 iptr[3].opc = ICMD_NOP;
1287                                                                 tbptr[1].flags = BBDELETED;
1288                                                                 tbptr[2].flags = BBDELETED;
1289                                                                 tbptr[1].icount = 0;
1290                                                                 tbptr[2].icount = 0;
1291                                                                 if (tbptr[3].pre_count == 2) {
1292                                                                         len += tbptr[3].icount + 3;
1293                                                                         bptr->icount += tbptr[3].icount + 3;
1294                                                                         tbptr[3].flags = BBDELETED;
1295                                                                         tbptr[3].icount = 0;
1296                                                                         b_index++;
1297                                                                 }
1298                                                                 else {
1299                                                                         bptr->icount++;
1300                                                                         len ++;
1301                                                                 }
1302                                                                 b_index += 2;
1303                                                                 break;
1304                                                         }
1305                                                 }
1306 #endif
1307                                                 OP1_0(TYPE_INT);
1308                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1309
1310                                                 iptr[0].target = (void *) tbptr;
1311
1312                                                 MARKREACHED(tbptr, copy);
1313                                                 break;
1314
1315                                                 /* pop 0 push 0 branch */
1316
1317                                         case ICMD_GOTO:
1318                                                 COUNT(count_pcmd_bra);
1319                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1320
1321                                                 iptr[0].target = (void *) tbptr;
1322
1323                                                 MARKREACHED(tbptr, copy);
1324                                                 SETDST;
1325                                                 superblockend = true;
1326                                                 break;
1327
1328                                                 /* pop 1 push 0 table branch */
1329
1330                                         case ICMD_TABLESWITCH:
1331                                                 COUNT(count_pcmd_table);
1332                                                 OP1_0(TYPE_INT);
1333                                                 s4ptr = iptr->val.a;
1334                                                 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1335                                                 MARKREACHED(tbptr, copy);
1336                                                 i = *s4ptr++;                          /* low     */
1337                                                 i = *s4ptr++ - i + 1;                  /* high    */
1338
1339                                                 tptr = DMNEW(void*, i+1);
1340                                                 iptr->target = (void *) tptr;
1341
1342                                                 tptr[0] = (void *) tbptr;
1343                                                 tptr++;
1344
1345                                                 while (--i >= 0) {
1346                                                         tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1347
1348                                                         tptr[0] = (void *) tbptr;
1349                                                         tptr++;
1350
1351                                                         MARKREACHED(tbptr, copy);
1352                                                 }
1353                                                 SETDST;
1354                                                 superblockend = true;
1355 #if defined(__I386__)
1356                                                 method_uses_ecx = true;
1357 #endif
1358                                                 break;
1359                                                         
1360                                                 /* pop 1 push 0 table branch */
1361
1362                                         case ICMD_LOOKUPSWITCH:
1363                                                 COUNT(count_pcmd_table);
1364                                                 OP1_0(TYPE_INT);
1365                                                 s4ptr = iptr->val.a;
1366                                                 tbptr = m->basicblocks + m->basicblockindex[*s4ptr++];
1367                                                 MARKREACHED(tbptr, copy);
1368                                                 i = *s4ptr++;                          /* count   */
1369
1370                                                 tptr = DMNEW(void*, i+1);
1371                                                 iptr->target = (void *) tptr;
1372
1373                                                 tptr[0] = (void *) tbptr;
1374                                                 tptr++;
1375
1376                                                 while (--i >= 0) {
1377                                                         tbptr = m->basicblocks + m->basicblockindex[s4ptr[1]];
1378
1379                                                         tptr[0] = (void *) tbptr;
1380                                                         tptr++;
1381                                                                 
1382                                                         MARKREACHED(tbptr, copy);
1383                                                         s4ptr += 2;
1384                                                 }
1385                                                 SETDST;
1386                                                 superblockend = true;
1387                                                 break;
1388
1389                                         case ICMD_NULLCHECKPOP:
1390                                         case ICMD_MONITORENTER:
1391                                                 COUNT(count_check_null);
1392                                         case ICMD_MONITOREXIT:
1393                                                 OP1_0(TYPE_ADR);
1394                                                 break;
1395
1396                                                 /* pop 2 push 0 branch */
1397
1398                                         case ICMD_IF_ICMPEQ:
1399                                         case ICMD_IF_ICMPNE:
1400                                         case ICMD_IF_ICMPLT:
1401                                         case ICMD_IF_ICMPGE:
1402                                         case ICMD_IF_ICMPGT:
1403                                         case ICMD_IF_ICMPLE:
1404                                                 COUNT(count_pcmd_bra);
1405                                                 OP2_0(TYPE_INT);
1406                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1407                                                         
1408                                                 iptr[0].target = (void *) tbptr;
1409
1410                                                 MARKREACHED(tbptr, copy);
1411                                                 break;
1412
1413                                         case ICMD_IF_ACMPEQ:
1414                                         case ICMD_IF_ACMPNE:
1415                                                 COUNT(count_pcmd_bra);
1416                                                 OP2_0(TYPE_ADR);
1417                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1418
1419                                                 iptr[0].target = (void *) tbptr;
1420
1421                                                 MARKREACHED(tbptr, copy);
1422                                                 break;
1423
1424                                                 /* pop 2 push 0 */
1425
1426                                         case ICMD_PUTFIELD:
1427                                                 COUNT(count_check_null);
1428                                                 COUNT(count_pcmd_mem);
1429                                                 OPTT2_0(iptr->op1,TYPE_ADR);
1430 #if defined(__I386__)
1431                                                 method_uses_ecx = true;
1432 #endif
1433                                                 break;
1434
1435                                         case ICMD_POP2:
1436                                                 REQUIRE_1;
1437                                                 if (! IS_2_WORD_TYPE(curstack->type)) {
1438                                                         /* ..., cat1 */
1439 #ifdef TYPECHECK_STACK_COMPCAT
1440                                                         if (opt_verify) {
1441                                                                 REQUIRE_2;
1442                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
1443                                                                         panic("Illegal instruction: POP2 on cat2, cat1 types");
1444                                                         }
1445 #endif
1446                                                         OP1_0ANY;                /* second pop */
1447                                                 }
1448                                                 else
1449                                                         iptr->opc = ICMD_POP;
1450                                                 OP1_0ANY;
1451                                                 break;
1452
1453                                                 /* pop 0 push 1 dup */
1454                                                 
1455                                         case ICMD_DUP:
1456 #ifdef TYPECHECK_STACK_COMPCAT
1457                                                 if (opt_verify) {
1458                                                         REQUIRE_1;
1459                                                         if (IS_2_WORD_TYPE(curstack->type))
1460                                                                 panic("Illegal instruction: DUP on category 2 type");
1461                                                 }
1462 #endif
1463                                                 COUNT(count_dup_instruction);
1464                                                 DUP;
1465                                                 break;
1466
1467                                         case ICMD_DUP2:
1468                                                 REQUIRE_1;
1469                                                 if (IS_2_WORD_TYPE(curstack->type)) {
1470                                                         /* ..., cat2 */
1471                                                         iptr->opc = ICMD_DUP;
1472                                                         DUP;
1473                                                 }
1474                                                 else {
1475                                                         REQUIRE_2;
1476                                                         /* ..., ????, cat1 */
1477 #ifdef TYPECHECK_STACK_COMPCAT
1478                                                         if (opt_verify) {
1479                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
1480                                                                         panic("Illegal instruction: DUP2 on cat2, cat1 types");
1481                                                         }
1482 #endif
1483                                                         copy = curstack;
1484                                                         NEWSTACK(copy->prev->type, copy->prev->varkind,
1485                                                                          copy->prev->varnum);
1486                                                         NEWSTACK(copy->type, copy->varkind,
1487                                                                          copy->varnum);
1488                                                         SETDST;
1489                                                         stackdepth+=2;
1490                                                 }
1491                                                 break;
1492
1493                                                 /* pop 2 push 3 dup */
1494                                                 
1495                                         case ICMD_DUP_X1:
1496 #ifdef TYPECHECK_STACK_COMPCAT
1497                                                 if (opt_verify) {
1498                                                         REQUIRE_2;
1499                                                         if (IS_2_WORD_TYPE(curstack->type) ||
1500                                                                 IS_2_WORD_TYPE(curstack->prev->type))
1501                                                                 panic("Illegal instruction: DUP_X1 on cat 2 type");
1502                                                 }
1503 #endif
1504                                                 DUP_X1;
1505                                                 break;
1506
1507                                         case ICMD_DUP2_X1:
1508                                                 REQUIRE_2;
1509                                                 if (IS_2_WORD_TYPE(curstack->type)) {
1510                                                         /* ..., ????, cat2 */
1511 #ifdef TYPECHECK_STACK_COMPCAT
1512                                                         if (opt_verify) {
1513                                                                 if (IS_2_WORD_TYPE(curstack->prev->type))
1514                                                                         panic("Illegal instruction: DUP2_X1 on cat2, cat2 types");
1515                                                         }
1516 #endif
1517                                                         iptr->opc = ICMD_DUP_X1;
1518                                                         DUP_X1;
1519                                                 }
1520                                                 else {
1521                                                         /* ..., ????, cat1 */
1522 #ifdef TYPECHECK_STACK_COMPCAT
1523                                                         if (opt_verify) {
1524                                                                 REQUIRE_3;
1525                                                                 if (IS_2_WORD_TYPE(curstack->prev->type)
1526                                                                         || IS_2_WORD_TYPE(curstack->prev->prev->type))
1527                                                                         panic("Illegal instruction: DUP2_X1 on invalid types");
1528                                                         }
1529 #endif
1530                                                         DUP2_X1;
1531                                                 }
1532                                                 break;
1533
1534                                                 /* pop 3 push 4 dup */
1535                                                 
1536                                         case ICMD_DUP_X2:
1537                                                 REQUIRE_2;
1538                                                 if (IS_2_WORD_TYPE(curstack->prev->type)) {
1539                                                         /* ..., cat2, ???? */
1540 #ifdef TYPECHECK_STACK_COMPCAT
1541                                                         if (opt_verify) {
1542                                                                 if (IS_2_WORD_TYPE(curstack->type))
1543                                                                         panic("Illegal instruction: DUP_X2 on cat2, cat2 types");
1544                                                         }
1545 #endif
1546                                                         iptr->opc = ICMD_DUP_X1;
1547                                                         DUP_X1;
1548                                                 }
1549                                                 else {
1550                                                         /* ..., cat1, ???? */
1551 #ifdef TYPECHECK_STACK_COMPCAT
1552                                                         if (opt_verify) {
1553                                                                 REQUIRE_3;
1554                                                                 if (IS_2_WORD_TYPE(curstack->type)
1555                                                                         || IS_2_WORD_TYPE(curstack->prev->prev->type))
1556                                                                         panic("Illegal instruction: DUP_X2 on invalid types");
1557                                                         }
1558 #endif
1559                                                         DUP_X2;
1560                                                 }
1561                                                 break;
1562
1563                                         case ICMD_DUP2_X2:
1564                                                 REQUIRE_2;
1565                                                 if (IS_2_WORD_TYPE(curstack->type)) {
1566                                                         /* ..., ????, cat2 */
1567                                                         if (IS_2_WORD_TYPE(curstack->prev->type)) {
1568                                                                 /* ..., cat2, cat2 */
1569                                                                 iptr->opc = ICMD_DUP_X1;
1570                                                                 DUP_X1;
1571                                                         }
1572                                                         else {
1573                                                                 /* ..., cat1, cat2 */
1574 #ifdef TYPECHECK_STACK_COMPCAT
1575                                                                 if (opt_verify) {
1576                                                                         REQUIRE_3;
1577                                                                         if (IS_2_WORD_TYPE(curstack->prev->prev->type))
1578                                                                                 panic("Illegal instruction: DUP2_X2 on invalid types");
1579                                                                 }
1580 #endif
1581                                                                 iptr->opc = ICMD_DUP_X2;
1582                                                                 DUP_X2;
1583                                                         }
1584                                                 }
1585                                                 else {
1586                                                         REQUIRE_3;
1587                                                         /* ..., ????, ????, cat1 */
1588                                                         if (IS_2_WORD_TYPE(curstack->prev->prev->type)) {
1589                                                                 /* ..., cat2, ????, cat1 */
1590 #ifdef TYPECHECK_STACK_COMPCAT
1591                                                                 if (opt_verify) {
1592                                                                         if (IS_2_WORD_TYPE(curstack->prev->type))
1593                                                                                 panic("Illegal instruction: DUP2_X2 on invalid types");
1594                                                                 }
1595 #endif
1596                                                                 iptr->opc = ICMD_DUP2_X1;
1597                                                                 DUP2_X1;
1598                                                         }
1599                                                         else {
1600                                                                 /* ..., cat1, ????, cat1 */
1601 #ifdef TYPECHECK_STACK_COMPCAT
1602                                                                 if (opt_verify) {
1603                                                                         REQUIRE_4;
1604                                                                         if (IS_2_WORD_TYPE(curstack->prev->type)
1605                                                                                 || IS_2_WORD_TYPE(curstack->prev->prev->prev->type))
1606                                                                                 panic("Illegal instruction: DUP2_X2 on invalid types");
1607                                                                 }
1608 #endif
1609                                                                 DUP2_X2;
1610                                                         }
1611                                                 }
1612                                                 break;
1613
1614                                                 /* pop 2 push 2 swap */
1615                                                 
1616                                         case ICMD_SWAP:
1617 #ifdef TYPECHECK_STACK_COMPCAT
1618                                                 if (opt_verify) {
1619                                                         REQUIRE_2;
1620                                                         if (IS_2_WORD_TYPE(curstack->type)
1621                                                                 || IS_2_WORD_TYPE(curstack->prev->type))
1622                                                                 panic("Illegal instruction: SWAP on category 2 type");
1623                                                 }
1624 #endif
1625                                                 SWAP;
1626                                                 break;
1627
1628                                                 /* pop 2 push 1 */
1629                                                 
1630                                         case ICMD_IDIV:
1631 #if !SUPPORT_DIVISION
1632                                                 iptr[0].opc = ICMD_BUILTIN2;
1633                                                 iptr[0].op1 = TYPE_INT;
1634                                                 iptr[0].val.a = BUILTIN_idiv;
1635                                                 m->isleafmethod = false;
1636                                                 goto builtin2;
1637 #endif
1638
1639                                         case ICMD_IREM:
1640 #if !SUPPORT_DIVISION
1641                                                 iptr[0].opc = ICMD_BUILTIN2;
1642                                                 iptr[0].op1 = TYPE_INT;
1643                                                 iptr[0].val.a = BUILTIN_irem;
1644                                                 m->isleafmethod = false;
1645                                                 goto builtin2;
1646 #endif
1647 #if defined(__I386__)
1648                                                 method_uses_ecx = true;
1649                                                 method_uses_edx = true;
1650 #endif
1651
1652                                         case ICMD_ISHL:
1653                                         case ICMD_ISHR:
1654                                         case ICMD_IUSHR:
1655 #if defined(__I386__)
1656                                                 method_uses_ecx = true;
1657 #endif
1658                                         case ICMD_IADD:
1659                                         case ICMD_ISUB:
1660                                         case ICMD_IMUL:
1661                                         case ICMD_IAND:
1662                                         case ICMD_IOR:
1663                                         case ICMD_IXOR:
1664                                                 COUNT(count_pcmd_op);
1665                                                 OP2_1(TYPE_INT);
1666                                                 break;
1667
1668                                         case ICMD_LDIV:
1669 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1670                                                 iptr[0].opc = ICMD_BUILTIN2;
1671                                                 iptr[0].op1 = TYPE_LNG;
1672                                                 iptr[0].val.a = BUILTIN_ldiv;
1673                                                 m->isleafmethod = false;
1674                                                 goto builtin2;
1675 #endif
1676
1677                                         case ICMD_LREM:
1678 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1679                                                 iptr[0].opc = ICMD_BUILTIN2;
1680                                                 iptr[0].op1 = TYPE_LNG;
1681                                                 iptr[0].val.a = BUILTIN_lrem;
1682                                                 m->isleafmethod = false;
1683                                                 goto builtin2;
1684 #endif
1685
1686                                         case ICMD_LMUL:
1687 #if defined(__I386__)
1688                                                 method_uses_ecx = true;
1689                                                 method_uses_edx = true;
1690 #endif
1691                                         case ICMD_LADD:
1692                                         case ICMD_LSUB:
1693                                         case ICMD_LOR:
1694                                         case ICMD_LAND:
1695                                         case ICMD_LXOR:
1696                                                 /* DEBUG */ /*dolog("OP2_1(TYPE_LNG)"); */
1697                                                 COUNT(count_pcmd_op);
1698                                                 OP2_1(TYPE_LNG);
1699                                                 break;
1700
1701                                         case ICMD_LSHL:
1702                                         case ICMD_LSHR:
1703                                         case ICMD_LUSHR:
1704                                                 COUNT(count_pcmd_op);
1705                                                 OP2IT_1(TYPE_LNG);
1706 #if defined(__I386__)
1707                                                 method_uses_ecx = true;
1708                                                 method_uses_edx = true;
1709 #endif
1710                                                 break;
1711
1712                                         case ICMD_FADD:
1713                                         case ICMD_FSUB:
1714                                         case ICMD_FMUL:
1715                                         case ICMD_FDIV:
1716                                         case ICMD_FREM:
1717                                                 COUNT(count_pcmd_op);
1718                                                 OP2_1(TYPE_FLT);
1719                                                 break;
1720
1721                                         case ICMD_DADD:
1722                                         case ICMD_DSUB:
1723                                         case ICMD_DMUL:
1724                                         case ICMD_DDIV:
1725                                         case ICMD_DREM:
1726                                                 COUNT(count_pcmd_op);
1727                                                 OP2_1(TYPE_DBL);
1728                                                 break;
1729
1730                                         case ICMD_LCMP:
1731                                                 COUNT(count_pcmd_op);
1732 #if !defined(NOLONG_CONDITIONAL)
1733                                                 if ((len > 0) && (iptr[1].val.i == 0)) {
1734                                                         switch (iptr[1].opc) {
1735                                                         case ICMD_IFEQ:
1736                                                                 iptr[0].opc = ICMD_IF_LCMPEQ;
1737 #if defined(__I386__)
1738                                                                 method_uses_ecx = true;
1739 #endif
1740                                                         icmd_lcmp_if_tail:
1741                                                                 iptr[0].op1 = iptr[1].op1;
1742                                                                 len--;
1743                                                                 bptr->icount--;
1744                                                                 /* iptr[1].opc = ICMD_NOP; */
1745                                                                 OP2_0(TYPE_LNG);
1746                                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1747                         
1748                                                                 iptr[0].target = (void *) tbptr;
1749
1750                                                                 MARKREACHED(tbptr, copy);
1751                                                                 COUNT(count_pcmd_bra);
1752                                                                 break;
1753                                                         case ICMD_IFNE:
1754                                                                 iptr[0].opc = ICMD_IF_LCMPNE;
1755 #if defined(__I386__)
1756                                                                 method_uses_ecx = true;
1757 #endif
1758                                                                 goto icmd_lcmp_if_tail;
1759                                                         case ICMD_IFLT:
1760                                                                 iptr[0].opc = ICMD_IF_LCMPLT;
1761                                                                 goto icmd_lcmp_if_tail;
1762                                                         case ICMD_IFGT:
1763                                                                 iptr[0].opc = ICMD_IF_LCMPGT;
1764                                                                 goto icmd_lcmp_if_tail;
1765                                                         case ICMD_IFLE:
1766                                                                 iptr[0].opc = ICMD_IF_LCMPLE;
1767                                                                 goto icmd_lcmp_if_tail;
1768                                                         case ICMD_IFGE:
1769                                                                 iptr[0].opc = ICMD_IF_LCMPGE;
1770                                                                 goto icmd_lcmp_if_tail;
1771                                                         default:
1772                                                                 OPTT2_1(TYPE_LNG, TYPE_INT);
1773                                                         }
1774                                                 }
1775                                                 else
1776 #endif
1777                                                         OPTT2_1(TYPE_LNG, TYPE_INT);
1778                                                 break;
1779                                         case ICMD_FCMPL:
1780                                         case ICMD_FCMPG:
1781                                                 COUNT(count_pcmd_op);
1782                                                 OPTT2_1(TYPE_FLT, TYPE_INT);
1783                                                 break;
1784                                         case ICMD_DCMPL:
1785                                         case ICMD_DCMPG:
1786                                                 COUNT(count_pcmd_op);
1787                                                 OPTT2_1(TYPE_DBL, TYPE_INT);
1788                                                 break;
1789
1790                                                 /* pop 1 push 1 */
1791                                                 
1792                                         case ICMD_INEG:
1793                                         case ICMD_INT2BYTE:
1794                                         case ICMD_INT2CHAR:
1795                                         case ICMD_INT2SHORT:
1796                                                 COUNT(count_pcmd_op);
1797                                                 OP1_1(TYPE_INT, TYPE_INT);
1798                                                 break;
1799                                         case ICMD_LNEG:
1800                                                 COUNT(count_pcmd_op);
1801                                                 OP1_1(TYPE_LNG, TYPE_LNG);
1802                                                 break;
1803                                         case ICMD_FNEG:
1804                                                 COUNT(count_pcmd_op);
1805                                                 OP1_1(TYPE_FLT, TYPE_FLT);
1806                                                 break;
1807                                         case ICMD_DNEG:
1808                                                 COUNT(count_pcmd_op);
1809                                                 OP1_1(TYPE_DBL, TYPE_DBL);
1810                                                 break;
1811
1812                                         case ICMD_I2L:
1813                                                 COUNT(count_pcmd_op);
1814                                                 OP1_1(TYPE_INT, TYPE_LNG);
1815 #if defined(__I386__)
1816                                                 method_uses_edx = true;
1817 #endif
1818                                                 break;
1819                                         case ICMD_I2F:
1820                                                 COUNT(count_pcmd_op);
1821                                                 OP1_1(TYPE_INT, TYPE_FLT);
1822                                                 break;
1823                                         case ICMD_I2D:
1824                                                 COUNT(count_pcmd_op);
1825                                                 OP1_1(TYPE_INT, TYPE_DBL);
1826                                                 break;
1827                                         case ICMD_L2I:
1828                                                 COUNT(count_pcmd_op);
1829                                                 OP1_1(TYPE_LNG, TYPE_INT);
1830                                                 break;
1831                                         case ICMD_L2F:
1832                                                 COUNT(count_pcmd_op);
1833                                                 OP1_1(TYPE_LNG, TYPE_FLT);
1834                                                 break;
1835                                         case ICMD_L2D:
1836                                                 COUNT(count_pcmd_op);
1837                                                 OP1_1(TYPE_LNG, TYPE_DBL);
1838                                                 break;
1839                                         case ICMD_F2I:
1840                                                 COUNT(count_pcmd_op);
1841                                                 OP1_1(TYPE_FLT, TYPE_INT);
1842                                                 break;
1843                                         case ICMD_F2L:
1844                                                 COUNT(count_pcmd_op);
1845                                                 OP1_1(TYPE_FLT, TYPE_LNG);
1846 #if defined(__I386__)
1847                                                 method_uses_edx = true;
1848 #endif
1849                                                 break;
1850                                         case ICMD_F2D:
1851                                                 COUNT(count_pcmd_op);
1852                                                 OP1_1(TYPE_FLT, TYPE_DBL);
1853                                                 break;
1854                                         case ICMD_D2I:
1855                                                 COUNT(count_pcmd_op);
1856                                                 OP1_1(TYPE_DBL, TYPE_INT);
1857                                                 break;
1858                                         case ICMD_D2L:
1859                                                 COUNT(count_pcmd_op);
1860                                                 OP1_1(TYPE_DBL, TYPE_LNG);
1861 #if defined(__I386__)
1862                                                 method_uses_edx = true;
1863 #endif
1864                                                 break;
1865                                         case ICMD_D2F:
1866                                                 COUNT(count_pcmd_op);
1867                                                 OP1_1(TYPE_DBL, TYPE_FLT);
1868                                                 break;
1869
1870                                         case ICMD_CHECKCAST:
1871                                                 OP1_1(TYPE_ADR, TYPE_ADR);
1872 #if defined(__I386__)
1873                                                 method_uses_ecx = true;
1874                                                 method_uses_edx = true;
1875 #endif
1876                                                 break;
1877
1878                                         case ICMD_INSTANCEOF:
1879 #if defined(__I386__)
1880                                                 method_uses_ecx = true;
1881                                                 method_uses_edx = true;
1882 #endif
1883                                         case ICMD_ARRAYLENGTH:
1884                                                 OP1_1(TYPE_ADR, TYPE_INT);
1885                                                 break;
1886
1887                                         case ICMD_NEWARRAY:
1888                                         case ICMD_ANEWARRAY:
1889                                                 OP1_1(TYPE_INT, TYPE_ADR);
1890                                                 break;
1891
1892                                         case ICMD_GETFIELD:
1893                                                 COUNT(count_check_null);
1894                                                 COUNT(count_pcmd_mem);
1895                                                 OP1_1(TYPE_ADR, iptr->op1);
1896 #if defined(__I386__)
1897                                                 method_uses_ecx = true;
1898 #endif
1899                                                 break;
1900
1901                                                 /* pop 0 push 1 */
1902                                                 
1903                                         case ICMD_GETSTATIC:
1904                                                 COUNT(count_pcmd_mem);
1905                                                 OP0_1(iptr->op1);
1906 #if defined(__I386__)
1907                                                 method_uses_ecx = true;
1908 #endif
1909                                                 break;
1910
1911                                         case ICMD_NEW:
1912                                                 OP0_1(TYPE_ADR);
1913                                                 break;
1914
1915                                         case ICMD_JSR:
1916                                                 OP0_1(TYPE_ADR);
1917                                                 tbptr = m->basicblocks + m->basicblockindex[iptr->op1];
1918
1919                                                 iptr[0].target = (void *) tbptr;
1920
1921                                                 /* This is a dirty hack. The typechecker
1922                                                  * needs it because the OP1_0ANY below
1923                                                  * overwrites iptr->dst.
1924                                                  */
1925                                                 iptr->val.a = (void *) iptr->dst;
1926
1927                                                 tbptr->type = BBTYPE_SBR;
1928
1929                                                 /* We need to check for overflow right here because
1930                                                  * the pushed value is poped after MARKREACHED. */
1931                                                 CHECKOVERFLOW;
1932                                                 MARKREACHED(tbptr, copy);
1933                                                 OP1_0ANY;
1934                                                 break;
1935
1936                                                 /* pop many push any */
1937                                                 
1938                                         case ICMD_INVOKEVIRTUAL:
1939                                         case ICMD_INVOKESPECIAL:
1940                                         case ICMD_INVOKEINTERFACE:
1941                                         case ICMD_INVOKESTATIC:
1942                                                 COUNT(count_pcmd_met);
1943 #if defined(__I386__)
1944                                                 method_uses_ecx = true;
1945 #endif
1946                                                 {
1947                                                         methodinfo *lm = iptr->val.a;
1948                                                         if (lm->flags & ACC_STATIC)
1949                                                                 {COUNT(count_check_null);}
1950                                                         i = iptr->op1;
1951                                                         if (i > m->registerdata->arguments_num)
1952                                                                 m->registerdata->arguments_num = i;
1953                                                         REQUIRE(i);
1954 #if defined(__X86_64__)
1955                                                         {
1956                                                                 s4 iarg = 0;
1957                                                                 s4 farg = 0;
1958                                                                 s4 stackargs = 0;
1959
1960                                                                 copy = curstack;
1961                                                                 while (--i >= 0) {
1962                                                                         (IS_FLT_DBL_TYPE(copy->type)) ? farg++ : iarg++;
1963                                                                         copy = copy->prev;
1964                                                                 }
1965
1966                                                                 stackargs += (iarg < m->registerdata->intreg_argnum) ?
1967                                                                         0 : (iarg - m->registerdata->intreg_argnum);
1968                                                                 stackargs += (farg < m->registerdata->fltreg_argnum) ?
1969                                                                         0 : (farg - m->registerdata->fltreg_argnum);
1970
1971                                                                 i = iptr->op1;
1972                                                                 copy = curstack;
1973                                                                 while (--i >= 0) {
1974                                                                         if (!(copy->flags & SAVEDVAR)) {
1975                                                                                 copy->varkind = ARGVAR;
1976                                                                                 if (IS_FLT_DBL_TYPE(copy->type)) {
1977                                                                                         if (--farg < m->registerdata->fltreg_argnum) {
1978                                                                                                 copy->varnum = farg;
1979                                                                                         } else {
1980                                                                                                 copy->varnum = --stackargs + m->registerdata->intreg_argnum;
1981                                                                                         }
1982                                                                                 } else {
1983                                                                                         if (--iarg < m->registerdata->intreg_argnum) {
1984                                                                                                 copy->varnum = iarg;
1985                                                                                         } else {
1986                                                                                                 copy->varnum = --stackargs + m->registerdata->intreg_argnum;
1987                                                                                         }
1988                                                                                 }
1989                                                                         } else {
1990                                                                                 (IS_FLT_DBL_TYPE(copy->type)) ? --farg : --iarg;
1991                                                                         }
1992                                                                         copy = copy->prev;
1993                                                                 }
1994                                                         }
1995 #else
1996                                                         copy = curstack;
1997                                                         while (--i >= 0) {
1998                                                                 if (! (copy->flags & SAVEDVAR)) {
1999                                                                         copy->varkind = ARGVAR;
2000                                                                         copy->varnum = i;
2001                                                                 }
2002                                                                 copy = copy->prev;
2003                                                         }
2004 #endif
2005                                                         while (copy) {
2006                                                                 copy->flags |= SAVEDVAR;
2007                                                                 copy = copy->prev;
2008                                                         }
2009                                                         i = iptr->op1;
2010                                                         POPMANY(i);
2011                                                         if (lm->returntype != TYPE_VOID) {
2012                                                                 OP0_1(lm->returntype);
2013                                                         }
2014                                                         break;
2015                                                 }
2016
2017                                         case ICMD_BUILTIN3:
2018                                                 /* DEBUG */ /*dolog("builtin3");*/
2019                                                 REQUIRE_3;
2020                                                 if (! (curstack->flags & SAVEDVAR)) {
2021                                                         curstack->varkind = ARGVAR;
2022                                                         curstack->varnum = 2;
2023                                                 }
2024                                                 if (3 > m->registerdata->arguments_num) {
2025                                                         m->registerdata->arguments_num = 3;
2026                                                 }
2027                                                 OP1_0ANY;
2028
2029                                         case ICMD_BUILTIN2:
2030                                         builtin2:
2031                                                 REQUIRE_2;
2032                                                 /* DEBUG */ /*dolog("builtin2");*/
2033                                         if (!(curstack->flags & SAVEDVAR)) {
2034                                                 curstack->varkind = ARGVAR;
2035                                                 curstack->varnum = 1;
2036                                         }
2037                                         if (2 > m->registerdata->arguments_num) {
2038                                                 m->registerdata->arguments_num = 2;
2039                                         }
2040                                         OP1_0ANY;
2041
2042                                         case ICMD_BUILTIN1:
2043                                         builtin1:
2044                                                 REQUIRE_1;
2045                                                 /* DEBUG */ /*dolog("builtin1");*/
2046                                         if (!(curstack->flags & SAVEDVAR)) {
2047                                                 curstack->varkind = ARGVAR;
2048                                                 curstack->varnum = 0;
2049                                         }
2050                                         if (1 > m->registerdata->arguments_num) {
2051                                                 m->registerdata->arguments_num = 1;
2052                                         }
2053                                         OP1_0ANY;
2054                                         copy = curstack;
2055                                         while (copy) {
2056                                                 copy->flags |= SAVEDVAR;
2057                                                 copy = copy->prev;
2058                                         }
2059                                         if (iptr->op1 != TYPE_VOID)
2060                                                 OP0_1(iptr->op1);
2061                                         break;
2062
2063                                         case ICMD_MULTIANEWARRAY:
2064                                                 i = iptr->op1;
2065                                                 REQUIRE(i);
2066                                                 if ((i + m->registerdata->intreg_argnum) > m->registerdata->arguments_num)
2067                                                         m->registerdata->arguments_num = i + m->registerdata->intreg_argnum;
2068                                                 copy = curstack;
2069                                                 while (--i >= 0) {
2070                                                         /* check INT type here? Currently typecheck does this. */
2071                                                         if (! (copy->flags & SAVEDVAR)) {
2072                                                                 copy->varkind = ARGVAR;
2073                                                                 copy->varnum = i + m->registerdata->intreg_argnum;
2074                                                         }
2075                                                         copy = copy->prev;
2076                                                 }
2077                                                 while (copy) {
2078                                                         copy->flags |= SAVEDVAR;
2079                                                         copy = copy->prev;
2080                                                 }
2081                                                 i = iptr->op1;
2082                                                 POPMANY(i);
2083                                                 OP0_1(TYPE_ADR);
2084                                                 break;
2085
2086                                         case ICMD_CLEAR_ARGREN:
2087                                                 for (i = iptr->op1; i<m->maxlocals; i++) 
2088                                                         argren[i] = i;
2089                                                 iptr->opc = opcode = ICMD_NOP;
2090                                                 SETDST;
2091                                                 break;
2092                                                 
2093                                         case ICMD_READONLY_ARG:
2094                                         case ICMD_READONLY_ARG+1:
2095                                         case ICMD_READONLY_ARG+2:
2096                                         case ICMD_READONLY_ARG+3:
2097                                         case ICMD_READONLY_ARG+4:
2098
2099                                                 REQUIRE_1;
2100                                                 if (curstack->varkind == LOCALVAR) {
2101                                                         i = curstack->varnum;
2102                                                         argren[iptr->op1] = i;
2103                                                         iptr->op1 = i;
2104                                                 }
2105                                                 opcode = iptr->opc = opcode - ICMD_READONLY_ARG + ICMD_ISTORE;
2106                                                 goto icmd_store;
2107
2108                                                 break;
2109
2110                                         default:
2111                                                 printf("ICMD %d at %d\n", iptr->opc, (s4) (iptr - m->instructions));
2112                                                 panic("Missing ICMD code during stack analysis");
2113                                         } /* switch */
2114
2115                                         CHECKOVERFLOW;
2116                                         
2117                                         /* DEBUG */ /*dolog("iptr++");*/
2118                                         iptr++;
2119                                 } /* while instructions */
2120                                 bptr->outstack = curstack;
2121                                 bptr->outdepth = stackdepth;
2122                                 BBEND(curstack, i);
2123                         } /* if */
2124                         else
2125                                 superblockend = true;
2126                         bptr++;
2127                 } /* while blocks */
2128         } while (repeat && !deadcode);
2129
2130 #ifdef STATISTICS
2131         if (m->basicblockcount > count_max_basic_blocks)
2132                 count_max_basic_blocks = m->basicblockcount;
2133         count_basic_blocks += m->basicblockcount;
2134         if (m->instructioncount > count_max_javainstr)
2135                 count_max_javainstr = m->instructioncount;
2136         count_javainstr += m->instructioncount;
2137         if (m->stackcount > count_upper_bound_new_stack)
2138                 count_upper_bound_new_stack = m->stackcount;
2139         if ((new - m->stack) > count_max_new_stack)
2140                 count_max_new_stack = (new - m->stack);
2141
2142         b_count = m->basicblockcount;
2143         bptr = m->basicblocks;
2144         while (--b_count >= 0) {
2145                 if (bptr->flags > BBREACHED) {
2146                         if (bptr->indepth >= 10)
2147                                 count_block_stack[10]++;
2148                         else
2149                                 count_block_stack[bptr->indepth]++;
2150                         len = bptr->icount;
2151                         if (len < 10) 
2152                                 count_block_size_distribution[len]++;
2153                         else if (len <= 12)
2154                                 count_block_size_distribution[10]++;
2155                         else if (len <= 14)
2156                                 count_block_size_distribution[11]++;
2157                         else if (len <= 16)
2158                                 count_block_size_distribution[12]++;
2159                         else if (len <= 18)
2160                                 count_block_size_distribution[13]++;
2161                         else if (len <= 20)
2162                                 count_block_size_distribution[14]++;
2163                         else if (len <= 25)
2164                                 count_block_size_distribution[15]++;
2165                         else if (len <= 30)
2166                                 count_block_size_distribution[16]++;
2167                         else
2168                                 count_block_size_distribution[17]++;
2169                 }
2170                 bptr++;
2171         }
2172
2173         if (loops == 1)
2174                 count_analyse_iterations[0]++;
2175         else if (loops == 2)
2176                 count_analyse_iterations[1]++;
2177         else if (loops == 3)
2178                 count_analyse_iterations[2]++;
2179         else if (loops == 4)
2180                 count_analyse_iterations[3]++;
2181         else
2182                 count_analyse_iterations[4]++;
2183
2184         if (m->basicblockcount <= 5)
2185                 count_method_bb_distribution[0]++;
2186         else if (m->basicblockcount <= 10)
2187                 count_method_bb_distribution[1]++;
2188         else if (m->basicblockcount <= 15)
2189                 count_method_bb_distribution[2]++;
2190         else if (m->basicblockcount <= 20)
2191                 count_method_bb_distribution[3]++;
2192         else if (m->basicblockcount <= 30)
2193                 count_method_bb_distribution[4]++;
2194         else if (m->basicblockcount <= 40)
2195                 count_method_bb_distribution[5]++;
2196         else if (m->basicblockcount <= 50)
2197                 count_method_bb_distribution[6]++;
2198         else if (m->basicblockcount <= 75)
2199                 count_method_bb_distribution[7]++;
2200         else
2201                 count_method_bb_distribution[8]++;
2202 #endif
2203
2204         /* just return methodinfo* to signal everything was ok */
2205
2206         return m;
2207 }
2208
2209
2210 /**********************************************************************/
2211 /* DEBUGGING HELPERS                                                  */
2212 /**********************************************************************/
2213
2214 void icmd_print_stack(methodinfo *m, stackptr s)
2215 {
2216         int i, j;
2217         stackptr t;
2218
2219         i = m->maxstack;
2220         t = s;
2221         
2222         while (t) {
2223                 i--;
2224                 t = t->prev;
2225         }
2226         j = m->maxstack - i;
2227         while (--i >= 0)
2228                 printf("    ");
2229         while (s) {
2230                 j--;
2231                 /* DEBUG */ /*printf("(%d,%d,%d,%d)",s->varkind,s->flags,s->regoff,s->varnum); fflush(stdout);*/
2232                 if (s->flags & SAVEDVAR)
2233                         switch (s->varkind) {
2234                         case TEMPVAR:
2235                                 if (s->flags & INMEMORY)
2236                                         printf(" M%02d", s->regoff);
2237                                 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2238                                         printf(" F%02d", s->regoff);
2239                                 else {
2240                                         printf(" %3s", regs[s->regoff]);
2241                                 }
2242                                 break;
2243                         case STACKVAR:
2244                                 printf(" I%02d", s->varnum);
2245                                 break;
2246                         case LOCALVAR:
2247                                 printf(" L%02d", s->varnum);
2248                                 break;
2249                         case ARGVAR:
2250                                 printf(" A%02d", s->varnum);
2251                                 break;
2252                         default:
2253                                 printf(" !%02d", j);
2254                         }
2255                 else
2256                         switch (s->varkind) {
2257                         case TEMPVAR:
2258                                 if (s->flags & INMEMORY)
2259                                         printf(" m%02d", s->regoff);
2260                                 else if ((s->type == TYPE_FLT) || (s->type == TYPE_DBL))
2261                                         printf(" f%02d", s->regoff);
2262                                 else {
2263                                         printf(" %3s", regs[s->regoff]);
2264                                 }
2265                                 break;
2266                         case STACKVAR:
2267                                 printf(" i%02d", s->varnum);
2268                                 break;
2269                         case LOCALVAR:
2270                                 printf(" l%02d", s->varnum);
2271                                 break;
2272                         case ARGVAR:
2273                                 printf(" a%02d", s->varnum);
2274                                 break;
2275                         default:
2276                                 printf(" ?%02d", j);
2277                         }
2278                 s = s->prev;
2279         }
2280 }
2281
2282
2283 #if 0
2284 static void print_reg(stackptr s) {
2285         if (s) {
2286                 if (s->flags & SAVEDVAR)
2287                         switch (s->varkind) {
2288                         case TEMPVAR:
2289                                 if (s->flags & INMEMORY)
2290                                         printf(" tm%02d", s->regoff);
2291                                 else
2292                                         printf(" tr%02d", s->regoff);
2293                                 break;
2294                         case STACKVAR:
2295                                 printf(" s %02d", s->varnum);
2296                                 break;
2297                         case LOCALVAR:
2298                                 printf(" l %02d", s->varnum);
2299                                 break;
2300                         case ARGVAR:
2301                                 printf(" a %02d", s->varnum);
2302                                 break;
2303                         default:
2304                                 printf(" ! %02d", s->varnum);
2305                         }
2306                 else
2307                         switch (s->varkind) {
2308                         case TEMPVAR:
2309                                 if (s->flags & INMEMORY)
2310                                         printf(" Tm%02d", s->regoff);
2311                                 else
2312                                         printf(" Tr%02d", s->regoff);
2313                                 break;
2314                         case STACKVAR:
2315                                 printf(" S %02d", s->varnum);
2316                                 break;
2317                         case LOCALVAR:
2318                                 printf(" L %02d", s->varnum);
2319                                 break;
2320                         case ARGVAR:
2321                                 printf(" A %02d", s->varnum);
2322                                 break;
2323                         default:
2324                                 printf(" ? %02d", s->varnum);
2325                         }
2326         }
2327         else
2328                 printf("     ");
2329                 
2330 }
2331 #endif
2332
2333
2334 char *icmd_builtin_name(functionptr bptr)
2335 {
2336         builtin_descriptor *bdesc = builtin_desc;
2337         while ((bdesc->opcode != 0) && (bdesc->builtin != bptr))
2338                 bdesc++;
2339         return (bdesc->opcode) ? bdesc->name : "<NOT IN TABLE>";
2340 }
2341
2342
2343 static char *jit_type[] = {
2344         "int",
2345         "lng",
2346         "flt",
2347         "dbl",
2348         "adr"
2349 };
2350
2351
2352 void show_icmd_method(methodinfo *m)
2353 {
2354         int i, j;
2355         basicblock *bptr;
2356         exceptiontable *ex;
2357
2358         printf("\n");
2359         utf_fprint_classname(stdout, m->class->name);
2360         printf(".");
2361         utf_fprint(stdout, m->name);
2362         utf_fprint_classname(stdout, m->descriptor);
2363         printf ("\n\nMax locals: %d\n", (int) m->maxlocals);
2364         printf ("Max stack:  %d\n", (int) m->maxstack);
2365
2366         printf ("Line number table length: %d\n", m->linenumbercount);
2367
2368         printf ("Exceptions (Number: %d):\n", m->exceptiontablelength);
2369         for (ex = m->exceptiontable; ex != NULL; ex = ex->down) {
2370                 printf("    L%03d ... ", ex->start->debug_nr );
2371                 printf("L%03d  = ", ex->end->debug_nr);
2372                 printf("L%03d\n", ex->handler->debug_nr);
2373         }
2374         
2375         printf ("Local Table:\n");
2376         for (i = 0; i < m->maxlocals; i++) {
2377                 printf("   %3d: ", i);
2378                 for (j = TYPE_INT; j <= TYPE_ADR; j++)
2379                         if (m->registerdata->locals[i][j].type >= 0) {
2380                                 printf("   (%s) ", jit_type[j]);
2381                                 if (m->registerdata->locals[i][j].flags & INMEMORY)
2382                                         printf("m%2d", m->registerdata->locals[i][j].regoff);
2383                                 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2384                                         printf("f%02d", m->registerdata->locals[i][j].regoff);
2385                                 else {
2386                                         printf("%3s", regs[m->registerdata->locals[i][j].regoff]);
2387                                 }
2388                         }
2389                 printf("\n");
2390         }
2391         printf("\n");
2392
2393         printf ("Interface Table:\n");
2394         for (i = 0; i < m->maxstack; i++) {
2395                 if ((m->registerdata->interfaces[i][0].type >= 0) ||
2396                         (m->registerdata->interfaces[i][1].type >= 0) ||
2397                     (m->registerdata->interfaces[i][2].type >= 0) ||
2398                         (m->registerdata->interfaces[i][3].type >= 0) ||
2399                     (m->registerdata->interfaces[i][4].type >= 0)) {
2400                         printf("   %3d: ", i);
2401                         for (j = TYPE_INT; j <= TYPE_ADR; j++)
2402                                 if (m->registerdata->interfaces[i][j].type >= 0) {
2403                                         printf("   (%s) ", jit_type[j]);
2404                                         if (m->registerdata->interfaces[i][j].flags & SAVEDVAR) {
2405                                                 if (m->registerdata->interfaces[i][j].flags & INMEMORY)
2406                                                         printf("M%2d", m->registerdata->interfaces[i][j].regoff);
2407                                                 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2408                                                         printf("F%02d", m->registerdata->interfaces[i][j].regoff);
2409                                                 else {
2410                                                         printf("%3s", regs[m->registerdata->interfaces[i][j].regoff]);
2411                                                 }
2412                                         }
2413                                         else {
2414                                                 if (m->registerdata->interfaces[i][j].flags & INMEMORY)
2415                                                         printf("m%2d", m->registerdata->interfaces[i][j].regoff);
2416                                                 else if ((j == TYPE_FLT) || (j == TYPE_DBL))
2417                                                         printf("f%02d", m->registerdata->interfaces[i][j].regoff);
2418                                                 else {
2419                                                         printf("%3s", regs[m->registerdata->interfaces[i][j].regoff]);
2420                                                 }
2421                                         }
2422                                 }
2423                         printf("\n");
2424                 }
2425         }
2426         printf("\n");
2427
2428         if (showdisassemble) {
2429 #if defined(__I386__) || defined(__X86_64__)
2430                 u1 *u1ptr;
2431                 s4 a;
2432
2433                 u1ptr = m->mcode + dseglen;
2434                 for (i = 0; i < m->basicblocks[0].mpc; i++, u1ptr++) {
2435                         a = disassinstr(u1ptr, i);
2436                         i += a;
2437                         u1ptr += a;
2438                 }
2439                 printf("\n");
2440 #else
2441                 s4 *s4ptr;
2442
2443                 s4ptr = (s4 *) (m->mcode + dseglen);
2444                 for (i = 0; i < m->basicblocks[0].mpc; i += 4, s4ptr++) {
2445                         disassinstr(s4ptr, i); 
2446                 }
2447                 printf("\n");
2448 #endif
2449         }
2450         
2451         for (bptr = m->basicblocks; bptr != NULL; bptr = bptr->next) {
2452                 show_icmd_block(m, bptr);
2453         }
2454 }
2455
2456
2457 void show_icmd_block(methodinfo *m, basicblock *bptr)
2458 {
2459         int i, j;
2460         int deadcode;
2461         instruction *iptr;
2462
2463         if (bptr->flags != BBDELETED) {
2464                 deadcode = bptr->flags <= BBREACHED;
2465                 printf("[");
2466                 if (deadcode)
2467                         for (j = m->maxstack; j > 0; j--)
2468                                 printf(" ?  ");
2469                 else
2470                         icmd_print_stack(m, bptr->instack);
2471                 printf("] L%03d(%d - %d) flags=%d:\n", bptr->debug_nr, bptr->icount, bptr->pre_count,bptr->flags);
2472                 iptr = bptr->iinstr;
2473
2474                 for (i = 0; i < bptr->icount; i++, iptr++) {
2475                         printf("[");
2476                         if (deadcode) {
2477                                 for (j = m->maxstack; j > 0; j--)
2478                                         printf(" ?  ");
2479                         }
2480                         else
2481                                 icmd_print_stack(m, iptr->dst);
2482                         printf("]     %4d  ", i);
2483                         show_icmd(iptr, deadcode);
2484                         printf("\n");
2485                 }
2486
2487                 if (showdisassemble && (!deadcode)) {
2488 #if defined(__I386__) || defined(__X86_64__)
2489                         u1 *u1ptr;
2490                         s4 a;
2491
2492                         printf("\n");
2493                         i = bptr->mpc;
2494                         u1ptr = m->mcode + dseglen + i;
2495
2496                         if (bptr->next != NULL) {
2497                                 for (; i < bptr->next->mpc; i++, u1ptr++) {
2498                                         a = disassinstr(u1ptr, i);
2499                                         i += a;
2500                                         u1ptr += a;
2501                                 }
2502                                 printf("\n");
2503
2504                         } else {
2505                                 for (; u1ptr < (u1 *) (m->mcode + m->mcodelength); i++, u1ptr++) {
2506                                         a = disassinstr(u1ptr, i); 
2507                                         i += a;
2508                                         u1ptr += a;
2509                                 }
2510                                 printf("\n");
2511                         }
2512 #else
2513                         s4 *s4ptr;
2514
2515                         printf("\n");
2516                         i = bptr->mpc;
2517                         s4ptr = (s4 *) (m->mcode + dseglen + i);
2518
2519                         if (bptr->next != NULL) {
2520                                 for (; i < bptr->next->mpc; i += 4, s4ptr++) {
2521                                         disassinstr(s4ptr, i); 
2522                                 }
2523                                 printf("\n");
2524
2525                         } else {
2526                                 for (; s4ptr < (s4 *) (m->mcode + m->mcodelength); i += 4, s4ptr++) {
2527                                         disassinstr(s4ptr, i); 
2528                                 }
2529                                 printf("\n");
2530                         }
2531 #endif
2532                 }
2533         }
2534 }
2535
2536
2537 void show_icmd(instruction *iptr, bool deadcode)
2538 {
2539         int j;
2540         s4  *s4ptr;
2541         void **tptr = NULL;
2542         
2543         printf("%s", icmd_names[iptr->opc]);
2544
2545         switch ((int) iptr->opc) {
2546         case ICMD_IADDCONST:
2547         case ICMD_ISUBCONST:
2548         case ICMD_IMULCONST:
2549         case ICMD_IDIVPOW2:
2550         case ICMD_IREMPOW2:
2551         case ICMD_IANDCONST:
2552         case ICMD_IORCONST:
2553         case ICMD_IXORCONST:
2554         case ICMD_ISHLCONST:
2555         case ICMD_ISHRCONST:
2556         case ICMD_IUSHRCONST:
2557         case ICMD_LSHLCONST:
2558         case ICMD_LSHRCONST:
2559         case ICMD_LUSHRCONST:
2560         case ICMD_ICONST:
2561         case ICMD_ELSE_ICONST:
2562         case ICMD_IFEQ_ICONST:
2563         case ICMD_IFNE_ICONST:
2564         case ICMD_IFLT_ICONST:
2565         case ICMD_IFGE_ICONST:
2566         case ICMD_IFGT_ICONST:
2567         case ICMD_IFLE_ICONST:
2568         case ICMD_IASTORECONST:
2569         case ICMD_BASTORECONST:
2570         case ICMD_CASTORECONST:
2571         case ICMD_SASTORECONST:
2572                 printf(" %d", iptr->val.i);
2573                 break;
2574
2575         case ICMD_LADDCONST:
2576         case ICMD_LSUBCONST:
2577         case ICMD_LMULCONST:
2578         case ICMD_LDIVPOW2:
2579         case ICMD_LREMPOW2:
2580         case ICMD_LANDCONST:
2581         case ICMD_LORCONST:
2582         case ICMD_LXORCONST:
2583         case ICMD_LCONST:
2584         case ICMD_LASTORECONST:
2585 #if defined(__I386__)
2586                 printf(" %lld", iptr->val.l);
2587 #else
2588                 printf(" %ld", iptr->val.l);
2589 #endif
2590                 break;
2591
2592         case ICMD_FCONST:
2593                 printf(" %f", iptr->val.f);
2594                 break;
2595
2596         case ICMD_DCONST:
2597                 printf(" %f", iptr->val.d);
2598                 break;
2599
2600         case ICMD_ACONST:
2601         case ICMD_AASTORECONST:
2602                 printf(" %p", iptr->val.a);
2603                 break;
2604
2605         case ICMD_GETFIELD:
2606         case ICMD_PUTFIELD:
2607                 printf(" %d,", ((fieldinfo *) iptr->val.a)->offset);
2608         case ICMD_PUTSTATIC:
2609         case ICMD_GETSTATIC:
2610                 printf(" ");
2611                 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->class->name);
2612                 printf(".");
2613                 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->name);
2614                 printf(" (type ");
2615                 utf_fprint(stdout, ((fieldinfo *) iptr->val.a)->descriptor);
2616                 printf(")");
2617                 break;
2618
2619         case ICMD_IINC:
2620                 printf(" %d + %d", iptr->op1, iptr->val.i);
2621                 break;
2622
2623         case ICMD_IASTORE:
2624         case ICMD_SASTORE:
2625         case ICMD_BASTORE:
2626         case ICMD_CASTORE:
2627         case ICMD_LASTORE:
2628         case ICMD_DASTORE:
2629         case ICMD_FASTORE:
2630         case ICMD_AASTORE:
2631
2632         case ICMD_IALOAD:
2633         case ICMD_SALOAD:
2634         case ICMD_BALOAD:
2635         case ICMD_CALOAD:
2636         case ICMD_LALOAD:
2637         case ICMD_DALOAD:
2638         case ICMD_FALOAD:
2639         case ICMD_AALOAD:
2640                 if (iptr->op1 != 0)
2641                         printf("(opt.)");
2642                 break;
2643
2644         case ICMD_RET:
2645         case ICMD_ILOAD:
2646         case ICMD_LLOAD:
2647         case ICMD_FLOAD:
2648         case ICMD_DLOAD:
2649         case ICMD_ALOAD:
2650         case ICMD_ISTORE:
2651         case ICMD_LSTORE:
2652         case ICMD_FSTORE:
2653         case ICMD_DSTORE:
2654         case ICMD_ASTORE:
2655                 printf(" %d", iptr->op1);
2656                 break;
2657
2658         case ICMD_NEW:
2659                 printf(" ");
2660                 utf_fprint(stdout,
2661                                    ((classinfo *) iptr->val.a)->name);
2662                 break;
2663
2664         case ICMD_NEWARRAY:
2665                 switch (iptr->op1) {
2666                 case 4:
2667                         printf(" boolean");
2668                         break;
2669                 case 5:
2670                         printf(" char");
2671                         break;
2672                 case 6:
2673                         printf(" float");
2674                         break;
2675                 case 7:
2676                         printf(" double");
2677                         break;
2678                 case 8:
2679                         printf(" byte");
2680                         break;
2681                 case 9:
2682                         printf(" short");
2683                         break;
2684                 case 10:
2685                         printf(" int");
2686                         break;
2687                 case 11:
2688                         printf(" long");
2689                         break;
2690                 }
2691                 break;
2692
2693         case ICMD_ANEWARRAY:
2694                 if (iptr->op1) {
2695                         printf(" ");
2696                         utf_fprint(stdout,
2697                                            ((classinfo *) iptr->val.a)->name);
2698                 }
2699                 break;
2700
2701         case ICMD_MULTIANEWARRAY:
2702                 {
2703                         vftbl_t *vft;
2704                         printf(" %d ",iptr->op1);
2705                         vft = (vftbl_t *)iptr->val.a;
2706                         if (vft)
2707                                 utf_fprint(stdout,vft->class->name);
2708                         else
2709                                 printf("<null>");
2710                 }
2711                 break;
2712
2713         case ICMD_CHECKCAST:
2714         case ICMD_INSTANCEOF:
2715                 if (iptr->op1) {
2716                         classinfo *c = iptr->val.a;
2717                         if (c->flags & ACC_INTERFACE)
2718                                 printf(" (INTERFACE) ");
2719                         else
2720                                 printf(" (CLASS,%3d) ", c->vftbl->diffval);
2721                         utf_fprint(stdout, c->name);
2722                 }
2723                 break;
2724
2725         case ICMD_BUILTIN3:
2726         case ICMD_BUILTIN2:
2727         case ICMD_BUILTIN1:
2728                 printf(" %s", icmd_builtin_name((functionptr) iptr->val.a));
2729                 break;
2730
2731         case ICMD_INVOKEVIRTUAL:
2732         case ICMD_INVOKESPECIAL:
2733         case ICMD_INVOKESTATIC:
2734         case ICMD_INVOKEINTERFACE:
2735                 printf(" ");
2736                 utf_fprint(stdout,
2737                                    ((methodinfo *) iptr->val.a)->class->name);
2738                 printf(".");
2739                 utf_fprint(stdout,
2740                                    ((methodinfo *) iptr->val.a)->name);
2741                 break;
2742
2743         case ICMD_IFEQ:
2744         case ICMD_IFNE:
2745         case ICMD_IFLT:
2746         case ICMD_IFGE:
2747         case ICMD_IFGT:
2748         case ICMD_IFLE:
2749                 if (deadcode || !iptr->target)
2750                         printf("(%d) op1=%d", iptr->val.i, iptr->op1);
2751                 else
2752                         printf("(%d) L%03d", iptr->val.i, ((basicblock *) iptr->target)->debug_nr);
2753                 break;
2754
2755         case ICMD_IF_LEQ:
2756         case ICMD_IF_LNE:
2757         case ICMD_IF_LLT:
2758         case ICMD_IF_LGE:
2759         case ICMD_IF_LGT:
2760         case ICMD_IF_LLE:
2761                 if (deadcode || !iptr->target)
2762 #if defined(__I386__) || defined(__POWERPC__)
2763                         printf("(%lld) op1=%d", iptr->val.l, iptr->op1);
2764 #else
2765                         printf("(%ld) op1=%d", iptr->val.l, iptr->op1);
2766 #endif
2767                 else
2768 #if defined(__I386__) || defined(__POWERPC__)
2769                         printf("(%lld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2770 #else
2771                         printf("(%ld) L%03d", iptr->val.l, ((basicblock *) iptr->target)->debug_nr);
2772 #endif
2773                 break;
2774
2775         case ICMD_JSR:
2776         case ICMD_GOTO:
2777         case ICMD_IFNULL:
2778         case ICMD_IFNONNULL:
2779         case ICMD_IF_ICMPEQ:
2780         case ICMD_IF_ICMPNE:
2781         case ICMD_IF_ICMPLT:
2782         case ICMD_IF_ICMPGE:
2783         case ICMD_IF_ICMPGT:
2784         case ICMD_IF_ICMPLE:
2785         case ICMD_IF_LCMPEQ:
2786         case ICMD_IF_LCMPNE:
2787         case ICMD_IF_LCMPLT:
2788         case ICMD_IF_LCMPGE:
2789         case ICMD_IF_LCMPGT:
2790         case ICMD_IF_LCMPLE:
2791         case ICMD_IF_ACMPEQ:
2792         case ICMD_IF_ACMPNE:
2793                 if (deadcode || !iptr->target)
2794                         printf(" op1=%d", iptr->op1);
2795                 else
2796                         printf(" L%03d", ((basicblock *) iptr->target)->debug_nr);
2797                 break;
2798
2799         case ICMD_TABLESWITCH:
2800                 s4ptr = (s4*)iptr->val.a;
2801
2802                 if (deadcode || !iptr->target) {
2803                         printf(" %d;", *s4ptr);
2804                 }
2805                 else {
2806                         tptr = (void **) iptr->target;
2807                         printf(" L%03d;", ((basicblock *) *tptr)->debug_nr); 
2808                         tptr++;
2809                 }
2810
2811                 s4ptr++;         /* skip default */
2812                 j = *s4ptr++;                               /* low     */
2813                 j = *s4ptr++ - j;                           /* high    */
2814                 while (j >= 0) {
2815                         if (deadcode || !*tptr)
2816                                 printf(" %d", *s4ptr++);
2817                         else {
2818                                 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2819                                 tptr++;
2820                         }
2821                         j--;
2822                 }
2823                 break;
2824
2825         case ICMD_LOOKUPSWITCH:
2826                 s4ptr = (s4*)iptr->val.a;
2827
2828                 if (deadcode || !iptr->target) {
2829                         printf(" %d;", *s4ptr);
2830                 }
2831                 else {
2832                         tptr = (void **) iptr->target;
2833                         printf(" L%03d;", ((basicblock *) *tptr)->debug_nr);
2834                         tptr++;
2835                 }
2836                 s4ptr++;                                         /* default */
2837                 j = *s4ptr++;                                    /* count   */
2838
2839                 while (--j >= 0) {
2840                         if (deadcode || !*tptr) {
2841                                 s4ptr++; /* skip value */
2842                                 printf(" %d",*s4ptr++);
2843                         }
2844                         else {
2845                                 printf(" L%03d", ((basicblock *) *tptr)->debug_nr);
2846                                 tptr++;
2847                         }
2848                 }
2849                 break;
2850         }
2851         printf(" Line number: %d, method:",iptr->line);
2852         utf_display(iptr->method->class->name);
2853         printf(".");
2854         utf_display(iptr->method->name);
2855 }
2856
2857
2858 /*
2859  * These are local overrides for various environment variables in Emacs.
2860  * Please do not remove this and leave it at the end of the file, where
2861  * Emacs will automagically detect them.
2862  * ---------------------------------------------------------------------
2863  * Local variables:
2864  * mode: c
2865  * indent-tabs-mode: t
2866  * c-basic-offset: 4
2867  * tab-width: 4
2868  * End:
2869  */