IL Code & JIT in .NET

Shivani Nalawade
3 min readSep 4, 2020

This post is about our contributions to the .NET to help to create a new and more flexible .NET Intermediate Language (IL) and JIT(just in time). It will explain what IL is, why you would actually want to modify it.

What is IL?

Different user have different machine configuration and different operating system whose unknown to visual studio. That is the main problem. To avoid this problem Microsoft Creates a code that is called as IL Code.

  • IL code (intermediate code) or half compiled code, it’s creates at compile time.
  • When this program will run at user system, this run time IL code is converted into machine code by JIT (just-in-time) compiler.
  • JIT Compiler converted IL Code into Machine Code.

Viewing IL code

  • By using ILDASM tool(IL Disassembler open the Tool directly from the Visual Studio) we can view a IL code of a DLL or EXE.
  • In order to view IL code using ILDASM, go to visual studio command prompt (CMD)and run “ILDASM.EXE”. Once ILDASM is running you view the IL code.

For example, this very simple C# console app:

is compiled to the following IL:

What is Just-In-Time(JIT) Compiler in .NET

Just-In-Time compiler(JIT) is a part of Common Language Runtime(CLR) in .NET which is responsible for managing the execution of NET programming language. A language-specific compiler converts the source code to the intermediate language. This intermediate language is then converted into the machine code by the Just-In-Time (JIT) compiler.

Working of JIT Compiler
  • The JIT compiler converts the Microsoft Intermediate Language(MSIL) or Common Intermediate Language(CIL) into the machine code this is done before the MSIL or CIL can be executed.

The following are the various types of JIT compilation in .NET:

  1. Pre-JIT Compiler :

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 go)This is done at the time of application deployment.

And this compiler is always implemented in the Ngen.exe (Native Image Generator).

2. Econo — JIT

In Econo-JIT compilation, the compiler compiles only those methods that are called at run time. After execution the compiled methods are removed from memory.

3. Normal — JIT

In Normal-JIT compilation, the compiler compiles only those methods that are called at run time.After that, they are stored in the cache and used whenever they are called again.

  • Much of the disadvantages of the JIT compiler can be handled using the Ahead-of-time (AOT) compilation. This involves compiling the MSIL into machine code so that runtime compilation is not required and the machine code file can be executed natively.

I hope this article has been helpful for you 😃!!!

--

--