[pypy-commit] stmgc bag: Test and fix

arigo noreply at buildbot.pypy.org
Sat Jan 24 16:16:14 CET 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: bag
Changeset: r1585:d94ccb7c1585
Date: 2015-01-24 16:16 +0100
http://bitbucket.org/pypy/stmgc/changeset/d94ccb7c1585/

Log:	Test and fix

diff --git a/c7/stm/bag.c b/c7/stm/bag.c
--- a/c7/stm/bag.c
+++ b/c7/stm/bag.c
@@ -46,7 +46,7 @@
         uintptr_t *deque_left, *deque_middle, *deque_right;
         struct list_s *abort_list;
         uint64_t start_time;    /* the transaction's unique_start_time */
-        bool must_add_to_overflow_bags;
+        bool must_add_to_modified_bags;
     };
     char alignment[64];   /* 64-bytes alignment, to prevent false sharing */
 } stm_bag_seg_t;
@@ -74,7 +74,7 @@
         bs->deque_right = &block->items[0];
         LIST_CREATE(bs->abort_list);
         bs->start_time = 0;
-        bs->must_add_to_overflow_bags = false;   /* currently young */
+        bs->must_add_to_modified_bags = false;   /* currently young */
     }
     return bag;
 }
@@ -154,8 +154,7 @@
         bs->deque_middle = bs->deque_right;
         list_clear(bs->abort_list);
         bs->start_time = STM_PSEGMENT->unique_start_time;
-        bs->must_add_to_overflow_bags = false;    /* not current transaction
-                                                     any more */
+        bs->must_add_to_modified_bags = true;
 
         /* We're about to modify the bag, so register an abort
            callback now. */
@@ -172,11 +171,11 @@
     stm_bag_seg_t *bs = bag_check_start_time(bag);
     bag_add(bs, newobj);
 
-    if (bs->must_add_to_overflow_bags) {
-        bs->must_add_to_overflow_bags = false;
-        if (STM_PSEGMENT->overflow_bags == NULL)
-            LIST_CREATE(STM_PSEGMENT->overflow_bags);
-        LIST_APPEND(STM_PSEGMENT->overflow_bags, bag);
+    if (bs->must_add_to_modified_bags) {
+        bs->must_add_to_modified_bags = false;
+        if (STM_PSEGMENT->modified_bags == NULL)
+            LIST_CREATE(STM_PSEGMENT->modified_bags);
+        LIST_APPEND(STM_PSEGMENT->modified_bags, bag);
     }
 }
 
@@ -214,9 +213,7 @@
 
         deque_trace(bs->deque_middle, bs->deque_right, trace);
 
-        /* this case should only be called if the bag is from the current
-           transaction (either in the nursery or already overflowed) */
-        bs->must_add_to_overflow_bags = true;
+        bs->must_add_to_modified_bags = true;
     }
     else {
         int i;
@@ -227,9 +224,9 @@
     }
 }
 
-static void collect_overflow_bags(void)
+static void collect_modified_bags(void)
 {
-    LIST_FOREACH_R(STM_PSEGMENT->overflow_bags, stm_bag_t *,
+    LIST_FOREACH_R(STM_PSEGMENT->modified_bags, stm_bag_t *,
                    stm_bag_tracefn(item, TRACE_FOR_MINOR_COLLECTION));
-    LIST_FREE(STM_PSEGMENT->overflow_bags);
+    LIST_FREE(STM_PSEGMENT->modified_bags);
 }
diff --git a/c7/stm/bag.h b/c7/stm/bag.h
--- a/c7/stm/bag.h
+++ b/c7/stm/bag.h
@@ -1,2 +1,2 @@
 
-static void collect_overflow_bags(void);
+static void collect_modified_bags(void);
diff --git a/c7/stm/core.h b/c7/stm/core.h
--- a/c7/stm/core.h
+++ b/c7/stm/core.h
@@ -206,9 +206,8 @@
     /* regular finalizers (objs from the current transaction only) */
     struct finalizers_s *finalizers;
 
-    /* list of bags that are overflow objects (current transaction but
-       outside the nursery) */
-    struct list_s *overflow_bags;
+    /* list of bags that are old but modified */
+    struct list_s *modified_bags;
 };
 
 enum /* safe_point */ {
diff --git a/c7/stm/nursery.c b/c7/stm/nursery.c
--- a/c7/stm/nursery.c
+++ b/c7/stm/nursery.c
@@ -578,8 +578,8 @@
     if (STM_PSEGMENT->finalizers != NULL)
         collect_objs_still_young_but_with_finalizers();
 
-    if (STM_PSEGMENT->overflow_bags != NULL)
-        collect_overflow_bags();
+    if (STM_PSEGMENT->modified_bags != NULL)
+        collect_modified_bags();
 
     collect_oldrefs_to_nursery();
     assert(list_is_empty(STM_PSEGMENT->old_objects_with_cards));
diff --git a/c7/stm/setup.c b/c7/stm/setup.c
--- a/c7/stm/setup.c
+++ b/c7/stm/setup.c
@@ -130,7 +130,7 @@
         pr->callbacks_on_commit_and_abort[1] = tree_create();
         pr->young_objects_with_light_finalizers = list_create();
         pr->old_objects_with_light_finalizers = list_create();
-        pr->overflow_bags = NULL;
+        pr->modified_bags = NULL;
         pr->overflow_number = GCFLAG_OVERFLOW_NUMBER_bit0 * i;
         highest_overflow_number = pr->overflow_number;
         pr->pub.transaction_read_version = 0xff;
@@ -175,7 +175,7 @@
         tree_free(pr->callbacks_on_commit_and_abort[1]);
         list_free(pr->young_objects_with_light_finalizers);
         list_free(pr->old_objects_with_light_finalizers);
-        list_free(pr->overflow_bags);
+        list_free(pr->modified_bags);
     }
 
     munmap(stm_object_pages, TOTAL_MEMORY);
diff --git a/c7/test/test_bag.py b/c7/test/test_bag.py
--- a/c7/test/test_bag.py
+++ b/c7/test/test_bag.py
@@ -116,6 +116,19 @@
         assert lp1b != ffi.NULL
         assert stm_get_char(lp1b) == 'N'
         assert lp1b != lp1
+        #
+        self.commit_transaction()
+        self.start_transaction()
+        lp2 = stm_allocate(16)
+        stm_set_char(lp2, 'M')
+        b_add(b, lp2)
+        stm_minor_collect()
+        lp2b = b_pop(b)
+        assert lp2b != ffi.NULL
+        assert stm_get_char(lp2b) == 'M'
+        assert lp2b != lp2
+        #
+        stm_major_collect()       # to get rid of the bag object
 
     def test_transaction_local(self):
         self.start_transaction()


More information about the pypy-commit mailing list