On Fri, 27 Nov 2026 10:27:11 GMT, Roman Kennke <[email protected]> wrote:
> For a negative `start_depth`, `JvmtiEnvBase::get_stack_trace(javaVFrame*, > ...)` first walks to the end of the stack, then walks again from a > `javaVFrame` it passed on the way. All `javaVFrame`s of one walk share the > `RegisterMap`'s stack chunk handle, and the first walk clears it when it > reaches the end of a continuation. If the frame it walks again from is in a > stack chunk, the second walk computes its sender as if it were on the thread > stack, and the VM crashes with a SIGSEGV in > `frame::sender_for_interpreter_frame()`. > > ### Changes > > - `get_stack_trace(JavaThread*, ...)` and > `GetStackTraceClosure::do_vthread()` convert a negative `start_depth` into > the equivalent positive one before they walk the stack. A new helper, > `start_depth_from_top()`, counts the frames with `get_frame_count()`, which > makes a separate walk. The stack trace is then taken by a fresh walk. > - `get_stack_trace(javaVFrame*, ...)` no longer handles a negative > `start_depth`. It asserts `start_depth >= 0`. > > The results do not change. In particular, a `-start_depth` greater than the > stack depth still returns `JVMTI_ERROR_ILLEGAL_ARGUMENT`. The negative-depth > path now walks the stack twice from the top. Before, it walked the stack once > and then part of it again. > > ### Relation to JDK-8398335 > > [JDK-8398335](https://bugs.openjdk.org/browse/JDK-8398335) (PR #34089) makes > `get_stack_trace(JavaThread*, ...)` walk with `WalkContinuation::include`, so > platform threads also walk into stack chunks. Without this fix, that change > exposes the crash for a platform thread that runs a `Continuation` that > resumed after a yield. This PR must integrate first. > > ### Testing > > New test > `serviceability/jvmti/thread/GetStackTrace/GetStackTraceNegativeDepthTest`: > - A virtual thread recurses 200 frames deep. It is checked while it is > unmounted (parked), and then from the thread itself after `Thread.yield()`, > when its frames below the top are still in the stack chunk. > - For start depths `-1`, `-3`, `-n/2`, `-(n-1)` and `-n`, with `max_count` > 1024 and 2, `GetStackTrace` must return the bottom frames of the full trace. > `-(n+1)` must return `JVMTI_ERROR_ILLEGAL_ARGUMENT`. > > Results on linux-x64 fastdebug: > > | Build | Test | Result | > | --- | --- | --- | > | without the fix | `GetStackTraceNegativeDepthTest` | fails: > `assert(_frame_index == -1) failed: Using absolute addresses with a chunk > frame` | > | with the fix | `GetStackTraceNegativeDepthTest` | passes with default > flags, `-Xint`, `-Xcomp`, `-XX:TieredStopAtLevel=1`, `-XX:+U... This pull request has been closed without being integrated. ------------- PR: https://git.openjdk.org/jdk/pull/34102
