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"
44 #include "vm/jit/abi.h"
45 #include "vm/jit/jit.h"
46 #include "vm/jit/show.h"
47 #include "vm/jit/disass.h"
48 #include "vm/jit/stack.h"
49 #include "vm/jit/parse.h"
51 #include "vmcore/options.h"
53 #if defined(ENABLE_DEBUG_FILTER)
54 # include <sys/types.h>
56 # if defined(ENABLE_THREADS)
57 # include "threads/native/threads.h"
59 # include "threads/none/threads.h"
63 /* global variables ***********************************************************/
65 #if defined(ENABLE_THREADS) && !defined(NDEBUG)
66 static java_objectheader *show_global_lock;
70 /* prototypes *****************************************************************/
73 static void show_variable_intern(jitdata *jd, s4 index, int stage);
77 /* show_init *******************************************************************
79 Initialized the show subsystem (called by jit_init).
81 *******************************************************************************/
86 #if defined(ENABLE_THREADS)
87 /* initialize the show lock */
89 show_global_lock = NEW(java_objectheader);
91 LOCK_INIT_OBJECT_LOCK(show_global_lock);
94 #if defined(ENABLE_DEBUG_FILTER)
106 char *show_jit_type_names[] = {
117 char show_jit_type_letters[] = {
131 /* show_method *****************************************************************
133 Print the intermediate representation of a method.
135 NOTE: Currently this function may only be called after register allocation!
137 *******************************************************************************/
140 void show_method(jitdata *jd, int stage)
147 basicblock *lastbptr;
151 #if defined(ENABLE_DISASSEMBLER)
155 /* get required compiler data */
162 /* We need to enter a lock here, since the binutils disassembler
163 is not reentrant-able and we could not read functions printed
166 LOCK_MONITOR_ENTER(show_global_lock);
168 #if defined(ENABLE_INTRP)
170 irstage = SHOW_PARSE;
175 /* get the last basic block */
177 for (lastbptr = jd->basicblocks; lastbptr->next != NULL; lastbptr = lastbptr->next);
183 if (jd->isleafmethod)
184 printf("LEAFMETHOD\n");
186 printf("\nBasic blocks: %d\n", jd->basicblockcount);
187 if (stage >= SHOW_CODE) {
188 printf("Code length: %d\n", (lastbptr->mpc - jd->basicblocks[0].mpc));
189 printf("Data length: %d\n", cd->dseglen);
190 printf("Stub length: %d\n", (s4) (code->mcodelength -
191 ((ptrint) cd->dseglen + lastbptr->mpc)));
193 printf("Variables: %d (%d used)\n", jd->varcount, jd->vartop);
194 if (stage >= SHOW_STACK)
195 printf("Max interfaces: %d\n", jd->maxinterfaces);
196 printf("Max locals: %d\n", jd->maxlocals);
197 printf("Max stack: %d\n", m->maxstack);
198 printf("Linenumbers: %d\n", m->linenumbercount);
199 printf("Branch to entry: %s\n", (jd->branchtoentry) ? "yes" : "no");
200 printf("Branch to end: %s\n", (jd->branchtoend) ? "yes" : "no");
201 if (stage >= SHOW_STACK) {
202 printf("Number of RETURNs: %d", jd->returncount);
203 if (jd->returncount == 1)
204 printf(" (block L%03d)", jd->returnblock->nr);
208 if (stage >= SHOW_PARSE) {
209 printf("Exceptions (Number: %d):\n", jd->exceptiontablelength);
210 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
211 printf(" L%03d ... ", ex->start->nr );
212 printf("L%03d = ", ex->end->nr);
213 printf("L%03d", ex->handler->nr);
214 printf(" (catchtype: ");
215 if (ex->catchtype.any)
216 if (IS_CLASSREF(ex->catchtype))
217 class_classref_print(ex->catchtype.ref);
219 class_print(ex->catchtype.cls);
226 if (irstage >= SHOW_PARSE && rd && jd->localcount > 0) {
227 printf("Local Table:\n");
228 for (i = 0; i < jd->localcount; i++) {
231 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
232 # if defined(ENABLE_INTRP)
235 printf(" (%s) ", show_jit_type_names[VAR(i)->type]);
236 if (irstage >= SHOW_REGS)
237 show_allocation(VAR(i)->type, VAR(i)->flags, VAR(i)->vv.regoff);
239 # if defined(ENABLE_INTRP)
242 #endif /* defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER) */
247 if (jd->maxlocals > 0 && jd->local_map != NULL) {
248 printf("Local Map:\n");
250 for (j = 0; j < jd->maxlocals; j++) {
254 for (i = 0; i < 5; i++) {
255 printf(" %5s ",show_jit_type_names[i]);
256 for (j = 0; j < jd->maxlocals; j++) {
257 if (jd->local_map[j*5+i] == UNUSED)
260 printf("%4i ",jd->local_map[j*5+i]);
267 if (jd->maxinterfaces > 0 && jd->interface_map && irstage >= SHOW_STACK) {
269 interface_info *mapptr = jd->interface_map;
271 /* look if there exist any INOUTS */
272 for (i = 0; (i < (5 * jd->maxinterfaces)) && !exist; i++, mapptr++)
273 exist = (mapptr->flags != UNUSED);
276 printf("Interface Table: (In/Outvars)\n");
278 for (j = 0; j < jd->maxinterfaces; j++) {
283 for (i = 0; i < 5; i++) {
284 printf(" %5s ",show_jit_type_names[i]);
285 for (j = 0; j < jd->maxinterfaces; j++) {
286 s4 flags = jd->interface_map[j*5+i].flags;
287 s4 regoff = jd->interface_map[j*5+i].regoff;
293 if (irstage >= SHOW_REGS) {
294 if (flags & SAVEDVAR) {
295 if (flags & INMEMORY)
301 if (flags & INMEMORY)
306 printf("%c%03d(", ch, regoff);
307 show_allocation(i, flags, regoff);
311 if (flags & SAVEDVAR)
324 if (rd->memuse && irstage >= SHOW_REGS) {
328 printf("Stack slots: (memuse=%d", rd->memuse);
329 if (irstage >= SHOW_CODE) {
330 printf(", stackframesize=%d", cd->stackframesize);
331 max = cd->stackframesize;
334 for (i = 0; i < max; ++i) {
335 #if defined(HAS_4BYTE_STACKSLOT)
336 printf(" M%02d = 0x%02x(sp): ", i, i * 4);
338 printf(" M%02d = 0x%02x(sp): ", i, i * 8);
340 for (j = 0; j < jd->vartop; ++j) {
342 if ((v->flags & INMEMORY) && (v->vv.regoff == i)) {
343 show_variable(jd, j, irstage);
354 #if defined(ENABLE_REPLACEMENT)
355 if (code->rplpoints) {
356 printf("Replacement Points:\n");
357 replace_show_replacement_points(code);
360 #endif /* defined(ENABLE_REPLACEMENT) */
362 #if defined(ENABLE_DISASSEMBLER)
363 /* show code before first basic block */
365 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
366 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen);
368 for (; pc < (u1 *) ((ptrint) code->mcode + cd->dseglen + jd->basicblocks[0].mpc);)
375 /* show code of all basic blocks */
377 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next)
378 show_basicblock(jd, bptr, stage);
380 #if defined(ENABLE_DISASSEMBLER)
381 /* show stubs code */
383 if (stage >= SHOW_CODE && opt_showdisassemble && opt_showexceptionstubs) {
384 printf("\nStubs code:\n");
385 printf("Length: %d\n\n", (s4) (code->mcodelength -
386 ((ptrint) cd->dseglen + lastbptr->mpc)));
388 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen + lastbptr->mpc);
390 for (; (ptrint) pc < ((ptrint) code->mcode + code->mcodelength);)
397 LOCK_MONITOR_EXIT(show_global_lock);
399 /* finally flush the output */
403 #endif /* !defined(NDEBUG) */
406 #if !defined(NDEBUG) && defined(ENABLE_INLINING)
407 static void show_inline_info(jitdata *jd, insinfo_inline *ii, s4 opcode, s4 stage)
412 printf("(pt %d+%d+%d st ",
413 ii->throughcount - (ii->stackvarscount - ii->paramcount),
414 ii->stackvarscount - ii->paramcount,
416 show_variable_array(jd, ii->stackvars, ii->stackvarscount, stage);
418 if (opcode == ICMD_INLINE_START || opcode == ICMD_INLINE_END) {
420 jl = (opcode == ICMD_INLINE_START) ? ii->javalocals_start : ii->javalocals_end;
421 n = (opcode == ICMD_INLINE_START) ? ii->method->maxlocals : ii->outer->maxlocals;
422 show_javalocals_array(jd, jl, n, stage);
429 method_print(ii->outer);
433 method_print(ii->method);
435 #endif /* !defined(NDEBUG) && defined(ENABLE_INLINING) */
438 /* show_basicblock *************************************************************
440 Print the intermediate representation of a basic block.
442 NOTE: Currently this function may only be called after register allocation!
444 *******************************************************************************/
447 void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
455 #if defined(ENABLE_DISASSEMBLER)
456 methodinfo *m; /* this is only a dummy */
459 s4 currentlinenumber;
462 /* get required compiler data */
467 if (bptr->flags != BBDELETED) {
468 #if defined(ENABLE_INTRP)
471 irstage = SHOW_PARSE;
476 deadcode = (bptr->flags < BBREACHED);
480 printf("======== %sL%03d ======== %s(flags: %d, bitflags: %01x, next: %d, type: ",
481 #if defined(ENABLE_REPLACEMENT)
482 (bptr->bitflags & BBFLAG_REPLACEMENT) ? "<REPLACE> " :
486 (deadcode && stage >= SHOW_STACK) ? "DEADCODE! " : "",
487 bptr->flags, bptr->bitflags,
488 (bptr->next) ? (bptr->next->nr) : -1);
490 switch (bptr->type) {
502 printf(", icount: %d", bptr->icount);
504 if (irstage >= SHOW_CFG) {
505 printf(", preds: %d [ ", bptr->predecessorcount);
507 for (i = 0; i < bptr->predecessorcount; i++)
508 printf("%d ", bptr->predecessors[i]->nr);
516 printf(" (clone of L%03d)", bptr->original->nr);
518 basicblock *b = bptr->copied_to;
520 printf(" (copied to ");
521 for (; b; b = b->copied_to)
522 printf("L%03d ", b->nr);
529 if (irstage >= SHOW_STACK) {
531 show_variable_array(jd, bptr->invars, bptr->indepth, irstage);
532 printf(" javalocals: ");
533 show_javalocals_array(jd, bptr->javalocals, bptr->method->maxlocals, irstage);
537 #if defined(ENABLE_INLINING)
538 if (bptr->inlineinfo) {
539 printf("inlineinfo: ");
540 show_inline_info(jd, bptr->inlineinfo, -1, irstage);
543 #endif /* defined(ENABLE_INLINING) */
547 for (i = 0; i < bptr->icount; i++, iptr++) {
548 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
550 show_icmd(jd, iptr, deadcode, irstage);
554 if (irstage >= SHOW_STACK) {
556 show_variable_array(jd, bptr->outvars, bptr->outdepth, irstage);
560 #if defined(ENABLE_DISASSEMBLER)
561 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd) &&
565 pc = (u1 *) (code->mcode + cd->dseglen + bptr->mpc);
568 if (bptr->next != NULL) {
569 for (; pc < (u1 *) (code->mcode + cd->dseglen + bptr->next->mpc);) {
571 dseg_get_linenumber_from_pc(&m, code->entrypoint, pc);
573 if (currentlinenumber != linenumber) {
574 linenumber = currentlinenumber;
575 printf("%4d:\n", linenumber);
582 for (; pc < (u1 *) (code->mcode + code->mcodelength);) {
584 dseg_get_linenumber_from_pc(&m, code->entrypoint, pc);
586 if (currentlinenumber != linenumber) {
587 linenumber = currentlinenumber;
588 printf("%4d:\n", linenumber);
599 #endif /* !defined(NDEBUG) */
602 /* show_icmd *******************************************************************
604 Print the intermediate representation of an instruction.
606 NOTE: Currently this function may only be called after register allocation!
608 *******************************************************************************/
612 #define SHOW_TARGET(target) \
613 if (stage >= SHOW_PARSE) { \
614 printf("--> L%03d ", (target).block->nr); \
617 printf("--> insindex %d ", (target).insindex); \
620 #define SHOW_INT_CONST(val) \
621 if (stage >= SHOW_PARSE) { \
622 printf("%d (0x%08x) ", (val), (val)); \
628 #if SIZEOF_VOID_P == 4
629 #define SHOW_LNG_CONST(val) \
630 if (stage >= SHOW_PARSE) \
631 printf("%lld (0x%016llx) ", (val), (val)); \
635 #define SHOW_LNG_CONST(val) \
636 if (stage >= SHOW_PARSE) \
637 printf("%ld (0x%016lx) ", (val), (val)); \
642 #if SIZEOF_VOID_P == 4
643 #define SHOW_ADR_CONST(val) \
644 if (stage >= SHOW_PARSE) \
645 printf("0x%08x ", (ptrint) (val)); \
649 #define SHOW_ADR_CONST(val) \
650 if (stage >= SHOW_PARSE) \
651 printf("0x%016lx ", (ptrint) (val)); \
656 #define SHOW_FLT_CONST(val) \
657 if (stage >= SHOW_PARSE) { \
660 printf("%g (0x%08x) ", (val), v.i); \
666 #if SIZEOF_VOID_P == 4
667 #define SHOW_DBL_CONST(val) \
668 if (stage >= SHOW_PARSE) { \
671 printf("%g (0x%016llx) ", (val), v.l); \
676 #define SHOW_DBL_CONST(val) \
677 if (stage >= SHOW_PARSE) { \
680 printf("%g (0x%016lx) ", (val), v.l); \
686 #define SHOW_INDEX(index) \
687 if (stage >= SHOW_PARSE) { \
688 printf("%d ", index); \
694 #define SHOW_STRING(val) \
695 if (stage >= SHOW_PARSE) { \
697 utf_display_printable_ascii( \
698 javastring_toutf((java_objectheader *)(val), false)); \
705 #define SHOW_CLASSREF_OR_CLASSINFO(c) \
706 if (stage >= SHOW_PARSE) { \
707 if (IS_CLASSREF(c)) \
708 class_classref_print(c.ref); \
710 class_print(c.cls); \
717 #define SHOW_FIELD(fmiref) \
718 if (stage >= SHOW_PARSE) { \
719 field_fieldref_print(fmiref); \
726 #define SHOW_VARIABLE(v) \
727 show_variable(jd, (v), stage)
729 #define SHOW_S1(iptr) \
730 if (stage >= SHOW_STACK) { \
731 SHOW_VARIABLE(iptr->s1.varindex); \
734 #define SHOW_S2(iptr) \
735 if (stage >= SHOW_STACK) { \
736 SHOW_VARIABLE(iptr->sx.s23.s2.varindex); \
739 #define SHOW_S3(iptr) \
740 if (stage >= SHOW_STACK) { \
741 SHOW_VARIABLE(iptr->sx.s23.s3.varindex); \
744 #define SHOW_DST(iptr) \
745 if (stage >= SHOW_STACK) { \
747 SHOW_VARIABLE(iptr->dst.varindex); \
750 #define SHOW_S1_LOCAL(iptr) \
751 if (stage >= SHOW_STACK) { \
752 printf("L%d ", iptr->s1.varindex); \
755 printf("JavaL%d ", iptr->s1.varindex); \
758 #define SHOW_DST_LOCAL(iptr) \
759 if (stage >= SHOW_STACK) { \
760 printf("=> L%d ", iptr->dst.varindex); \
763 printf("=> JavaL%d ", iptr->dst.varindex); \
766 void show_allocation(s4 type, s4 flags, s4 regoff)
768 if (type == TYPE_RET) {
773 if (flags & INMEMORY) {
774 printf("M%02d", regoff);
778 #ifdef HAS_ADDRESS_REGISTER_FILE
779 if (type == TYPE_ADR) {
780 printf("R%02d", regoff);
785 if (IS_FLT_DBL_TYPE(type)) {
786 printf("F%02d", regoff);
790 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
791 if (IS_2_WORD_TYPE(type)) {
792 # if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
793 # if defined(ENABLE_INTRP)
795 printf("%3d/%3d", GET_LOW_REG(regoff),
796 GET_HIGH_REG(regoff));
799 printf("%3s/%3s", abi_registers_integer_name[GET_LOW_REG(regoff)],
800 abi_registers_integer_name[GET_HIGH_REG(regoff)]);
802 printf("%3d/%3d", GET_LOW_REG(regoff),
803 GET_HIGH_REG(regoff));
807 #endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
809 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
810 # if defined(ENABLE_INTRP)
812 printf("%3d", regoff);
815 printf("%3s", abi_registers_integer_name[regoff]);
817 printf("%3d", regoff);
821 void show_variable(jitdata *jd, s4 index, int stage)
823 show_variable_intern(jd, index, stage);
827 static void show_variable_intern(jitdata *jd, s4 index, int stage)
833 if (index < 0 || index >= jd->vartop) {
834 printf("<INVALID INDEX:%d>", index);
841 case TYPE_INT: type = 'i'; break;
842 case TYPE_LNG: type = 'l'; break;
843 case TYPE_FLT: type = 'f'; break;
844 case TYPE_DBL: type = 'd'; break;
845 case TYPE_ADR: type = 'a'; break;
846 case TYPE_RET: type = 'r'; break;
850 if (index < jd->localcount) {
852 if (v->flags & (PREALLOC | INOUT))
853 printf("<INVALID FLAGS!>");
856 if (v->flags & PREALLOC) {
858 if (v->flags & INOUT) {
859 /* PREALLOC is used to avoid allocation of TYPE_RET */
860 if (v->type == TYPE_RET)
863 printf("<INVALID FLAGS!>");
866 else if (v->flags & INOUT)
872 printf("%c%c%d", kind, type, index);
874 if (v->flags & SAVEDVAR)
877 if (stage >= SHOW_REGS || (v->flags & PREALLOC)) {
879 show_allocation(v->type, v->flags, v->vv.regoff);
883 if (v->type == TYPE_RET && (v->flags & PREALLOC)) {
884 printf("(L%03d)", v->vv.retaddr->nr);
888 static void show_variable_array_intern(jitdata *jd, s4 *vars, int n, int stage,
900 for (i=0; i<n; ++i) {
904 if (vars[i] == UNUSED)
906 else if (javalocals) {
907 nr = RETADDR_FROM_JAVALOCAL(vars[i]);
908 printf("ret(L%03d)", nr);
911 printf("<INVALID INDEX:%d>", vars[i]);
915 show_variable_intern(jd, vars[i], stage);
920 void show_variable_array(jitdata *jd, s4 *vars, int n, int stage)
922 show_variable_array_intern(jd, vars, n, stage, false);
925 void show_javalocals_array(jitdata *jd, s4 *vars, int n, int stage)
927 show_variable_array_intern(jd, vars, n, stage, true);
930 void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
933 branch_target_t *table;
934 lookup_target_t *lookup;
935 constant_FMIref *fmiref;
939 /* get the opcode and the condition */
943 printf("%s ", icmd_table[opcode].name);
945 if (stage < SHOW_PARSE)
951 /* Print the condition for conditional instructions. */
953 /* XXX print condition from flags */
955 if (iptr->flags.bits & INS_FLAG_UNRESOLVED)
956 printf("(UNRESOLVED) ");
966 case ICMD_ARRAYLENGTH:
1033 /* binary/const INT */
1034 case ICMD_IADDCONST:
1035 case ICMD_ISUBCONST:
1036 case ICMD_IMULCONST:
1040 case ICMD_IANDCONST:
1042 case ICMD_IXORCONST:
1043 case ICMD_ISHLCONST:
1044 case ICMD_ISHRCONST:
1045 case ICMD_IUSHRCONST:
1046 case ICMD_LSHLCONST:
1047 case ICMD_LSHRCONST:
1048 case ICMD_LUSHRCONST:
1050 SHOW_INT_CONST(iptr->sx.val.i);
1054 /* ?ASTORECONST (trinary/const INT) */
1055 case ICMD_IASTORECONST:
1056 case ICMD_BASTORECONST:
1057 case ICMD_CASTORECONST:
1058 case ICMD_SASTORECONST:
1061 SHOW_INT_CONST(iptr->sx.s23.s3.constval);
1066 SHOW_INT_CONST(iptr->sx.val.i);
1070 /* binary/const LNG */
1071 case ICMD_LADDCONST:
1072 case ICMD_LSUBCONST:
1073 case ICMD_LMULCONST:
1077 case ICMD_LANDCONST:
1079 case ICMD_LXORCONST:
1081 SHOW_LNG_CONST(iptr->sx.val.l);
1085 /* trinary/const LNG (<= pointer size) */
1086 case ICMD_LASTORECONST:
1089 SHOW_ADR_CONST(iptr->sx.s23.s3.constval);
1094 SHOW_LNG_CONST(iptr->sx.val.l);
1100 SHOW_FLT_CONST(iptr->sx.val.f);
1106 SHOW_DBL_CONST(iptr->sx.val.d);
1112 if (iptr->flags.bits & INS_FLAG_CLASS) {
1113 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1114 SHOW_CLASSREF_OR_CLASSINFO(iptr->sx.val.c);
1116 else if (iptr->sx.val.anyptr == NULL) {
1120 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1121 SHOW_STRING(iptr->sx.val.stringconst);
1126 case ICMD_AASTORECONST:
1129 printf("%p ", (void*) iptr->sx.s23.s3.constval);
1132 case ICMD_GETFIELD: /* 1 -> 1 */
1133 case ICMD_PUTFIELD: /* 2 -> 0 */
1134 case ICMD_PUTSTATIC: /* 1 -> 0 */
1135 case ICMD_GETSTATIC: /* 0 -> 1 */
1136 case ICMD_PUTSTATICCONST: /* 0 -> 0 */
1137 case ICMD_PUTFIELDCONST: /* 1 -> 0 */
1138 if (opcode != ICMD_GETSTATIC && opcode != ICMD_PUTSTATICCONST) {
1140 if (opcode == ICMD_PUTFIELD) {
1144 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1147 if (opcode == ICMD_GETSTATIC || opcode == ICMD_GETFIELD) {
1153 SHOW_S1_LOCAL(iptr);
1154 SHOW_INT_CONST(iptr->sx.val.i);
1155 SHOW_DST_LOCAL(iptr);
1185 SHOW_S1_LOCAL(iptr);
1186 if (stage >= SHOW_STACK) {
1187 printf(" ---> L%03d", iptr->dst.block->nr);
1196 SHOW_S1_LOCAL(iptr);
1206 SHOW_DST_LOCAL(iptr);
1207 if (stage >= SHOW_STACK && iptr->sx.s23.s3.javaindex != UNUSED)
1208 printf(" (javaindex %d)", iptr->sx.s23.s3.javaindex);
1209 if (iptr->flags.bits & INS_FLAG_RETADDR) {
1210 printf(" (retaddr L%03d)", RETADDR_FROM_JAVALOCAL(iptr->sx.s23.s2.retaddrnr));
1222 case ICMD_ANEWARRAY:
1226 case ICMD_MULTIANEWARRAY:
1227 if (stage >= SHOW_STACK) {
1228 argp = iptr->sx.s23.s2.args;
1229 i = iptr->s1.argcount;
1231 SHOW_VARIABLE(*(argp++));
1235 printf("argcount=%d ", iptr->s1.argcount);
1240 case ICMD_CHECKCAST:
1243 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1247 case ICMD_INSTANCEOF:
1252 case ICMD_INLINE_START:
1253 case ICMD_INLINE_END:
1254 case ICMD_INLINE_BODY:
1255 #if defined(ENABLE_INLINING)
1257 insinfo_inline *ii = iptr->sx.s23.s3.inlineinfo;
1258 show_inline_info(jd, ii, opcode, stage);
1264 if (stage >= SHOW_STACK) {
1265 argp = iptr->sx.s23.s2.args;
1266 i = iptr->s1.argcount;
1268 if ((iptr->s1.argcount - 1 - i) == iptr->sx.s23.s3.bte->md->paramcount)
1269 printf(" pass-through: ");
1270 SHOW_VARIABLE(*(argp++));
1273 printf("%s ", iptr->sx.s23.s3.bte->cname);
1274 if (iptr->sx.s23.s3.bte->md->returntype.type != TYPE_VOID) {
1279 case ICMD_INVOKEVIRTUAL:
1280 case ICMD_INVOKESPECIAL:
1281 case ICMD_INVOKESTATIC:
1282 case ICMD_INVOKEINTERFACE:
1283 if (stage >= SHOW_STACK) {
1285 INSTRUCTION_GET_METHODDESC(iptr, md);
1286 argp = iptr->sx.s23.s2.args;
1287 i = iptr->s1.argcount;
1289 if ((iptr->s1.argcount - 1 - i) == md->paramcount)
1290 printf(" pass-through: ");
1291 SHOW_VARIABLE(*(argp++));
1294 INSTRUCTION_GET_METHODREF(iptr, fmiref);
1295 method_methodref_print(fmiref);
1296 if (fmiref->parseddesc.md->returntype.type != TYPE_VOID) {
1309 SHOW_INT_CONST(iptr->sx.val.i);
1310 SHOW_TARGET(iptr->dst);
1320 SHOW_LNG_CONST(iptr->sx.val.l);
1321 SHOW_TARGET(iptr->dst);
1325 SHOW_TARGET(iptr->dst);
1329 SHOW_TARGET(iptr->sx.s23.s3.jsrtarget);
1334 case ICMD_IFNONNULL:
1336 SHOW_TARGET(iptr->dst);
1339 case ICMD_IF_ICMPEQ:
1340 case ICMD_IF_ICMPNE:
1341 case ICMD_IF_ICMPLT:
1342 case ICMD_IF_ICMPGE:
1343 case ICMD_IF_ICMPGT:
1344 case ICMD_IF_ICMPLE:
1346 case ICMD_IF_LCMPEQ:
1347 case ICMD_IF_LCMPNE:
1348 case ICMD_IF_LCMPLT:
1349 case ICMD_IF_LCMPGE:
1350 case ICMD_IF_LCMPGT:
1351 case ICMD_IF_LCMPLE:
1353 case ICMD_IF_FCMPEQ:
1354 case ICMD_IF_FCMPNE:
1356 case ICMD_IF_FCMPL_LT:
1357 case ICMD_IF_FCMPL_GE:
1358 case ICMD_IF_FCMPL_GT:
1359 case ICMD_IF_FCMPL_LE:
1361 case ICMD_IF_FCMPG_LT:
1362 case ICMD_IF_FCMPG_GE:
1363 case ICMD_IF_FCMPG_GT:
1364 case ICMD_IF_FCMPG_LE:
1366 case ICMD_IF_DCMPEQ:
1367 case ICMD_IF_DCMPNE:
1369 case ICMD_IF_DCMPL_LT:
1370 case ICMD_IF_DCMPL_GE:
1371 case ICMD_IF_DCMPL_GT:
1372 case ICMD_IF_DCMPL_LE:
1374 case ICMD_IF_DCMPG_LT:
1375 case ICMD_IF_DCMPG_GE:
1376 case ICMD_IF_DCMPG_GT:
1377 case ICMD_IF_DCMPG_LE:
1379 case ICMD_IF_ACMPEQ:
1380 case ICMD_IF_ACMPNE:
1383 SHOW_TARGET(iptr->dst);
1386 case ICMD_TABLESWITCH:
1388 table = iptr->dst.table;
1390 i = iptr->sx.s23.s3.tablehigh - iptr->sx.s23.s2.tablelow + 1;
1392 printf("high=%d low=%d count=%d\n", iptr->sx.s23.s3.tablehigh, iptr->sx.s23.s2.tablelow, i);
1394 printf("\t\t%d --> ", (int) (table - iptr->dst.table));
1395 printf("L%03d\n", table->block->nr);
1401 case ICMD_LOOKUPSWITCH:
1404 printf("count=%d, default=L%03d\n",
1405 iptr->sx.s23.s2.lookupcount,
1406 iptr->sx.s23.s3.lookupdefault.block->nr);
1408 lookup = iptr->dst.lookup;
1409 i = iptr->sx.s23.s2.lookupcount;
1412 printf("\t\t%d --> L%03d\n",
1414 lookup->target.block->nr);
1429 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1430 /* XXX this needs more work */
1432 unresolved_class_debug_dump(iptr->sx.s23.s2.uc, stdout);
1445 #endif /* !defined(NDEBUG) */
1447 /* Debug output filtering */
1449 #if defined(ENABLE_DEBUG_FILTER)
1451 #if !defined(ENABLE_THREADS)
1452 u4 _no_threads_filterverbosecallctr[2] = { 0, 0 };
1455 struct show_filter {
1456 /* Boolean indicating if filter is enabled. */
1458 /* Regular expression the method name is matched against */
1460 /* Flag set on m->filtermatches if regex matches */
1464 typedef struct show_filter show_filter_t;
1466 #define SHOW_FILTERS_SIZE 3
1468 /* Array of filters applyed on a method */
1469 static struct show_filter show_filters[SHOW_FILTERS_SIZE];
1471 static void show_filter_init(show_filter_t *cf, const char *str, u1 flag, u1 default_flag, const char *description) {
1476 err = regcomp(&cf->regex, str, REG_EXTENDED | REG_NOSUB);
1478 regerror(err, &cf->regex, err_buf, sizeof(err_buf));
1480 "Invalid value given for %s: `%s' (%s).",
1481 description, str, err_buf
1487 cf->flag = default_flag;
1492 void show_filters_init(void) {
1496 opt_filter_verbosecall_include,
1497 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1498 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1499 "verbose call include filter"
1504 opt_filter_verbosecall_exclude,
1505 SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE,
1507 "verbose call exclude filter"
1512 opt_filter_show_method,
1513 SHOW_FILTER_FLAG_SHOW_METHOD,
1514 SHOW_FILTER_FLAG_SHOW_METHOD,
1515 "show method filter"
1521 (Pseudo)State machine:
1523 States are INITIAL, INCLUDE1, INCLUDE2, ..., EXCLUDE1, ..., EXCLUDE2, ...
1526 Enter Include Include
1528 | | Enter Enter Enter | | Enter | |
1529 | | Include Include Exclude | | Exclude | |
1530 | v ---------> ----------> ----------> | v ----------> | v
1531 INITIAL INCLUDE1 INCLUDE2 EXCLUDE1 EXCLUDE2
1532 | ^ <--------- <---------- <---------- | ^ <---------- | ^
1533 | | Exit Exit Exit | | Exit | |
1534 | | Include Include Exclude | | Exclude | |
1537 Exclude Include Include
1539 Verbose call scope is active if we are in a INCLUDE state.
1543 INITIAL: ctr[0] == 0, ctr[1] == 0
1544 INCLUDEN: ctr[1] == N, ctr[1] == 0
1545 EXCLUDEN: ctr[1] == N
1548 void show_filters_apply(methodinfo *m) {
1555 /* compose full name of method */
1558 utf_bytes(m->class->name) +
1560 utf_bytes(m->name) +
1561 utf_bytes(m->descriptor) +
1564 dumpsize = dump_size(); /* allocate memory */
1566 method_name = DMNEW(char, len);
1568 utf_cat_classname(method_name, m->class->name);
1569 strcat(method_name, ".");
1570 utf_cat(method_name, m->name);
1571 utf_cat(method_name, m->descriptor);
1573 /* reset all flags */
1575 m->filtermatches = 0;
1577 for (i = 0; i < SHOW_FILTERS_SIZE; ++i) {
1578 if (show_filters[i].enabled) {
1580 res = regexec(&show_filters[i].regex, method_name, 0, NULL, 0);
1583 m->filtermatches |= show_filters[i].flag;
1586 /* Default is to show all */
1587 m->filtermatches |= show_filters[i].flag;
1591 /* release memory */
1593 dump_release(dumpsize);
1597 #define STATE_IS_INITIAL() ((FILTERVERBOSECALLCTR[0] == 0) && (FILTERVERBOSECALLCTR[1] == 0))
1598 #define STATE_IS_INCLUDE() ((FILTERVERBOSECALLCTR[0] > 0) && (FILTERVERBOSECALLCTR[1] == 0))
1599 #define STATE_IS_EXCLUDE() (FILTERVERBOSECALLCTR[1] > 0)
1600 #define EVENT_INCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE)
1601 #define EVENT_EXCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE)
1602 #define TRANSITION_NEXT_INCLUDE() ++FILTERVERBOSECALLCTR[0]
1603 #define TRANSITION_PREV_INCLUDE() --FILTERVERBOSECALLCTR[0]
1604 #define TRANSITION_NEXT_EXCLUDE() ++FILTERVERBOSECALLCTR[1]
1605 #define TRANSITION_PREV_EXCLUDE() --FILTERVERBOSECALLCTR[1]
1609 if (STATE_IS_INITIAL()) printf("<INITIAL>\n");
1610 else if (STATE_IS_INCLUDE()) printf("<INCLUDE %hd>\n", FILTERVERBOSECALLCTR[0]);
1611 else if (STATE_IS_EXCLUDE()) printf("<EXCLUDE %hd>\n", FILTERVERBOSECALLCTR[1]);
1615 int show_filters_test_verbosecall_enter(methodinfo *m) {
1619 if (STATE_IS_INITIAL()) {
1620 if (EVENT_INCLUDE()) {
1621 TRANSITION_NEXT_INCLUDE();
1623 } else if (STATE_IS_INCLUDE()) {
1624 if (EVENT_EXCLUDE()) {
1625 TRANSITION_NEXT_EXCLUDE();
1626 /* just entered exclude, show this method */
1628 } else if (EVENT_INCLUDE()) {
1629 TRANSITION_NEXT_INCLUDE();
1631 } else if (STATE_IS_EXCLUDE()) {
1632 if (EVENT_EXCLUDE()) {
1633 TRANSITION_NEXT_EXCLUDE();
1637 return STATE_IS_INCLUDE() || force_show;
1640 int show_filters_test_verbosecall_exit(methodinfo *m) {
1645 if (STATE_IS_INCLUDE()) {
1646 if (EVENT_INCLUDE()) {
1647 TRANSITION_PREV_INCLUDE();
1648 /* just entered initial, show this method */
1649 if (STATE_IS_INITIAL()) force_show = 1;
1651 } else if (STATE_IS_EXCLUDE()) {
1652 if (EVENT_EXCLUDE()) {
1653 TRANSITION_PREV_EXCLUDE();
1658 return STATE_IS_INCLUDE() || force_show;
1665 * These are local overrides for various environment variables in Emacs.
1666 * Please do not remove this and leave it at the end of the file, where
1667 * Emacs will automagically detect them.
1668 * ---------------------------------------------------------------------
1671 * indent-tabs-mode: t
1675 * vim:noexpandtab:sw=4:ts=4: