ASM(来自ObjectWeb)即使设置了ClassWriter(COMPUTE

编程入门 行业动态 更新时间:2024-10-28 22:23:42
ASM(来自ObjectWeb)即使设置了ClassWriter(COMPUTE_MAX + COMPUTE_STACK),也不能正确计算MaxStack(ASM (from ObjectWeb) not calculating MaxStack correctly even though ClassWriter( COMPUTE_MAX + COMPUTE_STACK ) is set)

当我尝试加载我使用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);

更多推荐

本文发布于:2023-08-03 15:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1393496.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ObjectWeb   ASM   COMPUTE   ClassWriter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!