Microsoft Intermediate Language

From Wikipedia, the free encyclopedia

Microsoft Intermediate Language (MSIL) is a byte-code assembly that uses Microsoft .NET technology along with the Common Language Runtime to support the execution of computer applications.

Contents

[edit] General information

During compilation of .NET programming languages, the source code is translated into MSIL code rather than platform or processor-specific object code. MSIL is a CPU- and platform-independent instruction set that can be executed in any environment supporting the .NET framework. MSIL code is verified for safety during runtime, providing better security and reliability than natively compiled binaries.

[edit] Just-In-Time (JIT) Compilation

Just-in-time compilation involves the byte-code being turned 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.

[edit] NGEN (Native Image Generator) Compilation

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 Global Assembly Cache for use by all other .NET assemblies. It is advised that NGEN is run during applications' deployment.

[edit] Metadata

Metadata is information about the compiled classes. It serves the same purpose as a type library in COM. Metadata enables applications to support and discover the interfaces of classes in the assembly. The process of reading metadata is called reflection.

[edit] Executing MSIL

The following diagram explains briefly how the .NET Framework compiles and executes program code.

  • Source code is converted to Microsoft Intermediate Language and an assembly is created.
  • Upon execution of a .NET assembly, its MSIL is passed through the Common Language Runtime'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.

[edit] See also

In other languages