示例#1
0
 def f(x, y):
     if x > 20:
         a = None
     else:
         a = A(x, y)
     a1 = cast_instance_to_base_ptr(a)
     return a1
示例#2
0
 def f(x, y):
     if x > 20:
         a = None
     else:
         a = A(x, y)
     a1 = cast_instance_to_base_ptr(a)
     return a1
示例#3
0
 def f(x, y):
     if x > 20:
         a = None
     else:
         a = A(x, y)
     a1 = cast_instance_to_base_ptr(a)
     b = cast_base_ptr_to_instance(A, a1)
     return a is b
示例#4
0
 def test_cast_instance_to_base_ptr(self):
     class X(object):
         pass
     x = X()
     ptr = annlowlevel.cast_instance_to_base_ptr(x)
     assert lltype.typeOf(ptr) == OBJECTPTR
     y = annlowlevel.cast_base_ptr_to_instance(X, ptr)
     assert y is x
示例#5
0
 def f(x, y):
     if x > 20:
         a = None
     else:
         a = A(x, y)
     a1 = cast_instance_to_base_ptr(a)
     b = cast_base_ptr_to_instance(A, a1)
     return a is b
 def fn():
     a1 = A()
     a = objectmodel.instantiate(A, nonmovable=True)
     a.next = a1  # 'a' is known young here, so no write barrier emitted
     res = rgc.can_move(annlowlevel.cast_instance_to_base_ptr(a))
     rgc.collect()
     objectmodel.keepalive_until_here(a)
     return res
示例#7
0
 def test_cast_instance_to_base_ptr(self):
     class X(object):
         pass
     x = X()
     ptr = annlowlevel.cast_instance_to_base_ptr(x)
     assert lltype.typeOf(ptr) == OBJECTPTR
     y = annlowlevel.cast_base_ptr_to_instance(X, ptr)
     assert y is x
示例#8
0
 def fn():
     a1 = A()
     a = objectmodel.instantiate(A, nonmovable=True)
     a.next = a1  # 'a' is known young here, so no write barrier emitted
     res = rgc.can_move(annlowlevel.cast_instance_to_base_ptr(a))
     rgc.collect()
     objectmodel.keepalive_until_here(a)
     return res
示例#9
0
def get_llexception(cpu, e):
    if we_are_translated():
        return cast_instance_to_base_ptr(e)
    assert not isinstance(e, JitException)
    if isinstance(e, LLException):
        return e.args[1]    # ok
    if isinstance(e, OverflowError):
        return _get_standard_error(cpu.rtyper, OverflowError)
    raise   # leave other exceptions to be propagated
示例#10
0
文件: rgc.py 项目: yuanleilei/pypy
def cast_instance_to_gcref(x):
    # Before translation, casts an RPython instance into a _GcRef.
    # After translation, it is a variant of cast_object_to_ptr(GCREF).
    if we_are_translated():
        from rpython.rtyper import annlowlevel
        x = annlowlevel.cast_instance_to_base_ptr(x)
        return lltype.cast_opaque_ptr(llmemory.GCREF, x)
    else:
        return _GcRef(x)
示例#11
0
文件: rgc.py 项目: Qointum/pypy
def cast_instance_to_gcref(x):
    # Before translation, casts an RPython instance into a _GcRef.
    # After translation, it is a variant of cast_object_to_ptr(GCREF).
    if we_are_translated():
        from rpython.rtyper import annlowlevel
        x = annlowlevel.cast_instance_to_base_ptr(x)
        return lltype.cast_opaque_ptr(llmemory.GCREF, x)
    else:
        return _GcRef(x)
示例#12
0
def get_llexception(cpu, e):
    if we_are_translated():
        return cast_instance_to_base_ptr(e)
    assert not isinstance(e, JitException)
    if isinstance(e, LLException):
        return e.args[1]  # ok
    if isinstance(e, OverflowError):
        return _get_standard_error(cpu.rtyper, OverflowError)
    raise  # leave other exceptions to be propagated
