Author: Maciej Fijalkowski <[email protected]>
Branch: array-overallocation-in-nursery
Changeset: r67508:cc86c3b3bf85
Date: 2013-10-22 13:37 +0200
http://bitbucket.org/pypy/pypy/changeset/cc86c3b3bf85/
Log: (fijal, arigo) in-progress
diff --git a/rpython/memory/gctypelayout.py b/rpython/memory/gctypelayout.py
--- a/rpython/memory/gctypelayout.py
+++ b/rpython/memory/gctypelayout.py
@@ -38,11 +38,12 @@
hints={'immutable': True},
)
VARSIZE_TYPE_INFO = lltype.Struct("varsize_type_info",
- ("header", TYPE_INFO),
- ("varitemsize", lltype.Signed),
- ("ofstovar", lltype.Signed),
- ("ofstolength", lltype.Signed),
- ("varofstoptrs", lltype.Ptr(OFFSETS_TO_GC_PTR)),
+ ("header", TYPE_INFO),
+ ("varitemsize", lltype.Signed),
+ ("ofstovar", lltype.Signed),
+ ("ofstolength", lltype.Signed), # either length or allocated_length
+ ("ofstousedlength", lltype.Signed),
+ ("varofstoptrs", lltype.Ptr(OFFSETS_TO_GC_PTR)),
hints={'immutable': True},
)
TYPE_INFO_PTR = lltype.Ptr(TYPE_INFO)
@@ -240,10 +241,13 @@
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
- varinfo.ofstolength = llmemory.ArrayLengthOffset(ARRAY)
+ if 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)
+ else:
+ ...
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
@@ -29,6 +29,7 @@
GC_CAN_SHRINK_ARRAY = False
GC_CAN_SHRINK_BIG_ARRAY = False
BUT_HOW_BIG_IS_A_BIG_STRING = 3*WORD
+ SUPPORTS_OVERALLOCATED_ARRAYS = False
def setup_class(cls):
cls._saved_logstate = py.log._getstate()
@@ -86,7 +87,7 @@
for i in range(1, 15):
res = self.interpret(append_to_list, [i, i - 1])
assert res == i - 1 # crashes if constants are not considered roots
-
+
def test_string_concatenation(self):
#curr = simulator.current_size
def concat(j):
@@ -783,6 +784,29 @@
assert rgc.get_gcflag_extra(a2) == False
self.interpret(fn, [])
+ def test_overallocated_array(self):
+ S = lltype.GcStruct('S')
+ A = lltype.GcArray(lltype.Ptr(S), hints={'overallocated': True})
+ if self.SUPPORTS_OVERALLOCATED_ARRAYS:
+ EXPECTED_LENGTH = 2
+ else:
+ EXPECTED_LENGTH = 10
+
+ def fn():
+ a = lltype.malloc(A, 10)
+ a.used_length = 2
+ s1 = lltype.malloc(S)
+ s2 = lltype.malloc(S)
+ a[0] = s1
+ a[1] = s2
+ rgc.collect()
+ assert a[0] == s1
+ assert a[1] == s2
+ assert a.used_length == 2
+ assert a.allocated_length == EXPECTED_LENGTH
+
+ self.interpret(fn, [])
+
from rpython.rlib.objectmodel import UnboxedValue
class TaggedBase(object):
diff --git a/rpython/memory/test/test_gctypelayout.py
b/rpython/memory/test/test_gctypelayout.py
--- a/rpython/memory/test/test_gctypelayout.py
+++ b/rpython/memory/test/test_gctypelayout.py
@@ -23,7 +23,7 @@
GC_A = lltype.GcArray(S)
S2 = lltype.Struct('SPTRS',
- *[(getname(TYPE), lltype.Ptr(TYPE)) for TYPE in (GC_S,
GC_A)])
+ *[(getname(TYPE), lltype.Ptr(TYPE)) for TYPE in (GC_S,
GC_A)])
GC_S2 = lltype.GcStruct('GC_S2', ('S2', S2))
A2 = lltype.Array(S2)
@@ -120,3 +120,11 @@
adr = llmemory.cast_ptr_to_adr(s3)
lst = list(gc_pointers_inside(s3._obj, adr, mutable_only=True))
assert lst == [adr + llmemory.offsetof(S3, 'y')]
+
+def test_overallocated_array():
+ S = lltype.GcStruct('S')
+ A = lltype.GcArray(lltype.Ptr(S), hints={'overallocated': True})
+
+ layoutbuilder = TypeLayoutBuilder(FakeGC)
+ tid = layoutbuilder.get_type_id(A)
+ xxx
diff --git a/rpython/memory/test/test_incminimark_gc.py
b/rpython/memory/test/test_incminimark_gc.py
--- a/rpython/memory/test/test_incminimark_gc.py
+++ b/rpython/memory/test/test_incminimark_gc.py
@@ -4,3 +4,6 @@
class TestIncrementalMiniMarkGC(test_minimark_gc.TestMiniMarkGC):
from rpython.memory.gc.incminimark import IncrementalMiniMarkGC as GCClass
+
+ SUPPORTS_OVERALLOCATED_ARRAYS = True
+
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit