Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Friday, 30 January 2015

Common Language Runtime (CLR)

Today in Engineer's World, we are discussing a very important topic of .NET in very easy way. Posted By- +Manish Kumar Gautam +LIVE VIAR  +ASP.NET SOLUTIONS

Click imagination hunt to see latest Blogs

Previous - Just In Time (JIT)

How CLR is Define?

CLR: 

CLR is Common Language Runtime. CLR is the execution engine that performs the task to convert the IL Code to the Machine Specific Code.
It works as a layer between Operating Systems and the applications written in .NET languages that conforms to the Common Language Specification (CLS). The main function of CLR is to convert the Managed Code into native code and then execute the program. The Managed Code compiled only when it needed, that is it converts the appropriate instructions when each function is called. Just In Time (JIT) compilation converts Intermediate Language (IL) to native code on demand at application run time which is a part of it.
During the execution of the program, CLR manages memory, thread execution, garbage collection, exception handling, CTS, code safety, and other system services. It defines the CTS as a standard type system used by all .NET languages. That means all .NET programming languages uses the same representation for common Data Types, so CLR is a language-independent runtime environment. The CLR environment is also referred to as a managed environment, because during the execution of a program it also controls the interaction with the Operating System.

What is the Complete Architectural Working of CLR? 

Architecture:
 
Architecture of Common Language Run-time

CLR is a part of .Net Framework. You can read the complete working of .Net Framework in my previous Blog. However, in this Blog we will concentrate only on the working of CLR. Go through Figure 1.
Now, what happen when our source code is executed successfully by its language compiler, the assembly is loaded into the CLR. CLR serve as an execution engine for the IL code whose responsibility is to check the functioning of the code on the behalf of CLS and CTS. CLS define set of rules which every .NET compliant languages must follow whereas CTS uses the same representation for common Data Types. There are many more components that reside within CLR like Garbage Collection, Memory Management, Code Access Right, Type-Safety, Exception Handling, and many more which we will talk about later in this blog. Now, when the requirements are met. The CLR then transfer the managed code to JIT. JIT at run-time convert the code into user machine specific code. And when we double click on the IL Code the JIT convert it into machine which is actually getting executed according to the client machine configuration.

What are the various components that go within CLR?

Components:

The Components are listed as:
o   Code Execution: Code executions involve using the source code (in IL format) and execute it according to the machine configuration.
o   Common Type System (CTS): CTS uses the same representation for common Data Types.
o   Automatic Memory Management: Working on an application involves creation of variables and continuously storing them on heap memory. But doing this manually is not as easy task, as easily we are saying. So, it is also taken care by CLR automatically.
o   JIT Compiler: JIT is a tool provided by the CLR which give a way to the Source Code so that it can perform on the Machine efficiently.
o   Garbage Collector: It is used to free the memory space that it unknowingly used by some object in heap memory. GC can run manually as well as automatically.
 
Components of CLR
 
o  Security Manager: CLR implements a mechanism that operates on the concept granting permissions on the code's origin. Using security manager, it's possible to limit the resources to access code.
o   Access to Metadata: When creating an application, you might want to make sure that people could find out information. You can accomplish this task by adding metadata to the any document type (for e.g. pdf or word file).
o   Class Loader: For an application, CLR load the class that you create (or base class library that you referred), prepare them for use, and then either execute them or assist them to use either in their designed time use.
o   Exception Handling: Handling of exceptions that occur either at Compile-time or Design-time. Including Cross-Language Exception.
o   Conversion of IL to Native Code
o   Verification of Type-Safety: Interpreting of the code at compile time by the help of Intellisense. Type safety also comes into picture when you assign one type of variable to another.


How CLR is considered to be as an important organ of .NET Framework?

Advantages:

The Various Advantages are listed below:
o   High Performance Application: As you can see the components that CLR provide is all justifying its high performance.
o   Vastly Simplified Document: All the application is integrated with features like type-safe, data compatibility.
 
Advantages of CLR
 
o   Seamless Integration of the Code Written in Various Languages: CLR gave us a component i.e. CTS, which resolves the languages conflict and make the system Language Interoperable.
o   Evidence-Based Security with Code Identity: It grants the creator of original work exclusive rights to its use and distribution.
o   Assembly-Based Deployment that eliminates DLL HELL
o   Side-By-Side Versioning of Reusable Components: By the involvement of CLR, we can have multiple version of code execution at the same time.
o   Code Reuse through Implementation Inheritance: Inheriting of classes is not possible till Component Object Model. But, by the involvement of OOP, code reusing make task easy.
o   Automatic object management: GC provided by CLR clean unused managed object and reclaims the memory.


For any query, comment us below.


Click imagination hunt to see latest Blogs

Keep learning and sharing...

Thursday, 22 January 2015

JUST IN TIME (JIT)

Today in Engineer's World, we are discussing a very important topic of .NET Framework in very easy way. Posted By- +Manish Kumar Gautam +LIVE VIAR +ASP.NET SOLUTIONS

Click imagination hunt to see latest Blogs


What is the proper Definition of JIT?

Definition: JIT is Just In Time Compiler. A compiler which convert the IL code to machine specific code i.e., into Machine code. JIT is a tool provided by the CLR which give a way to the Source Code so that it can perform on the Machine efficiently.

How JIT work?
 
Working of Just-In-Time

Working: Firstly, the source code is compiled into its CIL code. Then the CIL code is taken by the CLR. Read the complete working of CLR and IL code in my previous blog ".NET FRAMEWORK".
The CLR then transfer the managed code to JIT. JIT at run-time convert the code into user machine specific code. And when we double click on the IL Code the JIT convert it into machine which is actually getting executed according to the client machine configuration.


How does it compile code?

Compilation: 

JIT compilation converts MSIL to native code on demand at application run time, when the contents of an assembly are loaded and executed. Because the common language runtime supplies a JIT compiler for each supported CPU architecture, developers can build a set of MSIL assemblies that can be JIT-compiled and run on different computers with different machine architectures. However, your managed code will run only on a specific operating system if it calls platform-specific native APIs, or a platform-specific class library.
The compilation of code can be done in three ways: 
 
Code compilation by JIT

o   Per File: It takes the complete C# File and compiles it to a machine language.
o   Per Method/Function:  It will take some methods or functions and compile that method and function and save that compile code into memory. 
o   Per Fragment: In Code Fragment where he probably takes 3 or 4 lines of codes and compile that code into machine language.

Does JIT also have types?
  
The answer is yes.

Types: 3 Types of JIT are available in .Net.
[NOTE]: These JIT may be categorized on the way they compile and the way they do caching.
 
Just-In-Time Types

o   Normal JIT: Compilation done on demand basis. Suppose there is Method 1. So, only Method 1 is compiled in case if it is needed. And once the Method 1 is compiled, the code is stored into RAM.
o   Econo JIT: Econo-JIT is same as Normal JIT, here also compilation is done on demand basis, but the code is not stored in cache into RAM. In case when you have low memory or you don't have lot of RAM. For example- Look at mobile phones memory. Then Econo-JIT is better thing to be used.
o   Pre JIT: In Pre-JIT there is no Dynamic compilation, instead there is full compilation. This compilation is done by ngen.exe. And this ngen.exe will compile your full .Net code into full machine language at that moment itself. This is full compilation rather than half compilation.





For any query, comment us below.

Click imagination hunt to see latest Blogs

Keep learning and sharing...

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...