2016-09-29 1 views
4

J'écris actuellement un compilateur bytecode pour mon propre DSL. Cependant, lors de l'exécution du bytecode, que je construisais avec ASM, je reçois l'erreur suivante:Java Bytecode Bad Instruction

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) 

Ce sont les instructions qui sont exécutées:

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

Les problèmes semble être le SIPUSH. Si je remplace l'instruction par BIPUSH, 10, tout fonctionne comme prévu. Le bytecode que j'ai reçu du contour bytecode utilise SIPUSH sans problème, alors qu'est-ce que je fais de mal?

Répondre

2

La solution est simple, j'ai utilisé une mauvaise méthode:

Au lieu d'utiliser visitVarInsn(SIPUSH, 1000), utilisez visitIntInsn(SIPUSH, 1000).

+0

Semble être un [problème commun] (http://stackoverflow.com/a/37751889/2711488) – Holger