dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dotgnu-pnet-commits] [SCM] DotGNU Portable.NET Just In Time compiler (l


From: Aleksey Demakov
Subject: [dotgnu-pnet-commits] [SCM] DotGNU Portable.NET Just In Time compiler (libjit) branch, cache-refactoring, created. d943a72457afe8013927eef5861edb7243bdd1fe
Date: Sat, 21 Jan 2012 19:18:01 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "DotGNU Portable.NET Just In Time compiler (libjit)".

The branch, cache-refactoring has been created
        at  d943a72457afe8013927eef5861edb7243bdd1fe (commit)

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/libjit.git/commit/?id=d943a72457afe8013927eef5861edb7243bdd1fe

commit d943a72457afe8013927eef5861edb7243bdd1fe
Author: Aleksey Demakov <address@hidden>
Date:   Sat Jan 21 22:11:21 2012 +0300

    move part of the jit cache functionality elsewhere, remove unused 
functionality

diff --git a/ChangeLog b/ChangeLog
index 198454d..264d3b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2012-01-21  Aleksey Demakov  <address@hidden>
+
+       * jit/jit-rules.h (struct jit_gencode): add offset_encoder field
+       to encode bytecode offsets with jit_varints.
+
+       * jit/jit-internal.h (struct _jit_function): move fields cookie,
+       start, end here from jit_cache_method; add bytecode_offset field
+       to encode bytecode offsets with jit_varints.
+
+       * jit/jit-compile.c (mark_offset, _jit_function_get_bytecode): add
+       functions that use jit_varints for bytecode offset compression.
+
+       * jit/jit-cache.h, jit/jit-cache.c (_jit_cache_get_method):
+       remove cookie argument.
+
+       * jit/jit-cache.h, jit/jit-cache.c (_jit_cache_mark_bytecode)
+       (_jit_cache_set_cookie, _jit_cache_get_start_method)
+       (_jit_cache_get_end_method, _jit_cache_get_native)
+       (_jit_cache_get_bytecode, _jit_cache_get_size): remove functions,
+       get rid of bytecode offset compression and method region machinary.
+
+       * jit/jit-dump.c, jit/jit-function.c, jit/jit-rules-interp.c
+       * jit/jit-except.c, jit/jit-unwind.c: adjust where appropriate for
+       cache API change.
+
 2011-12-18  Aleksey Demakov  <address@hidden>
 
        * jit/Makefile.am:
diff --git a/jit/jit-cache.c b/jit/jit-cache.c
index bf2ceef..b9a1eb2 100644
--- a/jit/jit-cache.c
+++ b/jit/jit-cache.c
@@ -50,18 +50,6 @@ extern       "C" {
 #endif
 
 /*
- * Structure of a debug information header for a method.
- * This header is followed by the debug data, which is
- * stored as compressed metadata integers.
- */
-typedef struct jit_cache_debug *jit_cache_debug_t;
-struct jit_cache_debug
-{
-       jit_cache_debug_t next;                 /* Next block for the method */
-
-};
-
-/*
  * Method information block, organised as a red-black tree node.
  * There may be more than one such block associated with a method
  * if the method contains exception regions.
@@ -69,14 +57,9 @@ struct jit_cache_debug
 typedef struct jit_cache_method *jit_cache_method_t;
 struct jit_cache_method
 {
-       void                    *method;        /* Method containing the region 
*/
-       void                    *cookie;        /* Cookie value for the region 
*/
-       unsigned char           *start;         /* Start of the region */
-       unsigned char           *end;           /* End of the region */
-       jit_cache_debug_t       debug;          /* Debug information for method 
*/
+       jit_function_t          func;           /* Function */
        jit_cache_method_t      left;           /* Left sub-tree and red/black 
bit */
        jit_cache_method_t      right;          /* Right sub-tree */
-
 };
 
 /*
@@ -106,196 +89,9 @@ struct jit_cache
        struct jit_cache_method head;           /* Head of the lookup tree */
        struct jit_cache_method nil;            /* Nil pointer for the lookup 
tree */
        unsigned char           *start;         /* Start of the current method 
*/
-       unsigned char           debugData[JIT_CACHE_DEBUG_SIZE];
-       int                     debugLen;       /* Length of temporary debug 
data */
-       jit_cache_debug_t       firstDebug;     /* First debug block for method 
*/
-       jit_cache_debug_t       lastDebug;      /* Last debug block for method 
*/
-
 };
 
 /*
- * Compress a "long" value so that it takes up less bytes.
- * This is used to store offsets within functions and
- * debug line numbers, which are usually small integers.
- */
-static int CompressInt(unsigned char *buf, long data)
-{
-       if(data >= 0)
-       {
-               if(data < (long)0x40)
-               {
-                       buf[0] = (unsigned char)(data << 1);
-                       return 1;
-               }
-               else if(data < (long)(1 << 13))
-               {
-                       buf[0] = (unsigned char)(((data >> 7) & 0x3F) | 0x80);
-                       buf[1] = (unsigned char)(data << 1);
-                       return 2;
-               }
-               else if(data < (long)(1L << 28))
-               {
-                       buf[0] = (unsigned char)((data >> 23) | 0xC0);
-                       buf[1] = (unsigned char)(data >> 15);
-                       buf[2] = (unsigned char)(data >> 7);
-                       buf[3] = (unsigned char)(data << 1);
-                       return 4;
-               }
-               else
-               {
-                       buf[0] = (unsigned char)0xE0;
-                       buf[1] = (unsigned char)(data >> 23);
-                       buf[2] = (unsigned char)(data >> 15);
-                       buf[3] = (unsigned char)(data >> 7);
-                       buf[4] = (unsigned char)(data << 1);
-                       return 5;
-               }
-       }
-       else
-       {
-               if(data >= ((long)-0x40))
-               {
-                       buf[0] = ((((unsigned char)(data << 1)) & 0x7E) | 0x01);
-                       return 1;
-               }
-               else if(data >= ((long)-(1 << 13)))
-               {
-                       buf[0] = (unsigned char)(((data >> 7) & 0x3F) | 0x80);
-                       buf[1] = (unsigned char)((data << 1) | 0x01);
-                       return 2;
-               }
-               else if(data >= ((long)-(1L << 29)))
-               {
-                       buf[0] = (unsigned char)(((data >> 23) & 0x1F) | 0xC0);
-                       buf[1] = (unsigned char)(data >> 15);
-                       buf[2] = (unsigned char)(data >> 7);
-                       buf[3] = (unsigned char)((data << 1) | 0x01);
-                       return 4;
-               }
-               else
-               {
-                       buf[0] = (unsigned char)0xE1;
-                       buf[1] = (unsigned char)(data >> 23);
-                       buf[2] = (unsigned char)(data >> 15);
-                       buf[3] = (unsigned char)(data >> 7);
-                       buf[4] = (unsigned char)((data << 1) | 0x01);
-                       return 5;
-               }
-       }
-}
-
-/*
- * Control data structure that is used by "UncompressInt".
- */
-typedef struct
-{
-       const unsigned char     *data;          /* Current data position */
-       unsigned long            len;           /* Length remaining to read */
-       int                      error;         /* Set to non-zero if error 
encountered */
-
-} UncompressReader;
-
-/*
- * Uncompress a value that was compressed by "CompressInt".
- */
-static long UncompressInt(UncompressReader *meta)
-{
-       unsigned char ch;
-       unsigned char ch2;
-       unsigned char ch3;
-       unsigned char ch4;
-       unsigned long value;
-
-       if(meta->len > 0)
-       {
-               ch = *((meta->data)++);
-               --(meta->len);
-               if((ch & 0x80) == 0x00)
-               {
-                       /* One-byte form of the item */
-                       if((ch & 0x01) == 0x00)
-                               return (long)(ch >> 1);
-                       else
-                               return (long)(signed char)((ch >> 1) | 0xC0);
-               }
-               else if((ch & 0xC0) == 0x80)
-               {
-                       /* Two-byte form of the item */
-                       if(meta->len > 0)
-                       {
-                               --(meta->len);
-                               value = (((unsigned long)(ch & 0x3F)) << 8) |
-                                            ((unsigned 
long)(*((meta->data)++)));
-                               if((value & 0x01) == 0x00)
-                                       return (long)(value >> 1);
-                               else
-                                       return (long)(jit_int)((value >> 1) | 
0xFFFFE000);
-                       }
-                       else
-                       {
-                               meta->error = 1;
-                               return 0;
-                       }
-               }
-               else if((ch & 0xE0) == 0xC0)
-               {
-                       /* Four-byte form of the item */
-                       if(meta->len >= 3)
-                       {
-                               ch2 = meta->data[0];
-                               ch3 = meta->data[1];
-                               ch4 = meta->data[2];
-                               meta->len -= 3;
-                               meta->data += 3;
-                               value = (((unsigned long)(ch & 0x1F)) << 24) |
-                                           (((unsigned long)ch2) << 16) |
-                                           (((unsigned long)ch3) << 8) |
-                                            ((unsigned long)ch4);
-                               if((value & 0x01) == 0x00)
-                                       return (long)(value >> 1);
-                               else
-                                       return (long)(jit_int)((value >> 1) | 
0xF0000000);
-                       }
-                       else
-                       {
-                               meta->len = 0;
-                               meta->error = 1;
-                               return 0;
-                       }
-               }
-               else
-               {
-                       /* Five-byte form of the item */
-                       if(meta->len >= 4)
-                       {
-                               ch  = meta->data[0];
-                               ch2 = meta->data[1];
-                               ch3 = meta->data[2];
-                               ch4 = meta->data[3];
-                               meta->len -= 4;
-                               meta->data += 4;
-                               value = (((unsigned long)ch) << 24) |
-                                           (((unsigned long)ch2) << 16) |
-                                           (((unsigned long)ch3) << 8) |
-                                            ((unsigned long)ch4);
-                               return (long)(jit_int)value;
-                       }
-                       else
-                       {
-                               meta->len = 0;
-                               meta->error = 1;
-                               return 0;
-                       }
-               }
-       }
-       else
-       {
-               meta->error = 1;
-               return 0;
-       }
-}
-
-/*
  * Allocate a cache page and add it to the cache.
  */
 static void AllocCachePage(jit_cache_t cache, int factor)
