liveBook · Manning

Common Language Runtime

As explained in .NET in Action, Second Edition

The .NET runtime is the execution environment that loads .NET assemblies and translates their intermediate code into processor-specific instructions.

The Common Language Runtime (CLR) is the execution environment shared by .NET languages. The modern .NET runtime is called CoreCLR; the original .NET Framework runtime was called CLR. C#, F#, and Visual Basic compilers produce Common Intermediate Language (CIL), which CoreCLR can execute. The runtime also provides memory management. section 1.1 section 1.5

A language compiler places CIL in a DLL. Because CIL does not target a particular processor, that DLL can run on another supported operating system or processor when a .NET runtime is available. CoreCLR normally uses just-in-time (JIT) compilation to turn CIL into machine code as the application needs it, rather than compiling the entire application at startup. section 1.5.1 section 1.5.2

For a known deployment target, such as a Docker container, ahead-of-time (AOT) compilation can reduce the initial wait for JIT compilation. AOT can also trim unused code, but trimming needs thorough testing because it may remove too much. The runtime’s other major concern, garbage collection, is introduced alongside CIL and JIT rather than detailed here. section 1.5.2 section 1.5

Figure 1.4 .NET languages compile to CIL in a DLL file that can be run on any machine with a .NET runtime.

Trace a .NET language from compilation into a CIL DLL, then through the runtime on the machine that executes it. section 1.5.1

How .NET in Action, Second Edition covers it

How deep it goes
Explains CIL portability and on-demand JIT compilation, while introducing garbage collection only at a high level.
Examples
Uses a compiler-to-CIL-to-runtime diagram and a Docker deployment target to illustrate portability and AOT.
What it assumes
Defines runtime and DLL terminology from basics; treats familiarity with Java bytecode as optional.
What you can do after
Evaluate/understand why a CIL DLL needs a .NET runtime and when JIT startup cost might favor AOT.
How it connects
Connects the CLR to CIL, DLLs, JIT compilation, garbage collection, and ahead-of-time compilation.

Also explained in

Compare how 3 books explain Common Language Runtime →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.