Пример #1
0
    def test_finish_with_guard_not_forced_2_ref(self):
        cpu = self.cpu

        loop = self.parse("""
        [p0, p1]
        guard_not_forced_2(descr=faildescr) [p1]
        finish(p0, descr=finaldescr)
        """,
                          namespace={
                              'faildescr': BasicFailDescr(1),
                              'finaldescr': BasicFinalDescr(2)
                          })

        token = JitCellToken()
        cpu.gc_ll_descr.init_nursery(100)
        cpu.setup_once()
        cpu.compile_loop(loop.inputargs, loop.operations, token)
        n = lltype.nullptr(llmemory.GCREF.TO)
        frame = lltype.cast_opaque_ptr(JITFRAMEPTR,
                                       cpu.execute_token(token, n, n))
        assert getmap(frame).count('1') == 2
Пример #2
0
    def optimize(self, ops):
        loop = self.parse(ops)
        self.add_guard_future_condition(loop)
        operations = loop.operations
        jumpop = operations[-1]
        assert jumpop.getopnum() == rop.JUMP
        inputargs = loop.inputargs

        jump_args = jumpop.getarglist()[:]
        operations = operations[:-1]

        preamble = TreeLoop('preamble')

        token = JitCellToken()
        trace = oparser.convert_loop_to_trace(
            loop, FakeMetaInterpStaticData(self.cpu))
        compile_data = LoopCompileData(trace, inputargs)
        start_state, newops = self._do_optimize_loop(compile_data)
        preamble.operations = newops
        preamble.inputargs = start_state.renamed_inputargs
        return start_state, loop, preamble
Пример #3
0
 def test_int_add(self):
     # random seed: 1202
     # block length: 4
     # AssertionError: Got 1431655764, expected 357913940 for value #3
     faildescr1 = BasicFailDescr(1)
     faildescr2 = BasicFailDescr(2)
     v1 = BoxInt()
     v2 = BoxInt()
     v3 = BoxInt()
     v4 = BoxInt()
     v5 = BoxInt()
     v6 = BoxInt()
     v7 = BoxInt()
     v8 = BoxInt()
     v9 = BoxInt()
     v10 = BoxInt()
     v11 = BoxInt()
     tmp12 = BoxInt()
     cpu = CPU(None, None)
     cpu.setup_once()
     inputargs = [v1, v2, v3, v4, v5, v6, v7, v8, v9, v10]
     operations = [
         ResOperation(rop.INT_ADD, [ConstInt(-1073741825), v3], v11),
         ResOperation(rop.INT_IS_TRUE, [v1], tmp12),
         ResOperation(rop.GUARD_FALSE, [tmp12], None, descr=faildescr1),
         ResOperation(rop.GUARD_FALSE, [v1], None, descr=faildescr2),
         ]
     operations[2].setfailargs([v10, v3, v6, v11, v9, v2])
     operations[-1].setfailargs([v8, v2, v10, v6, v7, v9, v5, v4])
     looptoken = JitCellToken()
     cpu.compile_loop(inputargs, operations, looptoken)
     args = [3 , -5 , 1431655765 , 47 , 12 , 1789569706 , 15 , 939524096 , 16 , -43]
     deadframe = cpu.execute_token(looptoken, *args)
     assert cpu.get_latest_descr(deadframe).identifier == 1
     assert cpu.get_int_value(deadframe, 0) == -43
     assert cpu.get_int_value(deadframe, 1) == 1431655765
     assert cpu.get_int_value(deadframe, 2) == 1789569706
     assert cpu.get_int_value(deadframe, 3) == 357913940
     assert cpu.get_int_value(deadframe, 4) == 16
     assert cpu.get_int_value(deadframe, 5) == -5
Пример #4
0
 def parse_loop(self, ops, add_label=True):
     loop = self.parse(ops)
     loop.operations = filter(lambda op: op.getopnum() != rop.DEBUG_MERGE_POINT, loop.operations)
     token = JitCellToken()
     if add_label:
         label = ResOperation(rop.LABEL, loop.inputargs, descr=TargetToken(token))
     else:
         label = loop.operations[0]
         label.setdescr(TargetToken(token))
     jump = loop.operations[-1]
     loop = VectorLoop(label, loop.operations[0:-1], jump)
     loop.jump.setdescr(token)
     class Optimizer(object):
         metainterp_sd = FakeMetaInterpStaticData(self.cpu)
         jitdriver_sd = FakeJitDriverStaticData()
     opt = Optimizer()
     opt.jitdriver_sd.vec = True
     for op in loop.operations:
         if op.is_guard() and not op.getdescr():
             descr = invent_fail_descr_for_op(op.getopnum(), opt)
             op.setdescr(descr)
     return loop
Пример #5
0
 def test_ops_offset(self):
     from rpython.rlib import debug
     looptoken = JitCellToken()
     targettoken = TargetToken()
     loop = parse("""
     [i0]
     label(i0, descr=targettoken)
     i1 = int_add(i0, 1)
     i2 = int_le(i1, 9)
     jump(i1, descr=targettoken)
     """, namespace=locals())
     debug._log = dlog = debug.DebugLog()
     info = self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
     ops_offset = info.ops_offset
     debug._log = None
     #
     assert ops_offset is looptoken._x86_ops_offset
     # 2*increment_debug_counter + ops + None
     assert len(ops_offset) == 2 + len(loop.operations) + 1
     assert (ops_offset[loop.operations[0]] <=
             ops_offset[loop.operations[1]] <=
             ops_offset[loop.operations[2]] <=
             ops_offset[None])
Пример #6
0
 def test_double_evenodd_pair(self):
     code = """
     [i0]
     i1 = int_floordiv(i0, 2)
     i2 = int_floordiv(i0, 3)
     i3 = int_floordiv(i0, 4)
     i4 = int_floordiv(i0, 5)
     i5 = int_floordiv(i0, 6)
     i6 = int_floordiv(i0, 7)
     i7 = int_floordiv(i0, 8)
     i8 = int_le(i1, 0)
     guard_true(i8) [i1,i2,i3,i4,i5,i6,i7]
     finish(i0, descr=faildescr)
     """
     # the guard forces 3 spills because after 4 divisions
     # all even slots of the managed registers are full
     loop = parse(code, namespace={'faildescr': BasicFinalDescr(1)})
     looptoken = JitCellToken()
     self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
     deadframe = self.cpu.execute_token(looptoken, 100)
     fail = self.cpu.get_latest_descr(deadframe)
     for i in range(2, 9):
         assert self.cpu.get_int_value(deadframe, i - 2) == 100 // i
Пример #7
0
def test_bug_rshift():
    v1 = BoxInt()
    v2 = BoxInt()
    v3 = BoxInt()
    v4 = BoxInt()
    zero = BoxInt()
    inputargs = [v1]
    operations = [
        ResOperation(rop.INT_ADD, [v1, v1], v2),
        ResOperation(rop.INT_INVERT, [v2], v3),
        ResOperation(rop.UINT_RSHIFT, [v1, ConstInt(3)], v4),
        ResOperation(rop.SAME_AS, [ConstInt(0)], zero),
        ResOperation(rop.GUARD_TRUE, [zero], None, descr=BasicFailDescr()),
        ResOperation(rop.FINISH, [], None, descr=BasicFinalDescr())
    ]
    operations[-2].setfailargs([v4, v3])
    cpu = CPU(None, None)
    cpu.setup_once()
    looptoken = JitCellToken()
    cpu.compile_loop(inputargs, operations, looptoken)
    deadframe = cpu.execute_token(looptoken, 9)
    assert cpu.get_int_value(deadframe, 0) == (9 >> 3)
    assert cpu.get_int_value(deadframe, 1) == (~18)
Пример #8
0
 def test_nullity_with_guard(self):
     allops = [rop.INT_IS_TRUE]
     guards = [rop.GUARD_TRUE, rop.GUARD_FALSE]
     p = lltype.cast_opaque_ptr(llmemory.GCREF,
                                lltype.malloc(lltype.GcStruct('x')))
     nullptr = lltype.nullptr(llmemory.GCREF.TO)
     f = InputArgInt()
     for op in allops:
         for guard in guards:
             if op == rop.INT_IS_TRUE:
                 bp = InputArgInt(1)
                 n = InputArgInt(0)
             else:
                 bp = InputArgRef(p)
                 n = InputArgRef(nullptr)
             for b in (bp, n):
                 i1 = ResOperation(rop.SAME_AS_I, [ConstInt(1)])
                 f = ResOperation(op, [b])
                 ops = [
                     i1,
                     f,
                     ResOperation(guard, [f],
                                  descr=BasicFailDescr()),
                     ResOperation(rop.FINISH, [ConstInt(0)],
                                  descr=BasicFinalDescr()),
                     ]
                 ops[-2].setfailargs([i1])
                 looptoken = JitCellToken()
                 self.cpu.compile_loop([b], ops, looptoken)
                 deadframe = self.cpu.execute_token(looptoken, b.getint())
                 result = self.cpu.get_int_value(deadframe, 0)
                 if guard == rop.GUARD_FALSE:
                     assert result == execute(self.cpu, None,
                                              op, None, b)
                 else:
                     assert result != execute(self.cpu, None,
                                              op, None, b)
