Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why not JIT(Just In Time) compilers everywhere?

Tags:

.net

jvm

jit

I recently learned that JIT compilers are used to compile platform independant code to native code. JVM and the .net runtime environments use this, for better performance and significant reduce in compiling time. My question is that why not the ordinary compilers that compile directly into native code (like c compilers) also be made as JIT? Is there a restriction or a specification for the usage if JIT compilers?

like image 553
Nithish Inpursuit Ofhappiness Avatar asked Dec 03 '12 18:12

Nithish Inpursuit Ofhappiness


People also ask

Is JIT compilation slower?

JIT compilers translate continuously, as with interpreters, but caching of compiled code minimizes lag on future execution of the same code during a given run. Since only part of the program is compiled, there is significantly less lag than if the entire program were compiled prior to execution.

What is the use of JIT just-in-time compiler?

The Just-In-Time (JIT) compiler is a component of the runtime environment that improves the performance of Java™ applications by compiling bytecodes to native machine code at run time.

What happens if JIT compiler is absent in Java?

Without the JIT, the VM has to interpret the bytecodes itself - a process that requires extra CPU and memory. The JIT compiler doesn't compile every method that gets called because thousands of methods can be called at startup.

Why do web based languages use just-in-time compilation explain?

The advantages of a JIT are due to the fact, that since the compilation takes place in run time, a JIT compiler has access to dynamic runtime information enabling it to make better optimizations (such as inlining functions).


2 Answers

JIT has advantages and disadvantages. JIT can be very useful if you deploy your software to a lot of different PCs because the JIT compiler can detect how to optimize the code for each specific platform.

The problem is that JIT adds another step that must be taken before the software can be executed first: first it has to be compiled to IL and then it is compiled to machine code, this means an extra performance overhead. However, this conversion from IL to machine code only has to be done the first time the software is run, so each subsequent call will be much faster.

So basically (as a rule of thumb) you can say: if the software is a long-running process it's often good to use JIT, if the software has a short life-time it's better to use native code.

like image 197
Leon Cullens Avatar answered Nov 15 '22 04:11

Leon Cullens


Modern javascript implementations also do JIT, as do some PHP, Python, and Ruby implementations (at least). The trick with JIT, though, is that they are a relatively recent developement, and part of what makes them work is that you rely on a framework or runtime of some type that lives on the end-user machine that is capable of making the correct optimizations for that machine and instance of the application.

For languages that want to be close to the "bare metal" of your computer, relying on that extra abstraction layer does not always make sense.

like image 29
Joel Coehoorn Avatar answered Nov 15 '22 05:11

Joel Coehoorn