[pypy-commit] pypy callback-jit: a strange experiment with jit merge point at a start of callback, not sure how to write tests for it?
fijal
noreply at buildbot.pypy.org
Wed Dec 26 19:23:39 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: callback-jit
Changeset: r59567:551095d724b6
Date: 2012-12-26 19:59 +0200
http://bitbucket.org/pypy/pypy/changeset/551095d724b6/
Log: a strange experiment with jit merge point at a start of callback,
not sure how to write tests for it?
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,7 @@
from pypy.tool.pairtype import extendabletype
from pypy.rlib.rarithmetic import r_uint, intmask
from pypy.rlib.jit import JitDriver, hint, we_are_jitted, dont_look_inside
-from pypy.rlib import jit
+from pypy.rlib import jit, objectmodel
from pypy.rlib.jit import current_trace_length, unroll_parameters
import pypy.interpreter.pyopcode # for side-effects
from pypy.interpreter.error import OperationError, operationerrfmt
@@ -97,6 +97,17 @@
is_being_profiled=self.is_being_profiled)
return jumpto
+callback_jit_driver = JitDriver(greens = ['name'], reds = 'auto')
+
+def callback_merge_point(name):
+ callback_jit_driver.jit_merge_point(name=name)
+
+ at callback_jit_driver.inline(callback_merge_point)
+def callback_hook(name):
+ pass
+
+objectmodel.register_around_callback_hook(callback_hook)
+
def _get_adapted_tick_counter():
# Normally, the tick counter is decremented by 100 for every
# Python opcode. Here, to better support JIT compilation of
diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -591,6 +591,19 @@
llhelper(rffi.AroundFnPtr, before)
llhelper(rffi.AroundFnPtr, after)
+def register_around_callback_hook(hook):
+ """ Register a hook that's called before a callback from C calls RPython.
+ Primary usage is for JIT to have 'started from' hook.
+ """
+ from pypy.rpython.lltypesystem import lltype, rffi, rstr
+ from pypy.rpython.annlowlevel import llhelper
+
+ CallbackHookPtr = lltype.Ptr(lltype.FuncType([rstr.STR], lltype.Void))
+
+ hook._always_inline_ = True
+ rffi.aroundstate.callback_hook = hook
+ llhelper(CallbackHookPtr, hook)
+
def is_in_callback():
from pypy.rpython.lltypesystem import rffi
return rffi.stackcounter.stacks_counter > 1
diff --git a/pypy/rpython/lltypesystem/rffi.py b/pypy/rpython/lltypesystem/rffi.py
--- a/pypy/rpython/lltypesystem/rffi.py
+++ b/pypy/rpython/lltypesystem/rffi.py
@@ -286,6 +286,9 @@
after = aroundstate.after
if after:
after()
+ callback_hook = aroundstate.callback_hook
+ if callback_hook:
+ callback_hook("%s")
# from now on we hold the GIL
stackcounter.stacks_counter += 1
try:
@@ -307,7 +310,7 @@
# by llexternal, it is essential that no exception checking occurs
# after the call to before().
return result
- """ % (args, args))
+ """ % (args, str(callable).replace('"', '\\"'), args))
miniglobals = locals().copy()
miniglobals['Exception'] = Exception
miniglobals['os'] = os
@@ -318,10 +321,12 @@
_make_wrapper_for._annspecialcase_ = 'specialize:memo'
AroundFnPtr = lltype.Ptr(lltype.FuncType([], lltype.Void))
+
class AroundState:
def _cleanup_(self):
- self.before = None # or a regular RPython function
- self.after = None # or a regular RPython function
+ self.before = None # or a regular RPython function
+ self.after = None # or a regular RPython function
+ self.callback_hook = None # or a regular RPython function
aroundstate = AroundState()
aroundstate._cleanup_()
More information about the pypy-commit
mailing list