Just-In-Time (JIT) Compiler in C#
- The JIT compiler translates the MSIL code of an assembly to native code and uses the CPU architecture of the target machine to execute a .NET application.
- It also stores the resulting native code so that it is accessible for subsequent calls.
- If a code executing on a target machine calls a non-native method, the JIT compiler converts the MSIL of that method into native code.
- The JIT compiler also enforces type-safety in the runtime environment of the .NET Framework.
- It checks for the values that are passed to parameters of any method.
- The following are the various types of JIT compilation in .NET:
- Pre - JIT.
- Econo - JIT.
- Normal - JIT.
Pre - JIT
- In Pre-JIT compilation, complete source code is converted into native code in a single cycle (i.e. compiles the entire code into native code in one stretch)
- This is done at the time of application deployment.
- In .Net it is called "Ngen.exe"
Econo - JIT
- In Econo-JIT compilation, the compiler compiles only those methods that are called at run time.
- After execution of this method the compiled methods are removed from memory.
Normal - JIT
- In Normal-JIT compilation, the compiler compiles only those methods that are called at run time.
- After executing this method, compiled methods are stored in a memory cache.
- Now further calls to compiled methods will execute the methods from the memory cache.