< prev index next >
src/share/vm/runtime/mutex.hpp
Print this page
rev 12096 : 8166970: Adapt mutex padding according to DEFAULT_CACHE_LINE_SIZE
Reviewed-by:
@@ -79,15 +79,11 @@
// See orderAccess.hpp. We assume throughout the VM that mutex lock and
// try_lock do fence-lock-acquire, and that unlock does a release-unlock,
// *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<mtInternal> {
-
+class MonitorBase : public CHeapObj<mtInternal> {
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.
// NOTE: It is critical that the rank 'special' be the lowest (earliest)
// (except for "event"?) for the deadlock detection to work correctly.
@@ -127,27 +123,19 @@
ParkEvent * volatile _OnDeck ; // heir-presumptive
volatile intptr_t _WaitLock [1] ; // Protects _WaitSet
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
bool _allow_vm_block;
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_<os_family>.cpp)
public:
enum {
_no_safepoint_check_flag = true,
_allow_vm_block_flag = true,
@@ -175,10 +163,32 @@
enum WaitResults {
CONDVAR_EVENT, // Wait returned because of condition variable notification
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) ;
int TryLock () ;
int TryFast () ;
< prev index next >