Presentation is loading. Please wait.

Presentation is loading. Please wait.

.NET and .NET Core: Languages, Cloud, Mobile and AI

Similar presentations


Presentation on theme: ".NET and .NET Core: Languages, Cloud, Mobile and AI"— Presentation transcript:

1 .NET and .NET Core: Languages, Cloud, Mobile and AI
2. Runtime and Assembly Pan Wuming 2018

2 Topics .NET Framework Common Language Runtime (CLR) Example
Language integration Assembly: Application Unit Metadata Runtime host Application domains Key Terms

3 Functional Programming
CLR in .NET Framework Programming Languages for .Net Managed Web Applications ASP.Net Runtime Managed Applications C# Foundation Class Library VB IIS CLR OS and Hardware C++ F# Functional Programming Unmanaged Applications Python R Javascript Typescript

4 WPF: Modern graphical display system for Windows
Built-in hardware acceleration Resolution independence The underlying graphics technology is DirectX Graphics, media and animation as the first-class programming concepts A web-like layout model Declarative user interface Programming: XAML whether you’re designing complex three-dimensional graphics (DirectX’s forte) or just drawing buttons and plain text, all the drawing work travels through the DirectX pipeline.

5 WCF: New Programming Model to increases a developer’s productivity
Earlier technologies will continue to work unchanged A WCF component can be hosted in any kind of environment, be it a console application, a Windows application, or IIS. Services Share the Schema and Contract, Not the Class COM/DCOM, Microsoft Message Queuing (MSMQ), Microsoft Transaction Server (MTS), COM+ ASMX, ASP.NET web services, Web Services Enhancements (WSE), Enterprise Services, System.Messaging, and .NET Remoting

6 The services the .NET implementations provides
CLR Memory management. A common type system. An extensive class library. Development frameworks and technologies. ASP.NET, ADO.NET, and WCF... Language interoperability. Intermediate Language (IL) Version compatibility. Side-by-side execution. Multitargeting. Performance, Safety and Security for applications Memory management. In many programming languages, programmers are responsible for allocating and releasing memory and for handling object lifetimes. In .NET Framework applications, the CLR provides these services on behalf of the application. A common type system. In traditional programming languages, basic types are defined by the compiler, which complicates cross-language interoperability. In the .NET Framework, basic types are defined by the .NET Framework type system and are common to all languages that target the .NET Framework. An extensive class library. Instead of having to write vast amounts of code to handle common low-level programming operations, programmers can use a readily accessible library of types and their members from the .NET Framework Class Library. Development frameworks and technologies. The .NET Framework includes libraries for specific areas of application development, such as ASP.NET for web applications, ADO.NET for data access, and Windows Communication Foundation for service-oriented applications. Language interoperability. Language compilers that target the .NET Framework emit an intermediate code named Common Intermediate Language (CIL), which, in turn, is compiled at run time by the common language runtime. With this feature, routines written in one language are accessible to other languages, and programmers can focus on creating applications in their preferred language or languages. Version compatibility. With rare exceptions, applications that are developed by using a particular version of the .NET Framework can run without modification on a later version. Side-by-side execution. The .NET Framework helps resolve version conflicts by allowing multiple versions of the common language runtime to exist on the same computer. This means that multiple versions of applications can also coexist, and that an application can run on the version of the .NET Framework with which it was built. Multitargeting. By targeting the .NET Framework Portable Class Library, developers can create assemblies that work on multiple .NET Framework platforms, such as Windows 7, Windows 8, Windows 8.1, Windows Phone, and Xbox 360. Productivity for Developers

7 IL: intermediate language
.NET Application A .NET Application contains one or more Assemblies An assembly contains Metadata and IL Code, and resources, within one or many files A .NET Application must run in a host environment The execution of a .NET Application is Managed by CLR IL: intermediate language Self-Host?

8 .NET runtimes Common Language Runtime (CLR) for the .NET Framework
Core Common Language Runtime (CoreCLR) for .NET Core .NET Native for Universal Windows Platform The Mono runtime for Xamarin.iOS, Xamarin.Android, Xamarin.Mac, and the Mono desktop framework

9 Managed execution process
Choosing a compiler. Compiling your code to MSIL. Compiling MSIL to native code. Running code. Managed By CLR Create Assembly

10 CLR Services Class Layout Security JIT Compiler Other Runtime Services
Type Awareness Exception Integration JIT Compiler Other Runtime Services Class Layout Memory & GC Security

11 Common Language Runtime (CLR)

