Author: Hakan Ardo <[email protected]>
Branch: jit-targets
Changeset: r49365:16b76159c68e
Date: 2011-11-13 11:01 +0100
http://bitbucket.org/pypy/pypy/changeset/16b76159c68e/
Log: make sure history.Stats dont keep things alive
diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py
--- a/pypy/jit/metainterp/compile.py
+++ b/pypy/jit/metainterp/compile.py
@@ -89,8 +89,8 @@
assert descr.exported_state is None
if not we_are_translated():
op._descr_wref = weakref.ref(op._descr)
- # xxx why do we need to clear op._descr??
- #op._descr = None # clear reference, mostly for tests
+ op._descr = None # clear reference to prevent the history.Stats
+ # from keeping the loop alive during tests
# record this looptoken on the QuasiImmut used in the code
if loop.quasi_immutable_deps is not None:
for qmut in loop.quasi_immutable_deps:
diff --git a/pypy/jit/metainterp/history.py b/pypy/jit/metainterp/history.py
--- a/pypy/jit/metainterp/history.py
+++ b/pypy/jit/metainterp/history.py
@@ -10,6 +10,7 @@
from pypy.jit.metainterp.resoperation import ResOperation, rop
from pypy.jit.codewriter import heaptracker, longlong
from pypy.rlib.objectmodel import compute_identity_hash
+import weakref
# ____________________________________________________________
@@ -978,7 +979,7 @@
self.locations = []
self.aborted_keys = []
self.invalidated_token_numbers = set()
- self.jitcell_tokens = set()
+ self.jitcell_token_wrefs = set()
def clear(self):
del self.loops[:]
@@ -990,7 +991,7 @@
self.aborted_count = 0
def add_jitcell_token(self, token):
- self.jitcell_tokens.add(token)
+ self.jitcell_token_wrefs.add(weakref.ref(token))
def set_history(self, history):
self.operations = history.operations
@@ -1021,6 +1022,15 @@
def get_all_loops(self):
return self.loops
+ def get_all_jitcell_tokens(self):
+ tokens = [t() for t in self.jitcell_token_wrefs]
+ if None in tokens:
+ assert False, "get_all_jitcell_tokens will not work as "+\
+ "loops have been freed"
+ return tokens
+
+
+
def check_history(self, expected=None, **check):
insns = {}
for op in self.operations:
@@ -1038,7 +1048,7 @@
def check_resops(self, expected=None, **check):
insns = {}
- for loop in self.loops:
+ for loop in self.get_all_loops():
insns = loop.summary(adding_insns=insns)
if expected is not None:
insns.pop('debug_merge_point', None)
@@ -1053,7 +1063,7 @@
def check_loops(self, expected=None, everywhere=False, **check):
insns = {}
- for loop in self.loops:
+ for loop in self.get_all_loops():
#if not everywhere:
# if getattr(loop, '_ignore_during_counting', False):
# continue
@@ -1083,7 +1093,7 @@
def check_consistency(self):
"NOT_RPYTHON"
- for loop in self.loops:
+ for loop in self.get_all_loops():
loop.check_consistency()
def maybe_view(self):
diff --git a/pypy/jit/metainterp/test/support.py
b/pypy/jit/metainterp/test/support.py
--- a/pypy/jit/metainterp/test/support.py
+++ b/pypy/jit/metainterp/test/support.py
@@ -169,10 +169,11 @@
assert get_stats().compiled_count <= count
def check_jitcell_token_count(self, count): # was check_tree_loop_count
- assert len(get_stats().jitcell_tokens) == count
+ assert len(get_stats().jitcell_token_wrefs) == count
def check_target_token_count(self, count):
- n = sum([len(t.target_tokens) for t in get_stats().jitcell_tokens])
+ tokens = get_stats().get_all_jitcell_tokens()
+ n = sum ([len(t.target_tokens) for t in tokens])
assert n == count
def check_enter_count(self, count):
diff --git a/pypy/jit/metainterp/test/test_ajit.py
b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -84,7 +84,7 @@
if self.basic:
found = 0
- for op in get_stats().loops[0]._all_operations():
+ for op in get_stats().get_all_loops()[0]._all_operations():
if op.getopname() == 'guard_true':
liveboxes = op.getfailargs()
assert len(liveboxes) == 3
@@ -2704,7 +2704,7 @@
assert res == g(10)
self.check_jitcell_token_count(2)
- for cell in get_stats().jitcell_tokens:
+ for cell in get_stats().get_all_jitcell_tokens():
# Initialal trace with two labels and 5 retraces
assert len(cell.target_tokens) <= 7
@@ -2745,7 +2745,7 @@
res = self.meta_interp(f, [10, 7])
assert res == f(10, 7)
self.check_jitcell_token_count(2)
- for cell in get_stats().jitcell_tokens:
+ for cell in get_stats().get_all_jitcell_tokens():
assert len(cell.target_tokens) == 2
def g(n):
@@ -2754,7 +2754,7 @@
res = self.meta_interp(g, [10])
assert res == g(10)
self.check_jitcell_token_count(2)
- for cell in get_stats().jitcell_tokens:
+ for cell in get_stats().get_all_jitcell_tokens():
assert len(cell.target_tokens) <= 3
def g(n):
@@ -2765,7 +2765,7 @@
# 2 loops and one function
self.check_jitcell_token_count(3)
cnt = 0
- for cell in get_stats().jitcell_tokens:
+ for cell in get_stats().get_all_jitcell_tokens():
if cell.target_tokens is None:
cnt += 1
else:
diff --git a/pypy/jit/metainterp/test/test_list.py
b/pypy/jit/metainterp/test/test_list.py
--- a/pypy/jit/metainterp/test/test_list.py
+++ b/pypy/jit/metainterp/test/test_list.py
@@ -225,7 +225,7 @@
return s
res = self.meta_interp(f, [15], listops=True)
assert res == f(15)
- self.check_resops({'jump': 2, 'int_gt': 2, 'int_add': 2,
+ self.check_resops({'jump': 1, 'int_gt': 2, 'int_add': 2,
'guard_true': 2, 'int_sub': 2})
class TestOOtype(ListTests, OOJitMixin):
diff --git a/pypy/jit/metainterp/test/test_memmgr.py
b/pypy/jit/metainterp/test/test_memmgr.py
--- a/pypy/jit/metainterp/test/test_memmgr.py
+++ b/pypy/jit/metainterp/test/test_memmgr.py
@@ -99,7 +99,7 @@
assert res == 42
# we should see only the loop and the entry bridge
- self.check_tree_loop_count(2)
+ self.check_target_token_count(2)
def test_target_loop_kept_alive_or_not(self):
myjitdriver = JitDriver(greens=['m'], reds=['n'])
@@ -132,14 +132,15 @@
# case A
res = self.meta_interp(f, [], loop_longevity=3)
assert res == 42
- # we should see only the loop and the entry bridge for g(5) and g(7)
- self.check_tree_loop_count(4)
+ # we should see only the loop with preamble and the exit bridge
+ # for g(5) and g(7)
+ self.check_enter_count(4)
# case B, with a lower longevity
res = self.meta_interp(f, [], loop_longevity=1)
assert res == 42
# we should see a loop for each call to g()
- self.check_tree_loop_count(8 + 20*2*2)
+ self.check_enter_count(8 + 20*2)
def test_throw_away_old_loops(self):
myjitdriver = JitDriver(greens=['m'], reds=['n'])
@@ -154,7 +155,7 @@
for i in range(10):
g(1) # g(1) gets a loop and an entry bridge, stays alive
g(2) # (and an exit bridge, which does not count in
- g(1) # check_tree_loop_count)
+ g(1) # check_target_token_count)
g(3)
g(1)
g(4) # g(2), g(3), g(4), g(5) are thrown away every iteration
@@ -164,7 +165,7 @@
res = self.meta_interp(f, [], loop_longevity=3)
assert res == 42
- self.check_tree_loop_count(2 + 10*4*2)
+ self.check_enter_count(2 + 10*4*2)
def test_call_assembler_keep_alive(self):
myjitdriver1 = JitDriver(greens=['m'], reds=['n'])
@@ -198,7 +199,7 @@
res = self.meta_interp(f, [1], loop_longevity=4, inline=True)
assert res == 42
- self.check_tree_loop_count(12)
+ self.check_enter_count(12)
# ____________________________________________________________
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit