diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2018-10-04 10:26:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-04 10:26:06 +0200 |
commit | 7559844bbe9e4230217a9a9cf4be8a857531c8c8 (patch) | |
tree | c1ad22769c0091396307d555a5959ecdc0dfed31 /src/vm/jithelpers.cpp | |
parent | 11832401739148f1f1e9419cb51180ba5263a41b (diff) | |
download | coreclr-7559844bbe9e4230217a9a9cf4be8a857531c8c8.tar.gz coreclr-7559844bbe9e4230217a9a9cf4be8a857531c8c8.tar.bz2 coreclr-7559844bbe9e4230217a9a9cf4be8a857531c8c8.zip |
Enable thread statics for collectible classes (#19944)
* Enable thread statics for collectible classes
This change removes checks that were preventing usage of thread statics
in collectible classes and also implements all the necessary changes.
The handles that hold arrays with thread statics are allocated from
LoaderAllocator for collectible classes instead of using the global
strong handle like in the case of non-collectible classes.
The change very much mimics what is done for regular statics.
This change also adds ability to reuse freed handles to the
LoaderAllocator handle table. Freed handle indexes are stored into a
stack and when a new handle allocation is requested, the indices from
this stack are used first.
Due to the code path from which the FreeTLM that in turn frees the
handles is called, I had to modify the critical section flags and also
refactor the handle allocation so that the actual managed array
representing the handle table is allocated out of the critical section.
When I was touching the code, I have also moved the code that was
dealing with handles that are not stored in the LoaderAllocator handle
tables out of the critical section, since there is no point in having it
inside of it.
Diffstat (limited to 'src/vm/jithelpers.cpp')
-rw-r--r-- | src/vm/jithelpers.cpp | 69 |
1 files changed, 45 insertions, 24 deletions
diff --git a/src/vm/jithelpers.cpp b/src/vm/jithelpers.cpp index 9bb6d9889e..f92e52b479 100644 --- a/src/vm/jithelpers.cpp +++ b/src/vm/jithelpers.cpp @@ -1935,11 +1935,14 @@ HCIMPL2(void*, JIT_GetSharedNonGCThreadStaticBaseDynamicClass, SIZE_T moduleDoma { FCALL_CONTRACT; - // Get the ModuleIndex - ModuleIndex index = + // Obtain the DomainLocalModule + DomainLocalModule *pDomainLocalModule = (Module::IsEncodedModuleIndex(moduleDomainID)) ? - Module::IDToIndex(moduleDomainID) : - ((DomainLocalModule *)moduleDomainID)->GetModuleIndex(); + GetAppDomain()->GetDomainLocalBlock()->GetModuleSlot(Module::IDToIndex(moduleDomainID)) : + (DomainLocalModule *)moduleDomainID; + + // Get the ModuleIndex + ModuleIndex index = pDomainLocalModule->GetModuleIndex(); // Get the relevant ThreadLocalModule ThreadLocalModule * pThreadLocalModule = ThreadStatics::GetTLMIfExists(index); @@ -1950,18 +1953,18 @@ HCIMPL2(void*, JIT_GetSharedNonGCThreadStaticBaseDynamicClass, SIZE_T moduleDoma { ThreadLocalModule::PTR_DynamicClassInfo pLocalInfo = pThreadLocalModule->GetDynamicClassInfoIfInitialized(dwDynamicClassDomainID); if (pLocalInfo != NULL) - return (void*)pLocalInfo->m_pDynamicEntry->GetNonGCStaticsBasePointer(); + { + PTR_BYTE retval; + GET_DYNAMICENTRY_NONGCTHREADSTATICS_BASEPOINTER(pDomainLocalModule->GetDomainFile()->GetModule()->GetLoaderAllocator(), + pLocalInfo, + &retval); + return retval; + } } // If the TLM was not allocated or if the class was not marked as initialized // then we have to go through the slow path - // Obtain the DomainLocalModule - DomainLocalModule *pDomainLocalModule = - (Module::IsEncodedModuleIndex(moduleDomainID)) ? - GetAppDomain()->GetDomainLocalBlock()->GetModuleSlot(Module::IDToIndex(moduleDomainID)) : - (DomainLocalModule *) moduleDomainID; - // Obtain the Module Module * pModule = pDomainLocalModule->GetDomainFile()->GetModule(); @@ -1986,11 +1989,14 @@ HCIMPL2(void*, JIT_GetSharedGCThreadStaticBaseDynamicClass, SIZE_T moduleDomainI { FCALL_CONTRACT; - // Get the ModuleIndex - ModuleIndex index = + // Obtain the DomainLocalModule + DomainLocalModule *pDomainLocalModule = (Module::IsEncodedModuleIndex(moduleDomainID)) ? - Module::IDToIndex(moduleDomainID) : - ((DomainLocalModule *)moduleDomainID)->GetModuleIndex(); + GetAppDomain()->GetDomainLocalBlock()->GetModuleSlot(Module::IDToIndex(moduleDomainID)) : + (DomainLocalModule *)moduleDomainID; + + // Get the ModuleIndex + ModuleIndex index = pDomainLocalModule->GetModuleIndex(); // Get the relevant ThreadLocalModule ThreadLocalModule * pThreadLocalModule = ThreadStatics::GetTLMIfExists(index); @@ -2001,18 +2007,19 @@ HCIMPL2(void*, JIT_GetSharedGCThreadStaticBaseDynamicClass, SIZE_T moduleDomainI { ThreadLocalModule::PTR_DynamicClassInfo pLocalInfo = pThreadLocalModule->GetDynamicClassInfoIfInitialized(dwDynamicClassDomainID); if (pLocalInfo != NULL) - return (void*)pLocalInfo->m_pDynamicEntry->GetGCStaticsBasePointer(); + { + PTR_BYTE retval; + GET_DYNAMICENTRY_GCTHREADSTATICS_BASEPOINTER(pDomainLocalModule->GetDomainFile()->GetModule()->GetLoaderAllocator(), + pLocalInfo, + &retval); + + return retval; + } } // If the TLM was not allocated or if the class was not marked as initialized // then we have to go through the slow path - // Obtain the DomainLocalModule - DomainLocalModule *pDomainLocalModule = - (Module::IsEncodedModuleIndex(moduleDomainID)) ? - GetAppDomain()->GetDomainLocalBlock()->GetModuleSlot(Module::IDToIndex(moduleDomainID)) : - (DomainLocalModule *) moduleDomainID; - // Obtain the Module Module * pModule = pDomainLocalModule->GetDomainFile()->GetModule(); @@ -2060,7 +2067,14 @@ HCIMPL1(void*, JIT_GetGenericsNonGCThreadStaticBase, MethodTable *pMT) { ThreadLocalModule::PTR_DynamicClassInfo pLocalInfo = pThreadLocalModule->GetDynamicClassInfoIfInitialized(dwDynamicClassDomainID); if (pLocalInfo != NULL) - return (void*)pLocalInfo->m_pDynamicEntry->GetNonGCStaticsBasePointer(); + { + PTR_BYTE retval; + GET_DYNAMICENTRY_NONGCSTATICS_BASEPOINTER(pMT->GetLoaderAllocator(), + pLocalInfo, + &retval); + + return retval; + } } // If the TLM was not allocated or if the class was not marked as initialized @@ -2105,7 +2119,14 @@ HCIMPL1(void*, JIT_GetGenericsGCThreadStaticBase, MethodTable *pMT) { ThreadLocalModule::PTR_DynamicClassInfo pLocalInfo = pThreadLocalModule->GetDynamicClassInfoIfInitialized(dwDynamicClassDomainID); if (pLocalInfo != NULL) - return (void*)pLocalInfo->m_pDynamicEntry->GetGCStaticsBasePointer(); + { + PTR_BYTE retval; + GET_DYNAMICENTRY_GCTHREADSTATICS_BASEPOINTER(pMT->GetLoaderAllocator(), + pLocalInfo, + &retval); + + return retval; + } } // If the TLM was not allocated or if the class was not marked as initialized |