整个组件的本机映像方法内联 [英] Method inlining across native images of assemblies

查看:146
本文介绍了整个组件的本机映像方法内联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如另一个问题,NGEN通常只允许在整个组件内联方法,如果该方法具有<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.targetedpatchingoptoutattribute%28v=vs.100%29.aspx">TargetedPatchingOptOutAttribute集。

As explained in another question, Ngen is usually only allowed to inline methods across assemblies if the method has the TargetedPatchingOptOutAttribute set.

但是,这也适用于硬约束组件通过使用<一href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.dependencyattribute%28v=vs.100%29.aspx">DependencyAttribute与 LoadHint.Always

But is this also true for hard bound assemblies by using the DependencyAttribute with LoadHint.Always?

编辑:也许回答我最初的问题是否定的,否则就没有任何意义了 TargetedPatchingOptOutAttribute ,因为这是用在mscorlib中装配总是很难约束(它有<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.defaultdependencyattribute%28v=vs.100%29.aspx">DefaultDependencyAttribute组)。所以,我想改一下我的问题:?是 TargetedPatchingOptOutAttribute 只有这样,才能得到一个方法内联跨组件的原始图像

edit: Maybe the answer to my initial question is no, otherwise it would make no sense that the TargetedPatchingOptOutAttribute is used in mscorlib since this assembly is always hard bound (it has the DefaultDependencyAttribute set). So I'd like to rephrase my question: Is the TargetedPatchingOptOutAttribute the only way to get a method inlined across native images of assemblies?

推荐答案

看起来像<一个href="http://stackoverflow.com/questions/6109745/targetedpatchingoptout-performance-critical-to-inline-across-ngen-image-bounda">other问题带我到一个完全错误的假设。在我们的组装方法的内联跨原生图像边界值,即使它们既不硬缠,也有 TargetedPatchingOptOutAttribute 组。此属性仅影响.NET Framework程序集。

It seems like that other question led me to a completely wrong assumption. Methods in our own assemblies are inlined across native image boundries, even if they are neither hard bound nor have the TargetedPatchingOptOutAttribute set. This attribute only affects the .NET Framework assemblies.

<一个href="http://blogs.msdn.com/b/clr$c$cgeneration/archive/2009/10/21/jit-etw-inlining-event-fail-reasons.aspx">A微软博客文章大约有一个相当不错的节 TargetedPatchingOptOutAttribute

A Microsoft blog post has a quite good section about the TargetedPatchingOptOutAttribute:

有针对性的补丁 - 方法缺乏TargetedPatchingOptOutAttribute -   这涉及到一个新的功能在CLR 4中NGEN图像更   版本弹性。简单地说,我们希望能够应用补丁   或修复了MSCORLIB.DLL,而不必重新编译其他所有本地   这取决于它在计算机上的图像。这应该只适用于   在.NET框架类库方法,因为它们是   只有组件,可以选择加入此功能。

"Targeted Patching - Method lacks TargetedPatchingOptOutAttribute" - this relates to a new feature in CLR 4 where NGEN images are more version resilient. In a nutshell, we hope to be able to apply a patch or fix to mscorlib.dll and not have to recompile all the other native images on the machine that depend upon it. This should only apply to methods in the .NET framework class libraries because they are the only assemblies that can opt into this feature.

这意味着:因为.NET Framework程序集现在支持<一href="http://blogs.msdn.com/b/clr$c$cgeneration/archive/2009/05/03/improvements-to-ngen-in-.net-framework-4.aspx">targeted在.NET 4.0补丁,从这些组件的方法通常不能被内联。但标有方法 TargetedPatchingOptOutAttribute 的性能是至关重要的,因此选择了有针对性的修补(这意味着如果他们​​不断变化的,使用这种方法的所有本机映像需要重新编译)。因为我们自己的assemblis不要使用有针对性的修补,没有理由在整个本机映像prevent方法内联。

This means: Because .NET Framework assemblies now support targeted patching in .NET 4.0, methods from those assemblies usually can't be inlined. But methods that are marked with the TargetedPatchingOptOutAttribute are performance critical and therefore opt out of the targeted patching (which means if they are ever changed, all native images that use that method need to be recompiled). Since our own assemblis don't use targeted patching, there is no reason to prevent method inlining across native images.

要测试这一点,我创建了一个小样本,显示扔在不同的装配异常的调用堆栈。只有我的主要方法和扔异常的方法是调用堆栈。摆在这两个主叫和被叫组件(即基本上做无非就是调用next方法),其他一些小方法是不是在调用堆栈。这种行为的组件(是的,我检查了本地图像使用)创建本机映像后并没有改变。

To test this I created a small sample that shows the call stack of an exception thrown in a different assembly. Only my main method and the method that throwed the exception were in the call stack. Some other small methods placed in both the calling and called assembly (that do basically nothing more than calling the next method) were not in the call stack. This behavior didn't change after creating native images for the assemblies (yes, I checked that the native images were used).

TLDR版本:不要在乎 TargetedPatchingOptOutAttribute ,它应该只在.NET框架组件中使用。自主开发的组件方法内联的工作原理同NGEN和JIT。

TLDR version: Don't care about the TargetedPatchingOptOutAttribute, it should only be used in the .NET Framework assemblies. Method inlining of self developed assemblies works the same with Ngen and JIT.

这篇关于整个组件的本机映像方法内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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