--- old/src/hotspot/share/runtime/biasedLocking.cpp Tue Nov 21 14:38:30 2017 +++ new/src/hotspot/share/runtime/biasedLocking.cpp Tue Nov 21 14:38:29 2017 @@ -215,12 +215,8 @@ if (requesting_thread == biased_thread) { thread_is_alive = true; } else { - for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur_thread = jtiwh.next(); ) { - if (cur_thread == biased_thread) { - thread_is_alive = true; - break; - } - } + ThreadsListHandle tlh; + thread_is_alive = tlh.includes(biased_thread); } if (!thread_is_alive) { if (allow_rebias) { --- old/src/hotspot/share/runtime/memprofiler.cpp Tue Nov 21 14:38:33 2017 +++ new/src/hotspot/share/runtime/memprofiler.cpp Tue Nov 21 14:38:32 2017 @@ -52,8 +52,6 @@ void MemProfilerTask::task() { - // Get thread lock to provide mutual exclusion, and so we can iterate safely over the thread list. - MutexLocker mu(Threads_lock); MemProfiler::do_trace(); } --- old/src/hotspot/share/runtime/thread.cpp Tue Nov 21 14:38:36 2017 +++ new/src/hotspot/share/runtime/thread.cpp Tue Nov 21 14:38:35 2017 @@ -3429,10 +3429,15 @@ // ======= Threads ======== // The Threads class links together all active threads, and provides -// operations over all threads. It is protected by its own Mutex -// lock, which is also used in other contexts to protect thread -// operations from having the thread being operated on from exiting -// and going away unexpectedly (e.g., safepoint synchronization) +// operations over all threads. It is protected by the Threads_lock, +// which is also used in other global contexts like safepointing. +// ThreadsListHandles are used to safely perform operations on one +// or more threads without the risk of the thread exiting during the +// operation. +// +// Note: The Threads_lock is currently more widely used than we +// would like. We are actively migrating Threads_lock uses to other +// mechanisms in order to reduce Threads_lock contention. JavaThread* Threads::_thread_list = NULL; int Threads::_number_of_threads = 0; @@ -4891,8 +4896,8 @@ // Retry the whole scenario. } - // If someone set a handshake on us just as we entered exit path, we simple cancel it. if (ThreadLocalHandshakes) { + // The thread is about to be deleted so cancel any handshake. thread->cancel_handshake(); } --- old/src/hotspot/share/runtime/thread.hpp Tue Nov 21 14:38:39 2017 +++ new/src/hotspot/share/runtime/thread.hpp Tue Nov 21 14:38:38 2017 @@ -1176,7 +1176,7 @@ // JavaThread termination and lifecycle support: void smr_delete(); - bool on_thread_list() { return _on_thread_list; } + bool on_thread_list() const { return _on_thread_list; } void set_on_thread_list() { _on_thread_list = true; } // thread has called JavaThread::exit() or is terminated @@ -1187,7 +1187,7 @@ bool check_is_terminated(TerminatedTypes l_terminated) const { return l_terminated != _not_terminated && l_terminated != _thread_exiting; } - bool is_terminated(); + bool is_terminated() const; void set_terminated(TerminatedTypes t); // special for Threads::remove() which is static: void set_terminated_value(); --- old/src/hotspot/share/runtime/thread.inline.hpp Tue Nov 21 14:38:42 2017 +++ new/src/hotspot/share/runtime/thread.inline.hpp Tue Nov 21 14:38:41 2017 @@ -192,12 +192,12 @@ return l_terminated == _thread_exiting || check_is_terminated(l_terminated); } -inline bool JavaThread::is_terminated() { +inline bool JavaThread::is_terminated() const { // Use load-acquire so that setting of _terminated by // JavaThread::exit() is seen more quickly. TerminatedTypes l_terminated = (TerminatedTypes) OrderAccess::load_acquire((volatile jint *) &_terminated); - return check_is_terminated(_terminated); + return check_is_terminated(l_terminated); } inline void JavaThread::set_terminated(TerminatedTypes t) { --- old/src/hotspot/share/runtime/vm_operations.hpp Tue Nov 21 14:38:45 2017 +++ new/src/hotspot/share/runtime/vm_operations.hpp Tue Nov 21 14:38:44 2017 @@ -403,8 +403,8 @@ VM_FindDeadlocks(outputStream* st) : _concurrent_locks(true), _out(st), _deadlocks(NULL) {}; ~VM_FindDeadlocks(); - DeadlockCycle* result() { return _deadlocks; }; - VMOp_Type type() const { return VMOp_FindDeadlocks; } + DeadlockCycle* result() { return _deadlocks; }; + VMOp_Type type() const { return VMOp_FindDeadlocks; } void doit(); bool doit_prologue(); };