[".NET Framework Design"] Chapter 1 Microsoft .NET Framework Development Platform Architecture

zhaozj2021-02-16  49

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-oriented code, the result is a managed module.

?

2, manage module: is a standard Windows portable-portable-portable executable that requires CLR to perform (Portable Executable: 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 and other information

3) ??????? Data: Definition in the source code, the type and member of the reference

4) ??????? Intermediate Language (IL) code

About metadata:

l ???????? always synchronize with IL code

l ???????? I save the demand for header files and library files when compiling

l ???????? Visual Studio .NET utilizes intelligent awareness, assist coding

l ???????? Code verification for CLR

L ???????? Serialization and reverse sequence

l ???????? garbage collector can track the survival of the object

?

Second, ??????????? combination of managed modules 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 ("goolbye");

}

? 0) The code is executed before:

???? CLR first detects all types referenced by the main code, and assigns a data structure to record this type, each method of the data structure allocates a corresponding entry, logging the method to implement the address of the code; initialize the structure When each method is set to a function (undefined functions) 1) ??????? first executed

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:

l ???????? JIT compiler can detect a new CPU and generate special instructions provided for these CPUs to optimize execution efficiency

l ???????? JIT 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 and higher execution efficiency.

l ???????? CLR has targetedly recompiled some IL code to improve the success rate of branch prediction at runtime.

4, NGEN.EXE provides a folding program, providing the IL code to the precompiled version 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:

l ???????? XML web service

L ???????? Web form

l ???????? windows form

l ???????? Windows console application

l ???????? window 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: indicate the status of the object

l ???????? method: used to change the state

l ???????? Properties: Provide functional input parameter authentication, status validity test, and necessary evaluation operations

L ???????? Event: Notification Mechanism between the object

Some rules of type visibility and access type members:

l ???????? private: can only be accessed by code in the same type

l ???????? family: You can be called by the code in the derived class, regardless of whether it is in the same program

L ???????? Family and Assembly: Detective class code that can only be located in the same program

l ???????? assembly: Code can only be called by the same program

l ???????? family or askEMBLY: Can be called by the derived class code in any assembly, or any type of call in the same program

l ???????? public: 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 ???????? managed code calls the non-hosting function in the DLL

l ???????? Household code uses existing COM components

L ???????? Non-hosting code uses managed types

?

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

New Post(0)