Exemple #1
0
 def f(n):
     while n > 0:
         myjitdriver.can_enter_jit(n=n)
         myjitdriver.jit_merge_point(n=n)
         xy = XY()
         xy.next1 = lltype.malloc(A, 0)
         xy.next2 = lltype.malloc(A, 0)
         xy.next3 = lltype.malloc(A, 0)
         xy.next4 = lltype.malloc(A, 0)
         xy.next5 = lltype.malloc(A, 0)
         xy.n = n
         exctx.topframeref = vref = virtual_ref(xy)
         if n % 6 == 0:
             xy.next1 = lltype.nullptr(A)
             xy.next2 = lltype.nullptr(A)
             xy.next3 = lltype.nullptr(A)
             externalfn(n)
         n -= 1
         exctx.topframeref = vref_None
         xy.next1 = lltype.nullptr(A)
         xy.next2 = lltype.nullptr(A)
         xy.next3 = lltype.nullptr(A)
         xy.next4 = lltype.nullptr(A)
         xy.next5 = lltype.nullptr(A)
         virtual_ref_finish(vref, xy)
     return exctx.m
Exemple #2
0
 def f(n):
     while n > 0:
         myjitdriver.can_enter_jit(n=n)
         myjitdriver.jit_merge_point(n=n)
         xy = XY()
         xy.next1 = lltype.malloc(A, 0)
         xy.next2 = lltype.malloc(A, 0)
         xy.next3 = lltype.malloc(A, 0)
         xy.next4 = lltype.malloc(A, 0)
         xy.next5 = lltype.malloc(A, 0)
         xy.n = n
         exctx.topframeref = vref = virtual_ref(xy)
         if n % 6 == 0:
             xy.next1 = lltype.nullptr(A)
             xy.next2 = lltype.nullptr(A)
             xy.next3 = lltype.nullptr(A)
             externalfn(n)
         n -= 1
         exctx.topframeref = vref_None
         xy.next1 = lltype.nullptr(A)
         xy.next2 = lltype.nullptr(A)
         xy.next3 = lltype.nullptr(A)
         xy.next4 = lltype.nullptr(A)
         xy.next5 = lltype.nullptr(A)
         virtual_ref_finish(vref, xy)
     return exctx.m
Exemple #3
0
def test_direct_invalid():
    x1 = X()
    vref = virtual_ref(x1)
    assert vref._state == 'non-forced'
    virtual_ref_finish(vref, x1)
    assert vref._state == 'invalid'
    py.test.raises(InvalidVirtualRef, "vref()")
Exemple #4
0
def test_direct_invalid():
    x1 = X()
    vref = virtual_ref(x1)
    assert vref._state == "non-forced"
    virtual_ref_finish(vref, x1)
    assert vref._state == "invalid"
    py.test.raises(InvalidVirtualRef, "vref()")
 def leave(self, frame, got_exception):
     frame_vref = self.topframeref
     self.topframeref = frame.backref
     if frame.escaped or got_exception:
         back = frame.backref()
         if back is not None:
             back.escaped = True
         frame_vref()
     jit.virtual_ref_finish(frame_vref, frame)
 def leave_virtual_frame(self, vref, ref):
     self.set_state(InactiveContext)
     if vref is not jit.vref_None:
         jit.virtual_ref_finish(vref, ref)
         if vref is self._s_sender:
             # If this frame was not manipulated, _s_sender is still our
             # initial vref. If the frame was manipulated (or has no sender)
             # _s_sender is already a non_virtual_ref.
             self._s_sender = jit.non_virtual_ref(ref)
Exemple #7
0
 def leave_virtual_frame(self, vref, ref):
     self.set_state(InactiveContext)
     if vref is not jit.vref_None:
         jit.virtual_ref_finish(vref, ref)
         if vref is self._s_sender:
             # If this frame was not manipulated, _s_sender is still our
             # initial vref. If the frame was manipulated (or has no sender)
             # _s_sender is already a non_virtual_ref.
             self._s_sender = jit.non_virtual_ref(ref)
Exemple #8
0
 def leave(self, frame, got_exception):
     frame_vref = self.topframeref
     self.topframeref = frame.backref
     if frame.escaped or got_exception:
         back = frame.backref()
         if back is not None:
             back.escaped = True
         frame_vref()
     jit.virtual_ref_finish(frame_vref, frame)
Exemple #9
0
 def f(n):
     res1 = -42
     while n > 0:
         myjitdriver.jit_merge_point(n=n, res1=res1)
         x = X()
         vref = virtual_ref(x)
         res1 = residual(vref)
         virtual_ref_finish(vref, x)
         n -= 1
     return res1
Exemple #10
0
 def leave(self, frame, got_exception, original_regexp_match_cell):
     frame_vref = self.topframeref
     self.topframeref = frame.backref
     if frame.escaped or got_exception:
         back = frame.backref()
         if back is not None:
             back.escaped = True
         frame_vref()
     jit.virtual_ref_finish(frame_vref, frame)
     self.regexp_match_cell = original_regexp_match_cell
Exemple #11
0
 def f(n):
     res1 = -42
     while n > 0:
         myjitdriver.jit_merge_point(n=n, res1=res1)
         x = X()
         vref = virtual_ref(x)
         res1 = residual(vref)
         virtual_ref_finish(vref, x)
         n -= 1
     return res1
Exemple #12
0
 def f(n):
     ec = ExecutionContext()
     while n > 0:
         myjitdriver.jit_merge_point(n=n, ec=ec)
         frame = Frame(1)
         ec.topframeref = virtual_ref(frame)
         n -= ec.topframeref().x
         frame_vref = ec.topframeref
         ec.topframeref = vref_None
         virtual_ref_finish(frame_vref, frame)
     return n
Exemple #13
0
 def f(n):
     ec = ExecutionContext()
     while n > 0:
         myjitdriver.jit_merge_point(n=n, ec=ec)
         frame = Frame(1)
         ec.topframeref = virtual_ref(frame)
         n -= ec.topframeref().x
         frame_vref = ec.topframeref
         ec.topframeref = vref_None
         virtual_ref_finish(frame_vref, frame)
     return n
Exemple #14
0
 def fn(n):
     res = False
     while n > 0:
         myjitdriver.can_enter_jit(n=n)
         myjitdriver.jit_merge_point(n=n)
         xy = XY()
         xy.n = n
         vref = virtual_ref(xy)
         virtual_ref_finish(vref, xy)
         vref() # raises InvalidVirtualRef when jitted
         n -= 1
     return res
Exemple #15
0
def test_direct_forced():
    x1 = X()
    vref = virtual_ref(x1)
    assert vref._state == 'non-forced'
    assert vref.virtual is True
    assert vref() is x1
    assert vref._state == 'forced'
    assert vref.virtual is False
    virtual_ref_finish(vref, x1)
    assert vref._state == 'forced'
    assert vref.virtual is False
    assert vref() is x1
Exemple #16
0
def test_direct_forced():
    x1 = X()
    vref = virtual_ref(x1)
    assert vref._state == "non-forced"
    assert vref.virtual is True
    assert vref() is x1
    assert vref._state == "forced"
    assert vref.virtual is False
    virtual_ref_finish(vref, x1)
    assert vref._state == "forced"
    assert vref.virtual is False
    assert vref() is x1
Exemple #17
0
 def fn(n):
     res = False
     while n > 0:
         myjitdriver.can_enter_jit(n=n)
         myjitdriver.jit_merge_point(n=n)
         xy = XY()
         xy.n = n
         vref = virtual_ref(xy)
         virtual_ref_finish(vref, xy)
         vref()  # raises InvalidVirtualRef when jitted
         n -= 1
     return res
Exemple #18
0
 def f(n):
     while n > 0:
         myjitdriver.can_enter_jit(n=n)
         myjitdriver.jit_merge_point(n=n)
         xy = XY()
         xy.n = n
         exctx.topframeref = vref = virtual_ref(xy)
         escapes.append(xy)
         xy.next1 = lltype.malloc(A, 0)
         n = exctx.topframeref().n - 1
         exctx.topframeref = vref_None
         virtual_ref_finish(vref, xy)
     return 1
