Advancing Asynchronous Stack Traces in Java: A Proposal Under Review in OpenJDK
A new proposal aimed at enhancing Java’s debugging capabilities through asynchronous stack traces is currently making its way through the OpenJDK’s Java Enhancement Process. Known as the Asynchronous Stack Trace VM API, this initiative seeks to introduce an AsyncGetStackTrace
API that would facilitate the collection of stack traces in an asynchronous manner, incorporating both Java and native stack frames. The primary objectives of this effort include creating a robust API for profilers and accommodating asynchronous operations, such as those initiated from signal handlers.
One of the significant advantages of the proposed API is its design, which aims to ensure that performance remains unaffected when the API is not actively in use. Additionally, it strives to maintain memory requirements comparable to those of the existing AsyncGetCallTrace
API. While the new API is not intended for production environments due to potential risks, such as JVM crashes, the development team plans to mitigate these risks through rigorous testing and fuzzing techniques. This careful approach will help identify and address any issues before broader deployment.
At present, the AsyncGetCallTrace
API serves as the foundation for most profiling tools, both open-source and commercial, including the popular async-profiler. However, it has notable limitations, primarily being an internal API that lacks documentation in headers and only provides data regarding Java frames, such as method and bytecode indices. These constraints complicate the development of profilers and associated tools, as crucial information about the execution context and stack frames remains obscured.
The proposed AsyncGetStackTrace
API aims to address these shortcomings by revealing additional insights into Java frames, including compilation levels and details about C/C++ frames that may be further down the stack. Such information is invaluable for developers looking to optimize their applications, particularly those that leverage the Java Native Interface (JNI). By improving access to this data, the OpenJDK initiative could significantly enhance the profiling and performance tuning processes for Java applications, paving the way for more efficient and effective software development.