inside clr n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Inside CLR PowerPoint Presentation
Download Presentation
Inside CLR

Loading in 2 Seconds...

play fullscreen
1 / 14

Inside CLR - PowerPoint PPT Presentation


  • 98 Views
  • Uploaded on

Inside CLR. Davide Morelli. IL is compiled, not interpreted. public class Hello1 { public static void Main() { System.Console.WriteLine ("Hello, World!"); } } Let’ use Mono: mcs Hello1.cs mono -v -v -v -O=-inline Hello1.exe. C# compiler.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Inside CLR' - huong


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
inside clr

Inside CLR

Davide Morelli

slide3

public class Hello1

{

public static void Main()

{

System.Console.WriteLine("Hello, World!");

}

}

  • Let’ use Mono:
    • mcs Hello1.cs
    • mono -v -v -v -O=-inline Hello1.exe

C# compiler

very verbosely tell me what you do to execute Hello.exe, step by step

slide4

iconst R8 <- [5996560]

sub_imm %esp <- %esp [12] clobbers: 1

x86_push R8

voidcall [System.Console:WriteLine (string)] clobbers: c

br [B1]

(__TEXT,__text) section

lo1_Main:

00000000 pushl %ebp

00000001 movl %esp, %ebp

00000003 subl $0x8, %esp

00000006 subl $0xc, %esp

00000009 pushl $0x5b8010

0000000e nop

0000000f calll 0x1c

00000014 addl $0x10, %esp

00000017 leave

00000018 ret

then it compiles WriteLine

slide5

public class Hello1 {

public static void Main() {

System.Console.WriteLine("Hello, World!");

}

public static int foo(int a) {

return a*a;

}

}

  • method foo is never called
  • foo is not compiled
slide6

public class Hello1 {

public static void Main() {

System.Console.WriteLine("Hello, World!");

System.Console.WriteLine(foo(7));

}

public static int foo(int a) {

return a*a;

}

}

  • foo() is compiled only when the function is called
  • see mono –v –v –v
slide7

1) JIT compiles main

2) JIT compiles

WriteLine(string)

and lots of required stuff..

public class Hello1 {

public static void Main() {

System.Console.WriteLine("Hello, World!");

System.Console.WriteLine(foo(7));

}

public static int foo(int a) {

return a*a;

}

}

3) JIT compiles

foo(int)

4) JIT compiles

WriteLine(int)

virtual stub dispatch
Virtual Stub Dispatch
  • Everytime a method is jitted, all the contained functions are substituted with stubs (an empty box), the functions are not jitted
  • only if (and when) the function is actually called, it gets jitted, the stub substituted with the real code
  • if called again everything is ready
slide9

JIT compiles main

stubs are created for Foo(int) and Bar(int)

public class Hello1 {

public static void Main() {

System.Console.WriteLine("Hello, World!");

if (1==Foo(1)) {

System.Console.WriteLine(Foo(7));

} else {

System.Console.WriteLine(Bar(7));

}

}

public static int Foo(int a) {

return a*a;

}

public static int Bar(int a) {

return a+a;

}

}

2) Foo(int) is Jitted and executed

3) Foo(int) is executed (was already jitted)

4) Bar is never Jitted because the function is never actually called

generational collection
Generational collection
  • expenses of copying mitigated by generational collection
  • new objects  more likely to die soon
references
references
  • ILSPY
    • http://www.ilspy.net/
  • mono:
    • http://www.mono-project.com/
  • Shared Source CLI 2.0
    • http://callvirt.net/blog/files/Shared%20Source%20CLI%202.0%20Internals.pdf‎