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?
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.
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.
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.
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With