[pypy-svn] r49886 - in pypy/dist/pypy/rpython/memory: gc gctransform

arigo at codespeak.net arigo at codespeak.net
Tue Dec 18 14:22:35 CET 2007


Author: arigo
Date: Tue Dec 18 14:22:29 2007
New Revision: 49886

Modified:
   pypy/dist/pypy/rpython/memory/gc/generation.py
   pypy/dist/pypy/rpython/memory/gc/semispace.py
   pypy/dist/pypy/rpython/memory/gctransform/framework.py
Log:
It seems useful to inline the common calls to malloc_varsize() too.


Modified: pypy/dist/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc/generation.py	(original)
+++ pypy/dist/pypy/rpython/memory/gc/generation.py	Tue Dec 18 14:22:29 2007
@@ -26,6 +26,7 @@
     list, chained to each other via their 'forw' header field.
     """
     inline_simple_malloc = True
+    inline_simple_malloc_varsize = True
     needs_write_barrier = True
     prebuilt_gc_objects_are_static_roots = False
 

Modified: pypy/dist/pypy/rpython/memory/gc/semispace.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc/semispace.py	(original)
+++ pypy/dist/pypy/rpython/memory/gc/semispace.py	Tue Dec 18 14:22:29 2007
@@ -21,6 +21,7 @@
 class SemiSpaceGC(MovingGCBase):
     _alloc_flavor_ = "raw"
     inline_simple_malloc = True
+    inline_simple_malloc_varsize = True
     needs_zero_gc_pointers = False
 
     HDR = lltype.Struct('header', ('forw', llmemory.Address),

Modified: pypy/dist/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctransform/framework.py	Tue Dec 18 14:22:29 2007
@@ -257,6 +257,28 @@
         else:
             self.malloc_fast_ptr = None
 
+        # in some GCs we can also inline the common case of
+        # malloc_varsize(typeid, length, (3 constant sizes), True, False)
+        if getattr(GCClass, 'inline_simple_malloc_varsize', False):
+            # make a copy of this function so that it gets annotated
+            # independently and the constants are folded inside
+            malloc_varsize_clear_fast = func_with_new_name(
+                GCClass.malloc_varsize_clear.im_func,
+                "malloc_varsize_clear_fast")
+            s_False = annmodel.SomeBool(); s_False.const = False
+            s_True  = annmodel.SomeBool(); s_True .const = True
+            self.malloc_varsize_clear_fast_ptr = getfn(
+                malloc_varsize_clear_fast,
+                [s_gc, annmodel.SomeInteger(nonneg=True),
+                 annmodel.SomeInteger(nonneg=True),
+                 annmodel.SomeInteger(nonneg=True),
+                 annmodel.SomeInteger(nonneg=True),
+                 annmodel.SomeInteger(nonneg=True),
+                 s_True, s_False], s_gcref,
+                inline = True)
+        else:
+            self.malloc_varsize_clear_fast_ptr = None
+
         if GCClass.moving_gc:
             self.id_ptr = getfn(GCClass.id.im_func,
                                 [s_gc, s_gcref], annmodel.SomeInteger(),
@@ -521,11 +543,11 @@
             v_length = op.args[-1]
             c_ofstolength = rmodel.inputconst(lltype.Signed, info.ofstolength)
             c_varitemsize = rmodel.inputconst(lltype.Signed, info.varitemsize)
-            malloc_ptr = self.malloc_varsize_clear_ptr
-##             if op.opname.startswith('zero'):
-##                 malloc_ptr = self.malloc_varsize_clear_ptr
-##             else:
-##                 malloc_ptr = self.malloc_varsize_clear_ptr
+            if (self.malloc_varsize_clear_fast_ptr is not None and
+                c_can_collect.value and not c_has_finalizer.value):
+                malloc_ptr = self.malloc_varsize_clear_fast_ptr
+            else:
+                malloc_ptr = self.malloc_varsize_clear_ptr
             args = [self.c_const_gc, c_type_id, v_length, c_size,
                     c_varitemsize, c_ofstolength, c_can_collect,
                     c_has_finalizer]



More information about the Pypy-commit mailing list