CLR basics, CLR running process, use the doscommand to create, compile, and run the C # file, and view the Il code

Source: Internet
Author: User

CLR is the abbreviation of Common Language Runtime. It is a virtual environment of. Net assembly or executable programs. CLR is used to manage managed code, but it is written by unmanaged code and is not an Assembly that contains managed code. Therefore, you cannot view it using IL dasm, however, CLR is located in.. Net version.

 

□C # the whole process from source code compilation to CLR running

→Write C # source code in the form of class, struct, Enum, interface, delegate...


The compiler compiles the source code into .dllor .exe, which contains some important information.

 

PE/coff header:
It is the abbreviation of portable executable/Common Object File formatting. In Windows operating system, the function of .dllor run .exe for .dllor. EXE contains the PE/coff header. Windows applications include Windows PE.. Net Development Assembly or executable program.. net pe. If it is Windows PE, the operating system executes the application. If it is.. net pe.

 

CLR header:
Tell the operating system that the PE/coff header is A. Net assembly, and then run the CLR compilation environment.

 

List:
Describes the information of an Assembly, such as the name, version, culture, resources contained in the Assembly, and files that comprise the assembly.

 

Metadata:
Describes the content of an Assembly, such as the visibility of modules, types, and type members in the Assembly (public, private, and protected ). The process of viewing metadata is called reflection.

 

Pencil code:
That is, type implementation in metadata, including method bodies and fields.

 

Resource file:
Instance resources.

 

→ When you click an executable program, the operating system checks the PE Header, creates a process to load the CLR, and then checks the CLR header. If yes, mscoree located under system32 is loaded. the DLL component calls the coreexemain () function. The function loads the appropriate CLR version and the CLR starts running.

 

→ There is a Class Loader component in the CLR that looks for types related to the main () method from the GAC, configuration file, and assembly metadata, and caches all the information, in addition, a stub is inserted for a method.

 

→ CLR finds the entry point of the program, which is usually executed by the main () method.

 

→ CLR verifies whether the type is secure, whether the metadata is correct, and whether the template code is type safe.

 

→ Real-time CLR compilation, that is, JIT compilation, which is usually referred to as the process of compiling the managed pencil code into machine code. Do you still remember to insert a stub for each method during loading? During JIT instant compilation, the system detects the stubs of each method. If the content of the stubs is empty, JIT instant compilation is executed. When this method is called again, the system checks the stub again. If the stub stores the address of the local machine code, you do not need to perform JIT real-time compilation on the method.

 

Of course, CLR has more responsibilities than this. Other responsibilities include memory management, thread management, and garbage collection.


□Use the "vs2012 developer command prompt" to create, compile, and run files, and view the Il code

→ Create a demo folder on drive C and a managed-code folder in demo


→ Click "start" -- "All Programs" -- "Microsoft Visual Studio 2012" -- "Visual Studio Tools" -- "vs2012 developer command prompt"


→ Enter the following command in the doscommand window and press ENTER


→ Close the doscommand window and find two more hello. CS files in the managed-code folder.


→ Re-open "vs2012 developer command prompt" and enter the following command

 

○ CSC hello. CS used to compile files
○ DIR/B is used to display the content in the folder.
○ Directly input hello.exe to run the hello.exe Executable File

 

→ Enter the following command and press Enter.


→ The Il dasm window is displayed to view the Il code.


→ Double-click the static method "Main: void ()" to view the relevant il code. The intermediate il code is used by CLR for execution.

 

CLR basics, CLR running process, use the doscommand to create, compile, and run the C # file, and view the Il code

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.