[pypy-svn] r25853 - in pypy/dist/pypy: rpython/memory translator/c/test

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Apr 15 13:33:17 CEST 2006


Author: cfbolz
Date: Sat Apr 15 13:33:08 2006
New Revision: 25853

Modified:
   pypy/dist/pypy/rpython/memory/gctransform.py
   pypy/dist/pypy/translator/c/test/test_newgc.py
Log:
test for saving of push/pop pairs plus a bit more tweaking


Modified: pypy/dist/pypy/rpython/memory/gctransform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctransform.py	Sat Apr 15 13:33:08 2006
@@ -959,6 +959,7 @@
         livevars = dict.fromkeys(
             [var for var in livevars if not var_ispyobj(var)], True)
         if not needs_conservative_livevar_calculation(block):
+            not_needed = {}
             if index == -1:
                 index = block.operations.index(op) # XXX hum
             needed = {}
@@ -966,11 +967,11 @@
                 if before_op.result not in livevars:
                     continue
                 if before_op.opname in ("cast_pointer", "same_as"):
-                    del livevars[before_op.result]
+                    not_needed[before_op.result] = True
                 elif before_op.opname in ("getfield", "getarrayitem"):
                     if (before_op.args[0] in livevars or
                         isinstance(before_op.args[0], Constant)):
-                        del livevars[before_op.result]
+                        not_needed[before_op.result] = True
             for after_op in block.operations[index:]:
                 for arg in after_op.args:
                     needed[arg] = True
@@ -980,7 +981,7 @@
                     needed[arg] = True
             newlivevars = []
             for var in livevars:
-                if var in needed:
+                if var in needed and var not in not_needed:
                     newlivevars.append(var)
             livevars = newlivevars
         else:

Modified: pypy/dist/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_newgc.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_newgc.py	Sat Apr 15 13:33:08 2006
@@ -210,6 +210,36 @@
         res = fn()
         assert res == 2
         assert len(self.t.graphs[0].startblock.exits[False].target.operations) == 10
+    def test_framework_safe_pushpop(self):
+        class A(object):
+            pass
+        class B(object):
+            pass
+        def g(x): # can cause a collect
+            return B()
+        global_a = A()
+        global_a.b = B()
+        global_a.b.a = A()
+        global_a.b.a.b = B()
+        global_a.b.a.b.c = 1
+        def f():
+            global_a.b.a.b.c = 40
+            a = global_a.b.a
+            b = a.b
+            b.c = 41
+            g(1)
+            b0 = a.b
+            b0.c = b.c = 42
+            # this should trigger a couple of collections
+            # XXX make sure it triggers at least one somehow!
+            for i in range(100000):
+                [A()] * 1000
+            return global_a.b.a.b.c
+        fn = self.getcompiled(f)
+        startblock = self.t.graphs[0].startblock
+        res = fn()
+        assert res == 42
+        assert len([op for op in startblock.operations if op.opname == "gc_reload_possibly_moved"]) == 0
 
     def test_framework_varsized(self):
         S = lltype.GcStruct("S", ('x', lltype.Signed))



More information about the Pypy-commit mailing list