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, master, updated. f7334fc65aef4d78f39efc2a308aa0e031c64b8e
Date: Sun, 18 Dec 2011 11:27: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, master has been updated
       via  f7334fc65aef4d78f39efc2a308aa0e031c64b8e (commit)
       via  5c3e3e39c3bdf28ac99a585793eaf151ebc9521c (commit)
       via  3a049596f7f21da323a06b325cec83134a66fef4 (commit)
       via  58debaa961ebe01458071a929eac90bb949364ca (commit)
      from  e797d01e97199e7f8a263d47d35fb0103ea7574a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

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

commit f7334fc65aef4d78f39efc2a308aa0e031c64b8e
Author: Aleksey Demakov <address@hidden>
Date:   Sun Dec 18 14:25:23 2011 +0300

    add jit-varint.[hc] files with refactored int compression

diff --git a/ChangeLog b/ChangeLog
index 9078bc2..198454d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-12-18  Aleksey Demakov  <address@hidden>
+
+       * jit/Makefile.am:
+       * jit/jit-varint.h, jit/jit-varint.c: add new files for varaible
+       length int encoding with algorithm similar but not identical to one
+       currently used in jit-cache.c.  The new algorithm in certain cases
+       better compresses unsigned ints.
+
 2011-09-30  Aleksey Demakov  <address@hidden>
 
        * jit/jit-cache.h, jit/jit-cache.c (_jit_cache_new_region):
diff --git a/jit/Makefile.am b/jit/Makefile.am
index de7acb0..df7b0ab 100644
--- a/jit/Makefile.am
+++ b/jit/Makefile.am
@@ -77,6 +77,8 @@ libjit_la_SOURCES = \
        jit-type.c \
        jit-unwind.c \
        jit-value.c \
+       jit-varint.h \
+       jit-varint.c \
        jit-vmem.c \
        jit-walk.c
 
