[pypy-svn] r70854 - in pypy/branch/stringbuilder2/pypy/rpython/memory: gctransform test
arigo at codespeak.net
arigo at codespeak.net
Mon Jan 25 20:15:24 CET 2010
Author: arigo
Date: Mon Jan 25 20:15:24 2010
New Revision: 70854
Modified:
pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/framework.py
pypy/branch/stringbuilder2/pypy/rpython/memory/test/test_transformed_gc.py
Log:
Finish the integration of shrink_array.
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 20:15:24 2010
@@ -276,6 +276,14 @@
[s_gc, annmodel.SomeAddress()],
annmodel.SomeBool())
+ if hasattr(GCClass, 'shrink_array'):
+ self.shrink_array_ptr = getfn(
+ GCClass.shrink_array.im_func,
+ [s_gc, annmodel.SomeAddress(),
+ annmodel.SomeInteger(nonneg=True)], annmodel.s_Bool)
+ else:
+ self.shrink_array_ptr = None
+
if hasattr(GCClass, 'assume_young_pointers'):
# xxx should really be a noop for gcs without generations
self.assume_young_pointers_ptr = getfn(
@@ -358,16 +366,16 @@
else:
self.malloc_varsize_nonmovable_ptr = None
- if getattr(GCClass, 'malloc_varsize_resizable', False):
- malloc_resizable = func_with_new_name(
- GCClass.malloc_varsize_resizable.im_func,
- "malloc_varsize_resizable")
- self.malloc_varsize_resizable_ptr = getfn(
- malloc_resizable,
- [s_gc, s_typeid16,
- annmodel.SomeInteger(nonneg=True)], s_gcref)
- else:
- self.malloc_varsize_resizable_ptr = None
+## if getattr(GCClass, 'malloc_varsize_resizable', False):
+## malloc_resizable = func_with_new_name(
+## GCClass.malloc_varsize_resizable.im_func,
+## "malloc_varsize_resizable")
+## self.malloc_varsize_resizable_ptr = getfn(
+## malloc_resizable,
+## [s_gc, s_typeid16,
+## annmodel.SomeInteger(nonneg=True)], s_gcref)
+## else:
+## self.malloc_varsize_resizable_ptr = None
if getattr(GCClass, 'realloc', False):
self.realloc_ptr = getfn(
@@ -627,11 +635,11 @@
info_varsize.ofstolength)
c_varitemsize = rmodel.inputconst(lltype.Signed,
info_varsize.varitemsize)
- if flags.get('resizable') and self.malloc_varsize_resizable_ptr:
- assert c_can_collect.value
- malloc_ptr = self.malloc_varsize_resizable_ptr
- args = [self.c_const_gc, c_type_id, v_length]
- elif flags.get('nonmovable') and self.malloc_varsize_nonmovable_ptr:
+## if flags.get('resizable') and self.malloc_varsize_resizable_ptr:
+## assert c_can_collect.value
+## malloc_ptr = self.malloc_varsize_resizable_ptr
+## args = [self.c_const_gc, c_type_id, v_length]
+ if flags.get('nonmovable') and self.malloc_varsize_nonmovable_ptr:
# we don't have tests for such cases, let's fail
# explicitely
assert c_can_collect.value
@@ -673,6 +681,17 @@
hop.genop("direct_call", [self.can_move_ptr, self.c_const_gc, v_addr],
resultvar=op.result)
+ def gct_shrink_array(self, hop):
+ if self.shrink_array_ptr is None:
+ return GCTransformer.gct_shrink_array(self, hop)
+ op = hop.spaceop
+ v_addr = hop.genop('cast_ptr_to_adr',
+ [op.args[0]], resulttype=llmemory.Address)
+ v_length = op.args[1]
+ hop.genop("direct_call", [self.shrink_array_ptr, self.c_const_gc,
+ v_addr, v_length],
+ resultvar=op.result)
+
def gct_gc_assume_young_pointers(self, hop):
op = hop.spaceop
v_addr = op.args[0]
Modified: pypy/branch/stringbuilder2/pypy/rpython/memory/test/test_transformed_gc.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/memory/test/test_transformed_gc.py (original)
+++ pypy/branch/stringbuilder2/pypy/rpython/memory/test/test_transformed_gc.py Mon Jan 25 20:15:24 2010
@@ -162,6 +162,7 @@
return run
class GenericGCTests(GCTest):
+ GC_CAN_SHRINK_ARRAY = False
def heap_usage(self, statistics):
try:
@@ -637,19 +638,24 @@
def f():
ptr = lltype.malloc(STR, 3)
ptr.hash = 0x62
- ptr.chars[0] = 'A'
+ ptr.chars[0] = '0'
ptr.chars[1] = 'B'
ptr.chars[2] = 'C'
- ptr = rgc.ll_shrink_array(ptr, 2)
- return ( ord(ptr.chars[0]) +
- (ord(ptr.chars[1]) << 8) +
- (len(ptr.chars) << 16) +
- (ptr.hash << 24))
+ ptr2 = rgc.ll_shrink_array(ptr, 2)
+ return ((ptr == ptr2) +
+ ord(ptr2.chars[0]) +
+ (ord(ptr2.chars[1]) << 8) +
+ (len(ptr2.chars) << 16) +
+ (ptr2.hash << 24))
return f
def test_shrink_array(self):
run = self.runner("shrink_array")
- assert run([]) == 0x62024241
+ if self.GC_CAN_SHRINK_ARRAY:
+ expected = 0x62024231
+ else:
+ expected = 0x62024230
+ assert run([]) == expected
def define_string_builder_over_allocation(cls):
import gc
@@ -1120,6 +1126,7 @@
class TestSemiSpaceGC(GenericMovingGCTests):
gcname = "semispace"
+ GC_CAN_SHRINK_ARRAY = True
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
@@ -1141,6 +1148,7 @@
class TestGenerationGC(GenericMovingGCTests):
gcname = "generation"
+ GC_CAN_SHRINK_ARRAY = True
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
More information about the Pypy-commit
mailing list