RFR: 8358429: JFR: minimize the time the Threads_lock is held for sampling
Erik Gahlin
egahlin at openjdk.org
Tue Jun 3 20:41:15 UTC 2025
On Mon, 2 Jun 2025 23:17:33 GMT, Markus Grönlund <mgronlun at openjdk.org> wrote:
> Greetings,
>
> Before [JDK-8352251](https://bugs.openjdk.org/browse/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](https://bugs.openjdk.org/browse/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.
>
> Testing: jdk_jfr, stress testing
>
> Thanks
> Markus
Marked as reviewed by egahlin (Reviewer).
-------------
PR Review: https://git.openjdk.org/jdk/pull/25602#pullrequestreview-2894053010
More information about the hotspot-jfr-dev
mailing list