Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introducing the Common Language Runtime for.NET. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution.

Similar presentations


Presentation on theme: "Introducing the Common Language Runtime for.NET. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution."— Presentation transcript:

1 Introducing the Common Language Runtime for.NET

2 The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution engine of The.NET Framework –Offers many system services –Similar to an OS –Runs on a host OS The.NET Framework The.NET Framework –New platform by Microsoft –Designed to target the Internet

3 The Purpose of the CLR… Safe binary execution Safe binary execution –Security, memory protection –Running un-trusted code, locally Performance and Functionality Performance and Functionality –Native execution (JIT Compiled) –No Sandbox

4 …The Purpose of the CLR Bug reduction Bug reduction –More code interacting, bugs affect more users Ease of integration Ease of integration Developer investment Developer investment –Reuse skills from project to project, even if the projects are vastly different

5 Managed Code and the CLR The Common Language Runtime (CLR) is a runtime engine The Common Language Runtime (CLR) is a runtime engine –Manages.NET Code (such as C# applications) –Provides features such as memory management, thread management, object type safety, security, etc. –Is a part of the.NET Framework

6 Windows (or other operating oystem) Common Language Runtime (JIT compilation, memory management, etc.) Legacy Software (unmanaged code) Managed Executable Reusable Managed Components The CLR and Managed Code

7 What is Managed Code Code that targets the CLR Code that targets the CLR –C#, VB.NET, PERL, Java, C++, Cobol, etc. All Managed code has all features of CLR All Managed code has all features of CLR –Object oriented infrastructure –Internet oriented infrastructure –Access to the Framework Class Library (FCL) All Managed executables consist of All Managed executables consist of –Intermediate Language (IL) instructions –Metadata

8 IL and Metadata (MSIL – microsoft intermediate language) IL CPU independent machine language IL CPU independent machine language –Just-in-time compiled at runtime –Makes cross-language integration possible. Metadata Metadata –Structured information –describes programming constructs including Classes definitions, field and method definitions, parameter lists, return types, etc. Classes definitions, field and method definitions, parameter lists, return types, etc.

9 ILDasm.exe Use ILDasm.exe to view IL for managed executable Use ILDasm.exe to view IL for managed executable

10 Just-in-Time Compiling All managed code runs in native machine language All managed code runs in native machine language All managed code is made up of IL and metadata All managed code is made up of IL and metadata The CLR JIT-compiles the IL and metadata The CLR JIT-compiles the IL and metadata –At execution time –Executed directly by CPU Allows for the best of both worlds Allows for the best of both worlds –Code management features –Performance of full-speed execution

11 Running Process’ Memory SomeSources.exe IL Metadata JIT Compiler 10010100 10110000 10000000 10111010 11011011 11010111 11000010 01110110 Native Machine Language The CPU executes the JIT- compiled machine code directly At execution time the IL and Metadata are JIT compiled Executing a Managed Application

12 Assembly vs. Managed Module Deployment of managed code broken-up into to logical concepts Deployment of managed code broken-up into to logical concepts –Assembly –Managed module Managed module Managed module –Single physical file –Contains type definitions –Cannot be executed or used directly Assembly Assembly –Unit of versioning, deployment, and security –Can consist of multiple files Managed modules Managed modules Resource files Resource files

13 Reasons for Assemblies Decouple concepts of physical and logical deployment Decouple concepts of physical and logical deployment –Logically, you deploy a complete assembly –Physically, deploy only necessary files Performance enhancement for network deployment Performance enhancement for network deployment Include resource files Include resource files –No embedding –Resource files retain their identity Smiley.jpg, Info.xml, etc. Smiley.jpg, Info.xml, etc.

14 Versioning Assemblies Assemblies can be strongly named Assemblies can be strongly named –Includes public/private key information Strong named assemblies bind by version Strong named assemblies bind by version –Code that uses V1 uses V1 even after V2 is installed on the system –Avoids DLL hell –Gives you the freedom to make V2 components incompatible with V1 Strong binding is a major improvement over DLLs Strong binding is a major improvement over DLLs

15 Reflection Programmatically gain access to metadata at runtime Programmatically gain access to metadata at runtime Used to make ultra-flexible code Used to make ultra-flexible code Components often perform reflection to find out about derivations Components often perform reflection to find out about derivations –Custom attributes Late and loose binding are possible with reflection Late and loose binding are possible with reflection –Instantiate objects, call methods, etc. Reflection Emit Reflection Emit –Possible to emit IL at runtime, JIT compile & execute

16 Automatic Memory Management The CLR manages memory for managed code The CLR manages memory for managed code –All allocations of objects and buffers made from a Managed Heap –Unused objects and buffers are cleaned up automatically through Garbage Collection Some common software bugs are not possible with managed code Some common software bugs are not possible with managed code –Leaked memory or objects –References to freed or non-existent objects –Reading of uninitialized variables Impossible to gain access to memory with object reference Impossible to gain access to memory with object reference

17 The Managed Heap Reduces bugs Reduces bugs Makes code access security possible Makes code access security possible –No direct memory access Makes type safety possible Makes type safety possible –Incompatible type coercion not possible Performance Performance –Newing up objects is much faster than malloc() –Garbage collection can be a perf-hit

18 Garbage Collection Garbage collection occurs when a “new” operation fails due to lack of memory Garbage collection occurs when a “new” operation fails due to lack of memory All managed threads are stopped All managed threads are stopped Collection starts with roots, and recursively finds referenced objects Collection starts with roots, and recursively finds referenced objects –Roots == globals, locals, cpu registers Referenced objects are moved down in the managed heap, Referenced objects are moved down in the managed heap, –Making space available at the end –Removing unreachable objects –No Fragmentation References fixed-up and managed threads restarted References fixed-up and managed threads restarted

19 A B E D C The Managed Heap = Object or buffer in memory class MyClass{ void Method(){ Variable v1; Variable v2; do{. Objects A and D will be cleaned up because neither is directly or indirectly referenced by code Garbage Collection

20 CLR Summary The platform for managed code The platform for managed code –C#, VB.NET, etc. Features Features –Memory management, security management, reflection, type safety –IL, metadata, JIT compilation –Assemblies, managed modules Understanding the platform will make coding.NET code easier Understanding the platform will make coding.NET code easier –C#, VB.NET, etc.


Download ppt "Introducing the Common Language Runtime for.NET. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution."

Similar presentations


Ads by Google