Tuesday, August 21, 2018

JIT Compiler & Its Types

JIT Compiler

In the .NET Framework, all the Microsoft .NET languages use a Common Language Runtime. The language compiler will convert code into MSIL. Before the MSIL can be executed, it must be converted to native code. Native code is CPU specific code which runs on the same machine. JIT compiler converts the MSIL code to CPU native code as it is needed during code execution. It is called just-in-time since it converts the MSIL code to CPU native code; when it is required within code execution otherwise it will not do nothing with that MSIL code.

Role of the JIT compiler:-

The JIT compiler loads MSIL on target machines for execution. The MSIL is stored in .NET assemblies after the developer has compiled the code written in any .NET-compliant programming language, such as Visual Basic and C#. JIT compiler translates the MSIL code of an assembly and uses the CPU architecture of the target machine to execute a .NET application. It also stores the resulting native code so that it is accessible for subsequent calls. If a code executing on a target machine calls a non-native method, the JIT compiler converts the MSIL of that method into native code. JIT compiler also enforces type-safety in runtime environment of .NET Framework. It checks for the values that are passed to parameters of any method.

Types of JIT Compiler:


Pre JIT:

PRE JIT Compiler compiles complete source code into native code in a single compilation cycle. It will convert the compiled .NET code from the platform-independent intermediate state to a platform specific stage. This is done at the time of deployment of the application. The advantage of PRE JIT Compiler is that you don't have the initial compilation delay that the compiler can introduce when an assembly or type is loaded for the first time in code.


Econo JIT: 

Econo JIT Compiler compiles only those methods that are called at runtime. These compiled methods are removed when they are not required. The idea of Econo JIT is to spend less time compiling so that startup latency (the delay before a transfer of data begins following an instruction for its transfer) is lower for interactive applications.



Normal JIT: 

This complies only those methods that are called at runtime. These methods are compiled only first time when they are called, and then they are stored in memory cache. This memory cache is commonly called as JITTED. When the same methods are called again, the complied code from cache is used for execution.




Thursday, August 16, 2018

Metadata


Metadata
Metadata in .Net is binary information which describes the characteristics of a resource . This information include Description of the Assembly , Data Types and members with their declarations and implementations, references to other types and members , Security permissions etc. A module's metadata contains everything that needed to interact with another module. In .NET, metadata includes type definitions, version information, external assembly references, and other standardized information. In order for two systems, components, or objects to interoperate with one another, at least one must know something about the other.
During the compile time Metadata created with Microsoft Intermediate Language (MSIL) and stored in a file called a Manifest . Both Metadata and Microsoft Intermediate Language (MSIL) together wrapped in a Portable Executable (PE) file. During the runtime of a program Just In Time (JIT) compiler of the Common Language Runtime (CLR) uses the Metadata and converts Microsoft Intermediate Language (MSIL) into native code. When code is executed, the runtime loads metadata into memory and references it to discover information about your code's classes, members, inheritance, and so on. Moreover Metadata eliminating the need for Interface Definition Language (IDL) files, header files, or any external method of component reference.
Metadata stores the following information:
  • Description of the assembly
    • Identity (name, version, culture, public key).
    • The types that are exported.
    • Other assemblies that this assembly depends on.
    • Security permissions needed to run.
  • Description of types
    • Name, visibility, base class, and interfaces implemented.
    • Members (methods, fields, properties, events, nested types).
  • Attributes
    • Additional descriptive elements that modify types and members.

Monday, August 13, 2018

Common Language Specification &


Common Language Specification
One of the obvious themes of .NET is unification and interoperability between various programming languages. In order to achieve this; certain rules must be laid and all the languages must follow these rules. CLS is the collection of the rules and constraints that every language (that seeks to achieve .NET compatibility) must follow.
The Common Language Specification is a set of basic language features (constructs and constraints) that serves as a guide for library writers and compiler writers. It allows libraries to be fully usable from any language supporting the CLS, and for those languages to integrate with each other. The Common Language Specification is a subset of the common type system. The CLS is actually a set of restrictions on the CTS. The CLS defines not only the types allowed in external calls, but the rules for using them, depending on the goal of the user.
The Common Language Specification describes a common level of language functionality. The CLS is a set of rules that a language compiler must follow to create .NET applications that run in the CLR. Anyone who wants to write a .NET compliant compiler needs simply to follow these rules and that's it.
Base Class Library
The .NET Framework base class library contains the base classes that provide many of the services and objects you need when writing your applications. The class library is organized into namespaces. The .NET Framework Class Library (FCL) is a set of managed classes that provide access to system services. File input/output, sockets, database access, remoting, and XML are just some of the services available in the FCL. Importantly, all the .NET languages rely on the same managed classes for the same services. This is one of the reasons that, once you have learned any .NET language, you have learned 40 percent of every other managed language. The same classes, methods, parameters, and types are used for system services regardless of the language. This is one of the most important contributions of FCL.


