记录CLR JIT策略 [英] Documenting CLR JIT Strategy

查看:134
本文介绍了记录CLR JIT策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是什么范围和顺序的CLR适用于JIT编译。

I'd like to know what scope and sequence the CLR applies to JIT compilation.

例如,如果我的应用程序调用一个给定类的只有一个方法,这样做课能得到JIT的未使用的方法编译不必要的?如果是的,他们是在执行我需要一个方法之前编制的JIT,或者他们事后懒洋洋地编译?

For example, if my application calls only a single method of a given class, do the unused methods of that class get JIT compiled needlessly? And if yes, are they all JIT compiled before executing the one method I needed, or are they lazily compiled after the fact?

和怎么样的方法分支机构?确实在CLR允许编译一半的code中的方法,同时允许中相同的方法的单独分支以保持未编译直到需要?

And what about branches in a method? Does the CLR allow half of the code in a method to be compiled, while allowing a separate branch in the same method to remain uncompiled until needed?

这似乎随着时间的推移,我发现文章,向公众展示了其中的一些细节,但现在我没有找到任何东西,让如何以及何时CLR选择JIT的部分的综合,可读的汇总code。任何建议书或链接?

It seems over time I've found articles that provide a glimpse for some of these details, but right now I'm not finding anything that gives a consolidated, readable summary of how and when the CLR chooses to JIT a section of code. Any suggested books or links?

这将是最好的,如果任何此类指南将打破这种JIT的决策逻辑通过.NET版本。

It would be best if any such guide would break down such JIT decision-logic by .net version.

推荐答案

JIT工作于.NET的方式是前一种方法已经被即时编译方法表项指向一个小存根调用时将JIT方法。之后,该方法表更新为引用的JIT编译code中的位置。

The way JIT works in .NET is that before a method has been jitted the method table entry points to a small stub that will JIT the method when invoked. After that the method table is updated to reference the location of the JIT compiled code.

鉴于只有被调用的方法是JIT编译没有JIT开销未调用的方法。

Given that only methods that are invoked are JIT compiled there's no JIT overhead for methods that are not invoked.

在需要时JIT编译器将编译整个方法。如果这是一个发布版本code可以被优化掉,但否则该方法被编译全部。

The JIT compiler will compile an entire method when needed. If it is a release build code may be optimized away but otherwise the method is compiled in full.

您可以检查使用的WinDbg / SOS方法表。考虑以下几点:

You can inspect the method tables using WinDbg/SOS. Consider the following:

class SomeType
{
    public void Called()
    {
        Console.WriteLine("called");
    }

    public void NotCalled()
    {
        Console.WriteLine("not called");
    }
}

假设我们创建 SOMETYPE 的实例,调用名为,然后检查方法表 SOMETYPE 。在x86上,你会看到这样的内容:

Assume that we create an instance of SomeType, call Called and then inspect the method table for SomeType. On x86 you'll see something like this:

0:000> !dumpmt -md 00a7381c
EEClass:         00a712d0
Module:          00a72e94
Name:            ConsoleApplication1.SomeType
mdToken:         02000002
File:            c:\temp\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe
BaseSize:        0xc
ComponentSize:   0x0
Slots in VTable: 7
Number of IFaces in IFaceMap: 0
--------------------------------------
MethodDesc Table
   Entry MethodDe    JIT Name
72ca4960 729a6728 PreJIT System.Object.ToString()
72c98790 729a6730 PreJIT System.Object.Equals(System.Object)
72c98360 729a6750 PreJIT System.Object.GetHashCode()
72c916f0 729a6764 PreJIT System.Object.Finalize()
00df00d8 00a73814    JIT ConsoleApplication1.SomeType..ctor()
00df0110 00a737fc    JIT ConsoleApplication1.SomeType.Called()
00a7c031 00a73808   NONE ConsoleApplication1.SomeType.NotCalled()

注意名为的JIT编译,但我们并没有援引 NotCalled 的是,它一直没有JIT编译。

Notice that Called is JIT compiled, but as we have not invoked NotCalled yet, it has not been JIT compiled.

另外,注意从对象的方法已全部preJIT编译。

Also, notice that the methods from object have all been PreJIT compiled.

请记住,在发布版本短的方法可以内联在这种情况下,他们不叫的方法,而仅​​仅包含作为产生code为号召的网站的一部分。

Keep in mind that in release build short methods may be inlined in which case they are not called as methods, but simply included as part of the generated code for the call site.

这篇关于记录CLR JIT策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