本文整理汇总了Python中pypy.jit.metainterp.warmstate.WarmEnterState._make_jitcell_getter_default方法的典型用法代码示例。如果您正苦于以下问题:Python WarmEnterState._make_jitcell_getter_default方法的具体用法?Python WarmEnterState._make_jitcell_getter_default怎么用?Python WarmEnterState._make_jitcell_getter_default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.jit.metainterp.warmstate.WarmEnterState
的用法示例。
在下文中一共展示了WarmEnterState._make_jitcell_getter_default方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cleanup_jitcell_dict
# 需要导入模块: from pypy.jit.metainterp.warmstate import WarmEnterState [as 别名]
# 或者: from pypy.jit.metainterp.warmstate.WarmEnterState import _make_jitcell_getter_default [as 别名]
def test_cleanup_jitcell_dict():
class FakeJitDriverSD:
_green_args_spec = [lltype.Signed]
#
# Test creating tons of jitcells that remain at 0
warmstate = WarmEnterState(None, FakeJitDriverSD())
get_jitcell = warmstate._make_jitcell_getter_default()
cell1 = get_jitcell(True, -1)
assert len(warmstate._jitcell_dict) == 1
#
for i in range(1, 20005):
get_jitcell(True, i) # should trigger a clean-up at 20001
assert len(warmstate._jitcell_dict) == (i % 20000) + 1
#
# Same test, with one jitcell that has a counter of BASE instead of 0
warmstate = WarmEnterState(None, FakeJitDriverSD())
get_jitcell = warmstate._make_jitcell_getter_default()
cell2 = get_jitcell(True, -2)
cell2.counter = BASE = warmstate.THRESHOLD_LIMIT // 2 # 50%
#
for i in range(0, 20005):
get_jitcell(True, i)
assert len(warmstate._jitcell_dict) == (i % 19999) + 2
#
assert cell2 in warmstate._jitcell_dict.values()
assert cell2.counter == int(BASE * 0.92) # decayed once
#
# Same test, with jitcells that are compiled and freed by the memmgr
warmstate = WarmEnterState(None, FakeJitDriverSD())
get_jitcell = warmstate._make_jitcell_getter_default()
get_jitcell(True, -1)
#
for i in range(1, 20005):
cell = get_jitcell(True, i)
cell.counter = -1
cell.wref_procedure_token = None # or a dead weakref, equivalently
assert len(warmstate._jitcell_dict) == (i % 20000) + 1
#
# Same test, with counter == -2 (rare case, kept alive)
warmstate = WarmEnterState(None, FakeJitDriverSD())
get_jitcell = warmstate._make_jitcell_getter_default()
cell = get_jitcell(True, -1)
cell.counter = -2
#
for i in range(1, 20005):
cell = get_jitcell(True, i)
cell.counter = -2
assert len(warmstate._jitcell_dict) == i + 1
示例2: test_make_jitcell_getter_default
# 需要导入模块: from pypy.jit.metainterp.warmstate import WarmEnterState [as 别名]
# 或者: from pypy.jit.metainterp.warmstate.WarmEnterState import _make_jitcell_getter_default [as 别名]
def test_make_jitcell_getter_default():
class FakeWarmRunnerDesc:
green_args_spec = [lltype.Signed, lltype.Float]
class FakeJitCell(BaseJitCell):
pass
state = WarmEnterState(FakeWarmRunnerDesc())
get_jitcell = state._make_jitcell_getter_default(FakeJitCell)
cell1 = get_jitcell(42, 42.5)
assert isinstance(cell1, FakeJitCell)
cell2 = get_jitcell(42, 42.5)
assert cell1 is cell2
cell3 = get_jitcell(41, 42.5)
cell4 = get_jitcell(42, 0.25)
assert cell1 is not cell3 is not cell4 is not cell1
示例3: test_make_jitcell_getter_default
# 需要导入模块: from pypy.jit.metainterp.warmstate import WarmEnterState [as 别名]
# 或者: from pypy.jit.metainterp.warmstate.WarmEnterState import _make_jitcell_getter_default [as 别名]
def test_make_jitcell_getter_default():
class FakeJitDriverSD:
_green_args_spec = [lltype.Signed, lltype.Float]
state = WarmEnterState(None, FakeJitDriverSD())
get_jitcell = state._make_jitcell_getter_default()
cell1 = get_jitcell(True, 42, 42.5)
assert isinstance(cell1, JitCell)
cell2 = get_jitcell(True, 42, 42.5)
assert cell1 is cell2
cell3 = get_jitcell(True, 41, 42.5)
assert get_jitcell(False, 42, 0.25) is None
cell4 = get_jitcell(True, 42, 0.25)
assert get_jitcell(False, 42, 0.25) is cell4
assert cell1 is not cell3 is not cell4 is not cell1