[pypy-svn] r54652 - in pypy/branch/hybrid-io/pypy/rpython/memory: . gc test
fijal at codespeak.net
fijal at codespeak.net
Sun May 11 18:26:42 CEST 2008
Author: fijal
Date: Sun May 11 18:26:40 2008
New Revision: 54652
Modified:
pypy/branch/hybrid-io/pypy/rpython/memory/gc/base.py
pypy/branch/hybrid-io/pypy/rpython/memory/gc/hybrid.py
pypy/branch/hybrid-io/pypy/rpython/memory/gcwrapper.py
pypy/branch/hybrid-io/pypy/rpython/memory/test/test_gc.py
Log:
Support for malloc_nonmovable (but only varsize) for hybrid gc.
Only test_gc passes by now, test_transformed_gc is a next step.
Modified: pypy/branch/hybrid-io/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/hybrid-io/pypy/rpython/memory/gc/base.py (original)
+++ pypy/branch/hybrid-io/pypy/rpython/memory/gc/base.py Sun May 11 18:26:40 2008
@@ -9,6 +9,9 @@
prebuilt_gc_objects_are_static_roots = True
can_realloc = False
+ def can_malloc_nonmovable(self):
+ return not self.moving_gc
+
# The following flag enables costly consistency checks after each
# collection. It is automatically set to True by test_gc.py. The
# checking logic is translatable, so the flag can be set to True
@@ -85,6 +88,9 @@
# lots of cast and reverse-cast around...
return llmemory.cast_ptr_to_adr(ref)
+ def malloc_nonmovable(self, typeid, length=0, zero=False):
+ return self.malloc(typeid, length, zero)
+
def id(self, ptr):
return lltype.cast_ptr_to_int(ptr)
Modified: pypy/branch/hybrid-io/pypy/rpython/memory/gc/hybrid.py
==============================================================================
--- pypy/branch/hybrid-io/pypy/rpython/memory/gc/hybrid.py (original)
+++ pypy/branch/hybrid-io/pypy/rpython/memory/gc/hybrid.py Sun May 11 18:26:40 2008
@@ -169,7 +169,7 @@
llmemory.GCREF)
return self.malloc_varsize_slowpath(typeid, length)
- def malloc_varsize_slowpath(self, typeid, length):
+ def malloc_varsize_slowpath(self, typeid, length, force_old=False):
# For objects that are too large, or when the nursery is exhausted.
# In order to keep malloc_varsize_clear() as compact as possible,
# we recompute what we need in this slow path instead of passing
@@ -187,7 +187,7 @@
nonlarge_max = self.nonlarge_gcptrs_max
else:
nonlarge_max = self.nonlarge_max
- if raw_malloc_usage(totalsize) > nonlarge_max:
+ if force_old or raw_malloc_usage(totalsize) > nonlarge_max:
result = self.malloc_varsize_marknsweep(totalsize)
flags = self.GCFLAGS_FOR_NEW_EXTERNAL_OBJECTS | GCFLAG_UNVISITED
else:
@@ -198,6 +198,19 @@
return llmemory.cast_adr_to_ptr(result+size_gc_header, llmemory.GCREF)
malloc_varsize_slowpath._dont_inline_ = True
+ malloc_varsize_slowpath._annspecialcase_ = 'specialize:arg(3)'
+
+ def malloc_nonmovable(self, typeid, length, zero):
+ # helper for testing, same as GCBase.malloc
+ if self.is_varsize(typeid):
+ gcref = self.malloc_varsize_slowpath(typeid, length, True)
+ else:
+ raise NotImplementedError("Not supported")
+ return llmemory.cast_ptr_to_adr(gcref)
+
+ def can_move(self, ptr):
+ tid = self.get_type_id(llmemory.cast_ptr_to_adr(ptr))
+ return tid & GCFLAG_AGE_MASK == GCFLAG_AGE_MAX
def malloc_varsize_collecting_nursery(self, totalsize):
result = self.collect_nursery()
@@ -515,3 +528,6 @@
"gen3: unexpected GCFLAG_UNVISITED")
ll_assert((tid & GCFLAG_AGE_MASK) == GCFLAG_AGE_MAX,
"gen3: wrong age field")
+
+ def can_malloc_nonmovable(self):
+ return True
Modified: pypy/branch/hybrid-io/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/branch/hybrid-io/pypy/rpython/memory/gcwrapper.py (original)
+++ pypy/branch/hybrid-io/pypy/rpython/memory/gcwrapper.py Sun May 11 18:26:40 2008
@@ -46,9 +46,9 @@
def malloc_nonmovable(self, TYPE, n=None, zero=False):
typeid = self.get_type_id(TYPE)
- if self.gc.moving_gc:
+ if not self.gc.can_malloc_nonmovable():
return lltype.nullptr(TYPE)
- addr = self.gc.malloc(typeid, n, zero=zero)
+ addr = self.gc.malloc_nonmovable(typeid, n, zero=zero)
result = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(TYPE))
if not self.gc.malloc_zero_filled:
gctypelayout.zero_gc_pointers(result)
Modified: pypy/branch/hybrid-io/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/branch/hybrid-io/pypy/rpython/memory/test/test_gc.py (original)
+++ pypy/branch/hybrid-io/pypy/rpython/memory/test/test_gc.py Sun May 11 18:26:40 2008
@@ -22,6 +22,7 @@
class GCTest(object):
GC_PARAMS = {}
GC_CAN_MOVE = False
+ GC_CANNOT_MALLOC_NONMOVABLE = False
def setup_class(cls):
cls._saved_logstate = py.log._getstate()
@@ -400,17 +401,14 @@
def test_malloc_nonmovable(self):
TP = lltype.GcArray(lltype.Char)
def func():
- try:
- from pypy.rlib import rgc
- a = rgc.malloc_nonmovable(TP, 3)
- if a:
- assert not rgc.can_move(a)
- return 0
- return 1
- except Exception, e:
- return 2
+ from pypy.rlib import rgc
+ a = rgc.malloc_nonmovable(TP, 3)
+ if a:
+ assert not rgc.can_move(a)
+ return 0
+ return 1
- assert self.interpret(func, []) == int(self.GC_CAN_MOVE)
+ assert self.interpret(func, []) == int(self.GC_CANNOT_MALLOC_NONMOVABLE)
def test_malloc_nonmovable_fixsize(self):
S = lltype.GcStruct('S', ('x', lltype.Float))
@@ -427,7 +425,7 @@
except Exception, e:
return 2
- assert self.interpret(func, []) == int(self.GC_CAN_MOVE)
+ assert self.interpret(func, []) == int(self.GC_CANNOT_MALLOC_NONMOVABLE)
def test_resizable_buffer(self):
from pypy.rpython.lltypesystem.rstr import STR
@@ -449,6 +447,7 @@
class TestSemiSpaceGC(GCTest, snippet.SemiSpaceGCTests):
from pypy.rpython.memory.gc.semispace import SemiSpaceGC as GCClass
GC_CAN_MOVE = True
+ GC_CANNOT_MALLOC_NONMOVABLE = True
class TestGrowingSemiSpaceGC(TestSemiSpaceGC):
GC_PARAMS = {'space_size': 64}
@@ -458,6 +457,7 @@
class TestHybridGC(TestGenerationalGC):
from pypy.rpython.memory.gc.hybrid import HybridGC as GCClass
+ GC_CANNOT_MALLOC_NONMOVABLE = False
def test_ref_from_rawmalloced_to_regular(self):
import gc
@@ -520,9 +520,13 @@
res = self.interpret(f, [15])
assert res == 16
+ def test_malloc_nonmovable_fixsize(self):
+ py.test.skip("Not supported")
+
class TestHybridGCSmallHeap(GCTest):
from pypy.rpython.memory.gc.hybrid import HybridGC as GCClass
GC_CAN_MOVE = True
+ GC_CANNOT_MALLOC_NONMOVABLE = False
GC_PARAMS = {'space_size': 192,
'min_nursery_size': 48,
'nursery_size': 48,
@@ -563,3 +567,6 @@
return i
res = self.interpret(f, [200])
assert res == 401
+
+ def test_malloc_nonmovable_fixsize(self):
+ py.test.skip("Not supported")
More information about the Pypy-commit
mailing list