Making it a macro rules out the risk of using __builtin_frame_address().
When __builtin_frame_address() is used in a function it is possible
that a call to it will be optimized so that new frame is not created.

Signed-off-by: Tomek Grabiec <[email protected]>
---
 include/vm/signal.h   |   16 ++++++++++++++++
 test/vm/signal-stub.c |    4 ----
 vm/signal.c           |   22 ----------------------
 3 files changed, 16 insertions(+), 26 deletions(-)

diff --git a/include/vm/signal.h b/include/vm/signal.h
index 55795e1..fddc3e9 100644
--- a/include/vm/signal.h
+++ b/include/vm/signal.h
@@ -12,4 +12,20 @@ void setup_signal_handlers(void);
 int install_signal_bh(void *ctx, signal_bh_fn bh);
 unsigned long throw_from_signal_bh(unsigned long jit_addr);
 
+/*
+ * This macro should be called directly from signal bottom half
+ * to obtain exception handler address.
+ *
+ * The frame chain looks here like this:
+ *
+ * 0  <signal_bottom_half_handler>
+ * 1  <signal_bh_trampoline>
+ * 2  <jit_method>
+ *    ...
+ */
+#define throw_from_signal_bh(jit_addr)                                 \
+       (unsigned long) throw_from_jit(jit_lookup_cu(jit_addr),         \
+                                      __builtin_frame_address(2),      \
+                                      (unsigned char *)jit_addr)
+
 #endif /* VM_SIGNAL_H */
diff --git a/test/vm/signal-stub.c b/test/vm/signal-stub.c
index 917b0fb..c73bfc3 100644
--- a/test/vm/signal-stub.c
+++ b/test/vm/signal-stub.c
@@ -1,6 +1,2 @@
 #include "vm/signal.h"
 
-unsigned long throw_from_signal_bh(unsigned long jit_addr)
-{
-       return 0;
-}
diff --git a/vm/signal.c b/vm/signal.c
index 0d0da24..3e59480 100644
--- a/vm/signal.c
+++ b/vm/signal.c
@@ -42,28 +42,6 @@
 #include <unistd.h>
 #include <stdio.h>
 
-unsigned long throw_from_signal_bh(unsigned long jit_addr)
-{
-       struct jit_stack_frame *frame;
-       struct compilation_unit *cu;
-
-       /*
-        * The frame chain looks like this here:
-        *
-        * 0  <throw_from_signal_bh>
-        * 1  <signal_bottom_half_handler>
-        * 2  <signal_bh_trampoline>
-        * 3  <jit_method>
-        *    ...
-        */
-       frame = __builtin_frame_address(3);
-
-       cu = jit_lookup_cu(jit_addr);
-
-       return (unsigned long)throw_from_jit(cu, frame,
-               (unsigned char *)jit_addr);
-}
-
 static unsigned long throw_arithmetic_exception(unsigned long src_addr)
 {
        signal_new_exception(vm_java_lang_ArithmeticException,
-- 
1.6.0.6


------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to