[pypy-svn] r69938 - in pypy/branch/virtual-forcing/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Sun Dec 6 22:32:31 CET 2009


Author: arigo
Date: Sun Dec  6 22:32:29 2009
New Revision: 69938

Modified:
   pypy/branch/virtual-forcing/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_virtualizable.py
   pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_virtualref.py
Log:
Test when forcing occurs on a bridge.  Works for virtualizables,
but not yet for virtualrefs.  Changes in the code are no-ops.


Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/pyjitpl.py	Sun Dec  6 22:32:29 2009
@@ -1836,18 +1836,20 @@
         self.virtualref_boxes = virtualref_boxes
         if expect_virtualizable:
             self.virtualizable_boxes = virtualizable_boxes
-            if self._already_allocated_resume_virtuals is not None:
-                # resuming from a ResumeGuardForcedDescr: load the new values
-                # currently stored on the virtualizable fields
-                self.load_fields_from_virtualizable()
-                return
             # just jumped away from assembler (case 4 in the comment in
             # virtualizable.py) into tracing (case 2); check that vable_token
-            # is and stays 0.
+            # is and stays 0.  Note the call to reset_vable_token() in
+            # warmstate.py.
             virtualizable_box = self.virtualizable_boxes[-1]
             virtualizable = vinfo.unwrap_virtualizable_box(virtualizable_box)
             assert not virtualizable.vable_token
-            self.synchronize_virtualizable()
+            if self._already_allocated_resume_virtuals is not None:
+                # resuming from a ResumeGuardForcedDescr: load the new values
+                # currently stored on the virtualizable fields
+                self.load_fields_from_virtualizable()
+            else:
+                # normal case: fill the virtualizable with the local boxes
+                self.synchronize_virtualizable()
 
     def check_synchronized_virtualizable(self):
         if not we_are_translated():

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_virtualizable.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_virtualizable.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_virtualizable.py	Sun Dec  6 22:32:29 2009
@@ -907,6 +907,39 @@
         res = self.meta_interp(f, [123], policy=StopAtXPolicy(g))
         assert res == f(123)
 
+    def test_bridge_forces(self):
+        jitdriver = JitDriver(greens = [], reds = ['frame'],
+                              virtualizables = ['frame'])
+        
+        class Frame(object):
+            _virtualizable2_ = ['x', 'y']
+        class SomewhereElse:
+            pass
+        somewhere_else = SomewhereElse()
+
+        def g():
+            n = somewhere_else.top_frame.y + 700
+            debug_print(lltype.Void, '-+-+-+-+- external write:', n)
+            somewhere_else.top_frame.y = n
+
+        def f(n):
+            frame = Frame()
+            frame.x = n
+            frame.y = 10
+            somewhere_else.counter = 0
+            somewhere_else.top_frame = frame
+            while frame.x > 0:
+                jitdriver.can_enter_jit(frame=frame)
+                jitdriver.jit_merge_point(frame=frame)
+                if frame.y > 17:
+                    g()
+                frame.x -= 5
+                frame.y += 1
+            return frame.y
+
+        res = self.meta_interp(f, [123], policy=StopAtXPolicy(g))
+        assert res == f(123)
+
     def test_promote_index_in_virtualizable_list(self):
         jitdriver = JitDriver(greens = [], reds = ['frame', 'n'],
                               virtualizables = ['frame'])

Modified: pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_virtualref.py
==============================================================================
--- pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_virtualref.py	(original)
+++ pypy/branch/virtual-forcing/pypy/jit/metainterp/test/test_virtualref.py	Sun Dec  6 22:32:29 2009
@@ -193,6 +193,38 @@
         res = self.meta_interp(f, [30])
         assert res == 13
 
+    def test_bridge_forces(self):
+        py.test.skip("in-progress")
+        myjitdriver = JitDriver(greens = [], reds = ['n'])
+        #
+        class XY:
+            pass
+        class ExCtx:
+            pass
+        exctx = ExCtx()
+        #
+        @dont_look_inside
+        def externalfn(n):
+            exctx.m = exctx.topframeref().n
+            return 1
+        #
+        def f(n):
+            while n > 0:
+                myjitdriver.can_enter_jit(n=n)
+                myjitdriver.jit_merge_point(n=n)
+                xy = XY()
+                xy.n = n
+                exctx.topframeref = virtual_ref(xy)
+                if n == 13:
+                    externalfn(n)
+                n -= 1
+                virtual_ref_finish(exctx.topframeref)
+                exctx.topframeref = None
+            return exctx.m
+        #
+        res = self.meta_interp(f, [30])
+        assert res == 13
+
 
 class TestLLtype(VRefTests, LLJitMixin):
     pass



More information about the Pypy-commit mailing list