32 bits header and alignment slack

Remi Forax forax at univ-mlv.fr
Sat Mar 2 10:25:28 UTC 2024


Hello,
I was try to read the code corresponding to the compact identity hashcode
  https://wiki.openjdk.org/display/lilliput/Compact+Identity+Hashcode

But I did not see any mention of the fact that due to object alignment, there is maybe already an empty 32 bits space at the end of the object.
By example, with a java.lang.Integer and a 64 bits header, due to alignment to 64 bits, there is 32 bits of space which is not used after the value of the Integer

  j.l.Integer layout
  mark word / 64 bits
  value / 32 bits
  empty / 32 bits

In that case, when System.identityHashCode() is called, it could use that space directly instead of waiting the GC to move the object to another location of the mostly same size.

Obviously, there is a good chance that this is exactly what the VM currently does and I've just missed that part :)

Rémi


More information about the lilliput-dev mailing list