. NET Compilation Principle Learning

Source: Internet
Author: User

Today to learn some of the principles of. NET compilation

First, through the contents of the book read:

  At the core of. NET Framewrok is the runtime execution Environment , called the Common language runtime (CLR), where code that runs under CLR control is called code hosting (managed code)

But before the CLR executes the source code that has been written, it needs to compile them, and the compilation is divided into two phases:

1. Compiling the source code into Microsoft intermediate Language (MSIL, abbreviated as IL)

2. Compiling IL into platform-specific code

A slightly more detailed process is:

1. If you use VS for development, the process of compiling the source code to IL is done by vs.

2.IL code from the CLR executable file (like a DLL file, I guess)? to the Jil (jusi-in-time) compiler, according to the corresponding metadata (metadata)? ( This does not understand how metadata is meant ), and is executed in real time after compiling to native code.

The second stage (Il compiles to native code) is explained in detail:

Here is the information found on the Internet http://www.cnblogs.com/szny/archive/2011/12/28/2304485.html

  Before running IL, you must first compile it according to the common language runtime to the native code of the appropriate target computer architecture (it should be the machine language of the local machine). ?

The. NET Framework provides two ways to perform this type of transformation:

The. NET Framework real-time compiler JIL

. NET Framework Native Image Generator Ngen.exe ?

JIL:

When the application runs, the JIT compiler can convert IL to native code as needed during the loading and execution of assembly content.

 Because the common language runtime provides a JIT compiler for each of the supported CPU architectures

(An architecture is a compiler, not a CPU a compiler, just look at the time to see preoccupied ...) If a CPU, a compiler word ... Hehe )

  So developers can generate a set of IL assemblies that can be JIT-compiled and run on different computers with different computer architectures

(The primary language is the physical education teacher teaches, this sentence I looked for about 5 minutes to understand ).

However, if managed code calls a platform-specific native API or platform-specific class library, it will only run on a specific operating system.

( only in a particular platform to use the API or class library, probably the meaning is like I write "Kuangcao", only I can read, others do not understand, do not know right )

JIT compilation takes into account the fact that some code may never be called during execution. It is not time-consuming and memory to convert all the MSIL in a portable executable (PE) file into native code

(Java bytecode seems to be in this way, as seen in the book )

Instead, the MSIL is converted as needed during execution and the generated native code is stored in memory for subsequent calls in the context of the process.

( here is a bit of doubt, the book said, "after the code compiled once, the resulting local executable program is stored, know to quit the application so far," said the book is a local executable program, here is the native code, I do not know how to parse. )

When a type is loaded and initialized, the loader creates a stub and attaches it to each method of that type. When a method is first called, the stub gives control to the JIT compiler, which converts the method's MSIL to native code and modifies the stub so that it points directly to the generated native code. In this way, subsequent calls to the JIT-compiled method go directly to the native code.

    

  

. NET Compilation Principle Learning

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.