Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: improve-heap-caching-tracing Changeset: r47125:77217d39842f Date: 2011-09-07 11:01 +0200 http://bitbucket.org/pypy/pypy/changeset/77217d39842f/
Log: be more precise about getarrayitem 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 @@ -107,6 +107,17 @@ if indexcache is not None: return indexcache.get(box, None) + def getarrayitem_now_known(self, box, descr, indexbox, valuebox): + if not isinstance(indexbox, ConstInt): + return + index = indexbox.getint() + cache = self.heap_array_cache.setdefault(descr, {}) + indexcache = cache.get(index, None) + if indexcache is not None: + indexcache[box] = valuebox + else: + cache[index] = {box: valuebox} + def setarrayitem(self, box, descr, indexbox, valuebox): if not isinstance(indexbox, ConstInt): cache = self.heap_array_cache.get(descr, None) @@ -118,6 +129,7 @@ indexcache = cache.get(index, None) cache[index] = self._do_write_with_aliasing(indexcache, box, valuebox) + def arraylen(self, box): return self.length_cache.get(box, None) 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 @@ -408,7 +408,7 @@ return tobox resbox = self.execute_with_descr(rop.GETARRAYITEM_GC, arraydescr, arraybox, indexbox) - self.metainterp.heapcache.setarrayitem( + self.metainterp.heapcache.getarrayitem_now_known( arraybox, arraydescr, indexbox, resbox) return resbox 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 @@ -179,6 +179,20 @@ assert h.getarrayitem(box1, descr1, index1) is None assert h.getarrayitem(box1, descr1, index2) is None + def test_heapcache_read_fields_multiple_array(self): + h = HeapCache() + h.getarrayitem_now_known(box1, descr1, index1, box2) + h.getarrayitem_now_known(box3, descr1, index1, box4) + assert h.getarrayitem(box1, descr1, index1) is box2 + assert h.getarrayitem(box1, descr2, index1) is None + assert h.getarrayitem(box3, descr1, index1) is box4 + assert h.getarrayitem(box3, descr2, index1) is None + + h.reset() + assert h.getarrayitem(box1, descr1, index1) is None + assert h.getarrayitem(box1, descr2, index1) is None + assert h.getarrayitem(box3, descr1, index1) is None + assert h.getarrayitem(box3, descr2, index1) is None def test_heapcache_write_fields_multiple_array(self): h = HeapCache() 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 @@ -469,6 +469,27 @@ assert res == 2 * -7 + 2 * -8 self.check_operations_history(getarrayitem_gc=0) + def test_heap_caching_multiple_arrays_getarrayitem(self): + class Gbl(object): + pass + g = Gbl() + g.a1 = [7, 8, 9] + g.a2 = [8, 9, 10, 11] + + def fn(i): + if i < 0: + g.a1 = [7, 8, 9] + g.a2 = [7, 8, 9, 10] + jit.promote(i) + a1 = g.a1 + a1[i + 1] = 15 # make lists mutable + a2 = g.a2 + a2[i + 1] = 19 + return a1[i] + a2[i] + a1[i] + a2[i] + res = self.interp_operations(fn, [0]) + assert res == 2 * 7 + 2 * 8 + self.check_operations_history(getarrayitem_gc=2) + def test_length_caching(self): class Gbl(object): pass _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit