Remove resetting of unmanaged thread locale from thread pool APIs (#22682)
authorJan Kotas <jkotas@microsoft.com>
Tue, 19 Feb 2019 00:37:19 +0000 (16:37 -0800)
committerGitHub <noreply@github.com>
Tue, 19 Feb 2019 00:37:19 +0000 (16:37 -0800)
The cost of doing this is showing up in the TechEmpower profiles. There is a lot of thread locale state in unmanaged libraries and OS APIs that the threadpool friendly code has to be aware off. It does not make sense to keep reseting just the Locale.

src/vm/finalizerthread.cpp
src/vm/util.cpp
src/vm/util.hpp
src/vm/win32threadpool.cpp

index 0a7569a..2a44b45 100644 (file)
@@ -168,12 +168,8 @@ Object * FinalizerThread::DoOneFinalization(Object* fobj, Thread* pThread,int bi
             }
         };
         {
-            ThreadLocaleHolder localeHolder;
-
-            {
-                ResetFinalizerStartTime resetTime;
-                CallFinalizer(fobj);
-            }
+            ResetFinalizerStartTime resetTime;
+            CallFinalizer(fobj);
         }
         pThread->InternalReset();
     } 
@@ -194,8 +190,6 @@ Object * FinalizerThread::DoOneFinalization(Object* fobj, Thread* pThread,int bi
             args.bitToCheck = bitToCheck;
             GCPROTECT_BEGIN(args.fobj);
             {
-                ThreadLocaleHolder localeHolder;
-
                 _ASSERTE(pThreadTurnAround != NULL);
                 ManagedThreadBase::FinalizerAppDomain(targetAppDomain,
                                                       FinalizeAllObjects_Wrapper,
index 65fe6dd..f03c5e3 100644 (file)
@@ -2043,11 +2043,6 @@ size_t GetCacheSizePerLogicalCpu(BOOL bTrueSize)
 //---------------------------------------------------------------------
 
 #ifndef FEATURE_PAL
-ThreadLocaleHolder::~ThreadLocaleHolder()
-{
-    SetThreadLocale(m_locale);
-}
-
 HMODULE CLRGetModuleHandle(LPCWSTR lpModuleFileName)
 {
     // Don't use dynamic contract: will override GetLastError value
@@ -2058,20 +2053,6 @@ HMODULE CLRGetModuleHandle(LPCWSTR lpModuleFileName)
     HMODULE hMod = WszGetModuleHandle(lpModuleFileName);
     return hMod;
 }
-
-
-HMODULE CLRGetCurrentModuleHandle()
-{
-    // Don't use dynamic contract: will override GetLastError value
-    STATIC_CONTRACT_NOTHROW;
-    STATIC_CONTRACT_GC_NOTRIGGER;
-    STATIC_CONTRACT_FORBID_FAULT;
-
-    HMODULE hMod = WszGetModuleHandle(NULL);
-    return hMod;
-}
-
-
 #endif // !FEATURE_PAL
 
 LPVOID EEHeapAllocInProcessHeap(DWORD dwFlags, SIZE_T dwBytes);
index 7f88f31..06afda6 100644 (file)
@@ -681,10 +681,6 @@ inline BOOL CLRHosted()
 #ifndef FEATURE_PAL
 HMODULE CLRGetModuleHandle(LPCWSTR lpModuleFileName);
 
-// Equivalent to CLRGetModuleHandle(NULL) but doesn't have the INJECT_FAULT contract associated
-// with CLRGetModuleHandle.
-HMODULE CLRGetCurrentModuleHandle();
-
 HMODULE CLRLoadLibraryEx(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
 #endif // !FEATURE_PAL
 
@@ -875,29 +871,8 @@ inline bool IsInCantStopRegion()
 }
 #endif // _DEBUG
 
-
-// PAL does not support per-thread locales. The holder is no-op for FEATURE_PALs
-class ThreadLocaleHolder
-{
-#ifndef FEATURE_PAL
-public:
-
-    ThreadLocaleHolder()
-    {
-        m_locale = GetThreadLocale();
-    }
-
-    ~ThreadLocaleHolder();
-
-private:
-    LCID m_locale;
-#endif // !FEATURE_PAL
-};
-
-
-
 BOOL IsValidMethodCodeNotification(USHORT Notification);
-    
+
 typedef DPTR(struct JITNotification) PTR_JITNotification;
 struct JITNotification
 {
index 908fedf..ccf6e8a 100644 (file)
@@ -831,8 +831,6 @@ BOOL ThreadpoolMgr::QueueUserWorkItem(LPTHREAD_START_ROUTINE Function,
         ThreadCounter::Counts counts = CPThreadCounter.GetCleanCounts();
         if ((MaxLimitTotalCPThreads - counts.NumActive) >= MinimumAvailableCPThreads )
         {
-            ThreadLocaleHolder localeHolder;
-
             QueueUserWorkItemHelp(Function, Context);
             return TRUE;
         }
@@ -1507,8 +1505,6 @@ DWORD WINAPI ThreadpoolMgr::ExecuteHostRequest(PVOID pArg)
     }
     CONTRACTL_END;
 
-    ThreadLocaleHolder localeHolder;
-
     bool foundWork, wasNotRecalled;
     ExecuteWorkRequest(&foundWork, &wasNotRecalled);
     return ERROR_SUCCESS;
@@ -2005,8 +2001,6 @@ Work:
     }
 
     {
-        ThreadLocaleHolder localeHolder;
-
         ThreadpoolMgr::UpdateLastDequeueTime();
         ThreadpoolMgr::ExecuteWorkRequest(&foundWork, &wasNotRecalled);
     }
@@ -3621,8 +3615,6 @@ Top:
                 {
                     CONTRACT_VIOLATION(ThrowsViolation);
 
-                    ThreadLocaleHolder localeHolder;
-
                     ((LPOVERLAPPED_COMPLETION_ROUTINE) key)(errorCode, numBytes, pOverlapped);
                 }