2016-09-29 22 views
4

我目前正在为自己的DSL编写一个字节码编译器。但是,在执行字节码,我与ASM构建的时候,我得到以下错误:Java字节码错误指令

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没有问题,所以我做错了什么?

回答

2

的解决方案是简单的,我使用的错误的方法:

代替使用visitVarInsn(SIPUSH, 1000)的,使用visitIntInsn(SIPUSH, 1000)

+0

似乎是一个[常见问题](http://stackoverflow.com/a/37751889/2711488) – Holger