Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why did object header size doubled in 64 bit architecture?

I can't really understand why did object header got twice bigger in 64 bit applications. The object header was 8 bytes and in 64 bit it is 16 what are these additional bytes used for ?

like image 543
Davit Karapetyan Avatar asked Sep 03 '16 18:09

Davit Karapetyan


1 Answers

The object header is made up of two fields, the syncblk and the method table pointer (aka "type handle"). Second field is easy to understand, it is a pointer so it must grow from 4 to 8 bytes in 64-bit mode.

The syncblk is the much less obvious case, it is mix of flags and values (lock owner thread id, hash code, sync block index). No reason to make it bigger in 64-bit mode. What matters is what happens after the object is collected by the GC. If the free space was not eliminated by compacting the heap then the object space participates in the free block list. Works like a doubly-linked list. The 2nd field is the forward pointer to the next free block. The object data space is used to store the size of the free block, basic reason why an object is never less than 12 bytes. And the syncblk stores the back pointer to the previous free block. So now it must be big enough to store a pointer and therefore needs to grow to 8 bytes. So it is 8 + 8 = 16 bytes.

Fwiw, the minimum object size in 64-bit mode is 24 bytes, even though 8 + 8 + 4 = 20 bytes would do just fine, just to ensure that everything is aligned to 8. Alignment matters a great deal, you'd never want to have a pointer value straddle the L1 cache line. Makes accessing it about x3 times slower. The <gcAllowVeryLargeObjects> option is another reason, added later.

like image 51
Hans Passant Avatar answered Oct 24 '22 20:10

Hans Passant