Under The Hood
backend java JDK 21+ (CDS + AppCDS, default archive)

Class Data Sharing (CDS) Archives & AOT Startup Optimization

Last updated
Prerequisites:
JVM class loading basics
Understanding of JVM startup and heap
  • java
  • cds
  • class-data-sharing
  • appcds
  • startup
  • aot

Read at your depth

The practical view

Class Data Sharing (CDS) archives pre-loaded classes so the JVM can start faster and share memory. The JDK ships a default archive (classes.jsa) for core classes; enabling it with -XX:+UseCDSOnDemand or the default (Java 12+) reduces startup and footprint. AppCDS extends this to your application classes: run java -XX:ArchiveClassesAtExit=app.jsa -jar app.jar to create an archive, then java -XX:SharedArchiveFile=app.jsa -jar app.jar to use it. Benefits: faster startup (classes are loaded from the archive, not re-parsed) and lower memory (the archive is mapped, often shared across processes).

The same idea in other frameworks

react equivalent
N/A — JVM startup optimization.

Legacy vs modern

Cold JVM startup vs CDS-archived startup

Without CDS the JVM parses class files at every start; with an archive it memory-maps pre-built class metadata, cutting startup.

before → after
No CDS archive (re-parse every start)
java -jar app.jar # ❌ OLD: every start re-loads and re-parses all classes
AppCDS archive
java -XX:ArchiveClassesAtExit=app.jsa -jar app.jar  # create
java -XX:SharedArchiveFile=app.jsa -jar app.jar      # ✅ NEW: use

Interview gotchas

Context

This tests the mechanism — interviewers want the memory-mapping of pre-built class metadata and the OS page-sharing effect, not just 'it caches classes'.

The mechanical answer

Normal class loading parses the class file, verifies it, and allocates VM structures (Klass, Method, constant pool) per process. CDS archives those structures at dump time and, at startup, memory-maps the archive file instead of re-parsing: the JVM points its class metadata at the mapped region, skipping parse/verify/allocation work. That removes a large chunk of startup CPU. Because the archive is a read-only mapped file with stable layout, the OS can share its physical pages across multiple JVM processes running the same archive — each process maps the same pages, so resident memory for class metadata is shared rather than duplicated. This is why CDS helps both single-process startup latency and multi-instance memory footprint.

Trap

The naive answer is 'CDS caches classes in a file so they load from disk faster'. The win is skipping the parse/verify work and mapping pre-built structures, plus OS page sharing. Another trap: assuming any app benefits automatically — AppCDS requires creating the archive, and archives invalidate when the classpath or JDK changes (falls back to normal loading). Candidates who mention memory-mapping and page sharing show real understanding.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.