更新我的一些代码示例以进行培训我注意到以前由CLR保持未初始化的一些本地内存现在正在归零。
这是一个显示“问题”的小CIL示例:
.assembly Test{}
.assembly extern mscorlib{}
.class S extends [mscorlib]System.ValueType
{
.field public int32 n;
}
.method static void F()
{
.locals (int32, valuetype S)
ldloc 0
call void [mscorlib]System.Console::WriteLine(int32)
ldloca 1
ldfld int32 S::n
call void [mscorlib]System.Console::WriteLine(int32)
ret
}
.method static void Main()
{
.entrypoint
.locals (int32, valuetype S)
ldloc 0
call void [mscorlib]System.Console::WriteLine(int32)
ldloca 1
ldfld int32 S::n
call void [mscorlib]System.Console::WriteLine(int32)
call void F()
ret
}
以下是输出:
.Net 2.0(我几乎可以肯定它与 .Net 4.0 相同):
$ /Windows/Microsoft.NET/Framework/v2.0.50727/ilasm.exe Test.il Microsoft (R) .NET Framework IL Assembler. Version 2.0.50727.5420 Copyright (c) Microsoft Corporation. All rights reserved. Assembling 'Test.il' to EXE --> 'Test.exe' Source file is ANSI Assembled global method F Assembled global method Main Creating PE file Emitting classes: Class 1: S Emitting fields and methods: Global Methods: 2; Class 1 Fields: 1; Resolving local member refs: 3 -> 3 defs, 0 refs, 0 unresolved Emitting events and properties: Global Class 1 Resolving local member refs: 0 -> 0 defs, 0 refs, 0 unresolved Writing PE file Operation completed successfully Test.il(6) : warning -- Non-sealed value class, made sealed $ ./Test.exe 211384 0 2157704 2157328
.Net 4.5:
$ /Windows/Microsoft.NET/Framework/v4.0.30319/ilasm.exe Test.il Microsoft (R) .NET Framework IL Assembler. Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved. Assembling 'Test.il' to EXE --> 'Test.exe' Source file is ANSI Assembled global method F Assembled global method Main Creating PE file Emitting classes: Class 1: S Emitting fields and methods: Global Methods: 2; Class 1 Fields: 1; Resolving local member refs: 3 -> 3 defs, 0 refs, 0 unresolved Emitting events and properties: Global Class 1 Resolving local member refs: 0 -> 0 defs, 0 refs, 0 unresolved Writing PE file Operation completed successfully Test.il(6) : warning : Non-sealed value class, made sealed $ ./Test.exe 0 0 0 0
我很好奇这种实现更改背后的基本原理。
因此,欢迎任何反馈,尤其是来自内部人员的反馈,或对任何文章的引用,或者更好的是对规范的引用。:)
提前致谢。