def __init__(self, cpu): self.cpu = cpu self.profiler = EmptyProfiler() self.options = Fake() self.globaldata = Fake() self.config = get_combined_translation_config(translating=True) self.jitlog = jl.JitLogger()
def test_debug_merge_point(self, tmpdir, metainterp_sd): logger = jl.JitLogger() file = tmpdir.join('binary_file') file.ensure() fd = file.open('wb') jl.jitlog_init(fd.fileno()) logger.start_new_trace(metainterp_sd, jd_name='jdname') log_trace = logger.log_trace(jl.MARK_TRACE, None, None) op = ResOperation(rop.DEBUG_MERGE_POINT, [ConstInt(0), ConstInt(0), ConstInt(0)]) log_trace.write([], [op]) #the next line will close 'fd', instead of logger.finish() fd.close() binary = file.read() is_32bit = chr(sys.maxint == 2**31-1) assert binary == (jl.MARK_START_TRACE) + jl.encode_le_addr(1) + \ jl.encode_str('loop') + jl.encode_le_addr(0) + \ jl.encode_str('jdname') + \ (jl.MARK_TRACE) + jl.encode_le_addr(1) + \ (jl.MARK_INPUT_ARGS) + jl.encode_str('') + \ (jl.MARK_INIT_MERGE_POINT) + b'\x05\x00\x01s\x00i\x08s\x00i\x10s' + \ (jl.MARK_MERGE_POINT) + \ b'\xff' + jl.encode_str('/home/pypy/jit.py') + \ b'\x00' + jl.encode_le_64bit(0) + \ b'\xff' + jl.encode_str('enclosed') + \ b'\x00' + jl.encode_le_64bit(99) + \ b'\xff' + jl.encode_str('DEL')
def test_redirect_assembler(self, tmpdir, metainterp_sd): looptoken = FakeCallAssemblerLoopToken(0x0) newlooptoken = FakeCallAssemblerLoopToken(0x1234) # logger = jl.JitLogger() file = tmpdir.join('binary_file') file.ensure() fd = file.open('wb') jl.jitlog_init(fd.fileno()) logger.start_new_trace(metainterp_sd, jd_name='jdname') log_trace = logger.log_trace(jl.MARK_TRACE, None, None) op = ResOperation(rop.CALL_ASSEMBLER_I, [], descr=looptoken) log_trace.write([], [op]) jl.redirect_assembler(looptoken, newlooptoken, 0x1234) #the next line will close 'fd', instead of logger.finish() fd.close() binary = file.read() opnum = jl.encode_le_16bit(rop.CALL_ASSEMBLER_I) id_looptoken = compute_unique_id(looptoken) new_id_looptoken = compute_unique_id(newlooptoken) end = jl.MARK_RESOP_DESCR + opnum + jl.encode_str('i0,looptoken') + \ jl.encode_le_addr(id_looptoken) + jl.encode_str('') + \ jl.MARK_REDIRECT_ASSEMBLER + \ jl.encode_le_addr(id_looptoken) + \ jl.encode_le_addr(new_id_looptoken) + \ jl.encode_le_addr(newlooptoken._ll_function_addr) assert binary.endswith(end)
def test_debug_merge_point(self, tmpdir, metainterp_sd): logger = jl.JitLogger() file = tmpdir.join('binary_file') file.ensure() # use rfile instead of file.open since the host python and compiled # code may use different runtime libraries (win32 visual2008 vs. # visual2019 for instance rfile = create_file(str(file), 'wb') with SuppressIPH(): jl.jitlog_init(rfile.fileno()) logger.start_new_trace(metainterp_sd, jd_name='jdname') log_trace = logger.log_trace(jl.MARK_TRACE, None, None) op = ResOperation( rop.DEBUG_MERGE_POINT, [ConstInt(0), ConstInt(0), ConstInt(0)]) log_trace.write([], [op]) #the next line will close the 'fd', instead of logger.finish() rfile.close() binary = file.read() is_32bit = chr(sys.maxint == 2**31 - 1) assert binary == (jl.MARK_START_TRACE) + jl.encode_le_addr(1) + \ jl.encode_str('loop') + jl.encode_le_addr(0) + \ jl.encode_str('jdname') + \ (jl.MARK_TRACE) + jl.encode_le_addr(1) + \ (jl.MARK_INPUT_ARGS) + jl.encode_str('') + \ (jl.MARK_INIT_MERGE_POINT) + b'\x05\x00\x01s\x00i\x08s\x00i\x10s' + \ (jl.MARK_MERGE_POINT) + \ b'\xff' + jl.encode_str('/home/pypy/jit.py') + \ b'\x00' + jl.encode_le_64bit(0) + \ b'\xff' + jl.encode_str('enclosed') + \ b'\x00' + jl.encode_le_64bit(99) + \ b'\xff' + jl.encode_str('DEL')
def test_redirect_assembler(self, tmpdir, metainterp_sd): looptoken = FakeCallAssemblerLoopToken(0x0) newlooptoken = FakeCallAssemblerLoopToken(0x1234) # logger = jl.JitLogger() file = tmpdir.join('binary_file') file.ensure() # use rfile instead of file.open since the host python and compiled # code may use different runtime libraries (win32 visual2008 vs. # visual2019 for instance rfile = create_file(str(file), 'wb') with SuppressIPH(): jl.jitlog_init(rfile.fileno()) logger.start_new_trace(metainterp_sd, jd_name='jdname') log_trace = logger.log_trace(jl.MARK_TRACE, None, None) op = ResOperation(rop.CALL_ASSEMBLER_I, [], descr=looptoken) log_trace.write([], [op]) jl.redirect_assembler(looptoken, newlooptoken, 0x1234) #the next line will close the 'fd', instead of logger.finish() rfile.close() binary = file.read() opnum = jl.encode_le_16bit(rop.CALL_ASSEMBLER_I) id_looptoken = compute_unique_id(looptoken) new_id_looptoken = compute_unique_id(newlooptoken) end = jl.MARK_RESOP_DESCR + opnum + jl.encode_str('i0,looptoken') + \ jl.encode_le_addr(id_looptoken) + jl.encode_str('') + \ jl.MARK_REDIRECT_ASSEMBLER + \ jl.encode_le_addr(id_looptoken) + \ jl.encode_le_addr(new_id_looptoken) + \ jl.encode_le_addr(newlooptoken._ll_function_addr) assert binary.endswith(end)
class FakeMetaInterpStaticData(object): all_descrs = [] logger_noopt = FakeLogger() logger_ops = FakeLogger() config = get_combined_translation_config(translating=True) jitlog = jl.JitLogger() stats = Stats(None) profiler = jitprof.EmptyProfiler() warmrunnerdesc = None def log(self, msg, event_kind=None): pass
def test_compile_loop(): cpu = FakeCPU() staticdata = FakeMetaInterpStaticData() staticdata.all_descrs = LLtypeMixin.cpu.setup_descrs() staticdata.cpu = cpu staticdata.jitlog = jl.JitLogger(cpu) staticdata.jitlog.trace_id = 1 # loop = parse(''' [p1] i1 = getfield_gc_i(p1, descr=valuedescr) i2 = int_add(i1, 1) p2 = new_with_vtable(descr=nodesize) setfield_gc(p2, i2, descr=valuedescr) jump(p2) ''', namespace=LLtypeMixin.__dict__.copy()) # metainterp = FakeMetaInterp() metainterp.staticdata = staticdata metainterp.cpu = cpu metainterp.history = History() t = convert_loop_to_trace(loop, staticdata) metainterp.history.inputargs = t.inputargs metainterp.history.trace = t # greenkey = 'faked' target_token = compile_loop( metainterp, greenkey, (0, 0, 0), t.inputargs, [t._mapping[x] for x in loop.operations[-1].getarglist()], use_unroll=False) jitcell_token = target_token.targeting_jitcell_token assert jitcell_token == target_token.original_jitcell_token assert jitcell_token.target_tokens == [target_token] assert jitcell_token.number == 2 # assert len(cpu.seen) == 1 assert cpu.seen[0][2] == jitcell_token # del cpu.seen[:]