Java字节码错误指令

4

我正在为自己的DSL编写字节码编译器。然而,当我执行用ASM构建的字节码时,出现了以下错误:

Exception in thread "main" java.lang.VerifyError: Bad instruction
Exception Details:
  Location:
    ForClass.doLoop()V @14: wide
  Reason:
    Error exists in the bytecode



Bytecode:
    0x0000000: 043c b200 101b b600 161b 0460 3c1b c411
    0x0000010: 03e8 a4ff f0b1                      

at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at Test3.main(Test3.java:28)

以下是要执行的指令:

mv.visitVarInsn(ILOAD, 1);
mv.visitVarInsn(SIPUSH, 1000);
mv.visitJumpInsn(IF_ICMPLE, l1);

问题似乎在于SIPUSH指令。如果我用BIPUSH, 10替换指令,一切都按预期工作。从字节码大纲获得的字节码使用SIPUSH没有问题,那么我做错了什么?
1个回答

2
解决方法很简单,我使用了错误的方法: 不要使用visitVarInsn(SIPUSH, 1000),而是使用visitIntInsn(SIPUSH, 1000)

似乎是一个常见问题 - Holger

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接