.NET Framework
It is a new technology for building modern applications that can execute on latest versions of Windows operating system and modern devices like desktop PCs, servers, palm-tops etc.
.NET Framework provides complete environment to developers for developing:
ü Windows applications
ü Web applications (ASP.NET applications)
ü Web services
ü Console applications
ü Class libraries
· Sharable component for being used in distributed computing architecture etc.
· .NET Framework supports Object Oriented Programming model for multiple languages like Visual Basic, Visual C#, Visual C++ etc.
· The application development environment of .NET Framework insulates the operating system from many system specific tasks, such as file handling, memory allocation and management.
· .NET is not a language or package but a framework that contains source and runtime for different languages to build applications.
Roles of JIT in .NET Framework
· Just-in-time compiler is an important element of Common Language Runtime (CLR) which loads MSIL on target machine for execution. The MSIL is stored in .NET assemblies after the developer has compiled the codes written in any .NET compliant programming language like Visual Basic, Visual C# etc.
· JIT compiler translates the MSIL code of an assembly and uses the CPU architecture of target machine for executing a .NET application. It also stores the resulting native code so that it is accessible for subsequent calls.
· JIT also enforces type-safety in runtime environment of .NET Framework. It checks for the values that are being passed to parameters of any method. For example, JIT detects any event if a user tries to assign a 32 bit value (4 bytes) to a parameter that can accept 8-bit values (1 byte).
Figure: Just-In-Time compilation of .NET code
Briefly describe MSIL
What is Metadata?
Describe .NET Portable Executable (PE) file.
Explain the Common Type System of .NET Framework?
Roles of Common Language Runtime
· The runtime environment of any programming language manages the execution of programs on CPUs. For example:
ü For Java programs = Java Virtual Machine
ü For Visual C++ = MSCRT40.DLL
ü For VB6 = MSVBVM60.DLL
· Similar to the runtime environment of other programming languages, Common Language Runtime (CLR) is an environment for executing .NET applications on target machines.
· CLR is also a common runtime environment for all .NET codes irrespective of their programming language, because the compilers of .NET Framework converts every code into a common language which is known as MSIL. Thus CLR is equally capable for executing the programs written in Visual Basic, Visual C#, VC ++ or any other .NET compliant programming language.
· CLR also gives various services to executing processes like memory management service and security services. CLR performs various tasks for managing the execution process of .NET applications: The responsibilities of CLR are listed below:
Automatic Memory Management
CLR involves various inbuilt functions of .NET framework for allocating and de-allocating the memory the .NET objects. Thus, programmers as they need not write the code for explicitly allocating and de-allocating memory to programs as they used to perform in C programs by using malloc() and free() methods.
Garbage Collection
It is the major role of CLR which prevents memory leaks during execution of programs. The Garbage collector of CLR automatically determines the best time to free the memory which is reserved by an object for execution.
Code Access Security
Code Access Security (CAS) model is used in .NET Framework for imposing restrictions and security during execution of programs. CLR uses security objects to manage access to codes during execution of .NET applications. CLR allows an executing code to perform only those tasks for which it has permissions. Also, the CLR checks for user’s permissions by using authentication and configuration files of .NET application.
Briefly describe the following:
1. .NET assembly
2. Global Assembly Cache (GAC)
3. Metadata
Assembly
· Assemblies are the building blocks of .NET applications.
· Assembly contains meta-data that define the type-safety and other security options for an application.
· An application uses various resources to produce output. For example, an application might use various resources like external assemblies, logos, image files, graphic and media files etc. Thus, an assembly of a .NET application contains the information about the resources that are used by a program during its execution. Assembly contains a manifest file into which all the information about the resources is written.
· Assemblies contain compiled code in MSIL language.
· Assembly contains information about its build and version.
· Assemblies are portables units that can be transferred for deployment on servers or PCs.
Global Assembly Cache
· GAC is a central repository (cache) in a system in which assemblies are registered for sharing among various applications that execute on local or remote machines.
· Many .NET applications can share an assembly that is registered in GAC.
· .NET framework provides gacutil tool which is used for viewing and changing the contents of Global Assembly Cache of a system. Adding new assemblies to GAC and removing assemblies from GAC are some of the tasks that can be performed by using gatutil tool.
· GAC can contain multiple versions of single .NET assembly.
· CLR checks that GAC for a requested assembly before using information of configuration files.
· gacutil – I <assembly name> is the command that is used for installing an assembly in GAC. Users use command prompt of Visual Studio to install an assembly in GAC by using this command.
Metadata
· It is a manifest which is used in assemblies to define information about .NET application.
· Metadata of an assembly describes every data-type and member defined in the code. Also, Metadata of assembly gives information about various features of Object-oriented programming that are used in program. For example, it gives the information about the inheritance performed in code to derive a class from a .NET class.
· Metadata is stored in binary format. Hence, metadata of an assembly is sharable among applications that execute on various platforms and hardware.
· Meta-data can be exported to other applications for giving information about the services and various features of an application.
· MSIL is the acronym of Microsoft Intermediate Language.
· NET Framework ships with compilers of all the programming languages which are available in Framework for developing programs. There are separate compilers for Visual Basic, Visual C#, Visual C++ etc programming languages in .NET Framework. Each .NET compiler produces an intermediate code after compiling the source code, i.e .vb, .cs, .cpp etc files. The intermediate code is common for all languages and is understandable only to .NET environment. This intermediate code is known a Microsoft Intermediate Language.
· A .NET assembly contains the MSIL code which is obtained after compiling source code files of a .NET application.
· MSIL file is an executable file that can be transferred across various machines. Hence, MSIL files are portable to any machine.
· .NET Framework provides tools for assembling and disassembling MSIL.
· Intermediate Language Assembler ilasm.exe is a tool in .NET Framework which is used for generating an executable file from MSIL code. The file generated by ilasm.exe is portable.
· Intermediate Language diassembler ildasm.exe is a tool in .NET Framework which is used for displaying Metadata of an MSIL code as an expandable tree-structure. Executing the ildasm.exe command in Visual Studio command prompt produces a GUI interface.
The Common Language Runtime encompasses (includes) a JIT compiler for the conversion of MSIL to native code. Just-In-Time compiler loads the Meta-data of code into .NET Runtime for executing the MSIL code. JIT invokes the class loader to load the respective .NET classes as required by the Meta-data contained in the .NET assembly.
· Metadata is a machine-readable information about a resource, or clearly “data about data”. Such information might include details on content, format size, or other characteristics of a data source. In .NET, metadata includes type definitions, version information, external assembly references, and other standardized information.
· In .NET, metadata is a common mechanism that the .NET runtime, compilers, and tools all can use.
· Microsoft .NET uses metadata to describe all types that are used and exposed by a particular .NET assembly.
· Metadata includes descriptions of an assembly and modules, classes, interfaces, methods, properties, fields, events, global methods, and so forth.
What are the types of assemblies?
There are four types of assemblies in .NET:
· Static Assemblies: These are the .NET PE files that you create at compile time.
· Dynamic Assemblies: These are PE-formatted, in-memory assemblies that you dynamically create at runtime by using the classes in the system.Reflection.Emit Namespace.
· Private Assemblies: These are static assemblies used by a specific application.
· Public or Shared Assembly: These are static assemblies that must have a unique shared name and can be used by any application.
· Compilers of .NET Framework store the Metadata and MSIL after compiling a .NET program into Portable Executable (PE) files.
· .Metadata and MSIL of an application are stored at separate locations in a PE file. One section of a PE file is reserved for storing Metadata only whereas the other section is reserved for storing MSIL only.
· Metadata is stored in a series of table and heap data-structures in the Metadata section of a PE file.
· The Metadata of classes, references of the classes used in program, etc are stored in tabular structure in the Metadata part of a PE file. Information about the memory usage by various data types and methods are stored on heap structures in PE file’s metadata section. String, blob, string and GUID are the four heap structures that are used for storing memory usage information in PE files.
· PE header is another section of a PE file which contains information for CLR about the starting point of the program or application. CLR uses PE header to identify a PE file.
· Common Type System is a general set of rules which is used by Common Language Runtime for managing the communication between types of all .NET compatible programming languages.
· It supports value types and reference types.
· CTS matches the types of different programming languages to ensure type safety among codes developed in different programming languages.
As the integer data type of Visual Basic.NET and long data type of C++ are not compatible so the interfacing between them is complicated. The .NET Framework ensures type safety in cases where data needs to be transferred between types of two different languages.
What are the different types of JIT?
JIT compiler is a part of the runtime execution environment.
· Pre-JIT: It 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: It compiles only those methods that are called at runtime. However, these compiled methods are removed when they are not required.
· Normal-JIT: It compiles only those methods that are called at runtime. These methods are compiled first time they are called, and then they are stored in cache. When the same methods are called again, the compiled code from cache is used for execution.
Posted by: Chaudhary Amit V.

nice post...would be helpful!
ReplyDeletemac
technirvanaa.wordpress.com