[pypy-svn] pypy jitypes2: Write the test by making sure that all opts are enabled.

arigo commits-noreply at bitbucket.org
Sun Mar 27 17:02:17 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: jitypes2
Changeset: r42983:b073f54b693e
Date: 2011-03-27 16:15 +0200
http://bitbucket.org/pypy/pypy/changeset/b073f54b693e/

Log:	Write the test by making sure that all opts are enabled. The test
	still passes, due to another issue (next checkin). Additionally, fix
	the fact that OS_LIBFFI_CALL calls can have random side-effects on
	random fields through callbacks.

diff --git a/pypy/jit/codewriter/call.py b/pypy/jit/codewriter/call.py
--- a/pypy/jit/codewriter/call.py
+++ b/pypy/jit/codewriter/call.py
@@ -234,6 +234,8 @@
             self.readwrite_analyzer.analyze(op), self.cpu, extraeffect,
             oopspecindex)
         #
+        if oopspecindex != EffectInfo.OS_NONE:
+            assert effectinfo is not None
         if pure or loopinvariant:
             assert effectinfo is not None
             assert extraeffect != EffectInfo.EF_FORCES_VIRTUAL_OR_VIRTUALIZABLE

diff --git a/pypy/jit/codewriter/effectinfo.py b/pypy/jit/codewriter/effectinfo.py
--- a/pypy/jit/codewriter/effectinfo.py
+++ b/pypy/jit/codewriter/effectinfo.py
@@ -101,6 +101,9 @@
     def check_forces_virtual_or_virtualizable(self):
         return self.extraeffect >= self.EF_FORCES_VIRTUAL_OR_VIRTUALIZABLE
 
+    def has_random_effects(self):
+        return self.oopspecindex == self.OS_LIBFFI_CALL
+
 def effectinfo_from_writeanalyze(effects, cpu,
                                  extraeffect=EffectInfo.EF_CAN_RAISE,
                                  oopspecindex=EffectInfo.OS_NONE):

diff --git a/pypy/jit/metainterp/optimizeopt/heap.py b/pypy/jit/metainterp/optimizeopt/heap.py
--- a/pypy/jit/metainterp/optimizeopt/heap.py
+++ b/pypy/jit/metainterp/optimizeopt/heap.py
@@ -172,7 +172,7 @@
                 effectinfo = None
             else:
                 effectinfo = op.getdescr().get_extra_info()
-            if effectinfo is not None:
+            if effectinfo is not None and not effectinfo.has_random_effects():
                 # XXX we can get the wrong complexity here, if the lists
                 # XXX stored on effectinfo are large
                 for fielddescr in effectinfo.readonly_descrs_fields:

diff --git a/pypy/jit/backend/x86/test/test_zrpy_gc.py b/pypy/jit/backend/x86/test/test_zrpy_gc.py
--- a/pypy/jit/backend/x86/test/test_zrpy_gc.py
+++ b/pypy/jit/backend/x86/test/test_zrpy_gc.py
@@ -67,7 +67,7 @@
     return entrypoint
 
 
-def compile(f, gc, **kwds):
+def compile(f, gc, enable_opts='', **kwds):
     from pypy.annotation.listdef import s_list_of_strings
     from pypy.translator.translator import TranslationContext
     from pypy.jit.metainterp.warmspot import apply_jit
@@ -83,7 +83,7 @@
     ann.build_types(f, [s_list_of_strings], main_entry_point=True)
     t.buildrtyper().specialize()
     if kwds['jit']:
-        apply_jit(t, enable_opts='')
+        apply_jit(t, enable_opts=enable_opts)
     cbuilder = genc.CStandaloneBuilder(t, f, t.config)
     cbuilder.generate_source()
     cbuilder.compile()
@@ -572,59 +572,66 @@
     def test_compile_framework_minimal_size_in_nursery(self):
         self.run('compile_framework_minimal_size_in_nursery')
 
