Compiling IL to Native Code

IL code cannot be directly executed. It must be converted to native CPU instructions. What follows is a discussion of this process.

JIT Compilation

At load time, if the CLR converted all the IL associated with an application to machine code, the program would run quickly. However, this compromises the initialization time of the application. Also, it is rare that a user uses all features of an application. This causes a waste of memory space, because unused modules of an application are also loaded into memory.

As a result, it is more efficient to compile IL instructions as the respective functions are being invoked. The .NET environment achieves this by implementing the following steps:

1.
Stub code is attached ...

Get Special Edition Using C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.