GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • java.evolved
  • ←
  • →

This view

  • Original page
  • New address

GeezerVison is showing javaevolved.dev — Compact object headers | java.evolved

Home / Tooling / Compact object headers
Tooling Advanced

Compact object headers

  • 🐛 Report a code issue
  • 🌐 Report a translation issue
  • 💡 Suggest a new pattern

Cut object header size in half for better memory density and cache usage.

Performance Tooling
Code Comparison
✕ Java 8
// Default: 128-bit object header
// = 16 bytes overhead per object
// A boolean field object = 32 bytes!
// Mark word (64) + Klass pointer (64)
✓ Java 25
// -XX:+UseCompactObjectHeaders
// 64-bit object header
// = 8 bytes overhead per object
// 50% less header memory
// More objects fit in cache
Share 𝕏
See a problem with this code? Let us know.
Why the modern way wins
📦

50% smaller headers

8 bytes instead of 16 per object.

⚡

Better cache usage

More objects fit in CPU cache lines.

📊

Higher density

Fit more objects in the same heap size.

Old Approach
128-bit Headers
Modern Approach
64-bit Headers
Since JDK
25
Difficulty
Advanced
JDK Support
Compact object headers
Available

Finalized in JDK 25 LTS (JEP 519, Sept 2025).

How it works

Compact object headers reduce the per-object overhead from 128 bits to 64 bits on 64-bit platforms. This saves memory and improves cache utilization, especially for applications with many small objects.

Related Documentation
Compact Object Headers (JEP 519) ↗
Related patterns
Tooling Beginner

JShell for prototyping

Java 8
// 1. Create Test.java
// 2. javac Test.java
// 3. java Test
// Just to test one expression!
Java 9+
$ jshell
jshell> "hello".chars().count()
$1 ==> 5
jshell> List.of(1,2,3).reversed()
$2 ==> [3, 2, 1]
Hover to see modern ➜
JDK 9+ →
Tooling Beginner

Single-file execution

Java 8
$ javac HelloWorld.java
$ java HelloWorld
// Two steps every time
Java 11+
$ java HelloWorld.java
// Compiles and runs in one step
// Also works with shebangs:
#!/usr/bin/java --source 25
Hover to see modern ➜
JDK 11+ →
Tooling Intermediate

Multi-file source launcher

Java 8
$ javac *.java
$ java Main
// Must compile all files first
// Need a build tool for dependencies
Java 22+
$ java Main.java
// Automatically finds and compiles
// other source files referenced
// by Main.java
Hover to see modern ➜
JDK 22+ →
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.