程序启动时配置参数。
VM arguments:
-XX:hashCode=4
可选范围0~4,其他值都是else
look out又是一张拼图
native 方式表示是本地程序c语言实现的,不是java实现。
这里是内部实现
jdk: 源码
https://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/file/a3f01f9da231/src/share/vm/runtime/synchronizer.cpp
java程序
package demo;
public class HashCode {
public static void main(String[] args) {
String s1 = "hello";
String s2 = "world";
String s3 = "helloworld";
String s4 = s1+s2;
System.out.println(s3==s4);
System.out.println(s3.hashCode());
System.out.println(s4.hashCode());
System.out.println(System.identityHashCode(s3));
System.out.println(System.identityHashCode(s4));
}
}
默认配置和hashCode=5 else块代码一致结果
false
-1524582912
-1524582912
1829164700
2018699554
-XX:hashCode=0
This form uses an unguarded global Park-Miller RNG,
false
-1524582912
-1524582912
401056976
1760911346
-XX:hashCode=1
以后在其他client程序或者socket也许会见到
// This variation has the property of being stable (idempotent)
// between STW operations. This can be useful in some of the 1-0
// synchronization schemes.
false
-1524582912
-1524582912
1778440328
1778440415
-XX:hashCode=2
for sensitivity testing
false
-1524582912
-1524582912
1
1
-XX:hashCode=3
false
-1524582912
-1524582912
24
25
-XX:hashCode=4
false
-1524582912
-1524582912
1801201000
1801201600
-XX:hashCode=5 else块
false
-1524582912
-1524582912
1829164700
2018699554