RE: MSIL Inquiry involving boxing

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Ben,

Based on my test, I will get the similar result as you, below is what I got
from Reflector:

method private hidebysig static void Main() cil managed
{
.entrypoint
.maxstack 3
.locals init (
[0] object[] objArray1,
[1] object obj1,
[2] object[] objArray2)
L_0000: ldc.i4.3
L_0001: newarr object
L_0006: stloc.2
L_0007: ldloc.2
L_0008: ldc.i4.0
L_0009: ldc.i4.1
L_000a: box int32
L_000f: stelem.ref
L_0010: ldloc.2
L_0011: ldc.i4.1
L_0012: ldstr "Hello"
L_0017: stelem.ref
L_0018: ldloc.2
L_0019: ldc.i4.2
L_001a: ldc.i4.s 123
L_001c: box int32
L_0021: stelem.ref
...
}

I can not find the usage of retrieving the address of local variable with
*ldloca.s* instruction. The decision of IL output is controlled by the C#
compiler. This means the offical Microsoft provided C# compiler will try to
generate a redundant local variable for holding the about-to-be-box value.

I am not sure of what C# compiler the author used. I will try to test this
on Rotor.

I think the output provided by the tutorial author may not be a pratical C#
compiler generation, since it event does not generate *init* keyword for
locals. The keyword *init* means that the local variables must be
initialized before the method executes. I think this is an important
keyword for a commercial C# compiler, since it can leverage CLR's
verification process to detect the security hole/programming error for the
developer.

Anyway, I think you'd better contact the author of the tutorial for which
compiler he used to generate his sample output. Thanks.

Regarding the boxing for local variable address issue, this is handled by
JIT compiler in CLR. I think JIT compiler will take care of getting the
value data from the address and do boxing with this value data. If you are
curious with the boxing process, the most clear way of understanding it is
looking the Rotor source code for boxing. This souce code is defined in
Jitinterface.cpp JIT_Box() function(Rotor1.0). <Shared Source CLI
Essentials> gives box/unbox an explanation with source code in chapter3.
You may comiple the IL code provided by the IL tutorial and set a
breakpoint in JIT_Box function, then you will see the call stack of the
CLR, which you may find out how box instruction is doing under the cover.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

.



Relevant Pages

  • RE: MSIL Inquiry involving boxing
    ... This means the offical Microsoft provided C# compiler will try to ... The keyword *init* means that the local variables must be ... Regarding the boxing for local variable address issue, ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework)
  • Re: IVF vs CVF
    ... I would paraphrase part of it as: Microsoft didn't accept ... > Fortran for a lower price than CVF. ... > necessity for a commercial compiler. ... High quality compiler, good support, free email support within ...
    (comp.lang.fortran)
  • RE: Suddenly cant compile - how did I break it?
    ... Thanks for using Microsoft Newsgroup Service. ... The error message indicates that the compiler is going to copy the resource ... occurs when it could not find the resource file in release folder. ... Microsoft Online Community Support ...
    (microsoft.public.vsnet.ide)
  • Re: Crash-bug in the VS 2008 C# compiler
    ... Welcome to Microsoft Newsgroup Support Service! ... I have reproduce the compiler error with your example code. ... the lookup erroneously returns a scope that is not for the lock statement. ...
    (microsoft.public.dotnet.framework)
  • Re: VC++.NET without VS
    ... You've downloaded and installed the .NET Framework and .NET Framework SDK, ... According to a post from a Microsoft rep, ... You may get a C++ compiler support Managed ...
    (microsoft.public.dotnet.languages.vc)