r/java • u/persism2 • May 04 '23
JEP 450: Compact Object Headers (Experimental)
https://openjdk.org/jeps/450
93
Upvotes
4
u/Joram2 May 04 '23
This is a cool feature, it just got promoted to candidate status, but it looks a ways off. There are two other JEPs that have to be finished before this can be done as an experimental feature.
6
u/Slanec May 04 '23
JEPs? Rather two enhancements, I think, and both of them have an existing PR. Not bad, I'd say!
0
11
u/ascii May 05 '23 edited May 05 '23
Never realised each allocated Java object had an overhead of 12-16 bytes, that's fairly significant. I expected a compressed class pointer (4 bytes) and a few bits for the GC state. But it makes sense that with modern moving GCs, you also need to store an object identity, since you can no longer use the memory address, and of course I forgot about the rather peculiar choice of making every single object a lock, which comes with many kinds of overhead as well.
Thinking about this some more, it seems like it should be possible to replace the class pointer with a class index into an array containing all classes. Clearly, this would make class loaders tricky to implement, but doing so should make it straightforward to use around 20 bits for the class. Not that it matters much, you'd still use 64 bit for the header because of memory alignment.