Exemple #19
0
 def f(n):
     while n > 0:
         myjitdriver.can_enter_jit(n=n)
         myjitdriver.jit_merge_point(n=n)
         xy = XY()
         xy.n = n
         exctx.topframeref = vref = virtual_ref(xy)
         escapes.append(xy)
         xy.next1 = lltype.malloc(A, 0)
         n = exctx.topframeref().n - 1
         exctx.topframeref = vref_None
         virtual_ref_finish(vref, xy)
     return 1
Exemple #20
0
 def fn(n):
     res = 0
     while n > 0:
         myjitdriver.can_enter_jit(n=n, res=res)
         myjitdriver.jit_merge_point(n=n, res=res)
         xy = XY()
         xy.n = n
         vref = virtual_ref(xy)
         force_it(vref, n)
         virtual_ref_finish(vref, xy)
         res += force_it(vref, n) # doesn't raise, because it was already forced
         n -= 1
     return res
Exemple #21
0
 def f(frame, n, reclevel):
     while n > 0:
         myjitdriver.can_enter_jit(n=n, frame=frame, rec=reclevel)
         myjitdriver.jit_merge_point(n=n, frame=frame, rec=reclevel)
         if reclevel == 0:
             return n
         xy = XY()
         exctx.topframeref = vref = virtual_ref(xy)
         m = f(xy, n, reclevel - 1)
         assert m == n
         n -= 1
         exctx.topframeref = vref_None
         virtual_ref_finish(vref, xy)
     return 2
Exemple #22
0
 def f(frame, n, reclevel):
     while n > 0:
         myjitdriver.can_enter_jit(n=n, frame=frame, rec=reclevel)
         myjitdriver.jit_merge_point(n=n, frame=frame, rec=reclevel)
         if reclevel == 0:
             return n
         xy = XY()
         exctx.topframeref = vref = virtual_ref(xy)
         m = f(xy, n, reclevel-1)
         assert m == n
         n -= 1
         exctx.topframeref = vref_None
         virtual_ref_finish(vref, xy)
     return 2
Exemple #23
0
 def fn(n):
     res = 0
     while n > 0:
         myjitdriver.can_enter_jit(n=n, res=res)
         myjitdriver.jit_merge_point(n=n, res=res)
         xy = XY()
         xy.n = n
         vref = virtual_ref(xy)
         force_it(vref, n)
         virtual_ref_finish(vref, xy)
         res += force_it(
             vref, n)  # doesn't raise, because it was already forced
         n -= 1
     return res
Exemple #24
0
 def f(n):
     while n > 0:
         myjitdriver.jit_merge_point(n=n)
         xy = XY()
         xy.n = n
         vr = virtual_ref(xy)
         # force the virtualref to be allocated
         exctx.vr = vr
         # force xy to be allocated
         escapexy(xy)
         # clean up
         exctx.vr = vref_None
         virtual_ref_finish(vr, xy)
         n -= 1
     return 1
Exemple #25
0
 def f(n):
     while n > 0:
         jitdriver.can_enter_jit(n=n)
         jitdriver.jit_merge_point(n=n)
         x = X()
         x.n = n
         exctx.topframeref = vref = virtual_ref(x)
         # here, 'x' should be virtual
         exctx.topframeref = vref_None
         virtual_ref_finish(vref, x)
         # 'x' and 'vref' can randomly escape after the call to
         # finish().
         g(vref)
         n -= 1
     return 1
Exemple #26
0
 def f(n):
     while n > 0:
         jitdriver.can_enter_jit(n=n)
         jitdriver.jit_merge_point(n=n)
         x = X()
         x.n = n
         exctx.topframeref = vref = virtual_ref(x)
         # here, 'x' should be virtual
         exctx.topframeref = vref_None
         virtual_ref_finish(vref, x)
         # 'x' and 'vref' can randomly escape after the call to
         # finish().
         g(vref)
         n -= 1
     return 1
Exemple #27
0
 def f(n):
     while n > 0:
         myjitdriver.jit_merge_point(n=n)
         xy = XY()
         xy.n = n
         vr = virtual_ref(xy)
         # force the virtualref to be allocated
         exctx.vr = vr
         # force xy to be allocated
         escapexy(xy)
         # clean up
         exctx.vr = vref_None
         virtual_ref_finish(vr, xy)
         n -= 1
     return 1
