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

Kerem Kat krk at openjdk.org
Wed Sep 10 13:54:24 UTC 2025


On Wed, 10 Sep 2025 10:09:46 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 with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains seven additional commits since the last revision:
> 
>  - Merge branch 'master' into JDK-8366154
>  - refine comment
>  - remove redundant proto for findpc
>  - add include for global placement new
>  - remove onJavaThread and check JavaThread::active null where needed
>  - Update src/hotspot/share/utilities/debug.cpp
>    
>    Co-authored-by: Francesco Andreuzzi <andreuzzi.francesco at gmail.com>
>  - 8366154: Validate thread type requirements in debug commands
>    
>    Prevent crashes when calling interactive debug commands from native
>    or non-java threads.
>    
>    Add onThread() and onJavaThread() methods to the Command class to
>    validate the current thread type. Update debug commands to use these
>    checks, printing an error and exiting gracefully upon failure.

Unrelated macos failure: https://github.com/krk/jdk/actions/runs/17610297210/job/50032942937


Unpacking jdk bundle...
jdk-26.jdk/Contents/Home/lib/server/libjvm.dylib: truncated gzip input

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

PR Comment: https://git.openjdk.org/jdk/pull/27033#issuecomment-3275076434


More information about the hotspot-dev mailing list