-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[cDAC] Add FeatureFlags contract, reduce direct global reads in legacy impl, expand NativeAOT descriptor parity #129637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Contract FeatureFlags | ||
|
|
||
| This contract exposes whether optional runtime features are enabled in the target. | ||
|
|
||
| ## APIs of contract | ||
|
|
||
| ```csharp | ||
| public enum RuntimeFeature | ||
| { | ||
| COMInterop, | ||
| ComWrappers, | ||
| ObjCMarshal, | ||
| JavaMarshal, | ||
| OnStackReplacement, | ||
| PortableEntrypoints, | ||
| Webcil, | ||
| } | ||
|
|
||
| // Returns true if the target runtime has the given feature enabled. | ||
| // A feature is considered disabled when its global is absent from the | ||
| // target descriptor or present with a zero value. | ||
| bool IsEnabled(RuntimeFeature feature); | ||
| ``` | ||
|
|
||
| ## Version 1 | ||
|
|
||
| Global variables used: | ||
| | Global Name | Type | Purpose | | ||
| | --- | --- | --- | | ||
| | FeatureCOMInterop | uint8 | Present (nonzero) when COM interop is enabled | | ||
| | FeatureComWrappers | uint8 | Present (nonzero) when ComWrappers is enabled | | ||
| | FeatureObjCMarshal | uint8 | Present (nonzero) when Objective-C marshalling is enabled | | ||
| | FeatureJavaMarshal | uint8 | Present (nonzero) when Java marshalling is enabled | | ||
| | FeatureOnStackReplacement | uint8 | Present (nonzero) when on-stack replacement is enabled | | ||
| | FeaturePortableEntrypoints | uint8 | Present (nonzero) when portable entrypoints are enabled | | ||
| | FeatureWebcil | uint8 | Present (nonzero) when Webcil is enabled | | ||
|
|
||
| Feature flag globals are **only present in the descriptor when the feature is enabled**. A missing global and a zero-valued global are both treated as "disabled". | ||
|
|
||
| ```csharp | ||
| bool IsEnabled(RuntimeFeature feature) | ||
| { | ||
| string? globalName = feature switch | ||
| { | ||
| RuntimeFeature.COMInterop => "FeatureCOMInterop", | ||
| RuntimeFeature.ComWrappers => "FeatureComWrappers", | ||
| RuntimeFeature.ObjCMarshal => "FeatureObjCMarshal", | ||
| RuntimeFeature.JavaMarshal => "FeatureJavaMarshal", | ||
| RuntimeFeature.OnStackReplacement => "FeatureOnStackReplacement", | ||
| RuntimeFeature.PortableEntrypoints => "FeaturePortableEntrypoints", | ||
| RuntimeFeature.Webcil => "FeatureWebcil", | ||
| _ => null, | ||
| }; | ||
| return globalName is not null | ||
| && TryReadGlobal<byte>(globalName, out byte? value) | ||
| && value != 0; | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...ged/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IFeatureFlags.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.Contracts; | ||
|
|
||
| /// <summary> | ||
| /// Feature flags that a runtime may or may not support. | ||
| /// </summary> | ||
| public enum RuntimeFeature | ||
| { | ||
| COMInterop, | ||
| ComWrappers, | ||
| ObjCMarshal, | ||
| JavaMarshal, | ||
| OnStackReplacement, | ||
| PortableEntrypoints, | ||
| Webcil, | ||
| } | ||
|
|
||
| public interface IFeatureFlags : IContract | ||
| { | ||
| static string IContract.Name { get; } = nameof(FeatureFlags); | ||
|
|
||
| /// <summary> | ||
| /// Returns <see langword="true"/> if the target runtime has the given feature enabled. | ||
| /// </summary> | ||
| bool IsEnabled(RuntimeFeature feature) => throw new NotImplementedException(); | ||
| } | ||
|
|
||
| public readonly struct FeatureFlags : IFeatureFlags { } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...naged/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/FeatureFlags_1.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.Diagnostics.DataContractReader.Contracts; | ||
|
|
||
| internal readonly struct FeatureFlags_1 : IFeatureFlags | ||
| { | ||
| private readonly Target _target; | ||
|
|
||
| public FeatureFlags_1(Target target) | ||
| { | ||
| _target = target; | ||
| } | ||
|
|
||
| bool IFeatureFlags.IsEnabled(RuntimeFeature feature) | ||
| { | ||
| string? globalName = feature switch | ||
| { | ||
| RuntimeFeature.COMInterop => Constants.Globals.FeatureCOMInterop, | ||
| RuntimeFeature.ComWrappers => Constants.Globals.FeatureComWrappers, | ||
| RuntimeFeature.ObjCMarshal => Constants.Globals.FeatureObjCMarshal, | ||
| RuntimeFeature.JavaMarshal => Constants.Globals.FeatureJavaMarshal, | ||
| RuntimeFeature.OnStackReplacement => Constants.Globals.FeatureOnStackReplacement, | ||
| RuntimeFeature.PortableEntrypoints => Constants.Globals.FeaturePortableEntrypoints, | ||
| RuntimeFeature.Webcil => Constants.Globals.FeatureWebcil, | ||
| _ => null, | ||
| }; | ||
| return globalName is not null | ||
| && _target.TryReadGlobal<byte>(globalName, out byte? value) | ||
| && value != 0; | ||
|
max-charlamb marked this conversation as resolved.
|
||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.