Remove STRESS_THREAD.
authorAditya Mandaleeka <adityam@microsoft.com>
Mon, 13 Mar 2017 23:17:24 +0000 (16:17 -0700)
committerAditya Mandaleeka <adityam@microsoft.com>
Mon, 13 Mar 2017 23:51:08 +0000 (16:51 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/ec723a53d7a098cf5b5455f3a248bc1d3269a954

src/coreclr/src/inc/apithreadstress.h
src/coreclr/src/utilcode/CMakeLists.txt
src/coreclr/src/utilcode/apithreadstress.cpp [deleted file]
src/coreclr/src/vm/assembly.cpp
src/coreclr/src/vm/eeconfig.cpp
src/coreclr/src/vm/eeconfig.h
src/coreclr/src/vm/threads.cpp
src/coreclr/src/vm/threads.h

index fc18dcc..a0c6cde 100644 (file)
 
 #include "utilcode.h"
 
-#ifdef STRESS_THREAD
-
-class APIThreadStress
-{
- public:
-    APIThreadStress();
-    ~APIThreadStress();
-
-    BOOL DoThreadStress();
-    static void SyncThreadStress();
-
-    static void SetThreadStressCount(int count);
-
- protected:
-    virtual void Invoke() {LIMITED_METHOD_CONTRACT;};
-
- private:
-    static DWORD WINAPI StartThread(void *arg);
-
-    static int s_threadStressCount;     
-
-    int       m_threadCount;
-    HANDLE    *m_hThreadArray;
-    BOOL      m_setupOK;
-    LONG      m_runCount;
-    HANDLE    m_syncEvent;
-
-};
-
-#else // STRESS_THREAD
-
 class APIThreadStress
 {
  public:
@@ -85,6 +54,4 @@ class APIThreadStress
     static void SetThreadStressCount(int count) { }
 };
 
-#endif // STRESS_THREAD
-
 #endif  // _APITHREADSTRESS_H_
index 7c39673..27b7a4a 100644 (file)
@@ -28,7 +28,6 @@ set(UTILCODE_COMMON_SOURCES
   peinformation.cpp
   check.cpp
   log.cpp
-  apithreadstress.cpp
   arraylist.cpp
   bitvector.cpp
   comex.cpp
diff --git a/src/coreclr/src/utilcode/apithreadstress.cpp b/src/coreclr/src/utilcode/apithreadstress.cpp
deleted file mode 100644 (file)
index 88b09fe..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-// ---------------------------------------------------------------------------
-// APIThreadStress.cpp  (API thread stresser)
-// ---------------------------------------------------------------------------
-
-#include "stdafx.h"
-
-#ifdef STRESS_THREAD
-
-#include "apithreadstress.h"
-#include "clrhost.h"
-#include "ex.h"
-#include "log.h"
-
-
-
-// For now, thread stress is incompatible with hosting.  We need a host CreateThread
-// to fix this.
-#undef SetEvent
-#undef ResetEvent
-
-int APIThreadStress::s_threadStressCount = 0;
-
-APIThreadStress::APIThreadStress()
-{
-    WRAPPER_NO_CONTRACT;
-
-    m_threadCount = 0;
-
-    // Don't "fork" stress threads
-    if (ClrFlsGetValue(TlsIdx_StressThread) == NULL)
-        m_threadCount = s_threadStressCount;
-
-    if (m_threadCount != 0)
-    {
-        m_setupOK = TRUE;
-
-        m_hThreadArray = new (nothrow) HANDLE [ m_threadCount ];
-        if (m_hThreadArray == NULL)
-            m_setupOK = FALSE;
-        else
-        {
-            HANDLE *p = m_hThreadArray;
-            HANDLE *pEnd = p + m_threadCount;
-            
-            while (p < pEnd)
-            {
-                DWORD id;
-                *p = ::CreateThread(NULL, 0, StartThread, this, 0, &id);
-                if (*p == NULL)
-                    m_setupOK = FALSE;
-                p++;
-            }
-        }
-
-        m_syncEvent = ClrCreateManualEvent(FALSE);
-        if (m_syncEvent == INVALID_HANDLE_VALUE)
-            m_setupOK = FALSE;
-    }
-}
-
-APIThreadStress::~APIThreadStress()
-{
-    WRAPPER_NO_CONTRACT;
-
-    if (m_threadCount > 0)
-    {
-        HANDLE *p = m_hThreadArray;
-        HANDLE *pEnd = p + m_threadCount;
-
-        if (p != NULL)
-        {
-            while (p < pEnd)
-            {
-                if (*p != NULL)
-                {
-                    if (m_threadCount > 0 && m_setupOK)
-                        WaitForSingleObjectEx(*p, INFINITE, FALSE);
-
-                    ::CloseHandle(*p);
-                }
-                p++;
-            }
-            delete [] m_hThreadArray;
-        }
-
-        if (m_syncEvent != INVALID_HANDLE_VALUE)
-            CloseHandle(m_syncEvent);
-    }
-}
-
-void APIThreadStress::SetThreadStressCount(int threadCount)
-{
-    LIMITED_METHOD_CONTRACT;
-
-    s_threadStressCount = threadCount;
-}
-
-
-DWORD WINAPI APIThreadStress::StartThread(void *arg)
-{
-    WRAPPER_NO_CONTRACT;
-    STATIC_CONTRACT_SO_NOT_MAINLINE;    // not mainline so scenario
-
-    APIThreadStress *pThis = (APIThreadStress *) arg;
-
-    ClrFlsSetValue(TlsIdx_StressThread, pThis);
-
-    EX_TRY
-    {
-        // Perform initial synchronization
-        WaitForSingleObjectEx(pThis->m_syncEvent, INFINITE, FALSE);
-        InterlockedIncrement(&pThis->m_runCount);
-
-        LOG((LF_ALL, LL_INFO100, "Stressing operation on thread %d\n", GetCurrentThreadId()));
-        ((APIThreadStress *)arg)->Invoke();
-        LOG((LF_ALL, LL_INFO100, "End stress operation on thread %d\n", GetCurrentThreadId()));
-
-        if (InterlockedDecrement(&pThis->m_runCount) == 0)
-            ::SetEvent(pThis->m_syncEvent);
-    }
-    EX_CATCH
-    {
-        LOG((LF_ALL, LL_ERROR, "Exception during stress operation on thread %d\n", GetCurrentThreadId()));
-    }
-    EX_END_CATCH(SwallowAllExceptions);
-
-    return 0;
-}
-
-BOOL APIThreadStress::DoThreadStress()
-{
-    WRAPPER_NO_CONTRACT;
-
-    if (m_threadCount > 0 && m_setupOK)
-    {
-        HANDLE *p = m_hThreadArray;
-        HANDLE *pEnd = p + m_threadCount;
-
-        while (p < pEnd)
-        {
-            ::ResumeThread(*p);
-            p++;
-        }
-
-        // Start the threads at the same time
-        ::SetEvent(m_syncEvent);
-
-        return TRUE;
-    }
-    else
-    {
-        SyncThreadStress();
-        return FALSE;
-    }
-}
-
-void APIThreadStress::SyncThreadStress()
-{
-    WRAPPER_NO_CONTRACT;
-
-    APIThreadStress *pThis = (APIThreadStress *) ClrFlsGetValue(TlsIdx_StressThread);
-
-    if (pThis != NULL)
-    {
-        LOG((LF_ALL, LL_INFO1000, "Syncing stress operation on thread %d\n", GetCurrentThreadId()));
-
-        ::ResetEvent(pThis->m_syncEvent);
-
-        if (InterlockedDecrement(&pThis->m_runCount) == 0)
-            ::SetEvent(pThis->m_syncEvent);
-        else
-            WaitForSingleObjectEx(pThis->m_syncEvent, INFINITE, FALSE);
-        InterlockedIncrement(&pThis->m_runCount);
-
-        LOG((LF_ALL, LL_INFO1000, "Resuming stress operation on thread %d\n", GetCurrentThreadId()));
-    }
-}
-
-#endif // STRESS_THREAD
index 5f0e75d..db59b5e 100644 (file)
@@ -1661,214 +1661,6 @@ enum CorEntryPointType
     EntryCrtMain                        // unsigned main(void)
 };
 
-#ifdef STRESS_THREAD
-
-struct Stress_Thread_Param
-{
-    MethodDesc *pFD;
-    GlobalStrongHandleHolder argHandle;
-    short numSkipArgs;
-    CorEntryPointType EntryType;
-    Thread* pThread;
-
-public:
-    Stress_Thread_Param()
-        : pFD(NULL),
-          argHandle(),
-          numSkipArgs(0),
-          EntryType(EntryManagedMain),
-          pThread(NULL)
-    { LIMITED_METHOD_CONTRACT; }
-
-    Stress_Thread_Param* Clone ()
-    {
-        CONTRACTL
-        {
-            THROWS;
-            GC_TRIGGERS;
-            MODE_ANY;
-        }
-        CONTRACTL_END;
-
-        NewHolder<Stress_Thread_Param> retVal= new Stress_Thread_Param;
-
-        retVal->pFD = pFD;
-        if (argHandle.GetValue()!=NULL)
-        {
-            GCX_COOP();
-            retVal->argHandle.Assign(CreateDuplicateHandle(argHandle.GetValue()));
-        }
-        retVal->numSkipArgs = numSkipArgs;
-        retVal->EntryType = EntryType;
-        retVal->pThread = pThread;
-        return retVal.Extract();
-    }
-};
-
-struct Stress_Thread_Worker_Param
-{
-    Stress_Thread_Param *lpParameter;
-    ULONG retVal;
-};
-
-static void Stress_Thread_Proc_Worker_Impl(Stress_Thread_Worker_Param * args)
-{
-    STATIC_CONTRACT_THROWS;
-
-    args->retVal = E_FAIL;
-
-    Stress_Thread_Param* lpParam =  (Stress_Thread_Param *)args->lpParameter;
-
-    ARG_SLOT stackVar = 0;
-
-    MethodDescCallSite threadStart(lpParam->pFD);
-
-    // Build the parameter array and invoke the method.
-    if (lpParam->EntryType == EntryManagedMain) 
-    {
-        PTRARRAYREF StrArgArray = (PTRARRAYREF)ObjectFromHandle(lpParam->argHandle.GetValue());
-        stackVar = ObjToArgSlot(StrArgArray);
-    }
-
-    if (lpParam->pFD->IsVoid())
-    {
-        threadStart.Call(&stackVar);
-        args->retVal = GetLatchedExitCode();
-    }
-    else
-    {
-        // We are doing the same cast as in RunMain.  Main is required to return INT32 if it returns.
-        ARG_SLOT retVal = (INT32)threadStart.Call_RetArgSlot(&stackVar);
-        args->retVal = static_cast<ULONG>(retVal);
-    }
-}
-
-// wrap into EX_TRY_NOCATCH and call the real thing
-static void Stress_Thread_Proc_Worker (LPVOID ptr)
-{
-    STATIC_CONTRACT_THROWS;
-
-    EX_TRY_NOCATCH(Stress_Thread_Worker_Param *, args, (Stress_Thread_Worker_Param *) ptr)
-    {
-        Stress_Thread_Proc_Worker_Impl(args);
-        //<TODO>
-        // When we get mainCRTStartup from the C++ then this should be able to go away.</TODO>
-        fflush(stdout);
-        fflush(stderr);
-    }
-    EX_END_NOCATCH
-}
-
-static DWORD WINAPI __stdcall Stress_Thread_Proc (LPVOID lpParameter)
-{
-    STATIC_CONTRACT_THROWS;
-
-    Stress_Thread_Worker_Param args = {(Stress_Thread_Param*)lpParameter,0};
-    Stress_Thread_Param *lpParam = (Stress_Thread_Param *)lpParameter;
-    Thread *pThread = lpParam->pThread;
-    if (!pThread->HasStarted())
-        return 0;
-
-    _ASSERTE(::GetAppDomain() != NULL);
-    BEGIN_SO_INTOLERANT_CODE_NO_THROW_CHECK_THREAD(return E_FAIL);
-    EX_TRY
-    {
-
-        ADID KickOffDomain = pThread->GetKickOffDomainId();
-
-        // should always have a kickoff domain - a thread should never start in a domain that is unloaded
-        // because otherwise it would have been collected because nobody can hold a reference to thread object
-        // in a domain that has been unloaded. But it is possible that we started the unload, in which
-        // case this thread wouldn't be allowed in or would be punted anyway.
-        if (KickOffDomain != lpParam->pThread->GetDomain()->GetId())
-            pThread->DoADCallBack(KickOffDomain, Stress_Thread_Proc_Worker, &args);
-        else
-            Stress_Thread_Proc_Worker(&args);
-       
-    }
-    EX_CATCH
-    {
-    }
-    EX_END_CATCH(SwallowAllExceptions);
-
-    delete (Stress_Thread_Param *) lpParameter;
-    // Enable preemptive GC so a GC thread can suspend me.
-    GCX_PREEMP_NO_DTOR();
-    DestroyThread(pThread);
-
-    END_SO_INTOLERANT_CODE;  
-    return args.retVal;
-}
-
-static void Stress_Thread_Start (LPVOID lpParameter)
-{
-    CONTRACT_VOID
-    {
-        THROWS;
-        GC_TRIGGERS;
-        INJECT_FAULT(COMPlusThrowOM());
-        MODE_ANY;
-    }
-    CONTRACT_END;
-
-    Thread *pCurThread = GetThread();
-    if (pCurThread->m_stressThreadCount == -1) {
-        pCurThread->m_stressThreadCount = g_pConfig->GetStressThreadCount();
-    }
-    DWORD dwThreads = pCurThread->m_stressThreadCount;
-    if (dwThreads <= 1)
-        RETURN;
-
-    Thread ** threads = new Thread* [dwThreads-1];
-
-    DWORD n;
-    for (n = 0; n < dwThreads-1; n ++)
-    {
-        threads[n] = SetupUnstartedThread();
-
-        threads[n]->m_stressThreadCount = dwThreads/2;
-        Stress_Thread_Param *param = ((Stress_Thread_Param*)lpParameter)->Clone();
-        param->pThread = threads[n];
-        if (!threads[n]->CreateNewThread(0, Stress_Thread_Proc, param))
-        {
-            delete param;
-            threads[n]->DecExternalCount(FALSE);
-            ThrowOutOfMemory();
-        }
-        threads[n]->SetThreadPriority (THREAD_PRIORITY_NORMAL);
-    }
-
-    for (n = 0; n < dwThreads-1; n ++)
-    {
-        threads[n]->StartThread();
-    }
-    __SwitchToThread (0, CALLER_LIMITS_SPINNING);
-
-    RETURN;
-}
-
-void Stress_Thread_RunMain(MethodDesc* pFD, CorEntryPointType EntryType, short numSkipArgs, OBJECTHANDLE argHandle)
-{
-    CONTRACTL
-    {
-        THROWS;
-        GC_TRIGGERS;
-        MODE_ANY;
-    }
-    CONTRACTL_END;
-
-    Stress_Thread_Param Param;
-    Param.pFD = pFD;
-    Param.argHandle.Assign(argHandle);
-    Param.numSkipArgs = numSkipArgs;
-    Param.EntryType = EntryType;
-    Param.pThread = NULL;
-    Stress_Thread_Start (&Param);
-}
-
-
-#endif // STRESS_THREAD
-
 void DECLSPEC_NORETURN ThrowMainMethodException(MethodDesc* pMD, UINT resID)
 {
     CONTRACTL
@@ -2043,11 +1835,6 @@ HRESULT RunMain(MethodDesc *pFD ,
                 StrArgArray = *pParam->stringArgs;
         }
 
-#ifdef STRESS_THREAD
-        OBJECTHANDLE argHandle = (StrArgArray != NULL) ? CreateGlobalStrongHandle (StrArgArray) : NULL;
-        Stress_Thread_RunMain(pParam->pFD, pParam->EntryType, pParam->numSkipArgs, argHandle);
-#endif
-
         ARG_SLOT stackVar = ObjToArgSlot(StrArgArray);
 
         if (pParam->pFD->IsVoid()) 
index a44039d..237e690 100644 (file)
@@ -939,10 +939,6 @@ HRESULT EEConfig::sync()
 
     fStressLog        =  GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_StressLog, fStressLog) != 0;
     fForceEnc         =  GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_ForceEnc, fForceEnc) != 0;
