We should build exception handler table with handler pointers
to not use basic block lookup at run-time.

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 include/jit/compilation-unit.h |    7 +++++++
 include/jit/exception.h        |    1 +
 jit/compilation-unit.c         |    2 ++
 jit/emit.c                     |    2 ++
 jit/exception.c                |   28 +++++++++++++++++++++++++++-
 5 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/include/jit/compilation-unit.h b/include/jit/compilation-unit.h
index 5c9b978..66fcb7c 100644
--- a/include/jit/compilation-unit.h
+++ b/include/jit/compilation-unit.h
@@ -83,6 +83,13 @@ struct compilation_unit {
         * This maps machine-code offset (of gc safepoint) to gc map
         */
        struct radix_tree *safepoint_map;
+
+       /*
+        * Contains native pointers of exception handlers.  Indices to
+        * this table are the same as for exception table in code
+        * attribute.
+        */
+       void **exception_handlers;
 };
 
 struct compilation_unit *compilation_unit_alloc(struct vm_method *);
diff --git a/include/jit/exception.h b/include/jit/exception.h
index 742d793..aeb6843 100644
--- a/include/jit/exception.h
+++ b/include/jit/exception.h
@@ -66,6 +66,7 @@ void init_exceptions(void);
 void thread_init_exceptions(void);
 void print_exception_table(const struct vm_method *,
        const struct cafebabe_code_attribute_exception *, int);
+int build_exception_handlers_table(struct compilation_unit *cu);
 
 static inline bool
 exception_covers(struct cafebabe_code_attribute_exception *eh, unsigned long 
offset)
diff --git a/jit/compilation-unit.c b/jit/compilation-unit.c
index c0110f3..9093d82 100644
--- a/jit/compilation-unit.c
+++ b/jit/compilation-unit.c
@@ -192,6 +192,8 @@ void free_compilation_unit(struct compilation_unit *cu)
        free_lookupswitch_list(cu);
        free_tableswitch_list(cu);
        free_lir_insn_map(cu);
+       free(cu->exception_handlers);
+
        free(cu);
 }
 
diff --git a/jit/emit.c b/jit/emit.c
index c62f1b5..0966923 100644
--- a/jit/emit.c
+++ b/jit/emit.c
@@ -17,6 +17,7 @@
 #include "jit/compilation-unit.h"
 #include "jit/basic-block.h"
 #include "jit/emit-code.h"
+#include "jit/exception.h"
 #include "jit/compiler.h"
 #include "jit/statement.h"
 #include "jit/text.h"
@@ -198,6 +199,7 @@ int emit_machine_code(struct compilation_unit *cu)
 
        backpatch_tableswitch_targets(cu);
        backpatch_lookupswitch_targets(cu);
+       build_exception_handlers_table(cu);
 
        jit_text_reserve(buffer_offset(cu->objcode));
        jit_text_unlock();
diff --git a/jit/exception.c b/jit/exception.c
index 4d9b0d9..de71618 100644
--- a/jit/exception.c
+++ b/jit/exception.c
@@ -182,6 +182,32 @@ static unsigned char *eh_native_ptr(struct 
compilation_unit *cu,
        return bb_native_ptr(bb);
 }
 
+int build_exception_handlers_table(struct compilation_unit *cu)
+{
+       struct vm_method *method;
+       int size;
+       int i;
+
+       method = cu->method;
+       size = method->code_attribute.exception_table_length;
+
+       if (size == 0)
+               return 0;
+
+       cu->exception_handlers = malloc(sizeof(void *) * size);
+       if (!cu->exception_handlers)
+               return -ENOMEM;
+
+       for (i = 0; i < size; i++) {
+               struct cafebabe_code_attribute_exception *eh
+                       = &method->code_attribute.exception_table[i];
+
+               cu->exception_handlers[i] = eh_native_ptr(cu, eh);
+       }
+
+       return 0;
+}
+
 /**
  * find_handler - return native pointer to exception handler for given
  *                @exception_class and @bc_offset of source.
@@ -216,7 +242,7 @@ static unsigned char *find_handler(struct compilation_unit 
*cu,
        }
 
        if (i < size)
-               return eh_native_ptr(cu, eh);
+               return cu->exception_handlers[i];
 
        return NULL;
 }
-- 
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

Reply via email to