Пример #9
0
    def test_return_spilled_args(self):
        numargs = 50
        ops = []
        arglist = "[%s]\n" % ", ".join(["i%d" % i for i in range(numargs)])
        ops.append(arglist)

        # spill every inputarg
        for i in range(numargs):
            ops.append("force_spill(i%d)\n" % i)
        ops.append("guard_value(i0, -1) %s" % arglist)
        ops = "".join(ops)
        loop = parse(ops)
        looptoken = JitCellToken()
        faildescr = loop.operations[-1].getdescr()
        self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
        ARGS = [lltype.Signed] * numargs
        RES = lltype.Signed
        args = [i + 1 for i in range(numargs)]
        deadframe = self.cpu.execute_token(looptoken, *args)
        fail = self.cpu.get_latest_descr(deadframe)
        assert fail is faildescr
        for i in range(numargs):
            assert self.cpu.get_int_value(deadframe, i) == i + 1

        bridgeops = [arglist]
        bridgeops.append("guard_value(i1, -5) %s" % arglist)
        bridgeops = "".join(bridgeops)
        bridge = parse(bridgeops)
        faildescr2 = bridge.operations[-1].getdescr()

        self.cpu.compile_bridge(faildescr, bridge.inputargs, bridge.operations,
                                looptoken)
        deadframe = self.cpu.execute_token(looptoken, *args)
        fail = self.cpu.get_latest_descr(deadframe)
        assert fail is faildescr2
        for i in range(numargs):
            assert self.cpu.get_int_value(deadframe, i) == i + 1
Пример #10
0
 def test0(self):
     faildescr1 = BasicFailDescr(1)
     faildescr2 = BasicFailDescr(2)
     v1 = BoxInt()
     v2 = BoxInt()
     v3 = BoxInt()
     v4 = BoxInt()
     v5 = BoxInt()
     v6 = BoxInt()
     v7 = BoxInt()
     v8 = BoxInt()
     v9 = BoxInt()
     v10 = BoxInt()
     v11 = BoxInt()
     v12 = BoxInt()
     cpu = CPU(None, None)
     cpu.setup_once()
     inputargs = [v1, v2, v3, v4, v5, v6, v7, v8, v9, v10]
     operations = [
         ResOperation(rop.INT_SUB, [ConstInt(-1073741824), v7], v11),
         ResOperation(rop.INT_GE, [v3, ConstInt(23)], v12),
         ResOperation(rop.GUARD_TRUE, [v12], None, descr=faildescr1),
         ResOperation(rop.GUARD_FALSE, [v1], None, descr=faildescr2),
         ]
     looptoken = JitCellToken()
     operations[2].setfailargs([v12, v8, v3, v2, v1, v11])
     operations[3].setfailargs([v9, v6, v10, v2, v8, v5, v1, v4])
     cpu.compile_loop(inputargs, operations, looptoken)
     args = [-12 , -26 , -19 , 7 , -5 , -24 , -37 , 62 , 9 , 12]
     deadframe = cpu.execute_token(looptoken, *args)
     assert cpu.get_int_value(deadframe, 0) == 0
     assert cpu.get_int_value(deadframe, 1) == 62
     assert cpu.get_int_value(deadframe, 2) == -19
     assert cpu.get_int_value(deadframe, 3) == -26
     assert cpu.get_int_value(deadframe, 4) == -12
     assert cpu.get_int_value(deadframe, 5) == -1073741787
Пример #11
0
 def test_ops_offset(self):
     from rpython.rlib import debug
     i0 = BoxInt()
     i1 = BoxInt()
     i2 = BoxInt()
     looptoken = JitCellToken()
     targettoken = TargetToken()
     operations = [
         ResOperation(rop.LABEL, [i0], None, descr=targettoken),
         ResOperation(rop.INT_ADD, [i0, ConstInt(1)], i1),
         ResOperation(rop.INT_LE, [i1, ConstInt(9)], i2),
         ResOperation(rop.JUMP, [i1], None, descr=targettoken),
     ]
     inputargs = [i0]
     debug._log = dlog = debug.DebugLog()
     info = self.cpu.compile_loop(inputargs, operations, looptoken)
     ops_offset = info.ops_offset
     debug._log = None
     #
     assert ops_offset is looptoken._x86_ops_offset
     # 2*increment_debug_counter + ops + None
     assert len(ops_offset) == 2 + len(operations) + 1
     assert (ops_offset[operations[0]] <= ops_offset[operations[1]] <=
             ops_offset[operations[2]] <= ops_offset[None])
Пример #12
0
def test_bug_int_is_true_1():
    v1 = BoxInt()
    v2 = BoxInt()
    v3 = BoxInt()
    v4 = BoxInt()
    tmp5 = BoxInt()
    inputargs = [v1]
    operations = [
        ResOperation(rop.INT_MUL, [v1, v1], v2),
        ResOperation(rop.INT_MUL, [v2, v1], v3),
        ResOperation(rop.INT_IS_TRUE, [v2], tmp5),
        ResOperation(rop.INT_IS_ZERO, [tmp5], v4),
        ResOperation(rop.GUARD_FALSE, [v1], None, descr=BasicFailDescr()),
        ResOperation(rop.FINISH, [], None, descr=BasicFinalDescr()),
    ]
    operations[-2].setfailargs([v4, v3, tmp5])
    cpu = CPU(None, None)
    cpu.setup_once()
    looptoken = JitCellToken()
    cpu.compile_loop(inputargs, operations, looptoken)
    deadframe = cpu.execute_token(looptoken, -10)
    assert cpu.get_int_value(deadframe, 0) == 0
    assert cpu.get_int_value(deadframe, 1) == -1000
    assert cpu.get_int_value(deadframe, 2) == 1
Пример #13
0
    def optimize_bridge(self, loops, bridge, expected, expected_target='Loop', **boxvalues):
        if isinstance(loops, str):
            loops = (loops, )
        loops = [self.parse(loop) for loop in loops]
        bridge = self.parse(bridge)
        for loop in loops:
            loop.preamble = self.unroll_and_optimize(loop)
        preamble = loops[0].preamble
        token = JitCellToken()
        token.target_tokens = [l.operations[0].getdescr() for l in [preamble] + loops]

        boxes = {}
        for b in bridge.inputargs + [op.result for op in bridge.operations]:
            boxes[str(b)] = b
        for b, v in boxvalues.items():
            boxes[b].value = v
        bridge.operations[-1].setdescr(token)
        self._do_optimize_bridge(bridge, None)
        if bridge.operations[-1].getopnum() == rop.LABEL:
            assert expected == 'RETRACE'
            return

        print '\n'.join([str(o) for o in bridge.operations])
        expected = self.parse(expected)
        self.assert_equal(bridge, expected)

        if expected_target == 'Preamble':
            assert bridge.operations[-1].getdescr() is preamble.operations[0].getdescr()
        elif expected_target == 'Loop':
            assert len(loops) == 1
            assert bridge.operations[-1].getdescr() is loops[0].operations[0].getdescr()
        elif expected_target.startswith('Loop'):
            n = int(expected_target[4:])
            assert bridge.operations[-1].getdescr() is loops[n].operations[0].getdescr()
        else:
            assert False
Пример #14
0
    def build_random_loop(self, cpu, builder_factory, r, startvars,
                          allow_delay):

        loop = TreeLoop('test_random_function')
        loop.inputargs = startvars[:]
        loop.operations = []
        loop._jitcelltoken = JitCellToken()
        builder = builder_factory(cpu, loop, startvars[:])
        if allow_delay:
            needs_a_label = True
        else:
            self.insert_label(loop, 0, r)
            needs_a_label = False
        self.generate_ops(builder,
                          r,
                          loop,
                          startvars,
                          needs_a_label=needs_a_label)
        self.builder = builder
        self.loop = loop
        dump(loop)
        cpu.compile_loop(loop.inputargs, loop.operations, loop._jitcelltoken)
        if self.output:
            builder.print_loop(self.output)
Пример #15
0
    def test_compile_bridge_check_profile_info(self):
        py.test.skip("does not work, reinvestigate")

        class FakeProfileAgent(object):
            def __init__(self):
                self.functions = []

            def native_code_written(self, name, address, size):
                self.functions.append((name, address, size))

        self.cpu.profile_agent = agent = FakeProfileAgent()

        i0 = InputArgInt()
        i1 = InputArgInt()
        i2 = InputArgInt()
        targettoken = TargetToken()
        faildescr1 = BasicFailDescr(1)
        faildescr2 = BasicFailDescr(2)
        looptoken = JitCellToken()
        looptoken.number = 17

        class FakeString(object):
            def __init__(self, val):
                self.val = val

            def _get_str(self):
                return self.val

        operations = [
            ResOperation(rop.LABEL, [i0], None, descr=targettoken),
            ResOperation(rop.DEBUG_MERGE_POINT, [FakeString("hello"), 0, 0],
                         None),
            ResOperation(rop.INT_ADD, [i0, ConstInt(1)], i1),
            ResOperation(rop.INT_LE, [i1, ConstInt(9)], i2),
            ResOperation(rop.GUARD_TRUE, [i2], None, descr=faildescr1),
            ResOperation(rop.JUMP, [i1], None, descr=targettoken),
        ]
        inputargs = [i0]
        operations[-2].setfailargs([i1])
        self.cpu.compile_loop(inputargs, operations, looptoken)
        name, loopaddress, loopsize = agent.functions[0]
        assert name == "Loop # 17: hello (loop counter 0)"
        assert loopaddress <= looptoken._ll_loop_code
        assert loopsize >= 40  # randomish number

        i1b = InputArgInt()
        i3 = InputArgInt()
        bridge = [
            ResOperation(rop.INT_LE, [i1b, ConstInt(19)], i3),
            ResOperation(rop.GUARD_TRUE, [i3], None, descr=faildescr2),
            ResOperation(rop.DEBUG_MERGE_POINT, [FakeString("bye"), 0, 0],
                         None),
            ResOperation(rop.JUMP, [i1b], None, descr=targettoken),
        ]
        bridge[1].setfailargs([i1b])

        self.cpu.compile_bridge(faildescr1, [i1b], bridge, looptoken)
        name, address, size = agent.functions[1]
        assert name == "Bridge # 0: bye (loop counter 1)"
        # Would be exactly ==, but there are some guard failure recovery
        # stubs in-between
        assert address >= loopaddress + loopsize
        assert size >= 10  # randomish number

        deadframe = self.cpu.execute_token(looptoken, 2)
        fail = self.cpu.get_latest_descr(deadframe)
        assert fail.identifier == 2
        res = self.cpu.get_int_value(deadframe, 0)
        assert res == 20
