Author: Remi Meier <[email protected]>
Branch: stmgc-c4
Changeset: r67983:73cb960f51c7
Date: 2013-11-12 16:01 +0100
http://bitbucket.org/pypy/pypy/changeset/73cb960f51c7/

Log:    fix for threadlocal access. It was missing barriers and push_roots.

diff --git a/TODO b/TODO
--- a/TODO
+++ b/TODO
@@ -1,3 +1,9 @@
+------------------------------------------------------------
+
+should stm_thread_local_obj always be read & writeable? would
+a write-barrier in begin_transaction be too much for small
+transactions? should we handle it specially (undolog?)
+
 ------------------------------------------------------------
 
 looking at trace of fibo.tlc (targettlc.py), there are a lot
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
@@ -104,6 +104,7 @@
     gct_stm_perform_transaction                     = _gct_with_roots_pushed
     gct_stm_allocate_nonmovable_int_adr             = _gct_with_roots_pushed
     gct_stm_inspect_abort_info                      = _gct_with_roots_pushed
+    gct_stm_threadlocalref_set                      = _gct_with_roots_pushed
 
 
 class StmRootWalker(BaseRootWalker):
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,7 +440,8 @@
     'stm_weakref_allocate':   LLOp(sideeffects=False, canmallocgc=True),
     
     'stm_threadlocalref_get': LLOp(sideeffects=False),
-    'stm_threadlocalref_set': LLOp(),
+    'stm_threadlocalref_set': LLOp(canmallocgc=True), # may allocate new array,
+                                                      # see threadlocalref.py
     'stm_threadlocal_get':    LLOp(sideeffects=False),
     'stm_threadlocal_set':    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
@@ -53,7 +53,14 @@
 
 def stm_barrier(funcgen, op):
     category_change = op.args[0].value
-    frm, middle, to = category_change
+    # XXX: how to unify the stm_barrier llop generation in
+    #      writebarrier.py and threadlocalref.py?
+    if isinstance(category_change, str):
+        frm, middle, to = category_change
+    else: # rstr
+        frm, middle, to = (category_change.chars[0],
+                           category_change.chars[1],
+                           category_change.chars[2])
     assert middle == '2'
     assert frm < to
     if to == 'W':
diff --git a/rpython/translator/stm/threadlocalref.py 
b/rpython/translator/stm/threadlocalref.py
--- a/rpython/translator/stm/threadlocalref.py
+++ b/rpython/translator/stm/threadlocalref.py
@@ -28,13 +28,19 @@
         if not array:
             return lltype.nullptr(rclass.OBJECTPTR.TO)
         else:
+            array = llop.stm_barrier(lltype.Ptr(ARRAY), 'A2R', array)
             return array[index]
     #
     def ll_threadlocalref_set(index, newvalue):
         array = llop.stm_threadlocal_get(lltype.Ptr(ARRAY))
         if not array:
-            array = lltype.malloc(ARRAY, total)
+            array = lltype.malloc(ARRAY, total) # llop may allocate!
             llop.stm_threadlocal_set(lltype.Void, array)
+        else:
+            array = llop.stm_barrier(lltype.Ptr(ARRAY), 'A2W', array)
+            # invalidating other barriers after an llop.threadlocalref_set
+            # is not necessary since no other variable should contain
+            # a reference to stm_threadlocal_obj
         array[index] = newvalue
     #
     annhelper = annlowlevel.MixLevelHelperAnnotator(t.rtyper)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to