diff options
author | Vance Morrison <vancem@microsoft.com> | 2018-06-01 07:53:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-01 07:53:12 -0700 |
commit | c17ca743320b8c0c54ca1b8248b4e8cbc771c241 (patch) | |
tree | c38e46ad005a89eeb871a17eff0a0b9ef715154f | |
parent | 95ae6621b1c7f176b518ad819f6eccd469e91ea1 (diff) | |
parent | 4280cda0dade54e3b07c348e8b1b3e9ca65fc1fe (diff) | |
download | coreclr-c17ca743320b8c0c54ca1b8248b4e8cbc771c241.tar.gz coreclr-c17ca743320b8c0c54ca1b8248b4e8cbc771c241.tar.bz2 coreclr-c17ca743320b8c0c54ca1b8248b4e8cbc771c241.zip |
Merge pull request #18216 from vancem/FixThreadNameSet
Fix Managed Thread Name Setting
-rw-r--r-- | src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs | 3 | ||||
-rw-r--r-- | src/vm/comsynchronizable.cpp | 14 | ||||
-rw-r--r-- | src/vm/object.h | 6 | ||||
-rw-r--r-- | src/vm/threads.cpp | 3 |
4 files changed, 22 insertions, 4 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs index cfe1d35fd8..6992dcea43 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs @@ -2211,7 +2211,10 @@ namespace System.Diagnostics.Tracing break; default: if (innerEx != null) + { + innerEx = innerEx.GetBaseException(); ReportOutOfBandMessage(errorPrefix + ": " + innerEx.GetType() + ":" + innerEx.Message, true); + } else ReportOutOfBandMessage(errorPrefix, true); if (ThrowOnEventWriteErrors) throw new EventSourceException(innerEx); diff --git a/src/vm/comsynchronizable.cpp b/src/vm/comsynchronizable.cpp index 772163aff2..d5d57cd7c1 100644 --- a/src/vm/comsynchronizable.cpp +++ b/src/vm/comsynchronizable.cpp @@ -467,13 +467,23 @@ void ThreadNative::StartInner(ThreadBaseObject* pThisUNSAFE) if (ETW_EVENT_ENABLED(MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_Context, ThreadCreating)) FireEtwThreadCreating(pNewThread, GetClrInstanceId()); + // copy out the managed name into a buffer that will not move if a GC happens + const WCHAR* nativeThreadName = NULL; + InlineSString<64> threadNameBuffer; + STRINGREF managedThreadName = gc.pThis->GetName(); + if (managedThreadName != NULL) + { + managedThreadName->GetSString(threadNameBuffer); + nativeThreadName = threadNameBuffer.GetUnicode(); + } + // As soon as we create the new thread, it is eligible for suspension, etc. // So it gets transitioned to cooperative mode before this call returns to // us. It is our duty to start it running immediately, so that GC isn't blocked. BOOL success = pNewThread->CreateNewThread( pNewThread->RequestedThreadStackSize() /* 0 stackSize override*/, - KickOffThread, share); + KickOffThread, share, nativeThreadName); if (!success) { @@ -1547,7 +1557,7 @@ void QCALLTYPE ThreadNative::InformThreadNameChange(QCall::ThreadHandle thread, #ifndef FEATURE_PAL // Set on Windows 10 Creators Update and later machines the unmanaged thread name as well. That will show up in ETW traces and debuggers which is very helpful // if more and more threads get a meaningful name - if (len > 0 && name != NULL) + if (len > 0 && name != NULL && pThread->GetThreadHandle() != INVALID_HANDLE_VALUE) { SetThreadName(pThread->GetThreadHandle(), name); } diff --git a/src/vm/object.h b/src/vm/object.h index 3dd1e26d63..302d82f580 100644 --- a/src/vm/object.h +++ b/src/vm/object.h @@ -1443,7 +1443,7 @@ private: // at run time, not compile time. OBJECTREF m_ExecutionContext; OBJECTREF m_SynchronizationContext; - OBJECTREF m_Name; + STRINGREF m_Name; OBJECTREF m_Delegate; OBJECTREF m_ThreadStartArg; @@ -1497,6 +1497,10 @@ public: } + STRINGREF GetName() { + LIMITED_METHOD_CONTRACT; + return m_Name; + } OBJECTREF GetDelegate() { LIMITED_METHOD_CONTRACT; return m_Delegate; } void SetDelegate(OBJECTREF delegate); diff --git a/src/vm/threads.cpp b/src/vm/threads.cpp index 48cb5322d3..5042e52b78 100644 --- a/src/vm/threads.cpp +++ b/src/vm/threads.cpp @@ -2226,7 +2226,8 @@ BOOL Thread::CreateNewThread(SIZE_T stackSize, LPTHREAD_START_ROUTINE start, voi bRet = CreateNewOSThread(stackSize, start, args); #ifndef FEATURE_PAL UndoRevert(bReverted, token); - SetThreadName(m_ThreadHandle, pName); + if (pName != NULL) + SetThreadName(m_ThreadHandle, pName); #endif // !FEATURE_PAL return bRet; |