示例#13
0
 def set(value):
     assert isinstance(value, Cls) or value is None
     if we_are_translated():
         from rpython.rtyper.annlowlevel import cast_instance_to_base_ptr
         ptr = cast_instance_to_base_ptr(value)
         _threadlocalref_seeme(self)
         llop.threadlocalref_store(lltype.Void, offset, ptr)
         rgc.register_custom_trace_hook(TRACETLREF, _lambda_trace_tlref)
         rgc.ll_writebarrier(_tracetlref_obj)
     else:
         self.local.value = value
示例#14
0
文件: rgc.py 项目: yuanleilei/pypy
 def register_finalizer(self, obj):
     assert isinstance(obj, self.Class)
     if we_are_translated():
         from rpython.rtyper.lltypesystem.lloperation import llop
         from rpython.rtyper.rclass import OBJECTPTR
         from rpython.rtyper.annlowlevel import cast_instance_to_base_ptr
         tag = FinalizerQueue._get_tag(self)
         ptr = cast_instance_to_base_ptr(obj)
         llop.gc_fq_register(lltype.Void, tag, ptr)
         return
     else:
         self._untranslated_register_finalizer(obj)
示例#15
0
文件: rgc.py 项目: mozillazg/pypy
 def register_finalizer(self, obj):
     assert isinstance(obj, self.Class)
     if we_are_translated():
         from rpython.rtyper.lltypesystem.lloperation import llop
         from rpython.rtyper.rclass import OBJECTPTR
         from rpython.rtyper.annlowlevel import cast_instance_to_base_ptr
         tag = FinalizerQueue._get_tag(self)
         ptr = cast_instance_to_base_ptr(obj)
         llop.gc_fq_register(lltype.Void, tag, ptr)
         return
     else:
         self._untranslated_register_finalizer(obj)
示例#16
0
def write_w_marker_deallocating(space):
    if we_are_translated():
        llptr = cast_instance_to_base_ptr(w_marker_deallocating)
        state = space.fromcache(State)
        state.C.set_marker(rffi.cast(Py_ssize_t, llptr))
示例#17
0
文件: jit_hooks.py 项目: charred/pypy
def _cast_to_gcref(obj):
    return lltype.cast_opaque_ptr(llmemory.GCREF,
                                  cast_instance_to_base_ptr(obj))
示例#18
0
 def g():
     e = OverflowError()
     lle = cast_instance_to_base_ptr(e)
     raise lle  # instead, must cast back from a base ptr to an instance
示例#19
0
def _cast_to_gcref(obj):
    return lltype.cast_opaque_ptr(llmemory.GCREF,
                                  cast_instance_to_base_ptr(obj))
示例#20
0
    def setup_class(cls):
        if cls.runappdirect:
            py.test.skip("Can't run this test with -A")
        w_f = cls.space.appexec([], """():
        def function():
            pass
        return function
        """)
        cls.w_f = w_f
        ll_code = cast_instance_to_base_ptr(w_f.code)
        code_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, ll_code)
        logger = Logger(MockSD())

        oplist = parse("""
        [i1, i2, p2]
        i3 = int_add(i1, i2)
        debug_merge_point(0, 0, 0, 0, 0, ConstPtr(ptr0))
        guard_nonnull(p2) []
        guard_true(i3) []
        """,
                       namespace={
                           'ptr0': code_gcref
                       }).operations
        greenkey = [ConstInt(0), ConstInt(0), ConstPtr(code_gcref)]
        offset = {}
        for i, op in enumerate(oplist):
            if i != 1:
                offset[op] = i

        class FailDescr(BasicFailDescr):
            def get_jitcounter_hash(self):
                from rpython.rlib.rarithmetic import r_uint
                return r_uint(13)

        oplist[-1].setdescr(FailDescr())
        oplist[-2].setdescr(FailDescr())

        token = JitCellToken()
        token.number = 0
        di_loop = JitDebugInfo(MockJitDriverSD, logger, token, oplist, 'loop',
                               greenkey)
        di_loop_optimize = JitDebugInfo(MockJitDriverSD, logger,
                                        JitCellToken(), oplist, 'loop',
                                        greenkey)
        di_loop.asminfo = AsmInfo(offset, 0x42, 12)
        di_bridge = JitDebugInfo(MockJitDriverSD,
                                 logger,
                                 JitCellToken(),
                                 oplist,
                                 'bridge',
                                 fail_descr=FailDescr())
        di_bridge.asminfo = AsmInfo(offset, 0, 0)

        def interp_on_compile():
            di_loop.oplist = cls.oplist
            pypy_hooks.after_compile(di_loop)

        def interp_on_compile_bridge():
            pypy_hooks.after_compile_bridge(di_bridge)

        def interp_on_optimize():
            di_loop_optimize.oplist = cls.oplist
            pypy_hooks.before_compile(di_loop_optimize)

        def interp_on_abort():
            pypy_hooks.on_abort(Counters.ABORT_TOO_LONG, pypyjitdriver,
                                greenkey, 'blah', Logger(MockSD), [])

        space = cls.space
        cls.w_on_compile = space.wrap(interp2app(interp_on_compile))
        cls.w_on_compile_bridge = space.wrap(
            interp2app(interp_on_compile_bridge))
        cls.w_on_abort = space.wrap(interp2app(interp_on_abort))
        cls.w_int_add_num = space.wrap(rop.INT_ADD)
        cls.w_dmp_num = space.wrap(rop.DEBUG_MERGE_POINT)
        cls.w_on_optimize = space.wrap(interp2app(interp_on_optimize))
        cls.orig_oplist = oplist
        cls.w_sorted_keys = space.wrap(sorted(Counters.counter_names))
