Skip to content

Commit

Permalink
Fix DynamicInvokeMethodThunk hash code collisions (#103274)
Browse files Browse the repository at this point in the history
* Fix DynamicInvokeMethodThunk hash code collisions

* Update src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs

Co-authored-by: Jan Kotas <[email protected]>

* Update comments

---------

Co-authored-by: Jan Kotas <[email protected]>
  • Loading branch information
filipnavara and jkotas authored Jun 17, 2024
1 parent e34003c commit 899c766
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ private int AcquireHashCode()
}

/// <summary>
/// Compute HashCode. Should only be overridden by a MethodDesc that represents an instantiated method.
/// Compute HashCode. This hashcode is persisted into the image.
/// The algorithm to compute it must be in sync with the one used at runtime.
/// </summary>
protected virtual int ComputeHashCode()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ public override MethodSignature Signature
}
}

protected override int ComputeHashCode()
{
// The hashcode of DynamicInvoke thunks is not persisted. It allows us to override default and
// use a hashcode with good distribution to reduce hash table collisions.
return base.ComputeHashCode() ^ _targetSignature.GetHashCode();
}

public override string Name => "DynamicInvoke";

public override string DiagnosticName => "DynamicInvoke";
Expand Down

0 comments on commit 899c766

Please sign in to comment.