1 /* src/vm/jit/show.c - 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-common.h"
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.h"
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_THREADS)
81 /* initialize the show lock */
86 #if defined(ENABLE_DEBUG_FILTER)
98 char *show_jit_type_names[] = {
109 char show_jit_type_letters[] = {
123 /* show_method *****************************************************************
125 Print the intermediate representation of a method.
127 NOTE: Currently this function may only be called after register allocation!
129 *******************************************************************************/
132 void show_method(jitdata *jd, int stage)
139 basicblock *lastbptr;
143 #if defined(ENABLE_DISASSEMBLER)
147 /* get required compiler data */
154 /* We need to enter a lock here, since the binutils disassembler
155 is not reentrant-able and we could not read functions printed
160 #if defined(ENABLE_INTRP)
162 irstage = SHOW_PARSE;
167 /* get the last basic block */
169 for (lastbptr = jd->basicblocks; lastbptr->next != NULL; lastbptr = lastbptr->next);
175 if (code_is_leafmethod(code))
176 printf("LEAFMETHOD\n");
178 printf("\nBasic blocks: %d\n", jd->basicblockcount);
179 if (stage >= SHOW_CODE) {
180 printf("Code length: %d\n", (lastbptr->mpc - jd->basicblocks[0].mpc));
181 printf("Data length: %d\n", cd->dseglen);
182 printf("Stub length: %d\n", (s4) (code->mcodelength -
183 ((ptrint) cd->dseglen + lastbptr->mpc)));
185 printf("Variables: %d (%d used)\n", jd->varcount, jd->vartop);
186 if (stage >= SHOW_STACK)
187 printf("Max interfaces: %d\n", jd->maxinterfaces);
188 printf("Max locals: %d\n", jd->maxlocals);
189 printf("Max stack: %d\n", m->maxstack);
190 printf("Linenumbers: %d\n", m->linenumbercount);
191 printf("Branch to entry: %s\n", (jd->branchtoentry) ? "yes" : "no");
192 printf("Branch to end: %s\n", (jd->branchtoend) ? "yes" : "no");
193 if (stage >= SHOW_STACK) {
194 printf("Number of RETURNs: %d", jd->returncount);
195 if (jd->returncount == 1)
196 printf(" (block L%03d)", jd->returnblock->nr);
200 if (stage >= SHOW_PARSE) {
201 printf("Exceptions (Number: %d):\n", jd->exceptiontablelength);
202 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
203 printf(" L%03d ... ", ex->start->nr );
204 printf("L%03d = ", ex->end->nr);
205 printf("L%03d", ex->handler->nr);
206 printf(" (catchtype: ");
207 if (ex->catchtype.any)
208 if (IS_CLASSREF(ex->catchtype))
209 class_classref_print(ex->catchtype.ref);
211 class_print(ex->catchtype.cls);
218 if (irstage >= SHOW_PARSE && rd && jd->localcount > 0) {
219 printf("Local Table:\n");
220 for (i = 0; i < jd->localcount; i++) {
223 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
224 # if defined(ENABLE_INTRP)
227 printf(" (%s) ", show_jit_type_names[VAR(i)->type]);
228 if (irstage >= SHOW_REGS)
229 show_allocation(VAR(i)->type, VAR(i)->flags, VAR(i)->vv.regoff);
231 # if defined(ENABLE_INTRP)
234 #endif /* defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER) */
239 if (jd->maxlocals > 0 && jd->local_map != NULL) {
240 printf("Local Map:\n");
242 for (j = 0; j < jd->maxlocals; j++) {
246 for (i = 0; i < 5; i++) {
247 printf(" %5s ",show_jit_type_names[i]);
248 for (j = 0; j < jd->maxlocals; j++) {
249 if (jd->local_map[j*5+i] == UNUSED)
252 printf("%4i ",jd->local_map[j*5+i]);
259 if (jd->maxinterfaces > 0 && jd->interface_map && irstage >= SHOW_STACK) {
261 interface_info *mapptr = jd->interface_map;
263 /* look if there exist any INOUTS */
264 for (i = 0; (i < (5 * jd->maxinterfaces)) && !exist; i++, mapptr++)
265 exist = (mapptr->flags != UNUSED);
268 printf("Interface Table: (In/Outvars)\n");
270 for (j = 0; j < jd->maxinterfaces; j++) {
275 for (i = 0; i < 5; i++) {
276 printf(" %5s ",show_jit_type_names[i]);
277 for (j = 0; j < jd->maxinterfaces; j++) {
278 s4 flags = jd->interface_map[j*5+i].flags;
279 s4 regoff = jd->interface_map[j*5+i].regoff;
285 if (irstage >= SHOW_REGS) {
286 if (flags & SAVEDVAR) {
287 if (flags & INMEMORY)
293 if (flags & INMEMORY)
298 printf("%c%03d(", ch, regoff);
299 show_allocation(i, flags, regoff);
303 if (flags & SAVEDVAR)
316 if (rd->memuse && irstage >= SHOW_REGS) {
320 printf("Stack slots: (memuse=%d", rd->memuse);
321 if (irstage >= SHOW_CODE) {
322 printf(", stackframesize=%d", cd->stackframesize);
323 max = cd->stackframesize;
326 for (i = 0; i < max; ++i) {
327 #if defined(HAS_4BYTE_STACKSLOT)
328 printf(" M%02d = 0x%02x(sp): ", i, i * 4);
330 printf(" M%02d = 0x%02x(sp): ", i, i * 8);
332 for (j = 0; j < jd->vartop; ++j) {
334 if ((v->flags & INMEMORY) && (v->vv.regoff == i)) {
335 show_variable(jd, j, irstage);
346 #if defined(ENABLE_REPLACEMENT)
347 if (code->rplpoints) {
348 printf("Replacement Points:\n");
349 replace_show_replacement_points(code);
352 #endif /* defined(ENABLE_REPLACEMENT) */
354 #if defined(ENABLE_DISASSEMBLER)
355 /* show code before first basic block */
357 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
358 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen);
360 for (; pc < (u1 *) ((ptrint) code->mcode + cd->dseglen + jd->basicblocks[0].mpc);)
367 /* show code of all basic blocks */
369 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next)
370 show_basicblock(jd, bptr, stage);
372 #if 0 && defined(ENABLE_DISASSEMBLER)
373 /* show code after last basic block */
375 if (stage >= SHOW_CODE && opt_showdisassemble) {
376 printf("\nStubs code:\n");
377 printf("Length: %d\n\n", (s4) (code->mcodelength -
378 ((ptrint) cd->dseglen + lastbptr->mpc)));
380 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen + lastbptr->mpc);
382 for (; (ptrint) pc < ((ptrint) code->mcode + code->mcodelength);)
391 /* finally flush the output */
395 #endif /* !defined(NDEBUG) */
398 #if !defined(NDEBUG) && defined(ENABLE_INLINING)
399 static void show_inline_info(jitdata *jd, insinfo_inline *ii, s4 opcode, s4 stage)
404 printf("(pt %d+%d+%d st ",
405 ii->throughcount - (ii->stackvarscount - ii->paramcount),
406 ii->stackvarscount - ii->paramcount,
408 show_variable_array(jd, ii->stackvars, ii->stackvarscount, stage);
410 if (opcode == ICMD_INLINE_START || opcode == ICMD_INLINE_END) {
412 jl = (opcode == ICMD_INLINE_START) ? ii->javalocals_start : ii->javalocals_end;
413 n = (opcode == ICMD_INLINE_START) ? ii->method->maxlocals : ii->outer->maxlocals;
414 show_javalocals_array(jd, jl, n, stage);
421 method_print(ii->outer);
425 method_print(ii->method);
427 #endif /* !defined(NDEBUG) && defined(ENABLE_INLINING) */
430 /* show_basicblock *************************************************************
432 Print the intermediate representation of a basic block.
434 NOTE: Currently this function may only be called after register allocation!
436 *******************************************************************************/
439 void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
447 #if defined(ENABLE_DISASSEMBLER)
448 methodinfo *m; /* this is only a dummy */
451 s4 currentlinenumber;
454 /* get required compiler data */
459 if (bptr->flags != BBDELETED) {
460 #if defined(ENABLE_INTRP)
463 irstage = SHOW_PARSE;
468 deadcode = (bptr->flags < BBREACHED);
472 printf("======== %sL%03d ======== %s(flags: %d, bitflags: %01x, next: %d, type: ",
473 #if defined(ENABLE_REPLACEMENT)
474 (bptr->bitflags & BBFLAG_REPLACEMENT) ? "<REPLACE> " :
478 (deadcode && stage >= SHOW_STACK) ? "DEADCODE! " : "",
479 bptr->flags, bptr->bitflags,
480 (bptr->next) ? (bptr->next->nr) : -1);
482 switch (bptr->type) {
494 printf(", icount: %d", bptr->icount);
496 if (irstage >= SHOW_CFG) {
497 printf(", preds: %d [ ", bptr->predecessorcount);
499 for (i = 0; i < bptr->predecessorcount; i++)
500 printf("%d ", bptr->predecessors[i]->nr);
508 printf(" (clone of L%03d)", bptr->original->nr);
510 basicblock *b = bptr->copied_to;
512 printf(" (copied to ");
513 for (; b; b = b->copied_to)
514 printf("L%03d ", b->nr);
521 if (irstage >= SHOW_CFG) {
522 printf("succs: %d [ ", bptr->successorcount);
524 for (i = 0; i < bptr->successorcount; i++)
525 printf("%d ", bptr->successors[i]->nr);
530 if (irstage >= SHOW_STACK) {
532 show_variable_array(jd, bptr->invars, bptr->indepth, irstage);
533 printf(" javalocals: ");
534 if (bptr->javalocals)
535 show_javalocals_array(jd, bptr->javalocals, bptr->method->maxlocals, irstage);
541 #if defined(ENABLE_INLINING)
542 if (bptr->inlineinfo) {
543 printf("inlineinfo: ");
544 show_inline_info(jd, bptr->inlineinfo, -1, irstage);
547 #endif /* defined(ENABLE_INLINING) */
549 #if defined(ENABLE_SSA)
553 for (i = 0; i < bptr->phicount; i++, iptr++) {
554 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
556 show_icmd(jd, iptr, deadcode, irstage);
563 for (i = 0; i < bptr->icount; i++, iptr++) {
564 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
566 show_icmd(jd, iptr, deadcode, irstage);
570 if (irstage >= SHOW_STACK) {
572 show_variable_array(jd, bptr->outvars, bptr->outdepth, irstage);
576 #if defined(ENABLE_DISASSEMBLER)
577 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd) &&
581 pc = (void *) (code->mcode + cd->dseglen + bptr->mpc);
584 if (bptr->next != NULL) {
585 for (; pc < (void *) (code->mcode + cd->dseglen + bptr->next->mpc);) {
587 linenumbertable_linenumber_for_pc(&m, code, pc);
589 if (currentlinenumber != linenumber) {
590 linenumber = currentlinenumber;
591 printf("%4d:\n", linenumber);
598 for (; pc < (void *) (code->mcode + code->mcodelength);) {
600 linenumbertable_linenumber_for_pc(&m, code, pc);
602 if (currentlinenumber != linenumber) {
603 linenumber = currentlinenumber;
604 printf("%4d:\n", linenumber);
615 #endif /* !defined(NDEBUG) */
618 /* show_icmd *******************************************************************
620 Print the intermediate representation of an instruction.
622 NOTE: Currently this function may only be called after register allocation!
624 *******************************************************************************/
628 #define SHOW_TARGET(target) \
629 if (stage >= SHOW_PARSE) { \
630 printf("--> L%03d ", (target).block->nr); \
633 printf("--> insindex %d ", (target).insindex); \
636 #define SHOW_INT_CONST(val) \
637 if (stage >= SHOW_PARSE) { \
638 printf("%d (0x%08x) ", (int32_t) (val), (int32_t) (val)); \
644 #if SIZEOF_VOID_P == 4
645 #define SHOW_LNG_CONST(val) \
646 if (stage >= SHOW_PARSE) \
647 printf("%lld (0x%016llx) ", (val), (val)); \
651 #define SHOW_LNG_CONST(val) \
652 if (stage >= SHOW_PARSE) \
653 printf("%ld (0x%016lx) ", (val), (val)); \
658 #if SIZEOF_VOID_P == 4
659 #define SHOW_ADR_CONST(val) \
660 if (stage >= SHOW_PARSE) \
661 printf("0x%08x ", (ptrint) (val)); \
665 #define SHOW_ADR_CONST(val) \
666 if (stage >= SHOW_PARSE) \
667 printf("0x%016lx ", (ptrint) (val)); \
672 #define SHOW_FLT_CONST(val) \
673 if (stage >= SHOW_PARSE) { \
676 printf("%g (0x%08x) ", (val), v.i); \
682 #if SIZEOF_VOID_P == 4
683 #define SHOW_DBL_CONST(val) \
684 if (stage >= SHOW_PARSE) { \
687 printf("%g (0x%016llx) ", (val), v.l); \
692 #define SHOW_DBL_CONST(val) \
693 if (stage >= SHOW_PARSE) { \
696 printf("%g (0x%016lx) ", (val), v.l); \
702 #define SHOW_INDEX(index) \
703 if (stage >= SHOW_PARSE) { \
704 printf("%d ", index); \
710 #define SHOW_STRING(val) \
711 if (stage >= SHOW_PARSE) { \
713 utf_display_printable_ascii( \
714 javastring_toutf((java_handle_t *)(val), false)); \
721 #define SHOW_CLASSREF_OR_CLASSINFO(c) \
722 if (stage >= SHOW_PARSE) { \
723 if (IS_CLASSREF(c)) \
724 class_classref_print(c.ref); \
726 class_print(c.cls); \
733 #define SHOW_FIELD(fmiref) \
734 if (stage >= SHOW_PARSE) { \
735 field_fieldref_print(fmiref); \
742 #define SHOW_VARIABLE(v) \
743 show_variable(jd, (v), stage)
745 #define SHOW_S1(iptr) \
746 if (stage >= SHOW_STACK) { \
747 SHOW_VARIABLE(iptr->s1.varindex); \
750 #define SHOW_S2(iptr) \
751 if (stage >= SHOW_STACK) { \
752 SHOW_VARIABLE(iptr->sx.s23.s2.varindex); \
755 #define SHOW_S3(iptr) \
756 if (stage >= SHOW_STACK) { \
757 SHOW_VARIABLE(iptr->sx.s23.s3.varindex); \
760 #define SHOW_DST(iptr) \
761 if (stage >= SHOW_STACK) { \
763 SHOW_VARIABLE(iptr->dst.varindex); \
766 #define SHOW_S1_LOCAL(iptr) \
767 if (stage >= SHOW_STACK) { \
768 printf("L%d ", iptr->s1.varindex); \
771 printf("JavaL%d ", iptr->s1.varindex); \
774 #define SHOW_DST_LOCAL(iptr) \
775 if (stage >= SHOW_STACK) { \
776 printf("=> L%d ", iptr->dst.varindex); \
779 printf("=> JavaL%d ", iptr->dst.varindex); \
782 void show_allocation(s4 type, s4 flags, s4 regoff)
784 if (type == TYPE_RET) {
789 if (flags & INMEMORY) {
790 printf("M%02d", regoff);
794 #ifdef HAS_ADDRESS_REGISTER_FILE
795 if (type == TYPE_ADR) {
796 printf("R%02d", regoff);
801 if (IS_FLT_DBL_TYPE(type)) {
802 printf("F%02d", regoff);
806 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
807 if (IS_2_WORD_TYPE(type)) {
808 # if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
809 # if defined(ENABLE_INTRP)
811 printf("%3d/%3d", GET_LOW_REG(regoff),
812 GET_HIGH_REG(regoff));
815 printf("%3s/%3s", abi_registers_integer_name[GET_LOW_REG(regoff)],
816 abi_registers_integer_name[GET_HIGH_REG(regoff)]);
818 printf("%3d/%3d", GET_LOW_REG(regoff),
819 GET_HIGH_REG(regoff));
823 #endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
825 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
826 # if defined(ENABLE_INTRP)
828 printf("%3d", regoff);
831 printf("%3s", abi_registers_integer_name[regoff]);
833 printf("%3d", regoff);
837 void show_variable(jitdata *jd, s4 index, int stage)
839 show_variable_intern(jd, index, stage);
843 static void show_variable_intern(jitdata *jd, s4 index, int stage)
849 if (index < 0 || index >= jd->vartop) {
850 printf("<INVALID INDEX:%d>", index);
857 case TYPE_INT: type = 'i'; break;
858 case TYPE_LNG: type = 'l'; break;
859 case TYPE_FLT: type = 'f'; break;
860 case TYPE_DBL: type = 'd'; break;
861 case TYPE_ADR: type = 'a'; break;
862 case TYPE_RET: type = 'r'; break;
866 if (index < jd->localcount) {
868 if (v->flags & (PREALLOC | INOUT))
869 printf("<INVALID FLAGS!>");
872 if (v->flags & PREALLOC) {
874 if (v->flags & INOUT) {
875 /* PREALLOC is used to avoid allocation of TYPE_RET */
876 if (v->type == TYPE_RET)
879 printf("<INVALID FLAGS!>");
882 else if (v->flags & INOUT)
888 printf("%c%c%d", kind, type, index);
890 if (v->flags & SAVEDVAR)
893 if (stage >= SHOW_REGS || (v->flags & PREALLOC)) {
895 show_allocation(v->type, v->flags, v->vv.regoff);
899 if (v->type == TYPE_RET && (v->flags & PREALLOC)) {
900 printf("(L%03d)", v->vv.retaddr->nr);
904 static void show_variable_array_intern(jitdata *jd, s4 *vars, int n, int stage,
916 for (i=0; i<n; ++i) {
920 if (vars[i] == UNUSED)
922 else if (javalocals) {
923 nr = RETADDR_FROM_JAVALOCAL(vars[i]);
924 printf("ret(L%03d)", nr);
927 printf("<INVALID INDEX:%d>", vars[i]);
931 show_variable_intern(jd, vars[i], stage);
936 void show_variable_array(jitdata *jd, s4 *vars, int n, int stage)
938 show_variable_array_intern(jd, vars, n, stage, false);
941 void show_javalocals_array(jitdata *jd, s4 *vars, int n, int stage)
943 show_variable_array_intern(jd, vars, n, stage, true);
946 void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
949 branch_target_t *table;
950 lookup_target_t *lookup;
951 constant_FMIref *fmiref;
955 /* get the opcode and the condition */
959 printf("%s ", icmd_table[opcode].name);
961 if (stage < SHOW_PARSE)
967 /* Print the condition for conditional instructions. */
969 /* XXX print condition from flags */
971 if (iptr->flags.bits & INS_FLAG_UNRESOLVED)
972 printf("(UNRESOLVED) ");
982 case ICMD_ARRAYLENGTH:
1001 case ICMD_INT2SHORT:
1049 /* binary/const INT */
1050 case ICMD_IADDCONST:
1051 case ICMD_ISUBCONST:
1052 case ICMD_IMULCONST:
1056 case ICMD_IANDCONST:
1058 case ICMD_IXORCONST:
1059 case ICMD_ISHLCONST:
1060 case ICMD_ISHRCONST:
1061 case ICMD_IUSHRCONST:
1062 case ICMD_LSHLCONST:
1063 case ICMD_LSHRCONST:
1064 case ICMD_LUSHRCONST:
1066 SHOW_INT_CONST(iptr->sx.val.i);
1070 /* ?ASTORECONST (trinary/const INT) */
1071 case ICMD_IASTORECONST:
1072 case ICMD_BASTORECONST:
1073 case ICMD_CASTORECONST:
1074 case ICMD_SASTORECONST:
1077 SHOW_INT_CONST(iptr->sx.s23.s3.constval);
1082 SHOW_INT_CONST(iptr->sx.val.i);
1086 /* binary/const LNG */
1087 case ICMD_LADDCONST:
1088 case ICMD_LSUBCONST:
1089 case ICMD_LMULCONST:
1093 case ICMD_LANDCONST:
1095 case ICMD_LXORCONST:
1097 SHOW_LNG_CONST(iptr->sx.val.l);
1101 /* trinary/const LNG (<= pointer size) */
1102 case ICMD_LASTORECONST:
1105 SHOW_ADR_CONST(iptr->sx.s23.s3.constval);
1110 SHOW_LNG_CONST(iptr->sx.val.l);
1116 SHOW_FLT_CONST(iptr->sx.val.f);
1122 SHOW_DBL_CONST(iptr->sx.val.d);
1128 if (iptr->flags.bits & INS_FLAG_CLASS) {
1129 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1130 SHOW_CLASSREF_OR_CLASSINFO(iptr->sx.val.c);
1132 else if (iptr->sx.val.anyptr == NULL) {
1136 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1137 SHOW_STRING(iptr->sx.val.stringconst);
1142 case ICMD_AASTORECONST:
1145 printf("%p ", (void*) iptr->sx.s23.s3.constval);
1148 case ICMD_GETFIELD: /* 1 -> 1 */
1149 case ICMD_PUTFIELD: /* 2 -> 0 */
1150 case ICMD_PUTSTATIC: /* 1 -> 0 */
1151 case ICMD_GETSTATIC: /* 0 -> 1 */
1152 case ICMD_PUTSTATICCONST: /* 0 -> 0 */
1153 case ICMD_PUTFIELDCONST: /* 1 -> 0 */
1154 if (opcode != ICMD_GETSTATIC && opcode != ICMD_PUTSTATICCONST) {
1156 if (opcode == ICMD_PUTFIELD) {
1160 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1163 if (opcode == ICMD_GETSTATIC || opcode == ICMD_GETFIELD) {
1169 SHOW_S1_LOCAL(iptr);
1170 SHOW_INT_CONST(iptr->sx.val.i);
1171 SHOW_DST_LOCAL(iptr);
1201 SHOW_S1_LOCAL(iptr);
1202 if (stage >= SHOW_STACK) {
1203 printf(" ---> L%03d", iptr->dst.block->nr);
1212 SHOW_S1_LOCAL(iptr);
1222 SHOW_DST_LOCAL(iptr);
1223 if (stage >= SHOW_STACK && iptr->sx.s23.s3.javaindex != UNUSED)
1224 printf(" (javaindex %d)", iptr->sx.s23.s3.javaindex);
1225 if (iptr->flags.bits & INS_FLAG_RETADDR) {
1226 printf(" (retaddr L%03d)", RETADDR_FROM_JAVALOCAL(iptr->sx.s23.s2.retaddrnr));
1238 case ICMD_ANEWARRAY:
1242 case ICMD_MULTIANEWARRAY:
1243 if (stage >= SHOW_STACK) {
1244 argp = iptr->sx.s23.s2.args;
1245 i = iptr->s1.argcount;
1247 SHOW_VARIABLE(*(argp++));
1251 printf("argcount=%d ", iptr->s1.argcount);
1253 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1258 case ICMD_CHECKCAST:
1260 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1265 case ICMD_INSTANCEOF:
1270 case ICMD_INLINE_START:
1271 case ICMD_INLINE_END:
1272 case ICMD_INLINE_BODY:
1273 #if defined(ENABLE_INLINING)
1275 insinfo_inline *ii = iptr->sx.s23.s3.inlineinfo;
1276 show_inline_info(jd, ii, opcode, stage);
1282 if (stage >= SHOW_STACK) {
1283 argp = iptr->sx.s23.s2.args;
1284 i = iptr->s1.argcount;
1286 if ((iptr->s1.argcount - 1 - i) == iptr->sx.s23.s3.bte->md->paramcount)
1287 printf(" pass-through: ");
1288 SHOW_VARIABLE(*(argp++));
1291 printf("%s ", iptr->sx.s23.s3.bte->cname);
1292 if (iptr->sx.s23.s3.bte->md->returntype.type != TYPE_VOID) {
1297 case ICMD_INVOKEVIRTUAL:
1298 case ICMD_INVOKESPECIAL:
1299 case ICMD_INVOKESTATIC:
1300 case ICMD_INVOKEINTERFACE:
1301 if (stage >= SHOW_STACK) {
1303 INSTRUCTION_GET_METHODDESC(iptr, md);
1304 argp = iptr->sx.s23.s2.args;
1305 i = iptr->s1.argcount;
1307 if ((iptr->s1.argcount - 1 - i) == md->paramcount)
1308 printf(" pass-through: ");
1309 SHOW_VARIABLE(*(argp++));
1312 INSTRUCTION_GET_METHODREF(iptr, fmiref);
1313 method_methodref_print(fmiref);
1314 if (fmiref->parseddesc.md->returntype.type != TYPE_VOID) {
1327 SHOW_INT_CONST(iptr->sx.val.i);
1328 SHOW_TARGET(iptr->dst);
1338 SHOW_LNG_CONST(iptr->sx.val.l);
1339 SHOW_TARGET(iptr->dst);
1343 SHOW_TARGET(iptr->dst);
1347 SHOW_TARGET(iptr->sx.s23.s3.jsrtarget);
1352 case ICMD_IFNONNULL:
1354 SHOW_TARGET(iptr->dst);
1357 case ICMD_IF_ICMPEQ:
1358 case ICMD_IF_ICMPNE:
1359 case ICMD_IF_ICMPLT:
1360 case ICMD_IF_ICMPGE:
1361 case ICMD_IF_ICMPGT:
1362 case ICMD_IF_ICMPLE:
1364 case ICMD_IF_LCMPEQ:
1365 case ICMD_IF_LCMPNE:
1366 case ICMD_IF_LCMPLT:
1367 case ICMD_IF_LCMPGE:
1368 case ICMD_IF_LCMPGT:
1369 case ICMD_IF_LCMPLE:
1371 case ICMD_IF_ACMPEQ:
1372 case ICMD_IF_ACMPNE:
1375 SHOW_TARGET(iptr->dst);
1378 case ICMD_TABLESWITCH:
1380 table = iptr->dst.table;
1382 i = iptr->sx.s23.s3.tablehigh - iptr->sx.s23.s2.tablelow + 1;
1384 printf("high=%d low=%d count=%d\n", iptr->sx.s23.s3.tablehigh, iptr->sx.s23.s2.tablelow, i);
1386 printf("\t\t%d --> ", (int) (table - iptr->dst.table));
1387 printf("L%03d\n", table->block->nr);
1393 case ICMD_LOOKUPSWITCH:
1396 printf("count=%d, default=L%03d\n",
1397 iptr->sx.s23.s2.lookupcount,
1398 iptr->sx.s23.s3.lookupdefault.block->nr);
1400 lookup = iptr->dst.lookup;
1401 i = iptr->sx.s23.s2.lookupcount;
1404 printf("\t\t%d --> L%03d\n",
1406 lookup->target.block->nr);
1421 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1422 /* XXX this needs more work */
1424 unresolved_class_debug_dump(iptr->sx.s23.s2.uc, stdout);
1434 case ICMD_GETEXCEPTION:
1437 #if defined(ENABLE_SSA)
1440 for (i = 0; i < iptr->s1.argcount; ++i) {
1441 SHOW_VARIABLE(iptr->sx.s23.s2.iargs[i]->dst.varindex);
1445 if (iptr->flags.bits & (1 << 0)) printf("used ");
1446 if (iptr->flags.bits & (1 << 1)) printf("redundantAll ");
1447 if (iptr->flags.bits & (1 << 2)) printf("redundantOne ");
1453 #endif /* !defined(NDEBUG) */
1455 /* Debug output filtering */
1457 #if defined(ENABLE_DEBUG_FILTER)
1459 #if !defined(ENABLE_THREADS)
1460 u2 _no_threads_filterverbosecallctr[2] = { 0, 0 };
1463 struct show_filter {
1464 /* Boolean indicating if filter is enabled. */
1466 /* Regular expression the method name is matched against */
1468 /* Flag set on m->filtermatches if regex matches */
1472 typedef struct show_filter show_filter_t;
1474 #define SHOW_FILTERS_SIZE 3
1476 /* Array of filters applyed on a method */
1477 static struct show_filter show_filters[SHOW_FILTERS_SIZE];
1479 static void show_filter_init(show_filter_t *cf, const char *str, u1 flag, u1 default_flag, const char *description) {
1484 err = regcomp(&cf->regex, str, REG_EXTENDED | REG_NOSUB);
1486 regerror(err, &cf->regex, err_buf, sizeof(err_buf));
1488 "Invalid value given for %s: `%s' (%s).",
1489 description, str, err_buf
1495 cf->flag = default_flag;
1500 void show_filters_init(void) {
1504 opt_filter_verbosecall_include,
1505 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1506 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1507 "verbose call include filter"
1512 opt_filter_verbosecall_exclude,
1513 SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE,
1515 "verbose call exclude filter"
1520 opt_filter_show_method,
1521 SHOW_FILTER_FLAG_SHOW_METHOD,
1522 SHOW_FILTER_FLAG_SHOW_METHOD,
1523 "show method filter"
1529 (Pseudo)State machine:
1531 States are INITIAL, INCLUDE1, INCLUDE2, ..., EXCLUDE1, ..., EXCLUDE2, ...
1534 Enter Include Include
1536 | | Enter Enter Enter | | Enter | |
1537 | | Include Include Exclude | | Exclude | |
1538 | v ---------> ----------> ----------> | v ----------> | v
1539 INITIAL INCLUDE1 INCLUDE2 EXCLUDE1 EXCLUDE2
1540 | ^ <--------- <---------- <---------- | ^ <---------- | ^
1541 | | Exit Exit Exit | | Exit | |
1542 | | Include Include Exclude | | Exclude | |
1545 Exclude Include Include
1547 Verbose call scope is active if we are in a INCLUDE state.
1551 INITIAL: ctr[0] == 0, ctr[1] == 0
1552 INCLUDEN: ctr[1] == N, ctr[1] == 0
1553 EXCLUDEN: ctr[1] == N
1556 void show_filters_apply(methodinfo *m) {
1562 /* compose full name of method */
1565 utf_bytes(m->clazz->name) +
1567 utf_bytes(m->name) +
1568 utf_bytes(m->descriptor) +
1571 method_name = MNEW(char, len);
1573 utf_cat_classname(method_name, m->clazz->name);
1574 strcat(method_name, ".");
1575 utf_cat(method_name, m->name);
1576 utf_cat(method_name, m->descriptor);
1578 /* reset all flags */
1580 m->filtermatches = 0;
1582 for (i = 0; i < SHOW_FILTERS_SIZE; ++i) {
1583 if (show_filters[i].enabled) {
1585 res = regexec(&show_filters[i].regex, method_name, 0, NULL, 0);
1588 m->filtermatches |= show_filters[i].flag;
1591 /* Default is to show all */
1592 m->filtermatches |= show_filters[i].flag;
1597 MFREE(method_name, char, len);
1600 #define STATE_IS_INITIAL() ((FILTERVERBOSECALLCTR[0] == 0) && (FILTERVERBOSECALLCTR[1] == 0))
1601 #define STATE_IS_INCLUDE() ((FILTERVERBOSECALLCTR[0] > 0) && (FILTERVERBOSECALLCTR[1] == 0))
1602 #define STATE_IS_EXCLUDE() (FILTERVERBOSECALLCTR[1] > 0)
1603 #define EVENT_INCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE)
1604 #define EVENT_EXCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE)
1605 #define TRANSITION_NEXT_INCLUDE() ++FILTERVERBOSECALLCTR[0]
1606 #define TRANSITION_PREV_INCLUDE() --FILTERVERBOSECALLCTR[0]
1607 #define TRANSITION_NEXT_EXCLUDE() ++FILTERVERBOSECALLCTR[1]
1608 #define TRANSITION_PREV_EXCLUDE() --FILTERVERBOSECALLCTR[1]
1612 if (STATE_IS_INITIAL()) printf("<INITIAL>\n");
1613 else if (STATE_IS_INCLUDE()) printf("<INCLUDE %hd>\n", FILTERVERBOSECALLCTR[0]);
1614 else if (STATE_IS_EXCLUDE()) printf("<EXCLUDE %hd>\n", FILTERVERBOSECALLCTR[1]);
1618 int show_filters_test_verbosecall_enter(methodinfo *m) {
1622 if (STATE_IS_INITIAL()) {
1623 if (EVENT_INCLUDE()) {
1624 TRANSITION_NEXT_INCLUDE();
1626 } else if (STATE_IS_INCLUDE()) {
1627 if (EVENT_EXCLUDE()) {
1628 TRANSITION_NEXT_EXCLUDE();
1629 /* just entered exclude, show this method */
1631 } else if (EVENT_INCLUDE()) {
1632 TRANSITION_NEXT_INCLUDE();
1634 } else if (STATE_IS_EXCLUDE()) {
1635 if (EVENT_EXCLUDE()) {
1636 TRANSITION_NEXT_EXCLUDE();
1640 return STATE_IS_INCLUDE() || force_show;
1643 int show_filters_test_verbosecall_exit(methodinfo *m) {
1648 if (STATE_IS_INCLUDE()) {
1649 if (EVENT_INCLUDE()) {
1650 TRANSITION_PREV_INCLUDE();
1651 /* just entered initial, show this method */
1652 if (STATE_IS_INITIAL()) force_show = 1;
1654 } else if (STATE_IS_EXCLUDE()) {
1655 if (EVENT_EXCLUDE()) {
1656 TRANSITION_PREV_EXCLUDE();
1661 return STATE_IS_INCLUDE() || force_show;
1668 * These are local overrides for various environment variables in Emacs.
1669 * Please do not remove this and leave it at the end of the file, where
1670 * Emacs will automagically detect them.
1671 * ---------------------------------------------------------------------
1674 * indent-tabs-mode: t
1678 * vim:noexpandtab:sw=4:ts=4: