Author: Armin Rigo <ar...@tunes.org> Branch: shadowstack-perf-2 Changeset: r84385:09e14faba25a Date: 2016-05-11 20:36 +0200 http://bitbucket.org/pypy/pypy/changeset/09e14faba25a/
Log: Test diff --git a/rpython/memory/gctransform/shadowcolor.py b/rpython/memory/gctransform/shadowcolor.py --- a/rpython/memory/gctransform/shadowcolor.py +++ b/rpython/memory/gctransform/shadowcolor.py @@ -1,5 +1,6 @@ from rpython.rtyper.lltypesystem import lltype, llmemory -from rpython.flowspace.model import mkentrymap, Variable, Constant +from rpython.flowspace.model import mkentrymap +from rpython.flowspace.model import Variable, Constant, SpaceOperation from rpython.tool.algo.regalloc import perform_register_allocation from rpython.translator.unsimplify import varoftype @@ -130,6 +131,21 @@ return (last_index, Constant(bitmask, lltype.Signed)) +def expand_one_push_roots(regalloc, args): + if regalloc is None: + assert len(args) == 0 + else: + filled = [False] * regalloc.numcolors + for v in args: + index = regalloc.getcolor(v) + assert not filled[index] + filled[index] = True + yield _gc_save_root(index, v) + bitmask_index, bitmask_v = make_bitmask(filled) + if bitmask_index is not None: + yield _gc_save_root(bitmask_index, bitmask_v) + + def expand_push_roots(graph, regalloc): """Expand gc_push_roots into a series of gc_save_root, including writing a bitmask tag to mark some entries as not-in-use @@ -139,18 +155,7 @@ newops = [] for op in block.operations: if op.opname == 'gc_push_roots': - if regalloc is None: - assert len(op.args) == 0 - else: - filled = [False] * regalloc.numcolors - for v in op.args: - index = regalloc.getcolor(v) - assert not filled[index] - filled[index] = True - newops.append(_gc_save_root(index, v)) - bitmask_index, bitmask_v = make_bitmask(filled) - if bitmask_index is not None: - newops.append(_gc_save_root(bitmask_index, bitmask_v)) + newops += expand_one_push_roots(regalloc, op) any_change = True else: newops.append(op) diff --git a/rpython/memory/gctransform/test/test_shadowcolor.py b/rpython/memory/gctransform/test/test_shadowcolor.py --- a/rpython/memory/gctransform/test/test_shadowcolor.py +++ b/rpython/memory/gctransform/test/test_shadowcolor.py @@ -265,3 +265,30 @@ bitmask >>= 1 index -= 1 assert boollist == [True] * len(boollist) + + +class FakeRegAlloc: + def __init__(self, **colors): + self.numcolors = len(colors) + self.getcolor = colors.__getitem__ + +def check_expand_one_push_roots(regalloc, args): + got = list(expand_one_push_roots(regalloc, args)) + result = [] + for spaceop in got: + assert spaceop.opname == 'gc_save_root' + result.append((spaceop.args[0].value, spaceop.args[1])) + return result + +def test_expand_one_push_roots(): + regalloc = FakeRegAlloc(a=0, b=1, c=2) + assert check_expand_one_push_roots(regalloc, ['a', 'b', 'c']) == [ + (0, 'a'), (1, 'b'), (2, 'c')] + assert check_expand_one_push_roots(regalloc, ['a', 'c']) == [ + (0, 'a'), (2, 'c'), (1, c_NULL)] + assert check_expand_one_push_roots(regalloc, ['b']) == [ + (1, 'b'), (2, Constant(0x5, lltype.Signed))] + assert check_expand_one_push_roots(regalloc, ['a']) == [ + (0, 'a'), (2, Constant(0x3, lltype.Signed))] + assert check_expand_one_push_roots(regalloc, []) == [ + (2, Constant(0x7, lltype.Signed))] _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit