[pypy-svn] r69891 - in pypy/branch/listcopyop/pypy/rpython/memory: . gc

fijal at codespeak.net fijal at codespeak.net
Fri Dec 4 14:05:31 CET 2009


Author: fijal
Date: Fri Dec  4 14:05:30 2009
New Revision: 69891

Modified:
   pypy/branch/listcopyop/pypy/rpython/memory/gc/base.py
   pypy/branch/listcopyop/pypy/rpython/memory/gctypelayout.py
Log:
Performance hack (an attempt at least) - store info whether object can have
gc pointers at all, otherwise don't trace it


Modified: pypy/branch/listcopyop/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/gc/base.py	(original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/gc/base.py	Fri Dec  4 14:05:30 2009
@@ -46,6 +46,7 @@
     DEBUG = False
 
     def set_query_functions(self, is_varsize, has_gcptr_in_varsize,
+                            has_gcptr,
                             is_gcarrayofgcptr,
                             getfinalizer,
                             offsets_to_gc_pointers,
@@ -58,6 +59,7 @@
         self.getfinalizer = getfinalizer
         self.is_varsize = is_varsize
         self.has_gcptr_in_varsize = has_gcptr_in_varsize
+        self.has_gcptr = has_gcptr
         self.is_gcarrayofgcptr = is_gcarrayofgcptr
         self.offsets_to_gc_pointers = offsets_to_gc_pointers
         self.fixed_size = fixed_size
@@ -160,6 +162,8 @@
         Typically, 'callback' is a bound method and 'arg' can be None.
         """
         typeid = self.get_type_id(obj)
+        if not self.has_gcptr(typeid):
+            return
         if self.is_gcarrayofgcptr(typeid):
             # a performance shortcut for GcArray(gcptr)
             length = (obj + llmemory.gcarrayofptr_lengthoffset).signed[0]

Modified: pypy/branch/listcopyop/pypy/rpython/memory/gctypelayout.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/gctypelayout.py	(original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/gctypelayout.py	Fri Dec  4 14:05:30 2009
@@ -62,6 +62,10 @@
         infobits = self.get(typeid).infobits
         return (infobits & T_HAS_GCPTR_IN_VARSIZE) != 0
 
+    def q_has_gcptrs(self, typeid):
+        infobits = self.get(typeid).infobits
+        return (infobits & T_HAS_GCPTR) != 0        
+
     def q_is_gcarrayofgcptr(self, typeid):
         infobits = self.get(typeid).infobits
         return (infobits & T_IS_GCARRAY_OF_GCPTR) != 0
@@ -101,6 +105,7 @@
         gc.set_query_functions(
             self.q_is_varsize,
             self.q_has_gcptr_in_varsize,
+            self.q_has_gcptrs,
             self.q_is_gcarrayofgcptr,
             self.q_finalizer,
             self.q_offsets_to_gc_pointers,
@@ -117,8 +122,9 @@
 T_MEMBER_INDEX         = 0xffff
 T_IS_VARSIZE           = 0x10000
 T_HAS_GCPTR_IN_VARSIZE = 0x20000
-T_IS_GCARRAY_OF_GCPTR  = 0x40000
-T_IS_WEAKREF           = 0x80000
+T_HAS_GCPTR            = 0x40000
+T_IS_GCARRAY_OF_GCPTR  = 0x80000
+T_IS_WEAKREF           = 0x100000
 
 def _check_typeid(typeid):
     ll_assert(llop.is_group_member_nonzero(lltype.Bool, typeid),
@@ -131,6 +137,7 @@
     infobits = index
     info.ofstoptrs = builder.offsets2table(offsets, TYPE)
     info.finalizer = builder.make_finalizer_funcptr_for_type(TYPE)
+    arroffsets = None
     if not TYPE._is_varsize():
         info.fixedsize = llarena.round_up_for_allocation(
             llmemory.sizeof(TYPE), builder.GCClass.object_minimal_size)
@@ -157,15 +164,18 @@
             varinfo.ofstovar = llmemory.itemoffsetof(TYPE, 0)
         assert isinstance(ARRAY, lltype.Array)
         if ARRAY.OF != lltype.Void:
-            offsets = offsets_to_gc_pointers(ARRAY.OF)
+            arroffsets = offsets_to_gc_pointers(ARRAY.OF)
         else:
-            offsets = ()
-        if len(offsets) > 0:
+            arroffsets = ()
+        if len(arroffsets) > 0:
             infobits |= T_HAS_GCPTR_IN_VARSIZE
-        varinfo.varofstoptrs = builder.offsets2table(offsets, ARRAY.OF)
+        varinfo.varofstoptrs = builder.offsets2table(arroffsets, ARRAY.OF)
         varinfo.varitemsize = llmemory.sizeof(ARRAY.OF)
     if TYPE == WEAKREF:
         infobits |= T_IS_WEAKREF
+    if offsets or arroffsets:
+        infobits |= T_HAS_GCPTR
+
     info.infobits = infobits
 
 # ____________________________________________________________



More information about the Pypy-commit mailing list