diff --git a/jit/jit-varint.c b/jit/jit-varint.c
new file mode 100644
index 0000000..023e722
--- /dev/null
+++ b/jit/jit-varint.c
@@ -0,0 +1,331 @@
+/*
+ * jit-varint.c - Variable length integer encoding.
+ *
+ * Copyright (C) 2011  Southern Storm Software, Pty Ltd.
+ *
+ * The libjit library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * The libjit library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the libjit library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <jit/jit.h>
+#include "jit-varint.h"
+
+/*
+ * Flush the current encode buffer.
+ */
+static int
+flush_encoder(jit_varint_encoder_t *encoder)
+{
+       jit_varint_data_t data;
+
+       /* Allocate a new jit_varint_data structure to hold the data */
+       data = jit_malloc(sizeof(struct jit_varint_data) + encoder->len);
+       if(!data)
+       {
+               return 0;
+       }
+
+       /* Copy the temporary debug data into the new structure */
+       jit_memcpy(data->data, encoder->buf, encoder->len);
+
+       /* Link the structure into the debug list */
+       data->next = 0;
+       if(encoder->last)
+       {
+               encoder->last->next = data;
+       }
+       else
+       {
+               encoder->data = data;
+       }
+       encoder->last = data;
+
+       /* Reset the temporary debug buffer */
+       encoder->len = 0;
+       return 1;
+}
+
+void
+_jit_varint_init_encoder(jit_varint_encoder_t *encoder)
+{
+       encoder->len = 0;
+       encoder->data = 0;
+       encoder->last = 0;
+}
+
+void
+_jit_varint_init_decoder(jit_varint_decoder_t *decoder, jit_varint_data_t data)
+{
+       decoder->len = 0;
+       decoder->data = data;
+       decoder->end = (data == 0);
+}
+
+int
+_jit_varint_encode_end(jit_varint_encoder_t *encoder)
+{
+       if(!encoder->len)
+       {
+               return 1;
+       }
+
+       /* Mark the end of the data */
+       encoder->buf[encoder->len++] = 0xFF;
+
+       /* Flush the data that we have collected so far */
+       return flush_encoder(encoder);
+}
+
+/*
+ * 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.
+ */
+int
+_jit_varint_encode_uint(jit_varint_encoder_t *encoder, jit_uint value)
+{
+       if(encoder->len + 6 > sizeof(encoder->buf))
+       {
+               /* Overflow occurred: end current buffer */
+               if(!_jit_varint_encode_end(encoder))
+               {
+                       return 0;
+               }
+       }
+
+       /* Write the value to the temporary buffer */
+       if(value < 0x80)
+       {
+               /* 0xxx xxxx */
+               encoder->buf[encoder->len++] = (unsigned char) (value);
+       }
+       else if(value < 0x4000)
+       {
+               /* 10xx xxxx | xxxx xxxx */
+               encoder->buf[encoder->len++] = (unsigned char) (value >> 8) | 
0x80;
+               encoder->buf[encoder->len++] = (unsigned char) (value);
+       }
+       else if(value < 0x200000)
+       {
+               /* 110x xxxx | xxxx xxxx | xxxx xxxx */
+               encoder->buf[encoder->len++] = (unsigned char) (value >> 16) | 
0xC0;
+               encoder->buf[encoder->len++] = (unsigned char) (value >> 8);
+               encoder->buf[encoder->len++] = (unsigned char) (value);
+       }
+       else if(value < 0x10000000)
+       {
+               /* 1110 xxxx | xxxx xxxx | xxxx xxxx | xxxx xxxx */
+               encoder->buf[encoder->len++] = (unsigned char) (value >> 24) | 
0xE0;
+               encoder->buf[encoder->len++] = (unsigned char) (value >> 16);
+               encoder->buf[encoder->len++] = (unsigned char) (value >> 8);
+               encoder->buf[encoder->len++] = (unsigned char) (value);
+       }
+       else
+       {
+               /* 1111 0000 | xxxx xxxx | xxxx xxxx | xxxx xxxx | xxxx xxxx */
+               encoder->buf[encoder->len++] = 0xF0;
+               encoder->buf[encoder->len++] = (unsigned char) (value >> 24);
+               encoder->buf[encoder->len++] = (unsigned char) (value >> 16);
+               encoder->buf[encoder->len++] = (unsigned char) (value >> 8);
+               encoder->buf[encoder->len++] = (unsigned char) (value);
+       }
+
+       return 1;
+}
+
+jit_varint_data_t
+_jit_varint_get_data(jit_varint_encoder_t *encoder)
+{
+       return encoder->data;
+}
+
+void
+_jit_varint_free_data(jit_varint_data_t data)
+{
+       while(data)
+       {
+               jit_varint_data_t next = data->next;
+               jit_free(data);
+               data = next;
+       }
+}
+
+int
+_jit_varint_decode_end(jit_varint_decoder_t *decoder)
+{
+       return decoder->end;
+}
+
+jit_uint
+_jit_varint_decode_uint(jit_varint_decoder_t *decoder)
+{
+       jit_uint value;
+       unsigned char c;
+
+       value = (jit_uint) (-1);
+       if(decoder->end)
+       {
+               return value;
+       }
+       if(decoder->len >= JIT_VARINT_BUFFER_SIZE)
+       {
+               /* Sanity check failed */
+               decoder->end = 2;
+               return value;
+       }
+
+again:
+       c = decoder->data->data[decoder->len++];
+       if(!(c & 0x80))
+       {
+               /* 0xxx xxxx */
+               value = ((jit_uint) c);
+       }
+       else if(!(c & 0x40))
+       {
+               /* 10xx xxxx | xxxx xxxx */
+               value = ((jit_uint) c & 0x3F) << 8;
+               value |= ((jit_uint) decoder->data->data[decoder->len++]);
+       }
+       else if(!(c & 0x20))
+       {
+               /* 110x xxxx | xxxx xxxx | xxxx xxxx */
+               value = ((jit_uint) c & 0x1F) << 16;
+               value |= ((jit_uint) decoder->data->data[decoder->len++]) << 8;
+               value |= ((jit_uint) decoder->data->data[decoder->len++]);
+       }
+       else if(!(c & 0x10))
+       {
+               /* 1110 xxxx | xxxx xxxx | xxxx xxxx | xxxx xxxx */
+               value = ((jit_uint) c & 0x0F) << 24;
+               value |= ((jit_uint) decoder->data->data[decoder->len++]) << 16;
+               value |= ((jit_uint) decoder->data->data[decoder->len++]) << 8;
+               value |= ((jit_uint) decoder->data->data[decoder->len++]);
+       }
+       else if(!(c & 0x0f))
+       {
+               /* 1111 0000 | xxxx xxxx | xxxx xxxx | xxxx xxxx | xxxx xxxx */
+               value |= ((jit_uint) decoder->data->data[decoder->len++]) << 24;
+               value |= ((jit_uint) decoder->data->data[decoder->len++]) << 16;
+               value |= ((jit_uint) decoder->data->data[decoder->len++]) << 8;
+               value |= ((jit_uint) decoder->data->data[decoder->len++]);
+       }
+       else
+       {
+               /* Met data end mark */
+               if(decoder->data->next)
+               {
+                       /* There is another data block */
+                       decoder->data = decoder->data->next;
+                       decoder->len = 0;
+                       goto again;
+               }
+
+               /* This was the last data block */
+               decoder->end = 1;
+       }
+
+       return value;
+}
+
+#if 0
+
+void
+_jit_varint_encode_int(jit_varint_encoder_t *encoder, jit_int value)
+{
+       value = (value << 1) ^ (value >> (8 * sizeof(jit_uint) - 1));;
+       _jit_varint_encode_uint(encoder, (jit_uint) value);
+}
+
+jit_int
+_jit_varint_decode_int(jit_varint_decoder_t *decoder)
+{
+       jit_uint value = _jit_varint_decode_uint(decoder);
+       return (jit_int) ((value >> 1) ^ -(value & 1));
+}
+
+#endif
+
+#if defined(VARINT_TEST)
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void *
+jit_malloc(unsigned int size)
+{
+       return malloc(size);
+}
+
+void
+jit_free(void *ptr)
+{
+       if(ptr)
+       {
+               free(ptr);
+       }
+}
+
+void *
+jit_memcpy(void *dest, const void *src, unsigned int len)
+{
+       return memcpy(dest, src, len);
+}
+
+int
+main()
+{
+       jit_uint i, j, n, v;
+
+       for(n = 1; n != 0; n >>= 1)
+       {
+               jit_varint_encoder_t encoder;
+               _jit_varint_init_encoder(&encoder);
+               _jit_varint_encode_uint(&encoder, n);
+               _jit_varint_encode_uint(&encoder, n - 1);
+               _jit_varint_encode_uint(&encoder, n + 1);
+               _jit_varint_encode_end(&encoder);
+
+               jit_varint_data_t data = _jit_varint_get_data(&encoder);
+
+               jit_varint_decoder_t decoder;
+               _jit_varint_init_decoder(&decoder, data);
+               v = _jit_varint_decode_uint(&decoder);
+               if(v != n)
+               {
+                       fprintf(stderr, "FAILED\n");
+               }
+               v = _jit_varint_decode_uint(&decoder);
+               if(v != n - 1)
+               {
+                       fprintf(stderr, "FAILED\n");
+               }
+               v = _jit_varint_decode_uint(&decoder);
+               if(v != n + 1)
+               {
+                       fprintf(stderr, "FAILED\n");
+               }
+               _jit_varint_decode_uint(&decoder);
+               if(!_jit_varint_decode_end(&decoder))
+               {
+                       fprintf(stderr, "FAILED\n");
+               }
+
+               _jit_varint_free_data(data);
+       }
+
+}
+
+#endif
diff --git a/jit/jit-varint.h b/jit/jit-varint.h
new file mode 100644
index 0000000..b761f28
--- /dev/null
+++ b/jit/jit-varint.h
@@ -0,0 +1,70 @@
+/*
+ * jit-varint.h - Variable length integer encoding.
+ *
+ * Copyright (C) 2011  Southern Storm Software, Pty Ltd.
+ *
+ * The libjit library is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation, either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * The libjit library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the libjit library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _JIT_VARINT_H
+#define        _JIT_VARINT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define        JIT_VARINT_BUFFER_SIZE          500
+
+typedef struct jit_varint_data *jit_varint_data_t;
+struct jit_varint_data
+{
+       jit_varint_data_t       next;
+       unsigned char           data[];
+};
+
+typedef struct jit_varint_encoder jit_varint_encoder_t;
+struct jit_varint_encoder
+{
+       unsigned char           buf[JIT_VARINT_BUFFER_SIZE];
+       int                     len;
+       jit_varint_data_t       data;
+       jit_varint_data_t       last;
+
+};
+
+typedef struct jit_varint_decoder jit_varint_decoder_t;
+struct jit_varint_decoder
+{
+       jit_varint_data_t       data;
+       int                     len;
+       int                     end;
+};
+
+void _jit_varint_init_encoder(jit_varint_encoder_t *encoder);
+void _jit_varint_init_decoder(jit_varint_decoder_t *decoder, jit_varint_data_t 
data);
+int _jit_varint_encode_end(jit_varint_encoder_t *encoder);
+int _jit_varint_encode_uint(jit_varint_encoder_t *encoder, jit_uint value);
+jit_varint_data_t _jit_varint_get_data(jit_varint_encoder_t *encoder);
+void _jit_varint_free_data(jit_varint_data_t data);
+int _jit_varint_decode_end(jit_varint_decoder_t *decoder);
+jit_uint _jit_varint_decode_uint(jit_varint_decoder_t *decoder);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _JIT_VARINT_H */
+

