[CLR via C #] 1.4 code for executing an assembly

Source: Internet
Author: User

2. ilis can also be written in assembler languages. Microsoft specializes in ilasm.exeand ildasm.exe. 3. The advanced language only discloses a subset of all CLR functions. The IL assembly language allows developers to access all CLR functions. If you need CLR functions not supported by the current language, you can use the IL language or other CLR languages. 4. to execute a method, you must first convert its IL to a local CPU command. This is the CLR JIT(Just-in-time or "instant") compiler's responsibilities. 5. display the first call of a method. ① Before the Main method is executed, CLR detects all types referenced by Main code. This assigns the CLR an internal data structure to manage access to the referenced type. In Figure 1-4, the Main method references a Console type (or Console class), which assigns the CLR an internal structure. In this structure, each method defined by the Console type has a corresponding record item. Each record item contains an address (but it does not exist yet). You can find the implementation method based on the address. ② An internal structure is assigned to the CLR during initialization., CLR sets each record item to an undocumented function contained in the CLR (it is understood as an undisclosed function only known to Microsoft ). Name this function JITCompiler (the function name can't be found in MSDN. To illustrate the process, you can get the function name by yourself, because the real function name is not public by Microsoft) ③ When the Main method calls WriteLine for the first timeJITCompiler is also called. The JIT function is responsible for compiling the IL code of a method with local CPU instructions. Since IL is compiled "instantly", all normally turn this component into a JIT compiler or JITter. ④ When the JITCompiler function is calledIt knows which method to call and which class defines the method. Therefore, JITCompiler searches for the IL of the called method in the metadata of the Assembly that defines this type. ⑤ NextIt is to verify the IL code and compile the IL into a local CPU command. The local CPU command is saved to a dynamically allocated memory block. ⑥ Then, JITCompiler finds the record corresponding to the called method in the internal data structure created by CLR for the type, and modifies the original reference to JITCompiler, let it point to the address of the memory block (including the locally compiled CPU command. 7. Last, The JITCompiler function jumps to the Code in the memory block and continues to execute the specific functional code in it. After the code is executed, it will return to Main and continue to execute as usual. The second WriteLine method is executed in Main. This time, because the WriteLine code has been verified and compiled for the first time, the code in the memory block is executed directly and the JITCompiler function is skipped completely. After the second WriteLine method is executed, Main is returned again. Figure 1-5 shows the second event that occurred when calling WriteLine. 6. For most applications, the performance loss caused by JIT compilation is not significant. Most reference programs call the same method repeatedly. See whether you have a disruptive understanding of. NET for the first time. 7. the clr jit compiler optimizes the local code and delivers better performance after code optimization. 9. IL is stack-based. This means that all its executions will push the operands to an execution stack, and the pop result will pop up at the same stack. 10. The biggest advantage of IL is Application robustness and security. When IL is compiled into a CPU command, CLR will execute a process called verfication. This process checks advanced IL Code to ensure that everything the Code does is safe. 11. C # by default, the compiler generates safe code, which is verifiable. However, the C # compiler also allows developers to write Insecure code. 12. insecure code allows you to directly operate on memory addresses and operate on the bytes of these addresses. Generally, this operation only works with unmanaged code or improves the performance of an algorithm with high efficiency,. 13. microsoftwares is a good program named peverify.exe. It checks all methods of an Assembly and reports methods that contain Insecure code.

Related Article

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.