-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Change g_fEEShutDown to be Volatile #116885
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
Conversation
g_fEEShutDown is read without locks. Make it volatile to ensure that the up-to-date value is read with Arm64 weak memory model. Cleanup g_fEEShutDown flags Fixes dotnet#106242
@@ -90,12 +90,8 @@ | |||
#include <minipal/mutex.h> | |||
|
|||
#define ShutDown_Start 0x00000001 | |||
#define ShutDown_Finalize1 0x00000002 |
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.
Debug-only bit, only used for low-value assert
Tagging subscribers to this area: @mangod9 |
#define ShutDown_Finalize2 0x00000004 | ||
#define ShutDown_Profiler 0x00000008 | ||
#define ShutDown_COM 0x00000010 | ||
#define ShutDown_SyncBlock 0x00000020 | ||
#define ShutDown_IUnknown 0x00000040 |
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.
Unused or low-value debug-only bits
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.
Pull Request Overview
This PR makes g_fEEShutDown
a volatile
variable for correct ordering on weak-memory models and cleans up obsolete shutdown flag usage throughout the VM.
- Mark
g_fEEShutDown
asVolatile<DWORD>
(except in DACCESS builds) and update its implementation. - Remove deprecated shutdown mask constants and their associated bitwise logic.
- Simplify and update conditional checks and cleanup logic that depended on the old flags.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/coreclr/vm/vars.hpp | Switched g_fEEShutDown to Volatile<DWORD> and removed profiling vars. |
src/coreclr/vm/vars.cpp | Updated GVAL_IMPL for g_fEEShutDown to use the volatile type. |
src/coreclr/vm/threads.cpp | Removed legacy if (g_fEEShutDown == 0) guard around thread termination. |
src/coreclr/vm/runtimecallablewrapper.cpp | Simplified PRECONDITION to drop shutdown-based branch. |
src/coreclr/vm/interoputil.cpp | Removed shutdown-specific sync block cleanup in CleanupSyncBlockComData . |
src/coreclr/vm/crst.h | Dropped obsolete ShutDown_* mask definitions. |
src/coreclr/vm/ceemain.cpp | Cleared out assignments to removed shutdown flags. |
src/coreclr/vm/appdomain.cpp | Updated assertion to use boolean g_fEEShutDown instead of a mask. |
src/coreclr/inc/dacvars.h | Changed DACVAR definition to DEFINE_DACVAR_VOLATILE for shutdown flag. |
Comments suppressed due to low confidence (2)
src/coreclr/vm/threads.cpp:868
- The original
if (g_fEEShutDown == 0)
guard was removed, soOnThreadTerminate
now runs unconditionally even during shutdown. This changes shutdown semantics and may invoke CLR state incorrectly; consider restoring a volatile-based check to gate termination calls.
th->SetThreadState(Thread::TS_ReportDead);
src/coreclr/vm/interoputil.cpp:1202
- The shutdown-specific call to
MinorCleanupSyncBlockComData
was removed, so COM SyncBlock data may no longer be cleaned up during shutdown. If this cleanup is still required at process exit, reintroduce the appropriate volatile-check logic.
void CleanupSyncBlockComData(InteropSyncBlockInfo* pInteropInfo)
@@ -1209,9 +1209,6 @@ void CleanupSyncBlockComData(InteropSyncBlockInfo* pInteropInfo) | |||
} | |||
CONTRACTL_END; | |||
|
|||
if ((g_fEEShutDown & ShutDown_SyncBlock) && IsAtProcessExit() ) |
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.
ShutDown_SyncBlock
was never set in release build, so this condition was always false in the shipping bits. Better to align non-release builds to do the same
@@ -865,11 +865,8 @@ void DestroyThread(Thread *th) | |||
th->UnmarkThreadForAbort(); | |||
} | |||
|
|||
if (g_fEEShutDown == 0) |
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.
Unnecessary check (also, the way it is written triggered a build error after changing g_fEEShutDown to Volatile)
@@ -151,9 +151,6 @@ GVAL_IMPL_INIT(DWORD, g_externalMethodFixupTraceActiveCount, 0); | |||
#endif // DEBUGGING_SUPPORTED | |||
|
|||
#if defined(PROFILING_SUPPORTED_DATA) || defined(PROFILING_SUPPPORTED) | |||
// Profiling support | |||
HINSTANCE g_pDebuggerDll = NULL; |
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.
Dead code that I happen to notice
GVAL_DECL(DWORD, g_fEEShutDown); | ||
#else | ||
GVAL_DECL(Volatile<DWORD>, g_fEEShutDown); |
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.
The actual fix
g_fEEShutDown is read without locks. Make it volatile to ensure that the up-to-date value is read with Arm64 weak memory model.
Cleanup g_fEEShutDown flags
Fixes #106242