2 ms·
Even in JDK 1.3 era I recognized that anyone could grab a lock on any object, not just the object itself, so that was a bit of a problem. I started experimenti
by hinkley 4y ago
Even in JDK 1.3 era I recognized that anyone could grab a lock on any object, not just the object itself, so that was a bit of a problem. I started experimenting with member variables called “lock” that were new Object(). It seemed pretty dumb at first but then I discovered lock splitting and it was off to the races. There’s always going to be some object with multiple concerns, especially if one or two functions involve both but others involve one (eg, add/delete versus generate data from the current state).
Am I misremembering that there was a time where the JRE lazily added locks to objects? I thought it was part of their long road to lock elision.
- mike_hearn 4y agoIt does. It's called lock inflation. The lock data structure is more than just a handful of bits, so the object header can point to the real lock once allocated. You don't pay a full lock for every object, just the memory needed to determine if it's in use or not.