Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,18 @@ public static void PrepareDelegate(Delegate d)
/// returned.
/// </summary>
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int TryGetHashCode(object? o);
internal static extern int TryGetHashCode(object o);

[LibraryImport(QCall, EntryPoint = "ObjectNative_GetHashCodeSlow")]
private static partial int GetHashCodeSlow(ObjectHandleOnStack o);

public static int GetHashCode(object? o)
{
if (o is null)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will make the method less likely to be inclined by the JIT, and when it gets inlined, the inlined code is going to be bigger. Both of these can manifest as regressions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This will make the method less likely to be inclined by the JIT, and when it gets inlined, the inlined code is going to be bigger. Both of these can manifest as regressions.

Yeah but when inlining the check can be eliminated, wheras otherwise it would always execute before.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These claims need numbers.

{
return 0;
}

int hashCode = TryGetHashCode(o);
if (hashCode == 0)
{
Expand All @@ -254,10 +259,6 @@ public static int GetHashCode(object? o)
[MethodImpl(MethodImplOptions.NoInlining)]
static int GetHashCodeWorker(object? o)
{
if (o is null)
{
return 0;
}
return GetHashCodeSlow(ObjectHandleOnStack.Create(ref o));
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/vm/comutilnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1585,8 +1585,7 @@ FCIMPL1(INT32, ObjectNative::TryGetHashCode, Object* obj)
{
FCALL_CONTRACT;

if (obj == NULL)
return 0;
_ASSERTE(obj != NULL);

OBJECTREF objRef = ObjectToOBJECTREF(obj);
return objRef->TryGetHashCode();
Expand Down
Loading