Esempio n. 1
0
 def test_redirect_assembler(self, tmpdir):
     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(self.make_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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 def redirect_call_assembler(self, oldlooptoken, newlooptoken):
     # some minimal sanity checking
     old_nbargs = oldlooptoken.compiled_loop_token._debug_nbargs
     new_nbargs = newlooptoken.compiled_loop_token._debug_nbargs
     assert old_nbargs == new_nbargs
     oldadr = oldlooptoken._ll_function_addr
     target = newlooptoken._ll_function_addr
     # copy frame-info data
     baseofs = self.cpu.get_baseofs_of_frame_field()
     newlooptoken.compiled_loop_token.update_frame_info(
         oldlooptoken.compiled_loop_token, baseofs)
     # we overwrite the instructions at the old _ll_function_addr
     # to start with a JMP to the new _ll_function_addr.
     mc = InstrBuilder()
     mc.load_imm(r.SCRATCH, target)
     mc.BCR(c.ANY, r.SCRATCH)
     mc.copy_to_raw_memory(oldadr)
     #
     jl.redirect_assembler(oldlooptoken, newlooptoken, newlooptoken.number)