New macro throw_from_jato_func() allows signalled exception to be thrown from jato C function that is directly called from JIT code. It uses return address substitution method. It does not require any polling-code to be inserted in JIT code. It can throw exceptions much faster than using guard-page method because it does not involve signals.
It should be used whenever possible instead of guard-page polling. However the latter method will be still useful for polling for asynchronous exceptions. Signed-off-by: Tomek Grabiec <tgrab...@gmail.com> --- include/jit/exception.h | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-) diff --git a/include/jit/exception.h b/include/jit/exception.h index 42bc2bb..71d1f3a 100644 --- a/include/jit/exception.h +++ b/include/jit/exception.h @@ -1,7 +1,11 @@ #ifndef JATO_JIT_EXCEPTION_H #define JATO_JIT_EXCEPTION_H +#include <arch/stack-frame.h> +#include <jit/cu-mapping.h> +#include <jit/compiler.h> #include <stdbool.h> +#include <vm/die.h> #include <vm/vm.h> struct compilation_unit; @@ -55,4 +59,36 @@ static inline struct object *exception_occurred(void) return exception_holder; } +/** + * Use this macro to throw signalled exception from jato functions + * that are directly called from JIT code. It replaces the function's + * return address so that it points to propper exception handler and + * removes call arguments from stack. The calling function can + * continue to execute safely as long as it's not trying to access + * call arguments. + * + * @args_size: the size of arguments pushed before call expressed in + * byte units. + */ +#define throw_from_jato_func(args_size) \ +({ \ + struct jit_stack_frame *frame; \ + struct compilation_unit *cu; \ + unsigned char *native_ptr; \ + void *eh; \ + \ + native_ptr = __builtin_return_address(0) - 1; \ + if (!is_jit_method((unsigned long)native_ptr)) \ + die("%s: must not be called from not-JIT code", \ + __func__); \ + \ + frame = __builtin_frame_address(1); \ + \ + cu = get_cu_from_native_addr((unsigned long)native_ptr); \ + eh = throw_exception_from(cu, frame, native_ptr); \ + \ + __override_return_address(eh); \ + __cleanup_args(args_size); \ +}) + #endif /* JATO_JIT_EXCEPTION_H */ -- 1.6.0.6 ------------------------------------------------------------------------------ OpenSolaris 2009.06 is a cutting edge operating system for enterprises looking to deploy the next generation of Solaris that includes the latest innovations from Sun and the OpenSource community. Download a copy and enjoy capabilities such as Networking, Storage and Virtualization. Go to: http://p.sf.net/sfu/opensolaris-get _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel