This patch adds a new command-line flag, -Xtrace:invoke, which will output a line whenever a method is called, saying which method of which class that was invoked. Note that the print-out happens from inside the JIT-compiled code itself, so we are certain to get the message every time the function is called (as opposed to e.g. -Xtrace:jit, which will only output a message when a method is compiled).
It looks like this: Running test jvm/PrintTest trace invoke: jvm/PrintTest.main([Ljava/lang/String;)V trace invoke: java/lang/System.<clinit>()V trace invoke: java/lang/VMSystem.makeStandardInputStream()Ljava/io/InputStream; trace invoke: java/io/FileDescriptor.<clinit>()V ... This patch has the potential to help debugging, but please review it so we're sure it can't mess up the generated code. x86_64 part is untested. Signed-off-by: Vegard Nossum <vegard.nos...@gmail.com> --- arch/x86/emit-code.c | 7 +++++++ include/jit/compiler.h | 2 ++ include/jit/emit-code.h | 1 + jit/emit.c | 3 +++ jit/trace-jit.c | 9 +++++++++ test/arch-x86/Makefile | 1 + test/jit/trace-stub.c | 9 +++++++++ vm/jato.c | 2 ++ 8 files changed, 34 insertions(+), 0 deletions(-) create mode 100644 test/jit/trace-stub.c diff --git a/arch/x86/emit-code.c b/arch/x86/emit-code.c index e72ae27..44626fc 100644 --- a/arch/x86/emit-code.c +++ b/arch/x86/emit-code.c @@ -354,6 +354,13 @@ void emit_unwind(struct buffer *buf) __emit_jmp(buf, (unsigned long)&unwind); } +void emit_trace_invoke(struct buffer *buf, struct compilation_unit *cu) +{ + __emit_push_imm(buf, (unsigned long) cu); + __emit_call(buf, &trace_invoke); + __emit_add_imm_reg(buf, sizeof(unsigned long), REG_XSP); +} + /* * This fixes relative calls generated by EXPR_INVOKE. * diff --git a/include/jit/compiler.h b/include/jit/compiler.h index a42b503..439a020 100644 --- a/include/jit/compiler.h +++ b/include/jit/compiler.h @@ -94,6 +94,7 @@ extern bool opt_trace_regalloc; extern bool opt_trace_machine_code; extern bool opt_trace_magic_trampoline; extern bool opt_trace_bytecode_offset; +extern bool opt_trace_invoke; void trace_magic_trampoline(struct compilation_unit *); void trace_method(struct compilation_unit *); @@ -103,5 +104,6 @@ void trace_lir(struct compilation_unit *); void trace_liveness(struct compilation_unit *); void trace_regalloc(struct compilation_unit *); void trace_machine_code(struct compilation_unit *); +void trace_invoke(struct compilation_unit *); #endif diff --git a/include/jit/emit-code.h b/include/jit/emit-code.h index bfa89c7..266da19 100644 --- a/include/jit/emit-code.h +++ b/include/jit/emit-code.h @@ -26,6 +26,7 @@ extern struct emitter emitters[]; [_insn_type] = { .emit_fn = _fn, .type = _emitter_type } extern void emit_prolog(struct buffer *, unsigned long); +extern void emit_trace_invoke(struct buffer *, struct compilation_unit *); extern void emit_epilog(struct buffer *); extern void emit_trampoline(struct compilation_unit *, void *, struct jit_trampoline *); extern void emit_unwind(struct buffer *); diff --git a/jit/emit.c b/jit/emit.c index 183fe41..5af6e56 100644 --- a/jit/emit.c +++ b/jit/emit.c @@ -156,6 +156,9 @@ int emit_machine_code(struct compilation_unit *cu) if (method_is_synchronized(cu->method)) emit_monitorenter(cu); + if (opt_trace_invoke) + emit_trace_invoke(cu->objcode, cu); + for_each_basic_block(bb, &cu->bb_list) emit_body(bb, cu->objcode); diff --git a/jit/trace-jit.c b/jit/trace-jit.c index 266179b..19118f1 100644 --- a/jit/trace-jit.c +++ b/jit/trace-jit.c @@ -33,6 +33,7 @@ bool opt_trace_regalloc; bool opt_trace_machine_code; bool opt_trace_magic_trampoline; bool opt_trace_bytecode_offset; +bool opt_trace_invoke; void trace_method(struct compilation_unit *cu) { @@ -259,3 +260,11 @@ void trace_magic_trampoline(struct compilation_unit *cu) cu->method->name, cu->method->method_index); } + +void trace_invoke(struct compilation_unit *cu) +{ + struct vm_method *vmm = cu->method; + struct vm_class *vmc = vmm->class; + + printf("trace invoke: %s.%s%s\n", vmc->name, vmm->name, vmm->type); +} diff --git a/test/arch-x86/Makefile b/test/arch-x86/Makefile index 3186e30..e3be573 100644 --- a/test/arch-x86/Makefile +++ b/test/arch-x86/Makefile @@ -75,6 +75,7 @@ OBJS = \ ../jamvm/cast-stub.o \ ../jamvm/lock.o \ ../jit/trampoline-stub.o \ + ../jit/trace-stub.o \ ../libharness/libharness.o \ ../vm/classloader-stub.o \ ../vm/java_lang-stub.o \ diff --git a/test/jit/trace-stub.c b/test/jit/trace-stub.c new file mode 100644 index 0000000..7d6cf12 --- /dev/null +++ b/test/jit/trace-stub.c @@ -0,0 +1,9 @@ +#include <stdbool.h> + +struct compilation_unit; + +bool opt_trace_invoke = false; + +void trace_invoke(struct compilation_unit *cu) +{ +} diff --git a/vm/jato.c b/vm/jato.c index f8226d9..c7f31ac 100644 --- a/vm/jato.c +++ b/vm/jato.c @@ -268,6 +268,8 @@ main(int argc, char *argv[]) opt_trace_bytecode_offset = true; } else if (!strcmp(argv[i], "-Xtrace:classloader")) { opt_trace_classloader = true; + } else if (!strcmp(argv[i], "-Xtrace:invoke")) { + opt_trace_invoke = true; } else if (!strcmp(argv[i], "-Xtrace:jit")) { opt_trace_method = true; opt_trace_cfg = true; -- 1.6.0.4 ------------------------------------------------------------------------------ _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel