20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "cds/aotLogging.hpp"
26 #include "cds/aotMapLogger.hpp"
27 #include "cds/archiveHeapLoader.hpp"
28 #include "cds/cdsConfig.hpp"
29 #include "cds/classListWriter.hpp"
30 #include "cds/filemap.hpp"
31 #include "cds/heapShared.hpp"
32 #include "classfile/classLoaderDataShared.hpp"
33 #include "classfile/moduleEntry.hpp"
34 #include "code/aotCodeCache.hpp"
35 #include "include/jvm_io.h"
36 #include "logging/log.hpp"
37 #include "memory/universe.hpp"
38 #include "prims/jvmtiAgentList.hpp"
39 #include "runtime/arguments.hpp"
40 #include "runtime/globals_extension.hpp"
41 #include "runtime/java.hpp"
42 #include "runtime/vmThread.hpp"
43 #include "utilities/defaultStream.hpp"
44 #include "utilities/formatBuffer.hpp"
45
46 bool CDSConfig::_is_dumping_static_archive = false;
47 bool CDSConfig::_is_dumping_preimage_static_archive = false;
48 bool CDSConfig::_is_dumping_final_static_archive = false;
49 bool CDSConfig::_is_dumping_dynamic_archive = false;
50 bool CDSConfig::_is_using_optimized_module_handling = true;
51 bool CDSConfig::_is_dumping_full_module_graph = true;
52 bool CDSConfig::_is_using_full_module_graph = true;
53 bool CDSConfig::_has_aot_linked_classes = false;
54 bool CDSConfig::_is_single_command_training = false;
55 bool CDSConfig::_has_temp_aot_config_file = false;
56 bool CDSConfig::_old_cds_flags_used = false;
57 bool CDSConfig::_new_aot_flags_used = false;
58 bool CDSConfig::_disable_heap_dumping = false;
59 bool CDSConfig::_is_at_aot_safepoint = false;
60
61 const char* CDSConfig::_default_archive_path = nullptr;
62 const char* CDSConfig::_input_static_archive_path = nullptr;
63 const char* CDSConfig::_input_dynamic_archive_path = nullptr;
64 const char* CDSConfig::_output_archive_path = nullptr;
65
66 JavaThread* CDSConfig::_dumper_thread = nullptr;
67
68 int CDSConfig::get_status() {
69 assert(Universe::is_fully_initialized(), "status is finalized only after Universe is initialized");
70 return (is_dumping_aot_linked_classes() ? IS_DUMPING_AOT_LINKED_CLASSES : 0) |
71 (is_dumping_archive() ? IS_DUMPING_ARCHIVE : 0) |
72 (is_dumping_method_handles() ? IS_DUMPING_METHOD_HANDLES : 0) |
73 (is_dumping_static_archive() ? IS_DUMPING_STATIC_ARCHIVE : 0) |
74 (is_logging_lambda_form_invokers() ? IS_LOGGING_LAMBDA_FORM_INVOKERS : 0) |
75 (is_using_archive() ? IS_USING_ARCHIVE : 0);
76 }
77
78 DEBUG_ONLY(static bool _cds_ergo_initialize_started = false);
79
80 void CDSConfig::ergo_initialize() {
127 Abstract_VM_Version::vm_variant(), os::file_separator());
128 } else {
129 // Assume .jsa is in the same directory where libjvm resides on
130 // non-static JDK.
131 char jvm_path[JVM_MAXPATHLEN];
132 os::jvm_path(jvm_path, sizeof(jvm_path));
133 char *end = strrchr(jvm_path, *os::file_separator());
134 if (end != nullptr) *end = '\0';
135 tmp.print("%s%sclasses", jvm_path, os::file_separator());
136 }
137 #ifdef _LP64
138 if (!UseCompressedOops) {
139 tmp.print_raw("_nocoops");
140 }
141 if (UseCompactObjectHeaders) {
142 // Note that generation of xxx_coh.jsa variants require
143 // --enable-cds-archive-coh at build time
144 tmp.print_raw("_coh");
145 }
146 #endif
147 tmp.print_raw(".jsa");
148 _default_archive_path = os::strdup(tmp.base());
149 }
150 return _default_archive_path;
151 }
152
153 int CDSConfig::num_archive_paths(const char* path_spec) {
154 if (path_spec == nullptr) {
155 return 0;
156 }
157 int npaths = 1;
158 char* p = (char*)path_spec;
159 while (*p != '\0') {
160 if (*p == os::path_separator()[0]) {
161 npaths++;
162 }
163 p++;
164 }
165 return npaths;
166 }
282 if (RecordDynamicDumpInfo) {
283 vm_exit_during_initialization("-XX:+RecordDynamicDumpInfo is unsupported when a dynamic CDS archive is specified in -XX:SharedArchiveFile",
284 SharedArchiveFile);
285 }
286 if (ArchiveClassesAtExit != nullptr) {
287 vm_exit_during_initialization("-XX:ArchiveClassesAtExit is unsupported when a dynamic CDS archive is specified in -XX:SharedArchiveFile",
288 SharedArchiveFile);
289 }
290 }
291
292 if (ArchiveClassesAtExit != nullptr && os::same_files(SharedArchiveFile, ArchiveClassesAtExit)) {
293 vm_exit_during_initialization(
294 "Cannot have the same archive file specified for -XX:SharedArchiveFile and -XX:ArchiveClassesAtExit",
295 SharedArchiveFile);
296 }
297 }
298 }
299 }
300
301 void CDSConfig::check_internal_module_property(const char* key, const char* value) {
302 if (Arguments::is_incompatible_cds_internal_module_property(key)) {
303 stop_using_optimized_module_handling();
304 aot_log_info(aot)("optimized module handling: disabled due to incompatible property: %s=%s", key, value);
305 }
306 }
307
308 void CDSConfig::check_incompatible_property(const char* key, const char* value) {
309 static const char* incompatible_properties[] = {
310 "java.system.class.loader",
311 "jdk.module.showModuleResolution",
312 "jdk.module.validation"
313 };
314
315 for (const char* property : incompatible_properties) {
316 if (strcmp(key, property) == 0) {
317 stop_dumping_full_module_graph();
318 stop_using_full_module_graph();
319 aot_log_info(aot)("full module graph: disabled due to incompatible property: %s=%s", key, value);
320 break;
321 }
322 }
323
324 }
325
326 // Returns any JVM command-line option, such as "--patch-module", that's not supported by CDS.
327 static const char* find_any_unsupported_module_option() {
328 // Note that arguments.cpp has translated the command-line options into properties. If we find an
329 // unsupported property, translate it back to its command-line option for better error reporting.
330
331 // The following properties are checked by Arguments::is_internal_module_property() and cannot be
332 // directly specified in the command-line.
333 static const char* unsupported_module_properties[] = {
334 "jdk.module.limitmods",
335 "jdk.module.upgrade.path",
336 "jdk.module.patch.0"
337 };
338 static const char* unsupported_module_options[] = {
339 "--limit-modules",
340 "--upgrade-module-path",
341 "--patch-module"
342 };
343
344 assert(ARRAY_SIZE(unsupported_module_properties) == ARRAY_SIZE(unsupported_module_options), "must be");
345 SystemProperty* sp = Arguments::system_properties();
346 while (sp != nullptr) {
347 for (uint i = 0; i < ARRAY_SIZE(unsupported_module_properties); i++) {
348 if (strcmp(sp->key(), unsupported_module_properties[i]) == 0) {
349 return unsupported_module_options[i];
350 }
351 }
352 sp = sp->next();
353 }
354
355 return nullptr; // not found
356 }
357
358 void CDSConfig::check_unsupported_dumping_module_options() {
359 assert(is_dumping_archive(), "this function is only used with CDS dump time");
360 const char* option = find_any_unsupported_module_option();
361 if (option != nullptr) {
362 vm_exit_during_initialization("Cannot use the following option when dumping the shared archive", option);
363 }
364 // Check for an exploded module build in use with -Xshare:dump.
365 if (!Arguments::has_jimage()) {
366 vm_exit_during_initialization("Dumping the shared archive is not supported with an exploded module build");
367 }
368 }
369
370 bool CDSConfig::has_unsupported_runtime_module_options() {
371 assert(is_using_archive(), "this function is only used with -Xshare:{on,auto}");
372 if (ArchiveClassesAtExit != nullptr) {
373 // dynamic dumping, just return false for now.
374 // check_unsupported_dumping_properties() will be called later to check the same set of
375 // properties, and will exit the VM with the correct error message if the unsupported properties
376 // are used.
377 return false;
378 }
379 const char* option = find_any_unsupported_module_option();
380 if (option != nullptr) {
381 if (RequireSharedSpaces) {
382 warning("CDS is disabled when the %s option is specified.", option);
383 } else {
384 if (new_aot_flags_used()) {
385 aot_log_warning(aot)("AOT cache is disabled when the %s option is specified.", option);
386 } else {
387 aot_log_info(aot)("CDS is disabled when the %s option is specified.", option);
388 }
389 }
390 return true;
391 }
392 return false;
393 }
394
395 #define CHECK_NEW_FLAG(f) check_new_flag(FLAG_IS_DEFAULT(f), #f)
396
397 void CDSConfig::check_new_flag(bool new_flag_is_default, const char* new_flag_name) {
398 if (old_cds_flags_used() && !new_flag_is_default) {
399 vm_exit_during_initialization(err_msg("Option %s cannot be used at the same time with "
400 "-Xshare:on, -Xshare:auto, -Xshare:off, -Xshare:dump, "
401 "DumpLoadedClassList, SharedClassListFile, or SharedArchiveFile",
402 new_flag_name));
403 }
404 }
405
406 #define CHECK_SINGLE_PATH(f) check_flag_single_path(#f, f)
407
408 void CDSConfig::check_flag_single_path(const char* flag_name, const char* value) {
409 if (value != nullptr && num_archive_paths(value) != 1) {
410 vm_exit_during_initialization(err_msg("Option %s must specify a single file name", flag_name));
411 }
606 void CDSConfig::ergo_init_aot_paths() {
607 assert(_cds_ergo_initialize_started, "sanity");
608 if (is_dumping_static_archive()) {
609 if (is_dumping_preimage_static_archive()) {
610 _output_archive_path = AOTConfiguration;
611 } else {
612 assert(is_dumping_final_static_archive(), "must be");
613 _input_static_archive_path = AOTConfiguration;
614 _output_archive_path = AOTCache;
615 }
616 } else if (is_using_archive()) {
617 if (FLAG_IS_DEFAULT(AOTCache)) {
618 // Only -XX:AOTMode={auto,on} is specified
619 _input_static_archive_path = default_archive_path();
620 } else {
621 _input_static_archive_path = AOTCache;
622 }
623 }
624 }
625
626 bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) {
627 assert(!_cds_ergo_initialize_started, "This is called earlier than CDSConfig::ergo_initialize()");
628
629 check_aot_flags();
630
631 if (!FLAG_IS_DEFAULT(AOTMode)) {
632 // Using any form of the new AOTMode switch enables enhanced optimizations.
633 FLAG_SET_ERGO_IF_DEFAULT(AOTClassLinking, true);
634 }
635
636 setup_compiler_args();
637
638 if (AOTClassLinking) {
639 // If AOTClassLinking is specified, enable all AOT optimizations by default.
640 FLAG_SET_ERGO_IF_DEFAULT(AOTInvokeDynamicLinking, true);
641 } else {
642 // AOTInvokeDynamicLinking depends on AOTClassLinking.
643 FLAG_SET_ERGO(AOTInvokeDynamicLinking, false);
644 }
645
646 if (is_dumping_static_archive()) {
681 return false;
682 }
683
684 if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
685 disable_dumping_dynamic_archive();
686 } else {
687 enable_dumping_dynamic_archive(ArchiveClassesAtExit);
688 }
689
690 if (AutoCreateSharedArchive) {
691 if (SharedArchiveFile == nullptr) {
692 aot_log_warning(aot)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
693 return false;
694 }
695 if (ArchiveClassesAtExit != nullptr) {
696 aot_log_warning(aot)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
697 return false;
698 }
699 }
700
701 if (is_using_archive() && patch_mod_javabase) {
702 Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
703 }
704 if (is_using_archive() && has_unsupported_runtime_module_options()) {
705 UseSharedSpaces = false;
706 }
707
708 if (is_dumping_archive()) {
709 // Always verify non-system classes during CDS dump
710 if (!BytecodeVerificationRemote) {
711 BytecodeVerificationRemote = true;
712 aot_log_info(aot)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
713 }
714 }
715
716 return true;
717 }
718
719 void CDSConfig::setup_compiler_args() {
720 // AOT profiles and AOT-compiled code are supported only in the JEP 483 workflow.
721 bool can_dump_profile_and_compiled_code = AOTClassLinking && new_aot_flags_used();
943 return AOTClassLinking;
944 } else if (is_dumping_final_static_archive()) { // writing AOT cache
945 return is_dumping_aot_linked_classes();
946 } else if (is_dumping_classic_static_archive()) {
947 return is_dumping_aot_linked_classes();
948 } else {
949 return false;
950 }
951 }
952
953 bool CDSConfig::is_old_class_for_verifier(const InstanceKlass* ik) {
954 return ik->major_version() < 50 /*JAVA_6_VERSION*/;
955 }
956
957 #if INCLUDE_CDS_JAVA_HEAP
958 bool CDSConfig::are_vm_options_incompatible_with_dumping_heap() {
959 return check_options_incompatible_with_dumping_heap() != nullptr;
960 }
961
962 bool CDSConfig::is_dumping_heap() {
963 if (!(is_dumping_classic_static_archive() || is_dumping_final_static_archive())
964 || are_vm_options_incompatible_with_dumping_heap()
965 || _disable_heap_dumping) {
966 return false;
967 }
968 return true;
969 }
970
971 bool CDSConfig::is_loading_heap() {
972 return ArchiveHeapLoader::is_in_use();
973 }
974
975 bool CDSConfig::is_using_full_module_graph() {
976 if (ClassLoaderDataShared::is_full_module_graph_loaded()) {
977 return true;
978 }
979
980 if (!_is_using_full_module_graph) {
981 return false;
982 }
|
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "cds/aotLogging.hpp"
26 #include "cds/aotMapLogger.hpp"
27 #include "cds/archiveHeapLoader.hpp"
28 #include "cds/cdsConfig.hpp"
29 #include "cds/classListWriter.hpp"
30 #include "cds/filemap.hpp"
31 #include "cds/heapShared.hpp"
32 #include "classfile/classLoaderDataShared.hpp"
33 #include "classfile/moduleEntry.hpp"
34 #include "code/aotCodeCache.hpp"
35 #include "include/jvm_io.h"
36 #include "logging/log.hpp"
37 #include "memory/universe.hpp"
38 #include "prims/jvmtiAgentList.hpp"
39 #include "runtime/arguments.hpp"
40 #include "runtime/globals.hpp"
41 #include "runtime/globals_extension.hpp"
42 #include "runtime/java.hpp"
43 #include "runtime/vmThread.hpp"
44 #include "utilities/defaultStream.hpp"
45 #include "utilities/formatBuffer.hpp"
46
47 bool CDSConfig::_is_dumping_static_archive = false;
48 bool CDSConfig::_is_dumping_preimage_static_archive = false;
49 bool CDSConfig::_is_dumping_final_static_archive = false;
50 bool CDSConfig::_is_dumping_dynamic_archive = false;
51 bool CDSConfig::_is_using_optimized_module_handling = true;
52 bool CDSConfig::_is_dumping_full_module_graph = true;
53 bool CDSConfig::_is_using_full_module_graph = true;
54 bool CDSConfig::_has_aot_linked_classes = false;
55 bool CDSConfig::_is_single_command_training = false;
56 bool CDSConfig::_has_temp_aot_config_file = false;
57 bool CDSConfig::_old_cds_flags_used = false;
58 bool CDSConfig::_new_aot_flags_used = false;
59 bool CDSConfig::_disable_heap_dumping = false;
60 bool CDSConfig::_is_at_aot_safepoint = false;
61
62 bool CDSConfig::_module_patching_disables_cds = false;
63 bool CDSConfig::_java_base_module_patching_disables_cds = false;
64
65 const char* CDSConfig::_default_archive_path = nullptr;
66 const char* CDSConfig::_input_static_archive_path = nullptr;
67 const char* CDSConfig::_input_dynamic_archive_path = nullptr;
68 const char* CDSConfig::_output_archive_path = nullptr;
69
70 JavaThread* CDSConfig::_dumper_thread = nullptr;
71
72 int CDSConfig::get_status() {
73 assert(Universe::is_fully_initialized(), "status is finalized only after Universe is initialized");
74 return (is_dumping_aot_linked_classes() ? IS_DUMPING_AOT_LINKED_CLASSES : 0) |
75 (is_dumping_archive() ? IS_DUMPING_ARCHIVE : 0) |
76 (is_dumping_method_handles() ? IS_DUMPING_METHOD_HANDLES : 0) |
77 (is_dumping_static_archive() ? IS_DUMPING_STATIC_ARCHIVE : 0) |
78 (is_logging_lambda_form_invokers() ? IS_LOGGING_LAMBDA_FORM_INVOKERS : 0) |
79 (is_using_archive() ? IS_USING_ARCHIVE : 0);
80 }
81
82 DEBUG_ONLY(static bool _cds_ergo_initialize_started = false);
83
84 void CDSConfig::ergo_initialize() {
131 Abstract_VM_Version::vm_variant(), os::file_separator());
132 } else {
133 // Assume .jsa is in the same directory where libjvm resides on
134 // non-static JDK.
135 char jvm_path[JVM_MAXPATHLEN];
136 os::jvm_path(jvm_path, sizeof(jvm_path));
137 char *end = strrchr(jvm_path, *os::file_separator());
138 if (end != nullptr) *end = '\0';
139 tmp.print("%s%sclasses", jvm_path, os::file_separator());
140 }
141 #ifdef _LP64
142 if (!UseCompressedOops) {
143 tmp.print_raw("_nocoops");
144 }
145 if (UseCompactObjectHeaders) {
146 // Note that generation of xxx_coh.jsa variants require
147 // --enable-cds-archive-coh at build time
148 tmp.print_raw("_coh");
149 }
150 #endif
151 if (is_valhalla_preview()) {
152 tmp.print_raw("_valhalla");
153 }
154 tmp.print_raw(".jsa");
155 _default_archive_path = os::strdup(tmp.base());
156 }
157 return _default_archive_path;
158 }
159
160 int CDSConfig::num_archive_paths(const char* path_spec) {
161 if (path_spec == nullptr) {
162 return 0;
163 }
164 int npaths = 1;
165 char* p = (char*)path_spec;
166 while (*p != '\0') {
167 if (*p == os::path_separator()[0]) {
168 npaths++;
169 }
170 p++;
171 }
172 return npaths;
173 }
289 if (RecordDynamicDumpInfo) {
290 vm_exit_during_initialization("-XX:+RecordDynamicDumpInfo is unsupported when a dynamic CDS archive is specified in -XX:SharedArchiveFile",
291 SharedArchiveFile);
292 }
293 if (ArchiveClassesAtExit != nullptr) {
294 vm_exit_during_initialization("-XX:ArchiveClassesAtExit is unsupported when a dynamic CDS archive is specified in -XX:SharedArchiveFile",
295 SharedArchiveFile);
296 }
297 }
298
299 if (ArchiveClassesAtExit != nullptr && os::same_files(SharedArchiveFile, ArchiveClassesAtExit)) {
300 vm_exit_during_initialization(
301 "Cannot have the same archive file specified for -XX:SharedArchiveFile and -XX:ArchiveClassesAtExit",
302 SharedArchiveFile);
303 }
304 }
305 }
306 }
307
308 void CDSConfig::check_internal_module_property(const char* key, const char* value) {
309 if (Arguments::is_incompatible_cds_internal_module_property(key) && !Arguments::patching_migrated_classes(key, value)) {
310 stop_using_optimized_module_handling();
311 aot_log_info(aot)("optimized module handling: disabled due to incompatible property: %s=%s", key, value);
312 }
313 }
314
315 void CDSConfig::check_incompatible_property(const char* key, const char* value) {
316 static const char* incompatible_properties[] = {
317 "java.system.class.loader",
318 "jdk.module.showModuleResolution",
319 "jdk.module.validation"
320 };
321
322 for (const char* property : incompatible_properties) {
323 if (strcmp(key, property) == 0) {
324 stop_dumping_full_module_graph();
325 stop_using_full_module_graph();
326 aot_log_info(aot)("full module graph: disabled due to incompatible property: %s=%s", key, value);
327 break;
328 }
329 }
330
331 }
332
333 // Returns any JVM command-line option, such as "--patch-module", that's not supported by CDS.
334 static const char* find_any_unsupported_module_option() {
335 // Note that arguments.cpp has translated the command-line options into properties. If we find an
336 // unsupported property, translate it back to its command-line option for better error reporting.
337
338 // The following properties are checked by Arguments::is_internal_module_property() and cannot be
339 // directly specified in the command-line.
340 static const char* unsupported_module_properties[] = {
341 "jdk.module.limitmods",
342 "jdk.module.upgrade.path"
343 };
344 static const char* unsupported_module_options[] = {
345 "--limit-modules",
346 "--upgrade-module-path"
347 };
348
349 assert(ARRAY_SIZE(unsupported_module_properties) == ARRAY_SIZE(unsupported_module_options), "must be");
350 SystemProperty* sp = Arguments::system_properties();
351 while (sp != nullptr) {
352 for (uint i = 0; i < ARRAY_SIZE(unsupported_module_properties); i++) {
353 if (strcmp(sp->key(), unsupported_module_properties[i]) == 0) {
354 return unsupported_module_options[i];
355 }
356 }
357 sp = sp->next();
358 }
359
360 return nullptr; // not found
361 }
362
363 void CDSConfig::check_unsupported_dumping_module_options() {
364 assert(is_dumping_archive(), "this function is only used with CDS dump time");
365 const char* option = find_any_unsupported_module_option();
366 if (option != nullptr) {
367 vm_exit_during_initialization("Cannot use the following option when dumping the shared archive", option);
368 }
369
370 if (module_patching_disables_cds()) {
371 vm_exit_during_initialization(
372 "Cannot use the following option when dumping the shared archive", "--patch-module");
373 }
374
375 // Check for an exploded module build in use with -Xshare:dump.
376 if (!Arguments::has_jimage()) {
377 vm_exit_during_initialization("Dumping the shared archive is not supported with an exploded module build");
378 }
379 }
380
381 bool CDSConfig::has_unsupported_runtime_module_options() {
382 assert(is_using_archive(), "this function is only used with -Xshare:{on,auto}");
383 if (ArchiveClassesAtExit != nullptr) {
384 // dynamic dumping, just return false for now.
385 // check_unsupported_dumping_properties() will be called later to check the same set of
386 // properties, and will exit the VM with the correct error message if the unsupported properties
387 // are used.
388 return false;
389 }
390 const char* option = find_any_unsupported_module_option();
391 if (option != nullptr) {
392 if (RequireSharedSpaces) {
393 warning("CDS is disabled when the %s option is specified.", option);
394 } else {
395 if (new_aot_flags_used()) {
396 aot_log_warning(aot)("AOT cache is disabled when the %s option is specified.", option);
397 } else {
398 aot_log_info(aot)("CDS is disabled when the %s option is specified.", option);
399 }
400 }
401 return true;
402 }
403
404 if (module_patching_disables_cds()) {
405 if (RequireSharedSpaces) {
406 warning("CDS is disabled when the %s option is specified.", "--patch-module");
407 } else {
408 log_info(cds)("CDS is disabled when the %s option is specified.", "--patch-module");
409 }
410 return true;
411 }
412
413 return false;
414 }
415
416 #define CHECK_NEW_FLAG(f) check_new_flag(FLAG_IS_DEFAULT(f), #f)
417
418 void CDSConfig::check_new_flag(bool new_flag_is_default, const char* new_flag_name) {
419 if (old_cds_flags_used() && !new_flag_is_default) {
420 vm_exit_during_initialization(err_msg("Option %s cannot be used at the same time with "
421 "-Xshare:on, -Xshare:auto, -Xshare:off, -Xshare:dump, "
422 "DumpLoadedClassList, SharedClassListFile, or SharedArchiveFile",
423 new_flag_name));
424 }
425 }
426
427 #define CHECK_SINGLE_PATH(f) check_flag_single_path(#f, f)
428
429 void CDSConfig::check_flag_single_path(const char* flag_name, const char* value) {
430 if (value != nullptr && num_archive_paths(value) != 1) {
431 vm_exit_during_initialization(err_msg("Option %s must specify a single file name", flag_name));
432 }
627 void CDSConfig::ergo_init_aot_paths() {
628 assert(_cds_ergo_initialize_started, "sanity");
629 if (is_dumping_static_archive()) {
630 if (is_dumping_preimage_static_archive()) {
631 _output_archive_path = AOTConfiguration;
632 } else {
633 assert(is_dumping_final_static_archive(), "must be");
634 _input_static_archive_path = AOTConfiguration;
635 _output_archive_path = AOTCache;
636 }
637 } else if (is_using_archive()) {
638 if (FLAG_IS_DEFAULT(AOTCache)) {
639 // Only -XX:AOTMode={auto,on} is specified
640 _input_static_archive_path = default_archive_path();
641 } else {
642 _input_static_archive_path = AOTCache;
643 }
644 }
645 }
646
647 bool CDSConfig::check_vm_args_consistency(bool mode_flag_cmd_line) {
648 assert(!_cds_ergo_initialize_started, "This is called earlier than CDSConfig::ergo_initialize()");
649
650 check_aot_flags();
651
652 if (!FLAG_IS_DEFAULT(AOTMode)) {
653 // Using any form of the new AOTMode switch enables enhanced optimizations.
654 FLAG_SET_ERGO_IF_DEFAULT(AOTClassLinking, true);
655 }
656
657 setup_compiler_args();
658
659 if (AOTClassLinking) {
660 // If AOTClassLinking is specified, enable all AOT optimizations by default.
661 FLAG_SET_ERGO_IF_DEFAULT(AOTInvokeDynamicLinking, true);
662 } else {
663 // AOTInvokeDynamicLinking depends on AOTClassLinking.
664 FLAG_SET_ERGO(AOTInvokeDynamicLinking, false);
665 }
666
667 if (is_dumping_static_archive()) {
702 return false;
703 }
704
705 if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
706 disable_dumping_dynamic_archive();
707 } else {
708 enable_dumping_dynamic_archive(ArchiveClassesAtExit);
709 }
710
711 if (AutoCreateSharedArchive) {
712 if (SharedArchiveFile == nullptr) {
713 aot_log_warning(aot)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
714 return false;
715 }
716 if (ArchiveClassesAtExit != nullptr) {
717 aot_log_warning(aot)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
718 return false;
719 }
720 }
721
722 if (is_using_archive() && java_base_module_patching_disables_cds() && module_patching_disables_cds()) {
723 Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
724 }
725 if (is_using_archive() && has_unsupported_runtime_module_options()) {
726 UseSharedSpaces = false;
727 }
728
729 if (is_dumping_archive()) {
730 // Always verify non-system classes during CDS dump
731 if (!BytecodeVerificationRemote) {
732 BytecodeVerificationRemote = true;
733 aot_log_info(aot)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
734 }
735 }
736
737 return true;
738 }
739
740 void CDSConfig::setup_compiler_args() {
741 // AOT profiles and AOT-compiled code are supported only in the JEP 483 workflow.
742 bool can_dump_profile_and_compiled_code = AOTClassLinking && new_aot_flags_used();
964 return AOTClassLinking;
965 } else if (is_dumping_final_static_archive()) { // writing AOT cache
966 return is_dumping_aot_linked_classes();
967 } else if (is_dumping_classic_static_archive()) {
968 return is_dumping_aot_linked_classes();
969 } else {
970 return false;
971 }
972 }
973
974 bool CDSConfig::is_old_class_for_verifier(const InstanceKlass* ik) {
975 return ik->major_version() < 50 /*JAVA_6_VERSION*/;
976 }
977
978 #if INCLUDE_CDS_JAVA_HEAP
979 bool CDSConfig::are_vm_options_incompatible_with_dumping_heap() {
980 return check_options_incompatible_with_dumping_heap() != nullptr;
981 }
982
983 bool CDSConfig::is_dumping_heap() {
984 if (is_valhalla_preview()) {
985 // Not working yet -- e.g., HeapShared::oop_hash() needs to be implemented for value oops
986 return false;
987 }
988 if (!(is_dumping_classic_static_archive() || is_dumping_final_static_archive())
989 || are_vm_options_incompatible_with_dumping_heap()
990 || _disable_heap_dumping) {
991 return false;
992 }
993 return true;
994 }
995
996 bool CDSConfig::is_loading_heap() {
997 return ArchiveHeapLoader::is_in_use();
998 }
999
1000 bool CDSConfig::is_using_full_module_graph() {
1001 if (ClassLoaderDataShared::is_full_module_graph_loaded()) {
1002 return true;
1003 }
1004
1005 if (!_is_using_full_module_graph) {
1006 return false;
1007 }
|