Skip to content
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

Fix DynamicInvokeMethodThunk hash code collisions #103274

Merged
merged 3 commits into from
Jun 17, 2024

Conversation

filipnavara
Copy link
Member

@filipnavara filipnavara commented Jun 11, 2024

Fixes #103070

Let's see the CI if it breaks anything.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 11, 2024
@filipnavara filipnavara marked this pull request as ready for review June 11, 2024 10:23
Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative fix would be to go back to how we used to compute the name of these methods (it wasn't always a constant string), but I don't have a strong opinion. We don't otherwise override ComputeHashCode anywhere else. It's only virtual because of instantiated methods:

/// <summary>
/// Compute HashCode. Should only be overridden by a MethodDesc that represents an instantiated method.
/// </summary>

@jkotas
Copy link
Member

jkotas commented Jun 13, 2024

Should only be overridden by a MethodDesc that represents an instantiated method.

Delete this comment since it is not valid anymore?

@filipnavara
Copy link
Member Author

Delete this comment since it is not valid anymore?

I would like to keep some comment there.

There are runtime dependencies on the hash code both in NativeAOT and R2R. For NativeAOT it should mostly link to the same code in TypeHashingAlgorithms so the code is in sync with runtime implementation. For R2R there are places in unmanaged CoreCLR that do the XOR hash combining and that are not in any way linked to the Crossgen2 implementation even if they need to produce the same value.

Any suggestion for wording?

@MichalStrehovsky
Copy link
Member

It might be easier to just add some suffix to the Name/DiagnosticName (e.g. number of parameters) so that we avert at least some of the collisions, drop the override, and call it good enough.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestion for wording?

This hashcode is persisted into the image. The algorithm to compute it must be in sync with the one used at runtime.

It might be easier to just add some suffix to the Name/DiagnosticName (e.g. number of parameters)

Number of parameters is going to reduce the collisions like 3x (a lot of methods take one or two arguments). It would be still leaving a lot on the table.

…odThunk.cs

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@jkotas jkotas merged commit 899c766 into dotnet:main Jun 17, 2024
84 of 87 checks passed
@jkotas
Copy link
Member

jkotas commented Jun 17, 2024

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unoptimal hash code combine in TypeHashingAlgorithms.ComputeMethodHashCode
3 participants