Пример #16
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))
Пример #17
0
def make_jitcell_token(jitdriver_sd):
    jitcell_token = JitCellToken()
    jitcell_token.outermost_jitdriver_sd = jitdriver_sd
    return jitcell_token
Пример #18
0
    def test_shadowstack_call(self):
        cpu = self.cpu
        cpu.gc_ll_descr.init_nursery(100)
        cpu.setup_once()
        S = self.S
        frames = []

        def check(i):
            assert cpu.gc_ll_descr.gcrootmap.curtop() == i
            frame = rffi.cast(JITFRAMEPTR, i)
            assert len(frame.jf_frame) == self.cpu.JITFRAME_FIXED_SIZE + 4
            # we "collect"
            frames.append(frame)
            new_frame = JITFRAME.allocate(frame.jf_frame_info)
            gcmap = unpack_gcmap(frame)
            if self.cpu.backend_name.startswith('ppc64'):
                assert gcmap == [30, 31, 32]
            elif self.cpu.backend_name.startswith('zarch'):
                # 10 gpr, 14 fpr -> 25 is the first slot
                assert gcmap == [26, 27, 28]
            elif self.cpu.IS_64_BIT:
                assert gcmap == [28, 29, 30]
            elif self.cpu.backend_name.startswith('arm'):
                assert gcmap == [44, 45, 46]
            else:
                assert gcmap == [22, 23, 24]
            for item, s in zip(gcmap, new_items):
                new_frame.jf_frame[item] = rffi.cast(lltype.Signed, s)
            assert cpu.gc_ll_descr.gcrootmap.curtop() == rffi.cast(lltype.Signed, frame)
            cpu.gc_ll_descr.gcrootmap.settop(rffi.cast(lltype.Signed, new_frame))
            print '"Collecting" moved the frame from %d to %d' % (
                i, cpu.gc_ll_descr.gcrootmap.curtop())
            frames.append(new_frame)

        def check2(i):
            assert cpu.gc_ll_descr.gcrootmap.curtop() == i
            frame = rffi.cast(JITFRAMEPTR, i)
            assert frame == frames[1]
            assert frame != frames[0]

        CHECK = lltype.FuncType([lltype.Signed], lltype.Void)
        checkptr = llhelper(lltype.Ptr(CHECK), check)
        check2ptr = llhelper(lltype.Ptr(CHECK), check2)
        checkdescr = cpu.calldescrof(CHECK, CHECK.ARGS, CHECK.RESULT,
                                          EffectInfo.MOST_GENERAL)

        loop = self.parse("""
        [p0, p1, p2]
        pf = force_token() # this is the frame
        call_n(ConstClass(check_adr), pf, descr=checkdescr) # this can collect
        p3 = getfield_gc_r(p0, descr=fielddescr)
        pf2 = force_token()
        call_n(ConstClass(check2_adr), pf2, descr=checkdescr)
        guard_nonnull(p3, descr=faildescr) [p0, p1, p2, p3]
        p4 = getfield_gc_r(p0, descr=fielddescr)
        finish(p4, descr=finaldescr)
        """, namespace={'finaldescr': BasicFinalDescr(),
                        'faildescr': BasicFailDescr(),
                        'check_adr': checkptr, 'check2_adr': check2ptr,
                        'checkdescr': checkdescr,
                        'fielddescr': cpu.fielddescrof(S, 'x')})
        token = JitCellToken()
        cpu.compile_loop(loop.inputargs, loop.operations, token)
        p0 = lltype.malloc(S, zero=True)
        p1 = lltype.malloc(S)
        p2 = lltype.malloc(S)
        new_items = [lltype.malloc(S), lltype.malloc(S), lltype.malloc(S)]
        new_items[0].x = new_items[2]
        frame = cpu.execute_token(token, p0, p1, p2)
        frame = lltype.cast_opaque_ptr(JITFRAMEPTR, frame)
        gcmap = unpack_gcmap(lltype.cast_opaque_ptr(JITFRAMEPTR, frame))
        assert len(gcmap) == 1
        assert gcmap[0] < self.cpu.JITFRAME_FIXED_SIZE
        item = rffi.cast(lltype.Ptr(S), frame.jf_frame[gcmap[0]])
        assert item == new_items[2]
Пример #19
0
    def test_call_alignment_call_assembler(self):
        cpu = self.cpu
        if not cpu.supports_floats:
            py.test.skip('requires floats')

        fdescr3 = BasicFinalDescr(3)
        fdescr4 = BasicFinalDescr(4)

        def assembler_helper(failindex, virtualizable):
            assert 0, 'should not be called, but was with failindex (%d)' % failindex
            return 13

        FUNCPTR = lltype.Ptr(
            lltype.FuncType([lltype.Signed, llmemory.GCREF], lltype.Signed))

        class FakeJitDriverSD:
            index_of_virtualizable = -1
            _assembler_helper_ptr = llhelper(FUNCPTR, assembler_helper)
            assembler_helper_adr = llmemory.cast_ptr_to_adr(
                _assembler_helper_ptr)

        floats = [0.7, 5.8, 0.1, 0.3, 0.9, -2.34, -3.45, -4.56]
        ints = [7, 11, 23, 42, -42, 1111, 95, 1]

        for case in range(256):
            float_count = 0
            int_count = 0
            args = []
            called_ops = ''
            total_index = -1
            for i in range(8):
                if case & (1 << i):
                    args.append('f%d' % float_count)
                else:
                    args.append('i%d' % int_count)
                    called_ops += 'f%d = cast_int_to_float(i%d)\n' % (
                        float_count, int_count)
                    int_count += 1
                if total_index == -1:
                    total_index = float_count
                    float_count += 1
                else:
                    called_ops += 'f%d = float_add(f%d, f%d)\n' % (
                        float_count + 1, total_index, float_count)
                    total_index = float_count + 1
                    float_count += 2
            arguments = ', '.join(args)
            called_ops = '[%s]\n' % arguments + called_ops
            called_ops += 'finish(f%d, descr=fdescr3)\n' % total_index
            # compile called loop
            called_loop = parse(called_ops, namespace=locals())
            called_looptoken = JitCellToken()
            called_looptoken.outermost_jitdriver_sd = FakeJitDriverSD()
            done_descr = called_loop.operations[-1].getdescr()
            self.cpu.compile_loop(called_loop.inputargs,
                                  called_loop.operations, called_looptoken)

            argvals, expected_result = self._prepare_args(args, floats, ints)
            deadframe = cpu.execute_token(called_looptoken, *argvals)
            assert cpu.get_latest_descr(deadframe) == fdescr3
            t = longlong.getrealfloat(cpu.get_float_value(deadframe, 0))
            assert abs(t - expected_result) < 0.0001

            ARGS = []
            RES = lltype.Float
            for x in args:
                if x[0] == 'f':
                    ARGS.append(lltype.Float)
                else:
                    ARGS.append(lltype.Signed)
            FakeJitDriverSD.portal_calldescr = self.cpu.calldescrof(
                lltype.Ptr(lltype.FuncType(ARGS, RES)), ARGS, RES,
                EffectInfo.MOST_GENERAL)
            ops = '''
            [%s]
            f99 = call_assembler(%s, descr=called_looptoken)
            guard_not_forced()[]
            finish(f99, descr=fdescr4)
            ''' % (arguments, arguments)
            loop = parse(ops, namespace=locals())
            # we want to take the fast path
            self.cpu.done_with_this_frame_descr_float = done_descr
            try:
                othertoken = JitCellToken()
                self.cpu.compile_loop(loop.inputargs, loop.operations,
                                      othertoken)

                # prepare call to called_loop
                argvals, _ = self._prepare_args(args, floats, ints)
                deadframe = cpu.execute_token(othertoken, *argvals)
                x = longlong.getrealfloat(cpu.get_float_value(deadframe, 0))
                assert cpu.get_latest_descr(deadframe) == fdescr4
                assert abs(x - expected_result) < 0.0001
            finally:
                del self.cpu.done_with_this_frame_descr_float
