Java 字节码子例程 - 无法加载返回地址

发布于 2024-12-20 13:01:53 字数 1215 浏览 1 评论 0原文

我一直在尝试编写一些 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

我在跳转到单个子例程时没有遇到任何问题,但它从子例程内跳转到子例程时似乎出现了问题。

任何关于为什么失败的见解将不胜感激!

I have been trying to write some Java bytecode and assemble it using Jasmin.

I am trying to get my head around subroutines, and am not sure why I obtain the following error message when running my program:

>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.

Here's the bytecode in 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

I haven't had any problems with jumping to a single subroutine, but it seems as though something is going wrong when jumping to a subroutine from within a subroutine.

Any insight as to why this is failing would be much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若无相欠,怎会相见 2024-12-27 13:01:53

您无法将地址类型值加载到任何寄存器中,您只能存储它,然后 ret 指令可以从那里检索它。

Java 虚拟机规范:

You can't load an address type value into any register, you can only store it and then ret instruction can retrieve it from there.

Java Virtual Machine Specification:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文