[pypy-commit] stmgc default: fix

arigo noreply at buildbot.pypy.org
Fri Jan 23 23:12:16 CET 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r1576:216c013a4b37
Date: 2015-01-23 23:11 +0100
http://bitbucket.org/pypy/stmgc/changeset/216c013a4b37/

Log:	fix

diff --git a/c7/stm/hashtable.c b/c7/stm/hashtable.c
--- a/c7/stm/hashtable.c
+++ b/c7/stm/hashtable.c
@@ -139,10 +139,10 @@
 
 static void _stm_rehash_hashtable(stm_hashtable_t *hashtable,
                                   uintptr_t biggercount,
-                                  bool remove_unread)
+                                  int remove_unread_from_seg)
 {
-    dprintf(("rehash %p to %ld, remove_unread=%d\n",
-             hashtable, biggercount, (int)remove_unread));
+    dprintf(("rehash %p to %ld, remove_unread_from_seg=%d\n",
+             hashtable, biggercount, remove_unread_from_seg));
 
     size_t size = (offsetof(stm_hashtable_table_t, items)
                    + biggercount * sizeof(stm_hashtable_entry_t *));
@@ -159,12 +159,14 @@
 
     uintptr_t j, mask = table->mask;
     uintptr_t rc = biggertable->resize_counter;
+    char *segment_base = get_segment_base(remove_unread_from_seg);
     for (j = 0; j <= mask; j++) {
         stm_hashtable_entry_t *entry = table->items[j];
         if (entry == NULL)
             continue;
-        if (remove_unread) {
-            if (entry->object == NULL &&
+        if (remove_unread_from_seg != 0) {
+            if (((struct stm_hashtable_entry_s *)
+                       REAL_ADDRESS(segment_base, entry))->object == NULL &&
                    !_stm_was_read_by_anybody((object_t *)entry)) {
                 dprintf(("  removing dead %p\n", entry));
                 continue;
@@ -257,6 +259,7 @@
             entry->userdata = stm_hashtable_entry_userdata;
             entry->index = index;
             entry->object = NULL;
+            hashtable->additions = STM_SEGMENT->segment_num;
         }
         else {
             /* for a non-nursery 'hashtableobj', we pretend that the
@@ -294,11 +297,11 @@
                 e->index = index;
                 e->object = NULL;
             }
+            hashtable->additions += 0x100;
             release_privatization_lock();
         }
         write_fence();     /* make sure 'entry' is fully initialized here */
         table->items[i] = entry;
-        hashtable->additions += 1;
         write_fence();     /* make sure 'table->items' is written here */
         VOLATILE_TABLE(table)->resize_counter = rc - 6;    /* unlock */
         return entry;
@@ -311,7 +314,7 @@
             biggercount *= 4;
         else
             biggercount *= 2;
-        _stm_rehash_hashtable(hashtable, biggercount, /*remove_unread=*/false);
+        _stm_rehash_hashtable(hashtable, biggercount, /*remove_unread=*/0);
         goto restart;
     }
 }
@@ -340,8 +343,10 @@
     stm_hashtable_table_t *table = hashtable->table;
     assert(!IS_EVEN(table->resize_counter));
 
-    if (hashtable->additions * 4 > table->mask) {
-        hashtable->additions = 0;
+    if ((hashtable->additions >> 8) * 4 > table->mask) {
+        int segment_num = (hashtable->additions & 0xFF);
+        if (!segment_num) segment_num = 1;
+        hashtable->additions = segment_num;
         uintptr_t initial_rc = (table->mask + 1) * 4 + 1;
         uintptr_t num_entries_times_6 = initial_rc - table->resize_counter;
         uintptr_t count = INITIAL_HASHTABLE_SIZE;
@@ -352,7 +357,7 @@
         assert(count <= table->mask + 1);
 
         dprintf(("compact with %ld items:\n", num_entries_times_6 / 6));
-        _stm_rehash_hashtable(hashtable, count, /*remove_unread=*/true);
+        _stm_rehash_hashtable(hashtable, count, /*remove_unread=*/segment_num);
     }
 
     table = hashtable->table;
diff --git a/c7/test/test_hashtable.py b/c7/test/test_hashtable.py
--- a/c7/test/test_hashtable.py
+++ b/c7/test/test_hashtable.py
@@ -216,7 +216,7 @@
         #
         self.switch(1)
         self.start_transaction()
-        stm_write(lp1)
+        stm_write(lp1)            # force this page to be shared
         #
         self.switch(0)
         self.start_transaction()
@@ -228,7 +228,7 @@
         self.push_root(h)
         #
         self.switch(1)            # in a different thread
-        stm_major_collect()
+        stm_major_collect()       # force a _stm_rehash_hashtable()
         #
         self.switch(0)            # back to the original thread
         h = self.pop_root()


More information about the pypy-commit mailing list