Question:
just in time compiler?
2009-04-03 14:48:53 UTC
please can anyone explain to me the meaning of just in time compiler in a simple way coz i dnt knw that much about compilers(plz explain it in abstract sense )
and plz why do java use these compilers!!!!!
Three answers:
Tizio 008
2009-04-03 15:13:26 UTC
the JIT compilers (Just In Time compilers) are "compilers" (i.e. translators from a "code"/source to machine language) which operates on the fly.

normally, the compiling step is taken by the developer, who "generates" the executable file ("containing" instructions for the CPU).

but in some environment, the developer does not generate a real exeutable (i.e. an executable containing code understandable by the processor), indeed it generates a "bytecode" executable (it's the case of Java).

this is a "machine language" of its own, but the machine is a virtual one, so indeed what's happening is that there's an "interpreter" of the bytecode.

this can slow down things, so in order to speed it up, there can exist a "compiling" step done "on the fly", i.e. when the bytecode need to be executed, they are first "translated" into real machine code (i.e. instruction for the physical processor, not the virtual one), so they can run at the maximum speed.

this step is done by the JIT compiler, and now you should understand why it is called so.



(JIT compilers could operate also on textual source, instead of "bytecode"; I mentioned it just because it's the Java case; but some modern "interpreted" languages, to reach better performance, have a JIT compiler that translate the source to machine code)
R.F.
2009-04-03 15:34:03 UTC
This explanation may be a little long, but to answer your question, you need to understand a little background to appreciate what the JIT compiler means.



A machine, or Computer's native language is machine code. But machine code is really hard for humans to understand and program. And each type of computer has its own version of machine code it can understand.



So "high level programming languages" were created that uses familiar human language words so programming is easier. But computers do not understand these high level languages.



So programs and commands in a high level programming language have to be translated into machine code for the computer to understand. There are 2 different types of translation: compilation and interpretation.



Briefly, in interpretation, an interpretor program translates the high level language program when you run the high level language program. Since it has to interpret the program code every time it's run, it's slower, but the advantage is that you can have a different interpretor that translates the code for that computer and it should work every time. For example, a BASIC program can run on any computer that has the right BASIC interpretor on the computer.



In compilation, a compiler program takes your high level language program and translates it into an executable program that you can run directly. You only have do a compilation translate once so that when you run the executable, it will run immediately. The downside is that because the compiled program is translated for that type of computer, the executable will work on only that type of computer. For example, a program compiled on a PC will not work on a Mac.



Now to get to your question.

There is actually a 3rd method that is a hybrid of the 2 types of translation. It uses both compiling and interpreting to address the problems of each individual method.



First, the program source code is compiled into a byte code that is not tied to any specific computer. That means the computer program is optimized into code a computer can process faster, but since it's not optimized for any specific computer, the computer can't understand it yet.

To understand this byte code, the computer needs a Virtual Machine to run this byte code program. And this Virtual Machine uses a "Just-in-Time (JIT) Compiler" to interpret the byte code into the specific machine code for that computer at the moment you run the program.

The advantage of all this is that you have an optimized machine-type code that is portable; it can be theoretically used on any computer that has a JIT compiling virtual machine.



The classic example of this is Java. You have to compile a Java program and you can run it from any computer with a Virtual Machine (which as the JIT compiler) that interprets the compiled Java class.
romnempire
2009-04-03 15:02:08 UTC
A computer can't understand and follow the instructions on the code that you write. ( it can't understand "import javax.swing.JMenuItem;"), but a compiler translates your code to a language your computer can understand, but you can't. Then the computer understands what is meant by that line of code.



Note that you couldn't possibly code in the language of computers on the java program level without a lot more effort than it's worth.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...