First, some background on COMPUTE_FRAMES and COMPUTE_MAXS
ClassWriter.COMPUTE_MAXS has a different function than ClassWriter.COMPUTE_FRAMES .
In recent versions of the JVM, classes contain a stack map along with method code. This map describes the stack layout at key points (jump targets) during the execution of the method. In previous versions of the JVM, you would have to compute this information, which is an expensive computing machine. By requesting this information, the JVM can simply check if frames work, which is much simpler than recalculating everything.
Of course, the compiler must generate these frames. This is also complicated, so ASM contains ClassWriter.COMPUTE_FRAMES to allow this - it will then calculate them for you.
Now ClassWriter.COMPUTE_MAXS does something similar: the JVM required the class files to indicate the maximum stack size and the number of variables that each method uses, so that it can just check this, instead of calculating them themselves. This is useful for the same reason as for stack frames: it is a less expensive calculation.
So you really want to ! But, as you said, it failed when you tried to add them. The likely answer is the documentation for ClassWriter.COMPUTE_FRAMES (this is the first place you should watch when embarrassed): it says "computeFrames means computeMaxs" . So just specify ClassWriter.COMPUTE_FRAMES .
First question
With MethodVisitor s, MethodVisitor calls are still required. It is at this point that ASM recounts frames and maximum values. He will simply ignore the arguments you give him. So no, you cannot delete them. (Also note that this is not actually an instruction.)
Second question
I explained above why using COMPUTE_FRAMES , which is the key part here. I don’t know exactly why specifying both flags will break your tests. If you can provide the exact code for what you did there, perhaps it will be possible. I did some source diving in the ClassWriter / MethodWriter , and there seems to be no reason why both pointers could break your code.
Cel skeggs
source share