Exemple #28
0
 def f(frame, n, reclevel):
     while n > 0:
         myjitdriver.can_enter_jit(n=n, frame=frame, rec=reclevel)
         myjitdriver.jit_merge_point(n=n, frame=frame, rec=reclevel)
         frame.n += 1
         xy = XY()
         xy.n = n
         exctx.topframeref = vref = virtual_ref(xy)
         if reclevel > 0:
             m = f(xy, frame.n, reclevel - 1)
             assert xy.n == m
             n -= 1
         else:
             n -= 2
         exctx.topframeref = vref_None
         virtual_ref_finish(vref, xy)
     return frame.n
Exemple #29
0
 def leave(self, frame, w_exitvalue, got_exception):
     try:
         if self.profilefunc:
             self._trace(frame, 'leaveframe', w_exitvalue)
     finally:
         frame_vref = self.topframeref
         self.topframeref = frame.f_backref
         if frame.escaped or got_exception:
             # if this frame escaped to applevel, we must ensure that also
             # f_back does
             f_back = frame.f_backref()
             if f_back:
                 f_back.mark_as_escaped()
             # force the frame (from the JIT point of view), so that it can
             # be accessed also later
             frame_vref()
         jit.virtual_ref_finish(frame_vref, frame)
Exemple #30
0
 def f(frame, n, reclevel):
     while n > 0:
         myjitdriver.can_enter_jit(n=n, frame=frame, rec=reclevel)
         myjitdriver.jit_merge_point(n=n, frame=frame, rec=reclevel)
         frame.n += 1
         xy = XY()
         xy.n = n
         exctx.topframeref = vref = virtual_ref(xy)
         if reclevel > 0:
             m = f(xy, frame.n, reclevel-1)
             assert xy.n == m
             n -= 1
         else:
             n -= 2
         exctx.topframeref = vref_None
         virtual_ref_finish(vref, xy)
     return frame.n
        def f():
            n = 0
            while n < 100:
                myjitdriver.jit_merge_point(n=n)
                xy = XY()
                xy.n = n
                exctx.topframeref = vref = jit.virtual_ref(xy)
                res = do_call(n)  # this is equivalent of a cffi call which
                # sometimes forces a frame

                # when n==50, fn() will force the frame, so guard_not_forced
                # fails and we enter blackholing: this test makes sure that
                # the result of call_release_gil is kept alive before the
                # raw_store, and that the corresponding box is passed
                # in the fail_args. Before the fix, the result of
                # call_release_gil was simply lost and when guard_not_forced
                # failed, and the value of "res" was unpredictable.
                # See commit b84ff38f34bd and subsequents.
                assert res == n * 2
                jit.virtual_ref_finish(vref, xy)
                exctx.topframeref = jit.vref_None
                n += 1
            return n
Exemple #32
0
        def f():
            n = 0
            while n < 100:
                myjitdriver.jit_merge_point(n=n)
                xy = XY()
                xy.n = n
                exctx.topframeref = vref = jit.virtual_ref(xy)
                res = do_call(n) # this is equivalent of a cffi call which
                                 # sometimes forces a frame

                # when n==50, fn() will force the frame, so guard_not_forced
                # fails and we enter blackholing: this test makes sure that
                # the result of call_release_gil is kept alive before the
                # raw_store, and that the corresponding box is passed
                # in the fail_args. Before the fix, the result of
                # call_release_gil was simply lost and when guard_not_forced
                # failed, and the value of "res" was unpredictable.
                # See commit b84ff38f34bd and subsequents.
                assert res == n*2
                jit.virtual_ref_finish(vref, xy)
                exctx.topframeref = jit.vref_None
                n += 1
            return n
