Author: Alex Gaynor <alex.gay...@gmail.com> Branch: on-abort-resops Changeset: r64401:fc25a3ecd9a4 Date: 2013-05-21 13:25 -0700 http://bitbucket.org/pypy/pypy/changeset/fc25a3ecd9a4/
Log: When calling the abort handler, include the list of operations thus diff --git a/pypy/module/pypyjit/interp_resop.py b/pypy/module/pypyjit/interp_resop.py --- a/pypy/module/pypyjit/interp_resop.py +++ b/pypy/module/pypyjit/interp_resop.py @@ -75,16 +75,19 @@ cache.w_optimize_hook = w_hook cache.in_recursion = NonConstant(False) + def set_abort_hook(space, w_hook): """ set_abort_hook(hook) Set a hook (callable) that will be called each time there is tracing aborted due to some reason. - The hook will be called as in: hook(jitdriver_name, greenkey, reason) + The hook will be called with the signature: + + hook(jitdriver_name, greenkey, reason, operations) Reason is a string, the meaning of other arguments is the same - as attributes on JitLoopInfo object + as attributes on JitLoopInfo object. """ cache = space.fromcache(Cache) cache.w_abort_hook = w_hook diff --git a/pypy/module/pypyjit/policy.py b/pypy/module/pypyjit/policy.py --- a/pypy/module/pypyjit/policy.py +++ b/pypy/module/pypyjit/policy.py @@ -4,25 +4,26 @@ from pypy.interpreter.error import OperationError from pypy.module.pypyjit.interp_resop import (Cache, wrap_greenkey, - WrappedOp, W_JitLoopInfo) + WrappedOp, W_JitLoopInfo, wrap_oplist) class PyPyJitIface(JitHookInterface): - def on_abort(self, reason, jitdriver, greenkey, greenkey_repr): + def on_abort(self, reason, jitdriver, greenkey, greenkey_repr, logops, operations): space = self.space cache = space.fromcache(Cache) if cache.in_recursion: return if space.is_true(cache.w_abort_hook): cache.in_recursion = True + oplist_w = wrap_oplist(space, logops, operations) try: try: space.call_function(cache.w_abort_hook, - space.wrap(jitdriver.name), - wrap_greenkey(space, jitdriver, - greenkey, greenkey_repr), - space.wrap( - Counters.counter_names[reason])) + space.wrap(jitdriver.name), + wrap_greenkey(space, jitdriver, greenkey, greenkey_repr), + space.wrap(Counters.counter_names[reason]), + space.newlist(oplist_w) + ) except OperationError, e: e.write_unraisable(space, "jit hook ", cache.w_abort_hook) finally: diff --git a/pypy/module/pypyjit/test/test_jit_hook.py b/pypy/module/pypyjit/test/test_jit_hook.py --- a/pypy/module/pypyjit/test/test_jit_hook.py +++ b/pypy/module/pypyjit/test/test_jit_hook.py @@ -16,6 +16,7 @@ from rpython.jit.metainterp.typesystem import llhelper from rpython.rlib.jit import JitDebugInfo, AsmInfo, Counters + class MockJitDriverSD(object): class warmstate(object): @staticmethod @@ -34,8 +35,10 @@ jitdrivers_sd = [MockJitDriverSD] + class AppTestJitHook(object): spaceconfig = dict(usemodules=('pypyjit',)) + def setup_class(cls): if cls.runappdirect: py.test.skip("Can't run this test with -A") @@ -86,7 +89,7 @@ def interp_on_abort(): pypy_hooks.on_abort(Counters.ABORT_TOO_LONG, pypyjitdriver, - greenkey, 'blah') + greenkey, 'blah', Logger(MockSD), []) space = cls.space cls.w_on_compile = space.wrap(interp2app(interp_on_compile)) @@ -189,12 +192,12 @@ import pypyjit l = [] - def hook(jitdriver_name, greenkey, reason): - l.append((jitdriver_name, reason)) + def hook(jitdriver_name, greenkey, reason, operations): + l.append((jitdriver_name, reason, operations)) pypyjit.set_abort_hook(hook) self.on_abort() - assert l == [('pypyjit', 'ABORT_TOO_LONG')] + assert l == [('pypyjit', 'ABORT_TOO_LONG', [])] def test_on_optimize(self): import pypyjit diff --git a/rpython/jit/metainterp/pyjitpl.py b/rpython/jit/metainterp/pyjitpl.py --- a/rpython/jit/metainterp/pyjitpl.py +++ b/rpython/jit/metainterp/pyjitpl.py @@ -1876,7 +1876,9 @@ self.staticdata.warmrunnerdesc.hooks.on_abort(reason, jd_sd.jitdriver, greenkey, - jd_sd.warmstate.get_location_str(greenkey)) + jd_sd.warmstate.get_location_str(greenkey), + self.staticdata.logger_ops, + self.history.operations) self.staticdata.stats.aborted() def blackhole_if_trace_too_long(self): diff --git a/rpython/jit/metainterp/test/test_jitiface.py b/rpython/jit/metainterp/test/test_jitiface.py --- a/rpython/jit/metainterp/test/test_jitiface.py +++ b/rpython/jit/metainterp/test/test_jitiface.py @@ -7,18 +7,20 @@ from rpython.rtyper.annlowlevel import hlstr from rpython.jit.metainterp.jitprof import Profiler + class JitHookInterfaceTests(object): # !!!note!!! - don't subclass this from the backend. Subclass the LL # class later instead def test_abort_quasi_immut(self): reasons = [] - + class MyJitIface(JitHookInterface): - def on_abort(self, reason, jitdriver, greenkey, greenkey_repr): + def on_abort(self, reason, jitdriver, greenkey, greenkey_repr, logops, operations): assert jitdriver is myjitdriver assert len(greenkey) == 1 reasons.append(reason) assert greenkey_repr == 'blah' + assert len(operations) > 1 iface = MyJitIface() @@ -27,8 +29,10 @@ class Foo: _immutable_fields_ = ['a?'] + def __init__(self, a): self.a = a + def f(a, x): foo = Foo(a) total = 0 @@ -47,7 +51,7 @@ def test_on_compile(self): called = [] - + class MyJitIface(JitHookInterface): def after_compile(self, di): called.append(("compile", di.greenkey[1].getint(), _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit