[pypy-commit] stmgc default: add two failing tests

Raemi noreply at buildbot.pypy.org
Mon Sep 8 12:56:23 CEST 2014


Author: Remi Meier <remi.meier at inf.ethz.ch>
Branch: 
Changeset: r1365:7f4ea36607f9
Date: 2014-09-08 12:57 +0200
http://bitbucket.org/pypy/stmgc/changeset/7f4ea36607f9/

Log:	add two failing tests

diff --git a/c8/stm/core.c b/c8/stm/core.c
--- a/c8/stm/core.c
+++ b/c8/stm/core.c
@@ -7,6 +7,32 @@
 
 /* ############# signal handler ############# */
 
+static void copy_bk_objs_from(int from_segnum, uintptr_t pagenum)
+{
+    acquire_modified_objs_lock(from_segnum);
+    struct tree_s *tree = get_priv_segment(from_segnum)->modified_old_objects;
+    wlog_t *item;
+    TREE_LOOP_FORWARD(tree, item); {
+        if (item->addr >= pagenum * 4096UL && item->addr < (pagenum + 1) * 4096UL) {
+            /* obj is in range. XXX: no page overlapping objs allowed yet */
+
+            object_t *obj = (object_t*)item->addr;
+            struct object_s* bk_obj = (struct object_s *)item->val;
+            size_t obj_size;
+
+            obj_size = stmcb_size_rounded_up(bk_obj);
+            assert(obj_size < 4096); /* XXX */
+
+            memcpy(REAL_ADDRESS(STM_SEGMENT->segment_base, obj),
+                   bk_obj, obj_size);
+
+            assert(obj->stm_flags & GCFLAG_WRITE_BARRIER); /* bk_obj never written */
+        }
+    } TREE_LOOP_END;
+
+    release_modified_objs_lock(from_segnum);
+}
+
 static void bring_page_up_to_date(uintptr_t pagenum)
 {
     /* Assuming pagenum is not yet private in this segment and
@@ -50,28 +76,8 @@
 
         /* get valid state from backup copies of written objs in
            the range of this page: */
-        acquire_modified_objs_lock(i);
-        struct tree_s *tree = get_priv_segment(i)->modified_old_objects;
-        wlog_t *item;
-        TREE_LOOP_FORWARD(tree, item); {
-            if (item->addr >= pagenum * 4096UL && item->addr < (pagenum + 1) * 4096UL) {
-                /* obj is in range. XXX: no page overlapping objs allowed yet */
+        copy_bk_objs_from(i, pagenum);
 
-                object_t *obj = (object_t*)item->addr;
-                struct object_s* bk_obj = (struct object_s *)item->val;
-                size_t obj_size;
-
-                obj_size = stmcb_size_rounded_up(bk_obj);
-                assert(obj_size < 4096); /* XXX */
-
-                memcpy(REAL_ADDRESS(STM_SEGMENT->segment_base, obj),
-                       bk_obj, obj_size);
-
-                assert(obj->stm_flags & GCFLAG_WRITE_BARRIER); /* bk_obj never written */
-            }
-        } TREE_LOOP_END;
-
-        release_modified_objs_lock(i);
         release_privatization_lock(i);
 
         return;
diff --git a/c8/test/support.py b/c8/test/support.py
--- a/c8/test/support.py
+++ b/c8/test/support.py
@@ -65,6 +65,9 @@
 void _set_ptr(object_t *obj, int n, object_t *v);
 object_t * _get_ptr(object_t *obj, int n);
 
+
+void _stm_set_nursery_free_count(uint64_t free_count);
+
 long _stm_count_modified_old_objects(void);
 long _stm_count_objects_pointing_to_nursery(void);
 object_t *_stm_enum_modified_old_objects(long index);
@@ -406,7 +409,7 @@
 
 
 class BaseTest(object):
-    NB_THREADS = 2
+    NB_THREADS = 4
 
     def setup_method(self, meth):
         lib.stm_setup()
diff --git a/c8/test/test_basic.py b/c8/test/test_basic.py
--- a/c8/test/test_basic.py
+++ b/c8/test/test_basic.py
@@ -110,6 +110,73 @@
         #
         py.test.raises(Conflict, self.switch, 0) # detects rw conflict
 
+    def test_read_write_11(self):
+        # test that stm_validate() and the SEGV-handler
+        # always ensure up-to-date views of pages:
+        lp1 = stm_allocate_old(16)
+        stm_get_real_address(lp1)[HDR] = 'a' #setchar
+        #
+        self.start_transaction()
+        stm_set_char(lp1, '0') # shared->private
+        # prot_none in seg: 1,2,3
+        #
+        self.switch(1)
+        self.start_transaction()
+        stm_set_char(lp1, '1')
+        # prot_none in seg: 2,3
+        #
+        self.switch(0)
+        self.commit_transaction()
+        assert last_commit_log_entries() == [lp1] # commit '0'
+        #
+        py.test.raises(Conflict, self.switch, 1)
+        self.start_transaction() # updates to '0'
+        stm_set_char(lp1, 'x')
+        self.commit_transaction()
+        assert last_commit_log_entries() == [lp1] # commit 'x'
+        #
+        #
+        self.switch(2)
+        self.start_transaction() # stm_validate()
+        res = stm_get_char(lp1) # should be 'x'
+        self.commit_transaction()
+        assert res == 'x'
+        # if fails, segfault-handler copied from seg0 which
+        # is out-of-date because seg1 committed 'x'
+        # (seg1 hasn't done stm_validate() since)
+
+
+    def test_read_write_12(self):
+        # test that stm_validate() and the SEGV-handler
+        # always ensure up-to-date views of pages:
+        lp1 = stm_allocate_old(16)
+        stm_get_real_address(lp1)[HDR] = 'a' #setchar
+        #
+        self.switch(1)
+        self.start_transaction()
+        stm_set_char(lp1, '1') # shared->private
+        # prot_none in seg: 0,2,3
+        #
+        self.switch(0)
+        self.start_transaction()
+        stm_set_char(lp1, '0')
+        # prot_none in seg: 2,3
+        #
+        self.switch(1)
+        self.commit_transaction()
+        assert last_commit_log_entries() == [lp1]
+        # '1' is committed
+        #
+        self.switch(2)
+        self.start_transaction() # stm_validate()
+        res = stm_get_char(lp1) # should be '1'
+        self.commit_transaction()
+        assert res == '1'
+        # if res=='a', then we got the outdated page-view
+        # of segment 0 that didn't do stm_validate() and
+        # therefore is still outdated.
+        py.test.raises(Conflict, self.switch, 0)
+
     def test_commit_fresh_objects(self):
         self.start_transaction()
         lp = stm_allocate(16)


More information about the pypy-commit mailing list