All Topics  
Common Intermediate Language

 

   Email Print
   Bookmark   Link






 

Common Intermediate Language



 
 
Common Intermediate Language (CIL, pronounced either "sil" or "kil") (formerly called Microsoft Intermediate Language or MSIL) is the lowest-level human-readable
Human-readable

The term "human-readable" refers to a representation of data that can be naturally Reading by humans. In most contexts, the alternative representation is a machine-readable format or medium of data primarily designed for reading by electronic, mechanical or optical devices, or computers....
 programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
 in the Common Language Infrastructure
Common Language Infrastructure

The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of a number of runtimes including the .NET Framework, Mono , and Portable.NET....
 and in the .NET Framework
.NET Framework

The Microsoft .NET Framework is a software framework that is available with several Microsoft Windows operating systems. It includes a large Library of coded solutions to prevent common programming problems and a virtual machine that manages the execution of programs written specifically for the Software framework....
. Languages which target the .NET Framework compile to CIL, which is assembled into bytecode
Bytecode

Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software Interpreter as well as being suitable for further compilation into machine language....
. CIL is an object-oriented assembly language
Assembly language

An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
, and is entirely stack-based
Stack-based memory allocation

Stack s in computing architectures are regions of memory where data is added or removed in a LIFO manner.In most modern computer systems, each Thread has a reserved region of memory referred to as its stack....
. It is executed by a virtual machine
Virtual machine

In computer science, a virtual machine is a software implementation of a machine that executes programs like a real machine.Definitions...
.

CIL was originally known as Microsoft Intermediate Language (MSIL) during the beta releases of the .NET languages.






Discussion
Ask a question about 'Common Intermediate Language'
Start a new discussion about 'Common Intermediate Language'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Common Intermediate Language (CIL, pronounced either "sil" or "kil") (formerly called Microsoft Intermediate Language or MSIL) is the lowest-level human-readable
Human-readable

The term "human-readable" refers to a representation of data that can be naturally Reading by humans. In most contexts, the alternative representation is a machine-readable format or medium of data primarily designed for reading by electronic, mechanical or optical devices, or computers....
 programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
 in the Common Language Infrastructure
Common Language Infrastructure

The Common Language Infrastructure is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of a number of runtimes including the .NET Framework, Mono , and Portable.NET....
 and in the .NET Framework
.NET Framework

The Microsoft .NET Framework is a software framework that is available with several Microsoft Windows operating systems. It includes a large Library of coded solutions to prevent common programming problems and a virtual machine that manages the execution of programs written specifically for the Software framework....
. Languages which target the .NET Framework compile to CIL, which is assembled into bytecode
Bytecode

Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software Interpreter as well as being suitable for further compilation into machine language....
. CIL is an object-oriented assembly language
Assembly language

An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
, and is entirely stack-based
Stack-based memory allocation

Stack s in computing architectures are regions of memory where data is added or removed in a LIFO manner.In most modern computer systems, each Thread has a reserved region of memory referred to as its stack....
. It is executed by a virtual machine
Virtual machine

In computer science, a virtual machine is a software implementation of a machine that executes programs like a real machine.Definitions...
.

CIL was originally known as Microsoft Intermediate Language (MSIL) during the beta releases of the .NET languages. Due to standardization of C# and the Common Language Infrastructure, the bytecode is now officially known as CIL. Because of this legacy, CIL is still frequently referred to as MSIL, especially by long-standing users of the .NET languages.

General information

During compilation of .NET programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
s, the source code
Source code

In computer science, source code is any collection of statements or declarations written in some human-readable computer programming language....
 is translated into CIL code rather than platform or processor-specific object code
Object file

In computer science, object code, or an object file, is the representation of code that a compiler or assembler generates by processing a source code file....
. CIL is a CPU- and platform-independent instruction set that can be executed in any environment supporting the .NET framework (either the .NET runtime
Common Language Runtime

The Common Language Runtime is a core component of Microsoft .NET Framework initiative. It is Microsoft's implementation of the Common Language Infrastructure standard, which defines an execution environment for program code....
 on Microsoft Windows
Microsoft Windows

Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces ....
 operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
, or the independently derived Mono
Mono (software)

Mono is a project led by Novell to create an Ecma International standard compliant, .NET Framework-compatible set of tools, including among others a C Sharp compiler and a Common Language Runtime....
, which can be used to execute some bytecode
Bytecode

Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software Interpreter as well as being suitable for further compilation into machine language....
 on Linux
Linux

Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license...
 or Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
-based operating systems). CIL code is verified for safety during runtime, providing better security and reliability than natively compiled binaries.

Bytecode instructions

CIL bytecode has instruction
Instruction (computer science)

In computer science, an instruction is a single operation of a central processing unit defined by an instruction set architecture. In a broader sense, an "instruction" may be any representation of an element of an executable program, such as a bytecode....
s for the following groups of tasks:
  • Load and store
  • Arithmetic
    Arithmetic

    Arithmetic or arithmetics is the oldest and most elementary branch of mathematics, used by almost everyone, for tasks ranging from simple day-to-day counting to advanced science and business calculations....
  • Type conversion
    Type conversion

    In computer science, type conversion or typecasting refers to changing an entity of one data type into another. This is done to take advantage of certain features of type hierarchies....
  • Object creation and manipulation
    Dynamic memory allocation

    In computer science, dynamic memory allocation is the allocation of computer storage storage for use in a computer program during the runtime of that program....
  • Operand stack management (push / pop)
    Stack (data structure)

    In computer science, a stack is an abstract data type and data structure based on the principle of LIFO . Stacks are used extensively at every level of a modern computer system....
  • Control transfer (branching)
    Branch (computer science)

    A branch is a point in a computer program where the flow of control is altered. The term branch is usually used when referring to a program written in machine code or assembly language; in a high-level programming language, branches usually take the form of conditional statements, subroutine calls or GOTO statements....
  • Method invocation and return
    Subroutine

    In computer science, a subroutine or subprogram is a portion of computer code within a larger computer program, which performs a specific task and is relatively independent of the remaining code....
  • Throwing exceptions
    Exception handling

    Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions - special conditions that change the normal flow of execution....
  • Monitor-based concurrency
    Monitor (synchronization)

    In concurrent programming, a monitor is an Object intended to be used safely by more than one Thread .The defining characteristic of a monitor is that its methods are executed with mutual exclusion....


Just-in-time compilation

Just-in-time compilation
Just-in-time compilation

In computing, just-in-time compilation , also known as dynamic translation, is a technique for improving the runtime performance of a computer program....
 involves turning the byte-code into code immediately executable by the CPU. The conversion is performed gradually during the program's execution. JIT compilation provides environment-specific optimization, runtime type safety, and assembly verification. To accomplish this, the JIT compiler examines the assembly metadata for any illegal accesses and handles violations appropriately.

Native image generator compilation

The native image generator (NGEN) produces a native binary image for the current environment. The byte-code is either skipped entirely or converted into native CPU instructions completely before runtime. This eliminates the JIT overhead at the expense of portability; whenever an NGEN-generated image is run in an incompatible environment, .NET framework automatically reverts to using JIT. Once NGEN is run against an assembly, the resulting native image is placed into the Native Image Cache for use by all other .NET assemblies. This makes it possible, for example, to use NGEN to process .NET assemblies at installation time, saving processor time later on, when the end-user invokes the application on their system.

NGEN is intended to make the assembly execute faster by removing the JIT compilation process at runtime, but this does not always improve performance because some optimizations can be done only by a JIT compiler (i.e. if the JIT compiler knows that the code is already running with full trust, it can skip certain expensive security checks). Because of this fact, it makes sense to use NGEN only after benchmarking the application performance before and after it.

Metadata

.NET records information about compiled classes as Metadata
Metadata

Metadata is "data about other data", of any sort in any media. An item of metadata may describe an individual datum, or content item, or a collection of data including multiple content items and hierarchical levels, for example a database schema....
. Like the type library in the Component Object Model
Component Object Model

Component Object Model is an interface standard for software componentry introduced by Microsoft in 1993. It is used to enable interprocess communication and dynamic object creation in a large range of programming languages....
, this enables applications to support and discover the interfaces, classes, types, methods, and fields in the assembly. The process of reading such metadata is called reflection
Reflection (computer science)

In computer science, reflection is the process by which a computer program can observe and modify its own structure and behaviour. The programming paradigm driven by reflection is called reflective programming....
.

Executing CIL

  • Source code is converted to Common Intermediate Language, .NET’s equivalent to Assembly language
    Assembly language

    An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
     for a CPU.
  • CIL is then assembled into bytecode
    Bytecode

    Bytecode is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software Interpreter as well as being suitable for further compilation into machine language....
     and a .NET assembly
    .NET assembly

    In the Microsoft .NET software framework, an assembly is a partially compiler code library for use in deployment, versioning and security. In the Microsoft Windows implementation of .NET, an assembly is a PE file for Windows GUI on Intel x86....
     is created.
  • Upon execution of a .NET assembly, its bytecode is passed through the Common Language Runtime
    Common Language Runtime

    The Common Language Runtime is a core component of Microsoft .NET Framework initiative. It is Microsoft's implementation of the Common Language Infrastructure standard, which defines an execution environment for program code....
    's JIT compiler to generate native code. (NGEN compilation eliminates this step at run time.)
  • The native code is executed by the computer's processor.


External links

  • Hello world program in CIL