Sample output:
tarce exception: exception object 0x823fb68 (java/lang/RuntimeException) thrown
from : 0xa7ce163d (java/lang/String.<init>([III)V)
action : unwind to 0xa7cdfeb0
(java/lang/Throwable.toString()Ljava/lang/String;)
tarce exception: exception object 0x823fb68 (java/lang/RuntimeException) thrown
from : 0xa7cdfeaf (java/lang/Throwable.toString()Ljava/lang/String;)
action : unwind to native caller at 0x80620fe
Signed-off-by: Tomek Grabiec <[email protected]>
---
include/jit/compiler.h | 5 ++++
jit/exception.c | 13 ++++++++++++
jit/trace-jit.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
test/jit/Makefile | 1 +
test/jit/trace-stub.c | 19 ++++++++++++++++++
vm/jato.c | 2 +
6 files changed, 89 insertions(+), 0 deletions(-)
diff --git a/include/jit/compiler.h b/include/jit/compiler.h
index 7743a89..acc4969 100644
--- a/include/jit/compiler.h
+++ b/include/jit/compiler.h
@@ -97,6 +97,7 @@ extern bool opt_trace_magic_trampoline;
extern bool opt_trace_bytecode_offset;
extern bool opt_trace_invoke;
extern bool opt_trace_invoke_dtls;
+extern bool opt_trace_exceptions;
void trace_magic_trampoline(struct compilation_unit *);
void trace_method(struct compilation_unit *);
@@ -107,5 +108,9 @@ 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 *);
+void trace_exception(struct compilation_unit *, struct jit_stack_frame *,
unsigned char *);
+void trace_exception_handler(unsigned char *);
+void trace_exception_unwind(struct jit_stack_frame *);
+void trace_exception_unwind_to_native(struct jit_stack_frame *);
#endif
diff --git a/jit/exception.c b/jit/exception.c
index 377dbca..99179ae 100644
--- a/jit/exception.c
+++ b/jit/exception.c
@@ -216,6 +216,9 @@ throw_exception_from(struct compilation_unit *cu, struct
jit_stack_frame *frame,
exception = exception_occurred();
assert(exception != NULL);
+ if (opt_trace_exceptions)
+ trace_exception(cu, frame, native_ptr);
+
clear_exception();
bc_offset = native_ptr_to_bytecode_offset(cu, native_ptr);
@@ -223,6 +226,10 @@ throw_exception_from(struct compilation_unit *cu, struct
jit_stack_frame *frame,
eh_ptr = find_handler(cu, exception->class, bc_offset);
if (eh_ptr != NULL) {
signal_exception(exception);
+
+ if (opt_trace_exceptions)
+ trace_exception_handler(eh_ptr);
+
return eh_ptr;
}
}
@@ -234,12 +241,18 @@ throw_exception_from(struct compilation_unit *cu, struct
jit_stack_frame *frame,
* No handler found within jitted method call chain.
* Return to previous (not jit) method.
*/
+ if (opt_trace_exceptions)
+ trace_exception_unwind_to_native(frame);
+
if (is_inside_exit_unlock(cu, native_ptr))
return cu->exit_past_unlock_ptr;
return bb_native_ptr(cu->exit_bb);
}
+ if (opt_trace_exceptions)
+ trace_exception_unwind(frame);
+
if (is_inside_unwind_unlock(cu, native_ptr))
return cu->unwind_past_unlock_ptr;
diff --git a/jit/trace-jit.c b/jit/trace-jit.c
index 6337fef..0fbe59d 100644
--- a/jit/trace-jit.c
+++ b/jit/trace-jit.c
@@ -12,6 +12,7 @@
#include <jit/basic-block.h>
#include <jit/disassemble.h>
#include <jit/lir-printer.h>
+#include <jit/exception.h>
#include <jit/cu-mapping.h>
#include <jit/statement.h>
#include <jit/vars.h>
@@ -40,6 +41,7 @@ bool opt_trace_magic_trampoline;
bool opt_trace_bytecode_offset;
bool opt_trace_invoke;
bool opt_trace_invoke_dtls;
+bool opt_trace_exceptions;
void trace_method(struct compilation_unit *cu)
{
@@ -384,3 +386,50 @@ void trace_invoke(struct compilation_unit *cu)
trace_invoke_args(vmm, frame);
}
}
+
+void trace_exception(struct compilation_unit *cu, struct jit_stack_frame
*frame,
+ unsigned char *native_ptr)
+{
+ struct vm_object *exception;
+ struct vm_method *vmm;
+ struct vm_class *vmc;
+
+
+ vmm = cu->method;
+ vmc = vmm->class;
+
+ exception = exception_occurred();
+ assert(exception);
+
+ printf("tarce exception: exception object %p (%s) thrown\n",
+ exception, exception->class->name);
+
+ printf("\tfrom\t: %p (%s.%s%s)\n", native_ptr, vmc->name, vmm->name,
+ vmm->type);
+}
+
+void trace_exception_handler(unsigned char *ptr)
+{
+ printf("\taction\t: jump to handler at %p\n", ptr);
+}
+
+void trace_exception_unwind(struct jit_stack_frame *frame)
+{
+ struct compilation_unit *cu;
+ struct vm_method *vmm;
+ struct vm_class *vmc;
+
+ cu = jit_lookup_cu(frame->return_address);
+
+ vmm = cu->method;
+ vmc = vmm->class;
+
+ printf("\taction\t: unwind to %p (%s.%s%s)\n",
+ (void*)frame->return_address, vmc->name, vmm->name, vmm->type);
+}
+
+void trace_exception_unwind_to_native(struct jit_stack_frame *frame)
+{
+ printf("\taction\t: unwind to native caller at %p\n",
+ (void*)frame->return_address);
+}
diff --git a/test/jit/Makefile b/test/jit/Makefile
index c6b40b3..cc0a1d6 100644
--- a/test/jit/Makefile
+++ b/test/jit/Makefile
@@ -63,6 +63,7 @@ OBJS = \
../vm/class-stub.o \
../vm/classloader-stub.o \
../vm/object-stub.o \
+ ../jit/trace-stub.o \
args-test-utils.o \
arithmetic-bc-test.o \
basic-block-test.o \
diff --git a/test/jit/trace-stub.c b/test/jit/trace-stub.c
index 7d6cf12..08bb9fc 100644
--- a/test/jit/trace-stub.c
+++ b/test/jit/trace-stub.c
@@ -3,7 +3,26 @@
struct compilation_unit;
bool opt_trace_invoke = false;
+bool opt_trace_exceptions = false;
void trace_invoke(struct compilation_unit *cu)
{
}
+
+void trace_exception(struct compilation_unit *cu, struct jit_stack_frame
*frame,
+ unsigned char *native_ptr)
+{
+}
+
+void trace_exception_handler(unsigned char *addr)
+{
+}
+
+void trace_exception_unwind(struct jit_stack_frame *frame)
+{
+}
+
+void trace_exception_unwind_to_native(struct jit_stack_frame *frame)
+{
+}
+
diff --git a/vm/jato.c b/vm/jato.c
index 3c17cdd..71c1dde 100644
--- a/vm/jato.c
+++ b/vm/jato.c
@@ -415,6 +415,8 @@ main(int argc, char *argv[])
opt_trace_classloader = true;
} else if (!strcmp(argv[i], "-Xtrace:invoke")) {
opt_trace_invoke = true;
+ } else if (!strcmp(argv[i], "-Xtrace:exceptions")) {
+ opt_trace_exceptions = true;
} else if (!strcmp(argv[i], "-Xtrace:invoke-dtls")) {
opt_trace_invoke = true;
opt_trace_invoke_dtls = true;
--
1.6.0.6
------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel