“Whidbey” CLR Internals 11/12/2018 12:39 PM Session Code: ARC413 “Whidbey” CLR Internals Jonathan Keljo jkeljo@microsoft.com Program Manager Microsoft Corporation © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
11/12/2018 12:39 PM Tools Client Application Model Web & Service Application Model Data Systems Application Model Mobile PC & Devices Application Model Command Line Compact Framework Avalon Windows Forms ASP.NET / Indigo Win FS Yukon System.Console Mobile PC Optimized System.Web System.Storage System.Data.SqlServer System.Windows.Forms System.Windows NT Service System.Windows System.Windows.Forms System.ServiceProcess Presentation Data Communication System.Windows System.Search System.Data System.Messaging System. Discovery System.Collaboration UI Element Explorer Media Annotations SqlClient DataSet System.DirectoryServices RealTimeEndpoint Documents Controls Animation SqlTypes Mapping Active Directory TransientDataSession Monitoring System.Remoting Text Element Dialogs Controls SqlXML ObjectSpaces SignalingSession Logging System.Runtime.Remoting Uddi Shapes SideBar Control OdbcClient ObjectSpace Media Shape Notification Panel Relevance OleDbClient Query Activities Ink Navigation Design OracleClient Schema System.Web.Services System.MessageBus Web.Service Transport Queue System.Storage System.Windows.Forms System.Web.UI Port PubSub Item Core Description Forms Page WebControls Discovery Channel Router Relationship Contact Control Control Adaptors Service Policy Media Location Protocols Print Dialog HtmlControls Design Peer Group Audio Message Design MobileControls Video Document System.Net Images Event System.Web System.Help System.Speech HttpWebRequest NetworkInformation System.Xml Personalization FtpWebListener Sockets System.Drawing Recognition Synthesis Caching Schema Xpath SslClientStream Cache System.NaturalLanguageServices Serialization Query SessionState WebClient Fundamentals Base & Application Services Security Configuration Deployment/Management System.Timers System.Text System.Collections System.Windows. TrustManagement System.Web.Configuration System.Globalization System.Design System.Security System.Web Generic System.MessageBus.Configuration Administration System.Serialization System.IO System.Web. Security Authorization Permissions System.ComponentModel System.Configuration Management System.Threading Ports AccessControl Policy System.CodeDom System.Resources System.Message Bus.Security Credentials Principal System.Management System.Runtime System.Reflection Cryptography Token System.Deployment Serialization InteropServices System.EnterpriseServices System.Diagnostics CompilerServices System.Transactions © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Frameworks (BCL, WinFX, etc.) 11/12/2018 12:39 PM The Big Picture IDE Debugger Editor Compiler Source Files Frameworks (BCL, WinFX, etc.) EXE (IL) CLR JIT Loader GC Metadata Exceptions Interop Threading Remoting Security Debugging © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
C++ Templates … Stack <int> <double> <point> Main 11/12/2018 12:39 PM C++ Templates template <class T> class Stack { … T Pop() … } Template stack class Stack <int> <double> <point> … Main program Executable (x86) C++ Compiler Stack<int> … … Stack <double> … Stack <point> … Main program source © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
CLR Generics Stack <T> Main program class Stack<T> { … 11/12/2018 12:39 PM CLR Generics class Stack<T> { … T Pop() … } Template stack class .NET Compiler Stack <T> Main program Executable (IL) Stack<int> … … Stack <double> … Stack <point> … Main program source © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Generics in IL & Metadata 11/12/2018 12:39 PM Generics in IL & Metadata © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
IL Execution IL (Source line “T retval = _array[topOfStack]”) ldarg.0 11/12/2018 12:39 PM IL Execution IL (Source line “T retval = _array[topOfStack]”) ldarg.0 ldfld !0[] class GenericsDemo.GenericStack<!0>::_array ldloc.0 ldelem !0 stloc.1 Arguments [0] this Locals [0] topOfStack [1] null topOfStack topOfStack this._array[topOfStack] this._array[topOfStack] this._array[topOfStack] this._array this._array this this Evaluation Stack © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
GenericParamConstraint (0x2c) 11/12/2018 12:39 PM Generics in Metadata TypeDef (0x2) … Name Field List Method GenericStack Method (0x6) … Name Signature Param List .ctor 20 01 01 08 Pop 20 00 13 00 Push 20 01 01 13 00 Param (0x8) … Name initialSize toPush GenericParam (0x2a) Number … Owner Name T Field (0x4) … Name Signature _array 06 1d 13 00 _depth 06 08 GenericParamConstraint (0x2c) Owner Constraint System.Object … © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Param 1 Type is Generic Type Parameter 11/12/2018 12:39 PM Generic Signatures … 20 01 01 13 00 Push 20 00 13 00 Pop 20 01 01 08 .ctor Signature Name Method (0x6) Param (0x8) … Name initialSize toPush 20 01 01 13 00 Push Param 1 Type is Generic Type Parameter Instance Method (has “this”/”Me”) With 1 Parameter Void Return void Push(T toPush); 20 01 01 13 Param 1 is of type T 00 “Calling Convention” # Parameters Return Type Element Type Parameter Types Type Param Index © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Generics: Code Generation 11/12/2018 12:39 PM Generics: Code Generation © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Generics – Code Generation 11/12/2018 12:39 PM Generics – Code Generation MethodTable _array _depth 2 … Stack <int> MethodTable x86 .ctor <int> 4 2 … x86 Pop <int> … Stack<object> MethodTable x86 Push <int> MethodTable _array _depth 5 … x86 .ctor <object> MethodTable _array _depth 7 x86 Pop <object> … Stack<Form> MethodTable … x86 Push <object> © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Frameworks (BCL, WinFX, etc.) 11/12/2018 12:39 PM The Big Picture IDE Debugger Editor Compiler Source Files Frameworks (BCL, WinFX, etc.) EXE (IL) CLR JIT Loader GC Metadata Exceptions Interop Threading Remoting Security Debugging © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
EnC: Editing a Method 11/12/2018 12:39 PM © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
EnC – Editing a Method (1) Delta IL & Delta Metadata 11/12/2018 12:39 PM EnC – Editing a Method (1) Delta IL & Delta Metadata Delta Metadata (Provided by debugger) Full Metadata (In Running Process) Method (0x6) RVA … Name 4 PrintStatistics Method (0x6) RVA … Name 2050 Main 20a8 PrintStatistics INV EnCLog (0x1e) Token FuncCode 06000002 … EnCMap (0x1f) Token 06000002 … 2050 Complete Original IL . Other Data 20a8 Delta Header IL Header for PrintStatistics nop ldc.i4.0 stloc.1 . 4 Delta IL 8940 8944 Delta IL © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
EnC – Editing a Method (2) Remap 11/12/2018 12:39 PM EnC – Editing a Method (2) Remap IL Virtual Execution System x86 Processor Original IL Variables Original x86 Stack … i sum Registers … numbers .locals init (int32, int32) . call Console.ReadLine pop nop ret numbers i sum . call FFFFD630 pop ebx pop esi pop edi avg avg New IL New x86 .locals init (int32, int32, double) . call Console.ReadLine pop nop ret . call FFFFD630 fild dword … fstp dword … mov ecx, edi pop ebx pop esi pop edi © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
EnC – Editing Within a Call 11/12/2018 12:39 PM EnC – Editing Within a Call IL Virtual Execution System x86 Processor Original IL Variables Original x86 Stack … i sum Registers … numbers .locals init (int32, int32) . call Console.ReadLine pop nop ret numbers i sum . call FFFFD630 pop ebx pop esi pop edi vars for ReadLine . avg avg New IL New x86 .locals init (int32, int32, double) . call Console.ReadLine pop nop ret . call FFFFD630 fild dword … fstp dword … mov ecx, edi pop ebx pop esi pop edi © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
EnC: Editing a Class 11/12/2018 12:39 PM © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
EnC – Editing a Class (1) Delta Metadata 11/12/2018 12:39 PM EnC – Editing a Class (1) Delta Metadata Delta Metadata (Provided by debugger) Full Metadata (In Running Process) Field (0x4) … Name Signature _avg 06 0d _max 06 08 TypeDef (0x2) … Name Field List StatBuilder 04000001 03000001 EnCLog (0x1e) Token Func Code 02000001 2 04000019 04000020 … EnCMap (0x1f) Token 04000019 04000020 … FieldPtr (0X3) Token 04000001 04000002 04000019 04000020 … Field (0x4) … Name Signature _numbers 06 12 45 _sum 06 08 _avg 06 0d _max 06 08 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
EnC – Editing a Class (2) Extending Existing Instances 11/12/2018 12:39 PM EnC – Editing a Class (2) Extending Existing Instances SyncBlock MethodTable _numbers _sum 500 SyncBlock MethodTable _numbers _sum 33 … SyncBlock MethodTable _numbers _sum 101 _max 8 _avg 5.5 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Keeping Things Sane Runtime Power vs. Language Legality 11/12/2018 12:39 PM Keeping Things Sane Runtime Power vs. Language Legality Can do all kinds of crazy things with CLR’s support Left to the languages to decide what edits make sense Lots of potential work here EnC-friendly codegen Exception handling Managing cascading effects of edits © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Shameless Plug Language Implementers’ Lunch Thursday 11:30-1:30 11/12/2018 12:39 PM Shameless Plug Language Implementers’ Lunch Thursday 11:30-1:30 Programming Languages & Tools Track Lounge © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Community Resources Get Your Questions Answered! 11/12/2018 12:39 PM Community Resources Get Your Questions Answered! Newsgroups: microsoft.private.whidbey.clr Architecture & Infrastructure Lounge: 309 Foyer connect with Microsoft infrastructure product teams, and PDC 2003 Speakers PDC Weblogs: http://pdcbloggers.net © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
11/12/2018 12:39 PM Resources Books The Common Language Infrastructure Annotated Standard. ISBN 0-3211-5493-2 Inside Microsoft .NET IL Assembler. ISBN 0-7356-1547-0 Essential .NET Volume 1. ISBN 0-201-73411-7 Shared Source CLI Essentials. ISBN 0-596-00351-X © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
11/12/2018 12:39 PM Questions? © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
© 2003-2004 Microsoft Corporation. All rights reserved. 11/12/2018 12:39 PM © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
11/12/2018 12:39 PM © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.