Skip to content
Merged
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
4 changes: 1 addition & 3 deletions src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private IntPtr AllocException(Exception ex)
[DllImport(JitSupportLibrary)]
private extern static char* GetExceptionMessage(IntPtr obj);

private readonly UnboxingMethodDescFactory _unboxingThunkFactory;
private static readonly UnboxingMethodDescFactory _unboxingThunkFactory = new UnboxingMethodDescFactory();

public static void Startup()
{
Expand All @@ -125,8 +125,6 @@ public CorInfoImpl()
}

_unmanagedCallbacks = GetUnmanagedCallbacks(out _keepAlive);

_unboxingThunkFactory = new UnboxingMethodDescFactory();
}

public TextWriter Log
Expand Down
22 changes: 14 additions & 8 deletions src/coreclr/src/tools/Common/JitInterface/UnboxingMethodDesc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using Internal.TypeSystem;
Expand Down Expand Up @@ -79,17 +80,22 @@ protected override int CompareToImpl(MethodDesc other, TypeSystemComparer compar
#endif
}

internal class UnboxingMethodDescFactory : Dictionary<MethodDesc, UnboxingMethodDesc>
internal class UnboxingMethodDescFactory : ConcurrentDictionary<MethodDesc, UnboxingMethodDesc>
{
public UnboxingMethodDesc GetUnboxingMethod(MethodDesc method)
private Func<MethodDesc, UnboxingMethodDesc> _factoryDelegate;
private UnboxingMethodDesc CreateUnboxingMethod(MethodDesc method)
{
if (!TryGetValue(method, out UnboxingMethodDesc result))
{
result = new UnboxingMethodDesc(method, this);
Add(method, result);
}
return new UnboxingMethodDesc(method, this);
}

return result;
public UnboxingMethodDescFactory()
{
_factoryDelegate = CreateUnboxingMethod;
}

public UnboxingMethodDesc GetUnboxingMethod(MethodDesc method)
{
return GetOrAdd(method, _factoryDelegate);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,7 @@ private void embedGenericHandle(ref CORINFO_RESOLVED_TOKEN pResolvedToken, bool
MethodDesc md = HandleToObject(pResolvedToken.hMethod);
TypeDesc td = HandleToObject(pResolvedToken.hClass);

if (td.IsValueType)
if ((td.IsValueType) && !md.Signature.IsStatic)
{
md = _unboxingThunkFactory.GetUnboxingMethod(md);
}
Expand Down