8209598: Clean up how messages are printed when CDS aborts start-up
Summary: added a new function vm_exit_during_cds_dumping() to java.cpp so that it can be used when an error condition is encountered during CDS dumping.
Reviewed-by: iklam, dholmes, jiangli
--- a/src/hotspot/share/classfile/classLoader.cpp Fri Oct 26 11:11:13 2018 +0800
+++ b/src/hotspot/share/classfile/classLoader.cpp Thu Oct 25 21:40:17 2018 -0700
@@ -1471,16 +1471,16 @@
// if no protocol prefix is found, path is the same as stream->source()
char* path = skip_uri_protocol(src);
char* canonical_class_src_path = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, JVM_MAXPATHLEN);
- if (!get_canonical_path(path, canonical_class_src_path, JVM_MAXPATHLEN)) {
- tty->print_cr("Bad pathname %s. CDS dump aborted.", path);
- vm_exit(1);
- }
+ bool success = get_canonical_path(path, canonical_class_src_path, JVM_MAXPATHLEN);
+ // The path is from the ClassFileStream. Since a ClassFileStream has been created successfully in functions
+ // such as ClassLoader::load_class(), its source path must be valid.
+ assert(success, "must be valid path");
for (int i = 0; i < FileMapInfo::get_number_of_shared_paths(); i++) {
SharedClassPathEntry* ent = FileMapInfo::shared_path(i);
- if (!get_canonical_path(ent->name(), canonical_path_table_entry, JVM_MAXPATHLEN)) {
- tty->print_cr("Bad pathname %s. CDS dump aborted.", ent->name());
- vm_exit(1);
- }
+ success = get_canonical_path(ent->name(), canonical_path_table_entry, JVM_MAXPATHLEN);
+ // A shared path has been validated during its creation in ClassLoader::create_class_path_entry(),
+ // it must be valid here.
+ assert(success, "must be valid path");
// If the path (from the class stream source) is the same as the shared
// class or module path, then we have a match.
if (strcmp(canonical_path_table_entry, canonical_class_src_path) == 0) {
--- a/src/hotspot/share/classfile/classLoaderExt.cpp Fri Oct 26 11:11:13 2018 +0800
+++ b/src/hotspot/share/classfile/classLoaderExt.cpp Thu Oct 25 21:40:17 2018 -0700
@@ -175,8 +175,7 @@
}
if (strstr(manifest, "Extension-List:") != NULL) {
- tty->print_cr("-Xshare:dump does not support Extension-List in JAR manifest: %s", entry->name());
- vm_exit(1);
+ vm_exit_during_cds_dumping(err_msg("-Xshare:dump does not support Extension-List in JAR manifest: %s", entry->name()));
}
char* cp_attr = get_class_path_attr(entry->name(), manifest, manifest_size);
--- a/src/hotspot/share/memory/metaspace.cpp Fri Oct 26 11:11:13 2018 +0800
+++ b/src/hotspot/share/memory/metaspace.cpp Thu Oct 25 21:40:17 2018 -0700
@@ -1291,10 +1291,9 @@
if (DumpSharedSpaces) {
// CDS dumping keeps loading classes, so if we hit an OOM we probably will keep hitting OOM.
// We should abort to avoid generating a potentially bad archive.
- tty->print_cr("Failed allocating metaspace object type %s of size " SIZE_FORMAT ". CDS dump aborted.",
- MetaspaceObj::type_name(type), word_size * BytesPerWord);
- tty->print_cr("Please increase MaxMetaspaceSize (currently " SIZE_FORMAT " bytes).", MaxMetaspaceSize);
- vm_exit(1);
+ vm_exit_during_cds_dumping(err_msg("Failed allocating metaspace object type %s of size " SIZE_FORMAT ". CDS dump aborted.",
+ MetaspaceObj::type_name(type), word_size * BytesPerWord),
+ err_msg("Please increase MaxMetaspaceSize (currently " SIZE_FORMAT " bytes).", MaxMetaspaceSize));
}
report_metadata_oome(loader_data, word_size, type, mdtype, THREAD);
assert(HAS_PENDING_EXCEPTION, "sanity");
--- a/src/hotspot/share/memory/metaspaceShared.cpp Fri Oct 26 11:11:13 2018 +0800
+++ b/src/hotspot/share/memory/metaspaceShared.cpp Thu Oct 25 21:40:17 2018 -0700
@@ -1646,12 +1646,11 @@
} while (check_closure.made_progress());
if (IgnoreUnverifiableClassesDuringDump) {
- // This is useful when running JCK or SQE tests. You should not
- // enable this when running real apps.
+ // IgnoreUnverifiableClassesDuringDump is enabled by default.
+ // Unverifiable classes will not be included in the CDS archive.
SystemDictionary::remove_classes_in_error_state();
} else {
- tty->print_cr("Please remove the unverifiable classes from your class list and try again");
- exit(1);
+ vm_exit_during_cds_dumping("Please remove the unverifiable classes from your class list and try again");
}
}
}
--- a/src/hotspot/share/runtime/java.cpp Fri Oct 26 11:11:13 2018 +0800
+++ b/src/hotspot/share/runtime/java.cpp Thu Oct 25 21:40:17 2018 -0700
@@ -609,6 +609,26 @@
ShouldNotReachHere();
}
+void vm_notify_during_cds_dumping(const char* error, const char* message) {
+ if (error != NULL) {
+ tty->print_cr("Error occurred during CDS dumping");
+ tty->print("%s", error);
+ if (message != NULL) {
+ tty->print_cr(": %s", message);
+ }
+ else {
+ tty->cr();
+ }
+ }
+}
+
+void vm_exit_during_cds_dumping(const char* error, const char* message) {
+ vm_notify_during_cds_dumping(error, message);
+
+ // Failure during CDS dumping, we don't want to dump core
+ vm_abort(false);
+}
+
void vm_notify_during_shutdown(const char* error, const char* message) {
if (error != NULL) {
tty->print_cr("Error occurred during initialization of VM");
--- a/src/hotspot/share/runtime/java.hpp Fri Oct 26 11:11:13 2018 +0800
+++ b/src/hotspot/share/runtime/java.hpp Thu Oct 25 21:40:17 2018 -0700
@@ -51,6 +51,8 @@
extern void vm_exit_during_initialization(const char* error, const char* message = NULL);
extern void vm_shutdown_during_initialization(const char* error, const char* message = NULL);
+extern void vm_exit_during_cds_dumping(const char* error, const char* message = NULL);
+
/**
* With the integration of the changes to handle the version string
* as defined by JEP-223, most of the code related to handle the version