def test_liveranges(self): i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0) t = Trace([i0, i1, i2], metainterp_sd) p0 = FakeOp(t.record_op(rop.NEW_WITH_VTABLE, [], descr=SomeDescr())) t.record_op(rop.GUARD_TRUE, [i0]) resume.capture_resumedata([], [i1, i2, p0], [p0, i1], t) assert t.get_live_ranges() == [4, 4, 4, 4]
def test_read_snapshot_interface(self): i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0) t = Trace([i0, i1, i2], metainterp_sd) t.record_op(rop.GUARD_TRUE, [i1]) frame0 = FakeFrame(1, JitCode(2), [i0, i1]) frame1 = FakeFrame(3, JitCode(4), [i2, i2]) resume.capture_resumedata([frame0, frame1], None, [], t) t.record_op(rop.GUARD_TRUE, [i1]) resume.capture_resumedata([frame0, frame1], None, [], t) (i0, i1, i2), l, iter = self.unpack(t) pos = l[0].rd_resume_position snapshot_iter = iter.get_snapshot_iter(pos) assert snapshot_iter.vable_array == [] assert snapshot_iter.vref_array == [] framestack = snapshot_iter.framestack jc_index, pc = snapshot_iter.unpack_jitcode_pc(framestack[1]) assert jc_index == 4 assert pc == 3 assert snapshot_iter.unpack_array(framestack[1].box_array) == [i2, i2] jc_index, pc = snapshot_iter.unpack_jitcode_pc(framestack[0]) assert jc_index == 2 assert pc == 1 assert snapshot_iter.unpack_array(framestack[0].box_array) == [i0, i1] pos = l[1].rd_resume_position snapshot_iter = iter.get_snapshot_iter(pos) framestack = snapshot_iter.framestack assert snapshot_iter.vable_array == [] assert snapshot_iter.vref_array == [] jc_index, pc = snapshot_iter.unpack_jitcode_pc(framestack[1]) assert jc_index == 4 assert pc == 3 assert snapshot_iter.unpack_array(framestack[1].box_array) == [i2, i2]
def test_ResumeDataLoopMemo_number_boxes(): memo = ResumeDataLoopMemo(FakeMetaInterpStaticData()) b1, b2 = [IntFrontendOp(0), IntFrontendOp(0)] assert memo.num_cached_boxes() == 0 boxes = [] num = memo.assign_number_to_box(b1, boxes) assert num == -1 assert boxes == [b1] assert memo.num_cached_boxes() == 1 boxes = [None] num = memo.assign_number_to_box(b1, boxes) assert num == -1 assert boxes == [b1] num = memo.assign_number_to_box(b2, boxes) assert num == -2 assert boxes == [b1, b2] assert memo.num_cached_boxes() == 2 boxes = [None, None] num = memo.assign_number_to_box(b2, boxes) assert num == -2 assert boxes == [None, b2] num = memo.assign_number_to_box(b1, boxes) assert num == -1 assert boxes == [b1, b2] memo.clear_box_virtual_numbers() assert memo.num_cached_boxes() == 0
def test_ll_arraycopy(self): h = HeapCache() box1 = RefFrontendOp(1) box2 = RefFrontendOp(2) box3 = RefFrontendOp(3) box4 = RefFrontendOp(4) box5 = RefFrontendOp(5) lengthbox1 = IntFrontendOp(11) lengthbox2 = IntFrontendOp(12) h.new_array(box1, lengthbox1) h.setarrayitem(box1, index1, box2, descr1) h.new_array(box2, lengthbox1) # Just need the destination box for this call h.invalidate_caches( rop.CALL_N, arraycopydescr1, [None, box5, box2, index1, index1, index1] ) assert h.getarrayitem(box1, index1, descr1) is box2 h.invalidate_caches( rop.CALL_N, arraycopydescr1, [None, box5, box3, index1, index1, index1] ) assert h.getarrayitem(box1, index1, descr1) is box2 h.setarrayitem(box4, index1, box2, descr1) assert h.getarrayitem(box4, index1, descr1) is box2 h.invalidate_caches( rop.CALL_N, arraycopydescr1, [None, box3, box5, index1, index1, index2] ) assert h.getarrayitem(box4, index1, descr1) is None
def test_register_virtual_fields(): b1, b2 = IntFrontendOp(0), IntFrontendOp(1) vbox = RefFrontendOp(2) modifier = ResumeDataVirtualAdder(FakeOptimizer(), None, None, None, None) modifier.liveboxes_from_env = {} modifier.liveboxes = {} modifier.vfieldboxes = {} modifier.register_virtual_fields(vbox, [b1, b2]) assert modifier.liveboxes == { vbox: UNASSIGNEDVIRTUAL, b1: UNASSIGNED, b2: UNASSIGNED } assert modifier.vfieldboxes == {vbox: [b1, b2]} modifier = ResumeDataVirtualAdder(FakeOptimizer(), None, None, None, None) modifier.liveboxes_from_env = {vbox: tag(0, TAGVIRTUAL)} modifier.liveboxes = {} modifier.vfieldboxes = {} modifier.register_virtual_fields(vbox, [b1, b2, vbox]) assert modifier.liveboxes == { b1: UNASSIGNED, b2: UNASSIGNED, vbox: tag(0, TAGVIRTUAL) } assert modifier.vfieldboxes == {vbox: [b1, b2, vbox]}
def test_unescaped_array(self): h = HeapCache() box1 = RefFrontendOp(1) box2 = RefFrontendOp(2) lengthbox1 = IntFrontendOp(11) lengthbox2 = IntFrontendOp(12) 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_N, FakeCallDescr(FakeEffectinfo.EF_RANDOM_EFFECTS), [box1] ) assert not h.is_unescaped(box1) assert not h.is_unescaped(box2)
def test_virtualizable_virtualref(self): i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0) t = Trace([i0, i1, i2], metainterp_sd) p0 = FakeOp(t.record_op(rop.NEW_WITH_VTABLE, [], descr=SomeDescr())) t.record_op(rop.GUARD_TRUE, [i0]) resume.capture_resumedata([], [i1, i2, p0], [p0, i1], t) (i0, i1, i2), l, iter = self.unpack(t) assert not l[1].framestack assert l[1].virtualizables == [l[0], i1, i2] assert l[1].vref_boxes == [l[0], i1]
def test_virtual_adder_make_varray(): b2s, b4s = [RefFrontendOp(0), IntFrontendOp(0)] b4s.setint(4) c1s = ConstInt(111) storage = Storage() memo = ResumeDataLoopMemo(FakeMetaInterpStaticData()) modifier = ResumeDataVirtualAdder(FakeOptimizer(), storage, storage, None, memo) modifier.liveboxes_from_env = {} modifier.liveboxes = {} modifier.vfieldboxes = {} v2 = info.ArrayPtrInfo(LLtypeMixin.arraydescr, size=2, is_virtual=True) b2s.set_forwarded(v2) v2._items = [b4s, c1s] modifier.register_virtual_fields(b2s, [b4s, c1s]) liveboxes = [] modifier._number_virtuals(liveboxes, 0) dump_storage(storage, liveboxes) storage.rd_consts = memo.consts[:] storage.rd_numb = Numbering([0]) # resume b1t, b3t, b4t = [IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0)] b1t.setint(11) b3t.setint(33) b4t.setint(44) newboxes = _resume_remap( liveboxes, [ #b2s -- virtual b4s ], b4t) # resume metainterp = MyMetaInterp() reader = ResumeDataFakeReader(storage, newboxes, metainterp) assert len(reader.virtuals_cache.virtuals_ptr_cache) == 1 b2t = reader.decode_ref(tag(0, TAGVIRTUAL)) trace = metainterp.trace expected = [ (rop.NEW_ARRAY, [ConstInt(2)], b2t.getref_base(), LLtypeMixin.arraydescr), (rop.SETARRAYITEM_GC, [b2t, ConstInt(0), b4t], None, LLtypeMixin.arraydescr), (rop.SETARRAYITEM_GC, [b2t, ConstInt(1), c1s], None, LLtypeMixin.arraydescr), ] with CompareableConsts(): for x, y in zip(expected, trace): assert x == y # ptr = b2t.getref_base()._obj.container._as_ptr() assert lltype.typeOf(ptr) == lltype.Ptr(lltype.GcArray(lltype.Signed)) assert len(ptr) == 2 assert ptr[0] == 44 assert ptr[1] == 111
def test_length_cache(self): h = HeapCache() box1 = RefFrontendOp(1) box2 = RefFrontendOp(2) lengthbox1 = IntFrontendOp(11) lengthbox2 = IntFrontendOp(12) h.new_array(box1, lengthbox1) assert h.arraylen(box1) is lengthbox1 assert h.arraylen(box2) is None h.arraylen_now_known(box2, lengthbox2) assert h.arraylen(box2) is lengthbox2
def test_simple_iterator(self): i0, i1 = IntFrontendOp(0), IntFrontendOp(0) t = Trace([i0, i1], metainterp_sd) add = FakeOp(t.record_op(rop.INT_ADD, [i0, i1])) t.record_op(rop.INT_ADD, [add, ConstInt(1)]) (i0, i1), l, _ = self.unpack(t) assert len(l) == 2 assert l[0].opnum == rop.INT_ADD assert l[1].opnum == rop.INT_ADD assert l[1].getarg(1).getint() == 1 assert l[1].getarg(0) is l[0] assert l[0].getarg(0) is i0 assert l[0].getarg(1) is i1
def test_cut_trace_from(self): i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0) t = Trace([i0, i1, i2], metainterp_sd) add1 = FakeOp(t.record_op(rop.INT_ADD, [i0, i1])) cut_point = t.cut_point() add2 = FakeOp(t.record_op(rop.INT_ADD, [add1, i1])) t.record_op(rop.GUARD_TRUE, [add2]) resume.capture_resumedata([FakeFrame(3, JitCode(4), [add2, add1, i1])], None, [], t) t.record_op(rop.INT_SUB, [add2, add1]) t2 = t.cut_trace_from(cut_point, [add1, i1]) (i0, i1), l, iter = self.unpack(t2) assert len(l) == 3 assert l[0].getarglist() == [i0, i1]
def test_remove_consts_and_duplicates(): class FakeStaticData: cpu = None all_descrs = [] warmrunnerdesc = None def is_another_box_like(box, referencebox): assert box is not referencebox assert box.type == referencebox.type assert box.getint() == referencebox.getint() return True metainterp = pyjitpl.MetaInterp(FakeStaticData(), None) metainterp.history = History() b1 = IntFrontendOp(1) b1.setint(1) b2 = IntFrontendOp(2) b2.setint(2) c3 = ConstInt(3) boxes = [b1, b2, b1, c3] dup = {} metainterp.history.set_inputargs([b1, b2], FakeStaticData()) metainterp.remove_consts_and_duplicates(boxes, 4, dup) assert boxes[0] is b1 assert boxes[1] is b2 assert is_another_box_like(boxes[2], b1) assert is_another_box_like(boxes[3], c3) inp, operations = metainterp.history.trace.unpack() remap = dict(zip([b1, b2], inp)) assert equaloplists(operations, [ ResOperation(rop.SAME_AS_I, [b1]), ResOperation(rop.SAME_AS_I, [c3]), ], remap=remap) assert dup == {b1: None, b2: None}
def test_deadranges(self): i0, i1, i2 = IntFrontendOp(0), IntFrontendOp(0), IntFrontendOp(0) t = Trace([i0, i1, i2], metainterp_sd) p0 = FakeOp(t.record_op(rop.NEW_WITH_VTABLE, [], descr=SomeDescr())) t.record_op(rop.GUARD_TRUE, [i0]) resume.capture_resumedata([], [i1, i2, p0], [p0, i1], t) i3 = FakeOp(t.record_op(rop.INT_ADD, [i1, ConstInt(1)])) i4 = FakeOp(t.record_op(rop.INT_ADD, [i3, ConstInt(1)])) t.record_op(rop.ESCAPE_N, [ConstInt(3)]) t.record_op(rop.ESCAPE_N, [ConstInt(3)]) t.record_op(rop.ESCAPE_N, [ConstInt(3)]) t.record_op(rop.ESCAPE_N, [ConstInt(3)]) t.record_op(rop.ESCAPE_N, [ConstInt(3)]) t.record_op(rop.FINISH, [i4]) assert t.get_dead_ranges() == [0, 0, 0, 0, 0, 3, 4, 5]
def test_ll_arraycopy_doesnt_escape_arrays(self): h = HeapCache() box1 = RefFrontendOp(1) box2 = RefFrontendOp(2) lengthbox1 = IntFrontendOp(11) lengthbox2 = IntFrontendOp(12) h.new_array(box1, lengthbox1) h.new_array(box2, lengthbox2) h.invalidate_caches(rop.CALL_N, arraycopydescr1, [None, box2, box1, index1, index1, index2]) assert h.is_unescaped(box1) assert h.is_unescaped(box2) h.invalidate_caches(rop.CALL_N, arraycopydescr1, [None, box2, box1, index1, index1, InputArgInt()]) assert not h.is_unescaped(box1) assert not h.is_unescaped(box2)
def execute_and_record(self, opnum, descr, *argboxes): resvalue = executor.execute(self.cpu, None, opnum, descr, *argboxes) if isinstance(resvalue, int): op = IntFrontendOp(0) else: op = RefFrontendOp(0) setvalue(op, resvalue) self.trace.append((opnum, list(argboxes), resvalue, descr)) return op
def test_ResumeDataLoopMemo_number_virtuals(): memo = ResumeDataLoopMemo(FakeMetaInterpStaticData()) b1, b2 = [IntFrontendOp(0), IntFrontendOp(0)] assert memo.num_cached_virtuals() == 0 num = memo.assign_number_to_virtual(b1) assert num == -1 assert memo.num_cached_virtuals() == 1 num = memo.assign_number_to_virtual(b1) assert num == -1 num = memo.assign_number_to_virtual(b2) assert num == -2 assert memo.num_cached_virtuals() == 2 num = memo.assign_number_to_virtual(b2) assert num == -2 num = memo.assign_number_to_virtual(b1) assert num == -1 memo.clear_box_virtual_numbers() assert memo.num_cached_virtuals() == 0
def test_call_doesnt_invalidate_unescaped_array_boxes(self): h = HeapCache() box1 = RefFrontendOp(1) box3 = RefFrontendOp(3) lengthbox1 = IntFrontendOp(11) h.new_array(box1, lengthbox1) assert h.is_unescaped(box1) h.setarrayitem(box1, index1, box3, descr1) h.invalidate_caches(rop.CALL_N, FakeCallDescr(FakeEffectinfo.EF_CAN_RAISE), []) assert h.getarrayitem(box1, index1, descr1) is box3
def test_ll_arraycopy_dest_new(self): h = HeapCache() box1 = RefFrontendOp(1) box2 = RefFrontendOp(2) box3 = RefFrontendOp(3) box4 = RefFrontendOp(4) lengthbox1 = IntFrontendOp(11) h.new_array(box1, lengthbox1) h.setarrayitem(box3, index1, box4, descr1) h.invalidate_caches(rop.CALL_N, arraycopydescr1, [None, box2, box1, index1, index1, index2])
def test_ll_arraycopy_differing_descrs(self): h = HeapCache() box1 = RefFrontendOp(1) box2 = RefFrontendOp(2) box3 = RefFrontendOp(3) lengthbox2 = IntFrontendOp(12) 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, [None, box3, box2, index1, index1, index2]) assert h.getarrayitem(box1, index1, descr2) is box2
def test_rd_snapshot(self): i0, i1 = IntFrontendOp(0), IntFrontendOp(0) t = Trace([i0, i1], metainterp_sd) add = FakeOp(t.record_op(rop.INT_ADD, [i0, i1])) t.record_op(rop.GUARD_FALSE, [add]) # now we write rd_snapshot and friends frame0 = FakeFrame(1, JitCode(2), [i0, i1]) frame1 = FakeFrame(3, JitCode(4), [i0, i0, add]) framestack = [frame0] resume.capture_resumedata(framestack, None, [], t) (i0, i1), l, iter = self.unpack(t) assert l[1].opnum == rop.GUARD_FALSE assert l[1].framestack[0].boxes == [i0, i1] t.record_op(rop.GUARD_FALSE, [add]) resume.capture_resumedata([frame0, frame1], None, [], t) t.record_op(rop.INT_ADD, [add, add]) (i0, i1), l, iter = self.unpack(t) assert l[1].opnum == rop.GUARD_FALSE assert l[1].framestack[0].boxes == [i0, i1] assert l[2].opnum == rop.GUARD_FALSE fstack = l[2].framestack assert fstack[0].boxes == [i0, i1] assert fstack[1].boxes == [i0, i0, l[0]]
def test_replace_box_with_const_in_array(self): h = HeapCache() box1 = RefFrontendOp(1) lengthbox2 = IntFrontendOp(2) lengthbox2.setint(10) h.arraylen_now_known(box1, lengthbox2) assert h.arraylen(box1) is lengthbox2 c10 = ConstInt(10) h.replace_box(lengthbox2, c10) assert c10.same_constant(h.arraylen(box1)) box2 = IntFrontendOp(2) box2.setint(12) h.setarrayitem(box1, index2, box2, descr1) assert h.getarrayitem(box1, index2, descr1) is box2 c12 = ConstInt(12) h.replace_box(box2, c12) assert c12.same_constant(h.getarrayitem(box1, index2, descr1))
def convert_values(self, inpargs, values): if values: r = [] for arg, v in zip(inpargs, values): if arg.type == 'i': n = IntFrontendOp(0) if v is not None: n.setint(v) else: n = RefFrontendOp(0) if v is not None: n.setref_base(v) assert arg.type == 'r' r.append(n) return r return inpargs
def convert_values(self, inpargs, values): from rpython.jit.metainterp.history import IntFrontendOp, RefFrontendOp if values: r = [] for arg, v in zip(inpargs, values): if arg.type == 'i': n = IntFrontendOp(0) if v is not None: n.setint(v) else: n = RefFrontendOp(0) if v is not None: n.setref_base(v) assert arg.type == 'r' r.append(n) return r return inpargs
def test_virtual_adder_pending_fields_and_arrayitems(): class Storage(object): pass storage = Storage() modifier = ResumeDataVirtualAdder(None, storage, storage, None, None) modifier._add_pending_fields([]) assert not storage.rd_pendingfields # class FieldDescr(AbstractDescr): def is_array_of_primitives(self): return False field_a = FieldDescr() storage = Storage() modifier = ResumeDataVirtualAdder(None, storage, storage, None, None) a = IntFrontendOp(0) b = IntFrontendOp(0) modifier.liveboxes_from_env = {a: rffi.cast(rffi.SHORT, 1042), b: rffi.cast(rffi.SHORT, 1061)} modifier._add_pending_fields( [ResOperation(rop.SETFIELD_GC, [a, b], descr=field_a)]) pf = storage.rd_pendingfields assert len(pf) == 1 assert (annlowlevel.cast_base_ptr_to_instance(FieldDescr, pf[0].lldescr) is field_a) assert rffi.cast(lltype.Signed, pf[0].num) == 1042 assert rffi.cast(lltype.Signed, pf[0].fieldnum) == 1061 assert rffi.cast(lltype.Signed, pf[0].itemindex) == -1 # array_a = FieldDescr() storage = Storage() modifier = ResumeDataVirtualAdder(None, storage, storage, None, None) a42 = IntFrontendOp(0) a61 = IntFrontendOp(0) a62 = IntFrontendOp(0) a63 = IntFrontendOp(0) modifier.liveboxes_from_env = {a42: rffi.cast(rffi.SHORT, 1042), a61: rffi.cast(rffi.SHORT, 1061), a62: rffi.cast(rffi.SHORT, 1062), a63: rffi.cast(rffi.SHORT, 1063)} modifier._add_pending_fields([ ResOperation(rop.SETARRAYITEM_GC, [a42, ConstInt(0), a61], descr=array_a), ResOperation(rop.SETARRAYITEM_GC, [a42, ConstInt(2147483647), a62], descr=array_a)]) pf = storage.rd_pendingfields assert len(pf) == 2 assert (annlowlevel.cast_base_ptr_to_instance(FieldDescr, pf[0].lldescr) is array_a) assert rffi.cast(lltype.Signed, pf[0].num) == 1042 assert rffi.cast(lltype.Signed, pf[0].fieldnum) == 1061 assert rffi.cast(lltype.Signed, pf[0].itemindex) == 0 assert (annlowlevel.cast_base_ptr_to_instance(FieldDescr, pf[1].lldescr) is array_a) assert rffi.cast(lltype.Signed, pf[1].num) == 1042 assert rffi.cast(lltype.Signed, pf[1].fieldnum) == 1062 assert rffi.cast(lltype.Signed, pf[1].itemindex) == 2147483647 # if sys.maxint >= 2147483648: with py.test.raises(TagOverflow): modifier._add_pending_fields( [ResOperation(rop.SETARRAYITEM_GC, [a42, ConstInt(2147483648), a63], descr=array_a)])
def test_ResumeDataLoopMemo_number(): b1, b2, b3, b4, b5 = [IntFrontendOp(0), IntFrontendOp(1), IntFrontendOp(2), RefFrontendOp(3), RefFrontendOp(4)] c1, c2, c3, c4 = [ConstInt(1), ConstInt(2), ConstInt(3), ConstInt(4)] env = [b1, c1, b2, b1, c2] metainterp_sd = FakeMetaInterpStaticData() t = Trace([b1, b2, b3, b4, b5], metainterp_sd) snap = t.create_snapshot(FakeJitCode("jitcode", 0), 0, Frame(env), False) env1 = [c3, b3, b1, c1] t.append(0) # descr index snap1 = t.create_top_snapshot(FakeJitCode("jitcode", 0), 2, Frame(env1), False, [], []) snap1.prev = snap env2 = [c3, b3, b1, c3] env3 = [c3, b3, b1, c3] env4 = [c3, b4, b1, c3] env5 = [b1, b4, b5] memo = ResumeDataLoopMemo(metainterp_sd) iter = t.get_iter() b1, b2, b3, b4, b5 = iter.inputargs numb_state = memo.number(0, iter) numb = numb_state.create_numbering() assert numb_state.num_virtuals == 0 assert numb_state.liveboxes == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX), b3: tag(2, TAGBOX)} base = [0, 0, tag(0, TAGBOX), tag(1, TAGINT), tag(1, TAGBOX), tag(0, TAGBOX), tag(2, TAGINT)] assert unpack_numbering(numb) == [17, 0, 0, 0] + base + [0, 2, tag(3, TAGINT), tag(2, TAGBOX), tag(0, TAGBOX), tag(1, TAGINT)] t.append(0) snap2 = t.create_top_snapshot(FakeJitCode("jitcode", 0), 2, Frame(env2), False, [], []) snap2.prev = snap numb_state2 = memo.number(1, iter) numb2 = numb_state2.create_numbering() assert numb_state2.num_virtuals == 0 assert numb_state2.liveboxes == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX), b3: tag(2, TAGBOX)} assert numb_state2.liveboxes is not numb_state.liveboxes assert unpack_numbering(numb2) == [17, 0, 0, 0] + base + [0, 2, tag(3, TAGINT), tag(2, TAGBOX), tag(0, TAGBOX), tag(3, TAGINT)] t.append(0) snap3 = t.create_top_snapshot(FakeJitCode("jitcode", 0), 2, Frame([]), False, [], env3) snap3.prev = snap class FakeVirtualInfo(info.AbstractVirtualPtrInfo): def __init__(self, virt): self._is_virtual = virt def is_virtual(self): return self._is_virtual # renamed b3.set_forwarded(c4) numb_state3 = memo.number(2, iter) numb3 = numb_state3.create_numbering() assert numb_state3.num_virtuals == 0 assert numb_state3.liveboxes == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX)} assert unpack_numbering(numb3) == ([17, 0, 0, 2, tag(3, TAGINT), tag(4, TAGINT), tag(0, TAGBOX), tag(3, TAGINT)] + base + [0, 2]) # virtual t.append(0) snap4 = t.create_top_snapshot(FakeJitCode("jitcode", 0), 2, Frame([]), False, [], env4) snap4.prev = snap b4.set_forwarded(FakeVirtualInfo(True)) numb_state4 = memo.number(3, iter) numb4 = numb_state4.create_numbering() assert numb_state4.num_virtuals == 1 assert numb_state4.liveboxes == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX), b4: tag(0, TAGVIRTUAL)} assert unpack_numbering(numb4) == [17, 0, 0, 2, tag(3, TAGINT), tag(0, TAGVIRTUAL), tag(0, TAGBOX), tag(3, TAGINT)] + base + [0, 2] t.append(0) snap4 = t.create_snapshot(FakeJitCode("jitcode", 2), 1, Frame(env4), False) t.append(0) snap4.prev = snap snap5 = t.create_top_snapshot(FakeJitCode("jitcode", 0), 0, Frame([]), False, env5, []) snap5.prev = snap4 b4.set_forwarded(FakeVirtualInfo(True)) b5.set_forwarded(FakeVirtualInfo(True)) numb_state5 = memo.number(4, iter) numb5 = numb_state5.create_numbering() assert numb_state5.num_virtuals == 2 assert numb_state5.liveboxes == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX), b4: tag(0, TAGVIRTUAL), b5: tag(1, TAGVIRTUAL)} assert unpack_numbering(numb5) == [22, 0, 3, tag(0, TAGBOX), tag(0, TAGVIRTUAL), tag(1, TAGVIRTUAL), 0] + base + [ 2, 1, tag(3, TAGINT), tag(0, TAGVIRTUAL), tag(0, TAGBOX), tag(3, TAGINT) ] + [0, 0]
def test_virtual_adder_make_virtual(): b2s, b3s, b4s, b5s = [RefFrontendOp(0), IntFrontendOp(0), RefFrontendOp(0), RefFrontendOp(0)] c1s = ConstInt(111) storage = Storage() memo = ResumeDataLoopMemo(FakeMetaInterpStaticData()) modifier = ResumeDataVirtualAdder(FakeOptimizer(), storage, storage, None, memo) modifier.liveboxes_from_env = {} modifier.liveboxes = {} modifier.vfieldboxes = {} vdescr = LLtypeMixin.nodesize2 ca = ConstInt(ptr2int(LLtypeMixin.node_vtable2)) v4 = info.InstancePtrInfo(vdescr, ca, True) b4s.set_forwarded(v4) v4.setfield(LLtypeMixin.nextdescr, ca, b2s) v4.setfield(LLtypeMixin.valuedescr, ca, b3s) v4.setfield(LLtypeMixin.otherdescr, ca, b5s) ca = ConstInt(ptr2int(LLtypeMixin.node_vtable)) v2 = info.InstancePtrInfo(LLtypeMixin.nodesize, ca, True) v2.setfield(LLtypeMixin.nextdescr, b4s, ca) v2.setfield(LLtypeMixin.valuedescr, c1s, ca) b2s.set_forwarded(v2) modifier.register_virtual_fields(b2s, [c1s, None, None, None, b4s]) modifier.register_virtual_fields(b4s, [b3s, None, None, None, b2s, b5s]) liveboxes = [] modifier._number_virtuals(liveboxes, 0) storage.rd_consts = memo.consts[:] storage.rd_numb = Numbering([0]) # resume b3t, b5t = [IntFrontendOp(0), RefFrontendOp(0)] b5t.setref_base(demo55o) b3t.setint(33) newboxes = _resume_remap(liveboxes, [#b2s -- virtual b3s, #b4s -- virtual #b2s -- again, shared #b3s -- again, shared b5s], b3t, b5t) metainterp = MyMetaInterp() reader = ResumeDataFakeReader(storage, newboxes, metainterp) assert len(reader.virtuals_cache.virtuals_ptr_cache) == 2 b2t = reader.decode_ref(modifier._gettagged(b2s)) b4t = reader.decode_ref(modifier._gettagged(b4s)) trace = metainterp.trace b2new = (rop.NEW_WITH_VTABLE, [], b2t.getref_base(), LLtypeMixin.nodesize) b4new = (rop.NEW_WITH_VTABLE, [], b4t.getref_base(), LLtypeMixin.nodesize2) b2set = [(rop.SETFIELD_GC, [b2t, b4t], None, LLtypeMixin.nextdescr), (rop.SETFIELD_GC, [b2t, c1s], None, LLtypeMixin.valuedescr)] b4set = [(rop.SETFIELD_GC, [b4t, b2t], None, LLtypeMixin.nextdescr), (rop.SETFIELD_GC, [b4t, b3t], None, LLtypeMixin.valuedescr), (rop.SETFIELD_GC, [b4t, b5t], None, LLtypeMixin.otherdescr)] expected = [b2new, b4new] + b4set + b2set # check that we get the operations in 'expected', in a possibly different # order. assert len(trace) == len(expected) orig = trace[:] with CompareableConsts(): for x in trace: assert x in expected expected.remove(x) ptr = b2t.getref_base()._obj.container._as_ptr() assert lltype.typeOf(ptr) == lltype.Ptr(LLtypeMixin.NODE) assert ptr.value == 111 ptr2 = ptr.next ptr2 = lltype.cast_pointer(lltype.Ptr(LLtypeMixin.NODE2), ptr2) assert ptr2.other == demo55 assert ptr2.parent.value == 33 assert ptr2.parent.next == ptr
def InputArgInt(a): i = IntFrontendOp(0) i.setint(a) return i