[pypy-commit] pypy stm: Yay, test_ztranslation passes. The issue was direct memcpy on STRs,
arigo
noreply at buildbot.pypy.org
Sat Nov 5 18:36:09 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r48800:e23ab2c195c1
Date: 2011-11-05 18:35 +0100
http://bitbucket.org/pypy/pypy/changeset/e23ab2c195c1/
Log: Yay, test_ztranslation passes. The issue was direct memcpy on STRs,
which don't work any more right now.
diff --git a/pypy/rlib/rgc.py b/pypy/rlib/rgc.py
--- a/pypy/rlib/rgc.py
+++ b/pypy/rlib/rgc.py
@@ -154,29 +154,33 @@
assert (source_start + length <= dest_start or
dest_start + length <= source_start)
- TP = lltype.typeOf(source).TO
- assert TP == lltype.typeOf(dest).TO
- if isinstance(TP.OF, lltype.Ptr) and TP.OF.TO._gckind == 'gc':
- # perform a write barrier that copies necessary flags from
- # source to dest
- if not llop.gc_writebarrier_before_copy(lltype.Bool, source, dest,
- source_start, dest_start,
- length):
- # if the write barrier is not supported, copy by hand
- for i in range(length):
- dest[i + dest_start] = source[i + source_start]
- return
- source_addr = llmemory.cast_ptr_to_adr(source)
- dest_addr = llmemory.cast_ptr_to_adr(dest)
- cp_source_addr = (source_addr + llmemory.itemoffsetof(TP, 0) +
- llmemory.sizeof(TP.OF) * source_start)
- cp_dest_addr = (dest_addr + llmemory.itemoffsetof(TP, 0) +
- llmemory.sizeof(TP.OF) * dest_start)
+ # XXX --- custom version for STM ---
+ # the old version first:
+## TP = lltype.typeOf(source).TO
+## assert TP == lltype.typeOf(dest).TO
+## if isinstance(TP.OF, lltype.Ptr) and TP.OF.TO._gckind == 'gc':
+## # perform a write barrier that copies necessary flags from
+## # source to dest
+## if not llop.gc_writebarrier_before_copy(lltype.Bool, source, dest,
+## source_start, dest_start,
+## length):
+## # if the write barrier is not supported, copy by hand
+## for i in range(length):
+## dest[i + dest_start] = source[i + source_start]
+## return
+## source_addr = llmemory.cast_ptr_to_adr(source)
+## dest_addr = llmemory.cast_ptr_to_adr(dest)
+## cp_source_addr = (source_addr + llmemory.itemoffsetof(TP, 0) +
+## llmemory.sizeof(TP.OF) * source_start)
+## cp_dest_addr = (dest_addr + llmemory.itemoffsetof(TP, 0) +
+## llmemory.sizeof(TP.OF) * dest_start)
- llmemory.raw_memcopy(cp_source_addr, cp_dest_addr,
- llmemory.sizeof(TP.OF) * length)
- keepalive_until_here(source)
- keepalive_until_here(dest)
+## llmemory.raw_memcopy(cp_source_addr, cp_dest_addr,
+## llmemory.sizeof(TP.OF) * length)
+## keepalive_until_here(source)
+## keepalive_until_here(dest)
+ for i in range(length):
+ dest[i + dest_start] = source[i + source_start]
def ll_shrink_array(p, smallerlength):
from pypy.rpython.lltypesystem.lloperation import llop
@@ -195,16 +199,24 @@
field = getattr(p, TP._names[0])
setattr(newp, TP._names[0], field)
- ARRAY = getattr(TP, TP._arrayfld)
- offset = (llmemory.offsetof(TP, TP._arrayfld) +
- llmemory.itemoffsetof(ARRAY, 0))
- source_addr = llmemory.cast_ptr_to_adr(p) + offset
- dest_addr = llmemory.cast_ptr_to_adr(newp) + offset
- llmemory.raw_memcopy(source_addr, dest_addr,
- llmemory.sizeof(ARRAY.OF) * smallerlength)
+ # XXX --- custom version for STM ---
+ # the old version first:
+## ARRAY = getattr(TP, TP._arrayfld)
+## offset = (llmemory.offsetof(TP, TP._arrayfld) +
+## llmemory.itemoffsetof(ARRAY, 0))
+## source_addr = llmemory.cast_ptr_to_adr(p) + offset
+## dest_addr = llmemory.cast_ptr_to_adr(newp) + offset
+## llmemory.raw_memcopy(source_addr, dest_addr,
+## llmemory.sizeof(ARRAY.OF) * smallerlength)
- keepalive_until_here(p)
- keepalive_until_here(newp)
+## keepalive_until_here(p)
+## keepalive_until_here(newp)
+
+ i = 0
+ while i < smallerlength:
+ newp.chars[i] = p.chars[i]
+ i += 1
+
return newp
ll_shrink_array._annspecialcase_ = 'specialize:ll'
ll_shrink_array._jit_look_inside_ = False
diff --git a/pypy/rpython/lltypesystem/rffi.py b/pypy/rpython/lltypesystem/rffi.py
--- a/pypy/rpython/lltypesystem/rffi.py
+++ b/pypy/rpython/lltypesystem/rffi.py
@@ -698,7 +698,10 @@
string is already nonmovable. Must be followed by a
free_nonmovingbuffer call.
"""
- if rgc.can_move(data):
+ # XXX --- custom version for STM ---
+ # disabled the "else" part
+ ##if rgc.can_move(data):
+ if 1:
count = len(data)
buf = lltype.malloc(TYPEP.TO, count, flavor='raw')
for i in range(count):
@@ -720,11 +723,14 @@
# if 'buf' points inside 'data'. This is only possible if we
# followed the 2nd case in get_nonmovingbuffer(); in the first case,
# 'buf' points to its own raw-malloced memory.
- data = llstrtype(data)
- data_start = cast_ptr_to_adr(data) + \
- offsetof(STRTYPE, 'chars') + itemoffsetof(STRTYPE.chars, 0)
- followed_2nd_path = (buf == cast(TYPEP, data_start))
- keepalive_until_here(data)
+
+ # XXX --- custom version for STM ---
+## data = llstrtype(data)
+## data_start = cast_ptr_to_adr(data) + \
+## offsetof(STRTYPE, 'chars') + itemoffsetof(STRTYPE.chars, 0)
+## followed_2nd_path = (buf == cast(TYPEP, data_start))
+## keepalive_until_here(data)
+ followed_2nd_path = False
if not followed_2nd_path:
lltype.free(buf, flavor='raw')
free_nonmovingbuffer._annenforceargs_ = [strtype, None]
diff --git a/pypy/rpython/lltypesystem/rstr.py b/pypy/rpython/lltypesystem/rstr.py
--- a/pypy/rpython/lltypesystem/rstr.py
+++ b/pypy/rpython/lltypesystem/rstr.py
@@ -65,11 +65,17 @@
assert srcstart >= 0
assert dststart >= 0
assert length >= 0
- src = llmemory.cast_ptr_to_adr(src) + _str_ofs(srcstart)
- dst = llmemory.cast_ptr_to_adr(dst) + _str_ofs(dststart)
- llmemory.raw_memcopy(src, dst, llmemory.sizeof(CHAR_TP) * length)
- keepalive_until_here(src)
- keepalive_until_here(dst)
+ # XXX --- custom version for STM ---
+ # the old version first:
+## src = llmemory.cast_ptr_to_adr(src) + _str_ofs(srcstart)
+## dst = llmemory.cast_ptr_to_adr(dst) + _str_ofs(dststart)
+## llmemory.raw_memcopy(src, dst, llmemory.sizeof(CHAR_TP) * length)
+## keepalive_until_here(src)
+## keepalive_until_here(dst)
+ i = 0
+ while i < length:
+ dst.chars[dststart + i] = src.chars[srcstart + i]
+ i += 1
copy_string_contents._always_inline_ = True
return func_with_new_name(copy_string_contents, 'copy_%s_contents' % name)
diff --git a/pypy/rpython/memory/gctransform/transform.py b/pypy/rpython/memory/gctransform/transform.py
--- a/pypy/rpython/memory/gctransform/transform.py
+++ b/pypy/rpython/memory/gctransform/transform.py
@@ -628,11 +628,7 @@
assert False, "%s has no support for free with flavor %r" % (self, flavor)
def gct_gc_can_move(self, hop):
- #return hop.cast_result(rmodel.inputconst(lltype.Bool, False))
- # XXX hack: in case of STM, we cannot pass a pointer inside a
- # GcStruct or GcArray to the C world, because some of the
- # content may still live in the STM buffers
- return hop.cast_result(rmodel.inputconst(lltype.Bool, True))
+ return hop.cast_result(rmodel.inputconst(lltype.Bool, False))
def gct_shrink_array(self, hop):
return hop.cast_result(rmodel.inputconst(lltype.Bool, False))
diff --git a/pypy/translator/c/funcgen.py b/pypy/translator/c/funcgen.py
--- a/pypy/translator/c/funcgen.py
+++ b/pypy/translator/c/funcgen.py
@@ -591,8 +591,14 @@
return '%s = %s.length;'%(self.expr(op.result), expr)
+ def _is_stm(self):
+ return getattr(self.db.translator, 'stm_transformation_applied', False)
+
def _OP_STM(self, op):
if not hasattr(self, 'op_stm'):
+ if not self._is_stm():
+ raise AssertionError("STM transformation not applied. "
+ "You need '--stm'")
from pypy.translator.stm.funcgen import op_stm
self.__class__.op_stm = op_stm
return self.op_stm(op)
@@ -681,10 +687,16 @@
self.expr(op.args[0])))
return '\t'.join(result)
- OP_CAST_PTR_TO_ADR = OP_CAST_POINTER
OP_CAST_ADR_TO_PTR = OP_CAST_POINTER
OP_CAST_OPAQUE_PTR = OP_CAST_POINTER
+ def OP_CAST_PTR_TO_ADR(self, op):
+ if self.lltypemap(op.args[0]).TO._gckind == 'gc' and self._is_stm():
+ raise AssertionError("cast_ptr_to_adr(gcref) is a bad idea "
+ "with STM. Consider checking config.stm "
+ "in %r" % (self.graph,))
+ return self.OP_CAST_POINTER(op)
+
def OP_CAST_INT_TO_PTR(self, op):
TYPE = self.lltypemap(op.result)
typename = self.db.gettype(TYPE)
diff --git a/pypy/translator/stm/funcgen.py b/pypy/translator/stm/funcgen.py
--- a/pypy/translator/stm/funcgen.py
+++ b/pypy/translator/stm/funcgen.py
@@ -167,7 +167,5 @@
def op_stm(funcgen, op):
- if not getattr(funcgen.db.translator, 'stm_transformation_applied', None):
- raise AssertionError("STM transformation not applied. You need '--stm'")
func = globals()[op.opname]
return func(funcgen, op)
More information about the pypy-commit
mailing list