diff --git a/src/coreclr/gc/env/volatile.h b/src/coreclr/gc/env/volatile.h index c15dcb1ca66448..578a9e413386ba 100644 --- a/src/coreclr/gc/env/volatile.h +++ b/src/coreclr/gc/env/volatile.h @@ -311,18 +311,16 @@ class Volatile // // Allow initialization of Volatile from a T // - inline Volatile(const T& val) + inline explicit Volatile(const T& val) { ((volatile T &)m_val) = val; } // - // Copy constructor + // Copy/Move constructor deleted // - inline Volatile(const Volatile& other) - { - ((volatile T &)m_val) = other.Load(); - } + Volatile(const Volatile& other) = delete; + Volatile(Volatile&& other) = delete; // // Loads the value of the volatile variable. See code:VolatileLoad for the semantics of this operation. @@ -386,6 +384,8 @@ class Volatile // Assignment from T // inline Volatile& operator=(T val) {Store(val); return *this;} + inline Volatile& operator=(const Volatile & val) {Store(val.Load()); return *this;} + inline Volatile& operator=(Volatile && val) = delete; // // Get the address of the volatile variable. This is dangerous, as it allows the value of the @@ -409,31 +409,7 @@ class Volatile // // Miscellaneous operators. Add more as necessary. // - inline Volatile& operator+=(T val) {Store(this->Load() + val); return *this;} - inline Volatile& operator-=(T val) {Store(this->Load() - val); return *this;} - inline Volatile& operator|=(T val) {Store(this->Load() | val); return *this;} - inline Volatile& operator&=(T val) {Store(this->Load() & val); return *this;} inline bool operator!() const { return !this->Load();} - - // - // Prefix increment - // - inline Volatile& operator++() {this->Store(this->Load()+1); return *this;} - - // - // Postfix increment - // - inline T operator++(int) {T val = this->Load(); this->Store(val+1); return val;} - - // - // Prefix decrement - // - inline Volatile& operator--() {this->Store(this->Load()-1); return *this;} - - // - // Postfix decrement - // - inline T operator--(int) {T val = this->Load(); this->Store(val-1); return val;} }; // @@ -456,19 +432,23 @@ class VolatilePtr : public Volatile

} // - // Allow assignment from the pointer type. + // Allow construction from the pointer type and from various representations of NULL; HOWEVER, note that construction must be explicit since + // these constructions do not do a volatile store. // - inline VolatilePtr(P val) : Volatile

(val) + inline explicit VolatilePtr(P val) : Volatile

(val) { } - // - // Copy constructor - // - inline VolatilePtr(const VolatilePtr& other) : Volatile

(other) + inline explicit VolatilePtr(std::nullptr_t val) : Volatile

((P)val) { } + // + // Copy/Move constructors deleted + // + VolatilePtr(const VolatilePtr& other) = delete; + VolatilePtr(VolatilePtr&& other) = delete; + // // Cast to the pointer type // @@ -477,6 +457,15 @@ class VolatilePtr : public Volatile

return (P)this->Load(); } + // + // Assignment from P + // + inline VolatilePtr& operator=(P val) {this->Store(val); return *this;} + inline VolatilePtr& operator=(const VolatilePtr& val) {this->Store(val.Load()); return *this;} + inline VolatilePtr& operator=(VolatilePtr&& val) = delete; + // nullptr is assigned via nullptr_t + inline VolatilePtr& operator=(std::nullptr_t val) {this->Store((P)val); return *this;} + // // Member access // @@ -504,5 +493,6 @@ class VolatilePtr : public Volatile

}; #define VOLATILE(T) Volatile +#define VOLATILE_INIT(val) (val) #endif //_VOLATILE_H_ diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 72e468f2896dae..5c0ab7c99448ea 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -157,7 +157,7 @@ uint8_t g_build_variant = 1; uint8_t g_build_variant = 2; #endif //BUILDENV_DEBUG -VOLATILE(int32_t) g_no_gc_lock = -1; +VOLATILE(int32_t) g_no_gc_lock VOLATILE_INIT(-1); #ifdef TRACE_GC const char * const allocation_state_str[] = { @@ -467,7 +467,7 @@ int gc_heap::gchist_index = 0; gc_mechanisms_store gc_heap::gchist[max_history_count]; #ifndef MULTIPLE_HEAPS -VOLATILE(bgc_state) gc_heap::current_bgc_state = bgc_not_in_process; +VOLATILE(bgc_state) gc_heap::current_bgc_state(bgc_not_in_process); int gc_heap::gchist_index_per_heap = 0; gc_heap::gc_history gc_heap::gchist_per_heap[max_history_count]; #endif //MULTIPLE_HEAPS @@ -2456,12 +2456,12 @@ last_recorded_gc_info gc_heap::last_full_blocking_gc_info; uint64_t gc_heap::last_alloc_reset_suspended_end_time = 0; size_t gc_heap::max_peak_heap_size = 0; -VOLATILE(size_t) gc_heap::llc_size = 0; +VOLATILE(size_t) gc_heap::llc_size(0); #ifdef BACKGROUND_GC last_recorded_gc_info gc_heap::last_bgc_info[2]; -VOLATILE(bool) gc_heap::is_last_recorded_bgc = false; -VOLATILE(int) gc_heap::last_bgc_info_index = 0; +VOLATILE(bool) gc_heap::is_last_recorded_bgc(false); +VOLATILE(int) gc_heap::last_bgc_info_index(0); #endif //BACKGROUND_GC #ifdef DYNAMIC_HEAP_COUNT @@ -2473,7 +2473,7 @@ size_t gc_heap::bgc_th_count_created = 0; size_t gc_heap::bgc_th_count_created_th_existed = 0; size_t gc_heap::bgc_th_count_creation_failed = 0; size_t gc_heap::bgc_init_gc_index = 0; -VOLATILE(short) gc_heap::bgc_init_n_heaps = 0; +VOLATILE(short) gc_heap::bgc_init_n_heaps(0); size_t gc_heap::hc_change_cancelled_count_bgc = 0; #endif //BACKGROUND_GC #endif //DYNAMIC_HEAP_COUNT @@ -2556,9 +2556,9 @@ BOOL gc_heap::do_concurrent_p = FALSE; size_t gc_heap::ephemeral_fgc_counts[max_generation]; -VOLATILE(c_gc_state) gc_heap::current_c_gc_state = c_gc_state_free; +VOLATILE(c_gc_state) gc_heap::current_c_gc_state(c_gc_state_free); -VOLATILE(BOOL) gc_heap::gc_background_running = FALSE; +VOLATILE(BOOL) gc_heap::gc_background_running(FALSE); #endif //BACKGROUND_GC #ifdef USE_REGIONS @@ -3010,7 +3010,7 @@ GCSpinLock gc_heap::more_space_lock_soh; GCSpinLock gc_heap::more_space_lock_uoh; #ifdef BACKGROUND_GC -VOLATILE(int32_t) gc_heap::uoh_alloc_thread_count = 0; +VOLATILE(int32_t) gc_heap::uoh_alloc_thread_count(0); #endif //BACKGROUND_GC #ifdef SYNCHRONIZATION_STATS @@ -8127,7 +8127,7 @@ void gc_heap::fix_allocation_context_heaps (gc_alloc_context* gc_context, void*) alloc_hp_num %= gc_heap::n_heaps; acontext->set_alloc_heap (GCHeap::GetHeap (alloc_hp_num)); gc_heap* hp = acontext->get_alloc_heap ()->pGenGCHeap; - hp->alloc_context_count++; + hp->alloc_context_count = hp->alloc_context_count + 1; } } @@ -19221,7 +19221,7 @@ void gc_heap::balance_heaps (alloc_context* acontext) acontext->set_home_heap (GCHeap::GetHeap (home_hp_num)); gc_heap* hp = acontext->get_home_heap ()->pGenGCHeap; acontext->set_alloc_heap (acontext->get_home_heap ()); - hp->alloc_context_count++; + hp->alloc_context_count = hp->alloc_context_count + 1; #ifdef HEAP_BALANCE_INSTRUMENTATION uint16_t ideal_proc_no = 0; @@ -19474,8 +19474,16 @@ void gc_heap::balance_heaps (alloc_context* acontext) { final_alloc_hp_num = max_hp->heap_number; - org_hp->alloc_context_count--; - max_hp->alloc_context_count++; + // update the alloc_context_count for the original and new heaps. + // NOTE: at this time the alloc_context_count for these heaps could have changed due to racing threads, + // but we will update the counts based on what we observed, without trying to re-check or + // synchronize, as this is just a heuristic to improve our balancing, and doesn't need to + // be perfectly accurate. + // + // This has been changed from a increment/decrement operators to emphasize that these are not + // atomic changes, so alloc_context_count may be inaccurate. + org_hp->alloc_context_count = org_hp->alloc_context_count - 1; + max_hp->alloc_context_count = max_hp->alloc_context_count + 1; acontext->set_alloc_heap (GCHeap::GetHeap (final_alloc_hp_num)); if (!gc_thread_no_affinitize_p) @@ -21679,9 +21687,13 @@ int gc_heap::generation_to_condemn (int n_initial, BOOL* elevation_requested_p, BOOL check_only_p) { - gc_mechanisms temp_settings = settings; + gc_mechanisms temp_settings; gen_to_condemn_tuning temp_condemn_reasons; gc_mechanisms* local_settings = (check_only_p ? &temp_settings : &settings); + if (check_only_p) + { + temp_settings = settings; + } gen_to_condemn_tuning* local_condemn_reasons = (check_only_p ? &temp_condemn_reasons : &gen_to_condemn_reasons); if (!check_only_p) { @@ -24237,7 +24249,7 @@ void gc_heap::pm_full_gc_init_or_clear() // Although arguably we should just turn off PM then... //assert (settings.entry_memory_load >= high_memory_load_th); assert (settings.entry_memory_load > 0); - settings.gc_index += 1; + settings.gc_index = settings.gc_index + 1; do_pre_gc(); } } @@ -29494,8 +29506,8 @@ void gc_heap::process_mark_overflow_internal (int condemned_gen_number, // achieved via two shared booleans (defined below). These both act as latches that are transitioned only from // false -> true by unsynchronized code. They are only read or reset to false by a single thread under the // protection of a join. -static VOLATILE(BOOL) s_fUnpromotedHandles = FALSE; -static VOLATILE(BOOL) s_fUnscannedPromotions = FALSE; +static VOLATILE(BOOL) s_fUnpromotedHandles(FALSE); +static VOLATILE(BOOL) s_fUnscannedPromotions(FALSE); static VOLATILE(BOOL) s_fScanRequired; void gc_heap::scan_dependent_handles (int condemned_gen_number, ScanContext *sc, BOOL initial_scan_p) { @@ -47849,14 +47861,14 @@ void gc_heap::descr_generations (const char* msg) //----------------------------------------------------------------------------- //Static member variables. -VOLATILE(BOOL) GCHeap::GcInProgress = FALSE; +VOLATILE(BOOL) GCHeap::GcInProgress(FALSE); GCEvent *GCHeap::WaitForGCEvent = NULL; unsigned GCHeap::GcCondemnedGeneration = 0; size_t GCHeap::totalSurvivedSize = 0; #ifdef FEATURE_PREMORTEM_FINALIZATION CFinalize* GCHeap::m_Finalize = 0; BOOL GCHeap::GcCollectClasses = FALSE; -VOLATILE(int32_t) GCHeap::m_GCFLock = 0; +VOLATILE(int32_t) GCHeap::m_GCFLock(0); #ifndef FEATURE_NATIVEAOT // NativeAOT forces relocation a different way #ifdef STRESS_HEAP diff --git a/src/coreclr/gc/gccommon.cpp b/src/coreclr/gc/gccommon.cpp index 304ee55636b756..8fe52945c9d224 100644 --- a/src/coreclr/gc/gccommon.cpp +++ b/src/coreclr/gc/gccommon.cpp @@ -36,7 +36,7 @@ uint8_t* g_shadow_lowest_address = NULL; uint32_t* g_gc_card_table; -VOLATILE(int32_t) g_fSuspensionPending = 0; +VOLATILE(int32_t) g_fSuspensionPending VOLATILE_INIT(0); #ifdef FEATURE_MANUALLY_MANAGED_CARD_BUNDLES uint32_t* g_gc_card_bundle_table; diff --git a/src/coreclr/gc/gceventstatus.cpp b/src/coreclr/gc/gceventstatus.cpp index 17f2b56019aeed..c57b3f83596ac0 100644 --- a/src/coreclr/gc/gceventstatus.cpp +++ b/src/coreclr/gc/gceventstatus.cpp @@ -4,5 +4,5 @@ #include "common.h" #include "gceventstatus.h" -Volatile GCEventStatus::enabledLevels[2] = {GCEventLevel_None, GCEventLevel_None}; -Volatile GCEventStatus::enabledKeywords[2] = {GCEventKeyword_None, GCEventKeyword_None}; +Volatile GCEventStatus::enabledLevels[2] = {Volatile(GCEventLevel_None), Volatile(GCEventLevel_None)}; +Volatile GCEventStatus::enabledKeywords[2] = {Volatile(GCEventKeyword_None), Volatile(GCEventKeyword_None)}; \ No newline at end of file diff --git a/src/coreclr/gc/gcpriv.h b/src/coreclr/gc/gcpriv.h index ef329bc882bc07..80074a5759ce5f 100644 --- a/src/coreclr/gc/gcpriv.h +++ b/src/coreclr/gc/gcpriv.h @@ -668,6 +668,12 @@ class gc_mechanisms BOOL stress_induced; #endif // STRESS_HEAP + gc_mechanisms() = default; + gc_mechanisms(const gc_mechanisms& other) + { + *this = other; + } + // These are opportunistically set uint32_t entry_memory_load; uint64_t entry_available_physical_mem; diff --git a/src/coreclr/gc/gcscan.cpp b/src/coreclr/gc/gcscan.cpp index 9a2c73e2c3caa7..981d004c987f1d 100644 --- a/src/coreclr/gc/gcscan.cpp +++ b/src/coreclr/gc/gcscan.cpp @@ -18,7 +18,7 @@ #include "gc.h" #include "objecthandle.h" -VOLATILE(int32_t) GCScan::m_GcStructuresInvalidCnt = 1; +VOLATILE(int32_t) GCScan::m_GcStructuresInvalidCnt VOLATILE_INIT(1); bool GCScan::GetGcRuntimeStructuresValid () { diff --git a/src/coreclr/gc/objecthandle.cpp b/src/coreclr/gc/objecthandle.cpp index af7805107e5909..eaa2d212db5d6f 100644 --- a/src/coreclr/gc/objecthandle.cpp +++ b/src/coreclr/gc/objecthandle.cpp @@ -1680,7 +1680,7 @@ void Ref_CheckAlive(uint32_t condemned, uint32_t maxgen, ScanContext *sc) #endif } -static VOLATILE(int32_t) uCount = 0; +static VOLATILE(int32_t) uCount VOLATILE_INIT(0); // NOTE: Please: if you update this function, update the very similar profiling function immediately below!!! void Ref_UpdatePointers(uint32_t condemned, uint32_t maxgen, ScanContext* sc, Ref_promote_func* fn) diff --git a/src/coreclr/inc/daccess.h b/src/coreclr/inc/daccess.h index 9870093d1bca57..146d32170a61eb 100644 --- a/src/coreclr/inc/daccess.h +++ b/src/coreclr/inc/daccess.h @@ -2230,7 +2230,7 @@ public: name(int dummy) : base(dummy) {} #define VOLATILE_SVAL_IMPL(type, cls, var) \ Volatile cls::var #define VOLATILE_SVAL_IMPL_INIT(type, cls, var, init) \ - Volatile cls::var = init + Volatile cls::var(init) #define SVAL_IMPL_NS(type, ns, cls, var) \ type cls::var #define SVAL_IMPL_NS_INIT(type, ns, cls, var, init) \ diff --git a/src/coreclr/inc/profilepriv.inl b/src/coreclr/inc/profilepriv.inl index 8d92fbd10a1fe0..5998f9a7b7649c 100644 --- a/src/coreclr/inc/profilepriv.inl +++ b/src/coreclr/inc/profilepriv.inl @@ -76,7 +76,7 @@ inline void ProfilerInfo::ResetPerSessionStatus() { LIMITED_METHOD_CONTRACT; - pProfInterface = NULL; + pProfInterface = nullptr; eventMask.SetEventMask(COR_PRF_MONITOR_NONE); eventMask.SetEventMaskHigh(COR_PRF_HIGH_MONITOR_NONE); } diff --git a/src/coreclr/inc/volatile.h b/src/coreclr/inc/volatile.h index 90fd1a766cb29a..02ebc4774ec28a 100644 --- a/src/coreclr/inc/volatile.h +++ b/src/coreclr/inc/volatile.h @@ -363,7 +363,7 @@ class Volatile // // Allow initialization of Volatile from a T // - inline Volatile(const T& val) + inline explicit Volatile(const T& val) { STATIC_CONTRACT_SUPPORTS_DAC; ((volatile T &)m_val) = val; @@ -372,11 +372,8 @@ class Volatile // // Copy constructor // - inline Volatile(const Volatile& other) - { - STATIC_CONTRACT_SUPPORTS_DAC; - ((volatile T &)m_val) = other.Load(); - } + inline Volatile(const Volatile& other) = delete; + inline Volatile(Volatile&& other) = delete; // // Loads the value of the volatile variable. See code:VolatileLoad for the semantics of this operation. @@ -445,6 +442,8 @@ class Volatile // Assignment from T // inline Volatile& operator=(T val) {Store(val); return *this;} + inline Volatile& operator=(const Volatile& val) {Store(val.Load()); return *this;} + inline Volatile& operator=(Volatile&& val) = delete; // // Get the address of the volatile variable. This is dangerous, as it allows the value of the @@ -468,31 +467,7 @@ class Volatile // // Miscellaneous operators. Add more as necessary. // - inline Volatile& operator+=(T val) {Store(this->Load() + val); return *this;} - inline Volatile& operator-=(T val) {Store(this->Load() - val); return *this;} - inline Volatile& operator|=(T val) {Store(this->Load() | val); return *this;} - inline Volatile& operator&=(T val) {Store(this->Load() & val); return *this;} inline bool operator!() const { STATIC_CONTRACT_SUPPORTS_DAC; return !this->Load();} - - // - // Prefix increment - // - inline Volatile& operator++() {this->Store(this->Load()+1); return *this;} - - // - // Postfix increment - // - inline T operator++(int) {T val = this->Load(); this->Store(val+1); return val;} - - // - // Prefix decrement - // - inline Volatile& operator--() {this->Store(this->Load()-1); return *this;} - - // - // Postfix decrement - // - inline T operator--(int) {T val = this->Load(); this->Store(val-1); return val;} }; // @@ -516,21 +491,22 @@ class VolatilePtr : public Volatile

} // - // Allow assignment from the pointer type. + // Allow construction from the pointer type and from various representations of NULL; HOWEVER, note that construction must be explicit since + // these constructions do not do a volatile store. // - inline VolatilePtr(P val) : Volatile

(val) + inline explicit VolatilePtr(P val) : Volatile

(val) { STATIC_CONTRACT_SUPPORTS_DAC; } - // - // Copy constructor - // - inline VolatilePtr(const VolatilePtr& other) : Volatile

(other) + inline explicit VolatilePtr(std::nullptr_t val) : Volatile

((P)val) { STATIC_CONTRACT_SUPPORTS_DAC; } + VolatilePtr(const VolatilePtr& other) = delete; + VolatilePtr(VolatilePtr&& other) = delete; + // // Cast to the pointer type // @@ -540,6 +516,15 @@ class VolatilePtr : public Volatile

return (P)this->Load(); } + // + // Assignment from P + // + inline VolatilePtr& operator=(P val) {this->Store(val); return *this;} + inline VolatilePtr& operator=(const VolatilePtr& val) {this->Store(val.Load()); return *this;} + inline VolatilePtr& operator=(VolatilePtr&& val) = delete; + // nullptr is assigned via nullptr_t + inline VolatilePtr& operator=(std::nullptr_t val) {this->Store((P)val); return *this;} + // // Member access // @@ -594,8 +579,10 @@ class VolatilePtr : public Volatile

// Disable use of Volatile for GC/HandleTable code except on platforms where it's absolutely necessary. #if defined(_MSC_VER) && !defined(HOST_ARM) && !defined(HOST_ARM64) #define VOLATILE(T) T RAW_KEYWORD(volatile) +#define VOLATILE_INIT(val) = val #else #define VOLATILE(T) Volatile +#define VOLATILE_INIT(val) (val) #endif #endif // DACCESS_COMPILE diff --git a/src/coreclr/interop/trackerobjectmanager.cpp b/src/coreclr/interop/trackerobjectmanager.cpp index cc178d4187179b..74469b0737401b 100644 --- a/src/coreclr/interop/trackerobjectmanager.cpp +++ b/src/coreclr/interop/trackerobjectmanager.cpp @@ -13,7 +13,7 @@ namespace const GUID IID_IFindReferenceTargetsCallback = { 0x04b3486c, 0x4687, 0x4229, { 0x8d, 0x14, 0x50, 0x5a, 0xb5, 0x84, 0xdd, 0x88} }; VolatilePtr s_TrackerManager; // The one and only Tracker Manager instance - Volatile s_HasTrackingStarted = false; + Volatile s_HasTrackingStarted(false); // Indicates if walking the external objects is needed. // (i.e. Have any IReferenceTracker instances been found?) diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index 01e8690d49f075..15980a5aecda2d 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -54,14 +54,14 @@ inline bool getInlinePInvokeCheckEnabled() // Enforce float narrowing for buggy compilers (notably preWhidbey VC) inline float forceCastToFloat(double d) { - Volatile f = (float)d; + Volatile f((float)d); return f; } // Enforce UInt32 narrowing for buggy compilers (notably Whidbey Beta 2 LKG) inline UINT32 forceCastToUInt32(double d) { - Volatile u = (UINT32)d; + Volatile u((UINT32)d); return u; } diff --git a/src/coreclr/nativeaot/Runtime/interoplibinterface_java.cpp b/src/coreclr/nativeaot/Runtime/interoplibinterface_java.cpp index 1fcda8be6089d8..0e967a205c8b6a 100644 --- a/src/coreclr/nativeaot/Runtime/interoplibinterface_java.cpp +++ b/src/coreclr/nativeaot/Runtime/interoplibinterface_java.cpp @@ -23,7 +23,7 @@ namespace { volatile CrossreferenceHandleCallback g_MarkCrossReferences = NULL; - Volatile g_GCBridgeActive = false; + Volatile g_GCBridgeActive(false); CLREventStatic g_bridgeFinished; void ReleaseGCBridgeArgumentsWorker( diff --git a/src/coreclr/pal/src/debug/debug.cpp b/src/coreclr/pal/src/debug/debug.cpp index 4cf61fee790b00..b953f74b952b8e 100644 --- a/src/coreclr/pal/src/debug/debug.cpp +++ b/src/coreclr/pal/src/debug/debug.cpp @@ -273,7 +273,7 @@ int run_debug_command (const char *command) { int pid; - Volatile spin = 1; + Volatile spin(1); if (!command) { return 1; diff --git a/src/coreclr/pal/src/init/pal.cpp b/src/coreclr/pal/src/init/pal.cpp index a1d5006a220050..60303e1c301407 100644 --- a/src/coreclr/pal/src/init/pal.cpp +++ b/src/coreclr/pal/src/init/pal.cpp @@ -96,9 +96,9 @@ extern bool g_running_in_exe; bool g_arm64_atomics_present = false; #endif -Volatile init_count = 0; -Volatile shutdown_intent = 0; -Volatile g_coreclrInitialized = 0; +Volatile init_count(0); +Volatile shutdown_intent(0); +Volatile g_coreclrInitialized(0); static BOOL g_fThreadDataAvailable = FALSE; static pthread_mutex_t init_critsec_mutex = PTHREAD_MUTEX_INITIALIZER; diff --git a/src/coreclr/pal/src/misc/dbgmsg.cpp b/src/coreclr/pal/src/misc/dbgmsg.cpp index c9451c99ffbc37..f7ec41e5bae5f9 100644 --- a/src/coreclr/pal/src/misc/dbgmsg.cpp +++ b/src/coreclr/pal/src/misc/dbgmsg.cpp @@ -63,7 +63,7 @@ BOOL g_Dbg_asserts_enabled; FILE *output_file = NULL; /* master switch for debug channel enablement, to be modified by debugger */ -Volatile dbg_master_switch = TRUE; +Volatile dbg_master_switch(TRUE); static const char *dbg_channel_names[]= diff --git a/src/coreclr/pal/src/synchmgr/synchmanager.cpp b/src/coreclr/pal/src/synchmgr/synchmanager.cpp index b6c44754210805..8f82a8848b1ac4 100644 --- a/src/coreclr/pal/src/synchmgr/synchmanager.cpp +++ b/src/coreclr/pal/src/synchmgr/synchmanager.cpp @@ -140,7 +140,7 @@ namespace CorUnix IPalSynchronizationManager * g_pSynchronizationManager = NULL; CPalSynchronizationManager * CPalSynchronizationManager::s_pObjSynchMgr = NULL; - Volatile CPalSynchronizationManager::s_lInitStatus = SynchMgrStatusIdle; + Volatile CPalSynchronizationManager::s_lInitStatus((LONG)SynchMgrStatusIdle); minipal_mutex CPalSynchronizationManager::s_csSynchProcessLock; minipal_mutex CPalSynchronizationManager::s_csMonitoredProcessesLock; diff --git a/src/coreclr/pal/src/thread/process.cpp b/src/coreclr/pal/src/thread/process.cpp index 42897270a9456f..4b6868ac43f3f3 100644 --- a/src/coreclr/pal/src/thread/process.cpp +++ b/src/coreclr/pal/src/thread/process.cpp @@ -158,10 +158,10 @@ LPWSTR g_lpwstrCmdLine = NULL; LPWSTR g_lpwstrAppDir = NULL; // Thread ID of thread that has started the ExitProcess process -Volatile terminator = 0; +Volatile terminator(0); // Id of thread generating a core dump -Volatile g_crashingThreadId = 0; +Volatile g_crashingThreadId(0); // Process and session ID of this process. DWORD gPID = (DWORD) -1; @@ -190,10 +190,10 @@ int gApplicationGroupIdLength = 0; static_assert(CLR_SEM_MAX_NAMELEN <= MAX_PATH); // Function to call during PAL/process shutdown/abort -Volatile g_shutdownCallback = nullptr; +Volatile g_shutdownCallback(nullptr); // Function to call instead of exec'ing the createdump binary. Used by single-file and native AOT hosts. -Volatile g_createdumpCallback = nullptr; +Volatile g_createdumpCallback(nullptr); // Crash dump generating program arguments. Initialized in PROCAbortInitialize(). #define MAX_ARGV_ENTRIES 32 diff --git a/src/coreclr/utilcode/debug.cpp b/src/coreclr/utilcode/debug.cpp index 02fe16a912d5dd..daf5a691e587a9 100644 --- a/src/coreclr/utilcode/debug.cpp +++ b/src/coreclr/utilcode/debug.cpp @@ -30,7 +30,7 @@ void CreateCrashDumpIfEnabled(bool stackoverflow = false); #endif // Global state counter to implement SUPPRESS_ALLOCATION_ASSERTS_IN_THIS_SCOPE. -Volatile g_DbgSuppressAllocationAsserts = 0; +Volatile g_DbgSuppressAllocationAsserts(0); static void GetExecutableFileNameUtf8(SString& value) { diff --git a/src/coreclr/utilcode/stresslog.cpp b/src/coreclr/utilcode/stresslog.cpp index b1b415c0dde833..f7e1794f11c952 100644 --- a/src/coreclr/utilcode/stresslog.cpp +++ b/src/coreclr/utilcode/stresslog.cpp @@ -131,7 +131,7 @@ uint64_t getTickFrequency() #ifdef STRESS_LOG -StressLog StressLog::theLog = { 0, 0, 0, 0, 0, 0, TLS_OUT_OF_INDEXES, 0, 0, 0 }; +StressLog StressLog::theLog = { 0, 0, 0, 0, Volatile(0), Volatile(0), TLS_OUT_OF_INDEXES, Volatile(0), 0, 0 }; const static uint64_t RECYCLE_AGE = 0x40000000L; // after a billion cycles, we can discard old threads /*********************************************************************************/ diff --git a/src/coreclr/utilcode/util.cpp b/src/coreclr/utilcode/util.cpp index 4efc5bd767c77c..3e079ffe7c74ba 100644 --- a/src/coreclr/utilcode/util.cpp +++ b/src/coreclr/utilcode/util.cpp @@ -1094,7 +1094,7 @@ uint32_t GetOsPageSizeUncached() namespace { - Volatile g_pageSize = 0; + Volatile g_pageSize(0); } uint32_t GetOsPageSize() diff --git a/src/coreclr/utilcode/utsem.cpp b/src/coreclr/utilcode/utsem.cpp index c916d0509bdec8..1661086eab62cf 100644 --- a/src/coreclr/utilcode/utsem.cpp +++ b/src/coreclr/utilcode/utsem.cpp @@ -68,7 +68,7 @@ BOOL __SwitchToThread(DWORD dwSleepMSec, DWORD dwSwitchCount) return SwitchToThread(); } -Volatile g_fInitializedGlobalSystemInfo = FALSE; +Volatile g_fInitializedGlobalSystemInfo(FALSE); // Global System Information SYSTEM_INFO g_SystemInfo; diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index c752df35852da2..61de0a5dd30dab 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -1636,7 +1636,7 @@ AppDomain::AppDomain() #endif // FEATURE_COMWRAPPERS , m_ForceTrivialWaitOperations{false} #ifdef FEATURE_TYPEEQUIVALENCE - , m_pTypeEquivalenceTable{NULL} + , m_pTypeEquivalenceTable{nullptr} #endif // FEATURE_TYPEEQUIVALENCE { // initialize fields so the appdomain can be safely destructed diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index 1860164c62e19a..7f76798c811dcc 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -171,6 +171,7 @@ void Module::DoInit(AllocMemTracker *pamTracker, LPCWSTR szName) #endif } +#endif //!DACCESS_COMPILE // Set the given bit on m_dwTransientFlags. Return true if we won the race to set the bit. BOOL Module::SetTransientFlagInterlocked(DWORD dwFlag) @@ -187,6 +188,21 @@ BOOL Module::SetTransientFlagInterlocked(DWORD dwFlag) } } +void Module::SetTransientFlagInterlockedWithMask(DWORD dwFlag, DWORD dwMask) +{ + LIMITED_METHOD_CONTRACT; + + for (;;) + { + DWORD dwTransientFlags = m_dwTransientFlags; + DWORD dwNewTransientFlags = (dwTransientFlags & ~dwMask) | dwFlag; + if ((DWORD)InterlockedCompareExchange((LONG*)&m_dwTransientFlags, dwNewTransientFlags, dwTransientFlags) == dwTransientFlags) + return; + } +} + +#ifndef DACCESS_COMPILE + #if defined(PROFILING_SUPPORTED) || defined(FEATURE_METADATA_UPDATER) void Module::UpdateNewlyAddedTypes() { @@ -424,7 +440,7 @@ void Module::Initialize(AllocMemTracker *pamTracker, LPCWSTR szName) _ASSERTE(m_path != NULL); m_baseAddress = m_pPEAssembly->HasLoadedPEImage() ? m_pPEAssembly->GetLoadedLayout()->GetBase() : NULL; if (m_pPEAssembly->IsReflectionEmit()) - m_dwTransientFlags |= IS_REFLECTION_EMIT; + m_dwTransientFlags = m_dwTransientFlags | IS_REFLECTION_EMIT; m_Crst.Init(CrstModule); m_LookupTableCrst.Init(CrstModuleLookupTable, CrstFlags(CRST_UNSAFE_ANYMODE | CRST_DEBUGGER_THREAD)); @@ -432,17 +448,17 @@ void Module::Initialize(AllocMemTracker *pamTracker, LPCWSTR szName) m_ISymUnmanagedReaderCrst.Init(CrstISymUnmanagedReader, CRST_DEBUGGER_THREAD); AllocateMaps(); - m_dwTransientFlags &= ~((DWORD)CLASSES_FREED); // Set flag indicating LookupMaps are now in a consistent and destructable state + m_dwTransientFlags = m_dwTransientFlags & ~((DWORD)CLASSES_FREED); // Set flag indicating LookupMaps are now in a consistent and destructable state if (IsSystem()) - m_dwPersistedFlags |= SKIP_TYPE_VALIDATION; // Skip type validation on System + m_dwPersistedFlags = m_dwPersistedFlags | SKIP_TYPE_VALIDATION; // Skip type validation on System #ifdef FEATURE_READYTORUN m_pNativeImage = NULL; if ((m_pReadyToRunInfo = ReadyToRunInfo::Initialize(this, pamTracker)) != NULL) { if (m_pReadyToRunInfo->SkipTypeValidation()) - m_dwPersistedFlags |= SKIP_TYPE_VALIDATION; // Skip type validation on System + m_dwPersistedFlags = m_dwPersistedFlags | SKIP_TYPE_VALIDATION; // Skip type validation on System m_pNativeImage = m_pReadyToRunInfo->GetNativeImage(); if (m_pNativeImage != NULL) @@ -489,11 +505,11 @@ void Module::Initialize(AllocMemTracker *pamTracker, LPCWSTR szName) // set profiler related JIT flags if (CORProfilerDisableInlining()) { - m_dwTransientFlags |= PROF_DISABLE_INLINING; + m_dwTransientFlags = m_dwTransientFlags | PROF_DISABLE_INLINING; } if (CORProfilerDisableOptimizations()) { - m_dwTransientFlags |= PROF_DISABLE_OPTIMIZATIONS; + m_dwTransientFlags = m_dwTransientFlags | PROF_DISABLE_OPTIMIZATIONS; } m_pJitInlinerTrackingMap = NULL; @@ -517,8 +533,7 @@ void Module::SetDebuggerInfoBits(DebuggerAssemblyControlFlags newBits) _ASSERTE(((newBits << DEBUGGER_INFO_SHIFT_PRIV) & ~DEBUGGER_INFO_MASK_PRIV) == 0); - m_dwTransientFlags &= ~DEBUGGER_INFO_MASK_PRIV; - m_dwTransientFlags |= (newBits << DEBUGGER_INFO_SHIFT_PRIV); + SetTransientFlagInterlockedWithMask(newBits << DEBUGGER_INFO_SHIFT_PRIV, DEBUGGER_INFO_MASK_PRIV); #ifdef DEBUGGING_SUPPORTED if (IsEditAndContinueCapable()) diff --git a/src/coreclr/vm/ceeload.h b/src/coreclr/vm/ceeload.h index b851f2d3275a52..06ee5f1b6e0125 100644 --- a/src/coreclr/vm/ceeload.h +++ b/src/coreclr/vm/ceeload.h @@ -823,6 +823,9 @@ class Module : public ModuleBase // Set the given bit on m_dwTransientFlags. Return true if we won the race to set the bit. BOOL SetTransientFlagInterlocked(DWORD dwFlag); + // Set bits on the m_dwTransientFlags according to the given mask. + void SetTransientFlagInterlockedWithMask(DWORD dwFlag, DWORD dwMask); + // Cannoically-cased hashtable of the available class names for // case insensitive lookup. Contains pointers into // m_pAvailableClasses. @@ -971,7 +974,7 @@ class Module : public ModuleBase SUPPORTS_DAC; _ASSERTE(IsEditAndContinueCapable()); LOG((LF_ENC, LL_INFO100, "M:EnableEditAndContinue: this:%p, %s\n", this, GetDebugName())); - m_dwTransientFlags |= IS_EDIT_AND_CONTINUE; + SetTransientFlagInterlocked(IS_EDIT_AND_CONTINUE); } public: @@ -1604,7 +1607,7 @@ class Module : public ModuleBase void SetIsRuntimeWrapExceptionsCached_ForReflectionEmitModules() { LIMITED_METHOD_CONTRACT; - m_dwPersistedFlags |= COMPUTED_WRAP_EXCEPTIONS; + m_dwPersistedFlags = m_dwPersistedFlags | COMPUTED_WRAP_EXCEPTIONS; } public: diff --git a/src/coreclr/vm/ceemain.cpp b/src/coreclr/vm/ceemain.cpp index 372222dce0ffe7..9cefe6b4070018 100644 --- a/src/coreclr/vm/ceemain.cpp +++ b/src/coreclr/vm/ceemain.cpp @@ -235,7 +235,7 @@ HRESULT g_EEStartupStatus = S_OK; // Flag indicating if the EE has been started. This is set prior to initializing the default AppDomain, and so does not indicate that // the EE is fully able to execute arbitrary managed code. To ensure the EE is fully started, call EnsureEEStarted rather than just // checking this flag. -Volatile g_fEEStarted = FALSE; +Volatile g_fEEStarted(FALSE); // The OS thread ID of the thread currently performing EE startup, or 0 if there is no such thread. DWORD g_dwStartupThreadId = 0; @@ -503,7 +503,7 @@ void InitGSCookie() } } -Volatile g_bIsGarbageCollectorFullyInitialized = FALSE; +Volatile g_bIsGarbageCollectorFullyInitialized(FALSE); void SetGarbageCollectorFullyInitialized() { @@ -1229,7 +1229,7 @@ void STDMETHODCALLTYPE EEShutDownHelper(BOOL fIsDllUnloading) } // Indicate the EE is the shut down phase. - g_fEEShutDown |= ShutDown_Start; + InterlockedOr((LONG*)&g_fEEShutDown, ShutDown_Start); if (!IsAtProcessExit() && !g_fFastExitProcess) { @@ -1354,7 +1354,7 @@ void STDMETHODCALLTYPE EEShutDownHelper(BOOL fIsDllUnloading) // lock -- after the OS has stopped all other threads. if (fIsDllUnloading && (g_fEEShutDown & ShutDown_Phase2) == 0) { - g_fEEShutDown |= ShutDown_Phase2; + InterlockedOr((LONG*)&g_fEEShutDown, ShutDown_Phase2); if (!g_fFastExitProcess) { @@ -1588,7 +1588,7 @@ BOOL STDMETHODCALLTYPE EEDllMain( // TRUE on success, FALSE on error. { if (GCHeapUtilities::IsGCInProgress()) { - g_fEEShutDown |= ShutDown_Phase2; + InterlockedOr((LONG*)&g_fEEShutDown, ShutDown_Phase2); break; } diff --git a/src/coreclr/vm/comcallablewrapper.cpp b/src/coreclr/vm/comcallablewrapper.cpp index 1b0c6eea5a4e45..3e59a93928bc25 100644 --- a/src/coreclr/vm/comcallablewrapper.cpp +++ b/src/coreclr/vm/comcallablewrapper.cpp @@ -748,7 +748,7 @@ VOID SimpleComCallWrapper::Cleanup() if (m_pAuxData) { delete m_pAuxData; - m_pAuxData = NULL; + m_pAuxData = nullptr; } } diff --git a/src/coreclr/vm/comcallablewrapper.h b/src/coreclr/vm/comcallablewrapper.h index 6b52861b66f030..a3cbb7bd02cda3 100644 --- a/src/coreclr/vm/comcallablewrapper.h +++ b/src/coreclr/vm/comcallablewrapper.h @@ -1072,7 +1072,7 @@ struct SimpleCCWAuxData { LIMITED_METHOD_CONTRACT; - m_pDispatchExInfo = NULL; + m_pDispatchExInfo = nullptr; } ~SimpleCCWAuxData() @@ -1082,7 +1082,7 @@ struct SimpleCCWAuxData if (m_pDispatchExInfo) { delete m_pDispatchExInfo; - m_pDispatchExInfo = NULL; + m_pDispatchExInfo = nullptr; } } }; diff --git a/src/coreclr/vm/crst.cpp b/src/coreclr/vm/crst.cpp index 4825e44e744dc5..bdbf6bd5093adc 100644 --- a/src/coreclr/vm/crst.cpp +++ b/src/coreclr/vm/crst.cpp @@ -22,7 +22,7 @@ #undef __IN_CRST_CPP #ifndef DACCESS_COMPILE -Volatile g_ShutdownCrstUsageCount = 0; +Volatile g_ShutdownCrstUsageCount(0); //----------------------------------------------------------------- // Initialize critical section diff --git a/src/coreclr/vm/eehash.h b/src/coreclr/vm/eehash.h index f4e221d247faed..7f684401edc598 100644 --- a/src/coreclr/vm/eehash.h +++ b/src/coreclr/vm/eehash.h @@ -204,7 +204,7 @@ class EEHashTable : public EEHashTableBase #endif #ifndef DACCESS_COMPILE - this->m_pVolatileBucketTable = NULL; + this->m_pVolatileBucketTable = nullptr; #endif this->m_dwNumEntries = 0; this->m_bGrowing = 0; diff --git a/src/coreclr/vm/eehash.inl b/src/coreclr/vm/eehash.inl index f8e4ecb6064a1d..0069cc68687ba2 100644 --- a/src/coreclr/vm/eehash.inl +++ b/src/coreclr/vm/eehash.inl @@ -58,7 +58,7 @@ void EEHashTableBase::Destroy() delete[] (m_pVolatileBucketTable->m_pBuckets-1); - m_pVolatileBucketTable = NULL; + m_pVolatileBucketTable = nullptr; } } diff --git a/src/coreclr/vm/eventtrace.cpp b/src/coreclr/vm/eventtrace.cpp index 66a39c08a98870..0a28c88b916135 100644 --- a/src/coreclr/vm/eventtrace.cpp +++ b/src/coreclr/vm/eventtrace.cpp @@ -60,7 +60,7 @@ DOTNET_TRACE_CONTEXT MICROSOFT_WINDOWS_DOTNETRUNTIME_STRESS_PROVIDER_DOTNET_Cont #ifdef FEATURE_NATIVEAOT volatile LONGLONG ETW::GCLog::s_l64LastClientSequenceNumber = 0; #else // FEATURE_NATIVEAOT -Volatile ETW::GCLog::s_l64LastClientSequenceNumber = 0; +Volatile ETW::GCLog::s_l64LastClientSequenceNumber(0); #endif // FEATURE_NATIVEAOT #ifndef FEATURE_NATIVEAOT diff --git a/src/coreclr/vm/excep.cpp b/src/coreclr/vm/excep.cpp index 078536db9e10e6..90d8b52a189d5e 100644 --- a/src/coreclr/vm/excep.cpp +++ b/src/coreclr/vm/excep.cpp @@ -3627,7 +3627,7 @@ bool CheckThreadExceptionStateForInterception() // UNHANDLED EXCEPTION HANDLING // -static Volatile fReady = 0; +static Volatile fReady(0); static SpinLock initLock; //****************************************************************************** diff --git a/src/coreclr/vm/finalizerthread.cpp b/src/coreclr/vm/finalizerthread.cpp index 38ccdae6713a19..24cfcdee5b7499 100644 --- a/src/coreclr/vm/finalizerthread.cpp +++ b/src/coreclr/vm/finalizerthread.cpp @@ -24,7 +24,7 @@ BOOL FinalizerThread::fQuitFinalizer = FALSE; extern bool s_forcedGCInProgress; int64_t FinalizerThread::LastHeapDumpTime = 0; -Volatile g_TriggerHeapDump = FALSE; +Volatile g_TriggerHeapDump(FALSE); #endif // __linux__ CLREvent * FinalizerThread::hEventFinalizer = NULL; @@ -85,7 +85,7 @@ namespace // This is a linked list of the LCGMethodResolvers that represent DynamicMethodDescs // waiting to be destroyed. The resolvers are used since they can be chained together // to avoid allocations when destroying multiple DynamicMethodDescs. - VolatilePtr s_delayDestroyDynamicMethod = nullptr; + VolatilePtr s_delayDestroyDynamicMethod(nullptr); bool HasDelayedDynamicMethod() { diff --git a/src/coreclr/vm/hosting.cpp b/src/coreclr/vm/hosting.cpp index d3b40449c66ca7..3af4fe4d648e0e 100644 --- a/src/coreclr/vm/hosting.cpp +++ b/src/coreclr/vm/hosting.cpp @@ -85,9 +85,9 @@ SIZE_T ClrVirtualQuery(LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, SI } #if defined(_DEBUG) && !defined(TARGET_UNIX) -static VolatilePtr s_pStartOfUEFSection = NULL; -static VolatilePtr s_pEndOfUEFSectionBoundary = NULL; -static Volatile s_dwProtection = 0; +static VolatilePtr s_pStartOfUEFSection(nullptr); +static VolatilePtr s_pEndOfUEFSectionBoundary(nullptr); +static Volatile s_dwProtection(0); #endif // _DEBUG && !TARGET_UNIX BOOL ClrVirtualProtect(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWORD lpflOldProtect) diff --git a/src/coreclr/vm/interoplibinterface_java.cpp b/src/coreclr/vm/interoplibinterface_java.cpp index e4f1f07f11997b..ee8951958ff268 100644 --- a/src/coreclr/vm/interoplibinterface_java.cpp +++ b/src/coreclr/vm/interoplibinterface_java.cpp @@ -17,7 +17,7 @@ namespace { CrossreferenceHandleCallback g_MarkCrossReferences = NULL; - Volatile g_GCBridgeActive = false; + Volatile g_GCBridgeActive(false); CLREvent* g_bridgeFinished = nullptr; void ReleaseGCBridgeArgumentsWorker( diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index d93d1d588fcbf3..3f365d5d61f430 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -84,9 +84,9 @@ GARY_IMPL(VMHELPDEF, hlpDynamicFuncTable, DYNAMIC_CORINFO_HELP_COUNT); #else // DACCESS_COMPILE -Volatile g_cbILJitted = 0; -Volatile g_cMethodsJitted = 0; -Volatile g_c100nsTicksInJit = 0; +Volatile g_cbILJitted(0); +Volatile g_cMethodsJitted(0); +Volatile g_c100nsTicksInJit(0); thread_local int64_t t_cbILJittedForThread = 0; thread_local int64_t t_cMethodsJittedForThread = 0; thread_local int64_t t_c100nsTicksInJitForThread = 0; diff --git a/src/coreclr/vm/loaderallocator.cpp b/src/coreclr/vm/loaderallocator.cpp index c2f5c813a305af..6c2f0faba74088 100644 --- a/src/coreclr/vm/loaderallocator.cpp +++ b/src/coreclr/vm/loaderallocator.cpp @@ -84,7 +84,7 @@ LoaderAllocator::LoaderAllocator(bool collectible) : m_pMarshalingData = NULL; #ifdef FEATURE_COMINTEROP - m_pComCallWrapperCache = NULL; + m_pComCallWrapperCache = nullptr; #endif // FEATURE_COMINTEROP #ifndef FEATURE_PORTABLE_ENTRYPOINTS @@ -698,7 +698,7 @@ BOOL LoaderAllocator::Destroy(QCall::LoaderAllocatorHandle pLoaderAllocator) #ifdef _DEBUG else { - pLoaderAllocator->m_pComCallWrapperCache = NULL; + pLoaderAllocator->m_pComCallWrapperCache = nullptr; LOG((LF_CLASSLOADER, LL_INFO10, "LoaderAllocator::Destroy ComCallWrapperCache not released\n")); } #endif // _DEBUG diff --git a/src/coreclr/vm/loaderallocator.hpp b/src/coreclr/vm/loaderallocator.hpp index 884e5c54daec7c..83bde11e1428dc 100644 --- a/src/coreclr/vm/loaderallocator.hpp +++ b/src/coreclr/vm/loaderallocator.hpp @@ -863,7 +863,7 @@ class LoaderAllocator void ResetComCallWrapperCache() { LIMITED_METHOD_CONTRACT; - m_pComCallWrapperCache = NULL; + m_pComCallWrapperCache = nullptr; } #ifndef DACCESS_COMPILE diff --git a/src/coreclr/vm/perfmap.cpp b/src/coreclr/vm/perfmap.cpp index f2cc1212595891..7015b11a1de316 100644 --- a/src/coreclr/vm/perfmap.cpp +++ b/src/coreclr/vm/perfmap.cpp @@ -27,7 +27,7 @@ #define TEMP_DIRECTORY_PATH "/data/local/tmp" #endif -Volatile PerfMap::s_enabled = false; +Volatile PerfMap::s_enabled(false); PerfMap * PerfMap::s_Current = nullptr; bool PerfMap::s_ShowOptimizationTiers = false; bool PerfMap::s_GroupStubsOfSameType = false; diff --git a/src/coreclr/vm/runtimecallablewrapper.h b/src/coreclr/vm/runtimecallablewrapper.h index f84c1133f3917b..b19f1e59178e78 100644 --- a/src/coreclr/vm/runtimecallablewrapper.h +++ b/src/coreclr/vm/runtimecallablewrapper.h @@ -596,7 +596,7 @@ inline RCW::CreationFlags operator|=(RCW::CreationFlags & lhs, RCW::CreationFlag // In order to save vtablePtr in minidumps, we put it on the stack as a volatile local // (so it's not optimized away by the compiler). Most places where we call out to COM // can absorb the cost of one stack slot and one instruction to improve debuggability. -#define RCW_VTABLEPTR(pRCW) Volatile __vtablePtr = (pRCW)->m_vtablePtr +#define RCW_VTABLEPTR(pRCW) Volatile __vtablePtr((pRCW)->m_vtablePtr) // 04 CLASS_IS_HINT 04 ITF_MARSHAL_CLASS_IS_HINT // 08 UNIQUE_OBJECT 08 CF_NeedUniqueObject diff --git a/src/coreclr/vm/syncclean.cpp b/src/coreclr/vm/syncclean.cpp index 7247529da56cdf..378388806a85b4 100644 --- a/src/coreclr/vm/syncclean.cpp +++ b/src/coreclr/vm/syncclean.cpp @@ -8,8 +8,8 @@ #include "virtualcallstub.h" #include "threadsuspend.h" -VolatilePtr SyncClean::m_HashMap = NULL; -VolatilePtr SyncClean::m_EEHashTable; +VolatilePtr SyncClean::m_HashMap(nullptr); +VolatilePtr SyncClean::m_EEHashTable(nullptr); void SyncClean::Terminate() { diff --git a/src/coreclr/vm/threads.cpp b/src/coreclr/vm/threads.cpp index 00f17de38ab91c..e10ea0b319fc2d 100644 --- a/src/coreclr/vm/threads.cpp +++ b/src/coreclr/vm/threads.cpp @@ -1201,7 +1201,7 @@ Thread::Thread() m_dwForbidSuspendThread = 0; - m_pBlockingLock = NULL; + m_pBlockingLock = nullptr; m_pRuntimeThreadLocals = nullptr; m_thAllocContextObj = 0; @@ -1336,7 +1336,7 @@ Thread::Thread() #endif // defined(GCCOVER_TOLERATE_SPURIOUS_AV) #endif // HAVE_GCCOVER - m_debuggerActivePatchSkipper = NULL; + m_debuggerActivePatchSkipper = nullptr; m_dwThreadHandleBeingUsed = 0; SetProfilerCallbacksAllowed(TRUE); @@ -6311,7 +6311,7 @@ UINT64 Thread::GetTotalCount(SIZE_T threadLocalCountOffset, UINT64 *overflowCoun } DeadlockAwareLock::DeadlockAwareLock(const char *description) - : m_pHoldingThread(NULL) + : m_pHoldingThread(nullptr) #ifdef _DEBUG , m_description(description) #endif @@ -6510,7 +6510,7 @@ void DeadlockAwareLock::LeaveLock() CONSISTENCY_CHECK(m_pHoldingThread == GetThread()); CONSISTENCY_CHECK(GetThread()->m_pBlockingLock.Load() == NULL); - m_pHoldingThread = NULL; + m_pHoldingThread = nullptr; } diff --git a/src/coreclr/vm/threads.h b/src/coreclr/vm/threads.h index f54ee613485dc6..f610499d112b59 100644 --- a/src/coreclr/vm/threads.h +++ b/src/coreclr/vm/threads.h @@ -2838,28 +2838,30 @@ class Thread { LIMITED_METHOD_CONTRACT; _ASSERTE(slot >= 0 && slot <= MAX_NOTIFICATION_PROFILERS); - return m_dwProfilerEvacuationCounters[slot]; + return m_dwProfilerEvacuationCounters[slot].Load(); } FORCEINLINE void IncProfilerEvacuationCounter(size_t slot) { + // All manipulation of the evacuation counters must be done from within the thread. A value of 0 or non-zero signals to other threads that various behavior should occur. LIMITED_METHOD_CONTRACT; _ASSERTE(slot >= 0 && slot <= MAX_NOTIFICATION_PROFILERS); #ifdef _DEBUG DWORD newValue = #endif // _DEBUG - ++m_dwProfilerEvacuationCounters[slot]; + m_dwProfilerEvacuationCounters[slot] = m_dwProfilerEvacuationCounters[slot].Load() + 1; _ASSERTE(newValue != 0U); } FORCEINLINE void DecProfilerEvacuationCounter(size_t slot) { LIMITED_METHOD_CONTRACT; + // All manipulation of the evacuation counters must be done from within the thread. A value of 0 or non-zero signals to other threads that various behavior should occur. _ASSERTE(slot >= 0 && slot <= MAX_NOTIFICATION_PROFILERS); #ifdef _DEBUG DWORD newValue = #endif // _DEBUG - --m_dwProfilerEvacuationCounters[slot]; + m_dwProfilerEvacuationCounters[slot] = m_dwProfilerEvacuationCounters[slot].Load() - 1; _ASSERTE(newValue != (DWORD)-1); } @@ -5271,7 +5273,7 @@ class DeadlockAwareLock static void ReleaseBlockingLock() { Thread *pThread = GetThread(); - pThread->m_pBlockingLock = NULL; + pThread->m_pBlockingLock = nullptr; } public: typedef StateHolder BlockingLockHolder; diff --git a/src/coreclr/vm/util.cpp b/src/coreclr/vm/util.cpp index 6e2e71f0e4a23b..f2615c7c03e735 100644 --- a/src/coreclr/vm/util.cpp +++ b/src/coreclr/vm/util.cpp @@ -1757,7 +1757,7 @@ HRESULT GetFileVersion( // S_OK or error } #endif // !TARGET_UNIX -Volatile NormalizedTimer::s_frequency = -1.0; +Volatile NormalizedTimer::s_frequency(-1.0); void FillStubCodePage(BYTE* pageBase, const void* code, SIZE_T codeSize, SIZE_T pageSize) { diff --git a/src/coreclr/vm/vars.cpp b/src/coreclr/vm/vars.cpp index f6fd1eac774627..7cf3df992f09b4 100644 --- a/src/coreclr/vm/vars.cpp +++ b/src/coreclr/vm/vars.cpp @@ -25,8 +25,8 @@ volatile int32_t g_TrapReturningThreads; #ifdef _DEBUG // next two variables are used to enforce an ASSERT in Thread::DbgFindThread // that does not allow g_TrapReturningThreads to creep up unchecked. -Volatile g_trtChgStamp = 0; -Volatile g_trtChgInFlight = 0; +Volatile g_trtChgStamp(0); +Volatile g_trtChgInFlight(0); const char * g_ExceptionFile; // Source of the last thrown exception (COMPLUSThrow()) DWORD g_ExceptionLine; // ... ditto ...