1 /* src/vm/jit/show.c - showing the intermediate representation
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zu Foerderung der freien virtuellen Machine 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 # if defined(ENABLE_THREADS)
55 # include "threads/native/threads.h"
57 # include "threads/none/threads.h"
61 /* global variables ***********************************************************/
63 #if defined(ENABLE_THREADS) && !defined(NDEBUG)
64 static java_object_t *show_global_lock;
68 /* prototypes *****************************************************************/
71 static void show_variable_intern(jitdata *jd, s4 index, int stage);
75 /* show_init *******************************************************************
77 Initialized the show subsystem (called by jit_init).
79 *******************************************************************************/
84 #if defined(ENABLE_THREADS)
85 /* initialize the show lock */
87 show_global_lock = NEW(java_object_t);
89 LOCK_INIT_OBJECT_LOCK(show_global_lock);
92 #if defined(ENABLE_DEBUG_FILTER)
104 char *show_jit_type_names[] = {
115 char show_jit_type_letters[] = {
129 /* show_method *****************************************************************
131 Print the intermediate representation of a method.
133 NOTE: Currently this function may only be called after register allocation!
135 *******************************************************************************/
138 void show_method(jitdata *jd, int stage)
145 basicblock *lastbptr;
149 #if defined(ENABLE_DISASSEMBLER)
153 /* get required compiler data */
160 /* We need to enter a lock here, since the binutils disassembler
161 is not reentrant-able and we could not read functions printed
164 LOCK_MONITOR_ENTER(show_global_lock);
166 #if defined(ENABLE_INTRP)
168 irstage = SHOW_PARSE;
173 /* get the last basic block */
175 for (lastbptr = jd->basicblocks; lastbptr->next != NULL; lastbptr = lastbptr->next);
181 if (code_is_leafmethod(code))
182 printf("LEAFMETHOD\n");
184 printf("\nBasic blocks: %d\n", jd->basicblockcount);
185 if (stage >= SHOW_CODE) {
186 printf("Code length: %d\n", (lastbptr->mpc - jd->basicblocks[0].mpc));
187 printf("Data length: %d\n", cd->dseglen);
188 printf("Stub length: %d\n", (s4) (code->mcodelength -
189 ((ptrint) cd->dseglen + lastbptr->mpc)));
191 printf("Variables: %d (%d used)\n", jd->varcount, jd->vartop);
192 if (stage >= SHOW_STACK)
193 printf("Max interfaces: %d\n", jd->maxinterfaces);
194 printf("Max locals: %d\n", jd->maxlocals);
195 printf("Max stack: %d\n", m->maxstack);
196 printf("Linenumbers: %d\n", m->linenumbercount);
197 printf("Branch to entry: %s\n", (jd->branchtoentry) ? "yes" : "no");
198 printf("Branch to end: %s\n", (jd->branchtoend) ? "yes" : "no");
199 if (stage >= SHOW_STACK) {
200 printf("Number of RETURNs: %d", jd->returncount);
201 if (jd->returncount == 1)
202 printf(" (block L%03d)", jd->returnblock->nr);
206 if (stage >= SHOW_PARSE) {
207 printf("Exceptions (Number: %d):\n", jd->exceptiontablelength);
208 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
209 printf(" L%03d ... ", ex->start->nr );
210 printf("L%03d = ", ex->end->nr);
211 printf("L%03d", ex->handler->nr);
212 printf(" (catchtype: ");
213 if (ex->catchtype.any)
214 if (IS_CLASSREF(ex->catchtype))
215 class_classref_print(ex->catchtype.ref);
217 class_print(ex->catchtype.cls);
224 if (irstage >= SHOW_PARSE && rd && jd->localcount > 0) {
225 printf("Local Table:\n");
226 for (i = 0; i < jd->localcount; i++) {
229 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
230 # if defined(ENABLE_INTRP)
233 printf(" (%s) ", show_jit_type_names[VAR(i)->type]);
234 if (irstage >= SHOW_REGS)
235 show_allocation(VAR(i)->type, VAR(i)->flags, VAR(i)->vv.regoff);
237 # if defined(ENABLE_INTRP)
240 #endif /* defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER) */
245 if (jd->maxlocals > 0 && jd->local_map != NULL) {
246 printf("Local Map:\n");
248 for (j = 0; j < jd->maxlocals; j++) {
252 for (i = 0; i < 5; i++) {
253 printf(" %5s ",show_jit_type_names[i]);
254 for (j = 0; j < jd->maxlocals; j++) {
255 if (jd->local_map[j*5+i] == UNUSED)
258 printf("%4i ",jd->local_map[j*5+i]);
265 if (jd->maxinterfaces > 0 && jd->interface_map && irstage >= SHOW_STACK) {
267 interface_info *mapptr = jd->interface_map;
269 /* look if there exist any INOUTS */
270 for (i = 0; (i < (5 * jd->maxinterfaces)) && !exist; i++, mapptr++)
271 exist = (mapptr->flags != UNUSED);
274 printf("Interface Table: (In/Outvars)\n");
276 for (j = 0; j < jd->maxinterfaces; j++) {
281 for (i = 0; i < 5; i++) {
282 printf(" %5s ",show_jit_type_names[i]);
283 for (j = 0; j < jd->maxinterfaces; j++) {
284 s4 flags = jd->interface_map[j*5+i].flags;
285 s4 regoff = jd->interface_map[j*5+i].regoff;
291 if (irstage >= SHOW_REGS) {
292 if (flags & SAVEDVAR) {
293 if (flags & INMEMORY)
299 if (flags & INMEMORY)
304 printf("%c%03d(", ch, regoff);
305 show_allocation(i, flags, regoff);
309 if (flags & SAVEDVAR)
322 if (rd->memuse && irstage >= SHOW_REGS) {
326 printf("Stack slots: (memuse=%d", rd->memuse);
327 if (irstage >= SHOW_CODE) {
328 printf(", stackframesize=%d", cd->stackframesize);
329 max = cd->stackframesize;
332 for (i = 0; i < max; ++i) {
333 #if defined(HAS_4BYTE_STACKSLOT)
334 printf(" M%02d = 0x%02x(sp): ", i, i * 4);
336 printf(" M%02d = 0x%02x(sp): ", i, i * 8);
338 for (j = 0; j < jd->vartop; ++j) {
340 if ((v->flags & INMEMORY) && (v->vv.regoff == i)) {
341 show_variable(jd, j, irstage);
352 #if defined(ENABLE_REPLACEMENT)
353 if (code->rplpoints) {
354 printf("Replacement Points:\n");
355 replace_show_replacement_points(code);
358 #endif /* defined(ENABLE_REPLACEMENT) */
360 #if defined(ENABLE_DISASSEMBLER)
361 /* show code before first basic block */
363 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
364 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen);
366 for (; pc < (u1 *) ((ptrint) code->mcode + cd->dseglen + jd->basicblocks[0].mpc);)
373 /* show code of all basic blocks */
375 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next)
376 show_basicblock(jd, bptr, stage);
378 #if 0 && defined(ENABLE_DISASSEMBLER)
379 /* show code after last basic block */
381 if (stage >= SHOW_CODE && opt_showdisassemble) {
382 printf("\nStubs code:\n");
383 printf("Length: %d\n\n", (s4) (code->mcodelength -
384 ((ptrint) cd->dseglen + lastbptr->mpc)));
386 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen + lastbptr->mpc);
388 for (; (ptrint) pc < ((ptrint) code->mcode + code->mcodelength);)
395 LOCK_MONITOR_EXIT(show_global_lock);
397 /* finally flush the output */
401 #endif /* !defined(NDEBUG) */
404 #if !defined(NDEBUG) && defined(ENABLE_INLINING)
405 static void show_inline_info(jitdata *jd, insinfo_inline *ii, s4 opcode, s4 stage)
410 printf("(pt %d+%d+%d st ",
411 ii->throughcount - (ii->stackvarscount - ii->paramcount),
412 ii->stackvarscount - ii->paramcount,
414 show_variable_array(jd, ii->stackvars, ii->stackvarscount, stage);
416 if (opcode == ICMD_INLINE_START || opcode == ICMD_INLINE_END) {
418 jl = (opcode == ICMD_INLINE_START) ? ii->javalocals_start : ii->javalocals_end;
419 n = (opcode == ICMD_INLINE_START) ? ii->method->maxlocals : ii->outer->maxlocals;
420 show_javalocals_array(jd, jl, n, stage);
427 method_print(ii->outer);
431 method_print(ii->method);
433 #endif /* !defined(NDEBUG) && defined(ENABLE_INLINING) */
436 /* show_basicblock *************************************************************
438 Print the intermediate representation of a basic block.
440 NOTE: Currently this function may only be called after register allocation!
442 *******************************************************************************/
445 void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
453 #if defined(ENABLE_DISASSEMBLER)
454 methodinfo *m; /* this is only a dummy */
457 s4 currentlinenumber;
460 /* get required compiler data */
465 if (bptr->flags != BBDELETED) {
466 #if defined(ENABLE_INTRP)
469 irstage = SHOW_PARSE;
474 deadcode = (bptr->flags < BBREACHED);
478 printf("======== %sL%03d ======== %s(flags: %d, bitflags: %01x, next: %d, type: ",
479 #if defined(ENABLE_REPLACEMENT)
480 (bptr->bitflags & BBFLAG_REPLACEMENT) ? "<REPLACE> " :
484 (deadcode && stage >= SHOW_STACK) ? "DEADCODE! " : "",
485 bptr->flags, bptr->bitflags,
486 (bptr->next) ? (bptr->next->nr) : -1);
488 switch (bptr->type) {
500 printf(", icount: %d", bptr->icount);
502 if (irstage >= SHOW_CFG) {
503 printf(", preds: %d [ ", bptr->predecessorcount);
505 for (i = 0; i < bptr->predecessorcount; i++)
506 printf("%d ", bptr->predecessors[i]->nr);
514 printf(" (clone of L%03d)", bptr->original->nr);
516 basicblock *b = bptr->copied_to;
518 printf(" (copied to ");
519 for (; b; b = b->copied_to)
520 printf("L%03d ", b->nr);
527 if (irstage >= SHOW_CFG) {
528 printf("succs: %d [ ", bptr->successorcount);
530 for (i = 0; i < bptr->successorcount; i++)
531 printf("%d ", bptr->successors[i]->nr);
536 if (irstage >= SHOW_STACK) {
538 show_variable_array(jd, bptr->invars, bptr->indepth, irstage);
539 printf(" javalocals: ");
540 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);
1428 #endif /* !defined(NDEBUG) */
1430 /* Debug output filtering */
1432 #if defined(ENABLE_DEBUG_FILTER)
1434 #if !defined(ENABLE_THREADS)
1435 u2 _no_threads_filterverbosecallctr[2] = { 0, 0 };
1438 struct show_filter {
1439 /* Boolean indicating if filter is enabled. */
1441 /* Regular expression the method name is matched against */
1443 /* Flag set on m->filtermatches if regex matches */
1447 typedef struct show_filter show_filter_t;
1449 #define SHOW_FILTERS_SIZE 3
1451 /* Array of filters applyed on a method */
1452 static struct show_filter show_filters[SHOW_FILTERS_SIZE];
1454 static void show_filter_init(show_filter_t *cf, const char *str, u1 flag, u1 default_flag, const char *description) {
1459 err = regcomp(&cf->regex, str, REG_EXTENDED | REG_NOSUB);
1461 regerror(err, &cf->regex, err_buf, sizeof(err_buf));
1463 "Invalid value given for %s: `%s' (%s).",
1464 description, str, err_buf
1470 cf->flag = default_flag;
1475 void show_filters_init(void) {
1479 opt_filter_verbosecall_include,
1480 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1481 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1482 "verbose call include filter"
1487 opt_filter_verbosecall_exclude,
1488 SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE,
1490 "verbose call exclude filter"
1495 opt_filter_show_method,
1496 SHOW_FILTER_FLAG_SHOW_METHOD,
1497 SHOW_FILTER_FLAG_SHOW_METHOD,
1498 "show method filter"
1504 (Pseudo)State machine:
1506 States are INITIAL, INCLUDE1, INCLUDE2, ..., EXCLUDE1, ..., EXCLUDE2, ...
1509 Enter Include Include
1511 | | Enter Enter Enter | | Enter | |
1512 | | Include Include Exclude | | Exclude | |
1513 | v ---------> ----------> ----------> | v ----------> | v
1514 INITIAL INCLUDE1 INCLUDE2 EXCLUDE1 EXCLUDE2
1515 | ^ <--------- <---------- <---------- | ^ <---------- | ^
1516 | | Exit Exit Exit | | Exit | |
1517 | | Include Include Exclude | | Exclude | |
1520 Exclude Include Include
1522 Verbose call scope is active if we are in a INCLUDE state.
1526 INITIAL: ctr[0] == 0, ctr[1] == 0
1527 INCLUDEN: ctr[1] == N, ctr[1] == 0
1528 EXCLUDEN: ctr[1] == N
1531 void show_filters_apply(methodinfo *m) {
1538 /* compose full name of method */
1541 utf_bytes(m->class->name) +
1543 utf_bytes(m->name) +
1544 utf_bytes(m->descriptor) +
1549 method_name = DMNEW(char, len);
1551 utf_cat_classname(method_name, m->class->name);
1552 strcat(method_name, ".");
1553 utf_cat(method_name, m->name);
1554 utf_cat(method_name, m->descriptor);
1556 /* reset all flags */
1558 m->filtermatches = 0;
1560 for (i = 0; i < SHOW_FILTERS_SIZE; ++i) {
1561 if (show_filters[i].enabled) {
1563 res = regexec(&show_filters[i].regex, method_name, 0, NULL, 0);
1566 m->filtermatches |= show_filters[i].flag;
1569 /* Default is to show all */
1570 m->filtermatches |= show_filters[i].flag;
1574 /* release memory */
1579 #define STATE_IS_INITIAL() ((FILTERVERBOSECALLCTR[0] == 0) && (FILTERVERBOSECALLCTR[1] == 0))
1580 #define STATE_IS_INCLUDE() ((FILTERVERBOSECALLCTR[0] > 0) && (FILTERVERBOSECALLCTR[1] == 0))
1581 #define STATE_IS_EXCLUDE() (FILTERVERBOSECALLCTR[1] > 0)
1582 #define EVENT_INCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE)
1583 #define EVENT_EXCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE)
1584 #define TRANSITION_NEXT_INCLUDE() ++FILTERVERBOSECALLCTR[0]
1585 #define TRANSITION_PREV_INCLUDE() --FILTERVERBOSECALLCTR[0]
1586 #define TRANSITION_NEXT_EXCLUDE() ++FILTERVERBOSECALLCTR[1]
1587 #define TRANSITION_PREV_EXCLUDE() --FILTERVERBOSECALLCTR[1]
1591 if (STATE_IS_INITIAL()) printf("<INITIAL>\n");
1592 else if (STATE_IS_INCLUDE()) printf("<INCLUDE %hd>\n", FILTERVERBOSECALLCTR[0]);
1593 else if (STATE_IS_EXCLUDE()) printf("<EXCLUDE %hd>\n", FILTERVERBOSECALLCTR[1]);
1597 int show_filters_test_verbosecall_enter(methodinfo *m) {
1601 if (STATE_IS_INITIAL()) {
1602 if (EVENT_INCLUDE()) {
1603 TRANSITION_NEXT_INCLUDE();
1605 } else if (STATE_IS_INCLUDE()) {
1606 if (EVENT_EXCLUDE()) {
1607 TRANSITION_NEXT_EXCLUDE();
1608 /* just entered exclude, show this method */
1610 } else if (EVENT_INCLUDE()) {
1611 TRANSITION_NEXT_INCLUDE();
1613 } else if (STATE_IS_EXCLUDE()) {
1614 if (EVENT_EXCLUDE()) {
1615 TRANSITION_NEXT_EXCLUDE();
1619 return STATE_IS_INCLUDE() || force_show;
1622 int show_filters_test_verbosecall_exit(methodinfo *m) {
1627 if (STATE_IS_INCLUDE()) {
1628 if (EVENT_INCLUDE()) {
1629 TRANSITION_PREV_INCLUDE();
1630 /* just entered initial, show this method */
1631 if (STATE_IS_INITIAL()) force_show = 1;
1633 } else if (STATE_IS_EXCLUDE()) {
1634 if (EVENT_EXCLUDE()) {
1635 TRANSITION_PREV_EXCLUDE();
1640 return STATE_IS_INCLUDE() || force_show;
1647 * These are local overrides for various environment variables in Emacs.
1648 * Please do not remove this and leave it at the end of the file, where
1649 * Emacs will automagically detect them.
1650 * ---------------------------------------------------------------------
1653 * indent-tabs-mode: t
1657 * vim:noexpandtab:sw=4:ts=4: