1 /* src/vm/jit/show.cpp - showing the intermediate representation
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
33 #include "mm/memory.h"
35 #include "threads/lock.hpp"
37 #include "vm/global.h"
38 #include "vm/jit/builtin.hpp"
39 #include "vm/options.h"
40 #include "vm/string.hpp"
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"
50 #if defined(ENABLE_DEBUG_FILTER)
51 # include <sys/types.h>
53 # include "threads/thread.hpp"
57 /* global variables ***********************************************************/
64 /* prototypes *****************************************************************/
67 static void show_variable_intern(jitdata *jd, s4 index, int stage);
71 /* show_init *******************************************************************
73 Initialized the show subsystem (called by jit_init).
75 *******************************************************************************/
80 #if defined(ENABLE_DEBUG_FILTER)
92 const char *show_jit_type_names[] = {
104 const char show_jit_type_letters[] = {
118 /* show_method *****************************************************************
120 Print the intermediate representation of a method.
122 NOTE: Currently this function may only be called after register allocation!
124 *******************************************************************************/
127 void show_method(jitdata *jd, int stage)
134 basicblock *lastbptr;
138 #if defined(ENABLE_DISASSEMBLER)
142 /* get required compiler data */
149 // We need to enter a lock here, since the binutils disassembler
150 // is not reentrant-able and we could not read functions printed
154 #if defined(ENABLE_INTRP)
156 irstage = SHOW_PARSE;
161 /* get the last basic block */
163 for (lastbptr = jd->basicblocks; lastbptr->next != NULL; lastbptr = lastbptr->next);
169 if (code_is_leafmethod(code))
170 printf("LEAFMETHOD\n");
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)));
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);
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);
205 class_print(ex->catchtype.cls);
212 if (irstage >= SHOW_PARSE && rd && jd->localcount > 0) {
213 printf("Local Table:\n");
214 for (i = 0; i < jd->localcount; i++) {
217 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
218 # if defined(ENABLE_INTRP)
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);
225 # if defined(ENABLE_INTRP)
228 #endif /* defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER) */
233 if (jd->maxlocals > 0 && jd->local_map != NULL) {
234 printf("Local Map:\n");
236 for (j = 0; j < jd->maxlocals; j++) {
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)
246 printf("%4i ",jd->local_map[j*5+i]);
253 if (jd->maxinterfaces > 0 && jd->interface_map && irstage >= SHOW_STACK) {
255 interface_info *mapptr = jd->interface_map;
257 /* look if there exist any INOUTS */
258 for (i = 0; (i < (5 * jd->maxinterfaces)) && !exist; i++, mapptr++)
259 exist = (mapptr->flags != UNUSED);
262 printf("Interface Table: (In/Outvars)\n");
264 for (j = 0; j < jd->maxinterfaces; j++) {
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;
279 if (irstage >= SHOW_REGS) {
280 if (flags & SAVEDVAR) {
281 if (flags & INMEMORY)
287 if (flags & INMEMORY)
292 printf("%c%03d(", ch, regoff);
293 show_allocation(i, flags, regoff);
297 if (flags & SAVEDVAR)
310 if (rd->memuse && irstage >= SHOW_REGS) {
314 printf("Stack slots: (memuse=%d", rd->memuse);
315 if (irstage >= SHOW_CODE) {
316 printf(", stackframesize=%d", cd->stackframesize);
317 max = cd->stackframesize;
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) {
324 if ((v->flags & INMEMORY) && (v->vv.regoff == i)) {
325 show_variable(jd, j, irstage);
336 #if defined(ENABLE_REPLACEMENT)
337 if (code->rplpoints) {
338 printf("Replacement Points:\n");
339 replace_show_replacement_points(code);
342 #endif /* defined(ENABLE_REPLACEMENT) */
344 #if defined(ENABLE_DISASSEMBLER)
345 /* show code before first basic block */
347 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
348 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen);
350 for (; pc < (u1 *) ((ptrint) code->mcode + cd->dseglen + jd->basicblocks[0].mpc);)
357 /* show code of all basic blocks */
359 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next)
360 show_basicblock(jd, bptr, stage);
362 #if 0 && defined(ENABLE_DISASSEMBLER)
363 /* show code after last basic block */
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)));
370 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen + lastbptr->mpc);
372 for (; (ptrint) pc < ((ptrint) code->mcode + code->mcodelength);)
381 /* finally flush the output */
385 #endif /* !defined(NDEBUG) */
388 #if !defined(NDEBUG) && defined(ENABLE_INLINING)
389 static void show_inline_info(jitdata *jd, insinfo_inline *ii, s4 opcode, s4 stage)
394 printf("(pt %d+%d+%d st ",
395 ii->throughcount - (ii->stackvarscount - ii->paramcount),
396 ii->stackvarscount - ii->paramcount,
398 show_variable_array(jd, ii->stackvars, ii->stackvarscount, stage);
400 if (opcode == ICMD_INLINE_START || opcode == ICMD_INLINE_END) {
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);
411 method_print(ii->outer);
415 method_print(ii->method);
417 #endif /* !defined(NDEBUG) && defined(ENABLE_INLINING) */
420 /* show_basicblock *************************************************************
422 Print the intermediate representation of a basic block.
424 NOTE: Currently this function may only be called after register allocation!
426 *******************************************************************************/
429 void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
437 #if defined(ENABLE_DISASSEMBLER)
438 methodinfo *m; /* this is only a dummy */
441 s4 currentlinenumber;
444 /* get required compiler data */
449 if (bptr->flags != BBDELETED) {
450 #if defined(ENABLE_INTRP)
453 irstage = SHOW_PARSE;
458 deadcode = (bptr->flags < BBREACHED);
462 printf("======== %sL%03d ======== %s(flags: %d, bitflags: %01x, next: %d, type: ",
463 #if defined(ENABLE_REPLACEMENT)
464 (bptr->bitflags & BBFLAG_REPLACEMENT) ? "<REPLACE> " :
468 (deadcode && stage >= SHOW_STACK) ? "DEADCODE! " : "",
469 bptr->flags, bptr->bitflags,
470 (bptr->next) ? (bptr->next->nr) : -1);
472 switch (bptr->type) {
484 printf(", icount: %d", bptr->icount);
486 if (irstage >= SHOW_CFG) {
487 printf(", preds: %d [ ", bptr->predecessorcount);
489 for (i = 0; i < bptr->predecessorcount; i++)
490 printf("%d ", bptr->predecessors[i]->nr);
498 printf(" (clone of L%03d)", bptr->original->nr);
500 basicblock *b = bptr->copied_to;
502 printf(" (copied to ");
503 for (; b; b = b->copied_to)
504 printf("L%03d ", b->nr);
511 if (irstage >= SHOW_CFG) {
512 printf("succs: %d [ ", bptr->successorcount);
514 for (i = 0; i < bptr->successorcount; i++)
515 printf("%d ", bptr->successors[i]->nr);
520 if (irstage >= SHOW_STACK) {
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);
531 #if defined(ENABLE_INLINING)
532 if (bptr->inlineinfo) {
533 printf("inlineinfo: ");
534 show_inline_info(jd, bptr->inlineinfo, -1, irstage);
537 #endif /* defined(ENABLE_INLINING) */
539 #if defined(ENABLE_SSA)
543 for (i = 0; i < bptr->phicount; i++, iptr++) {
544 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
546 show_icmd(jd, iptr, deadcode, irstage);
553 for (i = 0; i < bptr->icount; i++, iptr++) {
554 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
556 show_icmd(jd, iptr, deadcode, irstage);
560 if (irstage >= SHOW_STACK) {
562 show_variable_array(jd, bptr->outvars, bptr->outdepth, irstage);
566 #if defined(ENABLE_DISASSEMBLER)
567 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd) &&
571 pc = (void *) (code->mcode + cd->dseglen + bptr->mpc);
574 if (bptr->next != NULL) {
575 for (; pc < (void *) (code->mcode + cd->dseglen + bptr->next->mpc);) {
576 currentlinenumber = code->linenumbertable->find(&m, pc);
578 if (currentlinenumber != linenumber) {
579 linenumber = currentlinenumber;
580 printf("%4d:\n", linenumber);
587 for (; pc < (void *) (code->mcode + code->mcodelength);) {
588 currentlinenumber = code->linenumbertable->find(&m, pc);
590 if (currentlinenumber != linenumber) {
591 linenumber = currentlinenumber;
592 printf("%4d:\n", linenumber);
603 #endif /* !defined(NDEBUG) */
606 /* show_icmd *******************************************************************
608 Print the intermediate representation of an instruction.
610 NOTE: Currently this function may only be called after register allocation!
612 *******************************************************************************/
616 #define SHOW_TARGET(target) \
617 if (stage >= SHOW_PARSE) { \
618 printf("--> L%03d ", (target).block->nr); \
621 printf("--> insindex %d ", (target).insindex); \
624 #define SHOW_INT_CONST(val) \
625 if (stage >= SHOW_PARSE) { \
626 printf("%d (0x%08x) ", (int32_t) (val), (int32_t) (val)); \
632 #if SIZEOF_VOID_P == 4
633 #define SHOW_LNG_CONST(val) \
634 if (stage >= SHOW_PARSE) \
635 printf("%lld (0x%016llx) ", (val), (val)); \
639 #define SHOW_LNG_CONST(val) \
640 if (stage >= SHOW_PARSE) \
641 printf("%ld (0x%016lx) ", (val), (val)); \
646 #if SIZEOF_VOID_P == 4
647 #define SHOW_ADR_CONST(val) \
648 if (stage >= SHOW_PARSE) \
649 printf("0x%08x ", (ptrint) (val)); \
653 #define SHOW_ADR_CONST(val) \
654 if (stage >= SHOW_PARSE) \
655 printf("0x%016lx ", (ptrint) (val)); \
660 #define SHOW_FLT_CONST(val) \
661 if (stage >= SHOW_PARSE) { \
664 printf("%g (0x%08x) ", (val), v.i); \
670 #if SIZEOF_VOID_P == 4
671 #define SHOW_DBL_CONST(val) \
672 if (stage >= SHOW_PARSE) { \
675 printf("%g (0x%016llx) ", (val), v.l); \
680 #define SHOW_DBL_CONST(val) \
681 if (stage >= SHOW_PARSE) { \
684 printf("%g (0x%016lx) ", (val), v.l); \
690 #define SHOW_INDEX(index) \
691 if (stage >= SHOW_PARSE) { \
692 printf("%d ", index); \
698 #define SHOW_STRING(val) \
699 if (stage >= SHOW_PARSE) { \
701 utf_display_printable_ascii( \
702 javastring_toutf((java_handle_t *)(val), false)); \
709 #define SHOW_CLASSREF_OR_CLASSINFO(c) \
710 if (stage >= SHOW_PARSE) { \
711 if (IS_CLASSREF(c)) \
712 class_classref_print(c.ref); \
714 class_print(c.cls); \
721 #define SHOW_FIELD(fmiref) \
722 if (stage >= SHOW_PARSE) { \
723 field_fieldref_print(fmiref); \
730 #define SHOW_VARIABLE(v) \
731 show_variable(jd, (v), stage)
733 #define SHOW_S1(iptr) \
734 if (stage >= SHOW_STACK) { \
735 SHOW_VARIABLE(iptr->s1.varindex); \
738 #define SHOW_S2(iptr) \
739 if (stage >= SHOW_STACK) { \
740 SHOW_VARIABLE(iptr->sx.s23.s2.varindex); \
743 #define SHOW_S3(iptr) \
744 if (stage >= SHOW_STACK) { \
745 SHOW_VARIABLE(iptr->sx.s23.s3.varindex); \
748 #define SHOW_DST(iptr) \
749 if (stage >= SHOW_STACK) { \
751 SHOW_VARIABLE(iptr->dst.varindex); \
754 #define SHOW_S1_LOCAL(iptr) \
755 if (stage >= SHOW_STACK) { \
756 printf("L%d ", iptr->s1.varindex); \
759 printf("JavaL%d ", iptr->s1.varindex); \
762 #define SHOW_DST_LOCAL(iptr) \
763 if (stage >= SHOW_STACK) { \
764 printf("=> L%d ", iptr->dst.varindex); \
767 printf("=> JavaL%d ", iptr->dst.varindex); \
770 void show_allocation(s4 type, s4 flags, s4 regoff)
772 if (type == TYPE_RET) {
777 if (flags & INMEMORY) {
778 printf("M%02d", regoff);
782 #ifdef HAS_ADDRESS_REGISTER_FILE
783 if (type == TYPE_ADR) {
784 printf("R%02d", regoff);
789 if (IS_FLT_DBL_TYPE(type)) {
790 printf("F%02d", regoff);
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)
799 printf("%3d/%3d", GET_LOW_REG(regoff),
800 GET_HIGH_REG(regoff));
803 printf("%3s/%3s", abi_registers_integer_name[GET_LOW_REG(regoff)],
804 abi_registers_integer_name[GET_HIGH_REG(regoff)]);
806 printf("%3d/%3d", GET_LOW_REG(regoff),
807 GET_HIGH_REG(regoff));
811 #endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
813 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
814 # if defined(ENABLE_INTRP)
816 printf("%3d", regoff);
819 printf("%3s", abi_registers_integer_name[regoff]);
821 printf("%3d", regoff);
825 void show_variable(jitdata *jd, s4 index, int stage)
827 show_variable_intern(jd, index, stage);
831 static void show_variable_intern(jitdata *jd, s4 index, int stage)
837 if (index < 0 || index >= jd->vartop) {
838 printf("<INVALID INDEX:%d>", index);
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;
854 if (index < jd->localcount) {
856 if (v->flags & (PREALLOC | INOUT))
857 printf("<INVALID FLAGS!>");
860 if (v->flags & PREALLOC) {
862 if (v->flags & INOUT) {
863 /* PREALLOC is used to avoid allocation of TYPE_RET */
864 if (v->type == TYPE_RET)
867 printf("<INVALID FLAGS!>");
870 else if (v->flags & INOUT)
876 printf("%c%c%d", kind, type, index);
878 if (v->flags & SAVEDVAR)
881 if (stage >= SHOW_REGS || (v->flags & PREALLOC)) {
883 show_allocation(v->type, v->flags, v->vv.regoff);
887 if (v->type == TYPE_RET && (v->flags & PREALLOC)) {
888 printf("(L%03d)", v->vv.retaddr->nr);
892 static void show_variable_array_intern(jitdata *jd, s4 *vars, int n, int stage,
904 for (i=0; i<n; ++i) {
908 if (vars[i] == UNUSED)
910 else if (javalocals) {
911 nr = RETADDR_FROM_JAVALOCAL(vars[i]);
912 printf("ret(L%03d)", nr);
915 printf("<INVALID INDEX:%d>", vars[i]);
919 show_variable_intern(jd, vars[i], stage);
924 void show_variable_array(jitdata *jd, s4 *vars, int n, int stage)
926 show_variable_array_intern(jd, vars, n, stage, false);
929 void show_javalocals_array(jitdata *jd, s4 *vars, int n, int stage)
931 show_variable_array_intern(jd, vars, n, stage, true);
934 void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
937 branch_target_t *table;
938 lookup_target_t *lookup;
939 constant_FMIref *fmiref;
943 /* get the opcode and the condition */
947 printf("%s ", icmd_table[opcode].name);
949 if (stage < SHOW_PARSE)
955 /* Print the condition for conditional instructions. */
957 /* XXX print condition from flags */
959 if (iptr->flags.bits & INS_FLAG_UNRESOLVED)
960 printf("(UNRESOLVED) ");
970 case ICMD_ARRAYLENGTH:
1037 /* binary/const INT */
1038 case ICMD_IADDCONST:
1039 case ICMD_ISUBCONST:
1040 case ICMD_IMULCONST:
1044 case ICMD_IANDCONST:
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:
1054 SHOW_INT_CONST(iptr->sx.val.i);
1058 /* ?ASTORECONST (trinary/const INT) */
1059 case ICMD_IASTORECONST:
1060 case ICMD_BASTORECONST:
1061 case ICMD_CASTORECONST:
1062 case ICMD_SASTORECONST:
1065 SHOW_INT_CONST(iptr->sx.s23.s3.constval);
1070 SHOW_INT_CONST(iptr->sx.val.i);
1074 /* binary/const LNG */
1075 case ICMD_LADDCONST:
1076 case ICMD_LSUBCONST:
1077 case ICMD_LMULCONST:
1081 case ICMD_LANDCONST:
1083 case ICMD_LXORCONST:
1085 SHOW_LNG_CONST(iptr->sx.val.l);
1089 /* trinary/const LNG (<= pointer size) */
1090 case ICMD_LASTORECONST:
1093 SHOW_ADR_CONST(iptr->sx.s23.s3.constval);
1098 SHOW_LNG_CONST(iptr->sx.val.l);
1104 SHOW_FLT_CONST(iptr->sx.val.f);
1110 SHOW_DBL_CONST(iptr->sx.val.d);
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);
1120 else if (iptr->sx.val.anyptr == NULL) {
1124 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1125 SHOW_STRING(iptr->sx.val.stringconst);
1130 case ICMD_AASTORECONST:
1133 printf("%p ", (void*) iptr->sx.s23.s3.constval);
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) {
1144 if (opcode == ICMD_PUTFIELD) {
1148 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1151 if (opcode == ICMD_GETSTATIC || opcode == ICMD_GETFIELD) {
1157 SHOW_S1_LOCAL(iptr);
1158 SHOW_INT_CONST(iptr->sx.val.i);
1159 SHOW_DST_LOCAL(iptr);
1189 SHOW_S1_LOCAL(iptr);
1190 if (stage >= SHOW_STACK) {
1191 printf(" ---> L%03d", iptr->dst.block->nr);
1200 SHOW_S1_LOCAL(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));
1226 case ICMD_ANEWARRAY:
1230 case ICMD_MULTIANEWARRAY:
1231 if (stage >= SHOW_STACK) {
1232 argp = iptr->sx.s23.s2.args;
1233 i = iptr->s1.argcount;
1235 SHOW_VARIABLE(*(argp++));
1239 printf("argcount=%d ", iptr->s1.argcount);
1241 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1246 case ICMD_CHECKCAST:
1248 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1253 case ICMD_INSTANCEOF:
1258 case ICMD_INLINE_START:
1259 case ICMD_INLINE_END:
1260 case ICMD_INLINE_BODY:
1261 #if defined(ENABLE_INLINING)
1263 insinfo_inline *ii = iptr->sx.s23.s3.inlineinfo;
1264 show_inline_info(jd, ii, opcode, stage);
1270 if (stage >= SHOW_STACK) {
1271 argp = iptr->sx.s23.s2.args;
1272 i = iptr->s1.argcount;
1274 if ((iptr->s1.argcount - 1 - i) == iptr->sx.s23.s3.bte->md->paramcount)
1275 printf(" pass-through: ");
1276 SHOW_VARIABLE(*(argp++));
1279 printf("%s ", iptr->sx.s23.s3.bte->cname);
1280 if (iptr->sx.s23.s3.bte->md->returntype.type != TYPE_VOID) {
1285 case ICMD_INVOKEVIRTUAL:
1286 case ICMD_INVOKESPECIAL:
1287 case ICMD_INVOKESTATIC:
1288 case ICMD_INVOKEINTERFACE:
1289 if (stage >= SHOW_STACK) {
1291 INSTRUCTION_GET_METHODDESC(iptr, md);
1292 argp = iptr->sx.s23.s2.args;
1293 i = iptr->s1.argcount;
1295 if ((iptr->s1.argcount - 1 - i) == md->paramcount)
1296 printf(" pass-through: ");
1297 SHOW_VARIABLE(*(argp++));
1300 INSTRUCTION_GET_METHODREF(iptr, fmiref);
1301 method_methodref_print(fmiref);
1302 if (fmiref->parseddesc.md->returntype.type != TYPE_VOID) {
1315 SHOW_INT_CONST(iptr->sx.val.i);
1316 SHOW_TARGET(iptr->dst);
1326 SHOW_LNG_CONST(iptr->sx.val.l);
1327 SHOW_TARGET(iptr->dst);
1331 SHOW_TARGET(iptr->dst);
1335 SHOW_TARGET(iptr->sx.s23.s3.jsrtarget);
1340 case ICMD_IFNONNULL:
1342 SHOW_TARGET(iptr->dst);
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:
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:
1359 case ICMD_IF_ACMPEQ:
1360 case ICMD_IF_ACMPNE:
1363 SHOW_TARGET(iptr->dst);
1366 case ICMD_TABLESWITCH:
1368 table = iptr->dst.table;
1370 i = iptr->sx.s23.s3.tablehigh - iptr->sx.s23.s2.tablelow + 1;
1372 printf("high=%d low=%d count=%d\n", iptr->sx.s23.s3.tablehigh, iptr->sx.s23.s2.tablelow, i);
1374 printf("\t\t%d --> ", (int) (table - iptr->dst.table));
1375 printf("L%03d\n", table->block->nr);
1381 case ICMD_LOOKUPSWITCH:
1384 printf("count=%d, default=L%03d\n",
1385 iptr->sx.s23.s2.lookupcount,
1386 iptr->sx.s23.s3.lookupdefault.block->nr);
1388 lookup = iptr->dst.lookup;
1389 i = iptr->sx.s23.s2.lookupcount;
1392 printf("\t\t%d --> L%03d\n",
1394 lookup->target.block->nr);
1409 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1410 /* XXX this needs more work */
1412 unresolved_class_debug_dump(iptr->sx.s23.s2.uc, stdout);
1422 case ICMD_GETEXCEPTION:
1425 #if defined(ENABLE_SSA)
1428 for (i = 0; i < iptr->s1.argcount; ++i) {
1429 SHOW_VARIABLE(iptr->sx.s23.s2.iargs[i]->dst.varindex);
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 ");
1441 #endif /* !defined(NDEBUG) */
1443 /* Debug output filtering */
1445 #if defined(ENABLE_DEBUG_FILTER)
1447 #if !defined(ENABLE_THREADS)
1448 u2 _no_threads_filterverbosecallctr[2] = { 0, 0 };
1451 struct show_filter {
1452 /* Boolean indicating if filter is enabled. */
1454 /* Regular expression the method name is matched against */
1456 /* Flag set on m->filtermatches if regex matches */
1460 typedef struct show_filter show_filter_t;
1462 #define SHOW_FILTERS_SIZE 3
1464 /* Array of filters applyed on a method */
1465 static struct show_filter show_filters[SHOW_FILTERS_SIZE];
1467 static void show_filter_init(show_filter_t *cf, const char *str, u1 flag, u1 default_flag, const char *description) {
1472 err = regcomp(&cf->regex, str, REG_EXTENDED | REG_NOSUB);
1474 regerror(err, &cf->regex, err_buf, sizeof(err_buf));
1476 "Invalid value given for %s: `%s' (%s).",
1477 description, str, err_buf
1483 cf->flag = default_flag;
1488 void show_filters_init(void) {
1492 opt_filter_verbosecall_include,
1493 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1494 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1495 "verbose call include filter"
1500 opt_filter_verbosecall_exclude,
1501 SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE,
1503 "verbose call exclude filter"
1508 opt_filter_show_method,
1509 SHOW_FILTER_FLAG_SHOW_METHOD,
1510 SHOW_FILTER_FLAG_SHOW_METHOD,
1511 "show method filter"
1517 (Pseudo)State machine:
1519 States are INITIAL, INCLUDE1, INCLUDE2, ..., EXCLUDE1, ..., EXCLUDE2, ...
1522 Enter Include Include
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 | |
1533 Exclude Include Include
1535 Verbose call scope is active if we are in a INCLUDE state.
1539 INITIAL: ctr[0] == 0, ctr[1] == 0
1540 INCLUDEN: ctr[1] == N, ctr[1] == 0
1541 EXCLUDEN: ctr[1] == N
1544 void show_filters_apply(methodinfo *m) {
1550 /* compose full name of method */
1553 utf_bytes(m->clazz->name) +
1555 utf_bytes(m->name) +
1556 utf_bytes(m->descriptor) +
1559 method_name = MNEW(char, len);
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);
1566 /* reset all flags */
1568 m->filtermatches = 0;
1570 for (i = 0; i < SHOW_FILTERS_SIZE; ++i) {
1571 if (show_filters[i].enabled) {
1573 res = regexec(&show_filters[i].regex, method_name, 0, NULL, 0);
1576 m->filtermatches |= show_filters[i].flag;
1579 /* Default is to show all */
1580 m->filtermatches |= show_filters[i].flag;
1585 MFREE(method_name, char, len);
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]
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]);
1606 int show_filters_test_verbosecall_enter(methodinfo *m) {
1610 if (STATE_IS_INITIAL()) {
1611 if (EVENT_INCLUDE()) {
1612 TRANSITION_NEXT_INCLUDE();
1614 } else if (STATE_IS_INCLUDE()) {
1615 if (EVENT_EXCLUDE()) {
1616 TRANSITION_NEXT_EXCLUDE();
1617 /* just entered exclude, show this method */
1619 } else if (EVENT_INCLUDE()) {
1620 TRANSITION_NEXT_INCLUDE();
1622 } else if (STATE_IS_EXCLUDE()) {
1623 if (EVENT_EXCLUDE()) {
1624 TRANSITION_NEXT_EXCLUDE();
1628 return STATE_IS_INCLUDE() || force_show;
1631 int show_filters_test_verbosecall_exit(methodinfo *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;
1642 } else if (STATE_IS_EXCLUDE()) {
1643 if (EVENT_EXCLUDE()) {
1644 TRANSITION_PREV_EXCLUDE();
1649 return STATE_IS_INCLUDE() || force_show;
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 * ---------------------------------------------------------------------
1662 * indent-tabs-mode: t
1666 * vim:noexpandtab:sw=4:ts=4: