Let's say I have a C# Windows Class library in my solution and I build it in my VS2010 IDE. The output here in my bin directory is X.dll
1) X.dll does not contain MSIL at this stage but "compressed byte code".
Is this true?2) This "co开发者_JAVA技巧mpressed byte code" is converted to MSIL somehow.
When does this occur?3) When X.dll is accessed the JIT compiler of CLR takes the portion of MSIL that it needs to convert and does so into machine code.
Am I good on this final part?Can anybody help in filling in the gaps in my understanding here?
X.dll contains MSIL bytecode after you build it with Visual Studio. You can prove this by disassembling it with ildasm.
At some time between assembly loading and the actual execution of the code, the MSIL is translated to native code. I am not familiar with where exactly this is done, but I would suspect at assembly load.
To build upon Dark Falcon's response, on question no.2, the IL code (not compressed byte code) is converted to native code by the JIT compiler, method by method, at each of their first call. So, a shorter answer for no.2 is "when the method is first accessed". Fields are not subject to this, properties are disguised methods themselves.
As for the third question, no, the IL is not JITed when it is loaded. See above.
精彩评论