http://git.savannah.gnu.org/cgit/libjit.git/commit/?id=5c3e3e39c3bdf28ac99a585793eaf151ebc9521c

commit 5c3e3e39c3bdf28ac99a585793eaf151ebc9521c
Author: Aleksey Demakov <address@hidden>
Date:   Fri Sep 30 16:08:21 2011 +0700

    remove CountMethods(), FillMethodList() functions

diff --git a/jit/jit-cache.c b/jit/jit-cache.c
index 7351445..bf2ceef 100644
--- a/jit/jit-cache.c
+++ b/jit/jit-cache.c
@@ -1173,66 +1173,6 @@ failed:
 }
 
 /*
- * Count the number of methods in a sub-tree.
- */
-static unsigned long CountMethods(jit_cache_method_t node,
-                                                                 
jit_cache_method_t nil,
-                                                                 void **prev)
-{
-       unsigned long num;
-
-       /* Bail out if we've reached a leaf */
-       if(node == nil)
-       {
-               return 0;
-       }
-
-       /* Count the number of methods in the left sub-tree */
-       num = CountMethods(GetLeft(node), nil, prev);
-
-       /* Process the current node */
-       if(node->method != 0 && node->method != *prev)
-       {
-               ++num;
-               *prev = node->method;
-       }
-
-       /* Count the number of methods in the right sub-tree */
-       return num + CountMethods(GetRight(node), nil, prev);
-}
-
-/*
- * Fill a list with methods.
- */
-static unsigned long FillMethodList(void **list,
-                                                                       
jit_cache_method_t node,
-                                                                   
jit_cache_method_t nil,
-                                                                   void **prev)
-{
-       unsigned long num;
-
-       /* Bail out if we've reached a leaf */
-       if(node == nil)
-       {
-               return 0;
-       }
-
-       /* Process the methods in the left sub-tree */
-       num = FillMethodList(list, GetLeft(node), nil, prev);
-
-       /* Process the current node */
-       if(node->method != 0 && node->method != *prev)
-       {
-               list[num] = node->method;
-               ++num;
-               *prev = node->method;
-       }
-
-       /* Process the methods in the right sub-tree */
-       return num + FillMethodList(list + num, GetRight(node), nil, prev);
-}
-
-/*
  * Temporary structure for iterating over a method's debug list.
  */
 typedef struct

