[pypy-svn] r67568 - in pypy/branch/agressive-inlining/pypy/jit/metainterp: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Sep 8 11:00:21 CEST 2009
Author: cfbolz
Date: Tue Sep 8 11:00:20 2009
New Revision: 67568
Modified:
pypy/branch/agressive-inlining/pypy/jit/metainterp/history.py
pypy/branch/agressive-inlining/pypy/jit/metainterp/pyjitpl.py
pypy/branch/agressive-inlining/pypy/jit/metainterp/test/test_basic.py
pypy/branch/agressive-inlining/pypy/jit/metainterp/test/test_recursive.py
pypy/branch/agressive-inlining/pypy/jit/metainterp/warmspot.py
Log:
(pedronis, cfbolz; arigo around): reset counters for bridges as well. bit annoying to test.
Modified: pypy/branch/agressive-inlining/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/agressive-inlining/pypy/jit/metainterp/history.py (original)
+++ pypy/branch/agressive-inlining/pypy/jit/metainterp/history.py Tue Sep 8 11:00:20 2009
@@ -788,6 +788,7 @@
compiled_count = 0
enter_count = 0
+ aborted_count = 0
def __init__(self):
self.loops = []
Modified: pypy/branch/agressive-inlining/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/agressive-inlining/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/agressive-inlining/pypy/jit/metainterp/pyjitpl.py Tue Sep 8 11:00:20 2009
@@ -1252,6 +1252,7 @@
if len(self.history.operations) > warmrunnerstate.trace_limit:
self.history = history.BlackHole(self.cpu)
if not we_are_translated():
+ self.staticdata.stats.aborted_count += 1
history.log.event('ABORTING TRACING' + self.history.extratext)
elif DEBUG:
debug_print('~~~ ABORTING TRACING', self.history.extratext)
@@ -1306,7 +1307,7 @@
return self.designate_target_loop(gmp)
def handle_guard_failure(self, exec_result, key):
- self.initialize_state_from_guard_failure(exec_result)
+ resumedescr = self.initialize_state_from_guard_failure(exec_result)
assert isinstance(key, compile.ResumeGuardDescr)
top_history = key.find_toplevel_history()
source_loop = top_history.source_link
@@ -1316,12 +1317,18 @@
self.resumekey = key
self.seen_can_enter_jit = False
guard_op = key.get_guard_op()
+ started_as_blackhole = self.is_blackholing()
try:
self.prepare_resume_from_failure(guard_op.opnum)
self.interpret()
assert False, "should always raise"
except GenerateMergePoint, gmp:
return self.designate_target_loop(gmp)
+ except self.staticdata.ContinueRunningNormally:
+ if not started_as_blackhole:
+ warmrunnerstate = self.staticdata.state
+ warmrunnerstate.reset_counter_from_failure(resumedescr)
+ raise
def forget_consts(self, boxes, startindex=0):
for i in range(startindex, len(boxes)):
@@ -1556,6 +1563,7 @@
# the BlackHole is invalid because it doesn't start with
# guard_failure.key.guard_op.suboperations, but that's fine
self.rebuild_state_after_failure(resumedescr, guard_failure.args)
+ return resumedescr
def initialize_virtualizable(self, original_boxes):
vinfo = self.staticdata.virtualizable_info
Modified: pypy/branch/agressive-inlining/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/agressive-inlining/pypy/jit/metainterp/test/test_basic.py (original)
+++ pypy/branch/agressive-inlining/pypy/jit/metainterp/test/test_basic.py Tue Sep 8 11:00:20 2009
@@ -50,6 +50,8 @@
assert get_stats().enter_count <= count
def check_jumps(self, maxcount):
assert get_stats().exec_jumps <= maxcount
+ def check_aborted_count(self, maxcount):
+ assert get_stats().aborted_count == maxcount
def meta_interp(self, *args, **kwds):
kwds['CPUClass'] = self.CPUClass
Modified: pypy/branch/agressive-inlining/pypy/jit/metainterp/test/test_recursive.py
==============================================================================
--- pypy/branch/agressive-inlining/pypy/jit/metainterp/test/test_recursive.py (original)
+++ pypy/branch/agressive-inlining/pypy/jit/metainterp/test/test_recursive.py Tue Sep 8 11:00:20 2009
@@ -213,55 +213,58 @@
res = self.meta_interp(main, [100], optimizer=simple_optimize, inline=True)
assert res == 0
+ def check_max_trace_length(self, length):
+ for loop in get_stats().loops:
+ assert len(loop.operations) <= length + 5 # because we only check once per metainterp bytecode
+ for op in loop.operations:
+ if op.is_guard():
+ assert len(op.suboperations) <= length + 5
+
def test_inline_trace_limit(self):
- from pypy.rpython.annlowlevel import hlstr
- def p(code, pc):
- code = hlstr(code)
- return "%s %d %s" % (code, pc, code[pc])
- def c(code, pc):
- return "l" not in hlstr(code)
- myjitdriver = JitDriver(greens=['code', 'pc'], reds=['n'],
- get_printable_location=p, can_inline=c)
+ myjitdriver = JitDriver(greens=[], reds=['n'])
def recursive(n):
if n > 0:
return recursive(n - 1) + 1
return 0
- def f(code, n):
+ def loop(n):
myjitdriver.set_param("threshold", 10)
pc = 0
- while pc < len(code):
-
- myjitdriver.jit_merge_point(n=n, code=code, pc=pc)
- op = code[pc]
- if op == "-":
- n -= 1
- elif op == "r":
- n = recursive(n)
- elif op == "i":
- if n % 5 == 1:
- return n
- elif op == "l":
- if n > 0:
- myjitdriver.can_enter_jit(n=n, code=code, pc=0)
- pc = 0
- continue
- else:
- assert 0
- pc += 1
+ while n:
+ myjitdriver.can_enter_jit(n=n)
+ myjitdriver.jit_merge_point(n=n)
+ n = recursive(n)
+ n -= 1
return n
- def main(n):
- if n < 0:
- code = "--"
- else:
- code = "r-l"
- return f(code, n)
- print main(100)
TRACE_LIMIT = 66
- res = self.meta_interp(main, [100], optimizer=simple_optimize, inline=True, trace_limit=TRACE_LIMIT)
+ res = self.meta_interp(loop, [100], optimizer=simple_optimize, inline=True, trace_limit=TRACE_LIMIT)
assert res == 0
- for loop in get_stats().loops:
- assert len(loop.operations) <= TRACE_LIMIT + 5 # because we only check once per metainterp bytecode
- self.check_enter_count(27) # maybe
+ self.check_max_trace_length(TRACE_LIMIT)
+ self.check_enter_count(15) # maybe
+ self.check_aborted_count(7)
+
+ def test_trace_limit_bridge(self):
+ def recursive(n):
+ if n > 0:
+ return recursive(n - 1) + 1
+ return 0
+ myjitdriver = JitDriver(greens=[], reds=['n'])
+ def loop(n):
+ myjitdriver.set_param("threshold", 4)
+ myjitdriver.set_param("trace_eagerness", 2)
+ while n:
+ myjitdriver.can_enter_jit(n=n)
+ myjitdriver.jit_merge_point(n=n)
+ if n % 5 == 0:
+ n -= 1
+ if n < 50:
+ n = recursive(n)
+ n -= 1
+ TRACE_LIMIT = 20
+ res = self.meta_interp(loop, [100], optimizer=simple_optimize, inline=True, trace_limit=TRACE_LIMIT)
+ self.check_max_trace_length(TRACE_LIMIT)
+ self.check_aborted_count(8)
+ self.check_enter_count_at_most(30)
+
class TestLLtype(RecursiveTests, LLJitMixin):
Modified: pypy/branch/agressive-inlining/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/agressive-inlining/pypy/jit/metainterp/warmspot.py (original)
+++ pypy/branch/agressive-inlining/pypy/jit/metainterp/warmspot.py Tue Sep 8 11:00:20 2009
@@ -871,6 +871,9 @@
key.counter += 1
return key.counter >= self.trace_eagerness
+ def reset_counter_from_failure(self, key):
+ key.counter = 0
+
def attach_unoptimized_bridge_from_interp(self, greenkey, bridge):
greenargs = self.unwrap_greenkey(greenkey)
newcell = MachineCodeEntryPoint(bridge, *greenargs)
More information about the Pypy-commit
mailing list