Successfully reported this slideshow.
Your SlideShare is downloading. ×

From 'dotnet run' to 'hello world'

From 'dotnet run' to 'hello world'

Download to read offline

Have you ever stopped to think about all the things that have to take place when you execute a .NET program? As the quote from Neal Ford says "Understand one level below your usual abstraction", this talk will look at why this is important and how can it help you if we apply it to the .NET framework. We will delve into the internals of the recently open-sourced .NET Core Runtime, looking at what happens, when it happens and why. Using freely available diagnostic tools such as PerfView, libraries including ClrMD and even the source code itself! Along the way 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 a 'Hello World' app possible.

Have you ever stopped to think about all the things that have to take place when you execute a .NET program? As the quote from Neal Ford says "Understand one level below your usual abstraction", this talk will look at why this is important and how can it help you if we apply it to the .NET framework. We will delve into the internals of the recently open-sourced .NET Core Runtime, looking at what happens, when it happens and why. Using freely available diagnostic tools such as PerfView, libraries including ClrMD and even the source code itself! Along the way 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 a 'Hello World' app possible.

More Related Content

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

From 'dotnet run' to 'hello world'

  1. 1. From ‘dotnet run’ to “Hello World” @matthewwarren mattwarren.org
  2. 2. From ‘dotnet run’ to “Hello World” http://raygun.com/apm
  3. 3. I ❤ ‘.NET Internals’
  4. 4. Understand one level below your usual abstraction Neal Ford
  5. 5. Demo – “Hello World”
  6. 6. Outline • Main Components • Hosting the runtime • CLR Initialisation • Type Loader • JIT Compilation • Everything Else
  7. 7. Main Components
  8. 8. CoreCLR Repository • 2.6 million of source code, under src • 8.2 million lines of test code • 24,485 Files (7,466 source & 17,019 test) – 6,626 C# (956 source & 5,670 test) – 2,074 C and C++ – 3,701 IL – 93 Assembler, 43 Python & 6 Perl!!
  9. 9. Virtual Machine (VM) • Type System, Generics • Built-in Types • Loading types/classes • Threading • Exception Handling and Stack Walking • Event Tracing and Profiling • P/Invoke
  10. 10. Hosting
  11. 11. 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
  12. 12. Demo – Hosting API
  13. 13. Initialisation
  14. 14. 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/
  15. 15. Demo - PerfView
  16. 16. ImageCourtesyof JuliaEvans @b0rk–jvns.ca
  17. 17. https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/fundamentals
  18. 18. Type Loader
  19. 19. http://mattwarren.org/2017/06/15/How-the-.NET-Rutime-loads-a-Type/
  20. 20. JIT Compilation
  21. 21. http://mattwarren.org/2017/12/15/How-does-.NET-JIT-a- method-and-Tiered-Compilation/ Before JIT-ing
  22. 22. http://mattwarren.org/2017/12/15/How-does-.NET-JIT-a- method-and-Tiered-Compilation/ Before JIT-ing After 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 with ‘Tiered Compilation’
  24. 24. http://mattwarren.org/2017/12/15/How-does-.NET-JIT-a- method-and-Tiered-Compilation/ After JIT-ing with ‘Tiered Compilation’ - Optimised
  25. 25. Everything Else
  26. 26. Marshalling and P/Invoke
  27. 27. 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
  28. 28. I ❤ ‘.NET Internals’ AMA

Editor's Notes

  • We’re Engineers, we love knowing what’s going on ‘under the hood’
    Helps with Perf (Ben Adams, Kestrel, TechEmpower, deep JIT knowledge)
    As a community we should understand our ecosystem

  • mscorlib is now System.Private.CoreLib
  • mscorlib is now System.Private.CoreLib
  • mscorlib is now System.Private.CoreLib
  • mscorlib is now System.Private.CoreLib
  • mscorlib is now System.Private.CoreLib
  • mscorlib is now System.Private.CoreLib
  • mscorlib is now System.Private.CoreLib
  • mscorlib is now System.Private.CoreLib
  • Phase 1 – Config, ThreadManager, ETW Events, Diagnostics & Perf logs
    Phase 2 – Assembly Binding (aka “Fusion”), Perf Counters, Stub Manager, Debugger Manager
    Phase 3 – Also initial runtime thread is started
    Phase 4 – Code Access Security (CAS), Stack Probes,
    Phase 5 - Set-up all the shared static variables
  • Partially filled in ‘data structures’
    More data is added at each step
    A class can only progress through the steps if it’s dependencies also progress

×