1 / 23

.NET Native deep dive

.NET Native deep dive. Andrew Pardoe ( andrew.pardoe@microsoft.com ) .NET Native ( dotnetnative@microsoft.com ) Program Manager, .NET Runtime. Questions?. .NET code g eneration: A primer. MSIL bytecode. Source code (C#/VB/F#). Machine code. C#/VB/F# compiler. Code generation.

catrin
Télécharger la présentation

.NET Native deep dive

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. .NET Native deep dive Andrew Pardoe (andrew.pardoe@microsoft.com) .NET Native (dotnetnative@microsoft.com) Program Manager, .NET Runtime

  2. Questions?

  3. .NET code generation: A primer MSIL bytecode Source code (C#/VB/F#) Machine code C#/VB/F# compiler Code generation • Code generation is done either…. • Lazily at runtime with a Just-In-Time, or JIT, compiler • Optimistically at build time with NGen, Triton or .NET Native

  4. .NET Code Execution today C++ Performance Self-contained apps Dynamic experience “Unlimited” class libraries

  5. Code execution in CLR 4.5 • Code generation • One JIT compiler for each architecture • 64-bit JIT emphasizes code quality over throughputfor server scenarios • 32-bit JITs emphasize throughput over code quality for app scenarios • Two native code generators with different deployment properties • NGen runs on the user’s machine, at install time or automatically • Triton runs in the Windows Phone 8 Store, app bound to libraries at install • One runtime (VM or VEE) spans multiple scenarios • Desktop CLR for Windows Client and Server workloads (different GC modes) • CoreCLR for Mobile and targeted Server workloads built from the same codebase

  6. Triton: Native code on Windows Phone • C# • MSIL • MDIL •  • native • code • MSIL MDIL Windows Phone apps are compiled to native code in the cloud on WP8

  7. The properties of code execution • Code generation properties • Throughput • Code quality • Memory usage • Deployment properties • Distribution format • Acquisition process • Serviceability • Security properties • Typesafe execution • Code identity & isolation • Security functionality • Developer experience • Everything is a tradeoff! • “Make simple things easy and hard things possible.”

  8. .NET Code Execution tomorrow .NET Native RyuJIT& CLR VM C# Language with dynamic experiences C# Productivity with C++ Performance Today: One runtime engine & same code execution for all scenarios Tomorrow: Refactored engine & multiple execution strategies provide best of class on both extremes. From there, we target the middle.

  9. .NET Native (Project N)

  10. .NET Native

  11. .NET Native • Next Generation Compiler in the Cloud for Store Apps represents an evolution of Triton & NGen • Uses lean runtime and VC++ optimizer for fast code execution and reduced memory usage • Based on a refactored CLR engine. Native code is shared, managed code has moved into the libraries • Provides converged developer experience for .NET across devices . Wordament on .NET Native:

  12. Visual Studio Experience for .NET Native Debug and test your app with .NET Native Enable .NET Native for your project

  13. .NET Native Compiler Toolchain

  14. IL Compiler: C# -> MSIL • Compile C# source code • Generate & compile marshalling and serialization code

  15. Pregenerated interop code • Today, interop code is generated as MSIL at runtime, JIT-compiled, executed and thrown out • JIT compilation takes time (but the methods are small) • If your P/Invoke signature has an issue your compiled code is gone • In .NET Native, the Marshalling Code Generator creates interop code as a C# file at compile-time • Compilation is done at build-time • The code can be debugged as C#, not assembly • The code can be inspected and optimized before compilation to MSIL

  16. IL Compiler: Merge & reduce app code • Merge all app & library code • “Reduce” app to throw away unneeded types, code, metadata, etc.

  17. Static dynamic code (dynamic static code?) • A bit of a conundrum… • Static compilation means any code that can run is generated at compile-time • Reflection requires that anything you can inspect at runtime can be executed • The solution: preserve the set of classes, methods, generic types, etc., that the code might want to call • And if the compiler gets it wrong? • Missing metadata results in an exception • File a bug with the .NET Native team?

  18. Runtime directives (default.rd.xml) • The type specifies the class, namespace or assembly affected • Types: class, interface, or struct • Group of types: namespace, assembly (*Application* is all types in the app assemblies) • Type member: method, field, property, or event • The degree tells the compiler what behavior is needed • Reflection behaviors, Serialization behaviors, Interop behaviors • The policy notes the scope to apply that behavior inside the type • Accessibility: All, Public, Private, Internal • Required: Including this keyword means “Include these types in the final binary” <Directivesxmlns="http://schemas.microsoft.com/netfx/2013/01/metadata"> <Application> <AssemblyName="*Application*"Dynamic="Required All" /> <!-- Add your application specific runtime directives here. --> </Application> </Directives>

  19. IL Compiler: MSIL -> MDIL -> machine code • C++ optimizer compiles MSIL to MDIL, Machine Dependent Intermediate Format. App is mostly machine code but cannot execute. • “Bind” MDIL app code into machine code. App distributed as a stub, app.exe, and app code in a dll. MRT Runtime is distributed in the app package, making the app package self-sufficient.

  20. Example: automatic vectorization/parallelization for (long j = 0; j < numBodies; j++) // From Nbody sample { Float_4 r; r.x = A[j].pos.x - B.pos.x; r.y = A[j].pos.y - B.pos.y; r.z = A[j].pos.z - B.pos.z; floatdistSqr = r.x * r.x + r.y * r.y + r.z * r.z; distSqr += softeningSquared; floatinvDist = 1.0f / (float)Math1.Sqrt(distSqr); floatinvDistCube = invDist * invDist * invDist; float s = fParticleMass * invDistCube; acc.x += r.x * s; acc.y += r.y * s; acc.z += r.z * s; } The C++ optimizer can recognize this code as parallel and generate vector (SIMD) instructions

  21. .NET Native performance gains Optimized runtime Refactored core libraries Pregeneratedserializers Pregenerated interop Tree-shaken code Pay-for-play metadata C++ optimizer Global optimizations

  22. .NET Native: Call to action Learn more about .NET Native • http://aka.ms/dotnetnative • http://blogs.msdn.com/b/dotnet Download the .NET Native VS add-In • http://aka.ms/dotnetnative • Requires Visual Studio 2013 Update 2 RC Try out your Store app with .NET Native • Do you have a top Store app or library? • Reach out to us: dotnetnative@microsoft.com • Participate in the .NET Native Forum • Reach out to us: dotnetnative@microsoft.com Help us make .NET Native better

  23. We would love to hear from you! Blog E-mail dotnet UserVoice MSDN Forums @dotnet

More Related