[pypy-svn] r65260 - pypy/branch/pyjitpl5/pypy/jit/backend/x86/test
arigo at codespeak.net
arigo at codespeak.net
Thu May 14 11:38:56 CEST 2009
Author: arigo
Date: Thu May 14 11:38:55 2009
New Revision: 65260
Modified:
pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_zrpy_gc.py
Log:
Add a test for the GcRefList class.
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_zrpy_gc.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_zrpy_gc.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_zrpy_gc.py Thu May 14 11:38:55 2009
@@ -4,12 +4,14 @@
however, is the correct handling of GC, i.e. if objects are freed as
soon as possible (at least in a simple case).
"""
-import weakref
+import weakref, random
import py
from pypy.rlib import rgc
+from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.lltypesystem.lloperation import llop
from pypy.rlib.jit import JitDriver
from pypy.jit.backend.x86.runner import CPU386
+from pypy.jit.backend.x86.gc import GcRefList
myjitdriver = JitDriver(greens = [], reds = ['n', 'x'])
@@ -35,7 +37,7 @@
return weakref.ref(x)
g._dont_inline_ = True
-def f(args):
+def entrypoint(args):
r_list = []
for i in range(20):
r = g(1000)
@@ -50,34 +52,49 @@
return 0
-def compile_and_run(gc, **kwds):
+def compile_and_run(f, gc, **kwds):
from pypy.translator.translator import TranslationContext
from pypy.jit.metainterp.warmspot import apply_jit
from pypy.translator.c import genc
#
t = TranslationContext()
t.config.translation.gc = gc
- t.config.translation.jit = True
for name, value in kwds.items():
setattr(t.config.translation, name, value)
t.buildannotator().build_types(f, [int])
t.buildrtyper().specialize()
- apply_jit(t, CPUClass=CPU386)
+ if kwds['jit']:
+ apply_jit(t, CPUClass=CPU386)
cbuilder = genc.CStandaloneBuilder(t, f, t.config)
cbuilder.generate_source()
cbuilder.compile()
#
data = cbuilder.cmdexec('')
- res = int(data.strip())
- if gc == "boehm":
- assert res >= 16
- else:
- assert res == 20
+ return data.strip()
def test_compile_boehm():
- compile_and_run("boehm")
+ res = compile_and_run(entrypoint, "boehm", jit=True)
+ assert int(res) >= 16
+
+def test_GcRefList():
+ S = lltype.GcStruct('S')
+ order = range(20000) * 4
+ random.shuffle(order)
+ def fn(args):
+ allocs = [lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S))
+ for i in range(20000)]
+ allocs = [allocs[i] for i in order]
+ #
+ gcrefs = GcRefList()
+ addrs = [gcrefs.get_address_of_gcref(ptr) for ptr in allocs]
+ for i in range(len(allocs)):
+ assert addrs[i].address[0] == llmemory.cast_ptr_to_adr(allocs[i])
+ return 0
+ compile_and_run(fn, "hybrid", gcrootfinder="asmgcc", jit=False)
def test_compile_hybrid():
# a moving GC, with a write barrier. Supports malloc_varsize_nonmovable.
- compile_and_run("hybrid", gcrootfinder="asmgcc")
+ res = compile_and_run(entrypoint, "hybrid", gcrootfinder="asmgcc",
+ jit=True)
+ assert int(res) == 20
More information about the Pypy-commit
mailing list