14

As far as I know an object's hash code is normally stored in the header word of the object, which, for example, may have the following layout in HotSpot:

|  hash code  | age | 0 | 01 |

According to the HotSpotInternals - Synchronization with biased locking enabled the header word layout looks in the following way:

|   0   |epoch| age | 0 | 01 |

Where does the hash code is then actually stored if needed when biased locking is enabled?

1 Answer 1

15

My understanding is that asking for the (identity) hashcode prevents biased locking - as we cannot store both the hashcode and thread id in the mark word. If you ask for the hashcode of the mutex you transfer to unbiased locking mode.

This is supported by the following taken from this blog:

"Finally, there's not currently space in the mark word to support both an identity hashCode() value as well as the thread ID needed for the biased locking encoding. Given that, you can avoid biased locking on a per-object basis by calling System.identityHashCode(o). If the object is already biased, assigning an identity hashCode will result in revocation, otherwise, the assignment of a hashCode() will make the object ineligible for subsequent biased locking. This property is an artifact of our current implementation, of course."

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.