1 / 20

Overview

.Net’s Common Language Runtime: How does it really work? Presented by: Arjun Kumar Polu Instructor: Dr. Ravi Mukkamala. Overview. What is CLR & Why we need it? CLR Architecture How does CLR work? What is its role in .Net Security? Managed vs Unmanaged code Conclusion.

gretel
Download Presentation

Overview

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. .Net’s Common Language Runtime:How does it really work?Presented by:Arjun Kumar Polu Instructor: Dr. Ravi Mukkamala CS795

  2. Overview What is CLR & Why we need it? CLR Architecture How does CLR work? What is its role in .Net Security? Managed vs Unmanaged code Conclusion CS795

  3. Microsoft .NET Framework Architecture Microsoft Visual Basic® .NET C++ C# Microsoft JScript® … Microsoft Visual Studio® .NET Common Language Specification Framework Class Library Common Language Runtime Windows LINUX CS795

  4. What is CLR? • CLR is Common Language Runtime • The CLR is actually an environment in which we can run our .NET applications that have been compiled to IL (Intermediate language). • CLR is analogous to JRE in Java. • CLR facilitates: Runtime Environment & Runtime Services CS795

  5. CLR Facilitates 1.Run-time environment:CLR Compiles application into the runtime, compile the IL code into native code, execute the code 2.Run-time services like:a. Memory management, b. Type safety, c. Enforces Security, d. Exception Management. e. Thread support f. Debugging support CS795

  6. Execution of an .Net application CS795

  7. Architecture of CLR CS795

  8. Functions of each Module in CLR • Class loader, which loads classes into CLR. • MSIL to native code compiles, this converts MSIL code into native code. • Code manager, this manages the code during execution. • Memory allocation and Garbage collector, this performs automatic memory management. • Security engine, this enforces security restrictions as code level security folder level and machine level security using tools provided by Microsoft .NET and using .NET Framework setting under control panel. CS795

  9. Functions of each Module in CLR • Type checker, which enforces strict type checking. • Thread support, which provides multithreading support to applications. • Exception manager, which provides a mechanism to handle the run-time exceptions handling. • Debug engine, which allows developer to debug different types of applications. • COM marshaler, which allows .NET applications to exchange data with COM applications. • Base class library support, which provides the classes (types) that the applications need at run time. CS795

  10. C# Code C#Compiler CLR IL JITCompiler Visual Basic Code VisualBasicCompiler COBOL Code COBOL Compiler NativeCode CS795

  11. JIT Compilers The IL code is compiled to native machine and is not interpreted at all. For such a compilation the CLR uses the following two JIT compilers: • Econo-JIT : This compiler has a very fast compilation time; but it produces un-optimized code - thus the program may start quickly but would run slow. This compiler is suitable for running scripts. • Standard-JIT: This compiler has a slow compilation time; but it produces highly optimized code. Most of the times the CLR would use this compiler to run your IL code. CS795

  12. Role of CLR in .Net Security CLR enforces security in following manner: • To control and access the system resources like hard disk • To control and access the network connections • To control and access the other hard ware resources. CS795

  13. Managed Code • The code which can be executed by the CLR is managed code. • Managed code gives information to the CLR for multiple run-time services in .Net Framework. • This information is stored in the form of metadata inside the PE file. • Managed data is allocated and released from memory automatically by garbage collection. • Managed data can be accessible from managed code but managed code can be accessible from managed and unmanaged data. CS795

  14. Managed Code Execution steps: Managed code execution is known as the process executed by the CLR which is as follows: • CLR loads the MSIL & refers metadata, • CLR executes the Native code, • CLR provides automatic memory management. • Managed execution also performs JIT compilations, • Ensuring type safety, • Enforcing security, • Handling exceptions. CS795

  15. Unmanaged Code • The code which is executed without the involvement of CLR is unmanaged code. • Any code that tries to bypass the CLR and attempts to handle the functions like memory management is considered "unsafe“. • The compiler would not compile the code. CS795

  16. Unmanaged Demo using System; using System.Collections.Generic; using System.Text; namespace UnsafeApplication { class Program { static unsafe void Main(string[] args) { int MyInteger = 123; int* MyIntegerPointer = &MyInteger; Console.WriteLine(*MyIntegerPointer); Console.ReadLine(); } } } CS795

  17. Memory Management • Automatic memory management means no need to write code to allocate memory when objects are created or to release memory when objects are not required the application. • Automatic memory management involves: Allocation of memory Deallocation of Memory CS795

  18. Garbage Collector • Garbage Collector will take care of memory management in managed code. • Garbage collector improves performance as it uses memory allocation algorithm employed by the CLR is much faster than the memory allocation routines used in C runtime. • Garbage collection occurs infrequently which will have effect on the performance of the application as that process stops momentarily during that period. CS795

  19. Conclusion • CLR is heart and soul for the Dot Net. Then we have gone through the need for such an environment and then we have seen the architecture of the CLR and the working of the CLR. • Then we have gone through the managed and unmanaged code, then through the different JIT compilers . Then through the memory management and finally Garbage collector. CS795

  20. References • http://www.codeproject.com/dotnet/clr.asp#_clr • http://www.codeproject.com/dotnet/DotNetWhitePaper.asp • http://www.codeproject.com/useritems/C__basics.asp • http://msdn2.microsoft.com/en-us/library/ddk909ch.aspx CS795

More Related