
A proposal promoting asynchronous stack traces in Java is advancing through the OpenJDK's Java enhancement process.
The plan, Asynchronous Stack Trace VM API, would define an AsyncGetStackTrace
API to collect stack traces asynchronously and include data on both Java and native stack frames.
Goals of the effort include provision of a well-tested API for profilers, which would obtain the Java native stack frames information, and support for asynchronous usage, such as calling from signal handlers.
As per the proposal, performance would not be affected when the API is not in use and memory requirements would not be significantly increased compared to the existing AsyncGetCallTrace
API. The new API would not be recommended for production use, because it could crash the JVM. Plans call for minimising the chances of that through extensive testing and fuzzing.
Currently, AsyncGetCallTrace
is used by most available profilers, both open source and commercial, including async-profiler. But it has two major disadvantages. It is an internal API, not exported in any header, and it only returns information about Java frames, namely their method and bytecode indices.
These issues make implementing profilers and related tools more difficult. Although additional information can be extracted from the HotSpot VM through complex code, other useful information remains hidden, such as whether a compiled Java frame is inlined, the compilation level of a Java frame, and information on C/C++ frames not at the top of the stack.
This data can be helpful for profiling and tuning a VM for a given application and for profiling code that heavily uses JNI (Java Native Interface).
The AsyncGetStackTrace
API would be modelled on the AsyncGetCallTrace
API. The new API has not yet been proposed for a specific version of standard Java. The next version of Java is Java Development Kit (JDK) 20, which is expected in March 2023.