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.hpp"
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.hpp"
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)
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) */
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 (!code->patchers->empty()) {
337 int number = code->patchers->size();
338 printf("Patcher References (number=%d):\n", number);
339 patcher_list_show(code);
343 #if defined(ENABLE_REPLACEMENT)
344 if (code->rplpoints) {
345 printf("Replacement Points:\n");
346 replace_show_replacement_points(code);
349 #endif /* defined(ENABLE_REPLACEMENT) */
351 #if defined(ENABLE_DISASSEMBLER)
352 /* show code before first basic block */
354 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
355 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen);
357 for (; pc < (u1 *) ((ptrint) code->mcode + cd->dseglen + jd->basicblocks[0].mpc);)
364 /* show code of all basic blocks */
366 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next)
367 show_basicblock(jd, bptr, stage);
369 #if 0 && defined(ENABLE_DISASSEMBLER)
370 /* show code after last basic block */
372 if (stage >= SHOW_CODE && opt_showdisassemble) {
373 printf("\nStubs code:\n");
374 printf("Length: %d\n\n", (s4) (code->mcodelength -
375 ((ptrint) cd->dseglen + lastbptr->mpc)));
377 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen + lastbptr->mpc);
379 for (; (ptrint) pc < ((ptrint) code->mcode + code->mcodelength);)
388 /* finally flush the output */
392 #endif /* !defined(NDEBUG) */
395 #if !defined(NDEBUG) && defined(ENABLE_INLINING)
396 static void show_inline_info(jitdata *jd, insinfo_inline *ii, s4 opcode, s4 stage)
401 printf("(pt %d+%d+%d st ",
402 ii->throughcount - (ii->stackvarscount - ii->paramcount),
403 ii->stackvarscount - ii->paramcount,
405 show_variable_array(jd, ii->stackvars, ii->stackvarscount, stage);
407 if (opcode == ICMD_INLINE_START || opcode == ICMD_INLINE_END) {
409 jl = (opcode == ICMD_INLINE_START) ? ii->javalocals_start : ii->javalocals_end;
410 n = (opcode == ICMD_INLINE_START) ? ii->method->maxlocals : ii->outer->maxlocals;
411 show_javalocals_array(jd, jl, n, stage);
418 method_print(ii->outer);
422 method_print(ii->method);
424 #endif /* !defined(NDEBUG) && defined(ENABLE_INLINING) */
427 /* show_basicblock *************************************************************
429 Print the intermediate representation of a basic block.
431 NOTE: Currently this function may only be called after register allocation!
433 *******************************************************************************/
436 void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
444 #if defined(ENABLE_DISASSEMBLER)
445 methodinfo *m; /* this is only a dummy */
448 s4 currentlinenumber;
451 /* get required compiler data */
456 if (bptr->flags != BBDELETED) {
457 #if defined(ENABLE_INTRP)
460 irstage = SHOW_PARSE;
465 deadcode = (bptr->flags < BBREACHED);
469 printf("======== %sL%03d ======== %s(flags: %d, bitflags: %01x, next: %d, type: ",
470 #if defined(ENABLE_REPLACEMENT)
471 (bptr->bitflags & BBFLAG_REPLACEMENT) ? "<REPLACE> " :
475 (deadcode && stage >= SHOW_STACK) ? "DEADCODE! " : "",
476 bptr->flags, bptr->bitflags,
477 (bptr->next) ? (bptr->next->nr) : -1);
479 switch (bptr->type) {
491 printf(", icount: %d", bptr->icount);
493 if (irstage >= SHOW_CFG) {
494 printf(", preds: %d [ ", bptr->predecessorcount);
496 for (i = 0; i < bptr->predecessorcount; i++)
497 printf("%d ", bptr->predecessors[i]->nr);
505 printf(" (clone of L%03d)", bptr->original->nr);
507 basicblock *b = bptr->copied_to;
509 printf(" (copied to ");
510 for (; b; b = b->copied_to)
511 printf("L%03d ", b->nr);
518 if (irstage >= SHOW_CFG) {
519 printf("succs: %d [ ", bptr->successorcount);
521 for (i = 0; i < bptr->successorcount; i++)
522 printf("%d ", bptr->successors[i]->nr);
527 if (irstage >= SHOW_STACK) {
529 show_variable_array(jd, bptr->invars, bptr->indepth, irstage);
530 printf(" javalocals: ");
531 if (bptr->javalocals)
532 show_javalocals_array(jd, bptr->javalocals, bptr->method->maxlocals, irstage);
538 #if defined(ENABLE_INLINING)
539 if (bptr->inlineinfo) {
540 printf("inlineinfo: ");
541 show_inline_info(jd, bptr->inlineinfo, -1, irstage);
544 #endif /* defined(ENABLE_INLINING) */
546 #if defined(ENABLE_SSA)
550 for (i = 0; i < bptr->phicount; i++, iptr++) {
551 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
553 show_icmd(jd, iptr, deadcode, irstage);
560 for (i = 0; i < bptr->icount; i++, iptr++) {
561 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
563 show_icmd(jd, iptr, deadcode, irstage);
567 if (irstage >= SHOW_STACK) {
569 show_variable_array(jd, bptr->outvars, bptr->outdepth, irstage);
573 #if defined(ENABLE_DISASSEMBLER)
574 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd) &&
578 pc = (void *) (code->mcode + cd->dseglen + bptr->mpc);
581 if (bptr->next != NULL) {
582 for (; pc < (void *) (code->mcode + cd->dseglen + bptr->next->mpc);) {
583 currentlinenumber = code->linenumbertable->find(&m, pc);
585 if (currentlinenumber != linenumber) {
586 linenumber = currentlinenumber;
587 printf("%4d:\n", linenumber);
594 for (; pc < (void *) (code->mcode + code->mcodelength);) {
595 currentlinenumber = code->linenumbertable->find(&m, pc);
597 if (currentlinenumber != linenumber) {
598 linenumber = currentlinenumber;
599 printf("%4d:\n", linenumber);
610 #endif /* !defined(NDEBUG) */
613 /* show_icmd *******************************************************************
615 Print the intermediate representation of an instruction.
617 NOTE: Currently this function may only be called after register allocation!
619 *******************************************************************************/
623 #define SHOW_TARGET(target) \
624 if (stage >= SHOW_PARSE) { \
625 printf("--> L%03d ", (target).block->nr); \
628 printf("--> insindex %d ", (target).insindex); \
631 #define SHOW_INT_CONST(val) \
632 if (stage >= SHOW_PARSE) { \
633 printf("%d (0x%08x) ", (int32_t) (val), (int32_t) (val)); \
639 #if SIZEOF_VOID_P == 4
640 #define SHOW_LNG_CONST(val) \
641 if (stage >= SHOW_PARSE) \
642 printf("%lld (0x%016llx) ", (val), (val)); \
646 #define SHOW_LNG_CONST(val) \
647 if (stage >= SHOW_PARSE) \
648 printf("%ld (0x%016lx) ", (val), (val)); \
653 #if SIZEOF_VOID_P == 4
654 #define SHOW_ADR_CONST(val) \
655 if (stage >= SHOW_PARSE) \
656 printf("0x%08x ", (ptrint) (val)); \
660 #define SHOW_ADR_CONST(val) \
661 if (stage >= SHOW_PARSE) \
662 printf("0x%016lx ", (ptrint) (val)); \
667 #define SHOW_FLT_CONST(val) \
668 if (stage >= SHOW_PARSE) { \
671 printf("%g (0x%08x) ", (val), v.i); \
677 #if SIZEOF_VOID_P == 4
678 #define SHOW_DBL_CONST(val) \
679 if (stage >= SHOW_PARSE) { \
682 printf("%g (0x%016llx) ", (val), v.l); \
687 #define SHOW_DBL_CONST(val) \
688 if (stage >= SHOW_PARSE) { \
691 printf("%g (0x%016lx) ", (val), v.l); \
697 #define SHOW_INDEX(index) \
698 if (stage >= SHOW_PARSE) { \
699 printf("%d ", index); \
705 #define SHOW_STRING(val) \
706 if (stage >= SHOW_PARSE) { \
708 utf_display_printable_ascii( \
709 javastring_toutf((java_handle_t *)(val), false)); \
716 #define SHOW_CLASSREF_OR_CLASSINFO(c) \
717 if (stage >= SHOW_PARSE) { \
718 if (IS_CLASSREF(c)) \
719 class_classref_print(c.ref); \
721 class_print(c.cls); \
728 #define SHOW_FIELD(fmiref) \
729 if (stage >= SHOW_PARSE) { \
730 field_fieldref_print(fmiref); \
737 #define SHOW_VARIABLE(v) \
738 show_variable(jd, (v), stage)
740 #define SHOW_S1(iptr) \
741 if (stage >= SHOW_STACK) { \
742 SHOW_VARIABLE(iptr->s1.varindex); \
745 #define SHOW_S2(iptr) \
746 if (stage >= SHOW_STACK) { \
747 SHOW_VARIABLE(iptr->sx.s23.s2.varindex); \
750 #define SHOW_S3(iptr) \
751 if (stage >= SHOW_STACK) { \
752 SHOW_VARIABLE(iptr->sx.s23.s3.varindex); \
755 #define SHOW_DST(iptr) \
756 if (stage >= SHOW_STACK) { \
758 SHOW_VARIABLE(iptr->dst.varindex); \
761 #define SHOW_S1_LOCAL(iptr) \
762 if (stage >= SHOW_STACK) { \
763 printf("L%d ", iptr->s1.varindex); \
766 printf("JavaL%d ", iptr->s1.varindex); \
769 #define SHOW_DST_LOCAL(iptr) \
770 if (stage >= SHOW_STACK) { \
771 printf("=> L%d ", iptr->dst.varindex); \
774 printf("=> JavaL%d ", iptr->dst.varindex); \
777 void show_allocation(s4 type, s4 flags, s4 regoff)
779 if (type == TYPE_RET) {
784 if (flags & INMEMORY) {
785 printf("M%02d", regoff);
789 #ifdef HAS_ADDRESS_REGISTER_FILE
790 if (type == TYPE_ADR) {
791 printf("R%02d", regoff);
796 if (IS_FLT_DBL_TYPE(type)) {
797 printf("F%02d", regoff);
801 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
802 if (IS_2_WORD_TYPE(type)) {
803 # if defined(ENABLE_JIT)
804 # if defined(ENABLE_INTRP)
806 printf("%3d/%3d", GET_LOW_REG(regoff),
807 GET_HIGH_REG(regoff));
810 printf("%3s/%3s", abi_registers_integer_name[GET_LOW_REG(regoff)],
811 abi_registers_integer_name[GET_HIGH_REG(regoff)]);
813 printf("%3d/%3d", GET_LOW_REG(regoff),
814 GET_HIGH_REG(regoff));
818 #endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
820 #if defined(ENABLE_JIT)
821 # if defined(ENABLE_INTRP)
823 printf("%3d", regoff);
826 printf("%3s", abi_registers_integer_name[regoff]);
828 printf("%3d", regoff);
832 void show_variable(jitdata *jd, s4 index, int stage)
834 show_variable_intern(jd, index, stage);
838 static void show_variable_intern(jitdata *jd, s4 index, int stage)
844 if (index < 0 || index >= jd->vartop) {
845 printf("<INVALID INDEX:%d>", index);
852 case TYPE_INT: type = 'i'; break;
853 case TYPE_LNG: type = 'l'; break;
854 case TYPE_FLT: type = 'f'; break;
855 case TYPE_DBL: type = 'd'; break;
856 case TYPE_ADR: type = 'a'; break;
857 case TYPE_RET: type = 'r'; break;
861 if (index < jd->localcount) {
863 if (v->flags & (PREALLOC | INOUT))
864 printf("<INVALID FLAGS!>");
867 if (v->flags & PREALLOC) {
869 if (v->flags & INOUT) {
870 /* PREALLOC is used to avoid allocation of TYPE_RET */
871 if (v->type == TYPE_RET)
874 printf("<INVALID FLAGS!>");
877 else if (v->flags & INOUT)
883 printf("%c%c%d", kind, type, index);
885 if (v->flags & SAVEDVAR)
888 if (stage >= SHOW_REGS || (v->flags & PREALLOC)) {
890 show_allocation(v->type, v->flags, v->vv.regoff);
894 if (v->type == TYPE_RET && (v->flags & PREALLOC)) {
895 printf("(L%03d)", v->vv.retaddr->nr);
899 static void show_variable_array_intern(jitdata *jd, s4 *vars, int n, int stage,
911 for (i=0; i<n; ++i) {
915 if (vars[i] == UNUSED)
917 else if (javalocals) {
918 nr = RETADDR_FROM_JAVALOCAL(vars[i]);
919 printf("ret(L%03d)", nr);
922 printf("<INVALID INDEX:%d>", vars[i]);
926 show_variable_intern(jd, vars[i], stage);
931 void show_variable_array(jitdata *jd, s4 *vars, int n, int stage)
933 show_variable_array_intern(jd, vars, n, stage, false);
936 void show_javalocals_array(jitdata *jd, s4 *vars, int n, int stage)
938 show_variable_array_intern(jd, vars, n, stage, true);
941 void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
944 branch_target_t *table;
945 lookup_target_t *lookup;
946 constant_FMIref *fmiref;
950 /* get the opcode and the condition */
954 printf("%s ", icmd_table[opcode].name);
956 if (stage < SHOW_PARSE)
962 /* Print the condition for conditional instructions. */
964 /* XXX print condition from flags */
966 if (iptr->flags.bits & INS_FLAG_UNRESOLVED)
967 printf("(UNRESOLVED) ");
977 case ICMD_ARRAYLENGTH:
1044 /* binary/const INT */
1045 case ICMD_IADDCONST:
1046 case ICMD_ISUBCONST:
1047 case ICMD_IMULCONST:
1051 case ICMD_IANDCONST:
1053 case ICMD_IXORCONST:
1054 case ICMD_ISHLCONST:
1055 case ICMD_ISHRCONST:
1056 case ICMD_IUSHRCONST:
1057 case ICMD_LSHLCONST:
1058 case ICMD_LSHRCONST:
1059 case ICMD_LUSHRCONST:
1061 SHOW_INT_CONST(iptr->sx.val.i);
1065 /* ?ASTORECONST (trinary/const INT) */
1066 case ICMD_IASTORECONST:
1067 case ICMD_BASTORECONST:
1068 case ICMD_CASTORECONST:
1069 case ICMD_SASTORECONST:
1072 SHOW_INT_CONST(iptr->sx.s23.s3.constval);
1077 SHOW_INT_CONST(iptr->sx.val.i);
1081 /* binary/const LNG */
1082 case ICMD_LADDCONST:
1083 case ICMD_LSUBCONST:
1084 case ICMD_LMULCONST:
1088 case ICMD_LANDCONST:
1090 case ICMD_LXORCONST:
1092 SHOW_LNG_CONST(iptr->sx.val.l);
1096 /* trinary/const LNG (<= pointer size) */
1097 case ICMD_LASTORECONST:
1100 SHOW_ADR_CONST(iptr->sx.s23.s3.constval);
1105 SHOW_LNG_CONST(iptr->sx.val.l);
1111 SHOW_FLT_CONST(iptr->sx.val.f);
1117 SHOW_DBL_CONST(iptr->sx.val.d);
1123 if (iptr->flags.bits & INS_FLAG_CLASS) {
1124 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1125 SHOW_CLASSREF_OR_CLASSINFO(iptr->sx.val.c);
1127 else if (iptr->sx.val.anyptr == NULL) {
1131 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1132 SHOW_STRING(iptr->sx.val.stringconst);
1137 case ICMD_AASTORECONST:
1140 printf("%p ", (void*) iptr->sx.s23.s3.constval);
1143 case ICMD_GETFIELD: /* 1 -> 1 */
1144 case ICMD_PUTFIELD: /* 2 -> 0 */
1145 case ICMD_PUTSTATIC: /* 1 -> 0 */
1146 case ICMD_GETSTATIC: /* 0 -> 1 */
1147 case ICMD_PUTSTATICCONST: /* 0 -> 0 */
1148 case ICMD_PUTFIELDCONST: /* 1 -> 0 */
1149 if (opcode != ICMD_GETSTATIC && opcode != ICMD_PUTSTATICCONST) {
1151 if (opcode == ICMD_PUTFIELD) {
1155 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1158 if (opcode == ICMD_GETSTATIC || opcode == ICMD_GETFIELD) {
1164 SHOW_S1_LOCAL(iptr);
1165 SHOW_INT_CONST(iptr->sx.val.i);
1166 SHOW_DST_LOCAL(iptr);
1196 SHOW_S1_LOCAL(iptr);
1197 if (stage >= SHOW_STACK) {
1198 printf(" ---> L%03d", iptr->dst.block->nr);
1207 SHOW_S1_LOCAL(iptr);
1217 SHOW_DST_LOCAL(iptr);
1218 if (stage >= SHOW_STACK && iptr->sx.s23.s3.javaindex != UNUSED)
1219 printf(" (javaindex %d)", iptr->sx.s23.s3.javaindex);
1220 if (iptr->flags.bits & INS_FLAG_RETADDR) {
1221 printf(" (retaddr L%03d)", RETADDR_FROM_JAVALOCAL(iptr->sx.s23.s2.retaddrnr));
1233 case ICMD_ANEWARRAY:
1237 case ICMD_MULTIANEWARRAY:
1238 if (stage >= SHOW_STACK) {
1239 argp = iptr->sx.s23.s2.args;
1240 i = iptr->s1.argcount;
1242 SHOW_VARIABLE(*(argp++));
1246 printf("argcount=%d ", iptr->s1.argcount);
1248 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1253 case ICMD_CHECKCAST:
1255 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1260 case ICMD_INSTANCEOF:
1265 case ICMD_INLINE_START:
1266 case ICMD_INLINE_END:
1267 case ICMD_INLINE_BODY:
1268 #if defined(ENABLE_INLINING)
1270 insinfo_inline *ii = iptr->sx.s23.s3.inlineinfo;
1271 show_inline_info(jd, ii, opcode, stage);
1277 if (stage >= SHOW_STACK) {
1278 argp = iptr->sx.s23.s2.args;
1279 i = iptr->s1.argcount;
1281 if ((iptr->s1.argcount - 1 - i) == iptr->sx.s23.s3.bte->md->paramcount)
1282 printf(" pass-through: ");
1283 SHOW_VARIABLE(*(argp++));
1286 printf("%s ", iptr->sx.s23.s3.bte->cname);
1287 if (iptr->sx.s23.s3.bte->md->returntype.type != TYPE_VOID) {
1292 case ICMD_INVOKEVIRTUAL:
1293 case ICMD_INVOKESPECIAL:
1294 case ICMD_INVOKESTATIC:
1295 case ICMD_INVOKEINTERFACE:
1296 if (stage >= SHOW_STACK) {
1298 INSTRUCTION_GET_METHODDESC(iptr, md);
1299 argp = iptr->sx.s23.s2.args;
1300 i = iptr->s1.argcount;
1302 if ((iptr->s1.argcount - 1 - i) == md->paramcount)
1303 printf(" pass-through: ");
1304 SHOW_VARIABLE(*(argp++));
1307 INSTRUCTION_GET_METHODREF(iptr, fmiref);
1308 method_methodref_print(fmiref);
1309 if (fmiref->parseddesc.md->returntype.type != TYPE_VOID) {
1322 SHOW_INT_CONST(iptr->sx.val.i);
1323 SHOW_TARGET(iptr->dst);
1333 SHOW_LNG_CONST(iptr->sx.val.l);
1334 SHOW_TARGET(iptr->dst);
1338 SHOW_TARGET(iptr->dst);
1342 SHOW_TARGET(iptr->sx.s23.s3.jsrtarget);
1347 case ICMD_IFNONNULL:
1349 SHOW_TARGET(iptr->dst);
1352 case ICMD_IF_ICMPEQ:
1353 case ICMD_IF_ICMPNE:
1354 case ICMD_IF_ICMPLT:
1355 case ICMD_IF_ICMPGE:
1356 case ICMD_IF_ICMPGT:
1357 case ICMD_IF_ICMPLE:
1359 case ICMD_IF_LCMPEQ:
1360 case ICMD_IF_LCMPNE:
1361 case ICMD_IF_LCMPLT:
1362 case ICMD_IF_LCMPGE:
1363 case ICMD_IF_LCMPGT:
1364 case ICMD_IF_LCMPLE:
1366 case ICMD_IF_ACMPEQ:
1367 case ICMD_IF_ACMPNE:
1370 SHOW_TARGET(iptr->dst);
1373 case ICMD_TABLESWITCH:
1375 table = iptr->dst.table;
1377 i = iptr->sx.s23.s3.tablehigh - iptr->sx.s23.s2.tablelow + 1;
1379 printf("high=%d low=%d count=%d\n", iptr->sx.s23.s3.tablehigh, iptr->sx.s23.s2.tablelow, i);
1381 printf("\t\t%d --> ", (int) (table - iptr->dst.table));
1382 printf("L%03d\n", table->block->nr);
1388 case ICMD_LOOKUPSWITCH:
1391 printf("count=%d, default=L%03d\n",
1392 iptr->sx.s23.s2.lookupcount,
1393 iptr->sx.s23.s3.lookupdefault.block->nr);
1395 lookup = iptr->dst.lookup;
1396 i = iptr->sx.s23.s2.lookupcount;
1399 printf("\t\t%d --> L%03d\n",
1401 lookup->target.block->nr);
1416 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1417 /* XXX this needs more work */
1419 unresolved_class_debug_dump(iptr->sx.s23.s2.uc, stdout);
1429 case ICMD_GETEXCEPTION:
1432 #if defined(ENABLE_SSA)
1435 for (i = 0; i < iptr->s1.argcount; ++i) {
1436 SHOW_VARIABLE(iptr->sx.s23.s2.iargs[i]->dst.varindex);
1440 if (iptr->flags.bits & (1 << 0)) printf("used ");
1441 if (iptr->flags.bits & (1 << 1)) printf("redundantAll ");
1442 if (iptr->flags.bits & (1 << 2)) printf("redundantOne ");
1448 #endif /* !defined(NDEBUG) */
1450 /* Debug output filtering */
1452 #if defined(ENABLE_DEBUG_FILTER)
1454 #if !defined(ENABLE_THREADS)
1455 u2 _no_threads_filterverbosecallctr[2] = { 0, 0 };
1458 struct show_filter {
1459 /* Boolean indicating if filter is enabled. */
1461 /* Regular expression the method name is matched against */
1463 /* Flag set on m->filtermatches if regex matches */
1467 typedef struct show_filter show_filter_t;
1469 #define SHOW_FILTERS_SIZE 3
1471 /* Array of filters applyed on a method */
1472 static struct show_filter show_filters[SHOW_FILTERS_SIZE];
1474 static void show_filter_init(show_filter_t *cf, const char *str, u1 flag, u1 default_flag, const char *description) {
1479 err = regcomp(&cf->regex, str, REG_EXTENDED | REG_NOSUB);
1481 regerror(err, &cf->regex, err_buf, sizeof(err_buf));
1483 "Invalid value given for %s: `%s' (%s).",
1484 description, str, err_buf
1490 cf->flag = default_flag;
1495 void show_filters_init(void) {
1499 opt_filter_verbosecall_include,
1500 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1501 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1502 "verbose call include filter"
1507 opt_filter_verbosecall_exclude,
1508 SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE,
1510 "verbose call exclude filter"
1515 opt_filter_show_method,
1516 SHOW_FILTER_FLAG_SHOW_METHOD,
1517 SHOW_FILTER_FLAG_SHOW_METHOD,
1518 "show method filter"
1524 (Pseudo)State machine:
1526 States are INITIAL, INCLUDE1, INCLUDE2, ..., EXCLUDE1, ..., EXCLUDE2, ...
1529 Enter Include Include
1531 | | Enter Enter Enter | | Enter | |
1532 | | Include Include Exclude | | Exclude | |
1533 | v ---------> ----------> ----------> | v ----------> | v
1534 INITIAL INCLUDE1 INCLUDE2 EXCLUDE1 EXCLUDE2
1535 | ^ <--------- <---------- <---------- | ^ <---------- | ^
1536 | | Exit Exit Exit | | Exit | |
1537 | | Include Include Exclude | | Exclude | |
1540 Exclude Include Include
1542 Verbose call scope is active if we are in a INCLUDE state.
1546 INITIAL: ctr[0] == 0, ctr[1] == 0
1547 INCLUDEN: ctr[1] == N, ctr[1] == 0
1548 EXCLUDEN: ctr[1] == N
1551 void show_filters_apply(methodinfo *m) {
1557 /* compose full name of method */
1560 utf_bytes(m->clazz->name) +
1562 utf_bytes(m->name) +
1563 utf_bytes(m->descriptor) +
1566 method_name = MNEW(char, len);
1568 utf_cat_classname(method_name, m->clazz->name);
1569 strcat(method_name, ".");
1570 utf_cat(method_name, m->name);
1571 utf_cat(method_name, m->descriptor);
1573 /* reset all flags */
1575 m->filtermatches = 0;
1577 for (i = 0; i < SHOW_FILTERS_SIZE; ++i) {
1578 if (show_filters[i].enabled) {
1580 res = regexec(&show_filters[i].regex, method_name, 0, NULL, 0);
1583 m->filtermatches |= show_filters[i].flag;
1586 /* Default is to show all */
1587 m->filtermatches |= show_filters[i].flag;
1592 MFREE(method_name, char, len);
1595 #define STATE_IS_INITIAL() ((FILTERVERBOSECALLCTR[0] == 0) && (FILTERVERBOSECALLCTR[1] == 0))
1596 #define STATE_IS_INCLUDE() ((FILTERVERBOSECALLCTR[0] > 0) && (FILTERVERBOSECALLCTR[1] == 0))
1597 #define STATE_IS_EXCLUDE() (FILTERVERBOSECALLCTR[1] > 0)
1598 #define EVENT_INCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE)
1599 #define EVENT_EXCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE)
1600 #define TRANSITION_NEXT_INCLUDE() ++FILTERVERBOSECALLCTR[0]
1601 #define TRANSITION_PREV_INCLUDE() --FILTERVERBOSECALLCTR[0]
1602 #define TRANSITION_NEXT_EXCLUDE() ++FILTERVERBOSECALLCTR[1]
1603 #define TRANSITION_PREV_EXCLUDE() --FILTERVERBOSECALLCTR[1]
1607 if (STATE_IS_INITIAL()) printf("<INITIAL>\n");
1608 else if (STATE_IS_INCLUDE()) printf("<INCLUDE %hd>\n", FILTERVERBOSECALLCTR[0]);
1609 else if (STATE_IS_EXCLUDE()) printf("<EXCLUDE %hd>\n", FILTERVERBOSECALLCTR[1]);
1613 int show_filters_test_verbosecall_enter(methodinfo *m) {
1617 if (STATE_IS_INITIAL()) {
1618 if (EVENT_INCLUDE()) {
1619 TRANSITION_NEXT_INCLUDE();
1621 } else if (STATE_IS_INCLUDE()) {
1622 if (EVENT_EXCLUDE()) {
1623 TRANSITION_NEXT_EXCLUDE();
1624 /* just entered exclude, show this method */
1626 } else if (EVENT_INCLUDE()) {
1627 TRANSITION_NEXT_INCLUDE();
1629 } else if (STATE_IS_EXCLUDE()) {
1630 if (EVENT_EXCLUDE()) {
1631 TRANSITION_NEXT_EXCLUDE();
1635 return STATE_IS_INCLUDE() || force_show;
1638 int show_filters_test_verbosecall_exit(methodinfo *m) {
1643 if (STATE_IS_INCLUDE()) {
1644 if (EVENT_INCLUDE()) {
1645 TRANSITION_PREV_INCLUDE();
1646 /* just entered initial, show this method */
1647 if (STATE_IS_INITIAL()) force_show = 1;
1649 } else if (STATE_IS_EXCLUDE()) {
1650 if (EVENT_EXCLUDE()) {
1651 TRANSITION_PREV_EXCLUDE();
1656 return STATE_IS_INCLUDE() || force_show;
1663 * These are local overrides for various environment variables in Emacs.
1664 * Please do not remove this and leave it at the end of the file, where
1665 * Emacs will automagically detect them.
1666 * ---------------------------------------------------------------------
1669 * indent-tabs-mode: t
1673 * vim:noexpandtab:sw=4:ts=4: