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