Friday, March 23, 2012

what is CLR,JIT,GAC,GC


CLR means Common Language Runtime.It is  Major component of 
the .NET frameworkIt provides no of benefits to the 
developers such as Exception handling,Security,Debugging 
and Versioning.

Common Language Runtime is Runtime engine which converts 
Microsoft Intermediate Language in machine understandable 
code, it is similar to JVM in Java


working of CLR:-

When the .NET program is compiled, the output of the 
compiler is not an executable file but a file that contains 
a special type of code called  the Microsoft Intermediate 
Language (MSIL), which is a low-level set of instructions 
understood by the common language run time. This MSIL 
defines a set of portable instructions that are independent 
of any specific CPU. It's the job of the CLR to translate 
this Intermediate code into a executable code when the 
program is executed making the program to run in any 
environment for which the CLR is implemented. And that's 
how the .NET Framework achieves Portability. This MSIL is 
turned into executable code using a JIT (Just In Time) 
complier. The process goes like this, when .NET programs 
are executed, the CLR activates the JIT complier. The JIT 
complier converts MSIL into native code on a demand basis 
as each part of the program is needed. Thus the program 
executes as a native code even though it is compiled into 
MSIL making the program to run as fast as it would if it is 
compiled to native code but achieves the portability 
benefits of MSIL.

jit:

Before Microsoft intermediate language (MSIL) can be
executed, it must be converted by a .NET Framework
just-in-time (JIT) compiler to native code, which is
CPU-specific code that runs on the same computer
architecture as the JIT compiler. 
Rather than using time and memory to convert all the MSIL in
a portable executable (PE) file to native code, it converts
the MSIL as it is needed during execution and stores the
resulting native code so that it is accessible for
subsequent calls.

JIT compiler is a part of the runtime execution environment.
In Microsoft .NET there are three types of JIT compilers.

Pre-JIT : Pre-JIT compiles complete source code into native
code in a single compilation cycle. This is done at the time
of deployment of the application.

Econo-JIT : Econo-JIT compiles only those methods that are
called at runtime. However, these compiled methods are
removed when they are not required.

Normal-JIT : Normal-JIT compiles only those methods thar are
called at runtime.

What is GAC?
A shared assembly has version constraints. It is stored in the Global Assembly Cache (GAC). GAC is a repository of shared assemblies maintained by the .NET runtime. The shared assemblies may be used by many applications. To make an assembly a shared assembly, it has to be strongly named.
GC:
In .NET Garbage Collector maintained by CLR. The process of 
GC is reclaim the memory of objets which is no longer 
referenced by our program.Next thing is GC runs 
undeterministicly because of that we can't assure we the 
object will be released from the Heap Location

If there is any memory defeciency then only GC will called 
by CLR. GC always runs on the priority basis. If size of free 
memory is more, than GC runs on low priority basis.  And if 
memory becomes low than GC Starts running on high priority 
to free up the memory from those object which are no loger 
in used.

metadata: Metadata is information about a PE(Portable Executable)means information about Executable file