[pypy-svn] pypy default: Test and fix: fastpath_malloc_varsize() used to not align the request
arigo
commits-noreply at bitbucket.org
Mon Apr 18 13:55:36 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r43443:407d02bfd2a7
Date: 2011-04-18 13:54 +0200
http://bitbucket.org/pypy/pypy/changeset/407d02bfd2a7/
Log: Test and fix: fastpath_malloc_varsize() used to not align the
request to a multiple of WORD. This gives unaligned nursery
pointers :-(
diff --git a/pypy/jit/backend/x86/assembler.py b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -2090,6 +2090,7 @@
def malloc_cond(self, nursery_free_adr, nursery_top_adr, size, tid):
size = max(size, self.cpu.gc_ll_descr.minimal_size_in_nursery)
+ size = (size + WORD-1) & ~(WORD-1) # round up
self.mc.MOV(eax, heap(nursery_free_adr))
self.mc.LEA_rm(edx.value, (eax.value, size))
self.mc.CMP(edx, heap(nursery_top_adr))
diff --git a/pypy/jit/backend/x86/test/test_gc_integration.py b/pypy/jit/backend/x86/test/test_gc_integration.py
--- a/pypy/jit/backend/x86/test/test_gc_integration.py
+++ b/pypy/jit/backend/x86/test/test_gc_integration.py
@@ -326,6 +326,8 @@
ARRAY = lltype.GcArray(lltype.Signed)
arraydescr = cpu.arraydescrof(ARRAY)
self.arraydescr = arraydescr
+ ARRAYCHAR = lltype.GcArray(lltype.Char)
+ arraychardescr = cpu.arraydescrof(ARRAYCHAR)
self.namespace = locals().copy()
@@ -388,3 +390,24 @@
finish(p0)
'''
py.test.raises(Seen, self.interpret, ops, [])
+
+ def test_malloc_array_of_char(self):
+ # check that fastpath_malloc_varsize() respects the alignment
+ # of the pointer in the nursery
+ ops = '''
+ []
+ p1 = new_array(1, descr=arraychardescr)
+ p2 = new_array(2, descr=arraychardescr)
+ p3 = new_array(3, descr=arraychardescr)
+ p4 = new_array(4, descr=arraychardescr)
+ finish(p1, p2, p3, p4)
+ '''
+ self.interpret(ops, [])
+ p1 = self.getptr(0, llmemory.GCREF)
+ p2 = self.getptr(1, llmemory.GCREF)
+ p3 = self.getptr(2, llmemory.GCREF)
+ p4 = self.getptr(3, llmemory.GCREF)
+ assert p1._obj.intval & (WORD-1) == 0 # aligned
+ assert p2._obj.intval & (WORD-1) == 0 # aligned
+ assert p3._obj.intval & (WORD-1) == 0 # aligned
+ assert p4._obj.intval & (WORD-1) == 0 # aligned
More information about the Pypy-commit
mailing list