Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a JIT compiler do?

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.

So, what is the duty of a JIT compiler?

like image 855
mehmet6parmak Avatar asked May 25 '10 08:05

mehmet6parmak


People also ask

What does JIT compiler do in C#?

The JIT compiler translates the MSIL code of an assembly to native code and uses the CPU architecture of the target machine to execute a . NET application. It also stores the resulting native code so that it is accessible for subsequent calls.

What is the point of JIT?

Just-in-time, or JIT, is an inventory management method in which goods are received from suppliers only as they are needed. The main objective of this method is to reduce inventory holding costs and increase inventory turnover.

How is JIT compiler different from normal compiler?

A compiler compiles (translates) the given program to executable code (whole code at a time). A JIT compiler performs a similar task but it is used by JVM internally, to translate the hotspots in the byte code. A compiler compiles (translates) the given program to executable code (whole code at a time).

What is JIT compiler in JVM?

The Just-In-Time (JIT) compiler is a component of the Java™ Runtime Environment that improves the performance of Java applications at run time. Java programs consists of classes, which contain platform-neutral bytecodes that can be interpreted by a JVM on many different computer architectures.


2 Answers

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.

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.

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).

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.

Update

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.

like image 179
PauliL Avatar answered Oct 03 '22 00:10

PauliL


JIT is short for "just in time". A JIT compiler compiles code, which is often in an intermediate language like Java bytecode or Microsoft IL, into native, executable code, and it does this at the moment that the code is called. So until the code is called, it exists only in portable, non-machine specific bytecode or IL, and then when it is called, native code is generated (which is then re-used on subsequent calls).

like image 35
David M Avatar answered Oct 03 '22 01:10

David M