When a JRE is installed via an Oracle JRE installer, the installer creates a shared archive that enables class data sharing (CDS), reducing startup time and memory footprint of JRE processes.
If our installer instead installs a JRE by copying a JRE directory, do we lose class data sharing?
If so, can that be solved by regenerating the shared archive (using java -Xshare:dump
) from our own installer?
Is there a mechanism in Java code to detect whether class data sharing is active or not?
Our install includes a shared archive (e.g., jre/bin/client/classes.jsa) that was presumably created on the original machine onto which we installed Java with the Oracle installer. Is this useful, harmless, or harmful?
We're using Java 7. At least on some machines, we're using the HotSpot client VM.
"Is the Java code saved in a Class Data Sharing archive (classes.jsa) compiled natively or is it bytecode?" - Accepted answer says native, but appears to be somewhat of a guess.
by copying a JRE directory, do we lose class data sharing?
Class data sharing file will be valid only if the JVM version and the boot classpath remains the same. Starting from 8u40 as a result of JDK-8046070 JVM will refuse to load CDS archive even if JRE directory is renamed or moved.
Java 7 still allows CDS archive to be reused when JRE directory is copied, but this is not a reliable feature and I would not recommend doing so.
can that be solved by regenerating the shared archive (using java -Xshare:dump)
Yes, that is a right way to go. This will ensure the integrity of generated CDS archive and also save the size of installation package.
Is there a mechanism in Java code to detect whether class data sharing is active or not?
Yes, by reading UseSharedSpaces
flag with JMX:
HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy(
ManagementFactory.getPlatformMBeanServer(),
"com.sun.management:type=HotSpotDiagnostic",
HotSpotDiagnosticMXBean.class);
System.out.println(bean.getVMOption("UseSharedSpaces"));
You may also force CDS requirement by -XX:+RequireSharedSpaces
JVM flag.
"Is the Java code saved in a Class Data Sharing archive (classes.jsa) compiled natively or is it bytecode?"
Depends on what you mean by "compiled natively". Class metadata is saved in the native format specific to the concrete platform. But no bytecode is compiled. There is no ahead-of-time compilation, Java bytecode is saved in CDS archive as is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With