[pypy-svn] r53756 - in pypy/branch/io-improvements/pypy/rpython/memory: gctransform test
fijal at codespeak.net
fijal at codespeak.net
Mon Apr 14 16:03:24 CEST 2008
Author: fijal
Date: Mon Apr 14 16:03:24 2008
New Revision: 53756
Modified:
pypy/branch/io-improvements/pypy/rpython/memory/gctransform/framework.py
pypy/branch/io-improvements/pypy/rpython/memory/gctransform/transform.py
pypy/branch/io-improvements/pypy/rpython/memory/test/test_transformed_gc.py
Log:
* remove coalloc
* add rgc.malloc_nonmoving operation
Modified: pypy/branch/io-improvements/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/memory/gctransform/framework.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/memory/gctransform/framework.py Mon Apr 14 16:03:24 2008
@@ -295,20 +295,6 @@
inline=True)
else:
self.write_barrier_ptr = None
- if hasattr(GCClass, "coalloc_fixedsize_clear"):
- self.coalloc_clear_ptr = getfn(
- GCClass.coalloc_fixedsize_clear.im_func,
- [s_gc, annmodel.SomeAddress(),
- annmodel.SomeInteger(nonneg=True),
- annmodel.SomeInteger(nonneg=True)],
- s_gcref, inline=True)
- self.coalloc_varsize_clear_ptr = getfn(
- GCClass.coalloc_varsize_clear.im_func,
- [s_gc, annmodel.SomeAddress()] +
- [annmodel.SomeInteger(nonneg=True) for i in range(5)],
- s_gcref, inline=True)
- else:
- self.coalloc_clear_ptr = self.coalloc_varsize_clear_ptr = None
self.statistics_ptr = getfn(GCClass.statistics.im_func,
[s_gc, annmodel.SomeInteger()],
annmodel.SomeInteger())
@@ -489,43 +475,6 @@
gct_fv_gc_malloc_varsize = gct_fv_gc_malloc
- def gct_fv_gc_coalloc(self, hop, coallocator, flags, TYPE, *args):
- if self.coalloc_clear_ptr is None:
- return self.gct_fv_gc_malloc(
- hop, flags, TYPE, *args)
- op = hop.spaceop
- flavor = flags['flavor']
- assert not flags.get("nocollect", False)
-
- PTRTYPE = op.result.concretetype
- assert PTRTYPE.TO == TYPE
- type_id = self.get_type_id(TYPE)
-
- c_type_id = rmodel.inputconst(lltype.Signed, type_id)
- info = self.layoutbuilder.type_info_list[type_id]
- c_size = rmodel.inputconst(lltype.Signed, info.fixedsize)
- has_finalizer = bool(self.finalizer_funcptr_for_type(TYPE))
- assert not has_finalizer
-
- v_coallocator = gen_cast(hop.llops, llmemory.Address, coallocator)
-
- if not op.opname.endswith('_varsize'):
- malloc_ptr = self.coalloc_clear_ptr
- args = [self.c_const_gc, v_coallocator, c_type_id, c_size]
- else:
- v_length = op.args[-1]
- c_ofstolength = rmodel.inputconst(lltype.Signed, info.ofstolength)
- c_varitemsize = rmodel.inputconst(lltype.Signed, info.varitemsize)
- malloc_ptr = self.coalloc_varsize_clear_ptr
- args = [self.c_const_gc, v_coallocator, c_type_id, v_length, c_size,
- c_varitemsize, c_ofstolength]
- livevars = self.push_roots(hop)
- v_result = hop.genop("direct_call", [malloc_ptr] + args,
- resulttype=llmemory.GCREF)
- self.pop_roots(hop, livevars)
- return v_result
- gct_fv_gc_coalloc_varsize = gct_fv_gc_coalloc
-
def gct_gc__collect(self, hop):
op = hop.spaceop
livevars = self.push_roots(hop)
@@ -642,6 +591,22 @@
self.c_const_gc,
v_size])
+ def gct_malloc_nonmovable_varsize(self, hop):
+ TYPE = hop.spaceop.result.concretetype
+ if self.gcdata.gc.moving_gc:
+ # first approximation
+ c = rmodel.inputconst(TYPE, lltype.nullptr(TYPE.TO))
+ return hop.cast_result(c)
+ return self.gct_malloc_varsize(hop)
+
+ def gct_malloc_nonmovable(self, hop):
+ TYPE = hop.spaceop.result.concretetype
+ if self.gcdata.gc.moving_gc:
+ # first approximation
+ c = rmodel.inputconst(TYPE, lltype.nullptr(TYPE.TO))
+ return hop.cast_result(c)
+ return self.gct_malloc(hop)
+
def transform_generic_set(self, hop):
from pypy.objspace.flow.model import Constant
opname = hop.spaceop.opname
Modified: pypy/branch/io-improvements/pypy/rpython/memory/gctransform/transform.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/memory/gctransform/transform.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/memory/gctransform/transform.py Mon Apr 14 16:03:24 2008
@@ -491,27 +491,14 @@
assert not TYPE._is_varsize()
flags = hop.spaceop.args[1].value
flavor = flags['flavor']
+ if flavor == 'nonmovable':
+ flavor = 'gc'
meth = getattr(self, 'gct_fv_%s_malloc' % flavor, None)
assert meth, "%s has no support for malloc with flavor %r" % (self, flavor)
c_size = rmodel.inputconst(lltype.Signed, llmemory.sizeof(TYPE))
v_raw = meth(hop, flags, TYPE, c_size)
hop.cast_result(v_raw)
- def gct_coalloc(self, hop):
- TYPE = hop.spaceop.result.concretetype.TO
- assert not TYPE._is_varsize()
- flags = hop.spaceop.args[2].value
- flavor = flags['flavor']
- c_size = rmodel.inputconst(lltype.Signed, llmemory.sizeof(TYPE))
- meth = getattr(self, 'gct_fv_%s_comalloc' % flavor, None)
- if meth is None:
- meth = getattr(self, 'gct_fv_%s_malloc' % flavor, None)
- assert meth, "%s has no support for comalloc with flavor %r" % (self, flavor)
- v_raw = meth(hop, flags, TYPE, c_size)
- else:
- v_raw = meth(hop, hop.spaceop.args[1], flags, TYPE, c_size)
- hop.cast_result(v_raw)
-
def gct_fv_raw_malloc(self, hop, flags, TYPE, c_size):
v_raw = hop.genop("direct_call", [self.raw_malloc_fixedsize_ptr, c_size],
resulttype=llmemory.Address)
@@ -524,9 +511,11 @@
resulttype=llmemory.Address)
if flags.get('zero'):
hop.genop("raw_memclear", [v_raw, c_size])
- return v_raw
+ return v_raw
def gct_malloc_varsize(self, hop):
+ op = hop.spaceop
+ TYPE = op.result.concretetype.TO
flags = hop.spaceop.args[1].value
flavor = flags['flavor']
assert flavor != 'cpy', "cannot malloc CPython objects directly"
@@ -534,19 +523,8 @@
assert meth, "%s has no support for malloc_varsize with flavor %r" % (self, flavor)
return self.varsize_malloc_helper(hop, flags, meth, [])
- def gct_coalloc_varsize(self, hop):
-
- flags = hop.spaceop.args[2].value
- flavor = flags['flavor']
- meth = getattr(self, 'gct_fv_%s_coalloc_varsize' % flavor, None)
- if meth is None:
- meth = getattr(self, 'gct_fv_%s_malloc_varsize' % flavor, None)
- assert meth, "%s has no support for malloc_varsize with flavor %r" % (self, flavor)
- return self.varsize_malloc_helper(hop, flags, meth, [])
- else:
- return self.varsize_malloc_helper(hop, flags, meth,
- [hop.spaceop.args[1]])
-
+ gct_malloc_nonmovable = gct_malloc
+ gct_malloc_nonmovable_varsize = gct_malloc_varsize
def varsize_malloc_helper(self, hop, flags, meth, extraargs):
def intconst(c): return rmodel.inputconst(lltype.Signed, c)
Modified: pypy/branch/io-improvements/pypy/rpython/memory/test/test_transformed_gc.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/memory/test/test_transformed_gc.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/memory/test/test_transformed_gc.py Mon Apr 14 16:03:24 2008
@@ -457,9 +457,61 @@
res = run([])
assert res == self.GC_CAN_MOVE
+ 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
+
+ # this test would have different outcome for different
+ # gcs, please assert differently
+ run = self.runner(func)
+ return run([])
+
+ def _test_malloc_nonmovable_fixsize(self):
+ TP = lltype.GcStruct('T', ('x', lltype.Float))
+ def func():
+ try:
+ from pypy.rlib import rgc
+ a = rgc.malloc_nonmovable(TP)
+ if a:
+ assert not rgc.can_move(a)
+ return 0
+ return 1
+ except Exception, e:
+ return 2
+
+ # this test would have different outcome for different
+ # gcs, please assert differently
+ run = self.runner(func)
+ return run([])
+
+ def test_malloc_nonmovable(self):
+ res = self._test_malloc_nonmovable()
+ if self.GC_CAN_MOVE:
+ expected = 1
+ else:
+ expected = 0
+ assert res == expected
+
+ def test_malloc_nonmovable_fixsize(self):
+ res = self._test_malloc_nonmovable_fixsize()
+ if self.GC_CAN_MOVE:
+ expected = 1
+ else:
+ expected = 0
+ assert res == expected
+
class GenericMovingGCTests(GenericGCTests):
GC_CAN_MOVE = True
-
+
def test_many_ids(self):
py.test.skip("fails for bad reasons in lltype.py :-(")
class A(object):
More information about the Pypy-commit
mailing list