Before we understand Just in Time compilation let us get an
overview of compilation of source code to Microsoft Intermediate Language
(MSIL). MSIL is the CPU independent instructions. MSIL is generated from the
source code written in any .NET compliant language. The respective compiler is
responsible for translating the source code to the MSIL. The same is shown in figure
1. MSIL includes instructions for loading, storing, initializing, and calling
methods on objects, as well as instructions for arithmetic and logical
operations, control flow, direct memory access, exception handling, and other
operations. When a compiler produces MSIL, it also produces metadata. The MSIL
and metadata are contained in a Portable Executable (PE) file that is based on
and extends the published Microsoft PE and Common Object File Format (COFF)
used historically for executable content. This file format, which accommodates
MSIL or native code as well as metadata, enables the operating system to
recognize common language runtime images.
A native code is the code which CPU can execute. MSIL should
be converted to the native code to make the code executable. This will be done
by the .NET runtime Just In Time Compiler. Because the common language runtime
supplies a JIT compiler for all the supported CPU architectures, developers can
write a set of MSIL that can be JIT compiled and run on computers with
different architectures. However, the managed code will run only on a specific
operating system if it calls platform-specific native APIs or a
platform-specific class library.
The JIT compilation has some different flavors based on the
compilation procedures and verification process while compilations.