".NET Framework Program Design" Chapter 1 Microsoft .NET Framework Development Platform Architecture

xiaoxiao2021-03-06  77

Chapter 1 Microsoft .NET Framework Development Platform Architecture

First, compile the source code as a managed module:

1, the existence of CLR is that we can choose a language suitable for expression logic, as long as there is a corresponding compiler to compile the code into a CLR-facing code, the result is a managed module.

2. Managed Module: It is a standard Windows portable (Portable Executable: PE) that requires CLR to execute (PE), which consists:

1) PE header: pointing out the file type, the time tag of the file

2) CLR header: CLR version, managed module entrance, metadata, resources, strong naming, tag, etc.

3) Metadata: The type and member of the source code, reference

4) Intermediate Language (IL) code

About metadata:

l always synchronize with IL code

l To save the demand for header files and library files when compiling

Lvisual Studio .NET utilizes intelligent perception, auxiliary encoding

l Code verification for CLR

l Serialization and reverse sequence

l Garbage collector can track the survival of the object

Second, combine the managed module as an assembly

About the understanding of the assembly: Temparent

Third, load the general language operation

1. By finding the MSCoree.dll file in the% window% / system32 directory to determine if a .NET framework is installed in a machine; and the version of the frame can be from the sub-key under the registration:

HKEY_LOCAL_MACHINE / SOFTWARE / Microsoft / .Netframework / Policy View

2. When generating an EXE program set, the compiler / linker generates some special information and embeds them into the PE file header of the result assembly and its respective components .Text section. When the EXE file is called, these special information will cause the CLR to be loaded and initialized. The CLR will then be positioned to the entry point method of the winning program, and start the application from the face.

Similarly, if an unmanaged application is loaded by calling LoadLibrary, the entry point function of the managed assembly DLL will also know that the CLR is loaded to handle the code included there.

3, other processes such as Exe assemblies or DLL assemblies can be performed after examining the execution of ordinary Windows PE files to clearly implement the process

Fourth, execute assembly code

1, IL code: an object-oriented machine language. You can understand the object type, including advanced instructions: create and initialize the object, call the imaginary method on the object, direct operating array element, throw and capture abnormalities;

IL assembly language can get all the features of the CLR, other advanced language intelligence acquisition one of the subsets;

The IL code is independent of the CPU platform, and when executed, it must be compiled by the instant compiler (Just In Time Compiler);

Microsoft's IL assembler: ILASM.EXE reverse system: ILDasm.exe.

2, IL code execution process:

The following code segment is:

Static void

Main

()

{

Console.writeline ("Hello");

Console.Writeline ("Go Albye");

}

0) Before the code is executed:

The CLR first detects all the types referenced by the MAIN, and assigns a data structure to record this type, each method for the data structure allocates a corresponding entry, logging the method to implement the address of the code; initialize the structure, each method A function (undefined function) set to the interior of the CLR

1) When executed for the first time

When a function is called in the above-described structure, JitComPlier is locked by the type and address information of the function in the metadata of the assembly, and these IL code verifies and compiles the CPU instructions These CPU instructions are saved. A dynamically assigned memory, and the address of the data structure in the data structure is replaced with the address of the local CPU instruction in the step. 2) The second time is executed

If the called function has been verified and compiled, it is called directly from memory.

If it is not called, repeat the case when the first execution is performed.

3, performance

The hosted code may be better than non-hosting code efficiency:

The LJIT compiler detects a new CPU and produces special instructions provided for these CPUs to optimize execution efficiency.

The LJIT compiler detects a Boolean test that is always returned, and does not generate a CPU instruction for the code segment of the letter to make the code amount, more efficient.

LCLR is targeted in runtime, recompacted some IL code, reorganizes the success rate of branch prediction.

4, NGEN.exe provides a discharier, providing a pre-compiled version for the IL code to avoid compilation of runtime.

5, IL code verification:

- Verified code to "unsafe" will throw system.security.VerificationException exception

- Code verification makes it possible to run multiple hosting applications in a Windows process.

More discussion in 20 chapters

V. .NET Framework library (FCL)

CLR and FCL allow developers to create the following applications:

LXML Web Service

LWEB form

LWINDOWS form

LWINDOWS console application

LWindow Service

l component library

Making a specific application, the key is familiar with the corresponding FCL, then first, it is familiar with the .NET Framework.

Sixth, common type system (Common Type System)

Describe the specification of the type in CLR

Members of types:

l field: indicating the status of the object

l method: used to change the state

l Attribute: Provide functions such as input parameter authentication, state validity testing, and necessary evaluation operations on state access

l Event: Notification Mechanism between objects

Some rules of type visibility and access type members:

LpriVate: can only be accessed by code in the same type

LFamily: Can be called by code in the derived class, regardless of whether it is in the same program

LFamily and Assembly: Detective class code calls that can be located in the same program

LASSEMBLY: Code can only be called by the same program

LFamily or Assembly: Can be called by the derived class code in any assembly, or any type of call in the same program

LPUBLIC: Any code call can be called by any program

Seven, common language specification (Common language specification)

To make a language created by a language seamlessly accessed by other languages, Microsoft defines a Universal Language Normative (CLS). The characteristics supported by CLR / CTS are much larger than the CLS definition, and there is a subset of the CLR / CTS feature, and CLS is a intersection of all language features (a collection of minimum characteristics).

Therefore, only the type of CLS can be used by other languages, applications, and C #:

[Assembly: CLSCompliant (TRUE)]

Forcing the compiler to ensure that the part that does not meet the CLS is eliminated in the public export type.

Eight, interoperability with non-hosting code

To avoid re-implementing all existing code, the CLR is designed to include hosting parts and non-hosting parts, and CLR supports three interoperability:

l Hosting code calls the non-hosting function in the DLL

l Managed code uses existing COM components

l Availability code uses managed types

转载请注明原文地址:https://www.9cbs.com/read-121364.html

New Post(0)