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