[pypy-svn] r79676 - in pypy/branch/jit-free-asm2/pypy/jit/backend/llsupport: . test

arigo at codespeak.net arigo at codespeak.net
Tue Nov 30 15:10:02 CET 2010


Author: arigo
Date: Tue Nov 30 15:09:48 2010
New Revision: 79676

Modified:
   pypy/branch/jit-free-asm2/pypy/jit/backend/llsupport/gc.py
   pypy/branch/jit-free-asm2/pypy/jit/backend/llsupport/test/test_gc.py
Log:
Re-simplify the interface in the llsupport/gc module: compress
the call shapes one by one again.


Modified: pypy/branch/jit-free-asm2/pypy/jit/backend/llsupport/gc.py
==============================================================================
--- pypy/branch/jit-free-asm2/pypy/jit/backend/llsupport/gc.py	(original)
+++ pypy/branch/jit-free-asm2/pypy/jit/backend/llsupport/gc.py	Tue Nov 30 15:09:48 2010
@@ -222,7 +222,7 @@
     LOC_EBP_MINUS = 3
 
     GCMAP_ARRAY = rffi.CArray(lltype.Signed)
-    CALLSHAPE_ARRAY = rffi.CArray(rffi.UCHAR)
+    CALLSHAPE_ARRAY_PTR = rffi.CArrayPtr(rffi.UCHAR)
 
     def __init__(self):
         # '_gcmap' is an array of length '_gcmap_maxlength' of addresses.
@@ -264,8 +264,7 @@
         self._gcmap_sorted = True
         return sorted
 
-    @rgc.no_collect
-    def _put(self, retaddr, callshapeaddr):
+    def put(self, retaddr, callshapeaddr):
         """'retaddr' is the address just after the CALL.
         'callshapeaddr' is the address of the raw 'shape' marker.
         Both addresses are actually integers here."""
@@ -308,37 +307,6 @@
                 lltype.free(oldgcmap, flavor='raw', track_allocation=False)
         return j
 
-    def add_raw_gcroot_markers(self, asmmemmgr, allblocks,
-                               markers, total_size, rawstart):
-        """The interface is a bit custom, but this routine writes the
-        shapes of gcroots (for the GC to use) into raw memory."""
-        # xxx so far, we never try to share them.  But right now
-        # the amount of potential sharing would not be too large.
-        dst = 1
-        stop = 0
-        for relpos, shape in markers:
-            #
-            if dst + len(shape) > stop:
-                # No more space in the previous raw block,
-                # allocate a raw block of memory big enough to fit
-                # as many of the remaining 'shapes' as possible
-                start, stop = asmmemmgr.malloc(len(shape), total_size)
-                # add the raw block to 'compiled_loop_token.asmmemmgr_blocks'
-                allblocks.append((start, stop))
-                dst = start
-            #
-            # add the entry 'pos_after_call -> dst' to the table
-            self._put(rawstart + relpos, dst)
-            # Copy 'shape' into the raw memory, reversing the order
-            # of the bytes.  Similar to compress_callshape() in
-            # trackgcroot.py.
-            total_size -= len(shape)
-            src = len(shape) - 1
-            while src >= 0:
-                rffi.cast(rffi.CCHARP, dst)[0] = shape[src]
-                dst += 1
-                src -= 1
-
     @rgc.no_collect
     def freeing_block(self, start, stop):
         # if [start:stop] is a raw block of assembler, then look up the
@@ -409,6 +377,16 @@
         assert reg_index > 0
         shape.append(chr(self.LOC_REG | (reg_index << 2)))
 
+    def compress_callshape(self, shape, datablockwrapper):
+        # Similar to compress_callshape() in trackgcroot.py.
+        # Returns an address to raw memory (as an integer).
+        length = len(shape)
+        rawaddr = datablockwrapper.malloc_aligned(length, 1)
+        p = rffi.cast(self.CALLSHAPE_ARRAY_PTR, rawaddr)
+        for i in range(length):
+            p[length-1-i] = rffi.cast(rffi.UCHAR, shape[i])
+        return rawaddr
+
 
 class WriteBarrierDescr(AbstractDescr):
     def __init__(self, gc_ll_descr):

Modified: pypy/branch/jit-free-asm2/pypy/jit/backend/llsupport/test/test_gc.py
==============================================================================
--- pypy/branch/jit-free-asm2/pypy/jit/backend/llsupport/test/test_gc.py	(original)
+++ pypy/branch/jit-free-asm2/pypy/jit/backend/llsupport/test/test_gc.py	Tue Nov 30 15:09:48 2010
@@ -91,11 +91,27 @@
         assert shape == map(chr, [6, 7, 11, 15, 2, 0, num1a, num2b, num2a,
                                   4, 8, 12, 16])
 
