Upon exception throwing when it comes up that there is no handler in current 
method, then we must unwind to the previous one. But we know only return 
address and do not know the size of a call instruction that was used. The 
solution is to decrement the return address pointer, and then call 
native_ptr_to_bytecode_offset() which will return bytecode offset of the call 
instruction because the given address belongs to that instruction.

The solution utilises the fact, that basic blocks are emitted in order they 
appear in the list and instructions are emitted in order they appear in 
instruction lists.

Signed-off-by: Tomek Grabiec <[email protected]>
---
 jit/bc-offset-mapping.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/jit/bc-offset-mapping.c b/jit/bc-offset-mapping.c
index 707394e..67b897a 100644
--- a/jit/bc-offset-mapping.c
+++ b/jit/bc-offset-mapping.c
@@ -63,14 +63,29 @@ void tree_patch_bc_offset(struct tree_node *node, unsigned 
long bc_offset)
 unsigned long native_ptr_to_bytecode_offset(struct compilation_unit *cu,
                                            unsigned char *native_ptr)
 {
-       unsigned char *method_ptr = buffer_ptr(cu->objcode);
+       unsigned long method_addr = (unsigned long)buffer_ptr(cu->objcode);
+       unsigned long offset;
        struct basic_block *bb;
        struct insn *insn;
+       struct insn *prev_insn = NULL;
+
+       if ((unsigned long)native_ptr < method_addr)
+               return BC_OFFSET_UNKNOWN;
+
+       offset = (unsigned long)native_ptr - method_addr;
 
        for_each_basic_block(bb, &cu->bb_list) {
                for_each_insn(insn, &bb->insn_list) {
-                       if (method_ptr + insn->mach_offset == native_ptr)
+                       if (insn->mach_offset == offset)
                                return insn->bytecode_offset;
+
+                       if (insn->mach_offset > offset) {
+                               if (prev_insn->mach_offset <= offset)
+                                       return prev_insn->bytecode_offset;
+                               break;
+                       }
+
+                       prev_insn = insn;
                }
        }
 
-- 
1.6.0.6


------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to