[pypy-svn] r69973 - in pypy/branch/listcopyop/pypy: rlib rpython rpython/lltypesystem rpython/memory rpython/memory/gc rpython/memory/gctransform rpython/memory/test

fijal at codespeak.net fijal at codespeak.net
Tue Dec 8 11:30:10 CET 2009


Author: fijal
Date: Tue Dec  8 11:30:09 2009
New Revision: 69973

Modified:
   pypy/branch/listcopyop/pypy/rlib/rgc.py
   pypy/branch/listcopyop/pypy/rpython/llinterp.py
   pypy/branch/listcopyop/pypy/rpython/lltypesystem/lloperation.py
   pypy/branch/listcopyop/pypy/rpython/lltypesystem/opimpl.py
   pypy/branch/listcopyop/pypy/rpython/memory/gc/generation.py
   pypy/branch/listcopyop/pypy/rpython/memory/gctransform/framework.py
   pypy/branch/listcopyop/pypy/rpython/memory/gctransform/transform.py
   pypy/branch/listcopyop/pypy/rpython/memory/gcwrapper.py
   pypy/branch/listcopyop/pypy/rpython/memory/test/test_gc.py
   pypy/branch/listcopyop/pypy/rpython/memory/test/test_transformed_gc.py
Log:
Kill a lot of code :-)
Change arraycopy into arraycopy_writebarrier that only does the gc part
(after which it's safe to do raw_memcopy, provided there is no collection
in between).


Modified: pypy/branch/listcopyop/pypy/rlib/rgc.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rlib/rgc.py	(original)
+++ pypy/branch/listcopyop/pypy/rlib/rgc.py	Tue Dec  8 11:30:09 2009
@@ -336,15 +336,9 @@
     assert source != dest
     TP = lltype.typeOf(source).TO
     if isinstance(TP.OF, lltype.Ptr) and TP.OF.TO._gckind == 'gc':
-        if llop.gc_arraycopy(lltype.Void, source, dest, source_start, dest_start,
-                            length):
-            return # gc supports nicely copying lists
-        i = 0
-        while i < length:
-            dest[i + dest_start] = source[i + source_start]
-            i += 1
-        return
-    # it's safe to do memcpy
+        # perform a write barrier that copies necessary flags from
+        # source to dest
+        llop.gc_arraycopy_writebarrier(lltype.Void, source, dest)
     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) +

Modified: pypy/branch/listcopyop/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/llinterp.py	(original)
+++ pypy/branch/listcopyop/pypy/rpython/llinterp.py	Tue Dec  8 11:30:09 2009
@@ -754,11 +754,9 @@
     def op_zero_gc_pointers_inside(self, obj):
         raise NotImplementedError("zero_gc_pointers_inside")
 
-    def op_gc_arraycopy(self, source, dest, source_start, dest_start, length):
-        if hasattr(self.heap, 'arraycopy'):
-            self.heap.arraycopy(source, dest, source_start, dest_start, length)
-            return True
-        return False
+    def op_gc_arraycopy_writebarrier(self, source, dest):
+        if hasattr(self.heap, 'arraycopy_writebarrier'):
+            self.heap.arraycopy_writebarrier(source, dest)
 
     def op_getfield(self, obj, field):
         checkptr(obj)

Modified: pypy/branch/listcopyop/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/branch/listcopyop/pypy/rpython/lltypesystem/lloperation.py	Tue Dec  8 11:30:09 2009
@@ -358,7 +358,6 @@
     'resize_buffer':        LLOp(canraise=(MemoryError,), canunwindgc=True),
     'finish_building_buffer' : LLOp(canraise=(MemoryError,), canunwindgc=True),
     'zero_gc_pointers_inside': LLOp(),
-    'gc_arraycopy':             LLOp(canrun=True),
     'free':                 LLOp(),
     'getfield':             LLOp(sideeffects=False, canrun=True),
     'getarrayitem':         LLOp(sideeffects=False, canrun=True),
@@ -462,6 +461,7 @@
     'gc_thread_run'       : LLOp(),
     'gc_thread_die'       : LLOp(),
     'gc_assume_young_pointers': LLOp(canrun=True),
+    'gc_arraycopy_writebarrier': LLOp(canrun=True),
     'gc_heap_stats'       : LLOp(canunwindgc=True),
 
     # ------- JIT & GC interaction, only for some GCs ----------

