Example #1
0
 def test_circular_virtuals(self):
     h = HeapCache()
     h.new(box1)
     h.new(box2)
     h.invalidate_caches(rop.SETFIELD_GC, None, [box1, box2])
     h.invalidate_caches(rop.SETFIELD_GC, None, [box2, box1])
     h.invalidate_caches(rop.SETFIELD_GC, None, [box3, box1]) # does not crash
Example #2
0
 def test_circular_virtuals(self):
     h = HeapCache()
     h.new(box1)
     h.new(box2)
     h.invalidate_caches(rop.SETFIELD_GC, None, [box1, box2])
     h.invalidate_caches(rop.SETFIELD_GC, None, [box2, box1])
     h.invalidate_caches(rop.SETFIELD_GC, None, [box3, box1]) # does not crash
Example #3
0
 def test_unescaped_array(self):
     h = HeapCache()
     h.new_array(box1, lengthbox1)
     assert h.is_unescaped(box1)
     h.invalidate_caches(rop.SETARRAYITEM_GC, None, [box1, index1, box2])
     assert h.is_unescaped(box1)
     h.invalidate_caches(rop.SETARRAYITEM_GC, None, [box2, index1, box1])
     assert not h.is_unescaped(box1)
Example #4
0
 def test_unescaped(self):
     h = HeapCache()
     assert not h.is_unescaped(box1)
     h.new(box2)
     assert h.is_unescaped(box2)
     h.invalidate_caches(rop.SETFIELD_GC, None, [box2, box1])
     assert h.is_unescaped(box2)
     h.invalidate_caches(rop.SETFIELD_GC, None, [box1, box2])
     assert not h.is_unescaped(box2)
Example #5
0
 def test_unescaped(self):
     h = HeapCache()
     assert not h.is_unescaped(box1)
     h.new(box2)
     assert h.is_unescaped(box2)
     h.invalidate_caches(rop.SETFIELD_GC, None, [box2, box1])
     assert h.is_unescaped(box2)
     h.invalidate_caches(rop.SETFIELD_GC, None, [box1, box2])
     assert not h.is_unescaped(box2)
Example #6
0
    def test_ll_arraycopy(self):
        h = HeapCache()
        h.new_array(box1, lengthbox1)
        h.setarrayitem(box1, descr1, index1, box2)
        h.new_array(box2, lengthbox1)
        # Just need the destination box for this call
        h.invalidate_caches(
            rop.CALL,
            FakeCallDescr(FakeEffektinfo.EF_CANNOT_RAISE,
                          FakeEffektinfo.OS_ARRAYCOPY),
            [None, None, box2, None, None])
        assert h.getarrayitem(box1, descr1, index1) is box2
        h.invalidate_caches(
            rop.CALL,
            FakeCallDescr(FakeEffektinfo.EF_CANNOT_RAISE,
                          FakeEffektinfo.OS_ARRAYCOPY),
            [None, None, box3, None, None])
        assert h.getarrayitem(box1, descr1, index1) is None

        h.setarrayitem(box4, descr1, index1, box2)
        assert h.getarrayitem(box4, descr1, index1) is box2
        h.invalidate_caches(
            rop.CALL,
            FakeCallDescr(FakeEffektinfo.EF_CANNOT_RAISE,
                          FakeEffektinfo.OS_ARRAYCOPY),
            [None, None, box2, None, None])
        assert h.getarrayitem(box4, descr1, index1) is None