http://git.savannah.gnu.org/cgit/libjit.git/commit/?id=3a049596f7f21da323a06b325cec83134a66fef4

commit 3a049596f7f21da323a06b325cec83134a66fef4
Author: Aleksey Demakov <address@hidden>
Date:   Fri Sep 30 12:23:47 2011 +0700

    removed _jit_cache_new_region() function

diff --git a/ChangeLog b/ChangeLog
index ef88bac..9078bc2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-09-30  Aleksey Demakov  <address@hidden>
+
+       * jit/jit-cache.h, jit/jit-cache.c (_jit_cache_new_region):
+       function removed.
+
 2011-09-03  Aleksey Demakov  <address@hidden>
 
        * jit/jit-cache.h, jit/jit-cache.c (_jit_cache_get_method_list):
diff --git a/jit/jit-cache.c b/jit/jit-cache.c
index 77c52ec..7351445 100644
--- a/jit/jit-cache.c
+++ b/jit/jit-cache.c
@@ -974,46 +974,6 @@ void _jit_cache_mark_bytecode(jit_cache_posn *posn, 
unsigned long offset)
                                    (long)(posn->ptr - posn->cache->start));
 }
 
-void _jit_cache_new_region(jit_cache_posn *posn, void *cookie)
-{
-       jit_cache_method_t method;
-       jit_cache_method_t newMethod;
-
-       /* Fetch the current method information block */
-       method = posn->cache->method;
-       if(!method)
-       {
-               return;
-       }
-
-       /* If the current region starts here, then simply update it */
-       if(method->start == posn->ptr)
-       {
-               method->cookie = cookie;
-               return;
-       }
-
-       /* Close off the current method region */
-       method->end = posn->ptr;
-
-       /* Allocate a new method region block and initialise it */
-       newMethod = (jit_cache_method_t)
-               _jit_cache_alloc(posn, sizeof(struct jit_cache_method));
-       if(!newMethod)
-       {
-               return;
-       }
-       newMethod->method = method->method;
-       newMethod->cookie = cookie;
-       newMethod->start = posn->ptr;
-       newMethod->end = posn->ptr;
-
-       /* Attach the new region to the cache */
-       newMethod->left = 0;
-       newMethod->right = method;
-       posn->cache->method = newMethod;
-}
-
 void _jit_cache_set_cookie(jit_cache_posn *posn, void *cookie)
 {
        if(posn->cache->method)
diff --git a/jit/jit-cache.h b/jit/jit-cache.h
index aa180ae..ea04bee 100644
--- a/jit/jit-cache.h
+++ b/jit/jit-cache.h
@@ -132,12 +132,6 @@ void _jit_cache_align(jit_cache_posn *posn, int align, int 
diff, int nop);
 void _jit_cache_mark_bytecode(jit_cache_posn *posn, unsigned long offset);
 
 /*
- * Change to a new exception region within the current method.
- * The cookie will typically be NULL if no exception region.
- */
-void _jit_cache_new_region(jit_cache_posn *posn, void *cookie);
-
-/*
  * Set the exception region cookie for the current region.
  */
 void _jit_cache_set_cookie(jit_cache_posn *posn, void *cookie);

http://git.savannah.gnu.org/cgit/libjit.git/commit/?id=58debaa961ebe01458071a929eac90bb949364ca

commit 58debaa961ebe01458071a929eac90bb949364ca
Author: Aleksey Demakov <address@hidden>
Date:   Sat Sep 3 21:33:09 2011 +0700

    remove _jit_cache_get_method_list() function

diff --git a/ChangeLog b/ChangeLog
index 8b21823..ef88bac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-09-03  Aleksey Demakov  <address@hidden>
+
+       * jit/jit-cache.h, jit/jit-cache.c (_jit_cache_get_method_list):
+       function removed.
+
 2011-07-27  Aleksey Demakov  <address@hidden>
 
        * jit/jit-config.h: added new file as central location for all
diff --git a/jit/jit-cache.c b/jit/jit-cache.c
index 0f01485..77c52ec 100644
--- a/jit/jit-cache.c
+++ b/jit/jit-cache.c
@@ -1272,30 +1272,6 @@ static unsigned long FillMethodList(void **list,
        return num + FillMethodList(list + num, GetRight(node), nil, prev);
 }
 
-void **_jit_cache_get_method_list(jit_cache_t cache)
-{
-       void *prev;
-       unsigned long num;
-       void **list;
-
-       /* Count the number of distinct methods in the tree */
-       prev = 0;
-       num = CountMethods(cache->head.right, &(cache->nil), &prev);
-
-       /* Allocate a list to hold all of the method descriptors */
-       list = (void **)jit_malloc((num + 1) * sizeof(void *));
-       if(!list)
-       {
-               return 0;
-       }
-
-       /* Fill the list with methods and then return it */
-       prev = 0;
-       FillMethodList(list, cache->head.right, &(cache->nil), &prev);
-       list[num] = 0;
-       return list;
-}
-
 /*
  * Temporary structure for iterating over a method's debug list.
  */
diff --git a/jit/jit-cache.h b/jit/jit-cache.h
index 7c8d9ce..aa180ae 100644
--- a/jit/jit-cache.h
+++ b/jit/jit-cache.h
@@ -167,13 +167,6 @@ void *_jit_cache_get_start_method(jit_cache_t cache, void 
*pc);
 void *_jit_cache_get_end_method(jit_cache_t cache, void *pc);
 
 /*
- * Get a list of all method that are presently in the cache.
- * The list is terminated by a NULL, and must be free'd with
- * "jit_free".  Returns NULL if out of memory.
- */
-void **_jit_cache_get_method_list(jit_cache_t cache);
-
-/*
  * 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

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

Summary of changes:
 ChangeLog        |   18 +++
 jit/Makefile.am  |    2 +
 jit/jit-cache.c  |  124 --------------------
 jit/jit-cache.h  |   13 --
 jit/jit-varint.c |  331 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 jit/jit-varint.h |   70 ++++++++++++
 6 files changed, 421 insertions(+), 137 deletions(-)
 create mode 100644 jit/jit-varint.c
 create mode 100644 jit/jit-varint.h


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



reply via email to

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