@@ -416,11 +212,11 @@ static int CacheCompare(jit_cache_t cache, unsigned char 
*key,
        else
        {
                /* Compare a regular node */
-               if(key < node->start)
+               if(key < node->func->start)
                {
                        return -1;
                }
-               else if(key > node->start)
+               else if(key > node->func->start)
                {
                        return 1;
                }
@@ -499,7 +295,7 @@ static jit_cache_method_t CacheRotate(jit_cache_t cache, 
unsigned char *key,
  */
 static void AddToLookupTree(jit_cache_t cache, jit_cache_method_t method)
 {
-       unsigned char *key = method->start;
+       unsigned char *key = method->func->start;
        jit_cache_method_t temp;
        jit_cache_method_t greatGrandParent;
        jit_cache_method_t grandParent;
@@ -558,66 +354,6 @@ static void AddToLookupTree(jit_cache_t cache, 
jit_cache_method_t method)
        SetBlack(cache->head.right);
 }
 
-/*
- * Flush the current debug buffer.
- */
-static void FlushCacheDebug(jit_cache_posn *posn)
-{
-       jit_cache_t cache = posn->cache;
-       jit_cache_debug_t debug;
-
-       /* Allocate a new jit_cache_debug structure to hold the data */
-       debug = _jit_cache_alloc(posn,
-               (unsigned long)(sizeof(struct jit_cache_debug) + 
cache->debugLen));
-       if(!debug)
-       {
-               cache->debugLen = 0;
-               return;
-       }
-
-       /* Copy the temporary debug data into the new structure */
-       jit_memcpy(debug + 1, cache->debugData, cache->debugLen);
-
-       /* Link the structure into the debug list */
-       debug->next = 0;
-       if(cache->lastDebug)
-       {
-               cache->lastDebug->next = debug;
-       }
-       else
-       {
-               cache->firstDebug = debug;
-       }
-       cache->lastDebug = debug;
-
-       /* Reset the temporary debug buffer */
-       cache->debugLen = 0;
-}
-
-/*
- * Write a debug pair to the cache.  The pair (-1, -1)
- * terminates the debug information for a method.
- */
-static void WriteCacheDebug(jit_cache_posn *posn, long offset, long 
nativeOffset)
-{
-       jit_cache_t cache = posn->cache;
-
-       /* Write the two values to the temporary debug buffer */
-       cache->debugLen += CompressInt
-               (cache->debugData + cache->debugLen, offset);
-       cache->debugLen += CompressInt
-               (cache->debugData + cache->debugLen, nativeOffset);
-       if((cache->debugLen + 5 * 2 + 1) > (int)(sizeof(cache->debugData)))
-       {
-               /* Overflow occurred: write -2 to mark the end of this buffer */
-               cache->debugLen += CompressInt
-                               (cache->debugData + cache->debugLen, -2);
-
-               /* Flush the debug data that we have collected so far */
-               FlushCacheDebug(posn);
-       }
-}
-
 jit_cache_t _jit_cache_create(long limit, long cache_page_size, int 
max_page_factor)
 {
        jit_cache_t cache;
@@ -671,24 +407,13 @@ jit_cache_t _jit_cache_create(long limit, long 
cache_page_size, int max_page_fac
                cache->pagesLeft = -1;
        }
        cache->method = 0;
-       cache->nil.method = 0;
-       cache->nil.cookie = 0;
-       cache->nil.start = 0;
-       cache->nil.end = 0;
-       cache->nil.debug = 0;
+       cache->nil.func = 0;
        cache->nil.left = &(cache->nil);
        cache->nil.right = &(cache->nil);
-       cache->head.method = 0;
-       cache->head.cookie = 0;
-       cache->head.start = 0;
-       cache->head.end = 0;
-       cache->head.debug = 0;
+       cache->head.func = 0;
        cache->head.left = 0;
        cache->head.right = &(cache->nil);
        cache->start = 0;
-       cache->debugLen = 0;
-       cache->firstDebug = 0;
-       cache->lastDebug = 0;
 
        /* Allocate the initial cache page */
        AllocCachePage(cache, 0);
@@ -741,7 +466,7 @@ int _jit_cache_start_method(jit_cache_t cache,
                            jit_cache_posn *posn,
                            int page_factor,
                            int align,
-                           void *method)
+                           jit_function_t func)
 {
        unsigned char *ptr;
 
@@ -789,22 +514,15 @@ int _jit_cache_start_method(jit_cache_t cache,
                /* There is insufficient space in this page */
                return JIT_CACHE_RESTART;
        }
-       cache->method->method = method;
-       cache->method->cookie = 0;
-       cache->method->start = posn->ptr;
-       cache->method->end = posn->ptr;
-       cache->method->debug = 0;
+       cache->method->func = func;
+       cache->method->func->start = posn->ptr;
+       cache->method->func->end = posn->ptr;
        cache->method->left = 0;
        cache->method->right = 0;
 
        /* Store the method start address */
        cache->start = posn->ptr;
 
-       /* Clear the debug data */
-       cache->debugLen = 0;
-       cache->firstDebug = 0;
-       cache->lastDebug = 0;
-
        return JIT_CACHE_OK;
 }
 
@@ -836,16 +554,6 @@ int _jit_cache_end_method(jit_cache_posn *posn)
                return JIT_CACHE_RESTART;
        }
 
-       /* Terminate the debug information and flush it */
-       if(cache->firstDebug || cache->debugLen)
-       {
-               WriteCacheDebug(posn, -1, -1);
-               if(cache->debugLen)
-               {
-                       FlushCacheDebug(posn);
-               }
-       }
-
        /* Flush the position information back to the cache */
        cache->freeStart = posn->ptr;
        cache->freeEnd = posn->limit;
@@ -855,10 +563,9 @@ int _jit_cache_end_method(jit_cache_posn *posn)
        method = cache->method;
        if(method)
        {
-               method->end = posn->ptr;
+               method->func->end = posn->ptr;
                do
                {
-                       method->debug = cache->firstDebug;
                        next = method->right;
                        AddToLookupTree(cache, method);
                        method = next;
@@ -968,347 +675,29 @@ void _jit_cache_align(jit_cache_posn *posn, int align, 
int diff, int nop)
 #endif
 }
 
-void _jit_cache_mark_bytecode(jit_cache_posn *posn, unsigned long offset)
-{
-       WriteCacheDebug(posn, (long)offset,
-                                   (long)(posn->ptr - posn->cache->start));
-}
-
-void _jit_cache_set_cookie(jit_cache_posn *posn, void *cookie)
-{
-       if(posn->cache->method)
-       {
-               posn->cache->method->cookie = cookie;
-       }
-}
-
-void *_jit_cache_get_method(jit_cache_t cache, void *pc, void **cookie)
+jit_function_t
+_jit_cache_get_method(jit_cache_t cache, void *pc)
 {
        jit_cache_method_t node = cache->head.right;
        while(node != &(cache->nil))
        {
-               if(((unsigned char *)pc) < node->start)
+               if(((unsigned char *)pc) < node->func->start)
                {
                        node = GetLeft(node);
                }
-               else if(((unsigned char *)pc) >= node->end)
+               else if(((unsigned char *)pc) >= node->func->end)
                {
                        node = GetRight(node);
                }
                else
                {
-                       if(cookie)
-                       {
-                               *cookie = node->cookie;
-                       }
-                       return node->method;
+                       return node->func;
                }
        }
        return 0;
 }
 
 /*
- * Add a parent pointer to a list.  Returns null if out of memory.
- */
-static int add_parent(jit_cache_method_t *parent_buf,
-                                         jit_cache_method_t **parents,
-                                         int *num_parents, int *max_parents,
-                                         jit_cache_method_t node)
-{
-       jit_cache_method_t *new_list;
-       if(*num_parents >= *max_parents)
-       {
-               if(*parents == parent_buf)
-               {
-                       new_list = (jit_cache_method_t *)jit_malloc
-                               ((*max_parents * 2) * 
sizeof(jit_cache_method_t));
-                       if(new_list)
-                       {
-                               jit_memcpy(new_list, *parents,
-                                                  (*num_parents) * 
sizeof(jit_cache_method_t));
-                       }
-               }
-               else
-               {
-                       new_list = (jit_cache_method_t *)jit_realloc
-                               (*parents, (*max_parents * 2) * 
sizeof(jit_cache_method_t));
-               }
-               if(!new_list)
-               {
-                       return 0;
-               }
-               *parents = new_list;
-               *max_parents *= 2;
-       }
-       (*parents)[*num_parents] = node;
-       ++(*num_parents);
-       return 1;
-}
-
-void *_jit_cache_get_start_method(jit_cache_t cache, void *pc)
-{
-       /* TODO: This function is not currently aware of multiple regions. */
-       jit_cache_method_t node = cache->head.right;
-       while(node != &(cache->nil))
-       {
-               if(((unsigned char *)pc) < node->start)
-               {
-                       node = GetLeft(node);
-               }
-               else if(((unsigned char *)pc) >= node->end)
-               {
-                       node = GetRight(node);
-               }
-               else
-               {
-                       return node->start;
-               }
-       }
-       return 0;
-}
-
-void *_jit_cache_get_end_method(jit_cache_t cache, void *pc)
-{
-       jit_cache_method_t parent_buf[16];
-       jit_cache_method_t *parents = parent_buf;
-       int num_parents = 0;
-       int max_parents = 16;
-       jit_cache_method_t node = cache->head.right;
-       jit_cache_method_t last;
-       jit_cache_method_t parent;
-       void *method;
-       while(node != &(cache->nil))
-       {
-               if(((unsigned char *)pc) < node->start)
-               {
-                       if(!add_parent(parent_buf, &parents, &num_parents,
-                          &max_parents, node))
-                       {
-                               break;
-                       }
-                       node = GetLeft(node);
-               }
-               else if(((unsigned char *)pc) >= node->end)
-               {
-                       if(!add_parent(parent_buf, &parents, &num_parents,
-                          &max_parents, node))
-                       {
-                               break;
-                       }
-                       node = GetRight(node);
-               }
-               else
-               {
-                       /* This is the node that contains the starting position.
-                          We now need to do an inorder traversal from this 
point
-                          to find the last node that mentions this method */
-                       method = node->method;
-                       last = node;
-                       do
-                       {
-                               if(GetRight(node) != &(cache->nil))
-                               {
-                                       /* Move down the left-most sub-tree of 
the right */
-                                       if(!add_parent(parent_buf, &parents, 
&num_parents,
-                                          &max_parents, node))
-                                       {
-                                               goto failed;
-                                       }
-                                       node = GetRight(node);
-                                       while(GetLeft(node) != &(cache->nil))
-                                       {
-                                               if(!add_parent(parent_buf, 
&parents, &num_parents,
-                                                  &max_parents, node))
-                                               {
-                                                       goto failed;
-                                               }
-                                               node = GetLeft(node);
-                                       }
-                               }
-                               else
-                               {
-                                       /* Find a parent or other ancestor that 
contains this
-                                          node within its left sub-tree */
-                                       for(;;)
-                                       {
-                                               if(num_parents == 0)
-                                               {
-                                                       node = 0;
-                                                       break;
-                                               }
-                                               parent = parents[--num_parents];
-                                               if(GetLeft(parent) == node)
-                                               {
-                                                       /* We are on our 
parent's left, so next is parent */
-                                                       node = parent;
-                                                       break;
-                                               }
-                                               node = parent;
-                                       }
-                                       if(!node)
-                                       {
-                                               /* We reached the root of the 
tree */
-                                               break;
-                                       }
-                               }
-                               if(node->method == method)
-                               {
-                                       last = node;
-                               }
-                       }
-                       while(node->method == method);
-                       if(parents != parent_buf)
-                       {
-                               jit_free(parents);
-                       }
-                       return last->end;
-               }
-       }
-failed:
-       if(parents != parent_buf)
-       {
-               jit_free(parents);
-       }
-       return 0;
-}
-
-/*
- * Temporary structure for iterating over a method's debug list.
- */
-typedef struct
-{
-       jit_cache_debug_t       list;
-       UncompressReader        reader;
-
-} jit_cache_debug_iter;
-
-/*
- * Initialize a debug information list iterator for a method.
- */
-static void InitDebugIter(jit_cache_debug_iter *iter,
-                                                 jit_cache_t cache, void 
*start)
-{
-       jit_cache_method_t node = cache->head.right;
-       while(node != &(cache->nil))
-       {
-               if(((unsigned char *)start) < node->start)
-               {
-                       node = GetLeft(node);
-               }
-               else if(((unsigned char *)start) >= node->end)
-               {
-                       node = GetRight(node);
-               }
-               else
-               {
-                       iter->list = node->debug;
-                       if(iter->list)
-                       {
-                               iter->reader.data = (unsigned char 
*)(iter->list + 1);
-                               iter->reader.len = JIT_CACHE_DEBUG_SIZE;
-                               iter->reader.error = 0;
-                       }
-                       return;
-               }
-       }
-       iter->list = 0;
-}
-
-/*
- * Get the next debug offset pair from a debug information list.
- * Returns non-zero if OK, or zero at the end of the list.
- */
-static int GetNextDebug(jit_cache_debug_iter *iter, unsigned long *offset,
-                                               unsigned long *nativeOffset)
-{
-       long value;
-       while(iter->list)
-       {
-               value = UncompressInt(&(iter->reader));
-               if(value == -1)
-               {
-                       return 0;
-               }
-               else if(value != -2)
-               {
-                       *offset = (unsigned long)value;
-                       *nativeOffset = (unsigned 
long)(UncompressInt(&(iter->reader)));
-                       return 1;
-               }
-               iter->list = iter->list->next;
-               if(iter->list)
-               {
-                       iter->reader.data = (unsigned char *)(iter->list + 1);
-                       iter->reader.len = JIT_CACHE_DEBUG_SIZE;
-                       iter->reader.error = 0;
-               }
-       }
-       return 0;
-}
-
-unsigned long _jit_cache_get_native(jit_cache_t cache, void *start,
-                                                                       
unsigned long offset, int exact)
-{
-       jit_cache_debug_iter iter;
-       unsigned long ofs, nativeOfs;
-       unsigned long prevNativeOfs = JIT_CACHE_NO_OFFSET;
-
-       /* Search for the bytecode offset */
-       InitDebugIter(&iter, cache, start);
-       while(GetNextDebug(&iter, &ofs, &nativeOfs))
-       {
-               if(exact)
-               {
-                       if(ofs == offset)
-                       {
-                               return nativeOfs;
-                       }
-               }
-               else if(ofs > offset)
-               {
-                       return prevNativeOfs;
-               }
-               prevNativeOfs = nativeOfs;
-       }
-
-       return exact ? JIT_CACHE_NO_OFFSET : prevNativeOfs;
-}
-
-unsigned long _jit_cache_get_bytecode(jit_cache_t cache, void *start,
-                                                                         
unsigned long offset, int exact)
-{
-       jit_cache_debug_iter iter;
-       unsigned long ofs, nativeOfs;
-       unsigned long prevOfs = JIT_CACHE_NO_OFFSET;
-
-       /* Search for the native offset */
-       InitDebugIter(&iter, cache, start);
-       while(GetNextDebug(&iter, &ofs, &nativeOfs))
-       {
-               if(exact)
-               {
-                       if(nativeOfs == offset)
-                       {
-                               return ofs;
-                       }
-               }
-               else if(nativeOfs > offset)
-               {
-                       return prevOfs;
-               }
-               prevOfs = ofs;
-       }
-
-       return exact ? JIT_CACHE_NO_OFFSET : prevOfs;
-}
-
-unsigned long _jit_cache_get_size(jit_cache_t cache)
-{
-       return (cache->numPages * cache->pageSize) -
-                  (cache->freeEnd - cache->freeStart);
-}
-
-/*
 
 Using the cache
 ---------------
@@ -1388,21 +777,21 @@ Cache data structure
 --------------------
 
 The cache consists of one or more "cache pages", which contain method
-code and auxillary data.  The default size for a cache page is 64k
+code and auxiliary data.  The default size for a cache page is 64k
 (JIT_CACHE_PAGE_SIZE).  The size is adjusted to be a multiple
 of the system page size (usually 4k), and then stored in "pageSize".
 
 Method code is written into a cache page starting at the bottom of the
-page, and growing upwards.  Auxillary data is written into a cache page
+page, and growing upwards.  Auxiliary data is written into a cache page
 starting at the top of the page, and growing downwards.  When the two
 regions meet, a new cache page is allocated and the process restarts.
 
 To allow methods bigger than a single cache page it is possible to
 allocate a block of consecutive pages as a single unit. The method
-code and auxillary data is written to such a multiple-page block in
+code and auxiliary data is written to such a multiple-page block in
 the same manner as into an ordinary page.
 
-Each method has one or more jit_cache_method auxillary data blocks associated
+Each method has one or more jit_cache_method auxiliary data blocks associated
 with it.  These blocks indicate the start and end of regions within the
 method.  Normally these regions correspond to exception "try" blocks, or
 regular code between "try" blocks.
@@ -1415,7 +804,7 @@ processing.
 Each method can also have offset information associated with it, to map
 between native code addresses and offsets within the original bytecode.
 This is typically used to support debugging.  Offset information is stored
-as auxillary data, attached to the jit_cache_method block.
+as auxiliary data, attached to the jit_cache_method block.
 
 Threading issues
 ----------------
diff --git a/jit/jit-cache.h b/jit/jit-cache.h
index ea04bee..2c1c849 100644
--- a/jit/jit-cache.h
+++ b/jit/jit-cache.h
@@ -96,7 +96,7 @@ int _jit_cache_start_method(jit_cache_t cache,
                            jit_cache_posn *posn,
                            int page_factor,
                            int align,
-                           void *cookie);
+                           jit_function_t func);
 
 /*
  * End output of a method.  Returns zero if a restart.
@@ -127,60 +127,11 @@ void *_jit_cache_alloc_no_method
 void _jit_cache_align(jit_cache_posn *posn, int align, int diff, int nop);
 
 /*
- * Mark the current position with a bytecode offset value.
- */
-void _jit_cache_mark_bytecode(jit_cache_posn *posn, unsigned long offset);
-
-/*
- * Set the exception region cookie for the current region.
- */
-void _jit_cache_set_cookie(jit_cache_posn *posn, void *cookie);
-
-/*
  * Find the method that is associated with a particular
  * program counter.  Returns NULL if the PC is not associated
- * with a method within the cache.  The exception region
- * cookie is returned in "*cookie", if "cookie" is not NULL.
- */
-void *_jit_cache_get_method(jit_cache_t cache, void *pc, void **cookie);
-
-/*
- * Get the start of a method with a particular starting PC.
- * Returns NULL if the PC could not be located.
- * NOTE: This function is not currently aware of the
- * possibility of multiple regions per function. To ensure
- * correct results the ``pc'' argument has to be in the
- * first region.
- */
-void *_jit_cache_get_start_method(jit_cache_t cache, void *pc);
-
-/*
- * Get the end of a method with a particular starting PC.
- * Returns NULL if the PC could not be located.
- */
-void *_jit_cache_get_end_method(jit_cache_t cache, void *pc);
-
-/*
- * Get the native offset that is associated with a bytecode
- * offset within a method.  The value "start" indicates the
- * entry point for the method.  Returns JIT_CACHE_NO_OFFSET
- * if the native offset could not be determined.
- */
-#define        JIT_CACHE_NO_OFFSET             (~((unsigned long)0))
-unsigned long _jit_cache_get_native(jit_cache_t cache, void *start, unsigned 
long offset, int exact);
-
-/*
- * Get the bytecode offset that is associated with a native
- * offset within a method.  The value "start" indicates the
- * entry point for the method.  Returns JIT_CACHE_NO_OFFSET
- * if the bytecode offset could not be determined.
- */
-unsigned long _jit_cache_get_bytecode(jit_cache_t cache, void *start, unsigned 
long offset, int exact);
-
-/*
- * Get the number of bytes currently in use in the method cache.
+ * with a method within the cache.
  */
-unsigned long _jit_cache_get_size(jit_cache_t cache);
+jit_function_t _jit_cache_get_method(jit_cache_t cache, void *pc);
 
 /*
  * Convert a return address into a program counter value
diff --git a/jit/jit-compile.c b/jit/jit-compile.c
index 9246172..dfc0ffe 100644
--- a/jit/jit-compile.c
+++ b/jit/jit-compile.c
@@ -153,6 +153,24 @@ jit_optimize(jit_function_t func)
 }
 
 /*
+ * Mark the current position with a bytecode offset value.
+ */
+void
+mark_offset(jit_gencode_t gen, jit_function_t func, unsigned long offset)
+{
+       unsigned char *ptr = jit_cache_get_posn(&gen->posn);
+       unsigned long native_offset = ptr - func->start;
+       if(!_jit_varint_encode_uint(&gen->offset_encoder, (jit_uint) offset))
+       {
+               jit_exception_builtin(JIT_RESULT_OUT_OF_MEMORY);
+       }
+       if(!_jit_varint_encode_uint(&gen->offset_encoder, (jit_uint) 
native_offset))
+       {
+               jit_exception_builtin(JIT_RESULT_OUT_OF_MEMORY);
+       }
+}
+
+/*
  * Compile a single basic block within a function.
  */
 static void
@@ -269,9 +287,7 @@ compile_block(jit_gencode_t gen, jit_function_t func, 
jit_block_t block)
                case JIT_OP_MARK_OFFSET:
                        /* Mark the current code position as corresponding
                           to a particular bytecode offset */
-                       _jit_cache_mark_bytecode(&gen->posn,
-                                                (unsigned long)(long)
-                                                
jit_value_get_nint_constant(insn->value1));
+                       mark_offset(gen, func, (unsigned 
long)(long)jit_value_get_nint_constant(insn->value1));
                        break;
 
                default:
@@ -429,6 +445,9 @@ cache_alloc(_jit_compile_t *state)
                jit_exception_builtin(JIT_RESULT_OUT_OF_MEMORY);
        }
 
+       /* Prepare the bytecode offset encoder */
+       _jit_varint_init_encoder(&state->gen.offset_encoder);
+
        /* On success remember the cache state */
        state->cache_started = 1;
 }
@@ -469,6 +488,13 @@ cache_flush(_jit_compile_t *state)
                jit_flush_exec(state->code_start,
                               (unsigned int)(state->code_end - 
state->code_start));
 #endif
+
+               /* Terminate the debug information and flush it */
+               if(!_jit_varint_encode_end(&state->gen.offset_encoder))
+               {
+                       jit_exception_builtin(JIT_RESULT_OUT_OF_MEMORY);
+               }
+               state->func->bytecode_offset = 
_jit_varint_get_data(&state->gen.offset_encoder);
        }
 }
 
