JIT编译器做什么? [英] What does a JIT compiler do?

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

问题描述

我只是看着Google IO视频,他们谈论了他们包括在Android中的JIT编译器。他们展示了一个演示的性能改进感谢JIT编译器。我想知道什么是一个JIT编译器做,想听到来自不同的人。

I was just watching the Google IO videos and they talked about the JIT compiler that they included in the android. They showed a demo of performance improvements thanks to the JIT compiler. I wondered what does exactly a JIT compiler do and wanted to hear from different people.

那么,JIT编译器的职责是什么?

So, what is the duty of a JIT compiler?

推荐答案

Java代码通常作为字节码分发,这是机器无关的伪代码。 (之前在70年代开发的UCSD-p系统中使用的同样的想法)。这样做的优点是相同的应用程序可以在不同的处理器和操作系统中运行。此外,字节码通常比编译应用程序小。

Java code is normally distributed as bytecode, which is machine-independent pseudocode. (The same idea was previously used in UCSD-p system developed in the 70'ies.) The advantage of this is that the same application can be run in different processors and operating systems. In addition, the bytecode is often smaller than compiled application.

缺点是与运行编译代码相比,解释代码
为了解决这个问题,开发了 JIT编译器。 JIT编译器在代码执行之前将代码编译成机器码。与解释器相比,这可以加快执行速度,但是每次运行程序时都需要花费额外的时间进行编译。
此外,由于JIT编译器必须快速编译,因此不能使用静态编译器中使用的复杂优化技术。

The disadvantage is that interpreting the code is slow compared to running compiled code. To solve this problem, JIT compiler was developed. JIT compiler compiles the code into machine code just before the code is executed. This speeds up the execution compared to interpreter, but additional time is spent for compiling every time the program is run. In addition, since JIT compiler must compile fast, it can not use complex optimization techniques that are used in static compilers.

另一种方法是 HotSpot 编译。它最初作为解释器运行,但随后检测哪些例程最常使用,并只编译那些例程。优点是没有由于编译的初始延迟。此外,HotSpot编译器可以在执行期间执行概要分析,然后针对最重要的例程发出更强的优化。它甚至可以收集信息,以便当您一次又一次运行相同的应用程序时,它会运行更快更快。有关HotSpot编译的详细信息,请访问本文(tnx Pangea的链接)。

Another approach is HotSpot compiling. It initially runs as interpreter, but then detects which routines are used most often and compiles only those. The advantage is that there is no initial delay due to the compiling. In addition, HotSpot compiler may do profiling during the execution and then issue stronger optimization for the most important routines. It may even gather information so that when you run the same application again and again, it will run faster and faster. More information about HotSpot compiling can be found from this article (tnx Pangea for the link).

当然,不是使用JIT编译器,你可以使用一个静态编译器来编译你的机器的字节码。这允许完全优化,然后你不需要每次运行应用程序时再次编译。但是,在手机和网页中,你通常只执行一次代码(或applet),所以JIT编译器可能是更好的选择。

Of course, instead of using JIT compiler, you could just use a static compiler to compile the bytecode for your machine. This allows full optimization and then you do not need to compile again every time you run the application. However, in phones and web pages, you often just execute the code (or applet) once, so JIT compiler may be a better choice.

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

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