JDK-8266337 : ThreadTimesClosure doesn't handle exceptions properly
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc
  • Affected Version: 17
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-04-30
  • Updated: 2021-06-11
  • Resolved: 2021-06-03
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.
JDK 17 JDK 18
17 b26Fixed 18Resolved
Related Reports
Relates :  
Description
Case 1:

void ThreadTimesClosure::do_unlocked() {
  EXCEPTION_MARK;
  for (int i = 0; i < _count; i++) {
    Handle s = java_lang_String::create_from_str(_names_chars[i],  CHECK);
    _names_strings->obj_at_put(i, s());
  }
}

create_from_str can throw OOME as per the use of CHECK macro, but the EXCEPTION_MARK would cause us to crash if this happened. The EXCEPTION_MARK is not wanted here.

case 2:

void ThreadTimesClosure::do_thread(Thread* thread) {
 ...
  EXCEPTION_MARK;
  ResourceMark rm(THREAD); // thread->name() uses ResourceArea

  assert(thread->name() != NULL, "All threads should have a name");
  _names_chars[_count] = os::strdup(thread->name());
  _times->long_at_put(_count, os::is_thread_cpu_time_supported() ?
                        os::thread_cpu_time(thread) : -1);
  _count++;
}

This EXCEPTION_MARK is superfluous as no code raises exceptions.

If the code wants to assert it is not called with an exception pending then it should assert that directly rather than using the EXCEPTION_MARK.
Comments
Robo Duke added a comment - Yesterday Changeset: 06f87cf4 Author: Leonid Mesnik <lmesnik@openjdk.org> Date: 2021-06-03 04:12:40 +0000 URL: https://git.openjdk.java.net/jdk/commit/06f87cf4419be9c1bffe996d5d476d30b0f86bf6 Fix was pushed while main bug was targeted to '18'. Reset the main bug to fixed in '17' and copied the Robo Duke entry here.
04-06-2021

It is fixed but, the backport to 17 was created.
03-06-2021