CHAPTER 1 THE PHILOSOPHY OF .NET
on numerous operating systems). In fact, there is an international standard for the C# language and a
large subset of the .NET platform and implementations already exist for many non-Windows operating
systems (more details at the conclusion of this chapter).
Compiling CIL to Platform-Specific Instructions
Due to the fact that assemblies contain CIL instructions rather than platform-specific instructions, CIL
code must be compiled on the fly before use. The entity that compiles CIL code into meaningful CPU
instructions is a JIT compiler, which sometimes goes by the friendly name of Jitter. The .NET runtime
environment leverages a JIT compiler for each CPU targeting the runtime, each optimized for the
underlying platform.
For example, if you are building a .NET application to be deployed to a handheld device (such as a
Windows mobile device), the corresponding Jitter is well equipped to run within a low-memory
environment. On the other hand, if you are deploying your assembly to a back-end company server
(where memory is seldom an issue), the Jitter will be optimized to function in a high-memory
environment. In this way, developers can write a single body of code that can be efficiently JIT compiled
and executed on machines with different architectures.
Furthermore, as a given Jitter compiles CIL instructions into corresponding machine code, it will
cache the results in memory in a manner suited to the target operating system. In this way, if a call is
made to a method named PrintDocument(), the CIL instructions are compiled into platform-specific
instructions on the first invocation and retained in memory for later use. Therefore, the next time
PrintDocument() is called, there is no need to recompile the CIL.
Note It is also possible to perform a “pre-JIT” of an assembly when installing your application using the
ngen.exe command-line tool that ships with the .NET 4.5 Framework SDK. Doing so can improve startup time for
graphically intensive applications.
The Role of .NET Type Metadata
In addition to CIL instructions, a .NET assembly contains full, complete, and accurate metadata, which
describes each and every type (e.g., class, structure, enumeration) defined in the binary, as well as the
members of each type (e.g., properties, methods, events). Thankfully, it is always the job of the compiler
(not the programmer) to emit the latest and greatest type metadata. Because .NET metadata is so
wickedly meticulous, assemblies are completely self-describing entities.
To illustrate the format of .NET type metadata, let’s take a look at the metadata t