1 /* src/vm/jit/show.c - showing the intermediate representation
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
36 #include "mm/memory.h"
38 #include "threads/lock-common.h"
40 #include "vm/global.h"
41 #include "vm/builtin.h"
42 #include "vm/stringlocal.h"
45 #include "vm/jit/abi.h"
46 #include "vm/jit/jit.h"
47 #include "vm/jit/show.h"
48 #include "vm/jit/disass.h"
49 #include "vm/jit/stack.h"
50 #include "vm/jit/parse.h"
52 #include "vmcore/options.h"
54 #if defined(ENABLE_DEBUG_FILTER)
55 # include <sys/types.h>
57 # if defined(ENABLE_THREADS)
58 # include "threads/native/threads.h"
60 # include "threads/none/threads.h"
64 /* global variables ***********************************************************/
66 #if defined(ENABLE_THREADS) && !defined(NDEBUG)
67 static java_object_t *show_global_lock;
71 /* prototypes *****************************************************************/
74 static void show_variable_intern(jitdata *jd, s4 index, int stage);
78 /* show_init *******************************************************************
80 Initialized the show subsystem (called by jit_init).
82 *******************************************************************************/
87 #if defined(ENABLE_THREADS)
88 /* initialize the show lock */
90 show_global_lock = NEW(java_object_t);
92 LOCK_INIT_OBJECT_LOCK(show_global_lock);
95 #if defined(ENABLE_DEBUG_FILTER)
107 char *show_jit_type_names[] = {
118 char show_jit_type_letters[] = {
132 /* show_method *****************************************************************
134 Print the intermediate representation of a method.
136 NOTE: Currently this function may only be called after register allocation!
138 *******************************************************************************/
141 void show_method(jitdata *jd, int stage)
148 basicblock *lastbptr;
152 #if defined(ENABLE_DISASSEMBLER)
156 /* get required compiler data */
163 /* We need to enter a lock here, since the binutils disassembler
164 is not reentrant-able and we could not read functions printed
167 LOCK_MONITOR_ENTER(show_global_lock);
169 #if defined(ENABLE_INTRP)
171 irstage = SHOW_PARSE;
176 /* get the last basic block */
178 for (lastbptr = jd->basicblocks; lastbptr->next != NULL; lastbptr = lastbptr->next);
184 if (jd->isleafmethod)
185 printf("LEAFMETHOD\n");
187 printf("\nBasic blocks: %d\n", jd->basicblockcount);
188 if (stage >= SHOW_CODE) {
189 printf("Code length: %d\n", (lastbptr->mpc - jd->basicblocks[0].mpc));
190 printf("Data length: %d\n", cd->dseglen);
191 printf("Stub length: %d\n", (s4) (code->mcodelength -
192 ((ptrint) cd->dseglen + lastbptr->mpc)));
194 printf("Variables: %d (%d used)\n", jd->varcount, jd->vartop);
195 if (stage >= SHOW_STACK)
196 printf("Max interfaces: %d\n", jd->maxinterfaces);
197 printf("Max locals: %d\n", jd->maxlocals);
198 printf("Max stack: %d\n", m->maxstack);
199 printf("Linenumbers: %d\n", m->linenumbercount);
200 printf("Branch to entry: %s\n", (jd->branchtoentry) ? "yes" : "no");
201 printf("Branch to end: %s\n", (jd->branchtoend) ? "yes" : "no");
202 if (stage >= SHOW_STACK) {
203 printf("Number of RETURNs: %d", jd->returncount);
204 if (jd->returncount == 1)
205 printf(" (block L%03d)", jd->returnblock->nr);
209 if (stage >= SHOW_PARSE) {
210 printf("Exceptions (Number: %d):\n", jd->exceptiontablelength);
211 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
212 printf(" L%03d ... ", ex->start->nr );
213 printf("L%03d = ", ex->end->nr);
214 printf("L%03d", ex->handler->nr);
215 printf(" (catchtype: ");
216 if (ex->catchtype.any)
217 if (IS_CLASSREF(ex->catchtype))
218 class_classref_print(ex->catchtype.ref);
220 class_print(ex->catchtype.cls);
227 if (irstage >= SHOW_PARSE && rd && jd->localcount > 0) {
228 printf("Local Table:\n");
229 for (i = 0; i < jd->localcount; i++) {
232 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
233 # if defined(ENABLE_INTRP)
236 printf(" (%s) ", show_jit_type_names[VAR(i)->type]);
237 if (irstage >= SHOW_REGS)
238 show_allocation(VAR(i)->type, VAR(i)->flags, VAR(i)->vv.regoff);
240 # if defined(ENABLE_INTRP)
243 #endif /* defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER) */
248 if (jd->maxlocals > 0 && jd->local_map != NULL) {
249 printf("Local Map:\n");
251 for (j = 0; j < jd->maxlocals; j++) {
255 for (i = 0; i < 5; i++) {
256 printf(" %5s ",show_jit_type_names[i]);
257 for (j = 0; j < jd->maxlocals; j++) {
258 if (jd->local_map[j*5+i] == UNUSED)
261 printf("%4i ",jd->local_map[j*5+i]);
268 if (jd->maxinterfaces > 0 && jd->interface_map && irstage >= SHOW_STACK) {
270 interface_info *mapptr = jd->interface_map;
272 /* look if there exist any INOUTS */
273 for (i = 0; (i < (5 * jd->maxinterfaces)) && !exist; i++, mapptr++)
274 exist = (mapptr->flags != UNUSED);
277 printf("Interface Table: (In/Outvars)\n");
279 for (j = 0; j < jd->maxinterfaces; j++) {
284 for (i = 0; i < 5; i++) {
285 printf(" %5s ",show_jit_type_names[i]);
286 for (j = 0; j < jd->maxinterfaces; j++) {
287 s4 flags = jd->interface_map[j*5+i].flags;
288 s4 regoff = jd->interface_map[j*5+i].regoff;
294 if (irstage >= SHOW_REGS) {
295 if (flags & SAVEDVAR) {
296 if (flags & INMEMORY)
302 if (flags & INMEMORY)
307 printf("%c%03d(", ch, regoff);
308 show_allocation(i, flags, regoff);
312 if (flags & SAVEDVAR)
325 if (rd->memuse && irstage >= SHOW_REGS) {
329 printf("Stack slots: (memuse=%d", rd->memuse);
330 if (irstage >= SHOW_CODE) {
331 printf(", stackframesize=%d", cd->stackframesize);
332 max = cd->stackframesize;
335 for (i = 0; i < max; ++i) {
336 #if defined(HAS_4BYTE_STACKSLOT)
337 printf(" M%02d = 0x%02x(sp): ", i, i * 4);
339 printf(" M%02d = 0x%02x(sp): ", i, i * 8);
341 for (j = 0; j < jd->vartop; ++j) {
343 if ((v->flags & INMEMORY) && (v->vv.regoff == i)) {
344 show_variable(jd, j, irstage);
355 #if defined(ENABLE_REPLACEMENT)
356 if (code->rplpoints) {
357 printf("Replacement Points:\n");
358 replace_show_replacement_points(code);
361 #endif /* defined(ENABLE_REPLACEMENT) */
363 #if defined(ENABLE_DISASSEMBLER)
364 /* show code before first basic block */
366 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
367 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen);
369 for (; pc < (u1 *) ((ptrint) code->mcode + cd->dseglen + jd->basicblocks[0].mpc);)
376 /* show code of all basic blocks */
378 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next)
379 show_basicblock(jd, bptr, stage);
381 #if defined(ENABLE_DISASSEMBLER)
382 /* show stubs code */
384 if (stage >= SHOW_CODE && opt_showdisassemble && opt_showexceptionstubs) {
385 printf("\nStubs code:\n");
386 printf("Length: %d\n\n", (s4) (code->mcodelength -
387 ((ptrint) cd->dseglen + lastbptr->mpc)));
389 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen + lastbptr->mpc);
391 for (; (ptrint) pc < ((ptrint) code->mcode + code->mcodelength);)
398 LOCK_MONITOR_EXIT(show_global_lock);
400 /* finally flush the output */
404 #endif /* !defined(NDEBUG) */
407 #if !defined(NDEBUG) && defined(ENABLE_INLINING)
408 static void show_inline_info(jitdata *jd, insinfo_inline *ii, s4 opcode, s4 stage)
413 printf("(pt %d+%d+%d st ",
414 ii->throughcount - (ii->stackvarscount - ii->paramcount),
415 ii->stackvarscount - ii->paramcount,
417 show_variable_array(jd, ii->stackvars, ii->stackvarscount, stage);
419 if (opcode == ICMD_INLINE_START || opcode == ICMD_INLINE_END) {
421 jl = (opcode == ICMD_INLINE_START) ? ii->javalocals_start : ii->javalocals_end;
422 n = (opcode == ICMD_INLINE_START) ? ii->method->maxlocals : ii->outer->maxlocals;
423 show_javalocals_array(jd, jl, n, stage);
430 method_print(ii->outer);
434 method_print(ii->method);
436 #endif /* !defined(NDEBUG) && defined(ENABLE_INLINING) */
439 /* show_basicblock *************************************************************
441 Print the intermediate representation of a basic block.
443 NOTE: Currently this function may only be called after register allocation!
445 *******************************************************************************/
448 void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
456 #if defined(ENABLE_DISASSEMBLER)
457 methodinfo *m; /* this is only a dummy */
460 s4 currentlinenumber;
463 /* get required compiler data */
468 if (bptr->flags != BBDELETED) {
469 #if defined(ENABLE_INTRP)
472 irstage = SHOW_PARSE;
477 deadcode = (bptr->flags < BBREACHED);
481 printf("======== %sL%03d ======== %s(flags: %d, bitflags: %01x, next: %d, type: ",
482 #if defined(ENABLE_REPLACEMENT)
483 (bptr->bitflags & BBFLAG_REPLACEMENT) ? "<REPLACE> " :
487 (deadcode && stage >= SHOW_STACK) ? "DEADCODE! " : "",
488 bptr->flags, bptr->bitflags,
489 (bptr->next) ? (bptr->next->nr) : -1);
491 switch (bptr->type) {
503 printf(", icount: %d", bptr->icount);
505 if (irstage >= SHOW_CFG) {
506 printf(", preds: %d [ ", bptr->predecessorcount);
508 for (i = 0; i < bptr->predecessorcount; i++)
509 printf("%d ", bptr->predecessors[i]->nr);
517 printf(" (clone of L%03d)", bptr->original->nr);
519 basicblock *b = bptr->copied_to;
521 printf(" (copied to ");
522 for (; b; b = b->copied_to)
523 printf("L%03d ", b->nr);
530 if (irstage >= SHOW_STACK) {
532 show_variable_array(jd, bptr->invars, bptr->indepth, irstage);
533 printf(" javalocals: ");
534 show_javalocals_array(jd, bptr->javalocals, bptr->method->maxlocals, irstage);
538 #if defined(ENABLE_INLINING)
539 if (bptr->inlineinfo) {
540 printf("inlineinfo: ");
541 show_inline_info(jd, bptr->inlineinfo, -1, irstage);
544 #endif /* defined(ENABLE_INLINING) */
548 for (i = 0; i < bptr->icount; i++, iptr++) {
549 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
551 show_icmd(jd, iptr, deadcode, irstage);
555 if (irstage >= SHOW_STACK) {
557 show_variable_array(jd, bptr->outvars, bptr->outdepth, irstage);
561 #if defined(ENABLE_DISASSEMBLER)
562 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd) &&
566 pc = (u1 *) (code->mcode + cd->dseglen + bptr->mpc);
569 if (bptr->next != NULL) {
570 for (; pc < (u1 *) (code->mcode + cd->dseglen + bptr->next->mpc);) {
572 dseg_get_linenumber_from_pc(&m, code->entrypoint, pc);
574 if (currentlinenumber != linenumber) {
575 linenumber = currentlinenumber;
576 printf("%4d:\n", linenumber);
583 for (; pc < (u1 *) (code->mcode + code->mcodelength);) {
585 dseg_get_linenumber_from_pc(&m, code->entrypoint, pc);
587 if (currentlinenumber != linenumber) {
588 linenumber = currentlinenumber;
589 printf("%4d:\n", linenumber);
600 #endif /* !defined(NDEBUG) */
603 /* show_icmd *******************************************************************
605 Print the intermediate representation of an instruction.
607 NOTE: Currently this function may only be called after register allocation!
609 *******************************************************************************/
613 #define SHOW_TARGET(target) \
614 if (stage >= SHOW_PARSE) { \
615 printf("--> L%03d ", (target).block->nr); \
618 printf("--> insindex %d ", (target).insindex); \
621 #define SHOW_INT_CONST(val) \
622 if (stage >= SHOW_PARSE) { \
623 printf("%d (0x%08x) ", (val), (val)); \
629 #if SIZEOF_VOID_P == 4
630 #define SHOW_LNG_CONST(val) \
631 if (stage >= SHOW_PARSE) \
632 printf("%lld (0x%016llx) ", (val), (val)); \
636 #define SHOW_LNG_CONST(val) \
637 if (stage >= SHOW_PARSE) \
638 printf("%ld (0x%016lx) ", (val), (val)); \
643 #if SIZEOF_VOID_P == 4
644 #define SHOW_ADR_CONST(val) \
645 if (stage >= SHOW_PARSE) \
646 printf("0x%08x ", (ptrint) (val)); \
650 #define SHOW_ADR_CONST(val) \
651 if (stage >= SHOW_PARSE) \
652 printf("0x%016lx ", (ptrint) (val)); \
657 #define SHOW_FLT_CONST(val) \
658 if (stage >= SHOW_PARSE) { \
661 printf("%g (0x%08x) ", (val), v.i); \
667 #if SIZEOF_VOID_P == 4
668 #define SHOW_DBL_CONST(val) \
669 if (stage >= SHOW_PARSE) { \
672 printf("%g (0x%016llx) ", (val), v.l); \
677 #define SHOW_DBL_CONST(val) \
678 if (stage >= SHOW_PARSE) { \
681 printf("%g (0x%016lx) ", (val), v.l); \
687 #define SHOW_INDEX(index) \
688 if (stage >= SHOW_PARSE) { \
689 printf("%d ", index); \
695 #define SHOW_STRING(val) \
696 if (stage >= SHOW_PARSE) { \
698 utf_display_printable_ascii( \
699 javastring_toutf((java_handle_t *)(val), false)); \
706 #define SHOW_CLASSREF_OR_CLASSINFO(c) \
707 if (stage >= SHOW_PARSE) { \
708 if (IS_CLASSREF(c)) \
709 class_classref_print(c.ref); \
711 class_print(c.cls); \
718 #define SHOW_FIELD(fmiref) \
719 if (stage >= SHOW_PARSE) { \
720 field_fieldref_print(fmiref); \
727 #define SHOW_VARIABLE(v) \
728 show_variable(jd, (v), stage)
730 #define SHOW_S1(iptr) \
731 if (stage >= SHOW_STACK) { \
732 SHOW_VARIABLE(iptr->s1.varindex); \
735 #define SHOW_S2(iptr) \
736 if (stage >= SHOW_STACK) { \
737 SHOW_VARIABLE(iptr->sx.s23.s2.varindex); \
740 #define SHOW_S3(iptr) \
741 if (stage >= SHOW_STACK) { \
742 SHOW_VARIABLE(iptr->sx.s23.s3.varindex); \
745 #define SHOW_DST(iptr) \
746 if (stage >= SHOW_STACK) { \
748 SHOW_VARIABLE(iptr->dst.varindex); \
751 #define SHOW_S1_LOCAL(iptr) \
752 if (stage >= SHOW_STACK) { \
753 printf("L%d ", iptr->s1.varindex); \
756 printf("JavaL%d ", iptr->s1.varindex); \
759 #define SHOW_DST_LOCAL(iptr) \
760 if (stage >= SHOW_STACK) { \
761 printf("=> L%d ", iptr->dst.varindex); \
764 printf("=> JavaL%d ", iptr->dst.varindex); \
767 void show_allocation(s4 type, s4 flags, s4 regoff)
769 if (type == TYPE_RET) {
774 if (flags & INMEMORY) {
775 printf("M%02d", regoff);
779 #ifdef HAS_ADDRESS_REGISTER_FILE
780 if (type == TYPE_ADR) {
781 printf("R%02d", regoff);
786 if (IS_FLT_DBL_TYPE(type)) {
787 printf("F%02d", regoff);
791 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
792 if (IS_2_WORD_TYPE(type)) {
793 # if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
794 # if defined(ENABLE_INTRP)
796 printf("%3d/%3d", GET_LOW_REG(regoff),
797 GET_HIGH_REG(regoff));
800 printf("%3s/%3s", abi_registers_integer_name[GET_LOW_REG(regoff)],
801 abi_registers_integer_name[GET_HIGH_REG(regoff)]);
803 printf("%3d/%3d", GET_LOW_REG(regoff),
804 GET_HIGH_REG(regoff));
808 #endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
810 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
811 # if defined(ENABLE_INTRP)
813 printf("%3d", regoff);
816 printf("%3s", abi_registers_integer_name[regoff]);
818 printf("%3d", regoff);
822 void show_variable(jitdata *jd, s4 index, int stage)
824 show_variable_intern(jd, index, stage);
828 static void show_variable_intern(jitdata *jd, s4 index, int stage)
834 if (index < 0 || index >= jd->vartop) {
835 printf("<INVALID INDEX:%d>", index);
842 case TYPE_INT: type = 'i'; break;
843 case TYPE_LNG: type = 'l'; break;
844 case TYPE_FLT: type = 'f'; break;
845 case TYPE_DBL: type = 'd'; break;
846 case TYPE_ADR: type = 'a'; break;
847 case TYPE_RET: type = 'r'; break;
851 if (index < jd->localcount) {
853 if (v->flags & (PREALLOC | INOUT))
854 printf("<INVALID FLAGS!>");
857 if (v->flags & PREALLOC) {
859 if (v->flags & INOUT) {
860 /* PREALLOC is used to avoid allocation of TYPE_RET */
861 if (v->type == TYPE_RET)
864 printf("<INVALID FLAGS!>");
867 else if (v->flags & INOUT)
873 printf("%c%c%d", kind, type, index);
875 if (v->flags & SAVEDVAR)
878 if (stage >= SHOW_REGS || (v->flags & PREALLOC)) {
880 show_allocation(v->type, v->flags, v->vv.regoff);
884 if (v->type == TYPE_RET && (v->flags & PREALLOC)) {
885 printf("(L%03d)", v->vv.retaddr->nr);
889 static void show_variable_array_intern(jitdata *jd, s4 *vars, int n, int stage,
901 for (i=0; i<n; ++i) {
905 if (vars[i] == UNUSED)
907 else if (javalocals) {
908 nr = RETADDR_FROM_JAVALOCAL(vars[i]);
909 printf("ret(L%03d)", nr);
912 printf("<INVALID INDEX:%d>", vars[i]);
916 show_variable_intern(jd, vars[i], stage);
921 void show_variable_array(jitdata *jd, s4 *vars, int n, int stage)
923 show_variable_array_intern(jd, vars, n, stage, false);
926 void show_javalocals_array(jitdata *jd, s4 *vars, int n, int stage)
928 show_variable_array_intern(jd, vars, n, stage, true);
931 void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
934 branch_target_t *table;
935 lookup_target_t *lookup;
936 constant_FMIref *fmiref;
940 /* get the opcode and the condition */
944 printf("%s ", icmd_table[opcode].name);
946 if (stage < SHOW_PARSE)
952 /* Print the condition for conditional instructions. */
954 /* XXX print condition from flags */
956 if (iptr->flags.bits & INS_FLAG_UNRESOLVED)
957 printf("(UNRESOLVED) ");
967 case ICMD_ARRAYLENGTH:
1034 /* binary/const INT */
1035 case ICMD_IADDCONST:
1036 case ICMD_ISUBCONST:
1037 case ICMD_IMULCONST:
1041 case ICMD_IANDCONST:
1043 case ICMD_IXORCONST:
1044 case ICMD_ISHLCONST:
1045 case ICMD_ISHRCONST:
1046 case ICMD_IUSHRCONST:
1047 case ICMD_LSHLCONST:
1048 case ICMD_LSHRCONST:
1049 case ICMD_LUSHRCONST:
1051 SHOW_INT_CONST(iptr->sx.val.i);
1055 /* ?ASTORECONST (trinary/const INT) */
1056 case ICMD_IASTORECONST:
1057 case ICMD_BASTORECONST:
1058 case ICMD_CASTORECONST:
1059 case ICMD_SASTORECONST:
1062 SHOW_INT_CONST(iptr->sx.s23.s3.constval);
1067 SHOW_INT_CONST(iptr->sx.val.i);
1071 /* binary/const LNG */
1072 case ICMD_LADDCONST:
1073 case ICMD_LSUBCONST:
1074 case ICMD_LMULCONST:
1078 case ICMD_LANDCONST:
1080 case ICMD_LXORCONST:
1082 SHOW_LNG_CONST(iptr->sx.val.l);
1086 /* trinary/const LNG (<= pointer size) */
1087 case ICMD_LASTORECONST:
1090 SHOW_ADR_CONST(iptr->sx.s23.s3.constval);
1095 SHOW_LNG_CONST(iptr->sx.val.l);
1101 SHOW_FLT_CONST(iptr->sx.val.f);
1107 SHOW_DBL_CONST(iptr->sx.val.d);
1113 if (iptr->flags.bits & INS_FLAG_CLASS) {
1114 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1115 SHOW_CLASSREF_OR_CLASSINFO(iptr->sx.val.c);
1117 else if (iptr->sx.val.anyptr == NULL) {
1121 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1122 SHOW_STRING(iptr->sx.val.stringconst);
1127 case ICMD_AASTORECONST:
1130 printf("%p ", (void*) iptr->sx.s23.s3.constval);
1133 case ICMD_GETFIELD: /* 1 -> 1 */
1134 case ICMD_PUTFIELD: /* 2 -> 0 */
1135 case ICMD_PUTSTATIC: /* 1 -> 0 */
1136 case ICMD_GETSTATIC: /* 0 -> 1 */
1137 case ICMD_PUTSTATICCONST: /* 0 -> 0 */
1138 case ICMD_PUTFIELDCONST: /* 1 -> 0 */
1139 if (opcode != ICMD_GETSTATIC && opcode != ICMD_PUTSTATICCONST) {
1141 if (opcode == ICMD_PUTFIELD) {
1145 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1148 if (opcode == ICMD_GETSTATIC || opcode == ICMD_GETFIELD) {
1154 SHOW_S1_LOCAL(iptr);
1155 SHOW_INT_CONST(iptr->sx.val.i);
1156 SHOW_DST_LOCAL(iptr);
1186 SHOW_S1_LOCAL(iptr);
1187 if (stage >= SHOW_STACK) {
1188 printf(" ---> L%03d", iptr->dst.block->nr);
1197 SHOW_S1_LOCAL(iptr);
1207 SHOW_DST_LOCAL(iptr);
1208 if (stage >= SHOW_STACK && iptr->sx.s23.s3.javaindex != UNUSED)
1209 printf(" (javaindex %d)", iptr->sx.s23.s3.javaindex);
1210 if (iptr->flags.bits & INS_FLAG_RETADDR) {
1211 printf(" (retaddr L%03d)", RETADDR_FROM_JAVALOCAL(iptr->sx.s23.s2.retaddrnr));
1223 case ICMD_ANEWARRAY:
1227 case ICMD_MULTIANEWARRAY:
1228 if (stage >= SHOW_STACK) {
1229 argp = iptr->sx.s23.s2.args;
1230 i = iptr->s1.argcount;
1232 SHOW_VARIABLE(*(argp++));
1236 printf("argcount=%d ", iptr->s1.argcount);
1241 case ICMD_CHECKCAST:
1244 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1248 case ICMD_INSTANCEOF:
1253 case ICMD_INLINE_START:
1254 case ICMD_INLINE_END:
1255 case ICMD_INLINE_BODY:
1256 #if defined(ENABLE_INLINING)
1258 insinfo_inline *ii = iptr->sx.s23.s3.inlineinfo;
1259 show_inline_info(jd, ii, opcode, stage);
1265 if (stage >= SHOW_STACK) {
1266 argp = iptr->sx.s23.s2.args;
1267 i = iptr->s1.argcount;
1269 if ((iptr->s1.argcount - 1 - i) == iptr->sx.s23.s3.bte->md->paramcount)
1270 printf(" pass-through: ");
1271 SHOW_VARIABLE(*(argp++));
1274 printf("%s ", iptr->sx.s23.s3.bte->cname);
1275 if (iptr->sx.s23.s3.bte->md->returntype.type != TYPE_VOID) {
1280 case ICMD_INVOKEVIRTUAL:
1281 case ICMD_INVOKESPECIAL:
1282 case ICMD_INVOKESTATIC:
1283 case ICMD_INVOKEINTERFACE:
1284 if (stage >= SHOW_STACK) {
1286 INSTRUCTION_GET_METHODDESC(iptr, md);
1287 argp = iptr->sx.s23.s2.args;
1288 i = iptr->s1.argcount;
1290 if ((iptr->s1.argcount - 1 - i) == md->paramcount)
1291 printf(" pass-through: ");
1292 SHOW_VARIABLE(*(argp++));
1295 INSTRUCTION_GET_METHODREF(iptr, fmiref);
1296 method_methodref_print(fmiref);
1297 if (fmiref->parseddesc.md->returntype.type != TYPE_VOID) {
1310 SHOW_INT_CONST(iptr->sx.val.i);
1311 SHOW_TARGET(iptr->dst);
1321 SHOW_LNG_CONST(iptr->sx.val.l);
1322 SHOW_TARGET(iptr->dst);
1326 SHOW_TARGET(iptr->dst);
1330 SHOW_TARGET(iptr->sx.s23.s3.jsrtarget);
1335 case ICMD_IFNONNULL:
1337 SHOW_TARGET(iptr->dst);
1340 case ICMD_IF_ICMPEQ:
1341 case ICMD_IF_ICMPNE:
1342 case ICMD_IF_ICMPLT:
1343 case ICMD_IF_ICMPGE:
1344 case ICMD_IF_ICMPGT:
1345 case ICMD_IF_ICMPLE:
1347 case ICMD_IF_LCMPEQ:
1348 case ICMD_IF_LCMPNE:
1349 case ICMD_IF_LCMPLT:
1350 case ICMD_IF_LCMPGE:
1351 case ICMD_IF_LCMPGT:
1352 case ICMD_IF_LCMPLE:
1354 case ICMD_IF_FCMPEQ:
1355 case ICMD_IF_FCMPNE:
1357 case ICMD_IF_FCMPL_LT:
1358 case ICMD_IF_FCMPL_GE:
1359 case ICMD_IF_FCMPL_GT:
1360 case ICMD_IF_FCMPL_LE:
1362 case ICMD_IF_FCMPG_LT:
1363 case ICMD_IF_FCMPG_GE:
1364 case ICMD_IF_FCMPG_GT:
1365 case ICMD_IF_FCMPG_LE:
1367 case ICMD_IF_DCMPEQ:
1368 case ICMD_IF_DCMPNE:
1370 case ICMD_IF_DCMPL_LT:
1371 case ICMD_IF_DCMPL_GE:
1372 case ICMD_IF_DCMPL_GT:
1373 case ICMD_IF_DCMPL_LE:
1375 case ICMD_IF_DCMPG_LT:
1376 case ICMD_IF_DCMPG_GE:
1377 case ICMD_IF_DCMPG_GT:
1378 case ICMD_IF_DCMPG_LE:
1380 case ICMD_IF_ACMPEQ:
1381 case ICMD_IF_ACMPNE:
1384 SHOW_TARGET(iptr->dst);
1387 case ICMD_TABLESWITCH:
1389 table = iptr->dst.table;
1391 i = iptr->sx.s23.s3.tablehigh - iptr->sx.s23.s2.tablelow + 1;
1393 printf("high=%d low=%d count=%d\n", iptr->sx.s23.s3.tablehigh, iptr->sx.s23.s2.tablelow, i);
1395 printf("\t\t%d --> ", (int) (table - iptr->dst.table));
1396 printf("L%03d\n", table->block->nr);
1402 case ICMD_LOOKUPSWITCH:
1405 printf("count=%d, default=L%03d\n",
1406 iptr->sx.s23.s2.lookupcount,
1407 iptr->sx.s23.s3.lookupdefault.block->nr);
1409 lookup = iptr->dst.lookup;
1410 i = iptr->sx.s23.s2.lookupcount;
1413 printf("\t\t%d --> L%03d\n",
1415 lookup->target.block->nr);
1430 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1431 /* XXX this needs more work */
1433 unresolved_class_debug_dump(iptr->sx.s23.s2.uc, stdout);
1446 #endif /* !defined(NDEBUG) */
1448 /* Debug output filtering */
1450 #if defined(ENABLE_DEBUG_FILTER)
1452 #if !defined(ENABLE_THREADS)
1453 u2 _no_threads_filterverbosecallctr[2] = { 0, 0 };
1456 struct show_filter {
1457 /* Boolean indicating if filter is enabled. */
1459 /* Regular expression the method name is matched against */
1461 /* Flag set on m->filtermatches if regex matches */
1465 typedef struct show_filter show_filter_t;
1467 #define SHOW_FILTERS_SIZE 3
1469 /* Array of filters applyed on a method */
1470 static struct show_filter show_filters[SHOW_FILTERS_SIZE];
1472 static void show_filter_init(show_filter_t *cf, const char *str, u1 flag, u1 default_flag, const char *description) {
1477 err = regcomp(&cf->regex, str, REG_EXTENDED | REG_NOSUB);
1479 regerror(err, &cf->regex, err_buf, sizeof(err_buf));
1481 "Invalid value given for %s: `%s' (%s).",
1482 description, str, err_buf
1488 cf->flag = default_flag;
1493 void show_filters_init(void) {
1497 opt_filter_verbosecall_include,
1498 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1499 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1500 "verbose call include filter"
1505 opt_filter_verbosecall_exclude,
1506 SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE,
1508 "verbose call exclude filter"
1513 opt_filter_show_method,
1514 SHOW_FILTER_FLAG_SHOW_METHOD,
1515 SHOW_FILTER_FLAG_SHOW_METHOD,
1516 "show method filter"
1522 (Pseudo)State machine:
1524 States are INITIAL, INCLUDE1, INCLUDE2, ..., EXCLUDE1, ..., EXCLUDE2, ...
1527 Enter Include Include
1529 | | Enter Enter Enter | | Enter | |
1530 | | Include Include Exclude | | Exclude | |
1531 | v ---------> ----------> ----------> | v ----------> | v
1532 INITIAL INCLUDE1 INCLUDE2 EXCLUDE1 EXCLUDE2
1533 | ^ <--------- <---------- <---------- | ^ <---------- | ^
1534 | | Exit Exit Exit | | Exit | |
1535 | | Include Include Exclude | | Exclude | |
1538 Exclude Include Include
1540 Verbose call scope is active if we are in a INCLUDE state.
1544 INITIAL: ctr[0] == 0, ctr[1] == 0
1545 INCLUDEN: ctr[1] == N, ctr[1] == 0
1546 EXCLUDEN: ctr[1] == N
1549 void show_filters_apply(methodinfo *m) {
1556 /* compose full name of method */
1559 utf_bytes(m->class->name) +
1561 utf_bytes(m->name) +
1562 utf_bytes(m->descriptor) +
1565 dumpsize = dump_size(); /* allocate memory */
1567 method_name = DMNEW(char, len);
1569 utf_cat_classname(method_name, m->class->name);
1570 strcat(method_name, ".");
1571 utf_cat(method_name, m->name);
1572 utf_cat(method_name, m->descriptor);
1574 /* reset all flags */
1576 m->filtermatches = 0;
1578 for (i = 0; i < SHOW_FILTERS_SIZE; ++i) {
1579 if (show_filters[i].enabled) {
1581 res = regexec(&show_filters[i].regex, method_name, 0, NULL, 0);
1584 m->filtermatches |= show_filters[i].flag;
1587 /* Default is to show all */
1588 m->filtermatches |= show_filters[i].flag;
1592 /* release memory */
1594 dump_release(dumpsize);
1598 #define STATE_IS_INITIAL() ((FILTERVERBOSECALLCTR[0] == 0) && (FILTERVERBOSECALLCTR[1] == 0))
1599 #define STATE_IS_INCLUDE() ((FILTERVERBOSECALLCTR[0] > 0) && (FILTERVERBOSECALLCTR[1] == 0))
1600 #define STATE_IS_EXCLUDE() (FILTERVERBOSECALLCTR[1] > 0)
1601 #define EVENT_INCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE)
1602 #define EVENT_EXCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE)
1603 #define TRANSITION_NEXT_INCLUDE() ++FILTERVERBOSECALLCTR[0]
1604 #define TRANSITION_PREV_INCLUDE() --FILTERVERBOSECALLCTR[0]
1605 #define TRANSITION_NEXT_EXCLUDE() ++FILTERVERBOSECALLCTR[1]
1606 #define TRANSITION_PREV_EXCLUDE() --FILTERVERBOSECALLCTR[1]
1610 if (STATE_IS_INITIAL()) printf("<INITIAL>\n");
1611 else if (STATE_IS_INCLUDE()) printf("<INCLUDE %hd>\n", FILTERVERBOSECALLCTR[0]);
1612 else if (STATE_IS_EXCLUDE()) printf("<EXCLUDE %hd>\n", FILTERVERBOSECALLCTR[1]);
1616 int show_filters_test_verbosecall_enter(methodinfo *m) {
1620 if (STATE_IS_INITIAL()) {
1621 if (EVENT_INCLUDE()) {
1622 TRANSITION_NEXT_INCLUDE();
1624 } else if (STATE_IS_INCLUDE()) {
1625 if (EVENT_EXCLUDE()) {
1626 TRANSITION_NEXT_EXCLUDE();
1627 /* just entered exclude, show this method */
1629 } else if (EVENT_INCLUDE()) {
1630 TRANSITION_NEXT_INCLUDE();
1632 } else if (STATE_IS_EXCLUDE()) {
1633 if (EVENT_EXCLUDE()) {
1634 TRANSITION_NEXT_EXCLUDE();
1638 return STATE_IS_INCLUDE() || force_show;
1641 int show_filters_test_verbosecall_exit(methodinfo *m) {
1646 if (STATE_IS_INCLUDE()) {
1647 if (EVENT_INCLUDE()) {
1648 TRANSITION_PREV_INCLUDE();
1649 /* just entered initial, show this method */
1650 if (STATE_IS_INITIAL()) force_show = 1;
1652 } else if (STATE_IS_EXCLUDE()) {
1653 if (EVENT_EXCLUDE()) {
1654 TRANSITION_PREV_EXCLUDE();
1659 return STATE_IS_INCLUDE() || force_show;
1666 * These are local overrides for various environment variables in Emacs.
1667 * Please do not remove this and leave it at the end of the file, where
1668 * Emacs will automagically detect them.
1669 * ---------------------------------------------------------------------
1672 * indent-tabs-mode: t
1676 * vim:noexpandtab:sw=4:ts=4: