Profile Image

What is Java Class Sharing: -Xshare?

What is Java Class Sharing: -Xshare? Have you used this JVM argument before? What are the pros & cons of using this Java argument? Can you share your perspective/experience in using this JVM argument?

  • jvm-argument

  • xshare

  • share

  • Java Class Sharing

Please Sign In or to post your comment or answer

Profile Image

Pavel Khodakovsky



• -Xshare:<mode>


The possible arguments are as follows:

• auto

• on

• off




java -Xshare:auto java -Xshare:on java -Xshare:off



The -Xshare option controls the behaviour of Class Data Sharing, first introduced
in Java 1.5. This is a feature intended to reduce the start-up time of Java
applications. When the JVM starts, a pre-generated shared archive is mapped
into the memory space of the new JVM process. This enables multiple JVM
processes to share the read-only portion of the class metadata for classes on the
boot class path.

Because accessing the shared CDS archive is faster than loading classes, startup
time of the JVM is reduced. When multiple JVM processes are running, the
total memory footprint of each is reduced because some of the required data is
shared between the processes.

NOTE: the class data sharing (CDS) feature introduced in Java 1.5 applies only
to core classes loaded by the boot class loader. This is distinct from Application
Class Data Sharing (“AppCDS”) introduced in Java 10, which allows application
classes to be shared.

Class data sharing can be particularly valuable for programs that run frequently
and for a short time, e.g. shell commands implemented in Java. It is less
important for long-running applications, since startup time is a much smaller
fraction of the overall run time.

To make CDS work as optimally as possible, use the -XX:DumpLoadedClassList
to generate a shared archive based on the JDK classes actually used at runtime
by an application.

-Xshare:auto indicates that the shared class data archive should be loaded if it
is available, but if is not available then the JVM will still start; this is the default
behaviour. The -Xshare:on option indicates that CDS data must be used, and
if not available then the JVM will exit with an error. The -Xshare:off option
indicates that CDS data must not be used even if it is available.
WARNING: The -Xshare:on option should not be used in production, because
the JVM cannot guarantee to load the CDS archive even when it is present, due
to address space layout randomization by the operating system. This option
should only be used for testing, e.g. to measure the performance gains from
using CDS.


Default Value:

The default value of -Xshare is auto, i.e. use the shared class data when possible,
but not to fail if it is unavailable.


If -Xshare:on is used and the shared class data archive is not available, then
the JVM exits with the following error:
An error has occurred while processing the shared archive file.
Specified shared archive not found (/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home/lib/server/classes.jsa).
Error occurred during initialization of VM
Unable to use shared archive.

Arguments Related to -Xshare:

TODO: link to -XX:SharedArchiveFile TODO: link to -XX:DumpLoadedClassList
TODO: link to -XX:SharedClassListFile TODO: link to -Xbootclasspath

Related Posts:

• Deprecation of the -Xfuture option


If you have additional comments, interesting experiences or even point of disagreement with this JVM argument description, please leave a comment. Your
insights will help the entire 10+ million java developer community to develop
one standard source of documentation for all the JVM arguments

Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • jvm-argument

  • xshare

  • share

  • Java Class Sharing