. NET language compilation process: Intermediate language (IL) and instant compiler (JIT)

Source: Internet
Author: User

. NET language is divided into two stages. The first high-level language is compiled into an intermediate language called IL, and il is more of a machine language than a high-level language, but IL contains some abstract concepts (such as classes, exceptions), which is why this language is called an intermediate language. Il is packaged in a DLL or EXE file, and the main difference between DLLs and EXE in. NET is that only EXE can be run directly, and both can be dynamically loaded by a process being executed (detailed later in this article).      Since the CPU of the machine can only execute native assembly language instead of IL, further compiling IL into assembly language (i.e. the second phase) needs to be done at runtime, which is done by the instant compiler (JIT). High-level language at first compile time, the compiler does two things: first store the compiled IL in a DLL or EXE, and then create a stub function for each method of the class, which invokes the immediate compiler and passes its own address as a parameter to the compiler. The instant compiler obtains the appropriate IL from the DLL or EXE, compiles it into a machine language, and replaces the in-memory call function with the machine language. The idea of this process is to call the precompiled method with a compiled method, which is essentially called a stub function, and the stub function calls the compiler to compile itself into the native machine language; NET calls the method again, and the method is actually executed at this time. When a function is called repeatedly, the machine instruction is executed directly, and it takes time for the compiler to first compile the method. For those methods that are not called, they will not be compiled.

When the compiler generates an EXE file, the program's entry function is the main () method. Loader will load this EXE file, detect that this is a managed exe, and then loaded. NET runtime library file (including the instant compiler), and then calls the EXE's main () method. This triggers an immediate compilation of the Main () method, and the main () method is replaced in memory with the local machine language, so. NET application to start running. After being compiled into a local language, the application is free to call local code. When the program aborts, the local code is freed from memory, so the IL needs to be recompiled by the immediate compiler the next time it runs.

. NET language compilation process: Intermediate language (IL) and instant compiler (JIT)

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.