Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen is a method eligible to be inlined by the CLR?
    primarykey
    data
    text
    <p>I've observed a lot of "stack-introspective" code in applications, which often implicitly rely on their containing methods <em>not</em> being inlined for their correctness. Such methods commonly involve calls to:</p> <ul> <li><code>MethodBase.GetCurrentMethod</code></li> <li><code>Assembly.GetCallingAssembly</code></li> <li><code>Assembly.GetExecutingAssembly</code></li> </ul> <p>Now, I find the information surrounding these methods to be very confusing. I've heard that the run-time will not inline a method that calls GetCurrentMethod, but I can't find any documentation to that effect. I've seen posts on StackOverflow on several occasions, such as <a href="https://stackoverflow.com/questions/2784982/run-time-inlining-in-c/2785006#2785006">this one</a>, indicating the CLR does not inline cross-assembly calls, but the <code>GetCallingAssembly</code> <a href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getcallingassembly.aspx" rel="noreferrer">documentation</a> strongly indicates otherwise.</p> <p>There's also the much-maligned <code>[MethodImpl(MethodImplOptions.NoInlining)]</code>, but I am unsure if the CLR considers this to be a "request" or a "command."</p> <p>Note that I am asking about inlining <em>eligibility</em> from the standpoint of contract, <strong>not</strong> about when current implementations of the JITter decline to consider methods because of implementation difficulties, or about when the JITter finally ends up <em>choosing</em> to inline an eligible method after assessing the trade-offs. I have read <a href="http://blogs.msdn.com/b/ericgu/archive/2004/01/29/64717.aspx" rel="noreferrer">this</a> and <a href="http://blogs.msdn.com/b/davidnotario/archive/2004/11/01/250398.aspx" rel="noreferrer">this</a>, but they seem to be more focused on the last two points (there are passing mentions of MethodImpOptions.NoInlining and "exotic IL instructions", but these seem to be presented as heuristics rather than as <em>obligations</em>).</p> <p>When is the CLR <em>allowed</em> to inline?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload