JDK-8191784 : [JVMCI] JavaThread::collect_counters() should stop using Threads_lock
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 10
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2017-11-22
  • Updated: 2022-11-10
  • Resolved: 2022-11-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
Relates :  
Description
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.
Comments
[~dnsimon] JVMCI issue.
10-11-2022

Since the existing Threads_lock usage works fine and the bug just wants to reduce Threads_lock usage, I should have filed this as an enhancement rather than a bug.
24-11-2017

Use of the Threads_lock is safe. No inconsistencies are possible. However, it is a heavy weight mechanism to use so another mechanism should be investigated.
23-11-2017

initial ILW = possible failures, inconsistencies due to use of Threads_lock; no direct failures reported; no workaround = MLH = P4 (targeting to 11 for now, please change if required)
23-11-2017