Author: Armin Rigo <ar...@tunes.org> Branch: array-overallocation-in-nursery Changeset: r67810:e47b0be7335b Date: 2013-11-03 12:30 +0100 http://bitbucket.org/pypy/pypy/changeset/e47b0be7335b/
Log: Kill llmemory.gcarrayofptr_xxx. Found out that we can write the special case in gc/base.py without using them, but using only the size of a GCREF as a special constant. 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 @@ -217,12 +217,13 @@ # which we have a special case for performance, or we call # the slow path version. if self.is_gcarrayofgcptr(typeid): - length = (obj + llmemory.gcarrayofptr_lengthoffset).signed[0] - item = obj + llmemory.gcarrayofptr_itemsoffset + item = obj + self.varsize_offset_to_variable_part(typeid) + length_adr = (obj + self.varsize_offset_to_used_length(typeid)) + length = length_adr.signed[0] while length > 0: if self.points_to_valid_gc_object(item): callback(item, arg) - item += llmemory.gcarrayofptr_singleitemoffset + item += llmemory.size_of_gcref length -= 1 return self._trace_slow_path(obj, callback, arg) @@ -273,12 +274,12 @@ typeid = self.get_type_id(obj) if self.is_gcarrayofgcptr(typeid): # a performance shortcut for GcArray(gcptr) - item = obj + llmemory.gcarrayofptr_itemsoffset - item += llmemory.gcarrayofptr_singleitemoffset * start + item = obj + self.varsize_offset_to_variable_part(typeid) + item += llmemory.size_of_gcref * start while length > 0: if self.points_to_valid_gc_object(item): callback(item, arg) - item += llmemory.gcarrayofptr_singleitemoffset + item += llmemory.size_of_gcref length -= 1 return ll_assert(self.has_gcptr_in_varsize(typeid), diff --git a/rpython/memory/gctypelayout.py b/rpython/memory/gctypelayout.py --- a/rpython/memory/gctypelayout.py +++ b/rpython/memory/gctypelayout.py @@ -246,10 +246,10 @@ else: assert isinstance(TYPE, lltype.GcArray) ARRAY = TYPE + if (isinstance(ARRAY.OF, lltype.Ptr) + and ARRAY.OF.TO._gckind == 'gc'): + infobits |= T_IS_GCARRAY_OF_GCPTR if not ARRAY._is_overallocated_array(): - if (isinstance(ARRAY.OF, lltype.Ptr) - and ARRAY.OF.TO._gckind == 'gc'): - infobits |= T_IS_GCARRAY_OF_GCPTR varinfo.ofstolength = llmemory.ArrayLengthOffset(ARRAY) varinfo.ofstousedlength = varinfo.ofstolength else: diff --git a/rpython/rtyper/lltypesystem/llmemory.py b/rpython/rtyper/lltypesystem/llmemory.py --- a/rpython/rtyper/lltypesystem/llmemory.py +++ b/rpython/rtyper/lltypesystem/llmemory.py @@ -594,19 +594,11 @@ # GCREF is similar to Address but it is GC-aware GCREF = lltype.Ptr(lltype.GcOpaqueType('GCREF')) -# A placeholder for any type that is a GcArray of pointers. -# This can be used in the symbolic offsets above to access such arrays -# in a generic way. -GCARRAY_OF_PTR = lltype.GcArray(GCREF, hints={'placeholder': True}) -gcarrayofptr_lengthoffset = ArrayLengthOffset(GCARRAY_OF_PTR) -gcarrayofptr_itemsoffset = ArrayItemsOffset(GCARRAY_OF_PTR) -gcarrayofptr_singleitemoffset = ItemOffset(GCARRAY_OF_PTR.OF) +size_of_gcref = ItemOffset(GCREF) + def array_type_match(A1, A2): - return A1 == A2 or (A2 == GCARRAY_OF_PTR and - isinstance(A1, lltype.GcArray) and - isinstance(A1.OF, lltype.Ptr) and - not A1._hints.get('nolength') and - not A1._hints.get('overallocated')) + return A1 == A2 + def array_item_type_match(T1, T2): return T1 == T2 or (T2 == GCREF and isinstance(T1, lltype.Ptr)) diff --git a/rpython/rtyper/lltypesystem/test/test_llmemory.py b/rpython/rtyper/lltypesystem/test/test_llmemory.py --- a/rpython/rtyper/lltypesystem/test/test_llmemory.py +++ b/rpython/rtyper/lltypesystem/test/test_llmemory.py @@ -579,25 +579,6 @@ assert weakref_deref(lltype.Ptr(S), w) == lltype.nullptr(S) assert weakref_deref(lltype.Ptr(S1), w) == lltype.nullptr(S1) -def test_generic_gcarray_of_ptr(): - S1 = lltype.GcStruct('S1', ('x', lltype.Signed)) - A1 = lltype.GcArray(lltype.Ptr(S1)) - A2 = lltype.GcArray(lltype.Ptr(A1)) - a2 = lltype.malloc(A2, 3) - a2[1] = lltype.malloc(A1, 4) - a2[1][2] = lltype.malloc(S1) - a2[1][2].x = -33 - - adr = cast_ptr_to_adr(a2) - assert (adr + gcarrayofptr_lengthoffset).signed[0] == 3 - adr += gcarrayofptr_itemsoffset - adr += gcarrayofptr_singleitemoffset - adr = adr.address[0] # => a2[1] - assert (adr + gcarrayofptr_lengthoffset).signed[0] == 4 - adr += gcarrayofptr_itemsoffset + 2 * gcarrayofptr_singleitemoffset - adr = adr.address[0] # => s2[1][2] - assert (adr + FieldOffset(S1, 'x')).signed[0] == -33 - def test_raw_memclear_on_empty_array(): py.test.skip("Fails") A = lltype.FixedSizeArray(lltype.Signed, 0) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit