[pypy-commit] pypy array-overallocation-in-nursery: For GCs that never shrink overallocated array, test_overallocated_array

arigo noreply at buildbot.pypy.org
Tue Oct 22 13:57:00 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: array-overallocation-in-nursery
Changeset: r67510:4eb04f9f277a
Date: 2013-10-22 13:55 +0200
http://bitbucket.org/pypy/pypy/changeset/4eb04f9f277a/

Log:	For GCs that never shrink overallocated array,
	test_overallocated_array passes.

diff --git a/rpython/memory/gc/base.py b/rpython/memory/gc/base.py
--- a/rpython/memory/gc/base.py
+++ b/rpython/memory/gc/base.py
@@ -68,6 +68,7 @@
                             fixed_size, varsize_item_sizes,
                             varsize_offset_to_variable_part,
                             varsize_offset_to_length,
+                            varsize_offset_to_used_length,
                             varsize_offsets_to_gcpointers_in_var_part,
                             weakpointer_offset,
                             member_index,
@@ -86,6 +87,7 @@
         self.varsize_item_sizes = varsize_item_sizes
         self.varsize_offset_to_variable_part = varsize_offset_to_variable_part
         self.varsize_offset_to_length = varsize_offset_to_length
+        self.varsize_offset_to_used_length = varsize_offset_to_used_length
         self.varsize_offsets_to_gcpointers_in_var_part = varsize_offsets_to_gcpointers_in_var_part
         self.weakpointer_offset = weakpointer_offset
         self.member_index = member_index
@@ -217,7 +219,8 @@
         typeid = self.get_type_id(obj)
         if self.has_gcptr_in_varsize(typeid):
             item = obj + self.varsize_offset_to_variable_part(typeid)
-            length = (obj + self.varsize_offset_to_length(typeid)).signed[0]
+            length_adr = (obj + self.varsize_offset_to_used_length(typeid))
+            length = length_adr.signed[0]
             offsets = self.varsize_offsets_to_gcpointers_in_var_part(typeid)
             itemlength = self.varsize_item_sizes(typeid)
             while length > 0:
diff --git a/rpython/memory/gctypelayout.py b/rpython/memory/gctypelayout.py
--- a/rpython/memory/gctypelayout.py
+++ b/rpython/memory/gctypelayout.py
@@ -164,6 +164,7 @@
             self.q_varsize_item_sizes,
             self.q_varsize_offset_to_variable_part,
             self.q_varsize_offset_to_length,
+            self.q_varsize_offset_to_used_length,
             self.q_varsize_offsets_to_gcpointers_in_var_part,
             self.q_weakpointer_offset,
             self.q_member_index,
@@ -248,11 +249,12 @@
                 if (isinstance(ARRAY.OF, lltype.Ptr)
                     and ARRAY.OF.TO._gckind == 'gc'):
                     infobits |= T_IS_GCARRAY_OF_GCPTR
-                varinfo.ofstolength = llmemory.ArrayLengthOffset(ARRAY)
+                attrkinds = "length", "length"
             else:
-                ALO = llmemory.ArrayLengthOffset
-                varinfo.ofstolength = ALO(ARRAY, attrkind="allocated_length")
-                varinfo.ofstousedlength = ALO(ARRAY, attrkind="used_length")
+                attrkinds = "allocated_length", "used_length"
+            ALO = llmemory.ArrayLengthOffset
+            varinfo.ofstolength = ALO(ARRAY, attrkind=attrkinds[0])
+            varinfo.ofstousedlength = ALO(ARRAY, attrkind=attrkinds[1])
             varinfo.ofstovar = llmemory.itemoffsetof(TYPE, 0)
         assert isinstance(ARRAY, lltype.Array)
         if ARRAY.OF != lltype.Void:
diff --git a/rpython/memory/test/gc_test_base.py b/rpython/memory/test/gc_test_base.py
--- a/rpython/memory/test/gc_test_base.py
+++ b/rpython/memory/test/gc_test_base.py
@@ -785,7 +785,7 @@
         self.interpret(fn, [])
 
     def test_overallocated_array(self):
-        S = lltype.GcStruct('S')
+        S = lltype.GcStruct('S', ('n', lltype.Signed))
         A = lltype.GcArray(lltype.Ptr(S), hints={'overallocated': True})
         if self.SUPPORTS_OVERALLOCATED_ARRAYS:
             EXPECTED_LENGTH = 2
diff --git a/rpython/rtyper/lltypesystem/lltype.py b/rpython/rtyper/lltypesystem/lltype.py
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -1908,7 +1908,8 @@
                     raise Exception("can't grow an array in-place")
                 self.array.shrinklength(value)
         elif self.attrkind == "allocated_length":
-            raise Exception("can't set allocated_length")
+            if value != len(self.array.items):
+                raise Exception("can't set allocated_length")
         elif self.attrkind == "used_length":
             self.array.set_used_length(value)
 


More information about the pypy-commit mailing list