3 ms·
Does Java still have a word in every object allocation for locking it? Adding a 64-bit pointer sounds terribly inefficient. Did you know Objective-C does locks
by astrange 10y ago
Does Java still have a word in every object allocation for locking it? Adding a 64-bit pointer sounds terribly inefficient.
Did you know Objective-C does locks and retain counting without allocating any extra fields in objects?
- sbanach 10y agoOn hotspot: There are two bits in the header of every object. This is enough for an object that's never been used as a contended lock, CAS operations on the header can be used to handle the locking and that's that. As soon as you actually block on it, a 'real' lock is created (you can't get around the need for a list of threads to wake up as the lock is released) and the header grows to accomodate it. The process is called 'monitor inflation'. At a later date this might be cleaned up by a 'monitor deflation'.