JDK-8358429 : JFR: minimize the time the Threads_lock is held for sampling
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: jfr
  • Affected Version: 25
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2025-06-02
  • Updated: 2025-06-27
  • Resolved: 2025-06-04
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 25
25 b26Fixed
Related Reports
Relates :  
Relates :  
Description
Before JDK-8352251, the JFR Sampler Thread held onto the Threads_lock during the entire sampling period when iterating threads.

This was for two purposes:

1. Having a non-Java thread sampler thread race through an ongoing safepoint, touching oops is generally not supported by most GCs.
2. Since the sampler thread is a non-Java thread, and a JavaThread to be sampled can be in thread state _thread_in_native, it means both threads are outside the safepoint protocol. JFR evolves its global epoch during a safepoint.

With JDK-8352251, things have improved much. The sampling parts performed by the non-Java sampler thread do not touch any oops for threads sampled in state _thread_in_Java.
For sampling threads in native, the original issue persists (the sampler thread needs to capture the stack trace in the correct JFR epoch, and will also, in the case of virtual threads, need to touch oops).

However, we can significantly reduce the time the Threads_lock is held for sampling.

Comments
Changeset: b6d60280 Branch: master Author: Markus Grönlund <mgronlun@openjdk.org> Date: 2025-06-04 08:20:48 +0000 URL: https://git.openjdk.org/jdk/commit/b6d60280e789436c7f9e3cd1447c8f77b77e77b4
04-06-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/25602 Date: 2025-06-02 23:17:33 +0000
03-06-2025