1 / 16

Introducing the Common Language Runtime for .NET

Introducing the Common Language Runtime for .NET. The Common Language Runtime. 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 New platform by Microsoft

asasia
Télécharger la présentation

Introducing the Common Language Runtime for .NET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introducing the Common Language Runtime for .NET

  2. The Common Language Runtime • 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 • New platform by Microsoft • Designed to target the Internet

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

  4. …The Purpose of the CLR • Bug reduction • More code interacting, bugs affect more users • Ease of integration • 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 • 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. The CLR and Managed Code Legacy Software(unmanaged code) Managed Executable Reusable Managed Components Common Language Runtime(JIT compilation, memory management, etc.) Windows (or other operating oystem)

  7. What is Managed Code • Code that targets the CLR • C#, VB.NET, PERL, Java, C++, Cobol, etc. • 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 • Intermediate Language (IL) instructions • Metadata

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

  9. ILDasm.exe • 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 is made up of 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 • Code management features • Performance of full-speed execution

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

  12. Automatic Memory Management • 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 • Leaked memory or objects • References to freed or non-existent objects • Reading of uninitialized variables • Impossible to gain access to memory with object reference

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

  14. Garbage Collection • Garbage collection occurs when a “new” operation fails due to lack of memory • All managed threads are stopped • Collection starts with roots, and recursively finds referenced objects • Roots == globals, locals, cpu registers • 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

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

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

More Related