Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discussion Demographics of the developer community What made “the best C++ compiler” in 1980? What’s changed since 1980?

Similar presentations


Presentation on theme: "Discussion Demographics of the developer community What made “the best C++ compiler” in 1980? What’s changed since 1980?"— Presentation transcript:

1 Discussion Demographics of the developer community What made “the best C++ compiler” in 1980? What’s changed since 1980?

2 Introduction to.NET These slides are from the original introduction to.NET, in October 2000

3 Open Internet Protocols SOAP, SCL, DISCO HTTP, SMTP, XML, WAP, XSD HTTP, SMTP, XML, WAP, XSD.NET Blueprint Your Application and Web Service.NET Framework Windows CE, ME, 2000,.NET Operations End-User Clients Other Applications Using Your Service Orchestration Your Internal Services.NET Enterprise Servers Building Block Services Public Web Services Visual Studio.NET

4 Common Language Runtime Frameworks Class loader and layout IL to native code compilers GC, stack walk, code manager Security Execution Support Base Classes

5 Multiple Languages Common type system –Object-oriented in flavor –Procedural languages well-supported –Functional languages possible CLS guides frameworks design –Rules for wide reach –All.NET Framework functionality available Over 15 languages investigated –Most are CLS consumers –Many are CLS extenders

6 Metadata: Creation And Use Metadata (and code) Debugger SchemaGenerator Profiler OtherCompiler Proxy Generator Type Browser Compiler SourceCode XML encoding (SDL or SUDS) Serialization (e.g. SOAP) Designers Reflection

7 Execution Model VBVC...Script IL Native Code “Econo”-JIT Compiler Standard JIT Compiler Native Code Install time Code Gen Common Language Runtime

8 The Process Model Process Shared class data and native code App. Domain (class data and native code) App. Domain Thread

9 Managed Code Managed code provides... –Metadata describing data –Location of references to objects –Exception handling tables So runtime can provide… –Exception handling –Security –Automatic lifetime management –Debugging and profiling

10 Runtime Control Flow Class Loader IL to native code compiler CPU Security System Code Managers Managed Native Code Assembly First call to method First reference to type Execution Support

11 Compiling IL To Native “Econo” JIT –Generates unoptimized native code –Code can be discarded and regenerated “Standard” JIT –Generates optimized native code –Includes verification of IL code Install time code generation –Done at install time –Reduces start-up time –Native code has version checks and reverts to runtime JIT if they fail

12 Managed Data Layout Provided by Runtime –Usually automatic –Metadata can specify Order Packing Explicit layout Lifetime Managed by Runtime (GC) –Working set is compacted –Data is moved –Object references are updated –No more intrusive than a page fault

13 Calling Unmanaged Code Native Code “Econo”-JIT Compiler Standard JIT Compiler Native Code Common Language Runtime Unmanaged Managed

14 Crossing The Boundary Mode transition for code manager –Calling conventions differ on x86 –Fast, rarely more than register shuffle Data type marshalling –Representations may not be the same –Pinning, copying, and/or reformatting needed –Custom marshalling supported The IL to native compilers help –In-line code transition and simple marshalling –Per call site cost is very low Plus a small cost on entry to a procedure that can make calls across boundary

15 Three Mechanisms Via function pointer –No mode transition, no marshalling –Stringent restrictions on called code “It just works” –Mode transition, no marshalling –All work done by tools (VC) Linker resolves references Class loader creates transition thunks Platform invoke (P/Invoke) –Mode transition, marshalling

16 COM Interop Uses P/Invoke mechanism for calls Object identity is maintained (IUnknown) Selected COM interfaces automatically created Types are automatically exported to COM and registered COM type libraries can be converted to metadata and imported Many data types are automatically marshaled

17 Some Statistics In the 3 years since we launched: 50% of professional developers use.NET 120M copies have been downloaded 85% of consumer PCs sold in 2004 have.NET pre-installed 58% of business PCs sold in 2004 have.NET pre-installed HP printers/scanners/cameras install.NET (3M copies of.NET / year)

18 Discussion How does the move to managed code affect the compiler? How does the move to Web servers and Web services affect the compiler? What makes “the best Java compiler”? What makes “the best C++ compiler” in 2005?

19 Generics One of the major features added in Version 2.0 of the CLR, to be release later this year (2005)

20 In English... Instead of defining StackOfInt, StackOfString, etc., use class Stack { void Push(T item) { … } T Pop() { … } T TopOfStack() { … } } static Stack IntStack; static Stack StringStack; Type safe (compile and design time support) Shared code (better perf, easier maintenance)

21 Polymorphic Programming Languages Standard ML O’Caml Eiffel Ada GJ C++ Mercury Miranda Pizza Haskell Clu

22 Widely-used Polymorphic Programming Languages C++

23 By 2005: C# Visual Basic Java Cobol, Fortran, …? Managed C++

24 Design for multiple languages ML Functors are cool! Visual Basic Don’t confuse me! C++ Give me template specialization C++ And template meta-programming Java Run-time types please Scheme Why should I care? C# Just give me decent collection classes Haskell Rank-n types? Existentials? Kinds? Type classes? Eiffel All generic types covariant please COBOL Change my call syntax!?!? C++ Can I write class C : T

25 Simplicity => no odd restrictions interface IComparable { int CompareTo(T other); } class Set : IEnumerable where T : IComparable { private TreeNode root; public static Set empty = new Set (); public void Add(T x) { … } public bool HasMember(T x) { … } } Set > s = new Set >(); Type arguments can be value or reference types Even statics can use type parameter Constraints can reference type parameter (“F-bounded polymorphism”) Interfaces and superclass can be instantiated

26 Non-goals C++ style template meta-programming Leave this to source-language compilers Higher-order polymorphism, existentials L et’s get the basics right first!

27 Compiling polymorphism, as was Two main techniques: Specialize code for each instantiation –C++ templates, MLton & SML.NET monomorphization –good performance –code bloat  (though not a problem with modern C++ impls) Share code for all instantiations –Either use a single representation for all types (ML, Haskell) –Or restrict instantiations to “pointer” types (Java) –no code bloat –poor performance  (extra boxing operations required on primitive values)

28 Compiling polymorphism in the Common Language Runtime Polymorphism is built-in to the intermediate language (IL) and the execution engine CLR performs “just-in-time” type specialization Code sharing avoids bloat Performance is (almost) as good as hand- specialized code

29 Code sharing Rule: –share field layout and code if type arguments have same representation Examples: –Representation and code for methods in Set can be also be used for Set (string and object are both 32-bit GC-traced pointers) –Representation and code for Set is different from Set (int uses 32 bits, long uses 64 bits)

30 Exact run-time types We want to support if (x is Set ) {... } else if (x is Set ) {... } But representation and code is shared between compatible instantiations e.g. Set and Set So there’s a conflict to resolve… …and we don’t want to add lots of overhead to languages that don’t use run-time types (ML, Haskell)

31 Object representation in the CLR vtable ptr fields normal object representation: type = vtable pointer vtable ptr elements array representation: type is inside object element type no. of elements

32 Object representation for generics  Array-style: store the instantiation directly in the object?  extra word (possibly more for multi-parameter types) per object instance  e.g. every list cell in ML or Haskell would use an extra word  Alternative: make vtable copies, store instantiation info in the vtable  extra space (vtable size) per type instantiation  expect no. of instantiations << no. of objects  so we chose this option

33 Object representation for generics vtable ptr fields x : Set vtable ptr fields y : Set Add HasMember ToArray Add HasMember ToArray code for HasMember code for ToArray code for Add stringobject ……

34 What’s in the design? Type parameterization for all declarations –classes e.g. class Set –interfaces e.g. interface IComparable –structs e.g. struct HashBucket –methods e.g. static void Reverse (T[] arr) –delegates (“first-class methods”) e.g. delegate void Action (T arg)

35 Precompilation (ngen) JIT compilation is flexible, but –can lead to slow startup times –increases working set (must load JIT compiler, code pages can’t be shared between processes) Instead, we can pre-compile –.NET CLR has “ngen” tool for native generation –IL is compiled to x86 up-front –runtime data structures (vtables etc) are persisted in native image –read-only pages (e.g. code) can be shared between processes –loader now responsible only for “link” step (cross-module fix-ups)

36 Ngen for generics For non-generic code, to ngen an assembly: –just compile every class and method in the assembly –perhaps inline a little across assemblies For generic code: –compile every generic class and method, but at what instantiations? just reference types? (code is shared) or some “commonly-used” types? (e.g. int) –we don’t know statically what instantiations will be used it’s a “separate compilation” problem

37 Ngen all instantiations Our approach: –always compile generic code for reference-type instantiations –for value type instantiations, compute the transitive closure of instantiations used by the assembly –compile code for those instantiations not already present in other linked ngen images leads to code duplication at load-time, just pick one has some interesting interactions with app-domain code- sharing policy (see SPACE’04 paper on Don Syme’s home page)

38 NGen: example class List class Set …Set … x86 for List x86 for Set x86 for Set struct Point …List …Set …List … class Window …List … …List … MyCollectionsClient1Client2 x86 for List x86 for List x86 for List ngen

39 NGen: when we can’t JIT is still required for –instantiations requested through reflection (“late-bound”) e.g. typeof(List<>).BindGenericParameters(typeof(int)) –generic virtual methods double dispatch, on instantiation and class of object –polymorphic recursion (unbounded number of instantiations)

40 What’s in the design (2)? Constraints on type parameters –class constraint (“must extend”) e.g. class Grid where T : Control –interface constraints (“must implement”) e.g. class Set where T : IComparable –type parameter constraints (“must subtype”) e.g. class List { void AddList (List items) where U : T } –3 special cases Can be instantiated (“new”) Can be null (“nullable”) Must be a value type (“struct”)

41 And What About Perf? Do generics really provide performance? It depends on how you ask the question… –And who is asking the question Or at least why they are really asking the question

42 MSR Perf Measurements

43 My Perf Measurements Note: First three columns are based on my “natural” implementation of QuickSort(Array). Second three are based on Andrew Kennedy’s QuickSort(Array, ComparisonOperation)

44 What’s in the design (3)? Variance annotations on type parameters –covariant subtyping interface IEnumerator { T get_Current(); bool MoveNext(); } so IEnumerator assignable to IEnumerator –contravariant subtyping interface IComparer { int Compare(T x, int y); } so IComparer assignable to IComparer


Download ppt "Discussion Demographics of the developer community What made “the best C++ compiler” in 1980? What’s changed since 1980?"

Similar presentations


Ads by Google