[pypy-commit] pypy stm-gc: Tweak to make mt_global_turned_local and the tldict more similar.

arigo noreply at buildbot.pypy.org
Mon Apr 23 21:33:40 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r54697:ae1257934487
Date: 2012-04-23 21:32 +0200
http://bitbucket.org/pypy/pypy/changeset/ae1257934487/

Log:	Tweak to make mt_global_turned_local and the tldict more similar.

diff --git a/pypy/rpython/memory/gc/stmgc.py b/pypy/rpython/memory/gc/stmgc.py
--- a/pypy/rpython/memory/gc/stmgc.py
+++ b/pypy/rpython/memory/gc/stmgc.py
@@ -56,8 +56,9 @@
 #     in transactional mode only; see below.
 #
 #   - GCFLAG_VISITED: used during collections to flag objects found to be
-#     surviving.  Between collections, it must be set on LOCAL COPY objects
-#     and only on them.
+#     surviving.  Between collections, it must be set on the LOCAL COPY
+#     objects or the ones from 'mt_global_turned_local' (see below), and
+#     only on them.
 #
 #   - GCFLAG_HAS_SHADOW: set on nursery objects whose id() or identityhash()
 #     was taken.  Means that we already have a corresponding object allocated
diff --git a/pypy/rpython/memory/gc/stmtls.py b/pypy/rpython/memory/gc/stmtls.py
--- a/pypy/rpython/memory/gc/stmtls.py
+++ b/pypy/rpython/memory/gc/stmtls.py
@@ -113,7 +113,13 @@
         # We must also mark the following objects as GLOBAL again
         obj = self.mt_global_turned_local
         self.mt_global_turned_local = NULL
-        self._promote_list_to_globals(obj)
+        while obj:
+            hdr = self.gc.header(obj)
+            obj = hdr.version
+            ll_assert(hdr.tid & GCFLAG_GLOBAL == 0, "already GLOBAL [2]")
+            ll_assert(hdr.tid & GCFLAG_VISITED != 0, "missing VISITED [2]")
+            hdr.version = NULL
+            hdr.tid += GCFLAG_GLOBAL - GCFLAG_VISITED
         if not we_are_translated():
             del self.mt_global_turned_local   # don't use any more
 
@@ -232,7 +238,7 @@
         # don't have GCFLAG_VISITED.  As the newly allocated nursery
         # objects don't have it either, at the start of the next
         # collection, the only LOCAL objects that have it are the ones
-        # in 'copied_local_objects'.
+        # in 'mt_global_turned_local' or the C tldict with GCFLAG_WAS_COPIED.
         #
         # All live nursery objects are out, and the rest dies.  Fill
         # the whole nursery with zero and reset the current nursery pointer.
@@ -291,9 +297,11 @@
 
     def main_thread_writes_to_global_obj(self, obj):
         hdr = self.gc.header(obj)
-        ll_assert(hdr.tid & GCFLAG_WAS_COPIED == 0,
-                  "write in main thread: unexpected GCFLAG_WAS_COPIED")
-        hdr.tid &= ~GCFLAG_GLOBAL
+        ll_assert(hdr.tid & (GCFLAG_WAS_COPIED|GCFLAG_VISITED) == 0,
+                  "write in main thread: unexpected GCFLAG_WAS_COPIED"
+                  " or GCFLAG_VISITED")
+        # remove GCFLAG_GLOBAL, and add GCFLAG_VISITED
+        hdr.tid += (GCFLAG_VISITED - GCFLAG_GLOBAL)
         # add the object into this linked list
         hdr.version = self.mt_global_turned_local
         self.mt_global_turned_local = obj
@@ -307,13 +315,11 @@
         obj = self.sharedarea_tls.chained_list
         self.sharedarea_tls.chained_list = NULL
         #
-        self._promote_list_to_globals(obj)
-
-    def _promote_list_to_globals(self, obj):
         while obj:
             hdr = self.gc.header(obj)
             obj = hdr.version
-            ll_assert(not (hdr.tid & GCFLAG_GLOBAL), "already GLOBAL [1]")
+            ll_assert(hdr.tid & GCFLAG_GLOBAL == 0, "already GLOBAL [1]")
+            ll_assert(hdr.tid & GCFLAG_VISITED == 0, "unexpected VISITED [1]")
             hdr.version = NULL
             hdr.tid |= GCFLAG_GLOBAL
 
@@ -509,10 +515,10 @@
         while obj:
             hdr = self.gc.header(obj)
             ll_assert(hdr.tid & GCFLAG_GLOBAL == 0,
-                      "unexpected GLOBAL in mt_global_turned_local")
-            if hdr.tid & GCFLAG_VISITED == 0:
-                hdr.tid |= GCFLAG_VISITED
-                self.pending.append(obj)
+                      "unexpected GCFLAG_GLOBAL in mt_global_turned_local")
+            ll_assert(hdr.tid & GCFLAG_VISITED != 0,
+                      "missing GCFLAG_VISIBLE in mt_global_turned_local")
+            self.trace_and_drag_out_of_nursery(obj)
             obj = hdr.version
 
     def collect_flush_pending(self):


More information about the pypy-commit mailing list