为什么在ASM中使用f_same?

发布于 2025-02-02 00:35:25 字数 313 浏览 3 评论 0原文

在ASM中,f_same真正是什么? 我在,没有发现任何相关的东西。

我了解堆栈地图框架并节省空间。
但是,为什么在跳跃目标,例外处理程序或 遵循无条件的跳跃说明?
不过,不可能“预测”堆栈内容的类型吗?
使用此强制性吗?

我对此进行了很多搜索,但几乎在任何地方都找不到与之相关的任何内容。

谢谢你!

What is F_SAME really for in ASM?
I looked for this mnemonic in Java Virtual Machine Instruction Set and didn't find anything related.

I understand stack map frames and that they save space.
But, why is this mnemonic used precisely in cases of jump targets, exception handlers or
that follow unconditional jump instructions?
Still, it's not possible to "predict" the type of stack contents?
Is using this mandatory?

I searched a lot about this but I couldn't find anything related to it almost anywhere.

Thank you!

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

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

发布评论

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

评论(1

执妄 2025-02-09 00:35:25

这不是真正的操作码。源代码中的注释解释了:ASM特定的堆栈映射框架类型,在{@link classVisitor#visitframe}中使用。请记住,评论是错误的,并且访问框方法在方法视频中。

我想也许您想知道为什么这些帧出现在跳跃目标等。使用stackMaptableAttribute用于加快字母验证。验证者执行流量分析,以确保操作数堆栈和局部变量在所有基本块入口点都保持一致。在基本块中,随着每个说明访问,操作数堆栈和局部变量会逐渐更新。这些增量更新便宜,因此没有理由冗余地记录此信息。

在Java 1.6之前,验证者没有使用stackMaptableAttribute,但这迫使其对代码进行了更多通过以确保访问所有执行路径。

对您的问题的更精确的答案,为什么存在f_same?因为正如您所说,它比编码全帧小。

如果您使用ASM生成代码,则应使用Compute_maxs和Compute_frames选项,以便您不必担心此混乱。而且,如果您想更轻松地使用一些内容,请使用我写的Cojen/Maker库。

It's not a real opcode. The comment in the source code explains it: ASM specific stack map frame types, used in {@link ClassVisitor#visitFrame}. Bear in mind that the comment is wrong, and the visitFrame method is in MethodVisitor.

I think perhaps you're wondering why the frames appear at jump targets, etc. The StackMapTableAttribute is used to speed up bytecode verification. The verifier performs flow analysis to ensure that the operand stack and local variables are consistent at all basic block entry points. Within basic blocks, the operand stack and local variables are updated incrementally, as each instruction is visited. These incremental updates are cheap, and so there's no reason to record this information redundantly.

Before Java 1.6, the verifier didn't use the StackMapTableAttribute, but this forced it to perform more passes over the code to ensure that all execution paths were visited.

A more precise answer to your question, why does F_SAME exist? Because as you say, it's smaller than encoding a full frame.

If you're using ASM to generate code, then you should use the COMPUTE_MAXS and COMPUTE_FRAMES options so that you don't need to worry about this mess. And if you want to use something even easier, use the Cojen/Maker library that I wrote.

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