. Net Discovery Series five Me JIT (top)

Source: Internet
Author: User

JIT (Just in-time JIT) is a mechanism for a. NET edge to run and compile, the name of which comes from a mode of production that Toyota introduced in the 1960s, translated in Chinese into "just-in-time".

The. Net JIT compiler in the original design and operation of the way to speak, and Toyota Motor of this "just-in-time production" system has a lot of similarities, so let us first through the "Just-in-time production" approach to understand. NET of the JIT mechanism bar.

The basic idea of "just-in-time" can be summed up as "to produce the desired product as needed at the required time", which is what the. Net JIT compiler was designed to do when it needed to compile the code needed.

The first section. Me JIT

In C #, for example, before the C # code runs, it is typically compiled two times, the first stage is the C # code compiles to MSIL, and the second phase is the IL's compilation to the native code. The first stage of the compilation result is the generation of managed modules, the second stage of the compilation results are generated local code for the run, from here you can see that the first phase of the production of MSIL is not directly run.

Let's first explain what MSIL and managed modules are.

Msil:

MSIL, known as Microsoft Intermediate Language, is a kind of pseudo assembly language between high-level language and assembly language (in other words, you don't have to get excited). When a user compiles to run one. NET program, the advanced language compiler translates the source code into a set of instructions that can be independent of the CPU.

You can see that the IL includes instructions for loading (ldstr), storing (stacks, stacks) and initializing objects (locals) and calling object methods (call), as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations.

C # code:

string str_test = "test";
System.String Str_test = "test";

Corresponding IL code:

// 代码大小    14 (0xe)
      .maxstack 1
      .locals init ([0] string str_test,
           [1] string Str_test)
      IL_0000: nop
      IL_0001: ldstr   "test"
      IL_0006: stloc.0
      IL_0007: ldstr   "test"
      IL_000c: stloc.1
      IL_000d: ret

Managed Modules:

A managed module (managed module) is a standard 32-bit or 64-bit Microsoft Windows Portable executable (PE32 or pe32+) file that requires the CLR to execute, contains the IL code described above, and includes metadata, PE headers, The first few parts of the CLR.

Metadata (metadata) can be understood as a hashtable,table that maps built-in types and members and reference types and members, which are used with members for IL, so the metadata always needs to correlate the corresponding IL code, and the compiler also generates both metadata and IL. To ensure a self-describing synchronization.

The PE header (portable executable, translated into portable executable) includes PE32 and pe32+, which identifies the runtime environment of the managed module and the information that is needed to JIT-optimize the local code, as discussed later.

The CLR header mainly includes the method's entry address tag, as well as resources, strong naming and other information, which is an important parameter basis of the GAC.

The following figure shows the timing of the JIT intervention:

Figure 1 JIT working time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.