[pypy-commit] pypy improve-heap-caching-tracing: pass a slightly simpler version of this first test

cfbolz noreply at buildbot.pypy.org
Fri Sep 2 15:13:32 CEST 2011


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: improve-heap-caching-tracing
Changeset: r47021:1988d4a527b0
Date: 2011-09-02 11:59 +0200
http://bitbucket.org/pypy/pypy/changeset/1988d4a527b0/

Log:	pass a slightly simpler version of this first test

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
@@ -11,7 +11,7 @@
         # contains frame boxes that are not virtualizables
         self.nonstandard_virtualizables = {}
         # heap cache
-        # maps descrs to (from_box, to_box) tuples
+        # maps descrs to {from_box, to_box} dicts
         self.heap_cache = {}
         # heap array cache
         # maps descrs to {index: (from_box, to_box)} dicts
@@ -48,13 +48,18 @@
 
 
     def getfield(self, box, descr):
-        frombox, tobox = self.heap_cache.get(descr, (None, None))
-        if box is frombox:
-            return tobox
+        d = self.heap_cache.get(descr, None)
+        if d:
+            tobox = d.get(box, None)
+            if tobox:
+                return tobox
         return None
 
+    def getfield_now_known(self, box, descr, fieldbox):
+        self.heap_cache.setdefault(descr, {})[box] = fieldbox
+
     def setfield(self, box, descr, fieldbox):
-        self.heap_cache[descr] = (box, fieldbox)
+        self.heap_cache[descr] = {box: fieldbox}
 
     def getarrayitem(self, box, descr, indexbox):
         if not isinstance(indexbox, ConstInt):
@@ -77,14 +82,13 @@
         cache[index] = box, valuebox
 
     def replace_box(self, oldbox, newbox):
-        for descr, (frombox, tobox) in self.heap_cache.iteritems():
-            change = False
-            if frombox is oldbox:
-                change = True
-                frombox = newbox
-            if tobox is oldbox:
-                change = True
-                tobox = newbox
-            if change:
-                self.heap_cache[descr] = frombox, tobox
+        for descr, d in self.heap_cache.iteritems():
+            new_d = {}
+            for frombox, tobox in d.iteritems():
+                if frombox is oldbox:
+                    frombox = newbox
+                if tobox is oldbox:
+                    tobox = newbox
+                new_d[frombox] = tobox
+            self.heap_cache[descr] = new_d
         # XXX what about self.heap_array_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
@@ -81,6 +81,22 @@
         assert h.getfield(box1, descr2) is None
         assert h.getfield(box3, descr1) is None
 
+    def test_heapcache_fields_multiple(self):
+        h = HeapCache()
+        h.getfield_now_known(box1, descr1, box2)
+        h.getfield_now_known(box3, descr1, box4)
+        assert h.getfield(box1, descr1) is box2
+        assert h.getfield(box1, descr2) is None
+        assert h.getfield(box3, descr1) is box4
+        assert h.getfield(box3, descr2) is None
+
+        h.reset()
+        assert h.getfield(box1, descr1) is None
+        assert h.getfield(box1, descr2) is None
+        assert h.getfield(box3, descr1) is None
+        assert h.getfield(box3, descr2) is None
+
+
     def test_heapcache_arrays(self):
         h = HeapCache()
         assert h.getarrayitem(box1, descr1, index1) is None
@@ -166,3 +182,4 @@
         assert h.getfield(box1, descr2) is None
         assert h.getfield(box4, descr1) is box2
         assert h.getfield(box4, descr2) 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
@@ -416,15 +416,15 @@
         def fn(n):
             a1 = A()
             g.a = a1
-            a1.x = n - 2
+            a1.x = n
             a2 = A()
             g.a = a2
-            a2.x = n - 3
-            return a1.x + a2.x
+            a2.x = n - 1
+            return a1.x + a2.x + a1.x + a2.x
         res = self.interp_operations(fn, [7])
-        assert res == 2 * 7 - 5
-        self.check_operations_history(getfield_gc=0)
+        assert res == 2 * 7 + 2 * 6
+        self.check_operations_history(getfield_gc=2)
         res = self.interp_operations(fn, [-7])
-        assert res == 2 * -7 - 5
-        self.check_operations_history(getfield_gc=0)
+        assert res == 2 * -7 + 2 * -8
+        self.check_operations_history(getfield_gc=2)
 


More information about the pypy-commit mailing list