[pypy-commit] pypy heap-caching-during-tracing: proper invalidation for the array cache

cfbolz noreply at buildbot.pypy.org
Sat Jul 16 22:00:04 CEST 2011


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: heap-caching-during-tracing
Changeset: r45686:420fc8c6b8cd
Date: 2011-07-16 21:27 +0200
http://bitbucket.org/pypy/pypy/changeset/420fc8c6b8cd/

Log:	proper invalidation for the array cache

diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py
--- a/pypy/jit/metainterp/pyjitpl.py
+++ b/pypy/jit/metainterp/pyjitpl.py
@@ -391,7 +391,6 @@
     @arguments("box", "descr", "box")
     def _opimpl_getarrayitem_gc_any(self, arraybox, arraydescr, indexbox):
         cache = self.metainterp.heap_array_cache.get(arraydescr, None)
-        index = -1
         if cache and isinstance(indexbox, ConstInt):
             index = indexbox.getint()
             frombox, tobox = cache.get(index, (None, None))
@@ -399,9 +398,10 @@
                 return tobox
         resbox = self.execute_with_descr(rop.GETARRAYITEM_GC,
                                          arraydescr, arraybox, indexbox)
-        if index >= 0:
+        if isinstance(indexbox, ConstInt):
             if not cache:
                 cache = self.metainterp.heap_array_cache[arraydescr] = {}
+            index = indexbox.getint()
             cache[index] = arraybox, resbox
         return resbox
 
@@ -1671,10 +1671,13 @@
         # record the operation
         profiler = self.staticdata.profiler
         profiler.count_ops(opnum, RECORDED_OPS)
-        if (self.heap_cache and opnum != rop.SETFIELD_GC and
+        if (opnum != rop.SETFIELD_GC and
                 opnum != rop.SETARRAYITEM_GC):
             if not (rop._NOSIDEEFFECT_FIRST <= opnum <= rop._NOSIDEEFFECT_LAST):
-                self.heap_cache = {}
+                if self.heap_cache:
+                    self.heap_cache.clear()
+                if self.heap_array_cache:
+                    self.heap_array_cache.clear()
         op = self.history.record(opnum, argboxes, resbox, descr)
         self.attach_debug_info(op)
         return resbox
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
@@ -184,3 +184,27 @@
         res = self.interp_operations(fn, [-7, 1, 1])
         assert res == -7 * 2
         self.check_operations_history(getarrayitem_gc=1)
+
+    def test_array_caching_while_tracing_invalidation(self):
+        a1 = [0, 0]
+        a2 = [0, 0]
+        @jit.dont_look_inside
+        def f(a):
+            a[0] = 5
+        class A: pass
+        l = A()
+        def fn(n):
+            if n > 0:
+                a = a1
+            else:
+                a = a2
+            a[0] = n
+            x1 = a[0]
+            f(a)
+            x2 = a[0]
+            l.x = x2
+            return a[0] + x1 + x2
+        res = self.interp_operations(fn, [7])
+        assert res == 5 * 2 + 7
+        self.check_operations_history(getarrayitem_gc=1)
+


More information about the pypy-commit mailing list