JIT 编译器有什么作用? [英] What does a JIT compiler do?

查看:25
本文介绍了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 编译的更多信息可以从 这篇文章 (tnxPangea 的链接).

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 编译器.这允许完全优化,然后您无需在每次运行应用程序时再次编译.但是,在手机和网页中,您通常只执行一次代码(或小程序),因此 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.

更新

Python 字节码文件的扩展名为 .py.当您执行字节码文件时,Python JIT 编译器会生成编译后的文件 .pyc.下次运行相同的程序时,如果 .py 文件没有改变,则无需再次编译,而是 Python 运行之前编译的 .pyc 文件.这加快了程序的启动速度.

Python bytecode files have extension .py. When you execute the bytecode file, Python JIT compiler produces compiled file .pyc. Next time you run the same program, if the .py file has not changed, there is no need to compile it again but instead Python runs the previously compiled .pyc file. This speeds up the start of the program.

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

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