I know what the JIT compiler is but how about why is it called that, it obviously catches exceptions Just in Time, but how and why should it be called this?
Sorry if this sounds a bit vague.
I know what the JIT compiler is but how about why is it called that, it obviously catches exceptions Just in Time, but how and why should it be called this?
Sorry if this sounds a bit vague.
The Just-In-Time compiler doesn't have anything to do with exceptions. It refers to when code is compiled. Some languages, like Java, are translated from the language that you program in with your favorite editor into byte code. At runtime, some byte code might be further compiled into native code just prior to execution (hence the name, just-in-time). This is in contrast to some languages, like C, that are compiled into native machine code at the time when you invoke the compiler.
The name comes from the "just in time" manufacturing methodology, wherein parts are delivered "just in time" to be installed. In manufacturing, it costs a lot of money to keep parts and supplies in inventory, and producing and delivering them as they're needed makes a process cheaper/more efficient.
The Java JIT compiler works in a way that's analogous to JIT manufacturing: instead of compiling code beforehand and keeping it around, it compiles code as its needed. This gives you short development cycles and immediate feedback of an interpreted language and the speed of a compiled language.
In .Net, say when a C# program is compiled, it is compiled into what is called "Microsoft intermediate language" (MSIL) Code, this code is machine independent. The MSIL Code is not directly executable as is. It must be converted (and optimized) to code that can be executed by the target OS (and CPU). That conversion occurs when you request a .Net program to run and is performed by the Just In Time (JIT) compiler, the JIT produces executable that is specific to OS (and CPU) you are running the application on. So the name Just In Time, indicates that the compilation from MSIL to native OS code only occurs when you request the code to execute. For more information see Compiling MSIL to Native Code.
Code is compiled when called. It is compiled just in time, or just before it is called if you prefer.
This apply to methods. If a method is never called, it is never compiled.
It doesn't have anything to do with exceptions.
The name reflects the fact that the software is not compiled into machine code until it is about to be executed. This allows you deploy an application to multiple computers and have machine-specific optimizations applied at runtime.