@@ -489,6 +515,9 @@ cache_abort(_jit_compile_t *state)
 
                /* Actually release the cache space */
                _jit_cache_end_method(&state->gen.posn);
+
+               /* Free encoded bytecode offset data */
+               
_jit_varint_free_data(_jit_varint_get_data(&state->gen.offset_encoder));
        }
 }
 
@@ -518,6 +547,9 @@ cache_realloc(_jit_compile_t *state)
 
        state->page_factor *= 2;
 
+       /* Prepare the bytecode offset encoder */
+       _jit_varint_init_encoder(&state->gen.offset_encoder);
+
        /* On success remember the cache state */
        state->cache_started = 1;
 }
@@ -950,3 +982,56 @@ _jit_function_compile_on_demand(jit_function_t func)
 
        return func->entry_point;
 }
+
+#define        JIT_CACHE_NO_OFFSET             (~((unsigned long)0))
+
+unsigned long
+_jit_function_get_bytecode(jit_function_t func, void *pc, int exact)
+{
+       unsigned long offset = JIT_CACHE_NO_OFFSET;
+       jit_cache_t cache;
+       void *start;
+       unsigned long native_offset;
+       jit_varint_decoder_t decoder;
+       jit_uint off, noff;
+
+       cache = _jit_context_get_cache(func->context);
+
+#ifdef JIT_PROLOG_SIZE
+       start = func->start;
+#else
+       start = func->entry_point;
+#endif
+
+       native_offset = pc - start;
+
+       _jit_varint_init_decoder(&decoder, func->bytecode_offset);
+       for(;;)
+       {
+               off = _jit_varint_decode_uint(&decoder);
+               noff = _jit_varint_decode_uint(&decoder);
+               if(_jit_varint_decode_end(&decoder))
+               {
+                       if(exact)
+                       {
+                               offset = JIT_CACHE_NO_OFFSET;
+                       }
+                       break;
+               }
+               if(noff >= native_offset)
+               {
+                       if(noff == native_offset)
+                       {
+                               offset = off;
+                       }
+                       else if (exact)
+                       {
+                               offset = JIT_CACHE_NO_OFFSET;
+                       }
+                       break;
+               }
+               offset = off;
+       }
+
+       return offset;
+}
diff --git a/jit/jit-dump.c b/jit/jit-dump.c
index de6ac29..5e9cb0a 100644
--- a/jit/jit-dump.c
+++ b/jit/jit-dump.c
@@ -887,8 +887,6 @@ void jit_dump_function(FILE *stream, jit_function_t func, 
const char *name)
        }
        else if(func->is_compiled)
        {
-               void *end = _jit_cache_get_end_method
-                       (func->context->cache, func->entry_point);
 #if defined(JIT_BACKEND_INTERP)
                /* Dump the interpreter's bytecode representation */
                jit_function_interp_t interp;
@@ -897,9 +895,9 @@ void jit_dump_function(FILE *stream, jit_function_t func, 
const char *name)
                                (long)(jit_nint)interp, (long)(jit_nint)func,
                                (int)(interp->args_size), 
(int)(interp->frame_size),
                                (int)(interp->working_area));
-               dump_interp_code(stream, (void **)(interp + 1), (void **)end);
+               dump_interp_code(stream, (void **)(interp + 1), (void 
**)func->end);
 #else
-               dump_object_code(stream, func->entry_point, end);
+               dump_object_code(stream, func->entry_point, func->end);
 #endif
        }
 
diff --git a/jit/jit-except.c b/jit/jit-except.c
index ae391f6..abde516 100644
--- a/jit/jit-except.c
+++ b/jit/jit-except.c
@@ -400,8 +400,7 @@ jit_function_t jit_stack_trace_get_function
                jit_cache_t cache = _jit_context_get_cache(context);
                if(cache)
                {
-                       return (jit_function_t)_jit_cache_get_method
-                               (cache, trace->items[posn], 0);
+                       return _jit_cache_get_method(cache, trace->items[posn]);
                }
        }
        return 0;
@@ -442,18 +441,10 @@ unsigned int jit_stack_trace_get_offset
                jit_cache_t cache = _jit_context_get_cache(context);
                if(cache)
                {
-                       jit_function_t func = (jit_function_t) 
_jit_cache_get_method
-                               (cache, trace->items[posn], 0);
+                       jit_function_t func = _jit_cache_get_method(cache, 
trace->items[posn]);
                        if (func)
                        {
-#ifdef JIT_PROLOG_SIZE
-                               void *start = _jit_cache_get_start_method
-                                       (cache, func->entry_point);
-#else
-                               void *start = func->entry_point;
-#endif
-                               unsigned long offset = trace->items[posn] - 
start;
-                               return _jit_cache_get_bytecode(cache, start, 
offset, 0);
+                               return _jit_function_get_bytecode(func, 
trace->items[posn], 0);
                        }
                }
        }
