Author: Carl Friedrich Bolz <[email protected]>
Branch:
Changeset: r82453:97c9937d38ad
Date: 2016-02-23 18:00 +0100
http://bitbucket.org/pypy/pypy/changeset/97c9937d38ad/
Log: (fijal, cfbolz): make it possible to insert enter_portal_frame and
leave_portal_frame explicitly, for the weird interpreters that need
that.
diff --git a/rpython/jit/codewriter/jtransform.py
b/rpython/jit/codewriter/jtransform.py
--- a/rpython/jit/codewriter/jtransform.py
+++ b/rpython/jit/codewriter/jtransform.py
@@ -2042,6 +2042,11 @@
self.vable_flags[op.args[0]] = op.args[2].value
return []
+ def rewrite_op_jit_enter_portal_frame(self, op):
+ return [op]
+ def rewrite_op_jit_leave_portal_frame(self, op):
+ return [op]
+
# ---------
# ll_math.sqrt_nonneg()
diff --git a/rpython/jit/metainterp/blackhole.py
b/rpython/jit/metainterp/blackhole.py
--- a/rpython/jit/metainterp/blackhole.py
+++ b/rpython/jit/metainterp/blackhole.py
@@ -944,6 +944,14 @@
pass
@arguments("i")
+ def bhimpl_jit_enter_portal_frame(x):
+ pass
+
+ @arguments()
+ def bhimpl_jit_leave_portal_frame():
+ pass
+
+ @arguments("i")
def bhimpl_int_assert_green(x):
pass
@arguments("r")
diff --git a/rpython/jit/metainterp/pyjitpl.py
b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -1358,6 +1358,17 @@
self.metainterp.attach_debug_info(op)
@arguments("box")
+ def opimpl_jit_enter_portal_frame(self, uniqueidbox):
+ unique_id = uniqueidbox.getint()
+ jd_no = self.metainterp.jitdriver_sd.mainjitcode.index # fish
+ self.metainterp.enter_portal_frame(jd_no, unique_id)
+
+ @arguments()
+ def opimpl_jit_leave_portal_frame(self):
+ jd_no = self.metainterp.jitdriver_sd.mainjitcode.index # fish
+ self.metainterp.leave_portal_frame(jd_no)
+
+ @arguments("box")
def _opimpl_assert_green(self, box):
if not isinstance(box, Const):
msg = "assert_green failed at %s:%d" % (
diff --git a/rpython/jit/metainterp/test/test_jitdriver.py
b/rpython/jit/metainterp/test/test_jitdriver.py
--- a/rpython/jit/metainterp/test/test_jitdriver.py
+++ b/rpython/jit/metainterp/test/test_jitdriver.py
@@ -213,6 +213,21 @@
if op.getopname() == 'enter_portal_frame':
assert op.getarg(0).getint() == 0
assert op.getarg(1).getint() == 1
-
+
+ def test_manual_leave_enter_portal_frame(self):
+ from rpython.rlib import jit
+ driver = JitDriver(greens=[], reds='auto', is_recursive=True)
+
+ def f(arg):
+ i = 0
+ while i < 100:
+ driver.jit_merge_point()
+ jit.enter_portal_frame(42)
+ jit.leave_portal_frame()
+ i += 1
+
+ self.meta_interp(f, [0])
+ self.check_resops(enter_portal_frame=1, leave_portal_frame=1)
+
class TestLLtype(MultipleJitDriversTests, LLJitMixin):
pass
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -1168,6 +1168,24 @@
hop.exception_is_here()
return hop.genop('jit_conditional_call', args_v)
+def enter_portal_frame(unique_id):
+ """call this when starting to interpret a function. calling this is not
+ necessary for almost all interpreters. The only exception is stackless
+ interpreters where the portal never calls itself.
+ """
+ from rpython.rtyper.lltypesystem import lltype
+ from rpython.rtyper.lltypesystem.lloperation import llop
+ llop.jit_enter_portal_frame(lltype.Void, unique_id)
+
+def leave_portal_frame():
+ """call this after the end of executing a function. calling this is not
+ necessary for almost all interpreters. The only exception is stackless
+ interpreters where the portal never calls itself.
+ """
+ from rpython.rtyper.lltypesystem import lltype
+ from rpython.rtyper.lltypesystem.lloperation import llop
+ llop.jit_leave_portal_frame(lltype.Void)
+
class Counters(object):
counters="""
TRACING
diff --git a/rpython/rlib/test/test_jit.py b/rpython/rlib/test/test_jit.py
--- a/rpython/rlib/test/test_jit.py
+++ b/rpython/rlib/test/test_jit.py
@@ -4,7 +4,8 @@
from rpython.annotator.model import UnionError
from rpython.rlib.jit import (hint, we_are_jitted, JitDriver, elidable_promote,
JitHintError, oopspec, isconstant, conditional_call,
- elidable, unroll_safe, dont_look_inside)
+ elidable, unroll_safe, dont_look_inside,
+ enter_portal_frame, leave_portal_frame)
from rpython.rlib.rarithmetic import r_uint
from rpython.rtyper.test.tool import BaseRtypingTest
from rpython.rtyper.lltypesystem import lltype
@@ -300,3 +301,11 @@
mix = MixLevelHelperAnnotator(t.rtyper)
mix.getgraph(later, [annmodel.s_Bool], annmodel.s_None)
mix.finish()
+
+ def test_enter_leave_portal_frame(self):
+ from rpython.translator.interactive import Translation
+ def g():
+ enter_portal_frame(1)
+ leave_portal_frame()
+ t = Translation(g, [])
+ t.compile_c() # does not crash
diff --git a/rpython/rtyper/lltypesystem/lloperation.py
b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -453,6 +453,8 @@
'jit_record_exact_class' : LLOp(canrun=True),
'jit_ffi_save_result': LLOp(canrun=True),
'jit_conditional_call': LLOp(),
+ 'jit_enter_portal_frame': LLOp(canrun=True),
+ 'jit_leave_portal_frame': LLOp(canrun=True),
'get_exception_addr': LLOp(),
'get_exc_value_addr': LLOp(),
'do_malloc_fixedsize':LLOp(canmallocgc=True),
diff --git a/rpython/rtyper/lltypesystem/opimpl.py
b/rpython/rtyper/lltypesystem/opimpl.py
--- a/rpython/rtyper/lltypesystem/opimpl.py
+++ b/rpython/rtyper/lltypesystem/opimpl.py
@@ -624,6 +624,12 @@
def op_jit_ffi_save_result(*args):
pass
+def op_jit_enter_portal_frame(x):
+ pass
+
+def op_jit_leave_portal_frame():
+ pass
+
def op_get_group_member(TYPE, grpptr, memberoffset):
from rpython.rtyper.lltypesystem import llgroup
assert isinstance(memberoffset, llgroup.GroupMemberOffset)
diff --git a/rpython/translator/c/funcgen.py b/rpython/translator/c/funcgen.py
--- a/rpython/translator/c/funcgen.py
+++ b/rpython/translator/c/funcgen.py
@@ -842,6 +842,12 @@
def OP_JIT_FFI_SAVE_RESULT(self, op):
return '/* JIT_FFI_SAVE_RESULT %s */' % op
+ def OP_JIT_ENTER_PORTAL_FRAME(self, op):
+ return '/* JIT_ENTER_PORTAL_FRAME %s */' % op
+
+ def OP_JIT_LEAVE_PORTAL_FRAME(self, op):
+ return '/* JIT_LEAVE_PORTAL_FRAME %s */' % op
+
def OP_GET_GROUP_MEMBER(self, op):
typename = self.db.gettype(op.result.concretetype)
return '%s = (%s)_OP_GET_GROUP_MEMBER(%s, %s);' % (
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit