Is Inter-Class Communication (CDS) enabled by installing a JRE by copying a directory?

When the JRE is installed through the Oracle JRE installer, the installer creates a shared archive that allows data exchange with classes (CDS) , reducing the startup time and memory size of JRE processes.

Questions

If our installer installs the JRE instead by copying the JRE directory, will we lose class sharing?

If so, can this be resolved by regenerating the shared archive (using java -Xshare:dump ) from our own installer?

Is there a mechanism in Java code to determine if data exchange between classes is active or not?

Our installation includes a shared archive (for example, jre / bin / client / classes.jsa), which was supposedly created on the source machine on which we installed Java with the Oracle installer. Is it helpful, harmless or harmful?

More details

We use Java 7. At least on some machines we use the HotSpot client VM.

Related Questions

"Is the Java code stored in the class data sharing archive (classes.jsa) compiled initially or is it bytecode?" - The accepted answer says native, but an assumption appears.

+5
source share
1 answer

copying the JRE directory will we lose class sharing?

The class data exchange file will be valid only if the JVM version and the path to the load class remain unchanged. Starting at 8u40, as a result of the JDK-8046070, the JVM will refuse to load the CDS archive, even if the JRE directory is renamed or moved.

Java 7 still allows you to reuse the CDS archive when copying the JRE directory, but this is not a reliable feature, and I would not recommend doing this.

can be solved by regenerating the shared archive (using java -Xshare: dump)

Yes, that is the right way. This will ensure the integrity of the created CDS archive and also preserve the size of the installation package.

Is there a mechanism in Java code to determine if data exchange between classes is active or not?

Yes, reading the UseSharedSpaces flag using JMX:

  HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy( ManagementFactory.getPlatformMBeanServer(), "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class); System.out.println(bean.getVMOption("UseSharedSpaces")); 

You can also enforce the CDS requirement with the -XX:+RequireSharedSpaces JVM flag.

"Is the Java code stored in the class data sharing archive (classes.jsa) compiled initially or is it bytecode?"

Depends on what you mean by "compiled initially." Class metadata is stored in a proprietary platform-specific format. But the bytecode does not compile. There is no time-ahead compilation; Java bytecode is stored in the CDS archive as is.

+2
source

All Articles