Author: Remi Meier <remi.me...@inf.ethz.ch> Branch: stmgc-c7 Changeset: r72903:1a671d185d5f Date: 2014-08-19 13:08 +0200 http://bitbucket.org/pypy/pypy/changeset/1a671d185d5f/
Log: remove most should_break_transaction guards; also add rstm.is_inevitable() diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py --- a/pypy/interpreter/pyopcode.py +++ b/pypy/interpreter/pyopcode.py @@ -152,7 +152,7 @@ ec.bytecode_only_trace(self) else: ec.bytecode_trace(self) - rstm.possible_transaction_break() + rstm.possible_transaction_break(0) next_instr = r_uint(self.last_instr) opcode = ord(co_code[next_instr]) next_instr += 1 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 @@ -85,7 +85,7 @@ ec.bytecode_trace(self, decr_by) jumpto = r_uint(self.last_instr) if self.space.threadlocals.threads_running: # quasi-immutable field - rstm.possible_transaction_break() + rstm.possible_transaction_break(1) # pypyjitdriver.can_enter_jit(frame=self, ec=ec, next_instr=jumpto, pycode=self.getcode(), 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 @@ -908,10 +908,10 @@ return False - @arguments(returns="i") - def bhimpl_stm_should_break_transaction(): + @arguments("i", returns="i") + def bhimpl_stm_should_break_transaction(keep): from rpython.rlib import rstm - return rstm.should_break_transaction() + return rstm.should_break_transaction(0) @arguments() def bhimpl_stm_hint_commit_soon(): 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 @@ -187,14 +187,34 @@ # ------------------------------ - @arguments() - def opimpl_stm_should_break_transaction(self): - # XXX make it return BoxInt(1) instead of BoxInt(0) if there - # is an inevitable transaction, because it's likely that there - # will always be an inevitable transaction here - resbox = history.BoxInt(0) - mi = self.metainterp - mi.history.record(rop.STM_SHOULD_BREAK_TRANSACTION, [], resbox) + @arguments("int") + def opimpl_stm_should_break_transaction(self, keep): + # from rpython.rlib import rstm + + record_break = False + resbox = history.ConstInt(0) + + if bool(keep): + # always keep (i.c. end of loops) + resbox = history.BoxInt(0) + record_break = True + + ## XXX: not working yet. we are always inevitable when tracing + # if we_are_translated() and rstm.is_inevitable(): + # # return BoxInt(1) if there is an inevitable + # # transaction, because it's likely that there + # # will always be an inevitable transaction here + # resbox = history.BoxInt(1) + # record_break = True + + if record_break: + mi = self.metainterp + mi.history.record(rop.STM_SHOULD_BREAK_TRANSACTION, [], resbox) + else: + # don't record the should_break_transaction and optimize + # the guard away + pass + return resbox @arguments() diff --git a/rpython/jit/metainterp/test/test_stm.py b/rpython/jit/metainterp/test/test_stm.py --- a/rpython/jit/metainterp/test/test_stm.py +++ b/rpython/jit/metainterp/test/test_stm.py @@ -11,7 +11,7 @@ class STMTests: def test_simple(self): def g(): - return rstm.should_break_transaction() + return rstm.should_break_transaction(1) res = self.interp_operations(g, [], translationoptions={"stm":True}) assert res == False self.check_operations_history(stm_should_break_transaction=1) diff --git a/rpython/jit/tl/tlc.py b/rpython/jit/tl/tlc.py --- a/rpython/jit/tl/tlc.py +++ b/rpython/jit/tl/tlc.py @@ -15,12 +15,12 @@ def int_o(self): raise TypeError def to_string(self): raise TypeError - + def add(self, other): raise TypeError def sub(self, other): raise TypeError def mul(self, other): raise TypeError def div(self, other): raise TypeError - + def eq(self, other): raise TypeError def lt(self, other): raise TypeError @@ -92,7 +92,7 @@ self.methods = {} for methname, pc in descr.methods: self.methods[methname] = pc - + class InstanceObj(Obj): def __init__(self, cls): @@ -226,7 +226,7 @@ self.pc = pc self.stack = [] - + def make_interp(supports_call, jitted=True): myjitdriver = JitDriver(greens = ['pc', 'code'], reds = ['frame', 'pool']) @@ -234,7 +234,7 @@ def interp(code='', pc=0, inputarg=0, pool=None): if not isinstance(code,str): raise TypeError("code '%s' should be a string" % str(code)) - + if pool is None: pool = ConstantPool() args = [IntObj(inputarg)] @@ -255,7 +255,7 @@ if opcode == NOP: pass - + elif opcode == NIL: stack.append(nil) @@ -268,7 +268,7 @@ elif opcode == CDR: stack.append(stack.pop().cdr()) - + elif opcode == PUSH: stack.append(IntObj(char2int(code[pc]))) pc += 1 @@ -349,32 +349,32 @@ pc += char2int(code[pc]) pc += 1 if jitted and old_pc > pc: - rstm.possible_transaction_break() + rstm.possible_transaction_break(1) myjitdriver.can_enter_jit(code=code, pc=pc, frame=frame, pool=pool) - + elif opcode == BR_COND: cond = stack.pop() if cond.t(): old_pc = pc pc += char2int(code[pc]) + 1 if jitted and old_pc > pc: - rstm.possible_transaction_break() + rstm.possible_transaction_break(1) myjitdriver.can_enter_jit(code=code, pc=pc, frame=frame, pool=pool) else: pc += 1 - + elif opcode == BR_COND_STK: offset = stack.pop().int_o() if stack.pop().t(): old_pc = pc pc += offset if jitted and old_pc > pc: - rstm.possible_transaction_break() + rstm.possible_transaction_break(1) myjitdriver.can_enter_jit(code=code, pc=pc, frame=frame, pool=pool) - + elif supports_call and opcode == CALL: offset = char2int(code[pc]) @@ -451,7 +451,7 @@ return frame.stack[-1] else: return None - + return interp, interp_eval diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py --- a/rpython/rlib/rstm.py +++ b/rpython/rlib/rstm.py @@ -49,9 +49,13 @@ # special-cased below: the emitted operation must be placed # directly in the caller's graph -def possible_transaction_break(): +@specialize.arg(0) +def possible_transaction_break(keep): + """ keep: should be True for checks that are absolutely + needed. False means the JIT only keeps the check if it + thinks that it helps """ if stm_is_enabled(): - if llop.stm_should_break_transaction(lltype.Bool): + if llop.stm_should_break_transaction(lltype.Bool, keep): break_transaction() def hint_commit_soon(): @@ -70,9 +74,10 @@ def partial_commit_and_resume_other_threads(): pass # for now -def should_break_transaction(): +@specialize.arg(0) +def should_break_transaction(keep): return we_are_translated() and ( - llop.stm_should_break_transaction(lltype.Bool)) + llop.stm_should_break_transaction(lltype.Bool, keep)) @dont_look_inside def break_transaction(): @@ -95,6 +100,10 @@ return llop.stm_get_atomic(lltype.Signed) @dont_look_inside +def is_inevitable(): + return llop.stm_is_inevitable(lltype.Signed) + +@dont_look_inside def abort_and_retry(): llop.stm_abort_and_retry(lltype.Void) diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py --- a/rpython/rtyper/llinterp.py +++ b/rpython/rtyper/llinterp.py @@ -956,6 +956,7 @@ op_stm_enter_callback_call = _stm_not_implemented op_stm_leave_callback_call = _stm_not_implemented op_stm_get_atomic = _stm_not_implemented + op_stm_is_inevitable = _stm_not_implemented op_stm_change_atomic = _stm_not_implemented op_stm_set_transaction_length = _stm_not_implemented op_stm_hash = _stm_not_implemented @@ -970,7 +971,7 @@ op_stm_stop_all_other_threads = _stm_not_implemented op_stm_partial_commit_and_resume_other_threads = _stm_not_implemented - def op_stm_should_break_transaction(self): + def op_stm_should_break_transaction(self, keep): return False def op_threadlocalref_set(self, key, value): 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 @@ -445,6 +445,8 @@ 'stm_decrement_atomic': LLOp(), 'stm_get_atomic': LLOp(sideeffects=False), + 'stm_is_inevitable': LLOp(sideeffects=False), + 'stm_ignored_start': LLOp(canrun=True), 'stm_ignored_stop': LLOp(canrun=True), diff --git a/rpython/translator/stm/funcgen.py b/rpython/translator/stm/funcgen.py --- a/rpython/translator/stm/funcgen.py +++ b/rpython/translator/stm/funcgen.py @@ -190,6 +190,10 @@ result = funcgen.expr(op.result) return '%s = pypy_stm_get_atomic();' % (result,) +def stm_is_inevitable(funcgen, op): + result = funcgen.expr(op.result) + return '%s = stm_is_inevitable();' % (result,) + def stm_abort_and_retry(funcgen, op): return 'stm_abort_transaction();' _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit