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
34 #include "mm/memory.h"
36 #include "threads/lock-common.h"
38 #include "vm/global.h"
39 #include "vm/builtin.h"
40 #include "vm/stringlocal.h"
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 #include "vmcore/options.h"
52 #if defined(ENABLE_DEBUG_FILTER)
53 # include <sys/types.h>
55 # if defined(ENABLE_THREADS)
56 # include "threads/native/threads.h"
58 # include "threads/none/threads.h"
62 /* global variables ***********************************************************/
64 #if defined(ENABLE_THREADS) && !defined(NDEBUG)
65 static java_object_t *show_global_lock;
69 /* prototypes *****************************************************************/
72 static void show_variable_intern(jitdata *jd, s4 index, int stage);
76 /* show_init *******************************************************************
78 Initialized the show subsystem (called by jit_init).
80 *******************************************************************************/
85 #if defined(ENABLE_THREADS)
86 /* initialize the show lock */
88 show_global_lock = NEW(java_object_t);
90 LOCK_INIT_OBJECT_LOCK(show_global_lock);
93 #if defined(ENABLE_DEBUG_FILTER)
105 char *show_jit_type_names[] = {
116 char show_jit_type_letters[] = {
130 /* show_method *****************************************************************
132 Print the intermediate representation of a method.
134 NOTE: Currently this function may only be called after register allocation!
136 *******************************************************************************/
139 void show_method(jitdata *jd, int stage)
146 basicblock *lastbptr;
150 #if defined(ENABLE_DISASSEMBLER)
154 /* get required compiler data */
161 /* We need to enter a lock here, since the binutils disassembler
162 is not reentrant-able and we could not read functions printed
165 LOCK_MONITOR_ENTER(show_global_lock);
167 #if defined(ENABLE_INTRP)
169 irstage = SHOW_PARSE;
174 /* get the last basic block */
176 for (lastbptr = jd->basicblocks; lastbptr->next != NULL; lastbptr = lastbptr->next);
182 if (code_is_leafmethod(code))
183 printf("LEAFMETHOD\n");
185 printf("\nBasic blocks: %d\n", jd->basicblockcount);
186 if (stage >= SHOW_CODE) {
187 printf("Code length: %d\n", (lastbptr->mpc - jd->basicblocks[0].mpc));
188 printf("Data length: %d\n", cd->dseglen);
189 printf("Stub length: %d\n", (s4) (code->mcodelength -
190 ((ptrint) cd->dseglen + lastbptr->mpc)));
192 printf("Variables: %d (%d used)\n", jd->varcount, jd->vartop);
193 if (stage >= SHOW_STACK)
194 printf("Max interfaces: %d\n", jd->maxinterfaces);
195 printf("Max locals: %d\n", jd->maxlocals);
196 printf("Max stack: %d\n", m->maxstack);
197 printf("Linenumbers: %d\n", m->linenumbercount);
198 printf("Branch to entry: %s\n", (jd->branchtoentry) ? "yes" : "no");
199 printf("Branch to end: %s\n", (jd->branchtoend) ? "yes" : "no");
200 if (stage >= SHOW_STACK) {
201 printf("Number of RETURNs: %d", jd->returncount);
202 if (jd->returncount == 1)
203 printf(" (block L%03d)", jd->returnblock->nr);
207 if (stage >= SHOW_PARSE) {
208 printf("Exceptions (Number: %d):\n", jd->exceptiontablelength);
209 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
210 printf(" L%03d ... ", ex->start->nr );
211 printf("L%03d = ", ex->end->nr);
212 printf("L%03d", ex->handler->nr);
213 printf(" (catchtype: ");
214 if (ex->catchtype.any)
215 if (IS_CLASSREF(ex->catchtype))
216 class_classref_print(ex->catchtype.ref);
218 class_print(ex->catchtype.cls);
225 if (irstage >= SHOW_PARSE && rd && jd->localcount > 0) {
226 printf("Local Table:\n");
227 for (i = 0; i < jd->localcount; i++) {
230 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
231 # if defined(ENABLE_INTRP)
234 printf(" (%s) ", show_jit_type_names[VAR(i)->type]);
235 if (irstage >= SHOW_REGS)
236 show_allocation(VAR(i)->type, VAR(i)->flags, VAR(i)->vv.regoff);
238 # if defined(ENABLE_INTRP)
241 #endif /* defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER) */
246 if (jd->maxlocals > 0 && jd->local_map != NULL) {
247 printf("Local Map:\n");
249 for (j = 0; j < jd->maxlocals; j++) {
253 for (i = 0; i < 5; i++) {
254 printf(" %5s ",show_jit_type_names[i]);
255 for (j = 0; j < jd->maxlocals; j++) {
256 if (jd->local_map[j*5+i] == UNUSED)
259 printf("%4i ",jd->local_map[j*5+i]);
266 if (jd->maxinterfaces > 0 && jd->interface_map && irstage >= SHOW_STACK) {
268 interface_info *mapptr = jd->interface_map;
270 /* look if there exist any INOUTS */
271 for (i = 0; (i < (5 * jd->maxinterfaces)) && !exist; i++, mapptr++)
272 exist = (mapptr->flags != UNUSED);
275 printf("Interface Table: (In/Outvars)\n");
277 for (j = 0; j < jd->maxinterfaces; j++) {
282 for (i = 0; i < 5; i++) {
283 printf(" %5s ",show_jit_type_names[i]);
284 for (j = 0; j < jd->maxinterfaces; j++) {
285 s4 flags = jd->interface_map[j*5+i].flags;
286 s4 regoff = jd->interface_map[j*5+i].regoff;
292 if (irstage >= SHOW_REGS) {
293 if (flags & SAVEDVAR) {
294 if (flags & INMEMORY)
300 if (flags & INMEMORY)
305 printf("%c%03d(", ch, regoff);
306 show_allocation(i, flags, regoff);
310 if (flags & SAVEDVAR)
323 if (rd->memuse && irstage >= SHOW_REGS) {
327 printf("Stack slots: (memuse=%d", rd->memuse);
328 if (irstage >= SHOW_CODE) {
329 printf(", stackframesize=%d", cd->stackframesize);
330 max = cd->stackframesize;
333 for (i = 0; i < max; ++i) {
334 #if defined(HAS_4BYTE_STACKSLOT)
335 printf(" M%02d = 0x%02x(sp): ", i, i * 4);
337 printf(" M%02d = 0x%02x(sp): ", i, i * 8);
339 for (j = 0; j < jd->vartop; ++j) {
341 if ((v->flags & INMEMORY) && (v->vv.regoff == i)) {
342 show_variable(jd, j, irstage);
353 #if defined(ENABLE_REPLACEMENT)
354 if (code->rplpoints) {
355 printf("Replacement Points:\n");
356 replace_show_replacement_points(code);
359 #endif /* defined(ENABLE_REPLACEMENT) */
361 #if defined(ENABLE_DISASSEMBLER)
362 /* show code before first basic block */
364 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
365 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen);
367 for (; pc < (u1 *) ((ptrint) code->mcode + cd->dseglen + jd->basicblocks[0].mpc);)
374 /* show code of all basic blocks */
376 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next)
377 show_basicblock(jd, bptr, stage);
379 #if 0 && defined(ENABLE_DISASSEMBLER)
380 /* show code after last basic block */
382 if (stage >= SHOW_CODE && opt_showdisassemble) {
383 printf("\nStubs code:\n");
384 printf("Length: %d\n\n", (s4) (code->mcodelength -
385 ((ptrint) cd->dseglen + lastbptr->mpc)));
387 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen + lastbptr->mpc);
389 for (; (ptrint) pc < ((ptrint) code->mcode + code->mcodelength);)
396 LOCK_MONITOR_EXIT(show_global_lock);
398 /* finally flush the output */
402 #endif /* !defined(NDEBUG) */
405 #if !defined(NDEBUG) && defined(ENABLE_INLINING)
406 static void show_inline_info(jitdata *jd, insinfo_inline *ii, s4 opcode, s4 stage)
411 printf("(pt %d+%d+%d st ",
412 ii->throughcount - (ii->stackvarscount - ii->paramcount),
413 ii->stackvarscount - ii->paramcount,
415 show_variable_array(jd, ii->stackvars, ii->stackvarscount, stage);
417 if (opcode == ICMD_INLINE_START || opcode == ICMD_INLINE_END) {
419 jl = (opcode == ICMD_INLINE_START) ? ii->javalocals_start : ii->javalocals_end;
420 n = (opcode == ICMD_INLINE_START) ? ii->method->maxlocals : ii->outer->maxlocals;
421 show_javalocals_array(jd, jl, n, stage);
428 method_print(ii->outer);
432 method_print(ii->method);
434 #endif /* !defined(NDEBUG) && defined(ENABLE_INLINING) */
437 /* show_basicblock *************************************************************
439 Print the intermediate representation of a basic block.
441 NOTE: Currently this function may only be called after register allocation!
443 *******************************************************************************/
446 void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
454 #if defined(ENABLE_DISASSEMBLER)
455 methodinfo *m; /* this is only a dummy */
458 s4 currentlinenumber;
461 /* get required compiler data */
466 if (bptr->flags != BBDELETED) {
467 #if defined(ENABLE_INTRP)
470 irstage = SHOW_PARSE;
475 deadcode = (bptr->flags < BBREACHED);
479 printf("======== %sL%03d ======== %s(flags: %d, bitflags: %01x, next: %d, type: ",
480 #if defined(ENABLE_REPLACEMENT)
481 (bptr->bitflags & BBFLAG_REPLACEMENT) ? "<REPLACE> " :
485 (deadcode && stage >= SHOW_STACK) ? "DEADCODE! " : "",
486 bptr->flags, bptr->bitflags,
487 (bptr->next) ? (bptr->next->nr) : -1);
489 switch (bptr->type) {
501 printf(", icount: %d", bptr->icount);
503 if (irstage >= SHOW_CFG) {
504 printf(", preds: %d [ ", bptr->predecessorcount);
506 for (i = 0; i < bptr->predecessorcount; i++)
507 printf("%d ", bptr->predecessors[i]->nr);
515 printf(" (clone of L%03d)", bptr->original->nr);
517 basicblock *b = bptr->copied_to;
519 printf(" (copied to ");
520 for (; b; b = b->copied_to)
521 printf("L%03d ", b->nr);
528 if (irstage >= SHOW_STACK) {
530 show_variable_array(jd, bptr->invars, bptr->indepth, irstage);
531 printf(" javalocals: ");
532 show_javalocals_array(jd, bptr->javalocals, bptr->method->maxlocals, irstage);
536 #if defined(ENABLE_INLINING)
537 if (bptr->inlineinfo) {
538 printf("inlineinfo: ");
539 show_inline_info(jd, bptr->inlineinfo, -1, irstage);
542 #endif /* defined(ENABLE_INLINING) */
546 for (i = 0; i < bptr->icount; i++, iptr++) {
547 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
549 show_icmd(jd, iptr, deadcode, irstage);
553 if (irstage >= SHOW_STACK) {
555 show_variable_array(jd, bptr->outvars, bptr->outdepth, irstage);
559 #if defined(ENABLE_DISASSEMBLER)
560 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd) &&
564 pc = (u1 *) (code->mcode + cd->dseglen + bptr->mpc);
567 if (bptr->next != NULL) {
568 for (; pc < (u1 *) (code->mcode + cd->dseglen + bptr->next->mpc);) {
570 dseg_get_linenumber_from_pc(&m, code->entrypoint, pc);
572 if (currentlinenumber != linenumber) {
573 linenumber = currentlinenumber;
574 printf("%4d:\n", linenumber);
581 for (; pc < (u1 *) (code->mcode + code->mcodelength);) {
583 dseg_get_linenumber_from_pc(&m, code->entrypoint, pc);
585 if (currentlinenumber != linenumber) {
586 linenumber = currentlinenumber;
587 printf("%4d:\n", linenumber);
598 #endif /* !defined(NDEBUG) */
601 /* show_icmd *******************************************************************
603 Print the intermediate representation of an instruction.
605 NOTE: Currently this function may only be called after register allocation!
607 *******************************************************************************/
611 #define SHOW_TARGET(target) \
612 if (stage >= SHOW_PARSE) { \
613 printf("--> L%03d ", (target).block->nr); \
616 printf("--> insindex %d ", (target).insindex); \
619 #define SHOW_INT_CONST(val) \
620 if (stage >= SHOW_PARSE) { \
621 printf("%d (0x%08x) ", (val), (val)); \
627 #if SIZEOF_VOID_P == 4
628 #define SHOW_LNG_CONST(val) \
629 if (stage >= SHOW_PARSE) \
630 printf("%lld (0x%016llx) ", (val), (val)); \
634 #define SHOW_LNG_CONST(val) \
635 if (stage >= SHOW_PARSE) \
636 printf("%ld (0x%016lx) ", (val), (val)); \
641 #if SIZEOF_VOID_P == 4
642 #define SHOW_ADR_CONST(val) \
643 if (stage >= SHOW_PARSE) \
644 printf("0x%08x ", (ptrint) (val)); \
648 #define SHOW_ADR_CONST(val) \
649 if (stage >= SHOW_PARSE) \
650 printf("0x%016lx ", (ptrint) (val)); \
655 #define SHOW_FLT_CONST(val) \
656 if (stage >= SHOW_PARSE) { \
659 printf("%g (0x%08x) ", (val), v.i); \
665 #if SIZEOF_VOID_P == 4
666 #define SHOW_DBL_CONST(val) \
667 if (stage >= SHOW_PARSE) { \
670 printf("%g (0x%016llx) ", (val), v.l); \
675 #define SHOW_DBL_CONST(val) \
676 if (stage >= SHOW_PARSE) { \
679 printf("%g (0x%016lx) ", (val), v.l); \
685 #define SHOW_INDEX(index) \
686 if (stage >= SHOW_PARSE) { \
687 printf("%d ", index); \
693 #define SHOW_STRING(val) \
694 if (stage >= SHOW_PARSE) { \
696 utf_display_printable_ascii( \
697 javastring_toutf((java_handle_t *)(val), false)); \
704 #define SHOW_CLASSREF_OR_CLASSINFO(c) \
705 if (stage >= SHOW_PARSE) { \
706 if (IS_CLASSREF(c)) \
707 class_classref_print(c.ref); \
709 class_print(c.cls); \
716 #define SHOW_FIELD(fmiref) \
717 if (stage >= SHOW_PARSE) { \
718 field_fieldref_print(fmiref); \
725 #define SHOW_VARIABLE(v) \
726 show_variable(jd, (v), stage)
728 #define SHOW_S1(iptr) \
729 if (stage >= SHOW_STACK) { \
730 SHOW_VARIABLE(iptr->s1.varindex); \
733 #define SHOW_S2(iptr) \
734 if (stage >= SHOW_STACK) { \
735 SHOW_VARIABLE(iptr->sx.s23.s2.varindex); \
738 #define SHOW_S3(iptr) \
739 if (stage >= SHOW_STACK) { \
740 SHOW_VARIABLE(iptr->sx.s23.s3.varindex); \
743 #define SHOW_DST(iptr) \
744 if (stage >= SHOW_STACK) { \
746 SHOW_VARIABLE(iptr->dst.varindex); \
749 #define SHOW_S1_LOCAL(iptr) \
750 if (stage >= SHOW_STACK) { \
751 printf("L%d ", iptr->s1.varindex); \
754 printf("JavaL%d ", iptr->s1.varindex); \
757 #define SHOW_DST_LOCAL(iptr) \
758 if (stage >= SHOW_STACK) { \
759 printf("=> L%d ", iptr->dst.varindex); \
762 printf("=> JavaL%d ", iptr->dst.varindex); \
765 void show_allocation(s4 type, s4 flags, s4 regoff)
767 if (type == TYPE_RET) {
772 if (flags & INMEMORY) {
773 printf("M%02d", regoff);
777 #ifdef HAS_ADDRESS_REGISTER_FILE
778 if (type == TYPE_ADR) {
779 printf("R%02d", regoff);
784 if (IS_FLT_DBL_TYPE(type)) {
785 printf("F%02d", regoff);
789 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
790 if (IS_2_WORD_TYPE(type)) {
791 # if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
792 # if defined(ENABLE_INTRP)
794 printf("%3d/%3d", GET_LOW_REG(regoff),
795 GET_HIGH_REG(regoff));
798 printf("%3s/%3s", abi_registers_integer_name[GET_LOW_REG(regoff)],
799 abi_registers_integer_name[GET_HIGH_REG(regoff)]);
801 printf("%3d/%3d", GET_LOW_REG(regoff),
802 GET_HIGH_REG(regoff));
806 #endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
808 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
809 # if defined(ENABLE_INTRP)
811 printf("%3d", regoff);
814 printf("%3s", abi_registers_integer_name[regoff]);
816 printf("%3d", regoff);
820 void show_variable(jitdata *jd, s4 index, int stage)
822 show_variable_intern(jd, index, stage);
826 static void show_variable_intern(jitdata *jd, s4 index, int stage)
832 if (index < 0 || index >= jd->vartop) {
833 printf("<INVALID INDEX:%d>", index);
840 case TYPE_INT: type = 'i'; break;
841 case TYPE_LNG: type = 'l'; break;
842 case TYPE_FLT: type = 'f'; break;
843 case TYPE_DBL: type = 'd'; break;
844 case TYPE_ADR: type = 'a'; break;
845 case TYPE_RET: type = 'r'; break;
849 if (index < jd->localcount) {
851 if (v->flags & (PREALLOC | INOUT))
852 printf("<INVALID FLAGS!>");
855 if (v->flags & PREALLOC) {
857 if (v->flags & INOUT) {
858 /* PREALLOC is used to avoid allocation of TYPE_RET */
859 if (v->type == TYPE_RET)
862 printf("<INVALID FLAGS!>");
865 else if (v->flags & INOUT)
871 printf("%c%c%d", kind, type, index);
873 if (v->flags & SAVEDVAR)
876 if (stage >= SHOW_REGS || (v->flags & PREALLOC)) {
878 show_allocation(v->type, v->flags, v->vv.regoff);
882 if (v->type == TYPE_RET && (v->flags & PREALLOC)) {
883 printf("(L%03d)", v->vv.retaddr->nr);
887 static void show_variable_array_intern(jitdata *jd, s4 *vars, int n, int stage,
899 for (i=0; i<n; ++i) {
903 if (vars[i] == UNUSED)
905 else if (javalocals) {
906 nr = RETADDR_FROM_JAVALOCAL(vars[i]);
907 printf("ret(L%03d)", nr);
910 printf("<INVALID INDEX:%d>", vars[i]);
914 show_variable_intern(jd, vars[i], stage);
919 void show_variable_array(jitdata *jd, s4 *vars, int n, int stage)
921 show_variable_array_intern(jd, vars, n, stage, false);
924 void show_javalocals_array(jitdata *jd, s4 *vars, int n, int stage)
926 show_variable_array_intern(jd, vars, n, stage, true);
929 void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
932 branch_target_t *table;
933 lookup_target_t *lookup;
934 constant_FMIref *fmiref;
938 /* get the opcode and the condition */
942 printf("%s ", icmd_table[opcode].name);
944 if (stage < SHOW_PARSE)
950 /* Print the condition for conditional instructions. */
952 /* XXX print condition from flags */
954 if (iptr->flags.bits & INS_FLAG_UNRESOLVED)
955 printf("(UNRESOLVED) ");
965 case ICMD_ARRAYLENGTH:
1032 /* binary/const INT */
1033 case ICMD_IADDCONST:
1034 case ICMD_ISUBCONST:
1035 case ICMD_IMULCONST:
1039 case ICMD_IANDCONST:
1041 case ICMD_IXORCONST:
1042 case ICMD_ISHLCONST:
1043 case ICMD_ISHRCONST:
1044 case ICMD_IUSHRCONST:
1045 case ICMD_LSHLCONST:
1046 case ICMD_LSHRCONST:
1047 case ICMD_LUSHRCONST:
1049 SHOW_INT_CONST(iptr->sx.val.i);
1053 /* ?ASTORECONST (trinary/const INT) */
1054 case ICMD_IASTORECONST:
1055 case ICMD_BASTORECONST:
1056 case ICMD_CASTORECONST:
1057 case ICMD_SASTORECONST:
1060 SHOW_INT_CONST(iptr->sx.s23.s3.constval);
1065 SHOW_INT_CONST(iptr->sx.val.i);
1069 /* binary/const LNG */
1070 case ICMD_LADDCONST:
1071 case ICMD_LSUBCONST:
1072 case ICMD_LMULCONST:
1076 case ICMD_LANDCONST:
1078 case ICMD_LXORCONST:
1080 SHOW_LNG_CONST(iptr->sx.val.l);
1084 /* trinary/const LNG (<= pointer size) */
1085 case ICMD_LASTORECONST:
1088 SHOW_ADR_CONST(iptr->sx.s23.s3.constval);
1093 SHOW_LNG_CONST(iptr->sx.val.l);
1099 SHOW_FLT_CONST(iptr->sx.val.f);
1105 SHOW_DBL_CONST(iptr->sx.val.d);
1111 if (iptr->flags.bits & INS_FLAG_CLASS) {
1112 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1113 SHOW_CLASSREF_OR_CLASSINFO(iptr->sx.val.c);
1115 else if (iptr->sx.val.anyptr == NULL) {
1119 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1120 SHOW_STRING(iptr->sx.val.stringconst);
1125 case ICMD_AASTORECONST:
1128 printf("%p ", (void*) iptr->sx.s23.s3.constval);
1131 case ICMD_GETFIELD: /* 1 -> 1 */
1132 case ICMD_PUTFIELD: /* 2 -> 0 */
1133 case ICMD_PUTSTATIC: /* 1 -> 0 */
1134 case ICMD_GETSTATIC: /* 0 -> 1 */
1135 case ICMD_PUTSTATICCONST: /* 0 -> 0 */
1136 case ICMD_PUTFIELDCONST: /* 1 -> 0 */
1137 if (opcode != ICMD_GETSTATIC && opcode != ICMD_PUTSTATICCONST) {
1139 if (opcode == ICMD_PUTFIELD) {
1143 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1146 if (opcode == ICMD_GETSTATIC || opcode == ICMD_GETFIELD) {
1152 SHOW_S1_LOCAL(iptr);
1153 SHOW_INT_CONST(iptr->sx.val.i);
1154 SHOW_DST_LOCAL(iptr);
1184 SHOW_S1_LOCAL(iptr);
1185 if (stage >= SHOW_STACK) {
1186 printf(" ---> L%03d", iptr->dst.block->nr);
1195 SHOW_S1_LOCAL(iptr);
1205 SHOW_DST_LOCAL(iptr);
1206 if (stage >= SHOW_STACK && iptr->sx.s23.s3.javaindex != UNUSED)
1207 printf(" (javaindex %d)", iptr->sx.s23.s3.javaindex);
1208 if (iptr->flags.bits & INS_FLAG_RETADDR) {
1209 printf(" (retaddr L%03d)", RETADDR_FROM_JAVALOCAL(iptr->sx.s23.s2.retaddrnr));
1221 case ICMD_ANEWARRAY:
1225 case ICMD_MULTIANEWARRAY:
1226 if (stage >= SHOW_STACK) {
1227 argp = iptr->sx.s23.s2.args;
1228 i = iptr->s1.argcount;
1230 SHOW_VARIABLE(*(argp++));
1234 printf("argcount=%d ", iptr->s1.argcount);
1236 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1241 case ICMD_CHECKCAST:
1243 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_ACMPEQ:
1355 case ICMD_IF_ACMPNE:
1358 SHOW_TARGET(iptr->dst);
1361 case ICMD_TABLESWITCH:
1363 table = iptr->dst.table;
1365 i = iptr->sx.s23.s3.tablehigh - iptr->sx.s23.s2.tablelow + 1;
1367 printf("high=%d low=%d count=%d\n", iptr->sx.s23.s3.tablehigh, iptr->sx.s23.s2.tablelow, i);
1369 printf("\t\t%d --> ", (int) (table - iptr->dst.table));
1370 printf("L%03d\n", table->block->nr);
1376 case ICMD_LOOKUPSWITCH:
1379 printf("count=%d, default=L%03d\n",
1380 iptr->sx.s23.s2.lookupcount,
1381 iptr->sx.s23.s3.lookupdefault.block->nr);
1383 lookup = iptr->dst.lookup;
1384 i = iptr->sx.s23.s2.lookupcount;
1387 printf("\t\t%d --> L%03d\n",
1389 lookup->target.block->nr);
1404 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1405 /* XXX this needs more work */
1407 unresolved_class_debug_dump(iptr->sx.s23.s2.uc, stdout);
1420 #endif /* !defined(NDEBUG) */
1422 /* Debug output filtering */
1424 #if defined(ENABLE_DEBUG_FILTER)
1426 #if !defined(ENABLE_THREADS)
1427 u2 _no_threads_filterverbosecallctr[2] = { 0, 0 };
1430 struct show_filter {
1431 /* Boolean indicating if filter is enabled. */
1433 /* Regular expression the method name is matched against */
1435 /* Flag set on m->filtermatches if regex matches */
1439 typedef struct show_filter show_filter_t;
1441 #define SHOW_FILTERS_SIZE 3
1443 /* Array of filters applyed on a method */
1444 static struct show_filter show_filters[SHOW_FILTERS_SIZE];
1446 static void show_filter_init(show_filter_t *cf, const char *str, u1 flag, u1 default_flag, const char *description) {
1451 err = regcomp(&cf->regex, str, REG_EXTENDED | REG_NOSUB);
1453 regerror(err, &cf->regex, err_buf, sizeof(err_buf));
1455 "Invalid value given for %s: `%s' (%s).",
1456 description, str, err_buf
1462 cf->flag = default_flag;
1467 void show_filters_init(void) {
1471 opt_filter_verbosecall_include,
1472 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1473 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1474 "verbose call include filter"
1479 opt_filter_verbosecall_exclude,
1480 SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE,
1482 "verbose call exclude filter"
1487 opt_filter_show_method,
1488 SHOW_FILTER_FLAG_SHOW_METHOD,
1489 SHOW_FILTER_FLAG_SHOW_METHOD,
1490 "show method filter"
1496 (Pseudo)State machine:
1498 States are INITIAL, INCLUDE1, INCLUDE2, ..., EXCLUDE1, ..., EXCLUDE2, ...
1501 Enter Include Include
1503 | | Enter Enter Enter | | Enter | |
1504 | | Include Include Exclude | | Exclude | |
1505 | v ---------> ----------> ----------> | v ----------> | v
1506 INITIAL INCLUDE1 INCLUDE2 EXCLUDE1 EXCLUDE2
1507 | ^ <--------- <---------- <---------- | ^ <---------- | ^
1508 | | Exit Exit Exit | | Exit | |
1509 | | Include Include Exclude | | Exclude | |
1512 Exclude Include Include
1514 Verbose call scope is active if we are in a INCLUDE state.
1518 INITIAL: ctr[0] == 0, ctr[1] == 0
1519 INCLUDEN: ctr[1] == N, ctr[1] == 0
1520 EXCLUDEN: ctr[1] == N
1523 void show_filters_apply(methodinfo *m) {
1530 /* compose full name of method */
1533 utf_bytes(m->class->name) +
1535 utf_bytes(m->name) +
1536 utf_bytes(m->descriptor) +
1539 dumpsize = dump_size(); /* allocate memory */
1541 method_name = DMNEW(char, len);
1543 utf_cat_classname(method_name, m->class->name);
1544 strcat(method_name, ".");
1545 utf_cat(method_name, m->name);
1546 utf_cat(method_name, m->descriptor);
1548 /* reset all flags */
1550 m->filtermatches = 0;
1552 for (i = 0; i < SHOW_FILTERS_SIZE; ++i) {
1553 if (show_filters[i].enabled) {
1555 res = regexec(&show_filters[i].regex, method_name, 0, NULL, 0);
1558 m->filtermatches |= show_filters[i].flag;
1561 /* Default is to show all */
1562 m->filtermatches |= show_filters[i].flag;
1566 /* release memory */
1568 dump_release(dumpsize);
1572 #define STATE_IS_INITIAL() ((FILTERVERBOSECALLCTR[0] == 0) && (FILTERVERBOSECALLCTR[1] == 0))
1573 #define STATE_IS_INCLUDE() ((FILTERVERBOSECALLCTR[0] > 0) && (FILTERVERBOSECALLCTR[1] == 0))
1574 #define STATE_IS_EXCLUDE() (FILTERVERBOSECALLCTR[1] > 0)
1575 #define EVENT_INCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE)
1576 #define EVENT_EXCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE)
1577 #define TRANSITION_NEXT_INCLUDE() ++FILTERVERBOSECALLCTR[0]
1578 #define TRANSITION_PREV_INCLUDE() --FILTERVERBOSECALLCTR[0]
1579 #define TRANSITION_NEXT_EXCLUDE() ++FILTERVERBOSECALLCTR[1]
1580 #define TRANSITION_PREV_EXCLUDE() --FILTERVERBOSECALLCTR[1]
1584 if (STATE_IS_INITIAL()) printf("<INITIAL>\n");
1585 else if (STATE_IS_INCLUDE()) printf("<INCLUDE %hd>\n", FILTERVERBOSECALLCTR[0]);
1586 else if (STATE_IS_EXCLUDE()) printf("<EXCLUDE %hd>\n", FILTERVERBOSECALLCTR[1]);
1590 int show_filters_test_verbosecall_enter(methodinfo *m) {
1594 if (STATE_IS_INITIAL()) {
1595 if (EVENT_INCLUDE()) {
1596 TRANSITION_NEXT_INCLUDE();
1598 } else if (STATE_IS_INCLUDE()) {
1599 if (EVENT_EXCLUDE()) {
1600 TRANSITION_NEXT_EXCLUDE();
1601 /* just entered exclude, show this method */
1603 } else if (EVENT_INCLUDE()) {
1604 TRANSITION_NEXT_INCLUDE();
1606 } else if (STATE_IS_EXCLUDE()) {
1607 if (EVENT_EXCLUDE()) {
1608 TRANSITION_NEXT_EXCLUDE();
1612 return STATE_IS_INCLUDE() || force_show;
1615 int show_filters_test_verbosecall_exit(methodinfo *m) {
1620 if (STATE_IS_INCLUDE()) {
1621 if (EVENT_INCLUDE()) {
1622 TRANSITION_PREV_INCLUDE();
1623 /* just entered initial, show this method */
1624 if (STATE_IS_INITIAL()) force_show = 1;
1626 } else if (STATE_IS_EXCLUDE()) {
1627 if (EVENT_EXCLUDE()) {
1628 TRANSITION_PREV_EXCLUDE();
1633 return STATE_IS_INCLUDE() || force_show;
1640 * These are local overrides for various environment variables in Emacs.
1641 * Please do not remove this and leave it at the end of the file, where
1642 * Emacs will automagically detect them.
1643 * ---------------------------------------------------------------------
1646 * indent-tabs-mode: t
1650 * vim:noexpandtab:sw=4:ts=4: