This option enables tracing invocation return values.
Currently we cannot trace floats, doubles and longs yet.

Example output:
[main] trace return: java/nio/CharBuffer.get()C
[main]       J_CHAR: 0x68

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 arch/x86/insn-selector.brg |   25 +++++++++++++++++++++++++
 include/jit/compiler.h     |    2 ++
 jit/trace-jit.c            |   22 ++++++++++++++++++++++
 vm/jato.c                  |    6 ++++++
 4 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/arch/x86/insn-selector.brg b/arch/x86/insn-selector.brg
index 2b15450..b4c04e2 100644
--- a/arch/x86/insn-selector.brg
+++ b/arch/x86/insn-selector.brg
@@ -656,6 +656,9 @@ reg:        EXPR_INVOKEINTERFACE(arg) 1
        if (nr_stack_args)
                method_args_cleanup(s, tree, nr_stack_args);
 
+       if (opt_trace_return_value)
+               select_trace_return_value(s, tree, method);
+
        select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, eax, state->reg1));
        if (edx != NULL)
                select_insn(s, tree, reg_reg_insn(INSN_MOV_REG_REG, edx, 
state->reg2));
@@ -2555,6 +2558,22 @@ static void select_set_target(struct basic_block *s,
 }
 #endif
 
+static void select_trace_return_value(struct basic_block *s,
+                                     struct tree_node *tree,
+                                     struct vm_method *vmm)
+{
+       struct var_info *eax = get_fixed_var(s->b_parent, MACH_REG_xAX);
+       struct var_info *esp = get_fixed_var(s->b_parent, MACH_REG_xSP);
+
+       select_insn(s, tree, reg_insn(INSN_PUSH_REG, eax));
+       select_insn(s, tree, imm_insn(INSN_PUSH_IMM, (unsigned long) vmm));
+       select_insn(s, tree, rel_insn(INSN_CALL_REL,
+                                     (unsigned long) trace_return_value));
+       select_insn(s, tree, imm_reg_insn(INSN_ADD_IMM_REG, sizeof(void *),
+                                         esp));
+       select_insn(s, tree, reg_insn(INSN_POP_REG, eax));
+}
+
 static void select_vm_native_call(struct basic_block *s, struct tree_node 
*tree,
                                  struct insn *call_insn, void *target)
 {
@@ -2657,6 +2676,9 @@ static void invoke(struct basic_block *s, struct 
tree_node *tree, struct compila
        if (nr_stack_args)
                method_args_cleanup(s, tree, nr_stack_args);
 
+       if (opt_trace_return_value)
+               select_trace_return_value(s, tree, method);
+
        if (vm_method_is_jni(method))
                select_exception_test(s, tree);
 }
@@ -2699,6 +2721,9 @@ static void invokevirtual(struct _MBState *state, struct 
basic_block *s, struct
        nr_stack_args = get_stack_args_count(method);
        if (nr_stack_args)
                method_args_cleanup(s, tree, nr_stack_args);
+
+       if (opt_trace_return_value)
+               select_trace_return_value(s, tree, method);
 }
 
 static void emit_code(struct basic_block *bb, MBState *state, int goal)
diff --git a/include/jit/compiler.h b/include/jit/compiler.h
index de91e81..9bf2ea2 100644
--- a/include/jit/compiler.h
+++ b/include/jit/compiler.h
@@ -104,6 +104,7 @@ extern bool opt_trace_invoke_verbose;
 extern bool opt_trace_exceptions;
 extern bool opt_trace_bytecode;
 extern bool opt_trace_compile;
+extern bool opt_trace_return_value;
 
 void trace_magic_trampoline(struct compilation_unit *);
 void trace_method(struct compilation_unit *);
@@ -119,5 +120,6 @@ void trace_exception_handler(struct compilation_unit *, 
unsigned char *);
 void trace_exception_unwind(struct jit_stack_frame *);
 void trace_exception_unwind_to_native(struct jit_stack_frame *);
 void trace_bytecode(struct vm_method *);
+void trace_return_value(struct vm_method *, unsigned long);
 
 #endif
diff --git a/jit/trace-jit.c b/jit/trace-jit.c
index bb0984e..d7a3c5d 100644
--- a/jit/trace-jit.c
+++ b/jit/trace-jit.c
@@ -52,6 +52,7 @@ bool opt_trace_exceptions;
 bool opt_trace_bytecode;
 bool opt_trace_compile;
 bool opt_trace_threads;
+bool opt_trace_return_value;
 
 void trace_method(struct compilation_unit *cu)
 {
@@ -662,3 +663,24 @@ void trace_bytecode(struct vm_method *method)
                method->code_attribute.exception_table_length);
        trace_printf("\n");
 }
+
+void trace_return_value(struct vm_method *vmm, unsigned long value)
+{
+       enum vm_type type;
+       int dummy;
+
+       dummy = 0;
+       type = method_return_type(vmm);
+
+       trace_printf("trace return: %s.%s%s\n", vmm->class->name, vmm->name,
+                    vmm->type);
+       if (type == J_VOID)
+               return;
+
+       trace_printf("%12s: ", get_vm_type_name(type));
+
+       print_arg(type, &value, &dummy);
+       trace_printf("\n");
+
+       trace_flush();
+}
diff --git a/vm/jato.c b/vm/jato.c
index b1d69f8..a282a47 100644
--- a/vm/jato.c
+++ b/vm/jato.c
@@ -847,6 +847,11 @@ static void handle_define(const char *arg)
        free(str);
 }
 
+static void handle_trace_return(void)
+{
+       opt_trace_return_value = true;
+}
+
 struct option {
        const char *name;
 
@@ -892,6 +897,7 @@ const struct option options[] = {
        DEFINE_OPTION("Xtrace:itable",          handle_trace_itable),
        DEFINE_OPTION("Xtrace:jit",             handle_trace_jit),
        DEFINE_OPTION("Xtrace:trampoline",      handle_trace_trampoline),
+       DEFINE_OPTION("Xtrace:return",          handle_trace_return),
 };
 
 static const struct option *get_option(const char *name)
-- 
1.6.0.6


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to