如何理解这些段落在EMCA 335关于'.locals init`?落在、EMCA、init、locals

2023-09-03 04:27:31 作者:Large carved ︾

从ECMA 335 I.12.4.1方法调用

  

局部变量数组总是有对象类型和空   在持有对象的值类型的字段。此外,如果    .locals初始化设置,然后局部变量数组初始化为0   对于整型和0.0浮点类型。值类型不是由CLI初始化,但验证   code将提供调用一个初始化的方法的一部分   入口点code。

于是

难道初始化为0的整数类型和0.0的浮点类型的意思是归零值类型?

这是否意味着:无论 .locals初始化中,CLI必须始终确保对象类型在方法入口设置为null?那么,为什么它区分对象类型和位置值类型:?是不是零出类似归零对象类型的值类型

如何理解值类型不是由CLI初始化?

这是什么意思:验证code将提供调用一个初始化的方法的入口点code部分?是不是CLI的验证部分?

从ECMA 335 III.1.8.1.1验证算法

  

可验证的方法应 .locals初始化集。如果没有设置,CLI可能   抛出一个 VerificationException ,其中,大会还没有被授予    SecurityPermission.SkipVerification 。 CLI可以任意选择   进行明确赋值分析(以确定哪些位置是   写前仔细阅读),以允许CIL到native- code编译器   尽量减少其对这一要求的性能影响。

如果 .locals初始化设置,规范要求,CLI必须为零时的方法项中的局部变量数组。这意味着归零机code需要在入境时执行。因此,如何将明确赋值分析的帮助下,考虑到可能是不必要的归零已经完成?

如果我没有讲清楚道歉。我会尽我所能依据的意见,以提高我的问题。

解决方案 业9 1 超快棋大战第二部

这只是说,建立用于存储整数类型包括Byte,short,int和龙,UINT等任何内存应该是内存中清除和值设置为0,而浮动,双,等应该是0.0 。在.NET中,这是值类型局部变量的预期默认值。

确保在堆上该对象的引用与地址指向空可能需要不同的设置不是强迫的实际值在存储器地址堆栈上具有用于所述值类型零值开始。因此,虽然对象总是空,值类型只有归零如果.locals初始化设置。

值类型没有一个构造函数。当您维度变量的内存分配,但没有默认初始化调用发生在CLI值类型。

这听起来像核实code是上面的命令行直接提供的基本水平一个档次,并且除其他事项外,需要值类型的初始化。但我只是猜测在那一个。有点像宣称它不安全与管理或什么的。

这听起来像当值归零CLI作出主观判断,因为它是零值,以决定是否确实需要这样做或没有。但是,这听起来像这个选项并不总是可能的,这取决于本机平台上,或者根据内存大小什么的。

From ECMA 335 I.12.4.1 Method calls

The local variable array always has null for object types and for fields within value types that hold objects. In addition, if .locals init is set, then the local variable array is initialized to 0 for integral types and 0.0 for floating point types. Value types are not initialized by CLI, but verified code will supply a call to an initializer as part of the method's entry point code.

So

Does "initialized to 0 for integral types and 0.0 for floating point types" mean "zeroes the value types"?

Does it mean: regardless of .locals init, CLI must always ensure that object types are set to null upon method entry? Then why does it differentiate object types and value types here: isn't zero out value types similar to zero out object type?

How to understand that "value types are not initialized by CLI"?

What does this mean: "verified code will supply a call to an initializer as part of the method's entry point code"? Isn't verification part of CLI?

From ECMA 335 III.1.8.1.1 Verification algorithm

Verifiable methods shall have .locals init set. If not set, CLI might throw a VerificationException where the assembly has not been granted SecurityPermission.SkipVerification. CLI might optionally choose to perform definite assignment analysis (to determine which location are written before read) to allows a CIL-to-native-code compiler to minimize its performance impact for this requirement.

If .locals init is set, the spec requires that CLI must zero the local variable array upon method entry. This means the zeroing machine code needs to be execute upon entry. So, how would "definite assignment analysis" help, given that the possibly unnecessary zeroing is already done?

Apologies if I didn't make myself clear. I will try my best to improve my questions based on comments.

解决方案

This just says that any memory established for storing integral types including Byte, Short, Int, Long, UInt, etc should have that memory cleared and the value set to 0, and Float, Double, etc should be 0.0. In .Net, this is the expected default value for the local variables for value types.

Ensuring that object references on the heap start off with an address pointing to null may require a different setup than forcing actual values in a memory address on the stack to have a zero value for the value types. So while objects are always null, value types are only zeroed out if the .locals init is set.

Value types do not have a constructor. The memory is allocated when you dimension the variable, but no default initialization call takes place for value types in CLI.

It sounds like verified code is a notch above the basic level provided directly by the CLI, and among other things requires value type initialization. But I'm just guessing on that one. Sort of like declaring it "unsafe" vs. "managed" or whatever.

It sounds like when zeroing values CLI makes a judgement call as it is zeroing values to decide if it actually needs to do so or not. But it sounds like this option is not always possible, depending on the native platform, or else depending on the memory size or something.