[pypy-commit] pypy stm: Test and fix.

arigo noreply at buildbot.pypy.org
Thu Nov 3 19:15:39 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r48709:a45743e6ee4e
Date: 2011-11-03 18:54 +0100
http://bitbucket.org/pypy/pypy/changeset/a45743e6ee4e/

Log:	Test and fix.

diff --git a/pypy/translator/stm/funcgen.py b/pypy/translator/stm/funcgen.py
--- a/pypy/translator/stm/funcgen.py
+++ b/pypy/translator/stm/funcgen.py
@@ -102,7 +102,15 @@
 
 def stm_transaction_boundary(funcgen, op):
     assert funcgen.exception_policy == 'stm'
-    return 'STM_TRANSACTION_BOUNDARY();'
+    lines = ['STM_TRANSACTION_BOUNDARY();']
+    TMPVAR = 'ty_%s'
+    for v in op.args:
+        tmpname = TMPVAR % v.name
+        cdeclname = cdecl(funcgen.lltypename(v), 'volatile ' + tmpname)
+        realname = funcgen.expr(v)
+        lines.insert(0, '%s = %s;' % (cdeclname, realname))
+        lines.append('%s = %s;' % (realname, tmpname))
+    return '{\n\t' + '\n\t'.join(lines) + '\n}'
 
 def stm_try_inevitable(funcgen, op):
     info = op.args[0].value
diff --git a/pypy/translator/stm/test/test_transform.py b/pypy/translator/stm/test/test_transform.py
--- a/pypy/translator/stm/test/test_transform.py
+++ b/pypy/translator/stm/test/test_transform.py
@@ -175,3 +175,21 @@
             return 0
         t, cbuilder = self.compile(simplefunc)
         cbuilder.cmdexec('')
+
+    def test_transaction_boundary_3(self):
+        def simplefunc(argv):
+            s1 = argv[0]
+            debug_print('STEP1:', len(s1))
+            rstm.transaction_boundary()
+            rstm.transaction_boundary()
+            rstm.transaction_boundary()
+            debug_print('STEP2:', len(s1))
+            return 0
+        t, cbuilder = self.compile(simplefunc)
+        data, err = cbuilder.cmdexec('', err=True)
+        lines = err.splitlines()
+        steps = [(line[:6], line[6:])
+                 for line in lines if line.startswith('STEP')]
+        steps = zip(*steps)
+        assert steps[0] == ('STEP1:', 'STEP2:')
+        assert steps[1][0] == steps[1][1]
diff --git a/pypy/translator/stm/transform.py b/pypy/translator/stm/transform.py
--- a/pypy/translator/stm/transform.py
+++ b/pypy/translator/stm/transform.py
@@ -1,4 +1,4 @@
-from pypy.objspace.flow.model import SpaceOperation, Constant
+from pypy.objspace.flow.model import SpaceOperation, Constant, Variable
 from pypy.objspace.flow.model import Block, Link, checkgraph
 from pypy.annotation import model as annmodel
 from pypy.translator.stm import _rffi_stm
@@ -41,7 +41,9 @@
         if block.operations == ():
             return
         newoperations = []
-        for op in block.operations:
+        self.current_block = block
+        for i, op in enumerate(block.operations):
+            self.current_op_index = i
             try:
                 meth = getattr(self, 'stt_' + op.opname)
             except AttributeError:
@@ -60,6 +62,7 @@
             else:
                 assert res is None
         block.operations = newoperations
+        self.current_block = None
 
     def transform_graph(self, graph):
         for block in graph.iterblocks():
@@ -128,7 +131,20 @@
 
     def stt_stm_transaction_boundary(self, newoperations, op):
         self.seen_transaction_boundary = True
-        return True
+        v_result = op.result
+        # record in op.args the list of variables that are alive across
+        # this call
+        block = self.current_block
+        vars = set()
+        for op in block.operations[:self.current_op_index:-1]:
+            vars.discard(op.result)
+            vars.update(op.args)
+        for link in block.exits:
+            vars.update(link.args)
+            vars.update(link.getextravars())
+        livevars = [v for v in vars if isinstance(v, Variable)]
+        newop = SpaceOperation('stm_transaction_boundary', livevars, v_result)
+        newoperations.append(newop)
 
     def stt_malloc(self, newoperations, op):
         flags = op.args[1].value


More information about the pypy-commit mailing list