[pypy-svn] r61791 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test

fijal at codespeak.net fijal at codespeak.net
Thu Feb 12 16:32:37 CET 2009


Author: fijal
Date: Thu Feb 12 16:32:35 2009
New Revision: 61791

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
Log:
(arigo, fijal)
Correctly handle guard failure with virtualizables around


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py	Thu Feb 12 16:32:35 2009
@@ -71,9 +71,14 @@
     def __init__(self):
         # allocations: list of vtables to allocate
         # setfields: list of triples
-        #                 (index_in_allocations, ofs, index_in_arglist)
+        #                 (index_in_allocations, ofs, ~index_in_arglist)
         #                  -or-
-        #                 (index_in_allocations, ofs, ~index_in_allocations)
+        #                 (index_in_allocations, ofs, index_in_allocations)
+        #                  -or-
+        #                 (~index_in_arglist, ofs, index_in_allocations)
+        #                  -or-
+        #                 (~index_in_arglist, ofs, ~index_in_arglist)
+        # last two cases are for virtualizables only
         self.allocations = []
         self.setfields = []
 
@@ -82,19 +87,28 @@
             return memo[box]
         if isinstance(box, Const):
             virtual = False
+            virtualized = False
         else:
             instnode = nodes[box]
             virtual = instnode.virtual
+            virtualized = instnode.virtualized
         if virtual:
             alloc_offset = len(self.allocations)
             self.allocations.append(instnode.cls.source.getint())
-            res = ~alloc_offset
+            res = alloc_offset
             memo[box] = res
             for ofs, node in instnode.curfields.items():
                 num = self.deal_with_box(node.source, nodes, liveboxes, memo)
                 self.setfields.append((alloc_offset, ofs, num))
+        elif virtualized:
+            res = ~len(liveboxes)
+            memo[box] = res
+            liveboxes.append(box)
+            for ofs, node in instnode.curfields.items():
+                num = self.deal_with_box(node.source, nodes, liveboxes, memo)
+                self.setfields.append((res, ofs, num))
         else:
-            res = len(liveboxes)
+            res = ~len(liveboxes)
             memo[box] = res
             liveboxes.append(box)
         return res
@@ -546,18 +560,20 @@
         allocated_boxes.append(instbox)
     for index_in_alloc, ofs, index_in_arglist in storage.setfields:
         if index_in_arglist < 0:
-            fieldbox = allocated_boxes[~index_in_arglist]
+            fieldbox = boxes_from_frame[~index_in_arglist]
+        else:
+            fieldbox = allocated_boxes[index_in_arglist]
+        if index_in_alloc < 0:
+            box = boxes_from_frame[~index_in_alloc]
         else:
-            fieldbox = boxes_from_frame[index_in_arglist]
-        vtable = storage.allocations[index_in_alloc]
-        box = allocated_boxes[index_in_alloc]
+            box = allocated_boxes[index_in_alloc]
         history.execute_and_record('setfield_gc',
                                    [box, ConstInt(ofs), fieldbox],
                                    'void', False)
     newboxes = []
     for index in storage.indices:
         if index < 0:
-            newboxes.append(allocated_boxes[~index])
+            newboxes.append(boxes_from_frame[~index])
         else:
-            newboxes.append(boxes_from_frame[index])
+            newboxes.append(allocated_boxes[index])
     return newboxes

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	Thu Feb 12 16:32:35 2009
@@ -415,7 +415,8 @@
         clsbox = self.cls_of_box(box)
         op = self.generate_guard(pc, 'guard_nonvirtualized', box,
                                  [clsbox, ConstInt(guard_field)])
-        op.desc = vdesc
+        if op:
+            op.desc = vdesc
         
     @arguments("box")
     def opimpl_keepalive(self, box):

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py	Thu Feb 12 16:32:35 2009
@@ -296,7 +296,7 @@
     assert guard_op.liveboxes == [E.sum2, E.v2]
     vt = cpu.cast_adr_to_int(node_vtable_adr)
     assert guard_op.storage_info.allocations == [vt]
-    assert guard_op.storage_info.setfields == [(0, E.ofs_value, 1)]
+    assert guard_op.storage_info.setfields == [(0, E.ofs_value, -2)]
 
 def test_E_rebuild_after_failure():
     class FakeHistory(object):
@@ -425,7 +425,7 @@
     assert guard_op.liveboxes == [G.sum2, ConstInt(124)]
     vt = cpu.cast_adr_to_int(node_vtable_adr)
     assert guard_op.storage_info.allocations == [vt]
-    assert guard_op.storage_info.setfields == [(0, G.ofs_value, 1)]
+    assert guard_op.storage_info.setfields == [(0, G.ofs_value, -2)]
 
 # ____________________________________________________________
 

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py	Thu Feb 12 16:32:35 2009
@@ -14,16 +14,21 @@
 
 class ExplicitVirtualizableTests:
 
+    def _freeze_(self):
+        return True
+
+    @staticmethod
+    def setup():
+        xy = lltype.malloc(XY)
+        xy.vable_rti = lltype.nullptr(VABLERTIPTR.TO)
+        xy.parent.typeptr = xy_vtable
+        return xy
+
     def test_preexisting_access(self):
         myjitdriver = JitDriver(greens = [], reds = ['n', 'xy'],
                                 virtualizables = ['xy'])
-        def setup():
-            xy = lltype.malloc(XY)
-            xy.vable_rti = lltype.nullptr(VABLERTIPTR.TO)
-            xy.parent.typeptr = xy_vtable
-            return xy
         def f(n):
-            xy = setup()
+            xy = self.setup()
             xy.x = 10
             while n > 0:
                 myjitdriver.can_enter_jit(xy=xy, n=n)
@@ -32,26 +37,28 @@
                 x = xy.x
                 xy.x = x + 1
                 n -= 1
-        self.meta_interp(f, [5])
+            return xy.x
+        res = self.meta_interp(f, [20])
+        assert res == 30
         self.check_loops(getfield_gc=0, setfield_gc=0)
 
     def test_preexisting_access_2(self):
-        def setup():
-            xy = lltype.malloc(XY)
-            xy.vable_rti = lltype.nullptr(VABLERTIPTR.TO)
-            return xy
+        myjitdriver = JitDriver(greens = [], reds = ['n', 'xy'],
+                                virtualizables = ['xy'])
         def f(n):
-            xy = setup()
+            xy = self.setup()
             xy.x = 100
-            while n > 0:
-                promote_virtualizable(lltype.Void, xy, 'x')
-                x = xy.x
-                xy.x = x + 1
-                n -= 1
             while n > -8:
-                promote_virtualizable(lltype.Void, xy, 'x')
-                x = xy.x
-                xy.x = x + 10
+                myjitdriver.can_enter_jit(xy=xy, n=n)
+                myjitdriver.jit_merge_point(xy=xy, n=n)
+                if n > 0:
+                    promote_virtualizable(lltype.Void, xy, 'x')
+                    x = xy.x
+                    xy.x = x + 1
+                else:
+                    promote_virtualizable(lltype.Void, xy, 'x')
+                    x = xy.x
+                    xy.x = x + 10
                 n -= 1
             return xy.x
         res = self.meta_interp(f, [5])



More information about the Pypy-commit mailing list