[pypy-svn] r53092 - in pypy/branch/jit-hotpath/pypy/jit/rainbow: . test
arigo at codespeak.net
arigo at codespeak.net
Sat Mar 29 14:29:24 CET 2008
Author: arigo
Date: Sat Mar 29 14:29:24 2008
New Revision: 53092
Modified:
pypy/branch/jit-hotpath/pypy/jit/rainbow/hotpath.py
pypy/branch/jit-hotpath/pypy/jit/rainbow/rhotpath.py
pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hotpath.py
Log:
Add the trace_eagerness and hash_bits parameters.
Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/hotpath.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/hotpath.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/hotpath.py Sat Mar 29 14:29:24 2008
@@ -1,3 +1,4 @@
+import sys
from pypy.objspace.flow.model import Constant, Variable, SpaceOperation
from pypy.objspace.flow.model import Link, checkgraph
from pypy.annotation import model as annmodel
@@ -322,6 +323,8 @@
# ____________________________________________________________
+THRESHOLD_MAX = (sys.maxint-1) / 2
+
def make_state_class(hotrunnerdesc):
# very minimal, just to make the first test pass
num_green_args = len(hotrunnerdesc.green_args_spec)
@@ -332,9 +335,11 @@
green_args_range = unrolling_iterable(
range(len(hotrunnerdesc.green_args_spec)))
if hotrunnerdesc.green_args_spec:
- HASH_TABLE_SIZE = 2 ** 14
+ INITIAL_HASH_TABLE_BITS = 14
+ MAX_HASH_TABLE_BITS = 28
else:
- HASH_TABLE_SIZE = 1
+ INITIAL_HASH_TABLE_BITS = 0
+ MAX_HASH_TABLE_BITS = 0
# ---------- hacks for the 'invariants' argument ----------
drivercls = hotrunnerdesc.jitdrivercls
@@ -376,8 +381,29 @@
NULL_MC = lltype.nullptr(hotrunnerdesc.RESIDUAL_FUNCTYPE)
def __init__(self):
- self.cells = [Counter(0)] * HASH_TABLE_SIZE
- self.threshold = 10
+ self.set_param_threshold(40)
+ self.set_param_trace_eagerness(10)
+ self.set_param_hash_bits(INITIAL_HASH_TABLE_BITS)
+
+ def set_param_threshold(self, threshold):
+ if threshold > THRESHOLD_MAX:
+ threshold = THRESHOLD_MAX
+ self.threshold = threshold
+
+ def set_param_trace_eagerness(self, value):
+ if value <= 0:
+ value = 1
+ elif value > THRESHOLD_MAX:
+ value = THRESHOLD_MAX
+ self.trace_eagerness = value
+
+ def set_param_hash_bits(self, value):
+ if value < 0:
+ value = 0
+ elif value > MAX_HASH_TABLE_BITS:
+ value = MAX_HASH_TABLE_BITS
+ self.cells = [Counter(0)] * (1 << value)
+ self.hashtablemask = (1 << value) - 1
# Only use the hash of the arguments as the profiling key.
# Indeed, this is all a heuristic, so if things are designed
@@ -387,7 +413,7 @@
def maybe_compile(self, *args):
greenargs = args[:num_green_args]
argshash = self.getkeyhash(*greenargs)
- argshash &= (HASH_TABLE_SIZE - 1)
+ argshash &= self.hashtablemask
cell = self.cells[argshash]
if isinstance(cell, Counter):
# update the profiling counter
@@ -521,7 +547,4 @@
return residualargs
make_residualargs._always_inline_ = True
- def set_param_threshold(self, threshold):
- self.threshold = threshold
-
return HotEnterState
Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/rhotpath.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/rhotpath.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/rhotpath.py Sat Mar 29 14:29:24 2008
@@ -188,7 +188,11 @@
value = bool(value)
threshold = self.hotrunnerdesc.state.threshold
if value:
- counter = self.truepath_counter + 1
+ if self.falsepath_counter >= 0: # if other path not compiled either
+ bump = self.hotrunnerdesc.state.trace_eagerness
+ else:
+ bump = 1
+ counter = self.truepath_counter + bump
assert counter > 0, (
"reaching a fallback point for an already-compiled path")
if counter >= threshold:
@@ -196,7 +200,11 @@
self.truepath_counter = counter
return False
else:
- counter = self.falsepath_counter + 1
+ if self.truepath_counter >= 0: # if other path not compiled either
+ bump = self.hotrunnerdesc.state.trace_eagerness
+ else:
+ bump = 1
+ counter = self.falsepath_counter + bump
assert counter > 0, (
"reaching a fallback point for an already-compiled path")
if counter >= threshold:
@@ -256,7 +264,12 @@
def check_should_compile(self, value):
# XXX unsafe with a moving GC
hash = cast_whatever_to_int(lltype.typeOf(value), value)
- counter = self.counters.get(hash, 0) + 1
+ counter = self.counters.setdefault(hash, 0)
+ if len(self.counters) == 1: # if no other path compiled so far
+ bump = self.hotrunnerdesc.state.trace_eagerness
+ else:
+ bump = 1
+ counter = counter + bump
threshold = self.hotrunnerdesc.state.threshold
assert counter > 0, (
"reaching a fallback point for an already-compiled path")
Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hotpath.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hotpath.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/test/test_hotpath.py Sat Mar 29 14:29:24 2008
@@ -78,6 +78,7 @@
self.translate_support_code)
self.hotrunnerdesc.rewrite_all()
self.hotrunnerdesc.state.set_param_threshold(threshold)
+ self.hotrunnerdesc.state.set_param_trace_eagerness(1) # for tests
if self.simplify_virtualizable_accesses:
from pypy.jit.rainbow import graphopt
graphopt.simplify_virtualizable_accesses(self.writer)
@@ -452,6 +453,42 @@
"fb_return 1025",
])
+ def test_set_trace_eagerness(self):
+ class MyJitDriver(JitDriver):
+ greens = []
+ reds = ['i', 'x']
+ def ll_function(x):
+ MyJitDriver.set_param(trace_eagerness=x)
+ i = 1024
+ while i > 0:
+ i >>= 1
+ x += i
+ MyJitDriver.jit_merge_point(i=i, x=x)
+ MyJitDriver.can_enter_jit(i=i, x=x)
+ return x
+ res = self.run(ll_function, [2], threshold=5)
+ assert res == 1025
+ self.check_traces([
+ "jit_not_entered 512 514",
+ "jit_not_entered 256 770",
+ "jit_not_entered 128 898",
+ "jit_not_entered 64 962",
+ "jit_compile", # after the threshold of 5 is reached
+ "pause at hotsplit in ll_function",
+ "run_machine_code 32 994",
+ "fallback_interp",
+ "fb_leave 16 1010",
+ "run_machine_code 16 1010",
+ "fallback_interp",
+ "fb_leave 8 1018",
+ "run_machine_code 8 1018",
+ "jit_resume Bool path True in ll_function", # after 3 times already
+ "done at jit_merge_point", # 3*(eagerness=2) >= 5
+ "resume_machine_code",
+ "fallback_interp",
+ "fb_return 1025",
+ ])
+
def test_hp_tlr(self):
from pypy.jit.tl import tlr
More information about the Pypy-commit
mailing list