cod-E-mphasis

Understanding the .Net Framework

Posted in .Net, Framework by Piyali Sarkar on April 7, 2009

The main feature of .Net platform is its runtime system which is known as Common Language Runtime (CLR).CLR is the engine that handles the parsing and execution of all .NET application instruction. The CLR is the foundation upon which the entire .NET platform is built.

Code Management and Execution- Code management within the CLR covers most of the basic activities of loading and executing .NET programs. The key task of code management is converting the Intermediate Language (IL) files created by the command line compilers into native code for the target machine. Command line compilers do not create actual executable code; they create a form of compressed code called IL. This IL then converted to native code to run.

There are some important advantages of using IL. This IL makes code operating system independent. You can compile your code once and then ship it to many different platforms or devices for execution. That’s because the actual creation of the executable code is handled by the CLR on the host device itself.

Step-1: Create the source code. You can use any text editor to crate .NET source code files.

Step-2 & 3: A command line compiler accepts the source code as input and produces a file (.DLL or .EXE) that contains parsed code and additional metadata that describes the compiled component.

net1

Step-4 & 5: The parsed code and metadata is delivered to the Just-in-time (JIT) compiler that converts the parsed code into executable code for that operating system and processor. For ASP.NET applications, this last step occurs the first time a user request a page from the Web application.

Note:- It is important that the JIT-ed file is stored on disk for future use. Repeated requests to a component will be compiled to native code only the first time. All subsequent requests are routed directly to the native compiled file. This means that all ASP.NET applications executed at “native-code speed” every time. It also means that this conversion to native code happens only once in the lifetime of the component. The only times this changes is when the source code is changed; at that point, the entire cycle mentioned above starts again.

Tagged with: ,

Understanding CLR components

Posted in .Net, Framework by sutanu on April 7, 2009

CLR consists of various components that provide the run-time environment and run-time services. These components include– Class Loader,MSIL to native code compiler,Code manager,Garbage Collector,Security Engine,Type Checker,Thread Support,Exception Manager,Debug Engine,COM Marshaler,Base Class Library Support.

For a program to run within the CLR and benefit from the managed execution environment,you need to write the source code of the program in a CLS-compliant language.The compilers of CLS-compliant languages compile the source code and generate an intermediate code,called MSIL Code and Metadata. Before you execute the MSIL code,you need to compile it into CPU-specific instructions. To execute the code,the runtime requires information about the code that is in the metadata. The MSIL code and metadata are located in a “Portable Executable File”.

  • When you execute a portable executable file,the  Class Loader loads the MSIL code and the metadata from the portable executable file into run-time memory.Before the code is executed,it is passed to the native code compiler for compilation.
  • The IL to native code compiler contains just-in-time(JIT) compiler for different CPU architectures and compiles the IL code into a native instruction set.
  •  After the MSIL code and the metadata are loaded into memory,the Code Manager calls entry-point method,which is the Main,WinMain or D11Main method. During the execution of the entry-point method,the code manager places the objects in memory and controls the execution of the program.
  • The Garbage Collector performs periodic checks on the managed heap to identify the objects that are no longer required and removes them from the memory.
  • During program execution,the Type Checker ensures that all objects and values,and the references to those objects and values,have a valid type.
  • The Security Engine of the common language runtime(CLR) enforces restrictions on the code and controls the access to system resources such as hard disk,network connections,and other system resources.
  • The .NET Framework allows a single process to be divided into one or more subprocesses called application domains. Each application domain can contain one or more threads. The run-time monitors all the threads that have executed code within its process.
  • COM Marshaler performs marshaling of data when data passes between managed and unmanaged execution environments. Marshaling manages the different representations of data across different execution environments. It performs the necessary conversions in data formats between managed and unmanaged code.
  • During the execution process, a program depends upon the functionality provided by the .NET Framework class library .The CLR provides Base Class Library Support to the programes that are running within the managed execution process.
  • The CLR also provides a common Debug Engine which enables you to debug an applicationwritten in any language supported by the .NET framework. The common Debug engine supports debugging applications running on local and remote machines.