像记忆化一样及时编译?
我想了解即时编译/解释,以及时间编译?我说“及时”有点像记忆是正确的吗?因为它重用了它识别为重复的部分的“解决方案”,即机器或字节代码?
Im trying to understand Just in time compilation/interpretation, and a head of time compilation? Would i be correct in saying that Just in time is sort of like memoization? in that it reuses the "solutions," that is machine or byte code, of the parts that it recognises as being repeated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,那是不正确的。
让我们看看当你向这些工具添加一些字节码时它们会做什么。 (用非常简单的话来说)
解释器
解释器查看字节码,找出他必须做什么,执行它,然后继续处理下一个字节码。这非常简单,并且都在运行时发生。
AOT 编译器
AOT 编译器是人们谈论编译器时最常提到的。当你编译时,他会查看你给他的字节码,并找出他必须生成的本机代码(汇编程序)。因此,当您运行此本机代码时,您不必像解释器一样找出要做什么,这就是为什么它更快。
JIT 编译器:
JIT 的思想是程序中的大部分时间都花在循环上。因此,当你有一个包含 100 次迭代的循环,并且在每次迭代中添加一些内容时,解释器每次都必须查看你想要执行的操作并执行它。 JIT 看着循环并说“我不必找出它做了 100 次以上的事情。我只是要编译这段代码。然后他会执行普通编译器所做的事情并生成一些本机代码,然后 JIT 经常与解释器一起工作
。解释器发现某个东西是一个循环,然后将其传递给 JIT,并在循环之后继续解释。Java
和 .NET 的实现不使用循环。口译员,这也是可能的。
luajit、pypy 和 firefox 中的 JS 实现都有解释器。
(是否应该有口译员是争论的主题)
希望有所帮助。
No that would not be correct.
Lets look at what these tools do when you threw some bytecode on them. (In very simple terms)
Interpreter
A Interpreter looks a bytecode finds out what he has to do, does it and then moves on to the next bytecode. Thats quite simple and happens all at runtime.
AOT Compiler
A AOT Compiler is what is mostly refered to when people talk about a compiler. When you are compiling he looks at the bytecode you give him and finds out what nativ code (assembler) he has to generate. So when you then run this nativ code you don't have to find out what to do like with an interpreter and thats why its faster.
JIT Compiler:
The idea of a JIT is that most of the time in your programm is spent in loops. So when you have a loop that has 100 iteration and in every iteration you you add some stuff the interpreter has to look at what you want to do every time and do it. The JIT looks at the loop and sais "I don't have to find out what that does a 100 times over agian. Im just going to compile this bit of code. Then he does what a normal compiler does and generate some nativ code and runs that.
A JIT often works together with an interpreter. The interpreter finds that something is a loop and then passes that to the JIT and after the loop it keeps on interpreting.
The implmentations of Java and .NET don't use an interpreter, thats possible too.
luajit, pypy and the JS implementation in firefox do have an interpreter.
(If you should have an interpreter or not is subject of debate)
Hope that helps.