-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathcompact-object-headers.html
More file actions
322 lines (306 loc) · 13.2 KB
/
compact-object-headers.html
File metadata and controls
322 lines (306 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Compact object headers | java.evolved</title>
<meta name="description" content="Cut object header size in half for better memory density and cache usage.">
<meta name="robots" content="index, follow">
<link rel="canonical" href="https://javaevolved.github.io/compact-object-headers.html">
<link rel="stylesheet" href="styles.css">
<link rel="icon" href="favicon.svg" type="image/svg+xml">
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#f97316">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="java.evolved">
<meta property="og:title" content="Compact object headers | java.evolved">
<meta property="og:description" content="Cut object header size in half for better memory density and cache usage.">
<meta property="og:url" content="https://javaevolved.github.io/compact-object-headers.html">
<meta property="og:type" content="article">
<meta property="og:site_name" content="java.evolved">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://javaevolved.github.io/images/social-card.png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:type" content="image/png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Compact object headers | java.evolved">
<meta name="twitter:description" content="Cut object header size in half for better memory density and cache usage.">
<meta name="twitter:image" content="https://javaevolved.github.io/images/social-card.png">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "TechArticle",
"headline": "Compact object headers",
"description": "Cut object header size in half for better memory density and cache usage.",
"url": "https://javaevolved.github.io/compact-object-headers.html",
"publisher": {
"@type": "Organization",
"name": "java.evolved",
"url": "https://javaevolved.github.io"
},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://javaevolved.github.io/compact-object-headers.html"
}
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "Home",
"item": "https://javaevolved.github.io/"
},
{
"@type": "ListItem",
"position": 2,
"name": "Tooling",
"item": "https://javaevolved.github.io/?cat=tooling"
},
{
"@type": "ListItem",
"position": 3,
"name": "Compact object headers"
}
]
}
</script>
</head>
<body data-page="single">
<nav>
<div class="nav-inner">
<a href="/" class="logo">java.<span>evolved</span></a>
<div class="nav-right">
<a href="https://github.com/javaevolved/javaevolved.github.io" target="_blank" rel="noopener" class="github-link" aria-label="View on GitHub">
<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor">
<circle cx="10" cy="10" r="9" fill="none" stroke="currentColor" stroke-width="1.5"/>
<path d="M10 3C6.13 3 3 6.13 3 10c0 3.09 2 5.71 4.77 6.63.35.06.48-.15.48-.33v-1.16c-1.95.42-2.36-1.07-2.36-1.07-.32-.81-.78-1.03-.78-1.03-.64-.43.05-.42.05-.42.7.05 1.07.72 1.07.72.63 1.08 1.65.77 2.05.59.06-.46.24-.77.44-.95-1.57-.18-3.22-.78-3.22-3.48 0-.77.27-1.4.72-1.89-.07-.18-.31-.9.07-1.87 0 0 .59-.19 1.93.72.56-.16 1.16-.24 1.76-.24s1.2.08 1.76.24c1.34-.91 1.93-.72 1.93-.72.38.97.14 1.69.07 1.87.45.49.72 1.12.72 1.89 0 2.71-1.65 3.3-3.23 3.47.25.22.48.65.48 1.31v1.94c0 .19.13.4.48.33C15 15.71 17 13.09 17 10c0-3.87-3.13-7-7-7z"/>
</svg>
</a>
<a href="/" class="back-link">← All patterns</a>
<div class="nav-arrows">
<a href="/jfr-profiling.html" aria-label="Previous pattern">←</a>
<a href="/aot-class-preloading.html" aria-label="Next pattern">→</a>
</div>
</div>
</div>
</nav>
<article class="article">
<div class="breadcrumb">
<a href="/">Home</a>
<span class="sep">/</span>
<a href="/?cat=tooling">Tooling</a>
<span class="sep">/</span>
<span>Compact object headers</span>
</div>
<div class="tip-header">
<div class="tip-meta">
<span class="badge tooling">Tooling</span>
<span class="badge advanced">advanced</span>
</div>
<h1>Compact object headers</h1>
<p>Cut object header size in half for better memory density and cache usage.</p>
</div>
<section class="compare-section">
<div class="section-label">Code Comparison</div>
<div class="compare-container">
<div class="compare-panel old-panel">
<div class="compare-panel-header">
<span class="compare-tag old">✕ Java 8</span>
<button class="copy-btn" data-code="old">Copy</button>
</div>
<div class="compare-code">
<pre class="code-text">// Default: 128-bit object header
// = 16 bytes overhead per object
// A boolean field object = 32 bytes!
// Mark word (64) + Klass pointer (64)</pre>
</div>
</div>
<div class="compare-panel modern-panel">
<div class="compare-panel-header">
<span class="compare-tag modern">✓ Java 25</span>
<button class="copy-btn" data-code="modern">Copy</button>
</div>
<div class="compare-code">
<pre class="code-text">// -XX:+UseCompactObjectHeaders
// 64-bit object header
// = 8 bytes overhead per object
// 50% less header memory
// More objects fit in cache</pre>
</div>
</div>
</div>
</section>
<section class="why-section">
<div class="section-label">Why the modern way wins</div>
<div class="why-grid">
<div class="why-card">
<div class="why-icon">📦</div>
<h3>50% smaller headers</h3>
<p>8 bytes instead of 16 per object.</p>
</div>
<div class="why-card">
<div class="why-icon">⚡</div>
<h3>Better cache usage</h3>
<p>More objects fit in CPU cache lines.</p>
</div>
<div class="why-card">
<div class="why-icon">📊</div>
<h3>Higher density</h3>
<p>Fit more objects in the same heap size.</p>
</div>
</div>
</section>
<div class="info-grid">
<div class="info-card">
<div class="info-label">Old Approach</div>
<div class="info-value red">128-bit Headers</div>
</div>
<div class="info-card">
<div class="info-label">Modern Approach</div>
<div class="info-value green">64-bit Headers</div>
</div>
<div class="info-card">
<div class="info-label">Since JDK</div>
<div class="info-value accent">25</div>
</div>
<div class="info-card">
<div class="info-label">Difficulty</div>
<div class="info-value blue">advanced</div>
</div>
</div>
<section class="bs-section">
<div class="section-label">JDK Support</div>
<div class="bs-card">
<div class="bs-feature-name">Compact object headers</div>
<span class="baseline-badge widely">Available</span>
<p class="bs-desc">Finalized in JDK 25 LTS (JEP 519, Sept 2025).</p>
</div>
</section>
<section class="explanation">
<h2>How it works</h2>
<p>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.</p>
</section>
<section class="related">
<h2>Related patterns</h2>
<div class="related-grid">
<a href="/jshell-prototyping.html" class="tip-card">
<div class="tip-card-body">
<div class="tip-card-header">
<div class="tip-badges">
<span class="badge tooling">Tooling</span>
<span class="badge beginner">beginner</span>
</div>
</div>
<h3>JShell for prototyping</h3>
</div>
<div class="card-code">
<div class="card-code-layer old-layer">
<div class="mini-label">Java 8</div>
<pre class="code-text">// 1. Create Test.java
// 2. javac Test.java
// 3. java Test
// Just to test one expression!</pre>
</div>
<div class="card-code-layer modern-layer">
<div class="mini-label">Java 9+</div>
<pre class="code-text">$ jshell
jshell> "hello".chars().count()
$1 ==> 5
jshell> List.of(1,2,3).reversed()
$2 ==> [3, 2, 1]</pre>
</div>
<span class="hover-hint">Hover to see modern ➜</span>
</div>
<div class="tip-card-footer">
<span class="browser-support"><span class="dot"></span>JDK 9+</span>
<span class="arrow-link">→</span>
</div>
</a>
<a href="/single-file-execution.html" class="tip-card">
<div class="tip-card-body">
<div class="tip-card-header">
<div class="tip-badges">
<span class="badge tooling">Tooling</span>
<span class="badge beginner">beginner</span>
</div>
</div>
<h3>Single-file execution</h3>
</div>
<div class="card-code">
<div class="card-code-layer old-layer">
<div class="mini-label">Java 8</div>
<pre class="code-text">$ javac HelloWorld.java
$ java HelloWorld
// Two steps every time</pre>
</div>
<div class="card-code-layer modern-layer">
<div class="mini-label">Java 11+</div>
<pre class="code-text">$ java HelloWorld.java
// Compiles and runs in one step
// Also works with shebangs:
#!/usr/bin/java --source 25</pre>
</div>
<span class="hover-hint">Hover to see modern ➜</span>
</div>
<div class="tip-card-footer">
<span class="browser-support"><span class="dot"></span>JDK 11+</span>
<span class="arrow-link">→</span>
</div>
</a>
<a href="/multi-file-source.html" class="tip-card">
<div class="tip-card-body">
<div class="tip-card-header">
<div class="tip-badges">
<span class="badge tooling">Tooling</span>
<span class="badge intermediate">intermediate</span>
</div>
</div>
<h3>Multi-file source launcher</h3>
</div>
<div class="card-code">
<div class="card-code-layer old-layer">
<div class="mini-label">Java 8</div>
<pre class="code-text">$ javac *.java
$ java Main
// Must compile all files first
// Need a build tool for dependencies</pre>
</div>
<div class="card-code-layer modern-layer">
<div class="mini-label">Java 22+</div>
<pre class="code-text">$ java Main.java
// Automatically finds and compiles
// other source files referenced
// by Main.java</pre>
</div>
<span class="hover-hint">Hover to see modern ➜</span>
</div>
<div class="tip-card-footer">
<span class="browser-support"><span class="dot"></span>JDK 22+</span>
<span class="arrow-link">→</span>
</div>
</a>
</div>
</section>
</article>
</section>
<div class="social-share">
<span class="share-label">Share</span>
<a href="https://x.com/intent/tweet?url=https%3A%2F%2Fjavaevolved.github.io%2Fcompact-object-headers.html&text=Compact%20object%20headers%20%E2%80%93%20java.evolved" target="_blank" rel="noopener" class="share-btn share-x" aria-label="Share on X">𝕏</a>
<a href="https://bsky.app/intent/compose?text=Compact%20object%20headers%20%E2%80%93%20java.evolved%20https%3A%2F%2Fjavaevolved.github.io%2Fcompact-object-headers.html" target="_blank" rel="noopener" class="share-btn share-bsky" aria-label="Share on Bluesky">🦋</a>
<a href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fjavaevolved.github.io%2Fcompact-object-headers.html" target="_blank" rel="noopener" class="share-btn share-li" aria-label="Share on LinkedIn">in</a>
<a href="https://www.reddit.com/submit?url=https%3A%2F%2Fjavaevolved.github.io%2Fcompact-object-headers.html&title=Compact%20object%20headers%20%E2%80%93%20java.evolved" target="_blank" rel="noopener" class="share-btn share-reddit" aria-label="Share on Reddit">⬡</a>
</div>
<footer>
<p>A project by <a href="https://github.com/brunoborges" target="_blank" rel="noopener">Bruno Borges</a></p>
<p><a href="https://github.com/javaevolved/javaevolved.github.io" target="_blank" rel="noopener">View on GitHub</a></p>
</footer>
<script src="app.js"></script>
</body>
</html>