Author: Armin Rigo <[email protected]>
Branch: finalizer
Changeset: r1463:a02c1ad79557
Date: 2014-10-06 16:30 +0200
http://bitbucket.org/pypy/stmgc/changeset/a02c1ad79557/
Log: Major GC.
diff --git a/c7/stm/finalizer.c b/c7/stm/finalizer.c
--- a/c7/stm/finalizer.c
+++ b/c7/stm/finalizer.c
@@ -36,3 +36,30 @@
}
list_clear(lst);
}
+
+static void deal_with_old_objects_with_finalizers(void)
+{
+ long j;
+ for (j = 1; j <= NB_SEGMENTS; j++) {
+ struct stm_priv_segment_info_s *pseg = get_priv_segment(j);
+
+ struct list_s *lst = pseg->old_objects_with_light_finalizers;
+ long i, count = list_count(lst);
+ lst->count = 0;
+ for (i = 0; i < count; i++) {
+ object_t* obj = (object_t *)list_item(lst, i);
+ if (!mark_visited_test(obj)) {
+ /* not marked: object dies */
+ /* we're calling the light finalizer is a random thread,
+ but it should work, because it was dead already at the
+ start of that thread's transaction, so any thread should
+ see the same, old content */
+ stmcb_light_finalizer(obj);
+ }
+ else {
+ /* object survives */
+ list_set_item(lst, lst->count++, (uintptr_t)obj);
+ }
+ }
+ }
+}
diff --git a/c7/stm/finalizer.h b/c7/stm/finalizer.h
--- a/c7/stm/finalizer.h
+++ b/c7/stm/finalizer.h
@@ -1,2 +1,3 @@
static void deal_with_young_objects_with_finalizers(void);
+static void deal_with_old_objects_with_finalizers(void);
diff --git a/c7/stm/gcpage.c b/c7/stm/gcpage.c
--- a/c7/stm/gcpage.c
+++ b/c7/stm/gcpage.c
@@ -626,8 +626,9 @@
mark_visit_from_roots();
LIST_FREE(mark_objects_to_trace);
- /* weakrefs: */
+ /* weakrefs and old light finalizers */
stm_visit_old_weakrefs();
+ deal_with_old_objects_with_finalizers();
/* cleanup */
clean_up_segment_lists();
diff --git a/c7/test/test_finalizer.py b/c7/test/test_finalizer.py
--- a/c7/test/test_finalizer.py
+++ b/c7/test/test_finalizer.py
@@ -32,7 +32,7 @@
self.commit_transaction()
self.expect_finalized([lp1])
- def test_young_light_finalizer_dont_die(self):
+ def test_young_light_finalizer_survives(self):
self.start_transaction()
lp1 = stm_allocate(48)
lib.stm_enable_light_finalizer(lp1)
@@ -49,3 +49,27 @@
lib.stm_enable_light_finalizer(lp1)
self.commit_transaction()
self.expect_finalized([])
+
+ def test_old_light_finalizer(self):
+ self.start_transaction()
+ lp1 = stm_allocate(48)
+ lib.stm_enable_light_finalizer(lp1)
+ self.push_root(lp1)
+ stm_minor_collect()
+ lp1 = self.pop_root()
+ self.expect_finalized([])
+ stm_major_collect()
+ self.expect_finalized([lp1])
+ self.commit_transaction()
+
+ def test_old_light_finalizer_survives(self):
+ self.start_transaction()
+ lp1 = stm_allocate(48)
+ lib.stm_enable_light_finalizer(lp1)
+ self.push_root(lp1)
+ stm_minor_collect()
+ lp1 = self.pop_root()
+ self.push_root(lp1)
+ stm_major_collect()
+ self.commit_transaction()
+ self.expect_finalized([])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit