[pypy-svn] r70835 - in pypy/branch/stringbuilder2/pypy/rpython: lltypesystem memory/gc memory/gctransform

fijal at codespeak.net fijal at codespeak.net
Mon Jan 25 15:22:56 CET 2010


Author: fijal
Date: Mon Jan 25 15:22:55 2010
New Revision: 70835

Modified:
   pypy/branch/stringbuilder2/pypy/rpython/lltypesystem/rbuilder.py
   pypy/branch/stringbuilder2/pypy/rpython/memory/gc/base.py
   pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/boehm.py
   pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/framework.py
   pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/transform.py
Log:
IN-PROGRESS. This is a first attempt, breaks tests etc. I want to check that in,
so I can merge the trunk. Idea is to call realloc in framework gcs, which
by default would simply do a new allocation and copy. In arena-based gcs
we can be advanced and in case of shrinking simply change a length and
be happy


Modified: pypy/branch/stringbuilder2/pypy/rpython/lltypesystem/rbuilder.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/lltypesystem/rbuilder.py	(original)
+++ pypy/branch/stringbuilder2/pypy/rpython/lltypesystem/rbuilder.py	Mon Jan 25 15:22:55 2010
@@ -26,7 +26,7 @@
             new_allocated = ovfcheck(new_allocated + needed)
         except OverflowError:
             raise MemoryError
-        ll_builder.buf = rgc.resize_buffer(ll_builder.buf, ll_builder.used,
+        ll_builder.buf = rgc.resize_buffer(ll_builder.buf, ll_builder.allocated,
                                            new_allocated)
         ll_builder.allocated = new_allocated
     return func_with_new_name(stringbuilder_grow, name)

Modified: pypy/branch/stringbuilder2/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/memory/gc/base.py	(original)
+++ pypy/branch/stringbuilder2/pypy/rpython/memory/gc/base.py	Mon Jan 25 15:22:55 2010
@@ -1,5 +1,6 @@
 from pypy.rpython.lltypesystem import lltype, llmemory, llarena
 from pypy.rlib.debug import ll_assert
+from pypy.rlib.objectmodel import keepalive_until_here
 from pypy.rpython.memory.gcheader import GCHeaderBuilder
 from pypy.rpython.memory.support import DEFAULT_CHUNK_SIZE
 from pypy.rpython.memory.support import get_address_stack, get_address_deque
@@ -134,6 +135,29 @@
         # lots of cast and reverse-cast around...
         return llmemory.cast_ptr_to_adr(ref)
 
+    def realloc(self, source, oldlength, newlength, fixedsize, itemsize,
+                lengthofs, itemsofs, grow):
+        # by default, realloc mallocs stuff and copies it over when growing.
+        # when shrinking, we only change length and be happy
+        source_adr = llmemory.cast_ptr_to_adr(source)
+        type_id = self.get_type_id(source_adr)
+        if not hasattr(self, 'malloc_varsize'):
+            malloc_varsize = self.malloc_varsize_clear
+        else:
+            malloc_varsize = self.malloc_varsize
+        typeid = self.get_type_id(source_adr)
+        if grow:
+            dest = malloc_varsize(typeid, newlength, fixedsize, itemsize,
+                                  lengthofs, True)
+            dest_adr = llmemory.cast_ptr_to_adr(dest)
+            llmemory.raw_memcopy(source_adr + itemsofs, dest_adr + itemsofs,
+                                 itemsize * oldlength)
+            keepalive_until_here(source)
+        else:
+            (source_adr + lengthofs).signed[0] = newlength
+            dest = source
+        return dest
+
     def malloc_nonmovable(self, typeid, length=0, zero=False):
         return self.malloc(typeid, length, zero)
 

Modified: pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/boehm.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/boehm.py	(original)
+++ pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/boehm.py	Mon Jan 25 15:22:55 2010
@@ -77,7 +77,7 @@
         return True
 
     def perform_realloc(self, hop, v_ptr, v_newlgt, c_const_size, c_item_size,
-                        c_lengthofs, c_grow):
+                        c_lengthofs, c_itemsofs, c_grow):
         args = [self.realloc_ptr, v_ptr, v_newlgt, c_const_size,
                 c_item_size, c_lengthofs]
         return hop.genop('direct_call', args, resulttype=llmemory.Address)

