Author: Carl Friedrich Bolz <[email protected]>
Branch: improve-heap-caching-tracing
Changeset: r47011:9806d3b8c116
Date: 2011-09-02 10:21 +0200
http://bitbucket.org/pypy/pypy/changeset/9806d3b8c116/
Log: start a branch to cache more during tracing. start by stepwise
refactoring the current heap cache to be more independently testable
diff --git a/pypy/jit/metainterp/heapcache.py b/pypy/jit/metainterp/heapcache.py
new file mode 100644
--- /dev/null
+++ b/pypy/jit/metainterp/heapcache.py
@@ -0,0 +1,23 @@
+
+
+class HeapCache(object):
+ def __init__(self):
+ self.reset()
+
+ def reset(self):
+ # contains boxes where the class is already known
+ self.known_class_boxes = {}
+ # contains frame boxes that are not virtualizables
+ self.nonstandard_virtualizables = {}
+
+ def is_class_known(self, box):
+ return box in self.known_class_boxes
+
+ def class_now_know(self, box):
+ self.known_class_boxes[box] = None
+
+ def is_nonstandard_virtualizable(self, box):
+ return box in self.nonstandard_virtualizables
+
+ def nonstandard_virtualizables_now_known(self, box):
+ self.nonstandard_virtualizables[box] = None
diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py
--- a/pypy/jit/metainterp/pyjitpl.py
+++ b/pypy/jit/metainterp/pyjitpl.py
@@ -17,6 +17,7 @@
from pypy.jit.metainterp.jitprof import ABORT_TOO_LONG, ABORT_BRIDGE, \
ABORT_FORCE_QUASIIMMUT, ABORT_BAD_LOOP
from pypy.jit.metainterp.jitexc import JitException, get_llexception
+from pypy.jit.metainterp.heapcache import HeapCache
from pypy.rlib.objectmodel import specialize
from pypy.jit.codewriter.jitcode import JitCode, SwitchDictDescr
from pypy.jit.codewriter import heaptracker
@@ -321,7 +322,7 @@
def _establish_nullity(self, box, orgpc):
value = box.nonnull()
if value:
- if box not in self.metainterp.known_class_boxes:
+ if not self.metainterp.heapcache.is_class_known(box):
self.generate_guard(rop.GUARD_NONNULL, box, resumepc=orgpc)
else:
if not isinstance(box, Const):
@@ -373,7 +374,7 @@
cpu = self.metainterp.cpu
cls = heaptracker.descr2vtable(cpu, sizedescr)
resbox = self.execute(rop.NEW_WITH_VTABLE, ConstInt(cls))
- self.metainterp.known_class_boxes[resbox] = None
+ self.metainterp.heapcache.class_now_know(resbox)
return resbox
## @FixME #arguments("box")
@@ -633,7 +634,7 @@
standard_box = self.metainterp.virtualizable_boxes[-1]
if standard_box is box:
return False
- if box in self.metainterp.nonstandard_virtualizables:
+ if self.metainterp.heapcache.is_nonstandard_virtualizable(box):
return True
eqbox = self.metainterp.execute_and_record(rop.PTR_EQ, None,
box, standard_box)
@@ -642,7 +643,7 @@
if isstandard:
self.metainterp.replace_box(box, standard_box)
else:
- self.metainterp.nonstandard_virtualizables[box] = None
+ self.metainterp.heapcache.nonstandard_virtualizables_now_known(box)
return not isstandard
def _get_virtualizable_field_index(self, fielddescr):
@@ -884,9 +885,9 @@
@arguments("orgpc", "box")
def opimpl_guard_class(self, orgpc, box):
clsbox = self.cls_of_box(box)
- if box not in self.metainterp.known_class_boxes:
+ if not self.metainterp.heapcache.is_class_known(box):
self.generate_guard(rop.GUARD_CLASS, box, [clsbox], resumepc=orgpc)
- self.metainterp.known_class_boxes[box] = None
+ self.metainterp.heapcache.class_now_know(box)
return clsbox
@arguments("int", "orgpc")
@@ -1492,10 +1493,7 @@
self.last_exc_value_box = None
self.retracing_loop_from = None
self.call_pure_results = args_dict_box()
- # contains boxes where the class is already known
- self.known_class_boxes = {}
- # contains frame boxes that are not virtualizables
- self.nonstandard_virtualizables = {}
+ self.heapcache = HeapCache()
# heap cache
# maps descrs to (from_box, to_box) tuples
self.heap_cache = {}
@@ -1862,8 +1860,7 @@
duplicates[box] = None
def reached_loop_header(self, greenboxes, redboxes, resumedescr):
- self.known_class_boxes = {}
- self.nonstandard_virtualizables = {} # XXX maybe not needed?
+ self.heapcache.reset()
self.heap_cache = {}
self.heap_array_cache = {}
diff --git a/pypy/jit/metainterp/test/test_heapcache.py
b/pypy/jit/metainterp/test/test_heapcache.py
new file mode 100644
--- /dev/null
+++ b/pypy/jit/metainterp/test/test_heapcache.py
@@ -0,0 +1,26 @@
+from pypy.jit.metainterp.heapcache import HeapCache
+
+class TestHeapCache(object):
+ def test_known_class_box(self):
+ h = HeapCache()
+ assert not h.is_class_known(1)
+ assert not h.is_class_known(2)
+ h.class_now_know(1)
+ assert h.is_class_known(1)
+ assert not h.is_class_known(2)
+
+ h.reset()
+ assert not h.is_class_known(1)
+ assert not h.is_class_known(2)
+
+ def test_nonstandard_virtualizable(self):
+ h = HeapCache()
+ assert not h.is_nonstandard_virtualizable(1)
+ assert not h.is_nonstandard_virtualizable(2)
+ h.nonstandard_virtualizables_now_known(1)
+ assert h.is_nonstandard_virtualizable(1)
+ assert not h.is_nonstandard_virtualizable(2)
+
+ h.reset()
+ assert not h.is_nonstandard_virtualizable(1)
+ assert not h.is_nonstandard_virtualizable(2)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit