[pypy-svn] r77118 - in pypy/branch/gen2-gc/pypy/rpython/memory: gc test
arigo at codespeak.net
arigo at codespeak.net
Thu Sep 16 16:00:11 CEST 2010
Author: arigo
Date: Thu Sep 16 16:00:09 2010
New Revision: 77118
Modified:
pypy/branch/gen2-gc/pypy/rpython/memory/gc/minimark.py
pypy/branch/gen2-gc/pypy/rpython/memory/test/test_gc.py
Log:
shrink_array().
Modified: pypy/branch/gen2-gc/pypy/rpython/memory/gc/minimark.py
==============================================================================
--- pypy/branch/gen2-gc/pypy/rpython/memory/gc/minimark.py (original)
+++ pypy/branch/gen2-gc/pypy/rpython/memory/gc/minimark.py Thu Sep 16 16:00:09 2010
@@ -375,12 +375,30 @@
def can_malloc_nonmovable(self):
XXX
- def can_move(self, addr):
+ def can_move(self, obj):
"""Overrides the parent can_move()."""
- return self.is_in_nursery(addr)
+ return self.is_in_nursery(obj)
+
+
+ def shrink_array(self, obj, smallerlength):
+ #
+ # Only objects in the nursery can be "resized". Resizing them
+ # means recording that they have a smaller size, so that when
+ # moved out of the nursery, they will consume less memory.
+ if not self.is_in_nursery(obj):
+ return False
+ #
+ size_gc_header = self.gcheaderbuilder.size_gc_header
+ typeid = self.get_type_id(obj)
+ totalsmallersize = (
+ size_gc_header + self.fixed_size(typeid) +
+ self.varsize_item_sizes(typeid) * smallerlength)
+ llarena.arena_shrink_obj(obj - size_gc_header, totalsmallersize)
+ #
+ offset_to_length = self.varsize_offset_to_length(typeid)
+ (obj + offset_to_length).signed[0] = smallerlength
+ return True
- def shrink_array(self, addr, newsize):
- XXX
def malloc_varsize_nonmovable(self, typeid, length):
XXX
Modified: pypy/branch/gen2-gc/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/branch/gen2-gc/pypy/rpython/memory/test/test_gc.py (original)
+++ pypy/branch/gen2-gc/pypy/rpython/memory/test/test_gc.py Thu Sep 16 16:00:09 2010
@@ -28,6 +28,7 @@
GC_CAN_MOVE = False
GC_CANNOT_MALLOC_NONMOVABLE = False
GC_CAN_SHRINK_ARRAY = False
+ GC_CAN_SHRINK_BIG_ARRAY = False
def setup_class(cls):
cls._saved_logstate = py.log._getstate()
@@ -474,28 +475,27 @@
def test_shrink_array(self):
from pypy.rpython.lltypesystem.rstr import STR
- GC_CAN_SHRINK_ARRAY = self.GC_CAN_SHRINK_ARRAY
- def f(n, m):
+ def f(n, m, gc_can_shrink_array):
ptr = lltype.malloc(STR, n)
ptr.hash = 0x62
ptr.chars[0] = 'A'
ptr.chars[1] = 'B'
ptr.chars[2] = 'C'
ptr2 = rgc.ll_shrink_array(ptr, 2)
- assert (ptr == ptr2) == GC_CAN_SHRINK_ARRAY
+ assert (ptr == ptr2) == gc_can_shrink_array
rgc.collect()
return ( ord(ptr2.chars[0]) +
(ord(ptr2.chars[1]) << 8) +
(len(ptr2.chars) << 16) +
(ptr2.hash << 24))
- assert self.interpret(f, [3, 0]) == 0x62024241
- # don't test with larger numbers of top of the Hybrid GC, because
- # the default settings make it a too-large varsized object that
- # gets allocated outside the semispace
- if not isinstance(self, TestHybridGC):
- assert self.interpret(f, [12, 0]) == 0x62024241
+ flag = self.GC_CAN_SHRINK_ARRAY
+ assert self.interpret(f, [3, 0, flag]) == 0x62024241
+ # with larger numbers, it gets allocated outside the semispace
+ # with some GCs.
+ flag = self.GC_CAN_SHRINK_BIG_ARRAY
+ assert self.interpret(f, [12, 0, flag]) == 0x62024241
def test_tagged_simple(self):
from pypy.rlib.objectmodel import UnboxedValue
@@ -630,6 +630,7 @@
GC_CAN_MOVE = True
GC_CANNOT_MALLOC_NONMOVABLE = True
GC_CAN_SHRINK_ARRAY = True
+ GC_CAN_SHRINK_BIG_ARRAY = True
class TestGrowingSemiSpaceGC(TestSemiSpaceGC):
GC_PARAMS = {'space_size': 16*WORD}
@@ -641,6 +642,7 @@
from pypy.rpython.memory.gc.markcompact import MarkCompactGC as GCClass
GC_PARAMS = {'space_size': 65536+16384}
GC_CAN_SHRINK_ARRAY = False
+ GC_CAN_SHRINK_BIG_ARRAY = False
def test_finalizer_order(self):
py.test.skip("Not implemented yet")
@@ -651,6 +653,7 @@
class TestHybridGC(TestGenerationalGC):
from pypy.rpython.memory.gc.hybrid import HybridGC as GCClass
GC_CANNOT_MALLOC_NONMOVABLE = False
+ GC_CAN_SHRINK_BIG_ARRAY = False
def test_ref_from_rawmalloced_to_regular(self):
import gc
@@ -768,3 +771,4 @@
class TestMiniMarkGC(TestSemiSpaceGC):
from pypy.rpython.memory.gc.minimark import MiniMarkGC as GCClass
+ GC_CAN_SHRINK_BIG_ARRAY = False
More information about the Pypy-commit
mailing list