diff --git a/jit/jit-function.c b/jit/jit-function.c
index 3cdc580..0e4a6ef 100644
--- a/jit/jit-function.c
+++ b/jit/jit-function.c
@@ -258,6 +258,7 @@ void _jit_function_destroy(jit_function_t func)
                func->context->functions = func->next;
        }
        _jit_function_free_builder(func);
+       _jit_varint_free_data(func->bytecode_offset);
        jit_meta_destroy(&(func->meta));
        jit_type_free(func->signature);
        jit_free(func);
@@ -639,13 +640,11 @@ void *jit_function_to_closure(jit_function_t func)
 @*/
 jit_function_t jit_function_from_closure(jit_context_t context, void *closure)
 {
-       void *cookie;
        if(!context || !(context->cache))
        {
                return 0;
        }
-       return (jit_function_t)_jit_cache_get_method
-               (context->cache, closure, &cookie);
+       return _jit_cache_get_method(context->cache, closure);
 }
 
 /*@
@@ -669,11 +668,12 @@ jit_function_t jit_function_from_pc
        }
 
        /* Get the function and the exception handler cookie */
-       func = (jit_function_t)_jit_cache_get_method(context->cache, pc, 
&cookie);
+       func = _jit_cache_get_method(context->cache, pc);
        if(!func)
        {
                return 0;
        }
+       cookie = func->cookie;
 
        /* Convert the cookie into a handler address */
        if(handler)
@@ -744,13 +744,11 @@ jit_function_t 
jit_function_from_vtable_pointer(jit_context_t context, void *vta
        }
        return 0;
 #else
-       void *cookie;
        if(!context || !(context->cache))
        {
                return 0;
        }
-       return (jit_function_t)_jit_cache_get_method
-               (context->cache, vtable_pointer, &cookie);
+       return _jit_cache_get_method(context->cache, vtable_pointer);
 #endif
 }
 
diff --git a/jit/jit-init.c b/jit/jit-init.c
index 5b08c8a..3885f12 100644
--- a/jit/jit-init.c
+++ b/jit/jit-init.c
@@ -21,6 +21,7 @@
  */
 
 #include "jit-internal.h"
+#include "jit-rules.h"
 
 /*@
  * @deftypefun void jit_init (void)
diff --git a/jit/jit-internal.h b/jit/jit-internal.h
index 911348e..b6cb2bb 100644
--- a/jit/jit-internal.h
+++ b/jit/jit-internal.h
@@ -41,6 +41,11 @@ extern       "C" {
 #include "jit-thread.h"
 
 /*
+ * Include varint encoding for bytecode offset data.
+ */
+#include "jit-varint.h"
+
+/*
  * The following is some macro magic that attempts to detect
  * the best alignment to use on the target platform.  The final
  * value, "JIT_BEST_ALIGNMENT", will be a compile-time constant.
@@ -432,6 +437,12 @@ struct _jit_function
        /* The builder information for this function */
        jit_builder_t           builder;
 
+       /* Debug information for this function */
+       jit_varint_data_t       bytecode_offset;
+
+       /* Cookie value for this function */
+       void                    *cookie;
+
        /* Flag bits for this function */
        unsigned                is_recompilable : 1;
        unsigned                is_optimized : 1;
@@ -443,6 +454,11 @@ struct _jit_function
        /* Flag set once the function is compiled */
        int volatile            is_compiled;
 
+       /* Start of the cache region */
+       unsigned char           *start;
+       /* End of the cache region */
+       unsigned char           *end;
+
        /* The entry point for the function's compiled code */
        void * volatile         entry_point;
 
@@ -490,6 +506,13 @@ void _jit_function_compute_liveness(jit_function_t func);
 void *_jit_function_compile_on_demand(jit_function_t func);
 
 /*
+ * Get the bytecode offset that is associated with a native
+ * offset within a method.  Returns JIT_CACHE_NO_OFFSET
+ * if the bytecode offset could not be determined.
+ */
+unsigned long _jit_function_get_bytecode(jit_function_t func, void *pc, int 
exact);
+
+/*
  * Information about a registered external symbol.
  */
 typedef struct jit_regsym *jit_regsym_t;
diff --git a/jit/jit-rules-interp.c b/jit/jit-rules-interp.c
index 7cccde3..0aebe23 100644
--- a/jit/jit-rules-interp.c
+++ b/jit/jit-rules-interp.c
@@ -1603,7 +1603,7 @@ void _jit_gen_start_block(jit_gencode_t gen, jit_block_t 
block)
        if(block->label == block->func->builder->catcher_label &&
           block->func->has_try)
        {
-               _jit_cache_set_cookie(&(gen->posn), block->address);
+               block->func->cookie = block->address;
        }
 }
 
