Author: Armin Rigo <[email protected]>
Branch: gc-small-uniform
Changeset: r1133:0e454afc4c81
Date: 2014-04-05 22:37 +0200
http://bitbucket.org/pypy/stmgc/changeset/0e454afc4c81/

Log:    Better test, bug fixes

diff --git a/c7/stm/core.h b/c7/stm/core.h
--- a/c7/stm/core.h
+++ b/c7/stm/core.h
@@ -175,7 +175,10 @@
     TS_INEVITABLE,
 };
 
-static char *stm_object_pages;
+#ifndef STM_TESTS
+static
+#endif
+       char *stm_object_pages;
 static stm_thread_local_t *stm_all_thread_locals = NULL;
 
 static uint8_t write_locks[WRITELOCK_END - WRITELOCK_START];
diff --git a/c7/stm/smallmalloc.c b/c7/stm/smallmalloc.c
--- a/c7/stm/smallmalloc.c
+++ b/c7/stm/smallmalloc.c
@@ -221,7 +221,7 @@
             flprev = fl;
             fl = fl->next;
         }
-        else if (_smallmalloc_sweep_keep(p)) {
+        else if (!_smallmalloc_sweep_keep(p)) {
             /* the location should be freed now */
             if (flprev == NULL) {
                 flprev = (struct small_free_loc_s *)p;
@@ -231,7 +231,8 @@
             else {
                 assert(flprev->next == fl);
                 flprev->next = (struct small_free_loc_s *)p;
-                flprev->next->next = fl;
+                flprev = (struct small_free_loc_s *)p;
+                flprev->next = fl;
             }
         }
         else {
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -138,6 +138,7 @@
 uint64_t _stm_total_allocated(void);
 void _stm_mutex_pages_lock(void);
 void _stm_mutex_pages_unlock(void);
+char *stm_object_pages;
 #endif
 
 #define _STM_GCFLAG_WRITE_BARRIER      0x01
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -29,6 +29,8 @@
     ...;
 } stm_thread_local_t;
 
+char *stm_object_pages;
+
 void stm_read(object_t *obj);
 /*void stm_write(object_t *obj); use _checked_stm_write() instead */
 object_t *stm_allocate(ssize_t size_rounded_up);
diff --git a/c7/test/test_smallmalloc.py b/c7/test/test_smallmalloc.py
--- a/c7/test/test_smallmalloc.py
+++ b/c7/test/test_smallmalloc.py
@@ -1,4 +1,5 @@
 from support import *
+import random
 
 
 def pageof(p):
@@ -11,10 +12,13 @@
         BaseTest.setup_method(self, method)
         @ffi.callback("bool(char *)")
         def keep(data):
-            return data in self.keep_me
+            p = ffi.cast("object_t *", data - lib.stm_object_pages)
+            self.has_been_asked_for.append(p)
+            return p in self.keep_me
         lib._stm_smallmalloc_keep = keep
         self._keepalive_keep_function = keep
         self.keep_me = set()
+        self.has_been_asked_for = []
 
     def test_simple_uniform(self):
         page0 = [stm_allocate_old_small(16) for i in range(0, 4096, 16)]
@@ -36,6 +40,29 @@
             assert p == seen[0]
             seen.pop(0)
 
-    def test_sweep_freeing(self):
+    def test_sweep_freeing_simple(self):
         p1 = stm_allocate_old_small(16)
         lib._stm_smallmalloc_sweep()
+
+    def test_sweep_freeing_random_subset(self):
+        for i in range(50):
+            page0 = [stm_allocate_old_small(16) for i in range(0, 4096-16, 16)]
+            assert len(set(map(pageof, page0))) == 1
+            tid = lib._get_type_id(page0[0])
+            while len(page0) > 0:
+                self.keep_me = set(random.sample(page0, len(page0) // 2))
+                self.has_been_asked_for = []
+                lib._stm_smallmalloc_sweep()
+                assert sorted(page0) == self.has_been_asked_for
+                page0r = []
+                for p in page0:
+                    if p in self.keep_me:
+                        assert lib._get_type_id(p) == tid
+                        page0r.append(p)
+                    else:
+                        assert lib._get_type_id(p) != tid
+                page0 = page0r
+                if len(page0) > 10:
+                    p = stm_allocate_old_small(16)
+                    assert pageof(p) == pageof(page0[0])
+                    page0.append(p)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to