Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between a Just-in-Time-Compiler and an Interpreter?

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?

like image 627
Rookian Avatar asked Mar 11 '10 15:03

Rookian


People also ask

What is just in time compiler and interpreter?

A Just-In-Time (JIT) compiler is a feature of the run-time interpreter, that instead of interpreting bytecode every time a method is invoked, will compile the bytecode into the machine code instructions of the running machine, and then invoke this object code instead.

What are the two major differences between interpreter and compiler?

A Compiler takes a program as a whole. An Interpreter takes single lines of a code. The Compilers generate intermediate machine codes. The Interpreters never generate any intermediate machine codes.

What is the difference between compiler and interpreter Short answer?

Interpreter translates just one statement of the program at a time into machine code. Compiler scans the entire program and translates the whole of it into machine code at once. An interpreter takes very less time to analyze the source code. However, the overall time to execute the process is much slower.

What is difference between JIT and AOT?

JIT downloads the compiler and compiles code exactly before Displaying in the browser. AOT has already complied with the code while building your application, so it doesn't have to compile at runtime. Loading in JIT is slower than the AOT because it needs to compile your application at runtime.


2 Answers

I've always found that a more abstract explanation sometimes helps. Let's say that you are trying to ask everyone in Mexico "Hello. How are you?" (your source language) Of course, you'll first need to translate it to Spanish (the native language of the country). That translation would be "Hola. Como estas?"

If you know Spanish, there would be no need for you to translate (native code / assembler). You just ask "Hola. Como estas?"

If you don't know Spanish, there are 3 ways to deal with it.

The first is to get a Spanish Dictionary (a compiler) and look up what the Spanish words are before you go. Perhaps you realize that "Hola. Que tal?" is one syllable shorter (compiler optimization) and use that instead. This is language compilation; you are converting the information to the native language beforehand.

The second is where you look up the words in the Spanish Dictionary while you are standing in front of the first person and then store the result (looking up the words just-in-time). The advantage here is that you could get a Mandarin Dictionary and then do the same experiment in China without having to keep ten sticky notes (binaries for different platforms) of translated phrases.

The third is where you look up the words while you are standing in front of each person. In essence, you interpret the words for each person separately (you act as an interpreter). The advantage here is that any changes are instantly reflected with the next person (you could change to asking "Hello. What color is your dog?" without having to fly home and restart - you don't need to recompile the phrases).

  • Translating beforehand means you can ask people fastest (pre-compiliation); you don't need to even bring the dictionary with you.
  • Translating when you see the first person in each country is almost as fast as translating beforehand but still allows you to travel to multiple countries without needing to go home to get a dictionary but means that you need to bring several dictionaries with you (a platform independent runtime).
  • Translating on demand is much slower but allows you to change the words without traveling home (source distributed language).
like image 200
Colorfully Monochrome Avatar answered Oct 11 '22 10:10

Colorfully Monochrome


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.

like image 33
Mark Byers Avatar answered Oct 11 '22 09:10

Mark Byers