Пример #20
0
    def check_rewrite(self, frm_operations, to_operations, **namespace):
        # objects to use inside the test
        A = lltype.GcArray(lltype.Signed)
        adescr = get_array_descr(self.gc_ll_descr, A)
        adescr.tid = 4321
        alendescr = adescr.lendescr
        #
        pinned_obj_type = lltype.GcStruct('PINNED_STRUCT', ('my_int', lltype.Signed))
        pinned_obj_my_int_descr = get_field_descr(self.gc_ll_descr, pinned_obj_type, 'my_int')
        pinned_obj_ptr = lltype.malloc(pinned_obj_type)
        pinned_obj_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, pinned_obj_ptr)
        assert rgc.pin(pinned_obj_gcref)
        #
        notpinned_obj_type = lltype.GcStruct('NOT_PINNED_STRUCT', ('my_int', lltype.Signed))
        notpinned_obj_my_int_descr = get_field_descr(self.gc_ll_descr, notpinned_obj_type, 'my_int')
        notpinned_obj_ptr = lltype.malloc(notpinned_obj_type)
        notpinned_obj_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, notpinned_obj_ptr)
        #
        ptr_array_descr = self.cpu.arraydescrof(MovableObjectTracker.ptr_array_type)
        #
        vtable_descr = self.gc_ll_descr.fielddescr_vtable
        O = lltype.GcStruct('O', ('parent', rclass.OBJECT),
                                 ('x', lltype.Signed))
        o_vtable = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
        register_known_gctype(self.cpu, o_vtable, O)
        #
        tiddescr = self.gc_ll_descr.fielddescr_tid
        wbdescr = self.gc_ll_descr.write_barrier_descr
        WORD = globals()['WORD']
        #
        strdescr     = self.gc_ll_descr.str_descr
        unicodedescr = self.gc_ll_descr.unicode_descr
        strlendescr     = strdescr.lendescr
        unicodelendescr = unicodedescr.lendescr

        casmdescr = JitCellToken()
        clt = FakeLoopToken()
        clt._ll_initial_locs = [0, 8]
        frame_info = lltype.malloc(jitframe.JITFRAMEINFO, flavor='raw')
        clt.frame_info = frame_info
        frame_info.jfi_frame_depth = 13
        frame_info.jfi_frame_size = 255
        framedescrs = self.gc_ll_descr.getframedescrs(self.cpu)
        framelendescr = framedescrs.arraydescr.lendescr
        jfi_frame_depth = framedescrs.jfi_frame_depth
        jfi_frame_size = framedescrs.jfi_frame_size
        jf_frame_info = framedescrs.jf_frame_info
        signedframedescr = self.cpu.signedframedescr
        floatframedescr = self.cpu.floatframedescr
        casmdescr.compiled_loop_token = clt
        tzdescr = None # noone cares
        #
        namespace.update(locals())
        #
        for funcname in self.gc_ll_descr._generated_functions:
            namespace[funcname] = self.gc_ll_descr.get_malloc_fn(funcname)
            namespace[funcname + '_descr'] = getattr(self.gc_ll_descr,
                                                     '%s_descr' % funcname)
        #
        ops = parse(frm_operations, namespace=namespace)
        operations = self.gc_ll_descr.rewrite_assembler(self.cpu,
                                                        ops.operations,
                                                        [])
        # make the array containing the GCREF's accessible inside the tests.
        # This must be done after we call 'rewrite_assembler'. Before that
        # call 'last_moving_obj_tracker' is None or filled with some old
        # value.
        namespace['ptr_array_gcref'] = self.gc_ll_descr.last_moving_obj_tracker.ptr_array_gcref
        expected = parse(to_operations % Evaluator(namespace),
                         namespace=namespace)
        equaloplists(operations, expected.operations)
        lltype.free(frame_info, flavor='raw')
Пример #21
0
    def check_rewrite(self, frm_operations, to_operations, **namespace):
        S = lltype.GcStruct('S', ('x', lltype.Signed), ('y', lltype.Signed))
        sdescr = get_size_descr(self.gc_ll_descr, S)
        sdescr.tid = 1234
        #
        T = lltype.GcStruct('T', ('y', lltype.Signed), ('z', lltype.Ptr(S)),
                            ('t', lltype.Signed))
        tdescr = get_size_descr(self.gc_ll_descr, T)
        tdescr.tid = 5678
        tzdescr = get_field_descr(self.gc_ll_descr, T, 'z')
        #
        A = lltype.GcArray(lltype.Signed)
        adescr = get_array_descr(self.gc_ll_descr, A)
        adescr.tid = 4321
        alendescr = adescr.lendescr
        #
        B = lltype.GcArray(lltype.Char)
        bdescr = get_array_descr(self.gc_ll_descr, B)
        bdescr.tid = 8765
        blendescr = bdescr.lendescr
        #
        C = lltype.GcArray(lltype.Ptr(S))
        cdescr = get_array_descr(self.gc_ll_descr, C)
        cdescr.tid = 8111
        clendescr = cdescr.lendescr
        #
        E = lltype.GcStruct('Empty')
        edescr = get_size_descr(self.gc_ll_descr, E)
        edescr.tid = 9000
        #
        vtable_descr = self.gc_ll_descr.fielddescr_vtable
        O = lltype.GcStruct('O', ('parent', rclass.OBJECT),
                            ('x', lltype.Signed))
        o_vtable = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
        register_known_gctype(self.cpu, o_vtable, O)
        #
        tiddescr = self.gc_ll_descr.fielddescr_tid
        wbdescr = self.gc_ll_descr.write_barrier_descr
        WORD = globals()['WORD']
        #
        strdescr = self.gc_ll_descr.str_descr
        unicodedescr = self.gc_ll_descr.unicode_descr
        strlendescr = strdescr.lendescr
        unicodelendescr = unicodedescr.lendescr
        strhashdescr = self.gc_ll_descr.str_hash_descr
        unicodehashdescr = self.gc_ll_descr.unicode_hash_descr

        casmdescr = JitCellToken()
        clt = FakeLoopToken()
        clt._ll_initial_locs = [0, 8]
        frame_info = lltype.malloc(jitframe.JITFRAMEINFO, flavor='raw')
        clt.frame_info = frame_info
        frame_info.jfi_frame_depth = 13
        frame_info.jfi_frame_size = 255
        framedescrs = self.gc_ll_descr.getframedescrs(self.cpu)
        framelendescr = framedescrs.arraydescr.lendescr
        jfi_frame_depth = framedescrs.jfi_frame_depth
        jfi_frame_size = framedescrs.jfi_frame_size
        jf_frame_info = framedescrs.jf_frame_info
        jf_savedata = framedescrs.jf_savedata
        jf_force_descr = framedescrs.jf_force_descr
        jf_descr = framedescrs.jf_descr
        jf_guard_exc = framedescrs.jf_guard_exc
        jf_forward = framedescrs.jf_forward
        jf_extra_stack_depth = framedescrs.jf_extra_stack_depth
        signedframedescr = self.cpu.signedframedescr
        floatframedescr = self.cpu.floatframedescr
        casmdescr.compiled_loop_token = clt
        #
        guarddescr = AbstractFailDescr()
        #
        namespace.update(locals())
        #
        for funcname in self.gc_ll_descr._generated_functions:
            namespace[funcname] = self.gc_ll_descr.get_malloc_fn(funcname)
            namespace[funcname + '_descr'] = getattr(self.gc_ll_descr,
                                                     '%s_descr' % funcname)
        #
        ops = parse(frm_operations, namespace=namespace)
        expected = parse(to_operations % Evaluator(namespace),
                         namespace=namespace)
        operations = self.gc_ll_descr.rewrite_assembler(
            self.cpu, ops.operations, [])
        equaloplists(operations, expected.operations)
        lltype.free(frame_info, flavor='raw')
