当我尝试加载我使用ASM生成的类时,出现了预期的ClassVerifyErrors。 在进一步的检查中,我可以看到jvm是正确的,并且该方法正在讨论具有无效的MAX_STACK值。 奇怪的是我正在使用自动计算堆栈和最大本地选项,所以这不应该是一个问题......具有无效选项的方法非常简单,但结果是错误的字节码。
我写了一个预期方法的类,并将我的asm生成的类与javac生成的内容以及字节码匹配进行比较,唯一的错误是最大堆栈为0,这是错误的,而javac将值设置为2。
我喜欢避免必须自己计算最大堆栈/本地数据。
I am getting expected ClassVerifyErrors when attempting to load a class i have generated using ASM. On further inspection i can see that the jvm is correct and that the method is talking about has an invalid MAX_STACK value. THe strange thing is am using the auto calculate the stack and max local options so this should not be a problem... The method with the invalid option is very simple and yet the result is bad bytecode.
I have written a class with the intended method and compared my asm generated class against what javac produces and the byte codes matchup with the only error being the max stack is 0 which is wrong while javac sets a value of 2.
Id like to avoid having to calculate tha max stack/locals myself.
最满意答案
如果字节码无效,则最大堆栈和变量计算可能会产生错误的结果。 您可以通过运行生成的代码通过CheckClassAdapter来验证。
例如,
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); // generate code into cw instance... PrintWriter pw = new PrintWriter(System.out); CheckClassAdapter.verify(new ClassReader(cw.toByteArray()), true, pw);Max stack and variable calculation can produce the wrong results if bytecode is not valid. You can verify that by running generated code trough the CheckClassAdapter.
For example,
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); // generate code into cw instance... PrintWriter pw = new PrintWriter(System.out); CheckClassAdapter.verify(new ClassReader(cw.toByteArray()), true, pw);更多推荐
发布评论