What is an “internal address” in Java?

后端 未结 4 2045
你的背包
你的背包 2020-11-27 15:50

In the Javadoc for Object.hashCode() it states

As much as is reasonably practical, the hashCode method defined by class Object does retur

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 16:28

    IMHO, although implementation dependent, Object references in JVM are never actual memory addresses, but internal JVM references that point to actual addresses. These internal references ARE generated initially based on memory address, but they remain associated with the object until it is discarded.

    I say this because Java HotSpot GCs are copying collectors of some form or the other, and they work by traversing live objects and copying them from one heap to the other, destroying the old heap subsequently. So when GC occurs, the JVM does not have to update the references in all objects, but just change the actual memory address mapped to the internal reference.

提交回复
热议问题