示例#21
0
    def setup_class(cls):
        if cls.runappdirect:
            py.test.skip("Can't run this test with -A")
        w_f = cls.space.appexec([], """():
        def function():
            pass
        return function
        """)
        cls.w_f = w_f
        ll_code = cast_instance_to_base_ptr(w_f.code)
        code_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, ll_code)
        logger = Logger(MockSD())

        oplist = parse("""
        [i1, i2, p2]
        i3 = int_add(i1, i2)
        debug_merge_point(0, 0, 0, 0, 0, ConstPtr(ptr0))
        guard_nonnull(p2) []
        guard_true(i3) []
        """, namespace={'ptr0': code_gcref}).operations
        greenkey = [ConstInt(0), ConstInt(0), ConstPtr(code_gcref)]
        offset = {}
        for i, op in enumerate(oplist):
            if i != 1:
                offset[op] = i

        token = JitCellToken()
        token.number = 0
        di_loop = JitDebugInfo(MockJitDriverSD, logger, token, oplist, 'loop',
                   greenkey)
        di_loop_optimize = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
                                        oplist, 'loop', greenkey)
        di_loop.asminfo = AsmInfo(offset, 0x42, 12)
        di_bridge = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
                                 oplist, 'bridge', fail_descr=BasicFailDescr())
        di_bridge.asminfo = AsmInfo(offset, 0, 0)

        def interp_on_compile():
            di_loop.oplist = cls.oplist
            pypy_hooks.after_compile(di_loop)

        def interp_on_compile_bridge():
            pypy_hooks.after_compile_bridge(di_bridge)

        def interp_on_optimize():
            di_loop_optimize.oplist = cls.oplist
            pypy_hooks.before_compile(di_loop_optimize)

        def interp_on_abort():
            pypy_hooks.on_abort(Counters.ABORT_TOO_LONG, pypyjitdriver,
                                greenkey, 'blah', Logger(MockSD), [])

        space = cls.space
        cls.w_on_compile = space.wrap(interp2app(interp_on_compile))
        cls.w_on_compile_bridge = space.wrap(interp2app(interp_on_compile_bridge))
        cls.w_on_abort = space.wrap(interp2app(interp_on_abort))
        cls.w_int_add_num = space.wrap(rop.INT_ADD)
        cls.w_dmp_num = space.wrap(rop.DEBUG_MERGE_POINT)
        cls.w_on_optimize = space.wrap(interp2app(interp_on_optimize))
        cls.orig_oplist = oplist
        cls.w_sorted_keys = space.wrap(sorted(Counters.counter_names))
示例#22
0
 def g():
     e = OverflowError()
     lle = cast_instance_to_base_ptr(e)
     raise lle  # instead, must cast back from a base ptr to an instance