From db61e5b477fc62eea14e9904b4fd13ce62706ac0 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 8 Jun 2024 10:45:47 +0200 Subject: [PATCH 1/3] Fix DynamicInvokeMethodThunk hash code collisions --- .../Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs index ee50cc4f0565f..eb353e8235b0c 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs @@ -112,6 +112,11 @@ public override MethodSignature Signature } } + protected override int ComputeHashCode() + { + return base.ComputeHashCode() ^ _targetSignature.GetHashCode(); + } + public override string Name => "DynamicInvoke"; public override string DiagnosticName => "DynamicInvoke"; From 3a85767c3462cae22eea65497797fd9e58e8b26a Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Mon, 17 Jun 2024 09:05:11 +0200 Subject: [PATCH 2/3] Update src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs Co-authored-by: Jan Kotas --- .../Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs index eb353e8235b0c..bf48b508a06fa 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs @@ -114,6 +114,8 @@ 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(); } From a0080b1e9173a0a36f61ea9a9d5748c77eddbbab Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Mon, 17 Jun 2024 13:28:13 +0200 Subject: [PATCH 3/3] Update comments --- src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs | 3 ++- .../Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs b/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs index 639455ff98ba2..93b12af20f141 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/MethodDesc.cs @@ -491,7 +491,8 @@ private int AcquireHashCode() } /// - /// 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. /// protected virtual int ComputeHashCode() { diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs index bf48b508a06fa..9a02967189db3 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs @@ -114,7 +114,7 @@ public override MethodSignature Signature protected override int ComputeHashCode() { - // The hashcode of DynamicInvoke thunks is not persisted. It allows us to override default and + // 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(); }