On Mon, 30 Nov 2026 13:58:37 GMT, Roman Kennke <[email protected]> wrote:

> 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).

Looks good to me.

src/hotspot/share/prims/jvmtiEnvBase.cpp line 1177:

> 1175:         return JVMTI_ERROR_ILLEGAL_ARGUMENT;
> 1176:       }
> 1177:     } else { // start_depth < 0

All this negative depth logic can be simplified and the added stackChunk 
restoration code removed if we use a `GrowableArray<javaVFrame*>` where we push 
the `javaVFrame*` as we walk each frame. It avoids extra walks (to get the 
correct starting frame and to fill the method/location buffer), and even with 
the extra `GrowableArray` it should almost always allocate less memory in the 
resource area since each new vframe created in those extra walks allocates 
about 5KiB. I see you filed JDK-8398334, so maybe you have already considered 
this but don’t want the extra cost of the `GrowableArray` once 8398334 is fixed?

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

Marked as reviewed by pchilanomate (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/34123#pullrequestreview-6176859077
PR Review Comment: https://git.openjdk.org/jdk/pull/34123#discussion_r4790176714

Reply via email to