예제 #1
0
def test_prepare_virtuals():
    class FakeVinfo(object):
        kind = REF

        def allocate(self, decoder, index):
            s = "allocated"
            decoder.virtuals_cache.set_ptr(index, s)
            return s

    class FakeStorage(object):
        rd_virtuals = [FakeVinfo(), None]
        rd_numb = Numbering([1])
        rd_consts = []
        rd_pendingfields = None

    class FakeMetainterp(object):
        _already_allocated_resume_virtuals = None
        cpu = None

    reader = ResumeDataDirectReader(MyMetaInterp(None), FakeStorage(),
                                    "deadframe")
    cache = reader.force_all_virtuals()
    assert cache.virtuals_ptr_cache == [
        "allocated", reader.virtual_ptr_default
    ]
예제 #2
0
def test_virtual_adder_int_constants():
    b1s, b2s, b3s = [ConstInt(sys.maxint), ConstInt(2**16), ConstInt(-65)]
    storage, t = make_storage(b1s, b2s, b3s)
    metainterp_sd = FakeMetaInterpStaticData()
    memo = ResumeDataLoopMemo(metainterp_sd)
    i = t.get_iter()
    modifier = ResumeDataVirtualAdder(FakeOptimizer(i), storage, storage, i, memo)
    liveboxes = modifier.finish()
    cpu = MyCPU([])
    reader = ResumeDataDirectReader(MyMetaInterp(cpu), storage, "deadframe")
    reader.consume_vref_and_vable(None, None, None)
    reader.resumecodereader.jump(2) # framestack
    _next_section(reader, sys.maxint, 1, sys.maxint, 2**16)
    reader.resumecodereader.jump(2) # framestack
    _next_section(reader, 2, 3)
    reader.resumecodereader.jump(2) # framestack
    _next_section(reader, sys.maxint, 2**16, -65)
예제 #3
0
def test_simple_read_tagged_ints():
    storage = Storage()
    storage.rd_consts = []
    numb = Numbering([1, tag(100, TAGINT)])
    storage.rd_numb = numb
    #
    cpu = MyCPU([])
    reader = ResumeDataDirectReader(MyMetaInterp(cpu), storage, "deadframe")
    _next_section(reader, 100)
예제 #4
0
파일: compile.py 프로젝트: sota/pypy-old
 def handle_fail(self, deadframe, metainterp_sd, jitdriver_sd):
     # Failures of a GUARD_NOT_FORCED are never compiled, but
     # always just blackholed.  First fish for the data saved when
     # the virtualrefs and virtualizable have been forced by
     # handle_async_forcing() just a moment ago.
     from rpython.jit.metainterp.blackhole import resume_in_blackhole
     hidden_all_virtuals = metainterp_sd.cpu.get_savedata_ref(deadframe)
     obj = AllVirtuals.show(metainterp_sd.cpu, hidden_all_virtuals)
     all_virtuals = obj.cache
     if all_virtuals is None:
         all_virtuals = ResumeDataDirectReader.VirtualCache([], [])
     assert jitdriver_sd is self.jitdriver_sd
     resume_in_blackhole(metainterp_sd, jitdriver_sd, self, deadframe,
                         all_virtuals)
     assert 0, "unreachable"
예제 #5
0
def test_simple_read():
    #b1, b2, b3 = [BoxInt(), InputArgRef(), BoxInt()]
    c1, c2, c3 = [ConstInt(111), ConstInt(222), ConstInt(333)]
    storage = Storage()
    storage.rd_consts = [c1, c2, c3]
    numb = Numbering([3, tag(0, TAGBOX), tagconst(0),
                       NULLREF, tag(0, TAGBOX), tag(1, TAGBOX)] +
                       [tagconst(1), tagconst(2)] +
                       [tag(0, TAGBOX), tag(1, TAGBOX), tag(2, TAGBOX)])
    storage.rd_numb = numb
    #
    cpu = MyCPU([42, gcref1, -66])
    metainterp = MyMetaInterp(cpu)
    reader = ResumeDataDirectReader(metainterp, storage, "deadframe")
    _next_section(reader, 42, 111, gcrefnull, 42, gcref1)
    _next_section(reader, 222, 333)
    _next_section(reader, 42, gcref1, -66)
    #
    reader = ResumeDataBoxReader(storage, "deadframe", metainterp)
    bi, br, bf = [None]*3, [None]*2, [None]*0
    info = MyBlackholeInterp([lltype.Signed, lltype.Signed,
                              llmemory.GCREF, lltype.Signed,
                              llmemory.GCREF]).get_current_position_info()
    reader.consume_boxes(info, bi, br, bf)
    b1s = reader.liveboxes[0]
    b2s = reader.liveboxes[1]
    assert_same(bi, [b1s, ConstInt(111), b1s])
    assert_same(br, [ConstPtr(gcrefnull), b2s])
    bi, br, bf = [None]*2, [None]*0, [None]*0
    info = MyBlackholeInterp([lltype.Signed,
                              lltype.Signed]).get_current_position_info()
    reader.consume_boxes(info, bi, br, bf)
    assert_same(bi, [ConstInt(222), ConstInt(333)])
    bi, br, bf = [None]*2, [None]*1, [None]*0
    info = MyBlackholeInterp([lltype.Signed, llmemory.GCREF,
                              lltype.Signed]).get_current_position_info()
    reader.consume_boxes(info, bi, br, bf)
    b3s = reader.liveboxes[2]
    assert_same(bi, [b1s, b3s])
    assert_same(br, [b2s])
예제 #6
0
 def test_make_vref_guard(self):
     if not isinstance(self, TestLLtype):
         py.test.skip("purely frontend test")
     #
     class FooBarError(Exception):
         pass
     class X:
         def __init__(self, n):
             self.n = n
     class ExCtx:
         _frame = None
     exctx = ExCtx()
     #
     @dont_look_inside
     def external(n):
         if exctx._frame is None:
             raise FooBarError
         if n > 100:
             return exctx.topframeref().n
         return n
     def enter(n):
         x = X(n + 10)
         exctx._frame = x
         exctx.topframeref = virtual_ref(x)
     def leave():
         vref = exctx.topframeref
         exctx.topframeref = vref_None
         virtual_ref_finish(vref, exctx._frame)
     def f(n):
         enter(n)
         n = external(n)
         # ^^^ the point is that X() and the vref should be kept alive here
         leave()
         return n
     #
     res = self.interp_operations(f, [5])
     assert res == 5
     self.check_operations_history(virtual_ref=1, guard_not_forced=1)
     #
     ops = self.metainterp.staticdata.stats.loops[0].operations
     [guard_op] = [op for op in ops
                      if op.getopnum() == rop.GUARD_NOT_FORCED]
     bxs1 = [box for box in guard_op.getfailargs()
               if str(box._getrepr_()).endswith('.X')]
     assert len(bxs1) == 1
     bxs2 = [box for box in guard_op.getfailargs()
               if str(box._getrepr_()).endswith('JitVirtualRef')]
     assert len(bxs2) == 1
     JIT_VIRTUAL_REF = self.vrefinfo.JIT_VIRTUAL_REF
     FOO = lltype.GcStruct('FOO')
     foo = lltype.malloc(FOO)
     tok = lltype.cast_opaque_ptr(llmemory.GCREF, foo)
     bxs2[0].getref(lltype.Ptr(JIT_VIRTUAL_REF)).virtual_token = tok
     #
     # try reloading from blackhole.py's point of view
     from rpython.jit.metainterp.resume import ResumeDataDirectReader
     cpu = self.metainterp.cpu
     cpu.get_int_value = lambda df,i:guard_op.getfailargs()[i].getint()
     cpu.get_ref_value = lambda df,i:guard_op.getfailargs()[i].getref_base()
     class FakeMetaInterpSd:
         callinfocollection = None
     FakeMetaInterpSd.cpu = cpu
     resumereader = ResumeDataDirectReader(FakeMetaInterpSd(),
                                           guard_op.getdescr(),
                                           "deadframe")
     vrefinfo = self.metainterp.staticdata.virtualref_info
     lst = []
     vrefinfo.continue_tracing = lambda vref, virtual: \
                                     lst.append((vref, virtual))
     resumereader.consume_vref_and_vable(vrefinfo, None, None)
     del vrefinfo.continue_tracing
     assert len(lst) == 1
     lltype.cast_opaque_ptr(lltype.Ptr(JIT_VIRTUAL_REF),
                            lst[0][0])  # assert correct type
     #
     # try reloading from pyjitpl's point of view
     self.metainterp.rebuild_state_after_failure(guard_op.getdescr(),
                                                 "deadframe")
     assert len(self.metainterp.framestack) == 1
     assert len(self.metainterp.virtualref_boxes) == 2
     assert self.metainterp.virtualref_boxes[0].value == bxs1[0].value
     assert self.metainterp.virtualref_boxes[1].value == bxs2[0].value
예제 #7
0
    def test_make_vref_guard(self):
        if not isinstance(self, TestLLtype):
            py.test.skip("purely frontend test")
        #
        class FooBarError(Exception):
            pass

        class X:
            def __init__(self, n):
                self.n = n

        class ExCtx:
            _frame = None

        exctx = ExCtx()
        #
        @dont_look_inside
        def external(n):
            if exctx._frame is None:
                raise FooBarError
            if n > 100:
                return exctx.topframeref().n
            return n

        def enter(n):
            x = X(n + 10)
            exctx._frame = x
            exctx.topframeref = virtual_ref(x)

        def leave():
            vref = exctx.topframeref
            exctx.topframeref = vref_None
            virtual_ref_finish(vref, exctx._frame)

        def f(n):
            enter(n)
            n = external(n)
            # ^^^ the point is that X() and the vref should be kept alive here
            leave()
            return n

        #
        res = self.interp_operations(f, [5])
        assert res == 5
        self.check_operations_history(virtual_ref=1, guard_not_forced=1)
        #
        ops = self.metainterp.staticdata.stats.loops[0].operations
        [guard_op
         ] = [op for op in ops if op.getopnum() == rop.GUARD_NOT_FORCED]
        bxs1 = [box for box in guard_op.getfailargs() if '.X' in str(box)]
        assert len(bxs1) == 1
        bxs2 = [(i, box) for i, box in enumerate(guard_op.getfailargs())
                if 'JitVirtualRef' in str(box)]
        assert len(bxs2) == 1
        JIT_VIRTUAL_REF = self.vrefinfo.JIT_VIRTUAL_REF
        FOO = lltype.GcStruct('FOO')
        foo = lltype.malloc(FOO)
        tok = lltype.cast_opaque_ptr(llmemory.GCREF, foo)
        cpu = self.metainterp.cpu
        py.test.skip("rewrite this test")
        bxs2[0].getref(lltype.Ptr(JIT_VIRTUAL_REF)).virtual_token = tok
        #
        # try reloading from blackhole.py's point of view
        from rpython.jit.metainterp.resume import ResumeDataDirectReader
        cpu.get_int_value = lambda df, i: guard_op.getfailargs()[i].getint()
        cpu.get_ref_value = lambda df, i: guard_op.getfailargs()[
            i].getref_base()

        class FakeMetaInterpSd:
            callinfocollection = None

        FakeMetaInterpSd.cpu = cpu
        resumereader = ResumeDataDirectReader(FakeMetaInterpSd(),
                                              guard_op.getdescr(), "deadframe")
        vrefinfo = self.metainterp.staticdata.virtualref_info
        lst = []
        vrefinfo.continue_tracing = lambda vref, virtual: \
                                        lst.append((vref, virtual))
        resumereader.consume_vref_and_vable(vrefinfo, None, None)
        del vrefinfo.continue_tracing
        assert len(lst) == 1
        lltype.cast_opaque_ptr(lltype.Ptr(JIT_VIRTUAL_REF),
                               lst[0][0])  # assert correct type
        #
        # try reloading from pyjitpl's point of view
        self.metainterp.rebuild_state_after_failure(guard_op.getdescr(),
                                                    "deadframe")
        assert len(self.metainterp.framestack) == 1
        assert len(self.metainterp.virtualref_boxes) == 2
        assert self.metainterp.virtualref_boxes[0].value == bxs1[0].value
        assert self.metainterp.virtualref_boxes[1].value == bxs2[0].value