首先,看看Object的hashCode注释吧。
根据上图注释来解释,红框内容说明hashCode返回值与对象内存地址有一定关系。但是看看open-jdk源码就会发现,hashCode可不这么简单。
static inline intptr_t get_next_hash(Thread * Self, oop obj) {
intptr_t value = 0 ;
if (hashCode == 0) {
// This form uses an unguarded global Park-Miller RNG,
// so it's possible for two threads to race and generate the same RNG.
// On MP system we'll have lots of RW access to a global, so the
// mechanism induces lots of coherency traffic.
value = os::random