1 / 14

Inside CLR

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.

huong
Télécharger la présentation

Inside CLR

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Inside CLR Davide Morelli

  2. IL is compiled, not interpreted

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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)

  8. 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

  9. 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

  10. Garbage Collector

  11. Tracing the roots

  12. compacting the heap

  13. Generational collection • expenses of copying mitigated by generational collection • new objects  more likely to die soon

  14. 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‎

More Related