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/stringlocal.h"
42 #include "vm/jit/abi.h"
43 #include "vm/jit/jit.h"
44 #include "vm/jit/show.h"
45 #include "vm/jit/disass.h"
46 #include "vm/jit/stack.h"
47 #include "vm/jit/parse.h"
49 #include "vmcore/options.h"
51 #if defined(ENABLE_DEBUG_FILTER)
52 # include <sys/types.h>
54 # include "threads/thread.hpp"
58 /* global variables ***********************************************************/
60 #if defined(ENABLE_THREADS) && !defined(NDEBUG)
61 static java_object_t *show_global_lock;
65 /* prototypes *****************************************************************/
68 static void show_variable_intern(jitdata *jd, s4 index, int stage);
72 /* show_init *******************************************************************
74 Initialized the show subsystem (called by jit_init).
76 *******************************************************************************/
81 #if defined(ENABLE_THREADS)
82 /* initialize the show lock */
84 show_global_lock = NEW(java_object_t);
86 LOCK_INIT_OBJECT_LOCK(show_global_lock);
89 #if defined(ENABLE_DEBUG_FILTER)
101 char *show_jit_type_names[] = {
112 char show_jit_type_letters[] = {
126 /* show_method *****************************************************************
128 Print the intermediate representation of a method.
130 NOTE: Currently this function may only be called after register allocation!
132 *******************************************************************************/
135 void show_method(jitdata *jd, int stage)
142 basicblock *lastbptr;
146 #if defined(ENABLE_DISASSEMBLER)
150 /* get required compiler data */
157 /* We need to enter a lock here, since the binutils disassembler
158 is not reentrant-able and we could not read functions printed
161 LOCK_MONITOR_ENTER(show_global_lock);
163 #if defined(ENABLE_INTRP)
165 irstage = SHOW_PARSE;
170 /* get the last basic block */
172 for (lastbptr = jd->basicblocks; lastbptr->next != NULL; lastbptr = lastbptr->next);
178 if (code_is_leafmethod(code))
179 printf("LEAFMETHOD\n");
181 printf("\nBasic blocks: %d\n", jd->basicblockcount);
182 if (stage >= SHOW_CODE) {
183 printf("Code length: %d\n", (lastbptr->mpc - jd->basicblocks[0].mpc));
184 printf("Data length: %d\n", cd->dseglen);
185 printf("Stub length: %d\n", (s4) (code->mcodelength -
186 ((ptrint) cd->dseglen + lastbptr->mpc)));
188 printf("Variables: %d (%d used)\n", jd->varcount, jd->vartop);
189 if (stage >= SHOW_STACK)
190 printf("Max interfaces: %d\n", jd->maxinterfaces);
191 printf("Max locals: %d\n", jd->maxlocals);
192 printf("Max stack: %d\n", m->maxstack);
193 printf("Linenumbers: %d\n", m->linenumbercount);
194 printf("Branch to entry: %s\n", (jd->branchtoentry) ? "yes" : "no");
195 printf("Branch to end: %s\n", (jd->branchtoend) ? "yes" : "no");
196 if (stage >= SHOW_STACK) {
197 printf("Number of RETURNs: %d", jd->returncount);
198 if (jd->returncount == 1)
199 printf(" (block L%03d)", jd->returnblock->nr);
203 if (stage >= SHOW_PARSE) {
204 printf("Exceptions (Number: %d):\n", jd->exceptiontablelength);
205 for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
206 printf(" L%03d ... ", ex->start->nr );
207 printf("L%03d = ", ex->end->nr);
208 printf("L%03d", ex->handler->nr);
209 printf(" (catchtype: ");
210 if (ex->catchtype.any)
211 if (IS_CLASSREF(ex->catchtype))
212 class_classref_print(ex->catchtype.ref);
214 class_print(ex->catchtype.cls);
221 if (irstage >= SHOW_PARSE && rd && jd->localcount > 0) {
222 printf("Local Table:\n");
223 for (i = 0; i < jd->localcount; i++) {
226 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
227 # if defined(ENABLE_INTRP)
230 printf(" (%s) ", show_jit_type_names[VAR(i)->type]);
231 if (irstage >= SHOW_REGS)
232 show_allocation(VAR(i)->type, VAR(i)->flags, VAR(i)->vv.regoff);
234 # if defined(ENABLE_INTRP)
237 #endif /* defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER) */
242 if (jd->maxlocals > 0 && jd->local_map != NULL) {
243 printf("Local Map:\n");
245 for (j = 0; j < jd->maxlocals; j++) {
249 for (i = 0; i < 5; i++) {
250 printf(" %5s ",show_jit_type_names[i]);
251 for (j = 0; j < jd->maxlocals; j++) {
252 if (jd->local_map[j*5+i] == UNUSED)
255 printf("%4i ",jd->local_map[j*5+i]);
262 if (jd->maxinterfaces > 0 && jd->interface_map && irstage >= SHOW_STACK) {
264 interface_info *mapptr = jd->interface_map;
266 /* look if there exist any INOUTS */
267 for (i = 0; (i < (5 * jd->maxinterfaces)) && !exist; i++, mapptr++)
268 exist = (mapptr->flags != UNUSED);
271 printf("Interface Table: (In/Outvars)\n");
273 for (j = 0; j < jd->maxinterfaces; j++) {
278 for (i = 0; i < 5; i++) {
279 printf(" %5s ",show_jit_type_names[i]);
280 for (j = 0; j < jd->maxinterfaces; j++) {
281 s4 flags = jd->interface_map[j*5+i].flags;
282 s4 regoff = jd->interface_map[j*5+i].regoff;
288 if (irstage >= SHOW_REGS) {
289 if (flags & SAVEDVAR) {
290 if (flags & INMEMORY)
296 if (flags & INMEMORY)
301 printf("%c%03d(", ch, regoff);
302 show_allocation(i, flags, regoff);
306 if (flags & SAVEDVAR)
319 if (rd->memuse && irstage >= SHOW_REGS) {
323 printf("Stack slots: (memuse=%d", rd->memuse);
324 if (irstage >= SHOW_CODE) {
325 printf(", stackframesize=%d", cd->stackframesize);
326 max = cd->stackframesize;
329 for (i = 0; i < max; ++i) {
330 #if defined(HAS_4BYTE_STACKSLOT)
331 printf(" M%02d = 0x%02x(sp): ", i, i * 4);
333 printf(" M%02d = 0x%02x(sp): ", i, i * 8);
335 for (j = 0; j < jd->vartop; ++j) {
337 if ((v->flags & INMEMORY) && (v->vv.regoff == i)) {
338 show_variable(jd, j, irstage);
349 #if defined(ENABLE_REPLACEMENT)
350 if (code->rplpoints) {
351 printf("Replacement Points:\n");
352 replace_show_replacement_points(code);
355 #endif /* defined(ENABLE_REPLACEMENT) */
357 #if defined(ENABLE_DISASSEMBLER)
358 /* show code before first basic block */
360 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd)) {
361 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen);
363 for (; pc < (u1 *) ((ptrint) code->mcode + cd->dseglen + jd->basicblocks[0].mpc);)
370 /* show code of all basic blocks */
372 for (bptr = jd->basicblocks; bptr != NULL; bptr = bptr->next)
373 show_basicblock(jd, bptr, stage);
375 #if 0 && defined(ENABLE_DISASSEMBLER)
376 /* show code after last basic block */
378 if (stage >= SHOW_CODE && opt_showdisassemble) {
379 printf("\nStubs code:\n");
380 printf("Length: %d\n\n", (s4) (code->mcodelength -
381 ((ptrint) cd->dseglen + lastbptr->mpc)));
383 pc = (u1 *) ((ptrint) code->mcode + cd->dseglen + lastbptr->mpc);
385 for (; (ptrint) pc < ((ptrint) code->mcode + code->mcodelength);)
392 LOCK_MONITOR_EXIT(show_global_lock);
394 /* finally flush the output */
398 #endif /* !defined(NDEBUG) */
401 #if !defined(NDEBUG) && defined(ENABLE_INLINING)
402 static void show_inline_info(jitdata *jd, insinfo_inline *ii, s4 opcode, s4 stage)
407 printf("(pt %d+%d+%d st ",
408 ii->throughcount - (ii->stackvarscount - ii->paramcount),
409 ii->stackvarscount - ii->paramcount,
411 show_variable_array(jd, ii->stackvars, ii->stackvarscount, stage);
413 if (opcode == ICMD_INLINE_START || opcode == ICMD_INLINE_END) {
415 jl = (opcode == ICMD_INLINE_START) ? ii->javalocals_start : ii->javalocals_end;
416 n = (opcode == ICMD_INLINE_START) ? ii->method->maxlocals : ii->outer->maxlocals;
417 show_javalocals_array(jd, jl, n, stage);
424 method_print(ii->outer);
428 method_print(ii->method);
430 #endif /* !defined(NDEBUG) && defined(ENABLE_INLINING) */
433 /* show_basicblock *************************************************************
435 Print the intermediate representation of a basic block.
437 NOTE: Currently this function may only be called after register allocation!
439 *******************************************************************************/
442 void show_basicblock(jitdata *jd, basicblock *bptr, int stage)
450 #if defined(ENABLE_DISASSEMBLER)
451 methodinfo *m; /* this is only a dummy */
454 s4 currentlinenumber;
457 /* get required compiler data */
462 if (bptr->flags != BBDELETED) {
463 #if defined(ENABLE_INTRP)
466 irstage = SHOW_PARSE;
471 deadcode = (bptr->flags < BBREACHED);
475 printf("======== %sL%03d ======== %s(flags: %d, bitflags: %01x, next: %d, type: ",
476 #if defined(ENABLE_REPLACEMENT)
477 (bptr->bitflags & BBFLAG_REPLACEMENT) ? "<REPLACE> " :
481 (deadcode && stage >= SHOW_STACK) ? "DEADCODE! " : "",
482 bptr->flags, bptr->bitflags,
483 (bptr->next) ? (bptr->next->nr) : -1);
485 switch (bptr->type) {
497 printf(", icount: %d", bptr->icount);
499 if (irstage >= SHOW_CFG) {
500 printf(", preds: %d [ ", bptr->predecessorcount);
502 for (i = 0; i < bptr->predecessorcount; i++)
503 printf("%d ", bptr->predecessors[i]->nr);
511 printf(" (clone of L%03d)", bptr->original->nr);
513 basicblock *b = bptr->copied_to;
515 printf(" (copied to ");
516 for (; b; b = b->copied_to)
517 printf("L%03d ", b->nr);
524 if (irstage >= SHOW_CFG) {
525 printf("succs: %d [ ", bptr->successorcount);
527 for (i = 0; i < bptr->successorcount; i++)
528 printf("%d ", bptr->successors[i]->nr);
533 if (irstage >= SHOW_STACK) {
535 show_variable_array(jd, bptr->invars, bptr->indepth, irstage);
536 printf(" javalocals: ");
537 if (bptr->javalocals)
538 show_javalocals_array(jd, bptr->javalocals, bptr->method->maxlocals, irstage);
544 #if defined(ENABLE_INLINING)
545 if (bptr->inlineinfo) {
546 printf("inlineinfo: ");
547 show_inline_info(jd, bptr->inlineinfo, -1, irstage);
550 #endif /* defined(ENABLE_INLINING) */
552 #if defined(ENABLE_SSA)
556 for (i = 0; i < bptr->phicount; i++, iptr++) {
557 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
559 show_icmd(jd, iptr, deadcode, irstage);
566 for (i = 0; i < bptr->icount; i++, iptr++) {
567 printf("%4d:%4d: ", iptr->line, iptr->flags.bits >> INS_FLAG_ID_SHIFT);
569 show_icmd(jd, iptr, deadcode, irstage);
573 if (irstage >= SHOW_STACK) {
575 show_variable_array(jd, bptr->outvars, bptr->outdepth, irstage);
579 #if defined(ENABLE_DISASSEMBLER)
580 if ((stage >= SHOW_CODE) && JITDATA_HAS_FLAG_SHOWDISASSEMBLE(jd) &&
584 pc = (void *) (code->mcode + cd->dseglen + bptr->mpc);
587 if (bptr->next != NULL) {
588 for (; pc < (void *) (code->mcode + cd->dseglen + bptr->next->mpc);) {
590 linenumbertable_linenumber_for_pc(&m, code, pc);
592 if (currentlinenumber != linenumber) {
593 linenumber = currentlinenumber;
594 printf("%4d:\n", linenumber);
601 for (; pc < (void *) (code->mcode + code->mcodelength);) {
603 linenumbertable_linenumber_for_pc(&m, code, pc);
605 if (currentlinenumber != linenumber) {
606 linenumber = currentlinenumber;
607 printf("%4d:\n", linenumber);
618 #endif /* !defined(NDEBUG) */
621 /* show_icmd *******************************************************************
623 Print the intermediate representation of an instruction.
625 NOTE: Currently this function may only be called after register allocation!
627 *******************************************************************************/
631 #define SHOW_TARGET(target) \
632 if (stage >= SHOW_PARSE) { \
633 printf("--> L%03d ", (target).block->nr); \
636 printf("--> insindex %d ", (target).insindex); \
639 #define SHOW_INT_CONST(val) \
640 if (stage >= SHOW_PARSE) { \
641 printf("%d (0x%08x) ", (int32_t) (val), (int32_t) (val)); \
647 #if SIZEOF_VOID_P == 4
648 #define SHOW_LNG_CONST(val) \
649 if (stage >= SHOW_PARSE) \
650 printf("%lld (0x%016llx) ", (val), (val)); \
654 #define SHOW_LNG_CONST(val) \
655 if (stage >= SHOW_PARSE) \
656 printf("%ld (0x%016lx) ", (val), (val)); \
661 #if SIZEOF_VOID_P == 4
662 #define SHOW_ADR_CONST(val) \
663 if (stage >= SHOW_PARSE) \
664 printf("0x%08x ", (ptrint) (val)); \
668 #define SHOW_ADR_CONST(val) \
669 if (stage >= SHOW_PARSE) \
670 printf("0x%016lx ", (ptrint) (val)); \
675 #define SHOW_FLT_CONST(val) \
676 if (stage >= SHOW_PARSE) { \
679 printf("%g (0x%08x) ", (val), v.i); \
685 #if SIZEOF_VOID_P == 4
686 #define SHOW_DBL_CONST(val) \
687 if (stage >= SHOW_PARSE) { \
690 printf("%g (0x%016llx) ", (val), v.l); \
695 #define SHOW_DBL_CONST(val) \
696 if (stage >= SHOW_PARSE) { \
699 printf("%g (0x%016lx) ", (val), v.l); \
705 #define SHOW_INDEX(index) \
706 if (stage >= SHOW_PARSE) { \
707 printf("%d ", index); \
713 #define SHOW_STRING(val) \
714 if (stage >= SHOW_PARSE) { \
716 utf_display_printable_ascii( \
717 javastring_toutf((java_handle_t *)(val), false)); \
724 #define SHOW_CLASSREF_OR_CLASSINFO(c) \
725 if (stage >= SHOW_PARSE) { \
726 if (IS_CLASSREF(c)) \
727 class_classref_print(c.ref); \
729 class_print(c.cls); \
736 #define SHOW_FIELD(fmiref) \
737 if (stage >= SHOW_PARSE) { \
738 field_fieldref_print(fmiref); \
745 #define SHOW_VARIABLE(v) \
746 show_variable(jd, (v), stage)
748 #define SHOW_S1(iptr) \
749 if (stage >= SHOW_STACK) { \
750 SHOW_VARIABLE(iptr->s1.varindex); \
753 #define SHOW_S2(iptr) \
754 if (stage >= SHOW_STACK) { \
755 SHOW_VARIABLE(iptr->sx.s23.s2.varindex); \
758 #define SHOW_S3(iptr) \
759 if (stage >= SHOW_STACK) { \
760 SHOW_VARIABLE(iptr->sx.s23.s3.varindex); \
763 #define SHOW_DST(iptr) \
764 if (stage >= SHOW_STACK) { \
766 SHOW_VARIABLE(iptr->dst.varindex); \
769 #define SHOW_S1_LOCAL(iptr) \
770 if (stage >= SHOW_STACK) { \
771 printf("L%d ", iptr->s1.varindex); \
774 printf("JavaL%d ", iptr->s1.varindex); \
777 #define SHOW_DST_LOCAL(iptr) \
778 if (stage >= SHOW_STACK) { \
779 printf("=> L%d ", iptr->dst.varindex); \
782 printf("=> JavaL%d ", iptr->dst.varindex); \
785 void show_allocation(s4 type, s4 flags, s4 regoff)
787 if (type == TYPE_RET) {
792 if (flags & INMEMORY) {
793 printf("M%02d", regoff);
797 #ifdef HAS_ADDRESS_REGISTER_FILE
798 if (type == TYPE_ADR) {
799 printf("R%02d", regoff);
804 if (IS_FLT_DBL_TYPE(type)) {
805 printf("F%02d", regoff);
809 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
810 if (IS_2_WORD_TYPE(type)) {
811 # if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
812 # if defined(ENABLE_INTRP)
814 printf("%3d/%3d", GET_LOW_REG(regoff),
815 GET_HIGH_REG(regoff));
818 printf("%3s/%3s", abi_registers_integer_name[GET_LOW_REG(regoff)],
819 abi_registers_integer_name[GET_HIGH_REG(regoff)]);
821 printf("%3d/%3d", GET_LOW_REG(regoff),
822 GET_HIGH_REG(regoff));
826 #endif /* defined(SUPPORT_COMBINE_INTEGER_REGISTERS) */
828 #if defined(ENABLE_JIT) && defined(ENABLE_DISASSEMBLER)
829 # if defined(ENABLE_INTRP)
831 printf("%3d", regoff);
834 printf("%3s", abi_registers_integer_name[regoff]);
836 printf("%3d", regoff);
840 void show_variable(jitdata *jd, s4 index, int stage)
842 show_variable_intern(jd, index, stage);
846 static void show_variable_intern(jitdata *jd, s4 index, int stage)
852 if (index < 0 || index >= jd->vartop) {
853 printf("<INVALID INDEX:%d>", index);
860 case TYPE_INT: type = 'i'; break;
861 case TYPE_LNG: type = 'l'; break;
862 case TYPE_FLT: type = 'f'; break;
863 case TYPE_DBL: type = 'd'; break;
864 case TYPE_ADR: type = 'a'; break;
865 case TYPE_RET: type = 'r'; break;
869 if (index < jd->localcount) {
871 if (v->flags & (PREALLOC | INOUT))
872 printf("<INVALID FLAGS!>");
875 if (v->flags & PREALLOC) {
877 if (v->flags & INOUT) {
878 /* PREALLOC is used to avoid allocation of TYPE_RET */
879 if (v->type == TYPE_RET)
882 printf("<INVALID FLAGS!>");
885 else if (v->flags & INOUT)
891 printf("%c%c%d", kind, type, index);
893 if (v->flags & SAVEDVAR)
896 if (stage >= SHOW_REGS || (v->flags & PREALLOC)) {
898 show_allocation(v->type, v->flags, v->vv.regoff);
902 if (v->type == TYPE_RET && (v->flags & PREALLOC)) {
903 printf("(L%03d)", v->vv.retaddr->nr);
907 static void show_variable_array_intern(jitdata *jd, s4 *vars, int n, int stage,
919 for (i=0; i<n; ++i) {
923 if (vars[i] == UNUSED)
925 else if (javalocals) {
926 nr = RETADDR_FROM_JAVALOCAL(vars[i]);
927 printf("ret(L%03d)", nr);
930 printf("<INVALID INDEX:%d>", vars[i]);
934 show_variable_intern(jd, vars[i], stage);
939 void show_variable_array(jitdata *jd, s4 *vars, int n, int stage)
941 show_variable_array_intern(jd, vars, n, stage, false);
944 void show_javalocals_array(jitdata *jd, s4 *vars, int n, int stage)
946 show_variable_array_intern(jd, vars, n, stage, true);
949 void show_icmd(jitdata *jd, instruction *iptr, bool deadcode, int stage)
952 branch_target_t *table;
953 lookup_target_t *lookup;
954 constant_FMIref *fmiref;
958 /* get the opcode and the condition */
962 printf("%s ", icmd_table[opcode].name);
964 if (stage < SHOW_PARSE)
970 /* Print the condition for conditional instructions. */
972 /* XXX print condition from flags */
974 if (iptr->flags.bits & INS_FLAG_UNRESOLVED)
975 printf("(UNRESOLVED) ");
985 case ICMD_ARRAYLENGTH:
1004 case ICMD_INT2SHORT:
1052 /* binary/const INT */
1053 case ICMD_IADDCONST:
1054 case ICMD_ISUBCONST:
1055 case ICMD_IMULCONST:
1059 case ICMD_IANDCONST:
1061 case ICMD_IXORCONST:
1062 case ICMD_ISHLCONST:
1063 case ICMD_ISHRCONST:
1064 case ICMD_IUSHRCONST:
1065 case ICMD_LSHLCONST:
1066 case ICMD_LSHRCONST:
1067 case ICMD_LUSHRCONST:
1069 SHOW_INT_CONST(iptr->sx.val.i);
1073 /* ?ASTORECONST (trinary/const INT) */
1074 case ICMD_IASTORECONST:
1075 case ICMD_BASTORECONST:
1076 case ICMD_CASTORECONST:
1077 case ICMD_SASTORECONST:
1080 SHOW_INT_CONST(iptr->sx.s23.s3.constval);
1085 SHOW_INT_CONST(iptr->sx.val.i);
1089 /* binary/const LNG */
1090 case ICMD_LADDCONST:
1091 case ICMD_LSUBCONST:
1092 case ICMD_LMULCONST:
1096 case ICMD_LANDCONST:
1098 case ICMD_LXORCONST:
1100 SHOW_LNG_CONST(iptr->sx.val.l);
1104 /* trinary/const LNG (<= pointer size) */
1105 case ICMD_LASTORECONST:
1108 SHOW_ADR_CONST(iptr->sx.s23.s3.constval);
1113 SHOW_LNG_CONST(iptr->sx.val.l);
1119 SHOW_FLT_CONST(iptr->sx.val.f);
1125 SHOW_DBL_CONST(iptr->sx.val.d);
1131 if (iptr->flags.bits & INS_FLAG_CLASS) {
1132 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1133 SHOW_CLASSREF_OR_CLASSINFO(iptr->sx.val.c);
1135 else if (iptr->sx.val.anyptr == NULL) {
1139 SHOW_ADR_CONST(iptr->sx.val.anyptr);
1140 SHOW_STRING(iptr->sx.val.stringconst);
1145 case ICMD_AASTORECONST:
1148 printf("%p ", (void*) iptr->sx.s23.s3.constval);
1151 case ICMD_GETFIELD: /* 1 -> 1 */
1152 case ICMD_PUTFIELD: /* 2 -> 0 */
1153 case ICMD_PUTSTATIC: /* 1 -> 0 */
1154 case ICMD_GETSTATIC: /* 0 -> 1 */
1155 case ICMD_PUTSTATICCONST: /* 0 -> 0 */
1156 case ICMD_PUTFIELDCONST: /* 1 -> 0 */
1157 if (opcode != ICMD_GETSTATIC && opcode != ICMD_PUTSTATICCONST) {
1159 if (opcode == ICMD_PUTFIELD) {
1163 INSTRUCTION_GET_FIELDREF(iptr, fmiref);
1166 if (opcode == ICMD_GETSTATIC || opcode == ICMD_GETFIELD) {
1172 SHOW_S1_LOCAL(iptr);
1173 SHOW_INT_CONST(iptr->sx.val.i);
1174 SHOW_DST_LOCAL(iptr);
1204 SHOW_S1_LOCAL(iptr);
1205 if (stage >= SHOW_STACK) {
1206 printf(" ---> L%03d", iptr->dst.block->nr);
1215 SHOW_S1_LOCAL(iptr);
1225 SHOW_DST_LOCAL(iptr);
1226 if (stage >= SHOW_STACK && iptr->sx.s23.s3.javaindex != UNUSED)
1227 printf(" (javaindex %d)", iptr->sx.s23.s3.javaindex);
1228 if (iptr->flags.bits & INS_FLAG_RETADDR) {
1229 printf(" (retaddr L%03d)", RETADDR_FROM_JAVALOCAL(iptr->sx.s23.s2.retaddrnr));
1241 case ICMD_ANEWARRAY:
1245 case ICMD_MULTIANEWARRAY:
1246 if (stage >= SHOW_STACK) {
1247 argp = iptr->sx.s23.s2.args;
1248 i = iptr->s1.argcount;
1250 SHOW_VARIABLE(*(argp++));
1254 printf("argcount=%d ", iptr->s1.argcount);
1256 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1261 case ICMD_CHECKCAST:
1263 class_classref_or_classinfo_print(iptr->sx.s23.s3.c);
1268 case ICMD_INSTANCEOF:
1273 case ICMD_INLINE_START:
1274 case ICMD_INLINE_END:
1275 case ICMD_INLINE_BODY:
1276 #if defined(ENABLE_INLINING)
1278 insinfo_inline *ii = iptr->sx.s23.s3.inlineinfo;
1279 show_inline_info(jd, ii, opcode, stage);
1285 if (stage >= SHOW_STACK) {
1286 argp = iptr->sx.s23.s2.args;
1287 i = iptr->s1.argcount;
1289 if ((iptr->s1.argcount - 1 - i) == iptr->sx.s23.s3.bte->md->paramcount)
1290 printf(" pass-through: ");
1291 SHOW_VARIABLE(*(argp++));
1294 printf("%s ", iptr->sx.s23.s3.bte->cname);
1295 if (iptr->sx.s23.s3.bte->md->returntype.type != TYPE_VOID) {
1300 case ICMD_INVOKEVIRTUAL:
1301 case ICMD_INVOKESPECIAL:
1302 case ICMD_INVOKESTATIC:
1303 case ICMD_INVOKEINTERFACE:
1304 if (stage >= SHOW_STACK) {
1306 INSTRUCTION_GET_METHODDESC(iptr, md);
1307 argp = iptr->sx.s23.s2.args;
1308 i = iptr->s1.argcount;
1310 if ((iptr->s1.argcount - 1 - i) == md->paramcount)
1311 printf(" pass-through: ");
1312 SHOW_VARIABLE(*(argp++));
1315 INSTRUCTION_GET_METHODREF(iptr, fmiref);
1316 method_methodref_print(fmiref);
1317 if (fmiref->parseddesc.md->returntype.type != TYPE_VOID) {
1330 SHOW_INT_CONST(iptr->sx.val.i);
1331 SHOW_TARGET(iptr->dst);
1341 SHOW_LNG_CONST(iptr->sx.val.l);
1342 SHOW_TARGET(iptr->dst);
1346 SHOW_TARGET(iptr->dst);
1350 SHOW_TARGET(iptr->sx.s23.s3.jsrtarget);
1355 case ICMD_IFNONNULL:
1357 SHOW_TARGET(iptr->dst);
1360 case ICMD_IF_ICMPEQ:
1361 case ICMD_IF_ICMPNE:
1362 case ICMD_IF_ICMPLT:
1363 case ICMD_IF_ICMPGE:
1364 case ICMD_IF_ICMPGT:
1365 case ICMD_IF_ICMPLE:
1367 case ICMD_IF_LCMPEQ:
1368 case ICMD_IF_LCMPNE:
1369 case ICMD_IF_LCMPLT:
1370 case ICMD_IF_LCMPGE:
1371 case ICMD_IF_LCMPGT:
1372 case ICMD_IF_LCMPLE:
1374 case ICMD_IF_ACMPEQ:
1375 case ICMD_IF_ACMPNE:
1378 SHOW_TARGET(iptr->dst);
1381 case ICMD_TABLESWITCH:
1383 table = iptr->dst.table;
1385 i = iptr->sx.s23.s3.tablehigh - iptr->sx.s23.s2.tablelow + 1;
1387 printf("high=%d low=%d count=%d\n", iptr->sx.s23.s3.tablehigh, iptr->sx.s23.s2.tablelow, i);
1389 printf("\t\t%d --> ", (int) (table - iptr->dst.table));
1390 printf("L%03d\n", table->block->nr);
1396 case ICMD_LOOKUPSWITCH:
1399 printf("count=%d, default=L%03d\n",
1400 iptr->sx.s23.s2.lookupcount,
1401 iptr->sx.s23.s3.lookupdefault.block->nr);
1403 lookup = iptr->dst.lookup;
1404 i = iptr->sx.s23.s2.lookupcount;
1407 printf("\t\t%d --> L%03d\n",
1409 lookup->target.block->nr);
1424 if (INSTRUCTION_IS_UNRESOLVED(iptr)) {
1425 /* XXX this needs more work */
1427 unresolved_class_debug_dump(iptr->sx.s23.s2.uc, stdout);
1437 case ICMD_GETEXCEPTION:
1440 #if defined(ENABLE_SSA)
1443 for (i = 0; i < iptr->s1.argcount; ++i) {
1444 SHOW_VARIABLE(iptr->sx.s23.s2.iargs[i]->dst.varindex);
1448 if (iptr->flags.bits & (1 << 0)) printf("used ");
1449 if (iptr->flags.bits & (1 << 1)) printf("redundantAll ");
1450 if (iptr->flags.bits & (1 << 2)) printf("redundantOne ");
1456 #endif /* !defined(NDEBUG) */
1458 /* Debug output filtering */
1460 #if defined(ENABLE_DEBUG_FILTER)
1462 #if !defined(ENABLE_THREADS)
1463 u2 _no_threads_filterverbosecallctr[2] = { 0, 0 };
1466 struct show_filter {
1467 /* Boolean indicating if filter is enabled. */
1469 /* Regular expression the method name is matched against */
1471 /* Flag set on m->filtermatches if regex matches */
1475 typedef struct show_filter show_filter_t;
1477 #define SHOW_FILTERS_SIZE 3
1479 /* Array of filters applyed on a method */
1480 static struct show_filter show_filters[SHOW_FILTERS_SIZE];
1482 static void show_filter_init(show_filter_t *cf, const char *str, u1 flag, u1 default_flag, const char *description) {
1487 err = regcomp(&cf->regex, str, REG_EXTENDED | REG_NOSUB);
1489 regerror(err, &cf->regex, err_buf, sizeof(err_buf));
1491 "Invalid value given for %s: `%s' (%s).",
1492 description, str, err_buf
1498 cf->flag = default_flag;
1503 void show_filters_init(void) {
1507 opt_filter_verbosecall_include,
1508 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1509 SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE,
1510 "verbose call include filter"
1515 opt_filter_verbosecall_exclude,
1516 SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE,
1518 "verbose call exclude filter"
1523 opt_filter_show_method,
1524 SHOW_FILTER_FLAG_SHOW_METHOD,
1525 SHOW_FILTER_FLAG_SHOW_METHOD,
1526 "show method filter"
1532 (Pseudo)State machine:
1534 States are INITIAL, INCLUDE1, INCLUDE2, ..., EXCLUDE1, ..., EXCLUDE2, ...
1537 Enter Include Include
1539 | | Enter Enter Enter | | Enter | |
1540 | | Include Include Exclude | | Exclude | |
1541 | v ---------> ----------> ----------> | v ----------> | v
1542 INITIAL INCLUDE1 INCLUDE2 EXCLUDE1 EXCLUDE2
1543 | ^ <--------- <---------- <---------- | ^ <---------- | ^
1544 | | Exit Exit Exit | | Exit | |
1545 | | Include Include Exclude | | Exclude | |
1548 Exclude Include Include
1550 Verbose call scope is active if we are in a INCLUDE state.
1554 INITIAL: ctr[0] == 0, ctr[1] == 0
1555 INCLUDEN: ctr[1] == N, ctr[1] == 0
1556 EXCLUDEN: ctr[1] == N
1559 void show_filters_apply(methodinfo *m) {
1566 /* compose full name of method */
1569 utf_bytes(m->clazz->name) +
1571 utf_bytes(m->name) +
1572 utf_bytes(m->descriptor) +
1577 method_name = DMNEW(char, len);
1579 utf_cat_classname(method_name, m->clazz->name);
1580 strcat(method_name, ".");
1581 utf_cat(method_name, m->name);
1582 utf_cat(method_name, m->descriptor);
1584 /* reset all flags */
1586 m->filtermatches = 0;
1588 for (i = 0; i < SHOW_FILTERS_SIZE; ++i) {
1589 if (show_filters[i].enabled) {
1591 res = regexec(&show_filters[i].regex, method_name, 0, NULL, 0);
1594 m->filtermatches |= show_filters[i].flag;
1597 /* Default is to show all */
1598 m->filtermatches |= show_filters[i].flag;
1602 /* release memory */
1607 #define STATE_IS_INITIAL() ((FILTERVERBOSECALLCTR[0] == 0) && (FILTERVERBOSECALLCTR[1] == 0))
1608 #define STATE_IS_INCLUDE() ((FILTERVERBOSECALLCTR[0] > 0) && (FILTERVERBOSECALLCTR[1] == 0))
1609 #define STATE_IS_EXCLUDE() (FILTERVERBOSECALLCTR[1] > 0)
1610 #define EVENT_INCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_INCLUDE)
1611 #define EVENT_EXCLUDE() (m->filtermatches & SHOW_FILTER_FLAG_VERBOSECALL_EXCLUDE)
1612 #define TRANSITION_NEXT_INCLUDE() ++FILTERVERBOSECALLCTR[0]
1613 #define TRANSITION_PREV_INCLUDE() --FILTERVERBOSECALLCTR[0]
1614 #define TRANSITION_NEXT_EXCLUDE() ++FILTERVERBOSECALLCTR[1]
1615 #define TRANSITION_PREV_EXCLUDE() --FILTERVERBOSECALLCTR[1]
1619 if (STATE_IS_INITIAL()) printf("<INITIAL>\n");
1620 else if (STATE_IS_INCLUDE()) printf("<INCLUDE %hd>\n", FILTERVERBOSECALLCTR[0]);
1621 else if (STATE_IS_EXCLUDE()) printf("<EXCLUDE %hd>\n", FILTERVERBOSECALLCTR[1]);
1625 int show_filters_test_verbosecall_enter(methodinfo *m) {
1629 if (STATE_IS_INITIAL()) {
1630 if (EVENT_INCLUDE()) {
1631 TRANSITION_NEXT_INCLUDE();
1633 } else if (STATE_IS_INCLUDE()) {
1634 if (EVENT_EXCLUDE()) {
1635 TRANSITION_NEXT_EXCLUDE();
1636 /* just entered exclude, show this method */
1638 } else if (EVENT_INCLUDE()) {
1639 TRANSITION_NEXT_INCLUDE();
1641 } else if (STATE_IS_EXCLUDE()) {
1642 if (EVENT_EXCLUDE()) {
1643 TRANSITION_NEXT_EXCLUDE();
1647 return STATE_IS_INCLUDE() || force_show;
1650 int show_filters_test_verbosecall_exit(methodinfo *m) {
1655 if (STATE_IS_INCLUDE()) {
1656 if (EVENT_INCLUDE()) {
1657 TRANSITION_PREV_INCLUDE();
1658 /* just entered initial, show this method */
1659 if (STATE_IS_INITIAL()) force_show = 1;
1661 } else if (STATE_IS_EXCLUDE()) {
1662 if (EVENT_EXCLUDE()) {
1663 TRANSITION_PREV_EXCLUDE();
1668 return STATE_IS_INCLUDE() || force_show;
1675 * These are local overrides for various environment variables in Emacs.
1676 * Please do not remove this and leave it at the end of the file, where
1677 * Emacs will automagically detect them.
1678 * ---------------------------------------------------------------------
1681 * indent-tabs-mode: t
1685 * vim:noexpandtab:sw=4:ts=4: