[pypy-svn] r65021 - in pypy/branch/tagged-pointers-framework/pypy/rpython/memory: . gc gctransform

cfbolz at codespeak.net cfbolz at codespeak.net
Mon May 4 13:59:30 CEST 2009


Author: cfbolz
Date: Mon May  4 13:59:29 2009
New Revision: 65021

Modified:
   pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/base.py
   pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/generation.py
   pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/markcompact.py
   pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/marksweep.py
   pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/semispace.py
   pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gctransform/framework.py
   pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gcwrapper.py
Log:
Refactor things so that there is only one place where it is checked whether a
pointed-to object is NULL. This place can later be used for checking tagged
pointers as well.


Modified: pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/base.py	(original)
+++ pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/base.py	Mon May  4 13:59:29 2009
@@ -148,14 +148,17 @@
             length = (obj + llmemory.gcarrayofptr_lengthoffset).signed[0]
             item = obj + llmemory.gcarrayofptr_itemsoffset
             while length > 0:
-                callback(item, arg)
+                if self.points_to_valid_gc_object(item):
+                    callback(item, arg)
                 item += llmemory.gcarrayofptr_singleitemoffset
                 length -= 1
             return
         offsets = self.offsets_to_gc_pointers(typeid)
         i = 0
         while i < len(offsets):
-            callback(obj + offsets[i], arg)
+            item = obj + offsets[i]
+            if self.points_to_valid_gc_object(item):
+                callback(item, arg)
             i += 1
         if self.has_gcptr_in_varsize(typeid):
             item = obj + self.varsize_offset_to_variable_part(typeid)
@@ -165,12 +168,18 @@
             while length > 0:
                 j = 0
                 while j < len(offsets):
-                    callback(item + offsets[j], arg)
+                    itemobj = item + offsets[j]
+                    if self.points_to_valid_gc_object(itemobj):
+                        callback(itemobj, arg)
                     j += 1
                 item += itemlength
                 length -= 1
     trace._annspecialcase_ = 'specialize:arg(2)'
 
+    def points_to_valid_gc_object(self, addr):
+        pointsto = addr.address[0]
+        return pointsto != NULL
+
     def debug_check_consistency(self):
         """To use after a collection.  If self.DEBUG is set, this
         enumerates all roots and traces all objects to check if we didn't
@@ -205,8 +214,8 @@
         self._debug_record(obj)
     def _debug_callback2(self, pointer, ignored):
         obj = pointer.address[0]
-        if obj:
-            self._debug_record(obj)
+        ll_assert(bool(obj), "NULL address from self.trace()")
+        self._debug_record(obj)
 
     def debug_check_object(self, obj):
         pass

Modified: pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/generation.py	(original)
+++ pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/generation.py	Mon May  4 13:59:29 2009
@@ -295,10 +295,9 @@
 
     def _trace_external_obj(self, pointer, obj):
         addr = pointer.address[0]
-        if addr != NULL:
-            newaddr = self.copy(addr)
-            pointer.address[0] = newaddr
-            self.write_into_last_generation_obj(obj, newaddr)
+        newaddr = self.copy(addr)
+        pointer.address[0] = newaddr
+        self.write_into_last_generation_obj(obj, newaddr)
 
     # ____________________________________________________________
     # Implementation of nursery-only collections

Modified: pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/markcompact.py
==============================================================================
--- pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/markcompact.py	(original)
+++ pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/markcompact.py	Mon May  4 13:59:29 2009
@@ -342,11 +342,10 @@
 
     def _mark_obj(self, pointer, ignored):
         obj = pointer.address[0]
-        if obj != NULL:
-            if self.marked(obj):
-                return
-            self.mark(obj)
-            self.to_see.append(obj)
+        if self.marked(obj):
+            return
+        self.mark(obj)
+        self.to_see.append(obj)
 
     def _mark_root_recursively(self, root):
         self.mark(root.address[0])

Modified: pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/marksweep.py
==============================================================================
--- pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/marksweep.py	(original)
+++ pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/marksweep.py	Mon May  4 13:59:29 2009
@@ -499,8 +499,7 @@
 
     def _add_reachable(pointer, objects):
         obj = pointer.address[0]
-        if obj:
-            objects.append(obj)
+        objects.append(obj)
     _add_reachable = staticmethod(_add_reachable)
 
     def statistics(self, index):

Modified: pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/semispace.py
==============================================================================
--- pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/semispace.py	(original)
+++ pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gc/semispace.py	Mon May  4 13:59:29 2009
@@ -331,8 +331,7 @@
         self.trace(obj, self._trace_copy, None)
 
     def _trace_copy(self, pointer, ignored):
-        if pointer.address[0] != NULL:
-            pointer.address[0] = self.copy(pointer.address[0])
+        pointer.address[0] = self.copy(pointer.address[0])
 
     def surviving(self, obj):
         # To use during a collection.  Check if the object is currently
@@ -451,8 +450,7 @@
         return scan
 
     def _append_if_nonnull(pointer, stack):
-        if pointer.address[0] != NULL:
-            stack.append(pointer.address[0])
+        stack.append(pointer.address[0])
     _append_if_nonnull = staticmethod(_append_if_nonnull)
 
     def _finalization_state(self, obj):

Modified: pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gctransform/framework.py	Mon May  4 13:59:29 2009
@@ -909,7 +909,7 @@
         addr = gcdata.root_stack_base
         end = gcdata.root_stack_top
         while addr != end:
-            if addr.address[0] != llmemory.NULL:
+            if self.gc.points_to_valid_gc_object(addr):
                 collect_stack_root(gc, addr)
             addr += sizeofaddr
         if self.collect_stacks_from_other_threads is not None:

Modified: pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gcwrapper.py	(original)
+++ pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gcwrapper.py	Mon May  4 13:59:29 2009
@@ -141,15 +141,15 @@
         gc = gcheap.gc
         if collect_static_in_prebuilt_gc:
             for addrofaddr in gcheap.constantroots:
-                if addrofaddr.address[0]:
+                if self.gcheap.gc.points_to_valid_gc_object(addrofaddr):
                     collect_static_in_prebuilt_gc(gc, addrofaddr)
         if collect_static_in_prebuilt_nongc:
             for addrofaddr in gcheap.constantrootsnongc:
-                if addrofaddr.address[0]:
+                if self.gcheap.gc.points_to_valid_gc_object(addrofaddr):
                     collect_static_in_prebuilt_nongc(gc, addrofaddr)
         if collect_stack_root:
             for addrofaddr in gcheap.llinterp.find_roots():
-                if addrofaddr.address[0]:
+                if self.gcheap.gc.points_to_valid_gc_object(addrofaddr):
                     collect_stack_root(gc, addrofaddr)
 
     def _walk_prebuilt_gc(self, collect):    # debugging only!  not RPython



More information about the Pypy-commit mailing list