[pypy-svn] r65527 - in pypy/branch/pyjitpl5-experiments/pypy/rpython/memory: gc gctransform

arigo at codespeak.net arigo at codespeak.net
Mon Jun 1 17:56:48 CEST 2009


Author: arigo
Date: Mon Jun  1 17:56:46 2009
New Revision: 65527

Modified:
   pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gc/generation.py
   pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gctransform/framework.py
Log:
Turn 'remember_young_pointer' into a function attached to 'self'
instead of a regular method.  For the reasoning see the comment.


Modified: pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gc/generation.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gc/generation.py	Mon Jun  1 17:56:46 2009
@@ -61,6 +61,7 @@
         # GCFLAG_NO_YOUNG_PTRS bit is not set.
         self.young_objects_with_weakrefs = self.AddressStack()
         self.reset_nursery()
+        self._setup_wb()
 
         # compute the constant lower bounds for the attributes
         # largest_young_fixedsize and largest_young_var_basesize.
@@ -408,23 +409,30 @@
             self.objects_with_weakrefs.append(obj)
 
     # for the JIT: a minimal description of the write_barrier() method
+    # (the JIT assumes it is of the shape
+    #  "if newvalue.int0 & JIT_WB_IF_FLAG: remember_young_pointer()")
     JIT_WB_IF_FLAG = GCFLAG_NO_YOUNG_PTRS
-    JIT_WB_THEN_CALL = 'remember_young_pointer'
 
     def write_barrier(self, newvalue, addr_struct):
         if self.header(addr_struct).tid & GCFLAG_NO_YOUNG_PTRS:
             self.remember_young_pointer(addr_struct, newvalue)
 
-    def remember_young_pointer(self, addr_struct, addr):
-        ll_assert(not self.is_in_nursery(addr_struct),
-                     "nursery object with GCFLAG_NO_YOUNG_PTRS")
-        if self.is_in_nursery(addr):
-            self.old_objects_pointing_to_young.append(addr_struct)
-            self.header(addr_struct).tid &= ~GCFLAG_NO_YOUNG_PTRS
-        elif addr == NULL:
-            return
-        self.write_into_last_generation_obj(addr_struct, addr)
-    remember_young_pointer._dont_inline_ = True
+    def _setup_wb(self):
+        # The purpose of attaching remember_young_pointer to the instance
+        # instead of keeping it as a regular method is to help the JIT call it.
+        # Additionally, it makes the code in write_barrier() marginally smaller
+        # (which is important because it is inlined *everywhere*).
+        def remember_young_pointer(addr_struct, addr):
+            ll_assert(not self.is_in_nursery(addr_struct),
+                         "nursery object with GCFLAG_NO_YOUNG_PTRS")
+            if self.is_in_nursery(addr):
+                self.old_objects_pointing_to_young.append(addr_struct)
+                self.header(addr_struct).tid &= ~GCFLAG_NO_YOUNG_PTRS
+            elif addr == NULL:
+                return
+            self.write_into_last_generation_obj(addr_struct, addr)
+        remember_young_pointer._dont_inline_ = True
+        self.remember_young_pointer = remember_young_pointer
 
     def write_into_last_generation_obj(self, addr_struct, addr):
         objhdr = self.header(addr_struct)

Modified: pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gctransform/framework.py	Mon Jun  1 17:56:46 2009
@@ -19,7 +19,7 @@
 from pypy.rpython.memory.gctransform.log import log
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.rpython.lltypesystem.lloperation import llop, LL_OPERATIONS
-import sys
+import sys, types
 
 
 class CollectAnalyzer(graphanalyze.GraphAnalyzer):
@@ -340,10 +340,11 @@
                                             annmodel.SomeAddress()],
                                            annmodel.s_None,
                                            inline=True)
-            func = getattr(GCClass, GCClass.JIT_WB_THEN_CALL).im_func
+            func = getattr(gcdata.gc, GCClass.JIT_WB_THEN_CALL)
+            assert isinstance(func, types.FunctionType)   # not a bound method,
+                                                          # but a real function
             self.write_barrier_failing_case_ptr = getfn(func,
-                                           [s_gc,
-                                            annmodel.SomeAddress(),
+                                           [annmodel.SomeAddress(),
                                             annmodel.SomeAddress()],
                                            annmodel.s_None)
         else:



More information about the Pypy-commit mailing list