Generated by DeepSeek V3.2| Common Language Runtime | |
|---|---|
| Name | Common Language Runtime |
| Developer | Microsoft |
| Released | 13 February 2002 |
| Operating system | Microsoft Windows, Linux, macOS |
| Platform | .NET Framework, .NET Core, .NET |
| Genre | Virtual machine, Runtime system |
| License | MIT License |
Common Language Runtime. It is the foundational execution engine of the .NET Framework, and later .NET Core and .NET, developed by Microsoft. The CLR provides a managed environment for running applications, handling core services such as memory management, type safety, and exception handling. Its introduction was a central part of Microsoft's strategy with the .NET initiative to provide a unified platform for building diverse applications.
The Common Language Runtime serves as the virtual machine component within the .NET ecosystem, abstracting the underlying operating system and computer hardware. It executes code compiled into Microsoft Intermediate Language (MSIL), which is then just-in-time compiled into native code. This architecture enables key features like language interoperability, as compilers for languages like C#, Visual Basic .NET, and F# all target the same runtime. The design was influenced by earlier virtual machine technologies, including the Java virtual machine and research from projects like Singularity.
The core architecture of the CLR is built around several key components and services. The Class loader is responsible for loading assemblies, which are the fundamental deployment units containing metadata and MSIL code. The JIT compiler, often referred to as the JITter, converts MSIL into optimized machine code for the host CPU. The Type system enforces Common Type System (CTS) rules, while the Thread pool manages execution threads. Other critical subsystems include the Exception handling manager and the Debugger interface, which integrates with tools like Visual Studio.
Managed execution refers to the CLR's control over the lifecycle and execution of program code. When an application starts, the CLR's hosting interface is activated, often by a host like Internet Information Services or a standalone executable. The Execution engine then begins verifying and compiling MSIL, enforcing code access security policies. The runtime manages all aspects of program execution, including stack walking for exception propagation and providing services for profiling and monitoring. This model contrasts with unmanaged code executed directly by the Windows API.
A cornerstone of the CLR is its automatic memory management via a tracing garbage collector. The garbage collector operates on a managed heap, automatically reclaiming memory from objects no longer in use, which helps prevent memory leaks and dangling pointers. The heap is divided into generations (Gen 0, Gen 1, Gen 2) and a Large Object Heap for optimization. The CLR also provides mechanisms for deterministic finalization through the IDisposable interface and the `using` statement in C#.
The CLR implements a robust, multi-layered security model to protect systems and data. Its Code Access Security (CAS) system, prominent in the .NET Framework, evaluates permissions based on an assembly's evidence, such as its digital signature or URL. The runtime also enforces type safety and code verification to prevent buffer overflows and other vulnerabilities. With the evolution of .NET Core, the security emphasis shifted toward role-based security and leveraging operating system security boundaries, like those in Windows Server and Linux.
Interoperability features allow managed code within the CLR to interact with existing unmanaged components. The Platform Invocation Services (P/Invoke) enables calls to functions in native DLLs, such as the Windows API or libc. For COM interoperability, the CLR provides tools like the Type Library Importer (Tlbimp.exe) and Runtime Callable Wrappers. Furthermore, the Common Language Infrastructure (CLI) standard, ratified by Ecma International and ISO/IEC, ensures a degree of cross-platform interoperability across implementations like Mono.
Category:Microsoft development tools Category:.NET Framework Category:Virtual machines Category:Runtime systems