r/java • • Apr 13 '20

Java Objects Inside Out: Everything You Ever Wanted to Know About Java Object Internals in Hotspot

https://shipilev.net/jvm/objects-inside-out/
160 Upvotes

14 comments sorted by

View all comments

4

u/Polygnom Apr 14 '20

Quite interesting and helpful.

Something I wonder about is #4, especially word tearing and booleans wrt. records. Records are immutable. So in principle it should be possible to represent booleans inside records as exactly one bit, since concurrent writes simply aren't a problem, right?

3

u/shipilev Apr 14 '20

Yes, in principle. Practice would probably reveal lots of weird corner cases. For example, Java can still write to the otherwise final field with Reflection, which leaves the fields that are conceptually immutable still being mutable. Plus, as mentioned in the sidebar, it still leaves the problem how to address those individual fields on VM side. These things are not insurmountable, but they can tilt the cost/benefit unfavorably.