Author: Remi Meier <[email protected]>
Branch: stmgc-c8
Changeset: r80892:1f6b1cc69bca
Date: 2015-11-24 16:27 +0100
http://bitbucket.org/pypy/pypy/changeset/1f6b1cc69bca/

Log:    more tests and fix

diff --git a/rpython/memory/gctransform/framework.py 
b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -110,6 +110,7 @@
             elif op.opname == "stm_ignored_stop":
                 self.in_stm_ignored = False
             elif op.opname == "gc_writebarrier":
+                assert not self.in_stm_ignored
                 writeable[op.args[0]] = True
             elif op.opname == "malloc":
                 rtti = get_rtti(op.args[0].value)
@@ -148,13 +149,16 @@
                         # already writeable, this op is also clean
                         self.clean_ops.add(op)
                     elif op in self.clean_ops:
-                        # we require an stm_write
+                        # we changed our opinion in this iteration
                         self.clean_ops.remove(op)
                     # always writeable after this op
                     writeable[op.args[0]] = True
                 else:
                     # things that need partial write barriers (card marking)
-                    assert op not in self.clean_ops
+                    if writeable.get(op.args[0], False):
+                        self.clean_ops.add(op)
+                    elif op in self.clean_ops:
+                        self.clean_ops.remove(op)
         #
         # update in_states of all successors
         updated = set()
diff --git a/rpython/memory/gctransform/test/test_framework.py 
b/rpython/memory/gctransform/test/test_framework.py
--- a/rpython/memory/gctransform/test/test_framework.py
+++ b/rpython/memory/gctransform/test/test_framework.py
@@ -19,6 +19,7 @@
 from rpython.translator.unsimplify import varoftype
 
 import py
+import pytest
 
 class FrameworkGcPolicy2(BasicFrameworkGcPolicy):
     class transformerclass(ShadowStackFrameworkGCTransformer):
@@ -61,6 +62,7 @@
 
     assert res == 2
 
[email protected](reason="llinterp does not implement stm_allocate_tid")
 def test_framework_simple_stm():
     test_framework_simple("stmgc")
 
@@ -324,8 +326,75 @@
     db = cbuild.generate_graphs_for_llinterp()
 
     ff = graphof(t, f)
-    ff.show()
-    assert summary(ff)['stm_write'] == 2    # only one remember_young_pointer
+    #ff.show()
+    assert summary(ff)['stm_write'] == 2
+
+def test_remove_write_barrier_stm2():
+    from rpython.translator.c.genc import CStandaloneBuilder
+    from rpython.flowspace.model import summary
+    from rpython.rlib.objectmodel import stm_ignored
+
+    class A: pass
+    glob = A()
+    glob2 = A()
+    def f(n, g, g2):
+        i = 1
+        while n:
+            g.a = i # WB
+            with stm_ignored:
+                g2.a = i
+    def g(argv):
+        if argv[1]:
+            f(int(argv[1]), glob, glob2)
+        else:
+            f(int(argv[1]), glob2, glob)
+        return 0
+
+    t = rtype(g, [s_list_of_strings])
+    t.config.translation.stm = True
+    gcpolicy = StmFrameworkGcPolicy
+    t.config.translation.gc = "stmgc"
+    cbuild = CStandaloneBuilder(t, g, t.config,
+                                gcpolicy=gcpolicy)
+    db = cbuild.generate_graphs_for_llinterp()
+
+    ff = graphof(t, f)
+    #ff.show()
+    assert summary(ff)['stm_write'] == 1
+
+def test_remove_write_barrier_stm3():
+    from rpython.translator.c.genc import CStandaloneBuilder
+    from rpython.flowspace.model import summary
+
+    S = lltype.GcStruct('S')
+    A = lltype.GcArray(lltype.Ptr(S))
+    def f(l, l2, i):
+        s = lltype.malloc(S)
+        llop.gc_writebarrier(lltype.Void, l2)
+        while i:
+            l[i] = s # WB card
+            l[i] = s # WB card
+            l2[i] = s # no WB
+    def g(argv):
+        n = int(argv[1])
+        l = lltype.malloc(A, n)
+        l[0] = lltype.malloc(S)
+        l[1] = lltype.malloc(S)
+        l[2] = lltype.malloc(S)
+        f(l, l, n)
+        return 0
+    t = rtype(g, [s_list_of_strings])
+    t.config.translation.stm = True
+    gcpolicy = StmFrameworkGcPolicy
+    t.config.translation.gc = "stmgc"
+    cbuild = CStandaloneBuilder(t, g, t.config,
+                                gcpolicy=gcpolicy)
+    db = cbuild.generate_graphs_for_llinterp()
+
+    ff = graphof(t, f)
+    #ff.show()
+    assert summary(ff)['stm_write'] == 3
+
 
 def test_write_barrier_collector():
     class A(object):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to