[pypy-svn] r47419 - pypy/dist/pypy/rpython/memory

arigo at codespeak.net arigo at codespeak.net
Sat Oct 13 11:22:28 CEST 2007


Author: arigo
Date: Sat Oct 13 11:22:26 2007
New Revision: 47419

Modified:
   pypy/dist/pypy/rpython/memory/gctypelayout.py
Log:
Don't need to record the location of GC pointers inside
immutable prebuilt structures, because these cannot change
later to point to GC heap objects.


Modified: pypy/dist/pypy/rpython/memory/gctypelayout.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctypelayout.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctypelayout.py	Sat Oct 13 11:22:26 2007
@@ -146,10 +146,12 @@
             adr = llmemory.cast_ptr_to_adr(hdr)
             gc.init_gc_object_immortal(adr, typeid)
 
-        # XXX should skip the gc pointers inside immutable structures, because
-        # they cannot be dynamically modified to point to GC heap objects
+        # The following collects the addresses of all the fields that have
+        # a GC Pointer type, inside the current prebuilt object.  All such
+        # fields are potential roots: unless the structure is immutable,
+        # they could be changed later to point to GC heap objects.
         adr = llmemory.cast_ptr_to_adr(value._as_ptr())
-        for a in gc_pointers_inside(value, adr):
+        for a in mutable_gc_pointers_inside(value, adr):
             self.addresses_of_static_ptrs.append(a)
 
 # ____________________________________________________________
@@ -188,22 +190,28 @@
         return llmemory.offsetof(WEAKREF, "weakptr")
     return -1
 
-def gc_pointers_inside(v, adr):
+def mutable_gc_pointers_inside(v, adr):
     t = lltype.typeOf(v)
     if isinstance(t, lltype.Struct):
+        if t._hints.get('immutable'):
+            return
         for n, t2 in t._flds.iteritems():
             if isinstance(t2, lltype.Ptr) and t2.TO._gckind == 'gc':
                 yield adr + llmemory.offsetof(t, n)
             elif isinstance(t2, (lltype.Array, lltype.Struct)):
-                for a in gc_pointers_inside(getattr(v, n), adr + llmemory.offsetof(t, n)):
+                for a in mutable_gc_pointers_inside(getattr(v, n),
+                                                adr + llmemory.offsetof(t, n)):
                     yield a
     elif isinstance(t, lltype.Array):
+        if t._hints.get('immutable'):
+            return
         if isinstance(t.OF, lltype.Ptr) and t.OF.TO._gckind == 'gc':
             for i in range(len(v.items)):
                 yield adr + llmemory.itemoffsetof(t, i)
         elif isinstance(t.OF, lltype.Struct):
             for i in range(len(v.items)):
-                for a in gc_pointers_inside(v.items[i], adr + llmemory.itemoffsetof(t, i)):
+                for a in mutable_gc_pointers_inside(v.items[i],
+                                            adr + llmemory.itemoffsetof(t, i)):
                     yield a
 
 ########## weakrefs ##########



More information about the Pypy-commit mailing list