Beispiel #1
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)
Beispiel #2
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
Beispiel #3
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