Author: Maciej Fijalkowski <fij...@gmail.com>
Branch: optresult
Changeset: r77915:078c342333aa
Date: 2015-06-05 17:25 +0200
http://bitbucket.org/pypy/pypy/changeset/078c342333aa/

Log:    backout an attempt on heapcache, does not seem to help

diff --git a/rpython/jit/metainterp/compile.py 
b/rpython/jit/metainterp/compile.py
--- a/rpython/jit/metainterp/compile.py
+++ b/rpython/jit/metainterp/compile.py
@@ -129,8 +129,6 @@
     metainterp_sd = metainterp.staticdata
     jitdriver_sd = metainterp.jitdriver_sd
     history = metainterp.history
-    forget_optimization_info(inputargs)
-    forget_optimization_info(history.operations)
 
     enable_opts = jitdriver_sd.warmstate.enable_opts
     if try_disabling_unroll:
@@ -907,8 +905,6 @@
     #
     # Attempt to use optimize_bridge().  This may return None in case
     # it does not work -- i.e. none of the existing old_loop_tokens match.
-    forget_optimization_info(metainterp.history.inputargs)
-    forget_optimization_info(metainterp.history.operations)
     new_trace = create_empty_loop(metainterp)
     new_trace.inputargs = metainterp.history.inputargs[:]
 
diff --git a/rpython/jit/metainterp/heapcache.py 
b/rpython/jit/metainterp/heapcache.py
--- a/rpython/jit/metainterp/heapcache.py
+++ b/rpython/jit/metainterp/heapcache.py
@@ -1,7 +1,7 @@
-from rpython.jit.metainterp.history import Const, ConstInt
-from rpython.jit.metainterp.resoperation import rop, OpHelpers, AbstractValue
+from rpython.jit.metainterp.history import ConstInt
+from rpython.jit.metainterp.resoperation import rop, OpHelpers
 
-class HeapCacheValue(AbstractValue):
+class HeapCacheValue(object):
     def __init__(self, box):
         self.box = box
         self.likely_virtual = False
@@ -62,19 +62,11 @@
 
 class HeapCache(object):
     def __init__(self):
-        self.list_of_operations = []
-        self._reset(None)
+        self.reset()
 
     def reset(self):
-        self._reset(self.list_of_operations)
-
-    def _reset(self, lst):
-        if lst is not None:
-            for i in range(len(lst)):
-                lst[i].set_forwarded(None)
-        self.const_cache = {}
         # maps boxes to values
-        #self.values = {}
+        self.values = {}
         # store the boxes that contain newly allocated objects, this maps the
         # boxes to a bool, the bool indicates whether or not the object has
         # escaped the trace or not (True means the box never escaped, False
@@ -101,29 +93,16 @@
         self.heap_array_cache = {}
 
     def reset_keep_likely_virtuals(self):
-        for elem in self.list_of_operations:
-            value = self.getvalue(elem, False)
-            if value is not None:
-                assert isinstance(value, HeapCacheValue)
-                value.reset_keep_likely_virtual()
+        for value in self.values.itervalues():
+            value.reset_keep_likely_virtual()
         self.heap_cache = {}
         self.heap_array_cache = {}
 
-    def getvalue(self, box, create=True):
-        if isinstance(box, Const):
-            v = self.const_cache.get(box, None)
-            if v is None:
-                self.const_cache[box] = v = HeapCacheValue(box)
-            return v
-        v = box.get_forwarded()
-        if v is None:
-            if not create:
-                return None
-            v = HeapCacheValue(box)
-            self.list_of_operations.append(box)
-            box.set_forwarded(v)
-        assert isinstance(v, HeapCacheValue)
-        return v
+    def getvalue(self, box):
+        value = self.values.get(box, None)
+        if not value:
+            value = self.values[box] = HeapCacheValue(box)
+        return value
 
     def getvalues(self, boxes):
         return [self.getvalue(box) for box in boxes]
@@ -179,7 +158,7 @@
                 self._escape_box(box)
 
     def _escape_box(self, box):
-        value = self.getvalue(box, False)
+        value = self.values.get(box, None)
         if not value:
             return
         self._escape(value)
@@ -288,31 +267,31 @@
         self.reset_keep_likely_virtuals()
 
     def is_class_known(self, box):
-        v = self.getvalue(box, False)
-        if v:
-            return v.known_class
+        value = self.values.get(box, None)
+        if value:
+            return value.known_class
         return False
 
     def class_now_known(self, box):
         self.getvalue(box).known_class = True
 
     def is_nonstandard_virtualizable(self, box):
