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