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