[pypy-commit] pypy improve-heap-caching-tracing: fix XXX in replace_box

cfbolz noreply at buildbot.pypy.org
Sun Sep 4 11:30:29 CEST 2011


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: improve-heap-caching-tracing
Changeset: r47060:feecefe7686f
Date: 2011-09-04 11:30 +0200
http://bitbucket.org/pypy/pypy/changeset/feecefe7686f/

Log:	fix XXX in replace_box

diff --git a/pypy/jit/metainterp/heapcache.py b/pypy/jit/metainterp/heapcache.py
--- a/pypy/jit/metainterp/heapcache.py
+++ b/pypy/jit/metainterp/heapcache.py
@@ -111,4 +111,13 @@
                     tobox = newbox
                 new_d[frombox] = tobox
             self.heap_cache[descr] = new_d
-        # XXX what about self.heap_array_cache?
+        for descr, d in self.heap_array_cache.iteritems():
+            for index, cache in d.iteritems():
+                new_cache = {}
+                for frombox, tobox in cache.iteritems():
+                    if frombox is oldbox:
+                        frombox = newbox
+                    if tobox is oldbox:
+                        tobox = newbox
+                    new_cache[frombox] = tobox
+                d[index] = new_cache
diff --git a/pypy/jit/metainterp/test/test_heapcache.py b/pypy/jit/metainterp/test/test_heapcache.py
--- a/pypy/jit/metainterp/test/test_heapcache.py
+++ b/pypy/jit/metainterp/test/test_heapcache.py
@@ -8,6 +8,7 @@
 box4 = object()
 descr1 = object()
 descr2 = object()
+descr3 = object()
 
 index1 = ConstInt(0)
 index2 = ConstInt(1)
@@ -202,17 +203,26 @@
         h = HeapCache()
         h.setfield(box1, descr1, box2)
         h.setfield(box1, descr2, box3)
+        h.setfield(box2, descr3, box3)
         h.replace_box(box1, box4)
         assert h.getfield(box1, descr1) is None
         assert h.getfield(box1, descr2) is None
         assert h.getfield(box4, descr1) is box2
         assert h.getfield(box4, descr2) is box3
+        assert h.getfield(box2, descr3) is box3
 
+    def test_replace_box_array(self):
         h = HeapCache()
-        h.setfield(box1, descr1, box2)
-        h.setfield(box1, descr2, box3)
+        h.setarrayitem(box1, descr1, index1, box2)
+        h.setarrayitem(box1, descr2, index1, box3)
+        h.setarrayitem(box2, descr1, index2, box1)
+        h.setarrayitem(box3, descr2, index2, box1)
+        h.setarrayitem(box2, descr3, index2, box3)
         h.replace_box(box1, box4)
-        assert h.getfield(box1, descr1) is None
-        assert h.getfield(box1, descr2) is None
-        assert h.getfield(box4, descr1) is box2
-        assert h.getfield(box4, descr2) is box3
+        assert h.getarrayitem(box1, descr1, index1) is None
+        assert h.getarrayitem(box1, descr2, index1) is None
+        assert h.getarrayitem(box4, descr1, index1) is box2
+        assert h.getarrayitem(box4, descr2, index1) is box3
+        assert h.getarrayitem(box2, descr1, index2) is box4
+        assert h.getarrayitem(box3, descr2, index2) is box4
+        assert h.getarrayitem(box2, descr3, index2) is box3
diff --git a/pypy/jit/metainterp/test/test_tracingopts.py b/pypy/jit/metainterp/test/test_tracingopts.py
--- a/pypy/jit/metainterp/test/test_tracingopts.py
+++ b/pypy/jit/metainterp/test/test_tracingopts.py
@@ -257,6 +257,28 @@
         self.check_operations_history(setarrayitem_gc=2, setfield_gc=2,
                                       getarrayitem_gc=0, getfield_gc=2)
 
+    def test_promote_changes_array_cache(self):
+        a1 = [0, 0]
+        a2 = [0, 0]
+        def fn(n):
+            if n > 0:
+                a = a1
+            else:
+                a = a2
+            a[0] = n
+            jit.hint(n, promote=True)
+            x1 = a[0]
+            jit.hint(x1, promote=True)
+            a[n - n] = n + 1
+            return a[0] + x1
+        res = self.interp_operations(fn, [7])
+        assert res == 7 + 7 + 1
+        self.check_operations_history(getarrayitem_gc=0, guard_value=1)
+        res = self.interp_operations(fn, [-7])
+        assert res == -7 - 7 + 1
+        self.check_operations_history(getarrayitem_gc=0, guard_value=1)
+
+
     def test_list_caching(self):
         a1 = [0, 0]
         a2 = [0, 0]


More information about the pypy-commit mailing list