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 5 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
35 changes: 25 additions & 10 deletions src/coreclr/vm/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2702,8 +2702,18 @@ void EEClass::AddChunk (MethodDescChunk* pNewChunk)
STATIC_CONTRACT_FORBID_FAULT;

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

MethodDescChunk* head = GetChunks();
jkotas marked this conversation as resolved.
Show resolved Hide resolved

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
while (head->GetNextChunk() != NULL)
head = head->GetNextChunk();

head->SetNextChunk(pNewChunk);
}
}

//*******************************************************************************
Expand All @@ -2717,20 +2727,25 @@ void EEClass::AddChunkIfItHasNotBeenAdded (MethodDescChunk* pNewChunk)
if (pNewChunk->GetNextChunk() != NULL)
return;

buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
// even if pNewChunk->GetNextChunk() is NULL, this may still be the first chunk we added
// (last in the list) so find the end of the list and verify that
MethodDescChunk *chunk = GetChunks();
if (chunk != NULL)

if (chunk == NULL)
SetChunks(pNewChunk);
else
{
if (chunk == pNewChunk)
return;

while (chunk->GetNextChunk() != NULL)
{
chunk = chunk->GetNextChunk();

if (chunk == pNewChunk)
return;
}
if (chunk == pNewChunk)
return;
}

pNewChunk->SetNextChunk(GetChunks());
SetChunks(pNewChunk);
chunk->SetNextChunk(pNewChunk);
}
}

#endif // !DACCESS_COMPILE
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