All notes

· Per Lilja

Project Lilliput – how to make Java objects smaller

JEP 450 proposes compact object headers in HotSpot, shrinking them from 96–128 bits to 64 bits for potential 10–20% memory savings.

Initiating my programming journey with Java in 1997, I was immediately confronted with one of its principal challenges: the substantial memory footprint. In fact, my initial professional assignment was to optimize a Java application, focusing on both speed and size. Significant strides have been made to enhance Java’s performance and reduce memory consumption since then. However, the potential for further optimization remains.

The recent introduction of Project Lilliput, also known as JEP 450, represents an exciting advancement in this regard. This project proposes to decrease memory usage by 10–20% by reducing object headers. Currently in its experimental phase for the HotSpot JVM on x64 and ARM64, Project Lilliput advocates for compact object headers. The objective is to reduce the size of object headers in the HotSpot JVM from the current range of 96–128 bits to a more manageable 64 bits on 64-bit architectures. This reduction could lead to decreased heap size, increased deployment density, and improved data locality. The feature is deactivated by default but can be enabled with the UseCompactObjectHeaders option, potentially leading to 10–20% memory savings.

Under the leadership of Red Hat’s Roman Kennke, Project Lilliput aspires to identify techniques to downsize Java object headers in the HotSpot JVM from 16 bytes to 8 bytes, or even less. Object headers, in their current form, fulfil various roles, such as indicating an object’s locking state, tracking the age of objects during garbage collection, storing identity hash codes, and type information. The proposal explores several techniques for allocating and downsizing header fields, including the utilization of smaller object references, smaller mark words, and smaller class pointers.

The potential benefits of Project Lilliput are significant. In addition to reducing heap usage and increasing object allocation rates, the initiative could also reduce garbage collection activity and allow for tighter packing of objects. Furthermore, the project aims to enhance the flexibility of the header layout and permit some build or runtime configuration of bit utilization. A secondary objective even explores reducing the object header to 32 bits.

In conclusion, Project Lilliput (JEP 450) signifies a substantial and exciting development within the Java community. By reducing the size of object headers, Java could significantly enhance its memory utilization efficiency, leading to faster and more efficient applications. While the project remains in its experimental phase, it harbours the potential to dramatically revolutionize how Java applications are developed and deployed.

With tools and frameworks like GraalVM, Micronaut, Quarkus, etc., Java is taking another step toward becoming the cloud-native ecosystem.

For more detailed information on JEP 450, I encourage you to visit openjdk.org/jeps/450.

Have a hard problem? Let’s talk.

A 30-minute intro call, no pitch deck. You describe the problem, I tell you honestly whether I’m the right person for it.