RFR: 8366154: Validate thread type requirements in debug commands [v2]
Kerem Kat
krk at openjdk.org
Tue Sep 2 10:08:58 UTC 2025
> 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.
Kerem Kat has updated the pull request incrementally with two additional commits since the last revision:
- add include for global placement new
- remove onJavaThread and check JavaThread::active null where needed
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/27033/files
- new: https://git.openjdk.org/jdk/pull/27033/files/74d1e08b..0d3ded95
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=27033&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=27033&range=00-01
Stats: 30 lines in 1 file changed: 15 ins; 13 del; 2 mod
Patch: https://git.openjdk.org/jdk/pull/27033.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/27033/head:pull/27033
PR: https://git.openjdk.org/jdk/pull/27033
More information about the hotspot-dev
mailing list