# HG changeset patch # User pchilanomate # Date 1542207001 18000 # Node ID 3b2d22602c1602d0381203d327d3dd3d986d02e7 # Parent 5f1ca46703f9cdd4f7476a8cbfce391c7b7517f6 8213708: Different #ifdef guards cause incorrect use of Monitor::check_block_state() Summary: Wrapped check_block_state() method in DEBUG_ONLY macro and make the use of the latter more consistent Reviewed-by: dcubed, dholmes diff -r 5f1ca46703f9 -r 3b2d22602c16 src/hotspot/share/runtime/mutex.cpp --- a/src/hotspot/share/runtime/mutex.cpp Wed Nov 14 14:23:21 2018 +0000 +++ b/src/hotspot/share/runtime/mutex.cpp Wed Nov 14 09:50:01 2018 -0500 @@ -875,7 +875,7 @@ } #endif // CHECK_UNHANDLED_OOPS - debug_only(check_prelock_state(Self, StrictSafepointChecks)); + DEBUG_ONLY(check_prelock_state(Self, StrictSafepointChecks);) assert(_owner != Self, "invariant"); assert(_OnDeck != Self->_MutexEvent, "invariant"); @@ -902,7 +902,7 @@ // Try a brief spin to avoid passing thru thread state transition ... if (TrySpin(Self)) goto Exeunt; - check_block_state(Self); + DEBUG_ONLY(check_block_state(Self);) if (Self->is_Java_thread()) { // Horrible dictu - we suffer through a state transition assert(rank() > Mutex::special, "Potential deadlock with special or lesser rank mutex"); @@ -943,7 +943,7 @@ bool Monitor::try_lock() { Thread * const Self = Thread::current(); - debug_only(check_prelock_state(Self, false)); + DEBUG_ONLY(check_prelock_state(Self, false);) // assert(!thread->is_inside_signal_handler(), "don't lock inside signal handler"); // Special case, where all Java threads are stopped. @@ -1320,7 +1320,7 @@ // the thread is releasing this lock Thread* old_owner = _owner; - debug_only(_last_owner = old_owner); + DEBUG_ONLY(_last_owner = old_owner;) assert(old_owner != NULL, "removing the owner thread of an unowned mutex"); assert(old_owner == Thread::current(), "removing the owner thread of an unowned mutex"); @@ -1360,7 +1360,7 @@ if (thread->is_VM_thread() && !allow_vm_block()) { fatal("VM thread using lock %s (not allowed to block on)", name()); } - debug_only(if (rank() != Mutex::special) \ + DEBUG_ONLY(if (rank() != Mutex::special) \ thread->check_for_valid_safepoint_state(false);) } assert(!os::ThreadCrashProtection::is_crash_protected(thread), diff -r 5f1ca46703f9 -r 3b2d22602c16 src/hotspot/share/runtime/mutex.hpp --- a/src/hotspot/share/runtime/mutex.hpp Wed Nov 14 14:23:21 2018 +0000 +++ b/src/hotspot/share/runtime/mutex.hpp Wed Nov 14 09:50:01 2018 -0500 @@ -135,12 +135,12 @@ // 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);) + 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; @@ -237,17 +237,17 @@ #ifndef PRODUCT void print_on(outputStream* st) const; void print() const { print_on(tty); } - debug_only(int rank() const { return _rank; }) + DEBUG_ONLY(int rank() const { return _rank; }) bool allow_vm_block() { return _allow_vm_block; } - debug_only(Monitor *next() const { return _next; }) - debug_only(void set_next(Monitor *next) { _next = next; }) + DEBUG_ONLY(Monitor *next() const { return _next; }) + DEBUG_ONLY(void set_next(Monitor *next) { _next = next; }) #endif void set_owner(Thread* owner) { #ifndef PRODUCT set_owner_implementation(owner); - debug_only(void verify_Monitor(Thread* thr)); + DEBUG_ONLY(void verify_Monitor(Thread* thr);) #else _owner = owner; #endif