-    def define_compile_framework_close_stack(self):
-        from pypy.rlib.libffi import CDLL, types, ArgChain, clibffi
-        from pypy.rpython.lltypesystem.ll2ctypes import libc_name
-        from pypy.rpython.annlowlevel import llhelper
-        #
-        class Glob(object):
-            pass
-        glob = Glob()
-        class X(object):
-            pass
-        #
-        def callback(p1, p2):
-            for i in range(100):
-                glob.lst.append(X())
-            return rffi.cast(rffi.INT, 1)
-        CALLBACK = lltype.Ptr(lltype.FuncType([lltype.Signed,
-                                               lltype.Signed], rffi.INT))
-        #
-        @dont_look_inside
-        def alloc1():
-            return llmemory.raw_malloc(16)
-        @dont_look_inside
-        def free1(p):
-            llmemory.raw_free(p)
-        #
-        def f42(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
-            length = len(glob.lst)
-            raw = alloc1()
-            argchain = ArgChain()
-            fn = llhelper(CALLBACK, rffi._make_wrapper_for(CALLBACK, callback))
-            argchain = argchain.arg(rffi.cast(lltype.Signed, raw))
-            argchain = argchain.arg(rffi.cast(rffi.SIZE_T, 2))
-            argchain = argchain.arg(rffi.cast(rffi.SIZE_T, 8))
-            argchain = argchain.arg(rffi.cast(lltype.Signed, fn))
-            glob.c_qsort.call(argchain, lltype.Void)
-            free1(raw)
-            check(len(glob.lst) > length)
-            del glob.lst[:]
+
+def test_close_stack():
+    from pypy.rlib.libffi import CDLL, types, ArgChain, clibffi
+    from pypy.rpython.lltypesystem.ll2ctypes import libc_name
+    from pypy.rpython.annlowlevel import llhelper
+    from pypy.jit.metainterp.optimizeopt import ALL_OPTS_NAMES
+    #
+    class Glob(object):
+        pass
+    glob = Glob()
+    class X(object):
+        pass
+    #
+    def callback(p1, p2):
+        for i in range(100):
+            glob.lst.append(X())
+        return rffi.cast(rffi.INT, 1)
+    CALLBACK = lltype.Ptr(lltype.FuncType([lltype.Signed,
+                                           lltype.Signed], rffi.INT))
+    #
+    @dont_look_inside
+    def alloc1():
+        return llmemory.raw_malloc(16)
+    @dont_look_inside
+    def free1(p):
+        llmemory.raw_free(p)
+    #
+    def f42():
+        length = len(glob.lst)
+        c_qsort = glob.c_qsort
+        raw = alloc1()
+        fn = llhelper(CALLBACK, rffi._make_wrapper_for(CALLBACK, callback))
+        argchain = ArgChain()
+        argchain = argchain.arg(rffi.cast(lltype.Signed, raw))
+        argchain = argchain.arg(rffi.cast(rffi.SIZE_T, 2))
+        argchain = argchain.arg(rffi.cast(rffi.SIZE_T, 8))
+        argchain = argchain.arg(rffi.cast(lltype.Signed, fn))
+        c_qsort.call(argchain, lltype.Void)
+        free1(raw)
+        check(len(glob.lst) > length)
+        del glob.lst[:]
+    #
+    def before():
+        libc = CDLL(libc_name)
+        types_size_t = clibffi.cast_type_to_ffitype(rffi.SIZE_T)
+        c_qsort = libc.getpointer('qsort', [types.pointer, types_size_t,
+                                            types_size_t, types.pointer],
+                                  types.void)
+        glob.c_qsort = c_qsort
+        glob.lst = []
+    #
+    myjitdriver = JitDriver(greens=[], reds=['n'])
+    def main(n, x):
+        before()
+        while n > 0:
+            myjitdriver.jit_merge_point(n=n)
+            f42()
             n -= 1
-            return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
-        #
-        def before(n, x):
-            libc = CDLL(libc_name)
-            types_size_t = clibffi.cast_type_to_ffitype(rffi.SIZE_T)
-            c_qsort = libc.getpointer('qsort', [types.pointer, types_size_t,
-                                                types_size_t, types.pointer],
-                                      types.void)
-            glob.c_qsort = c_qsort
-            glob.lst = []
-            return (n, None, None, None, None, None, None,
-                    None, None, None, None, None)
-        #
-        return before, f42, None
-
-    def test_compile_framework_close_stack(self):
-        self.run('compile_framework_close_stack')
+    #
+    res = compile_and_run(get_entry(get_g(main)), DEFL_GC,
+                          gcrootfinder="asmgcc", jit=True,
+                          enable_opts=ALL_OPTS_NAMES)
+    assert int(res) == 20


More information about the Pypy-commit mailing list