RFR: JDK-8253001: [JVMCI] Add API for getting stacktraces independently of current thread

Doug Simon dnsimon at openjdk.java.net
Thu Sep 17 14:29:34 UTC 2020


On Thu, 10 Sep 2020 11:52:34 GMT, Allan Gregersen <github.com+4676506+javeleon at openjdk.org> wrote:

> The idea is to add a more powerful API for cases where the current iterateFrames API cannot be used.
> 
> For example, a debugger needs access to the content of stack frames such as local variables or monitors. In cases where
> threads execute in the runtime or in native code, it's not possible to obtain a thread suspension hook, for which
> iterateFrames can be used on the suspended thread. The getStackFrames method enables an immediate stack frames lookup
> regardless of the status of the underlying thread. Another use case would be for lookup of backtraces for non-current
> threads.  The implementation is done by means of a VM operation that collects vframe data for each thread during a
> safepoint, whereafter required object reallocation/reassign fields is performed based on the collected snapshot.

@vnkozlov @veresov @dean-long it would be great to get some reviews of this soon. To assist, let me try provide a
little more context on the area of JVMCI which is motivated by
[Truffle](https://www.graalvm.org/truffle/javadoc/com/oracle/truffle/api/package-summary.html).

The
[`StackIntrospection.iterateFrames()`](https://github.com/openjdk/jdk/blob/6bab0f539fba8fb441697846347597b4a0ade428/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.code/src/jdk/vm/ci/code/stack/StackIntrospection.java#L45)
API exists for Truffle to support walking guest language frames. In Truffle, all values, including primitives, are
boxed which explains why there is no `InspectedFrame.setLocal(int index, Object value)` method. All Truffle guest
language frame locals are accessed/updated by reading/updating the boxed value returned by `InspectedFrame.getLocal()`.
With this existing API, a thread can only inspect its own stack frames.

As the description of this PR states, it extends `StackIntrospection.iterateFrames()` with
`StackIntrospection.getStackFrames()` so that a thread can inspect the frames of other threads. It is somewhat
analogous to `java.lang.Thread.getAllStackTraces()` except it allows the local variables of the frames to be accessed
as well.

src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.code/src/jdk/vm/ci/code/stack/StackIntrospection.java line 52:

> 50:      * that any client inspecting and possibly mutating the frame contents will do so under the
> 51:      * assumption that the underlying threads might have continued, executing potentially
> 52:      * invalidating the frame state.

"... might have continued, executing potentially invalidating the frame state."

Not sure what this is trying to say. Maybe you mean something like "... might have continued, in which case mutations
are not reflected in the running thread state."

src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.code/src/jdk/vm/ci/code/stack/StackIntrospection.java line 55:

> 53:      *
> 54:      * Note that the locals of the {@link InspectedFrame}s will be collected as copies when the
> 55:      * underlying frame was compiled, whereas they'll be references for interpreted frames. Use

"will be collected as copies when the underlying frame was compiled" - what does that mean?

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

PR: https://git.openjdk.java.net/jdk/pull/110


More information about the hotspot-compiler-dev mailing list