Introduction to the ASM 2.0 Bytecode Framework
Pages: 1, 2, 3, 4, 5, 6, 7, 8
There are several other changes introduced in ASM 2.0.
- Introduced the new interfaces
FieldVisitorandAnnotationVisitor. CodeVisitorintoMethodVisitor.- New
visitCode()method added to theMethodVisitorto easily detect first instruction. Constantsinterface renamed intoOpcodes.- Almost all attributes from the
attrspackage are incorporated into ASM's event model. TreeClassAdapterandTreeCodeAdapterare incorporated into theClassNodeandMethodNode.- Introduced the
LabelNodeclass to make elements ofinstructionscollection common type ofAbstractInsnNode.
In general, it would be a good idea to run tool like JDiff and review the differences between the ASM 1.x and 2.0 APIs.
Conclusion
ASM 2.0 hides many bytecode complexities from the developer and allows one to efficiently work with Java features on a bytecode level. The framework allows you not only to transform and generate bytecode, but also to pull out significant details about existing classes. The API is being constantly improved--version 2.0 incorporates the generics and annotations introduced in J2SE 5.0. Since then, support for the new features introduced in Mustang (see "Java SE 6 Snapshot Releases") have been added to the ASM framework.
Resources
- Java Virtual Machine Specification
- "Revised Class File Format" (Chapter 4 of the JVM specification; PDF). Includes modifications for J2SE 5.0 to support changes mandated by JSR-14, JSR-175, and JSR-201, as well as minor corrections and adjustments.
- "Using the ASM Toolkit for Bytecode Manipulation"
- "Create and Read J2SE 5.0 Annotations with the ASM Bytecode Toolkit"
- Bytecode Instrumentation (BCI). Kelly O'Hair discusses challenges in bytecode instrumentation.
Eugene Kuleshov is an independent consultant with over 15 years of experience in software design and development.
Return to ONJava.com.