JIT (Just-In-Time) Compiler

In the .NET Framework, all the Microsoft .NET languages use a Common Language Runtime, which solves the problem of installing separate runtimes for each of the programming languages. When the Microsoft .NET Common Language Runtime is installed on a computer then it can run any language that is Microsoft .NET compatible. Before the Microsoft Intermediate Language (MSIL) can be executed, it must be converted by a .NET Framework Just-In-Time (JIT) compiler to native code, which is CPU-specific code that runs on the same computer architecture as the JIT compiler.

JIT (JUST-IN-TIME) COMPILER

A Web Service or WebForms file must be compiled to run within the CLR. Compilation can be implicit or explicit. Although you could explicitly call the appropriate compiler to compile your Web Service or WebForms files, it is easier to allow the file to comply implicitly. Implicit compilation occurs when you request the .asmx via HTTP-SOAP, HTTP-GET, or HTTP-POST. The parser (xsp.exe) determines whether a current version of the assembly resides in memory or in the disk. If it cannot use an existing version, the parser makes the appropriate call to the respective compiler (as you designated in the Class property of the .asmx page).

When the Web Service (or Web Forms page) is implicitly compiled, it is actually compiled twice. On the first pass, it is compiled into IL. On the second pass, the Web Service (now an assembly in IL) is compiled into machine language. This process is called Just-In-Time JIT compilation because it does not occur until the assembly is on the target machine. The reason you do not compile it ahead of time is so that the specific JITter for your OS and processor type can be used. As a result, the assembly is compiled into the fastest possible machine language code, optimized and enhanced for your specific configuration. It also enables you to compile once and then run on any number of operating systems.

How JIT Works?

Before MSIL(MS Intermediate Language) can be executed, it must be converted by .net Framework Just in time (JIT) compiler to native code, which is CPU-specific code that run on some computer architecture as the JIT compiler. Rather than using time and memory to convert all the MSIL in portable executable (PE) file to native code, it converts the MSIL as it is needed during execution and stored in resulting native code so it is accessible for subsequent calls.

The runtime supplies another mode of compilation called install-time code generation. The install-time code generation mode converts MSIL to native code just as the regular JIT compiler does, but it converts larger units of code at a time, storing the resulting native code for use when the assembly is subsequently loaded and executed. As part of compiling MSIL to native code, code must pass a verification process unless an administrator has established a security policy that allows code to bypass verification. Verification examines MSIL and metadata to find out whether the code can be determined to be type-safe, which means that it is known to access only the memory locations it is authorized to access.

JIT Types

In Microsoft .NET there are three types of JIT (Just-In-Time) compilers which are Explained as Under

  • Pre-JIT Compiler (Compiles entire code into native code completely)
  • Econo JIT Compiler (Compiles code part by part freeing when required)
  • Normal JIT Compiler (Compiles only that part of code when called and places in cache
    JIT

Description

  • Pre-JIT COMPILER: Pre-JIT compiles complete source code into native code in a single compilation cycle. This is done at the time of deployment of the application.
  • Econo-JIT COMPILER: Econo-JIT compiles only those methods that are called at runtime. However, these compiled methods are removed when they are not required.
  • Normal-JIT COMPILER: Normal-JIT compiles only those methods that are called at runtime. These methods are compiled the first time they are called, and then they are stored in the cache. When the same methods are called again, the compiled code from the cache is used for execution.

These methods are compiled the first time they are called, and then they are stored in the cache. When the same methods are called again, the compiled code from the cache is used for execution.


Similar Articles