gpt4 book ai didi

java - 调用方法时Java中的调用站点是什么?

转载 作者:行者123 更新时间:2023-11-30 10:18:14 26 4
gpt4 key购买 nike

我想了解什么是 JVM 中的调用站点。引自 https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.3.6

The result of call site specifier resolution is a tuple consisting of:

• the reference to an instance of java.lang.invoke.MethodHandle,

• the reference to an instance of java.lang.invoke.MethodType,

• the references to instances of Class, java.lang.invoke.MethodHandle, java.lang.invoke.MethodType, and String.

我们还有所谓的调用站点对象 https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.invokedynamic :

The result returned by the bootstrap method must be a reference to an object whose class is java.lang.invoke.CallSite or a subclass of java.lang.invoke.CallSite. This object is known as the call site object

调用站点对象的概念很清楚。这只是 CallSite 的一个实例。但是调用站点说明符呢?那是一个Java对象吗?那是 String 文字吗?

最佳答案

  • 动态调用站点invokedynamic的每次出现说明。

    Before the JVM can execute a dynamic call site (an invokedynamic instruction), the call site must first be linked. Linking is accomplished by calling a bootstrap method which is given the static information content of the call site, and which must produce a method handle that gives the behavior of the call site.

    // from java.lang.invoke package description

  • Call site specifier 是一个项目(从常量池中获取),描述如何链接给定的调用站点。

    没有具体说明这个项目到底是什么。
    JVMS 只告诉 symbolic reference 如何到调用站点说明符 looks like在常量池中。

    JVM 实现可以自由选择调用站点说明符的内部表示。它可以是堆中的一个对象,也可以是 native 内存中的一段元数据。例如,HotSpot JVM 将调用站点说明符缓存为 object array。其中第一个元素是表示引导方法的 MethodHandle 实例,其余元素是调用此引导方法的参数。

    无论调用站点说明符在 JVM 内部是如何实现的,当它被解析时,它应该产生一个永久绑定(bind)的调用站点对象(java.lang.invoke.CallSite 的一个实例)到动态调用站点。

关于java - 调用方法时Java中的调用站点是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49414207/

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