Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r68599:2f0d7dced731
Date: 2014-01-11 14:23 -0800
http://bitbucket.org/pypy/pypy/changeset/2f0d7dced731/
Log: Look a little bit more into weakref -- now a mapdict lookup is seen
by the JIT
diff --git a/pypy/module/_weakref/interp__weakref.py
b/pypy/module/_weakref/interp__weakref.py
--- a/pypy/module/_weakref/interp__weakref.py
+++ b/pypy/module/_weakref/interp__weakref.py
@@ -122,6 +122,7 @@
W_WeakrefBase.activate_callback,
'weakref callback of ')
+ @jit.dont_look_inside
def make_weakref_with_callback(self, w_subtype, w_obj, w_callable):
space = self.space
w_ref = space.allocate_instance(W_Weakref, w_subtype)
@@ -243,11 +244,12 @@
def get_or_make_weakref(space, w_subtype, w_obj):
return getlifeline(space, w_obj).get_or_make_weakref(w_subtype, w_obj)
[email protected]_look_inside
+
def make_weakref_with_callback(space, w_subtype, w_obj, w_callable):
lifeline = getlifelinewithcallbacks(space, w_obj)
return lifeline.make_weakref_with_callback(w_subtype, w_obj, w_callable)
+
def descr__new__weakref(space, w_subtype, w_obj, w_callable=None,
__args__=None):
if __args__.arguments_w:
diff --git a/pypy/module/pypyjit/test_pypy_c/test_weakref.py
b/pypy/module/pypyjit/test_pypy_c/test_weakref.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/pypyjit/test_pypy_c/test_weakref.py
@@ -0,0 +1,46 @@
+from pypy.module.pypyjit.test_pypy_c.test_00_model import BaseTestPyPyC
+
+
+class TestThread(BaseTestPyPyC):
+ def test_make_ref_with_callback(self):
+ log = self.run("""
+ import weakref
+
+ class Dummy(object):
+ pass
+
+ def noop(obj):
+ pass
+
+ def main(n):
+ obj = Dummy()
+ for i in xrange(n):
+ weakref.ref(obj, noop)
+ """, [500])
+ loop, = log.loops_by_filename(self.filepath)
+ assert loop.match("""
+ i58 = getfield_gc(p18, descr=<FieldS
pypy.module.__builtin__.functional.W_XRangeIterator.inst_current .>)
+ i59 = getfield_gc(p18, descr=<FieldS
pypy.module.__builtin__.functional.W_XRangeStepOneIterator.inst_stop \d+>)
+ i60 = int_lt(i58, i59)
+ guard_true(i60, descr=...)
+ i61 = int_add(i58, 1)
+ p62 = getfield_gc(ConstPtr(ptr37), descr=<FieldP
pypy.objspace.std.dictmultiobject.W_DictMultiObject.inst_strategy \d+>)
+ setfield_gc(p18, i61, descr=<FieldS
pypy.module.__builtin__.functional.W_XRangeIterator.inst_current 8>)
+ guard_value(p62, ConstPtr(ptr39), descr=...)
+ guard_not_invalidated(descr=...)
+ p64 = getfield_gc(ConstPtr(ptr40), descr=<FieldP
pypy.objspace.std.dictmultiobject.W_DictMultiObject.inst_strategy \d+>)
+ guard_value(p64, ConstPtr(ptr42), descr=...)
+ p65 = getfield_gc(p14, descr=<FieldP
pypy.objspace.std.mapdict.W_ObjectObjectSize5.inst_map 48>)
+ guard_value(p65, ConstPtr(ptr45), descr=...)
+ p66 = getfield_gc(p14, descr=<FieldP
pypy.objspace.std.mapdict.W_ObjectObjectSize5.inst__value0 \d+>)
+ guard_nonnull_class(p66, 4315455232, descr=...)
+ p67 = force_token()
+ setfield_gc(p0, p67, descr=<FieldP
pypy.interpreter.pyframe.PyFrame.vable_token \d+>)
+ p68 =
call_may_force(ConstClass(WeakrefLifelineWithCallbacks.make_weakref_with_callback),
p66, ConstPtr(ptr50), p14, ConstPtr(ptr51), descr=<Callr 8 rrrr EF=6>)
+ guard_not_forced(descr=...)
+ guard_no_exception(descr=...)
+ guard_nonnull_class(p68, 4315527384, descr=...)
+ guard_not_invalidated(descr=...)
+ --TICK--
+ jump(..., descr=...)
+ """)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit