[pypy-commit] pypy stm-thread-2: Mallocs.

arigo noreply at buildbot.pypy.org
Sun Sep 2 13:29:58 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-thread-2
Changeset: r57080:329b69f4e877
Date: 2012-09-02 13:29 +0200
http://bitbucket.org/pypy/pypy/changeset/329b69f4e877/

Log:	Mallocs.

diff --git a/pypy/translator/stm/test/test_transform2.py b/pypy/translator/stm/test/test_transform2.py
--- a/pypy/translator/stm/test/test_transform2.py
+++ b/pypy/translator/stm/test/test_transform2.py
@@ -77,6 +77,12 @@
         self.check_category(obj, 'W')
         return LLFrame.op_setfield(self, obj, fieldname, fieldvalue)
 
+    def op_malloc(self, obj, flags):
+        p = LLFrame.op_malloc(self, obj, flags)
+        ptr2 = _stmptr(p, 'W')
+        self.llinterpreter.tester.writemode.add(ptr2._obj)
+        return ptr2
+
 
 class TestTransform(BaseTestTransform):
 
@@ -137,3 +143,13 @@
         assert res == -81
         assert len(self.writemode) == 0
         assert self.barriers == ['G2R']
+
+    def test_malloc(self):
+        X = lltype.GcStruct('X', ('foo', lltype.Signed))
+        def f1(n):
+            p = lltype.malloc(X)
+            p.foo = n
+
+        self.interpret(f1, [4])
+        assert len(self.writemode) == 1
+        assert self.barriers == []
diff --git a/pypy/translator/stm/transform2.py b/pypy/translator/stm/transform2.py
--- a/pypy/translator/stm/transform2.py
+++ b/pypy/translator/stm/transform2.py
@@ -27,6 +27,11 @@
         log.info("Software Transactional Memory transformation applied")
 
 
+MALLOCS = set([
+    'malloc', 'malloc_varsize',
+    'malloc_nonmovable', 'malloc_nonmovable_varsize',
+    ])
+
 MORE_PRECISE_CATEGORIES = {
     'P': 'PGORLWN',
     'G': 'GN',
@@ -93,6 +98,8 @@
                         newoperations.append(newop)
                         renamings[op.args[0]] = w
                         category[w] = to
+                elif op.opname in MALLOCS:
+                    category[op.result] = 'W'
                 newop = SpaceOperation(op.opname,
                                        [renamings.get(v, v) for v in op.args],
                                        op.result)


More information about the pypy-commit mailing list