[pypy-commit] pypy stmgc-c7: fixes

arigo noreply at buildbot.pypy.org
Sat Feb 21 09:34:15 CET 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r76018:79bb7fe37c41
Date: 2015-02-20 19:16 +0100
http://bitbucket.org/pypy/pypy/changeset/79bb7fe37c41/

Log:	fixes

diff --git a/rpython/rlib/rthread.py b/rpython/rlib/rthread.py
--- a/rpython/rlib/rthread.py
+++ b/rpython/rlib/rthread.py
@@ -276,6 +276,13 @@
 # KEEP THE REFERENCE ALIVE, THE GC DOES NOT FOLLOW THEM SO FAR!
 # We use _make_sure_does_not_move() to make sure the pointer will not move.
 
+def _field2structptr(FIELDTYPE, cache={}):
+    if FIELDTYPE not in cache:
+        cache[FIELDTYPE] = lltype.Ptr(lltype.Struct(
+            'pypythread%d' % len(cache), ('c_value', FIELDTYPE),
+            hints={'stm_dont_track_raw_accesses': True}))
+    return cache[FIELDTYPE]
+
 
 class ThreadLocalField(object):
     def __init__(self, FIELDTYPE, fieldname, loop_invariant=False):
@@ -290,6 +297,9 @@
         offset.loop_invariant = loop_invariant
         self.offset = offset
 
+        # for STM only
+        PSTRUCTTYPE = _field2structptr(FIELDTYPE)
+
         def getraw():
             if we_are_translated():
                 _threadlocalref_seeme(self)
@@ -302,7 +312,11 @@
             if we_are_translated():
                 _threadlocalref_seeme(self)
                 addr = llop.threadlocalref_addr(llmemory.Address)
-                return llop.raw_load(FIELDTYPE, addr, offset)
+                if rgc.stm_is_enabled():
+                    p = llmemory.cast_adr_to_ptr(addr + offset, PSTRUCTTYPE)
+                    return p.c_value
+                else:
+                    return llop.raw_load(FIELDTYPE, addr, offset)
             else:
                 return getattr(self.local, 'rawvalue', zero)
 
@@ -311,7 +325,11 @@
             if we_are_translated():
                 _threadlocalref_seeme(self)
                 addr = llop.threadlocalref_addr(llmemory.Address)
-                llop.raw_store(lltype.Void, addr, offset, value)
+                if rgc.stm_is_enabled():
+                    p = llmemory.cast_adr_to_ptr(addr + offset, PSTRUCTTYPE)
+                    p.c_value = value
+                else:
+                    llop.raw_store(lltype.Void, addr, offset, value)
             else:
                 self.local.rawvalue = value
 
diff --git a/rpython/translator/stm/inevitable.py b/rpython/translator/stm/inevitable.py
--- a/rpython/translator/stm/inevitable.py
+++ b/rpython/translator/stm/inevitable.py
@@ -21,7 +21,7 @@
     'weakref_create', 'weakref_deref',
     'jit_assembler_call', 'gc_writebarrier',
     'shrink_array',
-    'threadlocalref_get', 'threadlocalref_set',
+    'threadlocalref_addr', 'threadlocalref_get',
     ])
 ALWAYS_ALLOW_OPERATIONS |= set(lloperation.enum_tryfold_ops())
 
diff --git a/rpython/translator/stm/test/test_inevitable.py b/rpython/translator/stm/test/test_inevitable.py
--- a/rpython/translator/stm/test/test_inevitable.py
+++ b/rpython/translator/stm/test/test_inevitable.py
@@ -287,14 +287,19 @@
         assert res is None
 
     def test_threadlocal(self):
-        from rpython.rlib.rthread import ThreadLocalReference
-        opaque_id = lltype.opaqueptr(ThreadLocalReference.OPAQUEID, "foobar")
-        X = lltype.GcStruct('X', ('foo', lltype.Signed))
+        from rpython.rlib.rthread import ThreadLocalField
+        from rpython.rlib.rthread import _threadlocalref_seeme
+        from rpython.rlib.rthread import _field2structptr
+        foobar = ThreadLocalField(lltype.Signed, 'foobar')
+        offset = foobar.offset
+        PSTRUCTTYPE = _field2structptr(lltype.Signed)
         def f1():
-            x = lltype.malloc(X)
-            llop.threadlocalref_set(lltype.Void, opaque_id, x)
-            y = llop.threadlocalref_get(lltype.Ptr(X), opaque_id)
-            return x == y
+            addr = llop.threadlocalref_addr(llmemory.Address)
+            # ...The rest of this test does not run on the llinterp so far...
+            #p = llmemory.cast_adr_to_ptr(addr + offset, PSTRUCTTYPE)
+            #p.c_value = 42
+            #x = llop.threadlocalref_get(lltype.Signed, offset)
+            #assert x == 42
 
         res = self.interpret_inevitable(f1, [])
         assert res is None


More information about the pypy-commit mailing list