19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
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/cdsConfig.hpp"
28 #include "cds/classListWriter.hpp"
29 #include "cds/filemap.hpp"
30 #include "cds/heapShared.inline.hpp"
31 #include "classfile/classLoaderDataShared.hpp"
32 #include "classfile/moduleEntry.hpp"
33 #include "code/aotCodeCache.hpp"
34 #include "include/jvm_io.h"
35 #include "logging/log.hpp"
36 #include "memory/universe.hpp"
37 #include "prims/jvmtiAgentList.hpp"
38 #include "runtime/arguments.hpp"
39 #include "runtime/globals_extension.hpp"
40 #include "runtime/java.hpp"
41 #include "runtime/vmThread.hpp"
42 #include "utilities/defaultStream.hpp"
43 #include "utilities/formatBuffer.hpp"
44
45 bool CDSConfig::_is_dumping_static_archive = false;
46 bool CDSConfig::_is_dumping_preimage_static_archive = false;
47 bool CDSConfig::_is_dumping_final_static_archive = false;
48 bool CDSConfig::_is_dumping_dynamic_archive = false;
49 bool CDSConfig::_is_using_optimized_module_handling = true;
50 bool CDSConfig::_is_dumping_full_module_graph = true;
51 bool CDSConfig::_is_using_full_module_graph = true;
52 bool CDSConfig::_has_aot_linked_classes = false;
53 bool CDSConfig::_is_single_command_training = false;
54 bool CDSConfig::_has_temp_aot_config_file = false;
55 bool CDSConfig::_old_cds_flags_used = false;
56 bool CDSConfig::_new_aot_flags_used = false;
57 bool CDSConfig::_disable_heap_dumping = false;
58 bool CDSConfig::_is_at_aot_safepoint = false;
59
60 const char* CDSConfig::_default_archive_path = nullptr;
61 const char* CDSConfig::_input_static_archive_path = nullptr;
62 const char* CDSConfig::_input_dynamic_archive_path = nullptr;
63 const char* CDSConfig::_output_archive_path = nullptr;
64
65 JavaThread* CDSConfig::_dumper_thread = nullptr;
66
67 int CDSConfig::get_status() {
68 assert(Universe::is_fully_initialized(), "status is finalized only after Universe is initialized");
69 return (is_dumping_aot_linked_classes() ? IS_DUMPING_AOT_LINKED_CLASSES : 0) |
70 (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() {
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 }
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 }
605 void CDSConfig::ergo_init_aot_paths() {
606 assert(_cds_ergo_initialize_started, "sanity");
607 if (is_dumping_static_archive()) {
608 if (is_dumping_preimage_static_archive()) {
609 _output_archive_path = AOTConfiguration;
610 } else {
611 assert(is_dumping_final_static_archive(), "must be");
612 _input_static_archive_path = AOTConfiguration;
613 _output_archive_path = AOTCache;
614 }
615 } else if (is_using_archive()) {
616 if (FLAG_IS_DEFAULT(AOTCache)) {
617 // Only -XX:AOTMode={auto,on} is specified
618 _input_static_archive_path = default_archive_path();
619 } else {
620 _input_static_archive_path = AOTCache;
621 }
622 }
623 }
624
625 bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) {
626 assert(!_cds_ergo_initialize_started, "This is called earlier than CDSConfig::ergo_initialize()");
627
628 check_aot_flags();
629
630 if (!FLAG_IS_DEFAULT(AOTMode)) {
631 // Using any form of the new AOTMode switch enables enhanced optimizations.
632 FLAG_SET_ERGO_IF_DEFAULT(AOTClassLinking, true);
633 }
634
635 setup_compiler_args();
636
637 if (AOTClassLinking) {
638 // If AOTClassLinking is specified, enable all AOT optimizations by default.
639 FLAG_SET_ERGO_IF_DEFAULT(AOTInvokeDynamicLinking, true);
640 } else {
641 // AOTInvokeDynamicLinking depends on AOTClassLinking.
642 FLAG_SET_ERGO(AOTInvokeDynamicLinking, false);
643 }
644
645 if (is_dumping_static_archive()) {
680 return false;
681 }
682
683 if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
684 disable_dumping_dynamic_archive();
685 } else {
686 enable_dumping_dynamic_archive(ArchiveClassesAtExit);
687 }
688
689 if (AutoCreateSharedArchive) {
690 if (SharedArchiveFile == nullptr) {
691 aot_log_warning(aot)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
692 return false;
693 }
694 if (ArchiveClassesAtExit != nullptr) {
695 aot_log_warning(aot)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
696 return false;
697 }
698 }
699
700 if (is_using_archive() && patch_mod_javabase) {
701 Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
702 }
703 if (is_using_archive() && has_unsupported_runtime_module_options()) {
704 UseSharedSpaces = false;
705 }
706
707 if (is_dumping_archive()) {
708 // Always verify non-system classes during CDS dump
709 if (!BytecodeVerificationRemote) {
710 BytecodeVerificationRemote = true;
711 aot_log_info(aot)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
712 }
713 }
714
715 return true;
716 }
717
718 void CDSConfig::setup_compiler_args() {
719 // AOT profiles and AOT-compiled code are supported only in the JEP 483 workflow.
720 bool can_dump_profile_and_compiled_code = AOTClassLinking && new_aot_flags_used();
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
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/cdsConfig.hpp"
28 #include "cds/classListWriter.hpp"
29 #include "cds/filemap.hpp"
30 #include "cds/heapShared.inline.hpp"
31 #include "classfile/classLoaderDataShared.hpp"
32 #include "classfile/moduleEntry.hpp"
33 #include "code/aotCodeCache.hpp"
34 #include "include/jvm_io.h"
35 #include "logging/log.hpp"
36 #include "memory/universe.hpp"
37 #include "prims/jvmtiAgentList.hpp"
38 #include "runtime/arguments.hpp"
39 #include "runtime/globals.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 bool CDSConfig::_module_patching_disables_cds = false;
62 bool CDSConfig::_java_base_module_patching_disables_cds = false;
63
64 const char* CDSConfig::_default_archive_path = nullptr;
65 const char* CDSConfig::_input_static_archive_path = nullptr;
66 const char* CDSConfig::_input_dynamic_archive_path = nullptr;
67 const char* CDSConfig::_output_archive_path = nullptr;
68
69 JavaThread* CDSConfig::_dumper_thread = nullptr;
70
71 int CDSConfig::get_status() {
72 assert(Universe::is_fully_initialized(), "status is finalized only after Universe is initialized");
73 return (is_dumping_aot_linked_classes() ? IS_DUMPING_AOT_LINKED_CLASSES : 0) |
74 (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() {
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 (Arguments::is_valhalla_enabled()) {
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 }
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 }
626 void CDSConfig::ergo_init_aot_paths() {
627 assert(_cds_ergo_initialize_started, "sanity");
628 if (is_dumping_static_archive()) {
629 if (is_dumping_preimage_static_archive()) {
630 _output_archive_path = AOTConfiguration;
631 } else {
632 assert(is_dumping_final_static_archive(), "must be");
633 _input_static_archive_path = AOTConfiguration;
634 _output_archive_path = AOTCache;
635 }
636 } else if (is_using_archive()) {
637 if (FLAG_IS_DEFAULT(AOTCache)) {
638 // Only -XX:AOTMode={auto,on} is specified
639 _input_static_archive_path = default_archive_path();
640 } else {
641 _input_static_archive_path = AOTCache;
642 }
643 }
644 }
645
646 bool CDSConfig::check_vm_args_consistency(bool mode_flag_cmd_line) {
647 assert(!_cds_ergo_initialize_started, "This is called earlier than CDSConfig::ergo_initialize()");
648
649 check_aot_flags();
650
651 if (!FLAG_IS_DEFAULT(AOTMode)) {
652 // Using any form of the new AOTMode switch enables enhanced optimizations.
653 FLAG_SET_ERGO_IF_DEFAULT(AOTClassLinking, true);
654 }
655
656 setup_compiler_args();
657
658 if (AOTClassLinking) {
659 // If AOTClassLinking is specified, enable all AOT optimizations by default.
660 FLAG_SET_ERGO_IF_DEFAULT(AOTInvokeDynamicLinking, true);
661 } else {
662 // AOTInvokeDynamicLinking depends on AOTClassLinking.
663 FLAG_SET_ERGO(AOTInvokeDynamicLinking, false);
664 }
665
666 if (is_dumping_static_archive()) {
701 return false;
702 }
703
704 if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
705 disable_dumping_dynamic_archive();
706 } else {
707 enable_dumping_dynamic_archive(ArchiveClassesAtExit);
708 }
709
710 if (AutoCreateSharedArchive) {
711 if (SharedArchiveFile == nullptr) {
712 aot_log_warning(aot)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
713 return false;
714 }
715 if (ArchiveClassesAtExit != nullptr) {
716 aot_log_warning(aot)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
717 return false;
718 }
719 }
720
721 if (is_using_archive() && java_base_module_patching_disables_cds() && module_patching_disables_cds()) {
722 Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
723 }
724 if (is_using_archive() && has_unsupported_runtime_module_options()) {
725 UseSharedSpaces = false;
726 }
727
728 if (is_dumping_archive()) {
729 // Always verify non-system classes during CDS dump
730 if (!BytecodeVerificationRemote) {
731 BytecodeVerificationRemote = true;
732 aot_log_info(aot)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
733 }
734 }
735
736 return true;
737 }
738
739 void CDSConfig::setup_compiler_args() {
740 // AOT profiles and AOT-compiled code are supported only in the JEP 483 workflow.
741 bool can_dump_profile_and_compiled_code = AOTClassLinking && new_aot_flags_used();
|