Skip to content

Commit 6969e7e

Browse files
Do not use RhGetCodeTarget in delegate equality (#88611)
dotnet/corert@08d78ae The original motivation for this was handling import stubs: ``` Function pointer equality comparison was not handling cross-module pointers correctly when optimizations were enabled (causes target pointers to be wrapped in jump stubs sometimes). The delegate equality comparison was hitting this bug. ``` We do not have import stubs anymore and unwrapping unboxing stubs serves no purpose here. Microbenchmarks of delegate equality show ~3x improvement with this change: ``` Bench_DelegateEquality_Positive_OpenStatic<10000000>() took: 355 ms Bench_DelegateEquality_Positive_ClosedStatic<10000000>() took: 367 ms Bench_DelegateEquality_Positive_ClosedInstance<10000000>() took: 371 ms Bench_DelegateEquality_Positive_OpenStatic<10000000>() took: 121 ms Bench_DelegateEquality_Positive_ClosedStatic<10000000>() took: 120 ms Bench_DelegateEquality_Positive_ClosedInstance<10000000>() took: 122 ms ``` Additionally, there is some desire to upstream changes for a portable RhGetCodeTarget implementation. Not having to deal with it at this relatively low-level layer will make things more robust.
1 parent d3d910e commit 6969e7e

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/FunctionPointerOps.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,25 +130,23 @@ public static unsafe bool Compare(IntPtr functionPointerA, IntPtr functionPointe
130130
{
131131
if (!IsGenericMethodPointer(functionPointerA))
132132
{
133-
IntPtr codeTargetA = RuntimeAugments.GetCodeTarget(functionPointerA);
134-
IntPtr codeTargetB = RuntimeAugments.GetCodeTarget(functionPointerB);
135-
return codeTargetA == codeTargetB;
133+
return functionPointerA == functionPointerB;
136134
}
137-
else
135+
136+
if (!IsGenericMethodPointer(functionPointerB))
138137
{
139-
if (!IsGenericMethodPointer(functionPointerB))
140-
return false;
138+
return false;
139+
}
141140

142-
GenericMethodDescriptor* pointerDefA = ConvertToGenericDescriptor(functionPointerA);
143-
GenericMethodDescriptor* pointerDefB = ConvertToGenericDescriptor(functionPointerB);
141+
GenericMethodDescriptor* pointerDefA = ConvertToGenericDescriptor(functionPointerA);
142+
GenericMethodDescriptor* pointerDefB = ConvertToGenericDescriptor(functionPointerB);
144143

145-
if (pointerDefA->InstantiationArgument != pointerDefB->InstantiationArgument)
146-
return false;
147-
148-
IntPtr codeTargetA = RuntimeAugments.GetCodeTarget(pointerDefA->MethodFunctionPointer);
149-
IntPtr codeTargetB = RuntimeAugments.GetCodeTarget(pointerDefB->MethodFunctionPointer);
150-
return codeTargetA == codeTargetB;
144+
if (pointerDefA->InstantiationArgument != pointerDefB->InstantiationArgument)
145+
{
146+
return false;
151147
}
148+
149+
return pointerDefA->MethodFunctionPointer == pointerDefB->MethodFunctionPointer;
152150
}
153151
}
154152
}

0 commit comments

Comments
 (0)