For a negative `start_depth`, `GetStackTrace` walks to the bottom of the stack, then resumes from an earlier `javaVFrame`. The `RegisterMap` copies share a mutable stack-chunk handle. By the time the walk resumes from the saved frame, that handle may point to a different chunk or have been cleared. This can cause HotSpot to walk a heap-backed frame as though it were on the native stack.
Before resuming the walk, compare the map’s current chunk with the chunk saved by the frame. If they differ, give the map a fresh mutable handle initialized to the saved chunk, leaving the chunk index and register state unchanged. This preserves the existing walk algorithm: it does not add a frame-counting pass or allocate a new handle for stacks that never enter a chunk. The regression test compares negative-depth traces with the corresponding slices of the full trace for both an unmounted virtual thread and a mounted virtual thread with frames still in a stack chunk. It also checks truncation and out-of-range depths. Testing: All 28 JVMTI thread tests passed on Linux x86-64 fastdebug. The new test also passed with `-Xint`, `-Xcomp`, ZGC, Shenandoah, and `-XX:-UseContinuationFastPath`. A separate check verified all 618 valid negative depths on a virtual thread with two non-empty stack chunks under both `-Xint` and `-Xcomp`. --------- - [x] I confirm that I make this contribution in accordance with the [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). ------------- Commit messages: - Add jtreg tests - 8398467: JVMTI GetStackTrace with a negative start_depth crashes on an unmounted virtual thread Changes: https://git.openjdk.org/jdk/pull/34123/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=34123&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8398467 Stats: 304 lines in 6 files changed: 296 ins; 3 del; 5 mod Patch: https://git.openjdk.org/jdk/pull/34123.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/34123/head:pull/34123 PR: https://git.openjdk.org/jdk/pull/34123
