gpt4 book ai didi

java - invokeinterface - 计数值

转载 作者:行者123 更新时间:2023-12-01 17:44:57 26 4
gpt4 key购买 nike

我试图理解 JVM 字节码,但我遇到了以下代码:

58: invokeinterface #5,  1            // InterfaceMethod java/util/List.stream:()Ljava/util/stream/Stream;
63: invokedynamic #6, 0 // InvokeDynamic #0:test:()Ljava/util/function/Predicate;
68: invokeinterface #7, 2 // InterfaceMethod java/util/stream/Stream.filter:(Ljava/util/function/Predicate;)Ljava/util/stream/Stream;

看起来count值总是nargs + 1(在58中:应该是0但是是1,在68中:应该是1但是是2)。

根据JVM doc :

The count operand is an unsigned byte that must not be zero

这就是为什么许多参数看起来是 nargs + 1 的原因吗?

最佳答案

this 对象(在 JVMS 中称为 objectref)始终是 invokeinterface 的第一个隐式参数。它与其他 nargs 参数一起在操作数堆栈上传递。

事实上,count并不是参数的数量,而是传递参数所需的堆栈槽的数量。实际上,现代 JVM 通常不使用该字节,请参阅 notes :

The count operand of the invokeinterface instruction records a measure of the number of argument values, where an argument value of type long or type double contributes two units to the count value and an argument of any other type contributes one unit. This information can also be derived from the descriptor of the selected method. The redundancy is historical.

关于java - invokeinterface - 计数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56644884/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com