* src/vm/jit/jit.h (basicblock): Changed type of iinstr to
[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->new_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         new_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                         printf("\n");
438                         u1ptr = (u1 *) (code->mcode + cd->dseglen + bptr->mpc);
439
440                         if (bptr->next != NULL) {
441                                 for (; u1ptr < (u1 *) (code->mcode + cd->dseglen + bptr->next->mpc);)
442                                         DISASSINSTR(u1ptr);
443
444                         } 
445                         else {
446                                 for (; u1ptr < (u1 *) (code->mcode + code->mcodelength);)
447                                         DISASSINSTR(u1ptr); 
448                         }
449                         printf("\n");
450                 }
451 #endif
452         }
453 }
454 #endif /* !defined(NDEBUG) */
455
456
457 /* show_icmd *******************************************************************
458
459    Print the intermediate representation of an instruction.
460
461    NOTE: Currently this function may only be called after register allocation!
462
463 *******************************************************************************/
464
465 #if !defined(NDEBUG)
466
467 #define SHOW_TARGET(target)                                          \
468         if (stage >= SHOW_STACK) {                                   \
469             printf("--> L%03d ", (target).block->nr);                \
470         }                                                            \
471         else if (stage >= SHOW_PARSE) {                              \
472             printf("--> insindex %d (L%03d) ", (target).insindex,    \
473                 jd->new_basicblocks[jd->new_basicblockindex[         \
474                 (target).insindex]].nr);                             \
475         }                                                            \
476         else {                                                       \
477             printf("--> insindex %d ", (target).insindex);           \
478         }
479
480 #define SHOW_INT_CONST(val)                                          \
481         if (stage >= SHOW_PARSE) {                                   \
482             printf("%ld ", (long) (val));                            \
483         }                                                            \
484         else {                                                       \
485             printf("iconst ");                                       \
486         }
487
488 #define SHOW_LNG_CONST(val)                                          \
489         if (stage >= SHOW_PARSE) {                                   \
490             printf("%lld ", (long long)(val));                       \
491         }                                                            \
492         else {                                                       \
493             printf("lconst ");                                       \
494         }
495
496 #define SHOW_FLT_CONST(val)                                          \
497         if (stage >= SHOW_PARSE) {                                   \
498             printf("%g ", (val));                                    \
499         }                                                            \
500         else {                                                       \
501             printf("fconst ");                                       \
502         }
503
504 #define SHOW_DBL_CONST(val)                                          \
505         if (stage >= SHOW_PARSE) {                                   \
506             printf("%g ", (val));                                    \
507         }                                                            \
508         else {                                                       \
509             printf("dconst ");                                       \
510         }
511
512 #define SHOW_INDEX(index)                                            \
513         if (stage >= SHOW_PARSE) {                                   \
514             printf("%d ", index);                                    \
515         }                                                            \
516         else {                                                       \
517             printf("index");                                         \
518         }
519
520 #define SHOW_STRING(val)                                             \
521         if (stage >= SHOW_PARSE) {                                   \
522             putchar('"');                                            \
523             utf_display_printable_ascii(                             \
524                 javastring_toutf((java_lang_String *)(val), false)); \
525             printf("\" ");                                           \
526         }                                                            \
527         else {                                                       \
528             printf("string ");                                       \
529         }
530
531 #define SHOW_CLASSREF_OR_CLASSINFO(c)                                \
532         if (stage >= SHOW_PARSE) {                                   \
533             if (IS_CLASSREF(c))                                      \
534                 class_classref_print(c.ref);                         \
535             else                                                     \
536                 class_print(c.cls);                                  \
537             putchar(' ');                                            \
538         }                                                            \
539         else {                                                       \
540             printf("class ");                                        \
541         }
542
543 #define SHOW_FIELD(fmiref)                                           \
544         if (stage >= SHOW_PARSE) {                                   \
545             field_fieldref_print(fmiref);                            \
546             putchar(' ');                                            \
547         }                                                            \
548         else {                                                       \
549             printf("field ");                                        \
550         }
551
552 #define SHOW_STACKVAR(sp)                                            \
553         new_show_stackvar(jd, (sp), stage)
554
555 #define SHOW_S1(iptr)                                                \
556         if (stage >= SHOW_STACK) {                                   \
557             SHOW_STACKVAR(iptr->s1.var);                             \
558         }
559
560 #define SHOW_S2(iptr)                                                \
561         if (stage >= SHOW_STACK) {                                   \
562             SHOW_STACKVAR(iptr->sx.s23.s2.var);                      \
563         }
564
565 #define SHOW_S3(iptr)                                                \
566         if (stage >= SHOW_STACK) {                                   \
567             SHOW_STACKVAR(iptr->sx.s23.s3.var);                      \
568         }
569
570 #define SHOW_DST(iptr)                                               \
571         if (stage >= SHOW_STACK) {                                   \
572             printf("=> ");                                           \
573             SHOW_STACKVAR(iptr->dst.var);                            \
574         }
575
576 #define SHOW_S1_LOCAL(iptr)                                          \
577         if (stage >= SHOW_STACK) {                                   \
578             printf("L%d ", iptr->s1.localindex);                     \
579         }
580
581 #define SHOW_DST_LOCAL(iptr)                                         \
582         if (stage >= SHOW_STACK) {                                   \
583             printf("=> L%d ", iptr->dst.localindex);                 \
584         }
585
586 static void new_show_stackvar(jitdata *jd, stackptr sp, int stage)
587 {
588         char type;
589
590         switch (sp->type) {
591                 case TYPE_INT: type = 'i'; break;
592                 case TYPE_LNG: type = 'l'; break;
593                 case TYPE_FLT: type = 'f'; break;
594                 case TYPE_DBL: type = 'd'; break;
595                 case TYPE_ADR: type = 'a'; break;
596                 default:       type = '?';
597         }
598         printf("S%c%d", type, (int) (sp - jd->new_stack));
599
600         if (stage >= SHOW_REGS) {
601                 putchar('(');
602
603                 if (sp->flags & SAVEDVAR) {
604                         switch (sp->varkind) {
605                         case TEMPVAR:
606                                 if (sp->flags & INMEMORY)
607                                         printf("M%02d", sp->regoff);
608 #ifdef HAS_ADDRESS_REGISTER_FILE
609                                 else if (sp->type == TYPE_ADR)
610                                         printf("R%02d", sp->regoff);
611 #endif
612                                 else if (IS_FLT_DBL_TYPE(sp->type))
613                                         printf("F%02d", sp->regoff);
614                                 else {
615 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
616                                         if (IS_2_WORD_TYPE(sp->type)) {
617 # if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
618 #  if defined(ENABLE_INTRP)
619                                                 if (opt_intrp)
620                                                         printf("%3d/%3d", GET_LOW_REG(sp->regoff),
621                                                                    GET_HIGH_REG(sp->regoff));
622                                                 else
623 #  endif
624                                                         printf("%3s/%3s", regs[GET_LOW_REG(sp->regoff)],
625                                                                    regs[GET_HIGH_REG(sp->regoff)]);
626 # else
627                                                 printf("%3d/%3d", GET_LOW_REG(sp->regoff),
628                                                            GET_HIGH_REG(sp->regoff));
629 # endif
630                                         } 
631                                         else 
632 #endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
633                                                 {
634 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
635 # if defined(ENABLE_INTRP)
636                                                         if (opt_intrp)
637                                                                 printf("%3d", sp->regoff);
638                                                         else
639 # endif
640                                                                 printf("%3s", regs[sp->regoff]);
641 #else
642                                                         printf("%3d", sp->regoff);
643 #endif
644                                                 }
645                                 }
646                                 break;
647                         case STACKVAR:
648                                 printf("I%02d", sp->varnum);
649                                 break;
650                         case LOCALVAR:
651                                 printf("L%02d", sp->varnum);
652                                 break;
653                         case ARGVAR:
654                                 if (sp->varnum == -1) {
655                                         /* Return Value                                  */
656                                         /* varkind ARGVAR "misused for this special case */
657                                         printf(" V0");
658                                 } 
659                                 else /* "normal" Argvar */
660                                         printf("A%02d", sp->varnum);
661                                 break;
662                         default:
663                                 printf("!xx {kind=%d, num=%d}", sp->varkind, sp->varnum);
664                         }
665                 }
666                 else { /* not SAVEDVAR */
667                         switch (sp->varkind) {
668                         case TEMPVAR:
669                                 if (sp->flags & INMEMORY)
670                                         printf("m%02d", sp->regoff);
671 #ifdef HAS_ADDRESS_REGISTER_FILE
672                                 else if (sp->type == TYPE_ADR)
673                                         printf("r%02d", sp->regoff);
674 #endif
675                                 else if (IS_FLT_DBL_TYPE(sp->type))
676                                         printf("f%02d", sp->regoff);
677                                 else {
678 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
679                                         if (IS_2_WORD_TYPE(sp->type)) {
680 # if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
681 #  if defined(ENABLE_INTRP)
682                                                 if (opt_intrp)
683                                                         printf("%3d/%3d", GET_LOW_REG(sp->regoff),
684                                                                    GET_HIGH_REG(sp->regoff));
685                                                 else
686 #  endif
687                                                         printf("%3s/%3s", regs[GET_LOW_REG(sp->regoff)],
688                                                                    regs[GET_HIGH_REG(sp->regoff)]);
689 # else
690                                                 printf("%3d/%3d", GET_LOW_REG(sp->regoff),
691                                                            GET_HIGH_REG(sp->regoff));
692 # endif
693                                         } 
694                                         else
695 #endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
696                                                 {
697 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
698 # if defined(ENABLE_INTRP)
699                                                         if (opt_intrp)
700                                                                 printf("%3d", sp->regoff);
701                                                         else
702 # endif
703                                                                 printf("%3s", regs[sp->regoff]);
704 #else
705                                                         printf("%3d", sp->regoff);
706 #endif
707                                                 }
708                                 }
709                                 break;
710                         case STACKVAR:
711                                 printf("i%02d", sp->varnum);
712                                 break;
713                         case LOCALVAR:
714                                 printf("l%02d", sp->varnum);
715                                 break;
716                         case ARGVAR:
717                                 if (sp->varnum == -1) {
718                                         /* Return Value                                  */
719                                         /* varkind ARGVAR "misused for this special case */
720                                         printf(" v0");
721                                 } 
722                                 else /* "normal" Argvar */
723                                 printf("a%02d", sp->varnum);
724                                 break;
725                         default:
726                                 printf("?xx {kind=%d, num=%d}", sp->varkind, sp->varnum);
727                         }
728                 }
729
730                 putchar(')');
731         }
732         putchar(' ');
733 }
734
735 static void new_show_variable_array(jitdata *jd, stackptr *vars, int n, int stage)
736 {
737         int i;
738
739         printf("[");
740         for (i=0; i<n; ++i) {
741                 if (i)
742                         printf(" ");
743                 new_show_stackvar(jd, vars[i], stage);
744         }
745         printf("]");
746 }
747
748 void new_show_icmd(jitdata *jd, new_instruction *iptr, bool deadcode, int stage)
749 {
750         u2                 opcode;
751         branch_target_t   *table;
752         lookup_target_t   *lookup;
753         constant_FMIref   *fmiref;
754         stackptr          *argp;
755         s4                 i;
756
757         /* get the opcode and the condition */
758
759         opcode    =  iptr->opc;
760
761         printf("%s ", icmd_names[opcode]);
762
763         if (stage < SHOW_PARSE)
764                 return;
765
766         if (deadcode)
767                 stage = SHOW_PARSE;
768
769         /* Print the condition for conditional instructions. */
770
771         /* XXX print condition from flags */
772
773         if (iptr->flags.bits & INS_FLAG_UNRESOLVED)
774                 printf("(UNRESOLVED) ");
775
776         switch (opcode) {
777
778         case ICMD_POP:
779         case ICMD_CHECKNULL:
780         case ICMD_CHECKNULL_POP:
781                 SHOW_S1(iptr);
782                 break;
783
784                 /* unary */
785         case ICMD_ARRAYLENGTH:
786         case ICMD_INEG:
787         case ICMD_LNEG:
788         case ICMD_FNEG:
789         case ICMD_DNEG:
790         case ICMD_I2L:
791         case ICMD_I2F:
792         case ICMD_I2D:
793         case ICMD_L2I:
794         case ICMD_L2F:
795         case ICMD_L2D:
796         case ICMD_F2I:
797         case ICMD_F2L:
798         case ICMD_F2D:
799         case ICMD_D2I:
800         case ICMD_D2L:
801         case ICMD_D2F:
802         case ICMD_INT2BYTE:
803         case ICMD_INT2CHAR:
804         case ICMD_INT2SHORT:
805                 SHOW_S1(iptr);
806                 SHOW_DST(iptr);
807                 break;
808
809                 /* binary */
810         case ICMD_IADD:
811         case ICMD_LADD:
812         case ICMD_FADD:
813         case ICMD_DADD:
814         case ICMD_ISUB:
815         case ICMD_LSUB:
816         case ICMD_FSUB:
817         case ICMD_DSUB:
818         case ICMD_IMUL:
819         case ICMD_LMUL:
820         case ICMD_FMUL:
821         case ICMD_DMUL:
822         case ICMD_IDIV:
823         case ICMD_LDIV:
824         case ICMD_FDIV:
825         case ICMD_DDIV:
826         case ICMD_IREM:
827         case ICMD_LREM:
828         case ICMD_FREM:
829         case ICMD_DREM:
830         case ICMD_ISHL:
831         case ICMD_LSHL:
832         case ICMD_ISHR:
833         case ICMD_LSHR:
834         case ICMD_IUSHR:
835         case ICMD_LUSHR:
836         case ICMD_IAND:
837         case ICMD_LAND:
838         case ICMD_IOR:
839         case ICMD_LOR:
840         case ICMD_IXOR:
841         case ICMD_LXOR:
842         case ICMD_LCMP:
843         case ICMD_FCMPL:
844         case ICMD_FCMPG:
845         case ICMD_DCMPL:
846         case ICMD_DCMPG:
847                 SHOW_S1(iptr);
848                 SHOW_S2(iptr);
849                 SHOW_DST(iptr);
850                 break;
851
852                 /* binary/const INT */
853         case ICMD_IADDCONST:
854         case ICMD_ISUBCONST:
855         case ICMD_IMULCONST:
856         case ICMD_IMULPOW2:
857         case ICMD_IDIVPOW2:
858         case ICMD_IREMPOW2:
859         case ICMD_IANDCONST:
860         case ICMD_IORCONST:
861         case ICMD_IXORCONST:
862         case ICMD_ISHLCONST:
863         case ICMD_ISHRCONST:
864         case ICMD_IUSHRCONST:
865         case ICMD_LSHLCONST:
866         case ICMD_LSHRCONST:
867         case ICMD_LUSHRCONST:
868                 SHOW_S1(iptr);
869                 SHOW_INT_CONST(iptr->sx.val.i); 
870                 SHOW_DST(iptr);
871                 break;
872
873                 /* ?ASTORECONST (trinary/const INT) */
874         case ICMD_IASTORECONST:
875         case ICMD_BASTORECONST:
876         case ICMD_CASTORECONST:
877         case ICMD_SASTORECONST:
878                 SHOW_S1(iptr);
879                 SHOW_S2(iptr);
880                 SHOW_INT_CONST(iptr->sx.s23.s3.constval);
881                 break;
882
883                 /* const INT */
884         case ICMD_ICONST:
885                 SHOW_INT_CONST(iptr->sx.val.i); 
886                 SHOW_DST(iptr);
887                 break;
888
889                 /* binary/const LNG */
890         case ICMD_LADDCONST:
891         case ICMD_LSUBCONST:
892         case ICMD_LMULCONST:
893         case ICMD_LMULPOW2:
894         case ICMD_LDIVPOW2:
895         case ICMD_LREMPOW2:
896         case ICMD_LANDCONST:
897         case ICMD_LORCONST:
898         case ICMD_LXORCONST:
899                 SHOW_S1(iptr);
900                 SHOW_LNG_CONST(iptr->sx.val.l); 
901                 SHOW_DST(iptr);
902                 break;
903
904                 /* trinary/const LNG (<= pointer size) */
905         case ICMD_LASTORECONST:
906                 SHOW_S1(iptr);
907                 SHOW_S2(iptr);
908                 SHOW_LNG_CONST(iptr->sx.s23.s3.constval);
909                 break;
910
911                 /* const LNG */
912         case ICMD_LCONST:
913                 SHOW_LNG_CONST(iptr->sx.val.l); 
914                 SHOW_DST(iptr);
915                 break;
916
917                 /* const FLT */
918         case ICMD_FCONST:
919                 SHOW_FLT_CONST(iptr->sx.val.f); 
920                 SHOW_DST(iptr);
921                 break;
922
923                 /* const DBL */
924         case ICMD_DCONST:
925                 SHOW_DBL_CONST(iptr->sx.val.d); 
926                 SHOW_DST(iptr);
927                 break;
928
929                 /* const ADR */
930         case ICMD_ACONST:
931                 if (iptr->flags.bits & INS_FLAG_CLASS) {
932                         SHOW_CLASSREF_OR_CLASSINFO(iptr->sx.val.c);
933                 }
934                 else if (iptr->sx.val.anyptr == NULL) {
935                         printf("NULL ");
936                 }
937                 else {
938                         SHOW_STRING(iptr->sx.val.stringconst);
939                 }
940                 SHOW_DST(iptr);
941                 break;
942
943         case ICMD_AASTORECONST:
944                 SHOW_S1(iptr);
945                 SHOW_S2(iptr);
946                 printf("%p ", (void*) iptr->sx.s23.s3.constval);
947                 break;
948
949         case ICMD_GETFIELD:        /* 1 -> 1 */
950         case ICMD_PUTFIELD:        /* 2 -> 0 */
951         case ICMD_PUTSTATIC:       /* 1 -> 0 */
952         case ICMD_GETSTATIC:       /* 0 -> 1 */
953         case ICMD_PUTSTATICCONST:  /* 0 -> 0 */
954         case ICMD_PUTFIELDCONST:   /* 1 -> 0 */
955                 if (opcode != ICMD_GETSTATIC && opcode != ICMD_PUTSTATICCONST) {
956                         SHOW_S1(iptr);
957                         if (opcode == ICMD_PUTFIELD) {
958                                 SHOW_S2(iptr);
959                         }
960                 }
961                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
962                 SHOW_FIELD(fmiref);
963
964                 if (opcode == ICMD_GETSTATIC || opcode == ICMD_GETFIELD) {
965                         SHOW_DST(iptr);
966                 }
967                 break;
968
969         case ICMD_IINC:
970                 SHOW_S1_LOCAL(iptr);
971                 SHOW_INT_CONST(iptr->sx.val.i);
972                 SHOW_DST_LOCAL(iptr);
973                 break;
974
975         case ICMD_IASTORE:
976         case ICMD_SASTORE:
977         case ICMD_BASTORE:
978         case ICMD_CASTORE:
979         case ICMD_LASTORE:
980         case ICMD_DASTORE:
981         case ICMD_FASTORE:
982         case ICMD_AASTORE:
983                 SHOW_S1(iptr);
984                 SHOW_S2(iptr);
985                 SHOW_S3(iptr);
986                 break;
987
988         case ICMD_IALOAD:
989         case ICMD_SALOAD:
990         case ICMD_BALOAD:
991         case ICMD_CALOAD:
992         case ICMD_LALOAD:
993         case ICMD_DALOAD:
994         case ICMD_FALOAD:
995         case ICMD_AALOAD:
996                 SHOW_S1(iptr);
997                 SHOW_S2(iptr);
998                 SHOW_DST(iptr);
999                 break;
1000
1001         case ICMD_RET:
1002                 SHOW_S1_LOCAL(iptr);
1003                 break;
1004
1005         case ICMD_ILOAD:
1006         case ICMD_LLOAD:
1007         case ICMD_FLOAD:
1008         case ICMD_DLOAD:
1009         case ICMD_ALOAD:
1010                 SHOW_S1_LOCAL(iptr);
1011                 SHOW_DST(iptr);
1012                 break;
1013
1014         case ICMD_ISTORE:
1015         case ICMD_LSTORE:
1016         case ICMD_FSTORE:
1017         case ICMD_DSTORE:
1018         case ICMD_ASTORE:
1019                 SHOW_S1(iptr);
1020                 SHOW_DST_LOCAL(iptr);
1021                 break;
1022
1023         case ICMD_NEW:
1024                 SHOW_DST(iptr);
1025                 break;
1026
1027         case ICMD_NEWARRAY:
1028                 SHOW_DST(iptr);
1029                 break;
1030
1031         case ICMD_ANEWARRAY:
1032                 SHOW_DST(iptr);
1033                 break;
1034
1035         case ICMD_MULTIANEWARRAY:
1036                 if (stage >= SHOW_STACK) {
1037                         argp = iptr->sx.s23.s2.args;
1038                         i = iptr->s1.argcount;
1039                         while (i--) {
1040                                 SHOW_STACKVAR(*(argp++));
1041                         }
1042                 }
1043                 else {
1044                         printf("argcount=%d ", iptr->s1.argcount);
1045                 }
1046                 SHOW_DST(iptr);
1047                 break;
1048
1049         case ICMD_CHECKCAST:
1050                 SHOW_S1(iptr);
1051                 SHOW_DST(iptr);
1052                 break;
1053
1054         case ICMD_INSTANCEOF:
1055                 SHOW_S1(iptr);
1056                 SHOW_DST(iptr);
1057                 break;
1058
1059         case ICMD_INLINE_START:
1060         case ICMD_INLINE_END:
1061                 break;
1062
1063         case ICMD_BUILTIN:
1064                 if (stage >= SHOW_STACK) {
1065                         argp = iptr->sx.s23.s2.args;
1066                         i = iptr->s1.argcount;
1067                         while (i--) {
1068                                 SHOW_STACKVAR(*(argp++));
1069                         }
1070                 }
1071                 printf("%s ", iptr->sx.s23.s3.bte->cname);
1072                 if (iptr->sx.s23.s3.bte->md->returntype.type != TYPE_VOID) {
1073                         SHOW_DST(iptr);
1074                 }
1075                 break;
1076
1077         case ICMD_INVOKEVIRTUAL:
1078         case ICMD_INVOKESPECIAL:
1079         case ICMD_INVOKESTATIC:
1080         case ICMD_INVOKEINTERFACE:
1081                 if (stage >= SHOW_STACK) {
1082                         argp = iptr->sx.s23.s2.args;
1083                         i = iptr->s1.argcount;
1084                         while (i--) {
1085                                 SHOW_STACKVAR(*(argp++));
1086                         }
1087                 }
1088                 INSTRUCTION_GET_METHODREF(iptr, fmiref);
1089                 method_methodref_print(fmiref);
1090                 if (fmiref->parseddesc.md->returntype.type != TYPE_VOID) {
1091                         SHOW_DST(iptr);
1092                 }
1093                 break;
1094
1095         case ICMD_IFEQ:
1096         case ICMD_IFNE:
1097         case ICMD_IFLT:
1098         case ICMD_IFGE:
1099         case ICMD_IFGT:
1100         case ICMD_IFLE:
1101                 SHOW_S1(iptr);
1102                 SHOW_TARGET(iptr->dst);
1103                 break;
1104
1105         case ICMD_IF_LEQ:
1106         case ICMD_IF_LNE:
1107         case ICMD_IF_LLT:
1108         case ICMD_IF_LGE:
1109         case ICMD_IF_LGT:
1110         case ICMD_IF_LLE:
1111                 SHOW_S1(iptr);
1112                 SHOW_TARGET(iptr->dst);
1113                 break;
1114
1115         case ICMD_GOTO:
1116         case ICMD_INLINE_GOTO:
1117                 SHOW_TARGET(iptr->dst);
1118                 break;
1119
1120         case ICMD_JSR:
1121                 SHOW_TARGET(iptr->sx.s23.s3.jsrtarget);
1122                 SHOW_DST(iptr);
1123                 break;
1124
1125         case ICMD_IFNULL:
1126         case ICMD_IFNONNULL:
1127                 SHOW_S1(iptr);
1128                 SHOW_TARGET(iptr->dst);
1129                 break;
1130
1131         case ICMD_IF_ICMPEQ:
1132         case ICMD_IF_ICMPNE:
1133         case ICMD_IF_ICMPLT:
1134         case ICMD_IF_ICMPGE:
1135         case ICMD_IF_ICMPGT:
1136         case ICMD_IF_ICMPLE:
1137
1138         case ICMD_IF_LCMPEQ:
1139         case ICMD_IF_LCMPNE:
1140         case ICMD_IF_LCMPLT:
1141         case ICMD_IF_LCMPGE:
1142         case ICMD_IF_LCMPGT:
1143         case ICMD_IF_LCMPLE:
1144
1145         case ICMD_IF_FCMPEQ:
1146         case ICMD_IF_FCMPNE:
1147
1148         case ICMD_IF_FCMPL_LT:
1149         case ICMD_IF_FCMPL_GE:
1150         case ICMD_IF_FCMPL_GT:
1151         case ICMD_IF_FCMPL_LE:
1152
1153         case ICMD_IF_FCMPG_LT:
1154         case ICMD_IF_FCMPG_GE:
1155         case ICMD_IF_FCMPG_GT:
1156         case ICMD_IF_FCMPG_LE:
1157
1158         case ICMD_IF_DCMPEQ:
1159         case ICMD_IF_DCMPNE:
1160
1161         case ICMD_IF_DCMPL_LT:
1162         case ICMD_IF_DCMPL_GE:
1163         case ICMD_IF_DCMPL_GT:
1164         case ICMD_IF_DCMPL_LE:
1165
1166         case ICMD_IF_DCMPG_LT:
1167         case ICMD_IF_DCMPG_GE:
1168         case ICMD_IF_DCMPG_GT:
1169         case ICMD_IF_DCMPG_LE:
1170
1171         case ICMD_IF_ACMPEQ:
1172         case ICMD_IF_ACMPNE:
1173                 SHOW_S1(iptr);
1174                 SHOW_S2(iptr);
1175                 SHOW_TARGET(iptr->dst);
1176                 break;
1177
1178         case ICMD_TABLESWITCH:
1179                 SHOW_S1(iptr);
1180                 break;
1181
1182         case ICMD_LOOKUPSWITCH:
1183                 SHOW_S1(iptr);
1184                 break;
1185
1186         case ICMD_ARETURN:
1187                 SHOW_S1(iptr);
1188                 break;
1189
1190         case ICMD_ATHROW:
1191                 SHOW_S1(iptr);
1192                 break;
1193
1194         case ICMD_DUP:
1195                 SHOW_S1(iptr);
1196                 SHOW_DST(iptr);
1197                 break;
1198
1199         case ICMD_DUP2:
1200                 if (stage >= SHOW_STACK) {
1201                         SHOW_STACKVAR(iptr->dst.dupslots[0]);
1202                         SHOW_STACKVAR(iptr->dst.dupslots[1]);
1203                         printf("=> ");
1204                         SHOW_STACKVAR(iptr->dst.dupslots[2+0]);
1205                         SHOW_STACKVAR(iptr->dst.dupslots[2+1]);
1206                 }
1207                 break;
1208
1209         case ICMD_DUP_X1:
1210                 if (stage >= SHOW_STACK) {
1211                         SHOW_STACKVAR(iptr->dst.dupslots[0]);
1212                         SHOW_STACKVAR(iptr->dst.dupslots[1]);
1213                         printf("=> ");
1214                         SHOW_STACKVAR(iptr->dst.dupslots[2+0]);
1215                         SHOW_STACKVAR(iptr->dst.dupslots[2+1]);
1216                         SHOW_STACKVAR(iptr->dst.dupslots[2+2]);
1217                 }
1218                 break;
1219
1220         case ICMD_DUP2_X1:
1221                 if (stage >= SHOW_STACK) {
1222                         SHOW_STACKVAR(iptr->dst.dupslots[0]);
1223                         SHOW_STACKVAR(iptr->dst.dupslots[1]);
1224                         SHOW_STACKVAR(iptr->dst.dupslots[2]);
1225                         printf("=> ");
1226                         SHOW_STACKVAR(iptr->dst.dupslots[3+0]);
1227                         SHOW_STACKVAR(iptr->dst.dupslots[3+1]);
1228                         SHOW_STACKVAR(iptr->dst.dupslots[3+2]);
1229                         SHOW_STACKVAR(iptr->dst.dupslots[3+3]);
1230                         SHOW_STACKVAR(iptr->dst.dupslots[3+4]);
1231                 }
1232                 break;
1233
1234         case ICMD_DUP_X2:
1235                 if (stage >= SHOW_STACK) {
1236                         SHOW_STACKVAR(iptr->dst.dupslots[0]);
1237                         SHOW_STACKVAR(iptr->dst.dupslots[1]);
1238                         SHOW_STACKVAR(iptr->dst.dupslots[2]);
1239                         printf("=> ");
1240                         SHOW_STACKVAR(iptr->dst.dupslots[3+0]);
1241                         SHOW_STACKVAR(iptr->dst.dupslots[3+1]);
1242                         SHOW_STACKVAR(iptr->dst.dupslots[3+2]);
1243                         SHOW_STACKVAR(iptr->dst.dupslots[3+3]);
1244                 }
1245                 break;
1246
1247         case ICMD_DUP2_X2:
1248                 if (stage >= SHOW_STACK) {
1249                         SHOW_STACKVAR(iptr->dst.dupslots[0]);
1250                         SHOW_STACKVAR(iptr->dst.dupslots[1]);
1251                         SHOW_STACKVAR(iptr->dst.dupslots[2]);
1252                         SHOW_STACKVAR(iptr->dst.dupslots[4]);
1253                         printf("=> ");
1254                         SHOW_STACKVAR(iptr->dst.dupslots[4+0]);
1255                         SHOW_STACKVAR(iptr->dst.dupslots[4+1]);
1256                         SHOW_STACKVAR(iptr->dst.dupslots[4+2]);
1257                         SHOW_STACKVAR(iptr->dst.dupslots[4+3]);
1258                         SHOW_STACKVAR(iptr->dst.dupslots[4+4]);
1259                         SHOW_STACKVAR(iptr->dst.dupslots[4+5]);
1260                 }
1261                 break;
1262
1263         case ICMD_SWAP:
1264                 if (stage >= SHOW_STACK) {
1265                         SHOW_STACKVAR(iptr->dst.dupslots[0]);
1266                         SHOW_STACKVAR(iptr->dst.dupslots[1]);
1267                         printf("=> ");
1268                         SHOW_STACKVAR(iptr->dst.dupslots[2+0]);
1269                         SHOW_STACKVAR(iptr->dst.dupslots[2+1]);
1270                 }
1271                 break;
1272
1273         }
1274 }
1275 #endif /* !defined(NDEBUG) */
1276
1277
1278 /*
1279  * These are local overrides for various environment variables in Emacs.
1280  * Please do not remove this and leave it at the end of the file, where
1281  * Emacs will automagically detect them.
1282  * ---------------------------------------------------------------------
1283  * Local variables:
1284  * mode: c
1285  * indent-tabs-mode: t
1286  * c-basic-offset: 4
1287  * tab-width: 4
1288  * End:
1289  * vim:noexpandtab:sw=4:ts=4:
1290  */