Quick revision
The short answer
Class Data Sharing stores already parsed class metadata in an archive file that the JVM maps into memory at startup, so it can skip reading, parsing and part of verifying those classes. Since JDK 12, JDK builds ship a default archive for the core JDK classes that is used automatically, with -Xshare:auto as the default mode and -Xlog:cds to check it. The read-only parts of the archive can be shared between JVM processes on the same host, and AppCDS extends the same idea to application classes.
What to remember
In this answer, we saw that loading a class means finding, parsing, verifying and linking it, and that CDS saves most of that by mapping an archive of parsed class metadata at startup. Since JDK 12, a default archive for core JDK classes ships with the JDK and is used automatically with the default -Xshare:auto, and -Xlog:cds or the class loading log shows whether it worked. Because the archive's read-only parts are mapped from a file, JVMs on the same host can share them in memory, and AppCDS extends the idea to application classes.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Class Data Sharing stores already parsed class metadata in an archive file that the JVM maps into memory at startup, so it can skip reading, parsing and part of verifying those classes. Since JDK 12, JDK builds ship a default archive for the core JDK classes that is used automatically, with -Xshare:auto as the default mode and -Xlog:cds to check it. The read-only parts of the archive can be shared between JVM processes on the same host, and AppCDS extends the same idea to application classes.
Why this question is asked
Startup time used to be a desktop concern, but containers, autoscaling and frequent deployments have made it a server concern too. CDS is the oldest and simplest startup feature in the JVM, it is already working in almost every Java process we run, and most developers have never noticed it. Interviewers ask about it as the entry point to the whole startup topic, which continues with AppCDS and the newer AOT cache. In this answer, we will see what the JVM does when it loads a class, how CDS saves that work, how the default archive is used and checked, and how it reduces memory across processes.
1What the JVM Does to Load a Class
Every class starts life as bytes in a .class file inside a jar or the JDK's modules image. Before the JVM can use a class, it has to find those bytes, parse them into its internal representation of the class, check that the bytecode is valid in a step called verification, and link the class to the classes it refers to. The internal representation, the class metadata, lives in a native memory area called metaspace.
A simple hello world program loads around 450 to 500 JDK classes before main even runs, and a Spring Boot application loads many thousands. Doing all that parsing on every start, for classes that are identical every time, is wasted work. CDS exists to do it once.
2How CDS Saves That Work
With CDS, the parsed metadata for a set of classes is written once into an archive file. On later starts, the JVM maps the archive file into memory, essentially telling the operating system to make the file's contents appear at an address, and uses the metadata directly. The classes in the archive do not need to be found in jars, read, parsed or verified again; they only need a small amount of final setup.
- Is the class in the mapped CDS archive?YesUse the archived metadata directlyNoLoad it the normal way
- Normal way: find the bytessearch the class path or module image
- Parse the class filebuild metadata in metaspace
- Verify the bytecodecheck types and control flow
- Link and initialiseboth paths finish here
5 steps in order. Play them, or step through them one at a time.
Archived classes skip the find, parse and verify steps.
Mapping a file is cheap because the operating system loads pages lazily and may already have them in its page cache from an earlier process. That is why CDS helps both the first start after boot and, even more, repeated starts.
3The Default CDS Archive
Since JDK 12, JDK builds include a default CDS archive for a standard set of core JDK classes, created when the JDK itself was built. It lives inside the JDK, typically as lib/server/classes.jsa, and the JVM uses it automatically. We do not need to do anything to benefit from it.
The behaviour is controlled by -Xshare. The default, -Xshare:auto, means use the archive if it can be mapped and quietly continue without it otherwise. -Xshare:off disables CDS, which is useful to measure what it saves. -Xshare:on requires it and makes the JVM fail at startup if the archive cannot be used, which is handy in tests that must not silently lose the benefit.
The source: shared objects file marker in the class loading log is the simplest proof that a class came from the archive. For a small program the gain is often in the tens of milliseconds, a large share of its total startup time.
4Sharing Memory Between Processes
The name Class Data Sharing comes from the second benefit. The archive is mapped from a file, and its read-only parts are never modified by the JVM. So when several JVMs on the same host map the same archive, the operating system can back their mappings with the same physical memory pages.
On a host or node running many Java processes from the same JDK, such as several containers sharing a base image layer, this saves memory: the core class metadata is held once in RAM rather than once per process. The saving per process is modest, but it adds up across dozens of JVMs, and it also means the pages are often already in memory when a new process starts.
5From the Default Archive to AppCDS
The default archive only covers JDK classes, and only a standard set of them. Our application's own classes and its libraries, which are most of what a framework application loads, still go through the normal path. AppCDS, Application Class Data Sharing, extends the same mechanism to them: we run the application once to record which classes it loads and dump an archive, then start production with that archive. In recent JDKs this has grown further into the AOT cache, which stores even more startup work. For a large Spring application, AppCDS can save much more time than the default archive, which is why it is the natural next step.
6Follow-up questions
Is CDS safe to rely on across JDK updates?
Yes, because the archive is tied to the exact JDK build. The default archive ships with each JDK, so updating the JDK updates the archive. A custom archive created with one JDK build is rejected by another, and with -Xshare:auto the JVM simply continues without it.
Why might the default archive not be used?
Common reasons include running with -Xshare:off, an unusual combination of options such as a different garbage collector or compressed pointer settings that the archive does not support in that JDK version, or a JDK image built without the archive. -Xlog:cds tells us why mapping failed.
Does CDS help peak performance as well as startup?
Not directly. CDS saves class loading work at startup and some memory. Peak performance depends on the JIT, which still compiles hot code after startup. The newer AOT cache in JDK 25 adds method profiles to help warmup, but that goes beyond classic CDS.
7Conclusion
In this answer, we saw that loading a class means finding, parsing, verifying and linking it, and that CDS saves most of that by mapping an archive of parsed class metadata at startup. Since JDK 12, a default archive for core JDK classes ships with the JDK and is used automatically with the default -Xshare:auto, and -Xlog:cds or the class loading log shows whether it worked. Because the archive's read-only parts are mapped from a file, JVMs on the same host can share them in memory, and AppCDS extends the idea to application classes.
Open with
Class Data Sharing is a way for the JVM to avoid redoing class loading work on every start. Normally, for each class, the JVM finds the class file, parses it into metadata in metaspace, verifies the bytecode and links it.
Then, if they want more
With CDS, the parsed metadata for a set of classes is stored in an archive file, and at startup the JVM simply maps that file into memory and uses the metadata directly, skipping the find, parse and most of the verify steps.
Since JDK 12, every JDK build ships a default archive for the core JDK classes, created when the JDK is built, and the JVM uses it automatically. The default mode is -Xshare:auto, which uses the archive if it can and silently continues without it otherwise; -Xshare:off disables it for comparison, and -Xshare:on makes startup fail if it cannot be used.
To check it, I would run with -Xlog:cds, or -Xlog:class+load and look for classes whose source is the shared objects file. There is also a memory benefit: the read-only parts of the archive are mapped from a file, so several JVMs on the same host can share the same physical pages.
The default archive only covers JDK classes, so for a framework application the next step is AppCDS, which archives the application and library classes too.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 12, Java 25
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is Class Data Sharing (CDS) in the JVM, and how does the default CDS archive help...": https://scrivio-interview-library.netlify.app/java/startup-and-footprint/f636a2adad/