这里说的是Java对象的hashCode()方法。

我们打开Java对象的hashCode()源码

public native int hashCode();
它是一个native方法,不是java的内部实现,是调用系统的内部实现。

这个方法解释如下

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.
The general contract of hashCode is:
Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
It is not required that if two objects are unequal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java™ programming language.)
Returns:
a hash code value for this object.
See Also:
equals(Object), System.identityHashCode
直接过来是:

指示其他对象是否“等于”此对象。
equals方法在非空对象引用上实现等价关系:
它是自反的:对于任何非空引用值x,x.equals(x)应返回true。
它是对称的:对于任何非空引用值x和y,x.equals(y)应返回true,当且仅当y.equals(x)返回true。
它是可传递的:对于任何非空引用值x、y和z,如果x.equals(y)返回true,而y.equals(z)返回true则x.equals(z)应返回true。
它是一致的:对于任何非空引用值x和y,如果不修改对象上的equals比较中使用的信息,则多次调用x.equals(y)始终返回true或始终返回false。
对于任何非空引用值x,x.equals(null)应返回false。
类Object的equals方法在对象上实现了最有区别的可能等价关系;也就是说,对于任何非空引用值x和y,当且仅当x和y引用同一对象(x==y的值为true)时,此方法返回true。
注意,每当重写hashCode方法时,通常需要重写该方法,以便维护hashCode方法的通用约定,该约定规定相等的对象必须具有相等的哈希代码。
参数:
obj–要与之比较的引用对象。
返回值:
如果此对象与obj参数相同,则为true;否则为false。

源码实现

static inline intptr_t get_next_hash(Thread * Self, oop obj) {
  intptr_t value = 0 ;
  if (hashCode == 0) {
    // 根据Park-Miller伪随机数生成器生成的随机数
     value = os::random() ;
  } else
  if (hashCode == 1) {
     // 此类方案将对象的内存地址,做移位运算后与一个随机数进行异或得到结果
     intptr_t addrBits = cast_from_oop<intptr_t>(obj) >> 3 ;
     value = addrBits ^ (addrBits >> 5) ^ GVars.stwRandom ;
  } else
  if (hashCode == 2) {
     value = 1 ;            // 返回固定的1
} else
  if (hashCode == 3) {
     value = ++GVars.hcSequence ;  // 返回一个自增序列的当前值
  } else
  if (hashCode == 4) {
     value = cast_from_oop<intptr_t>(obj) ;  // 对象地址
  } else {
     // 通过和当前线程有关的一个随机数+三个确定值
     unsigned t = Self->_hashStateX ;
     t ^= (t << 11) ;
     Self->_hashStateX = Self->_hashStateY ;
     Self->_hashStateY = Self->_hashStateZ ;
     Self->_hashStateZ = Self->_hashStateW ;
     unsigned v = Self->_hashStateW ;
     v = (v ^ (v >> 19)) ^ (t ^ (t >> 8)) ;
     Self->_hashStateW = v ;
     value = v ;
  }

  value &= markOopDesc::hash_mask;
  if (value == 0) value = 0xBAD ;
  assert (value != markOopDesc::no_hash, "invariant") ;
  TEVENT (hashCode: GENERATE) ;
  return value;
}