If Java's garbage collector moves objects, what is Object.hashCode and System.identityHashCode?

后端 未结 3 1638
面向向阳花
面向向阳花 2021-02-02 07:18

I\'ve often heard that these methods (Object.hashCode and System.identityHashCode) return the address of the object, or something computed quickly from

3条回答
  •  孤街浪徒
    2021-02-02 07:59

    The identityHashCode does not change for an object. So any moving is done beneath that level.

    A rudimentary implementation would have a logical address --> physical address mapping for every object.

    More sophisticated implementations would only have the mapping at a page level, so perhaps the last 6 bits is the memory offset, and the rest are the page id. The indirection would happen at the page id --> actual page address level.

提交回复
热议问题