Author: Maciej Fijalkowski <[email protected]>
Branch: remember-tracing-counts
Changeset: r79709:41627817b1f7
Date: 2015-09-20 08:54 +0200
http://bitbucket.org/pypy/pypy/changeset/41627817b1f7/
Log: reenable jit hooks and pass all the untranslated tests
diff --git a/pypy/goal/targetpypystandalone.py
b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -341,8 +341,7 @@
def jitpolicy(self, driver):
from pypy.module.pypyjit.policy import PyPyJitPolicy
- from pypy.module.pypyjit.interp_jit import pypy_hooks
- #from pypy.module.pypyjit.hooks import pypy_hooks
+ from pypy.module.pypyjit.hooks import pypy_hooks
return PyPyJitPolicy(pypy_hooks)
def get_entry_point(self, config):
diff --git a/pypy/module/pypyjit/__init__.py b/pypy/module/pypyjit/__init__.py
--- a/pypy/module/pypyjit/__init__.py
+++ b/pypy/module/pypyjit/__init__.py
@@ -12,25 +12,22 @@
'dont_trace_here': 'interp_jit.dont_trace_here',
'trace_next_iteration': 'interp_jit.trace_next_iteration',
'trace_next_iteration_hash': 'interp_jit.trace_next_iteration_hash',
- 'set_compile_bridge': 'interp_jit.set_compile_bridge',
- 'set_compile_loop': 'interp_jit.set_compile_loop',
- #'set_compile_hook': 'interp_resop.set_compile_hook',
- #'set_optimize_hook': 'interp_resop.set_optimize_hook',
- #'set_abort_hook': 'interp_resop.set_abort_hook',
- #'get_stats_snapshot': 'interp_resop.get_stats_snapshot',
- #'enable_debug': 'interp_resop.enable_debug',
- #'disable_debug': 'interp_resop.disable_debug',
- #'ResOperation': 'interp_resop.WrappedOp',
- #'DebugMergePoint': 'interp_resop.DebugMergePoint',
- #'JitLoopInfo': 'interp_resop.W_JitLoopInfo',
- #'Box': 'interp_resop.WrappedBox',
+ 'set_compile_hook': 'interp_resop.set_compile_hook',
+ 'set_optimize_hook': 'interp_resop.set_optimize_hook',
+ 'set_abort_hook': 'interp_resop.set_abort_hook',
+ 'get_stats_snapshot': 'interp_resop.get_stats_snapshot',
+ 'enable_debug': 'interp_resop.enable_debug',
+ 'disable_debug': 'interp_resop.disable_debug',
+ 'ResOperation': 'interp_resop.WrappedOp',
+ 'DebugMergePoint': 'interp_resop.DebugMergePoint',
+ 'JitLoopInfo': 'interp_resop.W_JitLoopInfo',
'PARAMETER_DOCS': 'space.wrap(rpython.rlib.jit.PARAMETER_DOCS)',
}
def setup_after_space_initialization(self):
# force the __extend__ hacks to occur early
from pypy.module.pypyjit.interp_jit import pypyjitdriver
- from pypy.module.pypyjit.interp_jit import pypy_hooks
+ from pypy.module.pypyjit.hooks import pypy_hooks
# add the 'defaults' attribute
from rpython.rlib.jit import PARAMETERS
space = self.space
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
@@ -46,7 +46,8 @@
if cache.in_recursion:
return
if space.is_true(cache.w_compile_hook):
- w_debug_info = W_JitLoopInfo(space, debug_info, is_bridge)
+ w_debug_info = W_JitLoopInfo(space, debug_info, is_bridge,
+ cache.compile_hook_with_ops)
cache.in_recursion = True
try:
try:
@@ -63,7 +64,8 @@
if cache.in_recursion:
return
if space.is_true(cache.w_optimize_hook):
- w_debug_info = W_JitLoopInfo(space, debug_info, is_bridge)
+ w_debug_info = W_JitLoopInfo(space, debug_info, is_bridge,
+ cache.optimize_hook_with_ops)
cache.in_recursion = True
try:
try:
diff --git a/pypy/module/pypyjit/interp_jit.py
b/pypy/module/pypyjit/interp_jit.py
--- a/pypy/module/pypyjit/interp_jit.py
+++ b/pypy/module/pypyjit/interp_jit.py
@@ -221,70 +221,70 @@
jit_hooks.trace_next_iteration_hash('pypyjit', hash)
return space.w_None
-class Cache(object):
- in_recursion = False
+# class Cache(object):
+# in_recursion = False
- def __init__(self, space):
- self.w_compile_bridge = space.w_None
- self.w_compile_loop = space.w_None
+# def __init__(self, space):
+# self.w_compile_bridge = space.w_None
+# self.w_compile_loop = space.w_None
-def set_compile_bridge(space, w_hook):
- cache = space.fromcache(Cache)
- assert w_hook is not None
- cache.w_compile_bridge = w_hook
+# def set_compile_bridge(space, w_hook):
+# cache = space.fromcache(Cache)
+# assert w_hook is not None
+# cache.w_compile_bridge = w_hook
-def set_compile_loop(space, w_hook):
- from rpython.rlib.nonconst import NonConstant
+# def set_compile_loop(space, w_hook):
+# from rpython.rlib.nonconst import NonConstant
- cache = space.fromcache(Cache)
- assert w_hook is not None
- cache.w_compile_loop = w_hook
- cache.in_recursion = NonConstant(False)
+# cache = space.fromcache(Cache)
+# assert w_hook is not None
+# cache.w_compile_loop = w_hook
+# cache.in_recursion = NonConstant(False)
-class PyPyJitHookInterface(JitHookInterface):
- def after_compile(self, debug_info):
- space = self.space
- cache = space.fromcache(Cache)
- if cache.in_recursion:
- return
- l_w = []
- if not space.is_true(cache.w_compile_loop):
- return
- for i, op in enumerate(debug_info.operations):
- if op.is_guard():
- w_t = space.newtuple([space.wrap(i),
space.wrap(op.getopnum()), space.wrap(op.getdescr().get_jitcounter_hash())])
- l_w.append(w_t)
- try:
- cache.in_recursion = True
- try:
- space.call_function(cache.w_compile_loop, space.newlist(l_w))
- except OperationError, e:
- e.write_unraisable(space, "jit hook ", cache.w_compile_bridge)
- finally:
- cache.in_recursion = False
+# class PyPyJitHookInterface(JitHookInterface):
+# def after_compile(self, debug_info):
+# space = self.space
+# cache = space.fromcache(Cache)
+# if cache.in_recursion:
+# return
+# l_w = []
+# if not space.is_true(cache.w_compile_loop):
+# return
+# for i, op in enumerate(debug_info.operations):
+# if op.is_guard():
+# w_t = space.newtuple([space.wrap(i),
space.wrap(op.getopnum()), space.wrap(op.getdescr().get_jitcounter_hash())])
+# l_w.append(w_t)
+# try:
+# cache.in_recursion = True
+# try:
+# space.call_function(cache.w_compile_loop, space.newlist(l_w))
+# except OperationError, e:
+# e.write_unraisable(space, "jit hook ",
cache.w_compile_bridge)
+# finally:
+# cache.in_recursion = False
- def after_compile_bridge(self, debug_info):
- space = self.space
- cache = space.fromcache(Cache)
- if cache.in_recursion:
- return
- if not space.is_true(cache.w_compile_bridge):
- return
- w_hash = space.wrap(debug_info.fail_descr.get_jitcounter_hash())
- try:
- cache.in_recursion = True
- try:
- space.call_function(cache.w_compile_bridge, w_hash)
- except OperationError, e:
- e.write_unraisable(space, "jit hook ", cache.w_compile_bridge)
- finally:
- cache.in_recursion = False
+# def after_compile_bridge(self, debug_info):
+# space = self.space
+# cache = space.fromcache(Cache)
+# if cache.in_recursion:
+# return
+# if not space.is_true(cache.w_compile_bridge):
+# return
+# w_hash = space.wrap(debug_info.fail_descr.get_jitcounter_hash())
+# try:
+# cache.in_recursion = True
+# try:
+# space.call_function(cache.w_compile_bridge, w_hash)
+# except OperationError, e:
+# e.write_unraisable(space, "jit hook ",
cache.w_compile_bridge)
+# finally:
+# cache.in_recursion = False
- def before_compile(self, debug_info):
- pass
+# def before_compile(self, debug_info):
+# pass
- def before_compile_bridge(self, debug_info):
- pass
+# def before_compile_bridge(self, debug_info):
+# pass
-pypy_hooks = PyPyJitHookInterface()
+# pypy_hooks = PyPyJitHookInterface()
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
@@ -43,8 +43,9 @@
else:
return space.wrap(greenkey_repr)
-def set_compile_hook(space, w_hook):
- """ set_compile_hook(hook)
+@unwrap_spec(operations=bool)
+def set_compile_hook(space, w_hook, operations=True):
+ """ set_compile_hook(hook, operations=True)
Set a compiling hook that will be called each time a loop is compiled.
@@ -58,10 +59,12 @@
cache = space.fromcache(Cache)
assert w_hook is not None
cache.w_compile_hook = w_hook
+ cache.compile_hook_with_ops = operations
cache.in_recursion = NonConstant(False)
-def set_optimize_hook(space, w_hook):
- """ set_optimize_hook(hook)
+@unwrap_spec(operations=bool)
+def set_optimize_hook(space, w_hook, operations=True):
+ """ set_optimize_hook(hook, operations=True)
Set a compiling hook that will be called each time a loop is optimized,
but before assembler compilation. This allows adding additional
@@ -74,6 +77,7 @@
"""
cache = space.fromcache(Cache)
cache.w_optimize_hook = w_hook
+ cache.optimize_hook_with_ops = operations
cache.in_recursion = NonConstant(False)
@@ -96,6 +100,9 @@
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:
@@ -103,117 +110,58 @@
ofs = -1
else:
ofs = ops_offset.get(op, 0)
- if op.opnum == rop.DEBUG_MERGE_POINT:
+ num = op.getopnum()
+ name = op.getopname()
+ if num == rop.DEBUG_MERGE_POINT:
jd_sd = jitdrivers_sd[op.getarg(0).getint()]
greenkey = op.getarglist()[3:]
repr = jd_sd.warmstate.get_location_str(greenkey)
w_greenkey = wrap_greenkey(space, jd_sd.jitdriver, greenkey, repr)
- l_w.append(DebugMergePoint(space, jit_hooks._cast_to_gcref(op),
+ l_w.append(DebugMergePoint(space, name,
logops.repr_of_resop(op),
jd_sd.jitdriver.name,
op.getarg(1).getint(),
op.getarg(2).getint(),
w_greenkey))
else:
- l_w.append(WrappedOp(jit_hooks._cast_to_gcref(op), ofs,
- logops.repr_of_resop(op)))
+ l_w.append(WrappedOp(name, ofs, logops.repr_of_resop(op)))
return l_w
+@unwrap_spec(offset=int, repr=str, name=str)
+def descr_new_resop(space, w_tp, name, offset=-1, repr=''):
+ return WrappedOp(name, offset, repr)
-class WrappedBox(W_Root):
- """ A class representing a single box
- """
- def __init__(self, llbox):
- self.llbox = llbox
-
- def descr_getint(self, space):
- if not jit_hooks.box_isint(self.llbox):
- raise OperationError(space.w_NotImplementedError,
- space.wrap("Box has no int value"))
- return space.wrap(jit_hooks.box_getint(self.llbox))
-
-@unwrap_spec(no=int)
-def descr_new_box(space, w_tp, no):
- return WrappedBox(jit_hooks.boxint_new(no))
-
-WrappedBox.typedef = TypeDef(
- 'Box',
- __new__ = interp2app(descr_new_box),
- getint = interp2app(WrappedBox.descr_getint),
-)
-
-@unwrap_spec(num=int, offset=int, repr=str, w_res=W_Root)
-def descr_new_resop(space, w_tp, num, w_args, w_res, offset=-1,
- repr=''):
- args = [space.interp_w(WrappedBox, w_arg).llbox for w_arg in
- space.listview(w_args)]
- if space.is_none(w_res):
- llres = jit_hooks.emptyval()
- else:
- if not isinstance(w_res, WrappedBox):
- raise OperationError(space.w_TypeError, space.wrap(
- "expected box type, got %s" % space.type(w_res)))
- llres = w_res.llbox
- return WrappedOp(jit_hooks.resop_new(num, args, llres), offset, repr)
-
-@unwrap_spec(repr=str, jd_name=str, call_depth=int, call_id=int)
-def descr_new_dmp(space, w_tp, w_args, repr, jd_name, call_depth, call_id,
+@unwrap_spec(repr=str, name=str, jd_name=str, call_depth=int, call_id=int)
+def descr_new_dmp(space, w_tp, name, repr, jd_name, call_depth, call_id,
w_greenkey):
- args = [space.interp_w(WrappedBox, w_arg).llbox for w_arg in
- space.listview(w_args)]
- num = rop.DEBUG_MERGE_POINT
- return DebugMergePoint(space,
- jit_hooks.resop_new(num, args,
jit_hooks.emptyval()),
+ return DebugMergePoint(space, name,
repr, jd_name, call_depth, call_id, w_greenkey)
class WrappedOp(W_Root):
""" A class representing a single ResOperation, wrapped nicely
"""
- def __init__(self, op, offset, repr_of_resop):
- self.op = op
+ def __init__(self, name, offset, repr_of_resop):
self.offset = offset
+ self.name = name
self.repr_of_resop = repr_of_resop
def descr_repr(self, space):
return space.wrap(self.repr_of_resop)
- def descr_num(self, space):
- return space.wrap(jit_hooks.resop_getopnum(self.op))
-
def descr_name(self, space):
- return space.wrap(hlstr(jit_hooks.resop_getopname(self.op)))
-
- @unwrap_spec(no=int)
- def descr_getarg(self, space, no):
- try:
- box = jit_hooks.resop_getarg(self.op, no)
- except IndexError:
- raise OperationError(space.w_IndexError,
- space.wrap("Index out of range"))
- return WrappedBox(box)
-
- @unwrap_spec(no=int, w_box=WrappedBox)
- def descr_setarg(self, space, no, w_box):
- jit_hooks.resop_setarg(self.op, no, w_box.llbox)
-
- def descr_getresult(self, space):
- return WrappedBox(jit_hooks.resop_getresult(self.op))
-
- def descr_setresult(self, space, w_box):
- box = space.interp_w(WrappedBox, w_box)
- jit_hooks.resop_setresult(self.op, box.llbox)
+ return space.wrap(self.name)
class DebugMergePoint(WrappedOp):
""" A class representing Debug Merge Point - the entry point
to a jitted loop.
"""
- def __init__(self, space, op, repr_of_resop, jd_name, call_depth, call_id,
- w_greenkey):
+ def __init__(self, space, name, repr_of_resop, jd_name, call_depth,
+ call_id, w_greenkey):
- WrappedOp.__init__(self, op, -1, repr_of_resop)
+ WrappedOp.__init__(self, name, -1, repr_of_resop)
self.jd_name = jd_name
self.call_depth = call_depth
self.call_id = call_id
@@ -237,12 +185,7 @@
__doc__ = WrappedOp.__doc__,
__new__ = interp2app(descr_new_resop),
__repr__ = interp2app(WrappedOp.descr_repr),
- num = GetSetProperty(WrappedOp.descr_num),
name = GetSetProperty(WrappedOp.descr_name),
- getarg = interp2app(WrappedOp.descr_getarg),
- setarg = interp2app(WrappedOp.descr_setarg),
- result = GetSetProperty(WrappedOp.descr_getresult,
- WrappedOp.descr_setresult),
offset = interp_attrproperty("offset", cls=WrappedOp),
)
WrappedOp.typedef.acceptable_as_base_class = False
@@ -278,14 +221,18 @@
asmaddr = 0
asmlen = 0
- def __init__(self, space, debug_info, is_bridge=False):
- logops = debug_info.logger._make_log_operations()
- if debug_info.asminfo is not None:
- ofs = debug_info.asminfo.ops_offset
+ def __init__(self, space, debug_info, is_bridge=False, wrap_ops=True):
+ if wrap_ops:
+ memo = {}
+ logops = debug_info.logger._make_log_operations(memo)
+ if debug_info.asminfo is not None:
+ ofs = debug_info.asminfo.ops_offset
+ else:
+ ofs = {}
+ ops = debug_info.operations
+ self.w_ops = space.newlist(wrap_oplist(space, logops, ops, ofs))
else:
- ofs = {}
- self.w_ops = space.newlist(
- wrap_oplist(space, logops, debug_info.operations, ofs))
+ self.w_ops = space.w_None
self.jd_name = debug_info.get_jitdriver().name
self.type = debug_info.type
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
@@ -136,7 +136,6 @@
assert dmp.call_id == 0
assert dmp.offset == -1
assert int_add.name == 'int_add'
- assert int_add.num == self.int_add_num
assert int_add.offset == 0
self.on_compile_bridge()
expected = ('<JitLoopInfo pypyjit, 4 operations, starting at '
@@ -173,10 +172,7 @@
self.on_compile()
loop = loops[0]
op = loop.operations[2]
- # Should not crash the interpreter
- raises(IndexError, op.getarg, 2)
assert op.name == 'guard_nonnull'
- raises(NotImplementedError, op.getarg(0).getint)
def test_non_reentrant(self):
import pypyjit
@@ -234,35 +230,28 @@
assert l == ['pypyjit']
def test_creation(self):
- from pypyjit import Box, ResOperation
+ from pypyjit import ResOperation
- op = ResOperation(self.int_add_num, [Box(1), Box(3)], Box(4))
- assert op.num == self.int_add_num
+ op = ResOperation("int_add", -1, "int_add(1, 2)")
assert op.name == 'int_add'
- box = op.getarg(0)
- assert box.getint() == 1
- box2 = op.result
- assert box2.getint() == 4
- op.setarg(0, box2)
- assert op.getarg(0).getint() == 4
- op.result = box
- assert op.result.getint() == 1
+ assert repr(op) == "int_add(1, 2)"
def test_creation_dmp(self):
- from pypyjit import DebugMergePoint, Box
+ from pypyjit import DebugMergePoint
def f():
pass
- op = DebugMergePoint([Box(0)], 'repr', 'pypyjit', 2, 3, (f.func_code,
0, 0))
+ op = DebugMergePoint("debug_merge_point", 'repr', 'pypyjit', 2, 3,
(f.func_code, 0, 0))
assert op.bytecode_no == 0
assert op.pycode is f.func_code
assert repr(op) == 'repr'
assert op.jitdriver_name == 'pypyjit'
- assert op.num == self.dmp_num
+ assert op.name == 'debug_merge_point'
assert op.call_depth == 2
assert op.call_id == 3
- op = DebugMergePoint([Box(0)], 'repr', 'notmain', 5, 4, ('str',))
+ op = DebugMergePoint('debug_merge_point', 'repr', 'notmain',
+ 5, 4, ('str',))
raises(AttributeError, 'op.pycode')
assert op.call_depth == 5
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit