dabaicai
dabaicai

Reputation: 71

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. I would like to know the usefulness of hashcode.

Upvotes: 3

Views: 288

Answers (1)

Eugene
Eugene

Reputation: 120868

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.

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.

Upvotes: 1

Related Questions