[pypy-commit] pypy stmgc-c7: Redo thread-local objects
arigo
noreply at buildbot.pypy.org
Tue Mar 11 19:06:14 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r69871:a59d46c8f5c6
Date: 2014-03-11 19:04 +0100
http://bitbucket.org/pypy/pypy/changeset/a59d46c8f5c6/
Log: Redo thread-local objects
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
@@ -433,6 +433,11 @@
'stm_leave_callback_call':LLOp(),
'stm_should_break_transaction': LLOp(sideeffects=False),
'stm_set_transaction_length': LLOp(),
+ 'stm_threadlocalref_get': LLOp(sideeffects=False),
+ 'stm_threadlocalref_set': LLOp(canmallocgc=True), # may allocate new array,
+ # see threadlocalref.py
+ 'stm_threadlocal_get': LLOp(sideeffects=False),
+ 'stm_threadlocal_set': LLOp(),
## 'stm_allocate_nonmovable_int_adr': LLOp(sideeffects=False, canmallocgc=True),
## 'stm_become_inevitable': LLOp(canmallocgc=True),
diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -160,6 +160,9 @@
sandbox=self.config.translation.sandbox)
self.db = db
+ if self.config.translation.stm:
+ stmtransformer.transform_after_gc()
+
# give the gc a chance to register interest in the start-up functions it
# need (we call this for its side-effects of db.get())
list(db.gcpolicy.gc_startup_code())
@@ -185,7 +188,7 @@
db.complete()
if self.config.translation.stm:
- stmtransformer.transform_after_gc()
+ stmtransformer.transform_after_complete()
self.collect_compilation_info(db)
return db
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
@@ -158,6 +158,15 @@
arg0 = funcgen.expr(op.args[0])
return 'pypy_stm_set_transaction_length(%s);' % (arg0,)
+def stm_threadlocal_get(funcgen, op):
+ result = funcgen.expr(op.result)
+ return '%s = (%s)stm_thread_local.thread_local_obj;' % (
+ result, cdecl(funcgen.lltypename(op.result), ''))
+
+def stm_threadlocal_set(funcgen, op):
+ arg0 = funcgen.expr(op.args[0])
+ return 'stm_thread_local.thread_local_obj = (object_t *)%s;' % (arg0,)
+
##def stm_initialize(funcgen, op):
## return '''stm_initialize();
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
@@ -1,4 +1,5 @@
from rpython.annotator import model as annmodel
+from rpython.rtyper import llannotation
from rpython.rtyper import annlowlevel
from rpython.rtyper.lltypesystem import lltype, rclass
from rpython.rtyper.lltypesystem.lloperation import llop
@@ -28,7 +29,10 @@
if not array:
return lltype.nullptr(rclass.OBJECTPTR.TO)
else:
- array = llop.stm_barrier(lltype.Ptr(ARRAY), 'A2R', array)
+ llop.stm_read(lltype.Void, array)
+ # ^^^ might not actually be needed, because this array is
+ # only ever seen from the current transaction; but better
+ # safe than sorry
return array[index]
#
def ll_threadlocalref_set(index, newvalue):
@@ -37,15 +41,18 @@
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
+ llop.stm_write(lltype.Void, array)
+ # ^^^ might not actually be needed, because this array is
+ # only ever seen from the current transaction; but better
+ # safe than sorry
+ # 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)
s_Int = annmodel.SomeInteger()
- s_Ptr = annmodel.SomePtr(rclass.OBJECTPTR)
+ s_Ptr = llannotation.SomePtr(rclass.OBJECTPTR)
c_getter_ptr = annhelper.constfunc(ll_threadlocalref_get,
[s_Int], s_Ptr)
c_setter_ptr = annhelper.constfunc(ll_threadlocalref_set,
diff --git a/rpython/translator/stm/transform.py b/rpython/translator/stm/transform.py
--- a/rpython/translator/stm/transform.py
+++ b/rpython/translator/stm/transform.py
@@ -21,8 +21,12 @@
def transform_after_gc(self):
self.start_log(2)
self.transform_threadlocalref()
+ self.print_logs(2)
+
+ def transform_after_complete(self):
+ self.start_log(3)
self.transform_read_barrier()
- self.print_logs(2)
+ self.print_logs(3)
def transform_read_barrier(self):
self.read_barrier_counts = 0
@@ -39,7 +43,6 @@
reorganize_around_jit_driver(self, graph)
def transform_threadlocalref(self):
- return #XXX XXX XXX
transform_tlref(self.translator)
def start_log(self, step):
More information about the pypy-commit
mailing list