|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <title>AOT class preloading | java.evolved</title> |
| 7 | + <meta name="description" content="Cache class loading and compilation for instant startup."> |
| 8 | + <meta name="robots" content="index, follow"> |
| 9 | + <link rel="canonical" href="https://javaevolved.github.io/aot-class-preloading.html"> |
| 10 | + <link rel="stylesheet" href="styles.css"> |
| 11 | + <link rel="icon" href="favicon.svg" type="image/svg+xml"> |
| 12 | + <link rel="manifest" href="manifest.json"> |
| 13 | + <meta name="theme-color" content="#f97316"> |
| 14 | + <meta name="mobile-web-app-capable" content="yes"> |
| 15 | + <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> |
| 16 | + <meta name="apple-mobile-web-app-title" content="java.evolved"> |
| 17 | + |
| 18 | + <meta property="og:title" content="AOT class preloading | java.evolved"> |
| 19 | + <meta property="og:description" content="Cache class loading and compilation for instant startup."> |
| 20 | + <meta property="og:url" content="https://javaevolved.github.io/aot-class-preloading.html"> |
| 21 | + <meta property="og:type" content="article"> |
| 22 | + <meta property="og:site_name" content="java.evolved"> |
| 23 | + <meta property="og:locale" content="en_US"> |
| 24 | + |
| 25 | + <meta name="twitter:card" content="summary"> |
| 26 | + <meta name="twitter:title" content="AOT class preloading | java.evolved"> |
| 27 | + <meta name="twitter:description" content="Cache class loading and compilation for instant startup."> |
| 28 | + |
| 29 | + <script type="application/ld+json"> |
| 30 | + { |
| 31 | + "@context": "https://schema.org", |
| 32 | + "@type": "TechArticle", |
| 33 | + "headline": "AOT class preloading", |
| 34 | + "description": "Cache class loading and compilation for instant startup.", |
| 35 | + "url": "https://javaevolved.github.io/aot-class-preloading.html", |
| 36 | + "publisher": { |
| 37 | + "@type": "Organization", |
| 38 | + "name": "java.evolved", |
| 39 | + "url": "https://javaevolved.github.io" |
| 40 | + }, |
| 41 | + "mainEntityOfPage": { |
| 42 | + "@type": "WebPage", |
| 43 | + "@id": "https://javaevolved.github.io/aot-class-preloading.html" |
| 44 | + } |
| 45 | +} |
| 46 | + </script> |
| 47 | + <script type="application/ld+json"> |
| 48 | + { |
| 49 | + "@context": "https://schema.org", |
| 50 | + "@type": "BreadcrumbList", |
| 51 | + "itemListElement": [ |
| 52 | + { |
| 53 | + "@type": "ListItem", |
| 54 | + "position": 1, |
| 55 | + "name": "Home", |
| 56 | + "item": "https://javaevolved.github.io/" |
| 57 | + }, |
| 58 | + { |
| 59 | + "@type": "ListItem", |
| 60 | + "position": 2, |
| 61 | + "name": "Tooling", |
| 62 | + "item": "https://javaevolved.github.io/?cat=tooling" |
| 63 | + }, |
| 64 | + { |
| 65 | + "@type": "ListItem", |
| 66 | + "position": 3, |
| 67 | + "name": "AOT class preloading" |
| 68 | + } |
| 69 | + ] |
| 70 | +} |
| 71 | + </script> |
| 72 | +</head> |
| 73 | +<body data-page="single"> |
| 74 | + <nav> |
| 75 | + <div class="nav-inner"> |
| 76 | + <a href="/" class="logo">java.<span>evolved</span></a> |
| 77 | + <div class="nav-right"> |
| 78 | + <a href="/" class="back-link">← All patterns</a> |
| 79 | + |
| 80 | + <div class="nav-arrows"> |
| 81 | + <a href="/compact-object-headers.html" aria-label="Previous pattern">←</a> |
| 82 | + |
| 83 | + </div> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + </nav> |
| 87 | + |
| 88 | + <article class="article"> |
| 89 | + <div class="breadcrumb"> |
| 90 | + <a href="/">Home</a> |
| 91 | + <span class="sep">/</span> |
| 92 | + <a href="/?cat=tooling">Tooling</a> |
| 93 | + <span class="sep">/</span> |
| 94 | + <span>AOT class preloading</span> |
| 95 | + </div> |
| 96 | + |
| 97 | + <div class="tip-header"> |
| 98 | + <div class="tip-meta"> |
| 99 | + <span class="badge tooling">Tooling</span> |
| 100 | + <span class="badge advanced">advanced</span> |
| 101 | + </div> |
| 102 | + <h1>AOT class preloading</h1> |
| 103 | + <p>Cache class loading and compilation for instant startup.</p> |
| 104 | + </div> |
| 105 | + |
| 106 | + <section class="compare-section"> |
| 107 | + <div class="section-label">Code Comparison</div> |
| 108 | + <div class="compare-container"> |
| 109 | + <div class="compare-panel old-panel"> |
| 110 | + <div class="compare-panel-header"> |
| 111 | + <span class="compare-tag old">✕ Java 8</span> |
| 112 | + <button class="copy-btn" data-code="old">Copy</button> |
| 113 | + </div> |
| 114 | + <div class="compare-code"> |
| 115 | + <pre class="code-text">// Every startup: |
| 116 | +// - Load 10,000+ classes |
| 117 | +// - Verify bytecode |
| 118 | +// - JIT compile hot paths |
| 119 | +// Startup: 2-5 seconds</pre> |
| 120 | + </div> |
| 121 | + </div> |
| 122 | + <div class="compare-panel modern-panel"> |
| 123 | + <div class="compare-panel-header"> |
| 124 | + <span class="compare-tag modern">✓ Java 25</span> |
| 125 | + <button class="copy-btn" data-code="modern">Copy</button> |
| 126 | + </div> |
| 127 | + <div class="compare-code"> |
| 128 | + <pre class="code-text">// Training run: |
| 129 | +$ java -XX:AOTMode=record \ |
| 130 | + -XX:AOTConfiguration=app.aotconf \ |
| 131 | + -cp app.jar com.App |
| 132 | +// Production: |
| 133 | +$ java -XX:AOTMode=on \ |
| 134 | + -XX:AOTCache=app.aot \ |
| 135 | + -cp app.jar com.App</pre> |
| 136 | + </div> |
| 137 | + </div> |
| 138 | + </div> |
| 139 | + </section> |
| 140 | + |
| 141 | + <section class="why-section"> |
| 142 | + <div class="section-label">Why the modern way wins</div> |
| 143 | + <div class="why-grid"> |
| 144 | + <div class="why-card"> |
| 145 | + <div class="why-icon">⚡</div> |
| 146 | + <h3>Faster startup</h3> |
| 147 | + <p>Skip class loading, verification, and linking.</p> |
| 148 | + </div> |
| 149 | + <div class="why-card"> |
| 150 | + <div class="why-icon">📦</div> |
| 151 | + <h3>Cached state</h3> |
| 152 | + <p>Training run captures the ideal class state.</p> |
| 153 | + </div> |
| 154 | + <div class="why-card"> |
| 155 | + <div class="why-icon">🔧</div> |
| 156 | + <h3>No code changes</h3> |
| 157 | + <p>Works with existing applications — just add JVM flags.</p> |
| 158 | + </div> |
| 159 | + </div> |
| 160 | + </section> |
| 161 | + |
| 162 | + <div class="info-grid"> |
| 163 | + <div class="info-card"> |
| 164 | + <div class="info-label">Old Approach</div> |
| 165 | + <div class="info-value red">Cold Start Every Time</div> |
| 166 | + </div> |
| 167 | + <div class="info-card"> |
| 168 | + <div class="info-label">Modern Approach</div> |
| 169 | + <div class="info-value green">AOT Cache</div> |
| 170 | + </div> |
| 171 | + <div class="info-card"> |
| 172 | + <div class="info-label">Since JDK</div> |
| 173 | + <div class="info-value accent">25</div> |
| 174 | + </div> |
| 175 | + <div class="info-card"> |
| 176 | + <div class="info-label">Difficulty</div> |
| 177 | + <div class="info-value blue">advanced</div> |
| 178 | + </div> |
| 179 | + </div> |
| 180 | + |
| 181 | + <section class="bs-section"> |
| 182 | + <div class="section-label">JDK Support</div> |
| 183 | + <div class="bs-card"> |
| 184 | + <div class="bs-feature-name">AOT class preloading</div> |
| 185 | + <span class="baseline-badge widely">Available</span> |
| 186 | + <p class="bs-desc">Available in JDK 25 LTS (JEPs 514/515, Sept 2025). Experimental.</p> |
| 187 | + </div> |
| 188 | + </section> |
| 189 | + |
| 190 | + <section class="explanation"> |
| 191 | + <h2>How it works</h2> |
| 192 | + <p>AOT class preloading caches loaded and linked classes from a training run. On subsequent starts, classes are loaded from the cache, skipping verification and linking. Combined with AOT compilation, this dramatically reduces startup time.</p> |
| 193 | + </section> |
| 194 | + |
| 195 | + <section class="related"> |
| 196 | + <h2>Related patterns</h2> |
| 197 | + <div class="related-grid"> |
| 198 | + <a href="/jshell-prototyping.html" class="tip-card"> |
| 199 | + <div class="tip-card-body"> |
| 200 | + <div class="tip-card-header"> |
| 201 | + <div class="tip-badges"> |
| 202 | + <span class="badge tooling">Tooling</span> |
| 203 | + <span class="badge beginner">beginner</span> |
| 204 | + </div> |
| 205 | + </div> |
| 206 | + <h3>JShell for prototyping</h3> |
| 207 | + </div> |
| 208 | + <div class="card-code"> |
| 209 | + <div class="card-code-layer old-layer"> |
| 210 | + <div class="mini-label">Java 8</div> |
| 211 | + <pre class="code-text">// 1. Create Test.java |
| 212 | +// 2. javac Test.java |
| 213 | +// 3. java Test |
| 214 | +// Just to test one expression!</pre> |
| 215 | + </div> |
| 216 | + <div class="card-code-layer modern-layer"> |
| 217 | + <div class="mini-label">Java 9+</div> |
| 218 | + <pre class="code-text">$ jshell |
| 219 | +jshell> "hello".chars().count() |
| 220 | +$1 ==> 5 |
| 221 | +jshell> List.of(1,2,3).reversed() |
| 222 | +$2 ==> [3, 2, 1]</pre> |
| 223 | + </div> |
| 224 | + <span class="hover-hint">Hover to see modern ➜</span> |
| 225 | + </div> |
| 226 | + <div class="tip-card-footer"> |
| 227 | + <span class="browser-support"><span class="dot"></span>JDK 9+</span> |
| 228 | + <span class="arrow-link">→</span> |
| 229 | + </div> |
| 230 | + </a> |
| 231 | + <a href="/single-file-execution.html" class="tip-card"> |
| 232 | + <div class="tip-card-body"> |
| 233 | + <div class="tip-card-header"> |
| 234 | + <div class="tip-badges"> |
| 235 | + <span class="badge tooling">Tooling</span> |
| 236 | + <span class="badge beginner">beginner</span> |
| 237 | + </div> |
| 238 | + </div> |
| 239 | + <h3>Single-file execution</h3> |
| 240 | + </div> |
| 241 | + <div class="card-code"> |
| 242 | + <div class="card-code-layer old-layer"> |
| 243 | + <div class="mini-label">Java 8</div> |
| 244 | + <pre class="code-text">$ javac HelloWorld.java |
| 245 | +$ java HelloWorld |
| 246 | +// Two steps every time</pre> |
| 247 | + </div> |
| 248 | + <div class="card-code-layer modern-layer"> |
| 249 | + <div class="mini-label">Java 11+</div> |
| 250 | + <pre class="code-text">$ java HelloWorld.java |
| 251 | +// Compiles and runs in one step |
| 252 | +// Also works with shebangs: |
| 253 | +#!/usr/bin/java --source 25</pre> |
| 254 | + </div> |
| 255 | + <span class="hover-hint">Hover to see modern ➜</span> |
| 256 | + </div> |
| 257 | + <div class="tip-card-footer"> |
| 258 | + <span class="browser-support"><span class="dot"></span>JDK 11+</span> |
| 259 | + <span class="arrow-link">→</span> |
| 260 | + </div> |
| 261 | + </a> |
| 262 | + <a href="/multi-file-source.html" class="tip-card"> |
| 263 | + <div class="tip-card-body"> |
| 264 | + <div class="tip-card-header"> |
| 265 | + <div class="tip-badges"> |
| 266 | + <span class="badge tooling">Tooling</span> |
| 267 | + <span class="badge intermediate">intermediate</span> |
| 268 | + </div> |
| 269 | + </div> |
| 270 | + <h3>Multi-file source launcher</h3> |
| 271 | + </div> |
| 272 | + <div class="card-code"> |
| 273 | + <div class="card-code-layer old-layer"> |
| 274 | + <div class="mini-label">Java 8</div> |
| 275 | + <pre class="code-text">$ javac *.java |
| 276 | +$ java Main |
| 277 | +// Must compile all files first |
| 278 | +// Need a build tool for dependencies</pre> |
| 279 | + </div> |
| 280 | + <div class="card-code-layer modern-layer"> |
| 281 | + <div class="mini-label">Java 22+</div> |
| 282 | + <pre class="code-text">$ java Main.java |
| 283 | +// Automatically finds and compiles |
| 284 | +// other source files referenced |
| 285 | +// by Main.java</pre> |
| 286 | + </div> |
| 287 | + <span class="hover-hint">Hover to see modern ➜</span> |
| 288 | + </div> |
| 289 | + <div class="tip-card-footer"> |
| 290 | + <span class="browser-support"><span class="dot"></span>JDK 22+</span> |
| 291 | + <span class="arrow-link">→</span> |
| 292 | + </div> |
| 293 | + </a> |
| 294 | + </div> |
| 295 | + </section> |
| 296 | + </article> |
| 297 | +</section> |
| 298 | + |
| 299 | + |
| 300 | + <div class="social-share"> |
| 301 | + <span class="share-label">Share</span> |
| 302 | + <a href="https://x.com/intent/tweet?url=https%3A%2F%2Fjavaevolved.github.io%2Faot-class-preloading.html&text=AOT%20class%20preloading%20%E2%80%93%20java.evolved" target="_blank" rel="noopener" class="share-btn share-x" aria-label="Share on X">𝕏</a> |
| 303 | + <a href="https://bsky.app/intent/compose?text=AOT%20class%20preloading%20%E2%80%93%20java.evolved%20https%3A%2F%2Fjavaevolved.github.io%2Faot-class-preloading.html" target="_blank" rel="noopener" class="share-btn share-bsky" aria-label="Share on Bluesky">🦋</a> |
| 304 | + <a href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fjavaevolved.github.io%2Faot-class-preloading.html" target="_blank" rel="noopener" class="share-btn share-li" aria-label="Share on LinkedIn">in</a> |
| 305 | + <a href="https://www.reddit.com/submit?url=https%3A%2F%2Fjavaevolved.github.io%2Faot-class-preloading.html&title=AOT%20class%20preloading%20%E2%80%93%20java.evolved" target="_blank" rel="noopener" class="share-btn share-reddit" aria-label="Share on Reddit">⬡</a> |
| 306 | + </div> |
| 307 | + |
| 308 | + <footer> |
| 309 | + <p>A project by <a href="https://github.com/brunoborges" target="_blank" rel="noopener">Bruno Borges</a></p> |
| 310 | + </footer> |
| 311 | + |
| 312 | + <script src="app.js"></script> |
| 313 | +</body> |
| 314 | +</html> |
0 commit comments