Project Lilliput
Goals
- Reduce the object header to 64 bits. It may be possible to shrink it down to 32 bits as a secondary goal.
- Make the header layout more flexible, i.e. allow some build-time (possibly even run-time) configuration of how we use the bits.
Motivation
In 64-bit Hotspot, Java objects have an object header of 128 bits: a 64 bit multi-purpose header (‘mark’ or ‘lock’) word and a 64-bit class pointer. With typical average object sizes of 5-6 words, this is quite significant: 2 of those words are always taken by the header. If it were possible to reduce the size of the header, we could significantly reduce memory pressure, which directly translates to one or more of (depending what you care about or what your workload does):
Reduced heap usage
Higher object allocation rate
Reduced GC activity
Tighter packing of objects -> better cache locality
In other words, we could reduce the overall CPU and/or memory usage of all Java workloads, whether it's a large in-memory database or a small containerized application.
Current situation
The object header (in 64 bit Hotspot builds) is currently 128 bits long. The first 64 bits are the so-called 'lock' or 'mark' word, the subsequent 64 bits are the class-pointer.
+------------------+ | Lock-word | +------------------+ | Class pointer | +------------------+ | Field 1 | +--------+---------+ | Field 2| Field 3 | +--------+---------+ | etc |
For arrays, we will reserve an additional field for the arraylength:
+------------------+ | Lock-word | +------------------+ | Class pointer | +------------------+ | Array-Length | +--------+---------+ | Elem 1 | Elem 2 | +--------+---------+ | etc |
The lock/mark word
The lock word (for simplicity I'll continue to call it that, even if it's grossly imprecise) is overloaded with various purpuses:
Locking: The 3 lowest bits are used for locking, and can take the following combinations:
[ ptr | 00 ]
Locked, the upper bits interpreted as a pointer point to real header on stack[ header | 0 | 01 ]
Unlocked, upper bits are regular object header[ ptr | 10 ]
Monitor, the upper bits point to inflated lock, header is swapped out[ 0 ...... 0 | 00 ]
Inflating in progress[ ptr | 11 ]
Forwarded, used by GC to indicate that upper bits point to forwarded object, which also contains the real header
Resources
- Lilliput Project
- Repository
- Mailing list: lilliput-dev (archives)