[pypy-svn] r70840 - in pypy/branch/stringbuilder2/pypy: rlib rpython rpython/lltypesystem rpython/memory rpython/memory/gc rpython/memory/gctransform rpython/memory/test
fijal at codespeak.net
fijal at codespeak.net
Mon Jan 25 16:49:23 CET 2010
Author: fijal
Date: Mon Jan 25 16:49:22 2010
New Revision: 70840
Modified:
pypy/branch/stringbuilder2/pypy/rlib/rgc.py
pypy/branch/stringbuilder2/pypy/rpython/llinterp.py
pypy/branch/stringbuilder2/pypy/rpython/lltypesystem/rbuilder.py
pypy/branch/stringbuilder2/pypy/rpython/memory/gc/base.py
pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/transform.py
pypy/branch/stringbuilder2/pypy/rpython/memory/gcwrapper.py
pypy/branch/stringbuilder2/pypy/rpython/memory/test/test_gc.py
Log:
IN-PROGRESS Check in what I have in my wc, so we can pair
Modified: pypy/branch/stringbuilder2/pypy/rlib/rgc.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rlib/rgc.py (original)
+++ pypy/branch/stringbuilder2/pypy/rlib/rgc.py Mon Jan 25 16:49:22 2010
@@ -308,7 +308,7 @@
return hop.genop('resize_buffer', vlist,
resulttype=hop.r_result.lowleveltype)
-def finish_building_buffer(ptr, final_size):
+def finish_building_buffer(ptr, old_size, final_size):
""" Finish building resizable buffer returned by resizable_buffer_of_shape
"""
return ptr
@@ -316,20 +316,24 @@
class FinishBuildingBufferEntry(ExtRegistryEntry):
_about_ = finish_building_buffer
- def compute_result_annotation(self, s_arr, s_final_size):
+ def compute_result_annotation(self, s_arr, s_old_size, s_final_size):
from pypy.annotation.model import SomePtr, s_ImpossibleValue,\
SomeInteger
assert isinstance(s_arr, SomePtr)
+ assert isinstance(s_old_size, SomeInteger)
assert isinstance(s_final_size, SomeInteger)
return s_arr
def specialize_call(self, hop):
from pypy.rpython.lltypesystem import lltype
vlist = [hop.inputarg(hop.args_r[0], 0),
- hop.inputarg(hop.args_r[1], 1)]
- hop.exception_cannot_occur()
- return hop.genop('finish_building_buffer', vlist,
- resulttype=hop.r_result.lowleveltype)
+ hop.inputarg(hop.args_r[1], 1),
+ hop.inputarg(hop.args_r[2], 2)]
+ hop.exception_is_here()
+ res = hop.genop('finish_building_buffer', vlist,
+ resulttype=hop.r_result.lowleveltype)
+ hop.genop('keepalive', [hop.args_v[0]])
+ return res
def ll_arraycopy(source, dest, source_start, dest_start, length):
from pypy.rpython.lltypesystem.lloperation import llop
Modified: pypy/branch/stringbuilder2/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/llinterp.py (original)
+++ pypy/branch/stringbuilder2/pypy/rpython/llinterp.py Mon Jan 25 16:49:22 2010
@@ -754,8 +754,8 @@
def op_resize_buffer(self, obj, old_size, new_size):
return self.heap.resize_buffer(obj, old_size, new_size)
- def op_finish_building_buffer(self, obj, size):
- return self.heap.finish_building_buffer(obj, size)
+ def op_finish_building_buffer(self, obj, oldsize, size):
+ return self.heap.finish_building_buffer(obj, oldsize, size)
def op_free(self, obj, flavor):
assert isinstance(flavor, str)
Modified: pypy/branch/stringbuilder2/pypy/rpython/lltypesystem/rbuilder.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/lltypesystem/rbuilder.py (original)
+++ pypy/branch/stringbuilder2/pypy/rpython/lltypesystem/rbuilder.py Mon Jan 25 16:49:22 2010
@@ -99,7 +99,8 @@
@staticmethod
def ll_build(ll_builder):
final_size = ll_builder.used
- return rgc.finish_building_buffer(ll_builder.buf, final_size)
+ return rgc.finish_building_buffer(ll_builder.buf, ll_builder.allocated,
+ final_size)
class StringBuilderRepr(BaseStringBuilderRepr):
lowleveltype = lltype.Ptr(STRINGBUILDER)
Modified: pypy/branch/stringbuilder2/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/memory/gc/base.py (original)
+++ pypy/branch/stringbuilder2/pypy/rpython/memory/gc/base.py Mon Jan 25 16:49:22 2010
@@ -135,29 +135,6 @@
# lots of cast and reverse-cast around...
return llmemory.cast_ptr_to_adr(ref)
- def realloc(self, source, oldlength, newlength, fixedsize, itemsize,
- lengthofs, itemsofs, grow):
- # by default, realloc mallocs stuff and copies it over when growing.
- # when shrinking, we only change length and be happy
- source_adr = llmemory.cast_ptr_to_adr(source)
- type_id = self.get_type_id(source_adr)
- if not hasattr(self, 'malloc_varsize'):
- malloc_varsize = self.malloc_varsize_clear
- else:
- malloc_varsize = self.malloc_varsize
- typeid = self.get_type_id(source_adr)
- if grow:
- dest = malloc_varsize(typeid, newlength, fixedsize, itemsize,
- lengthofs, True)
- dest_adr = llmemory.cast_ptr_to_adr(dest)
- llmemory.raw_memcopy(source_adr + itemsofs, dest_adr + itemsofs,
- itemsize * oldlength)
- keepalive_until_here(source)
- else:
- (source_adr + lengthofs).signed[0] = newlength
- dest = source
- return dest
-
def malloc_nonmovable(self, typeid, length=0, zero=False):
return self.malloc(typeid, length, zero)
Modified: pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/transform.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/transform.py (original)
+++ pypy/branch/stringbuilder2/pypy/rpython/memory/gctransform/transform.py Mon Jan 25 16:49:22 2010
@@ -576,36 +576,31 @@
def gct_resize_buffer(self, hop):
op = hop.spaceop
- if self._can_realloc():
- self._gct_resize_buffer_realloc(hop, op.args[1], op.args[2], True)
- else:
- self._gct_resize_buffer_no_realloc(hop, op.args[1])
-
- def _can_realloc(self):
- return False
+ # if we want to support a general realloc, support goes here
+ self._malloc_and_copy(hop, op.args[1], op.args[2])
- def _gct_resize_buffer_realloc(self, hop, v_oldsize, v_newsize, grow=True):
- def intconst(c): return rmodel.inputconst(lltype.Signed, c)
- op = hop.spaceop
- flags = {'flavor':'gc', 'varsize': True}
- TYPE = op.args[0].concretetype.TO
- ARRAY = TYPE._flds[TYPE._arrayfld]
- offset_to_length = llmemory.FieldOffset(TYPE, TYPE._arrayfld) + \
- llmemory.ArrayLengthOffset(ARRAY)
- c_const_size = intconst(llmemory.sizeof(TYPE, 0))
- c_item_size = intconst(llmemory.sizeof(ARRAY.OF))
-
- c_lengthofs = intconst(offset_to_length)
- c_itemsofs = intconst(llmemory.itemoffsetof(TYPE, 0))
- v_ptr = op.args[0]
- v_ptr = gen_cast(hop.llops, llmemory.GCREF, v_ptr)
- c_grow = rmodel.inputconst(lltype.Bool, grow)
- v_raw = self.perform_realloc(hop, v_ptr, v_oldsize, v_newsize,
- c_const_size, c_item_size, c_lengthofs,
- c_itemsofs, c_grow)
- hop.cast_result(v_raw)
+ # def _malloc_and_copy(self, hop, v_oldsize, v_newsize, grow=True):
+ # def intconst(c): return rmodel.inputconst(lltype.Signed, c)
+ # op = hop.spaceop
+ # flags = {'flavor':'gc', 'varsize': True}
+ # TYPE = op.args[0].concretetype.TO
+ # ARRAY = TYPE._flds[TYPE._arrayfld]
+ # offset_to_length = llmemory.FieldOffset(TYPE, TYPE._arrayfld) + \
+ # llmemory.ArrayLengthOffset(ARRAY)
+ # c_const_size = intconst(llmemory.sizeof(TYPE, 0))
+ # c_item_size = intconst(llmemory.sizeof(ARRAY.OF))
+
+ # c_lengthofs = intconst(offset_to_length)
+ # c_itemsofs = intconst(llmemory.itemoffsetof(TYPE, 0))
+ # v_ptr = op.args[0]
+ # v_ptr = gen_cast(hop.llops, llmemory.GCREF, v_ptr)
+ # c_grow = rmodel.inputconst(lltype.Bool, grow)
+ # v_raw = self.perform_realloc(hop, v_ptr, v_oldsize, v_newsize,
+ # c_const_size, c_item_size, c_lengthofs,
+ # c_itemsofs, c_grow)
+ # hop.cast_result(v_raw)
- def _gct_resize_buffer_no_realloc(self, hop, v_lgt):
+ def _malloc_and_copy(self, hop, v_lgt):
op = hop.spaceop
meth = self.gct_fv_gc_malloc_varsize
flags = {'flavor':'gc', 'varsize': True, 'keep_current_args': True}
@@ -634,6 +629,7 @@
hop.genop('raw_memcopy', vlist)
def gct_finish_building_buffer(self, hop):
+ xxx
op = hop.spaceop
if self._can_realloc():
return self._gct_resize_buffer_realloc(hop, op.args[1],
Modified: pypy/branch/stringbuilder2/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/memory/gcwrapper.py (original)
+++ pypy/branch/stringbuilder2/pypy/rpython/memory/gcwrapper.py Mon Jan 25 16:49:22 2010
@@ -4,7 +4,6 @@
from pypy.rpython.memory import gctypelayout
from pypy.objspace.flow.model import Constant
-
class GCManagedHeap(object):
def __init__(self, llinterp, flowgraphs, gc_class, GC_PARAMS={}):
@@ -70,28 +69,22 @@
def resize_buffer(self, obj, oldlength, newlength):
T = lltype.typeOf(obj).TO
ARRAY = getattr(T, T._arrayfld)
+ addr = llmemory.cast_ptr_to_adr(obj)
+ newaddr = self.gc.malloc(self.gc.get_type_id(addr), newlength, True)
+ addr = llmemory.cast_ptr_to_adr(obj)
itemsofs = (llmemory.FieldOffset(T, T._arrayfld) +
llmemory.itemoffsetof(ARRAY, 0))
- fixedsize = llmemory.sizeof(T, 0)
- itemsize = llmemory.sizeof(ARRAY.OF)
- lengthofs = llmemory.FieldOffset(T, T._arrayfld) + \
- llmemory.ArrayLengthOffset(ARRAY)
- result = self.gc.realloc(obj, oldlength, newlength, fixedsize,
- itemsize, lengthofs, itemsofs, True)
- return lltype.cast_opaque_ptr(lltype.typeOf(obj), result)
-
- def finish_building_buffer(self, obj, newlength):
- T = lltype.typeOf(obj).TO
- ARRAY = getattr(T, T._arrayfld)
- itemsofs = (llmemory.FieldOffset(T, T._arrayfld) +
- llmemory.itemoffsetof(ARRAY, 0))
- fixedsize = llmemory.sizeof(T, 0)
itemsize = llmemory.sizeof(ARRAY.OF)
- lengthofs = llmemory.FieldOffset(T, T._arrayfld) + \
- llmemory.ArrayLengthOffset(ARRAY)
- result = self.gc.realloc(obj, 0, newlength, fixedsize,
- itemsize, lengthofs, itemsofs, False)
- return lltype.cast_opaque_ptr(lltype.typeOf(obj), result)
+ tocopy = min(newlength, oldlength)
+ llmemory.raw_memcopy(addr + itemsofs, newaddr + itemsofs,
+ tocopy * itemsize)
+ return llmemory.cast_adr_to_ptr(newaddr, lltype.Ptr(T))
+
+ def finish_building_buffer(self, obj, oldlength, newlength):
+ if hasattr(self.gc, 'realloc_shrink'):
+ xxx
+ else:
+ return self.resize_buffer(obj, oldlength, newlength)
def free(self, TYPE, flavor='gc'):
assert flavor != 'gc'
Modified: pypy/branch/stringbuilder2/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/branch/stringbuilder2/pypy/rpython/memory/test/test_gc.py (original)
+++ pypy/branch/stringbuilder2/pypy/rpython/memory/test/test_gc.py Mon Jan 25 16:49:22 2010
@@ -571,20 +571,20 @@
self.interpret(fn, [])
- def test_stringbuilder(self):
- def fn():
- s = StringBuilder(4)
- s.append("abcd")
- s.append("defg")
- s.append("rty")
- s.append_multiple_char('y', 1000)
- rgc.collect()
- s.append_multiple_char('y', 1000)
- res = s.build()[1000]
- rgc.collect()
- return ord(res)
- res = self.interpret(fn, [])
- assert res == ord('y')
+ # def test_stringbuilder(self):
+ # def fn():
+ # s = StringBuilder(4)
+ # s.append("abcd")
+ # s.append("defg")
+ # s.append("rty")
+ # s.append_multiple_char('y', 1000)
+ # rgc.collect()
+ # s.append_multiple_char('y', 1000)
+ # res = s.build()[1000]
+ # rgc.collect()
+ # return ord(res)
+ # res = self.interpret(fn, [])
+ # assert res == ord('y')
from pypy.rlib.objectmodel import UnboxedValue
More information about the Pypy-commit
mailing list