views:

378

answers:

4

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?

+8  A: 

Just-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

  1. executes the source code directly
  2. translates source code into some efficient intermediate representation (code) and immediately executes this
  3. 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.

Mark Byers
Does the JIT Compiler of the CLR compiles the WHOLE code once or not?
Rookian
No, it compiles only the necessary code. This gives you an atvantage to optimise in a runtime.
Al Bundy
But the optimisation process per call occurs only one time, doesn't it (.NET JIT)? Because I red the .NET JIT compiles a peace of code only one time.
Rookian
+3  A: 

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.

crowne
Your answer is related to the Java JIT Compiler doesn't it?
Rookian
Yup, but I believe that the JIT technique was first developed on smalltalk.
crowne
+1  A: 

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.

more info

Al Bundy
+2  A: 

JIT compiler produces binary machine codes translating block source code. Interpreter translates line by line.

erasmus