Пример #22
0
def test_bug_0():
    v1 = BoxInt()
    v2 = BoxInt()
    v3 = BoxInt()
    v4 = BoxInt()
    v5 = BoxInt()
    v6 = BoxInt()
    v7 = BoxInt()
    v8 = BoxInt()
    v9 = BoxInt()
    v10 = BoxInt()
    v11 = BoxInt()
    v12 = BoxInt()
    v13 = BoxInt()
    v14 = BoxInt()
    v15 = BoxInt()
    v16 = BoxInt()
    v17 = BoxInt()
    v18 = BoxInt()
    v19 = BoxInt()
    v20 = BoxInt()
    v21 = BoxInt()
    v22 = BoxInt()
    v23 = BoxInt()
    v24 = BoxInt()
    v25 = BoxInt()
    v26 = BoxInt()
    v27 = BoxInt()
    v28 = BoxInt()
    v29 = BoxInt()
    v30 = BoxInt()
    v31 = BoxInt()
    v32 = BoxInt()
    v33 = BoxInt()
    v34 = BoxInt()
    v35 = BoxInt()
    v36 = BoxInt()
    v37 = BoxInt()
    v38 = BoxInt()
    v39 = BoxInt()
    v40 = BoxInt()
    tmp41 = BoxInt()
    tmp42 = BoxInt()
    tmp43 = BoxInt()
    tmp44 = BoxInt()
    tmp45 = BoxInt()
    tmp46 = BoxInt()
    inputargs = [v1, v2, v3, v4, v5, v6, v7, v8, v9, v10]
    operations = [
        ResOperation(rop.UINT_GT, [v3, ConstInt(-48)], v11),
        ResOperation(rop.INT_XOR, [v8, v1], v12),
        ResOperation(rop.INT_GT, [v6, ConstInt(-9)], v13),
        ResOperation(rop.INT_LE, [v13, v2], v14),
        ResOperation(rop.INT_LE, [v11, v5], v15),
        ResOperation(rop.UINT_GE, [v13, v13], v16),
        ResOperation(rop.INT_OR, [v9, ConstInt(-23)], v17),
        ResOperation(rop.INT_LT, [v10, v13], v18),
        ResOperation(rop.INT_OR, [v15, v5], v19),
        ResOperation(rop.INT_XOR, [v17, ConstInt(54)], v20),
        ResOperation(rop.INT_MUL, [v8, v10], v21),
        ResOperation(rop.INT_OR, [v3, v9], v22),
        ResOperation(rop.INT_AND, [v11, ConstInt(-4)], tmp41),
        ResOperation(rop.INT_OR, [tmp41, ConstInt(1)], tmp42),
        ResOperation(rop.INT_MOD, [v12, tmp42], v23),
        ResOperation(rop.INT_IS_TRUE, [v6], v24),
        ResOperation(rop.UINT_RSHIFT, [v15, ConstInt(6)], v25),
        ResOperation(rop.INT_OR, [ConstInt(-4), v25], v26),
        ResOperation(rop.INT_INVERT, [v8], v27),
        ResOperation(rop.INT_SUB, [ConstInt(-113), v11], v28),
        ResOperation(rop.INT_NEG, [v7], v29),
        ResOperation(rop.INT_NEG, [v24], v30),
        ResOperation(rop.INT_FLOORDIV, [v3, ConstInt(53)], v31),
        ResOperation(rop.INT_MUL, [v28, v27], v32),
        ResOperation(rop.INT_AND, [v18, ConstInt(-4)], tmp43),
        ResOperation(rop.INT_OR, [tmp43, ConstInt(1)], tmp44),
        ResOperation(rop.INT_MOD, [v26, tmp44], v33),
        ResOperation(rop.INT_OR, [v27, v19], v34),
        ResOperation(rop.UINT_LT, [v13, ConstInt(1)], v35),
        ResOperation(rop.INT_AND, [v21, ConstInt(31)], tmp45),
        ResOperation(rop.INT_RSHIFT, [v21, tmp45], v36),
        ResOperation(rop.INT_AND, [v20, ConstInt(31)], tmp46),
        ResOperation(rop.UINT_RSHIFT, [v4, tmp46], v37),
        ResOperation(rop.UINT_GT, [v33, ConstInt(-11)], v38),
        ResOperation(rop.INT_NEG, [v7], v39),
        ResOperation(rop.INT_GT, [v24, v32], v40),
        ResOperation(rop.GUARD_FALSE, [v1], None, descr=BasicFailDescr()),
    ]
    operations[-1].setfailargs(
        [v40, v36, v37, v31, v16, v34, v35, v23, v22, v29, v14, v39, v30, v38])
    cpu = CPU(None, None)
    cpu.setup_once()
    looptoken = JitCellToken()
    cpu.compile_loop(inputargs, operations, looptoken)
    args = [-13, 10, 10, 8, -8, -16, -18, 46, -12, 26]
    deadframe = cpu.execute_token(looptoken, *args)
    assert cpu.get_int_value(deadframe, 0) == 0
    assert cpu.get_int_value(deadframe, 1) == 0
    assert cpu.get_int_value(deadframe, 2) == 0
    assert cpu.get_int_value(deadframe, 3) == 0
    assert cpu.get_int_value(deadframe, 4) == 1
    assert cpu.get_int_value(deadframe, 5) == -7
    assert cpu.get_int_value(deadframe, 6) == 1
    assert cpu.get_int_value(deadframe, 7) == 0
    assert cpu.get_int_value(deadframe, 8) == -2
    assert cpu.get_int_value(deadframe, 9) == 18
    assert cpu.get_int_value(deadframe, 10) == 1
    assert cpu.get_int_value(deadframe, 11) == 18
    assert cpu.get_int_value(deadframe, 12) == -1
    assert cpu.get_int_value(deadframe, 13) == 0
Пример #23
0
def test_bug_1():
    v1 = BoxInt()
    v2 = BoxInt()
    v3 = BoxInt()
    v4 = BoxInt()
    v5 = BoxInt()
    v6 = BoxInt()
    v7 = BoxInt()
    v8 = BoxInt()
    v9 = BoxInt()
    v10 = BoxInt()
    v11 = BoxInt()
    v12 = BoxInt()
    v13 = BoxInt()
    v14 = BoxInt()
    v15 = BoxInt()
    v16 = BoxInt()
    v17 = BoxInt()
    v18 = BoxInt()
    v19 = BoxInt()
    v20 = BoxInt()
    v21 = BoxInt()
    v22 = BoxInt()
    v23 = BoxInt()
    v24 = BoxInt()
    v25 = BoxInt()
    v26 = BoxInt()
    v27 = BoxInt()
    v28 = BoxInt()
    v29 = BoxInt()
    v30 = BoxInt()
    v31 = BoxInt()
    v32 = BoxInt()
    v33 = BoxInt()
    v34 = BoxInt()
    v35 = BoxInt()
    v36 = BoxInt()
    v37 = BoxInt()
    v38 = BoxInt()
    v39 = BoxInt()
    v40 = BoxInt()
    tmp41 = BoxInt()
    tmp42 = BoxInt()
    tmp43 = BoxInt()
    tmp44 = BoxInt()
    tmp45 = BoxInt()
    inputargs = [v1, v2, v3, v4, v5, v6, v7, v8, v9, v10]
    operations = [
        ResOperation(rop.UINT_LT, [v6, ConstInt(0)], v11),
        ResOperation(rop.INT_AND, [v3, ConstInt(31)], tmp41),
        ResOperation(rop.INT_RSHIFT, [v3, tmp41], v12),
        ResOperation(rop.INT_NEG, [v2], v13),
        ResOperation(rop.INT_ADD, [v11, v7], v14),
        ResOperation(rop.INT_OR, [v3, v2], v15),
        ResOperation(rop.INT_OR, [v12, v12], v16),
        ResOperation(rop.INT_NE, [v2, v5], v17),
        ResOperation(rop.INT_AND, [v5, ConstInt(31)], tmp42),
        ResOperation(rop.UINT_RSHIFT, [v14, tmp42], v18),
        ResOperation(rop.INT_AND, [v14, ConstInt(31)], tmp43),
        ResOperation(rop.INT_LSHIFT, [ConstInt(7), tmp43], v19),
        ResOperation(rop.INT_NEG, [v19], v20),
        ResOperation(rop.INT_MOD, [v3, ConstInt(1)], v21),
        ResOperation(rop.UINT_GE, [v15, v1], v22),
        ResOperation(rop.INT_AND, [v16, ConstInt(31)], tmp44),
        ResOperation(rop.INT_LSHIFT, [v8, tmp44], v23),
        ResOperation(rop.INT_IS_TRUE, [v17], v24),
        ResOperation(rop.INT_AND, [v5, ConstInt(31)], tmp45),
        ResOperation(rop.INT_LSHIFT, [v14, tmp45], v25),
        ResOperation(rop.INT_LSHIFT, [v5, ConstInt(17)], v26),
        ResOperation(rop.INT_EQ, [v9, v15], v27),
        ResOperation(rop.INT_GE, [ConstInt(0), v6], v28),
        ResOperation(rop.INT_NEG, [v15], v29),
        ResOperation(rop.INT_NEG, [v22], v30),
        ResOperation(rop.INT_ADD, [v7, v16], v31),
        ResOperation(rop.UINT_LT, [v19, v19], v32),
        ResOperation(rop.INT_ADD, [v2, ConstInt(1)], v33),
        ResOperation(rop.INT_NEG, [v5], v34),
        ResOperation(rop.INT_ADD, [v17, v24], v35),
        ResOperation(rop.UINT_LT, [ConstInt(2), v16], v36),
        ResOperation(rop.INT_NEG, [v9], v37),
        ResOperation(rop.INT_GT, [v4, v11], v38),
        ResOperation(rop.INT_LT, [v27, v22], v39),
        ResOperation(rop.INT_NEG, [v27], v40),
        ResOperation(rop.GUARD_FALSE, [v1], None, descr=BasicFailDescr()),
    ]
    operations[-1].setfailargs([
        v40, v10, v36, v26, v13, v30, v21, v33, v18, v25, v31, v32, v28, v29,
        v35, v38, v20, v39, v34, v23, v37
    ])
    cpu = CPU(None, None)
    cpu.setup_once()
    looptoken = JitCellToken()
    cpu.compile_loop(inputargs, operations, looptoken)
    args = [17, -20, -6, 6, 1, 13, 13, 9, 49, 8]
    deadframe = cpu.execute_token(looptoken, *args)
    assert cpu.get_int_value(deadframe, 0) == 0
    assert cpu.get_int_value(deadframe, 1) == 8
    assert cpu.get_int_value(deadframe, 2) == 1
    assert cpu.get_int_value(deadframe, 3) == 131072
    assert cpu.get_int_value(deadframe, 4) == 20
    assert cpu.get_int_value(deadframe, 5) == -1
    assert cpu.get_int_value(deadframe, 6) == 0
    assert cpu.get_int_value(deadframe, 7) == -19
    assert cpu.get_int_value(deadframe, 8) == 6
    assert cpu.get_int_value(deadframe, 9) == 26
    assert cpu.get_int_value(deadframe, 10) == 12
    assert cpu.get_int_value(deadframe, 11) == 0
    assert cpu.get_int_value(deadframe, 12) == 0
    assert cpu.get_int_value(deadframe, 13) == 2
    assert cpu.get_int_value(deadframe, 14) == 2
    assert cpu.get_int_value(deadframe, 15) == 1
    assert cpu.get_int_value(deadframe, 16) == -57344
    assert cpu.get_int_value(deadframe, 17) == 1
    assert cpu.get_int_value(deadframe, 18) == -1
    if WORD == 4:
        assert cpu.get_int_value(deadframe, 19) == -2147483648
    elif WORD == 8:
        assert cpu.get_int_value(deadframe, 19) == 19327352832
    assert cpu.get_int_value(deadframe, 20) == -49
Пример #24
0
def test_bug_2():
    cpu = CPU(None, None)
    cpu.setup_once()

    S4 = lltype.Struct('Sx', ("f0", lltype.Char), ("f1", lltype.Signed),
                       ("f2", lltype.Signed), ("f3", lltype.Signed))
    S5 = lltype.GcArray(S4)
    v1 = BoxInt()
    v2 = BoxInt()
    v3 = BoxInt()
    v4 = BoxInt()
    v5 = BoxInt()
    v6 = BoxInt()
    v7 = BoxInt()
    v8 = BoxInt()
    v9 = BoxInt()
    v10 = BoxInt()
    tmp11 = BoxInt()
    tmp12 = BoxPtr()
    faildescr0 = BasicFailDescr()
    tmp13 = BoxPtr()
    faildescr1 = BasicFailDescr()
    finishdescr2 = BasicFinalDescr()
    const_ptr14 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.STR, 1)))
    const_ptr15 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF,
                               lltype.malloc(rstr.UNICODE, 489)))
    const_ptr16 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.UNICODE,
                                                             16)))
    const_ptr17 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S5, 299)))
    inputargs = [v1, v2, v3, v4, v5, v6, v7, v8, v9, v10]

    xtp, func, funcdescr = getexception(cpu, 3)
    xtp2, func2, func2descr = getexception(cpu, 2)

    operations = [
        ResOperation(rop.STRGETITEM, [const_ptr14, ConstInt(0)], tmp11),
        ResOperation(rop.LABEL,
                     [v1, v2, tmp11, v3, v4, v5, v6, v7, v8, v9, v10], None,
                     TargetToken()),
        ResOperation(rop.UNICODESETITEM,
                     [const_ptr15, v4, ConstInt(22)], None),
        ResOperation(rop.CALL, [ConstInt(func), v2, v1, v9],
                     None,
                     descr=funcdescr),
        ResOperation(rop.GUARD_EXCEPTION, [ConstInt(xtp)],
                     tmp12,
                     descr=faildescr0),
        ResOperation(
            rop.UNICODESETITEM,
            [const_ptr16, ConstInt(13), ConstInt(9)], None),
        ResOperation(rop.SETINTERIORFIELD_GC, [const_ptr17, v3, v7], None,
                     cpu.interiorfielddescrof(S5, 'f3')),
        ResOperation(rop.CALL, [ConstInt(func2), v7, v10],
                     None,
                     descr=func2descr),
        ResOperation(rop.GUARD_NO_EXCEPTION, [], tmp13, descr=faildescr1),
        ResOperation(rop.FINISH, [], None, descr=finishdescr2),
    ]
    operations[4].setfailargs([v4, v8, v10, v2, v9, v7, v6, v1])
    operations[8].setfailargs([v3, v9, v2, v6, v4])
    looptoken = JitCellToken()
    cpu.compile_loop(inputargs, operations, looptoken)
    loop_args = [1, -39, 46, 21, 16, 6, -4611686018427387905, 12, 14, 2]
    frame = cpu.execute_token(looptoken, *loop_args)
    assert cpu.get_int_value(frame, 0) == 46
    assert cpu.get_int_value(frame, 1) == 14
    assert cpu.get_int_value(frame, 2) == -39
    assert cpu.get_int_value(frame, 3) == 6
    assert cpu.get_int_value(frame, 4) == 21
    S4 = lltype.GcStruct('Sx', ("parent", rclass.OBJECT),
                         ("f0", lltype.Signed))
    S5 = lltype.GcStruct('Sx', ("f0", lltype.Signed))
    S6 = lltype.GcArray(lltype.Signed)
    S7 = lltype.GcStruct('Sx', ("parent", rclass.OBJECT), ("f0", lltype.Char))
    S8 = lltype.Struct('Sx', ("f0", lltype.Char), ("f1", lltype.Signed),
                       ("f2", lltype.Signed), ("f3", lltype.Signed))
    S9 = lltype.GcArray(S8)
    v1 = BoxInt()
    v2 = BoxInt()
    v3 = BoxInt()
    v4 = BoxInt()
    v5 = BoxInt()
    v6 = BoxInt()
    v7 = BoxInt()
    v8 = BoxInt()
    v9 = BoxInt()
    v10 = BoxInt()
    v11 = BoxInt()
    v12 = BoxInt()
    v13 = BoxInt()
    v14 = BoxInt()
    v15 = BoxInt()
    v16 = BoxInt()
    v17 = BoxInt()
    v18 = BoxInt()
    v19 = BoxInt()
    p20 = BoxPtr()
    tmp21 = BoxPtr()
    faildescr3 = BasicFailDescr()
    tmp22 = BoxPtr()
    faildescr4 = BasicFailDescr()
    tmp23 = BoxInt()
    tmp24 = BoxInt()
    tmp25 = BoxInt()
    tmp26 = BoxInt()
    tmp27 = BoxInt()
    tmp28 = BoxInt()
    tmp29 = BoxInt()
    faildescr5 = BasicFailDescr()
    tmp30 = BoxPtr()
    faildescr6 = BasicFailDescr()
    finishdescr7 = BasicFinalDescr()
    const_ptr31 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S4)))
    const_ptr32 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.STR, 46)))
    const_ptr33 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S5)))
    const_ptr34 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.UNICODE,
                                                             26)))
    const_ptr35 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.UNICODE,
                                                             15)))
    const_ptr36 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S7)))
    const_ptr37 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.STR, 484)))
    const_ptr38 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S9, 299)))
    inputargs = [v1, v2, v3, v4, v5]

    func3, func3descr = getnoexception(cpu, 5)
    xtp3, func4, func4descr = getexception(cpu, 10)

    operations = [
        ResOperation(rop.GUARD_EXCEPTION, [ConstInt(xtp2)],
                     tmp21,
                     descr=faildescr3),
        ResOperation(rop.INT_IS_ZERO, [v4], v6),
        ResOperation(rop.INT_NE, [v6, ConstInt(13)], v7),
        ResOperation(rop.GETFIELD_GC, [const_ptr31], v8,
                     cpu.fielddescrof(S4, 'f0')),
        ResOperation(rop.STRSETITEM,
                     [const_ptr32, v6, ConstInt(0)], None),
        ResOperation(rop.NEWSTR, [ConstInt(5)], tmp22),
        ResOperation(rop.STRSETITEM,
                     [tmp22, ConstInt(0), ConstInt(42)], None),
        ResOperation(rop.STRSETITEM,
                     [tmp22, ConstInt(1), ConstInt(42)], None),
        ResOperation(rop.STRSETITEM,
                     [tmp22, ConstInt(2), ConstInt(20)], None),
        ResOperation(rop.STRSETITEM,
                     [tmp22, ConstInt(3), ConstInt(48)], None),
        ResOperation(rop.STRSETITEM,
                     [tmp22, ConstInt(4), ConstInt(6)], None),
        ResOperation(rop.GETFIELD_GC, [const_ptr33], v9,
                     cpu.fielddescrof(S5, 'f0')),
        ResOperation(rop.UNICODESETITEM,
                     [const_ptr34, ConstInt(24),
                      ConstInt(65533)], None),
        ResOperation(rop.GETFIELD_GC, [const_ptr31], v10,
                     cpu.fielddescrof(S4, 'f0')),
        ResOperation(rop.INT_NE, [v10, ConstInt(25)], v11),
        ResOperation(rop.CALL, [ConstInt(func3), v5, v1, v8, v3, v2],
                     v12,
                     descr=func3descr),
        ResOperation(rop.GUARD_NO_EXCEPTION, [], None, descr=faildescr4),
        ResOperation(rop.UNICODELEN, [const_ptr35], tmp23),
        ResOperation(rop.NEW_ARRAY, [v2], p20, cpu.arraydescrof(S6)),
        ResOperation(rop.GETFIELD_GC, [const_ptr36], v13,
                     cpu.fielddescrof(S7, 'f0')),
        ResOperation(rop.INT_OR, [v8, ConstInt(2)], tmp24),
        ResOperation(rop.INT_FLOORDIV, [ConstInt(8), tmp24], v14),
        ResOperation(rop.GETARRAYITEM_GC, [p20, ConstInt(3)], v15,
                     cpu.arraydescrof(S6)),
        ResOperation(
            rop.COPYSTRCONTENT,
            [tmp22, const_ptr37,
             ConstInt(1),
             ConstInt(163),
             ConstInt(0)], None),
        ResOperation(rop.COPYUNICODECONTENT,
                     [const_ptr35, const_ptr34,
                      ConstInt(13),
                      ConstInt(0), v6], None),
        ResOperation(rop.STRGETITEM, [tmp22, v6], tmp25),
        ResOperation(rop.STRGETITEM, [tmp22, ConstInt(0)], tmp26),
        ResOperation(rop.GETINTERIORFIELD_GC, [const_ptr38, v13], v16,
                     cpu.interiorfielddescrof(S9, 'f0')),
        ResOperation(rop.INT_GE, [v4, v5], v17),
        ResOperation(rop.INT_OR, [v13, ConstInt(2)], tmp27),
        ResOperation(rop.INT_FLOORDIV, [ConstInt(12), tmp27], v18),
        ResOperation(rop.INT_AND, [v1, ConstInt(-4)], tmp28),
        ResOperation(rop.INT_OR, [tmp28, ConstInt(2)], tmp29),
        ResOperation(rop.INT_FLOORDIV, [v15, tmp29], v19),
        ResOperation(rop.GUARD_FALSE, [v17], None, descr=faildescr5),
        ResOperation(rop.UNICODESETITEM,
                     [const_ptr34, ConstInt(20),
                      ConstInt(65522)], None),
        ResOperation(
            rop.CALL,
            [ConstInt(func4), v3, v9, v10, v8, v11, v5, v13, v14, v15, v6],
            None,
            descr=func4descr),
        ResOperation(rop.GUARD_NO_EXCEPTION, [], tmp30, descr=faildescr6),
        ResOperation(rop.FINISH, [], None, descr=finishdescr7),
    ]
    operations[0].setfailargs([])
    operations[16].setfailargs([v5, v9])
    operations[34].setfailargs([])
    operations[37].setfailargs([v12, v19, v10, v7, v4, v8, v18, v15, v9])
    cpu.compile_bridge(faildescr1, inputargs, operations, looptoken)
    frame = cpu.execute_token(looptoken, *loop_args)
    #assert cpu.get_int_value(frame, 0) == -9223372036854775766
    assert cpu.get_int_value(frame, 1) == 0
    #assert cpu.get_int_value(frame, 2) == -9223372036854775808
    assert cpu.get_int_value(frame, 3) == 1
    assert cpu.get_int_value(frame, 4) == 6
    #assert cpu.get_int_value(frame, 5) == -9223372036854775808
    assert cpu.get_int_value(frame, 6) == 0
    assert cpu.get_int_value(frame, 7) == 0
    #assert cpu.get_int_value(frame, 8) == 26
    S4 = lltype.GcStruct('Sx', ("parent", rclass.OBJECT),
                         ("f0", lltype.Signed), ("f1", lltype.Signed))
    S5 = lltype.GcStruct('Sx', ("parent", rclass.OBJECT),
                         ("f0", lltype.Signed))
    S6 = lltype.GcStruct('Sx', ("f0", lltype.Signed), ("f1", rffi.UCHAR))
    v1 = BoxInt()
    v2 = BoxInt()
    v3 = BoxInt()
    v4 = BoxInt()
    v5 = BoxInt()
    v6 = BoxInt()
    v7 = BoxInt()
    v8 = BoxInt()
    v9 = BoxInt()
    v10 = BoxInt()
    v11 = BoxInt()
    v12 = BoxInt()
    v13 = BoxInt()
    v14 = BoxInt()
    v15 = BoxInt()
    v16 = BoxInt()
    v17 = BoxInt()
    v18 = BoxInt()
    tmp19 = BoxPtr()
    faildescr8 = BasicFailDescr()
    tmp20 = BoxInt()
    tmp21 = BoxInt()
    tmp22 = BoxInt()
    tmp23 = BoxInt()
    faildescr9 = BasicFailDescr()
    tmp24 = BoxInt()
    tmp25 = BoxInt()
    tmp26 = BoxInt()
    tmp27 = BoxPtr()
    tmp28 = BoxPtr()
    faildescr10 = BasicFailDescr()
    finishdescr11 = BasicFinalDescr()
    const_ptr29 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S4)))
    const_ptr30 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.UNICODE,
                                                             26)))
    const_ptr31 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.UNICODE, 1)))
    const_ptr32 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S5)))
    const_ptr33 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S6)))
    const_ptr34 = ConstPtr(
        lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.STR, 26)))
    inputargs = [v1, v2, v3, v4, v5, v6, v7, v8, v9]
    operations = [
        ResOperation(rop.GUARD_EXCEPTION, [ConstInt(xtp3)],
                     tmp19,
                     descr=faildescr8),
        ResOperation(rop.SETFIELD_GC, [const_ptr29, v7], None,
                     cpu.fielddescrof(S4, 'f0')),
        ResOperation(rop.UNICODEGETITEM,
                     [const_ptr30, ConstInt(21)], tmp20),
        ResOperation(rop.UNICODEGETITEM,
                     [const_ptr30, ConstInt(10)], tmp21),
        ResOperation(rop.UINT_RSHIFT, [v9, ConstInt(40)], v10),
        ResOperation(rop.UNICODEGETITEM,
                     [const_ptr30, ConstInt(25)], tmp22),
        ResOperation(rop.INT_NE, [ConstInt(-8), v9], v11),
        ResOperation(rop.INT_MUL_OVF, [v3, ConstInt(-4)], tmp23),
        ResOperation(rop.GUARD_OVERFLOW, [], None, descr=faildescr9),
        ResOperation(rop.UNICODESETITEM,
                     [const_ptr31, ConstInt(0),
                      ConstInt(50175)], None),
        ResOperation(rop.UINT_GT, [v8, ConstInt(-6)], v12),
        ResOperation(rop.GETFIELD_GC, [const_ptr32], v13,
                     cpu.fielddescrof(S5, 'f0')),
        ResOperation(rop.INT_AND, [ConstInt(8), v8], v14),
        ResOperation(rop.INT_INVERT, [v1], v15),
        ResOperation(rop.SETFIELD_GC, [const_ptr33, ConstInt(3)], None,
                     cpu.fielddescrof(S6, 'f1')),
        ResOperation(rop.INT_GE, [v14, v6], v16),
        ResOperation(rop.INT_AND, [v5, ConstInt(-4)], tmp24),
        ResOperation(rop.INT_OR, [tmp24, ConstInt(2)], tmp25),
        ResOperation(rop.INT_FLOORDIV, [v9, tmp25], v17),
        ResOperation(rop.STRLEN, [const_ptr34], tmp26),
        ResOperation(rop.NEWSTR, [ConstInt(7)], tmp27),
        ResOperation(rop.STRSETITEM,
                     [tmp27, ConstInt(0), ConstInt(21)], None),
        ResOperation(rop.STRSETITEM,
                     [tmp27, ConstInt(1), ConstInt(79)], None),
        ResOperation(rop.STRSETITEM,
                     [tmp27, ConstInt(2), ConstInt(7)], None),
        ResOperation(rop.STRSETITEM,
                     [tmp27, ConstInt(3), ConstInt(2)], None),
        ResOperation(rop.STRSETITEM,
                     [tmp27, ConstInt(4), ConstInt(229)], None),
        ResOperation(rop.STRSETITEM,
                     [tmp27, ConstInt(5), ConstInt(233)], None),
        ResOperation(rop.STRSETITEM,
                     [tmp27, ConstInt(6), ConstInt(208)], None),
        ResOperation(rop.INT_LT, [ConstInt(-31), v10], v18),
        ResOperation(rop.SAME_AS,
                     [ConstPtr(lltype.nullptr(llmemory.GCREF.TO))], tmp28),
        ResOperation(rop.GUARD_NONNULL_CLASS, [tmp28, ConstInt(xtp2)],
                     None,
                     descr=faildescr10),
        ResOperation(rop.FINISH, [v4], None, descr=finishdescr11),
    ]
    operations[0].setfailargs([])
    operations[8].setfailargs([tmp23, v5, v3, v11, v6])
    operations[30].setfailargs([v6])
    cpu.compile_bridge(faildescr6, inputargs, operations, looptoken)
    frame = cpu.execute_token(looptoken, *loop_args)
    #assert cpu.get_int_value(frame, 0) == -9223372036854775808
    v1 = BoxInt()
    v2 = BoxInt()
    p3 = BoxPtr()
    tmp4 = BoxInt()
    tmp5 = BoxPtr()
    faildescr12 = BasicFailDescr()
    finishdescr13 = BasicFinalDescr()
    inputargs = [v1]

    _, func5, func5descr = getexception(cpu, 0)
    vt = getvtable(cpu, S4)

    operations = [
        ResOperation(rop.INT_AND, [v1, ConstInt(63)], tmp4),
        ResOperation(rop.INT_LSHIFT, [ConstInt(10), tmp4], v2),
        ResOperation(rop.NEW_WITH_VTABLE, [ConstInt(vt)], p3),
        ResOperation(rop.CALL, [ConstInt(func5)], None, descr=func5descr),
        ResOperation(rop.GUARD_EXCEPTION, [ConstInt(xtp2)],
                     tmp5,
                     descr=faildescr12),
        ResOperation(rop.FINISH, [], None, descr=finishdescr13),
    ]
    operations[4].setfailargs([v2])
    cpu.compile_bridge(faildescr10, inputargs, operations, looptoken)
    frame = cpu.execute_token(looptoken, *loop_args)
Пример #25
0
    def test_calling_convention(self, monkeypatch):
        if WORD != 4:
            py.test.skip("32-bit only test")
        from rpython.jit.backend.x86.regloc import eax, edx
        from rpython.jit.backend.x86 import codebuf, callbuilder
        from rpython.jit.codewriter.effectinfo import EffectInfo
        from rpython.rlib.libffi import types, clibffi
        had_stdcall = hasattr(clibffi, 'FFI_STDCALL')
        if not had_stdcall:  # not running on Windows, but we can still test
            monkeypatch.setattr(clibffi, 'FFI_STDCALL', 12345, raising=False)
            monkeypatch.setattr(callbuilder, 'stdcall_or_cdecl', True)
        else:
            assert callbuilder.stdcall_or_cdecl
        #
        for real_ffi, reported_ffi in [
            (clibffi.FFI_DEFAULT_ABI, clibffi.FFI_DEFAULT_ABI),
            (clibffi.FFI_STDCALL, clibffi.FFI_DEFAULT_ABI),
            (clibffi.FFI_STDCALL, clibffi.FFI_STDCALL)
        ]:
            cpu = self.cpu
            mc = codebuf.MachineCodeBlockWrapper()
            mc.MOV_rs(eax.value, 4)  # argument 1
            mc.MOV_rs(edx.value, 40)  # argument 10
            mc.SUB_rr(eax.value, edx.value)  # return arg1 - arg10
            if real_ffi == clibffi.FFI_DEFAULT_ABI:
                mc.RET()
            else:
                mc.RET16_i(40)
            rawstart = mc.materialize(cpu, [])
            #
            calldescr = cpu._calldescr_dynamic_for_tests([types.slong] * 10,
                                                         types.slong)
            calldescr.get_call_conv = lambda: reported_ffi  # <==== hack
            # ^^^ we patch get_call_conv() so that the test also makes sense
            #     on Linux, because clibffi.get_call_conv() would always
            #     return FFI_DEFAULT_ABI on non-Windows platforms.
            funcbox = ConstInt(rawstart)
            i1 = InputArgInt()
            i2 = InputArgInt()
            c = ConstInt(-1)
            faildescr = BasicFailDescr(1)
            cz = ConstInt(0)
            # we must call it repeatedly: if the stack pointer gets increased
            # by 40 bytes by the STDCALL call, and if we don't expect it,
            # then we are going to get our stack emptied unexpectedly by
            # several repeated calls
            ops = [
                ResOperation(rop.CALL_RELEASE_GIL_I,
                             [cz, funcbox, i1, c, c, c, c, c, c, c, c, i2],
                             descr=calldescr),
                ResOperation(rop.GUARD_NOT_FORCED, [], descr=faildescr),
                ResOperation(rop.CALL_RELEASE_GIL_I,
                             [cz, funcbox, i1, c, c, c, c, c, c, c, c, i2],
                             descr=calldescr),
                ResOperation(rop.GUARD_NOT_FORCED, [], descr=faildescr),
                ResOperation(rop.CALL_RELEASE_GIL_I,
                             [cz, funcbox, i1, c, c, c, c, c, c, c, c, i2],
                             descr=calldescr),
                ResOperation(rop.GUARD_NOT_FORCED, [], descr=faildescr),
                ResOperation(rop.CALL_RELEASE_GIL_I,
                             [cz, funcbox, i1, c, c, c, c, c, c, c, c, i2],
                             descr=calldescr),
                ResOperation(rop.GUARD_NOT_FORCED, [], descr=faildescr),
            ]
            i3 = ops[0]
            i4 = ops[2]
            i5 = ops[4]
            i6 = ops[6]

            ops += [
                ResOperation(rop.GUARD_FALSE, [i3], descr=BasicFailDescr(0)),
                ResOperation(rop.FINISH, [], descr=BasicFinalDescr(1))
            ]
            ops[-2].setfailargs([i3, i4, i5, i6])
            ops[1].setfailargs([])
            ops[3].setfailargs([])
            ops[5].setfailargs([])
            ops[7].setfailargs([])
            looptoken = JitCellToken()
            self.cpu.compile_loop([i1, i2], ops, looptoken)

            deadframe = self.cpu.execute_token(looptoken, 123450, 123408)
            fail = self.cpu.get_latest_descr(deadframe)
            assert fail.identifier == 0
            assert self.cpu.get_int_value(deadframe, 0) == 42
            assert self.cpu.get_int_value(deadframe, 1) == 42
            assert self.cpu.get_int_value(deadframe, 2) == 42
            assert self.cpu.get_int_value(deadframe, 3) == 42
