. NET learning notes-what are the names of the stacks (CLR, CLI, CTS, CLS, IL, JIT)

Source: Internet
Author: User

What is the CLR?

The CLR, the common language runtime (Common Language Runtime) is a "runtime" that is used by multiple languages. His core capabilities include (memory management, assembly loading, security, exception handling, and thread synchronization) and can be used by all languages that target the CLR. The "runtime" here is a run-time environment, just like a Java virtual machine. Oh, wrong, the exact JRE (Java Runtime enviromental). The JVM is not exactly a Java virtual machine for an entity, but a specification, just like the CLI. There will be different implementations, such as JRockit or hotspot (the former is Oracle's JVM commercial implementation, which is the sun's open source implementation-and, of course, Oracle now)

What is a CLI?

The common Language Infrastructure (Common Language Infrastructure) defines the executable code that makes up the. NET framework infrastructure, as well as the environment specification when the code runs. It defines a language-independent, cross-architecture operating environment that enables developers to develop software in a variety of high-level languages defined within the specification, and to run software on different computer architectures without modification. The CLI is an open technical specification that was launched by Microsoft, Hewlett-Packard, and Intel in 2000 to the ECMA initiative. To be blunt, the CLI is a set of specifications, and the CLR is an implementation of the CLI. So what exactly is defined in this specification of the CLI? You may wish to visit the ECMA website next, or download it here:

As shown above: contains 6 parts:

Partition i:concepts and Architecture – describes the full architecture of the. NET CLI, providing a common type system (Cts,common type systems), Virtual execution System (ves,virtual Execution System) and a standardized description of the common Language Specification (Cls,common Language specification), also provides an informative description of the metadata (Metadata).

Common type System (CTS): Specification of the type of data in. Net.

Metadata System (Metadata): Is data that describes data in. Net.

Universal Language Specification (CLS): A language specification that describes the interaction between multiple languages. NET systems include C #, C + +, VB, J #, and they all adhere to the common language specification.

Virtual Execution System (VES): is a running environment that runs managed code, which provides the built-in data type required to run managed code, and Managed parameters such as machine configuration and state settings, Process Control, and exception handling.

Partition ii:metadata Definition and Semantics - provides a standardized description of metadata, including metadata in. NET extended PE file format (represented in. NET extended PE file format), the logical content of the metadata (in the form of tables and their associated collections, in fact using formal method representations) and the semantics of the metadata (in the form of assembler ilasm understanding that compiles into virtual machine code).

Partition iii:cil instruction Set describes the instruction set of the CIL (note that it is CIL, not the CLI OH)

Partition iv:profiles and Libraries- provides a brief introduction to the CLI Library and a specification for decomposing it into profiles and libraries. Here is a companion file clilibrarytypes.xml, considered to be released with this section, but the file is in XML format, which provides a detailed description of each class, value type, and interface in the CLI library. The term "profile" here means a collection of libraries that together make up a coherent whole that provides a functional level, in other words, different profiles correspond to different sets of libraries, providing different levels of functionality.

Partition V:debug Interchange format- describes the way in which the CLI product's debug interaction is marked;

Partition vi:annexes-provides some routines written in ILAsm (CIL Assembly Language), etc.

What is CTS?

The CLR is fully expanded around the type, and code written in one programming language can communicate with code written in another language. So Microsoft developed a formal specification, "Common Type System" (Common type System,cts), which describes the definition and behavior of a type. As mentioned above, Microsoft has done standardization work with the other components of the CTS and, NET framework, including (file format, meta-number, intermediate language, and to the underlying platform) to the ECMA, and the resulting standard is called the "Common Language Infrastructure" (Common Language Infrastructure).

The following are defined in the CTS:

What is a CLS?

The CLR integrates multiple languages, and one language can invoke objects created in another language. To achieve this, Microsoft has defined a common language specification (Common Language specification). It defines a minimum set of features in detail. Any compiler must support this minimum feature set if it wants to build a component that is compatible with the other "CLS-oriented, CLR language" generated components. Here is a diagram to illustrate the relationship between the two:

What is IL?

(Cut from "clr.via.c#")

Start by looking at the. NET compilation process, where the source code files are compiled by the compiler to generate a managed module (managed module). The managed module is plainly a 32-bit (PE32) or 64-bit (pe32+) PE file.

The specific structure is as follows:

PE32 or pe32+ file header
CLR Header
Meta data
Il code

Here we focus on Il,il is CPU-independent machine language, which is more advanced than most CPU machine languages. The ability to access operation object types, create and initialize objects, invoke virtual methods on objects, manipulate array elements directly, and even throw and catch exception handling can be said to be an object-oriented machine language.

What is JIT? How does it work?

The CLR executes the managed module, and the IL code must be compiled with the cost of the CPU instruction. This is done by the JIT (just in time). The following is a simple example of how the JIT works:

Static void Main () {    Console.WriteLine ("Hello");    Console.WriteLine ("Goodbye");}

1. The CLR executes the main function to check all the referenced types, where main uses the console class, where the CRL allocates an internal structure. In this structure, all the methods of the console class have corresponding portals.

2. Mian the Jitccompiler function is called when the WriteLine function is first called. Jitccompiler knows that the console class defines the WriteLine function and finds the IL code for WriteLine in the assembly that defines the console class.

3, dynamic allocation of a piece of memory;

4, the found IL code to verify, and then compile the cost of the CPU instruction, the instruction is placed in the previously allocated memory;

5. Modify the entry of the WriteLine function in the internal structure so that it points to the address of the dynamically allocated memory;

6, Jitccompiler function jump to the existence of local CPU instructions;

7, after the execution, recall the main function, continue to execute the following code;

The point here is that the second time the WriteLine function is executed, there is no JIT, because the local CPU instructions in the memory block are called directly.

Reference: Distinguish between language/specification and platform/implementation, and cross-platform. NET development "

"Clr.via.c#"

. NET learning notes-what are the names of the stacks (CLR, CLI, CTS, CLS, IL, JIT)

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.