Академический Документы
Профессиональный Документы
Культура Документы
Agenda
Interoperability with
Unmanaged code
IL and Verification
Unsafe Code
Example :
Compilers for Ada, APL, Caml, COBOL, Eiffel, Forth, Fortran, Haskell,
Lexico, LISP, LOGO,Lua, Mercury, ML, Mondrian, Oberon, Pascal, Perl, Php,
Prolog, Python, RPG, Scheme, Smalltalk, and Tcl/Tk.
These compilers check the syntax and analyze the source code and generate a
Managed Module.
CLR header
If the header uses the PE32 format, the file can run on a 32-bit or 64-bit version of
Windows.
If the header uses the PE32+ format, the file requires a 64-bit version of Windows to
run.
Also indicates the type of file: GUI, CUI, or DLL, and contains a timestamp indicating
when the file was built.
CLR header
Version of the CLR required, module's entry point method (Main method), and the
location/ size of the module's metadata, resources, strong name, some flags, and
other less interesting stuff.
The above command would result with result.txt file which contains
the PE header information , CLR Header , Metadata and IL code.
Also can use ildasm a tool to view the IL code and Metadata
information. (Will discuss in next chapter.)
For projects that have just one managed module and no resource (or
data) files, the assembly will be the managed module.
There are tools to create assembly with more than one managed
module. (Discussed in next chapter.)
In visual studio , under project's property pages, click the Build tab,
and then selecting an option in the Platform Target list.
IL code is converted to native CPU instructions by the CLR's JIT (justin-time) compiler.
Just before the Main method executes, the CLR detects all of the
types that are referenced by Main's code.
Here ,the Main method refers to a single type, Console, causing the
CLR to allocate a single internal structure.
This data structure will be used by the JIT compiler in the CLR.
When Main makes its first call to WriteLine, the JITCompiler is called.
When called, the JITCompiler knows what method is being called and what
type defines this method.
JIT compiler then searches the internal data structure to verify the structure
and syntax of the method and finally compiles the IL code into native CPU
instructions.
Then, JITCompiler goes back to the entry for the called method in the type's
internal data structure created by the CLR and replaces the reference that
called it in the first place with the address of the block of memory containing
the native CPU instructions it just compiled.
Finally, the JITCompiler function jumps to the code in the memory block.
Main now calls WriteLine a second time. This time, the code for
WriteLine has already been verified and compiled. So the call goes
directly to the block of memory, skipping the JITCompiler function
entirely. After the WriteLine method executes, it returns to Main.
All subsequent calls to the method execute at the full speed of the
native code because verification and compilation to native code do not
need to be performed again.
This means that the compiled code is discarded when the application
terminates.
The NGen.exe tool that ships with the .NET Framework can be used to compile
IL code to native code when an application is installed on a user's machine.
The code gets compiled at install time, the CLR's JIT compiler does not have
to compile the IL code at run time, and this can improve the application's
performance.
Advantages :
Improving an application's startup time
compiles the IL to native code and saves the output in a separate file.
This new file is placed in a folder under the directory with a name like
C:\Windows\Assembly\NativeImages_v2.0.50727_32.
Whenever the CLR loads an assembly file, the CLR looks to see if a
corresponding NGen'd native file exists. If a native file cannot be
found, the CLR JIT compiles the IL code as usual.
Developers can use the base classes directly or derive from these
classes to provide customized functionality.
CTS defines how data types are going to be declared and managed in runtime.
In .Net Framework, System.Object is the common base type from where all
the other types are derived.
The types in .NET Framework are the base on which .NET applications,
components, and controls are built.
Thank You