510 likes | 741 Views
.Net Framework. An Overview By: Sukhdeep Sidhu sidhu@cis. Outline. .Net goals .Net concepts Design and compile time Deployment time Execution time Garbage Collection in .Net Summary. Online . Shop Get traffic conditions Compare products Read product reviews. More ?.
E N D
.Net Framework An Overview By: Sukhdeep Sidhu sidhu@cis
Outline • .Net goals • .Net concepts • Design and compile time • Deployment time • Execution time • Garbage Collection in .Net • Summary
Online • Shop • Get traffic conditions • Compare products • Read product reviews
More ? • Search for restaurants in an area which offer a particular cuisine and have seating available at 7 pm tonight • Look for vendors having a particular item in stock, offering the best price and having the best delivery time • Why is this not possible ?
How to integrate services • XML standard for describing data • .Net: A new development platform infrastructure that will help developers create and deploy distributed applications on the Internet
.Net Goals 1 • Consistent programming model • Simplified programming model • Run once, run always • Execute on many platforms • Language integration • Code reuse • Automatic resource management
.Net Goals 2 • Type safety • Rich debugging support • Consistent error-handling • Deployment • Security
Outline • .Net goals • .Net concepts • Design and compile time • Deployment time • Execution time • Garbage Collection in .Net • Summary
What is Metadata ? • It is the common format for exposing the information describing a type
An example • What would the metadata of a C++ class describe ? • Methods of the class and their parameters • Data members of the class • Visibility of all class members • The concepts could extend to events the class could fire. • Comparable to .class in java ?
What’s in the Metadata ? • Description of deployment unit (assembly) • Identity: name, version, culture[, public key] • What types are exported • Description of types • What other assemblies it depends on • Security permissions for it to run
What’s in the Metadata ? • Description of types • Name, visibility, base class, interfaces • Members (methods, fields, properties, events, nested types) • Custom attributes
Assemblies • Assembly is the unit of reuse and deployment in .Net • Assemblies can be single-file multi-file. • Consumer – assembly is a named and versioned collection of exported types and resources. • Developer – assembly is a collection of one or more files (HTML pages, metadata files, GIFS etc)
Manifest • Components of an assembly are described in a manifest. Makes the assemblies self-describing • Set of tables that describe the assembly’s identity, culture, files and publicly exported types. Other referenced assemblies are also included
Outline • .Net goals • .Net concepts • Design and compile time • Deployment time • Execution time • Garbage Collection in .Net • Summary
The right language for the job • MS plans to create four language compilers that target common language runtime – C++ with managed extensions, C#, Visual Basic, JScript. • Non-MS compilers for Cobol, Perl, Pascal, APL, Smalltalk, Scheme. • Rational planning to create Java compiler
The Common Type System • Formal specification of type system implemented by CLR • Possible member of a class – field, method, property and event • Visibility rules • Rules governing type inheritance, virtual functions, object lifetime • All class types must inherit from System.Object
Buiding types into a module • App.cs in C# public class App{ static public void Main( System.String[] args){ System.Console.WriteLine(“Hi”); } } • Compiler generates a PE file (App.exe) containing the CLR header, the metadata and the MSIL
Building types into an Assembly • One of the PE files is selected as the keeper of a manifest or a separate file can contain the manifest. • Example: Add module to an assembly • Two source code files – RUT.cs (rarely used types) and FUT.cs (frequently used types) • Compile RUT.cs into one module (RUT.mod) • Compile FUT.cs into MyTypes.dll (this will be the keeper of manifest • Assembly Linker Utility
RUT module and MyTypes.dll RUT.mod MyTypes.dll RUT.cs methods’ compiled MSIL FUT.cs methods’ compiled MSIL Metadata RUT.cs defined types, methods… RUT.cs referenced types, methods… Metadata FUT.cs defined types, methods… FUT.cs referenced types, methods… Manifest Assembly files (self and RUT.mod) Exported files (self and RUT.mod)
Outline • .Net goals • .Net concepts • Design and compile time • Deployment time • Execution time • Garbage Collection in .Net • Summary
Assemblies • Assemblies are key to application deployment • Private assemblies – deployed with the application for the sole use of the application. Runtime imposes no administrative policies • Shared assemblies – public-key cryptographic techniques • Guarantee name uniqueness • Secure notion of identity
Deployment • Avoiding the DLL Hell ! • Every assembly self describing through metadata • Every reference to a type is scoped by assembly reference • Well-defined heuristics to locate assemblies • Shared assemblies – Global Assembly Cache
Outline • .Net goals • .Net concepts • Design and compile time • Deployment time • Execution time • Garbage Collection in .Net • Summary
Common Language Runtime • MSIL instructions cannot be directly executed • MSIL instructions are first compiled into native CPU instructions – JIT compiler
How runtime locates assemblies • Step 1: Initiating the bind • Step 2: Version policy in the application configuration <BindingPolicy> <BindingRedir Name="Calcr" Originator="32ab4ba45e0a69a1" Version="*" VersionNew="2.1.0.0" UseLatestBuildRevision="yes"/> </BindingPolicy>
How runtime locates assemblies • Step 3: Locating Assembly through Codebases or Probing • Codebases • Probing • AppBase (order: .mcl, .dll, .exe) • Search Path • Example
How runtime locates assemblies NAME=MyName APPBASE=http://www.code.microsoft.com SEARCH PATH=bin (The AssemblyResolver changes this to: MyName;bin) LOCALE=de Explicit Codebases: Binding context CODEBASE=http://www.all.code.microsoft.com/codebase.exe App.cfg CODEBASE=[none] Probing URLs: • http://www.all.code.microsoft.com/codebase.exe • http://www.code.microsoft.com/MyName.MCL • http://www.code.microsoft.com/MyName.DLL • http://www.code.microsoft.com/MyName.EXE • http://www.code.microsoft.com/MyName/MyName.MCL • http://www.code.microsoft.com/MyName/de/MyName.MCL • http://www.code.microsoft.com/bin/MyName.MCL • http://www.code.microsoft.com/bin/de/MyName.MCL • http://www.code.microsoft.com/MyName/MyName.DLL • http://www.code.microsoft.com/MyName/de/MyName.DLL • http://www.code.microsoft.com/bin/MyName.DLL • http://www.code.microsoft.com/bin/de/MyName.DLL • http://www.code.microsoft.com/MyName/MyName.EXE • http://www.code.microsoft.com/MyName/de/MyName.EXE • http://www.code.microsoft.com/bin/MyName.EXE • http://www.code.microsoft.com/bin/de/MyName.EXE
How runtime locates assemblies • Step 4: The Global Assembly Cache and Auto-QFE policy • Step 5: Administrator Policy • Version policies specified by the administrator
JIT compilers • Normal compiler • Examine’s a method’s MSIL • Optimizes the resulting native code just like the back end of an unmanaged compiler • Economy compiler • On machines where cost of using memory and CPU cycles is high • Replaces each MSIL instruction with its native code counterpart
Verification and Security 1 • Code Identity – through class loader or interoperability services • Type safety – access only memory that has been allocated for their use and access objects only through their exposed interfaces • Combine strong typing in metadata with strong typing in MSIL
Verification and Security 2 • Code Access Security • Resource Permissions – CLR walks up the call stack to check if all assemblies have required permissions • Identity permissions – Site, Zone, Shared Name, Publisher • Declarative security – load time or runtime
Outline • .Net goals • .Net concepts • Design and compile time • Deployment time • Execution time • Garbage Collection in .Net • Summary
Resource allocation • All resource allocated from a managed heap
The Garbage Collection Algo 1 • Makes a graph of accessible objects
The Garbage Collection Algo 2 • Collect the unaccessible objects
Finalization • Object can gracefully clean up itself • Downsides: • Objects take longer to allocate • Performance is affected • No guarantee of order or execution • resurrection
Finalization Internals 1 • Before garbage collection
Finalization Internals 2 • Heap after garbage collection
Finalization Internals 3 • Heap after Second gabage collection
Weak References • Weak references allow the garbage collector to collect the object • To access the object, the application must obtain a strong reference to the object • Long/Short weak references
Generational garbage collector 1 • Also called ephemeral garbage collector • Based on following assumptions: • Newer the object, shorter its lifetime • Older the object, longer its lifetime • Newer objects strongly related and are frequently accessed around the same time • Compacting a portion of the heap faster than compacting the whole heap
Generational garbage collector 2 • Initially all objects in generation 0 • Any objects surviving a garbage collection are considered to be generation 1 • New objects are always added to generation 0 • Generation incremented when an object survives the garbage collection (currently generation 2 is the highest)
Generational garbage collector 3 • Performance optimizations • Collect only from generation 0 • If more memory required, proceed to higher generations
Issues in garbage collection • Multi-threaded applications • Fully interruptible code • Hijacking – modifying the thread’s stack so that the return address points to a special function • Safe points • Synchronization free allocations • Scalable collections
Outline • .Net goals • .Net concepts • Design and compile time • Deployment time • Execution time • Garbage Collection in .Net • Summary
Summary • Enables building and deploying of web services and applications in any programming language • Bind applications over the Internet that take advantage of existing infrastructure and applications • A new platform for building integrated service-oriented applications for Internet Businesses.
References • Jeffrey Richter’s articles in MSDN magazine: • http://msdn.microsoft.com/msdnmag/issues/0900/Framework/Framework.asp • http://msdn.microsoft.com/msdnmag/issues/1000/Framework2/Framework2.asp • http://msdn.microsoft.com/msdnmag/issues/1100/GCI/GCI.asp • http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/GCI2.asp • http://msdn.microsoft.com/msdnmag