Example #7
0
    def test_ll_arraycopy(self):
        h = HeapCache()
        h.new_array(box1, lengthbox1)
        h.setarrayitem(box1, descr1, index1, box2)
        h.new_array(box2, lengthbox1)
        # Just need the destination box for this call
        h.invalidate_caches(
            rop.CALL,
            FakeCallDescr(FakeEffektinfo.EF_CANNOT_RAISE, FakeEffektinfo.OS_ARRAYCOPY),
            [None, None, box2, None, None]
        )
        assert h.getarrayitem(box1, descr1, index1) is box2
        h.invalidate_caches(
            rop.CALL,
            FakeCallDescr(FakeEffektinfo.EF_CANNOT_RAISE, FakeEffektinfo.OS_ARRAYCOPY),
            [None, None, box3, None, None]
        )
        assert h.getarrayitem(box1, descr1, index1) is None

        h.setarrayitem(box4, descr1, index1, box2)
        assert h.getarrayitem(box4, descr1, index1) is box2
        h.invalidate_caches(
            rop.CALL,
            FakeCallDescr(FakeEffektinfo.EF_CANNOT_RAISE, FakeEffektinfo.OS_ARRAYCOPY),
            [None, None, box2, None, None]
        )
        assert h.getarrayitem(box4, descr1, index1) is None
Example #8
0
    def test_unescaped_array(self):
        h = HeapCache()
        h.new_array(box1, lengthbox1)
        assert h.is_unescaped(box1)
        h.invalidate_caches(rop.SETARRAYITEM_GC, None, [box1, index1, box2])
        assert h.is_unescaped(box1)
        h.invalidate_caches(rop.SETARRAYITEM_GC, None, [box2, index1, box1])
        assert not h.is_unescaped(box1)

        h = HeapCache()
        h.new_array(box1, lengthbox1)
        h.new(box2)
        assert h.is_unescaped(box1)
        assert h.is_unescaped(box2)
        h.invalidate_caches(rop.SETARRAYITEM_GC, None, [box1, lengthbox2, box2])
        assert h.is_unescaped(box1)
        assert h.is_unescaped(box2)
        h.invalidate_caches(
            rop.CALL, FakeCallDescr(FakeEffektinfo.EF_RANDOM_EFFECTS), [box1]
        )
        assert not h.is_unescaped(box1)
        assert not h.is_unescaped(box2)
Example #9
0
    def test_unescaped_array(self):
        h = HeapCache()
        h.new_array(box1, lengthbox1)
        assert h.is_unescaped(box1)
        h.invalidate_caches(rop.SETARRAYITEM_GC, None, [box1, index1, box2])
        assert h.is_unescaped(box1)
        h.invalidate_caches(rop.SETARRAYITEM_GC, None, [box2, index1, box1])
        assert not h.is_unescaped(box1)

        h = HeapCache()
        h.new_array(box1, lengthbox1)
        h.new(box2)
        assert h.is_unescaped(box1)
        assert h.is_unescaped(box2)
        h.invalidate_caches(rop.SETARRAYITEM_GC, None, [box1, lengthbox2, box2])
        assert h.is_unescaped(box1)
        assert h.is_unescaped(box2)
        h.invalidate_caches(
            rop.CALL, FakeCallDescr(FakeEffektinfo.EF_RANDOM_EFFECTS), [box1]
        )
        assert not h.is_unescaped(box1)
        assert not h.is_unescaped(box2)
Example #10
0
 def test_unescaped_testing(self):
     h = HeapCache()
     h.new(box1)
     h.new(box2)
     assert h.is_unescaped(box1)
     assert h.is_unescaped(box2)
     # Putting a virtual inside of another virtual doesn't escape it.
     h.invalidate_caches(rop.SETFIELD_GC, None, [box1, box2])
     assert h.is_unescaped(box2)
     # Reading a field from a virtual doesn't escape it.
     h.invalidate_caches(rop.GETFIELD_GC, None, [box1])
     assert h.is_unescaped(box1)
     # Escaping a virtual transitively escapes anything inside of it.
     assert not h.is_unescaped(box3)
     h.invalidate_caches(rop.SETFIELD_GC, None, [box3, box1])
     assert not h.is_unescaped(box1)
     assert not h.is_unescaped(box2)
