[release/5.0] Take SuppressGCTransition into account in IL stub caching #47619
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.
Issue: #46184
Fix in master: #47320
This is a stripped down version of the fix that went into master and the change it depended on: adds the
NDIRECTSTUB_FL_SUPPRESSGCTRANSITION
flag, updates the P/Invoke stub flags based onSuppressGCTransition
, and uses the updated flags in the IL stub cache.Customer Impact
When this issue results in the runtime suppressing the GC transition for P/Invokes that should not have them suppressed, users may hit GC starvation, data corruption, or runtime termination. When the runtime doesn't suppress the transition when it should, users will miss getting the performance benefits expected from suppressing the transition.
This is difficult to diagnose and does not have a reasonable workaround (only options would be to never use
SuppressGCTransition
or to re-work P/Invokes such that they do not have the same signature).Example based on the customer-reported issue:
Testing
Tests added to verify that P/Invokes with the same signature, differing only in
SuppressGCTransition
, do not re-use the same IL stub.Risk
This is a fairly targeted fix, but it does affect IL stub caching and the stub flags used during generation,
Regression
No.
SuppressGCTransition
was introduced in 5.0.