Modified: pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/framework.py	Mon Jan 25 15:22:55 2010
@@ -373,7 +373,7 @@
             self.realloc_ptr = getfn(
                 GCClass.realloc.im_func,
                 [s_gc, s_gcref] +
-                [annmodel.SomeInteger(nonneg=True)] * 4 +
+                [annmodel.SomeInteger(nonneg=True)] * 6 +
                 [annmodel.SomeBool()],
                 s_gcref)
 
@@ -713,10 +713,11 @@
     def _can_realloc(self):
         return True
 
-    def perform_realloc(self, hop, v_ptr, v_newsize, c_const_size,
-                        c_itemsize, c_lengthofs, c_grow):
-        vlist = [self.realloc_ptr, self.c_const_gc, v_ptr, v_newsize,
-                 c_const_size, c_itemsize, c_lengthofs, c_grow]
+    def perform_realloc(self, hop, v_ptr, v_oldsize, v_newsize, c_const_size,
+                        c_itemsize, c_lengthofs, c_itemsofs, c_grow):
+        vlist = [self.realloc_ptr, self.c_const_gc, v_ptr,
+                 v_oldsize, v_newsize,
+                 c_const_size, c_itemsize, c_lengthofs, c_itemsofs, c_grow]
         livevars = self.push_roots(hop)
         v_result = hop.genop('direct_call', vlist,
                              resulttype=llmemory.GCREF)

Modified: pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/transform.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/transform.py	(original)
+++ pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/transform.py	Mon Jan 25 15:22:55 2010
@@ -577,14 +577,14 @@
     def gct_resize_buffer(self, hop):
         op = hop.spaceop
         if self._can_realloc():
-            self._gct_resize_buffer_realloc(hop, op.args[2], True)
+            self._gct_resize_buffer_realloc(hop, op.args[1], op.args[2], True)
         else:
             self._gct_resize_buffer_no_realloc(hop, op.args[1])
 
     def _can_realloc(self):
         return False
 
-    def _gct_resize_buffer_realloc(self, hop, v_newsize, grow=True):
+    def _gct_resize_buffer_realloc(self, hop, v_oldsize, v_newsize, grow=True):
         def intconst(c): return rmodel.inputconst(lltype.Signed, c)
         op = hop.spaceop
         flags = {'flavor':'gc', 'varsize': True}
@@ -596,11 +596,13 @@
         c_item_size = intconst(llmemory.sizeof(ARRAY.OF))
 
         c_lengthofs = intconst(offset_to_length)
+        c_itemsofs = intconst(llmemory.itemoffsetof(TYPE, 0))
         v_ptr = op.args[0]
         v_ptr = gen_cast(hop.llops, llmemory.GCREF, v_ptr)
         c_grow = rmodel.inputconst(lltype.Bool, grow)
-        v_raw = self.perform_realloc(hop, v_ptr, v_newsize, c_const_size,
-                                     c_item_size, c_lengthofs, c_grow)
+        v_raw = self.perform_realloc(hop, v_ptr, v_oldsize, v_newsize,
+                                     c_const_size, c_item_size, c_lengthofs,
+                                     c_itemsofs, c_grow)
         hop.cast_result(v_raw)
 
     def _gct_resize_buffer_no_realloc(self, hop, v_lgt):
@@ -634,7 +636,8 @@
     def gct_finish_building_buffer(self, hop):
         op = hop.spaceop
         if self._can_realloc():
-            return self._gct_resize_buffer_realloc(hop, op.args[1], False)
+            return self._gct_resize_buffer_realloc(hop, op.args[1],
+                                                   op.args[2], False)
         else:
             return self._gct_resize_buffer_no_realloc(hop, op.args[1])
 



More information about the Pypy-commit mailing list