Commits

Alex Gaynor  committed 7bf619e

Fish the descr in the tracing HeapCache when optimizing LL_ARRAYCOPY

  • Participants
  • Parent commits fc18028

Comments (0)

Files changed (2)

File rpython/jit/metainterp/heapcache.py

             # effects are so well defined.
             elif effectinfo.oopspecindex == effectinfo.OS_ARRAYCOPY:
                 # The destination box
-                if argboxes[2] in self.new_boxes:
-                    # XXX: no descr here so we invalidate any of them, not just
-                    # of the correct type
-                    # XXX: in theory the indices of the copy could be looked at
-                    # as well
-                    for descr, cache in self.heap_array_cache.iteritems():
+                if (
+                    argboxes[2] in self.new_boxes and
+                    len(effectinfo.write_descrs_arrays) == 1
+                ):
+                    # Fish the descr out of the effectinfo
+                    cache = self.heap_array_cache.get(effectinfo.write_descrs_arrays[0])
+                    if cache is not None:
+                        # XXX: in theory the indices of the copy could be
+                        # looked at
                         for idx, cache in cache.iteritems():
                             for frombox in cache.keys():
                                 if not self.is_unescaped(frombox):

File rpython/jit/metainterp/test/test_heapcache.py

 
     OS_ARRAYCOPY = 0
 
-    def __init__(self, extraeffect, oopspecindex):
+    def __init__(self, extraeffect, oopspecindex, write_descrs_arrays):
         self.extraeffect = extraeffect
         self.oopspecindex = oopspecindex
+        self.write_descrs_arrays = write_descrs_arrays
+
 
 class FakeCallDescr(object):
-    def __init__(self, extraeffect, oopspecindex=None):
+    def __init__(self, extraeffect, oopspecindex=None, write_descrs_arrays=[]):
         self.extraeffect = extraeffect
         self.oopspecindex = oopspecindex
+        self.write_descrs_arrays = write_descrs_arrays
 
     def get_extra_info(self):
-        return FakeEffectinfo(self.extraeffect, self.oopspecindex)
+        return FakeEffectinfo(
+            self.extraeffect, self.oopspecindex,
+            write_descrs_arrays=self.write_descrs_arrays
+        )
+
 
 class TestHeapCache(object):
     def test_known_class_box(self):
         # Just need the destination box for this call
         h.invalidate_caches(
             rop.CALL,
-            FakeCallDescr(FakeEffectinfo.EF_CANNOT_RAISE, FakeEffectinfo.OS_ARRAYCOPY),
+            FakeCallDescr(FakeEffectinfo.EF_CANNOT_RAISE, FakeEffectinfo.OS_ARRAYCOPY, write_descrs_arrays=[descr1]),
             [None, None, box2, None, None]
         )
         assert h.getarrayitem(box1, index1, descr1) is box2
         h.invalidate_caches(
             rop.CALL,
-            FakeCallDescr(FakeEffectinfo.EF_CANNOT_RAISE, FakeEffectinfo.OS_ARRAYCOPY),
+            FakeCallDescr(FakeEffectinfo.EF_CANNOT_RAISE, FakeEffectinfo.OS_ARRAYCOPY, write_descrs_arrays=[descr1]),
             [None, None, box3, None, None]
         )
         assert h.getarrayitem(box1, index1, descr1) is None
         assert h.getarrayitem(box4, index1, descr1) is box2
         h.invalidate_caches(
             rop.CALL,
-            FakeCallDescr(FakeEffectinfo.EF_CANNOT_RAISE, FakeEffectinfo.OS_ARRAYCOPY),
+            FakeCallDescr(FakeEffectinfo.EF_CANNOT_RAISE, FakeEffectinfo.OS_ARRAYCOPY, write_descrs_arrays=[descr1]),
             [None, None, box2, None, None]
         )
         assert h.getarrayitem(box4, index1, descr1) is None
 
+    def test_ll_arraycopy_differing_descrs(self):
+        h = HeapCache()
+        h.setarrayitem(box1, index1, box2, descr1)
+        assert h.getarrayitem(box1, index1, descr1) is box2
+        h.new_array(box2, lengthbox2)
+        h.invalidate_caches(
+            rop.CALL,
+            FakeCallDescr(FakeEffectinfo.EF_CANNOT_RAISE, FakeEffectinfo.OS_ARRAYCOPY, write_descrs_arrays=[descr2]),
+            [None, None, box2, None, None]
+        )
+        assert h.getarrayitem(box1, index1, descr1) is box2
+
+
     def test_unescaped(self):
         h = HeapCache()
         assert not h.is_unescaped(box1)