diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2018-10-16 16:42:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-16 16:42:33 -0700 |
commit | afb6185394511fb30c9278d40d6e6e2ca59cb6f8 (patch) | |
tree | a98a24851941c32785b891580bfd28574cac08d1 | |
parent | 5c2c5961a6142fc0bf0c9f992ff76b4a32ad65e4 (diff) | |
download | coreclr-afb6185394511fb30c9278d40d6e6e2ca59cb6f8.tar.gz coreclr-afb6185394511fb30c9278d40d6e6e2ca59cb6f8.tar.bz2 coreclr-afb6185394511fb30c9278d40d6e6e2ca59cb6f8.zip |
Remove per-AppDomain TLB (#20423)
Since there is only one AppDomain, there is no need for a per-AppDomain
TLB table for each Thread. This change removes that table and thus gets
rid of the extra indirection needed to access the TLB.
-rw-r--r-- | src/vm/threads.cpp | 43 | ||||
-rw-r--r-- | src/vm/threads.h | 35 | ||||
-rw-r--r-- | src/vm/threadstatics.cpp | 35 | ||||
-rw-r--r-- | src/vm/threadstatics.h | 74 |
4 files changed, 13 insertions, 174 deletions
diff --git a/src/vm/threads.cpp b/src/vm/threads.cpp index e6f7c45f5e..b9395a8bb9 100644 --- a/src/vm/threads.cpp +++ b/src/vm/threads.cpp @@ -1374,8 +1374,6 @@ Thread::Thread() #endif // Initialize data members related to thread statics - m_pTLBTable = NULL; - m_TLBTableSize = 0; m_pThreadLocalBlock = NULL; m_dwLockCount = 0; @@ -2754,9 +2752,6 @@ Thread::~Thread() //Ensure DeleteThreadStaticData was executed _ASSERTE(m_pThreadLocalBlock == NULL); - _ASSERTE(m_pTLBTable == NULL); - _ASSERTE(m_TLBTableSize == 0); - #ifdef FEATURE_PREJIT if (m_pIBCInfo) { @@ -9100,24 +9095,12 @@ void Thread::DeleteThreadStaticData() CONTRACTL_END; // Deallocate the memory used by the table of ThreadLocalBlocks - if (m_pTLBTable != NULL) + if (m_pThreadLocalBlock != NULL) { - for (SIZE_T i = 0; i < m_TLBTableSize; ++i) - { - ThreadLocalBlock * pTLB = m_pTLBTable[i]; - if (pTLB != NULL) - { - m_pTLBTable[i] = NULL; - pTLB->FreeTable(); - delete pTLB; - } - } - - delete m_pTLBTable; - m_pTLBTable = NULL; + m_pThreadLocalBlock->FreeTable(); + delete m_pThreadLocalBlock; + m_pThreadLocalBlock = NULL; } - m_pThreadLocalBlock = NULL; - m_TLBTableSize = 0; } //+---------------------------------------------------------------------------- @@ -9132,13 +9115,9 @@ void Thread::DeleteThreadStaticData() void Thread::DeleteThreadStaticData(ModuleIndex index) { - for (SIZE_T i = 0; i < m_TLBTableSize; ++i) + if (m_pThreadLocalBlock != NULL) { - ThreadLocalBlock * pTLB = m_pTLBTable[i]; - if (pTLB != NULL) - { - pTLB->FreeTLM(index.m_dwIndex, FALSE /* isThreadShuttingDown */); - } + m_pThreadLocalBlock->FreeTLM(index.m_dwIndex, FALSE /* isThreadShuttingDown */); } } @@ -9163,14 +9142,8 @@ void Thread::DeleteThreadStaticData(AppDomain *pDomain) // Look up the AppDomain index SIZE_T index = pDomain->GetIndex().m_dwIndex; - ThreadLocalBlock * pTLB = NULL; - - // NULL out the pointer to the ThreadLocalBlock - if (index < m_TLBTableSize) - { - pTLB = m_pTLBTable[index]; - m_pTLBTable[index] = NULL; - } + ThreadLocalBlock * pTLB = m_pThreadLocalBlock; + m_pThreadLocalBlock = NULL; if (pTLB != NULL) { diff --git a/src/vm/threads.h b/src/vm/threads.h index 3f281c0274..d736fac6e9 100644 --- a/src/vm/threads.h +++ b/src/vm/threads.h @@ -197,8 +197,6 @@ class Thread friend class ThreadStatics; PTR_ThreadLocalBlock m_pThreadLocalBlock; - PTR_PTR_ThreadLocalBlock m_pTLBTable; - SIZE_T m_TLBTableSize; public: BOOL IsAddressInStack (PTR_VOID addr) const { return TRUE; } @@ -4490,41 +4488,8 @@ public: // m_pThreadLocalBLock points to the ThreadLocalBlock that corresponds to the // AppDomain that the Thread is currently in - - // m_pTLBTable points to the this Thread's table of ThreadLocalBlocks, indexed by - // ADIndex. It's important to note that ADIndexes get recycled when AppDomains are - // torn down. m_TLBTableSize holds to current size the size of this Thread's TLB table. - // See "ThreadStatics.h" for more information. PTR_ThreadLocalBlock m_pThreadLocalBlock; - PTR_PTR_ThreadLocalBlock m_pTLBTable; - SIZE_T m_TLBTableSize; - - // This getter is used by SOS; if m_pThreadLocalBlock is NULL, it's - // important that we look in the TLB table as well - /* - PTR_ThreadLocalBlock GetThreadLocalBlock() - { - // If the current TLB pointer is NULL, search the TLB table - if (m_pThreadLocalBlock != NULL) - return m_pThreadLocalBlock; - - ADIndex index = GetDomain()->GetIndex(); - - // Check to see if we have a ThreadLocalBlock for the the current AppDomain, - if (index.m_dwIndex < m_TLBTableSize) - { - // Update the current ThreadLocalBlock pointer, - // but only on non-DAC builds -#ifndef DACCESS_COMPILE - m_pThreadLocalBlock = m_pTLBTable[index.m_dwIndex]; -#endif - return m_pTLBTable[index.m_dwIndex]; - } - - return NULL; - } - */ // Called during AssemblyLoadContext teardown to clean up all structures // associated with thread statics for the specific Module diff --git a/src/vm/threadstatics.cpp b/src/vm/threadstatics.cpp index 7e9a9da987..dcfc082927 100644 --- a/src/vm/threadstatics.cpp +++ b/src/vm/threadstatics.cpp @@ -697,7 +697,7 @@ PTR_ThreadLocalModule ThreadStatics::GetTLM(MethodTable * pMT) //static return GetTLM(pModule->GetModuleIndex(), pModule); } -PTR_ThreadLocalBlock ThreadStatics::AllocateTLB(PTR_Thread pThread, ADIndex index) //static +PTR_ThreadLocalBlock ThreadStatics::AllocateTLB(PTR_Thread pThread) //static { CONTRACTL { @@ -709,22 +709,10 @@ PTR_ThreadLocalBlock ThreadStatics::AllocateTLB(PTR_Thread pThread, ADIndex inde CONTRACTL_END; _ASSERTE(pThread->m_pThreadLocalBlock == NULL); - // Grow the TLB table so that it has room to store the newly allocated - // ThreadLocalBlock. If this growing the table fails we cannot proceed. - ThreadStatics::EnsureADIndex(pThread, index); - // Allocate a new TLB and update this Thread's pointer to the current // ThreadLocalBlock. Constructor zeroes out everything for us. pThread->m_pThreadLocalBlock = new ThreadLocalBlock(); - // Store the newly allocated ThreadLocalBlock in the TLB table - if (pThread->m_pThreadLocalBlock != NULL) - { - // We grew the TLB table earlier, so it should have room - _ASSERTE(index.m_dwIndex >= 0 && index.m_dwIndex < pThread->m_TLBTableSize); - pThread->m_pTLBTable[index.m_dwIndex] = pThread->m_pThreadLocalBlock; - } - return pThread->m_pThreadLocalBlock; } @@ -758,24 +746,3 @@ PTR_ThreadLocalModule ThreadStatics::AllocateTLM(Module * pModule) } #endif - -PTR_ThreadLocalBlock ThreadStatics::GetTLBIfExists(PTR_Thread pThread, ADIndex index) //static -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - MODE_ANY; - SUPPORTS_DAC; - SO_TOLERANT; - } - CONTRACTL_END; - - // Check to see if we have a ThreadLocalBlock for the this AppDomain, - if (index.m_dwIndex < pThread->m_TLBTableSize) - { - return pThread->m_pTLBTable[index.m_dwIndex]; - } - - return NULL; -} diff --git a/src/vm/threadstatics.h b/src/vm/threadstatics.h index b6cd7db4d7..823e1d1626 100644 --- a/src/vm/threadstatics.h +++ b/src/vm/threadstatics.h @@ -604,65 +604,20 @@ class ThreadStatics public: #ifndef DACCESS_COMPILE - static PTR_ThreadLocalBlock AllocateTLB(PTR_Thread pThread, ADIndex index); + static PTR_ThreadLocalBlock AllocateTLB(PTR_Thread pThread); static PTR_ThreadLocalModule AllocateTLM(Module * pModule); static PTR_ThreadLocalModule AllocateAndInitTLM(ModuleIndex index, PTR_ThreadLocalBlock pThreadLocalBlock, Module * pModule); static PTR_ThreadLocalModule GetTLM(ModuleIndex index, Module * pModule); static PTR_ThreadLocalModule GetTLM(MethodTable * pMT); #endif - static PTR_ThreadLocalBlock GetTLBIfExists(PTR_Thread pThread, ADIndex index); #ifndef DACCESS_COMPILE - // Grows the TLB table - inline static void EnsureADIndex(PTR_Thread pThread, ADIndex index) - { - CONTRACTL - { - THROWS; - GC_NOTRIGGER; - SO_TOLERANT; - MODE_ANY; - } - CONTRACTL_END; - SIZE_T size = max(16, pThread->m_TLBTableSize); - while (size <= index.m_dwIndex) - { - size *= 2; - } - - // If this allocation fails, we will throw. If it succeeds, - // then we are good to go - PTR_ThreadLocalBlock * pNewTLBTable = (PTR_ThreadLocalBlock *)(void*)new PTR_ThreadLocalBlock [size]; - - // Zero out the new TLB table - memset(pNewTLBTable, 0, sizeof(PTR_ThreadLocalBlock) * size); - - if (pThread->m_pTLBTable != NULL) - { - memcpy(pNewTLBTable, pThread->m_pTLBTable, sizeof(PTR_ThreadLocalBlock) * pThread->m_TLBTableSize); - } - - PTR_ThreadLocalBlock * pOldTLBTable = pThread->m_pTLBTable; - - pThread->m_pTLBTable = pNewTLBTable; - pThread->m_TLBTableSize = size; - - delete pOldTLBTable; - } - FORCEINLINE static PTR_ThreadLocalBlock GetCurrentTLBIfExists() { // Get the current thread PTR_Thread pThread = GetThread(); - // If the current TLB pointer is NULL, search the TLB table - if (pThread->m_pThreadLocalBlock == NULL) - { - ADIndex index = pThread->GetDomain()->GetIndex(); - pThread->m_pThreadLocalBlock = ThreadStatics::GetTLBIfExists(pThread, index); - } - return pThread->m_pThreadLocalBlock; } #endif @@ -671,23 +626,7 @@ class ThreadStatics { SUPPORTS_DAC; - // If the current TLB pointer is NULL, search the TLB table PTR_ThreadLocalBlock pTLB = pThread->m_pThreadLocalBlock; - if (pTLB == NULL) - { - if (pDomain == NULL) - { - pDomain = pThread->GetDomain(); - } - - pTLB = ThreadStatics::GetTLBIfExists(pThread, pDomain->GetIndex()); - - // Update the ThreadLocalBlock pointer, - // but only on non-DAC builds -#ifndef DACCESS_COMPILE - pThread->m_pThreadLocalBlock = pTLB; -#endif - } return pTLB; } @@ -701,14 +640,9 @@ class ThreadStatics // If the current TLB pointer is NULL, search the TLB table if (pThread->m_pThreadLocalBlock == NULL) { - AppDomain * pDomain = pThread->GetDomain(); - pThread->m_pThreadLocalBlock = ThreadStatics::GetTLBIfExists(pThread, pDomain->GetIndex()); - if (pThread->m_pThreadLocalBlock == NULL) - { - // Allocate the new ThreadLocalBlock. - // If the allocation fails this will throw. - return ThreadStatics::AllocateTLB(pThread, pDomain->GetIndex()); - } + // Allocate the new ThreadLocalBlock. + // If the allocation fails this will throw. + return ThreadStatics::AllocateTLB(pThread); } return pThread->m_pThreadLocalBlock; |