1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
from rpython.rlib import jit_hooks
from rpython.rlib.jit import JitHookInterface, Counters
from pypy.interpreter.error import OperationError
from pypy.module.pypyjit.interp_resop import (Cache, wrap_greenkey,
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 cache.w_abort_hook is not None:
cache.in_recursion = True
oplist_w = wrap_oplist(space, logops, operations)
try:
try:
space.call_function(cache.w_abort_hook,
space.newtext(jitdriver.name),
wrap_greenkey(space, jitdriver, greenkey, greenkey_repr),
space.newtext(Counters.counter_names[reason]),
space.newlist(oplist_w)
)
except OperationError as e:
e.write_unraisable(space, "jit hook ", cache.w_abort_hook)
finally:
cache.in_recursion = False
def on_trace_too_long(self, jitdriver, greenkey, greenkey_repr):
space = self.space
cache = space.fromcache(Cache)
if cache.in_recursion:
return
if cache.w_trace_too_long_hook is not None:
cache.in_recursion = True
try:
try:
space.call_function(cache.w_trace_too_long_hook,
space.newtext(jitdriver.name),
wrap_greenkey(space, jitdriver, greenkey, greenkey_repr))
except OperationError as e:
e.write_unraisable(space, "jit hook", cache.w_trace_too_long_hook)
finally:
cache.in_recursion = False
def after_compile(self, debug_info):
self._compile_hook(debug_info, is_bridge=False)
def after_compile_bridge(self, debug_info):
self._compile_hook(debug_info, is_bridge=True)
def before_compile(self, debug_info):
pass
def before_compile_bridge(self, debug_info):
pass
def _compile_hook(self, debug_info, is_bridge):
space = self.space
cache = space.fromcache(Cache)
if cache.in_recursion:
return
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
try:
try:
space.call_function(cache.w_compile_hook,
w_debug_info)
except OperationError as e:
e.write_unraisable(space, "jit hook ", cache.w_compile_hook)
finally:
cache.in_recursion = False
pypy_hooks = PyPyJitIface()
|