[pypy-svn] r67846 - in pypy/branch/remove-plfbid/pypy/jit: backend/test metainterp/test

pedronis at codespeak.net pedronis at codespeak.net
Tue Sep 22 17:56:00 CEST 2009


Author: pedronis
Date: Tue Sep 22 17:55:59 2009
New Revision: 67846

Modified:
   pypy/branch/remove-plfbid/pypy/jit/backend/test/runner_test.py
   pypy/branch/remove-plfbid/pypy/jit/metainterp/test/test_basic.py
Log:
(arigo, pedronis) a test and a goal test



Modified: pypy/branch/remove-plfbid/pypy/jit/backend/test/runner_test.py
==============================================================================
--- pypy/branch/remove-plfbid/pypy/jit/backend/test/runner_test.py	(original)
+++ pypy/branch/remove-plfbid/pypy/jit/backend/test/runner_test.py	Tue Sep 22 17:55:59 2009
@@ -121,6 +121,30 @@
         res = self.cpu.get_latest_value_int(0)
         assert res == 10
 
+    def test_backends_dont_keep_loops_alive(self):
+        import weakref, gc
+        loop = TreeLoop('single op')
+        i0 = BoxInt()
+        i1 = BoxInt()
+        i2 = BoxInt()
+        loop.operations = [
+            ResOperation(rop.INT_ADD, [i0, ConstInt(1)], i1),
+            ResOperation(rop.INT_LE, [i1, ConstInt(9)], i2),
+            ResOperation(rop.GUARD_TRUE, [i2], None),
+            ResOperation(rop.JUMP, [i1], None),
+            ]
+        loop.inputargs = [i0]
+        loop.operations[2].suboperations = [
+            ResOperation(rop.FAIL, [i1], None)
+            ]
+        loop.operations[-1].jump_target = loop
+        
+        executable_token = self.cpu.compile_loop(loop)        
+        wr = weakref.ref(loop)
+        del loop
+        gc.collect()
+        assert not wr()
+
     def test_compile_bridge(self):
         loop = TreeLoop('single op')
         i0 = BoxInt()

Modified: pypy/branch/remove-plfbid/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/remove-plfbid/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/branch/remove-plfbid/pypy/jit/metainterp/test/test_basic.py	Tue Sep 22 17:55:59 2009
@@ -177,12 +177,6 @@
         res = self.interp_operations(f, [40, 2])
         assert res == 42
 
-    def test_basic_mp(self):
-        def f(x, y):
-            return x + y
-        res = self.interp_operations(f, [40, 2])
-        assert res == 42
-
     def test_basic_inst(self):
         class A:
             pass
@@ -238,6 +232,36 @@
                     found += 1
             assert found == 1
 
+    @py.test.mark.xfail
+    def test_loops_are_transient(self):
+        import gc, weakref
+        myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res'])
+        def f(x, y):
+            res = 0
+            while y > 0:
+                myjitdriver.can_enter_jit(x=x, y=y, res=res)
+                myjitdriver.jit_merge_point(x=x, y=y, res=res)
+                res += x
+                if y%2:
+                    res *= 2
+                y -= 1
+            return res
+        wr_loops = []
+        old_init = history.TreeLoop.__init__.im_func
+        try:
+            def track_init(self, name):
+                old_init(self, name)
+                wr_loops.append(weakref.ref(self))
+            history.TreeLoop.__init__ = track_init
+            res = self.meta_interp(f, [6, 15], no_stats=True)
+        finally:
+            history.TreeLoop.__init__ = old_init
+            
+        assert res == f(6, 15)
+        gc.collect()
+
+        assert not [wr for wr in wr_loops if wr()]
+
     def test_string(self):
         def f(n):
             bytecode = 'adlfkj' + chr(n)



More information about the Pypy-commit mailing list