For example, a test program written in C #,
output two sentences respectively: Hello, GoodBye, describes its invocation procedure for the CLR on Windows.
1. Before executing the main method, the CLR detects all the types of code references in main . This causes the CLR to allocate an internal data structure to manage access to reference types.
When the Main method calls WriteLine for the first time , the JIT function is called, and the JIT function compiles the IL code of the method into the CPU instructions of the machine.
Because IL is compiled on the fly, the CLR component is called the JIT compiler .
2. When the JIT function is called, it knows which method to invoke and what type defines the method.
The JIT then looks for the il of the called method in the metadata of the assembly that defines the type.
Next, the JIT validates the IL code, and the IL code compiles the cost machine CPU instructions. The native CPU instruction is saved in a dynamically allocated memory block.
The JIT then returns to the CLR to create an internal data structure for the type, finding the record that corresponds to the called method,
Modify the original reference to the JIT so that it points to the address of the memory block.
Finally, the JIT function jumps to the code in the memory block, the code formally WriteLine the method, and when the code execution is returned,
Will go back to the code in main and proceed as usual.
Executable exe in Windows call procedure