8329112: Clean up CDS checking of unsupported module options

Reviewed-by: ccheung, matsaave
This commit is contained in:
Ioi Lam 2024-03-29 16:01:54 +00:00
parent 59c2aff1ed
commit 5b05f8e0c4
4 changed files with 48 additions and 47 deletions

View File

@ -140,7 +140,7 @@ void CDSConfig::init_shared_archive_paths() {
if (is_dumping_static_archive()) {
vm_exit_during_initialization("-XX:ArchiveClassesAtExit cannot be used with -Xshare:dump");
}
check_unsupported_dumping_properties();
check_unsupported_dumping_module_options();
if (os::same_files(default_archive_path(), ArchiveClassesAtExit)) {
vm_exit_during_initialization(
@ -260,41 +260,52 @@ void CDSConfig::check_incompatible_property(const char* key, const char* value)
}
static const char* unsupported_properties[] = {
"jdk.module.limitmods",
"jdk.module.upgrade.path",
"jdk.module.patch.0"
};
static const char* unsupported_options[] = {
"--limit-modules",
"--upgrade-module-path",
"--patch-module"
};
// Returns any JVM command-line option, such as "--patch-module", that's not supported by CDS.
static const char* find_any_unsupported_module_option() {
// Note that arguments.cpp has translated the command-line options into properties. If we find an
// unsupported property, translate it back to its command-line option for better error reporting.
void CDSConfig::check_unsupported_dumping_properties() {
assert(is_dumping_archive(), "this function is only used with CDS dump time");
assert(ARRAY_SIZE(unsupported_properties) == ARRAY_SIZE(unsupported_options), "must be");
// If a vm option is found in the unsupported_options array, vm will exit with an error message.
// The following properties are checked by Arguments::is_internal_module_property() and cannot be
// directly specified in the command-line.
static const char* unsupported_module_properties[] = {
"jdk.module.limitmods",
"jdk.module.upgrade.path",
"jdk.module.patch.0"
};
static const char* unsupported_module_options[] = {
"--limit-modules",
"--upgrade-module-path",
"--patch-module"
};
assert(ARRAY_SIZE(unsupported_module_properties) == ARRAY_SIZE(unsupported_module_options), "must be");
SystemProperty* sp = Arguments::system_properties();
while (sp != nullptr) {
for (uint i = 0; i < ARRAY_SIZE(unsupported_properties); i++) {
if (strcmp(sp->key(), unsupported_properties[i]) == 0) {
vm_exit_during_initialization(
"Cannot use the following option when dumping the shared archive", unsupported_options[i]);
for (uint i = 0; i < ARRAY_SIZE(unsupported_module_properties); i++) {
if (strcmp(sp->key(), unsupported_module_properties[i]) == 0) {
return unsupported_module_options[i];
}
}
sp = sp->next();
}
return nullptr; // not found
}
void CDSConfig::check_unsupported_dumping_module_options() {
assert(is_dumping_archive(), "this function is only used with CDS dump time");
const char* option = find_any_unsupported_module_option();
if (option != nullptr) {
vm_exit_during_initialization("Cannot use the following option when dumping the shared archive", option);
}
// Check for an exploded module build in use with -Xshare:dump.
if (!Arguments::has_jimage()) {
vm_exit_during_initialization("Dumping the shared archive is not supported with an exploded module build");
}
}
bool CDSConfig::check_unsupported_cds_runtime_properties() {
bool CDSConfig::has_unsupported_runtime_module_options() {
assert(UseSharedSpaces, "this function is only used with -Xshare:{on,auto}");
assert(ARRAY_SIZE(unsupported_properties) == ARRAY_SIZE(unsupported_options), "must be");
if (ArchiveClassesAtExit != nullptr) {
// dynamic dumping, just return false for now.
// check_unsupported_dumping_properties() will be called later to check the same set of
@ -302,20 +313,19 @@ bool CDSConfig::check_unsupported_cds_runtime_properties() {
// are used.
return false;
}
for (uint i = 0; i < ARRAY_SIZE(unsupported_properties); i++) {
if (Arguments::get_property(unsupported_properties[i]) != nullptr) {
if (RequireSharedSpaces) {
warning("CDS is disabled when the %s option is specified.", unsupported_options[i]);
} else {
log_info(cds)("CDS is disabled when the %s option is specified.", unsupported_options[i]);
}
return true;
const char* option = find_any_unsupported_module_option();
if (option != nullptr) {
if (RequireSharedSpaces) {
warning("CDS is disabled when the %s option is specified.", option);
} else {
log_info(cds)("CDS is disabled when the %s option is specified.", option);
}
return true;
}
return false;
}
bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) {
bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) {
if (is_dumping_static_archive()) {
if (!mode_flag_cmd_line) {
// By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
@ -363,7 +373,7 @@ bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_fl
if (UseSharedSpaces && patch_mod_javabase) {
Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
}
if (UseSharedSpaces && check_unsupported_cds_runtime_properties()) {
if (UseSharedSpaces && has_unsupported_runtime_module_options()) {
UseSharedSpaces = false;
}

View File

@ -46,7 +46,6 @@ class CDSConfig : public AllStatic {
char** base_archive_path,
char** top_archive_path);
static void init_shared_archive_paths();
static bool check_unsupported_cds_runtime_properties();
public:
// Used by jdk.internal.misc.CDS.getCDSConfigStatus();
@ -60,8 +59,9 @@ public:
static void initialize() NOT_CDS_RETURN;
static void check_internal_module_property(const char* key, const char* value) NOT_CDS_RETURN;
static void check_incompatible_property(const char* key, const char* value) NOT_CDS_RETURN;
static void check_unsupported_dumping_properties() NOT_CDS_RETURN;
static bool check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) NOT_CDS_RETURN_(true);
static void check_unsupported_dumping_module_options() NOT_CDS_RETURN;
static bool has_unsupported_runtime_module_options() NOT_CDS_RETURN_(false);
static bool check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) NOT_CDS_RETURN_(true);
// --- Basic CDS features

View File

@ -651,7 +651,7 @@ void MetaspaceShared::link_shared_classes(bool jcmd_request, TRAPS) {
void MetaspaceShared::prepare_for_dumping() {
assert(CDSConfig::is_dumping_archive(), "sanity");
CDSConfig::check_unsupported_dumping_properties();
CDSConfig::check_unsupported_dumping_module_options();
ClassLoader::initialize_shared_path(JavaThread::current());
}

View File

@ -1119,18 +1119,8 @@ InstanceKlass* ClassLoader::load_class(Symbol* name, PackageEntry* pkg_entry, bo
// Note: The --patch-module entries are never searched if the boot loader's
// visibility boundary is limited to only searching the append entries.
if (_patch_mod_entries != nullptr && !search_append_only) {
// At CDS dump time, the --patch-module entries are ignored. That means a
// class is still loaded from the runtime image even if it might
// appear in the _patch_mod_entries. The runtime shared class visibility
// check will determine if a shared class is visible based on the runtime
// environment, including the runtime --patch-module setting.
//
// Dynamic dumping requires UseSharedSpaces to be enabled. Since --patch-module
// is not supported with UseSharedSpaces, we can never come here during dynamic dumping.
assert(!CDSConfig::is_dumping_dynamic_archive(), "sanity");
if (!CDSConfig::is_dumping_static_archive()) {
stream = search_module_entries(THREAD, _patch_mod_entries, pkg_entry, file_name);
}
assert(!CDSConfig::is_dumping_archive(), "CDS doesn't support --patch-module during dumping");
stream = search_module_entries(THREAD, _patch_mod_entries, pkg_entry, file_name);
}
// Load Attempt #2: [jimage | exploded build]
@ -1141,6 +1131,7 @@ InstanceKlass* ClassLoader::load_class(Symbol* name, PackageEntry* pkg_entry, bo
} else {
// Exploded build - attempt to locate class in its defining module's location.
assert(_exploded_entries != nullptr, "No exploded build entries present");
assert(!CDSConfig::is_dumping_archive(), "CDS dumping doesn't support exploded build");
stream = search_module_entries(THREAD, _exploded_entries, pkg_entry, file_name);
}
}