• Non ci sono risultati.

Inside CLR

N/A
N/A
Protected

Academic year: 2021

Condividi "Inside CLR"

Copied!
14
0
0

Testo completo

(1)

Inside CLR

Davide Morelli

(2)

IL is compiled, not interpreted

Source code

• C#

• VB.NET

• IronPython

• …

IL

• Same

assembly will work on all OS and arch

Assembly

• Compiled by JIT

• Only when

needed

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

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;

} }

1) JIT compiles main

2) JIT compiles WriteLine(string)

and lots of required stuff..

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)

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;

} }

1) JIT compiles main stubs are created for

Foo(int) and Bar(int) 2) Foo(int) is Jitted and

executed

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

called

3) Foo(int) is executed

(was already jitted)

(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

Riferimenti

Documenti correlati

For questions requiring calculations, full credit is given only if necessary steps of the calculations are

Solution proposed by Roberto Tauraso, Dipartimento di Matematica, Universit`a di Roma “Tor Vergata”, via della Ricerca Scientifica, 00133 Roma,

It remains to show that the partition exists when n is multiple of 8 and n ≥ 16.. For any non-negative integer x, we have a partition of {1

[r]

Let α, β, and γ be the angle measures of a non-degenerate triangle.. Let a, b and c be the side lenghts and let s be

Patients suffering from  cluster headache, a primary headache disorder, also show similar re- sults, with significantly lower rCBF changes during the headache-free period compared

“It’s criminalizing mental illness,” the Cook County sheriff, Thomas Dart, told me as he showed me the jail, on a day when 60 percent of the jail’s intake reported that they had

To construct the other three vectors as requested we need to find a basis of W and orthogonalize it... However in this case the calculations are so easy that it can be