2016-09-29 30 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