NOTE
Java Object Memory Layout
Conceptual object layout in HotSpot: headers, instance fields, alignment, compressed references, and why byte offsets are implementation-specific.
This is a historical learning note and may contain outdated or incomplete understanding.
1. Conceptual Layout
A HotSpot heap object is commonly described as containing:
- object-header metadata;
- class/type information, directly or indirectly;
- instance-field storage;
- optional padding for alignment.
Arrays additionally need length information.
2. Header Details Are Implementation-Specific
Header encoding, mark-word bits, compressed class pointers, compressed ordinary object pointers, alignment, and field placement depend on JVM build, architecture, flags, and JDK generation.
Do not hard-code historical diagrams as a permanent Java object format.
3. Field Layout
The JVM may arrange fields according to implementation rules rather than source declaration order. Padding can appear for alignment, and subclass layout adds further constraints.
4. Measuring Real Layout
When exact footprint matters, inspect the actual runtime with a suitable object-layout/profiling tool rather than calculating from one old rule of thumb. For application optimization, retained heap and object count are often more important than the size of one isolated object.