Author: Stefan Beyer <[email protected]>
Branch: cpyext-gc-cycle
Changeset: r97554:a84af3d1e5c1
Date: 2019-09-19 12:46 +0200
http://bitbucket.org/pypy/pypy/changeset/a84af3d1e5c1/

Log:    Fixed tests for non-gc proxies in mark Added some TODOs and comments

diff --git a/rpython/memory/gc/rrc/base.py b/rpython/memory/gc/rrc/base.py
--- a/rpython/memory/gc/rrc/base.py
+++ b/rpython/memory/gc/rrc/base.py
@@ -388,11 +388,11 @@
         pygchdr = self.pyobj_as_gc(pyobj)
         if pygchdr != lltype.nullptr(self.PYOBJ_GC_HDR):
             if pygchdr.c_gc_refs != self.RAWREFCOUNT_REFS_UNTRACKED:
-                rc = 0
+                rc = 0 # do not mark, we will mark them later
             else:
-                rc = pyobj.c_ob_refcnt
+                rc = pyobj.c_ob_refcnt # take cyclic refcount
         else:
-            rc = pyobj.c_ob_refcnt
+            rc = pyobj.c_ob_refcnt # take cyclic refcount
 
         if rc == REFCNT_FROM_PYPY or rc == REFCNT_FROM_PYPY_LIGHT or rc == 0:
             pass  # the corresponding object may die
diff --git a/rpython/memory/gc/rrc/incmark.py b/rpython/memory/gc/rrc/incmark.py
--- a/rpython/memory/gc/rrc/incmark.py
+++ b/rpython/memory/gc/rrc/incmark.py
@@ -239,7 +239,7 @@
         # take snapshot of p_list_old
         self.p_list_old.foreach(self._take_snapshot_pyobject, None)
 
-        # take snapshot of gc objs
+        # take snapshot of gc objs TODO: include finalizer_list from last cycle
         pygchdr = pygclist.c_gc_next
         while pygchdr <> pygclist:
             pyobj = self.gc_as_pyobj(pygchdr)
diff --git a/rpython/memory/gc/rrc/mark.py b/rpython/memory/gc/rrc/mark.py
--- a/rpython/memory/gc/rrc/mark.py
+++ b/rpython/memory/gc/rrc/mark.py
@@ -61,8 +61,8 @@
             use_cylicrc = not found_finalizer
             self._debug_check_consistency(print_label="end-mark-cyclic")
 
-            # mark all pypy objects at the border which are linked to non-gc
-            # pyobjs which are not directly referenced by any gc pyobj
+            # mark all pypy objects at the border which are linked to live
+            # non-gc pyobjs which are not directly referenced by any gc pyobj
             debug_print("use_cylicrc", use_cylicrc)
             self.p_list_old.foreach(self._major_trace, (use_cylicrc, True))  # 
TODO: set flag to keep marked, check other occurences
             self._debug_check_consistency(print_label="end-mark")
@@ -149,8 +149,6 @@
 
     def _obj_fix_refcnt(self, pyobject, ignore):
         pyobj = self._pyobj(pyobject)
-        #intobj = pyobj.c_ob_pypy_link
-        #obj = llmemory.cast_int_to_adr(intobj)
         obj = self.refcnt_dict.get(pyobject)
         gchdr = self.pyobj_as_gc(pyobj)
         if gchdr <> lltype.nullptr(self.PYOBJ_GC_HDR):
@@ -167,6 +165,11 @@
                                               self.GCFLAG_NO_HEAP_PTRS):
                     refcnt += 1
                 self._pyobj_gc_refcnt_set(gchdr, refcnt)
+        else:
+            debug_print("non gc obj", obj, "real-rc", pyobj.c_ob_refcnt)
+            if self.gc.header(obj).tid & (self.GCFLAG_VISITED |
+                                          self.GCFLAG_NO_HEAP_PTRS):
+                pyobj.c_ob_refcnt += 1
 
     def _mark_rawrefcount(self):
         if self._gc_list_is_empty(self.pyobj_list):
diff --git a/rpython/memory/gc/test/dot/free_cross_simple_2.dot 
b/rpython/memory/gc/test/dot/free_cross_nogc_1.dot
copy from rpython/memory/gc/test/dot/free_cross_simple_2.dot
copy to rpython/memory/gc/test/dot/free_cross_nogc_1.dot
--- a/rpython/memory/gc/test/dot/free_cross_simple_2.dot
+++ b/rpython/memory/gc/test/dot/free_cross_nogc_1.dot
@@ -2,7 +2,7 @@
     "a" [type=P, alive=n];
     "b" [type=B, alive=n];
     "c" [type=C, alive=n];
-    "d" [type=B, alive=n];
+    "d" [type=B, alive=n, gc=n];
     "a" -> "b";
     "b" -> "c";
     "c" -> "d";
diff --git a/rpython/memory/gc/test/dot/free_cross_simple_2.dot 
b/rpython/memory/gc/test/dot/keep_cross_nogc_1.dot
copy from rpython/memory/gc/test/dot/free_cross_simple_2.dot
copy to rpython/memory/gc/test/dot/keep_cross_nogc_1.dot
--- a/rpython/memory/gc/test/dot/free_cross_simple_2.dot
+++ b/rpython/memory/gc/test/dot/keep_cross_nogc_1.dot
@@ -1,10 +1,12 @@
 digraph G {
-    "a" [type=P, alive=n];
-    "b" [type=B, alive=n];
-    "c" [type=C, alive=n];
-    "d" [type=B, alive=n];
+    "a" [type=P, alive=y];
+    "b" [type=B, alive=y];
+    "c" [type=C, alive=y];
+    "d" [type=B, alive=y, gc=n];
+    "e" [type=P, alive=y, rooted=y];
     "a" -> "b";
     "b" -> "c";
     "c" -> "d";
     "d" -> "a";
+    "e" -> "d";
 }
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
@@ -26,8 +26,8 @@
 
 class TestRawRefCount(BaseDirectGCTest):
     GCClass = IncMiniMark
-    RRCGCClass = RawRefCountIncMarkGC
-    #RRCGCClass = RawRefCountMarkGC
+    #RRCGCClass = RawRefCountIncMarkGC
+    RRCGCClass = RawRefCountMarkGC
 
     def setup_method(self, method):
         BaseDirectGCTest.setup_method(self, method)
@@ -60,10 +60,7 @@
 
         def rawrefcount_pyobj_as_gc(pyobj):
             index = self.pyobjs.index(pyobj)
-            if self.is_pygc[index]:
-                return self.gcobjs[index]
-            else:
-                return lltype.nullptr(PYOBJ_GC_HDR)
+            return self.gcobjs[index]
 
         def rawrefcount_finalizer_type(gc):
             pyobj = self.pyobjs[self.gcobjs.index(gc)]
@@ -166,6 +163,8 @@
 
         if is_gc:
             self._rawrefcount_add_gc(tracked, tuple)
+        else:
+            self.gcobjs.append(lltype.nullptr(PYOBJ_GC_HDR))
 
         self.pyobjs.append(r1)
         self.is_pygc.append(is_gc)
@@ -214,6 +213,8 @@
 
         if is_gc:
             self._rawrefcount_add_gc(tracked, tuple)
+        else:
+            self.gcobjs.append(lltype.nullptr(PYOBJ_GC_HDR))
 
         self.pyobjs.append(r1)
         self.is_pygc.append(is_gc)
@@ -510,7 +511,7 @@
 
         class NodeInfo:
             def __init__(self, type, alive, ext_refcnt, finalizer, resurrect,
-                         delete, garbage, tuple):
+                         delete, garbage, tuple, gc):
                 self.type = type
                 self.alive = alive
                 self.ext_refcnt = ext_refcnt
@@ -519,6 +520,7 @@
                 self.delete = delete
                 self.garbage = garbage
                 self.tuple = tuple
+                self.gc = gc
 
         class WeakrefNode(BorderNode):
             def __init__(self, p, pref, r, raddr, check_alive, info, r_dest,
@@ -556,8 +558,9 @@
             delete = attr['delete'] if 'delete' in attr else None
             garbage = True if 'garbage' in attr else False
             tuple = attr['tuple'] == "y" if 'tuple' in attr else False
+            gc = attr['gc'] == "y" if 'gc' in attr else True
             info = NodeInfo(type, alive, ext_refcnt, finalizer, resurrect,
-                            delete, garbage, tuple)
+                            delete, garbage, tuple, gc)
             if type == "C":
                 r, raddr, check_alive = self._rawrefcount_pyobj(
                     tracked=tracked, tuple=tuple)
@@ -569,11 +572,11 @@
                                               create_old=True)
                 nodes[name] = PyPyNode(p, pref, check_alive, info)
                 i += 1
-            elif type == "B":
+            elif type == "B": # TODO: add to correct list (now always p_list)
                 p, pref, r, raddr, check_alive =\
                     self._rawrefcount_pair(42 + i, rooted=rooted,
                                            create_old=True, tracked=tracked,
-                                           tuple=tuple)
+                                           tuple=tuple, is_gc=gc)
                 r.c_ob_refcnt += ext_refcnt
                 nodes[name] = BorderNode(p, pref, r, raddr, check_alive, info)
                 i += 1
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to