This book in the past few years fragmented read two or three times, as a classic book, should repeat read and reread, since I began to write Bo, I am also ready to think of the classic good book reread carefully read it again, and put the notes into the blog, good memory than bad writing, but also in the process can deepen their understanding of the depth, And, of course, it's shared with friends in the technology community.
Assembly
- Description: A collection of one or more type definition files and resource files
- Features: Reusable, protected, versioning-able units
- Build: Can be generated from the C # compiler (or other compiler) or AL.exe
- Composition
- Managed modules (module)
- PE head, PE32 or pe32+, information for CPU architectures
- CLR header, CLR-oriented information, versions, portals, metadata, etc.
- metadata, source code type member definitions and reference type member definitions
- Il code, compiler-generated managed code, object-oriented machine language
- Resource file
- Assembly manifest
CPU Architecture
Three versions of the CLR for x86, x64, and IA64 three platforms, with information contained in the PE header
- Cross-CPU Architecture: Use ANYCPU, compatible with all CPU architecture platforms
- Specify CPU Architecture: Use a specific CPU architecture when considering the platform-specific nature of unmanaged interfaces when interacting with unmanaged
/switch |
Managed modules |
x86 windows |
x64 windows |
IA64 windows |
AnyCPU |
pe32/not specified |
32 Guests |
64 guests |
64 guests |
x86 |
Pe32/x86 |
32 Guests |
Wow64 Run |
Wow64 Run |
x64 |
Pe32+/x64 |
Do not run |
64 guests |
Do not run |
Itanium |
Pe32+/itanium |
Do not run |
Do not run |
64 guests |
Meta data
- Compile-time support, all information that already contains and refers to the type/member
- IntelliSense (Intelligence), members (methods, properties, events, and fields) and method parameters
- Verifying type safety
- Reflection and serialization (object activation and object rebuilding)
- Garbage collection, the garbage collector can determine object types and reference information for object fields
Execution process
- To determine if there is a compiled local code, or if there is a direct execution (3), the JIT compiler is turned on
- Start JIT compilation (MSCorEE.dll)
- Finding invocation information in metadata (methods, etc.)
- Gets the IL of the call information
- Allocating memory Blocks Dynamicmemory
- Compile IL as local CPU instruction, and store to Dynamicmemory
- Modify the Type table call pointer to point to Dynamicmemory
- Jump to local code in Dynamicmemory
- Executing local code (CPU instructions)
Compilation process
There are two C # compiler switches that affect the optimization of your code:/optimize and/debug, see the following table:
compiler switch Settings |
C # IL code quality |
JIT native code Quality |
/optimize-/debug (default) |
Not optimized |
Have optimized |
/optimize-/debug (+/full/pdbonly |
Not optimized |
Not optimized |
/optimize+/debug (-/+/full/pdbonly |
Have optimized |
Have optimized |
Comparison of advantages and disadvantages:
- Not optimized (/optimize-), not optimized IL code, contains many NOP (no-operation) directives, and also contains branch instructions, with the advantage of even debugging
- Optimized IL code, the compiler removes redundant NOP and branch instructions, and the code is smaller, but it is difficult to debug one step at a time
Compiler default Debug Configuration
- Debug:/optimize-/debug:full
- Release:/optimize+/debug:pdbonly
Performance Artifact –jit
- When you compile il as native code, you understand the environment more profoundly than other compilers
- Generate instructions for specific CPUs to efficiently leverage resources from different platforms to improve efficiency
- Optimize code to make IL lighter and easier to understand
Chicken? NGen.exe
Advantages:
- Pre-compilation saved on disk for faster start-up
- Reduce working set, shared code between processes (through memory mapping)
Disadvantages:
- No optimizations for code
- Poor execution time performance (no specific CPU instruction optimizations, run-time fields are not directly accessible)
Deployment
|
Private deployment |
Global deployment |
Weakly Named Assemblies |
Support |
Not supported |
Strong-Named Assemblies |
Support |
Support |
Private assembly Deployment Characteristics: Reference assemblies are stored in the base directory or subdirectories of the base directory
Detection range: Base Path-Configuration path-same name sub-path-language culture sub-directory
Private assembly Directory Configuration:
<configuration> <runtime> <assemblybinding xmlns= "Urn:schemas-microsoft-com:asm.v1" > <probing privatepath= "Auxfiles1,auxfiles2"/> </assemblyBinding> </runtime></ Configuration>
Others (other Tips)
SDK Tools
- Il compilation and anti-compilation –ilasm.exe/ildasm.exe
- CLRVer.exe viewing the CLR version
- DumpBin.exe and CorFlags.exe, view the information embedded in the managed module
- Security Check tool: PEVerify.exe
Il is an intermediate language, supports mixed programming, C # just takes advantage of a subset of the CLR, and IL is fully clr-oriented
CLR Startup portal (MSCorEE.dll) (3 CPU Architectures 3 versions, responsible for loading assemblies)
WOW64 can simulate x86 instruction set
CLS Language Specification, specification for interoperability between mixed languages [Assembly:clscompliant (True)]
Language interoperability
- Managed code calls an unmanaged function in a DLL (PInvoke platform invoke)
- Managed code uses existing COM components
- Unmanaged code uses managed types
- Open Source implementation: http://CLRInterop.CodePlex.com
Response file, RSP file, contains some compile switch parameters, System global response file automatically references default assembly
Assembly Search Directory and order
- Working directory
- CSC.exe itself directory
- /lib The specified directory
- The directory specified by the LIB environment variable
Multi-file assembly, the compiler will merge module, addmodule switch, can also use AL.exe, useful:
- Separate file storage type, allow incremental updates, batch package/deploy
- Embed Resources
- Different languages are implemented and then merged
Assembly culture
- Language culture includes specific cultural or cultural neutrality
- Satellite assemblies, accessing resources for satellite assemblies using System.Resources.ResourceManager
- Setting mode 1:al.exe/culture 2:[assembly:assemblyculture ("De-ch")]
Reading notes-CLR via C # Chapter 1-2