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/options.h"
40 #include "vm/string.hpp"
43 #include "vm/jit/abi.h"
44 #include "vm/jit/jit.h"
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 ***********************************************************/
59 #if defined(ENABLE_THREADS) && !defined(NDEBUG)
60 static java_object_t *show_global_lock;
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 */
83 show_global_lock = NEW(java_object_t);
85 LOCK_INIT_OBJECT_LOCK(show_global_lock);
88 #if defined(ENABLE_DEBUG_FILTER)
100 char *show_jit_type_names[] = {
111 char show_jit_type_letters[] = {
125 /* show_method *****************************************************************
127 Print the intermediate representation of a method.
129 NOTE: Currently this function may only be called after register allocation!
131 *******************************************************************************/
134 void show_method(jitdata *jd, int stage)
141 basicblock *lastbptr;
145 #if defined(ENABLE_DISASSEMBLER)
149 /* get required compiler data */
156 /* We need to enter a lock here, since the binutils disassembler
157 is not reentrant-able and we could not read functions printed
160 LOCK_MONITOR_ENTER(show_global_lock);
162 #if defined(ENABLE_INTRP)
164 irstage = SHOW_PARSE;
169 /* get the last basic block */
171 for (lastbptr = jd->basicblocks; lastbptr->next != NULL; lastbptr = lastbptr->next);
177 if (code_is_leafmethod(code))
178 printf("LEAFMETHOD\n");
180 printf("\nBasic blocks: %d\n", jd->basicblockcount);
181 if (stage >= SHOW_CODE) {
182 printf("Code length: %d\n", (lastbptr->mpc - jd->basicblocks[0].mpc));
183 printf("Data length: %d\n", cd->dseglen);
184 printf("Stub length: %d\n", (s4) (code->mcodelength -
185 ((ptrint) cd->dseglen + lastbptr->mpc)));
187 printf("Variables: %d (%d used)\n", jd->varcount, jd->vartop);
188 if (stage >= SHOW_STACK)
189 printf("Max interfaces: %d\n", jd->maxinterfaces);
190 printf("Max locals: %d\n", jd->maxlocals);
191 printf("Max stack: %d\n", m->maxstack);
192 printf("Linenumbers: %d\n", m->linenumbercount);
193 printf("Branch to entry: %s\n", (jd->branchtoentry) ? "yes" : "no");
194 printf("Branch to end: %s\n", (jd->branchtoend) ? "yes" : "no");
195 if (stage >= SHOW_STACK) {
196 printf("Number of RETURNs: %d", jd->returncount);
197 if (jd->returncount == 1)
198 printf(" (block L%03d)", jd->returnblock->nr);
202 if (stage >= SHOW_PARSE) {
203 printf("Exceptions (Number: %d):\n", jd->exceptiontablelength);
204 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
205 printf(" L%03d ... ", ex->start->nr );
206 printf("L%03d = ", ex->end->nr);
207 printf("L%03d", ex->handler->nr);
208 printf(" (catchtype: ");
209 if (ex->catchtype.any)
210 if (IS_CLASSREF(ex->catchtype))
211 class_classref_print(ex->catchtype.ref);
213 class_print(ex->catchtype.cls);
220 if (irstage >= SHOW_PARSE && rd && jd->localcount > 0) {
221 printf("Local Table:\n");
222 for (i = 0; i < jd->localcount; i++) {
225 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
226 # if defined(ENABLE_INTRP)
229 printf(" (%s) ", show_jit_type_names[VAR(i)->type]);
230 if (irstage >= SHOW_REGS)
231 show_allocation(VAR(i)->type, VAR(i)->flags, VAR(i)->vv.regoff);
233 # if defined(ENABLE_INTRP)
236 #endif /* defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER) */
241 if (jd->maxlocals > 0 && jd->local_map != NULL) {
242 printf("Local Map:\n");
244 for (j = 0; j < jd->maxlocals; j++) {
248 for (i = 0; i < 5; i++) {
249 printf(" %5s ",show_jit_type_names[i]);
250 for (j = 0; j < jd->maxlocals; j++) {
251 if (jd->local_map[j*5+i] == UNUSED)
254 printf("%4i ",jd->local_map[j*5+i]);
261 if (jd->maxinterfaces > 0 && jd->interface_map && irstage >= SHOW_STACK) {
263 interface_info *mapptr = jd->interface_map;
265 /* look if there exist any INOUTS */
266 for (i = 0; (i < (5 * jd->maxinterfaces)) && !exist; i++, mapptr++)
267 exist = (mapptr->flags != UNUSED);
270 printf("Interface Table: (In/Outvars)\n");
272 for (j = 0; j < jd->maxinterfaces; j++) {
277 for (i = 0; i < 5; i++) {
278 printf(" %5s ",show_jit_type_names[i]);
279 for (j = 0; j < jd->maxinterfaces; j++) {
280 s4 flags = jd->interface_map[j*5+i].flags;
281 s4 regoff = jd->interface_map[j*5+i].regoff;
287 if (irstage >= SHOW_REGS) {
288 if (flags & SAVEDVAR) {
289 if (flags & INMEMORY)
295 if (flags & INMEMORY)
300 printf("%c%03d(", ch, regoff);
301 show_allocation(i, flags, regoff);
305 if (flags & SAVEDVAR)
318 if (rd->memuse && irstage >= SHOW_REGS) {
322 printf("Stack slots: (memuse=%d", rd->memuse);
323 if (irstage >= SHOW_CODE) {
324 printf(", stackframesize=%d", cd->stackframesize);
325 max = cd->stackframesize;
328 for (i = 0; i < max; ++i) {
329 #if defined(HAS_4BYTE_STACKSLOT)
330 printf(" M%02d = 0x%02x(sp): ", i, i * 4);
332 printf(" M%02d = 0x%02x(sp): ", i, i * 8);
334 for (j = 0; j < jd->vartop; ++j) {
336 if ((v->flags & INMEMORY) && (v->vv.regoff == i)) {
337 show_variable(jd, j, irstage);
348 #if defined(ENABLE_REPLACEMENT)
349 if (code->rplpoints) {
350 printf("Replacement Points:\n");
351 replace_show_replacement_points(code);
354 #endif /* defined(ENABLE_REPLACEMENT) */
356 #if defined(ENABLE_DISASSEMBLER)
357 /* show code before first basic block */
359 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
360 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen);
362 for (; pc < (u1 *) ((ptrint) code->mcode + cd->dseglen + jd->basicblocks[0].mpc);)
369 /* show code of all basic blocks */
371 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next)
372 show_basicblock(jd, bptr, stage);
374 #if 0 && defined(ENABLE_DISASSEMBLER)
375 /* show code after last basic block */
377 if (stage >= SHOW_CODE && opt_showdisassemble) {
378 printf("\nStubs code:\n");
379 printf("Length: %d\n\n", (s4) (code->mcodelength -
380 ((ptrint) cd->dseglen + lastbptr->mpc)));
382 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen + lastbptr->mpc);
384 for (; (ptrint) pc < ((ptrint) code->mcode + code->mcodelength);)
391 LOCK_MONITOR_EXIT(show_global_lock);
393 /* finally flush the output */
397 #endif /* !defined(NDEBUG) */
400 #if !defined(NDEBUG) && defined(ENABLE_INLINING)
401 static void show_inline_info(jitdata *jd, insinfo_inline *ii, s4 opcode, s4 stage)
406 printf("(pt %d+%d+%d st ",
407 ii->throughcount - (ii->stackvarscount - ii->paramcount),
408 ii->stackvarscount - ii->paramcount,
410 show_variable_array(jd, ii->stackvars, ii->stackvarscount, stage);
412 if (opcode == ICMD_INLINE_START || opcode == ICMD_INLINE_END) {
414 jl = (opcode == ICMD_INLINE_START) ? ii->javalocals_start : ii->javalocals_end;
415 n = (opcode == ICMD_INLINE_START) ? ii->method->maxlocals : ii->outer->maxlocals;
416 show_javalocals_array(jd, jl, n, stage);
423 method_print(ii->outer);
427 method_print(ii->method);
429 #endif /* !defined(NDEBUG) && defined(ENABLE_INLINING) */
432 /* show_basicblock *************************************************************
434 Print the intermediate representation of a basic block.
436 NOTE: Currently this function may only be called after register allocation!
438 *******************************************************************************/
441 void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
449 #if defined(ENABLE_DISASSEMBLER)
450 methodinfo *m; /* this is only a dummy */
453 s4 currentlinenumber;
456 /* get required compiler data */
461 if (bptr->flags != BBDELETED) {
462 #if defined(ENABLE_INTRP)
465 irstage = SHOW_PARSE;
470 deadcode = (bptr->flags < BBREACHED);
474 printf("======== %sL%03d ======== %s(flags: %d, bitflags: %01x, next: %d, type: ",
475 #if defined(ENABLE_REPLACEMENT)
476 (bptr->bitflags & BBFLAG_REPLACEMENT) ? "<REPLACE> " :
480 (deadcode && stage >= SHOW_STACK) ? "DEADCODE! " : "",
481 bptr->flags, bptr->bitflags,
482 (bptr->next) ? (bptr->next->nr) : -1);
484 switch (bptr->type) {
496 printf(", icount: %d", bptr->icount);
498 if (irstage >= SHOW_CFG) {
499 printf(", preds: %d [ ", bptr->predecessorcount);
501 for (i = 0; i < bptr->predecessorcount; i++)
502 printf("%d ", bptr->predecessors[i]->nr);
510 printf(" (clone of L%03d)", bptr->original->nr);
512 basicblock *b = bptr->copied_to;
514 printf(" (copied to ");
515 for (; b; b = b->copied_to)
516 printf("L%03d ", b->nr);
523 if (irstage >= SHOW_CFG) {
524 printf("succs: %d [ ", bptr->successorcount);
526 for (i = 0; i < bptr->successorcount; i++)
527 printf("%d ", bptr->successors[i]->nr);
532 if (irstage >= SHOW_STACK) {
534 show_variable_array(jd, bptr->invars, bptr->indepth, irstage);
535 printf(" javalocals: ");
536 if (bptr->javalocals)
537 show_javalocals_array(jd, bptr->javalocals, bptr->method->maxlocals, irstage);
543 #if defined(ENABLE_INLINING)
544 if (bptr->inlineinfo) {
545 printf("inlineinfo: ");
546 show_inline_info(jd, bptr->inlineinfo, -1, irstage);
549 #endif /* defined(ENABLE_INLINING) */
551 #if defined(ENABLE_SSA)
555 for (i = 0; i < bptr->phicount; i++, iptr++) {
556 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
558 show_icmd(jd, iptr, deadcode, irstage);
565 for (i = 0; i < bptr->icount; i++, iptr++) {
566 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
568 show_icmd(jd, iptr, deadcode, irstage);
572 if (irstage >= SHOW_STACK) {
574 show_variable_array(jd, bptr->outvars, bptr->outdepth, irstage);
578 #if defined(ENABLE_DISASSEMBLER)
579 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd) &&
583 pc = (void *) (code->mcode + cd->dseglen + bptr->mpc);
586 if (bptr->next != NULL) {
587 for (; pc < (void *) (code->mcode + cd->dseglen + bptr->next->mpc);) {
589 linenumbertable_linenumber_for_pc(&m, code, pc);
591 if (currentlinenumber != linenumber) {
592 linenumber = currentlinenumber;
593 printf("%4d:\n", linenumber);
600 for (; pc < (void *) (code->mcode + code->mcodelength);) {
602 linenumbertable_linenumber_for_pc(&m, code, pc);
604 if (currentlinenumber != linenumber) {
605 linenumber = currentlinenumber;
606 printf("%4d:\n", linenumber);
617 #endif /* !defined(NDEBUG) */
620 /* show_icmd *******************************************************************
622 Print the intermediate representation of an instruction.
624 NOTE: Currently this function may only be called after register allocation!
626 *******************************************************************************/
630 #define SHOW_TARGET(target) \
631 if (stage >= SHOW_PARSE) { \
632 printf("--> L%03d ", (target).block->nr); \
635 printf("--> insindex %d ", (target).insindex); \
638 #define SHOW_INT_CONST(val) \
639 if (stage >= SHOW_PARSE) { \
640 printf("%d (0x%08x) ", (int32_t) (val), (int32_t) (val)); \
646 #if SIZEOF_VOID_P == 4
647 #define SHOW_LNG_CONST(val) \
648 if (stage >= SHOW_PARSE) \
649 printf("%lld (0x%016llx) ", (val), (val)); \
653 #define SHOW_LNG_CONST(val) \
654 if (stage >= SHOW_PARSE) \
655 printf("%ld (0x%016lx) ", (val), (val)); \
660 #if SIZEOF_VOID_P == 4
661 #define SHOW_ADR_CONST(val) \
662 if (stage >= SHOW_PARSE) \
663 printf("0x%08x ", (ptrint) (val)); \
667 #define SHOW_ADR_CONST(val) \
668 if (stage >= SHOW_PARSE) \
669 printf("0x%016lx ", (ptrint) (val)); \
674 #define SHOW_FLT_CONST(val) \
675 if (stage >= SHOW_PARSE) { \
678 printf("%g (0x%08x) ", (val), v.i); \
684 #if SIZEOF_VOID_P == 4
685 #define SHOW_DBL_CONST(val) \
686 if (stage >= SHOW_PARSE) { \
689 printf("%g (0x%016llx) ", (val), v.l); \
694 #define SHOW_DBL_CONST(val) \
695 if (stage >= SHOW_PARSE) { \
698 printf("%g (0x%016lx) ", (val), v.l); \
704 #define SHOW_INDEX(index) \
705 if (stage >= SHOW_PARSE) { \
706 printf("%d ", index); \
712 #define SHOW_STRING(val) \
713 if (stage >= SHOW_PARSE) { \
715 utf_display_printable_ascii( \
716 javastring_toutf((java_handle_t *)(val), false)); \
723 #define SHOW_CLASSREF_OR_CLASSINFO(c) \
724 if (stage >= SHOW_PARSE) { \
725 if (IS_CLASSREF(c)) \
726 class_classref_print(c.ref); \
728 class_print(c.cls); \
735 #define SHOW_FIELD(fmiref) \
736 if (stage >= SHOW_PARSE) { \
737 field_fieldref_print(fmiref); \
744 #define SHOW_VARIABLE(v) \
745 show_variable(jd, (v), stage)
747 #define SHOW_S1(iptr) \
748 if (stage >= SHOW_STACK) { \
749 SHOW_VARIABLE(iptr->s1.varindex); \
752 #define SHOW_S2(iptr) \
753 if (stage >= SHOW_STACK) { \
754 SHOW_VARIABLE(iptr->sx.s23.s2.varindex); \
757 #define SHOW_S3(iptr) \
758 if (stage >= SHOW_STACK) { \
759 SHOW_VARIABLE(iptr->sx.s23.s3.varindex); \
762 #define SHOW_DST(iptr) \
763 if (stage >= SHOW_STACK) { \
765 SHOW_VARIABLE(iptr->dst.varindex); \
768 #define SHOW_S1_LOCAL(iptr) \
769 if (stage >= SHOW_STACK) { \
770 printf("L%d ", iptr->s1.varindex); \
773 printf("JavaL%d ", iptr->s1.varindex); \
776 #define SHOW_DST_LOCAL(iptr) \
777 if (stage >= SHOW_STACK) { \
778 printf("=> L%d ", iptr->dst.varindex); \
781 printf("=> JavaL%d ", iptr->dst.varindex); \
784 void show_allocation(s4 type, s4 flags, s4 regoff)
786 if (type == TYPE_RET) {
791 if (flags & INMEMORY) {
792 printf("M%02d", regoff);
796 #ifdef HAS_ADDRESS_REGISTER_FILE
797 if (type == TYPE_ADR) {
798 printf("R%02d", regoff);
803 if (IS_FLT_DBL_TYPE(type)) {
804 printf("F%02d", regoff);
808 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
809 if (IS_2_WORD_TYPE(type)) {
810 # if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
811 # if defined(ENABLE_INTRP)
813 printf("%3d/%3d", GET_LOW_REG(regoff),
814 GET_HIGH_REG(regoff));
817 printf("%3s/%3s", abi_registers_integer_name[GET_LOW_REG(regoff)],
818 abi_registers_integer_name[GET_HIGH_REG(regoff)]);
820 printf("%3d/%3d", GET_LOW_REG(regoff),
821 GET_HIGH_REG(regoff));
825 #endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
827 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
828 # if defined(ENABLE_INTRP)
830 printf("%3d", regoff);
833 printf("%3s", abi_registers_integer_name[regoff]);
835 printf("%3d", regoff);
839 void show_variable(jitdata *jd, s4 index, int stage)
841 show_variable_intern(jd, index, stage);
845 static void show_variable_intern(jitdata *jd, s4 index, int stage)
851 if (index < 0 || index >= jd->vartop) {
852 printf("<INVALID INDEX:%d>", index);
859 case TYPE_INT: type = 'i'; break;
860 case TYPE_LNG: type = 'l'; break;
861 case TYPE_FLT: type = 'f'; break;
862 case TYPE_DBL: type = 'd'; break;
863 case TYPE_ADR: type = 'a'; break;
864 case TYPE_RET: type = 'r'; break;
868 if (index < jd->localcount) {
870 if (v->flags & (PREALLOC | INOUT))
871 printf("<INVALID FLAGS!>");
874 if (v->flags & PREALLOC) {
876 if (v->flags & INOUT) {
877 /* PREALLOC is used to avoid allocation of TYPE_RET */
878 if (v->type == TYPE_RET)
881 printf("<INVALID FLAGS!>");
884 else if (v->flags & INOUT)
890 printf("%c%c%d", kind, type, index);
892 if (v->flags & SAVEDVAR)
895 if (stage >= SHOW_REGS || (v->flags & PREALLOC)) {
897 show_allocation(v->type, v->flags, v->vv.regoff);
901 if (v->type == TYPE_RET && (v->flags & PREALLOC)) {
902 printf("(L%03d)", v->vv.retaddr->nr);
906 static void show_variable_array_intern(jitdata *jd, s4 *vars, int n, int stage,
918 for (i=0; i<n; ++i) {
922 if (vars[i] == UNUSED)
924 else if (javalocals) {
925 nr = RETADDR_FROM_JAVALOCAL(vars[i]);
926 printf("ret(L%03d)", nr);
929 printf("<INVALID INDEX:%d>", vars[i]);
933 show_variable_intern(jd, vars[i], stage);
938 void show_variable_array(jitdata *jd, s4 *vars, int n, int stage)
940 show_variable_array_intern(jd, vars, n, stage, false);
943 void show_javalocals_array(jitdata *jd, s4 *vars, int n, int stage)
945 show_variable_array_intern(jd, vars, n, stage, true);
948 void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
951 branch_target_t *table;
952 lookup_target_t *lookup;
953 constant_FMIref *fmiref;
957 /* get the opcode and the condition */
961 printf("%s ", icmd_table[opcode].name);
963 if (stage < SHOW_PARSE)
969 /* Print the condition for conditional instructions. */
971 /* XXX print condition from flags */
973 if (iptr->flags.bits & INS_FLAG_UNRESOLVED)
974 printf("(UNRESOLVED) ");
984 case ICMD_ARRAYLENGTH:
1003 case ICMD_INT2SHORT:
1051 /* binary/const INT */
1052 case ICMD_IADDCONST:
1053 case ICMD_ISUBCONST:
1054 case ICMD_IMULCONST:
1058 case ICMD_IANDCONST:
1060 case ICMD_IXORCONST:
1061 case ICMD_ISHLCONST:
1062 case ICMD_ISHRCONST:
1063 case ICMD_IUSHRCONST:
1064 case ICMD_LSHLCONST:
1065 case ICMD_LSHRCONST:
1066 case ICMD_LUSHRCONST:
1068 SHOW_INT_CONST(iptr->sx.val.i);
1072 /* ?ASTORECONST (trinary/const INT) */
1073 case ICMD_IASTORECONST:
1074 case ICMD_BASTORECONST:
1075 case ICMD_CASTORECONST:
1076 case ICMD_SASTORECONST:
1079 SHOW_INT_CONST(iptr->sx.s23.s3.constval);
1084 SHOW_INT_CONST(iptr->sx.val.i);
1088 /* binary/const LNG */
1089 case ICMD_LADDCONST:
1090 case ICMD_LSUBCONST:
1091 case ICMD_LMULCONST:
1095 case ICMD_LANDCONST:
1097 case ICMD_LXORCONST:
1099 SHOW_LNG_CONST(iptr->sx.val.l);
1103 /* trinary/const LNG (<= pointer size) */
1104 case ICMD_LASTORECONST:
1107 SHOW_ADR_CONST(iptr->sx.s23.s3.constval);
1112 SHOW_LNG_CONST(iptr->sx.val.l);
1118 SHOW_FLT_CONST(iptr->sx.val.f);
1124 SHOW_DBL_CONST(iptr->sx.val.d);
1130 if (iptr->flags.bits & INS_FLAG_CLASS) {
1131 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1132 SHOW_CLASSREF_OR_CLASSINFO(iptr->sx.val.c);
1134 else if (iptr->sx.val.anyptr == NULL) {
1138 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1139 SHOW_STRING(iptr->sx.val.stringconst);
1144 case ICMD_AASTORECONST:
1147 printf("%p ", (void*) iptr->sx.s23.s3.constval);
1150 case ICMD_GETFIELD: /* 1 -> 1 */
1151 case ICMD_PUTFIELD: /* 2 -> 0 */
1152 case ICMD_PUTSTATIC: /* 1 -> 0 */
1153 case ICMD_GETSTATIC: /* 0 -> 1 */
1154 case ICMD_PUTSTATICCONST: /* 0 -> 0 */
1155 case ICMD_PUTFIELDCONST: /* 1 -> 0 */
1156 if (opcode != ICMD_GETSTATIC && opcode != ICMD_PUTSTATICCONST) {
1158 if (opcode == ICMD_PUTFIELD) {
1162 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1165 if (opcode == ICMD_GETSTATIC || opcode == ICMD_GETFIELD) {
1171 SHOW_S1_LOCAL(iptr);
1172 SHOW_INT_CONST(iptr->sx.val.i);
1173 SHOW_DST_LOCAL(iptr);
1203 SHOW_S1_LOCAL(iptr);
1204 if (stage >= SHOW_STACK) {
1205 printf(" ---> L%03d", iptr->dst.block->nr);
1214 SHOW_S1_LOCAL(iptr);
1224 SHOW_DST_LOCAL(iptr);
1225 if (stage >= SHOW_STACK && iptr->sx.s23.s3.javaindex != UNUSED)
1226 printf(" (javaindex %d)", iptr->sx.s23.s3.javaindex);
1227 if (iptr->flags.bits & INS_FLAG_RETADDR) {
1228 printf(" (retaddr L%03d)", RETADDR_FROM_JAVALOCAL(iptr->sx.s23.s2.retaddrnr));
1240 case ICMD_ANEWARRAY:
1244 case ICMD_MULTIANEWARRAY:
1245 if (stage >= SHOW_STACK) {
1246 argp = iptr->sx.s23.s2.args;
1247 i = iptr->s1.argcount;
1249 SHOW_VARIABLE(*(argp++));
1253 printf("argcount=%d ", iptr->s1.argcount);
1255 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1260 case ICMD_CHECKCAST:
1262 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1267 case ICMD_INSTANCEOF:
1272 case ICMD_INLINE_START:
1273 case ICMD_INLINE_END:
1274 case ICMD_INLINE_BODY:
1275 #if defined(ENABLE_INLINING)
1277 insinfo_inline *ii = iptr->sx.s23.s3.inlineinfo;
1278 show_inline_info(jd, ii, opcode, stage);
1284 if (stage >= SHOW_STACK) {
1285 argp = iptr->sx.s23.s2.args;
1286 i = iptr->s1.argcount;
1288 if ((iptr->s1.argcount - 1 - i) == iptr->sx.s23.s3.bte->md->paramcount)
1289 printf(" pass-through: ");
1290 SHOW_VARIABLE(*(argp++));
1293 printf("%s ", iptr->sx.s23.s3.bte->cname);
1294 if (iptr->sx.s23.s3.bte->md->returntype.type != TYPE_VOID) {
1299 case ICMD_INVOKEVIRTUAL:
1300 case ICMD_INVOKESPECIAL:
1301 case ICMD_INVOKESTATIC:
1302 case ICMD_INVOKEINTERFACE:
1303 if (stage >= SHOW_STACK) {
1305 INSTRUCTION_GET_METHODDESC(iptr, md);
1306 argp = iptr->sx.s23.s2.args;
1307 i = iptr->s1.argcount;
1309 if ((iptr->s1.argcount - 1 - i) == md->paramcount)
1310 printf(" pass-through: ");
1311 SHOW_VARIABLE(*(argp++));
1314 INSTRUCTION_GET_METHODREF(iptr, fmiref);
1315 method_methodref_print(fmiref);
1316 if (fmiref->parseddesc.md->returntype.type != TYPE_VOID) {
1329 SHOW_INT_CONST(iptr->sx.val.i);
1330 SHOW_TARGET(iptr->dst);
1340 SHOW_LNG_CONST(iptr->sx.val.l);
1341 SHOW_TARGET(iptr->dst);
1345 SHOW_TARGET(iptr->dst);
1349 SHOW_TARGET(iptr->sx.s23.s3.jsrtarget);
1354 case ICMD_IFNONNULL:
1356 SHOW_TARGET(iptr->dst);
1359 case ICMD_IF_ICMPEQ:
1360 case ICMD_IF_ICMPNE:
1361 case ICMD_IF_ICMPLT:
1362 case ICMD_IF_ICMPGE:
1363 case ICMD_IF_ICMPGT:
1364 case ICMD_IF_ICMPLE:
1366 case ICMD_IF_LCMPEQ:
1367 case ICMD_IF_LCMPNE:
1368 case ICMD_IF_LCMPLT:
1369 case ICMD_IF_LCMPGE:
1370 case ICMD_IF_LCMPGT:
1371 case ICMD_IF_LCMPLE:
1373 case ICMD_IF_ACMPEQ:
1374 case ICMD_IF_ACMPNE:
1377 SHOW_TARGET(iptr->dst);
1380 case ICMD_TABLESWITCH:
1382 table = iptr->dst.table;
1384 i = iptr->sx.s23.s3.tablehigh - iptr->sx.s23.s2.tablelow + 1;
1386 printf("high=%d low=%d count=%d\n", iptr->sx.s23.s3.tablehigh, iptr->sx.s23.s2.tablelow, i);
1388 printf("\t\t%d --> ", (int) (table - iptr->dst.table));
1389 printf("L%03d\n", table->block->nr);
1395 case ICMD_LOOKUPSWITCH:
1398 printf("count=%d, default=L%03d\n",
1399 iptr->sx.s23.s2.lookupcount,
1400 iptr->sx.s23.s3.lookupdefault.block->nr);
1402 lookup = iptr->dst.lookup;
1403 i = iptr->sx.s23.s2.lookupcount;
1406 printf("\t\t%d --> L%03d\n",
1408 lookup->target.block->nr);
1423 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1424 /* XXX this needs more work */
1426 unresolved_class_debug_dump(iptr->sx.s23.s2.uc, stdout);
1436 case ICMD_GETEXCEPTION:
1439 #if defined(ENABLE_SSA)
1442 for (i = 0; i < iptr->s1.argcount; ++i) {
1443 SHOW_VARIABLE(iptr->sx.s23.s2.iargs[i]->dst.varindex);
1447 if (iptr->flags.bits & (1 << 0)) printf("used ");
1448 if (iptr->flags.bits & (1 << 1)) printf("redundantAll ");
1449 if (iptr->flags.bits & (1 << 2)) printf("redundantOne ");
1455 #endif /* !defined(NDEBUG) */
1457 /* Debug output filtering */
1459 #if defined(ENABLE_DEBUG_FILTER)
1461 #if !defined(ENABLE_THREADS)
1462 u2 _no_threads_filterverbosecallctr[2] = { 0, 0 };
1465 struct show_filter {
1466 /* Boolean indicating if filter is enabled. */
1468 /* Regular expression the method name is matched against */
1470 /* Flag set on m->filtermatches if regex matches */
1474 typedef struct show_filter show_filter_t;
1476 #define SHOW_FILTERS_SIZE 3
1478 /* Array of filters applyed on a method */
1479 static struct show_filter show_filters[SHOW_FILTERS_SIZE];
1481 static void show_filter_init(show_filter_t *cf, const char *str, u1 flag, u1 default_flag, const char *description) {
1486 err = regcomp(&cf->regex, str, REG_EXTENDED | REG_NOSUB);
1488 regerror(err, &cf->regex, err_buf, sizeof(err_buf));
1490 "Invalid value given for %s: `%s' (%s).",
1491 description, str, err_buf
1497 cf->flag = default_flag;
1502 void show_filters_init(void) {
1506 opt_filter_verbosecall_include,
1507 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1508 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1509 "verbose call include filter"
1514 opt_filter_verbosecall_exclude,
1515 SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE,
1517 "verbose call exclude filter"
1522 opt_filter_show_method,
1523 SHOW_FILTER_FLAG_SHOW_METHOD,
1524 SHOW_FILTER_FLAG_SHOW_METHOD,
1525 "show method filter"
1531 (Pseudo)State machine:
1533 States are INITIAL, INCLUDE1, INCLUDE2, ..., EXCLUDE1, ..., EXCLUDE2, ...
1536 Enter Include Include
1538 | | Enter Enter Enter | | Enter | |
1539 | | Include Include Exclude | | Exclude | |
1540 | v ---------> ----------> ----------> | v ----------> | v
1541 INITIAL INCLUDE1 INCLUDE2 EXCLUDE1 EXCLUDE2
1542 | ^ <--------- <---------- <---------- | ^ <---------- | ^
1543 | | Exit Exit Exit | | Exit | |
1544 | | Include Include Exclude | | Exclude | |
1547 Exclude Include Include
1549 Verbose call scope is active if we are in a INCLUDE state.
1553 INITIAL: ctr[0] == 0, ctr[1] == 0
1554 INCLUDEN: ctr[1] == N, ctr[1] == 0
1555 EXCLUDEN: ctr[1] == N
1558 void show_filters_apply(methodinfo *m) {
1565 /* compose full name of method */
1568 utf_bytes(m->clazz->name) +
1570 utf_bytes(m->name) +
1571 utf_bytes(m->descriptor) +
1576 method_name = DMNEW(char, len);
1578 utf_cat_classname(method_name, m->clazz->name);
1579 strcat(method_name, ".");
1580 utf_cat(method_name, m->name);
1581 utf_cat(method_name, m->descriptor);
1583 /* reset all flags */
1585 m->filtermatches = 0;
1587 for (i = 0; i < SHOW_FILTERS_SIZE; ++i) {
1588 if (show_filters[i].enabled) {
1590 res = regexec(&show_filters[i].regex, method_name, 0, NULL, 0);
1593 m->filtermatches |= show_filters[i].flag;
1596 /* Default is to show all */
1597 m->filtermatches |= show_filters[i].flag;
1601 /* release memory */
1606 #define STATE_IS_INITIAL() ((FILTERVERBOSECALLCTR[0] == 0) && (FILTERVERBOSECALLCTR[1] == 0))
1607 #define STATE_IS_INCLUDE() ((FILTERVERBOSECALLCTR[0] > 0) && (FILTERVERBOSECALLCTR[1] == 0))
1608 #define STATE_IS_EXCLUDE() (FILTERVERBOSECALLCTR[1] > 0)
1609 #define EVENT_INCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE)
1610 #define EVENT_EXCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE)
1611 #define TRANSITION_NEXT_INCLUDE() ++FILTERVERBOSECALLCTR[0]
1612 #define TRANSITION_PREV_INCLUDE() --FILTERVERBOSECALLCTR[0]
1613 #define TRANSITION_NEXT_EXCLUDE() ++FILTERVERBOSECALLCTR[1]
1614 #define TRANSITION_PREV_EXCLUDE() --FILTERVERBOSECALLCTR[1]
1618 if (STATE_IS_INITIAL()) printf("<INITIAL>\n");
1619 else if (STATE_IS_INCLUDE()) printf("<INCLUDE %hd>\n", FILTERVERBOSECALLCTR[0]);
1620 else if (STATE_IS_EXCLUDE()) printf("<EXCLUDE %hd>\n", FILTERVERBOSECALLCTR[1]);
1624 int show_filters_test_verbosecall_enter(methodinfo *m) {
1628 if (STATE_IS_INITIAL()) {
1629 if (EVENT_INCLUDE()) {
1630 TRANSITION_NEXT_INCLUDE();
1632 } else if (STATE_IS_INCLUDE()) {
1633 if (EVENT_EXCLUDE()) {
1634 TRANSITION_NEXT_EXCLUDE();
1635 /* just entered exclude, show this method */
1637 } else if (EVENT_INCLUDE()) {
1638 TRANSITION_NEXT_INCLUDE();
1640 } else if (STATE_IS_EXCLUDE()) {
1641 if (EVENT_EXCLUDE()) {
1642 TRANSITION_NEXT_EXCLUDE();
1646 return STATE_IS_INCLUDE() || force_show;
1649 int show_filters_test_verbosecall_exit(methodinfo *m) {
1654 if (STATE_IS_INCLUDE()) {
1655 if (EVENT_INCLUDE()) {
1656 TRANSITION_PREV_INCLUDE();
1657 /* just entered initial, show this method */
1658 if (STATE_IS_INITIAL()) force_show = 1;
1660 } else if (STATE_IS_EXCLUDE()) {
1661 if (EVENT_EXCLUDE()) {
1662 TRANSITION_PREV_EXCLUDE();
1667 return STATE_IS_INCLUDE() || force_show;
1674 * These are local overrides for various environment variables in Emacs.
1675 * Please do not remove this and leave it at the end of the file, where
1676 * Emacs will automagically detect them.
1677 * ---------------------------------------------------------------------
1680 * indent-tabs-mode: t
1684 * vim:noexpandtab:sw=4:ts=4: