1. CLS (Common Language Specification) Public language specification
CLS is defined in ECMA (European Computer Manufacturers Association-European Computer Manufacturers Association) standards. CLS includes language interoperability rules, that is, the Code written in a CLS-compliant language can interoperate with the code written in another CLS-compliant language. This is because code written in CLS-compliant languages will be compiled into the intermediate language (IL, intermediate lanugage) code. The runtime engine executes the Il code.
VB. NET, C #, Visual C ++. net, and Visual J #. Net provided by. Net all comply with Cls. Code written in these languages will be generated by their respective compilers as an intermediate code, that is, Microsoft's intermediate language (msil). msil enables code written in. NET language to be interoperable.
2. CLI (Common Language infrastructure) Common Language infrastructure
The ECMA standard also defines the specification that is followed by the infrastructure required to execute the Il code. CLI provides common type systems and services, such as type security and managed code execution.
. net the framework mainly includes. net Framework class library (provides all.. Net Language) and the Public Language Runtime Library.
the. NET Framework provides the following infrastructure and services for each CLI specification:
1. Common Language Runtime Library (CLR): CLR consists of multiple components, these components provide runtime environment and runtime services for the Program of the application, load the msil code of the application into the Runtime Library, compile the msil code into local code, execute the code, enforce security, and provide automatic memory management and thread support. Example:
| support for base class libraries |
| thread support |
com package |
| exception manager |
Security Engine |
| type checker |
debugging engine |
Code Manager |
Compile Il as a compiler for local code |
Garbage Collector |
Class Loader |
| |
|
|
|
The Code Manager manages code during execution.
When an executable file is executed, the Class Loader loads the msil code and metadata in the file into the runtime memory. Before executing the code, the code is uploaded to the local code compiler (including the JIT (Just In Time) compiler of the CPU architecture) and compiled into the local code and instruction set. When a method is called for the first time, it will be compiled from msil to the local code. Then, the Code Compiled by the JIT will be executed during the call.
2. The general type System (CTS) provides the data types, values, and object types required to develop applications in different languages.
3. Type security: the. NET Framework ensures that operations performed on a value or object only apply to this value or object. This requires that each value or object has a type, and the value or object reference also has a type.
4. Managed code execution: Different CLR components provide infrastructure and runtime services for managed code, called managed code execution. The Managed execution process is the process of running the library to load, execute, and provide automatic memory management. There are other services, such as JIT compilation, ensuring type security, force security, and handling exceptions.
What is managed code? What is metadata?
Code running in CLR is called managed code, and those running in CLR are called unmanaged code. CLR provides an interoperability layer that allows interoperability between hosted and unmanaged code. Managed code It is a self-describing code that provides information to the Common Language Runtime Library for various runtime services. In. net, this information is stored in executable files together with msil code in the form of metadata. Metadata Is used to describe the code and the type information contained in the Code. Managed code is automatically allocated and released from memory by the garbage collection process. Managed data can only be accessed by managed code, but managed code can also access unmanaged data.
5. Parallel Execution: the. NET framework allows you to deploy multiple versions of applications on the same system through an assembly. An assembly is the basic unit for development and deployment in the. NET Framework, including msil code and metadata. The metadata contains the assembly version, name, and version of the other Assembly on which the Assembly depends. CLR uses the version information in the metadata to determine the application dependency, so that multiple versions of a program can be run in parallel.
What is an assembly?
An assembly is the basic unit for development and deployment in the. NET Framework, including the types and resources required by the application. The Assembly shared by multiple applications is implemented. Global Assembly (a global assembly can also be called a shared assembly. It has a strong name and contains the Assembly name, version, region information, digital signature, and public key information) , It is stored in Global Assembly Cache (GAC) . GAC is a cache with the entire machine scope. It contains an Assembly shared by multiple applications. A set of available programs executes version control and security configuration for applications.
Syntax for creating a key using the strong name tool: Sn-K mykey. dat
Specify the file name containing the key pair in the assemblykeyfile attribute of the Assembly: [Assembly: assemblykeyfile ("mykey. dat")]
Install, uninstall, and view shared assembly in GAC: gacutil/I or/u <Assembly>; open the % WINDIR % "assembly folder, view the Assembly installed in GAC in Windows Explorer.
3. Application domain
1 . Process : The execution boundary of an application running. When a process starts, all runtime environments allocate address space for it.
2 . application domain : the boundary of the application running. A process can contain multiple application domains. Applications in one application domain cannot directly access applications in another application domain. To access the service, you must use a proxy ( the proxy is an object used to start inter-process communication ), This isolation does not affect the application domains in a process. It is the isolation boundary provided for security, reliability, isolation, version control, and uninstallation. It is generally created by the runtime host, and the application domain provides a safer and more useful processing unit.
Iv. packing and unpacking
Packing and unpacking: the process of converting the value type to the reference type is implicit. The opposite process is unpacking and explicit.
Packing is divided into three parts:
1) allocate memory space. Including the space, method table, and synblockindex of the value type to be boxed. The latter two are used to manage the referenced objects.
2) copy the value. Copy the value to be packed in the stack to the stack.
3) return the reference of the referenced object.
The unpacking is also divided into three parts
1) Check the type to ensure that the reference type is the result of packing.
2) the pointer returns the address of the value in the reference type to be split.
3) copy the fields in the reference type to the stack.
5. Garbage collection mechanism?
Automatic Memory Management implemented by CLR. Several points that need to be clarified:
1) what is considered a recyclable object?
GC adopts certainAlgorithmTraverse all objects to find reachable objects and inaccessible objects. Inaccessible objects are recyclable objects.
2) When will it be recycled?
Generally, when memory overflow is insufficient, it is precisely the first generation when the object is full.
3) How to recycle it?
Garbage collection process to release the memory space of inaccessible objects.
4) What else do I need to do after recycling?
Avoid memory fragments on the managed stack, re-allocate the memory, and compress the managed stack.
5) To avoid the performance impact of garbage collection, the aging mechanism is adopted.