Throwing code will always push exception reference because exit basic block
will always safely discard it. This also fixes a crash when running jato on
the following code:

public class Test() {
    public static void main(String []args) {
        throw new RuntimeException("test");
    }
}

That's because code selected for STMT_ATHROW didn't handle the case
where the jump target was NULL which meant that a jump to exit block should
be made and no exception object should be pushed.

Signed-off-by: Tomek Grabiec <[email protected]>
---
 arch/x86/exception_32.c        |   19 +++++++------------
 arch/x86/unwind_32.S           |   13 +------------
 include/jit/compilation-unit.h |    1 -
 jit/compilation-unit.c         |    5 -----
 jit/exception.c                |    6 +++---
 5 files changed, 11 insertions(+), 33 deletions(-)

diff --git a/arch/x86/exception_32.c b/arch/x86/exception_32.c
index f3e5612..070ef33 100644
--- a/arch/x86/exception_32.c
+++ b/arch/x86/exception_32.c
@@ -44,10 +44,11 @@ unsigned char *throw_exception(struct compilation_unit *cu,
 
 void throw_exception_from_signal(void *ctx, struct object *exception)
 {
-       ucontext_t *uc;
        struct jit_stack_frame *frame;
        struct compilation_unit *cu;
        unsigned long source_addr;
+       unsigned long *stack;
+       ucontext_t *uc;
        void *eh;
 
        uc = ctx;
@@ -59,16 +60,10 @@ void throw_exception_from_signal(void *ctx, struct object 
*exception)
        eh = throw_exception_from(cu, frame, (unsigned char*)source_addr,
                                  exception);
 
-       if (eh == NULL) {
-               uc->uc_mcontext.gregs[REG_IP] = (unsigned 
long)bb_native_ptr(cu->exit_bb);
-       } else {
-               unsigned long *stack;
-
-               uc->uc_mcontext.gregs[REG_IP] = (unsigned long)eh;
+       uc->uc_mcontext.gregs[REG_IP] = (unsigned long)eh;
 
-               /* push exception object reference on stack */
-               uc->uc_mcontext.gregs[REG_SP] -= sizeof(exception);
-               stack = (unsigned long*)uc->uc_mcontext.gregs[REG_SP];
-               *stack = (unsigned long)exception;
-       }
+       /* push exception object reference on stack */
+       uc->uc_mcontext.gregs[REG_SP] -= sizeof(exception);
+       stack = (unsigned long*)uc->uc_mcontext.gregs[REG_SP];
+       *stack = (unsigned long)exception;
 }
diff --git a/arch/x86/unwind_32.S b/arch/x86/unwind_32.S
index df32a0d..0455c7d 100644
--- a/arch/x86/unwind_32.S
+++ b/arch/x86/unwind_32.S
@@ -55,18 +55,7 @@ unwind:
        pushl   %ebp    # frame
        pushl   %eax    # cu
        call    throw_exception_from
-       popl    %ecx    # cu -> ECX
-       addl    $12, %esp
+       addl    $16, %esp
 
-       test    %eax, %eax
-       jnz     finish
-
-       /* Jump to exit block. Do not push exception object */
-       add     $4, %esp
-       pushl   %ecx
-       call    cu_exit_bb_native_ptr
-       addl    $4, %esp
-
-finish:
        pushl %eax
        ret
diff --git a/include/jit/compilation-unit.h b/include/jit/compilation-unit.h
index 4b1891c..a7653cc 100644
--- a/include/jit/compilation-unit.h
+++ b/include/jit/compilation-unit.h
@@ -49,7 +49,6 @@ struct basic_block *find_bb(struct compilation_unit *, 
unsigned long);
 unsigned long nr_bblocks(struct compilation_unit *);
 void compute_insn_positions(struct compilation_unit *);
 int sort_basic_blocks(struct compilation_unit *);
-unsigned char *cu_exit_bb_native_ptr(struct compilation_unit *);
 
 #define for_each_variable(var, var_list) for (var = var_list; var != NULL; var 
= var->next)
 
diff --git a/jit/compilation-unit.c b/jit/compilation-unit.c
index 8d60b20..10b68c3 100644
--- a/jit/compilation-unit.c
+++ b/jit/compilation-unit.c
@@ -189,8 +189,3 @@ int sort_basic_blocks(struct compilation_unit *cu)
 {
        return list_sort(&cu->bb_list, bb_list_compare);
 }
-
-unsigned char *cu_exit_bb_native_ptr(struct compilation_unit *cu)
-{
-       return bb_native_ptr(cu->exit_bb);
-}
diff --git a/jit/exception.c b/jit/exception.c
index 2aa9b81..d0bf31e 100644
--- a/jit/exception.c
+++ b/jit/exception.c
@@ -134,10 +134,10 @@ unsigned char *throw_exception_from(struct 
compilation_unit *cu,
 
        if (!is_jit_method(frame->return_address)) {
                /* No handler found within jitted method call
-                  chain. Signal exception and return to previous
-                  (non-jitted) method. */
+                  chain. Set exception in execution environment and
+                  return to previous (not jit) method. */
                getExecEnv()->exception = exception;
-               return NULL;
+               return bb_native_ptr(cu->exit_bb);
        }
 
        return bb_native_ptr(cu->unwind_bb);
-- 
1.6.0.6


------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to