Domanda

Since, attributes such as TargetedPatchingOptOut aren't handled inside the framework, do the attributes propagate to the inherited classes during the optimization?

Eg:

public abstract class TestBase
{
    [TargetedPatchingOptOut("Optimize across boundaries")]
    public abstract void TestFunc();
}

public class Test : TestBase
{
    // Is re-defining attributes like these necessary?
    public override void TestFunc()
    {
        throw new NotImplementedException();
    }
}

Also, does the JIT compiler (ever/always) lookup inherited attributes?

Note: Although the specific functionality above can be figured out easily by examining the JIT instructions on WinDbg with a few (tediously) extravagant methods, I appreciate any insights on how its implemented, as it is not impossible for the JIT compiler to behave very differently for different attributes without knowing its exact implementation.

Update:

I made a wrong assumption that the TargetedPatchingOptOut is handled by the JIT compiler, but while it is infact handled by NGen. The answer for this specific case has been answered clearly by @Hans Passant.

I think its safe to guess, each of the internal tools utilize the attributes by the same rules as given by the AttributeUsage flag.

È stato utile?

Soluzione

Whether an attribute is visible on a derived class by default is determined by the AttributeUsageAttribute.Inherited property. Which is false for this attribute:

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, 
     AllowMultiple = false, Inherited = false)]
public sealed class TargetedPatchingOptOutAttribute : Attribute {
    // etc...
}

It is not exclusive, a method like Type.GetCustomAttribute() also has an inherit argument to allow overriding the default.

Do be careful about making assumptions about what tooling reads an attribute. [TargetedPatchingOptOut] is almost certainly not read by the jitter. It is used to determine if Ngen.exe needs to run to re-create the native image of an assembly when an update is deployed. I don't know what the tooling looks like, the only thing that makes sense to me is that this is done on Microsoft machine in Redmond.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top