Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep native order of get members call from Type #69506

Merged
merged 9 commits into from
May 31, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ internal void Insert(ref T[] list, string? name, MemberListType listType)
case MemberListType.All:
if (!m_cacheComplete)
{
MergeWithGlobalList(list);
MergeWithGlobalListInOrder(list);

// Trim null entries at the end of m_allMembers array
int memberCount = m_allMembers!.Length;
Expand Down Expand Up @@ -499,6 +499,36 @@ internal void Insert(ref T[] list, string? name, MemberListType listType)
}
}

private void MergeWithGlobalListInOrder(T[] list)
{
T?[]? cachedMembers = m_allMembers;

if (cachedMembers == null)
{
m_allMembers = list;
return;
}

foreach (T? cachedMemberInfo in cachedMembers)
{
if (cachedMemberInfo == null)
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
break;

for (int i = 0; i < list.Length; i++)
{
T newMemberInfo = list[i];

if (newMemberInfo.CacheEquals(cachedMemberInfo))
{
list[i] = cachedMemberInfo;
break;
}
}
}

m_allMembers = list;
}

// Modifies the existing list.
private void MergeWithGlobalList(T[] list)
{
Expand Down
18 changes: 16 additions & 2 deletions src/coreclr/vm/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2702,8 +2702,22 @@ void EEClass::AddChunk (MethodDescChunk* pNewChunk)
STATIC_CONTRACT_FORBID_FAULT;

_ASSERTE(pNewChunk->GetNextChunk() == NULL);
pNewChunk->SetNextChunk(GetChunks());
SetChunks(pNewChunk);

MethodDescChunk* head = GetChunks();

if (head == NULL)
{
SetChunks(pNewChunk);
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
// Current chunk needs to be added to the end of the list so that
// when reflection is iterating all methods, they would come in declared order
while (head->GetNextChunk() != NULL)
head = head->GetNextChunk();

head->SetNextChunk(pNewChunk);
}
}

//*******************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<Compile Include="System\RangeTests.cs" />
<Compile Include="System\RankExceptionTests.cs" />
<Compile Include="System\Reflection\NullabilityInfoContextTests.cs" />
<Compile Include="System\Reflection\RuntimeTypeMemberCacheTests.cs" />
<Compile Include="System\SByteTests.cs" />
<Compile Include="System\SingleTests.cs" />
<Compile Include="System\StackOverflowExceptionTests.cs" />
Expand Down
Loading