Sunday, August 12, 2018

Managed Code V/S Unmanaged Code

Managed Code & Unmanaged Code
Managed Code:
Managed code is the code that is written to target the services of the managed runtime execution environment such as Common Language Runtime in .Net Technology. This code is directly executed by CLR with help of managed code execution. Any language that is written in .NET Framework is managed code.
In simple terms the code which is executed by CLR (Common Language Runtime) is called Managed Code, any application which is developed in .Net framework is going to work under CLR, the CLR internally uses the Garbage Collector to clear the unused memory and also used the other functionalities like CTS, CAS etc. Managed code uses CLR which in turns looks after your applications by managing memory, handling security, allowing cross - language debugging, and so on.
Unmanaged Code:
Unmanaged code compiles straight to machine code and directly executed by the Operating System. The generated code runs natively on the host processor and the processor directly executes the code generated by the compiler. It is always compiled to target a specific architecture and will only run on the intended platform. All code compiled by traditional C/C++ compilers are Unmanaged Code.
         The managed code is comparatively easier to learn, write and manage. It offer less code writing efforts to the developer. The legacy of library concept is still maintained by the managed category. While writing an unmanaged code, the programmer works closer to the system hardware, thus faces security and memory management issues too. Most of the modern languages under the managed class have been written (directly or indirectly) in the unmanaged C language code. Unlike the newer, the unmanaged code does not need any supporting environment to execute. It’s ready to run just after the source code compilation.

Difference between Managed & Unmanaged Code:


Tuesday, August 7, 2018

Common Type System

Common Type System ( CTS )


The language interoperability, and .NET Class Framework, are not possible without all the language sharing the same data types. What this means is that an "int" should mean the same in VB, VC++, C# and all other .NET compliant languages. The common type system defines how types are declared, used, and managed in the common language runtime, and is also an important part of the runtime's support for cross-language integration. The Common Type System (CTS) standardizes the data types of all programming languages using .NET under the umbrella of .NET to a common data type for easy and smooth communication among these .NET languages.
          For example, when we declare an int type data type in C# and VB.Net then they are converted to int32. In other words, now both will have a common data type that provides flexible communication between these two languages.



The common type system performs the following functions:
  • Establishes a framework that helps enable cross-language integration, type safety, and high-performance code execution.
  • Provides an object-oriented model that supports the complete implementation of many programming languages.
  • Defines rules that languages must follow, which helps ensure that objects written in different languages can interact with each other.
  • Provides a library that contains the primitive data types (such as Boolean, Byte, Char, Int32, and UInt64) used in application development.
-S
     - Prof. Shardul P. Patil

Monday, August 6, 2018

Common Language Runtime

Common Language Runtime


