[pypy-svn] r49682 - in pypy/branch/pypy-gc-traceopt: . jit/tl/test rpython/memory rpython/memory/gc rpython/memory/gctransform

arigo at codespeak.net arigo at codespeak.net
Wed Dec 12 21:52:13 CET 2007


Author: arigo
Date: Wed Dec 12 21:52:12 2007
New Revision: 49682

Added:
   pypy/branch/pypy-gc-traceopt/
      - copied from r49641, pypy/dist/pypy/
   pypy/branch/pypy-gc-traceopt/jit/tl/test/test_tl.py
      - copied unchanged from r49648, pypy/dist/pypy/jit/tl/test/test_tl.py
Modified:
   pypy/branch/pypy-gc-traceopt/rpython/memory/gc/base.py
   pypy/branch/pypy-gc-traceopt/rpython/memory/gc/generation.py
   pypy/branch/pypy-gc-traceopt/rpython/memory/gc/semispace.py
   pypy/branch/pypy-gc-traceopt/rpython/memory/gctransform/framework.py
   pypy/branch/pypy-gc-traceopt/rpython/memory/gctypelayout.py
   pypy/branch/pypy-gc-traceopt/rpython/memory/gcwrapper.py
Log:
In-progress, hackish enough to go to a branch:
try to speed up tracing for common object shapes.
So far this crashes on the llinterp and can only
run after translation to C.


Modified: pypy/branch/pypy-gc-traceopt/rpython/memory/gc/base.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc/base.py	(original)
+++ pypy/branch/pypy-gc-traceopt/rpython/memory/gc/base.py	Wed Dec 12 21:52:12 2007
@@ -30,6 +30,10 @@
     def setup(self):
         pass
 
+    def set_typeid_count(self, count):
+        from pypy.rpython.memory.gc import traceopt
+        traceopt.set_typeid_count(self, count)
+
     def statistics(self, index):
         return -1
 
@@ -106,6 +110,35 @@
     def x_become(self, target_addr, source_addr):
         raise RuntimeError("no support for x_become in the GC")
 
+    def trace(self, obj, callback):
+        from pypy.rpython.memory.gc import traceopt
+        typeid = self.get_type_id(obj)
+        if not traceopt.optimized_trace(self, obj, typeid, callback):
+            self._slow_trace(obj, typeid, callback)
+    trace._annspecialcase_ = 'specialize:arg(2)'
+
+    def _slow_trace(self, obj, typeid, callback):
+        offsets = self.offsets_to_gc_pointers(typeid)
+        i = 0
+        while i < len(offsets):
+            callback(self, obj + offsets[i])
+            i += 1
+        if self.is_varsize(typeid):
+            offset = self.varsize_offset_to_variable_part(
+                typeid)
+            length = (obj + self.varsize_offset_to_length(typeid)).signed[0]
+            offsets = self.varsize_offsets_to_gcpointers_in_var_part(typeid)
+            itemlength = self.varsize_item_sizes(typeid)
+            i = 0
+            while i < length:
+                item = obj + offset + itemlength * i
+                j = 0
+                while j < len(offsets):
+                    callback(self, item + offsets[j])
+                    j += 1
+                i += 1
+    _slow_trace._annspecialcase_ = 'specialize:arg(3)'
+
 
 class MovingGCBase(GCBase):
     moving_gc = True

