diff --git a/src/mono/mono/metadata/domain.c b/src/mono/mono/metadata/domain.c index 8519cf409c54bc..10666a5f2b229e 100644 --- a/src/mono/mono/metadata/domain.c +++ b/src/mono/mono/metadata/domain.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index a4ec470a2ddb62..11af2c344bc63f 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -38,7 +38,6 @@ #endif #include "mono/metadata/icall-internals.h" -#include "mono/utils/mono-membar.h" #include #include #include diff --git a/src/mono/mono/metadata/jit-info.c b/src/mono/mono/metadata/jit-info.c index 5446a3248acff4..9cc5e817deebde 100644 --- a/src/mono/mono/metadata/jit-info.c +++ b/src/mono/mono/metadata/jit-info.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mono/mono/metadata/loader.c b/src/mono/mono/metadata/loader.c index afb16c6351d072..81209134e64441 100644 --- a/src/mono/mono/metadata/loader.c +++ b/src/mono/mono/metadata/loader.c @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mono/mono/metadata/property-bag.c b/src/mono/mono/metadata/property-bag.c index 42c083f0381150..b1b60da8d19713 100644 --- a/src/mono/mono/metadata/property-bag.c +++ b/src/mono/mono/metadata/property-bag.c @@ -9,7 +9,7 @@ */ #include #include -#include +#include /* * mono_property_bag_get: diff --git a/src/mono/mono/metadata/reflection.c b/src/mono/mono/metadata/reflection.c index 37898f954ff348..431e7643932989 100644 --- a/src/mono/mono/metadata/reflection.c +++ b/src/mono/mono/metadata/reflection.c @@ -13,7 +13,7 @@ * Licensed under the MIT license. See LICENSE file in the project root for full license information. */ #include -#include "mono/utils/mono-membar.h" +#include "mono/utils/mono-memory-model.h" #include "mono/metadata/assembly-internals.h" #include "mono/metadata/reflection-internals.h" #include "mono/metadata/tabledefs.h" diff --git a/src/mono/mono/metadata/string-icalls.c b/src/mono/mono/metadata/string-icalls.c index a8e3cb14dd14d2..c73f197a120bc4 100644 --- a/src/mono/mono/metadata/string-icalls.c +++ b/src/mono/mono/metadata/string-icalls.c @@ -14,7 +14,7 @@ #include #include #include -#include "mono/utils/mono-membar.h" +#include "mono/utils/mono-memory-model.h" #include #include #include diff --git a/src/mono/mono/metadata/threads-types.h b/src/mono/mono/metadata/threads-types.h index c1436094559c8c..c92e61497dba60 100644 --- a/src/mono/mono/metadata/threads-types.h +++ b/src/mono/mono/metadata/threads-types.h @@ -19,7 +19,7 @@ #include #include "mono/metadata/handle.h" #include "mono/utils/mono-compiler.h" -#include "mono/utils/mono-membar.h" +#include "mono/utils/mono-memory-model.h" #include "mono/utils/mono-threads.h" #include "mono/metadata/class-internals.h" #include diff --git a/src/mono/mono/metadata/threads.c b/src/mono/mono/metadata/threads.c index 7cde95a9dc0b1a..6f976887972093 100644 --- a/src/mono/mono/metadata/threads.c +++ b/src/mono/mono/metadata/threads.c @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index a6ee9e1f3eeaf5..5e5dcd05844fe0 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #ifdef HAVE_ALLOCA_H # include @@ -3606,6 +3606,8 @@ method_entry (ThreadContext *context, InterpFrame *frame, frame->stack = (stackval*)context->stack_pointer; return slow; } + } else { + mono_memory_read_barrier (); } return slow; diff --git a/src/mono/mono/mini/mini-trampolines.c b/src/mono/mono/mini/mini-trampolines.c index 663120fd540301..5eb7be5c46c08e 100644 --- a/src/mono/mono/mini/mini-trampolines.c +++ b/src/mono/mono/mini/mini-trampolines.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mono/mono/profiler/log.c b/src/mono/mono/profiler/log.c index 110253833a97bb..1aa33e9c40ee85 100644 --- a/src/mono/mono/profiler/log.c +++ b/src/mono/mono/profiler/log.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mono/mono/sgen/sgen-fin-weak-hash.c b/src/mono/mono/sgen/sgen-fin-weak-hash.c index 7b5f3c908aeedd..615982c3d66113 100644 --- a/src/mono/mono/sgen/sgen-fin-weak-hash.c +++ b/src/mono/mono/sgen/sgen-fin-weak-hash.c @@ -23,7 +23,7 @@ #include "mono/sgen/sgen-pointer-queue.h" #include "mono/sgen/sgen-client.h" #include "mono/sgen/gc-internal-agnostic.h" -#include "mono/utils/mono-membar.h" +#include "mono/utils/mono-memory-model.h" #include "mono/utils/atomic.h" #include "mono/utils/unlocked.h" diff --git a/src/mono/mono/sgen/sgen-gchandles.c b/src/mono/mono/sgen/sgen-gchandles.c index 7d4f3344f030fa..fa9742b93c0cc5 100644 --- a/src/mono/mono/sgen/sgen-gchandles.c +++ b/src/mono/mono/sgen/sgen-gchandles.c @@ -13,7 +13,7 @@ #include "mono/sgen/sgen-gc.h" #include "mono/sgen/sgen-client.h" #include "mono/sgen/sgen-array-list.h" -#include "mono/utils/mono-membar.h" +#include "mono/utils/mono-memory-model.h" #ifdef HEAVY_STATISTICS static volatile guint32 stat_gc_handles_allocated = 0; diff --git a/src/mono/mono/sgen/sgen-nursery-allocator.c b/src/mono/mono/sgen/sgen-nursery-allocator.c index 731dfcccbd1d4b..9f9548474cf477 100644 --- a/src/mono/mono/sgen/sgen-nursery-allocator.c +++ b/src/mono/mono/sgen/sgen-nursery-allocator.c @@ -55,7 +55,7 @@ #include "mono/sgen/sgen-memory-governor.h" #include "mono/sgen/sgen-pinning.h" #include "mono/sgen/sgen-client.h" -#include "mono/utils/mono-membar.h" +#include "mono/utils/mono-memory-model.h" /* Enable it so nursery allocation diagnostic data is collected */ //#define NALLOC_DEBUG 1 diff --git a/src/mono/mono/sgen/sgen-protocol.c b/src/mono/mono/sgen/sgen-protocol.c index 1e76136dc82818..7c7543cd4292c8 100644 --- a/src/mono/mono/sgen/sgen-protocol.c +++ b/src/mono/mono/sgen/sgen-protocol.c @@ -18,7 +18,7 @@ #include "sgen-memory-governor.h" #include "sgen-workers.h" #include "sgen-client.h" -#include "mono/utils/mono-membar.h" +#include "mono/utils/mono-memory-model.h" #include "mono/utils/mono-proclib.h" #include diff --git a/src/mono/mono/sgen/sgen-workers.c b/src/mono/mono/sgen/sgen-workers.c index f68911581e0d27..adb4b8f3e8a484 100644 --- a/src/mono/mono/sgen/sgen-workers.c +++ b/src/mono/mono/sgen/sgen-workers.c @@ -18,7 +18,7 @@ #include "mono/sgen/sgen-gc.h" #include "mono/sgen/sgen-workers.h" #include "mono/sgen/sgen-thread-pool.h" -#include "mono/utils/mono-membar.h" +#include "mono/utils/mono-memory-model.h" #include "mono/sgen/sgen-client.h" #ifndef DISABLE_SGEN_MAJOR_MARKSWEEP_CONC diff --git a/src/mono/mono/utils/CMakeLists.txt b/src/mono/mono/utils/CMakeLists.txt index efbfa3c119cffa..fdcece6573e352 100644 --- a/src/mono/mono/utils/CMakeLists.txt +++ b/src/mono/mono/utils/CMakeLists.txt @@ -101,7 +101,6 @@ set(utils_common_sources mono-forward-internal.h mono-machine.h mono-math.h - mono-membar.h mono-path.h mono-poll.h mono-uri.h diff --git a/src/mono/mono/utils/atomic.h b/src/mono/mono/utils/atomic.h index 1bf7fea44b74c2..0a69b80bb4f51c 100644 --- a/src/mono/mono/utils/atomic.h +++ b/src/mono/mono/utils/atomic.h @@ -15,7 +15,7 @@ #include "config.h" #include -#include +#include #include /* diff --git a/src/mono/mono/utils/hazard-pointer.c b/src/mono/mono/utils/hazard-pointer.c index 9769c4b38ad026..bf01d58627c8d6 100644 --- a/src/mono/mono/utils/hazard-pointer.c +++ b/src/mono/mono/utils/hazard-pointer.c @@ -11,7 +11,6 @@ #include #include -#include #include #include #include diff --git a/src/mono/mono/utils/hazard-pointer.h b/src/mono/mono/utils/hazard-pointer.h index a1f453e88cae36..1093b09b475dd1 100644 --- a/src/mono/mono/utils/hazard-pointer.h +++ b/src/mono/mono/utils/hazard-pointer.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include #define HAZARD_POINTER_COUNT 3 diff --git a/src/mono/mono/utils/lock-free-alloc.c b/src/mono/mono/utils/lock-free-alloc.c index e90731ca86fa20..7826c270178487 100644 --- a/src/mono/mono/utils/lock-free-alloc.c +++ b/src/mono/mono/utils/lock-free-alloc.c @@ -73,7 +73,7 @@ #else #include #endif -#include +#include #include #include diff --git a/src/mono/mono/utils/lock-free-array-queue.c b/src/mono/mono/utils/lock-free-array-queue.c index 82ef5649cd4e64..3672e3306cc767 100644 --- a/src/mono/mono/utils/lock-free-array-queue.c +++ b/src/mono/mono/utils/lock-free-array-queue.c @@ -21,7 +21,7 @@ #include #include -#include +#include #ifdef SGEN_WITHOUT_MONO #include #include diff --git a/src/mono/mono/utils/lock-free-queue.c b/src/mono/mono/utils/lock-free-queue.c index 02ce5b1745a77b..a8152efee5e9d3 100644 --- a/src/mono/mono/utils/lock-free-queue.c +++ b/src/mono/mono/utils/lock-free-queue.c @@ -52,7 +52,7 @@ #include #endif -#include +#include #include #include diff --git a/src/mono/mono/utils/mono-linked-list-set.h b/src/mono/mono/utils/mono-linked-list-set.h index 04e1537f314c23..50024f486bb4bb 100644 --- a/src/mono/mono/utils/mono-linked-list-set.h +++ b/src/mono/mono/utils/mono-linked-list-set.h @@ -12,7 +12,7 @@ #define __MONO_SPLIT_ORDERED_LIST_H__ #include -#include +#include typedef struct _MonoLinkedListSetNode MonoLinkedListSetNode; diff --git a/src/mono/mono/utils/mono-membar.h b/src/mono/mono/utils/mono-membar.h deleted file mode 100644 index 1092ca634dd6eb..00000000000000 --- a/src/mono/mono/utils/mono-membar.h +++ /dev/null @@ -1,83 +0,0 @@ -/** - * \file - * Memory barrier inline functions - * - * Author: - * Mark Probst (mark.probst@gmail.com) - * - * (C) 2007 Novell, Inc - */ - -#ifndef _MONO_UTILS_MONO_MEMBAR_H_ -#define _MONO_UTILS_MONO_MEMBAR_H_ - -#include - -#include - -/* - * Memory barrier which only affects the compiler. - * mono_memory_barrier_process_wide () should be uses to synchronize with code which uses this. - */ -//#define mono_compiler_barrier() asm volatile("": : :"memory") - -#if _MSC_VER -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#include - -static inline void mono_memory_barrier (void) -{ - /* NOTE: _ReadWriteBarrier and friends only prevent the - compiler from reordering loads and stores. To prevent - the CPU from doing the same, we have to use the - MemoryBarrier macro which expands to e.g. a serializing - XCHG instruction on x86. Also note that the MemoryBarrier - macro does *not* imply _ReadWriteBarrier, so that call - cannot be eliminated. */ - _ReadWriteBarrier (); - MemoryBarrier (); -} - -static inline void mono_memory_read_barrier (void) -{ - _ReadBarrier (); - MemoryBarrier (); -} - -static inline void mono_memory_write_barrier (void) -{ - _WriteBarrier (); - MemoryBarrier (); -} - -#define mono_compiler_barrier() _ReadWriteBarrier () - -#elif defined(USE_GCC_ATOMIC_OPS) || defined(HOST_WASM) - -static inline void mono_memory_barrier (void) -{ - __sync_synchronize (); -} - -static inline void mono_memory_read_barrier (void) -{ - mono_memory_barrier (); -} - -static inline void mono_memory_write_barrier (void) -{ - mono_memory_barrier (); -} - -#define mono_compiler_barrier() asm volatile("": : :"memory") - -#else -#error "Don't know how to do memory barriers!" -#endif - -void mono_memory_barrier_process_wide (void); - -#endif /* _MONO_UTILS_MONO_MEMBAR_H_ */ diff --git a/src/mono/mono/utils/mono-memory-model.h b/src/mono/mono/utils/mono-memory-model.h index 863ee77d615635..aef59eab69ca99 100644 --- a/src/mono/mono/utils/mono-memory-model.h +++ b/src/mono/mono/utils/mono-memory-model.h @@ -12,7 +12,45 @@ #define _MONO_UTILS_MONO_MEMMODEL_H_ #include -#include + +#if _MSC_VER +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#include + +static inline void +mono_memory_barrier (void) +{ + /* NOTE: _ReadWriteBarrier and friends only prevent the + compiler from reordering loads and stores. To prevent + the CPU from doing the same, we have to use the + MemoryBarrier macro which expands to e.g. a serializing + XCHG instruction on x86. Also note that the MemoryBarrier + macro does *not* imply _ReadWriteBarrier, so that call + cannot be eliminated. */ + _ReadWriteBarrier (); + MemoryBarrier (); +} + +#define mono_compiler_barrier() _ReadWriteBarrier () + +#elif defined(USE_GCC_ATOMIC_OPS) || defined(HOST_WASM) + +static inline void +mono_memory_barrier (void) +{ + __sync_synchronize (); +} + +#define mono_compiler_barrier() asm volatile("": : :"memory") + +#else +#error "Don't know how to do memory barriers!" +#endif + +void mono_memory_barrier_process_wide (void); /* In order to allow for fast concurrent code, we must use fencing to properly order @@ -46,8 +84,6 @@ enum { }; #define MEMORY_BARRIER mono_memory_barrier () -#define LOAD_BARRIER mono_memory_read_barrier () -#define STORE_BARRIER mono_memory_write_barrier () #if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) /* @@ -77,8 +113,8 @@ AND R0, R0, #0 LDR R3, [R4, R0] */ -#define STORE_STORE_FENCE STORE_BARRIER -#define LOAD_LOAD_FENCE LOAD_BARRIER +#define STORE_STORE_FENCE MEMORY_BARRIER +#define LOAD_LOAD_FENCE MEMORY_BARRIER #define STORE_LOAD_FENCE MEMORY_BARRIER #define STORE_ACQUIRE_FENCE MEMORY_BARRIER #define STORE_RELEASE_FENCE MEMORY_BARRIER @@ -96,8 +132,8 @@ LDR R3, [R4, R0] #else /*default implementation with the weakest possible memory model */ -#define STORE_STORE_FENCE STORE_BARRIER -#define LOAD_LOAD_FENCE LOAD_BARRIER +#define STORE_STORE_FENCE MEMORY_BARRIER +#define LOAD_LOAD_FENCE MEMORY_BARRIER #define STORE_LOAD_FENCE MEMORY_BARRIER #define LOAD_STORE_FENCE MEMORY_BARRIER #define STORE_ACQUIRE_FENCE MEMORY_BARRIER @@ -172,4 +208,17 @@ Acquire/release semantics macros. STORE_ACQUIRE_FENCE; \ } + +static inline void +mono_memory_read_barrier (void) +{ + LOAD_LOAD_FENCE; +} + +static inline void +mono_memory_write_barrier (void) +{ + STORE_STORE_FENCE; +} + #endif /* _MONO_UTILS_MONO_MEMMODEL_H_ */