The CLR stands for Common Language Runtime is an Execution Environment. It works as a layer between Operating Systems and the applications written in .Net languages that conforms to the Common Language Specification (CLS).
The common language runtime (CLR) is the core runtime engine for executing applications in the .NET Framework. The CLR allows an instance of a class written in one language to call a method of the class written in another language. At the base level, it is the infrastructure that executes applications, and allows them to interact with the other parts of the Framework. The code which runs under the CLR is called as Managed Code. Programmers need not to worry on managing the memory if the programs are running under the CLR as it provides memory management and thread management. The main function of Common Language Runtime (CLR) is to convert the Managed Code into native code and then execute the Program. It acts as a layer between Operating Systems and the applications written in .Net languages.
Compilers and tools expose the common language runtime's functionality and enable you to write code that benefits from this managed execution environment. Code that you develop with a language compiler that targets the runtime is called managed code; it benefits from features such as cross-language integration, cross-language exception handling, enhanced security, versioning and deployment support, a simplified model for component interaction, and debugging and profiling services.
CLR handles the execution of code and provides useful services for the implementation of the program. In addition to executing code, CLR provides services such as memory management, thread management, security management, code verification, compilation, and other system services.
The main function of Common Language Runtime (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 . The Common Language Runtime (CLR) 's just in time (JIT) compilation converts Intermediate Language (MSIL) to native code on demand at application run time.
Functions of the CLR:
Class Loader:
Used to load all classes at run time.
MSIL to Native code compiler:
The Just In Time (JTI) compiler will convert MSIL code into native code.
Code Manager:
It manages the code at run time.
Garbage Collector:
It manages the memory. Collect all unused objects and deallocate them to reduce memory.
Thread Support:
It supports multi-threading of our application.
Exception Handler:
Exception Manager will handle exceptions thrown by application by executing catch block provided by exception, it there is no catch block , it will terminate application.

- Prof. Shardul P. Patil

Saturday, August 4, 2018

Architecture of .Net Framework

Architecture of .Net Framework


The architecture of .NET framework is tiered, modular, and hierarchical architecture. Each tier of the .NET Framework is a layer of abstraction. .NET languages are the top tier and the most abstracted level. The common language runtime is the bottom tier, the least abstracted, and closest to the native environment. This is important since the common language runtime works closely with the operating environment to manage .NET applications. The .NET Framework is partitioned into modules, each with its own distinct responsibility. Finally, since higher tiers request services only from the lower tiers.

The .NET Framework is a managed environment. The common language runtime monitors the execution of .NET applications and provides essential services. It manages memory, handles exceptions, ensures that applications are well-behaved, and much more.

         Language interoperability is one goal of .NET. The .NET languages share a common runtime (the common language runtime), the Framework Class Library (FCL), a common component model, and common types. In .NET, the programming language is a lifestyle choice. Except for subtle differences, C#, VB.NET, or JScript. .NET offer a similar experience.


Components of .Net Framework:-

  Common Language Runtime (CLR)
  .Net Framework Class Library
  Common Type System (CTS)
  Common Language Specification (CLS)

Common Language Runtime (CLR):

Common Language Runtime (CLR) is the programming environment (Virtual Machine component) that manages the execution of programs written in any language. The common language runtime (CLR) is the core runtime engine for executing applications in the .NET Framework. The CLR allows an instance of a class written in one language to call a method of the class written in another language. The Common Language Runtime (CLR) is a very important part of the .NET Framework. At the base level, it is the infrastructure that executes applications, and allows them to interact with the other parts of the Framework. The .Net Framework provides runtime environment called Common Language Runtime (CLR). .It provides an environment to run all the .Net Programs. The code which runs under the CLR is called as Managed Code. Programmers need not to worry on managing the memory if the programs are running under the CLR as it provides memory management and thread management. The main function of Common Language Runtime (CLR) is to convert the Managed Code into native code and then execute the Program. It acts as a layer between Operating Systems and the applications written in .Net languages.
CLR handles the execution of code and provides useful services for the implementation of the program. In addition to executing code, CLR provides services such as memory management, thread management, security management, code verification, compilation, and other system services.
Functions of CLR:
             ·         Conversion of IL to native code
             ·         Exception handling
             ·         Type safety
             ·         Memory management (using the Garbage Collector)
             ·         Security
             ·         Improved performance
             ·         Language independency
             ·         Platform independency
             ·        Architecture independency

Framework Class Library (FCL):

The .NET Framework Class Library (FCL) is a set of managed classes that provide access to system services. File input/output, sockets, database access, remoting, and XML are just some of the services available in the FCL. Importantly, all the .NET languages rely on the same managed classes for the same services. This is one of the reasons that, once you have learned any .NET language, you have learned 40 percent of every other managed language. The same classes, methods, parameters, and types are used for system services regardless of the language. This is one of the most important contributions of FCL.
Common Type System (CTS):
CTS define some basic data types that IL can understand. The common type system defines how types are declared, used, and managed in the common language runtime. It important part of the runtime's support for cross-language integration, type safety, and high-performance code execution. It provides an object-oriented model that supports the complete implementation of many programming languages. It defines rules that languages must follow, which helps ensure that objects written in different languages can interact with each other. Provides a library that contains the primitive data types (such as Boolean, Byte, Char, Int32, and UInt64) used in application development.
Common Language Specification (CLS):
It is a sub set of CTS and it specifies a set of rules that needs to be adhered or satisfied by all language compilers targeting CLR. It helps in cross language inheritance and cross language debugging. Common Language Specification (CLS) is a set of basic language features that .Net Languages needed to develop Applications and Services , which are compatible with the .Net Framework. Microsoft has defined some specifications that each .Net language has to follow. When there is a situation to communicate Objects written in different .Net Complaint language, those objects must expose the features that are common to all the languages. Common Language Specification (CLS) ensures complete interoperability among applications, regardless of the language used to create the application.

- Prof. Shardul P. Patil

Thursday, August 2, 2018

Overview of .Net

Overview of .Net:-
The .NET framework is a complete development and execution environment. That allows the developer to develop, run and deploy the Console application, Windows application Web application, Service oriented application (WCF), Web service, Windows service, WPF, WWF etc. .NET framework support the object oriented programming model for multiple language such as, C#, VB, vC++, J#, etc. It support the language interoperability. Interoperability implies that each language can use the code written in some other language. It provides a common set of tools and enables easy integration of module developed with one another. It also enables the developers to create shareable component to be used in distributed computing architecture.
The .NET Framework consists of the common language runtime and the .NET Framework class library. The common language runtime is the foundation of the .NET Framework. You can think of the runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety and other forms of code accuracy that promote security and robustness. In fact, the concept of code management is a fundamental principle of the runtime. Code that targets the runtime is known as managed code, while code that does not target the runtime is known as unmanaged code. The class library is a comprehensive, object-oriented collection of reusable types that you can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET, such as Web Forms and XML Web services.

Objectives of .Net Framework :-
  • To provide a consistent object-oriented programming environment whether object code is stored and executed locally, executed locally but Internet-distributed, or executed remotely.
  • To provide a code-execution environment that minimizes software deployment and versioning conflicts.
  • To provide a code-execution environment that promotes safe execution of code, including code created by an unknown or semi-trusted third party.
  • To provide a code-execution environment that eliminates the performance problems of scripted or interpreted environments.
  • To make the developer experience consistent across widely varying types of applications, such as Windows-based applications and Web-based applications.
  • To build all communication on industry standards to ensure that code based on the .NET Framework can integrate with any other code.




Advantages of .Net Framework:

     1. Interoperability 
The .NET Framework supports interoperability between new application and existing application. It implies that the code written in one language can be used in some other language.
           2.      Cross Platform support
Each .NET compatible language, such as C#, VB, VC++ provides its own compiler to compile code to MSIL. After that, the common runtime engine compile MSIL code to native code with the help of Just In Time (JIT) compiler and then run the application.
           3.      Consistent programming model :
With .Net accessing data with a C# and VB.Net very similar apart from slight syntactical differences. Both the programs need to import the System.Data namespace, both programs establish connection with database and both programs run a query and display the data.
           4.      Direct Support for Security :
The .Net framework enables the developer and the system administrator to specify method level security. The .NET Framework provides security model that allows you to authorize and authenticate the user.
           5.      Simplified Development efforts:
The .Net Framework simplifies debugging with support for Runtime diagnostics.
           6.      Easy application deployment and Maintenance:
The .Net Framework makes easy to deploy applications. The .Net Framework handles the details of locating and loads the components. The .NET Framework makes the task of employment easier. In most cases, to install an application along with component on the target computer is easier.
            7.      Assemblies:
Assembly is elementary unit in a framework application. It performs various functions in programming with the .Net Frame work. Every computer that has the .Net Framework installed with have the Global Assembly Cache.
             8.      Language Independence:
The .NET framework provides the multiple language support by using feature known as common type system. That is built into common language runtime.
             9.      Base Class Library:
            The base class library provides the fundamental building block for any application you develop. These applications could be windows, web, console, or service oriented. The BCL mostly serves as the main point of interaction with the CLR.

-Prof. Shardul P. Patil