-        v = self.getvalue(box, False)
-        if v:
-            return v.nonstandard_virtualizable
+        value = self.values.get(box, None)
+        if value:
+            return value.nonstandard_virtualizable
         return False
 
     def nonstandard_virtualizables_now_known(self, box):
         self.getvalue(box).nonstandard_virtualizable = True
 
     def is_unescaped(self, box):
-        value = self.getvalue(box, False)
+        value = self.values.get(box, None)
         if value:
             return value.is_unescaped
         return False
 
     def is_likely_virtual(self, box):
-        value = self.getvalue(box, False)
+        value = self.values.get(box, None)
         if value:
             return value.likely_virtual
         return False
@@ -328,11 +307,11 @@
         self.arraylen_now_known(box, lengthbox)
 
     def getfield(self, box, descr):
-        v = self.getvalue(box, False)
-        if v:
+        value = self.values.get(box, None)
+        if value:
             cache = self.heap_cache.get(descr, None)
             if cache:
-                tovalue = cache.read(v)
+                tovalue = cache.read(value)
                 if tovalue:
                     return tovalue.box
         return None
@@ -356,7 +335,7 @@
     def getarrayitem(self, box, indexbox, descr):
         if not isinstance(indexbox, ConstInt):
             return None
-        value = self.getvalue(box, False)
+        value = self.values.get(box, None)
         if value is None:
             return None
         index = indexbox.getint()
@@ -400,7 +379,7 @@
             indexcache.do_write_with_aliasing(value, fieldvalue)
 
     def arraylen(self, box):
-        value = self.getvalue(box, False)
+        value = self.values.get(box, None)
         if value and value.length:
             return value.length.box
         return None
@@ -410,11 +389,8 @@
         value.length = self.getvalue(lengthbox)
 
     def replace_box(self, oldbox, newbox):
-        value = self.getvalue(oldbox, False)
+        value = self.values.get(oldbox, None)
         if value is None:
             return
         value.box = newbox
-        if isinstance(newbox, Const):
-            self.const_cache[newbox] = value
-        else:
-            newbox.set_forwarded(value)
+        self.values[newbox] = value
diff --git a/rpython/jit/metainterp/pyjitpl.py 
b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -1907,7 +1907,6 @@
         self.current_call_id = 0
 
     def retrace_needed(self, trace, exported_state):
-        raise Exception("I dont want that function to exist")
         self.partial_trace = trace
         self.retracing_from = len(self.history.operations) - 1
         self.exported_state = exported_state
diff --git a/rpython/jit/metainterp/test/test_heapcache.py 
b/rpython/jit/metainterp/test/test_heapcache.py
--- a/rpython/jit/metainterp/test/test_heapcache.py
+++ b/rpython/jit/metainterp/test/test_heapcache.py
@@ -2,6 +2,14 @@
 from rpython.jit.metainterp.resoperation import rop, InputArgInt
 from rpython.jit.metainterp.history import ConstInt, BasicFailDescr
 
+box1 = "box1"
+box2 = "box2"
+box3 = "box3"
+box4 = "box4"
+box5 = "box5"
+lengthbox1 = object()
+lengthbox2 = object()
+lengthbox3 = object()
 descr1 = object()
 descr2 = object()
 descr3 = object()
@@ -50,37 +58,29 @@
 class TestHeapCache(object):
     def test_known_class_box(self):
         h = HeapCache()
-        i0 = InputArgInt(1)
-        i1 = InputArgInt(2)
-        assert not h.is_class_known(i0)
-        assert not h.is_class_known(i1)
-        h.class_now_known(i0)
-        assert h.is_class_known(i0)
-        assert not h.is_class_known(i1)
+        assert not h.is_class_known(1)
+        assert not h.is_class_known(2)
+        h.class_now_known(1)
+        assert h.is_class_known(1)
+        assert not h.is_class_known(2)
 
         h.reset()
-        assert not h.is_class_known(i0)
-        assert not h.is_class_known(i1)
+        assert not h.is_class_known(1)
+        assert not h.is_class_known(2)
 
     def test_nonstandard_virtualizable(self):
         h = HeapCache()
-        i0 = InputArgInt(1)
-        i1 = InputArgInt(2)
-        assert not h.is_nonstandard_virtualizable(i0)
-        assert not h.is_nonstandard_virtualizable(i1)
-        h.nonstandard_virtualizables_now_known(i0)
-        assert h.is_nonstandard_virtualizable(i0)
-        assert not h.is_nonstandard_virtualizable(i1)
+        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(i0)
-        assert not h.is_nonstandard_virtualizable(i1)
+        assert not h.is_nonstandard_virtualizable(1)
+        assert not h.is_nonstandard_virtualizable(2)
 
     def test_heapcache_fields(self):
-
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
         h = HeapCache()
         assert h.getfield(box1, descr1) is None
         assert h.getfield(box1, descr2) is None
