Usage:
This flag allows you to override the default Class Data Sharing (CDS) list.-XX:SharedClassListFile=path/file.lst, where path is the full path where the file that contains the shared classes.
Since:
Starting from JDK 8.
Examples:
This will instruct JVM to use the shared classes list from the current working directory:
java -XX:SharedClassListFile=sharedClasses.lst MainClass
Description:
Class Data Sharing (CDS), which means that by loading a set of core system classes (such as java.lang.Integer) into shared memory, these classes can be shared among multiple JVMs. We know that when multiple JVMs are started on the same physical machine/virtual machine, if each virtual machine loads all the classes separately, the start-up cost and memory usage are relatively high. In JDK 1.5, the JAVA team introduced the concept of CDS. By sharing some core classes, each JVM only needs to load its own application classes, which reduces the start-up time. In addition, the core classes are shared, so the JVM The memory footprint is also reduced.
CDS uses a read-only memory-mapped file that contains the internal representation of the core classes and is mapped into each JVM's heap. This file can be created by the JRE or manually according to the CDS documentation. Up to now, JAVA 10 has extended CDS to allow application classes to be shared, expanding the scope of shared classes. Let's see what this extension looks like.
Let's take a look at this code snippet:
public class SharedClassListFile {
public static void main(String[] args) {
System.out.println("This is a test from SharedClassListFile class");
}
}
public class AnotherClass {
public static void main(String[] args) {
System.out.println("This is a test from AnotherClass class");
}
}
Let’s run it with the arguments “-XX:DumpLoadedClassList=dumpLoadedClasses.lst” and take a look at the generated file “dumpLoadedClasses.lst” in the root directory of the project.
java -XX:DumpLoadedClassList=dumpLoadedClasses.lst SharedClassListFile
We will see that the dump contains start-up class loaders by default and the class “SharedClassListFile”, but it doesn’t contain the second class “AnotherClass” because it’s not used.
The JVM introduced the flag “SharedClassListFile” to allow you to specify the shared classes file to be used. A good example is to use the shared classes generated above using the flag “DumpLoadedClassList” with the flag “SharedClassListFile” while dumping the CDS.
java -Xshare:dump -XX:SharedClassListFile=dumpLoadedClasses.lst -jar target/arguments-1.0.jar SharedClassListFile
As we can see, JVM will map the content of the given classes to a fixed address in memory.
The structure of the file given as an argument to the flag should contains a list of line and each line displays the full name of one class (the “.” in the package name should be replaced by ‘/’).
Example:
java/lang/String
com/java/arguments/SharedClassListFile
Default Value:
By default, this flag is disabled.
Note:
The classes specified in the file should be commonly used by other applications.
Arguments related:
DumpLoadedClassList, UseAppCDS, SharedArchiveConfigFile, SharedArchiveFile
Related Posts:
- https://docs.oracle.com/javase/7/docs/technotes/guides/vm/class->Application Class Data Sharing
- https://docs.oracle.com/javase/10/tools/java.htm#JSWOR-GUID-4856361B-8BFD-4964-AE84-121F5F6CF111">Java Oracle
Edit your Comment