RFR: 8376568: Change Thread::getStackTrace to use handshake op for all cases [v2]

Alan Bateman alanb at openjdk.org
Fri Jan 30 08:10:33 UTC 2026


On Fri, 30 Jan 2026 04:45:33 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> ThreadSnapshot.of(Thread) may be invoked with a platform or virtual Thread in any state. It could sample the thread state before calling ThreadSnapshotFactory::get_thread_snapshot. That would allow it to filter out unstarted/NEW threads. It could also filter terminated threads but that would be racy and get_thread_snapshot would still need to handle terminated threads.
>> 
>> For platform threads, get_thread_snapshot will bail out early if there is no JavaThread. So the effect of the above is to have virtual threads also be filtered out.
>
> Still not clear to me why any new thread is not already filtered out long before now; nor why we have not needed this in the past.

We want ThreadSnapshot.of(Thread) to accept a Thread in any state. Existing behavior is to return null for platform threads that are not alive. For virtual threads it will return a snapshot so we want to change that. The ThreadNotAlive test in the PR allows to specifically check these cases as they are hard to demonstrate with the thread dump.

ThreadSnapshot.of(Thread) does not filter out the "not alive" cases. It could, in which case ThreadSnapshotFactory::get_thread_snapshot would need to assert if called with a new/unstarted thread. The terminating thread case would still need to be handled by ThreadSnapshotFactory::get_thread_snapshot. For platform threads there is no JavaThread so it bails easy. For virtual threads it needs to examine the state. So would you prefer that?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/29461#discussion_r2745112416


More information about the core-libs-dev mailing list