Пример #26
0
    def g():
        cpu.setup_once()
        token1 = JitCellToken()
        token1a = JitCellToken()
        token2 = JitCellToken()
        token3 = JitCellToken()
        token4 = JitCellToken()
        cpu.compile_loop(loop1.inputargs, loop1.operations, token1)
        cpu.compile_loop(loop1a.inputargs, loop1a.operations, token1a)
        cpu.compile_loop(loop2.inputargs, loop2.operations, token2)
        cpu.compile_loop(loop3.inputargs, loop3.operations, token3)
        cpu.compile_loop(loop4.inputargs, loop4.operations, token4)

        for token, p0 in [
            (token1, rffi.cast(llmemory.GCREF, A())),
            (token1, rffi.cast(llmemory.GCREF, B())),
            (token1, rffi.cast(llmemory.GCREF, C())),
            (token1a, rffi.cast(llmemory.GCREF, A())),
            (token1a, lltype.nullptr(llmemory.GCREF.TO)),
            (token1a, rffi.cast(llmemory.GCREF, B())),
            (token1a, rffi.cast(llmemory.GCREF, C())),
            (token2, rffi.cast(llmemory.GCREF, A())),
            (token2, rffi.cast(llmemory.GCREF, B())),
            (token2, rffi.cast(llmemory.GCREF, C())),
            (token2, rffi.cast(llmemory.GCREF, [42, 43])),
            (token3, rffi.cast(llmemory.GCREF, A())),
            (token3, rffi.cast(llmemory.GCREF, B())),
            (token3, rffi.cast(llmemory.GCREF, [44, 45])),
            (token4, rffi.cast(llmemory.GCREF, A())),
            (token4, rffi.cast(llmemory.GCREF, B())),
            (token4, rffi.cast(llmemory.GCREF, C())),
        ]:
            frame = execute_token(token, p0)
            descr = cpu.get_latest_descr(frame)
            if descr is finaldescr:
                print 'match'
            elif descr is faildescr:
                print 'fail'
            else:
                print '???'
            #
            if token is token2:  # guard_gc_type
                print int(cpu.get_actual_typeid(p0) == typeid_B)
            if token is token3:  # guard_is_object
                print int(cpu.check_is_object(p0))

        for p0 in [
                lltype.nullptr(llmemory.GCREF.TO),
                rffi.cast(llmemory.GCREF, A()),
                rffi.cast(llmemory.GCREF, B()),
                rffi.cast(llmemory.GCREF, C()),
                rffi.cast(llmemory.GCREF, lltype.malloc(LLD)),
                rffi.cast(llmemory.GCREF, lltype.malloc(ARRAY, 5)),
                rffi.cast(llmemory.GCREF, "foobar"),
                rffi.cast(llmemory.GCREF, u"foobaz")
        ]:
            results = ['B', 'D', 'A', 'S', 'U']
            try:
                cpu.protect_speculative_field(p0, fielddescr_B)
            except SpeculativeError:
                results[0] = '-'
            try:
                cpu.protect_speculative_field(p0, fielddescr_D)
            except SpeculativeError:
                results[1] = '-'
            try:
                cpu.protect_speculative_array(p0, arraydescr)
            except SpeculativeError:
                results[2] = '-'
            try:
                cpu.protect_speculative_string(p0)
            except SpeculativeError:
                results[3] = '-'
            try:
                cpu.protect_speculative_unicode(p0)
            except SpeculativeError:
                results[4] = '-'
            print ''.join(results)
Пример #27
0
 def test_wrong_guard3(self):
     # random seed: 8029
     # block length: 10
     faildescr1 = BasicFailDescr(1)
     faildescr2 = BasicFailDescr(2)
     faildescr3 = BasicFailDescr(3)
     faildescr4 = BasicFailDescr(4)
     v1 = BoxInt()
     v2 = BoxInt()
     v3 = BoxInt()
     v4 = BoxInt()
     v5 = BoxInt()
     v6 = BoxInt()
     v7 = BoxInt()
     v8 = BoxInt()
     v9 = BoxInt()
     v10 = BoxInt()
     v11 = BoxInt()
     v12 = BoxInt()
     v13 = BoxInt()
     v14 = BoxInt()
     v15 = BoxInt()
     v16 = BoxInt()
     cpu = CPU(None, None)
     cpu.setup_once()
     inputargs = [v1, v2, v3, v4, v5, v6, v7, v8, v9, v10]
     operations = [
         ResOperation(rop.UINT_LT, [ConstInt(-11), v7], v11),
         ResOperation(rop.INT_GE, [v3, v5], v12),
         ResOperation(rop.INT_INVERT, [v9], v13),
         ResOperation(rop.GUARD_VALUE, [v13, ConstInt(14)],
                      None,
                      descr=faildescr3),
         ResOperation(rop.INT_IS_ZERO, [v12], v14),
         ResOperation(rop.INT_SUB, [v2, v13], v15),
         ResOperation(rop.GUARD_VALUE, [v15, ConstInt(-32)],
                      None,
                      descr=faildescr4),
         ResOperation(rop.INT_FLOORDIV, [v3, ConstInt(805306366)], v16),
         ResOperation(rop.GUARD_VALUE, [v15, ConstInt(0)],
                      None,
                      descr=faildescr1),
         ResOperation(rop.GUARD_FALSE, [v1], None, descr=faildescr2),
     ]
     operations[3].setfailargs([])
     operations[-4].setfailargs([v15])
     operations[-2].setfailargs([v9, v4, v10, v11, v14])
     operations[-1].setfailargs([v10, v8, v1, v6, v4])
     looptoken = JitCellToken()
     cpu.compile_loop(inputargs, operations, looptoken)
     args = [
         -39, -18, 1588243114, -9, -4, 1252698794, 0, 715827882, -15,
         536870912
     ]
     deadframe = cpu.execute_token(looptoken, *args)
     assert cpu.get_latest_descr(deadframe).identifier == 1
     assert cpu.get_int_value(deadframe, 0) == -15
     assert cpu.get_int_value(deadframe, 1) == -9
     assert cpu.get_int_value(deadframe, 2) == 536870912
     assert cpu.get_int_value(deadframe, 3) == 0
     assert cpu.get_int_value(deadframe, 4) == 0