Summary
Add the AllowArchvingWithJavaAgent diganostic vm option to allow running of java agent(s) during CDS dumping.
Problem
Sometimes running a Java agent during CDS dumping is useful for testing purposes such as provoking GC activities during dumping. However, if the Java agent rewrite classes during dump time, the resulting CDS archive is not suitable for production environment, as it may contain classes with unexpected contents.
Solution
Allow java agent during CDS dumping only if the user specifies the AllowArchvingWithJavaAgent diagnostic flag in the command line.
Specification
The AllowArchvingWithJavaAgent flag must be enabled using the UnlockDiagnosticVMOptions flag as follows:
-XX:+UnlockDiagnosticVMOptions -XX:+AllowArchvingWithJavaAgent
If the user specifies a java agent without the diagnostic flag during CDS dumping, VM will exit with the following error message:
Error occurred during CDS dumping
Must enable AllowArchivingWithJavaAgent in order to run Java agent during CDS dumping
If the user specifies the diagnostic flag with a java agent during CDS dumping, the following warning will be printed:
Java HotSpot(TM) 64-Bit Server VM warning: This archive was created with
AllowArchivingWithJavaAgent. It should be used for testing purposes only and
should not be used in a production environment
The above warning will also be printed during run time if the -XX:+AllowArchvingWithJavaAgent flag is specified.
The diagnostic flag will be stored in the CDS archive header. If the CDS archive is created with the diagnostic flag and during run time the diagnostic flag is not specified.
1) if -Xshare:on is specified, vm will exit with the following error:
An error has occurred while processing the shared archive file.
The setting of the AllowArchivingWithJavaAgent is different from
the setting in the shared archive.
2) if -Xshare:auto is specified together with -Xlog:cds=info, the following info message will be printed, and the VM will continue execution without loading the CDS archive.
[0.021s][info][cds ] UseSharedSpaces: The setting of the
AllowArchivingWithJavaAgent is different from the setting in the shared archive.
The -XX:+AllowArchvingWithJavaAgent should only be used for testing purpose only.
- csr of
-
JDK-8201375 Add the AllowArchivingWithJavaAgent diagnostic vm option to allow the use of the -javaagent option during CDS dumping
-
- Resolved
-