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
31 changes: 27 additions & 4 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ private void CompileMethodCleanup()
_actualInstructionSetUnsupported = default(InstructionSetFlags);
#endif

_instantiationToJitVisibleInstantiation = null;

_pgoResults.Clear();
}

Expand Down Expand Up @@ -644,6 +646,25 @@ private bool Get_CORINFO_METHOD_INFO(MethodDesc method, MethodIL methodIL, CORIN
return true;
}

private Dictionary<Instantiation, IntPtr[]> _instantiationToJitVisibleInstantiation = null;
private CORINFO_CLASS_STRUCT_** GetJitInstantiation(Instantiation inst)
{
IntPtr [] jitVisibleInstantiation;
if (_instantiationToJitVisibleInstantiation == null)
{
_instantiationToJitVisibleInstantiation = new Dictionary<Instantiation, IntPtr[]>();
}

if (!_instantiationToJitVisibleInstantiation.TryGetValue(inst, out jitVisibleInstantiation))
{
jitVisibleInstantiation = new IntPtr[inst.Length];
for (int i = 0; i < inst.Length; i++)
jitVisibleInstantiation[i] = (IntPtr)ObjectToHandle(inst[i]);
_instantiationToJitVisibleInstantiation.Add(inst, jitVisibleInstantiation);
}
return (CORINFO_CLASS_STRUCT_**)GetPin(jitVisibleInstantiation);
}

private void Get_CORINFO_SIG_INFO(MethodDesc method, CORINFO_SIG_INFO* sig, bool suppressHiddenArgument = false)
{
Get_CORINFO_SIG_INFO(method.Signature, sig);
Expand All @@ -668,10 +689,12 @@ private void Get_CORINFO_SIG_INFO(MethodDesc method, CORINFO_SIG_INFO* sig, bool
sig->sigInst.classInstCount = (uint)owningTypeInst.Length;
if (owningTypeInst.Length > 0)
{
var classInst = new IntPtr[owningTypeInst.Length];
for (int i = 0; i < owningTypeInst.Length; i++)
classInst[i] = (IntPtr)ObjectToHandle(owningTypeInst[i]);
sig->sigInst.classInst = (CORINFO_CLASS_STRUCT_**)GetPin(classInst);
sig->sigInst.classInst = GetJitInstantiation(owningTypeInst);
}

if (method.Instantiation.Length != 0)
{
sig->sigInst.methInst = GetJitInstantiation(method.Instantiation);
}
}

Expand Down
30 changes: 29 additions & 1 deletion src/coreclr/tools/Common/TypeSystem/Common/Instantiation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Internal.TypeSystem
/// Represents a generic instantiation - a collection of generic parameters
/// or arguments of a generic type or a generic method.
/// </summary>
public struct Instantiation
public struct Instantiation : IEquatable<Instantiation>
{
private TypeDesc[] _genericParameters;

Expand Down Expand Up @@ -113,5 +113,33 @@ public bool MoveNext()
return true;
}
}

public bool Equals(Instantiation other)
{
if (_genericParameters.Length != other._genericParameters.Length)
return false;

for (int i = 0; i < _genericParameters.Length; i++)
{
if (_genericParameters[i] != other._genericParameters[i])
return false;
}
return true;
}
public override bool Equals(object o)
{
if (o is Instantiation inst)
return Equals(inst);
return false;
}
public override int GetHashCode()
{
int hashcode = 1;
foreach (var t in _genericParameters)
{
hashcode = (hashcode << 3) ^ t.GetHashCode();
}
return hashcode;
}
}
}