What's the default hash value of an object on 64 bit JVM

后端 未结 5 1687
慢半拍i
慢半拍i 2020-12-17 07:40

Since default hash value of an object is the object address of the object, on 32-bit machine, it makes sense considering hash value is an int value. My question is that on 6

5条回答
  •  没有蜡笔的小新
    2020-12-17 08:08

    As far as I know and test, the most reliable way to get native address from JVM internal addess in case of compressed-oops mode, is using "getNarrowOopBase" and "getNarrowOopShift" methods of "sun.jvm.hotspot.memory.Universe" class and that class can be available in case of using "Java HotSpot Serviceability Agent".

    Native address can be calculated as:

    if (compressedRef) {
        return (address >> compressRefShift) - compressRefBase;
    } 
    else {
        return address;
    }
    

    Here are usages of it

    https://github.com/serkan-ozal/jillegal/blob/master/src/main/java/tr/com/serkanozal/jillegal/util/HotspotJvmInfoUtil.java

    https://github.com/serkan-ozal/jillegal/blob/master/src/main/java/tr/com/serkanozal/jillegal/util/JvmUtil.java

提交回复
热议问题