-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
A few follow up changes to LookupTypeKey change #61718
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -627,7 +627,6 @@ void ClassLoader::GetClassValue(NameHandleTable nhTable, | |
CONTRACTL_END | ||
|
||
|
||
mdToken mdEncloser; | ||
EEClassHashEntry_t *pBucket = NULL; | ||
|
||
needsToBuildHashtable = FALSE; | ||
|
@@ -643,8 +642,6 @@ void ClassLoader::GetClassValue(NameHandleTable nhTable, | |
} | ||
#endif | ||
|
||
BOOL isNested = IsNested(pName, &mdEncloser); | ||
|
||
PTR_Assembly assembly = GetAssembly(); | ||
PREFIX_ASSUME(assembly != NULL); | ||
ModuleIterator i = assembly->IterateModules(); | ||
|
@@ -719,6 +716,9 @@ void ClassLoader::GetClassValue(NameHandleTable nhTable, | |
} | ||
_ASSERTE(pTable); | ||
|
||
mdToken mdEncloser; | ||
BOOL isNested = IsNested(pName, &mdEncloser); | ||
|
||
if (isNested) | ||
{ | ||
Module *pNameModule = pName->GetTypeModule(); | ||
|
@@ -834,6 +834,9 @@ void ClassLoader::LazyPopulateCaseSensitiveHashTables() | |
} | ||
CONTRACTL_END; | ||
|
||
|
||
_ASSERT(m_cUnhashedModules > 0); | ||
|
||
AllocMemTracker amTracker; | ||
ModuleIterator i = GetAssembly()->IterateModules(); | ||
|
||
|
@@ -909,6 +912,8 @@ void ClassLoader::LazyPopulateCaseInsensitiveHashTables() | |
amTracker.SuppressRelease(); | ||
pModule->SetAvailableClassCaseInsHash(pNewClassCaseInsHash); | ||
FastInterlockDecrement((LONG*)&m_cUnhashedModules); | ||
|
||
_ASSERT(m_cUnhashedModules >= 0); | ||
} | ||
} | ||
} | ||
|
@@ -1238,18 +1243,18 @@ BOOL ClassLoader::FindClassModuleThrowing( | |
|
||
if (pBucket == NULL) | ||
{ | ||
// Take the lock. To make sure the table is not being built by another thread. | ||
AvailableClasses_LockHolder lh(this); | ||
|
||
// Try again with the lock. This will protect against another thread reallocating | ||
// the hash table underneath us | ||
GetClassValue(nhTable, pName, &Data, &pTable, pLookInThisModuleOnly, &foundEntry, loadFlag, needsToBuildHashtable); | ||
pBucket = foundEntry.GetClassHashBasedEntryValue(); | ||
|
||
if (!needsToBuildHashtable || (m_cUnhashedModules == 0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not need to do lookup 3 times if tables were populated by another thread when we did a lookup. Also tweaked comments to explain the real reason why we need to re-do the lookup. |
||
{ | ||
// the table should be finished now, try again | ||
GetClassValue(nhTable, pName, &Data, &pTable, pLookInThisModuleOnly, &foundEntry, loadFlag, needsToBuildHashtable); | ||
pBucket = foundEntry.GetClassHashBasedEntryValue(); | ||
} | ||
#ifndef DACCESS_COMPILE | ||
if (needsToBuildHashtable && (pBucket == NULL) && (m_cUnhashedModules > 0)) | ||
else | ||
{ | ||
_ASSERT(needsToBuildHashtable); | ||
|
||
if (nhTable == nhCaseInsensitive) | ||
{ | ||
LazyPopulateCaseInsensitiveHashTables(); | ||
|
@@ -1268,7 +1273,7 @@ BOOL ClassLoader::FindClassModuleThrowing( | |
#endif | ||
} | ||
|
||
// Same check as above, but this time we've checked with the lock so the table will be populated | ||
// Same check as above, but this time we've ensured that the tables are populated | ||
if (pBucket == NULL) | ||
{ | ||
#if defined(_DEBUG_IMPL) && !defined(DACCESS_COMPILE) | ||
|
@@ -1536,19 +1541,19 @@ ClassLoader::LoadTypeHandleThrowing( | |
pClsLdr = pFoundModule->GetClassLoader(); | ||
pLookInThisModuleOnly = NULL; | ||
} | ||
} | ||
|
||
#ifndef DACCESS_COMPILE | ||
// Replace AvailableClasses Module entry with found TypeHandle | ||
if (!typeHnd.IsNull() && | ||
typeHnd.IsRestored() && | ||
foundEntry.GetEntryType() == HashedTypeEntry::EntryType::IsHashedClassEntry && | ||
(foundEntry.GetClassHashBasedEntryValue() != NULL) && | ||
(foundEntry.GetClassHashBasedEntryValue()->GetData() != typeHnd.AsPtr())) | ||
{ | ||
foundEntry.GetClassHashBasedEntryValue()->SetData(typeHnd.AsPtr()); | ||
} | ||
#endif // !DACCESS_COMPILE | ||
// Replace AvailableClasses Module entry with found TypeHandle | ||
if (!typeHnd.IsNull() && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an optimization where we can replace a token with a type handle as the value in the table. That would save a lookup in another table next time. There is some additional infrastructure in the table to support this optimization and this is very intentional, but I think someone misplaced All successful lookups break from the loop, so the code taking the note of the found handle must be outside of the loop body. |
||
typeHnd.IsRestored() && | ||
foundEntry.GetEntryType() == HashedTypeEntry::EntryType::IsHashedClassEntry && | ||
(foundEntry.GetClassHashBasedEntryValue() != NULL) && | ||
(foundEntry.GetClassHashBasedEntryValue()->GetData() != typeHnd.AsPtr())) | ||
{ | ||
foundEntry.GetClassHashBasedEntryValue()->SetData(typeHnd.AsPtr()); | ||
} | ||
#endif // !DACCESS_COMPILE | ||
|
||
RETURN typeHnd; | ||
} // ClassLoader::LoadTypeHandleThrowing | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsNested
is a bit involved. In some cases like R2R, we may not need to knowisNested
, so it makes sense to move the call down to where we are sure we need it.