d4dad98c7c069427575e10ea835afc917db2e0b7
[cacao.git] / src / vm / jit / show.cpp
1 /* src/vm/jit/show.cpp - showing the intermediate representation
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <assert.h>
29 #include <stdint.h>
30
31 #include "vm/types.h"
32
33 #include "mm/memory.h"
34
35 #include "threads/lock.hpp"
36
37 #include "vm/global.h"
38 #include "vm/jit/builtin.hpp"
39 #include "vm/options.h"
40 #include "vm/string.hpp"
41 #include "vm/vm.hpp"
42
43 #include "vm/jit/abi.h"
44 #include "vm/jit/jit.hpp"
45 #include "vm/jit/show.hpp"
46 #include "vm/jit/disass.h"
47 #include "vm/jit/stack.h"
48 #include "vm/jit/parse.h"
49
50 #if defined(ENABLE_DEBUG_FILTER)
51 # include <sys/types.h>
52 # include <regex.h>
53 # include "threads/thread.hpp"
54 #endif
55
56
57 /* global variables ***********************************************************/
58
59 #if !defined(NDEBUG)
60 static Mutex mutex;
61 #endif
62
63
64 /* prototypes *****************************************************************/
65
66 #if !defined(NDEBUG)
67 static void show_variable_intern(jitdata *jd, s4 index, int stage);
68 #endif
69
70
71 /* show_init *******************************************************************
72
73    Initialized the show subsystem (called by jit_init).
74
75 *******************************************************************************/
76
77 #if !defined(NDEBUG)
78 bool show_init(void)
79 {
80 #if defined(ENABLE_DEBUG_FILTER)
81         show_filters_init();
82 #endif
83
84         /* everything's ok */
85
86         return true;
87 }
88 #endif
89
90
91 #if !defined(NDEBUG)
92 const char *show_jit_type_names[] = {
93         "INT",
94         "LNG",
95         "FLT",
96         "DBL",
97         "ADR",
98         "??5",
99         "??6",
100         "??7",
101         "RET"
102 };
103
104 const char show_jit_type_letters[] = {
105         'I',
106         'L',
107         'F',
108         'D',
109         'A',
110         '5',
111         '6',
112         '7',
113         'R'
114 };
115 #endif
116
117
118 /* show_method *****************************************************************
119
120    Print the intermediate representation of a method.
121
122    NOTE: Currently this function may only be called after register allocation!
123
124 *******************************************************************************/
125
126 #if !defined(NDEBUG)
127 void show_method(jitdata *jd, int stage)
128 {
129         methodinfo     *m;
130         codeinfo       *code;
131         codegendata    *cd;
132         registerdata   *rd;
133         basicblock     *bptr;
134         basicblock     *lastbptr;
135         exception_entry *ex;
136         s4              i, j;
137         int             irstage;
138 #if defined(ENABLE_DISASSEMBLER)
139         u1             *pc;
140 #endif
141
142         /* get required compiler data */
143
144         m    = jd->m;
145         code = jd->code;
146         cd   = jd->cd;
147         rd   = jd->rd;
148
149         // We need to enter a lock here, since the binutils disassembler
150         // is not reentrant-able and we could not read functions printed
151         // at the same time.
152         mutex.lock();
153
154 #if defined(ENABLE_INTRP)
155         if (opt_intrp)
156                 irstage = SHOW_PARSE;
157         else
158 #endif
159                 irstage = stage;
160
161         /* get the last basic block */
162
163         for (lastbptr = jd->basicblocks; lastbptr->next != NULL; lastbptr = lastbptr->next);
164
165         printf("\n");
166
167         method_println(m);
168
169         if (code_is_leafmethod(code))
170                 printf("LEAFMETHOD\n");
171
172         printf("\nBasic blocks: %d\n", jd->basicblockcount);
173         if (stage >= SHOW_CODE) {
174                 printf("Code length:  %d\n", (lastbptr->mpc - jd->basicblocks[0].mpc));
175                 printf("Data length:  %d\n", cd->dseglen);
176                 printf("Stub length:  %d\n", (s4) (code->mcodelength -
177                                                                                    ((ptrint) cd->dseglen + lastbptr->mpc)));
178         }
179         printf("Variables:       %d (%d used)\n", jd->varcount, jd->vartop);
180         if (stage >= SHOW_STACK)
181                 printf("Max interfaces:  %d\n", jd->maxinterfaces);
182         printf("Max locals:      %d\n", jd->maxlocals);
183         printf("Max stack:       %d\n", m->maxstack);
184         printf("Linenumbers:     %d\n", m->linenumbercount);
185         printf("Branch to entry: %s\n", (jd->branchtoentry) ? "yes" : "no");
186         printf("Branch to end:   %s\n", (jd->branchtoend) ? "yes" : "no");
187         if (stage >= SHOW_STACK) {
188                 printf("Number of RETURNs: %d", jd->returncount);
189                 if (jd->returncount == 1)
190                         printf(" (block L%03d)", jd->returnblock->nr);
191                 printf("\n");
192         }
193
194         if (stage >= SHOW_PARSE) {
195                 printf("Exceptions (Number: %d):\n", jd->exceptiontablelength);
196                 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
197                         printf("    L%03d ... ", ex->start->nr );
198                         printf("L%03d  = ", ex->end->nr);
199                         printf("L%03d", ex->handler->nr);
200                         printf("  (catchtype: ");
201                         if (ex->catchtype.any)
202                                 if (IS_CLASSREF(ex->catchtype))
203                                         class_classref_print(ex->catchtype.ref);
204                                 else
205                                         class_print(ex->catchtype.cls);
206                         else
207                                 printf("ANY");
208                         printf(")\n");
209                 }
210         }
211         
212         if (irstage >= SHOW_PARSE && rd && jd->localcount > 0) {
213                 printf("Local Table:\n");
214                 for (i = 0; i < jd->localcount; i++) {
215                         printf("   %3d: ", i);
216
217 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
218 # if defined(ENABLE_INTRP)
219                         if (!opt_intrp) {
220 # endif
221                                 printf("   (%s) ", show_jit_type_names[VAR(i)->type]);
222                                 if (irstage >= SHOW_REGS)
223                                         show_allocation(VAR(i)->type, VAR(i)->flags, VAR(i)->vv.regoff);
224                                 printf("\n");
225 # if defined(ENABLE_INTRP)
226                         }
227 # endif
228 #endif /* defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER) */
229                 }
230                 printf("\n");
231         }
232
233         if (jd->maxlocals > 0 && jd->local_map != NULL) {
234                 printf("Local Map:\n");
235                 printf("    index ");
236                 for (j = 0; j < jd->maxlocals; j++) {
237                         printf(" [%2d]", j);
238                 }
239                 printf("\n");
240                 for (i = 0; i < 5; i++) {
241                         printf("    %5s ",show_jit_type_names[i]);
242                         for (j = 0; j < jd->maxlocals; j++) {
243                                 if (jd->local_map[j*5+i] == UNUSED)
244                                         printf("  -- ");
245                                 else
246                                         printf("%4i ",jd->local_map[j*5+i]);
247                         }
248                         printf("\n");
249                 }
250                 printf("\n");
251         }
252
253         if (jd->maxinterfaces > 0 && jd->interface_map && irstage >= SHOW_STACK) {
254                 bool exist = false;
255                 interface_info *mapptr = jd->interface_map;
256                 
257                 /* look if there exist any INOUTS */
258                 for (i = 0; (i < (5 * jd->maxinterfaces)) && !exist; i++, mapptr++)
259                         exist = (mapptr->flags != UNUSED);
260
261                 if (exist) {
262                         printf("Interface Table: (In/Outvars)\n");
263                         printf("    depth ");
264                         for (j = 0; j < jd->maxinterfaces; j++) {
265                                 printf("      [%2d]", j);
266                         }
267                         printf("\n");
268
269                         for (i = 0; i < 5; i++) {
270                                 printf("    %5s      ",show_jit_type_names[i]);
271                                 for (j = 0; j < jd->maxinterfaces; j++) {
272                                         s4 flags  = jd->interface_map[j*5+i].flags;
273                                         s4 regoff = jd->interface_map[j*5+i].regoff;
274                                         if (flags == UNUSED)
275                                                 printf("  --      ");
276                                         else {
277                                                 int ch;
278
279                                                 if (irstage >= SHOW_REGS) {
280                                                         if (flags & SAVEDVAR) {
281                                                                 if (flags & INMEMORY)
282                                                                         ch = 'M';
283                                                                 else
284                                                                         ch = 'R';
285                                                         }
286                                                         else {
287                                                                 if (flags & INMEMORY)
288                                                                         ch = 'm';
289                                                                 else
290                                                                         ch = 'r';
291                                                         }
292                                                         printf("%c%03d(", ch, regoff);
293                                                         show_allocation(i, flags, regoff);
294                                                         printf(") ");
295                                                 }
296                                                 else {
297                                                         if (flags & SAVEDVAR)
298                                                                 printf("  I       ");
299                                                         else
300                                                                 printf("  i       ");
301                                                 }
302                                         }
303                                 }
304                                 printf("\n");
305                         }
306                         printf("\n");
307                 }
308         }
309
310         if (rd->memuse && irstage >= SHOW_REGS) {
311                 int max;
312
313                 max = rd->memuse;
314                 printf("Stack slots: (memuse=%d", rd->memuse);
315                 if (irstage >= SHOW_CODE) {
316                         printf(", stackframesize=%d", cd->stackframesize);
317                         max = cd->stackframesize;
318                 }
319                 printf(")\n");
320                 for (i = 0; i < max; ++i) {
321                         printf("    M%02d = 0x%02x(sp): ", i, i * 8);
322                         for (j = 0; j < jd->vartop; ++j) {
323                                 varinfo *v = VAR(j);
324                                 if ((v->flags & INMEMORY) && (v->vv.regoff == i)) {
325                                         show_variable(jd, j, irstage);
326                                         putchar(' ');
327                                 }
328                         }
329
330                         printf("\n");
331
332                 }
333                 printf("\n");
334         }
335
336 #if defined(ENABLE_REPLACEMENT)
337         if (code->rplpoints) {
338                 printf("Replacement Points:\n");
339                 replace_show_replacement_points(code);
340                 printf("\n");
341         }
342 #endif /* defined(ENABLE_REPLACEMENT) */
343
344 #if defined(ENABLE_DISASSEMBLER)
345         /* show code before first basic block */
346
347         if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
348                 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen);
349
350                 for (; pc < (u1 *) ((ptrint) code->mcode + cd->dseglen + jd->basicblocks[0].mpc);)
351                         DISASSINSTR(pc);
352
353                 printf("\n");
354         }
355 #endif
356
357         /* show code of all basic blocks */
358
359         for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next)
360                 show_basicblock(jd, bptr, stage);
361
362 #if 0 && defined(ENABLE_DISASSEMBLER)
363         /* show code after last basic block */
364
365         if (stage >= SHOW_CODE && opt_showdisassemble) {
366                 printf("\nStubs code:\n");
367                 printf("Length: %d\n\n", (s4) (code->mcodelength -
368                                                                            ((ptrint) cd->dseglen + lastbptr->mpc)));
369
370                 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen + lastbptr->mpc);
371
372                 for (; (ptrint) pc < ((ptrint) code->mcode + code->mcodelength);)
373                         DISASSINSTR(pc);
374
375                 printf("\n");
376         }
377 #endif
378
379         mutex.unlock();
380
381         /* finally flush the output */
382
383         fflush(stdout);
384 }
385 #endif /* !defined(NDEBUG) */
386
387
388 #if !defined(NDEBUG) && defined(ENABLE_INLINING)
389 static void show_inline_info(jitdata *jd, insinfo_inline *ii, s4 opcode, s4 stage)
390 {
391         s4 *jl;
392         s4 n;
393
394         printf("(pt %d+%d+%d st ", 
395                         ii->throughcount - (ii->stackvarscount - ii->paramcount),
396                         ii->stackvarscount - ii->paramcount,
397                         ii->paramcount);
398         show_variable_array(jd, ii->stackvars, ii->stackvarscount, stage);
399
400         if (opcode == ICMD_INLINE_START || opcode == ICMD_INLINE_END) {
401                 printf(" jl ");
402                 jl = (opcode == ICMD_INLINE_START) ? ii->javalocals_start : ii->javalocals_end;
403                 n = (opcode == ICMD_INLINE_START) ? ii->method->maxlocals : ii->outer->maxlocals;
404                 show_javalocals_array(jd, jl, n, stage);
405         }
406
407         printf(") ");
408
409 #if 0
410         printf("(");
411         method_print(ii->outer);
412         printf(" ==> ");
413 #endif
414
415         method_print(ii->method);
416 }
417 #endif /* !defined(NDEBUG) && defined(ENABLE_INLINING) */
418
419
420 /* show_basicblock *************************************************************
421
422    Print the intermediate representation of a basic block.
423
424    NOTE: Currently this function may only be called after register allocation!
425
426 *******************************************************************************/
427
428 #if !defined(NDEBUG)
429 void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
430 {
431         codeinfo    *code;
432         codegendata *cd;
433         s4           i;
434         bool         deadcode;
435         instruction *iptr;
436         int          irstage;
437 #if defined(ENABLE_DISASSEMBLER)
438         methodinfo  *m;                     /* this is only a dummy               */
439         void        *pc;
440         s4           linenumber;
441         s4           currentlinenumber;
442 #endif
443
444         /* get required compiler data */
445
446         code = jd->code;
447         cd   = jd->cd;
448
449         if (bptr->flags != BBDELETED) {
450 #if defined(ENABLE_INTRP)
451                 if (opt_intrp) {
452                         deadcode = false;
453                         irstage = SHOW_PARSE;
454                 }
455                 else
456 #endif
457                 {
458                         deadcode = (bptr->flags < BBREACHED);
459                         irstage = stage;
460                 }
461
462                 printf("======== %sL%03d ======== %s(flags: %d, bitflags: %01x, next: %d, type: ",
463 #if defined(ENABLE_REPLACEMENT)
464                                 (bptr->bitflags & BBFLAG_REPLACEMENT) ? "<REPLACE> " : 
465 #endif
466                                                                                                                 "",
467                            bptr->nr, 
468                            (deadcode && stage >= SHOW_STACK) ? "DEADCODE! " : "",
469                            bptr->flags, bptr->bitflags, 
470                            (bptr->next) ? (bptr->next->nr) : -1);
471
472                 switch (bptr->type) {
473                 case BBTYPE_STD:
474                         printf("STD");
475                         break;
476                 case BBTYPE_EXH:
477                         printf("EXH");
478                         break;
479                 case BBTYPE_SBR:
480                         printf("SBR");
481                         break;
482                 }
483
484                 printf(", icount: %d", bptr->icount);
485
486                 if (irstage >= SHOW_CFG) {
487                         printf(", preds: %d [ ", bptr->predecessorcount);
488
489                         for (i = 0; i < bptr->predecessorcount; i++)
490                                 printf("%d ", bptr->predecessors[i]->nr);
491
492                         printf("]");
493                 }
494
495                 printf("):");
496
497                 if (bptr->original)
498                         printf(" (clone of L%03d)", bptr->original->nr);
499                 else {
500                         basicblock *b = bptr->copied_to;
501                         if (b) {
502                                 printf(" (copied to ");
503                                 for (; b; b = b->copied_to)
504                                         printf("L%03d ", b->nr);
505                                 printf(")");
506                         }
507                 }
508
509                 printf("\n");
510
511                 if (irstage >= SHOW_CFG) {
512                         printf("succs: %d [ ", bptr->successorcount);
513
514                         for (i = 0; i < bptr->successorcount; i++)
515                                 printf("%d ", bptr->successors[i]->nr);
516
517                         printf("]\n");
518                 }
519
520                 if (irstage >= SHOW_STACK) {
521                         printf("IN:  ");
522                         show_variable_array(jd, bptr->invars, bptr->indepth, irstage);
523                         printf(" javalocals: ");
524                         if (bptr->javalocals)
525                                 show_javalocals_array(jd, bptr->javalocals, bptr->method->maxlocals, irstage);
526                         else
527                                 printf("null");
528                         printf("\n");
529                 }
530
531 #if defined(ENABLE_INLINING)
532                 if (bptr->inlineinfo) {
533                         printf("inlineinfo: ");
534                         show_inline_info(jd, bptr->inlineinfo, -1, irstage);
535                         printf("\n");
536                 }
537 #endif /* defined(ENABLE_INLINING) */
538
539 #if defined(ENABLE_SSA)
540         
541                 iptr = bptr->phis;
542
543                 for (i = 0; i < bptr->phicount; i++, iptr++) {
544                         printf("%4d:%4d:  ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
545
546                         show_icmd(jd, iptr, deadcode, irstage);
547                         printf("\n");
548                 }
549 #endif
550
551                 iptr = bptr->iinstr;
552
553                 for (i = 0; i < bptr->icount; i++, iptr++) {
554                         printf("%4d:%4d:  ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
555
556                         show_icmd(jd, iptr, deadcode, irstage);
557                         printf("\n");
558                 }
559
560                 if (irstage >= SHOW_STACK) {
561                         printf("OUT: ");
562                         show_variable_array(jd, bptr->outvars, bptr->outdepth, irstage);
563                         printf("\n");
564                 }
565
566 #if defined(ENABLE_DISASSEMBLER)
567                 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd) &&
568                         (!deadcode)) 
569                 {
570                         printf("\n");
571                         pc         = (void *) (code->mcode + cd->dseglen + bptr->mpc);
572                         linenumber = 0;
573
574                         if (bptr->next != NULL) {
575                                 for (; pc < (void *) (code->mcode + cd->dseglen + bptr->next->mpc);) {
576                                         currentlinenumber = code->linenumbertable->find(&m, pc);
577
578                                         if (currentlinenumber != linenumber) {
579                                                 linenumber = currentlinenumber;
580                                                 printf("%4d:\n", linenumber);
581                                         }
582
583                                         DISASSINSTR(pc);
584                                 }
585                         }
586                         else {
587                                 for (; pc < (void *) (code->mcode + code->mcodelength);) {
588                                         currentlinenumber = code->linenumbertable->find(&m, pc);
589
590                                         if (currentlinenumber != linenumber) {
591                                                 linenumber = currentlinenumber;
592                                                 printf("%4d:\n", linenumber);
593                                         }
594
595                                         DISASSINSTR(pc);
596                                 }
597                         }
598                         printf("\n");
599                 }
600 #endif
601         }
602 }
603 #endif /* !defined(NDEBUG) */
604
605
606 /* show_icmd *******************************************************************
607
608    Print the intermediate representation of an instruction.
609
610    NOTE: Currently this function may only be called after register allocation!
611
612 *******************************************************************************/
613
614 #if !defined(NDEBUG)
615
616 #define SHOW_TARGET(target)                                          \
617         if (stage >= SHOW_PARSE) {                                   \
618             printf("--> L%03d ", (target).block->nr);                \
619         }                                                            \
620         else {                                                       \
621             printf("--> insindex %d ", (target).insindex);           \
622         }
623
624 #define SHOW_INT_CONST(val)                                          \
625         if (stage >= SHOW_PARSE) {                                   \
626             printf("%d (0x%08x) ", (int32_t) (val), (int32_t) (val)); \
627         }                                                            \
628         else {                                                       \
629             printf("iconst ");                                       \
630         }
631
632 #if SIZEOF_VOID_P == 4
633 #define SHOW_LNG_CONST(val)                                          \
634         if (stage >= SHOW_PARSE)                                     \
635             printf("%lld (0x%016llx) ", (val), (val));               \
636         else                                                         \
637             printf("lconst ");
638 #else
639 #define SHOW_LNG_CONST(val)                                          \
640         if (stage >= SHOW_PARSE)                                     \
641             printf("%ld (0x%016lx) ", (val), (val));                 \
642         else                                                         \
643             printf("lconst ");
644 #endif
645
646 #if SIZEOF_VOID_P == 4
647 #define SHOW_ADR_CONST(val)                                          \
648         if (stage >= SHOW_PARSE)                                     \
649             printf("0x%08x ", (ptrint) (val));                       \
650         else                                                         \
651             printf("aconst ");
652 #else
653 #define SHOW_ADR_CONST(val)                                          \
654         if (stage >= SHOW_PARSE)                                     \
655             printf("0x%016lx ", (ptrint) (val));                     \
656         else                                                         \
657             printf("aconst ");
658 #endif
659
660 #define SHOW_FLT_CONST(val)                                          \
661         if (stage >= SHOW_PARSE) {                                   \
662             imm_union v;                                             \
663             v.f = (val);                                             \
664             printf("%g (0x%08x) ", (val), v.i);                      \
665         }                                                            \
666         else {                                                       \
667             printf("fconst ");                                       \
668         }
669
670 #if SIZEOF_VOID_P == 4
671 #define SHOW_DBL_CONST(val)                                          \
672         if (stage >= SHOW_PARSE) {                                   \
673             imm_union v;                                             \
674             v.d = (val);                                             \
675             printf("%g (0x%016llx) ", (val), v.l);                   \
676         }                                                            \
677         else                                                         \
678             printf("dconst ");
679 #else
680 #define SHOW_DBL_CONST(val)                                          \
681         if (stage >= SHOW_PARSE) {                                   \
682             imm_union v;                                             \
683             v.d = (val);                                             \
684             printf("%g (0x%016lx) ", (val), v.l);                    \
685         }                                                            \
686         else                                                         \
687             printf("dconst ");
688 #endif
689
690 #define SHOW_INDEX(index)                                            \
691         if (stage >= SHOW_PARSE) {                                   \
692             printf("%d ", index);                                    \
693         }                                                            \
694         else {                                                       \
695             printf("index");                                         \
696         }
697
698 #define SHOW_STRING(val)                                             \
699         if (stage >= SHOW_PARSE) {                                   \
700             putchar('"');                                            \
701             utf_display_printable_ascii(                             \
702                javastring_toutf((java_handle_t *)(val), false));     \
703             printf("\" ");                                           \
704         }                                                            \
705         else {                                                       \
706             printf("string ");                                       \
707         }
708
709 #define SHOW_CLASSREF_OR_CLASSINFO(c)                                \
710         if (stage >= SHOW_PARSE) {                                   \
711             if (IS_CLASSREF(c))                                      \
712                 class_classref_print(c.ref);                         \
713             else                                                     \
714                 class_print(c.cls);                                  \
715             putchar(' ');                                            \
716         }                                                            \
717         else {                                                       \
718             printf("class ");                                        \
719         }
720
721 #define SHOW_FIELD(fmiref)                                           \
722         if (stage >= SHOW_PARSE) {                                   \
723             field_fieldref_print(fmiref);                            \
724             putchar(' ');                                            \
725         }                                                            \
726         else {                                                       \
727             printf("field ");                                        \
728         }
729
730 #define SHOW_VARIABLE(v)                                             \
731     show_variable(jd, (v), stage)
732
733 #define SHOW_S1(iptr)                                                \
734         if (stage >= SHOW_STACK) {                                   \
735             SHOW_VARIABLE(iptr->s1.varindex);                        \
736         }
737
738 #define SHOW_S2(iptr)                                                \
739         if (stage >= SHOW_STACK) {                                   \
740             SHOW_VARIABLE(iptr->sx.s23.s2.varindex);                 \
741         }
742
743 #define SHOW_S3(iptr)                                                \
744     if (stage >= SHOW_STACK) {                                       \
745         SHOW_VARIABLE(iptr->sx.s23.s3.varindex);                     \
746     }
747
748 #define SHOW_DST(iptr)                                               \
749     if (stage >= SHOW_STACK) {                                       \
750         printf("=> ");                                               \
751         SHOW_VARIABLE(iptr->dst.varindex);                           \
752     }
753
754 #define SHOW_S1_LOCAL(iptr)                                          \
755     if (stage >= SHOW_STACK) {                                       \
756         printf("L%d ", iptr->s1.varindex);                           \
757     }                                                                \
758     else {                                                           \
759         printf("JavaL%d ", iptr->s1.varindex);                       \
760     }
761
762 #define SHOW_DST_LOCAL(iptr)                                         \
763     if (stage >= SHOW_STACK) {                                       \
764         printf("=> L%d ", iptr->dst.varindex);                       \
765     }                                                                \
766     else {                                                           \
767         printf("=> JavaL%d ", iptr->dst.varindex);                   \
768     }
769
770 void show_allocation(s4 type, s4 flags, s4 regoff)
771 {
772         if (type == TYPE_RET) {
773                 printf("N/A");
774                 return;
775         }
776
777         if (flags & INMEMORY) {
778                 printf("M%02d", regoff);
779                 return;
780         }
781
782 #ifdef HAS_ADDRESS_REGISTER_FILE
783         if (type == TYPE_ADR) {
784                 printf("R%02d", regoff);
785                 return;
786         }
787 #endif
788
789         if (IS_FLT_DBL_TYPE(type)) {
790                 printf("F%02d", regoff);
791                 return;
792         }
793
794 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
795         if (IS_2_WORD_TYPE(type)) {
796 # if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
797 #  if defined(ENABLE_INTRP)
798                 if (opt_intrp)
799                         printf("%3d/%3d", GET_LOW_REG(regoff),
800                                         GET_HIGH_REG(regoff));
801                 else
802 #  endif
803                         printf("%3s/%3s", abi_registers_integer_name[GET_LOW_REG(regoff)],
804                                    abi_registers_integer_name[GET_HIGH_REG(regoff)]);
805 # else
806                 printf("%3d/%3d", GET_LOW_REG(regoff),
807                            GET_HIGH_REG(regoff));
808 # endif
809                 return;
810         } 
811 #endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
812
813 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
814 # if defined(ENABLE_INTRP)
815         if (opt_intrp)
816                 printf("%3d", regoff);
817         else
818 # endif
819                 printf("%3s", abi_registers_integer_name[regoff]);
820 #else
821         printf("%3d", regoff);
822 #endif
823 }
824
825 void show_variable(jitdata *jd, s4 index, int stage)
826 {
827         show_variable_intern(jd, index, stage);
828         putchar(' ');
829 }
830
831 static void show_variable_intern(jitdata *jd, s4 index, int stage)
832 {
833         char type;
834         char kind;
835         varinfo *v;
836
837         if (index < 0 || index >= jd->vartop) {
838                 printf("<INVALID INDEX:%d>", index);
839                 return;
840         }
841
842         v = VAR(index);
843
844         switch (v->type) {
845                 case TYPE_INT: type = 'i'; break;
846                 case TYPE_LNG: type = 'l'; break;
847                 case TYPE_FLT: type = 'f'; break;
848                 case TYPE_DBL: type = 'd'; break;
849                 case TYPE_ADR: type = 'a'; break;
850                 case TYPE_RET: type = 'r'; break;
851                 default:       type = '?';
852         }
853
854         if (index < jd->localcount) {
855                 kind = 'L';
856                 if (v->flags & (PREALLOC | INOUT))
857                                 printf("<INVALID FLAGS!>");
858         }
859         else {
860                 if (v->flags & PREALLOC) {
861                         kind = 'A';
862                         if (v->flags & INOUT) {
863                                 /* PREALLOC is used to avoid allocation of TYPE_RET */
864                                 if (v->type == TYPE_RET)
865                                         kind = 'i';
866                                 else
867                                         printf("<INVALID FLAGS!>");
868                         }
869                 }
870                 else if (v->flags & INOUT)
871                         kind = 'I';
872                 else
873                         kind = 'T';
874         }
875
876         printf("%c%c%d", kind, type, index);
877
878         if (v->flags & SAVEDVAR)
879                 putchar('!');
880
881         if (stage >= SHOW_REGS || (v->flags & PREALLOC)) {
882                 putchar('(');
883                 show_allocation(v->type, v->flags, v->vv.regoff);
884                 putchar(')');
885         }
886
887         if (v->type == TYPE_RET && (v->flags & PREALLOC)) {
888                 printf("(L%03d)", v->vv.retaddr->nr);
889         }
890 }
891
892 static void show_variable_array_intern(jitdata *jd, s4 *vars, int n, int stage,
893                                                                            bool javalocals)
894 {
895         int i;
896         int nr;
897
898         if (vars == NULL) {
899                 printf("<null>");
900                 return;
901         }
902
903         printf("[");
904         for (i=0; i<n; ++i) {
905                 if (i)
906                         putchar(' ');
907                 if (vars[i] < 0) {
908                         if (vars[i] == UNUSED)
909                                 putchar('-');
910                         else if (javalocals) {
911                                 nr = RETADDR_FROM_JAVALOCAL(vars[i]);
912                                 printf("ret(L%03d)", nr);
913                         }
914                         else {
915                                 printf("<INVALID INDEX:%d>", vars[i]);
916                         }
917                 }
918                 else
919                         show_variable_intern(jd, vars[i], stage);
920         }
921         printf("]");
922 }
923
924 void show_variable_array(jitdata *jd, s4 *vars, int n, int stage)
925 {
926         show_variable_array_intern(jd, vars, n, stage, false);
927 }
928
929 void show_javalocals_array(jitdata *jd, s4 *vars, int n, int stage)
930 {
931         show_variable_array_intern(jd, vars, n, stage, true);
932 }
933
934 void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
935 {
936         u2                 opcode;
937         branch_target_t   *table;
938         lookup_target_t   *lookup;
939         constant_FMIref   *fmiref;
940         s4                *argp;
941         s4                 i;
942
943         /* get the opcode and the condition */
944
945         opcode    =  iptr->opc;
946
947         printf("%s ", icmd_table[opcode].name);
948
949         if (stage < SHOW_PARSE)
950                 return;
951
952         if (deadcode)
953                 stage = SHOW_PARSE;
954
955         /* Print the condition for conditional instructions. */
956
957         /* XXX print condition from flags */
958
959         if (iptr->flags.bits & INS_FLAG_UNRESOLVED)
960                 printf("(UNRESOLVED) ");
961
962         switch (opcode) {
963
964         case ICMD_POP:
965         case ICMD_CHECKNULL:
966                 SHOW_S1(iptr);
967                 break;
968
969                 /* unary */
970         case ICMD_ARRAYLENGTH:
971         case ICMD_INEG:
972         case ICMD_LNEG:
973         case ICMD_FNEG:
974         case ICMD_DNEG:
975         case ICMD_I2L:
976         case ICMD_I2F:
977         case ICMD_I2D:
978         case ICMD_L2I:
979         case ICMD_L2F:
980         case ICMD_L2D:
981         case ICMD_F2I:
982         case ICMD_F2L:
983         case ICMD_F2D:
984         case ICMD_D2I:
985         case ICMD_D2L:
986         case ICMD_D2F:
987         case ICMD_INT2BYTE:
988         case ICMD_INT2CHAR:
989         case ICMD_INT2SHORT:
990                 SHOW_S1(iptr);
991                 SHOW_DST(iptr);
992                 break;
993
994                 /* binary */
995         case ICMD_IADD:
996         case ICMD_LADD:
997         case ICMD_FADD:
998         case ICMD_DADD:
999         case ICMD_ISUB:
1000         case ICMD_LSUB:
1001         case ICMD_FSUB:
1002         case ICMD_DSUB:
1003         case ICMD_IMUL:
1004         case ICMD_LMUL:
1005         case ICMD_FMUL:
1006         case ICMD_DMUL:
1007         case ICMD_IDIV:
1008         case ICMD_LDIV:
1009         case ICMD_FDIV:
1010         case ICMD_DDIV:
1011         case ICMD_IREM:
1012         case ICMD_LREM:
1013         case ICMD_FREM:
1014         case ICMD_DREM:
1015         case ICMD_ISHL:
1016         case ICMD_LSHL:
1017         case ICMD_ISHR:
1018         case ICMD_LSHR:
1019         case ICMD_IUSHR:
1020         case ICMD_LUSHR:
1021         case ICMD_IAND:
1022         case ICMD_LAND:
1023         case ICMD_IOR:
1024         case ICMD_LOR:
1025         case ICMD_IXOR:
1026         case ICMD_LXOR:
1027         case ICMD_LCMP:
1028         case ICMD_FCMPL:
1029         case ICMD_FCMPG:
1030         case ICMD_DCMPL:
1031         case ICMD_DCMPG:
1032                 SHOW_S1(iptr);
1033                 SHOW_S2(iptr);
1034                 SHOW_DST(iptr);
1035                 break;
1036
1037                 /* binary/const INT */
1038         case ICMD_IADDCONST:
1039         case ICMD_ISUBCONST:
1040         case ICMD_IMULCONST:
1041         case ICMD_IMULPOW2:
1042         case ICMD_IDIVPOW2:
1043         case ICMD_IREMPOW2:
1044         case ICMD_IANDCONST:
1045         case ICMD_IORCONST:
1046         case ICMD_IXORCONST:
1047         case ICMD_ISHLCONST:
1048         case ICMD_ISHRCONST:
1049         case ICMD_IUSHRCONST:
1050         case ICMD_LSHLCONST:
1051         case ICMD_LSHRCONST:
1052         case ICMD_LUSHRCONST:
1053                 SHOW_S1(iptr);
1054                 SHOW_INT_CONST(iptr->sx.val.i); 
1055                 SHOW_DST(iptr);
1056                 break;
1057
1058                 /* ?ASTORECONST (trinary/const INT) */
1059         case ICMD_IASTORECONST:
1060         case ICMD_BASTORECONST:
1061         case ICMD_CASTORECONST:
1062         case ICMD_SASTORECONST:
1063                 SHOW_S1(iptr);
1064                 SHOW_S2(iptr);
1065                 SHOW_INT_CONST(iptr->sx.s23.s3.constval);
1066                 break;
1067
1068                 /* const INT */
1069         case ICMD_ICONST:
1070                 SHOW_INT_CONST(iptr->sx.val.i); 
1071                 SHOW_DST(iptr);
1072                 break;
1073
1074                 /* binary/const LNG */
1075         case ICMD_LADDCONST:
1076         case ICMD_LSUBCONST:
1077         case ICMD_LMULCONST:
1078         case ICMD_LMULPOW2:
1079         case ICMD_LDIVPOW2:
1080         case ICMD_LREMPOW2:
1081         case ICMD_LANDCONST:
1082         case ICMD_LORCONST:
1083         case ICMD_LXORCONST:
1084                 SHOW_S1(iptr);
1085                 SHOW_LNG_CONST(iptr->sx.val.l);
1086                 SHOW_DST(iptr);
1087                 break;
1088
1089                 /* trinary/const LNG (<= pointer size) */
1090         case ICMD_LASTORECONST:
1091                 SHOW_S1(iptr);
1092                 SHOW_S2(iptr);
1093                 SHOW_ADR_CONST(iptr->sx.s23.s3.constval);
1094                 break;
1095
1096                 /* const LNG */
1097         case ICMD_LCONST:
1098                 SHOW_LNG_CONST(iptr->sx.val.l); 
1099                 SHOW_DST(iptr);
1100                 break;
1101
1102                 /* const FLT */
1103         case ICMD_FCONST:
1104                 SHOW_FLT_CONST(iptr->sx.val.f); 
1105                 SHOW_DST(iptr);
1106                 break;
1107
1108                 /* const DBL */
1109         case ICMD_DCONST:
1110                 SHOW_DBL_CONST(iptr->sx.val.d); 
1111                 SHOW_DST(iptr);
1112                 break;
1113
1114                 /* const ADR */
1115         case ICMD_ACONST:
1116                 if (iptr->flags.bits & INS_FLAG_CLASS) {
1117                         SHOW_ADR_CONST(iptr->sx.val.anyptr);
1118                         SHOW_CLASSREF_OR_CLASSINFO(iptr->sx.val.c);
1119                 }
1120                 else if (iptr->sx.val.anyptr == NULL) {
1121                         printf("NULL ");
1122                 }
1123                 else {
1124                         SHOW_ADR_CONST(iptr->sx.val.anyptr);
1125                         SHOW_STRING(iptr->sx.val.stringconst);
1126                 }
1127                 SHOW_DST(iptr);
1128                 break;
1129
1130         case ICMD_AASTORECONST:
1131                 SHOW_S1(iptr);
1132                 SHOW_S2(iptr);
1133                 printf("%p ", (void*) iptr->sx.s23.s3.constval);
1134                 break;
1135
1136         case ICMD_GETFIELD:        /* 1 -> 1 */
1137         case ICMD_PUTFIELD:        /* 2 -> 0 */
1138         case ICMD_PUTSTATIC:       /* 1 -> 0 */
1139         case ICMD_GETSTATIC:       /* 0 -> 1 */
1140         case ICMD_PUTSTATICCONST:  /* 0 -> 0 */
1141         case ICMD_PUTFIELDCONST:   /* 1 -> 0 */
1142                 if (opcode != ICMD_GETSTATIC && opcode != ICMD_PUTSTATICCONST) {
1143                         SHOW_S1(iptr);
1144                         if (opcode == ICMD_PUTFIELD) {
1145                                 SHOW_S2(iptr);
1146                         }
1147                 }
1148                 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1149                 SHOW_FIELD(fmiref);
1150
1151                 if (opcode == ICMD_GETSTATIC || opcode == ICMD_GETFIELD) {
1152                         SHOW_DST(iptr);
1153                 }
1154                 break;
1155
1156         case ICMD_IINC:
1157                 SHOW_S1_LOCAL(iptr);
1158                 SHOW_INT_CONST(iptr->sx.val.i);
1159                 SHOW_DST_LOCAL(iptr);
1160                 break;
1161
1162         case ICMD_IASTORE:
1163         case ICMD_SASTORE:
1164         case ICMD_BASTORE:
1165         case ICMD_CASTORE:
1166         case ICMD_LASTORE:
1167         case ICMD_DASTORE:
1168         case ICMD_FASTORE:
1169         case ICMD_AASTORE:
1170                 SHOW_S1(iptr);
1171                 SHOW_S2(iptr);
1172                 SHOW_S3(iptr);
1173                 break;
1174
1175         case ICMD_IALOAD:
1176         case ICMD_SALOAD:
1177         case ICMD_BALOAD:
1178         case ICMD_CALOAD:
1179         case ICMD_LALOAD:
1180         case ICMD_DALOAD:
1181         case ICMD_FALOAD:
1182         case ICMD_AALOAD:
1183                 SHOW_S1(iptr);
1184                 SHOW_S2(iptr);
1185                 SHOW_DST(iptr);
1186                 break;
1187
1188         case ICMD_RET:
1189                 SHOW_S1_LOCAL(iptr);
1190                 if (stage >= SHOW_STACK) {
1191                         printf(" ---> L%03d", iptr->dst.block->nr);
1192                 }
1193                 break;
1194
1195         case ICMD_ILOAD:
1196         case ICMD_LLOAD:
1197         case ICMD_FLOAD:
1198         case ICMD_DLOAD:
1199         case ICMD_ALOAD:
1200                 SHOW_S1_LOCAL(iptr);
1201                 SHOW_DST(iptr);
1202                 break;
1203
1204         case ICMD_ISTORE:
1205         case ICMD_LSTORE:
1206         case ICMD_FSTORE:
1207         case ICMD_DSTORE:
1208         case ICMD_ASTORE:
1209                 SHOW_S1(iptr);
1210                 SHOW_DST_LOCAL(iptr);
1211                 if (stage >= SHOW_STACK && iptr->sx.s23.s3.javaindex != UNUSED)
1212                         printf(" (javaindex %d)", iptr->sx.s23.s3.javaindex);
1213                 if (iptr->flags.bits & INS_FLAG_RETADDR) {
1214                         printf(" (retaddr L%03d)", RETADDR_FROM_JAVALOCAL(iptr->sx.s23.s2.retaddrnr));
1215                 }
1216                 break;
1217
1218         case ICMD_NEW:
1219                 SHOW_DST(iptr);
1220                 break;
1221
1222         case ICMD_NEWARRAY:
1223                 SHOW_DST(iptr);
1224                 break;
1225
1226         case ICMD_ANEWARRAY:
1227                 SHOW_DST(iptr);
1228                 break;
1229
1230         case ICMD_MULTIANEWARRAY:
1231                 if (stage >= SHOW_STACK) {
1232                         argp = iptr->sx.s23.s2.args;
1233                         i = iptr->s1.argcount;
1234                         while (i--) {
1235                                 SHOW_VARIABLE(*(argp++));
1236                         }
1237                 }
1238                 else {
1239                         printf("argcount=%d ", iptr->s1.argcount);
1240                 }
1241                 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1242                 putchar(' ');
1243                 SHOW_DST(iptr);
1244                 break;
1245
1246         case ICMD_CHECKCAST:
1247                 SHOW_S1(iptr);
1248                 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1249                 putchar(' ');
1250                 SHOW_DST(iptr);
1251                 break;
1252
1253         case ICMD_INSTANCEOF:
1254                 SHOW_S1(iptr);
1255                 SHOW_DST(iptr);
1256                 break;
1257
1258         case ICMD_INLINE_START:
1259         case ICMD_INLINE_END:
1260         case ICMD_INLINE_BODY:
1261 #if defined(ENABLE_INLINING)
1262                 {
1263                         insinfo_inline *ii = iptr->sx.s23.s3.inlineinfo;
1264                         show_inline_info(jd, ii, opcode, stage);
1265                 }
1266 #endif
1267                 break;
1268
1269         case ICMD_BUILTIN:
1270                 if (stage >= SHOW_STACK) {
1271                         argp = iptr->sx.s23.s2.args;
1272                         i = iptr->s1.argcount;
1273                         while (i--) {
1274                                 if ((iptr->s1.argcount - 1 - i) == iptr->sx.s23.s3.bte->md->paramcount)
1275                                         printf(" pass-through: ");
1276                                 SHOW_VARIABLE(*(argp++));
1277                         }
1278                 }
1279                 printf("%s ", iptr->sx.s23.s3.bte->cname);
1280                 if (iptr->sx.s23.s3.bte->md->returntype.type != TYPE_VOID) {
1281                         SHOW_DST(iptr);
1282                 }
1283                 break;
1284
1285         case ICMD_INVOKEVIRTUAL:
1286         case ICMD_INVOKESPECIAL:
1287         case ICMD_INVOKESTATIC:
1288         case ICMD_INVOKEINTERFACE:
1289                 if (stage >= SHOW_STACK) {
1290                         methoddesc *md;
1291                         INSTRUCTION_GET_METHODDESC(iptr, md);
1292                         argp = iptr->sx.s23.s2.args;
1293                         i = iptr->s1.argcount;
1294                         while (i--) {
1295                                 if ((iptr->s1.argcount - 1 - i) == md->paramcount)
1296                                         printf(" pass-through: ");
1297                                 SHOW_VARIABLE(*(argp++));
1298                         }
1299                 }
1300                 INSTRUCTION_GET_METHODREF(iptr, fmiref);
1301                 method_methodref_print(fmiref);
1302                 if (fmiref->parseddesc.md->returntype.type != TYPE_VOID) {
1303                         putchar(' ');
1304                         SHOW_DST(iptr);
1305                 }
1306                 break;
1307
1308         case ICMD_IFEQ:
1309         case ICMD_IFNE:
1310         case ICMD_IFLT:
1311         case ICMD_IFGE:
1312         case ICMD_IFGT:
1313         case ICMD_IFLE:
1314                 SHOW_S1(iptr);
1315                 SHOW_INT_CONST(iptr->sx.val.i); 
1316                 SHOW_TARGET(iptr->dst);
1317                 break;
1318
1319         case ICMD_IF_LEQ:
1320         case ICMD_IF_LNE:
1321         case ICMD_IF_LLT:
1322         case ICMD_IF_LGE:
1323         case ICMD_IF_LGT:
1324         case ICMD_IF_LLE:
1325                 SHOW_S1(iptr);
1326                 SHOW_LNG_CONST(iptr->sx.val.l); 
1327                 SHOW_TARGET(iptr->dst);
1328                 break;
1329
1330         case ICMD_GOTO:
1331                 SHOW_TARGET(iptr->dst);
1332                 break;
1333
1334         case ICMD_JSR:
1335                 SHOW_TARGET(iptr->sx.s23.s3.jsrtarget);
1336                 SHOW_DST(iptr);
1337                 break;
1338
1339         case ICMD_IFNULL:
1340         case ICMD_IFNONNULL:
1341                 SHOW_S1(iptr);
1342                 SHOW_TARGET(iptr->dst);
1343                 break;
1344
1345         case ICMD_IF_ICMPEQ:
1346         case ICMD_IF_ICMPNE:
1347         case ICMD_IF_ICMPLT:
1348         case ICMD_IF_ICMPGE:
1349         case ICMD_IF_ICMPGT:
1350         case ICMD_IF_ICMPLE:
1351
1352         case ICMD_IF_LCMPEQ:
1353         case ICMD_IF_LCMPNE:
1354         case ICMD_IF_LCMPLT:
1355         case ICMD_IF_LCMPGE:
1356         case ICMD_IF_LCMPGT:
1357         case ICMD_IF_LCMPLE:
1358
1359         case ICMD_IF_ACMPEQ:
1360         case ICMD_IF_ACMPNE:
1361                 SHOW_S1(iptr);
1362                 SHOW_S2(iptr);
1363                 SHOW_TARGET(iptr->dst);
1364                 break;
1365
1366         case ICMD_TABLESWITCH:
1367                 SHOW_S1(iptr);
1368                 table = iptr->dst.table;
1369
1370                 i = iptr->sx.s23.s3.tablehigh - iptr->sx.s23.s2.tablelow + 1;
1371
1372                 printf("high=%d low=%d count=%d\n", iptr->sx.s23.s3.tablehigh, iptr->sx.s23.s2.tablelow, i);
1373                 while (--i >= 0) {
1374                         printf("\t\t%d --> ", (int) (table - iptr->dst.table));
1375                         printf("L%03d\n", table->block->nr);
1376                         table++;
1377                 }
1378
1379                 break;
1380
1381         case ICMD_LOOKUPSWITCH:
1382                 SHOW_S1(iptr);
1383
1384                 printf("count=%d, default=L%03d\n",
1385                            iptr->sx.s23.s2.lookupcount,
1386                            iptr->sx.s23.s3.lookupdefault.block->nr);
1387
1388                 lookup = iptr->dst.lookup;
1389                 i = iptr->sx.s23.s2.lookupcount;
1390
1391                 while (--i >= 0) {
1392                         printf("\t\t%d --> L%03d\n",
1393                                    lookup->value,
1394                                    lookup->target.block->nr);
1395                         lookup++;
1396                 }
1397                 break;
1398
1399         case ICMD_FRETURN:
1400         case ICMD_IRETURN:
1401         case ICMD_DRETURN:
1402         case ICMD_LRETURN:
1403                 SHOW_S1(iptr);
1404                 break;
1405
1406         case ICMD_ARETURN:
1407         case ICMD_ATHROW:
1408                 SHOW_S1(iptr);
1409                 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1410                         /* XXX this needs more work */
1411 #if 0
1412                         unresolved_class_debug_dump(iptr->sx.s23.s2.uc, stdout);
1413 #endif
1414                 }
1415                 break;
1416
1417         case ICMD_COPY:
1418         case ICMD_MOVE:
1419                 SHOW_S1(iptr);
1420                 SHOW_DST(iptr);
1421                 break;
1422         case ICMD_GETEXCEPTION:
1423                 SHOW_DST(iptr);
1424                 break;
1425 #if defined(ENABLE_SSA) 
1426         case ICMD_PHI:
1427                 printf("[ ");
1428                 for (i = 0; i < iptr->s1.argcount; ++i) {
1429                         SHOW_VARIABLE(iptr->sx.s23.s2.iargs[i]->dst.varindex);
1430                 }
1431                 printf("] ");
1432                 SHOW_DST(iptr);
1433                 if (iptr->flags.bits & (1 << 0)) printf("used ");
1434                 if (iptr->flags.bits & (1 << 1)) printf("redundantAll ");
1435                 if (iptr->flags.bits & (1 << 2)) printf("redundantOne ");
1436                 break;
1437 #endif
1438         }
1439         fflush(stdout);
1440 }
1441 #endif /* !defined(NDEBUG) */
1442
1443 /* Debug output filtering */
1444
1445 #if defined(ENABLE_DEBUG_FILTER)
1446
1447 #if !defined(ENABLE_THREADS)
1448 u2 _no_threads_filterverbosecallctr[2] = { 0, 0 };
1449 #endif
1450
1451 struct show_filter {
1452         /* Boolean indicating if filter is enabled. */
1453         u1 enabled;
1454         /* Regular expression the method name is matched against */
1455         regex_t regex;
1456         /* Flag set on m->filtermatches if regex matches */
1457         u1 flag;
1458 };
1459
1460 typedef struct show_filter show_filter_t;
1461
1462 #define SHOW_FILTERS_SIZE 3
1463
1464 /* Array of filters applyed on a method */
1465 static struct show_filter show_filters[SHOW_FILTERS_SIZE];
1466
1467 static void show_filter_init(show_filter_t *cf, const char *str, u1 flag, u1 default_flag, const char *description) {
1468         int err;
1469         char err_buf[128];
1470
1471         if (str) {
1472                 err = regcomp(&cf->regex, str, REG_EXTENDED | REG_NOSUB);
1473                 if (err != 0) {
1474                         regerror(err, &cf->regex, err_buf, sizeof(err_buf));
1475                         vm_abort(
1476                                 "Invalid value given for %s: `%s' (%s).", 
1477                                 description, str, err_buf
1478                         );
1479                 }
1480                 cf->flag = flag;
1481                 cf->enabled = 1;
1482         } else {
1483                 cf->flag = default_flag;
1484                 cf->enabled = 0;
1485         }
1486 }
1487
1488 void show_filters_init(void) {
1489
1490         show_filter_init(
1491                 show_filters + 0,
1492                 opt_filter_verbosecall_include,
1493                 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1494                 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1495                 "verbose call include filter"
1496         );
1497
1498         show_filter_init(
1499                 show_filters + 1,
1500                 opt_filter_verbosecall_exclude,
1501                 SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE,
1502                 0,
1503                 "verbose call exclude filter"
1504         );
1505
1506         show_filter_init(
1507                 show_filters + 2,
1508                 opt_filter_show_method,
1509                 SHOW_FILTER_FLAG_SHOW_METHOD,
1510                 SHOW_FILTER_FLAG_SHOW_METHOD,
1511                 "show method filter"
1512         );
1513 }
1514
1515 /*
1516  
1517  (Pseudo)State machine:
1518
1519  States are INITIAL, INCLUDE1, INCLUDE2, ..., EXCLUDE1, ..., EXCLUDE2, ...
1520
1521                                                         Enter              Enter
1522  Enter                                                  Include            Include
1523  Exclude                                                  | |                | |
1524   | |    Enter              Enter              Enter      | |     Enter      | |
1525   | |    Include            Include            Exclude    | |     Exclude    | |
1526   | v   --------->        ---------->        ---------->  | v   ---------->  | v
1527 INITIAL           INCLUDE1           INCLUDE2           EXCLUDE1           EXCLUDE2
1528   | ^   <---------        <----------        <----------  | ^   <----------  | ^
1529   | |    Exit               Exit               Exit       | |     Exit       | |
1530   | |    Include            Include            Exclude    | |     Exclude    | |
1531   | |                                                     | |                | |
1532  Exit                                                    Exit               Exit
1533  Exclude                                                 Include            Include
1534
1535   Verbose call scope is active if we are in a INCLUDE state.
1536
1537   State encoding:
1538
1539   INITIAL: ctr[0] == 0, ctr[1] == 0
1540   INCLUDEN: ctr[1] == N, ctr[1] == 0
1541   EXCLUDEN: ctr[1] == N
1542 */
1543
1544 void show_filters_apply(methodinfo *m) {
1545         int i;
1546         int res;
1547         char *method_name;
1548         s4 len;
1549
1550         /* compose full name of method */
1551
1552         len = 
1553                 utf_bytes(m->clazz->name) +
1554                 1 +
1555                 utf_bytes(m->name) +
1556                 utf_bytes(m->descriptor) +
1557                 1;
1558
1559         method_name = MNEW(char, len);
1560
1561         utf_cat_classname(method_name, m->clazz->name);
1562         strcat(method_name, ".");
1563         utf_cat(method_name, m->name);
1564         utf_cat(method_name, m->descriptor);
1565
1566         /* reset all flags */
1567
1568         m->filtermatches = 0;
1569
1570         for (i = 0; i < SHOW_FILTERS_SIZE; ++i) {
1571                 if (show_filters[i].enabled) {
1572
1573                         res = regexec(&show_filters[i].regex, method_name, 0, NULL, 0);
1574
1575                         if (res == 0) {
1576                                 m->filtermatches |= show_filters[i].flag;
1577                         }
1578                 } else {
1579                         /* Default is to show all */
1580                         m->filtermatches |= show_filters[i].flag;
1581                 }
1582         }
1583
1584         // Release memory.
1585         MFREE(method_name, char, len);
1586 }
1587
1588 #define STATE_IS_INITIAL() ((FILTERVERBOSECALLCTR[0] == 0) && (FILTERVERBOSECALLCTR[1] == 0))
1589 #define STATE_IS_INCLUDE() ((FILTERVERBOSECALLCTR[0] > 0) && (FILTERVERBOSECALLCTR[1] == 0))
1590 #define STATE_IS_EXCLUDE() (FILTERVERBOSECALLCTR[1] > 0)
1591 #define EVENT_INCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE)
1592 #define EVENT_EXCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE)
1593 #define TRANSITION_NEXT_INCLUDE() ++FILTERVERBOSECALLCTR[0]
1594 #define TRANSITION_PREV_INCLUDE() --FILTERVERBOSECALLCTR[0]
1595 #define TRANSITION_NEXT_EXCLUDE() ++FILTERVERBOSECALLCTR[1]
1596 #define TRANSITION_PREV_EXCLUDE() --FILTERVERBOSECALLCTR[1]
1597
1598 #if 0
1599 void dump_state() {
1600         if (STATE_IS_INITIAL()) printf("<INITIAL>\n");
1601         else if (STATE_IS_INCLUDE()) printf("<INCLUDE %hd>\n", FILTERVERBOSECALLCTR[0]);
1602         else if (STATE_IS_EXCLUDE()) printf("<EXCLUDE %hd>\n", FILTERVERBOSECALLCTR[1]);
1603 }
1604 #endif
1605
1606 int show_filters_test_verbosecall_enter(methodinfo *m) {
1607
1608         int force_show = 0;
1609
1610         if (STATE_IS_INITIAL()) {
1611                 if (EVENT_INCLUDE()) {
1612                         TRANSITION_NEXT_INCLUDE();
1613                 }
1614         } else if (STATE_IS_INCLUDE()) {
1615                 if (EVENT_EXCLUDE()) {
1616                         TRANSITION_NEXT_EXCLUDE();
1617                         /* just entered exclude, show this method */
1618                         force_show = 1;
1619                 } else if (EVENT_INCLUDE()) {
1620                         TRANSITION_NEXT_INCLUDE();
1621                 }
1622         } else if (STATE_IS_EXCLUDE()) {
1623                 if (EVENT_EXCLUDE()) {
1624                         TRANSITION_NEXT_EXCLUDE();
1625                 }
1626         }
1627
1628         return STATE_IS_INCLUDE() || force_show;
1629 }
1630
1631 int show_filters_test_verbosecall_exit(methodinfo *m) {
1632
1633         int force_show = 0;
1634
1635         if (m) {
1636                 if (STATE_IS_INCLUDE()) {
1637                         if (EVENT_INCLUDE()) {
1638                                 TRANSITION_PREV_INCLUDE();
1639                                 /* just entered initial, show this method */
1640                                 if (STATE_IS_INITIAL()) force_show = 1;
1641                         }
1642             } else if (STATE_IS_EXCLUDE()) {
1643                         if (EVENT_EXCLUDE()) {
1644                                 TRANSITION_PREV_EXCLUDE();
1645                         }
1646                 }
1647         }
1648
1649         return STATE_IS_INCLUDE() || force_show;
1650 }
1651
1652 #endif
1653
1654
1655 /*
1656  * These are local overrides for various environment variables in Emacs.
1657  * Please do not remove this and leave it at the end of the file, where
1658  * Emacs will automagically detect them.
1659  * ---------------------------------------------------------------------
1660  * Local variables:
1661  * mode: c++
1662  * indent-tabs-mode: t
1663  * c-basic-offset: 4
1664  * tab-width: 4
1665  * End:
1666  * vim:noexpandtab:sw=4:ts=4:
1667  */