Integrated: 8366154: Validate thread type requirements in debug commands

Kerem Kat krk at openjdk.org
Wed Sep 10 14:39:07 UTC 2025


On Mon, 1 Sep 2025 11:36:21 GMT, Kerem Kat <krk at openjdk.org> wrote:

> Prevents segmentation faults during `gdb` sessions. The crashes were caused by the `ResourceMark` constructor being called on a native thread, which is not supported. This happened when invoking debug commands that require a `Thread` or `JavaThread` context from an incorrect thread type.
> 
> ### Solution
> 
> This change introduces `onThread()` and `onJavaThread()` helper methods to the `Command` class. These methods validate the thread context and ensure `ResourceMark` is only created when on a valid VM thread. All thread-dependent debug commands now use these guards to validate the context, printing a clear error and exiting gracefully upon failure.
> 
> ### Testing
> 
> Manually verified using `gdb` by calling the modified commands (`ps`, `universe`, `pns`, etc.) from different thread contexts (native, Java, and non-java threads) to ensure they fail gracefully with an error message instead of crashing the debug session.

This pull request has now been integrated.

Changeset: 5cd7721a
Author:    Kerem Kat <krk at openjdk.org>
Committer: Kevin Walls <kevinw at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/5cd7721ad448cc4bdac37b0456252335f6b9d9f5
Stats:     70 lines in 1 file changed: 48 ins; 7 del; 15 mod

8366154: Validate thread type requirements in debug commands

Reviewed-by: dholmes, simonis, kevinw

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

PR: https://git.openjdk.org/jdk/pull/27033


More information about the hotspot-dev mailing list