[pypy-svn] r71326 - in pypy/branch/debug-vref/pypy/jit/backend: llsupport llsupport/test x86/test

arigo at codespeak.net arigo at codespeak.net
Fri Feb 19 12:53:32 CET 2010


Author: arigo
Date: Fri Feb 19 12:53:31 2010
New Revision: 71326

Modified:
   pypy/branch/debug-vref/pypy/jit/backend/llsupport/gc.py
   pypy/branch/debug-vref/pypy/jit/backend/llsupport/test/test_gc.py
   pypy/branch/debug-vref/pypy/jit/backend/x86/test/test_zrpy_gc.py
Log:
svn merge -r71323:71325 svn+ssh://codespeak.net/svn/pypy/trunk/pypy/jit


Modified: pypy/branch/debug-vref/pypy/jit/backend/llsupport/gc.py
==============================================================================
--- pypy/branch/debug-vref/pypy/jit/backend/llsupport/gc.py	(original)
+++ pypy/branch/debug-vref/pypy/jit/backend/llsupport/gc.py	Fri Feb 19 12:53:31 2010
@@ -503,15 +503,16 @@
             # xxx some performance issue here
             for i in range(len(op.args)):
                 v = op.args[i]
-                if (isinstance(v, ConstPtr) and bool(v.value)
-                                            and rgc.can_move(v.value)):
-                    box = BoxPtr(v.value)
+                if isinstance(v, ConstPtr) and bool(v.value):
                     addr = self.gcrefs.get_address_of_gcref(v.value)
-                    addr = cpu.cast_adr_to_int(addr)
-                    newops.append(ResOperation(rop.GETFIELD_RAW,
-                                               [ConstInt(addr)], box,
-                                               self.single_gcref_descr))
-                    op.args[i] = box
+                    # ^^^even for non-movable objects, to record their presence
+                    if rgc.can_move(v.value):
+                        box = BoxPtr(v.value)
+                        addr = cpu.cast_adr_to_int(addr)
+                        newops.append(ResOperation(rop.GETFIELD_RAW,
+                                                   [ConstInt(addr)], box,
+                                                   self.single_gcref_descr))
+                        op.args[i] = box
             # ---------- write barrier for SETFIELD_GC ----------
             if op.opnum == rop.SETFIELD_GC:
                 v = op.args[1]

Modified: pypy/branch/debug-vref/pypy/jit/backend/llsupport/test/test_gc.py
==============================================================================
--- pypy/branch/debug-vref/pypy/jit/backend/llsupport/test/test_gc.py	(original)
+++ pypy/branch/debug-vref/pypy/jit/backend/llsupport/test/test_gc.py	Fri Feb 19 12:53:31 2010
@@ -278,9 +278,12 @@
         # check rewriting of ConstPtrs
         class MyFakeCPU:
             def cast_adr_to_int(self, adr):
-                stored_addr = adr.address[0]
-                assert stored_addr == llmemory.cast_ptr_to_adr(s_gcref)
+                assert adr == "some fake address"
                 return 43
+        class MyFakeGCRefList:
+            def get_address_of_gcref(self, s_gcref1):
+                assert s_gcref1 == s_gcref
+                return "some fake address"
         S = lltype.GcStruct('S')
         s = lltype.malloc(S)
         s_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, s)
@@ -291,6 +294,7 @@
                          v_result),
             ]
         gc_ll_descr = self.gc_ll_descr
+        gc_ll_descr.gcrefs = MyFakeGCRefList()
         gc_ll_descr.rewrite_assembler(MyFakeCPU(), operations)
         assert len(operations) == 2
         assert operations[0].opnum == rop.GETFIELD_RAW
@@ -302,6 +306,42 @@
         assert operations[1].args == [v_random_box, v_box]
         assert operations[1].result == v_result
 
+    def test_rewrite_assembler_1_cannot_move(self):
+        # check rewriting of ConstPtrs
+        class MyFakeCPU:
+            def cast_adr_to_int(self, adr):
+                xxx    # should not be called
+        class MyFakeGCRefList:
+            def get_address_of_gcref(self, s_gcref1):
+                seen.append(s_gcref1)
+                assert s_gcref1 == s_gcref
+                return "some fake address"
+        seen = []
+        S = lltype.GcStruct('S')
+        s = lltype.malloc(S)
+        s_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, s)
+        v_random_box = BoxPtr()
+        v_result = BoxInt()
+        operations = [
+            ResOperation(rop.OOIS, [v_random_box, ConstPtr(s_gcref)],
+                         v_result),
+            ]
+        gc_ll_descr = self.gc_ll_descr
+        gc_ll_descr.gcrefs = MyFakeGCRefList()
+        old_can_move = rgc.can_move
+        try:
+            rgc.can_move = lambda s: False
+            gc_ll_descr.rewrite_assembler(MyFakeCPU(), operations)
+        finally:
+            rgc.can_move = old_can_move
+        assert len(operations) == 1
+        assert operations[0].opnum == rop.OOIS
+        assert operations[0].args == [v_random_box, ConstPtr(s_gcref)]
+        assert operations[0].result == v_result
+        # check that s_gcref gets added to the list anyway, to make sure
+        # that the GC sees it
+        assert seen == [s_gcref]
+
     def test_rewrite_assembler_2(self):
         # check write barriers before SETFIELD_GC
         v_base = BoxPtr()

Modified: pypy/branch/debug-vref/pypy/jit/backend/x86/test/test_zrpy_gc.py
==============================================================================
--- pypy/branch/debug-vref/pypy/jit/backend/x86/test/test_zrpy_gc.py	(original)
+++ pypy/branch/debug-vref/pypy/jit/backend/x86/test/test_zrpy_gc.py	Fri Feb 19 12:53:31 2010
@@ -12,6 +12,7 @@
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rlib.jit import JitDriver, OPTIMIZER_SIMPLE, dont_look_inside
+from pypy.rlib.jit import purefunction
 from pypy.jit.backend.x86.runner import CPU386
 from pypy.jit.backend.llsupport.gc import GcRefList, GcRootMap_asmgcc
 from pypy.tool.udir import udir
@@ -413,3 +414,28 @@
     def test_compile_hybrid_external_exception_handling(self):
         self.run('compile_hybrid_external_exception_handling')
             
+    def define_compile_hybrid_bug1(self):
+        @purefunction
+        def nonmoving():
+            x = X(1)
+            for i in range(7):
+                rgc.collect()
+            return x
+
+        @dont_look_inside
+        def do_more_stuff():
+            x = X(5)
+            for i in range(7):
+                rgc.collect()
+            return x
+
+        def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
+            x0 = do_more_stuff()
+            check(nonmoving().x == 1)
+            n -= 1
+            return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
+
+        return None, f, None
+
+    def test_compile_hybrid_bug1(self):
+        self.run('compile_hybrid_bug1', 200)



More information about the Pypy-commit mailing list