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