[pypy-commit] pypy stmgc-c7: import stmgc/3c39b8d8e184

arigo noreply at buildbot.pypy.org
Fri Mar 14 11:26:19 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r69950:6ec806be961b
Date: 2014-03-14 11:25 +0100
http://bitbucket.org/pypy/pypy/changeset/6ec806be961b/

Log:	import stmgc/3c39b8d8e184

diff --git a/rpython/translator/stm/src_stm/revision b/rpython/translator/stm/src_stm/revision
--- a/rpython/translator/stm/src_stm/revision
+++ b/rpython/translator/stm/src_stm/revision
@@ -1,1 +1,1 @@
-c4e8d6220b74
+3c39b8d8e184
diff --git a/rpython/translator/stm/src_stm/stm/list.c b/rpython/translator/stm/src_stm/stm/list.c
--- a/rpython/translator/stm/src_stm/stm/list.c
+++ b/rpython/translator/stm/src_stm/stm/list.c
@@ -76,7 +76,7 @@
 
 static wlog_t *_tree_find(char *entry, uintptr_t addr)
 {
-    uintptr_t key = addr;
+    uintptr_t key = TREE_HASH(addr);
     while (((long)entry) & 1) {
         /* points to a further level */
         key >>= TREE_BITS;
@@ -123,10 +123,9 @@
 static void tree_insert(struct tree_s *tree, uintptr_t addr, uintptr_t val)
 {
     assert(addr != 0);    /* the NULL key is reserved */
-    assert(!(addr & (sizeof(void *) - 1)));    /* the key must be aligned */
  retry:;
     wlog_t *wlog;
-    uintptr_t key = addr;
+    uintptr_t key = TREE_HASH(addr);
     int shift = 0;
     char *p = (char *)(tree->toplevel.items);
     char *entry;
@@ -156,7 +155,7 @@
                 _tree_grab(tree, sizeof(wlog_node_t));
             if (node == NULL) goto retry;
             _tree_clear_node(node);
-            uintptr_t key1 = wlog1->addr;
+            uintptr_t key1 = TREE_HASH(wlog1->addr);
             char *p1 = (char *)(node->items);
             *(wlog_t **)(p1 + ((key1 >> shift) & TREE_MASK)) = wlog1;
             *(char **)p = ((char *)node) + 1;
diff --git a/rpython/translator/stm/src_stm/stm/list.h b/rpython/translator/stm/src_stm/stm/list.h
--- a/rpython/translator/stm/src_stm/stm/list.h
+++ b/rpython/translator/stm/src_stm/stm/list.h
@@ -83,17 +83,19 @@
    supporting very high performance in TREE_FIND in the common case where
    there are no or few elements in the tree, but scaling correctly
    if the number of items becomes large (logarithmically, rather
-   than almost-constant-time with hash maps, but with low constants). */
+   than almost-constant-time with hash maps, but with low constants).
+   The value 0 cannot be used as a key.
+*/
 
 #define TREE_BITS   4
 #define TREE_ARITY  (1 << TREE_BITS)
 
-#define TREE_DEPTH_MAX   ((sizeof(void*)*8 - 2 + TREE_BITS-1) / TREE_BITS)
-/* sizeof(void*) = total number of bits
-   2 = bits that we ignore anyway (2 or 3, conservatively 2)
+#define TREE_DEPTH_MAX   ((sizeof(void*)*8 + TREE_BITS-1) / TREE_BITS)
+/* sizeof(void*)*8 = total number of bits
    (x + TREE_BITS-1) / TREE_BITS = divide by TREE_BITS, rounding up
 */
 
+#define TREE_HASH(key)  ((key) ^ ((key) << 4))
 #define TREE_MASK   ((TREE_ARITY - 1) * sizeof(void*))
 
 typedef struct {
@@ -175,7 +177,7 @@
 
 #define TREE_FIND(tree, addr1, result, goto_not_found)          \
 {                                                               \
-  uintptr_t _key = (addr1);                                     \
+  uintptr_t _key = TREE_HASH(addr1);                            \
   char *_p = (char *)((tree).toplevel.items);                   \
   char *_entry = *(char **)(_p + (_key & TREE_MASK));           \
   if (_entry == NULL)                                           \
diff --git a/rpython/translator/stm/src_stm/stm/prebuilt.c b/rpython/translator/stm/src_stm/stm/prebuilt.c
--- a/rpython/translator/stm/src_stm/stm/prebuilt.c
+++ b/rpython/translator/stm/src_stm/stm/prebuilt.c
@@ -17,13 +17,11 @@
         return;
 
     /* If the object was already moved, it is stored in 'tree_prebuilt_objs'.
-       For now we use this dictionary, with keys being equal to the double
-       of the numeric address of the prebuilt object.  We double them in
-       order to support addresses that are only 4-byte-aligned in the
-       static data.
+       For now we use this dictionary, with keys being equal to the numeric
+       address of the prebuilt object.
      */
     wlog_t *item;
-    TREE_FIND(*tree_prebuilt_objs, 2 * (uintptr_t)obj, item, goto not_found);
+    TREE_FIND(*tree_prebuilt_objs, (uintptr_t)obj, item, goto not_found);
 
     *pstaticobj_invalid = (object_t *)item->val;    /* already moved */
     return;
@@ -43,7 +41,7 @@
     nobj->stm_flags = GCFLAG_WRITE_BARRIER;
 
     /* Add the object to the tree */
-    tree_insert(tree_prebuilt_objs, 2 * (uintptr_t)obj, (uintptr_t)nobj);
+    tree_insert(tree_prebuilt_objs, (uintptr_t)obj, (uintptr_t)nobj);
 
     /* Done */
     *pstaticobj_invalid = nobj;


More information about the pypy-commit mailing list