RFR: 8366154: Validate thread type requirements in debug commands [v3]

Kevin Walls kevinw at openjdk.org
Wed Sep 10 09:06:23 UTC 2025


On Tue, 9 Sep 2025 17:19:23 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.
>
> Kerem Kat has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - refine comment
>  - remove redundant proto for findpc

I made the comment earlier about duplication, it seemed odd not to keep the command implementations simple, by putting the common Thread::active calls and checks in one place.  But that doesn't need to hold this up, if everybody is happy, I do like the change. 8-)

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

Marked as reviewed by kevinw (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/27033#pullrequestreview-3205186030


More information about the hotspot-dev mailing list