-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Completely lock-free ClassLoader::LookupTypeKey #61346
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
Changes from 1 commit
1b003e3
5330325
c5db8c4
c264f69
e8e7d6e
b9b4813
749695a
5569c66
7c3cd08
f8b1021
067cefb
1516f6b
efe6043
f455581
e874b3c
c7eb7e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -181,6 +181,10 @@ void DacEnumerableHashTable<DAC_ENUM_HASH_ARGS>::GrowTable() | |||||
| return; | ||||||
|
|
||||||
| ((size_t*)pNewBuckets)[0] = cNewBuckets; | ||||||
| ((PTR_VolatileEntry**)curBuckets)[1] = pNewBuckets; | ||||||
|
|
||||||
| // the new buckets must be published before we start moving entries. | ||||||
| MemoryBarrier(); | ||||||
|
|
||||||
| // All buckets are initially empty. | ||||||
| // Note: Memory allocated on loader heap is zero filled | ||||||
|
|
@@ -215,8 +219,7 @@ void DacEnumerableHashTable<DAC_ENUM_HASH_ARGS>::GrowTable() | |||||
| } | ||||||
|
|
||||||
| // Make sure that all writes are visible before publishing the new array. | ||||||
| MemoryBarrier(); | ||||||
| m_pBuckets = pNewBuckets; | ||||||
| VolatileStore(&m_pBuckets, pNewBuckets); | ||||||
| } | ||||||
|
|
||||||
| // Returns the next prime larger (or equal to) than the number given. | ||||||
|
|
@@ -264,36 +267,57 @@ DPTR(VALUE) DacEnumerableHashTable<DAC_ENUM_HASH_ARGS>::BaseFindFirstEntryByHash | |||||
| if (m_cEntries == 0) | ||||||
| return NULL; | ||||||
|
|
||||||
| auto curBuckets = GetBuckets(); | ||||||
| DWORD cBuckets = (DWORD)dac_cast<size_t>(curBuckets[0]); | ||||||
|
|
||||||
| // Compute which bucket the entry belongs in based on the hash. | ||||||
| DWORD dwBucket = iHash % cBuckets; | ||||||
| PTR_VolatileEntry* curBuckets = GetBuckets(); | ||||||
|
||||||
| return BaseFindFirstEntryByHashCore(curBuckets, iHash, pContext); | ||||||
| } | ||||||
|
|
||||||
| // Point at the first entry in the bucket chain which would contain any entries with the given hash code. | ||||||
| PTR_VolatileEntry pEntry = curBuckets[dwBucket + 2]; | ||||||
| template <DAC_ENUM_HASH_PARAMS> | ||||||
| DPTR(VALUE) DacEnumerableHashTable<DAC_ENUM_HASH_ARGS>::BaseFindFirstEntryByHashCore(PTR_VolatileEntry* curBuckets, DacEnumerableHashValue iHash, LookupContext* pContext) | ||||||
| { | ||||||
| CONTRACTL | ||||||
| { | ||||||
| NOTHROW; | ||||||
| GC_NOTRIGGER; | ||||||
| MODE_ANY; | ||||||
| SUPPORTS_DAC; | ||||||
| PRECONDITION(CheckPointer(pContext)); | ||||||
| } | ||||||
| CONTRACTL_END; | ||||||
|
|
||||||
| // Walk the bucket chain one entry at a time. | ||||||
| while (pEntry) | ||||||
| do | ||||||
| { | ||||||
| if (pEntry->m_iHashValue == iHash) | ||||||
| DWORD cBuckets = (DWORD)dac_cast<size_t>(curBuckets[0]); | ||||||
|
|
||||||
| // Compute which bucket the entry belongs in based on the hash. | ||||||
| DWORD dwBucket = iHash % cBuckets; | ||||||
|
|
||||||
| // Point at the first entry in the bucket chain which would contain any entries with the given hash code. | ||||||
| PTR_VolatileEntry pEntry = curBuckets[dwBucket + 2]; | ||||||
|
|
||||||
| // Walk the bucket chain one entry at a time. | ||||||
| while (pEntry) | ||||||
| { | ||||||
| // We've found our match. | ||||||
| if (pEntry->m_iHashValue == iHash) | ||||||
| { | ||||||
| // We've found our match. | ||||||
|
|
||||||
| // Record our current search state into the provided context so that a subsequent call to | ||||||
| // BaseFindNextEntryByHash can pick up the search where it left off. | ||||||
| pContext->m_pEntry = dac_cast<TADDR>(pEntry); | ||||||
| // Record our current search state into the provided context so that a subsequent call to | ||||||
| // BaseFindNextEntryByHash can pick up the search where it left off. | ||||||
| pContext->m_pEntry = dac_cast<TADDR>(pEntry); | ||||||
| pContext->m_curTable = dac_cast<TADDR>(curBuckets); | ||||||
|
|
||||||
| // Return the address of the sub-classes' embedded entry structure. | ||||||
| return VALUE_FROM_VOLATILE_ENTRY(pEntry); | ||||||
| // Return the address of the sub-classes' embedded entry structure. | ||||||
| return VALUE_FROM_VOLATILE_ENTRY(pEntry); | ||||||
| } | ||||||
|
|
||||||
| // Move to the next entry in the chain. | ||||||
| pEntry = pEntry->m_pNextEntry; | ||||||
| } | ||||||
|
|
||||||
| // Move to the next entry in the chain. | ||||||
| pEntry = pEntry->m_pNextEntry; | ||||||
| } | ||||||
| curBuckets = (DPTR(PTR_VolatileEntry))dac_cast<TADDR>(curBuckets[1]); | ||||||
| } while (curBuckets != nullptr); | ||||||
|
|
||||||
| // If we get here then none of the entries in the target bucket matched the hash code and we have a miss | ||||||
| // (for this section of the table at least). | ||||||
| return NULL; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -334,6 +358,15 @@ DPTR(VALUE) DacEnumerableHashTable<DAC_ENUM_HASH_ARGS>::BaseFindNextEntryByHash( | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| // check for next buckets must hapen after we looked through current | ||||||
| MemoryBarrier(); | ||||||
|
|
||||||
| auto nextBuckets = ((DPTR(PTR_VolatileEntry)*)pContext->m_curTable)[1]; | ||||||
|
||||||
| auto nextBuckets = ((DPTR(PTR_VolatileEntry)*)pContext->m_curTable)[1]; | |
| auto nextBuckets = dac_cast<DPTR(PTR_VolatileEntry)>(pContext->m_curTable)[1]; |
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.
I made GetNext a common helper. With that it is more convenient if m_curTable is (DPTR(PTR_VolatileEntry)
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.
Would it make sense to define constants or something for the fake 0 and 1 bucket indices to make this easier to understand?
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.
I think making "Length" and "Next" helpers that take an array could make this more clear.