def test_ResumeDataLoopMemo_ints(): memo = ResumeDataLoopMemo(FakeMetaInterpStaticData()) tagged = memo.getconst(ConstInt(44)) assert untag(tagged) == (44, TAGINT) tagged = memo.getconst(ConstInt(-3)) assert untag(tagged) == (-3, TAGINT) const = ConstInt(5000000) tagged = memo.getconst(const) index, tagbits = untag(tagged) assert tagbits == TAGCONST assert memo.consts[index - TAG_CONST_OFFSET] is const tagged = memo.getconst(ConstInt(5000000)) index2, tagbits = untag(tagged) assert tagbits == TAGCONST assert index2 == index
def test_ResumeDataLoopMemo_random(lst): inpargs = [box for box in lst if not isinstance(box, Const)] metainterp_sd = FakeMetaInterpStaticData() t = Trace(inpargs, metainterp_sd) t.append(0) i = t.get_iter() t.create_top_snapshot(FakeJitCode("", 0), 0, Frame(lst), False, [], []) memo = ResumeDataLoopMemo(metainterp_sd) numb_state = memo.number(0, i) numb = numb_state.create_numbering() l = unpack_numbering(numb) assert l[0] == len(l) assert l[1] == 0 assert l[1] == 0 assert l[2] == 0 assert l[3] == 0 assert l[4] == 0 mapping = dict(zip(inpargs, i.inputargs)) for i, item in enumerate(lst): v, tag = untag(l[i + 6]) if tag == TAGBOX: assert l[i + 6] == numb_state.liveboxes[mapping[item]] elif tag == TAGCONST: assert memo.consts[v].getint() == item.getint() elif tag == TAGINT: assert v == item.getint()
def test_ResumeDataLoopMemo_other(): memo = ResumeDataLoopMemo(FakeMetaInterpStaticData()) const = ConstFloat(longlong.getfloatstorage(-1.0)) tagged = memo.getconst(const) index, tagbits = untag(tagged) assert tagbits == TAGCONST assert memo.consts[index - TAG_CONST_OFFSET] is const
def test_ResumeDataLoopMemo_refs(): memo = ResumeDataLoopMemo(FakeMetaInterpStaticData()) const = ConstPtr(demo55o) tagged = memo.getconst(const) index, tagbits = untag(tagged) assert tagbits == TAGCONST assert memo.consts[index - TAG_CONST_OFFSET] is const tagged = memo.getconst(ConstPtr(demo55o)) index2, tagbits = untag(tagged) assert tagbits == TAGCONST assert index2 == index tagged = memo.getconst(ConstPtr(demo66o)) index3, tagbits = untag(tagged) assert tagbits == TAGCONST assert index3 != index tagged = memo.getconst(CONST_NULL) assert tagged == NULLREF
def dump_storage(storage, liveboxes): "For profiling only." debug_start("jit-resume") return # XXX refactor if needed if have_debug_prints(): debug_print('Log storage', compute_unique_id(storage)) frameinfo = storage.rd_frame_info_list while frameinfo is not None: try: jitcodename = frameinfo.jitcode.name except AttributeError: jitcodename = str(compute_unique_id(frameinfo.jitcode)) debug_print('\tjitcode/pc', jitcodename, frameinfo.pc, 'at', compute_unique_id(frameinfo)) frameinfo = frameinfo.prev numb = storage.rd_numb while numb: debug_print( '\tnumb', str([untag(numb.nums[i]) for i in range(len(numb.nums))]), 'at', compute_unique_id(numb)) numb = numb.prev for const in storage.rd_consts: debug_print('\tconst', const.repr_rpython()) for box in liveboxes: if box is None: debug_print('\tbox', 'None') else: debug_print('\tbox', box.repr_rpython()) if storage.rd_virtuals is not None: for virtual in storage.rd_virtuals: if virtual is None: debug_print('\t\t', 'None') else: virtual.debug_prints() if storage.rd_pendingfields: debug_print('\tpending setfields') for i in range(len(storage.rd_pendingfields)): lldescr = storage.rd_pendingfields[i].lldescr num = storage.rd_pendingfields[i].num fieldnum = storage.rd_pendingfields[i].fieldnum itemindex = storage.rd_pendingfields[i].itemindex debug_print("\t\t", str(lldescr), str(untag(num)), str(untag(fieldnum)), itemindex) debug_stop("jit-resume")
def decode_box(resumestorage, tagged, liveboxes, cpu): from rpython.jit.metainterp.resume import untag, TAGCONST, TAGINT, TAGBOX from rpython.jit.metainterp.resume import NULLREF, TAG_CONST_OFFSET, tagged_eq num, tag = untag(tagged) # NB: the TAGVIRTUAL case can't happen here, because this code runs after # virtuals are already forced again if tag == TAGCONST: if tagged_eq(tagged, NULLREF): box = CONST_NULL else: box = resumestorage.rd_consts[num - TAG_CONST_OFFSET] elif tag == TAGINT: box = ConstInt(num) elif tag == TAGBOX: box = liveboxes[num] else: raise AssertionError("unreachable") return box
def enumerate_vars(callback_i, callback_r, callback_f, _): index = 0 while not self.done_reading(): tagged = self.resumecodereader.peek() _, tag = untag(tagged) if tag == TAGVIRTUAL: kind = REF else: kind = Whatever() box = self.decode_box(tagged, kind) if box.type == INT: callback_i(index) elif box.type == REF: callback_r(index) elif box.type == FLOAT: callback_f(index) else: assert 0 index += 1
def unicode_setitem(self, unistring, i, fieldnum): value, tag = untag(fieldnum) assert tag == TAGINT assert 0 <= i < len(unistring.unistring) unistring.unistring[i] = value
def string_setitem(self, string, i, fieldnum): value, tag = untag(fieldnum) assert tag == TAGINT assert 0 <= i < len(string.string) string.string[i] = value
def test_untag(): assert untag(tag(3, 1)) == (3, 1) assert untag(tag(-3, 2)) == (-3, 2) assert untag(tag((1<<13)-1, 3)) == ((1<<13)-1, 3) assert untag(tag(-1<<13, 3)) == (-1<<13, 3)