[pypy-commit] stmgc c8-private-pages: increase confidence with a test

Raemi noreply at buildbot.pypy.org
Mon Jan 19 10:50:16 CET 2015


Author: Remi Meier <remi.meier at inf.ethz.ch>
Branch: c8-private-pages
Changeset: r1542:f1bfa3441475
Date: 2015-01-19 10:51 +0100
http://bitbucket.org/pypy/stmgc/changeset/f1bfa3441475/

Log:	increase confidence with a test

diff --git a/c8/test/support.py b/c8/test/support.py
--- a/c8/test/support.py
+++ b/c8/test/support.py
@@ -121,7 +121,8 @@
 """)
 
 
-GC_N_SMALL_REQUESTS = 36      # from gcpage.c
+GC_N_SMALL_REQUESTS = 36      # from smallmalloc.h
+GC_LAST_SMALL_SIZE  =   (8 * (GC_N_SMALL_REQUESTS - 1))
 LARGE_MALLOC_OVERHEAD = 16    # from largemalloc.h
 
 lib = ffi.verify(r'''
diff --git a/c8/test/test_gcpage.py b/c8/test/test_gcpage.py
--- a/c8/test/test_gcpage.py
+++ b/c8/test/test_gcpage.py
@@ -344,3 +344,51 @@
 
         stm_major_collect()
         assert lib._stm_total_allocated() == 0
+
+    def test_mixed_major_collections(self):
+        import random
+        obj_sizes = [16, 48, 1024, 1000*8]
+
+        self.start_transaction()
+        random.seed(123)
+
+        # allocate objs:
+        allocated = 0
+        NOBJS = 100
+        for _ in range(NOBJS):
+            osize = random.choice(obj_sizes)
+            is_small = osize <= GC_LAST_SMALL_SIZE
+            if is_small:
+                allocated += osize
+            else:
+                allocated += osize + LMO
+
+            o = stm_allocate(osize)
+            self.push_root(o)
+
+            # sometimes do a minor collection:
+            if random.random() > 0.95:
+                stm_minor_collect()
+                assert lib._stm_total_allocated() == allocated
+
+        stm_minor_collect()
+        assert lib._stm_total_allocated() == allocated
+        # -> all objs old
+
+        objs = set()
+        for _ in range(NOBJS):
+            objs.add(self.pop_root())
+
+        # do major collections while always saving less
+        # and less objs
+        while objs:
+            objs = random.sample(objs, len(objs) // 2)
+            for o in objs:
+                self.push_root(o)
+            stm_major_collect()
+            for o in objs:
+                self.pop_root()
+
+        assert lib._stm_total_allocated() == 0
+
+        self.commit_transaction()


More information about the pypy-commit mailing list