Skip to content

8327495: Print more warning with -Xshare:auto when CDS fails to use archive #24889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

calvinccheung
Copy link
Member

@calvinccheung calvinccheung commented Apr 25, 2025

Before this change, if the -Xshare:auto is specified with a CDS archive, the user won't see the following error message when the archive has failed to load:
An error has occurred while processing the the shared archive file.
This change will print the above error message if the -Xshare:auto is specified and the archive is not the default one.
Several existing log_ino(cds)() calls have been changed to calling the new function MetaspaceShared::report_loading_error(). Also modified couple of tests to check the above error message is printed.

Passed tiers 1 - 3 testing.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8327495: Print more warning with -Xshare:auto when CDS fails to use archive (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24889/head:pull/24889
$ git checkout pull/24889

Update a local copy of the PR:
$ git checkout pull/24889
$ git pull https://git.openjdk.org/jdk.git pull/24889/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24889

View PR using the GUI difftool:
$ git pr show -t 24889

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24889.diff

Using Webrev

Link to Webrev Comment

@calvinccheung calvinccheung marked this pull request as ready for review April 25, 2025 21:43
@bridgekeeper
Copy link

bridgekeeper bot commented Apr 25, 2025

👋 Welcome back ccheung! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Apr 25, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 25, 2025
@openjdk
Copy link

openjdk bot commented Apr 25, 2025

@calvinccheung The following label will be automatically applied to this pull request:

  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@mlbridge
Copy link

mlbridge bot commented Apr 25, 2025

Webrevs

Comment on lines 1121 to 1135
void MetaspaceShared::report_loading_error(const char* message) {

if (SharedArchiveFile != nullptr) {
log_error(cds)("An error has occurred while processing the %s.", CDSConfig::type_of_archive_being_loaded());
if (message != nullptr) {
log_error(cds)("%s", message);
}
} else {
log_info(cds)("An error has occurred while processing the %s.", CDSConfig::type_of_archive_being_loaded());
if (message != nullptr) {
log_info(cds)("%s", message);
}
}
}

Copy link
Member

Choose a reason for hiding this comment

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

The AOT workflow doesn't use the SharedArchiveFile flag. I think to detect that we are not using the default archive, we should do this:

bool CDSConfig::is_using_only_default_archive() {
  return is_using_archive() &&
         input_static_archive_path() != nullptr &&
         default_archive_path() != nullptr &&
         strcmp(input_static_archive_path(), default_archive_path()) == 0 &&
         input_dynamic_archive_path() == nullptr;
}

I think the printing can be simplified like this to avoid duplication:

// If the user doesn't specify any CDS options, we will try to load the default CDS archive, which
// may fail due to incompatible VM options. Print at the info level to avoid excessive verbosity.
// However, if the user has specified a CDS archive (or AOT cache), they would be interested in
// knowing that the loading fails, so we print at the error level.
Log(cds) log;
LogStream ls_error(log.error());
LogStream ls_info(log.warning());
LogStream& ls = CDSConfig::is_using_only_default_archive() ? ls_info : ls_error;

ls.print_cr("An error has occurred while processing the %s.", CDSConfig::type_of_archive_being_loaded());
if (message != nullptr) {
   ls_print(cds)("%s", message);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. I've incorporated your suggestion with some slight adjustment. For the CDSConfig::is_using_only_default_archive(), it needs to account for dumping a classlist during JDK build time.

Comment on lines +650 to +654
if (!is_using_archive()) {
// During JDK build when dumping a classlist (DumpLoadedClassList), exclude error
// message from the classlist as it interferes with the default CDS archive creation.
return true;
}
Copy link
Member

Choose a reason for hiding this comment

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

I check the Makefiles, and the situation you are trying to avoid is this part in make/GenerateLinkOptData.gmk:

	$(FIXPATH) $(INTERIM_IMAGE_DIR)/bin/java \
	    -cp $(SUPPORT_OUTPUTDIR)/classlist.jar \
	    build.tools.classlist.SortClasslist [email protected] > $@

After adding -Xlog:cds=/tmp/foo.txt to the above command, I get the following in the log file:

[0.004s][info][cds] trying to map /jdk3/bld/tin/support/interim-image/lib/server/classes.jsa
[0.004s][info][cds] Specified shared archive file not found (/jdk3/bld/tin/support/interim-image/lib/server/classes.jsa)
[0.004s][info][cds] An error has occurred while processing the shared archive file.
[0.004s][info][cds] Loading static archive failed.
[0.004s][error][cds] An error has occurred while processing the shared archive file.
[0.004s][error][cds] Unable to map shared spaces

I think the !is_using_archive() shouldn't be in this function. Instead it should be in MetaspaceShared::report_loading_error():

LogStream& ls = (!CDSConfig::is_using_archive()) || CDSConfig::is_using_only_default_archive() ? ls_info : ls_error;

Copy link
Member

Choose a reason for hiding this comment

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

I found that with AOT class linking, we need better diagnostics. E.g.:

$ java -cp HelloWorld.jar -XX:AOTMode=record -XX:AOTConfiguration=hw.aotconfig HelloWorld
Hello World
AOTConfiguration recorded: hw.aotconfig

$ java -cp HelloWorld.jar -XX:AOTMode=create -XX:AOTCache=hw.aot -XX:AOTConfiguration=hw.aotconfig
Reading AOTConfiguration hw.aotconfig and writing AOTCache hw.aot
AOTCache creation is complete: hw.aot 9682944 bytes

$ java --add-modules=java.base -cp HelloWorld.jar -XX:AOTMode=on -XX:AOTCache=hw.aot HelloWorld
[0.005s][error][cds] CDS archive has aot-linked classes. It cannot be used when archived full module graph is not used.
Error occurred during initialization of VM
Unable to use AOT cache.

It's not clear why "full module graph is not used". I added the following patch on to of your PR:

iklam@a2ca2c0

Now there's a better explanation:

$ java --add-modules=java.base -cp HelloWorld.jar -XX:AOTMode=on -XX:AOTCache=hw.aot HelloWorld
[0.017s][error][cds] An error has occurred while processing the AOT cache. Run with -Xlog:cds for details.
[0.017s][error][cds] Mismatched values for property jdk.module.addmods: java.base specified during runtime but not during dump time
[0.017s][error][cds] Disabling optimized module handling
[0.017s][error][cds] CDS archive has aot-linked classes. It cannot be used when archived full module graph is not used.
Error occurred during initialization of VM
Unable to use AOT cache.

Could you check other cases where the FMG is disabled and change their error reporting to use MetaspaceShared::report_loading_error()

Also, we have a few messages that says: "CDS archive has aot-linked classes ...". I think these should be changed to use CDSConfig::type_of_archive_being_loaded().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime [email protected] rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants