JIT与口译员 [英] JIT vs Interpreters

查看:52
本文介绍了JIT与口译员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到JIT和口译员之间的区别.

I couldn't find the difference between JIT and Interpreters.

Jit是翻译和编译器的中介.在运行时,它将字节代码转换为机器代码(JVM或实际机器?),下一次,它从缓存中获取并运行 我说的对吗?

Jit is intermediary to Interpreters and Compilers. During runtime, it converts byte code to machine code ( JVM or Actual Machine ?) For the next time, it takes from the cache and runs Am I right?

解释器将直接执行字节码,而无需将其转换为机器代码.是吗?

Interpreters will directly execute bytecode without transforming it into machine code. Is that right?

我们电脑中的真实处理器将如何理解指令?

How the real processor in our pc will understand the instruction.?

请清除我的疑虑.

推荐答案

第一件事:
使用JVM,解释器和编译器(JVM编译器,而不是像Javac这样的源代码编译器)产生本机代码(也就是用于诸如x86之类的基础物理CPU的机器语言代码),从字节码.

First thing first:
With JVM, both interpreter and compiler (the JVM compiler and not the source-code compiler like javac) produce native code (aka Machine language code for the underlying physical CPU like x86) from byte code.

然后有什么区别:
不同之处在于它们如何生成本机代码,其优化程度以及优化成本.非正式地,解释器通过查找预定义的JVM指令到机器指令的映射,将每个字节码指令转换为相应的本机指令(参见下图).有趣的是,如果我们将一段字节代码并将其转换为机器代码,则可以进一步提高执行速度-因为考虑整个逻辑部分通常会提供优化空间,而不是进行转换(解释)隔离在每一行中(到机器指令).将一部分字节代码转换为(可能是优化的)机器指令的这种行为称为编译(在当前上下文中).在运行时完成编译时,该编译器称为JIT编译器.

What's the difference then:
The difference is in how they generate the native code, how optimized it is as well how costly the optimization is. Informally, an interpreter pretty much converts each byte-code instruction to corresponding native instruction by looking up a predefined JVM-instruction to machine instruction mapping (see below pic). Interestingly, a further speedup in execution can be achieved, if we take a section of byte-code and convert it into machine code - because considering a whole logical section often provides rooms for optimization as opposed to converting (interpreting) each line in isolation (to machine instruction). This very act of converting a section of byte-code into (presumably optimized) machine instruction is called compiling (in the current context). When the compilation is done at run-time, the compiler is called JIT compiler.

相互关系和协调性:
由于Java设计人员追求( hardware& OS )的可移植性,因此他们选择了解释器体系结构(而不是c样式的编译,组装和链接).但是,为了实现更高的速度,还可以选择将编译器添加到JVM.但是,随着程序继续被解释(并在物理CPU中执行),JVM会检测到热点"并生成统计信息.因此,使用来自解释器的统计信息,这些部分将成为编译(优化的本机代码)的候选项.实际上,它是即时完成的(因此是JIT编译器),并且随后将使用已编译的机器指令(而不是对其进行解释). JVM也自然地缓存了这些已编译的代码段.

The co-relation and co-ordination:
Since Java designer went for (hardware & OS) portability, they had chosen interpreter architecture (as opposed to c style compiling, assembling, and linking). However, in order to achieve more speed up, a compiler is also optionally added to a JVM. Nonetheless, as a program goes on being interpreted (and executed in physical CPU) "hotspot"s are detected by JVM and statistics are generated. Consequently, using statistics from interpreter, those sections become candidate for compilation (optimized native code). It is in fact done on-the-fly (thus JIT compiler) and the compiled machine instructions are used subsequently (rather than being interpreted). In a natural way, JVM also caches such compiled pieces of code.

警告语:
这些几乎是基本概念.如果是JVM的实际实现者,它的使用方式有所不同,请不要感到惊讶.其他语言的VM可能也是这种情况.

Words of caution:
These are pretty much the fundamental concepts. If an actual implementer of JVM, does it a bit different way, don't get surprised. So could be the case for VM's in other languages.

警告语:
只要您了解最终要在物理硬件中运行的一组机器指令,诸如解释程序将在虚拟处理器中执行字节代码",解释程序直接在字节处理器中执行"之类的语句都是正确的.

Words of caution:
Statements like "interpreter executes byte code in virtual processor", "interpreter executes byte code directly", etc. are all correct as long as you understand that in the end there is a set of machine instructions that have to run in a physical hardware.

一些好的参考文献: [尽管我还没有进行广泛的搜索]

Some Good References: [I've not done extensive search though]

  • [论文]基于硬件翻译的Java虚拟中的指令折叠 大井仁司的机器
  • [book]计算机组织和设计,第四版,D.A. Patterson. (见图2.23 )
  • [web-article] JVM性能优化,第2部分:编译器,作者:Eva Andreasson(JavaWorld)
  • [paper] Instruction Folding in a Hardware-Translation Based Java Virtual Machine by Hitoshi Oi
  • [book] Computer organization and design, 4th ed, D. A. Patterson. (see Fig 2.23)
  • [web-article] JVM performance optimization, Part 2: Compilers, by Eva Andreasson (JavaWorld)

PS:我已经交替使用以下术语-本机代码",机器语言代码",机器指令"等.

这篇关于JIT与口译员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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