Author: Remi Meier <[email protected]>
Branch: stmgc-c8-gcc
Changeset: r79655:c657942f1620
Date: 2015-09-16 11:26 +0200
http://bitbucket.org/pypy/pypy/changeset/c657942f1620/

Log:    add rstm.allocate_noconflict()

diff --git a/rpython/memory/gctransform/stmframework.py 
b/rpython/memory/gctransform/stmframework.py
--- a/rpython/memory/gctransform/stmframework.py
+++ b/rpython/memory/gctransform/stmframework.py
@@ -234,6 +234,7 @@
     gct_stm_queue_get                = _gct_with_roots_pushed
     gct_stm_queue_put                = _gct_with_roots_pushed
     gct_stm_queue_join               = _gct_with_roots_pushed
+    gct_stm_allocate_preexisting     = _gct_with_roots_pushed
 
 
     def gct_stm_malloc_nonmovable(self, hop):
@@ -253,6 +254,26 @@
         self.pop_roots(hop, livevars)
         hop.genop("cast_opaque_ptr", [v_result], resultvar=op.result)
 
+    def gct_stm_malloc_noconflict(self, hop):
+        op = hop.spaceop
+        PTRTYPE = op.result.concretetype
+        TYPE = PTRTYPE.TO
+        type_id = self.get_type_id(TYPE)
+
+        c_type_id = rmodel.inputconst(TYPE_ID, type_id)
+        info = self.layoutbuilder.get_info(type_id)
+        c_size = rmodel.inputconst(lltype.Signed, info.fixedsize)
+
+        livevars = self.push_roots(hop)
+        v_result = hop.genop("stm_allocate_noconflict",
+                             [c_size, c_type_id],
+                             resulttype=llmemory.GCREF)
+        self.pop_roots(hop, livevars)
+        hop.genop("cast_opaque_ptr", [v_result], resultvar=op.result)
+
+
+
+
 
 
 
diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py
--- a/rpython/rlib/rstm.py
+++ b/rpython/rlib/rstm.py
@@ -190,6 +190,13 @@
     return llop.stm_allocate_preexisting(TP, size, p)
 
 @specialize.ll()
+def allocate_noconflict(GCTYPE):
+    """Return a new instance of GCTYPE that never generates conflicts when
+    reading or writing to it. However, modifications may get lost
+    and are not guaranteed to propagate."""
+    return llop.stm_malloc_noconflict(lltype.Ptr(GCTYPE))
+
[email protected]()
 def allocate_nonmovable(GCTYPE):
     return llop.stm_malloc_nonmovable(lltype.Ptr(GCTYPE))
 
diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py
--- a/rpython/rtyper/llinterp.py
+++ b/rpython/rtyper/llinterp.py
@@ -992,6 +992,7 @@
     op_stm_allocate_finalizer = _stm_not_implemented
     op_stm_allocate_nonmovable = _stm_not_implemented
     op_stm_allocate_preexisting = _stm_not_implemented
+    op_stm_malloc_noconflict = _stm_not_implemented
     op_stm_malloc_nonmovable = _stm_not_implemented
     op_stm_can_move = _stm_not_implemented
     op_stm_read = _stm_not_implemented
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
@@ -423,6 +423,8 @@
     'stm_allocate_finalizer': LLOp(sideeffects=False, canmallocgc=True),
     'stm_allocate_f_light':   LLOp(sideeffects=False, canmallocgc=True),
     'stm_allocate_preexisting':LLOp(sideeffects=False, canmallocgc=True),
+    'stm_allocate_noconflict':LLOp(sideeffects=False, canmallocgc=True),
+    'stm_malloc_noconflict':  LLOp(sideeffects=False, canmallocgc=True),
     'stm_allocate_nonmovable':LLOp(sideeffects=False, canmallocgc=True),
     'stm_malloc_nonmovable':  LLOp(sideeffects=False, canmallocgc=True),
     'stm_set_into_obj':       LLOp(),
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
@@ -129,6 +129,17 @@
             (result, arg_size, arg_size) +
             '((rpyobj_t *)%s)->tid = %s;' % (result, arg_type_id))
 
+def stm_allocate_noconflict(funcgen, op):
+    arg_size    = funcgen.expr(op.args[0])  # <- could be smaller than 16 here
+    arg_type_id = funcgen.expr(op.args[1])
+    result      = funcgen.expr(op.result)
+    # XXX NULL returns?
+    return ('%s = (rpygcchar_t *)stm_allocate_noconflict(%s >= 16 ? %s : 16); 
' %
+            (result, arg_size, arg_size) +
+            'pypy_stm_memclearinit((object_t*)%s, 0, %s >= 16 ? %s : 16);' %
+            (result, arg_size, arg_size) +
+            '((rpyobj_t *)%s)->tid = %s;' % (result, arg_type_id))
+
 def stm_set_into_obj(funcgen, op):
     assert op.args[0].concretetype == llmemory.GCREF
     arg_obj = funcgen.expr(op.args[0])
diff --git a/rpython/translator/stm/readbarrier.py 
b/rpython/translator/stm/readbarrier.py
--- a/rpython/translator/stm/readbarrier.py
+++ b/rpython/translator/stm/readbarrier.py
@@ -7,6 +7,7 @@
 MALLOCS = set([
     'malloc', 'malloc_varsize',
     'malloc_nonmovable', 'malloc_nonmovable_varsize',
+    'malloc_noconflict', 'malloc_noconflict_varsize',
     ])
 READ_OPS = set(['getfield', 'getarrayitem', 'getinteriorfield', 'raw_load'])
 
diff --git a/rpython/translator/stm/test/test_ztranslated.py 
b/rpython/translator/stm/test/test_ztranslated.py
--- a/rpython/translator/stm/test/test_ztranslated.py
+++ b/rpython/translator/stm/test/test_ztranslated.py
@@ -592,7 +592,6 @@
             assert count == 1
             assert intmask(array[0].index) == -1234
             assert cast_gcref_to_instance(X, array[0].object) is x1
-            h.freelist(array)
             #
             print "ok!"
             return 0
@@ -709,3 +708,18 @@
         t, cbuilder = self.compile(main)
         data = cbuilder.cmdexec('')
         assert 'ok!\n' in data
+
+    def test_allocate_noconflict(self):
+        S = lltype.GcStruct('S', ('n', lltype.Signed))
+
+        def main(argv):
+            s1 = rstm.allocate_noconflict(S)
+            s1.n = 42
+            assert s1.n == 42
+            #
+            print "ok!"
+            return 0
+
+        t, cbuilder = self.compile(main)
+        data = cbuilder.cmdexec('')
+        assert 'ok!\n' in data
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to