gpt4 book ai didi

java - 什么是 native 指针和返回地址?

转载 作者:行者123 更新时间:2023-11-30 02:50:59 26 4
gpt4 key购买 nike

我正在阅读 JVM 的内部结构 here并遇到了“ native 指针”这个术语,它是什么意思,它与 JNI 有关吗?

在上面的文本中,它讨论了程序计数器并说:

Each thread of a running program has its own pc register, or program counter, which is created when the thread is started. The pc register is one word in size, so it can hold both a native pointer and a returnAddress. As a thread executes a Java method, the pc register contains the address of the current instruction being executed by the thread. An "address" can be a native pointer or an offset from the beginning of a method's bytecodes. If a thread is executing a native method, the value of the pc register is undefined.

据我了解,returnAddress 可以是任何引用地址。喜欢:Object o = new Object(); 这里 o 将返回在堆中创建的对象的地址。我的理解正确吗?

任何解释两者的例子都会很棒。

最佳答案

here o would return the address of the Object created in the heap.

变量o存储一个引用。它是该对象唯一的查找值。它可能是地址,但也可能是可以转换为地址的值。例如64 位 JVM 可以使用 32 位引用,最大可达 64 GB 堆,并使用转换后的值。

what does it mean, does it has something to do with JNI?

CPU 使用指针来寻址内存。为了区别于引用,它在 Java 中被称为“ native ”指针。

JNI 是使用指针的 C 代码的接口(interface)。

JVM 的程序计数器是虚拟机中的概念,Java 程序无法访问。

实际的机器代码使用由 CPU 管理的程序计数器。即使这是一些抽象的东西,因为 CPU 可以在每个时钟周期执行多条指令,因此在任何时刻,程序计数器都只是您无法回滚的点,或者它取决于正在执行的指令。

关于java - 什么是 native 指针和返回地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38672839/

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