Author: Carl Friedrich Bolz <[email protected]>
Branch: heap-caching-during-tracing
Changeset: r45689:160b69e37ce6
Date: 2011-07-16 23:04 +0200
http://bitbucket.org/pypy/pypy/changeset/160b69e37ce6/
Log: make sure the stuff works with resizable lists too
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
@@ -485,10 +485,8 @@
@arguments("box", "descr", "descr", "box")
def _opimpl_getlistitem_gc_any(self, listbox, itemsdescr, arraydescr,
indexbox):
- arraybox = self.metainterp.execute_and_record(rop.GETFIELD_GC,
- itemsdescr, listbox)
- return self.execute_with_descr(rop.GETARRAYITEM_GC,
- arraydescr, arraybox, indexbox)
+ arraybox = self._opimpl_getfield_gc_any(listbox, itemsdescr)
+ return self._opimpl_getarrayitem_gc_any(arraybox, arraydescr, indexbox)
opimpl_getlistitem_gc_i = _opimpl_getlistitem_gc_any
opimpl_getlistitem_gc_r = _opimpl_getlistitem_gc_any
@@ -497,10 +495,9 @@
@arguments("box", "descr", "descr", "box", "box")
def _opimpl_setlistitem_gc_any(self, listbox, itemsdescr, arraydescr,
indexbox, valuebox):
- arraybox = self.metainterp.execute_and_record(rop.GETFIELD_GC,
- itemsdescr, listbox)
- self.execute_with_descr(rop.SETARRAYITEM_GC, arraydescr, arraybox,
- indexbox, valuebox)
+ arraybox = self._opimpl_getfield_gc_any(listbox, itemsdescr)
+ self._opimpl_setarrayitem_gc_any(arraybox, arraydescr, indexbox,
+ valuebox)
opimpl_setlistitem_gc_i = _opimpl_setlistitem_gc_any
opimpl_setlistitem_gc_r = _opimpl_setlistitem_gc_any
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
@@ -256,3 +256,47 @@
assert res == 7 * 2 + 1
self.check_operations_history(setarrayitem_gc=2, setfield_gc=2,
getarrayitem_gc=0, getfield_gc=2)
+
+ def test_list_caching(self):
+ a1 = [0, 0]
+ a2 = [0, 0]
+ def fn(n):
+ if n > 0:
+ a = a1
+ else:
+ a = a2
+ if n < -1000:
+ a.append(5)
+ a[0] = n
+ x1 = a[0]
+ 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=1,
+ getfield_gc=1)
+ res = self.interp_operations(fn, [-7])
+ assert res == -7 - 7 + 1
+ self.check_operations_history(getarrayitem_gc=1,
+ getfield_gc=1)
+
+ def fn(n, ca, cb):
+ a1[0] = n
+ a2[0] = n
+ a = a1
+ if ca:
+ a = a2
+ if n < -100:
+ a.append(5)
+ b = a1
+ if cb:
+ b = a
+ return a[0] + b[0]
+ res = self.interp_operations(fn, [7, 0, 1])
+ assert res == 7 * 2
+ self.check_operations_history(getarrayitem_gc=1,
+ getfield_gc=3)
+ res = self.interp_operations(fn, [-7, 1, 1])
+ assert res == -7 * 2
+ self.check_operations_history(getarrayitem_gc=1,
+ getfield_gc=3)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit