src/hotspot/share/runtime/thread.cpp:
void JavaThread::collect_counters(typeArrayOop array) {
if (JVMCICounterSize > 0) {
// dcubed - Looks like the Threads_lock is for stable access
// to _jvmci_old_thread_counters and _jvmci_counters.
MutexLocker tl(Threads_lock);
JavaThreadIteratorWithHandle jtiwh;
for (int i = 0; i < array->length(); i++) {
array->long_at_put(i, _jvmci_old_thread_counters[i]);
}
for (; JavaThread *tp = jtiwh.next(); ) {
if (jvmci_counters_include(tp)) {
for (int i = 0; i < array->length(); i++) {
array->long_at_put(i, array->long_at(i) + tp->_jvmci_counters[i]);
}
}
}
}
}
With the advent of ThreadsListHandles (and JavaThreadIteratorWithHandle),
JavaThread::collect_counters() no longer needs to use Threads_lock to
safely access JavaThreads. However, it looks like Threads_lock is also
being used for stable access to _jvmci_old_thread_counters and
_jvmci_counters.
It would be better if another mechanism or lock were used for that
access in order to reduce use of the Threads_lock.