Example #11
0
 def test_unescaped_testing(self):
     h = HeapCache()
     h.new(box1)
     h.new(box2)
     assert h.is_unescaped(box1)
     assert h.is_unescaped(box2)
     # Putting a virtual inside of another virtual doesn't escape it.
     h.invalidate_caches(rop.SETFIELD_GC, None, [box1, box2])
     assert h.is_unescaped(box2)
     # Reading a field from a virtual doesn't escape it.
     h.invalidate_caches(rop.GETFIELD_GC, None, [box1])
     assert h.is_unescaped(box1)
     # Escaping a virtual transitively escapes anything inside of it.
     assert not h.is_unescaped(box3)
     h.invalidate_caches(rop.SETFIELD_GC, None, [box3, box1])
     assert not h.is_unescaped(box1)
     assert not h.is_unescaped(box2)
Example #12
0
    def test_invalidate_cache(self):
        h = HeapCache()
        h.setfield(box1, descr1, box2)
        h.setarrayitem(box1, descr1, index1, box2)
        h.setarrayitem(box1, descr1, index2, box4)
        h.invalidate_caches(rop.INT_ADD, None, [])
        h.invalidate_caches(rop.INT_ADD_OVF, None, [])
        h.invalidate_caches(rop.SETFIELD_RAW, None, [])
        h.invalidate_caches(rop.SETARRAYITEM_RAW, None, [])
        assert h.getfield(box1, descr1) is box2
        assert h.getarrayitem(box1, descr1, index1) is box2
        assert h.getarrayitem(box1, descr1, index2) is box4

        h.invalidate_caches(
            rop.CALL, FakeCallDescr(FakeEffektinfo.EF_ELIDABLE_CANNOT_RAISE),
            [])
        assert h.getfield(box1, descr1) is box2
        assert h.getarrayitem(box1, descr1, index1) is box2
        assert h.getarrayitem(box1, descr1, index2) is box4

        h.invalidate_caches(rop.GUARD_TRUE, None, [])
        assert h.getfield(box1, descr1) is box2
        assert h.getarrayitem(box1, descr1, index1) is box2
        assert h.getarrayitem(box1, descr1, index2) is box4

        h.invalidate_caches(rop.CALL_LOOPINVARIANT,
                            FakeCallDescr(FakeEffektinfo.EF_LOOPINVARIANT), [])

        h.invalidate_caches(rop.CALL,
                            FakeCallDescr(FakeEffektinfo.EF_RANDOM_EFFECTS),
                            [])
        assert h.getfield(box1, descr1) is None
        assert h.getarrayitem(box1, descr1, index1) is None
        assert h.getarrayitem(box1, descr1, index2) is None
Example #13
0
    def test_invalidate_cache(self):
        h = HeapCache()
        h.setfield(box1, descr1, box2)
        h.setarrayitem(box1, descr1, index1, box2)
        h.setarrayitem(box1, descr1, index2, box4)
        h.invalidate_caches(rop.INT_ADD, None, [])
        h.invalidate_caches(rop.INT_ADD_OVF, None, [])
        h.invalidate_caches(rop.SETFIELD_RAW, None, [])
        h.invalidate_caches(rop.SETARRAYITEM_RAW, None, [])
        assert h.getfield(box1, descr1) is box2
        assert h.getarrayitem(box1, descr1, index1) is box2
        assert h.getarrayitem(box1, descr1, index2) is box4

        h.invalidate_caches(
            rop.CALL, FakeCallDescr(FakeEffektinfo.EF_ELIDABLE_CANNOT_RAISE), [])
        assert h.getfield(box1, descr1) is box2
        assert h.getarrayitem(box1, descr1, index1) is box2
        assert h.getarrayitem(box1, descr1, index2) is box4

        h.invalidate_caches(
            rop.CALL_LOOPINVARIANT, FakeCallDescr(FakeEffektinfo.EF_LOOPINVARIANT), [])

        h.invalidate_caches(
            rop.CALL, FakeCallDescr(FakeEffektinfo.EF_RANDOM_EFFECTS), [])
        assert h.getfield(box1, descr1) is None
        assert h.getarrayitem(box1, descr1, index1) is None
        assert h.getarrayitem(box1, descr1, index2) is None