[pypy-svn] r65571 - in pypy/branch/pyjitpl5-experiments/pypy: jit/backend/x86 jit/backend/x86/test rpython/memory rpython/memory/gctransform
arigo at codespeak.net
arigo at codespeak.net
Thu Jun 4 10:26:50 CEST 2009
Author: arigo
Date: Thu Jun 4 10:26:48 2009
New Revision: 65571
Modified:
pypy/branch/pyjitpl5-experiments/pypy/jit/backend/x86/gc.py
pypy/branch/pyjitpl5-experiments/pypy/jit/backend/x86/test/test_zrpy_gc.py
pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gctransform/framework.py
pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gctypelayout.py
Log:
To support __del__ we must delay a bit its annotation.
Implemented by delaying encode_type_shape() until we
are really doing the GC transform.
Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/x86/gc.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/x86/gc.py (original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/x86/gc.py Thu Jun 4 10:26:48 2009
@@ -246,6 +246,8 @@
# make a TransformerLayoutBuilder and save it on the translator
# where it can be fished and reused by the FrameworkGCTransformer
self.layoutbuilder = framework.TransformerLayoutBuilder()
+ self.layoutbuilder._pending_type_shapes = []
+ self.layoutbuilder.can_encode_type_shape = False
self.translator._jit2gc = {
'layoutbuilder': self.layoutbuilder,
'gcmapstart': lambda: gcrootmap.gcmapstart(),
Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/x86/test/test_zrpy_gc.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/x86/test/test_zrpy_gc.py (original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/x86/test/test_zrpy_gc.py Thu Jun 4 10:26:48 2009
@@ -186,3 +186,24 @@
res = compile_and_run(get_test(main), "hybrid", gcrootfinder="asmgcc",
jit=True)
assert int(res) == 20
+
+def test_compile_hybrid_4():
+ # Fourth version of the test, with __del__.
+ class Counter:
+ cnt = 0
+ counter = Counter()
+ class Z:
+ def __del__(self):
+ counter.cnt -= 1
+ myjitdriver = JitDriver(greens = [], reds = ['n', 'x'])
+ def main(n, x):
+ assert counter.cnt < 5
+ counter.cnt = n // x.foo
+ while n > 0:
+ myjitdriver.can_enter_jit(n=n, x=x)
+ myjitdriver.jit_merge_point(n=n, x=x)
+ Z()
+ n -= x.foo
+ res = compile_and_run(get_test(main), "hybrid", gcrootfinder="asmgcc",
+ jit=True)
+ assert int(res) == 20
Modified: pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gctransform/framework.py (original)
+++ pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gctransform/framework.py Thu Jun 4 10:26:48 2009
@@ -382,6 +382,8 @@
self.thread_die_ptr = getfn(root_walker.thread_die,
[], annmodel.s_None)
+ self.layoutbuilder.encode_type_shapes_now()
+
annhelper.finish() # at this point, annotate all mix-level helpers
annhelper.backend_optimize()
Modified: pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gctypelayout.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gctypelayout.py (original)
+++ pypy/branch/pyjitpl5-experiments/pypy/rpython/memory/gctypelayout.py Thu Jun 4 10:26:48 2009
@@ -181,6 +181,7 @@
class TypeLayoutBuilder(object):
can_add_new_types = True
+ can_encode_type_shape = True # set to False initially by the JIT
def __init__(self):
self.type_info_list = [None] # don't use typeid 0, helps debugging
@@ -226,11 +227,21 @@
# build the TYPE_INFO structure
info = lltype.malloc(GCData.TYPE_INFO, immortal=True, zero=True)
- encode_type_shape(self, info, TYPE)
+ if self.can_encode_type_shape:
+ encode_type_shape(self, info, TYPE)
+ else:
+ self._pending_type_shapes.append((info, TYPE))
self.type_info_list[type_id] = info
self.id_of_type[TYPE] = type_id
return type_id
+ def encode_type_shapes_now(self):
+ if not self.can_encode_type_shape:
+ self.can_encode_type_shape = True
+ for info, TYPE in self._pending_type_shapes:
+ encode_type_shape(self, info, TYPE)
+ del self._pending_type_shapes
+
def offsets2table(self, offsets, TYPE):
if len(offsets) == 0:
TYPE = lltype.Void # we can share all zero-length arrays
More information about the Pypy-commit
mailing list