Execution of the assembly code of the CLR execution pattern

Source: Internet
Author: User

Known IL is a CPU-independent machine language that can access and manipulate object types, provide instructions to create and initialize objects, invoke virtual methods on objects, and manipulate array objects directly, so it can be regarded as an object-oriented machine language. The existence of each language has its own value and reason, and each has its own advantages, because of the uniqueness of the CLR, you can try to describe different features in different languages (must be the CLR-oriented compiler language).

When the method executes, it is necessary to convert the Il of the method to the CPU instruction of the machine, which is the function of the JIT compiler. When a method is first called:

The CLR detects all the types referenced by its code before the main method executes, and assigns an internal data structure to manage access to the reference type. For example, within the main method there is Console.WriteLine ("");

At this point in the internal data structure, each method defined by the console type has a corresponding record entry, each record entry contains an address, based on this address to find the specific implementation of the method. When this structure is initialized, the CLR will

The record is set to a non-file function that is contained within the CLR. This function is called Jitcompiler. When WriteLine is first called, the Jitcompiler function is called and the Il Code of the method is compiled to compile the CPU instruction of the cost machine and save to

Dynamically allocated in a block of memory. Then JC goes back to the CLR to create an internal data structure for the type, find the record for the called method, modify the original reference to JC to point to the address of the memory block, and finally the JC function jumps to the code in the memory block

(The concrete implementation of the method), the code executes and returns to continue executing the subsequent code.

The whole process is a bit cumbersome, roughly two-step walk, the first step to find the address of the specific method, initialize the data structure, compiled into instructions. The second step goes back to the CLR to find a record of the method, and returns. When main calls WriteLine again, the code in the memory block is executed directly, because the code for WriteLine is validated and compiled, skipping the JC function completely. Obviously, when the application terminates, the compiled code is discarded as well. (superficial understanding, forgetting to testify)

Execution of the assembly code of the CLR execution pattern

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.