Skip to main content

JVM - Class Data Sharing

Topic: JVM Internals                                                                                               Level: Advanced

Problem Statement

When we run a Java application all the related classes and their dependencies associated are loaded at the runtime, adding to the startup time of the application as well as to the memory footprint.

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?

AppCDS (Application Class Data Sharing) improves the startup performance of the application by creating an archive of the library classes/selected classes from the application classpath such that when the JVM loads, the shared archive is consulted which is memory-mapped to allow sharing of read-only JVM metadata for the classes among multiple JVM processes. 

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.

Class_Data_Sharing_IllustrationImage 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
The default CDS archive is enabled at the runtime by default, and it could be turned off with the command -Xshare:off.

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

  1. https://docs.oracle.com/en/java/javase/19/docs/specs/man/java.html#application-class-data-sharing
  2. https://docs.oracle.com/en/java/javase/19/vm/class-data-sharing.html#GUID-2942983A-E83C-4DA3-A60C-60411D731D5A
  3. https://inside.java/2022/09/26/sip067/
  4. https://www.happycoders.eu/java/java-10-features/

Disclaimer: 
This is a personal blog. Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated. Any views or opinions are not intended to malign any religion, ethnic group, club, organization, company, or individual. All content provided on this blog is for informational purposes only. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.
Downloadable Files and ImagesAny downloadable file, including but not limited to pdfs, docs, jpegs, pngs, is provided at the user’s own risk. The owner will not be liable for any losses, injuries, or damages resulting from a corrupted or damaged file.
  • 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.
The blog owner is not responsible for the content in the comments. This blog disclaimer is subject to change at any time.

Comments

Popular posts from this blog

Tech Conversant Weekly Jul 03 - Jul 15

Topic: General                                                                                                                                              Level: All Welcome to the world of cutting-edge technology! Every bi-week, we bring you the latest and most incredible advancements in the tech industry that are sure to leave you feeling inspired and empowered. Stay ahead of the game and be the first to know about the newest innovations shaping our world. Discover new ways to improve your daily life, become more efficient, and enjoy new experiences. This time, we've got some exciting news to share with you! Boosting Java startup with Class Data Sharing (CDS) https://www.youtube.com/watch?v=vvlQv1Dh-HU JDK21 LTS Maintenance and Support https://www.youtube.com/watch?v=3bfR22iv8Pc Health checking of multiple cloud applications with Spring Cloud Gateway https://spring.io/blog/2023/07/05/active-health-check-strategies-with-spring-cloud-gateway Functional Style Non-reactive HTTP clie

Tech Conversant Weekly Jun 19 - Jul 01

Topic: General                                                                                                                                              Level: All Welcome to the world of cutting-edge technology! Every bi-week, we bring you the latest and most incredible advancements in the tech industry that are sure to leave you feeling inspired and empowered. Stay ahead of the game and be the first to know about the newest innovations shaping our world. Discover new ways to improve your daily life, become more efficient, and enjoy new experiences. This time, we've got some exciting news to share with you! Modelling common behaviors between the List and the Set interface has been partially provided by LinkedHashSet. Now from JDK21 with the new interface SequencedCollection extending the Collection interface and is also extended by the List, SortedSet via SequencedSet (for reversal operation), Deque. The SequencedMap interface extends the Map interface by providing the below me

Microservices - Design Patterns

Topic: Software Design                                                                                                        Level: Intermediate Microservices - What? Microservice is a software design methodology, delegated to perform an isolated decoupled single functionality (following the Single-Responsibility Principle from object-oriented SOLID design principles).  Moreover, microservices by design, are decoupled making it easy to develop, test, maintain, deploy, configure, monitor and scale modules independently. Microservices - Why? Having one microservice would not be helpful without it being able to interact with other microservices, to aid in bringing an end-to-end business solution. So arises a question, how can I design a software system that is resilient, decentralized, fault-tolerant, scalable, maintainable, and extensible that complies with the microservice architecture? Design Patterns - What? Design patterns are solutions for commonly occurring problems within a given