Topic: JVM Internals Level: Advanced
Problem Statement
Every time when we launch the application, the process would be the same and starting up multiple instances of the application would add up significant latency, and also becoming memory intensive, as the same class-related data need to be replicated and loaded.
What is CDS?
Because accessing the shared archive is faster than loading the classes, startup time is reduced and no additional memory allocation is required when starting up a new instance.
Image source: https://www.happycoders.eu/java/java-10-features/
How?
Available from JDK12, a default CDS will be created at the JDK build time by running, -Xshare:dump, using G1GC and 128M Java heap, containing default selective core library classes in the archive.
The CDS resides in the directory,
- /lib/[arch]/server/classes.jsa - for Linux and macOS platforms
- /bin/server/classes.jsa - for Windows platform
AppCDS allows the class loaders, garbage collectors, and custom loaders to load the archived pre-processed data. On the application launch, the shared CDS archive is visited and leveraged for bootstrapping, if not found then on application exit the archive will be created with the list of classes that were used to load the application.
The archived classes hold all the loaded application classes, and library classes that are not available as part of the default CDS archive, making it dynamically evolve on each application launch. To enable dynamic CDS archiving, -XX:+RecordDynamicDumpInfo; XX:ArchiveClassesAtExit which updates the shared CDS archive with the new list of classes on exiting the application.
Additionally, when there is a Java version mismatch in the shared CDS archive then on the application exit a new archive will be created overriding the redundant archive.
References
- https://docs.oracle.com/en/java/javase/19/docs/specs/man/java.html#application-class-data-sharing
- https://docs.oracle.com/en/java/javase/19/vm/class-data-sharing.html#GUID-2942983A-E83C-4DA3-A60C-60411D731D5A
- https://inside.java/2022/09/26/sip067/
- https://www.happycoders.eu/java/java-10-features/
- Comments are welcome. However, the blog owner reserves the right to edit or delete any comments submitted to this blog without notice due to :
- Comments deemed to be spam or questionable spam.
- Comments including profanity.
- Comments containing language or concepts that could be deemed offensive.
- Comments containing hate speech, credible threats, or direct attacks on an individual or group.
Comments
Post a Comment