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 | 24 ++++++++++++++++++++++++ include/jit/compiler.h | 2 ++ include/jit/emit-code.h | 2 ++ 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, 52 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..3ab945e 100644 --- a/arch/x86/emit-code.c +++ b/arch/x86/emit-code.c @@ -783,6 +783,17 @@ void emit_prolog(struct buffer *buf, unsigned long nr_locals) __emit_sub_imm_reg(buf, nr_locals * sizeof(unsigned long), REG_ESP); } +void emit_trace_invoke(struct buffer *buf, + const char *class, const char *method, const char *type) +{ + __emit_push_imm(buf, (unsigned long) type); + __emit_push_imm(buf, (unsigned long) method); + __emit_push_imm(buf, (unsigned long) class); + __emit_push_imm(buf, (unsigned long) "trace invoke: %s.%s%s\n"); + __emit_call(buf, &printf); + __emit_add_imm_reg(buf, 16, REG_ESP); +} + static void emit_pop_memlocal(struct buffer *buf, struct operand *operand) { unsigned long disp = slot_offset(operand->slot); @@ -1666,6 +1677,19 @@ void emit_prolog(struct buffer *buf, unsigned long nr_locals) REG_RSP); } +void emit_trace_invoke(struct buffer *buf, + const char *class, const char *method, const char *type) +{ + __emit_push_imm(buf, (unsigned long) type); + __emit_push_imm(buf, (unsigned long) method); + __emit_push_imm(buf, (unsigned long) class); + __emit_push_imm(buf, (unsigned long) "trace invoke: %s.%s%s\n"); + __emit_call(buf, &printf); + __emit_add_imm_reg(buf, 32, REG_RSP); +} + +void emit_epilog(struct buffer *buf) + static void emit_restore_regs(struct buffer *buf) { __emit_pop_reg(buf, REG_R15); 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..05bef93 100644 --- a/include/jit/emit-code.h +++ b/include/jit/emit-code.h @@ -26,6 +26,8 @@ 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 *, + const char *class, const char *method, const char *type); 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..e4f6c74 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) + trace_invoke(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..3fb3fda 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; + + emit_trace_invoke(cu->objcode, 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 729455f..26ae739 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