Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: jit-hooks-can-be-disabled
Changeset: r94162:d27c76b67b51
Date: 2018-03-28 14:03 +0200
http://bitbucket.org/pypy/pypy/changeset/d27c76b67b51/
Log: use new hook to check whether any hooks are set at all
diff --git a/pypy/module/pypyjit/hooks.py b/pypy/module/pypyjit/hooks.py
--- a/pypy/module/pypyjit/hooks.py
+++ b/pypy/module/pypyjit/hooks.py
@@ -7,12 +7,20 @@
WrappedOp, W_JitLoopInfo, wrap_oplist)
class PyPyJitIface(JitHookInterface):
+ def are_hooks_enabled(self):
+ space = self.space
+ cache = space.fromcache(Cache)
+ return (cache.w_compile_hook is not None or
+ cache.w_abort_hook is not None or
+ cache.w_trace_too_long_hook is not None)
+
+
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):
+ if cache.w_abort_hook is not None:
cache.in_recursion = True
oplist_w = wrap_oplist(space, logops, operations)
try:
@@ -33,7 +41,7 @@
cache = space.fromcache(Cache)
if cache.in_recursion:
return
- if space.is_true(cache.w_trace_too_long_hook):
+ if cache.w_trace_too_long_hook is not None:
cache.in_recursion = True
try:
try:
@@ -62,7 +70,7 @@
cache = space.fromcache(Cache)
if cache.in_recursion:
return
- if space.is_true(cache.w_compile_hook):
+ if cache.w_compile_hook is not None:
w_debug_info = W_JitLoopInfo(space, debug_info, is_bridge,
cache.compile_hook_with_ops)
cache.in_recursion = True
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
@@ -21,9 +21,10 @@
no = 0
def __init__(self, space):
- self.w_compile_hook = space.w_None
- self.w_abort_hook = space.w_None
- self.w_trace_too_long_hook = space.w_None
+ self.w_compile_hook = None
+ self.w_abort_hook = None
+ self.w_trace_too_long_hook = None
+ self.compile_hook_with_ops = False
def getno(self):
self.no += 1
@@ -58,7 +59,8 @@
jit hook won't be called for that.
"""
cache = space.fromcache(Cache)
- assert w_hook is not None
+ if space.is_w(w_hook, space.w_None):
+ w_hook = None
cache.w_compile_hook = w_hook
cache.compile_hook_with_ops = operations
cache.in_recursion = NonConstant(False)
@@ -77,7 +79,8 @@
as attributes on JitLoopInfo object.
"""
cache = space.fromcache(Cache)
- assert w_hook is not None
+ if space.is_w(w_hook, space.w_None):
+ w_hook = None
cache.w_abort_hook = w_hook
cache.in_recursion = NonConstant(False)
@@ -92,14 +95,15 @@
hook(jitdriver_name, greenkey)
"""
cache = space.fromcache(Cache)
- assert w_hook is not None
+ if space.is_w(w_hook, space.w_None):
+ w_hook = None
cache.w_trace_too_long_hook = w_hook
cache.in_recursion = NonConstant(False)
def wrap_oplist(space, logops, operations, ops_offset=None):
# this function is called from the JIT
from rpython.jit.metainterp.resoperation import rop
-
+
l_w = []
jitdrivers_sd = logops.metainterp_sd.jitdrivers_sd
for op in operations:
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
@@ -86,18 +86,22 @@
def interp_on_compile():
di_loop.oplist = cls.oplist
- pypy_hooks.after_compile(di_loop)
+ if pypy_hooks.are_hooks_enabled():
+ pypy_hooks.after_compile(di_loop)
def interp_on_compile_bridge():
- pypy_hooks.after_compile_bridge(di_bridge)
+ if pypy_hooks.are_hooks_enabled():
+ pypy_hooks.after_compile_bridge(di_bridge)
def interp_on_optimize():
- di_loop_optimize.oplist = cls.oplist
- pypy_hooks.before_compile(di_loop_optimize)
+ if pypy_hooks.are_hooks_enabled():
+ di_loop_optimize.oplist = cls.oplist
+ pypy_hooks.before_compile(di_loop_optimize)
def interp_on_abort():
- pypy_hooks.on_abort(Counters.ABORT_TOO_LONG, pypyjitdriver,
- greenkey, 'blah', Logger(MockSD), [])
+ if pypy_hooks.are_hooks_enabled():
+ pypy_hooks.on_abort(Counters.ABORT_TOO_LONG, pypyjitdriver,
+ greenkey, 'blah', Logger(MockSD), [])
space = cls.space
cls.w_on_compile = space.wrap(interp2app(interp_on_compile))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit