Use this functions to start and end tracing. They ensure mutual exclusion and print thread's name they're called from. They are necessary to make trace outputs readable in multithreaded applications.
Signed-off-by: Tomek Grabiec <tgrab...@gmail.com> --- include/jit/compiler.h | 2 ++ jit/trace-jit.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 0 deletions(-) diff --git a/include/jit/compiler.h b/include/jit/compiler.h index 10e3118..a781730 100644 --- a/include/jit/compiler.h +++ b/include/jit/compiler.h @@ -116,5 +116,7 @@ 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_begin(void); +void trace_end(void); #endif diff --git a/jit/trace-jit.c b/jit/trace-jit.c index 6ebd299..37fe6d4 100644 --- a/jit/trace-jit.c +++ b/jit/trace-jit.c @@ -32,6 +32,7 @@ #include <malloc.h> #include <stdlib.h> #include <stdio.h> +#include <pthread.h> bool opt_trace_method; bool opt_trace_cfg; @@ -47,6 +48,39 @@ bool opt_trace_invoke_verbose; bool opt_trace_exceptions; bool opt_trace_bytecode; +static pthread_mutex_t trace_mutex = PTHREAD_MUTEX_INITIALIZER; + +static void print_current_thread(void) +{ + struct vm_object *thread; + struct vm_object *name; + struct vm_thread *self; + + self = vm_thread_self(); + if (!self) + return; + + thread = vm_thread_get_java_thread(self); + + name = field_get_object(thread, vm_java_lang_Thread_name); + + char * name_s; + + name_s = vm_string_to_cstr(name); + printf("[thread: %s] ", name_s); + free(name_s); +} + +void trace_begin(void) +{ + pthread_mutex_lock(&trace_mutex); + print_current_thread(); +} + +void trace_end(void) { + pthread_mutex_unlock(&trace_mutex); +} + void trace_method(struct compilation_unit *cu) { struct vm_method *method = cu->method; @@ -438,6 +472,8 @@ void trace_invoke(struct compilation_unit *cu) struct vm_method *vmm = cu->method; struct vm_class *vmc = vmm->class; + trace_begin(); + printf("trace invoke: %s.%s%s\n", vmc->name, vmm->name, vmm->type); if (opt_trace_invoke_verbose) { @@ -449,6 +485,8 @@ void trace_invoke(struct compilation_unit *cu) trace_return_address(frame); trace_invoke_args(vmm, frame); } + + trace_end(); } void trace_exception(struct compilation_unit *cu, struct jit_stack_frame *frame, -- 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