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 aVerificationException
where the assembly has not been grantedSecurityPermission.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.