Java Reference
In-Depth Information
To check whether all local variables have assigned values before their use.
Once the compiler is done with the passes for problem checks, it initiates the set of
optimizing passes:
To transform expression trees into the sequence of factory method calls necessary to
create the expression trees at run-time,
To rewrite all arithmetic that can possibly have null value as code that checks for null
values,
To rewrite references to methods defined in base classes as non-virtual calls,
To find unreachable code and remove it from the tree, as generating IL for such code
is redundant,
To rewrite switch (constant) expressions as a direct branch to the correct case,
To optimize arithmetic, and
To transform iterator blocks into switch-based state machines.
After all these passes 17 , the compiler can finally generate IL code by using the latest
version of the annotated parse tree. The Microsoft C # compiler is written in unmanaged
C ++ and generates IL code structures as a sequence of basic blocks. The compiler can apply
further optimizations on the basic blocks; for instance, it can rewrite branches between
basic blocks for a more ecient call sequence, or remove the basic blocks containing dead
code. Generated metadata and IR code are then fed to the CLR as an executable, to be
JIT-compiled on any architecture running a Windows OS.
8.5.3 Classic Just-in-Time Compilation in the CLR
Microsoft's .NET run-time has two JIT compilers: the Standard-JIT compiler and the
Econo-JIT compiler. The Econo-JIT compiler works faster than the Standard-JIT com-
piler. It compiles only Common Intermediate Language (CIL) code for methods that are
invoked during run-time, but the native code is not saved for further calls. The Standard-
JIT generates more optimized code than does the Econo-JIT and verifies the CIL code;
compiled code is cached for subsequent invocations.
When an application is executed, the Windows OS checks whether it is a .NET assembly;
if so, the OS starts up the CLR and passes the application to it for execution. The first thing
the CLR's JIT compiler does is to subject the code to a verication process to determine
whether the code is type safe by examining the CIL code and the associated metadata.
In addition to checking that the assembly complies with the CTS, the CLR's JIT uses
the metadata to locate and load classes; discover information about the programs classes,
members, and inheritance; lay out instances in memory; and resolve method invocations
during run-time. The executed assembly may refer to other assemblies; in this case, the
referenced assemblies are loaded as needed.
When a type (for example, a structure, interface, enumerated type, or primitive type) is
loaded, the loader creates and attaches a stub 18 to each of the types methods. All types have
17 There are some more passes for .NET-specific tasks dealing with COM objects, anonymous types and
functions, and dynamic calls using the CLR; however, they are excluded here to avoid introducing extra
terminology and unnecessary details.
18 Astubis a routine that only declares itself and the parameters it accepts and returns an expected value
for the caller. A stub contains just enough code to allow it to be compiled and linked with the rest of the
program; it does not contain the complete implementation.
 
Search WWH ::




Custom Search