diff --git a/jit/jit-rules.h b/jit/jit-rules.h
index 67909ff..4ff23f4 100644
--- a/jit/jit-rules.h
+++ b/jit/jit-rules.h
@@ -173,6 +173,7 @@ struct jit_gencode
 #endif
        void                    *epilog_fixup;  /* Fixup list for function 
epilogs */
        int                     stack_changed;  /* Stack top changed since 
entry */
+       jit_varint_encoder_t    offset_encoder; /* Bytecode offset encoder */
 };
 
 /*
diff --git a/jit/jit-unwind.c b/jit/jit-unwind.c
index a5f9320..4e3619a 100644
--- a/jit/jit-unwind.c
+++ b/jit/jit-unwind.c
@@ -169,8 +169,7 @@ jit_unwind_get_function(jit_unwind_context_t *unwind)
        {
                jit_cache_t cache = _jit_context_get_cache(unwind->context);
                void *pc = jit_unwind_get_pc(unwind);
-               unwind->cache = (jit_function_t)
-                       _jit_cache_get_method(cache, pc, NULL);
+               unwind->cache = _jit_cache_get_method(cache, pc);
        }
 
        return (jit_function_t) unwind->cache;
@@ -180,8 +179,7 @@ unsigned int
 jit_unwind_get_offset(jit_unwind_context_t *unwind)
 {
        jit_function_t func;
-       jit_cache_t cache;
-       void *pc, *start;
+       void *pc;
 
        if(!unwind || !unwind->frame || !unwind->context)
        {
@@ -200,13 +198,5 @@ jit_unwind_get_offset(jit_unwind_context_t *unwind)
                return JIT_NO_OFFSET;
        }
 
-       cache = _jit_context_get_cache(unwind->context);
-
-#ifdef JIT_PROLOG_SIZE
-       start = _jit_cache_get_start_method(cache, func->entry_point);
-#else
-       start = func->entry_point;
-#endif
-
-       return _jit_cache_get_bytecode(cache, start, pc - start, 0);
+       return _jit_function_get_bytecode(func, pc, 0);
 }

-----------------------------------------------------------------------


hooks/post-receive
-- 
DotGNU Portable.NET Just In Time compiler (libjit)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]