Interface | Description |
---|---|
AnnotationVisitor |
A visitor to visit a Java annotation.
|
ClassVisitor |
A visitor to visit a Java class.
|
FieldVisitor |
A visitor to visit a Java field.
|
MethodVisitor |
A visitor to visit a Java method.
|
Opcodes |
Defines the JVM opcodes, access flags and array type codes.
|
Class | Description |
---|---|
AnnotationWriter |
An
AnnotationVisitor that generates annotations in bytecode form. |
Attribute |
A non standard class, field, method or code attribute.
|
ByteVector |
A dynamically extensible vector of bytes.
|
ClassAdapter |
An empty
ClassVisitor that delegates to another ClassVisitor . |
ClassReader |
A Java class parser to make a
ClassVisitor visit an existing class. |
ClassWriter |
A
ClassVisitor that generates classes in bytecode form. |
Edge |
An edge in the control flow graph of a method body.
|
FieldWriter |
An
FieldVisitor that generates Java fields in bytecode form. |
Frame |
Information about the input and output stack map frames of a basic block.
|
Handler |
Information about an exception handler block.
|
Item |
A constant pool item.
|
Label |
A label represents a position in the bytecode of a method.
|
MethodAdapter |
An empty
MethodVisitor that delegates to another
MethodVisitor . |
MethodWriter |
A
MethodVisitor that generates methods in bytecode form. |
Type |
A Java type.
|
The ASM framework is organized
around the ClassVisitor
,
FieldVisitor
and
MethodVisitor
interfaces, which allow
one to visit the fields and methods of a class, including the bytecode
instructions of each method.
In addition to these main interfaces, ASM provides a ClassReader
class, that can parse an
existing class and make a given visitor visit it. ASM also provides
a ClassWriter
class, which is
a visitor that generates Java class files.
In order to generate a class from scratch, only the ClassWriter
class is necessary. Indeed,
in order to generate a class, one must just call its visitXXX
methods with the appropriate arguments to generate the desired fields
and methods. See the "helloworld" example in the ASM distribution for
more details about class generation.
In order to modify existing classes, one must use a ClassReader
class to analyze
the original class, a class modifier, and a ClassWriter
to construct the modified class. The class modifier
is just a ClassVisitor
that delegates most of the work to another ClassVisitor
, but that sometimes changes some parameter values,
or call additional methods, in order to implement the desired
modification process. In order to make it easier to implement such
class modifiers, ASM provides the ClassAdapter
and MethodAdapter
classes, which implement the ClassVisitor
and MethodVisitor
interfaces by
delegating all work to other visitors. See the "adapt" example in the ASM
distribution for more details about class modification.
The size of the core ASM library, asm.jar, is only 42KB, which is much smaller than the size of the BCEL library (504KB), and than the size of the SERP library (150KB). ASM is also much faster than these tools. Indeed the overhead of a load time class transformation process is of the order of 60% with ASM, 700% or more with BCEL, and 1100% or more with SERP (see the test/perf directory in the ASM distribution)!