Home All Groups Group Topic Archive Search About

Where the native code store for second time execution

Author
30 Mar 2007 9:58 AM
Umeshnath
Where the native code store for second time execution. When it will clear or
how long it will be there ?

Author
30 Mar 2007 1:48 PM
Wibberlet
Hi Umeshnath,

Please consider the following code...

public static void main()
{
    Console.writeline("First call to the writeline method");
    Console.writeline("Second call to the writeline method");
}

When the call to writeline is made, the JITCompiler has to convert the
intermediate language (IL) into native code. The IL is stored in the
assembly's metadata that the code is contained in. The JITCompiler stores the
native code in a section of memory that has been dynamically allocated and
then redirects the call to Console.writeline to the newly created native
code.

When the second call to Console.writeline is made, the native code has
already been compiled and can be executed without the 'compile to native'
step.

This means that there is a slight performance hit the first time the call to
writeline is made but not the second time.

Since the JITCompiler stores the code in dynamically allocated memory, it is
thrown away when the application terminates. If you stop the application and
then re-run it, the code for writeline will have to be JITCompiled again as
explained previously.

Hope this helps,

wibberlet (development blog at  http://wibberlet.blogspot.com)





=================================================

Show quote
"Umeshnath" wrote:

> Where the native code store for second time execution. When it will clear or
> how long it will be there ?
Author
2 Apr 2007 10:58 AM
Umeshnath
Hi,
My query is slight different you think about to run a dot exe and close it,
then again you try to run it the same exe. You can see, in the second the exe
is executed faster than the first time. When exe is running the JIT compiles
and generate CPU specific native code and store it into the process specific
memory and run it. When close normally it will unload from the memory then
how second time it will be faster.

If it stores some where ,where exactly , when it removes ……..


Show quote
"Wibberlet" wrote:

> Hi Umeshnath,
>
> Please consider the following code...
>
> public static void main()
> {
>     Console.writeline("First call to the writeline method");
>     Console.writeline("Second call to the writeline method");
> }
>
> When the call to writeline is made, the JITCompiler has to convert the
> intermediate language (IL) into native code. The IL is stored in the
> assembly's metadata that the code is contained in. The JITCompiler stores the
> native code in a section of memory that has been dynamically allocated and
> then redirects the call to Console.writeline to the newly created native
> code.
>
> When the second call to Console.writeline is made, the native code has
> already been compiled and can be executed without the 'compile to native'
> step.
>
> This means that there is a slight performance hit the first time the call to
> writeline is made but not the second time.
>
> Since the JITCompiler stores the code in dynamically allocated memory, it is
> thrown away when the application terminates. If you stop the application and
> then re-run it, the code for writeline will have to be JITCompiled again as
> explained previously.
>
> Hope this helps,
>
> wibberlet (development blog at  http://wibberlet.blogspot.com)
>
>  
>
>
>
> =================================================
>
> "Umeshnath" wrote:
>
> > Where the native code store for second time execution. When it will clear or
> > how long it will be there ?

AddThis Social Bookmark Button