ASM's ClassVisitor
constructor requires passing one of Opcodes
's ASM4
, ASM5
, ASM6
, ASM7
, ASM8
or ASM9
.
How do I know which ASM#
to use for each version of Java? What ASM#
would I use for Java 8? What ASM#
would I use for Java 11?
The JVM opcodes, access flags and array type codes. This interface does not define all the JVM opcodes because some opcodes are automatically handled. For example, the xLOAD and xSTORE opcodes are automatically replaced by xLOAD_n and xSTORE_n opcodes when possible. The xLOAD_n and xSTORE_n opcodes are therefore not defined in this interface.
The ASM API provides two styles of interacting with Java classes for transformation and generation: event-based and tree-based. 3.1. Event-based API This API is heavily based on the Visitor pattern and is similar in feel to the SAX parsing model of processing XML documents.
We can get the latest versions of asm and asm-util from Maven Central. 3. ASM API Basics The ASM API provides two styles of interacting with Java classes for transformation and generation: event-based and tree-based.
URI path versioning is the most common. This strategy involves putting the version number in the path of the URI, and is often done with the prefix "v". More often than not, API designers use it to refer to their application version (i.e. "trunk") rather than the endpoint version (i.e. "leaf" or "branch"), but that's not always a safe assumption.
The ASM…
constants describe the minimum ASM library version required by your software. This is crucial for compatibility, e.g. in the Visitor API, as when you’re overriding a method that does not exist in an older version, you wouldn’t notice when linking against an older version. The method would just never get called.
So, using the ASM…
constant allows to spot such issue earlier. That’s why some implementation classes offer a constructors not requiring the version number, not allowed for subclasses, whereas their constructor for subclasses does require it. As only subclasses can override methods, thus, are affected by this issue.
If you are not planning to use your software with an older version of the ASM library, just use the number corresponding to your current ASM library version, i.e. the highest without the EXPERIMENTAL
suffix. Otherwise, I suggest using the older version during development and testing, which again allows to just use the highest ASM…
number existing in that version.
You can use the newest ASM library to generate classes targeting all versions. It depends on the version you’re passing to the visit
method. Which is V1_8
for Java 8 and V11
for Java 11. The actual values of these constants are identical to the versions of the JVM specification.
As far as I know, no easy way, but the changelog of ASM helps a lot. Note that these versions refer to the ASM version, NOT the class file format version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With