简体   繁体   English

hashcode在java对象头中的作用是什么

[英]What's the role of hashcode in the java object header

There are 25 bits in the object header to identify the hashcode when a lock is in the state of lock-free. 当锁处于无锁状态时,对象头中有25位用于标识哈希码。 I would like to know the usefulness of hashcode. 我想知道hashcode的用处。

This is an implementation detail, as such the true definition is in the source code, for example these comments should explain some of those details. 这是一个实现细节,因此真正的定义在源代码中,例如这些注释应该解释其中的一些细节。

The default hashCode has 25 bits for a 32-bit VM (no idea where you got the 23 from) and 31 for a 64-bit VM. 对于32-bit VM,默认的hashCode有25位(不知道从哪里得到23 ),对于64-bit VM,默认hashCode 31 64-bit

I guess by lock-free state you mean biased locking, but it's either one or the other, not both at the same time, because simply there is no space in the mark work for both. 通过无锁状态你的意思是偏向锁定,但它是一个或另一个,而不是两个同时,因为标记中没有空间可以同时工作。

The usefulness is the same (whatever you mean by that) - it's just that since there are less bits there are higher collisions expected. 实用性是相同的(无论你的意思是什么) - 只是因为有较少的位,所以预期会有更高的冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM