我一直在尝试编写一些 Java 字节码并使用 Jasmin 对其进行组装。
我正在尝试了解子例程,但不确定为什么在运行我的程序时会收到以下错误消息:
>java -jar jasmin.jar test.j
Generated: test.class
>java test
Exception in thread "main" java.lang.VerifyError: (class: test,
method: main signature: ([Ljava/lang/String;)V)
Cannot load return address from register 0
Could not find the main class: test. Program will exit.
这是 test.j 中的字节码:
.class public test
.super java/lang/Object
.method public static main([Ljava/lang/String;)V
.limit stack 6
.limit locals 5
jsr a ;Jump to subroutine 'a', pushing return address on operand stack
return ;Exit the program
a:
astore_0 ;Store the return address in variable 0
aload_0 ;Save the address onto the stack as address will be overwritten in 'b'
jsr b ;Jump to subroutine 'b', pushing return address on operand stack
astore_0 ;Store the address that was on the stack back into variable 0
ret 0 ;Return to just after "jsr a"
b:
astore_0 ;Store return address in variable 0
ret 0 ;Return to address stored in 0 (ie back to just after the jump in 'a')
.end method
我在跳转到单个子例程时没有遇到任何问题,但是从子例程内部跳转到子例程时似乎出了点问题。
任何关于失败原因的见解都将不胜感激!
最佳答案
关于Java 字节码子例程 - 无法加载返回地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8456048/