'Doubts about the ClassReader and the accept method
I would like to know how the "optimization" described in the ASM user manual works.
I took a small snippet from the manual:
If a ClassReader component detects that a MethodVisitor returned by the ClassVisitor passed as argument to its accept method comes from a ClassWriter, this means that the content of this method will not be transformed, and will in fact not even be seen by the application. In this case the ClassReader component does not parse the content of this method, does not generate the corresponding events, and just copies the byte array representation of this method in the ClassWriter.
More precisely, I would like to know:
What events does the
ClassReadernot generate when theMethodVisitoris retrieving from aClassWriterand this is detected by the accept method?Theoretically the
ClassReaderis just an event producer. Can the accept method really "copy" the content of a method to theClassWriterof aClassVisitorthat was passed as a parameter or make any other type of modification?Is the
MethodVisitorreturned by thevisitMethodmethod really useful for anything? If yes, for what? I have this doubt because even returningnullin this method, my modifications occur normally without any kind of error.
Solution 1:[1]
If you pass the ClassReader, the ClassWriter can detect that a MethodVisitor is directly issued from the corresponding ClassReader. In this case, ASM does not deserialize and serialize a method but simply copied the entire methods representation from the class file.
Once you wrap a visitor, it goes back to deserializing and serializing.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rafael Winterhalter |
