JIT代码生成技术 [英] JIT code generation techniques

查看:106
本文介绍了JIT代码生成技术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虚拟机如何动态生成并执行本机代码?

How does a virtual machine generate native machine code on the fly and execute it?

假设您可以弄清楚要执行的本机操作码是什么发出,您如何实际运行它?

Assuming you can figure out what are the native machine op-codes you want to emit, how do you go about actually running it?

是难事吗,就像将助记符指令映射到二进制代码,将其填充到char *指针并将其强制转换一样

Is it something as hacky as mapping the mnemonic instructions to binary codes, stuffing it into an char* pointer and casting it as a function and executing?

还是您会生成一个临时共享库(.dll或.so或任何东西),然后使用<$ c之类的标准函数将其加载到内存中? $ c> LoadLibrary ?

Or would you generate a temporary shared library (.dll or .so or whatever) and load it into memory using standard functions like LoadLibrary ?

推荐答案

您只需将程序计数器指向您要执行的代码。请记住,数据可以是数据或代码。在x86上,程序计数器是EIP寄存器。 EIP的IP部分代表指令指针。调用JMP指令以跳转到一个地址。跳转后,EIP将包含此地址。

You can just make the program counter point to the code you want to execute. Remember that data can be data or code. On x86 the program counter is the EIP register. The IP part of EIP stands for instruction pointer. The JMP instruction is called to jump to an address. After the jump EIP will contain this address.


这难道就像将助记符指令映射到二进制代码,并将其填充到一个char中一样*指针并将其强制转换为函数并执行?

Is it something as hacky as mapping the mnemonic instructions to binary codes, stuffing it into an char* pointer and casting it as a function and executing?

是。这是一种方法。产生的代码将转换为C中的功能指针

Yes. This is one way of doing it. The resulting code would be cast to a pointer to function in C.

这篇关于JIT代码生成技术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