[pypy-svn] r36749 - in pypy/dist/pypy/jit/timeshifter: . test

ac at codespeak.net ac at codespeak.net
Sun Jan 14 17:50:00 CET 2007


Author: ac
Date: Sun Jan 14 17:49:59 2007
New Revision: 36749

Modified:
   pypy/dist/pypy/jit/timeshifter/rcontainer.py
   pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py
Log:
(pedronis, arre) A small step forward. Reading a virtual struct from a
virtualizable more than once will get the same struct.



Modified: pypy/dist/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/rcontainer.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/rcontainer.py	Sun Jan 14 17:49:59 2007
@@ -372,7 +372,7 @@
                 self.ownbox.genvar = gv
                 self.ownbox.content = None
                 return
-        debug_print(lltype.Void, "FORCE CONTAINER")
+        debug_print(lltype.Void, "FORCE CONTAINER: "+ typedesc.TYPE._name)
         #debug_pdb(lltype.Void)
         genvar = builder.genop_malloc_fixedsize(typedesc.alloctoken)
         # force the box pointing to this VirtualStruct
@@ -461,7 +461,8 @@
     def __init__(self, RGenOp):
         self.RGenOp = RGenOp
         self.vinfos = []
-
+        self.s = lltype.nullptr(llmemory.GCREF.TO)
+        
     def read_field(self, fielddesc, base, index):
         T = fielddesc.RESTYPE
         vinfo = self.vinfos[index]
@@ -469,9 +470,11 @@
             return self.RGenOp.read_frame_var(T, base,
                                               self.info, index)
         assert isinstance(T, lltype.Ptr)
+        if self.s:
+            return lltype.cast_opaque_ptr(T, self.s)
         S = T.TO
         s = lltype.malloc(S)
-        # xxx remember that s has been forced
+        self.s = lltype.cast_opaque_ptr(llmemory.GCREF, s)
         fielddesc.fill_into(s, base, vinfo)
         return s
                     

Modified: pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_virtualizable.py	Sun Jan 14 17:49:59 2007
@@ -638,3 +638,67 @@
         res = self.timeshift_from_portal(main, f, [2, 20, 10],
                                          policy=StopAtGPolicy())
         assert res == 42
+
+    def test_explicit_force_multiple_reads_residual_red_call(self):
+        def get_p(xp):
+            xp_access = xp.vable_access
+            if xp_access:
+                p = xp_access.get_p(xp)
+            else:
+                p = xp.p
+            return p
+        def g(e):
+            xp = e.xp
+            p1 = get_p(xp)
+            p2 = get_p(xp)
+            e.w = int(p1 == p2)
+
+        def f(e, a, b):
+            xp = e.xp
+            s = lltype.malloc(S)
+            s.a = a
+            s.b = b            
+            xp_access = xp.vable_access
+            if xp_access:
+                xp_access.set_p(xp, s)
+            else:
+                xp.p = s
+            xp_access = xp.vable_access
+            
+            xp_access = xp.vable_access
+            if xp_access:
+                x = xp_access.get_x(xp)
+            else:
+                x = xp.x
+            xp_access = xp.vable_access
+            newx = 2*x
+            if xp_access:
+                xp_access.set_x(xp, newx)
+            else:
+                xp.x = newx
+            g(e)            
+            return xp.x
+            
+        def main(a, b, x):
+            xp = lltype.malloc(XP)
+            xp.vable_access = lltype.nullptr(XP_ACCESS)
+            xp.x = x
+            xp.p = lltype.nullptr(S)
+            e = lltype.malloc(E2)
+            e.xp = xp
+            f(e, a, b)
+            return e.w
+
+
+        class StopAtGPolicy(HintAnnotatorPolicy):
+            def __init__(self):
+                HintAnnotatorPolicy.__init__(self, novirtualcontainer=True)
+
+            def look_inside_graph(self, graph):
+                if graph.name == 'g':
+                    return False
+                return True
+
+        res = self.timeshift_from_portal(main, f, [2, 20, 10],
+                                         policy=StopAtGPolicy())
+        assert res == 1



More information about the Pypy-commit mailing list