+    def test_compress_callshape(self):
+        class FakeDataBlockWrapper:
+            def malloc_aligned(self, size, alignment):
+                assert alignment == 1    # here
+                assert size == 4
+                return rffi.cast(lltype.Signed, p)
+        datablockwrapper = FakeDataBlockWrapper()
+        p = lltype.malloc(rffi.CArray(lltype.Char), 4, immortal=True)
+        gcrootmap = GcRootMap_asmgcc()
+        shape = ['a', 'b', 'c', 'd']
+        gcrootmap.compress_callshape(shape, datablockwrapper)
+        assert p[0] == 'd'
+        assert p[1] == 'c'
+        assert p[2] == 'b'
+        assert p[3] == 'a'
+
     def test_put_basic(self):
         gcrootmap = GcRootMap_asmgcc()
         retaddr = 1234567890
         shapeaddr = 51627384
-        gcrootmap._put(retaddr, shapeaddr)
+        gcrootmap.put(retaddr, shapeaddr)
         assert gcrootmap._gcmap[0] == retaddr
         assert gcrootmap._gcmap[1] == shapeaddr
         p = rffi.cast(rffi.LONGP, gcrootmap.gcmapstart())
@@ -109,7 +125,7 @@
         for i in range(700):
             shapeaddr = i * 100 + 1
             retaddr = 123456789 + i
-            gcrootmap._put(retaddr, shapeaddr)
+            gcrootmap.put(retaddr, shapeaddr)
         for i in range(700):
             assert gcrootmap._gcmap[i*2+0] == 123456789 + i
             assert gcrootmap._gcmap[i*2+1] == i * 100 + 1
@@ -126,7 +142,7 @@
         for i in range(700):
             shapeaddr = i * 100       # 0 if i == 0
             retaddr = 123456789 + i
-            gcrootmap._put(retaddr, shapeaddr)
+            gcrootmap.put(retaddr, shapeaddr)
             if shapeaddr != 0:
                 expected.append((retaddr, shapeaddr))
         # at the first resize, the 0 should be removed
@@ -142,72 +158,11 @@
             # check that we can again insert 350 entries without a resize
             oldgcmap = gcrootmap._gcmap
             for i in range(0, 699, 2):
-                gcrootmap._put(515151 + i + repeat, 626262 + i)
+                gcrootmap.put(515151 + i + repeat, 626262 + i)
                 expected.append((515151 + i + repeat, 626262 + i))
             assert gcrootmap._gcmap == oldgcmap
             check()
 
-    def test_add_raw_gcroot_markers_maxalloc(self):
-        class FakeAsmMemMgr:
-            def malloc(self, minsize, maxsize):
-                assert minsize == 4
-                assert maxsize == 7
-                return (prawstart, prawstart + 8)
-        put = []
-        def fakeput(a, b):
-            put.append((a, b))
-        gcrootmap = GcRootMap_asmgcc()
-        gcrootmap._put = fakeput
-        memmgr = FakeAsmMemMgr()
-        allblocks = []
-        p = lltype.malloc(rffi.CArray(lltype.Char), 7, immortal=True)
-        prawstart = rffi.cast(lltype.Signed, p)
-        gcrootmap.add_raw_gcroot_markers(memmgr, allblocks,
-                                         [(2, ['a', 'b', 'c', 'd']),
-                                          (4, ['e', 'f', 'g'])],
-                                         4 + 3, 1200000)
-        assert allblocks == [(prawstart, prawstart + 8)]
-        assert ''.join([p[i] for i in range(7)]) == 'dcbagfe'
-        assert put == [(1200002, prawstart),
-                       (1200004, prawstart + 4)]
-
-    def test_add_raw_gcroot_markers_minalloc(self):
-        class FakeAsmMemMgr:
-            callnum = 0
-            def malloc(self, minsize, maxsize):
-                self.callnum += 1
-                if self.callnum == 1:
-                    assert minsize == 4
-                    assert maxsize == 7
-                    return (prawstart, prawstart + 6)
-                elif self.callnum == 2:
-                    assert minsize == 3
-                    assert maxsize == 3
-                    return (qrawstart, qrawstart + 5)
-                else:
-                    raise AssertionError
-        put = []
-        def fakeput(a, b):
-            put.append((a, b))
-        gcrootmap = GcRootMap_asmgcc()
-        gcrootmap._put = fakeput
-        memmgr = FakeAsmMemMgr()
-        allblocks = []
-        p = lltype.malloc(rffi.CArray(lltype.Char), 6, immortal=True)
-        prawstart = rffi.cast(lltype.Signed, p)
-        q = lltype.malloc(rffi.CArray(lltype.Char), 5, immortal=True)
-        qrawstart = rffi.cast(lltype.Signed, q)
-        gcrootmap.add_raw_gcroot_markers(memmgr, allblocks,
-                                         [(2, ['a', 'b', 'c', 'd']),
-                                          (4, ['e', 'f', 'g'])],
-                                         4 + 3, 1200000)
-        assert allblocks == [(prawstart, prawstart + 6),
-                             (qrawstart, qrawstart + 5)]
-        assert ''.join([p[i] for i in range(4)]) == 'dcba'
-        assert ''.join([q[i] for i in range(3)]) == 'gfe'
-        assert put == [(1200002, prawstart),
-                       (1200004, qrawstart)]
-
     def test_freeing_block(self):
         from pypy.jit.backend.llsupport import gc
         class Asmgcroot:



More information about the Pypy-commit mailing list