-    
-#ifdef STRESS_THREAD
-    dwStressThreadCount =  GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_StressThreadCount, dwStressThreadCount);
-#endif
 
     iRequireZaps        = RequireZapsType(GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_ZapRequire, iRequireZaps));
     if (IsCompilationProcess() || iRequireZaps >= REQUIRE_ZAPS_COUNT)
index 8e21c44..84df6c3 100644 (file)
@@ -708,12 +708,6 @@ public:
                                                                                     && pSkipGCCoverageList->IsInList(assemblyName));}
 #endif
 
-
-    // thread stress: number of threads to run
-#ifdef STRESS_THREAD
-    DWORD GetStressThreadCount ()           const {LIMITED_METHOD_CONTRACT; return dwStressThreadCount;}
-#endif
-
 #ifdef _DEBUG
     inline DWORD FastGCStressLevel() const
     {LIMITED_METHOD_CONTRACT;  return iFastGCStress;}
@@ -1091,10 +1085,6 @@ private: //----------------------------------------------------------------
 
     bool fGCBreakOnOOM;
 
-#ifdef  STRESS_THREAD
-    DWORD dwStressThreadCount;
-#endif
-
 #ifdef _DEBUG
     DWORD iFastGCStress;
     LPUTF8 pszGcCoverageOnMethod;
index 83dafd9..3915b3e 100644 (file)
@@ -1897,10 +1897,6 @@ Thread::Thread()
     m_dwAbortPoint = 0;
 #endif
 
-#ifdef STRESS_THREAD
-    m_stressThreadCount = -1;
-#endif
-
     m_pFiberData = NULL;
 
     m_TaskId = INVALID_TASK_ID;
index fc8ed94..6371a5e 100644 (file)
@@ -4733,12 +4733,6 @@ public:
     size_t *m_pCleanedStackBase;
 #endif
 
-#ifdef STRESS_THREAD
-public:
-    LONG  m_stressThreadCount;
-#endif
-
-
 private:
     PVOID      m_pFiberData;