Skip to content

Commit

Permalink
8284313: Improve warning messages when CDS archive fails to load
Browse files Browse the repository at this point in the history
Reviewed-by: iklam, dholmes
  • Loading branch information
calvinccheung committed Aug 12, 2022
1 parent 00decca commit 22d6d31
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 9 deletions.
18 changes: 15 additions & 3 deletions src/hotspot/share/cds/filemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,16 @@ bool SharedClassPathEntry::validate(bool is_class_path) const {
"Timestamp mismatch" :
"File size mismatch");
} else {
FileMapInfo::fail_continue("A jar file is not the one used while building"
" the shared archive file: %s", name);
const char* bad_jar_msg = "A jar file is not the one used while building the shared archive file:";
FileMapInfo::fail_continue("%s %s", bad_jar_msg, name);
if (!log_is_enabled(Info, cds)) {
log_warning(cds)("%s %s", bad_jar_msg, name);
}
if (_timestamp != st.st_mtime) {
log_warning(cds)("%s timestamp has changed.", name);
} else {
log_warning(cds)("%s size has changed.", name);
}
}
}

Expand Down Expand Up @@ -1052,7 +1060,11 @@ bool FileMapInfo::validate_shared_path_table() {
assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image");
} else {
if (!validate_boot_class_paths() || !validate_app_class_paths(shared_app_paths_len)) {
fail_continue("shared class paths mismatch (hint: enable -Xlog:class+path=info to diagnose the failure)");
const char* mismatch_msg = "shared class paths mismatch (hint: enable -Xlog:class+path=info to diagnose the failure)";
fail_continue("%s", mismatch_msg);
if (!log_is_enabled(Info, cds) && !log_is_enabled(Info, class, path)) {
log_warning(cds)("%s", mismatch_msg);
}
return false;
}
}
Expand Down
25 changes: 20 additions & 5 deletions test/hotspot/jtreg/runtime/cds/appcds/WrongClasspath.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -40,6 +40,8 @@ public class WrongClasspath {

public static void main(String[] args) throws Exception {
String appJar = JarBuilder.getOrCreateHelloJar();
String unableToUseMsg = "Unable to use shared archive";
String mismatchMsg = "shared class paths mismatch (hint: enable -Xlog:class+path=info to diagnose the failure)";

// Dump an archive with a specified JAR file in -classpath
TestCommon.testDump(appJar, TestCommon.list("Hello"));
Expand All @@ -49,8 +51,12 @@ public static void main(String[] args) throws Exception {
/* "-cp", appJar, */ // <- uncomment this and the execution should succeed
"-Xlog:cds",
"Hello")
.assertAbnormalExit("Unable to use shared archive",
"shared class paths mismatch");
.assertAbnormalExit(unableToUseMsg, mismatchMsg);

// Run with -Xshare:auto and without CDS logging enabled, the mismatch message
// should still be there.
OutputAnalyzer output = TestCommon.execAuto("Hello");
output.shouldContain(mismatchMsg);

// Dump CDS archive with 2 jars: -cp hello.jar:jar2.jar
// Run with 2 jars but the second jar doesn't exist: -cp hello.jarjar2.jarx
Expand All @@ -60,7 +66,16 @@ public static void main(String[] args) throws Exception {
TestCommon.testDump(jars, TestCommon.list("Hello", "pkg/C2"));
TestCommon.run(
"-cp", jars + "x", "Hello")
.assertAbnormalExit("Unable to use shared archive",
"shared class paths mismatch");
.assertAbnormalExit(unableToUseMsg, mismatchMsg);

// modify the timestamp of the jar2
(new File(jar2.toString())).setLastModified(System.currentTimeMillis() + 2000);

// Run with -Xshare:auto and without CDS logging enabled, the "timestamp has changed"
// message should be there.
output = TestCommon.execAuto(
"-cp", jars, "Hello");
output.shouldMatch(".warning..cds. A jar file is not the one used while building the shared archive file:.*jar2.jar")
.shouldMatch(".warning..cds.*jar2.jar timestamp has changed.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ static void test(String args[]) throws Exception {
"-cp", appJar, mainClass)
.assertNormalExit();

String topArchiveMsg = "The top archive failed to load";

// ... but try to load the top archive using "-cp WrongJar.jar".
// Use -Xshare:auto so top archive can fail after base archive has succeeded,
// but the app will continue to run.
Expand All @@ -71,6 +73,31 @@ static void test(String args[]) throws Exception {
"-cp", wrongJar, mainClass,
"assertShared:java.lang.Object", // base archive still useable
"assertNotShared:GenericTestApp") // but top archive is not useable
.assertNormalExit("The top archive failed to load");
.assertNormalExit(topArchiveMsg);

// Turn off all CDS logging, the "shared class paths mismatch" warning
// message should still be there.
run2_WB(baseArchiveName, topArchiveName,
"-Xshare:auto",
"-cp", wrongJar, mainClass,
"assertShared:java.lang.Object", // base archive still useable
"assertNotShared:GenericTestApp") // but top archive is not useable
.assertNormalExit(topArchiveMsg,
"[warning][cds] shared class paths mismatch (hint: enable -Xlog:class+path=info to diagnose the failure)");

// modify the timestamp of appJar
(new File(appJar.toString())).setLastModified(System.currentTimeMillis() + 2000);

// Without CDS logging enabled, the "timestamp has changed" message should
// be there.
run2_WB(baseArchiveName, topArchiveName,
"-Xshare:auto",
"-cp", appJar, mainClass,
"assertShared:java.lang.Object", // base archive still useable
"assertNotShared:GenericTestApp") // but top archive is not useable
.assertNormalExit(output -> {
output.shouldContain(topArchiveMsg);
output.shouldMatch(".warning..cds. A jar file is not the one used while building the shared archive file:.*GenericTestApp.jar");
output.shouldMatch(".warning..cds.*GenericTestApp.jar timestamp has changed.");});
}
}

1 comment on commit 22d6d31

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.