# HG changeset patch # User mdoerr # Date 1475249949 -7200 # Fri Sep 30 17:39:09 2016 +0200 # Node ID b0bfe59d6f45032743f6c2bbbd95ec8bc74a31b3 # Parent a6934ab21a0b0a890ca2a06e09d66817d7972e45 8166970: Adapt mutex padding according to DEFAULT_CACHE_LINE_SIZE Reviewed-by: diff --git a/src/share/vm/runtime/mutex.hpp b/src/share/vm/runtime/mutex.hpp --- a/src/share/vm/runtime/mutex.hpp +++ b/src/share/vm/runtime/mutex.hpp @@ -81,11 +81,7 @@ // *in that order*. If their implementations change such that these // assumptions are violated, a whole lot of code will break. -// The default length of monitor name is chosen to be 64 to avoid false sharing. -static const int MONITOR_NAME_LEN = 64; - -class Monitor : public CHeapObj { - +class MonitorBase : public CHeapObj { public: // A special lock: Is a lock where you are guaranteed not to block while you are // holding it, i.e., no vm operation can happen, taking other locks, etc. @@ -129,7 +125,6 @@ ParkEvent * volatile _WaitSet ; // LL of ParkEvents volatile bool _snuck; // Used for sneaky locking (evil). int NotifyCount ; // diagnostic assist - char _name[MONITOR_NAME_LEN]; // Name of mutex // Debugging fields for naming, deadlock detection, etc. (some only used in debug mode) #ifndef PRODUCT @@ -137,16 +132,9 @@ debug_only(int _rank;) // rank (to avoid/detect potential deadlocks) debug_only(Monitor * _next;) // Used by a Thread to link up owned locks debug_only(Thread* _last_owner;) // the last thread to own the lock - debug_only(static bool contains(Monitor * locks, Monitor * lock);) - debug_only(static Monitor * get_least_ranked_lock(Monitor * locks);) - debug_only(Monitor * get_least_ranked_lock_besides_this(Monitor * locks);) #endif - void set_owner_implementation(Thread* owner) PRODUCT_RETURN; - void check_prelock_state (Thread* thread) PRODUCT_RETURN; - void check_block_state (Thread* thread) PRODUCT_RETURN; - - // platform-dependent support code can go here (in os_.cpp) + // platform-dependent support code can go here (in os_.cpp) public: enum { _no_safepoint_check_flag = true, @@ -177,6 +165,28 @@ INTERRUPT_EVENT, // Wait returned because waiting thread was interrupted NUMBER_WAIT_RESULTS }; +}; + +class Monitor : public MonitorBase { + protected: + // The default length of monitor name is chosen to avoid false sharing. + enum { + CACHE_LINE_PADDING = DEFAULT_CACHE_LINE_SIZE - sizeof(MonitorBase), + MONITOR_NAME_LEN = CACHE_LINE_PADDING > 64 ? CACHE_LINE_PADDING : 64 + }; + char _name[MONITOR_NAME_LEN]; // Name of mutex + // Other fields should be declared in MonitorBase. + + public: +#ifndef PRODUCT + debug_only(static bool contains(Monitor * locks, Monitor * lock);) + debug_only(static Monitor * get_least_ranked_lock(Monitor * locks);) + debug_only(Monitor * get_least_ranked_lock_besides_this(Monitor * locks);) +#endif + + void set_owner_implementation(Thread* owner) PRODUCT_RETURN; + void check_prelock_state (Thread* thread) PRODUCT_RETURN; + void check_block_state (Thread* thread) PRODUCT_RETURN; private: int TrySpin (Thread * Self) ;