NET Core Composition System
- Brief analysis of. NET Core Composition System
- Roslyn compiler
- RyuJIT compiler
- CoreCLR & Corert
- Corefx (. NET Core Libraries)
- . NET Core code Development, deployment, and operational procedures
- Summarize
The previous article describes the status of. NET Core across the. NET platform and its relationship to the. NET Framework (source link), this article details the composition of the. NET Core Framework and the main features of each module, and how to implement cross-platform.
Describes the system composition of. NET Core, the top tier is the application layer, which is the development of a framework set based on the UI application, including the ASP (for creating Web apps), and the UWP (for creating the Windows10 app).
The middle tier is a public library (COREFX) that implements the. NET standard library, which includes common system-level operations such as files, networks, and so on.
Under Corefx is the runtime environment,. NET Core contains two runtimes (CoreCLR, Corert), and CoreCLR is a runtime based on the instant compiler program (Just in Time Compiler,jit). It uses the cross-platform open source compiler Ryujit, and Corert is the runtime using the advance compiler (Ahead of Time Compiler,aot), which can either use Ryujit to implement AOT compilation or use other AOT compilers. Because AOT compiles IL into machine code, it also has better start-up speed and energy saving on mobile devices.
Finally, I want to mention an open source cross-platform source code compiler Roslyn, which differs from just two compilers, JIT and AOT compilers are primarily used to compile IL machine code, and Roslyn is to compile C # or vb.net code into a program intermediate language (intermediate Language,il).
Roslyn compiler
The Roslyn compiler is used to compile C # or vb.net code into an assembly (assembly), and its compilation process is a pipelined process with a total of 4 steps, as described in the procedure.
A. Parser (parsing)
Parses the source code according to the syntax.
B. Declaration (statement)
To generate metadata for code (metadata), metadata is a collection of data tables that describe the data types and members defined in the current code, as well as the types and members of the references.
C. Bind (BIND)
The generated IL code is bound together with the metadata that describes it, generating a managed module (managed module).
D. Emit (generated)
Merges one or more managed modules into the Build assembly (assembly).
RyuJIT compiler
In the program to run a certain method, the first need to convert the compiled IL to the machine code of the machine, and this task is given to the Ryujit. It is a new generation of JIT compilers that, for the first time, implemented the AMD64 architecture, Ryujit able to generate code faster than JIT64 (the previous generation compiler) to improve program efficiency (test detail link).
CoreCLR & Corert
Both. NET core runtime (CoreCLR) and. NET Core runtime (Corert) are the runtime (runtime) of. NET Core.
They provide core functionality similar to the. NET Framework CLR (memory management, assembly loading, security, exceptions, thread management, and so on) that can be used by all languages that are intended for the runtime.
Corert and CoreCLR are different, Corert provides a set of
AOT mechanism, you can compile the. NET core program into native code and run on the host machine without relying on. Net. In addition to the two runtime most of the function code is shared, such as GC. The AOT optimization brings many benefits:
Compiled into a single file containing all dependencies, including Corert, without the need to install the framework
Machine code on startup, no machine code required and no JIT compiler to load
Other optimization compilers can be used, including LLILC, IL to CPP
Corert There are two ways to generate machine code, the first use is to directly compile IL into machine code, by default, RyuJIT as an AOT compiler to compile IL into machine code, another way is to compile C # code into C + + code, and then call the corresponding platform C + + compiler optimization compiled into machine code.
Compiling machine code using RyuJIT
restoredotnet build --native --ilcpath <repo_root>\bin\Product\Windows_NT.x64.Debug\packaging\publish1
Compile to generate C + + code
restoredotnet build --native --cpp --ilcpath <repo_root>\bin\Product\Windows_NT.x64.Debug\packagingpublish1 --cppcompilerflags /MTd
Corert also has shortcomings, it needs to compile for different platforms once; but it allows engineers to not publish to platforms they do not want to support (such as a game that only supports the desktop and does not support mobile phones).
Note: Both of these names are not available in the. NET Core RC2 version, which is officially removed from the current version, and is not known until the official version of June 27 is issued.
Corefx (. NET Core Libraries)
Corefx mainly contains several public libraries, such as System.Collections, System.IO, System.Xml, etc. Corefx is the implementation of the. NET Standard library, and the same. NET Framework 4.6.3 is also based on the. NET Standard library implementation. They are currently based on the. NET standard Library1.6 version, as detailed in the following table:
. NET Core code Development, deployment, and operational procedures
You can see that using JIT compiling and using AOT to compile source code and run programs are two different processes.
If you are using the JIT compiler to deploy a program with only the assemblies of the program packaged as IL, the compiler compiles the IL to the target machine code (Native code) before the method executes the first time, and AOT compilation compiles the source code directly to the target machine code at compile time.
The AOT compiles the source code into machine code and has the following features:
Replace the reflection with static code, for example, if a value type is not overridden by the Equals method of Valuetype.equals, the default is equal, and the reflection is used to find the filedinfo to determine whether the type is equal, The value is then compared for equality. In AOT compilation, you can only compare value for equality because it replaces reflection.
Dependent third-party class libraries and. NET libraries are packaged into the final compiled program.
The packaged program runs on a compact version of the runtime (Corert) primarily contains the garbage collector, and the runtime is packaged in an app file.
Although the reflection code is replaced at compile time, when the dynamic reflection code is powerless, the runtime throws an exception if the corresponding metadata and implementation are not found when the dynamic reflection call is encountered. The workaround is to configure the run-time Directive file (runtime, Directive file) to specify the assembly to use before compiling.
Summarize
This section describes the architecture of. NET core, including the addition of multiple compilers and the Corefx of the. NET Standard library, which, overall, has a significant improvement in performance and development efficiency compared to the previous. NET Framework.关键是首次实现了.NET的完全跨平台能力的基础技术栈。
. NET core is based on cross-platform capabilities and does not migrate GUI-height-related APIs into. NET core, 因此像是 Windows Forms 或是 Windows Presentation Foundation (WPF) 并未移植到 .NET Core。
. NET Core Support Console Application (console application), and class library Type of project.
However, Microsoft uses. NET Core in its Universal Windows Platform (UWP) development platform and leverages.NET Native 技术将其性能提升至十分接近原生码的速度。
ASP. NET core drives its managed environment to Kestrel Server
support the operation of the ASP. NET Core program with a console application.
There are any errors or inaccuracies in the above content please correct me, do not like to spray!
The source of the handsome insects: http://www.cnblogs.com/vipyoumay/p/5613373.html
This article is copyright to the author and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility. If you feel that there is help, you can click on the lower right corner of the "recommendation", hoping to continue to bring good technical articles for everyone! Want to make progress with me? Then "pay attention" to me.
Reference links
"1" https://github.com/dotnet/corefx/blob/master/Documentation/architecture/net-platform-standard.md
"2" Https://github.com/dotnet/corefx
"3" https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/glossary.md
"4" https://www.microsoft.com/net/core#windows
"5" https://msdn.microsoft.com/en-us/library/dn807190 (v=vs.110). aspx
"6" https://blogs.msdn.microsoft.com/dotnet/2013/09/30/ryujit-the-next-generation-jit-compiler-for-net/
"7" Https://zh.wikipedia.org/wiki/.NET_Core
Category: NET core Tags:. NET core, ASP. RyuJIT
NET Core Composition System