What are the differences between a Just-in-Time-Compiler and an Interpreter, and are there differences between the .NET and the JAVA JIT compiler?
views:
378answers:
4Just-in-time compilation is the conversion of non-native code, for example bytecode, into native code just before it is executed.
From Wikipedia:
JIT builds upon two earlier ideas in run-time environments: bytecode compilation and dynamic compilation. It converts code at runtime prior to executing it natively, for example bytecode into native machine code.
An interpreter executes a program. It may or may not have a jitter.
Again, from Wikipedia:
An interpreter may be a program that either
- executes the source code directly
- translates source code into some efficient intermediate representation (code) and immediately executes this
- explicitly executes stored precompiled code made by a compiler which is part of the interpreter system
Both the standard Java and .NET distributions have JIT compilation, but it is not required by the standards. The JIT compiler in .NET and C# are of course different because the intermediate bytecode is different. The principle is the same though.
An interpreter generates and executes the machine code instructions on the fly for each instruction, regardless of whether it has previously been executed.
A JIT caches the instructions that have been previously been interpreted to machine code, and reuses those native machine code instruction thus saving time & resources by not having to re-interpret statements that have already been interpreted.
When you compile a Microsoft.NET language, the complier generates code written in the Microsoft Intermediate Language (MSIL). MSIL is a set of instructions that can quickly be translated into native code.
A Microsoft.NET application can be run only after the MSIL code is translated into native machine code. In .NET Framework, the intermediate language is complied "just in time" (JIT) into native code when the application or component is run instead of compiling the application at development time.
JIT compiler produces binary machine codes translating block source code. Interpreter translates line by line.