Exemple #33
0
 def f(n):
     while n > 0:
         myjitdriver.can_enter_jit(n=n)
         myjitdriver.jit_merge_point(n=n)
         xy = XY()
         xy.next1 = lltype.malloc(A, 0)
         xy.next2 = lltype.malloc(A, 0)
         xy.next3 = lltype.malloc(A, 0)
         buf = lltype.malloc(rffi.CCHARP.TO, 1, flavor='raw')
         buf[0] = chr(n)
         # this is a raw virtual
         xy.next4 = lltype.malloc(rffi.CCHARP.TO, 1, flavor='raw')
         xy.n = n
         exctx.topframeref = vref = virtual_ref(xy)
         n -= externalfn(n)
         xy.next1 = lltype.nullptr(A)
         xy.next2 = lltype.nullptr(A)
         xy.next3 = lltype.nullptr(A)
         lltype.free(xy.next4, flavor='raw')
         xy.next4 = lltype.nullptr(rffi.CCHARP.TO)
         virtual_ref_finish(vref, xy)
         exctx.topframeref = vref_None
         lltype.free(buf, flavor='raw')
     return exctx.m
Exemple #34
0
 def f(n):
     while n > 0:
         myjitdriver.can_enter_jit(n=n)
         myjitdriver.jit_merge_point(n=n)
         xy = XY()
         xy.next1 = lltype.malloc(A, 0)
         xy.next2 = lltype.malloc(A, 0)
         xy.next3 = lltype.malloc(A, 0)
         buf = lltype.malloc(rffi.CCHARP.TO, 1, flavor='raw')
         buf[0] = chr(n)
         # this is a raw virtual
         xy.next4 = lltype.malloc(rffi.CCHARP.TO, 1, flavor='raw')
         xy.n = n
         exctx.topframeref = vref = virtual_ref(xy)
         n -= externalfn(n)
         xy.next1 = lltype.nullptr(A)
         xy.next2 = lltype.nullptr(A)
         xy.next3 = lltype.nullptr(A)
         lltype.free(xy.next4, flavor='raw')
         xy.next4 = lltype.nullptr(rffi.CCHARP.TO)
         virtual_ref_finish(vref, xy)
         exctx.topframeref = vref_None
         lltype.free(buf, flavor='raw')
     return exctx.m
Exemple #35
0
 def leave():
     vref = exctx.topframeref
     exctx.topframeref = vref_None
     virtual_ref_finish(vref, exctx._frame)
Exemple #36
0
 def f():
     x = X()
     exctx.topframeref = vref = virtual_ref(x)
     exctx.topframeref = vref_None
     virtual_ref_finish(vref, x)
     return 1
Exemple #37
0
 def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
     a = A()
     glob.v = vref = virtual_ref(a)
     virtual_ref_finish(vref, a)
     n -= 1
     return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
Exemple #38
0
 def leave(self, frame):
     frame_vref = self.topframeref
     self.topframeref = frame.f_backref
     frame.f_backref()
     virtual_ref_finish(frame_vref, frame)
Exemple #39
0
 def leave():
     vref = exctx.topframeref
     exctx.topframeref = vref_None
     virtual_ref_finish(vref, exctx._frame)
Exemple #40
0
 def f():
     x1 = X()
     vref = virtual_ref(x1)
     x2 = vref()
     virtual_ref_finish(vref, x1)
     return x2
Exemple #41
0
 def fn():
     x = X()
     vref = virtual_ref(x)
     x1 = vref()                  # jit_force_virtual
     virtual_ref_finish(vref, x)
 def leave(self, frame):
     jit.virtual_ref_finish(self.topframeref, frame)
     self.topframeref = frame.f_backref
Exemple #43
0
 def f():
     x = X()
     exctx.topframeref = vref = virtual_ref(x)
     exctx.topframeref = vref_None
     virtual_ref_finish(vref, x)
     return 1
Exemple #44
0
 def f(n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s):
     a = A()
     glob.v = vref = virtual_ref(a)
     virtual_ref_finish(vref, a)
     n -= 1
     return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
Exemple #45
0
 def fn():
     x = X()
     vref = virtual_ref(x)
     x1 = vref()  # jit_force_virtual
     virtual_ref_finish(vref, x)
Exemple #46
0
 def f():
     x1 = X()
     vref = virtual_ref(x1)
     x2 = vref()
     virtual_ref_finish(vref, x1)
     return x2
Exemple #47
0
 def leave(self, frame):
     frame_vref = self.topframeref
     self.topframeref = frame.f_backref
     frame.f_backref()
     virtual_ref_finish(frame_vref, frame)