Java Reference
In-Depth Information
Programs written in .NET languages are first compiled into a stack-based bytecode
format named as Common Intermediate Language (CIL) 14 . Then this CIL code is fed into
the CLR, with the associated metadata. Metadata in .NET is binary information that
describes the classes and methods (with their declarations and implementations), data types,
references to other types and members, and attributes (for example, versioning information,
security permissions, etc.) of the program. Metadata is stored in a file called the Manifest.
CIL code and the Manifest are wrapped in a Portable Executable 15 file called an Assembly.
An Assembly can consist of one or more program files and a manifest, possibly along with
reference files, such as bitmap files that are called within the program. Assemblies can be
either Process Assemblies (.EXE files) or Library Assemblies (.DLL files). (See Figure 8.3)
FIGURE 8.3 Single-file versus multi-file assembly.
CIL code contained in an assembly with metadata is managed code. The program code
that executes under the management of a VM is called managed code, whereas the program
code that is directly compiled into machine code before execution and executed directly by
the CPU is called unmanaged code. Managed code is designed to be more reliable and robust
than unmanaged code, with features such as garbage collection and type safety available
to it. The managed code running in the CLR cannot be accessed outside the run-time
environment and/or cannot call Operating System (OS) services directly from outside the
run-time environment. This isolates programs and makes computers more secure. Managed
code needs the CLR's JIT compiler to convert it to native executable code, and it relies
on CLR to provide services such as security, memory, management, and threading during
run-time.
Pre-compiled executables are called unmanaged code. One may prefer bypassing CLR
and make direct calls to specific OS services through the Win32 API. However, such code
would be considered unsafe because it yields security risks, and it will throw an exception if
fed to CLR because it is not verifiable. Unmanaged code is directly compiled to architecture-
specific machine code. Hence, unmanaged code is not portable.
Figure 8.4 depicts the compilation of programs written in .NET languages for the .NET
14 Also referred to asIntermediateLanguage(IL), formerlyMicrosoftIntermediateLanguage(MSIL).
15 The Portable Executable (PE) format is a file format for executables, object code, and DLLs, used in
32-bit and 64-bit versions of Windows operating systems.
 
Search WWH ::




Custom Search