[pypy-svn] r68677 - in pypy/trunk/pypy/jit/metainterp: . test
fijal at codespeak.net
fijal at codespeak.net
Wed Oct 21 13:32:55 CEST 2009
Author: fijal
Date: Wed Oct 21 13:32:55 2009
New Revision: 68677
Modified:
pypy/trunk/pypy/jit/metainterp/compile.py
pypy/trunk/pypy/jit/metainterp/history.py
pypy/trunk/pypy/jit/metainterp/optimizeopt.py
pypy/trunk/pypy/jit/metainterp/pyjitpl.py
pypy/trunk/pypy/jit/metainterp/test/test_optimizeopt.py
pypy/trunk/pypy/jit/metainterp/test/test_recursive.py
Log:
Check in raising GiveUp when number of fail args for guards exceeds
some limit (1000 for now)
Modified: pypy/trunk/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/compile.py (original)
+++ pypy/trunk/pypy/jit/metainterp/compile.py Wed Oct 21 13:32:55 2009
@@ -13,6 +13,9 @@
from pypy.jit.metainterp.typesystem import llhelper, oohelper
from pypy.jit.metainterp.optimizeutil import InvalidLoop
+class GiveUp(Exception):
+ pass
+
def show_loop(metainterp_sd, loop=None, error=None):
# debugging
if option.view or option.viewloops:
@@ -284,7 +287,6 @@
old_loop_tokens,
new_loop)
except InvalidLoop:
- assert 0, "InvalidLoop in optimize_bridge?"
return None
# Did it work?
if target_loop_token is not None:
Modified: pypy/trunk/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/history.py (original)
+++ pypy/trunk/pypy/jit/metainterp/history.py Wed Oct 21 13:32:55 2009
@@ -21,6 +21,8 @@
REF = 'r'
FLOAT = 'f'
+FAILARGS_LIMIT = 1000
+
def getkind(TYPE, supports_floats=True):
if TYPE is lltype.Void:
return "void"
@@ -117,6 +119,9 @@
def repr_rpython(self):
return '%s' % self
+ def _get_str(self):
+ raise NotImplementedError
+
class AbstractDescr(AbstractValue):
__slots__ = ()
@@ -930,8 +935,9 @@
# ----------------------------------------------------------------
class Options:
- def __init__(self, listops=False):
+ def __init__(self, listops=False, failargs_limit=FAILARGS_LIMIT):
self.listops = listops
+ self.failargs_limit = failargs_limit
def _freeze_(self):
return True
Modified: pypy/trunk/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/optimizeopt.py (original)
+++ pypy/trunk/pypy/jit/metainterp/optimizeopt.py Wed Oct 21 13:32:55 2009
@@ -520,6 +520,8 @@
assert isinstance(descr, compile.ResumeGuardDescr)
modifier = resume.ResumeDataVirtualAdder(descr, self.resumedata_memo)
newboxes = modifier.finish(self.values)
+ if len(newboxes) > self.metainterp_sd.options.failargs_limit:
+ raise compile.GiveUp
descr.store_final_boxes(op, newboxes)
def optimize_default(self, op):
Modified: pypy/trunk/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/trunk/pypy/jit/metainterp/pyjitpl.py Wed Oct 21 13:32:55 2009
@@ -16,6 +16,7 @@
from pypy.rlib.rarithmetic import intmask
from pypy.rlib.objectmodel import specialize
from pypy.rlib.jit import DEBUG_OFF, DEBUG_PROFILE, DEBUG_STEPS, DEBUG_DETAILED
+from pypy.jit.metainterp.compile import GiveUp
# ____________________________________________________________
@@ -1154,7 +1155,11 @@
return True
else:
if not self.is_blackholing():
- self.compile_done_with_this_frame(resultbox)
+ try:
+ self.compile_done_with_this_frame(resultbox)
+ except GiveUp:
+ self.staticdata.profiler.count(ABORT_BRIDGE)
+ self.switch_to_blackhole()
sd = self.staticdata
if sd.result_type == 'void':
assert resultbox is None
@@ -1188,7 +1193,11 @@
return True
self.popframe()
if not self.is_blackholing():
- self.compile_exit_frame_with_exception(excvaluebox)
+ try:
+ self.compile_exit_frame_with_exception(excvaluebox)
+ except GiveUp:
+ self.staticdata.profiler.count(ABORT_BRIDGE)
+ self.switch_to_blackhole()
raise self.staticdata.ExitFrameWithExceptionRef(self.cpu, excvaluebox.getref_base())
def check_recursion_invariant(self):
@@ -1801,6 +1810,3 @@
assert target_loop_token is not None
self.argboxes = args
self.target_loop_token = target_loop_token
-
-class GiveUp(Exception):
- pass
Modified: pypy/trunk/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_optimizeopt.py (original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_optimizeopt.py Wed Oct 21 13:32:55 2009
@@ -23,11 +23,15 @@
self.pc = pc
self.exception_target = exc_target
+class FakeOptions(object):
+ failargs_limit = 1000
+
class FakeMetaInterpStaticData(object):
def __init__(self, cpu):
self.cpu = cpu
self.profiler = EmptyProfiler()
+ self.options = FakeOptions()
def test_store_final_boxes_in_guard():
from pypy.jit.metainterp.compile import ResumeGuardDescr
Modified: pypy/trunk/pypy/jit/metainterp/test/test_recursive.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_recursive.py (original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_recursive.py Wed Oct 21 13:32:55 2009
@@ -393,6 +393,80 @@
self.check_aborted_count(8)
self.check_enter_count_at_most(30)
+ def test_max_failure_args(self):
+ FAILARGS_LIMIT = 10
+ jitdriver = JitDriver(greens = [], reds = ['o', 'i', 'n'])
+
+ class A(object):
+ def __init__(self, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9):
+ self.i0 = i0
+ self.i1 = i1
+ self.i2 = i2
+ self.i3 = i3
+ self.i4 = i4
+ self.i5 = i5
+ self.i6 = i6
+ self.i7 = i7
+ self.i8 = i8
+ self.i9 = i9
+
+
+ def loop(n):
+ i = 0
+ o = A(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
+ while i < n:
+ jitdriver.can_enter_jit(o=o, i=i, n=n)
+ jitdriver.jit_merge_point(o=o, i=i, n=n)
+ o = A(i, i + 1, i + 2, i + 3, i + 4, i + 5,
+ i + 6, i + 7, i + 8, i + 9)
+ i += 1
+ return o
+
+ res = self.meta_interp(loop, [20], failargs_limit=FAILARGS_LIMIT,
+ listops=True)
+ self.check_aborted_count(5)
+
+ def test_max_failure_args_exc(self):
+ FAILARGS_LIMIT = 10
+ jitdriver = JitDriver(greens = [], reds = ['o', 'i', 'n'])
+
+ class A(object):
+ def __init__(self, i0, i1, i2, i3, i4, i5, i6, i7, i8, i9):
+ self.i0 = i0
+ self.i1 = i1
+ self.i2 = i2
+ self.i3 = i3
+ self.i4 = i4
+ self.i5 = i5
+ self.i6 = i6
+ self.i7 = i7
+ self.i8 = i8
+ self.i9 = i9
+
+
+ def loop(n):
+ i = 0
+ o = A(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
+ while i < n:
+ jitdriver.can_enter_jit(o=o, i=i, n=n)
+ jitdriver.jit_merge_point(o=o, i=i, n=n)
+ o = A(i, i + 1, i + 2, i + 3, i + 4, i + 5,
+ i + 6, i + 7, i + 8, i + 9)
+ i += 1
+ raise ValueError
+
+ def main(n):
+ try:
+ loop(n)
+ return 1
+ except ValueError:
+ return 0
+
+ res = self.meta_interp(main, [20], failargs_limit=FAILARGS_LIMIT,
+ listops=True)
+ assert not res
+ self.check_aborted_count(5)
+
def test_set_param_inlining(self):
myjitdriver = JitDriver(greens=[], reds=['n', 'recurse'])
def loop(n, recurse=False):
More information about the Pypy-commit
mailing list