[pypy-commit] pypy default: Test and fix: if we use create_link_pypy() on *non-nursery* young

arigo pypy.commits at gmail.com
Sat Mar 12 14:25:12 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r82998:82f5992c242d
Date: 2016-03-12 20:24 +0100
http://bitbucket.org/pypy/pypy/changeset/82f5992c242d/

Log:	Test and fix: if we use create_link_pypy() on *non-nursery* young
	objects, crash

diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -1654,15 +1654,15 @@
             else:
                 self.nursery_objects_shadows.clear()
         #
+        # visit the P and O lists from rawrefcount, if enabled.
+        if self.rrc_enabled:
+            self.rrc_minor_collection_free()
+        #
         # Walk the list of young raw-malloced objects, and either free
         # them or make them old.
         if self.young_rawmalloced_objects:
             self.free_young_rawmalloced_objects()
         #
-        # visit the P and O lists from rawrefcount, if enabled.
-        if self.rrc_enabled:
-            self.rrc_minor_collection_free()
-        #
         # All live nursery objects are out of the nursery or pinned inside
         # the nursery.  Create nursery barriers to protect the pinned objects,
         # fill the rest of the nursery with zeros and reset the current nursery
diff --git a/rpython/memory/gc/test/test_rawrefcount.py b/rpython/memory/gc/test/test_rawrefcount.py
--- a/rpython/memory/gc/test/test_rawrefcount.py
+++ b/rpython/memory/gc/test/test_rawrefcount.py
@@ -29,7 +29,8 @@
         assert count2 - count1 == expected_trigger
 
     def _rawrefcount_pair(self, intval, is_light=False, is_pyobj=False,
-                          create_old=False, create_immortal=False):
+                          create_old=False, create_immortal=False,
+                          force_external=False):
         if is_light:
             rc = REFCNT_FROM_PYPY_LIGHT
         else:
@@ -40,7 +41,13 @@
         if create_immortal:
             p1 = lltype.malloc(S, immortal=True)
         else:
-            p1 = self.malloc(S)
+            saved = self.gc.nonlarge_max
+            try:
+                if force_external:
+                    self.gc.nonlarge_max = 1
+                p1 = self.malloc(S)
+            finally:
+                self.gc.nonlarge_max = saved
         p1.x = intval
         if create_immortal:
             self.consider_constant(p1)
@@ -220,9 +227,10 @@
     def test_pypy_nonlight_dies_quickly_old(self):
         self.test_pypy_nonlight_dies_quickly(old=True)
 
-    def test_pyobject_pypy_link_dies_on_minor_collection(self):
+    @py.test.mark.parametrize('external', [False, True])
+    def test_pyobject_pypy_link_dies_on_minor_collection(self, external):
         p1, p1ref, r1, r1addr, check_alive = (
-            self._rawrefcount_pair(42, is_pyobj=True))
+            self._rawrefcount_pair(42, is_pyobj=True, force_external=external))
         check_alive(0)
         r1.ob_refcnt += 1            # the pyobject is kept alive
         self._collect(major=False)
@@ -231,9 +239,12 @@
         self.gc.check_no_more_rawrefcount_state()
         lltype.free(r1, flavor='raw')
 
-    def test_pyobject_dies(self, old=False):
+    @py.test.mark.parametrize('old,external', [
+        (False, False), (True, False), (False, True)])
+    def test_pyobject_dies(self, old, external):
         p1, p1ref, r1, r1addr, check_alive = (
-            self._rawrefcount_pair(42, is_pyobj=True, create_old=old))
+            self._rawrefcount_pair(42, is_pyobj=True, create_old=old,
+                                   force_external=external))
         check_alive(0)
         if old:
             self._collect(major=False)
@@ -247,9 +258,12 @@
         self.gc.check_no_more_rawrefcount_state()
         lltype.free(r1, flavor='raw')
 
-    def test_pyobject_survives_from_obj(self, old=False):
+    @py.test.mark.parametrize('old,external', [
+        (False, False), (True, False), (False, True)])
+    def test_pyobject_survives_from_obj(self, old, external):
         p1, p1ref, r1, r1addr, check_alive = (
-            self._rawrefcount_pair(42, is_pyobj=True, create_old=old))
+            self._rawrefcount_pair(42, is_pyobj=True, create_old=old,
+                                   force_external=external))
         check_alive(0)
         self.stackroots.append(p1)
         self._collect(major=False)
@@ -269,11 +283,6 @@
         self.gc.check_no_more_rawrefcount_state()
         lltype.free(r1, flavor='raw')
 
-    def test_pyobject_dies_old(self):
-        self.test_pyobject_dies(old=True)
-    def test_pyobject_survives_from_obj_old(self):
-        self.test_pyobject_survives_from_obj(old=True)
-
     def test_pyobject_attached_to_prebuilt_obj(self):
         p1, p1ref, r1, r1addr, check_alive = (
             self._rawrefcount_pair(42, create_immortal=True))


More information about the pypy-commit mailing list