[pypy-svn] r69857 - in pypy/branch/listcopyop/pypy/rpython/memory: gc gctransform test
fijal at codespeak.net
fijal at codespeak.net
Thu Dec 3 11:12:55 CET 2009
Author: fijal
Date: Thu Dec 3 11:12:53 2009
New Revision: 69857
Modified:
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/support.py
pypy/branch/listcopyop/pypy/rpython/memory/gctransform/transform.py
pypy/branch/listcopyop/pypy/rpython/memory/test/test_transformed_gc.py
Log:
intermediate checkin
* Specialize listcopy over lltype
* Support having listcopy on gc, so one can overwrite it
* Write a test, but it does not crash yet because of lack of write barrier,
need to improve
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 Thu Dec 3 11:12:53 2009
@@ -5,7 +5,7 @@
from pypy.rpython.lltypesystem.llmemory import NULL, raw_malloc_usage
from pypy.rpython.lltypesystem import lltype, llmemory, llarena
from pypy.rpython.memory.support import DEFAULT_CHUNK_SIZE
-from pypy.rlib.objectmodel import free_non_gc_object
+from pypy.rlib.objectmodel import free_non_gc_object, specialize
from pypy.rlib.debug import ll_assert
from pypy.rlib.debug import debug_print, debug_start, debug_stop
from pypy.rpython.lltypesystem.lloperation import llop
@@ -475,6 +475,20 @@
objhdr.tid &= ~GCFLAG_NO_HEAP_PTRS
self.last_generation_root_objects.append(addr_struct)
+ @specialize.arglltype(0)
+ def listcopy(source, dest, source_start, dest_start, length):
+ TP = lltype.typeOf(source).TO
+ if isinstance(TP.OF, lltype.Ptr):
+ pass # do write barrier
+ source_addr = (llmemory.cast_ptr_to_adr(source) +
+ llmemory.itemoffsetof(TP, 0) +
+ llmemory.sizeof(TP.OF) * source_start)
+ dest_addr = (llmemory.cast_ptr_to_adr(dest)
+ + llmemory.itemoffsetof(TP, 0) +
+ llmemory.sizeof(TP.OF) * dest_start)
+ llmemory.raw_memcopy(source_addr, dest_addr,
+ llmemory.sizeof(TP.OF) * length)
+
def write_into_last_generation_obj(self, addr_struct, addr):
objhdr = self.header(addr_struct)
if objhdr.tid & GCFLAG_NO_HEAP_PTRS:
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 Thu Dec 3 11:12:53 2009
@@ -776,6 +776,16 @@
TYPE = v_ob.concretetype.TO
gen_zero_gc_pointers(TYPE, v_ob, hop.llops)
+ def gct_listcopy(self, hop):
+ if not hasattr(self.GCClass, 'listcopy'):
+ return GCTransformer.gct_listcopy(self, hop)
+ op = hop.spaceop
+ ARGS = [arg.concretetype for arg in op.args]
+ llptr = self.annotate_helper(self.GCClass.listcopy.im_func, ARGS,
+ op.result.concretetype, inline=True)
+ c_func = rmodel.inputconst(lltype.Void, llptr)
+ hop.genop('direct_call', [c_func] + op.args)
+
def gct_weakref_create(self, hop):
op = hop.spaceop
Modified: pypy/branch/listcopyop/pypy/rpython/memory/gctransform/support.py
==============================================================================
--- pypy/branch/listcopyop/pypy/rpython/memory/gctransform/support.py (original)
+++ pypy/branch/listcopyop/pypy/rpython/memory/gctransform/support.py Thu Dec 3 11:12:53 2009
@@ -1,6 +1,7 @@
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.annotation import model as annmodel
+from pypy.rlib.objectmodel import specialize
import os
def var_ispyobj(var):
@@ -106,3 +107,10 @@
os.write(2, "a destructor raised an exception, ignoring it\n")
except:
pass
+
+ at specialize.arglltype(0)
+def ll_listcopy(source, dest, source_start, dest_start, length):
+ i = 0
+ while i < length:
+ dest[i + dest_start] = source[i + source_start]
+ i += 1
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 Thu Dec 3 11:12:53 2009
@@ -5,7 +5,7 @@
from pypy.translator.unsimplify import insert_empty_block
from pypy.translator.unsimplify import insert_empty_startblock
from pypy.translator.unsimplify import starts_with_empty_block
-from pypy.translator.backendopt.support import var_needsgc
+from pypy.translator.backendopt.support import var_needsgc, ll_listcopy
from pypy.translator.backendopt import inline
from pypy.translator.backendopt import graphanalyze
from pypy.translator.backendopt.canraise import RaiseAnalyzer
@@ -383,8 +383,7 @@
def gct_listcopy(self, hop):
# by default, this becomes a raw memcopy
op = hop.spaceop
- from pypy.rpython.lltypesystem import opimpl
- llptr = self.annotate_helper(opimpl.op_listcopy,
+ llptr = self.annotate_helper(ll_listcopy,
[arg.concretetype for arg in op.args],
op.result.concretetype, inline=True)
c_func = rmodel.inputconst(lltype.Void, llptr)
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 Thu Dec 3 11:12:53 2009
@@ -862,7 +862,27 @@
def test_listcopy(self):
run = self.runner("listcopy")
run([])
-
+
+ def define_listcopy_ptr(cls):
+ S = lltype.GcStruct('S')
+ TP = lltype.GcArray(lltype.Ptr(S))
+ def fn():
+ l = lltype.malloc(TP, 100)
+ for i in range(100):
+ l[i] = lltype.malloc(S)
+ l2 = lltype.malloc(TP, 50)
+ llop.listcopy(lltype.Void, l, l2, 50, 0, 50)
+ llop.gc__collect(lltype.Void)
+ for i in range(50):
+ assert l2[i] is l[i + 50]
+ return 0
+
+ return fn
+
+ def test_listcopy_ptr(self):
+ run = self.runner("listcopy_ptr")
+ run([])
+
# ________________________________________________________________
class TestMarkSweepGC(GenericGCTests):
More information about the Pypy-commit
mailing list