我正在为自己的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
没有问题,那么我做错了什么?