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.
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.
10.
11.
12.
13.
14.
15.
16.
17. Virtual Machine (VM)
• Type System, Generics
• Built-in Types
• Loading types/classes
• Threading
• Exception Handling and Stack Walking
• Event Tracing and Profiling
• P/Invoke
19. 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
22. 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/
39. 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
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