A new proposal in the Java community is set to introduce an API specifically designed for processing Java class files. This initiative aims to create a standardized library for parsing, generating, and transforming Java class files, addressing several current limitations in the Java ecosystem. The proposed classfile API will initially replace the ASM Java bytecode manipulation framework, with a future goal of completely phasing out ASM from the JDK.
The proposal highlights that class file manipulation is a common requirement across many Java tools and libraries. Frameworks frequently perform on-the-fly bytecode instrumentation, which necessitates reliable and efficient class file processing capabilities. The new API aims to provide an accurate, complete, and up-to-date solution for reading, writing, and transforming class files, ensuring that it meets the performance standards needed for modern Java development.
Key design goals for the API include representing all class file entities, such as methods and fields, as immutable objects. This design choice supports user-driven navigation and helps maintain the integrity of class file representations. The motivation behind this proposal stems from several critical factors, including the need for consolidation within the JDK, current delays associated with the use of ASM, and version skew issues between frameworks and the running JDK.
One significant issue addressed by the proposal is the version mismatch between class file libraries bundled with frameworks and the evolving JDK. As new class file features are introduced in JDK updates, applications and frameworks often encounter class files that are not compatible with the libraries they use, leading to runtime errors or issues with parsing future class file formats. The new classfile API is designed to stay in sync with the running JDK, reducing such compatibility issues.
The evolution of the JVM and class file format has accelerated, with recent projects like Project Valhalla introducing new bytecodes, field descriptors, and verification rules. The new API aims to accommodate these changes, providing a more adaptable and future-proof solution. Additionally, the proposal acknowledges the advancements in the Java language since the ASM framework was developed, underscoring the need for an updated class file library.
Initially, the goal is to replace ASM as a runtime dependency of the JDK without compromising performance. The proposal also aims to replace the internal classreader library used by the compiler and JDK tools. In the long term, the new classfile API is expected to serve as a viable alternative to ASM, cglib, and other bytecode libraries, enhancing the efficiency and reliability of class file processing across various Java applications and frameworks.