@@ -105,11 +105,6 @@
 
     def test_heapcache_read_fields_multiple(self):
         h = HeapCache()
-
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
-        box4 = InputArgInt(3)
         h.getfield_now_known(box1, descr1, box2)
         h.getfield_now_known(box3, descr1, box4)
         assert h.getfield(box1, descr1) is box2
@@ -125,10 +120,6 @@
 
     def test_heapcache_write_fields_multiple(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
-        box4 = InputArgInt(3)
         h.setfield(box1, box2, descr1)
         assert h.getfield(box1, descr1) is box2
         h.setfield(box3, box4, descr1)
@@ -157,10 +148,6 @@
 
     def test_heapcache_arrays(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
-        box4 = InputArgInt(3)
         assert h.getarrayitem(box1, index1, descr1) is None
         assert h.getarrayitem(box1, index1, descr2) is None
         assert h.getarrayitem(box1, index2, descr1) is None
@@ -203,10 +190,6 @@
 
     def test_heapcache_array_nonconst_index(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
-        box4 = InputArgInt(3)
         h.setarrayitem(box1, index1, box2, descr1)
         h.setarrayitem(box1, index2, box4, descr1)
         assert h.getarrayitem(box1, index1, descr1) is box2
@@ -217,10 +200,6 @@
 
     def test_heapcache_read_fields_multiple_array(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
-        box4 = InputArgInt(3)
         h.getarrayitem_now_known(box1, index1, box2, descr1)
         h.getarrayitem_now_known(box3, index1, box4, descr1)
         assert h.getarrayitem(box1, index1, descr1) is box2
@@ -236,10 +215,6 @@
 
     def test_heapcache_write_fields_multiple_array(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
-        box4 = InputArgInt(3)
         h.setarrayitem(box1, index1, box2, descr1)
         assert h.getarrayitem(box1, index1, descr1) is box2
         h.setarrayitem(box3, index1, box4, descr1)
@@ -268,10 +243,6 @@
 
     def test_length_cache(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        lengthbox1 = InputArgInt(2)
-        lengthbox2 = InputArgInt(3)
         h.new_array(box1, lengthbox1)
         assert h.arraylen(box1) is lengthbox1
 
@@ -282,9 +253,6 @@
 
     def test_invalidate_cache(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box4 = InputArgInt(3)
         h.setfield(box1, box2, descr1)
         h.setarrayitem(box1, index1, box2, descr1)
         h.setarrayitem(box1, index2, box4, descr1)
@@ -318,10 +286,6 @@
 
     def test_replace_box(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
-        box4 = InputArgInt(3)
         h.setfield(box1, box2, descr1)
         h.setfield(box1, box3, descr2)
         h.setfield(box2, box3, descr3)
@@ -343,11 +307,6 @@
 
     def test_replace_box_twice(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
-        box4 = InputArgInt(3)
-        box5 = InputArgInt(4)    
         h.setfield(box1, box2, descr1)
         h.setfield(box1, box3, descr2)
         h.setfield(box2, box3, descr3)
@@ -371,12 +330,6 @@
 
     def test_replace_box_array(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
-        box4 = InputArgInt(3)
-        lengthbox1 = InputArgInt(0)
-        lengthbox2 = InputArgInt(2)
         h.setarrayitem(box1, index1, box2, descr1)
         h.setarrayitem(box1, index1, box3, descr2)
         h.arraylen_now_known(box1, lengthbox1)
@@ -396,15 +349,6 @@
 
     def test_replace_box_array_twice(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
-        box4 = InputArgInt(3)
-        box5 = InputArgInt(4)
-        lengthbox1 = InputArgInt(0)
-        lengthbox2 = InputArgInt(1)
-        lengthbox3 = InputArgInt(2)
-        
         h.setarrayitem(box1, index1, box2, descr1)
         h.setarrayitem(box1, index1, box3, descr2)
         h.arraylen_now_known(box1, lengthbox1)
@@ -426,12 +370,6 @@
 
     def test_ll_arraycopy(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
-        box4 = InputArgInt(3)
-        box5 = InputArgInt(4)
-        lengthbox1 = InputArgInt(0)
         h.new_array(box1, lengthbox1)
         h.setarrayitem(box1, index1, box2, descr1)
         h.new_array(box2, lengthbox1)
@@ -460,68 +398,49 @@
 
     def test_ll_arraycopy_differing_descrs(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
-        lengthbox2 = InputArgInt(1)
         h.setarrayitem(box1, index1, box2, descr2)
         assert h.getarrayitem(box1, index1, descr2) is box2
         h.new_array(box2, lengthbox2)
         h.invalidate_caches(
             rop.CALL_N,
             arraycopydescr1,
-            [ConstInt(123), box3, box2, index1, index1, index2]
+            [None, box3, box2, index1, index1, index2]
         )
         assert h.getarrayitem(box1, index1, descr2) is box2
 
     def test_ll_arraycopy_differing_descrs_nonconst_index(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
         h.setarrayitem(box1, index1, box2, descr2)
         assert h.getarrayitem(box1, index1, descr2) is box2
         h.invalidate_caches(
             rop.CALL_N,
             arraycopydescr1,
-            [ConstInt(123), box3, box2, index1, index1, InputArgInt()]
+            [None, box3, box2, index1, index1, InputArgInt()]
         )
         assert h.getarrayitem(box1, index1, descr2) is box2
 
     def test_ll_arraycopy_result_propogated(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
         h.setarrayitem(box1, index1, box2, descr1)
         h.invalidate_caches(
             rop.CALL_N,
             arraycopydescr1,
-            [ConstInt(13), box1, box3, index1, index1, index2]
+            [None, box1, box3, index1, index1, index2]
         )
         assert h.getarrayitem(box3, index1, descr1) is box2
 
     def test_ll_arraycopy_dest_new(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
-        box4 = InputArgInt(3)
-        lengthbox1 = InputArgInt(0)
         h.new_array(box1, lengthbox1)
         h.setarrayitem(box3, index1, box4, descr1)
         h.invalidate_caches(
             rop.CALL_N,
             arraycopydescr1,
-            [ConstInt(13), box2, box1, index1, index1, index2]
+            [None, box2, box1, index1, index1, index2]
         )
 
     def test_ll_arraycopy_doesnt_escape_arrays(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        lengthbox1 = InputArgInt(1)
-        lengthbox2 = InputArgInt(2)
         h.new_array(box1, lengthbox1)
         h.new_array(box2, lengthbox2)
         h.invalidate_caches(
@@ -534,15 +453,13 @@
         h.invalidate_caches(
             rop.CALL_N,
             arraycopydescr1,
-            [ConstInt(123), box2, box1, index1, index1, InputArgInt()]
+            [None, box2, box1, index1, index1, InputArgInt()]
         )
         assert not h.is_unescaped(box1)
         assert not h.is_unescaped(box2)
 
     def test_unescaped(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
         assert not h.is_unescaped(box1)
         h.new(box2)
         assert h.is_unescaped(box2)
@@ -553,9 +470,6 @@
 
     def test_unescaped_testing(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
         h.new(box1)
         h.new(box2)
         assert h.is_unescaped(box1)
@@ -574,8 +488,6 @@
 
     def test_ops_dont_escape(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
         h.new(box1)
         h.new(box2)
         assert h.is_unescaped(box1)
@@ -589,9 +501,6 @@
 
     def test_circular_virtuals(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        box3 = InputArgInt(2)
         h.new(box1)
         h.new(box2)
         h.invalidate_caches(rop.SETFIELD_GC, None, [box1, box2])
@@ -600,10 +509,6 @@
 
     def test_unescaped_array(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-        lengthbox1 = InputArgInt(0)
-        lengthbox2 = InputArgInt(1)
         h.new_array(box1, lengthbox1)
         assert h.is_unescaped(box1)
         h.invalidate_caches(rop.SETARRAYITEM_GC, None, [box1, index1, box2])
@@ -627,9 +532,6 @@
 
     def test_call_doesnt_invalidate_unescaped_boxes(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
-
         h.new(box1)
         assert h.is_unescaped(box1)
         h.setfield(box1, box2, descr1)
@@ -641,9 +543,6 @@
 
     def test_call_doesnt_invalidate_unescaped_array_boxes(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        lengthbox1 = InputArgInt(2)
-        box3 = InputArgInt(1)
         h.new_array(box1, lengthbox1)
         assert h.is_unescaped(box1)
         h.setarrayitem(box1, index1, box3, descr1)
@@ -655,8 +554,6 @@
 
     def test_bug_missing_ignored_operations(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
         h.new(box1)
         h.new(box2)
         h.setfield(box1, box2, descr1)
@@ -679,8 +576,6 @@
         # calling some residual code that changes the values on box3: then
         # the content of box2 is still cached at the old value.
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
         h.new(box1)
         h.new(box2)
         h.setfield(box1, box2, descr1)
@@ -693,8 +588,6 @@
 
     def test_bug_heap_cache_is_cleared_but_not_is_unescaped_2(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-        box2 = InputArgInt(1)
         h.new(box1)
         h.new(box2)
         h.setfield(box1, box2, descr1)
@@ -716,8 +609,6 @@
 
     def test_is_likely_virtual(self):
         h = HeapCache()
-        box1 = InputArgInt(0)
-
         h.new(box1)
         assert h.is_unescaped(box1)
         assert h.is_likely_virtual(box1)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to