-
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
Fix thread static cleanup paths #107438
Fix thread static cleanup paths #107438
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Do not destroy GC handles while holding the spin lock - Free the pLoaderHandle array when the thread is terminated
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -405,6 +405,13 @@ void FreeLoaderAllocatorHandlesForTLSData(Thread *pThread) | |||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
pThread->cLoaderHandles = -1; // Sentinel value indicating that there are no LoaderHandles and the thread is permanently dead. | ||||||||||||||||||
if (pThread->pLoaderHandles != NULL) | ||||||||||||||||||
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. Nit: This should be always true since |
||||||||||||||||||
{ | ||||||||||||||||||
delete[] pThread->pLoaderHandles; | ||||||||||||||||||
pThread->pLoaderHandles = NULL; | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -431,34 +438,48 @@ void FreeThreadStaticData(Thread* pThread) | |||||||||||||||||
} | ||||||||||||||||||
CONTRACTL_END; | ||||||||||||||||||
|
||||||||||||||||||
SpinLockHolder spinLock(&pThread->m_TlsSpinLock); | ||||||||||||||||||
InFlightTLSData* pOldInFlightData = nullptr; | ||||||||||||||||||
|
||||||||||||||||||
ThreadLocalData *pThreadLocalData = &t_ThreadStatics; | ||||||||||||||||||
int32_t oldCollectibleTlsDataCount = 0; | ||||||||||||||||||
DPTR(OBJECTHANDLE) pOldCollectibleTlsArrayData = nullptr; | ||||||||||||||||||
|
||||||||||||||||||
for (int32_t iTlsSlot = 0; iTlsSlot < pThreadLocalData->cCollectibleTlsData; ++iTlsSlot) | ||||||||||||||||||
{ | ||||||||||||||||||
if (!IsHandleNullUnchecked(pThreadLocalData->pCollectibleTlsArrayData[iTlsSlot])) | ||||||||||||||||||
SpinLockHolder spinLock(&pThread->m_TlsSpinLock); | ||||||||||||||||||
|
||||||||||||||||||
ThreadLocalData *pThreadLocalData = &t_ThreadStatics; | ||||||||||||||||||
|
||||||||||||||||||
pOldCollectibleTlsArrayData = pThreadLocalData->pCollectibleTlsArrayData; | ||||||||||||||||||
oldCollectibleTlsDataCount = pThreadLocalData->cCollectibleTlsData; | ||||||||||||||||||
|
||||||||||||||||||
pThreadLocalData->pCollectibleTlsArrayData = 0; | ||||||||||||||||||
pThreadLocalData->cCollectibleTlsData = 0; | ||||||||||||||||||
pThreadLocalData->pNonCollectibleTlsArrayData = 0; | ||||||||||||||||||
pThreadLocalData->cNonCollectibleTlsData = 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.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
pOldInFlightData = pThreadLocalData->pInFlightData; | ||||||||||||||||||
_ASSERTE(pThreadLocalData->pThread == pThread); | ||||||||||||||||||
pThreadLocalData->pThread = NULL; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
for (int32_t iTlsSlot = 0; iTlsSlot < oldCollectibleTlsDataCount; ++iTlsSlot) | ||||||||||||||||||
{ | ||||||||||||||||||
if (!IsHandleNullUnchecked(pOldCollectibleTlsArrayData[iTlsSlot])) | ||||||||||||||||||
{ | ||||||||||||||||||
DestroyLongWeakHandle(pThreadLocalData->pCollectibleTlsArrayData[iTlsSlot]); | ||||||||||||||||||
DestroyLongWeakHandle(pOldCollectibleTlsArrayData[iTlsSlot]); | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
delete[] (uint8_t*)pThreadLocalData->pCollectibleTlsArrayData; | ||||||||||||||||||
|
||||||||||||||||||
pThreadLocalData->pCollectibleTlsArrayData = 0; | ||||||||||||||||||
pThreadLocalData->cCollectibleTlsData = 0; | ||||||||||||||||||
pThreadLocalData->pNonCollectibleTlsArrayData = 0; | ||||||||||||||||||
pThreadLocalData->cNonCollectibleTlsData = 0; | ||||||||||||||||||
if (pOldCollectibleTlsArrayData != NULL) | ||||||||||||||||||
{ | ||||||||||||||||||
delete[] (uint8_t*)pOldCollectibleTlsArrayData; | ||||||||||||||||||
} | ||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
while (pThreadLocalData->pInFlightData != NULL) | ||||||||||||||||||
while (pOldInFlightData != NULL) | ||||||||||||||||||
{ | ||||||||||||||||||
InFlightTLSData* pInFlightData = pThreadLocalData->pInFlightData; | ||||||||||||||||||
pThreadLocalData->pInFlightData = pInFlightData->pNext; | ||||||||||||||||||
InFlightTLSData* pInFlightData = pOldInFlightData; | ||||||||||||||||||
pOldInFlightData = pInFlightData->pNext; | ||||||||||||||||||
delete pInFlightData; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
_ASSERTE(pThreadLocalData->pThread == pThread); | ||||||||||||||||||
pThreadLocalData->pThread = NULL; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
void SetTLSBaseValue(TADDR *ppTLSBaseAddress, TADDR pTLSBaseAddress, bool useGCBarrierInsteadOfHandleStore) | ||||||||||||||||||
|
@@ -553,6 +574,8 @@ void* GetThreadLocalStaticBase(TLSIndex index) | |||||||||||||||||
delete[] pOldArray; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
_ASSERTE(t_ThreadStatics.pThread->cLoaderHandles != -1); // Check sentinel value indicating that there are no LoaderHandles, the thread has gone through termination and is permanently dead. | ||||||||||||||||||
|
||||||||||||||||||
if (isCollectible && t_ThreadStatics.pThread->cLoaderHandles <= index.GetIndexOffset()) | ||||||||||||||||||
{ | ||||||||||||||||||
// Grow the underlying TLS array | ||||||||||||||||||
|
@@ -594,9 +617,11 @@ void* GetThreadLocalStaticBase(TLSIndex index) | |||||||||||||||||
gcBaseAddresses.pTLSBaseAddress = dac_cast<TADDR>(OBJECTREFToObject(ObjectFromHandle(pInFlightData->hTLSData))); | ||||||||||||||||||
if (pMT->IsClassInited()) | ||||||||||||||||||
{ | ||||||||||||||||||
SpinLockHolder spinLock(&t_ThreadStatics.pThread->m_TlsSpinLock); | ||||||||||||||||||
SetTLSBaseValue(gcBaseAddresses.ppTLSBaseAddress, gcBaseAddresses.pTLSBaseAddress, staticIsNonCollectible); | ||||||||||||||||||
*ppOldNextPtr = pInFlightData->pNext; | ||||||||||||||||||
{ | ||||||||||||||||||
SpinLockHolder spinLock(&t_ThreadStatics.pThread->m_TlsSpinLock); | ||||||||||||||||||
SetTLSBaseValue(gcBaseAddresses.ppTLSBaseAddress, gcBaseAddresses.pTLSBaseAddress, staticIsNonCollectible); | ||||||||||||||||||
*ppOldNextPtr = pInFlightData->pNext; | ||||||||||||||||||
} | ||||||||||||||||||
delete pInFlightData; | ||||||||||||||||||
} | ||||||||||||||||||
break; | ||||||||||||||||||
|
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.
Set the sentinel before we start cleaning the entries?