-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Misc cleanup of VM threading code #108171
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,6 @@ namespace System.Threading | |
{ | ||
public sealed partial class Thread | ||
{ | ||
[ThreadStatic] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code |
||
private static int t_reentrantWaitSuppressionCount; | ||
|
||
[ThreadStatic] | ||
private static ApartmentType t_apartmentType; | ||
|
||
|
@@ -404,24 +401,8 @@ internal static Thread EnsureThreadPoolThreadInitialized() | |
|
||
public void Interrupt() { throw new PlatformNotSupportedException(); } | ||
|
||
// | ||
// Suppresses reentrant waits on the current thread, until a matching call to RestoreReentrantWaits. | ||
// This should be used by code that's expected to be called inside the STA message pump, so that it won't | ||
// reenter itself. In an ASTA, this should only be the CCW implementations of IUnknown and IInspectable. | ||
// | ||
internal static void SuppressReentrantWaits() | ||
{ | ||
t_reentrantWaitSuppressionCount++; | ||
} | ||
|
||
internal static void RestoreReentrantWaits() | ||
{ | ||
Debug.Assert(t_reentrantWaitSuppressionCount > 0); | ||
t_reentrantWaitSuppressionCount--; | ||
} | ||
|
||
internal static bool ReentrantWaitsEnabled => | ||
GetCurrentApartmentType() == ApartmentType.STA && t_reentrantWaitSuppressionCount == 0; | ||
GetCurrentApartmentType() == ApartmentType.STA; | ||
|
||
internal static ApartmentType GetCurrentApartmentType() | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,42 +52,6 @@ BOOL FinalizerThread::HaveExtraWorkForFinalizer() | |
return GetFinalizerThread()->HaveExtraWorkForFinalizer(); | ||
} | ||
|
||
static void CallFinalizerOnThreadObject(OBJECTREF obj) | ||
{ | ||
STATIC_CONTRACT_MODE_COOPERATIVE; | ||
|
||
THREADBASEREF refThis = (THREADBASEREF)obj; | ||
Thread* thread = refThis->GetInternal(); | ||
|
||
// Prevent multiple calls to Finalize | ||
// Objects can be resurrected after being finalized. However, there is no | ||
// race condition here. We always check whether an exposed thread object is | ||
// still attached to the internal Thread object, before proceeding. | ||
if (thread) | ||
{ | ||
refThis->ResetStartHelper(); | ||
|
||
// During process shutdown, we finalize even reachable objects. But if we break | ||
// the link between the System.Thread and the internal Thread object, the runtime | ||
// may not work correctly. In particular, we won't be able to transition between | ||
// contexts and domains to finalize other objects. Since the runtime doesn't | ||
// require that Threads finalize during shutdown, we need to disable this. If | ||
// we wait until phase 2 of shutdown finalization (when the EE is suspended and | ||
// will never resume) then we can simply skip the side effects of Thread | ||
// finalization. | ||
if ((g_fEEShutDown & ShutDown_Finalize2) == 0) | ||
{ | ||
if (GetThreadNULLOk() != thread) | ||
{ | ||
refThis->ClearInternal(); | ||
} | ||
|
||
thread->SetThreadState(Thread::TS_Finalized); | ||
Thread::SetCleanupNeededForFinalizedThread(); | ||
} | ||
} | ||
} | ||
|
||
OBJECTREF FinalizerThread::GetNextFinalizableObject() | ||
{ | ||
STATIC_CONTRACT_THROWS; | ||
|
@@ -138,20 +102,6 @@ OBJECTREF FinalizerThread::GetNextFinalizableObject() | |
} | ||
while (pMTCur != NULL); | ||
} | ||
|
||
if (pMT == g_pThreadClass) | ||
{ | ||
// Finalizing Thread object requires ThreadStoreLock. It is expensive if | ||
// we keep taking ThreadStoreLock. This is very bad if we have high retiring | ||
// rate of Thread objects. | ||
// To avoid taking ThreadStoreLock multiple times, we mark Thread with TS_Finalized | ||
// and clean up a batch of them when we take ThreadStoreLock next time. | ||
|
||
// To avoid possible hierarchy requirement between critical finalizers, we call cleanup | ||
// code directly. | ||
CallFinalizerOnThreadObject(obj); | ||
goto Again; | ||
} | ||
|
||
return obj; | ||
} | ||
|
@@ -426,19 +376,8 @@ DWORD WINAPI FinalizerThread::FinalizerThreadStart(void *args) | |
ASSERT(args == 0); | ||
ASSERT(hEventFinalizer->IsValid()); | ||
|
||
// TODO: The following line should be removed after contract violation is fixed. | ||
// See bug 27409 | ||
SCAN_IGNORE_THROW; | ||
SCAN_IGNORE_TRIGGER; | ||
|
||
LOG((LF_GC, LL_INFO10, "Finalizer thread starting...\n")); | ||
|
||
#if defined(FEATURE_COMINTEROP_APARTMENT_SUPPORT) && !defined(FEATURE_COMINTEROP) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition was always false. |
||
// Make sure the finalizer thread is set to MTA to avoid hitting | ||
// DevDiv Bugs 180773 - [Stress Failure] AV at CoreCLR!SafeQueryInterfaceHelper | ||
GetFinalizerThread()->SetApartment(Thread::AS_InMTA); | ||
#endif // FEATURE_COMINTEROP_APARTMENT_SUPPORT && !FEATURE_COMINTEROP | ||
|
||
s_FinalizerThreadOK = GetFinalizerThread()->HasStarted(); | ||
|
||
_ASSERTE(s_FinalizerThreadOK); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not handling the case of finalizer threads.