Modified: pypy/branch/pypy-gc-traceopt/rpython/memory/gc/generation.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc/generation.py	(original)
+++ pypy/branch/pypy-gc-traceopt/rpython/memory/gc/generation.py	Wed Dec 12 21:52:12 2007
@@ -258,30 +258,11 @@
         young objects it references out of the nursery.
         """
         self.header(obj).tid |= GCFLAG_NO_YOUNG_PTRS
-        typeid = self.get_type_id(obj)
-        offsets = self.offsets_to_gc_pointers(typeid)
-        i = 0
-        while i < len(offsets):
-            pointer = obj + offsets[i]
-            if self.is_in_nursery(pointer.address[0]):
-                pointer.address[0] = self.copy(pointer.address[0])
-            i += 1
-        if self.is_varsize(typeid):
-            offset = self.varsize_offset_to_variable_part(
-                typeid)
-            length = (obj + self.varsize_offset_to_length(typeid)).signed[0]
-            offsets = self.varsize_offsets_to_gcpointers_in_var_part(typeid)
-            itemlength = self.varsize_item_sizes(typeid)
-            i = 0
-            while i < length:
-                item = obj + offset + itemlength * i
-                j = 0
-                while j < len(offsets):
-                    pointer = item + offsets[j]
-                    if self.is_in_nursery(pointer.address[0]):
-                        pointer.address[0] = self.copy(pointer.address[0])
-                    j += 1
-                i += 1
+        self.trace(obj, GenerationGC._drag_out_of_nursery)
+
+    def _drag_out_of_nursery(self, refaddr):
+        if self.is_in_nursery(refaddr.address[0]):
+            refaddr.address[0] = self.copy(refaddr.address[0])
 
     def invalidate_young_weakrefs(self):
         # walk over the list of objects that contain weakrefs and are in the

Modified: pypy/branch/pypy-gc-traceopt/rpython/memory/gc/semispace.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc/semispace.py	(original)
+++ pypy/branch/pypy-gc-traceopt/rpython/memory/gc/semispace.py	Wed Dec 12 21:52:12 2007
@@ -37,6 +37,7 @@
         self.AddressLinkedList = AddressLinkedList
 
     def setup(self):
+        MovingGCBase.setup(self)
         self.tospace = llarena.arena_malloc(self.space_size, True)
         ll_assert(bool(self.tospace), "couldn't allocate tospace")
         self.top_of_space = self.tospace + self.space_size
@@ -256,30 +257,11 @@
             return newobj
 
     def trace_and_copy(self, obj):
-        typeid = self.get_type_id(obj)
-        offsets = self.offsets_to_gc_pointers(typeid)
-        i = 0
-        while i < len(offsets):
-            pointer = obj + offsets[i]
-            if pointer.address[0] != NULL:
-                pointer.address[0] = self.copy(pointer.address[0])
-            i += 1
-        if self.is_varsize(typeid):
-            offset = self.varsize_offset_to_variable_part(
-                typeid)
-            length = (obj + self.varsize_offset_to_length(typeid)).signed[0]
-            offsets = self.varsize_offsets_to_gcpointers_in_var_part(typeid)
-            itemlength = self.varsize_item_sizes(typeid)
-            i = 0
-            while i < length:
-                item = obj + offset + itemlength * i
-                j = 0
-                while j < len(offsets):
-                    pointer = item + offsets[j]
-                    if pointer.address[0] != NULL:
-                        pointer.address[0] = self.copy(pointer.address[0])
-                    j += 1
-                i += 1
+        self.trace(obj, SemiSpaceGC._copy_ref)
+
+    def _copy_ref(self, refaddr):
+        if refaddr.address[0] != NULL:
+            refaddr.address[0] = self.copy(refaddr.address[0])
 
     def is_forwarded(self, obj):
         return self.header(obj).forw != NULL

Modified: pypy/branch/pypy-gc-traceopt/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/branch/pypy-gc-traceopt/rpython/memory/gctransform/framework.py	Wed Dec 12 21:52:12 2007
@@ -202,6 +202,7 @@
                 q_varsize_offset_to_length,
                 q_varsize_offsets_to_gcpointers_in_var_part,
                 q_weakpointer_offset)
+            gcdata.gc.set_typeid_count(len(gcdata.type_info_table))
 
         bk = self.translator.annotator.bookkeeper
 

Modified: pypy/branch/pypy-gc-traceopt/rpython/memory/gctypelayout.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctypelayout.py	(original)
+++ pypy/branch/pypy-gc-traceopt/rpython/memory/gctypelayout.py	Wed Dec 12 21:52:12 2007
@@ -136,6 +136,10 @@
                 self.q_varsize_offsets_to_gcpointers_in_var_part,
                 self.q_weakpointer_offset)
 
+    def count_typeids(self):
+        self.can_add_new_types = False
+        return len(self.type_info_list)
+
     def consider_constant(self, TYPE, value, gc):
         if value is not lltype.top_container(value):
             return

Modified: pypy/branch/pypy-gc-traceopt/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gcwrapper.py	(original)
+++ pypy/branch/pypy-gc-traceopt/rpython/memory/gcwrapper.py	Wed Dec 12 21:52:12 2007
@@ -27,6 +27,7 @@
 
         self.constantroots = layoutbuilder.addresses_of_static_ptrs
         self.constantrootsnongc = layoutbuilder.addresses_of_static_ptrs_in_nongc
+        self.gc.set_typeid_count(layoutbuilder.count_typeids())
 
     def get_roots_from_llinterp(self, with_static=True):
         sizeofaddr = llmemory.sizeof(llmemory.Address)



More information about the Pypy-commit mailing list