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.
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
From 'dotnet run' to 'hello world'
1. Organized by Donating to
R&Devents@criteo.com
criteo.com
Medium.com/criteo-labs
@CriteoEng #NYANconf
Runtime Internals
by Matt Warren
NYAN conference
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.
11.
12.
13.
14.
15.
16.
17.
18. Virtual Machine (VM)
• Type System, Generics
• Built-in Types
• Loading types/classes
• Threading
• Exception Handling and Stack Walking
• Event Tracing and Profiling
• P/Invoke
20. 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
23. 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/
41. 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