Modified: pypy/branch/listcopyop/pypy/rpython/lltypesystem/opimpl.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/lltypesystem/opimpl.py	(original)
+++ pypy/branch/listcopyop/pypy/rpython/lltypesystem/opimpl.py	Tue Dec  8 11:30:09 2009
@@ -394,13 +394,12 @@
     checkadr(addr2)
     return addr1 - addr2
 
-def op_gc_arraycopy(source, dest, source_start, dest_start, length):
+def op_gc_arraycopy_writebarrier(source, dest):
     A = lltype.typeOf(source)
     assert A == lltype.typeOf(dest)
     assert isinstance(A.TO, lltype.GcArray)
     assert isinstance(A.TO.OF, lltype.Ptr)
     assert A.TO.OF.TO._gckind == 'gc'
-    return False # no special support
 
 def op_getfield(p, name):
     checkptr(p)

Modified: pypy/branch/listcopyop/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/gc/generation.py	(original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/gc/generation.py	Tue Dec  8 11:30:09 2009
@@ -475,8 +475,7 @@
             objhdr.tid &= ~GCFLAG_NO_HEAP_PTRS
             self.last_generation_root_objects.append(addr_struct)
 
-    def arraycopy(self, source_addr, dest_addr, source_start,
-                  dest_start, length):
+    def arraycopy_writebarrier(self, source_addr, dest_addr):
         typeid = self.get_type_id(source_addr)
         assert self.is_gcarrayofgcptr(typeid)
         need_set = False
@@ -486,14 +485,6 @@
             need_set = True
         if need_set:
             self.assume_young_pointers(dest_addr)
-        itemsize = llmemory.gcarrayofptr_singleitemoffset
-        cp_source_addr = (source_addr + llmemory.gcarrayofptr_itemsoffset +
-                          itemsize * source_start)
-        cp_dest_addr = (dest_addr + llmemory.gcarrayofptr_itemsoffset + 
-                        itemsize * dest_start)
-        llmemory.raw_memcopy(cp_source_addr, cp_dest_addr,
-                             itemsize * length)
-        return True
 
     def write_into_last_generation_obj(self, addr_struct, addr):
         objhdr = self.header(addr_struct)

Modified: pypy/branch/listcopyop/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/gctransform/framework.py	Tue Dec  8 11:30:09 2009
@@ -292,8 +292,8 @@
                 [s_gc, annmodel.SomeInteger(knowntype=rffi.r_ushort)],
                 annmodel.SomeInteger())
 
-        if hasattr(GCClass, 'arraycopy'):
-            self.arraycopy_ptr = getfn(GCClass.arraycopy.im_func,
+        if hasattr(GCClass, 'arraycopy_writebarrier'):
+            self.arraycopy_wb_p = getfn(GCClass.arraycopy_writebarrier.im_func,
                     [s_gc] + [annmodel.SomeAddress()] * 2 +
                      [annmodel.SomeInteger()] * 3, annmodel.SomeBool())
 
@@ -781,17 +781,17 @@
             TYPE = v_ob.concretetype.TO
             gen_zero_gc_pointers(TYPE, v_ob, hop.llops)
 
-    def gct_gc_arraycopy(self, hop):
-        if not hasattr(self, 'arraycopy_ptr'):
-            return GCTransformer.gct_gc_arraycopy(self, hop)
+    def gct_gc_arraycopy_writebarrier(self, hop):
+        if not hasattr(self, 'arraycopy_wb_p'):
+            # should do nothing
+            return GCTransformer.gct_gc_arraycopy_writebarrier(self, hop)
         op = hop.spaceop
         source_addr = hop.genop('cast_ptr_to_adr', [op.args[0]],
                                 resulttype=llmemory.Address)
         dest_addr = hop.genop('cast_ptr_to_adr', [op.args[1]],
                                 resulttype=llmemory.Address)
         hop.genop('direct_call', [self.arraycopy_ptr, self.c_const_gc,
-                                  source_addr, dest_addr] + op.args[2:],
-                  resultvar=op.result)
+                                  source_addr, dest_addr])
 
     def gct_weakref_create(self, hop):
         op = hop.spaceop

Modified: pypy/branch/listcopyop/pypy/rpython/memory/gctransform/transform.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/gctransform/transform.py	(original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/gctransform/transform.py	Tue Dec  8 11:30:09 2009
@@ -380,8 +380,8 @@
     def gct_zero_gc_pointers_inside(self, hop):
         pass
 
-    def gct_gc_arraycopy(self, hop):
-        return rmodel.inputconst(lltype.Bool, False)
+    def gct_gc_arraycopy_writebarrier(self, hop):
+        pass
 
     def gct_gc_identityhash(self, hop):
         # must be implemented in the various GCs

Modified: pypy/branch/listcopyop/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/gcwrapper.py	(original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/gcwrapper.py	Tue Dec  8 11:30:09 2009
@@ -128,16 +128,11 @@
         ptr = lltype.cast_opaque_ptr(llmemory.GCREF, ptr)
         return self.gc.id(ptr)
 
-    def arraycopy(self, source, dest, source_start, dest_start, length):
-        if hasattr(self.gc, 'arraycopy'):
+    def arraycopy_writebarrier(self, source, dest):
+        if hasattr(self.gc, 'arraycopy_writebarrier'):
             source_addr = llmemory.cast_ptr_to_adr(source)
             dest_addr   = llmemory.cast_ptr_to_adr(dest)
-            return self.gc.arraycopy(source_addr, dest_addr, source_start,
-                                     dest_start, length)
-        i = 0
-        while i < length:
-            dest[dest_start + i] = source[source_start + i]
-            i += 1
+            return self.gc.arraycopy_writebarrier(source_addr, dest_addr)
 
 # ____________________________________________________________
 

Modified: pypy/branch/listcopyop/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/test/test_gc.py	(original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/test/test_gc.py	Tue Dec  8 11:30:09 2009
@@ -551,7 +551,10 @@
         res = self.interpret(fn, [-1000], taggedpointers=True)
         assert res == 111
 
-    def test_arraycopy(self):
+    def test_arraycopy_writebarrier(self):
+        import new
+        ll_arraycopy = new.function(rgc.ll_arraycopy.func_code, {})
+        
         S = lltype.GcStruct('S')
         TP = lltype.GcArray(lltype.Ptr(S))
         def fn():
@@ -559,14 +562,14 @@
             l2 = lltype.malloc(TP, 100)
             for i in range(100):
                 l[i] = lltype.malloc(S)
-            if llop.gc_arraycopy(lltype.Void, l, l2, 50, 0, 50):
-                x = []
-                # force minor collect
-                t = (1, lltype.malloc(S))
-                for i in range(20):
-                    x.append(t)
-                for i in range(50):
-                    assert l2[i]
+            ll_arraycopy(l, l2, 50, 0, 50)
+            x = []
+            # force minor collect
+            t = (1, lltype.malloc(S))
+            for i in range(20):
+                x.append(t)
+            for i in range(50):
+                assert l2[i]
             return 0
 
         self.interpret(fn, [])

Modified: pypy/branch/listcopyop/pypy/rpython/memory/test/test_transformed_gc.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/test/test_transformed_gc.py	(original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/test/test_transformed_gc.py	Tue Dec  8 11:30:09 2009
@@ -834,7 +834,9 @@
             return d * 1000 + c * 100 + b * 10 + a
         return f
 
-    def xxxtest_gc_heap_stats(self):
+    @py.test.mark.xfail("Fails if followed by any test")
+    def test_gc_heap_stats(self):
+        XXX # this test makes next test to crash
         run = self.runner("gc_heap_stats")
         res = run([])
         assert res % 10000 == 2611
@@ -845,6 +847,9 @@
         #     (and give fixedsize)
 
     def define_arraycopy(cls):
+        import new
+        ll_arraycopy = new.function(rgc.ll_arraycopy.func_code, {})
+        
         S = lltype.GcStruct('S')
         TP = lltype.GcArray(lltype.Ptr(S))
         def fn():
@@ -852,13 +857,13 @@
             l2 = lltype.malloc(TP, 100)
             for i in range(100):
                 l[i] = lltype.malloc(S)
-            if llop.gc_arraycopy(lltype.Void, l, l2, 50, 0, 50):
-                # force nursery collect
-                x = []
-                for i in range(20):
-                    x.append((1, lltype.malloc(S)))
-                for i in range(50):
-                    assert l2[i]
+            ll_arraycopy(l, l2, 50, 0, 50)
+            # force nursery collect
+            x = []
+            for i in range(20):
+                x.append((1, lltype.malloc(S)))
+            for i in range(50):
+                assert l2[i]
             return 0
 
         return fn



More information about the Pypy-commit mailing list