We need to use whole address as a mapping key because we will have to
store compilation unit mappings for native methods too. Native
functions that implement native java methods are not aligned like
compilation unit's objcode buffer.

Signed-off-by: Tomek Grabiec <[email protected]>
---
 include/jit/cu-mapping.h |    4 ++--
 include/vm/alloc.h       |    1 -
 jit/alloc.c              |   13 -------------
 jit/cu-mapping.c         |   31 ++++++-------------------------
 jit/trampoline.c         |    2 +-
 5 files changed, 9 insertions(+), 42 deletions(-)

diff --git a/include/jit/cu-mapping.h b/include/jit/cu-mapping.h
index 2720951..357bb20 100644
--- a/include/jit/cu-mapping.h
+++ b/include/jit/cu-mapping.h
@@ -3,8 +3,8 @@
 
 struct compilation_unit;
 
-int add_cu_mapping(struct compilation_unit *cu);
-void remove_cu_mapping(struct compilation_unit *cu);
+int add_cu_mapping(unsigned long addr, struct compilation_unit *cu);
+void remove_cu_mapping(unsigned long addr);
 struct compilation_unit *get_cu_from_native_addr(unsigned long addr);
 void init_cu_mapping();
 
diff --git a/include/vm/alloc.h b/include/vm/alloc.h
index 0079c84..f268a0d 100644
--- a/include/vm/alloc.h
+++ b/include/vm/alloc.h
@@ -6,7 +6,6 @@
 struct buffer;
 
 void *alloc_page(void);
-int get_buffer_align_bits(void);
 void *alloc_exec(size_t);
 int expand_buffer_exec(struct buffer *);
 
diff --git a/jit/alloc.c b/jit/alloc.c
index 2964b20..c314ff7 100644
--- a/jit/alloc.c
+++ b/jit/alloc.c
@@ -21,19 +21,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-int get_buffer_align_bits(void)
-{
-       int page_size = getpagesize();
-       int bits = 0;
-
-       while (page_size) {
-               bits++;
-               page_size >>= 1;
-       }
-
-       return bits;
-}
-
 static void *__alloc_exec(size_t size)
 {
        int page_size;
diff --git a/jit/cu-mapping.c b/jit/cu-mapping.c
index 5e59ee3..3f9e3fc 100644
--- a/jit/cu-mapping.c
+++ b/jit/cu-mapping.c
@@ -48,56 +48,37 @@ pthread_rwlock_t cu_map_rwlock = PTHREAD_RWLOCK_INITIALIZER;
 void init_cu_mapping(void)
 {
        int key_bits = sizeof(unsigned long) * 8;
-       int viable_key_bits = key_bits - get_buffer_align_bits();
 
-       cu_map = alloc_radix_tree(BITS_PER_LEVEL, viable_key_bits);
+       cu_map = alloc_radix_tree(BITS_PER_LEVEL, key_bits);
        if (!cu_map)
                die("out of memory");
 }
 
-static unsigned long addr_key(unsigned long addr)
-{
-       return addr >> get_buffer_align_bits();
-}
-
-static unsigned long cu_key(struct compilation_unit *cu)
-{
-       return addr_key((unsigned long)buffer_ptr(cu->objcode));
-}
-
-int add_cu_mapping(struct compilation_unit *cu)
+int add_cu_mapping(unsigned long addr, struct compilation_unit *cu)
 {
        int result;
 
        pthread_rwlock_wrlock(&cu_map_rwlock);
-       result = radix_tree_insert(cu_map, cu_key(cu), cu);
+       result = radix_tree_insert(cu_map, addr, cu);
        pthread_rwlock_unlock(&cu_map_rwlock);
 
        return result;
 }
 
-void remove_cu_mapping(struct compilation_unit *cu)
+void remove_cu_mapping(unsigned long addr)
 {
        pthread_rwlock_wrlock(&cu_map_rwlock);
-       radix_tree_remove(cu_map, cu_key(cu));
+       radix_tree_remove(cu_map, addr);
        pthread_rwlock_unlock(&cu_map_rwlock);
 }
 
 struct compilation_unit *get_cu_from_native_addr(unsigned long addr)
 {
        struct compilation_unit *cu;
-       unsigned long method_addr;
 
        pthread_rwlock_rdlock(&cu_map_rwlock);
-       cu = radix_tree_lookup_prev(cu_map, addr_key(addr));
+       cu = radix_tree_lookup_prev(cu_map, addr);
        pthread_rwlock_unlock(&cu_map_rwlock);
 
-       if (cu == NULL)
-               return NULL;
-
-       method_addr = (unsigned long)buffer_ptr(cu->objcode);
-       if (method_addr + buffer_offset(cu->objcode) <= addr)
-               return NULL;
-
        return cu;
 }
diff --git a/jit/trampoline.c b/jit/trampoline.c
index c0b6507..303abc7 100644
--- a/jit/trampoline.c
+++ b/jit/trampoline.c
@@ -62,7 +62,7 @@ static void *jit_java_trampoline(struct compilation_unit *cu)
                return NULL;
        }
 
-       if (add_cu_mapping(cu) != 0)
+       if (add_cu_mapping((unsigned long)buffer_ptr(cu->objcode), cu) != 0)
                /* TODO: throw OutOfMemoryError */
                die("%s: out of memory", __func__);
 
-- 
1.6.0.6


------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to