[pypy-commit] pypy remember-tracing-counts: a bit untested but try to expose minimal thing

fijal noreply at buildbot.pypy.org
Mon Sep 14 14:28:15 CEST 2015


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: remember-tracing-counts
Changeset: r79624:da93da5c1b8f
Date: 2015-09-14 14:28 +0200
http://bitbucket.org/pypy/pypy/changeset/da93da5c1b8f/

Log:	a bit untested but try to expose minimal thing

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,9 @@
 
     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
-        return PyPyJitPolicy()#pypy_hooks)
+        return PyPyJitPolicy(pypy_hooks)
 
     def get_entry_point(self, config):
         from pypy.tool.lib_pypy import import_from_lib_pypy
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
@@ -11,6 +11,7 @@
         'get_jitcell_at_key': 'interp_jit.get_jitcell_at_key',
         'dont_trace_here': 'interp_jit.dont_trace_here',
         'trace_next_iteration': 'interp_jit.trace_next_iteration',
+        'set_compile_bridge': 'interp_jit.set_compile_bridge',
         #'set_compile_hook': 'interp_resop.set_compile_hook',
         #'set_optimize_hook': 'interp_resop.set_optimize_hook',
         #'set_abort_hook': 'interp_resop.set_abort_hook',
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
@@ -6,7 +6,8 @@
 from rpython.rlib.rarithmetic import r_uint, intmask
 from rpython.rlib.jit import JitDriver, hint, we_are_jitted, dont_look_inside
 from rpython.rlib import jit, jit_hooks
-from rpython.rlib.jit import current_trace_length, unroll_parameters
+from rpython.rlib.jit import current_trace_length, unroll_parameters,\
+     JitHookInterface
 from rpython.rtyper.annlowlevel import cast_instance_to_gcref
 import pypy.interpreter.pyopcode   # for side-effects
 from pypy.interpreter.error import OperationError, oefmt
@@ -213,3 +214,77 @@
     jit_hooks.trace_next_iteration(
         'pypyjit', r_uint(next_instr), int(is_being_profiled), ll_pycode)
     return space.w_None
+
+ at unwrap_spec(hash=r_uint)
+ at dont_look_inside
+def trace_next_iteration_hash(space, hash):
+    jit_hooks.trace_next_iteration_hash(hash)
+    return space.w_None
+
+class Cache(object):
+    in_recursion = False
+
+    def __init__(self, space):
+        self.w_compile_bridge = None
+        self.w_compile_loop = 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_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)
+
+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.get_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_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_bridge(self, debug_info):
+        pass
+
+pypy_hooks = PyPyJitHookInterface()
+


More information about the pypy-commit mailing list