12 The Roles of CLR Compiler Assembly Development Source code C# VB F# …
public static void Main(String[] args ) usr=Environment.GetEnvironmentVariable("USERNAME"); try { { String usr; FileStream f; StreamWriter w; w.WriteLine(usr); w=new StreamWriter(f); f=new FileStream(“C:\\test.txt",FileMode.Create); Console.WriteLine("Exception:"+e.ToString()); } catch (Exception e){ w.Close(); } Compiler public static void Main(String[] args ) usr=Environment.GetEnvironmentVariable("USERNAME"); try { { String usr; FileStream f; StreamWriter w; w.WriteLine(usr); w=new StreamWriter(f); f=new FileStream(“C:\\test.txt",FileMode.Create); Console.WriteLine("Exception:"+e.ToString()); } catch (Exception e){ w.Close(); } Source code C# VB F# MSIL Metadata Resources

13 Global Assembly Cache (GAC) Application Directory
The Roles of CLR Assembly Development Compiler Assembly Development C# VB F# MSIL Metadata Resources public static void Main(String[] args ) usr=Environment.GetEnvironmentVariable("USERNAME"); try { { String usr; FileStream f; StreamWriter w; w.WriteLine(usr); w=new StreamWriter(f); f=new FileStream(“C:\\test.txt",FileMode.Create); Console.WriteLine("Exception:"+e.ToString()); } catch (Exception e){ w.Close(); } Source code Global Assembly Cache (GAC) Install Setup Copy Browser Application Directory Download Cache

14 The Roles of CLR Assembly on Target Machine
Development Application Directory Setup Copy Browser Download Cache Deployment Assembly on Target Machine Global Assembly Cache (GAC) Install Policy <security> <mscorlib> <configuration> <?xml version="1.0" encoding="utf-8" ?> <policy> version="1" <CodeGroup class="UnionCodeGroup" <PolicyLevel version="1"> PermissionSetName="Nothing" Description="Code group grants no permissio ns and forms the root of the code group tree."> Name="All_Code" <IMembershipCondition clas s="AllMembershipCondition" version="1"/> PermissionSetName="FullTrust" Execution IL to Native Compiler Class Loader Security Assembly Loader Garbage Collection Native code + GC table Code Manager Exception Manager Thread Support COM Interop Debug Engine

15 JIT Process JITCompiler function {
Method Structure to Console static void WriteLine() Managed.exe JitCompiler static void Main() { Console.WriteLine("Hello"); Console.WriteLine("GoodBye"); } static void WriteLine(string) JitCompiler (remaining members) JitCompiler MSCorEE.dll Native CPU instructions JITCompiler function { In the assembly that implements the type (Console) look up the method (Writeline) being called in metadata. From the metadata, get the IL for this method. Allocate the block of memory. Compile the IL into native CPU instructions; the native code is saved in the memory allocated in step 3. Modify the method's entry in the Type's table so that it now points to the memory block allocated in step 3. Jump to the native code contained inside the memory block. }

16 Console Managed.exe MSCorEE.dll static void WriteLine() JitCompiler
static void Main() { Console.WriteLine("Hello"); Console.WriteLine("GoodBye"); } static void WriteLine(string) Native CPU instructions Native (remaining members) JitCompiler MSCorEE.dll JITCompiler function { In the assembly that implements the type (Console) look up the method (Writeline) being called in metadata. From the metadata, get the IL for this method. Allocate the block of memory. Compile the IL into native CPU instructions; the native code is saved in the memory allocated in step 3. Modify the method's entry in the Type's table so that it now points to the memory block allocated in step 3. Jump to the native code contained inside the memory block. }

17 Benefits of Presence of the CLR
Performance improvements Cross-language integration Cross-language exception handling Enhanced security Versioning and deployment support A simplified model for component interaction Debugging and profiling services.

18 Example: Language Integration
C# Project A Static Public Method It will be used for F#, C++ and VB codes

19

20

21 F#

22 C++

23 The previous C# Assembly used by a VB project
Similar XAML UI Two controls: a textbox and a button A method delegate for button’s Click event

24

25

26

27

28 Assembly: Application Unit
Contains Code Security boundary. Type boundary Reference scope boundary Version boundary Deployment unit To support Side-by-side execution

29

30 Manifest Enumerates the files that make up the assembly.
Governs how references to the assembly's types and resources map to the files that contain their declarations and implementations. Enumerates other assemblies on which the assembly depends. Provides a level of indirection between consumers of the assembly and the assembly's implementation details. Renders the assembly self-describing.

31 GAC and Strong-Named Assembly
Global Assembly Cache: Machine-wide Code Cache Strongly Named Assemblies Are Tamper-Resistant Strong-Named the simple text name the version number optional culture information a digital signature, and the token of the public key that corresponds to the private key used for signing. Delay Signing or Partial Signing an Assembly Assemblies deployed in the GAC must have a strong name

32 Signing an assembly

33 The AssemblyRef metadata information

34 Metadata within a PE File
Win32 Portable Executable File Format

35 Metadata Tables and Heaps
Each metadata table holds information about a certain type of elements of your program Method, type, and so on Metadata also stores information in four heap structures String Blob: binary objects of arbitrary size user string GUID: 16-byte binary objects Metadata tokens are used in MSIL to reference a row of a particular metadata table.

36 Application Domains Application domains are typically created by runtime hosts To provide isolation between assemblies Objects that pass between domains are either copied or accessed by proxy

37 Runtime Hosts Shell executables IE ASP.NET Before any managed code can be executed, the host must load and initialize the CLR. Loads the runtime into a process Creates the application domains within the process Loads user code into the application domains The hosting APIs All hosts start with an unmanaged stub because the runtime is not yet running in the process. C++! #include <metahost.h> #pragma comment(lib, "mscoree.lib") hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*)&pMetaHost);

38 Class library: types of applications and services
Paradigms Evolving and Abstracting Console applications. Windows GUI applications (Windows Forms). Windows Presentation Foundation (WPF) applications. ASP.NET applications. Windows services. Service-oriented applications using Windows Communication Foundation (WCF). Workflow-enabled applications using Windows Workflow Foundation (WF).

39 Finally, These are the key words:
Common Language Runtime (CLR) Assembly Metadata Manifest Global Assembly Cache(GAC) Strong Named Assembly Intermediate language (IL) Delay Sign JIT Complier Application Domains


Download ppt ".NET and .NET Core: Languages, Cloud, Mobile and AI"

Similar presentations


Ads by Google