Author: Armin Rigo <ar...@tunes.org> Branch: stmgc-c4 Changeset: r65137:aef695dc9da1 Date: 2013-07-01 15:35 +0200 http://bitbucket.org/pypy/pypy/changeset/aef695dc9da1/
Log: Enough to have test_targetdemo compile (but not run yet). diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py --- a/rpython/rlib/rstm.py +++ b/rpython/rlib/rstm.py @@ -1,5 +1,5 @@ from rpython.rlib.objectmodel import we_are_translated, specialize -from rpython.rtyper.lltypesystem import lltype +from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rtyper.lltypesystem.lloperation import llop from rpython.rtyper.extregistry import ExtRegistryEntry @@ -37,73 +37,48 @@ stmgcintf.StmOperations.abort_and_retry() def before_external_call(): - if not is_atomic(): - e = get_errno() - llop.stm_stop_transaction(lltype.Void) - stmgcintf.StmOperations.commit_transaction() - set_errno(e) + llop.stm_commit_transaction(lltype.Void) before_external_call._dont_reach_me_in_del_ = True before_external_call._transaction_break_ = True def after_external_call(): - if not is_atomic(): - e = get_errno() - stmgcintf.StmOperations.begin_inevitable_transaction() - llop.stm_start_transaction(lltype.Void) - set_errno(e) + llop.stm_begin_inevitable_transaction(lltype.Void) after_external_call._dont_reach_me_in_del_ = True after_external_call._transaction_break_ = True def enter_callback_call(): - token = stmgcintf.StmOperations.descriptor_init() - if token != 1: - after_external_call() - else: - ll_assert(not is_atomic(), "new thread: is_atomic() != 0") - stmgcintf.StmOperations.begin_inevitable_transaction() - # the StmGCTLS is not built yet. leave it to gc_thread_start() - return token + # XXX assumes that we're not called in a fresh new thread + llop.stm_begin_inevitable_transaction(lltype.Void) + return 0 enter_callback_call._dont_reach_me_in_del_ = True enter_callback_call._transaction_break_ = True -def leave_callback_call(token): - if token != 1: - before_external_call() - else: - # the StmGCTLS is already destroyed, done by gc_thread_die() - # (we don't care if is_atomic() or not, we'll commit now) - stmgcintf.StmOperations.commit_transaction() - stmgcintf.StmOperations.descriptor_done() +def leave_callback_call(ignored): + llop.stm_commit_transaction(lltype.Void) leave_callback_call._dont_reach_me_in_del_ = True leave_callback_call._transaction_break_ = True # ____________________________________________________________ def make_perform_transaction(func, CONTAINERP): + from rpython.rtyper.annlowlevel import llhelper + from rpython.rtyper.annlowlevel import cast_instance_to_base_ptr + from rpython.translator.stm.stmgcintf import CALLBACK_TX # def _stm_callback(llcontainer, retry_counter): - if not is_atomic(): - llop.stm_start_transaction(lltype.Void) llcontainer = rffi.cast(CONTAINERP, llcontainer) + retry_counter = rffi.cast(lltype.Signed, retry_counter) try: res = func(llcontainer, retry_counter) except Exception, e: - res = 0 # stop perform_transaction() and returns + res = 0 # ends perform_transaction() and returns lle = cast_instance_to_base_ptr(e) llcontainer.got_exception = lle - if not is_atomic(): - llop.stm_stop_transaction(lltype.Void) - return res + return rffi.cast(rffi.INT_real, res) # def perform_transaction(llcontainer): - before_external_call() - adr_of_top = llop.gc_adr_of_root_stack_top(llmemory.Address) - llcallback = llhelper(stmgcintf.StmOperations.CALLBACK_TX, - _stm_callback) - stmgcintf.StmOperations.perform_transaction(llcallback, llcontainer, - adr_of_top) - after_external_call() - keepalive_until_here(llcontainer) + llcallback = llhelper(CALLBACK_TX, _stm_callback) + llop.stm_perform_transaction(lltype.Void, llcontainer, llcallback) perform_transaction._transaction_break_ = True # return perform_transaction 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 @@ -440,6 +440,7 @@ 'stm_set_transaction_length': LLOp(), 'stm_change_atomic': LLOp(), 'stm_get_atomic': LLOp(sideeffects=False), + 'stm_perform_transaction':LLOp(), 'stm_threadlocalref_get': LLOp(sideeffects=False), 'stm_threadlocalref_set': LLOp(), 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 @@ -603,6 +603,7 @@ OP_STM_GET_ATOMIC = _OP_STM OP_STM_THREADLOCAL_GET = _OP_STM OP_STM_THREADLOCAL_SET = _OP_STM + OP_STM_PERFORM_TRANSACTION = _OP_STM def OP_PTR_NONZERO(self, op): 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 @@ -6,6 +6,7 @@ class StmHeaderOpaqueDefNode(Node): typetag = 'struct' + dependencies = () def __init__(self, db, T): Node.__init__(self, db) @@ -115,10 +116,10 @@ return '%s = stm_id((gcptr)%s);' % (result, arg0) def stm_commit_transaction(funcgen, op): - return 'stm_commit_transaction();' + return '{ int e = errno; stm_commit_transaction(); errno = e; }' def stm_begin_inevitable_transaction(funcgen, op): - return 'stm_begin_inevitable_transaction();' + return '{ int e = errno; stm_begin_inevitable_transaction(); errno = e; }' def stm_should_break_transaction(funcgen, op): result = funcgen.expr(op.result) @@ -145,6 +146,11 @@ arg0 = funcgen.expr(op.args[0]) return 'stm_thread_local_obj = (gcptr)%s;' % (arg0,) +def stm_perform_transaction(funcgen, op): + arg0 = funcgen.expr(op.args[0]) + arg1 = funcgen.expr(op.args[1]) + return 'stm_perform_transaction((gcptr)%s, %s);' % (arg0, arg1) + def op_stm(funcgen, op): func = globals()[op.opname] diff --git a/rpython/translator/stm/jitdriver.py b/rpython/translator/stm/jitdriver.py --- a/rpython/translator/stm/jitdriver.py +++ b/rpython/translator/stm/jitdriver.py @@ -107,12 +107,9 @@ # turn the following link into an "if False" link, add a new # "if True" link going to a fresh new block, and return this new # block. - funcptr = StmOperations.should_break_transaction - c = Constant(funcptr, lltype.typeOf(funcptr)) - v1 = varoftype(lltype.Signed) - block.operations.append(SpaceOperation('direct_call', [c], v1)) v2 = varoftype(lltype.Bool) - block.operations.append(SpaceOperation('int_is_true', [v1], v2)) + block.operations.append( + SpaceOperation('stm_should_break_transaction', [], v2)) # assert block.exitswitch is None [link] = block.exits diff --git a/rpython/translator/stm/stmgcintf.py b/rpython/translator/stm/stmgcintf.py --- a/rpython/translator/stm/stmgcintf.py +++ b/rpython/translator/stm/stmgcintf.py @@ -1,4 +1,5 @@ import os +from rpython.rtyper.lltypesystem import lltype, rffi from rpython.translator.tool.cbuild import ExternalCompilationInfo from rpython.conftest import cdir as cdir2 @@ -30,3 +31,7 @@ pre_include_bits = ['#define RPY_STM 1'], separate_module_sources = [separate_source], ) + +GCPTR = lltype.Ptr(rffi.COpaque('struct stm_object_s')) +CALLBACK_TX = lltype.Ptr(lltype.FuncType([GCPTR, rffi.INT_real], + rffi.INT_real)) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit