为什么 Java 对象指针指向指针?

Why are Java objects pointers to pointers?

JVMS says that:

In some of Oracle’s implementations of the Java Virtual Machine, a reference to a class instance is a pointer to a handle that is itself a pair of pointers: one to a table containing the methods of the object and a pointer to the Class object that represents the type of the object, and the other to the memory allocated from the heap for the object data.

我不明白为什么引用会以这种方式实现,而不是使它们成为指向方法的指针 table 直接跟在对象数据之后的指针。这将避免对象创建时的额外内存分配和字段访问时的额外指针取消引用。

Oracle 以这种方式实施它们的原因是什么?

这样的策略将允许在内存中移动对象而无需调整所有现有引用,因为只需要调整一个直接指针。在内存中移动对象将通过复制或压缩垃圾收集器来完成。

然而,对于所有最近的 JVM 实现,这种间接的成本被认为不值得节省,因此“一些 Oracle 的实现”实际上意味着“Oracle 在购买 Sun 时获得的一些来自 Sun 的非常古老的 JVM”。在内存中移动对象时,当今现实世界的 JVM 确实会调整所有引用。

换句话说,这是关于仍在使用的 JVM 的过时声明,但作为替代实施策略的示例保留在规范中。