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