Unified variables changes for common/i386.
[cacao.git] / src / vm / jit / show.c
1 /* src/vm/jit/show.c - showing the intermediate representation
2
3    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
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., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Andreas Krall
28
29    Changes: Edwin Steiner
30             Christian Thalinger
31             Christian Ullrich
32
33    $Id$
34
35 */
36
37
38 #include "config.h"
39 #include "vm/types.h"
40
41 #include <assert.h>
42
43 #include "mm/memory.h"
44
45 #if defined(ENABLE_THREADS)
46 # include "threads/native/lock.h"
47 #else
48 # include "threads/none/lock.h"
49 #endif
50
51 #include "vm/global.h"
52 #include "vm/options.h"
53 #include "vm/builtin.h"
54 #include "vm/stringlocal.h"
55 #include "vm/jit/jit.h"
56 #include "vm/jit/show.h"
57 #include "vm/jit/disass.h"
58 #include "vm/jit/stack.h"
59
60
61 /* global variables ***********************************************************/
62
63 #if defined(ENABLE_THREADS) && !defined(NDEBUG)
64 static java_objectheader *show_global_lock;
65 #endif
66
67
68 /* forward declarations *******************************************************/
69
70 #if !defined(NDEBUG)
71 static void new_show_variable_array(jitdata *jd, s4 *vars, int n, int stage);
72 #endif
73
74
75 /* show_init *******************************************************************
76
77    Initialized the show subsystem (called by jit_init).
78
79 *******************************************************************************/
80
81 #if !defined(NDEBUG)
82 bool show_init(void)
83 {
84 #if defined(ENABLE_THREADS)
85         /* initialize the show lock */
86
87         show_global_lock = NEW(java_objectheader);
88
89         lock_init_object_lock(show_global_lock);
90 #endif
91
92         /* everything's ok */
93
94         return true;
95 }
96 #endif
97
98
99 #if !defined(NDEBUG)
100 static char *jit_type[] = {
101         "int",
102         "lng",
103         "flt",
104         "dbl",
105         "adr"
106 };
107 #endif
108
109
110 /* show_method *****************************************************************
111
112    Print the intermediate representation of a method.
113
114    NOTE: Currently this function may only be called after register allocation!
115
116 *******************************************************************************/
117
118 #if !defined(NDEBUG)
119 void new_show_method(jitdata *jd, int stage)
120 {
121         methodinfo     *m;
122         codeinfo       *code;
123         codegendata    *cd;
124         registerdata   *rd;
125         basicblock     *bptr;
126         basicblock     *lastbptr;
127         exceptiontable *ex;
128         s4              i, j;
129         u1             *u1ptr;
130
131         /* get required compiler data */
132
133         m    = jd->m;
134         code = jd->code;
135         cd   = jd->cd;
136         rd   = jd->rd;
137
138         /* We need to enter a lock here, since the binutils disassembler
139            is not reentrant-able and we could not read functions printed
140            at the same time. */
141
142         LOCK_MONITOR_ENTER(show_global_lock);
143
144         /* get the last basic block */
145
146         for (lastbptr = jd->new_basicblocks; lastbptr->next != NULL; lastbptr = lastbptr->next);
147
148         printf("\n");
149
150         method_println(m);
151
152         printf("\n(NEW INSTRUCTION FORMAT)\n");
153         printf("\nBasic blocks: %d\n", jd->new_basicblockcount);
154         if (stage >= SHOW_CODE) {
155                 printf("Code length:  %d\n", (lastbptr->mpc - jd->new_basicblocks[0].mpc));
156                 printf("Data length:  %d\n", cd->dseglen);
157                 printf("Stub length:  %d\n", (s4) (code->mcodelength -
158                                                                                    ((ptrint) cd->dseglen + lastbptr->mpc)));
159         }
160         printf("Max locals:   %d\n", cd->maxlocals);
161         printf("Max stack:    %d\n", cd->maxstack);
162         printf("Line number table length: %d\n", m->linenumbercount);
163
164         if (stage >= SHOW_PARSE) {
165                 printf("Exceptions (Number: %d):\n", cd->exceptiontablelength);
166                 for (ex = cd->exceptiontable; ex != NULL; ex = ex->down) {
167                         printf("    L%03d ... ", ex->start->nr );
168                         printf("L%03d  = ", ex->end->nr);
169                         printf("L%03d", ex->handler->nr);
170                         printf("  (catchtype: ");
171                         if (ex->catchtype.any)
172                                 if (IS_CLASSREF(ex->catchtype))
173                                         utf_display_printable_ascii_classname(ex->catchtype.ref->name);
174                                 else
175                                         utf_display_printable_ascii_classname(ex->catchtype.cls->name);
176                         else
177                                 printf("ANY");
178                         printf(")\n");
179                 }
180         }
181         
182         if (stage >= SHOW_PARSE && rd) {
183         printf("Local Table:\n");
184         for (i = 0; i < cd->maxlocals; i++) {
185                 printf("   %3d: ", i);
186
187 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
188 /*              for (j = TYPE_INT; j <= TYPE_ADR; j++) { */
189 # if defined(ENABLE_INTRP)
190                         if (!opt_intrp) {
191 # endif
192 /*                              if (rd->locals[i][j].type >= 0) { */
193                                         printf("   (%s) ", jit_type[jd->var[i].type]);
194                                         if (stage >= SHOW_REGS) {
195                                                 if (jd->var[i].flags & INMEMORY)
196                                                         printf("m%2d", jd->var[i].regoff);
197 # ifdef HAS_ADDRESS_REGISTER_FILE
198                                                 else if (jd->var[i].type == TYPE_ADR)
199                                                         printf("r%02d", jd->var[i].regoff);
200 # endif
201                                                 else if ((jd->var[i].type == TYPE_FLT) ||
202                                                                  (jd->var[i].type == TYPE_DBL))
203                                                         printf("f%02d", jd->var[i].regoff);
204                                                 else {
205 # if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
206                                                         if (IS_2_WORD_TYPE(j))
207                                                                 printf(" %3s/%3s",
208                                                                            regs[GET_LOW_REG(jd->var[i].regoff)],
209                                                                            regs[GET_HIGH_REG(jd->var[i].regoff)]);
210                                                         else
211 # endif
212                                                                 printf("%3s", regs[jd->var[i].regoff]);
213                                                 }
214                                         }
215 /*                              } */
216 # if defined(ENABLE_INTRP)
217                         }
218 # endif
219 /*              } */
220 #endif /* defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER) */
221
222                 printf("\n");
223         }
224         printf("\n");
225         }
226
227         if (cd->maxlocals > 0) {
228                 for (i = 0; i < 5; i++) {
229                         printf("%5s ",jit_type[i]);
230                         for (j = 0; j < cd->maxlocals; j++)
231                                 printf("%3i ",jd->local_map[j*5+i]);
232                         printf("\n");
233                 }
234                 printf("\n");
235         }
236
237         printf("Interface Table:(In/Outvars)\n");
238         if (cd->maxstack > 0) {
239                 bool exist = false;
240                 s4 *mapptr = jd->interface_map;
241                 
242                 /* look if there exist IN/OUTVARS */
243                 if (mapptr != NULL) {
244                         for (i = 0; (i < (5 * cd->maxstack)) && !exist; i++, mapptr++)
245                                 exist = (*mapptr != UNUSED);
246                 
247                         if (exist)
248                                 for (i = 0; i < 5; i++) {
249                                         printf("%5s ",jit_type[i]);
250                                         for (j = 0; j < cd->maxstack; j++)
251                                                 printf("%3i ",jd->interface_map[j*5+i]);
252                                         printf("\n");
253                                 }
254                         printf("\n");
255                 }
256         }
257
258         if (code->rplpoints) {
259                 printf("Replacement Points:\n");
260                 replace_show_replacement_points(code);
261                 printf("\n");
262         }
263
264 #if defined(ENABLE_DISASSEMBLER)
265         /* show code before first basic block */
266
267         if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
268                 u1ptr = (u1 *) ((ptrint) code->mcode + cd->dseglen);
269
270                 for (; u1ptr < (u1 *) ((ptrint) code->mcode + cd->dseglen + jd->new_basicblocks[0].mpc);)
271                         DISASSINSTR(u1ptr);
272
273                 printf("\n");
274         }
275 #endif
276
277         /* show code of all basic blocks */
278
279         for (bptr = jd->new_basicblocks; bptr != NULL; bptr = bptr->next)
280                 new_show_basicblock(jd, bptr, stage);
281
282 #if defined(ENABLE_DISASSEMBLER)
283         /* show stubs code */
284
285         if (stage >= SHOW_CODE && opt_showdisassemble && opt_showexceptionstubs) {
286                 printf("\nStubs code:\n");
287                 printf("Length: %d\n\n", (s4) (code->mcodelength -
288                                                                            ((ptrint) cd->dseglen + lastbptr->mpc)));
289
290                 u1ptr = (u1 *) ((ptrint) code->mcode + cd->dseglen + lastbptr->mpc);
291
292                 for (; (ptrint) u1ptr < ((ptrint) code->mcode + code->mcodelength);)
293                         DISASSINSTR(u1ptr);
294
295                 printf("\n");
296         }
297 #endif
298
299         LOCK_MONITOR_EXIT(show_global_lock);
300
301         /* finally flush the output */
302
303         fflush(stdout);
304 }
305 #endif /* !defined(NDEBUG) */
306
307
308 /* show_basicblock *************************************************************
309
310    Print the intermediate representation of a basic block.
311
312    NOTE: Currently this function may only be called after register allocation!
313
314 *******************************************************************************/
315
316 #if !defined(NDEBUG)
317 void new_show_basicblock(jitdata *jd, basicblock *bptr, int stage)
318 {
319         methodinfo  *m;
320         codeinfo    *code;
321         codegendata *cd;
322         s4           i;
323         bool         deadcode;
324         instruction *iptr;
325         u1          *u1ptr;
326
327         /* get required compiler data */
328
329         m    = jd->m;
330         code = jd->code;
331         cd   = jd->cd;
332
333         if (bptr->flags != BBDELETED) {
334                 deadcode = bptr->flags <= BBREACHED;
335
336                 printf("======== %sL%03d ======== (flags: %d, bitflags: %01x, next: %d, type: ",
337                                 (bptr->bitflags & BBFLAG_REPLACEMENT) ? "<REPLACE> " : "",
338                            bptr->nr, bptr->flags, bptr->bitflags, 
339                            (bptr->next) ? (bptr->next->nr) : -1);
340
341                 switch (bptr->type) {
342                 case BBTYPE_STD:
343                         printf("STD");
344                         break;
345                 case BBTYPE_EXH:
346                         printf("EXH");
347                         break;
348                 case BBTYPE_SBR:
349                         printf("SBR");
350                         break;
351                 }
352
353                 printf(", instruction count: %d, predecessors: %d [ ",
354                            bptr->icount, bptr->predecessorcount);
355
356                 for (i = 0; i < bptr->predecessorcount; i++)
357                         printf("%d ", bptr->predecessors[i]->nr);
358
359                 printf("]):\n");
360
361                 if (stage >= SHOW_STACK) {
362                         printf("IN:  ");
363                         new_show_variable_array(jd, bptr->invars, bptr->indepth, stage);
364                         printf("\n");
365                 }
366
367                 iptr = bptr->iinstr;
368
369                 for (i = 0; i < bptr->icount; i++, iptr++) {
370                         printf("%4d:  ", iptr->line);
371
372                         new_show_icmd(jd, iptr, deadcode, stage);
373                         printf("\n");
374                 }
375
376                 if (stage >= SHOW_STACK) {
377                         printf("OUT: ");
378                         new_show_variable_array(jd, bptr->outvars, bptr->outdepth, stage);
379                         printf("\n");
380                 }
381
382 #if defined(ENABLE_DISASSEMBLER)
383                 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd) &&
384                         (!deadcode)) 
385                 {
386                         printf("\n");
387                         u1ptr = (u1 *) (code->mcode + cd->dseglen + bptr->mpc);
388
389                         if (bptr->next != NULL) {
390                                 for (; u1ptr < (u1 *) (code->mcode + cd->dseglen + bptr->next->mpc);)
391                                         DISASSINSTR(u1ptr);
392
393                         } 
394                         else {
395                                 for (; u1ptr < (u1 *) (code->mcode + code->mcodelength);)
396                                         DISASSINSTR(u1ptr); 
397                         }
398                         printf("\n");
399                 }
400 #endif
401         }
402 }
403 #endif /* !defined(NDEBUG) */
404
405
406 /* show_icmd *******************************************************************
407
408    Print the intermediate representation of an instruction.
409
410    NOTE: Currently this function may only be called after register allocation!
411
412 *******************************************************************************/
413
414 #if !defined(NDEBUG)
415
416 #define SHOW_TARGET(target)                                          \
417         if (stage >= SHOW_STACK) {                                   \
418             printf("--> L%03d ", (target).block->nr);                \
419         }                                                            \
420         else if (stage >= SHOW_PARSE) {                              \
421             printf("--> insindex %d (L%03d) ", (target).insindex,    \
422                 jd->new_basicblocks[jd->new_basicblockindex[         \
423                 (target).insindex]].nr);                             \
424         }                                                            \
425         else {                                                       \
426             printf("--> insindex %d ", (target).insindex);           \
427         }
428
429 #define SHOW_INT_CONST(val)                                          \
430         if (stage >= SHOW_PARSE) {                                   \
431             printf("%ld ", (long) (val));                            \
432         }                                                            \
433         else {                                                       \
434             printf("iconst ");                                       \
435         }
436
437 #define SHOW_LNG_CONST(val)                                          \
438         if (stage >= SHOW_PARSE) {                                   \
439             printf("%lld ", (long long)(val));                       \
440         }                                                            \
441         else {                                                       \
442             printf("lconst ");                                       \
443         }
444
445 #define SHOW_FLT_CONST(val)                                          \
446         if (stage >= SHOW_PARSE) {                                   \
447             printf("%g ", (val));                                    \
448         }                                                            \
449         else {                                                       \
450             printf("fconst ");                                       \
451         }
452
453 #define SHOW_DBL_CONST(val)                                          \
454         if (stage >= SHOW_PARSE) {                                   \
455             printf("%g ", (val));                                    \
456         }                                                            \
457         else {                                                       \
458             printf("dconst ");                                       \
459         }
460
461 #define SHOW_INDEX(index)                                            \
462         if (stage >= SHOW_PARSE) {                                   \
463             printf("%d ", index);                                    \
464         }                                                            \
465         else {                                                       \
466             printf("index");                                         \
467         }
468
469 #define SHOW_STRING(val)                                             \
470         if (stage >= SHOW_PARSE) {                                   \
471             putchar('"');                                            \
472             utf_display_printable_ascii(                             \
473                 javastring_toutf((java_lang_String *)(val), false)); \
474             printf("\" ");                                           \
475         }                                                            \
476         else {                                                       \
477             printf("string ");                                       \
478         }
479
480 #define SHOW_CLASSREF_OR_CLASSINFO(c)                                \
481         if (stage >= SHOW_PARSE) {                                   \
482             if (IS_CLASSREF(c))                                      \
483                 class_classref_print(c.ref);                         \
484             else                                                     \
485                 class_print(c.cls);                                  \
486             putchar(' ');                                            \
487         }                                                            \
488         else {                                                       \
489             printf("class ");                                        \
490         }
491
492 #define SHOW_FIELD(fmiref)                                           \
493         if (stage >= SHOW_PARSE) {                                   \
494             field_fieldref_print(fmiref);                            \
495             putchar(' ');                                            \
496         }                                                            \
497         else {                                                       \
498             printf("field ");                                        \
499         }
500
501 #define SHOW_STACKVAR(sp)                                            \
502         new_show_stackvar(jd, (sp), stage)
503
504 #define SHOW_S1(iptr)                                                \
505         if (stage >= SHOW_STACK) {                                   \
506             SHOW_STACKVAR(iptr->s1.varindex);                    \
507         }
508
509 #define SHOW_S2(iptr)                                                \
510         if (stage >= SHOW_STACK) {                                   \
511             SHOW_STACKVAR(iptr->sx.s23.s2.varindex);                     \
512         }
513
514 #define SHOW_S3(iptr)                                                \
515         if (stage >= SHOW_STACK) {                                                                               \
516                 SHOW_STACKVAR(iptr->sx.s23.s3.varindex);                                         \
517         }
518
519 #define SHOW_DST(iptr)                                               \
520         if (stage >= SHOW_STACK) {                                                                               \
521                 printf("=> ");                                                                                           \
522                 SHOW_STACKVAR(iptr->dst.varindex);                                                       \
523         }
524
525 #define SHOW_S1_LOCAL(iptr)                                          \
526         if (stage >= SHOW_STACK) {                                                                               \
527                 printf("L%d ", iptr->s1.varindex);                                                       \
528         }
529
530 #define SHOW_DST_LOCAL(iptr)                                         \
531         if (stage >= SHOW_STACK) {                                                                               \
532                 printf("=> L%d ", iptr->dst.varindex);                                           \
533         }
534
535 static void new_show_stackvar(jitdata *jd, s4 index, int stage)
536 {
537         char type;
538         varinfo *sp;
539
540         sp = &(jd->var[index]);
541
542         switch (sp->type) {
543         case TYPE_INT: type = 'i'; break;
544         case TYPE_LNG: type = 'l'; break;
545         case TYPE_FLT: type = 'f'; break;
546         case TYPE_DBL: type = 'd'; break;
547         case TYPE_ADR: type = 'a'; break;
548         default:       type = '?';
549         }
550 #if 0
551         switch (sp->varkind) {
552         case TEMPVAR: printf("T%c%d", type, (int) (sp - jd->new_stack)); break;
553         case LOCALVAR: printf("L%c%d(T%d)", type, sp->varnum, (int) (sp - jd->new_stack)); break;
554         case STACKVAR: printf("I%c%d(T%d)", type, sp->varnum, (int) (sp - jd->new_stack)); break;
555         case ARGVAR: printf("A%c%d(T%d)", type, sp->varnum, (int) (sp - jd->new_stack)); break;
556         default: printf("?%c%d", type, index); break;
557         }
558 #endif
559
560         if (sp->flags & PREALLOC)
561                 printf("A");
562         else if (sp->flags & OUTVAR)
563                 printf("I");
564         else if (index < jd->localcount)
565                 printf("L");
566         else printf("T");
567         printf("%c%d", type, index);
568
569         if (stage >= SHOW_REGS) {
570                 putchar('(');
571
572                 if (sp->flags & INMEMORY)
573                         printf("M%02d", sp->regoff);
574 #ifdef HAS_ADDRESS_REGISTER_FILE
575                 else if (sp->type == TYPE_ADR)
576                         printf("R%02d", sp->regoff);
577 #endif
578                 else if (IS_FLT_DBL_TYPE(sp->type))
579                         printf("F%02d", sp->regoff);
580                 else {
581 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
582                         if (IS_2_WORD_TYPE(sp->type)) {
583 # if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
584 #  if defined(ENABLE_INTRP)
585                                 if (opt_intrp)
586                                         printf("%3d/%3d", GET_LOW_REG(sp->regoff),
587                                                    GET_HIGH_REG(sp->regoff));
588                                 else
589 #  endif
590                                         printf("%3s/%3s", regs[GET_LOW_REG(sp->regoff)],
591                                                    regs[GET_HIGH_REG(sp->regoff)]);
592 # else
593                                 printf("%3d/%3d", GET_LOW_REG(sp->regoff),
594                                            GET_HIGH_REG(sp->regoff));
595 # endif
596                         } 
597                         else 
598 #endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
599                                 {
600 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
601 # if defined(ENABLE_INTRP)
602                                         if (opt_intrp)
603                                                 printf("%3d", sp->regoff);
604                                         else
605 # endif
606                                                 printf("%3s", regs[sp->regoff]);
607 #else
608                                         printf("%3d", sp->regoff);
609 #endif
610                                 }
611                 }
612
613
614                 putchar(')');
615         }
616         putchar(' ');
617         fflush(stdout);
618 }
619
620 static void new_show_variable_array(jitdata *jd, s4 *vars, int n, int stage)
621 {
622         int i;
623
624         printf("[");
625         for (i=0; i<n; ++i) {
626                 if (i)
627                         printf(" ");
628                 new_show_stackvar(jd, vars[i], stage);
629         }
630         printf("]");
631 }
632
633 void new_show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
634 {
635         u2                 opcode;
636         branch_target_t   *table;
637         lookup_target_t   *lookup;
638         constant_FMIref   *fmiref;
639         s4          *argp;
640         s4                 i;
641
642         /* get the opcode and the condition */
643
644         opcode    =  iptr->opc;
645
646         printf("%s ", icmd_names[opcode]);
647
648         if (stage < SHOW_PARSE)
649                 return;
650
651         if (deadcode)
652                 stage = SHOW_PARSE;
653
654         /* Print the condition for conditional instructions. */
655
656         /* XXX print condition from flags */
657
658         if (iptr->flags.bits & INS_FLAG_UNRESOLVED)
659                 printf("(UNRESOLVED) ");
660
661         switch (opcode) {
662
663         case ICMD_POP:
664         case ICMD_CHECKNULL:
665         case ICMD_CHECKNULL_POP:
666                 SHOW_S1(iptr);
667                 break;
668
669                 /* unary */
670         case ICMD_ARRAYLENGTH:
671         case ICMD_INEG:
672         case ICMD_LNEG:
673         case ICMD_FNEG:
674         case ICMD_DNEG:
675         case ICMD_I2L:
676         case ICMD_I2F:
677         case ICMD_I2D:
678         case ICMD_L2I:
679         case ICMD_L2F:
680         case ICMD_L2D:
681         case ICMD_F2I:
682         case ICMD_F2L:
683         case ICMD_F2D:
684         case ICMD_D2I:
685         case ICMD_D2L:
686         case ICMD_D2F:
687         case ICMD_INT2BYTE:
688         case ICMD_INT2CHAR:
689         case ICMD_INT2SHORT:
690                 SHOW_S1(iptr);
691                 SHOW_DST(iptr);
692                 break;
693
694                 /* binary */
695         case ICMD_IADD:
696         case ICMD_LADD:
697         case ICMD_FADD:
698         case ICMD_DADD:
699         case ICMD_ISUB:
700         case ICMD_LSUB:
701         case ICMD_FSUB:
702         case ICMD_DSUB:
703         case ICMD_IMUL:
704         case ICMD_LMUL:
705         case ICMD_FMUL:
706         case ICMD_DMUL:
707         case ICMD_IDIV:
708         case ICMD_LDIV:
709         case ICMD_FDIV:
710         case ICMD_DDIV:
711         case ICMD_IREM:
712         case ICMD_LREM:
713         case ICMD_FREM:
714         case ICMD_DREM:
715         case ICMD_ISHL:
716         case ICMD_LSHL:
717         case ICMD_ISHR:
718         case ICMD_LSHR:
719         case ICMD_IUSHR:
720         case ICMD_LUSHR:
721         case ICMD_IAND:
722         case ICMD_LAND:
723         case ICMD_IOR:
724         case ICMD_LOR:
725         case ICMD_IXOR:
726         case ICMD_LXOR:
727         case ICMD_LCMP:
728         case ICMD_FCMPL:
729         case ICMD_FCMPG:
730         case ICMD_DCMPL:
731         case ICMD_DCMPG:
732                 SHOW_S1(iptr);
733                 SHOW_S2(iptr);
734                 SHOW_DST(iptr);
735                 break;
736
737                 /* binary/const INT */
738         case ICMD_IADDCONST:
739         case ICMD_ISUBCONST:
740         case ICMD_IMULCONST:
741         case ICMD_IMULPOW2:
742         case ICMD_IDIVPOW2:
743         case ICMD_IREMPOW2:
744         case ICMD_IANDCONST:
745         case ICMD_IORCONST:
746         case ICMD_IXORCONST:
747         case ICMD_ISHLCONST:
748         case ICMD_ISHRCONST:
749         case ICMD_IUSHRCONST:
750         case ICMD_LSHLCONST:
751         case ICMD_LSHRCONST:
752         case ICMD_LUSHRCONST:
753                 SHOW_S1(iptr);
754                 SHOW_INT_CONST(iptr->sx.val.i); 
755                 SHOW_DST(iptr);
756                 break;
757
758                 /* ?ASTORECONST (trinary/const INT) */
759         case ICMD_IASTORECONST:
760         case ICMD_BASTORECONST:
761         case ICMD_CASTORECONST:
762         case ICMD_SASTORECONST:
763                 SHOW_S1(iptr);
764                 SHOW_S2(iptr);
765                 SHOW_INT_CONST(iptr->sx.s23.s3.constval);
766                 break;
767
768                 /* const INT */
769         case ICMD_ICONST:
770                 SHOW_INT_CONST(iptr->sx.val.i); 
771                 SHOW_DST(iptr);
772                 break;
773
774                 /* binary/const LNG */
775         case ICMD_LADDCONST:
776         case ICMD_LSUBCONST:
777         case ICMD_LMULCONST:
778         case ICMD_LMULPOW2:
779         case ICMD_LDIVPOW2:
780         case ICMD_LREMPOW2:
781         case ICMD_LANDCONST:
782         case ICMD_LORCONST:
783         case ICMD_LXORCONST:
784                 SHOW_S1(iptr);
785                 SHOW_LNG_CONST(iptr->sx.val.l); 
786                 SHOW_DST(iptr);
787                 break;
788
789                 /* trinary/const LNG (<= pointer size) */
790         case ICMD_LASTORECONST:
791                 SHOW_S1(iptr);
792                 SHOW_S2(iptr);
793                 SHOW_LNG_CONST(iptr->sx.s23.s3.constval);
794                 break;
795
796                 /* const LNG */
797         case ICMD_LCONST:
798                 SHOW_LNG_CONST(iptr->sx.val.l); 
799                 SHOW_DST(iptr);
800                 break;
801
802                 /* const FLT */
803         case ICMD_FCONST:
804                 SHOW_FLT_CONST(iptr->sx.val.f); 
805                 SHOW_DST(iptr);
806                 break;
807
808                 /* const DBL */
809         case ICMD_DCONST:
810                 SHOW_DBL_CONST(iptr->sx.val.d); 
811                 SHOW_DST(iptr);
812                 break;
813
814                 /* const ADR */
815         case ICMD_ACONST:
816                 if (iptr->flags.bits & INS_FLAG_CLASS) {
817                         SHOW_CLASSREF_OR_CLASSINFO(iptr->sx.val.c);
818                 }
819                 else if (iptr->sx.val.anyptr == NULL) {
820                         printf("NULL ");
821                 }
822                 else {
823                         SHOW_STRING(iptr->sx.val.stringconst);
824                 }
825                 SHOW_DST(iptr);
826                 break;
827
828         case ICMD_AASTORECONST:
829                 SHOW_S1(iptr);
830                 SHOW_S2(iptr);
831                 printf("%p ", (void*) iptr->sx.s23.s3.constval);
832                 break;
833
834         case ICMD_GETFIELD:        /* 1 -> 1 */
835         case ICMD_PUTFIELD:        /* 2 -> 0 */
836         case ICMD_PUTSTATIC:       /* 1 -> 0 */
837         case ICMD_GETSTATIC:       /* 0 -> 1 */
838         case ICMD_PUTSTATICCONST:  /* 0 -> 0 */
839         case ICMD_PUTFIELDCONST:   /* 1 -> 0 */
840                 if (opcode != ICMD_GETSTATIC && opcode != ICMD_PUTSTATICCONST) {
841                         SHOW_S1(iptr);
842                         if (opcode == ICMD_PUTFIELD) {
843                                 SHOW_S2(iptr);
844                         }
845                 }
846                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
847                 SHOW_FIELD(fmiref);
848
849                 if (opcode == ICMD_GETSTATIC || opcode == ICMD_GETFIELD) {
850                         SHOW_DST(iptr);
851                 }
852                 break;
853
854         case ICMD_IINC:
855                 SHOW_S1_LOCAL(iptr);
856                 SHOW_INT_CONST(iptr->sx.val.i);
857                 SHOW_DST_LOCAL(iptr);
858                 break;
859
860         case ICMD_IASTORE:
861         case ICMD_SASTORE:
862         case ICMD_BASTORE:
863         case ICMD_CASTORE:
864         case ICMD_LASTORE:
865         case ICMD_DASTORE:
866         case ICMD_FASTORE:
867         case ICMD_AASTORE:
868                 SHOW_S1(iptr);
869                 SHOW_S2(iptr);
870                 SHOW_S3(iptr);
871                 break;
872
873         case ICMD_IALOAD:
874         case ICMD_SALOAD:
875         case ICMD_BALOAD:
876         case ICMD_CALOAD:
877         case ICMD_LALOAD:
878         case ICMD_DALOAD:
879         case ICMD_FALOAD:
880         case ICMD_AALOAD:
881                 SHOW_S1(iptr);
882                 SHOW_S2(iptr);
883                 SHOW_DST(iptr);
884                 break;
885
886         case ICMD_RET:
887                 SHOW_S1_LOCAL(iptr);
888                 break;
889
890         case ICMD_ILOAD:
891         case ICMD_LLOAD:
892         case ICMD_FLOAD:
893         case ICMD_DLOAD:
894         case ICMD_ALOAD:
895                 SHOW_S1_LOCAL(iptr);
896                 SHOW_DST(iptr);
897                 break;
898
899         case ICMD_ISTORE:
900         case ICMD_LSTORE:
901         case ICMD_FSTORE:
902         case ICMD_DSTORE:
903         case ICMD_ASTORE:
904                 SHOW_S1(iptr);
905                 SHOW_DST_LOCAL(iptr);
906                 break;
907
908         case ICMD_NEW:
909                 SHOW_DST(iptr);
910                 break;
911
912         case ICMD_NEWARRAY:
913                 SHOW_DST(iptr);
914                 break;
915
916         case ICMD_ANEWARRAY:
917                 SHOW_DST(iptr);
918                 break;
919
920         case ICMD_MULTIANEWARRAY:
921                 if (stage >= SHOW_STACK) {
922                         argp = iptr->sx.s23.s2.args;
923                         i = iptr->s1.argcount;
924                         while (i--) {
925                                 SHOW_STACKVAR(*(argp++));
926                         }
927                 }
928                 else {
929                         printf("argcount=%d ", iptr->s1.argcount);
930                 }
931                 SHOW_DST(iptr);
932                 break;
933
934         case ICMD_CHECKCAST:
935                 SHOW_S1(iptr);
936                 SHOW_DST(iptr);
937                 break;
938
939         case ICMD_INSTANCEOF:
940                 SHOW_S1(iptr);
941                 SHOW_DST(iptr);
942                 break;
943
944         case ICMD_INLINE_START:
945         case ICMD_INLINE_END:
946                 break;
947
948         case ICMD_BUILTIN:
949                 if (stage >= SHOW_STACK) {
950                         argp = iptr->sx.s23.s2.args;
951                         i = iptr->s1.argcount;
952                         while (i--) {
953                                 if ((iptr->s1.argcount - 1 - i) == iptr->sx.s23.s3.bte->md->paramcount)
954                                         printf(" pass-through: ");
955                                 SHOW_STACKVAR(*(argp++));
956                         }
957                 }
958                 printf("%s ", iptr->sx.s23.s3.bte->cname);
959                 if (iptr->sx.s23.s3.bte->md->returntype.type != TYPE_VOID) {
960                         SHOW_DST(iptr);
961                 }
962                 break;
963
964         case ICMD_INVOKEVIRTUAL:
965         case ICMD_INVOKESPECIAL:
966         case ICMD_INVOKESTATIC:
967         case ICMD_INVOKEINTERFACE:
968                 if (stage >= SHOW_STACK) {
969                         methoddesc *md;
970                         INSTRUCTION_GET_METHODDESC(iptr, md);
971                         argp = iptr->sx.s23.s2.args;
972                         i = iptr->s1.argcount;
973                         while (i--) {
974                                 if ((iptr->s1.argcount - 1 - i) == md->paramcount)
975                                         printf(" pass-through: ");
976                                 SHOW_STACKVAR(*(argp++));
977                         }
978                 }
979                 INSTRUCTION_GET_METHODREF(iptr, fmiref);
980                 method_methodref_print(fmiref);
981                 if (fmiref->parseddesc.md->returntype.type != TYPE_VOID) {
982                         SHOW_DST(iptr);
983                 }
984                 break;
985
986         case ICMD_IFEQ:
987         case ICMD_IFNE:
988         case ICMD_IFLT:
989         case ICMD_IFGE:
990         case ICMD_IFGT:
991         case ICMD_IFLE:
992                 SHOW_S1(iptr);
993                 SHOW_TARGET(iptr->dst);
994                 break;
995
996         case ICMD_IF_LEQ:
997         case ICMD_IF_LNE:
998         case ICMD_IF_LLT:
999         case ICMD_IF_LGE:
1000         case ICMD_IF_LGT:
1001         case ICMD_IF_LLE:
1002                 SHOW_S1(iptr);
1003                 SHOW_TARGET(iptr->dst);
1004                 break;
1005
1006         case ICMD_GOTO:
1007         case ICMD_INLINE_GOTO:
1008                 SHOW_TARGET(iptr->dst);
1009                 break;
1010
1011         case ICMD_JSR:
1012                 SHOW_TARGET(iptr->sx.s23.s3.jsrtarget);
1013                 SHOW_DST(iptr);
1014                 break;
1015
1016         case ICMD_IFNULL:
1017         case ICMD_IFNONNULL:
1018                 SHOW_S1(iptr);
1019                 SHOW_TARGET(iptr->dst);
1020                 break;
1021
1022         case ICMD_IF_ICMPEQ:
1023         case ICMD_IF_ICMPNE:
1024         case ICMD_IF_ICMPLT:
1025         case ICMD_IF_ICMPGE:
1026         case ICMD_IF_ICMPGT:
1027         case ICMD_IF_ICMPLE:
1028
1029         case ICMD_IF_LCMPEQ:
1030         case ICMD_IF_LCMPNE:
1031         case ICMD_IF_LCMPLT:
1032         case ICMD_IF_LCMPGE:
1033         case ICMD_IF_LCMPGT:
1034         case ICMD_IF_LCMPLE:
1035
1036         case ICMD_IF_FCMPEQ:
1037         case ICMD_IF_FCMPNE:
1038
1039         case ICMD_IF_FCMPL_LT:
1040         case ICMD_IF_FCMPL_GE:
1041         case ICMD_IF_FCMPL_GT:
1042         case ICMD_IF_FCMPL_LE:
1043
1044         case ICMD_IF_FCMPG_LT:
1045         case ICMD_IF_FCMPG_GE:
1046         case ICMD_IF_FCMPG_GT:
1047         case ICMD_IF_FCMPG_LE:
1048
1049         case ICMD_IF_DCMPEQ:
1050         case ICMD_IF_DCMPNE:
1051
1052         case ICMD_IF_DCMPL_LT:
1053         case ICMD_IF_DCMPL_GE:
1054         case ICMD_IF_DCMPL_GT:
1055         case ICMD_IF_DCMPL_LE:
1056
1057         case ICMD_IF_DCMPG_LT:
1058         case ICMD_IF_DCMPG_GE:
1059         case ICMD_IF_DCMPG_GT:
1060         case ICMD_IF_DCMPG_LE:
1061
1062         case ICMD_IF_ACMPEQ:
1063         case ICMD_IF_ACMPNE:
1064                 SHOW_S1(iptr);
1065                 SHOW_S2(iptr);
1066                 SHOW_TARGET(iptr->dst);
1067                 break;
1068
1069         case ICMD_TABLESWITCH:
1070                 SHOW_S1(iptr);
1071                 table = iptr->dst.table;
1072
1073                 i = iptr->sx.s23.s3.tablehigh
1074                         - iptr->sx.s23.s2.tablelow + 1;
1075
1076                 printf("high=%d low=%d count=%d\n", iptr->sx.s23.s3.tablehigh, iptr->sx.s23.s2.tablelow, i);
1077                 while (--i >= 0) {
1078                         printf("\t\t%d --> ", table - iptr->dst.table);
1079                         if (stage >= SHOW_STACK) {
1080                                 printf("L%03d\n", table->block->nr);
1081                         }
1082                         else {
1083                                 printf("insindex %d (L%03d)\n", table->insindex, BLOCK_OF(table->insindex)->nr);
1084                         }
1085                         table++;
1086                 }
1087
1088                 break;
1089
1090         case ICMD_LOOKUPSWITCH:
1091                 SHOW_S1(iptr);
1092
1093                 printf("count=%d, default=", iptr->sx.s23.s2.lookupcount);
1094                 if (stage >= SHOW_STACK) {
1095                         printf("L%03d\n", iptr->sx.s23.s3.lookupdefault.block->nr);
1096                 }
1097                 else {
1098                         printf("insindex %d (L%03d)\n", iptr->sx.s23.s3.lookupdefault.insindex, BLOCK_OF(iptr->sx.s23.s3.lookupdefault.insindex)->nr);
1099                 }
1100
1101                 lookup = iptr->dst.lookup;
1102                 i = iptr->sx.s23.s2.lookupcount;
1103                 while (--i >= 0) {
1104                         printf("\t\t%d --> ", lookup->value);
1105                         if (stage >= SHOW_STACK) {
1106                                 printf("L%03d\n", lookup->target.block->nr);
1107                         }
1108                         else {
1109                                 printf("insindex %d (L%03d)\n", lookup->target.insindex, BLOCK_OF(lookup->target.insindex)->nr);
1110                         }
1111                         lookup++;
1112                 }
1113                 break;
1114
1115         case ICMD_ARETURN:
1116                 SHOW_S1(iptr);
1117                 break;
1118
1119         case ICMD_ATHROW:
1120                 SHOW_S1(iptr);
1121                 break;
1122
1123         case ICMD_DUP:
1124 /*      case ICMD_COPY: */
1125 /*      case ICMD_MOVE: */
1126                 SHOW_S1(iptr);
1127                 SHOW_DST(iptr);
1128                 break;
1129
1130         case ICMD_DUP2:
1131                 if (stage >= SHOW_STACK) {
1132                         SHOW_STACKVAR(iptr->dst.dupslots[0]);
1133                         SHOW_STACKVAR(iptr->dst.dupslots[1]);
1134                         printf("=> ");
1135                         SHOW_STACKVAR(iptr->dst.dupslots[2+0]);
1136                         SHOW_STACKVAR(iptr->dst.dupslots[2+1]);
1137                 }
1138                 break;
1139
1140         case ICMD_DUP_X1:
1141                 if (stage >= SHOW_STACK) {
1142                         SHOW_STACKVAR(iptr->dst.dupslots[0]);
1143                         SHOW_STACKVAR(iptr->dst.dupslots[1]);
1144                         printf("=> ");
1145                         SHOW_STACKVAR(iptr->dst.dupslots[2+0]);
1146                         SHOW_STACKVAR(iptr->dst.dupslots[2+1]);
1147                         SHOW_STACKVAR(iptr->dst.dupslots[2+2]);
1148                 }
1149                 break;
1150
1151         case ICMD_DUP2_X1:
1152                 if (stage >= SHOW_STACK) {
1153                         SHOW_STACKVAR(iptr->dst.dupslots[0]);
1154                         SHOW_STACKVAR(iptr->dst.dupslots[1]);
1155                         SHOW_STACKVAR(iptr->dst.dupslots[2]);
1156                         printf("=> ");
1157                         SHOW_STACKVAR(iptr->dst.dupslots[3+0]);
1158                         SHOW_STACKVAR(iptr->dst.dupslots[3+1]);
1159                         SHOW_STACKVAR(iptr->dst.dupslots[3+2]);
1160                         SHOW_STACKVAR(iptr->dst.dupslots[3+3]);
1161                         SHOW_STACKVAR(iptr->dst.dupslots[3+4]);
1162                 }
1163                 break;
1164
1165         case ICMD_DUP_X2:
1166                 if (stage >= SHOW_STACK) {
1167                         SHOW_STACKVAR(iptr->dst.dupslots[0]);
1168                         SHOW_STACKVAR(iptr->dst.dupslots[1]);
1169                         SHOW_STACKVAR(iptr->dst.dupslots[2]);
1170                         printf("=> ");
1171                         SHOW_STACKVAR(iptr->dst.dupslots[3+0]);
1172                         SHOW_STACKVAR(iptr->dst.dupslots[3+1]);
1173                         SHOW_STACKVAR(iptr->dst.dupslots[3+2]);
1174                         SHOW_STACKVAR(iptr->dst.dupslots[3+3]);
1175                 }
1176                 break;
1177
1178         case ICMD_DUP2_X2:
1179                 if (stage >= SHOW_STACK) {
1180                         SHOW_STACKVAR(iptr->dst.dupslots[0]);
1181                         SHOW_STACKVAR(iptr->dst.dupslots[1]);
1182                         SHOW_STACKVAR(iptr->dst.dupslots[2]);
1183                         SHOW_STACKVAR(iptr->dst.dupslots[4]);
1184                         printf("=> ");
1185                         SHOW_STACKVAR(iptr->dst.dupslots[4+0]);
1186                         SHOW_STACKVAR(iptr->dst.dupslots[4+1]);
1187                         SHOW_STACKVAR(iptr->dst.dupslots[4+2]);
1188                         SHOW_STACKVAR(iptr->dst.dupslots[4+3]);
1189                         SHOW_STACKVAR(iptr->dst.dupslots[4+4]);
1190                         SHOW_STACKVAR(iptr->dst.dupslots[4+5]);
1191                 }
1192                 break;
1193
1194         case ICMD_SWAP:
1195                 if (stage >= SHOW_STACK) {
1196                         SHOW_STACKVAR(iptr->dst.dupslots[0]);
1197                         SHOW_STACKVAR(iptr->dst.dupslots[1]);
1198                         printf("=> ");
1199                         SHOW_STACKVAR(iptr->dst.dupslots[2+0]);
1200                         SHOW_STACKVAR(iptr->dst.dupslots[2+1]);
1201                 }
1202                 break;
1203
1204         }
1205         fflush(stdout);
1206 }
1207 #endif /* !defined(NDEBUG) */
1208
1209
1210 /*
1211  * These are local overrides for various environment variables in Emacs.
1212  * Please do not remove this and leave it at the end of the file, where
1213  * Emacs will automagically detect them.
1214  * ---------------------------------------------------------------------
1215  * Local variables:
1216  * mode: c
1217  * indent-tabs-mode: t
1218  * c-basic-offset: 4
1219  * tab-width: 4
1220  * End:
1221  * vim:noexpandtab:sw=4:ts=4:
1222  */