Sunday, September 20, 2015

What is IL (Intermediate Language) in .Net framework ?

Intermediate Language is also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language). All .NET source code is compiled to IL. IL is then converted to machine code at the point where the software is installed, or at run-time by a Just-In-Time (JIT) compiler.

It is a CPU independent partially compiled code. Partial/half compiled means this code is not yet compiled to machine/CPU specific instructions.

We do not know in what kind of environment.NET code will run. In other words we do not know what can be the end operating system, CPU configuration, machine configuration, security configuration etc. So the IL code is half compiled and on runtime this code is compiled to machine specific using the environmental properties (CPU, OS, machine configuration etc.).

Using ILDASM simple tool 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 and run “ILDASM.EXE”. Once ILDASM is running you view the IL code.

When a compiler compiles a code he takes in to consideration things like operating system version, hardware etc. and then compiles an optimized code as per those environmental data.

What is IL (Intermediate Language) in .Net framework ?



Now let’s say your compiler has compiled an optimized code as per “Windows 98” operating system. Now this code when run on windows server will not probably run in a optimized manner.

What is IL (Intermediate Language) in .Net framework ?



So what .NET does it only compiles the code partially. Later when the code runs the compiler kicks off, detects the environment and does a fully optimized code compiler as per that operating system and hardware.

What is IL (Intermediate Language) in .Net framework ?


So every time compiling on the fly can lead to performance issues?

Once the code is compiled it’s maintained in cache. So the performance hit is only for the first time when .NET application runs. 

No comments :

Post a Comment

Threaded Minds would love to hear from you !!!