Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

From 'dotnet run' to 'hello world'

65 views

Published on

Have you ever stopped to think about all the things that happen when you execute a simple .NET program?



This talk will delve into the internals of the recently open-sourced .NET Core runtime, looking at what happens, when it happens and why.



Making use of freely available tools such as 'PerfView', we'll examine the Execution Engine, Type Loader, Just-in-Time (JIT) Compiler and the CLR Hosting API to see how all these components play a part in making 'Hello World' possible.

Published in: Internet
  • Be the first to comment

  • Be the first to like this

From 'dotnet run' to 'hello world'

  1. 1. Organized by Donating to R&Devents@criteo.com criteo.com Medium.com/criteo-labs @CriteoEng #NYANconf Runtime Internals by Matt Warren NYAN conference
  2. 2. From ‘dotnet run’ to “Hello World” @matthewwarren mattwarren.org
  3. 3. www.contrastsecurity.com/contrast-community-edition
  4. 4. I ♥️‘.NET Internals’
  5. 5. Understand one level below your usual abstraction Neal Ford
  6. 6. Demo – “Hello World”
  7. 7. Outline • Main Components • Hosting the runtime • CLR Initialisation • Type Loader • JIT Compilation • Everything Else
  8. 8. Main Components
  9. 9. CoreCLR Repository • 1.6 million LOC under src • 7.6 million LOC under tests • 22,744 Files (6,668 source & 16,076 test) – 7,290 C# (1,529 source & 5,761 test) – 3,641 C and C++ – 3,799 IL (tests) – 139 Assembly, 10 Python & 6 Perl!!
  10. 10. Virtual Machine (VM) • Type System, Generics • Built-in Types • Loading types/classes • Threading • Exception Handling and Stack Walking • Event Tracing and Profiling • P/Invoke
  11. 11. Hosting
  12. 12. Hosting API 1. Identify the managed entry point 2. Find and load CoreCLR.dll 3. Get an ICLRRuntimeHost2 Instance 4. Set start-up flags and start the runtime 5. Preparing AppDomain settings 6. Create the AppDomain 7. Run managed code 8. Clean up https://docs.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting
  13. 13. Demo – Hosting API
  14. 14. Initialisation
  15. 15. Initialising the CLR • Phase 1 - Set-up infrastructure for all components • Phase 2 - Initialise the core, low-level components • Phase 3 - Start-up the low-level components, i.e. error handling, profiling API, debugging • Phase 4 - Start the main components, i.e. GC & AppDomains • Phase 5 - Final setup and send out a notification http://mattwarren.org/2017/02/07/The-68-things-the-CLR-does-before- executing-a-single-line-of-your-code/
  16. 16. Demo - PerfView
  17. 17. ImageCourtesyof JuliaEvans @b0rk–jvns.ca
  18. 18. https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals
  19. 19. Type Loader
  20. 20. http://mattwarren.org/2017/06/15/How-the-.NET-Rutime-loads-a-Type/
  21. 21. JIT Compilation
  22. 22. http://mattwarren.org/2017/12/15/How-does-.NET-JIT-a- method-and-Tiered-Compilation/ Before JIT-ing
  23. 23. http://mattwarren.org/2017/12/15/How-does-.NET-JIT-a- method-and-Tiered-Compilation/ Before JIT-ing After JIT-ing
  24. 24. http://mattwarren.org/2017/12/15/How-does-.NET-JIT-a- method-and-Tiered-Compilation/ Before JIT-ing After JIT-ing with ‘Tiered Compilation’
  25. 25. http://mattwarren.org/2017/12/15/How-does-.NET-JIT-a- method-and-Tiered-Compilation/ After JIT-ing with ‘Tiered Compilation’ - Optimised
  26. 26. Everything Else
  27. 27. Marshalling and P/Invoke
  28. 28. Resources • http://mattwarren.org/tags/#Internals – Resources for Learning about .NET Internals – Exploring the Internals of the .NET Runtime – Tools for Exploring .NET Internals – Presentations and Talks covering '.NET Internals' • Book of the Runtime (BotR) – https://github.com/dotnet/coreclr/tree/master/Document ation/botr

×