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/builtin.h"
39 #include "vm/stringlocal.h"
42 #include "vm/jit/abi.h"
43 #include "vm/jit/jit.h"
44 #include "vm/jit/show.h"
45 #include "vm/jit/disass.h"
46 #include "vm/jit/stack.h"
47 #include "vm/jit/parse.h"
49 #include "vmcore/options.h"
51 #if defined(ENABLE_DEBUG_FILTER)
52 # include <sys/types.h>
54 # include "threads/thread.h"
58 /* global variables ***********************************************************/
60 #if defined(ENABLE_THREADS) && !defined(NDEBUG)
61 static java_object_t *show_global_lock;
65 /* prototypes *****************************************************************/
68 static void show_variable_intern(jitdata *jd, s4 index, int stage);
72 /* show_init *******************************************************************
74 Initialized the show subsystem (called by jit_init).
76 *******************************************************************************/
81 #if defined(ENABLE_THREADS)
82 /* initialize the show lock */
84 show_global_lock = NEW(java_object_t);
86 LOCK_INIT_OBJECT_LOCK(show_global_lock);
89 #if defined(ENABLE_DEBUG_FILTER)
101 char *show_jit_type_names[] = {
112 char show_jit_type_letters[] = {
126 /* show_method *****************************************************************
128 Print the intermediate representation of a method.
130 NOTE: Currently this function may only be called after register allocation!
132 *******************************************************************************/
135 void show_method(jitdata *jd, int stage)
142 basicblock *lastbptr;
146 #if defined(ENABLE_DISASSEMBLER)
150 /* get required compiler data */
157 /* We need to enter a lock here, since the binutils disassembler
158 is not reentrant-able and we could not read functions printed
161 LOCK_MONITOR_ENTER(show_global_lock);
163 #if defined(ENABLE_INTRP)
165 irstage = SHOW_PARSE;
170 /* get the last basic block */
172 for (lastbptr = jd->basicblocks; lastbptr->next != NULL; lastbptr = lastbptr->next);
178 if (code_is_leafmethod(code))
179 printf("LEAFMETHOD\n");
181 printf("\nBasic blocks: %d\n", jd->basicblockcount);
182 if (stage >= SHOW_CODE) {
183 printf("Code length: %d\n", (lastbptr->mpc - jd->basicblocks[0].mpc));
184 printf("Data length: %d\n", cd->dseglen);
185 printf("Stub length: %d\n", (s4) (code->mcodelength -
186 ((ptrint) cd->dseglen + lastbptr->mpc)));
188 printf("Variables: %d (%d used)\n", jd->varcount, jd->vartop);
189 if (stage >= SHOW_STACK)
190 printf("Max interfaces: %d\n", jd->maxinterfaces);
191 printf("Max locals: %d\n", jd->maxlocals);
192 printf("Max stack: %d\n", m->maxstack);
193 printf("Linenumbers: %d\n", m->linenumbercount);
194 printf("Branch to entry: %s\n", (jd->branchtoentry) ? "yes" : "no");
195 printf("Branch to end: %s\n", (jd->branchtoend) ? "yes" : "no");
196 if (stage >= SHOW_STACK) {
197 printf("Number of RETURNs: %d", jd->returncount);
198 if (jd->returncount == 1)
199 printf(" (block L%03d)", jd->returnblock->nr);
203 if (stage >= SHOW_PARSE) {
204 printf("Exceptions (Number: %d):\n", jd->exceptiontablelength);
205 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
206 printf(" L%03d ... ", ex->start->nr );
207 printf("L%03d = ", ex->end->nr);
208 printf("L%03d", ex->handler->nr);
209 printf(" (catchtype: ");
210 if (ex->catchtype.any)
211 if (IS_CLASSREF(ex->catchtype))
212 class_classref_print(ex->catchtype.ref);
214 class_print(ex->catchtype.cls);
221 if (irstage >= SHOW_PARSE && rd && jd->localcount > 0) {
222 printf("Local Table:\n");
223 for (i = 0; i < jd->localcount; i++) {
226 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
227 # if defined(ENABLE_INTRP)
230 printf(" (%s) ", show_jit_type_names[VAR(i)->type]);
231 if (irstage >= SHOW_REGS)
232 show_allocation(VAR(i)->type, VAR(i)->flags, VAR(i)->vv.regoff);
234 # if defined(ENABLE_INTRP)
237 #endif /* defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER) */
242 if (jd->maxlocals > 0 && jd->local_map != NULL) {
243 printf("Local Map:\n");
245 for (j = 0; j < jd->maxlocals; j++) {
249 for (i = 0; i < 5; i++) {
250 printf(" %5s ",show_jit_type_names[i]);
251 for (j = 0; j < jd->maxlocals; j++) {
252 if (jd->local_map[j*5+i] == UNUSED)
255 printf("%4i ",jd->local_map[j*5+i]);
262 if (jd->maxinterfaces > 0 && jd->interface_map && irstage >= SHOW_STACK) {
264 interface_info *mapptr = jd->interface_map;
266 /* look if there exist any INOUTS */
267 for (i = 0; (i < (5 * jd->maxinterfaces)) && !exist; i++, mapptr++)
268 exist = (mapptr->flags != UNUSED);
271 printf("Interface Table: (In/Outvars)\n");
273 for (j = 0; j < jd->maxinterfaces; j++) {
278 for (i = 0; i < 5; i++) {
279 printf(" %5s ",show_jit_type_names[i]);
280 for (j = 0; j < jd->maxinterfaces; j++) {
281 s4 flags = jd->interface_map[j*5+i].flags;
282 s4 regoff = jd->interface_map[j*5+i].regoff;
288 if (irstage >= SHOW_REGS) {
289 if (flags & SAVEDVAR) {
290 if (flags & INMEMORY)
296 if (flags & INMEMORY)
301 printf("%c%03d(", ch, regoff);
302 show_allocation(i, flags, regoff);
306 if (flags & SAVEDVAR)
319 if (rd->memuse && irstage >= SHOW_REGS) {
323 printf("Stack slots: (memuse=%d", rd->memuse);
324 if (irstage >= SHOW_CODE) {
325 printf(", stackframesize=%d", cd->stackframesize);
326 max = cd->stackframesize;
329 for (i = 0; i < max; ++i) {
330 #if defined(HAS_4BYTE_STACKSLOT)
331 printf(" M%02d = 0x%02x(sp): ", i, i * 4);
333 printf(" M%02d = 0x%02x(sp): ", i, i * 8);
335 for (j = 0; j < jd->vartop; ++j) {
337 if ((v->flags & INMEMORY) && (v->vv.regoff == i)) {
338 show_variable(jd, j, irstage);
349 #if defined(ENABLE_REPLACEMENT)
350 if (code->rplpoints) {
351 printf("Replacement Points:\n");
352 replace_show_replacement_points(code);
355 #endif /* defined(ENABLE_REPLACEMENT) */
357 #if defined(ENABLE_DISASSEMBLER)
358 /* show code before first basic block */
360 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
361 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen);
363 for (; pc < (u1 *) ((ptrint) code->mcode + cd->dseglen + jd->basicblocks[0].mpc);)
370 /* show code of all basic blocks */
372 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next)
373 show_basicblock(jd, bptr, stage);
375 #if 0 && defined(ENABLE_DISASSEMBLER)
376 /* show code after last basic block */
378 if (stage >= SHOW_CODE && opt_showdisassemble) {
379 printf("\nStubs code:\n");
380 printf("Length: %d\n\n", (s4) (code->mcodelength -
381 ((ptrint) cd->dseglen + lastbptr->mpc)));
383 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen + lastbptr->mpc);
385 for (; (ptrint) pc < ((ptrint) code->mcode + code->mcodelength);)
392 LOCK_MONITOR_EXIT(show_global_lock);
394 /* finally flush the output */
398 #endif /* !defined(NDEBUG) */
401 #if !defined(NDEBUG) && defined(ENABLE_INLINING)
402 static void show_inline_info(jitdata *jd, insinfo_inline *ii, s4 opcode, s4 stage)
407 printf("(pt %d+%d+%d st ",
408 ii->throughcount - (ii->stackvarscount - ii->paramcount),
409 ii->stackvarscount - ii->paramcount,
411 show_variable_array(jd, ii->stackvars, ii->stackvarscount, stage);
413 if (opcode == ICMD_INLINE_START || opcode == ICMD_INLINE_END) {
415 jl = (opcode == ICMD_INLINE_START) ? ii->javalocals_start : ii->javalocals_end;
416 n = (opcode == ICMD_INLINE_START) ? ii->method->maxlocals : ii->outer->maxlocals;
417 show_javalocals_array(jd, jl, n, stage);
424 method_print(ii->outer);
428 method_print(ii->method);
430 #endif /* !defined(NDEBUG) && defined(ENABLE_INLINING) */
433 /* show_basicblock *************************************************************
435 Print the intermediate representation of a basic block.
437 NOTE: Currently this function may only be called after register allocation!
439 *******************************************************************************/
442 void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
450 #if defined(ENABLE_DISASSEMBLER)
451 methodinfo *m; /* this is only a dummy */
454 s4 currentlinenumber;
457 /* get required compiler data */
462 if (bptr->flags != BBDELETED) {
463 #if defined(ENABLE_INTRP)
466 irstage = SHOW_PARSE;
471 deadcode = (bptr->flags < BBREACHED);
475 printf("======== %sL%03d ======== %s(flags: %d, bitflags: %01x, next: %d, type: ",
476 #if defined(ENABLE_REPLACEMENT)
477 (bptr->bitflags & BBFLAG_REPLACEMENT) ? "<REPLACE> " :
481 (deadcode && stage >= SHOW_STACK) ? "DEADCODE! " : "",
482 bptr->flags, bptr->bitflags,
483 (bptr->next) ? (bptr->next->nr) : -1);
485 switch (bptr->type) {
497 printf(", icount: %d", bptr->icount);
499 if (irstage >= SHOW_CFG) {
500 printf(", preds: %d [ ", bptr->predecessorcount);
502 for (i = 0; i < bptr->predecessorcount; i++)
503 printf("%d ", bptr->predecessors[i]->nr);
511 printf(" (clone of L%03d)", bptr->original->nr);
513 basicblock *b = bptr->copied_to;
515 printf(" (copied to ");
516 for (; b; b = b->copied_to)
517 printf("L%03d ", b->nr);
524 if (irstage >= SHOW_CFG) {
525 printf("succs: %d [ ", bptr->successorcount);
527 for (i = 0; i < bptr->successorcount; i++)
528 printf("%d ", bptr->successors[i]->nr);
533 if (irstage >= SHOW_STACK) {
535 show_variable_array(jd, bptr->invars, bptr->indepth, irstage);
536 printf(" javalocals: ");
537 if (bptr->javalocals)
538 show_javalocals_array(jd, bptr->javalocals, bptr->method->maxlocals, irstage);
544 #if defined(ENABLE_INLINING)
545 if (bptr->inlineinfo) {
546 printf("inlineinfo: ");
547 show_inline_info(jd, bptr->inlineinfo, -1, irstage);
550 #endif /* defined(ENABLE_INLINING) */
554 for (i = 0; i < bptr->icount; i++, iptr++) {
555 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
557 show_icmd(jd, iptr, deadcode, irstage);
561 if (irstage >= SHOW_STACK) {
563 show_variable_array(jd, bptr->outvars, bptr->outdepth, irstage);
567 #if defined(ENABLE_DISASSEMBLER)
568 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd) &&
572 pc = (void *) (code->mcode + cd->dseglen + bptr->mpc);
575 if (bptr->next != NULL) {
576 for (; pc < (void *) (code->mcode + cd->dseglen + bptr->next->mpc);) {
578 linenumbertable_linenumber_for_pc(&m, code, pc);
580 if (currentlinenumber != linenumber) {
581 linenumber = currentlinenumber;
582 printf("%4d:\n", linenumber);
589 for (; pc < (void *) (code->mcode + code->mcodelength);) {
591 linenumbertable_linenumber_for_pc(&m, code, pc);
593 if (currentlinenumber != linenumber) {
594 linenumber = currentlinenumber;
595 printf("%4d:\n", linenumber);
606 #endif /* !defined(NDEBUG) */
609 /* show_icmd *******************************************************************
611 Print the intermediate representation of an instruction.
613 NOTE: Currently this function may only be called after register allocation!
615 *******************************************************************************/
619 #define SHOW_TARGET(target) \
620 if (stage >= SHOW_PARSE) { \
621 printf("--> L%03d ", (target).block->nr); \
624 printf("--> insindex %d ", (target).insindex); \
627 #define SHOW_INT_CONST(val) \
628 if (stage >= SHOW_PARSE) { \
629 printf("%d (0x%08x) ", (int32_t) (val), (int32_t) (val)); \
635 #if SIZEOF_VOID_P == 4
636 #define SHOW_LNG_CONST(val) \
637 if (stage >= SHOW_PARSE) \
638 printf("%lld (0x%016llx) ", (val), (val)); \
642 #define SHOW_LNG_CONST(val) \
643 if (stage >= SHOW_PARSE) \
644 printf("%ld (0x%016lx) ", (val), (val)); \
649 #if SIZEOF_VOID_P == 4
650 #define SHOW_ADR_CONST(val) \
651 if (stage >= SHOW_PARSE) \
652 printf("0x%08x ", (ptrint) (val)); \
656 #define SHOW_ADR_CONST(val) \
657 if (stage >= SHOW_PARSE) \
658 printf("0x%016lx ", (ptrint) (val)); \
663 #define SHOW_FLT_CONST(val) \
664 if (stage >= SHOW_PARSE) { \
667 printf("%g (0x%08x) ", (val), v.i); \
673 #if SIZEOF_VOID_P == 4
674 #define SHOW_DBL_CONST(val) \
675 if (stage >= SHOW_PARSE) { \
678 printf("%g (0x%016llx) ", (val), v.l); \
683 #define SHOW_DBL_CONST(val) \
684 if (stage >= SHOW_PARSE) { \
687 printf("%g (0x%016lx) ", (val), v.l); \
693 #define SHOW_INDEX(index) \
694 if (stage >= SHOW_PARSE) { \
695 printf("%d ", index); \
701 #define SHOW_STRING(val) \
702 if (stage >= SHOW_PARSE) { \
704 utf_display_printable_ascii( \
705 javastring_toutf((java_handle_t *)(val), false)); \
712 #define SHOW_CLASSREF_OR_CLASSINFO(c) \
713 if (stage >= SHOW_PARSE) { \
714 if (IS_CLASSREF(c)) \
715 class_classref_print(c.ref); \
717 class_print(c.cls); \
724 #define SHOW_FIELD(fmiref) \
725 if (stage >= SHOW_PARSE) { \
726 field_fieldref_print(fmiref); \
733 #define SHOW_VARIABLE(v) \
734 show_variable(jd, (v), stage)
736 #define SHOW_S1(iptr) \
737 if (stage >= SHOW_STACK) { \
738 SHOW_VARIABLE(iptr->s1.varindex); \
741 #define SHOW_S2(iptr) \
742 if (stage >= SHOW_STACK) { \
743 SHOW_VARIABLE(iptr->sx.s23.s2.varindex); \
746 #define SHOW_S3(iptr) \
747 if (stage >= SHOW_STACK) { \
748 SHOW_VARIABLE(iptr->sx.s23.s3.varindex); \
751 #define SHOW_DST(iptr) \
752 if (stage >= SHOW_STACK) { \
754 SHOW_VARIABLE(iptr->dst.varindex); \
757 #define SHOW_S1_LOCAL(iptr) \
758 if (stage >= SHOW_STACK) { \
759 printf("L%d ", iptr->s1.varindex); \
762 printf("JavaL%d ", iptr->s1.varindex); \
765 #define SHOW_DST_LOCAL(iptr) \
766 if (stage >= SHOW_STACK) { \
767 printf("=> L%d ", iptr->dst.varindex); \
770 printf("=> JavaL%d ", iptr->dst.varindex); \
773 void show_allocation(s4 type, s4 flags, s4 regoff)
775 if (type == TYPE_RET) {
780 if (flags & INMEMORY) {
781 printf("M%02d", regoff);
785 #ifdef HAS_ADDRESS_REGISTER_FILE
786 if (type == TYPE_ADR) {
787 printf("R%02d", regoff);
792 if (IS_FLT_DBL_TYPE(type)) {
793 printf("F%02d", regoff);
797 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
798 if (IS_2_WORD_TYPE(type)) {
799 # if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
800 # if defined(ENABLE_INTRP)
802 printf("%3d/%3d", GET_LOW_REG(regoff),
803 GET_HIGH_REG(regoff));
806 printf("%3s/%3s", abi_registers_integer_name[GET_LOW_REG(regoff)],
807 abi_registers_integer_name[GET_HIGH_REG(regoff)]);
809 printf("%3d/%3d", GET_LOW_REG(regoff),
810 GET_HIGH_REG(regoff));
814 #endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
816 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
817 # if defined(ENABLE_INTRP)
819 printf("%3d", regoff);
822 printf("%3s", abi_registers_integer_name[regoff]);
824 printf("%3d", regoff);
828 void show_variable(jitdata *jd, s4 index, int stage)
830 show_variable_intern(jd, index, stage);
834 static void show_variable_intern(jitdata *jd, s4 index, int stage)
840 if (index < 0 || index >= jd->vartop) {
841 printf("<INVALID INDEX:%d>", index);
848 case TYPE_INT: type = 'i'; break;
849 case TYPE_LNG: type = 'l'; break;
850 case TYPE_FLT: type = 'f'; break;
851 case TYPE_DBL: type = 'd'; break;
852 case TYPE_ADR: type = 'a'; break;
853 case TYPE_RET: type = 'r'; break;
857 if (index < jd->localcount) {
859 if (v->flags & (PREALLOC | INOUT))
860 printf("<INVALID FLAGS!>");
863 if (v->flags & PREALLOC) {
865 if (v->flags & INOUT) {
866 /* PREALLOC is used to avoid allocation of TYPE_RET */
867 if (v->type == TYPE_RET)
870 printf("<INVALID FLAGS!>");
873 else if (v->flags & INOUT)
879 printf("%c%c%d", kind, type, index);
881 if (v->flags & SAVEDVAR)
884 if (stage >= SHOW_REGS || (v->flags & PREALLOC)) {
886 show_allocation(v->type, v->flags, v->vv.regoff);
890 if (v->type == TYPE_RET && (v->flags & PREALLOC)) {
891 printf("(L%03d)", v->vv.retaddr->nr);
895 static void show_variable_array_intern(jitdata *jd, s4 *vars, int n, int stage,
907 for (i=0; i<n; ++i) {
911 if (vars[i] == UNUSED)
913 else if (javalocals) {
914 nr = RETADDR_FROM_JAVALOCAL(vars[i]);
915 printf("ret(L%03d)", nr);
918 printf("<INVALID INDEX:%d>", vars[i]);
922 show_variable_intern(jd, vars[i], stage);
927 void show_variable_array(jitdata *jd, s4 *vars, int n, int stage)
929 show_variable_array_intern(jd, vars, n, stage, false);
932 void show_javalocals_array(jitdata *jd, s4 *vars, int n, int stage)
934 show_variable_array_intern(jd, vars, n, stage, true);
937 void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
940 branch_target_t *table;
941 lookup_target_t *lookup;
942 constant_FMIref *fmiref;
946 /* get the opcode and the condition */
950 printf("%s ", icmd_table[opcode].name);
952 if (stage < SHOW_PARSE)
958 /* Print the condition for conditional instructions. */
960 /* XXX print condition from flags */
962 if (iptr->flags.bits & INS_FLAG_UNRESOLVED)
963 printf("(UNRESOLVED) ");
973 case ICMD_ARRAYLENGTH:
1040 /* binary/const INT */
1041 case ICMD_IADDCONST:
1042 case ICMD_ISUBCONST:
1043 case ICMD_IMULCONST:
1047 case ICMD_IANDCONST:
1049 case ICMD_IXORCONST:
1050 case ICMD_ISHLCONST:
1051 case ICMD_ISHRCONST:
1052 case ICMD_IUSHRCONST:
1053 case ICMD_LSHLCONST:
1054 case ICMD_LSHRCONST:
1055 case ICMD_LUSHRCONST:
1057 SHOW_INT_CONST(iptr->sx.val.i);
1061 /* ?ASTORECONST (trinary/const INT) */
1062 case ICMD_IASTORECONST:
1063 case ICMD_BASTORECONST:
1064 case ICMD_CASTORECONST:
1065 case ICMD_SASTORECONST:
1068 SHOW_INT_CONST(iptr->sx.s23.s3.constval);
1073 SHOW_INT_CONST(iptr->sx.val.i);
1077 /* binary/const LNG */
1078 case ICMD_LADDCONST:
1079 case ICMD_LSUBCONST:
1080 case ICMD_LMULCONST:
1084 case ICMD_LANDCONST:
1086 case ICMD_LXORCONST:
1088 SHOW_LNG_CONST(iptr->sx.val.l);
1092 /* trinary/const LNG (<= pointer size) */
1093 case ICMD_LASTORECONST:
1096 SHOW_ADR_CONST(iptr->sx.s23.s3.constval);
1101 SHOW_LNG_CONST(iptr->sx.val.l);
1107 SHOW_FLT_CONST(iptr->sx.val.f);
1113 SHOW_DBL_CONST(iptr->sx.val.d);
1119 if (iptr->flags.bits & INS_FLAG_CLASS) {
1120 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1121 SHOW_CLASSREF_OR_CLASSINFO(iptr->sx.val.c);
1123 else if (iptr->sx.val.anyptr == NULL) {
1127 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1128 SHOW_STRING(iptr->sx.val.stringconst);
1133 case ICMD_AASTORECONST:
1136 printf("%p ", (void*) iptr->sx.s23.s3.constval);
1139 case ICMD_GETFIELD: /* 1 -> 1 */
1140 case ICMD_PUTFIELD: /* 2 -> 0 */
1141 case ICMD_PUTSTATIC: /* 1 -> 0 */
1142 case ICMD_GETSTATIC: /* 0 -> 1 */
1143 case ICMD_PUTSTATICCONST: /* 0 -> 0 */
1144 case ICMD_PUTFIELDCONST: /* 1 -> 0 */
1145 if (opcode != ICMD_GETSTATIC && opcode != ICMD_PUTSTATICCONST) {
1147 if (opcode == ICMD_PUTFIELD) {
1151 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1154 if (opcode == ICMD_GETSTATIC || opcode == ICMD_GETFIELD) {
1160 SHOW_S1_LOCAL(iptr);
1161 SHOW_INT_CONST(iptr->sx.val.i);
1162 SHOW_DST_LOCAL(iptr);
1192 SHOW_S1_LOCAL(iptr);
1193 if (stage >= SHOW_STACK) {
1194 printf(" ---> L%03d", iptr->dst.block->nr);
1203 SHOW_S1_LOCAL(iptr);
1213 SHOW_DST_LOCAL(iptr);
1214 if (stage >= SHOW_STACK && iptr->sx.s23.s3.javaindex != UNUSED)
1215 printf(" (javaindex %d)", iptr->sx.s23.s3.javaindex);
1216 if (iptr->flags.bits & INS_FLAG_RETADDR) {
1217 printf(" (retaddr L%03d)", RETADDR_FROM_JAVALOCAL(iptr->sx.s23.s2.retaddrnr));
1229 case ICMD_ANEWARRAY:
1233 case ICMD_MULTIANEWARRAY:
1234 if (stage >= SHOW_STACK) {
1235 argp = iptr->sx.s23.s2.args;
1236 i = iptr->s1.argcount;
1238 SHOW_VARIABLE(*(argp++));
1242 printf("argcount=%d ", iptr->s1.argcount);
1244 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1249 case ICMD_CHECKCAST:
1251 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1256 case ICMD_INSTANCEOF:
1261 case ICMD_INLINE_START:
1262 case ICMD_INLINE_END:
1263 case ICMD_INLINE_BODY:
1264 #if defined(ENABLE_INLINING)
1266 insinfo_inline *ii = iptr->sx.s23.s3.inlineinfo;
1267 show_inline_info(jd, ii, opcode, stage);
1273 if (stage >= SHOW_STACK) {
1274 argp = iptr->sx.s23.s2.args;
1275 i = iptr->s1.argcount;
1277 if ((iptr->s1.argcount - 1 - i) == iptr->sx.s23.s3.bte->md->paramcount)
1278 printf(" pass-through: ");
1279 SHOW_VARIABLE(*(argp++));
1282 printf("%s ", iptr->sx.s23.s3.bte->cname);
1283 if (iptr->sx.s23.s3.bte->md->returntype.type != TYPE_VOID) {
1288 case ICMD_INVOKEVIRTUAL:
1289 case ICMD_INVOKESPECIAL:
1290 case ICMD_INVOKESTATIC:
1291 case ICMD_INVOKEINTERFACE:
1292 if (stage >= SHOW_STACK) {
1294 INSTRUCTION_GET_METHODDESC(iptr, md);
1295 argp = iptr->sx.s23.s2.args;
1296 i = iptr->s1.argcount;
1298 if ((iptr->s1.argcount - 1 - i) == md->paramcount)
1299 printf(" pass-through: ");
1300 SHOW_VARIABLE(*(argp++));
1303 INSTRUCTION_GET_METHODREF(iptr, fmiref);
1304 method_methodref_print(fmiref);
1305 if (fmiref->parseddesc.md->returntype.type != TYPE_VOID) {
1318 SHOW_INT_CONST(iptr->sx.val.i);
1319 SHOW_TARGET(iptr->dst);
1329 SHOW_LNG_CONST(iptr->sx.val.l);
1330 SHOW_TARGET(iptr->dst);
1334 SHOW_TARGET(iptr->dst);
1338 SHOW_TARGET(iptr->sx.s23.s3.jsrtarget);
1343 case ICMD_IFNONNULL:
1345 SHOW_TARGET(iptr->dst);
1348 case ICMD_IF_ICMPEQ:
1349 case ICMD_IF_ICMPNE:
1350 case ICMD_IF_ICMPLT:
1351 case ICMD_IF_ICMPGE:
1352 case ICMD_IF_ICMPGT:
1353 case ICMD_IF_ICMPLE:
1355 case ICMD_IF_LCMPEQ:
1356 case ICMD_IF_LCMPNE:
1357 case ICMD_IF_LCMPLT:
1358 case ICMD_IF_LCMPGE:
1359 case ICMD_IF_LCMPGT:
1360 case ICMD_IF_LCMPLE:
1362 case ICMD_IF_ACMPEQ:
1363 case ICMD_IF_ACMPNE:
1366 SHOW_TARGET(iptr->dst);
1369 case ICMD_TABLESWITCH:
1371 table = iptr->dst.table;
1373 i = iptr->sx.s23.s3.tablehigh - iptr->sx.s23.s2.tablelow + 1;
1375 printf("high=%d low=%d count=%d\n", iptr->sx.s23.s3.tablehigh, iptr->sx.s23.s2.tablelow, i);
1377 printf("\t\t%d --> ", (int) (table - iptr->dst.table));
1378 printf("L%03d\n", table->block->nr);
1384 case ICMD_LOOKUPSWITCH:
1387 printf("count=%d, default=L%03d\n",
1388 iptr->sx.s23.s2.lookupcount,
1389 iptr->sx.s23.s3.lookupdefault.block->nr);
1391 lookup = iptr->dst.lookup;
1392 i = iptr->sx.s23.s2.lookupcount;
1395 printf("\t\t%d --> L%03d\n",
1397 lookup->target.block->nr);
1412 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1413 /* XXX this needs more work */
1415 unresolved_class_debug_dump(iptr->sx.s23.s2.uc, stdout);
1425 case ICMD_GETEXCEPTION:
1431 #endif /* !defined(NDEBUG) */
1433 /* Debug output filtering */
1435 #if defined(ENABLE_DEBUG_FILTER)
1437 #if !defined(ENABLE_THREADS)
1438 u2 _no_threads_filterverbosecallctr[2] = { 0, 0 };
1441 struct show_filter {
1442 /* Boolean indicating if filter is enabled. */
1444 /* Regular expression the method name is matched against */
1446 /* Flag set on m->filtermatches if regex matches */
1450 typedef struct show_filter show_filter_t;
1452 #define SHOW_FILTERS_SIZE 3
1454 /* Array of filters applyed on a method */
1455 static struct show_filter show_filters[SHOW_FILTERS_SIZE];
1457 static void show_filter_init(show_filter_t *cf, const char *str, u1 flag, u1 default_flag, const char *description) {
1462 err = regcomp(&cf->regex, str, REG_EXTENDED | REG_NOSUB);
1464 regerror(err, &cf->regex, err_buf, sizeof(err_buf));
1466 "Invalid value given for %s: `%s' (%s).",
1467 description, str, err_buf
1473 cf->flag = default_flag;
1478 void show_filters_init(void) {
1482 opt_filter_verbosecall_include,
1483 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1484 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1485 "verbose call include filter"
1490 opt_filter_verbosecall_exclude,
1491 SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE,
1493 "verbose call exclude filter"
1498 opt_filter_show_method,
1499 SHOW_FILTER_FLAG_SHOW_METHOD,
1500 SHOW_FILTER_FLAG_SHOW_METHOD,
1501 "show method filter"
1507 (Pseudo)State machine:
1509 States are INITIAL, INCLUDE1, INCLUDE2, ..., EXCLUDE1, ..., EXCLUDE2, ...
1512 Enter Include Include
1514 | | Enter Enter Enter | | Enter | |
1515 | | Include Include Exclude | | Exclude | |
1516 | v ---------> ----------> ----------> | v ----------> | v
1517 INITIAL INCLUDE1 INCLUDE2 EXCLUDE1 EXCLUDE2
1518 | ^ <--------- <---------- <---------- | ^ <---------- | ^
1519 | | Exit Exit Exit | | Exit | |
1520 | | Include Include Exclude | | Exclude | |
1523 Exclude Include Include
1525 Verbose call scope is active if we are in a INCLUDE state.
1529 INITIAL: ctr[0] == 0, ctr[1] == 0
1530 INCLUDEN: ctr[1] == N, ctr[1] == 0
1531 EXCLUDEN: ctr[1] == N
1534 void show_filters_apply(methodinfo *m) {
1541 /* compose full name of method */
1544 utf_bytes(m->clazz->name) +
1546 utf_bytes(m->name) +
1547 utf_bytes(m->descriptor) +
1552 method_name = DMNEW(char, len);
1554 utf_cat_classname(method_name, m->clazz->name);
1555 strcat(method_name, ".");
1556 utf_cat(method_name, m->name);
1557 utf_cat(method_name, m->descriptor);
1559 /* reset all flags */
1561 m->filtermatches = 0;
1563 for (i = 0; i < SHOW_FILTERS_SIZE; ++i) {
1564 if (show_filters[i].enabled) {
1566 res = regexec(&show_filters[i].regex, method_name, 0, NULL, 0);
1569 m->filtermatches |= show_filters[i].flag;
1572 /* Default is to show all */
1573 m->filtermatches |= show_filters[i].flag;
1577 /* release memory */
1582 #define STATE_IS_INITIAL() ((FILTERVERBOSECALLCTR[0] == 0) && (FILTERVERBOSECALLCTR[1] == 0))
1583 #define STATE_IS_INCLUDE() ((FILTERVERBOSECALLCTR[0] > 0) && (FILTERVERBOSECALLCTR[1] == 0))
1584 #define STATE_IS_EXCLUDE() (FILTERVERBOSECALLCTR[1] > 0)
1585 #define EVENT_INCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE)
1586 #define EVENT_EXCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE)
1587 #define TRANSITION_NEXT_INCLUDE() ++FILTERVERBOSECALLCTR[0]
1588 #define TRANSITION_PREV_INCLUDE() --FILTERVERBOSECALLCTR[0]
1589 #define TRANSITION_NEXT_EXCLUDE() ++FILTERVERBOSECALLCTR[1]
1590 #define TRANSITION_PREV_EXCLUDE() --FILTERVERBOSECALLCTR[1]
1594 if (STATE_IS_INITIAL()) printf("<INITIAL>\n");
1595 else if (STATE_IS_INCLUDE()) printf("<INCLUDE %hd>\n", FILTERVERBOSECALLCTR[0]);
1596 else if (STATE_IS_EXCLUDE()) printf("<EXCLUDE %hd>\n", FILTERVERBOSECALLCTR[1]);
1600 int show_filters_test_verbosecall_enter(methodinfo *m) {
1604 if (STATE_IS_INITIAL()) {
1605 if (EVENT_INCLUDE()) {
1606 TRANSITION_NEXT_INCLUDE();
1608 } else if (STATE_IS_INCLUDE()) {
1609 if (EVENT_EXCLUDE()) {
1610 TRANSITION_NEXT_EXCLUDE();
1611 /* just entered exclude, show this method */
1613 } else if (EVENT_INCLUDE()) {
1614 TRANSITION_NEXT_INCLUDE();
1616 } else if (STATE_IS_EXCLUDE()) {
1617 if (EVENT_EXCLUDE()) {
1618 TRANSITION_NEXT_EXCLUDE();
1622 return STATE_IS_INCLUDE() || force_show;
1625 int show_filters_test_verbosecall_exit(methodinfo *m) {
1630 if (STATE_IS_INCLUDE()) {
1631 if (EVENT_INCLUDE()) {
1632 TRANSITION_PREV_INCLUDE();
1633 /* just entered initial, show this method */
1634 if (STATE_IS_INITIAL()) force_show = 1;
1636 } else if (STATE_IS_EXCLUDE()) {
1637 if (EVENT_EXCLUDE()) {
1638 TRANSITION_PREV_EXCLUDE();
1643 return STATE_IS_INCLUDE() || force_show;
1650 * These are local overrides for various environment variables in Emacs.
1651 * Please do not remove this and leave it at the end of the file, where
1652 * Emacs will automagically detect them.
1653 * ---------------------------------------------------------------------
1656 * indent-tabs-mode: t
1660 * vim:noexpandtab:sw=4:ts=4: