/* This sample shows that local's lifetime ends before Sleep, a lot earlier than its lexical scope. * This code is JITted into partialy-interruptible code - only safe points are on method calls * (please note each such safepoint resets previous tracked slots, so safepoint without any * following '+' means - "there are no live slots till now" * > !u -gcinfo -o 00007fff43218528 * Normal JIT generated code * CoreCLR.CollectScenarios.Scenarios.EagerRootCollection.SimpleCase(Int32) * Begin 00007fff43333450, size 40 * 0000 00007fff`43333450 57 push rdi * 0001 00007fff`43333451 56 push rsi * 0002 00007fff`43333452 4883ec28 sub rsp,28h * 0006 00007fff`43333456 8bf2 mov esi,edx * 0008 00007fff`43333458 48b9e0af3e43ff7f0000 mov rcx,7FFF433EAFE0h (MT: CoreCLR.CollectScenarios.Scenarios.EagerRootCollection+BigClass) * 0012 00007fff`43333462 e81969f65e call CoreCLR!JIT_New (00007fff`a2299d80) * 00000017 is a safepoint: * 0017 00007fff`43333467 488bf8 mov rdi,rax * 001a 00007fff`4333346a 488bcf mov rcx,rdi * 001d 00007fff`4333346d e87e5cd15c call System_Private_CoreLib+0xc890f0 (00007fff`a00490f0) (System.Object..ctor(), mdToken: 0000000006000117) * 00000022 is a safepoint: * 00000021 +rdi * 0022 00007fff`43333472 897708 mov dword ptr [rdi+8],esi * 0025 00007fff`43333475 8b4f08 mov ecx,dword ptr [rdi+8] * 0028 00007fff`43333478 e813d6ffff call 00007fff`43330a90 (System.Console.Write(Int32), mdToken: 0000000006000093) * 0000002d is a safepoint: * 002d 00007fff`4333347d b9e8030000 mov ecx,3E8h * 0032 00007fff`43333482 e8e97adf5c call System_Private_CoreLib+0xd6af70 (00007fff`a012af70) (Internal.Runtime.Augments.RuntimeThread.Sleep(Int32), mdToken: 00000000060000e7) * 00000037 is a safepoint: * 0037 00007fff`43333487 33c0 xor eax,eax * 0039 00007fff`43333489 4883c428 add rsp,28h * 003d 00007fff`4333348d 5e pop rsi * 003e 00007fff`4333348e 5f pop rdi * 003f 00007fff`4333348f c3 ret */ private int SimpleCase(int value) { BigClass local = new BigClass() { Field = value }; local.DoSomething(); Thread.Sleep(1000); return(0); }
/* This sample shows that local's lifetime ends before loop, a lot earlier than its lexical scope. * This code is JITted into fully-interruptible code - safe points are on all most instructions * (please note, each line within an interruptible section is safepoint so only differences are * printed. For example, at offset 26h, rax content starts to hold live reference. * > !u -gcinfo -o 00007fff43218560 * Normal JIT generated code * CoreCLR.CollectScenarios.Scenarios.EagerRootCollection.SimpleCase2(Int32) * Begin 00007fff433334b0, size 6c * 0000 00007fff`433334b0 57 push rdi * 0001 00007fff`433334b1 56 push rsi * 0002 00007fff`433334b2 4883ec38 sub rsp,38h * 0006 00007fff`433334b6 c5f877 vzeroupper * 0009 00007fff`433334b9 c4e17829742420 vmovaps xmmword ptr [rsp+20h],xmm6 * 0010 00007fff`433334c0 8bf2 mov esi,edx * 00000012 interruptible * 0012 00007fff`433334c2 c4e14857f6 vxorps xmm6,xmm6,xmm6 * 0017 00007fff`433334c7 48b9e0af3e43ff7f0000 mov rcx,7FFF433EAFE0h (MT: CoreCLR.CollectScenarios.Scenarios.EagerRootCollection+BigClass) * 0021 00007fff`433334d1 e8aa68f65e call CoreCLR!JIT_New (00007fff`a2299d80) * 00000026 +rax * 0026 00007fff`433334d6 488bf8 mov rdi,rax * 00000029 +rdi * 0029 00007fff`433334d9 488bcf mov rcx,rdi * 0000002c +rcx * 00007fff`433334dc e80f5cd15c call System_Private_CoreLib+0xc890f0 (00007fff`a00490f0) (System.Object..ctor(), mdToken: 0000000006000117) * 00000031 -rcx -rax * 0031 00007fff`433334e1 897708 mov dword ptr [rdi+8],esi * 0034 00007fff`433334e4 8b4f08 mov ecx,dword ptr [rdi+8] * 0037 00007fff`433334e7 e8b8f3ffff call 00007fff`433328a4 (System.Console.Write(Int32), mdToken: 0000000006000093) * 0000003c -rdi * 003c 00007fff`433334ec 33ff xor edi,edi * 003e 00007fff`433334ee 85f6 test esi,esi * 0040 00007fff`433334f0 7e1a jle 00007fff`4333350c * 0042 00007fff`433334f2 c4e17857c0 vxorps xmm0,xmm0,xmm0 * 0047 00007fff`433334f7 c4e17b2ac7 vcvtsi2sd xmm0,xmm0,edi * 004c 00007fff`433334fc e8af7b835f call CoreCLR!COMDouble::Sin (00007fff`a2b6b0b0) * 0051 00007fff`43333501 c4e14b58f0 vaddsd xmm6,xmm6,xmm0 * 0056 00007fff`43333506 ffc7 inc edi * 0058 00007fff`43333508 3bfe cmp edi,esi * 005a 00007fff`4333350a 7ce6 jl 00007fff`433334f2 * 005c 00007fff`4333350c 33c0 xor eax,eax * 0000005e not interruptible * 005e 00007fff`4333350e c4e17828742420 vmovaps xmm6,xmmword ptr [rsp+20h] * 0065 00007fff`43333515 4883c438 add rsp,38h * 0069 00007fff`43333519 5e pop rsi * 006a 00007fff`4333351a 5f pop rdi * 006b 00007fff`4333351b c3 ret */ private int SimpleCase2(int value) { double total = 0.0; BigClass local = new BigClass() { Field = value }; local.DoSomething(); for (int i = 0; i < value; ++i) { total += Math.Sin(i); // * Math.Pow(i, Math.PI); } return(0); }