< prev index next >

src/hotspot/share/cds/cdsConfig.cpp

Print this page

   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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() {
  80   DEBUG_ONLY(_cds_ergo_initialize_started = true);
  81 
  82   if (is_dumping_static_archive() && !is_dumping_final_static_archive()) {
  83     // Note: -Xshare and -XX:AOTMode flags are mutually exclusive.
  84     // - Classic workflow: -Xshare:on and -Xshare:dump cannot take effect at the same time.
  85     // - JEP 483 workflow: -XX:AOTMode:record and -XX:AOTMode=on cannot take effect at the same time.
  86     // So we can never come to here with RequireSharedSpaces==true.
  87     assert(!RequireSharedSpaces, "sanity");
  88 
  89     // If dumping the classic archive, or making an AOT training run (dumping a preimage archive),
  90     // for sanity, parse all classes from classfiles.
  91     // TODO: in the future, if we want to support re-training on top of an existing AOT cache, this
  92     // needs to be changed.
  93     UseSharedSpaces = false;
  94   }
  95 
  96   // Initialize shared archive paths which could include both base and dynamic archive paths
  97   // This must be after set_ergonomics_flags() called so flag UseCompressedOops is set properly.
  98   if (is_dumping_static_archive() || is_using_archive()) {
  99     if (new_aot_flags_used()) {
 100       ergo_init_aot_paths();
 101     } else {
 102       ergo_init_classic_archive_paths();
 103     }
 104   }
 105 
 106   if (!is_dumping_heap()) {
 107     _is_dumping_full_module_graph = false;
 108   }
 109 
 110   AOTMapLogger::ergo_initialize();




















 111 }
 112 
 113 const char* CDSConfig::default_archive_path() {
 114   // The path depends on UseCompressedOops, etc, which are set by GC ergonomics just
 115   // before CDSConfig::ergo_initialize() is called.
 116   assert(_cds_ergo_initialize_started, "sanity");
 117   if (_default_archive_path == nullptr) {
 118     stringStream tmp;
 119     if (is_vm_statically_linked()) {
 120       // It's easier to form the path using JAVA_HOME as os::jvm_path
 121       // gives the path to the launcher executable on static JDK.
 122       const char* subdir = WINDOWS_ONLY("bin") NOT_WINDOWS("lib");
 123       tmp.print("%s%s%s%s%s%sclasses",
 124                 Arguments::get_java_home(), os::file_separator(),
 125                 subdir, os::file_separator(),
 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];

 280         // Check for case (c)
 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 

 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()) {
 646     if (is_dumping_preimage_static_archive()) {
 647       // Don't tweak execution mode during AOT training run
 648     } else if (is_dumping_final_static_archive()) {
 649       if (Arguments::mode() == Arguments::_comp) {
 650         // AOT assembly phase submits the non-blocking compilation requests
 651         // for methods collected during training run, then waits for all compilations
 652         // to complete. With -Xcomp, we block for each compilation request, which is
 653         // counter-productive. Switching back to mixed mode improves testing time
 654         // with AOT and -Xcomp.
 655         Arguments::set_mode_flags(Arguments::_mixed);
 656       }
 657     } else if (!mode_flag_cmd_line) {
 658       // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
 659       //
 660       // If your classlist is large and you don't care about deterministic dumping, you can use
 661       // -Xshare:dump -Xmixed to improve dumping speed.
 662       Arguments::set_mode_flags(Arguments::_int);
 663     } else if (Arguments::mode() == Arguments::_comp) {
 664       // -Xcomp may use excessive CPU for the test tiers. Also, -Xshare:dump runs a small and fixed set of

 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();

 721 
 722   if (is_dumping_preimage_static_archive() && can_dump_profile_and_compiled_code) {
 723     // JEP 483 workflow -- training
 724     FLAG_SET_ERGO_IF_DEFAULT(AOTRecordTraining, true);
 725     FLAG_SET_ERGO(AOTReplayTraining, false);
 726     AOTCodeCache::disable_caching(); // No AOT code generation during training run

 727   } else if (is_dumping_final_static_archive() && can_dump_profile_and_compiled_code) {
 728     // JEP 483 workflow -- assembly
 729     FLAG_SET_ERGO(AOTRecordTraining, false);
 730     FLAG_SET_ERGO_IF_DEFAULT(AOTReplayTraining, true);
 731     AOTCodeCache::enable_caching(); // Generate AOT code during assembly phase.

 732     disable_dumping_aot_code();     // Don't dump AOT code until metadata and heap are dumped.
 733   } else if (is_using_archive() && new_aot_flags_used()) {
 734     // JEP 483 workflow -- production
 735     FLAG_SET_ERGO(AOTRecordTraining, false);
 736     FLAG_SET_ERGO_IF_DEFAULT(AOTReplayTraining, true);
 737     AOTCodeCache::enable_caching();

 738   } else {
 739     FLAG_SET_ERGO(AOTReplayTraining, false);
 740     FLAG_SET_ERGO(AOTRecordTraining, false);
 741     AOTCodeCache::disable_caching();

 742   }
 743 }
 744 
 745 void CDSConfig::prepare_for_dumping() {
 746   assert(CDSConfig::is_dumping_archive(), "sanity");
 747 
 748   if (is_dumping_dynamic_archive() && AOTClassLinking) {
 749     if (FLAG_IS_CMDLINE(AOTClassLinking)) {
 750       log_warning(cds)("AOTClassLinking is not supported for dynamic CDS archive");
 751     }
 752     FLAG_SET_ERGO(AOTClassLinking, false);
 753   }
 754 
 755   if (is_dumping_dynamic_archive() && !is_using_archive()) {
 756     assert(!is_dumping_static_archive(), "cannot be dumping both static and dynamic archives");
 757 
 758     // This could happen if SharedArchiveFile has failed to load:
 759     // - -Xshare:off was specified
 760     // - SharedArchiveFile points to an non-existent file.
 761     // - SharedArchiveFile points to an archive that has failed CRC check

 770       aot_log_warning(aot)("-XX:ArchiveClassesAtExit" __THEMSG);
 771     }
 772 #undef __THEMSG
 773     disable_dumping_dynamic_archive();
 774     return;
 775   }
 776 
 777   check_unsupported_dumping_module_options();
 778 }
 779 
 780 bool CDSConfig::is_dumping_classic_static_archive() {
 781   return _is_dumping_static_archive &&
 782     !is_dumping_preimage_static_archive() &&
 783     !is_dumping_final_static_archive();
 784 }
 785 
 786 bool CDSConfig::is_dumping_preimage_static_archive() {
 787   return _is_dumping_preimage_static_archive;
 788 }
 789 




 790 bool CDSConfig::is_dumping_final_static_archive() {
 791   return _is_dumping_final_static_archive;
 792 }
 793 
 794 void CDSConfig::enable_dumping_dynamic_archive(const char* output_path) {
 795   _is_dumping_dynamic_archive = true;
 796   if (output_path == nullptr) {
 797     // output_path can be null when the VM is started with -XX:+RecordDynamicDumpInfo
 798     // in anticipation of "jcmd VM.cds dynamic_dump", which will provide the actual
 799     // output path.
 800     _output_archive_path = nullptr;
 801   } else {
 802     _output_archive_path = os::strdup_check_oom(output_path, mtArguments);
 803   }
 804 }
 805 
 806 bool CDSConfig::allow_only_single_java_thread() {
 807   // See comments in JVM_StartThread()
 808   return is_dumping_classic_static_archive() || is_dumping_final_static_archive();
 809 }
 810 




 811 bool CDSConfig::is_using_archive() {
 812   return UseSharedSpaces;
 813 }
 814 
 815 bool CDSConfig::is_using_only_default_archive() {
 816   return is_using_archive() &&
 817          input_static_archive_path() != nullptr &&
 818          default_archive_path() != nullptr &&
 819          strcmp(input_static_archive_path(), default_archive_path()) == 0 &&
 820          input_dynamic_archive_path() == nullptr;
 821 }
 822 
 823 bool CDSConfig::is_logging_lambda_form_invokers() {
 824   return ClassListWriter::is_enabled() || is_dumping_dynamic_archive();
 825 }
 826 
 827 bool CDSConfig::is_dumping_regenerated_lambdaform_invokers() {
 828   if (is_dumping_final_static_archive()) {
 829     // No need to regenerate -- the lambda form invokers should have been regenerated
 830     // in the preimage archive (if allowed)
 831     return false;
 832   } else if (is_dumping_dynamic_archive() && is_using_aot_linked_classes()) {
 833     // The base archive has aot-linked classes that may have AOT-resolved CP references
 834     // that point to the lambda form invokers in the base archive. Such pointers will
 835     // be invalid if lambda form invokers are regenerated in the dynamic archive.
 836     return false;
 837   } else {
 838     return is_dumping_archive();
 839   }
 840 }
 841 
 842 void CDSConfig::stop_using_optimized_module_handling() {
 843   _is_using_optimized_module_handling = false;
 844   _is_dumping_full_module_graph = false; // This requires is_using_optimized_module_handling()

1005   }
1006 }
1007 
1008 bool CDSConfig::is_dumping_aot_linked_classes() {
1009   if (is_dumping_classic_static_archive() || is_dumping_final_static_archive()) {
1010     // FMG is required to guarantee that all cached boot/platform/app classes
1011     // are visible in the production run, so they can be unconditionally
1012     // loaded during VM bootstrap.
1013     return is_dumping_full_module_graph() && AOTClassLinking;
1014   } else {
1015     return false;
1016   }
1017 }
1018 
1019 bool CDSConfig::is_using_aot_linked_classes() {
1020   // Make sure we have the exact same module graph as in the assembly phase, or else
1021   // some aot-linked classes may not be visible so cannot be loaded.
1022   return is_using_full_module_graph() && _has_aot_linked_classes;
1023 }
1024 




1025 void CDSConfig::set_has_aot_linked_classes(bool has_aot_linked_classes) {
1026   _has_aot_linked_classes |= has_aot_linked_classes;
1027 }
1028 
1029 bool CDSConfig::is_initing_classes_at_dump_time() {
1030   return is_dumping_heap() && is_dumping_aot_linked_classes();
1031 }
1032 
1033 bool CDSConfig::is_dumping_invokedynamic() {
1034   // Requires is_dumping_aot_linked_classes(). Otherwise the classes of some archived heap
1035   // objects used by the archive indy callsites may be replaced at runtime.
1036   return AOTInvokeDynamicLinking && is_dumping_aot_linked_classes() && is_dumping_heap();
1037 }
1038 





1039 // When we are dumping aot-linked classes and we are able to write archived heap objects, we automatically
1040 // enable the archiving of MethodHandles. This will in turn enable the archiving of MethodTypes and hidden
1041 // classes that are used in the implementation of MethodHandles.
1042 // Archived MethodHandles are required for higher-level optimizations such as AOT resolution of invokedynamic
1043 // and dynamic proxies.
1044 bool CDSConfig::is_dumping_method_handles() {
1045   return is_initing_classes_at_dump_time();
1046 }
1047 
1048 #endif // INCLUDE_CDS_JAVA_HEAP
1049 
1050 // AOT code generation and its archiving is disabled by default.
1051 // We enable it only in the final image dump after the metadata and heap are dumped.
1052 // This affects only JITed code because it may have embedded oops and metadata pointers
1053 // which AOT code encodes as offsets in final CDS archive regions.
1054 
1055 static bool _is_dumping_aot_code = false;
1056 
1057 bool CDSConfig::is_dumping_aot_code() {
1058   return _is_dumping_aot_code;

   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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/aotMetaspace.hpp"
  28 #include "cds/cds_globals.hpp"
  29 #include "cds/cdsConfig.hpp"
  30 #include "cds/classListWriter.hpp"
  31 #include "cds/filemap.hpp"
  32 #include "cds/heapShared.inline.hpp"
  33 #include "classfile/classLoaderDataShared.hpp"
  34 #include "classfile/moduleEntry.hpp"
  35 #include "classfile/systemDictionaryShared.hpp"
  36 #include "code/aotCodeCache.hpp"
  37 #include "compiler/compilerDefinitions.inline.hpp"
  38 #include "include/jvm_io.h"
  39 #include "logging/log.hpp"
  40 #include "memory/universe.hpp"
  41 #include "prims/jvmtiAgentList.hpp"
  42 #include "prims/jvmtiExport.hpp"
  43 #include "runtime/arguments.hpp"
  44 #include "runtime/globals_extension.hpp"
  45 #include "runtime/java.hpp"
  46 #include "runtime/vmThread.hpp"
  47 #include "utilities/defaultStream.hpp"
  48 #include "utilities/formatBuffer.hpp"
  49 
  50 bool CDSConfig::_is_dumping_static_archive = false;
  51 bool CDSConfig::_is_dumping_preimage_static_archive = false;
  52 bool CDSConfig::_is_dumping_final_static_archive = false;
  53 bool CDSConfig::_is_dumping_dynamic_archive = false;
  54 bool CDSConfig::_is_using_optimized_module_handling = true;
  55 bool CDSConfig::_is_dumping_full_module_graph = true;
  56 bool CDSConfig::_is_using_full_module_graph = true;
  57 bool CDSConfig::_has_aot_linked_classes = false;
  58 bool CDSConfig::_is_single_command_training = false;
  59 bool CDSConfig::_has_temp_aot_config_file = false;
  60 bool CDSConfig::_old_cds_flags_used = false;
  61 bool CDSConfig::_new_aot_flags_used = false;
  62 bool CDSConfig::_disable_heap_dumping = false;
  63 bool CDSConfig::_is_at_aot_safepoint = 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          (is_dumping_heap()                 ? IS_DUMPING_HEAP : 0) |
  81          (is_logging_dynamic_proxies()      ? IS_LOGGING_DYNAMIC_PROXIES : 0);
  82 }
  83 
  84 DEBUG_ONLY(static bool _cds_ergo_initialize_started = false);
  85 
  86 void CDSConfig::ergo_initialize() {
  87   DEBUG_ONLY(_cds_ergo_initialize_started = true);
  88 
  89   if (is_dumping_static_archive() && !is_dumping_final_static_archive()) {
  90     // Note: -Xshare and -XX:AOTMode flags are mutually exclusive.
  91     // - Classic workflow: -Xshare:on and -Xshare:dump cannot take effect at the same time.
  92     // - JEP 483 workflow: -XX:AOTMode:record and -XX:AOTMode=on cannot take effect at the same time.
  93     // So we can never come to here with RequireSharedSpaces==true.
  94     assert(!RequireSharedSpaces, "sanity");
  95 
  96     // If dumping the classic archive, or making an AOT training run (dumping a preimage archive),
  97     // for sanity, parse all classes from classfiles.
  98     // TODO: in the future, if we want to support re-training on top of an existing AOT cache, this
  99     // needs to be changed.
 100     UseSharedSpaces = false;
 101   }
 102 
 103   // Initialize shared archive paths which could include both base and dynamic archive paths
 104   // This must be after set_ergonomics_flags() called so flag UseCompressedOops is set properly.
 105   if (is_dumping_static_archive() || is_using_archive()) {
 106     if (new_aot_flags_used()) {
 107       ergo_init_aot_paths();
 108     } else {
 109       ergo_init_classic_archive_paths();
 110     }
 111   }
 112 
 113   if (!is_dumping_heap()) {
 114     _is_dumping_full_module_graph = false;
 115   }
 116 
 117   AOTMapLogger::ergo_initialize();
 118 
 119 #ifdef _LP64
 120   //
 121   // By default, when using AOTClassLinking, use the CompressedOops::HeapBasedNarrowOop
 122   // mode so that AOT code can be always work regardless of runtime heap range.
 123   //
 124   // If you are *absolutely sure* that the CompressedOops::mode() will be the same
 125   // between training and production runs (e.g., if you specify -Xmx128m for
 126   // both training and production runs, and you know the OS will always reserve
 127   // the heap under 4GB), you can explicitly disable this with:
 128   //     java -XX:+UnlockDiagnosticVMOptions -XX:-UseCompatibleCompressedOops ...
 129   // However, this is risky and there's a chance that the production run will be slower
 130   // than expected because it is unable to load the AOT code cache.
 131   //
 132   if (UseCompressedOops && AOTCodeCache::is_caching_enabled()) {
 133     FLAG_SET_ERGO_IF_DEFAULT(UseCompatibleCompressedOops, true);
 134   } else if (!FLAG_IS_DEFAULT(UseCompatibleCompressedOops)) {
 135     FLAG_SET_ERGO(UseCompatibleCompressedOops, false);
 136   }
 137 #endif // _LP64
 138 }
 139 
 140 const char* CDSConfig::default_archive_path() {
 141   // The path depends on UseCompressedOops, etc, which are set by GC ergonomics just
 142   // before CDSConfig::ergo_initialize() is called.
 143   assert(_cds_ergo_initialize_started, "sanity");
 144   if (_default_archive_path == nullptr) {
 145     stringStream tmp;
 146     if (is_vm_statically_linked()) {
 147       // It's easier to form the path using JAVA_HOME as os::jvm_path
 148       // gives the path to the launcher executable on static JDK.
 149       const char* subdir = WINDOWS_ONLY("bin") NOT_WINDOWS("lib");
 150       tmp.print("%s%s%s%s%s%sclasses",
 151                 Arguments::get_java_home(), os::file_separator(),
 152                 subdir, os::file_separator(),
 153                 Abstract_VM_Version::vm_variant(), os::file_separator());
 154     } else {
 155       // Assume .jsa is in the same directory where libjvm resides on
 156       // non-static JDK.
 157       char jvm_path[JVM_MAXPATHLEN];

 307         // Check for case (c)
 308         if (RecordDynamicDumpInfo) {
 309           vm_exit_during_initialization("-XX:+RecordDynamicDumpInfo is unsupported when a dynamic CDS archive is specified in -XX:SharedArchiveFile",
 310                                         SharedArchiveFile);
 311         }
 312         if (ArchiveClassesAtExit != nullptr) {
 313           vm_exit_during_initialization("-XX:ArchiveClassesAtExit is unsupported when a dynamic CDS archive is specified in -XX:SharedArchiveFile",
 314                                         SharedArchiveFile);
 315         }
 316       }
 317 
 318       if (ArchiveClassesAtExit != nullptr && os::same_files(SharedArchiveFile, ArchiveClassesAtExit)) {
 319           vm_exit_during_initialization(
 320             "Cannot have the same archive file specified for -XX:SharedArchiveFile and -XX:ArchiveClassesAtExit",
 321             SharedArchiveFile);
 322       }
 323     }
 324   }
 325 }
 326 
 327 static char* bad_module_prop_key   = nullptr;
 328 static char* bad_module_prop_value = nullptr;
 329 
 330 void CDSConfig::check_internal_module_property(const char* key, const char* value) {
 331   if (Arguments::is_incompatible_cds_internal_module_property(key)) {
 332     stop_using_optimized_module_handling();
 333     if (bad_module_prop_key == nullptr) {
 334       // We don't want to print an unconditional warning here, as we are still processing the command line.
 335       // A later argument may specify something like -Xshare:off, which makes such a warning irrelevant.
 336       //
 337       // Instead, we save the info so we can warn when necessary: we are doing it only during AOT Cache
 338       // creation for now, but could add it to other places.
 339       bad_module_prop_key   = os::strdup(key);
 340       bad_module_prop_value = os::strdup(value);
 341     }
 342     aot_log_info(aot)("optimized module handling: disabled due to incompatible property: %s=%s", key, value);
 343   }
 344 }
 345 
 346 void CDSConfig::check_incompatible_property(const char* key, const char* value) {
 347   static const char* incompatible_properties[] = {
 348     "java.system.class.loader",
 349     "jdk.module.showModuleResolution",
 350     "jdk.module.validation"
 351   };
 352 
 353   for (const char* property : incompatible_properties) {
 354     if (strcmp(key, property) == 0) {
 355       stop_dumping_full_module_graph();
 356       stop_using_full_module_graph();
 357       aot_log_info(aot)("full module graph: disabled due to incompatible property: %s=%s", key, value);
 358       break;
 359     }
 360   }

 361 }
 362 
 363 // Returns any JVM command-line option, such as "--patch-module", that's not supported by CDS.
 364 static const char* find_any_unsupported_module_option() {
 365   // Note that arguments.cpp has translated the command-line options into properties. If we find an
 366   // unsupported property, translate it back to its command-line option for better error reporting.
 367 
 368   // The following properties are checked by Arguments::is_internal_module_property() and cannot be
 369   // directly specified in the command-line.
 370   static const char* unsupported_module_properties[] = {
 371     "jdk.module.limitmods",
 372     "jdk.module.upgrade.path",
 373     "jdk.module.patch.0"
 374   };
 375   static const char* unsupported_module_options[] = {
 376     "--limit-modules",
 377     "--upgrade-module-path",
 378     "--patch-module"
 379   };
 380 

 656       _input_static_archive_path = default_archive_path();
 657     } else {
 658       _input_static_archive_path = AOTCache;
 659     }
 660   }
 661 }
 662 
 663 bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) {
 664   assert(!_cds_ergo_initialize_started, "This is called earlier than CDSConfig::ergo_initialize()");
 665 
 666   check_aot_flags();
 667 
 668   if (!FLAG_IS_DEFAULT(AOTMode)) {
 669     // Using any form of the new AOTMode switch enables enhanced optimizations.
 670     FLAG_SET_ERGO_IF_DEFAULT(AOTClassLinking, true);
 671   }
 672 
 673   setup_compiler_args();
 674 
 675   if (AOTClassLinking) {
 676     // If AOTClassLinking is specified, enable all these optimizations by default.
 677     FLAG_SET_ERGO_IF_DEFAULT(AOTInvokeDynamicLinking, true);
 678     FLAG_SET_ERGO_IF_DEFAULT(ArchiveDynamicProxies, true);
 679     FLAG_SET_ERGO_IF_DEFAULT(ArchiveLoaderLookupCache, true);
 680     FLAG_SET_ERGO_IF_DEFAULT(ArchiveReflectionData, true);
 681 
 682     // For simplicity, enable these by default only for new workflow
 683     if (new_aot_flags_used()) {
 684       // These flags will be removed when JDK-8350550 is merged from mainline
 685       FLAG_SET_ERGO_IF_DEFAULT(ArchivePackages, true);
 686       FLAG_SET_ERGO_IF_DEFAULT(ArchiveProtectionDomains, true);
 687     }
 688   } else {
 689     // All of these *might* depend on AOTClassLinking. Better be safe than sorry.
 690     FLAG_SET_ERGO(AOTInvokeDynamicLinking, false);
 691     FLAG_SET_ERGO(ArchiveDynamicProxies, false);
 692     FLAG_SET_ERGO(ArchiveLoaderLookupCache, false);
 693     FLAG_SET_ERGO(ArchivePackages, false);
 694     FLAG_SET_ERGO(ArchiveProtectionDomains, false);
 695     FLAG_SET_ERGO(ArchiveReflectionData, false);
 696 
 697     if (CDSConfig::is_dumping_archive()) {
 698       FLAG_SET_ERGO(AOTRecordTraining, false);
 699       FLAG_SET_ERGO(AOTReplayTraining, false);
 700       AOTCodeCache::disable_caching();
 701     }
 702   }

 703   if (is_dumping_static_archive()) {
 704     if (is_dumping_preimage_static_archive()) {
 705       // Don't tweak execution mode during AOT training run
 706     } else if (is_dumping_final_static_archive()) {
 707       if (Arguments::mode() == Arguments::_comp) {
 708         // AOT assembly phase submits the non-blocking compilation requests
 709         // for methods collected during training run, then waits for all compilations
 710         // to complete. With -Xcomp, we block for each compilation request, which is
 711         // counter-productive. Switching back to mixed mode improves testing time
 712         // with AOT and -Xcomp.
 713         Arguments::set_mode_flags(Arguments::_mixed);
 714       }
 715     } else if (!mode_flag_cmd_line) {
 716       // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
 717       //
 718       // If your classlist is large and you don't care about deterministic dumping, you can use
 719       // -Xshare:dump -Xmixed to improve dumping speed.
 720       Arguments::set_mode_flags(Arguments::_int);
 721     } else if (Arguments::mode() == Arguments::_comp) {
 722       // -Xcomp may use excessive CPU for the test tiers. Also, -Xshare:dump runs a small and fixed set of

 753       aot_log_warning(aot)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
 754       return false;
 755     }
 756   }
 757 
 758   if (is_using_archive() && patch_mod_javabase) {
 759     Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
 760   }
 761   if (is_using_archive() && has_unsupported_runtime_module_options()) {
 762     UseSharedSpaces = false;
 763   }
 764 
 765   if (is_dumping_archive()) {
 766     // Always verify non-system classes during CDS dump
 767     if (!BytecodeVerificationRemote) {
 768       BytecodeVerificationRemote = true;
 769       aot_log_info(aot)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
 770     }
 771   }
 772 
 773   if (AOTClassLinking) {
 774     if (is_dumping_final_static_archive() && !is_dumping_full_module_graph()) {
 775       if (bad_module_prop_key != nullptr) {
 776         log_warning(cds)("optimized module handling/full module graph: disabled due to incompatible property: %s=%s",
 777                          bad_module_prop_key, bad_module_prop_value);
 778       }
 779       vm_exit_during_initialization("AOT cache cannot be created because AOTClassLinking is enabled but full module graph is disabled");
 780     }
 781   }
 782 
 783   return true;
 784 }
 785 
 786 void CDSConfig::setup_compiler_args() {
 787   // AOT profiles and AOT-compiled methods are supported only in the JEP 483 workflow.
 788   bool can_dump_profile_and_compiled_code = !CompilerConfig::is_interpreter_only() && AOTClassLinking && new_aot_flags_used();
 789   bool can_use_profile_and_compiled_code = !CompilerConfig::is_interpreter_only() && new_aot_flags_used();
 790 
 791   if (is_dumping_preimage_static_archive() && can_dump_profile_and_compiled_code) {
 792     // JEP 483 workflow -- training
 793     FLAG_SET_ERGO_IF_DEFAULT(AOTRecordTraining, true);
 794     FLAG_SET_ERGO(AOTReplayTraining, false);
 795     AOTCodeCache::disable_caching(); // No AOT code generation during training run
 796     FLAG_SET_ERGO(UseAOTCodeLoadThread, false);
 797   } else if (is_dumping_final_static_archive() && can_dump_profile_and_compiled_code) {
 798     // JEP 483 workflow -- assembly
 799     FLAG_SET_ERGO(AOTRecordTraining, false);
 800     FLAG_SET_ERGO_IF_DEFAULT(AOTReplayTraining, true);
 801     AOTCodeCache::enable_caching(); // Generate AOT code during assembly phase.
 802     FLAG_SET_ERGO(UseAOTCodeLoadThread, false);
 803     disable_dumping_aot_code();     // Don't dump AOT code until metadata and heap are dumped.
 804   } else if (is_using_archive() && can_use_profile_and_compiled_code) {
 805     // JEP 483 workflow -- production
 806     FLAG_SET_ERGO(AOTRecordTraining, false);
 807     FLAG_SET_ERGO_IF_DEFAULT(AOTReplayTraining, true);
 808     AOTCodeCache::enable_caching();
 809     FLAG_SET_ERGO_IF_DEFAULT(UseAOTCodeLoadThread, true);
 810   } else {
 811     FLAG_SET_ERGO(AOTReplayTraining, false);
 812     FLAG_SET_ERGO(AOTRecordTraining, false);
 813     AOTCodeCache::disable_caching();
 814     FLAG_SET_ERGO(UseAOTCodeLoadThread, false);
 815   }
 816 }
 817 
 818 void CDSConfig::prepare_for_dumping() {
 819   assert(CDSConfig::is_dumping_archive(), "sanity");
 820 
 821   if (is_dumping_dynamic_archive() && AOTClassLinking) {
 822     if (FLAG_IS_CMDLINE(AOTClassLinking)) {
 823       log_warning(cds)("AOTClassLinking is not supported for dynamic CDS archive");
 824     }
 825     FLAG_SET_ERGO(AOTClassLinking, false);
 826   }
 827 
 828   if (is_dumping_dynamic_archive() && !is_using_archive()) {
 829     assert(!is_dumping_static_archive(), "cannot be dumping both static and dynamic archives");
 830 
 831     // This could happen if SharedArchiveFile has failed to load:
 832     // - -Xshare:off was specified
 833     // - SharedArchiveFile points to an non-existent file.
 834     // - SharedArchiveFile points to an archive that has failed CRC check

 843       aot_log_warning(aot)("-XX:ArchiveClassesAtExit" __THEMSG);
 844     }
 845 #undef __THEMSG
 846     disable_dumping_dynamic_archive();
 847     return;
 848   }
 849 
 850   check_unsupported_dumping_module_options();
 851 }
 852 
 853 bool CDSConfig::is_dumping_classic_static_archive() {
 854   return _is_dumping_static_archive &&
 855     !is_dumping_preimage_static_archive() &&
 856     !is_dumping_final_static_archive();
 857 }
 858 
 859 bool CDSConfig::is_dumping_preimage_static_archive() {
 860   return _is_dumping_preimage_static_archive;
 861 }
 862 
 863 bool CDSConfig::is_dumping_preimage_static_archive_with_triggers() {
 864   return (!FLAG_IS_DEFAULT(AOTEndTrainingOnMethodEntry)) && is_dumping_preimage_static_archive();
 865 }
 866 
 867 bool CDSConfig::is_dumping_final_static_archive() {
 868   return _is_dumping_final_static_archive;
 869 }
 870 
 871 void CDSConfig::enable_dumping_dynamic_archive(const char* output_path) {
 872   _is_dumping_dynamic_archive = true;
 873   if (output_path == nullptr) {
 874     // output_path can be null when the VM is started with -XX:+RecordDynamicDumpInfo
 875     // in anticipation of "jcmd VM.cds dynamic_dump", which will provide the actual
 876     // output path.
 877     _output_archive_path = nullptr;
 878   } else {
 879     _output_archive_path = os::strdup_check_oom(output_path, mtArguments);
 880   }
 881 }
 882 
 883 bool CDSConfig::allow_only_single_java_thread() {
 884   // See comments in JVM_StartThread()
 885   return is_dumping_classic_static_archive() || is_dumping_final_static_archive();
 886 }
 887 
 888 bool CDSConfig::is_logging_dynamic_proxies() {
 889   return ClassListWriter::is_enabled() || is_dumping_preimage_static_archive();
 890 }
 891 
 892 bool CDSConfig::is_using_archive() {
 893   return UseSharedSpaces;
 894 }
 895 
 896 bool CDSConfig::is_using_only_default_archive() {
 897   return is_using_archive() &&
 898          input_static_archive_path() != nullptr &&
 899          default_archive_path() != nullptr &&
 900          strcmp(input_static_archive_path(), default_archive_path()) == 0 &&
 901          input_dynamic_archive_path() == nullptr;
 902 }
 903 
 904 bool CDSConfig::is_logging_lambda_form_invokers() {
 905   return ClassListWriter::is_enabled() || is_dumping_dynamic_archive() || is_dumping_preimage_static_archive();
 906 }
 907 
 908 bool CDSConfig::is_dumping_regenerated_lambdaform_invokers() {
 909   if (is_dumping_final_static_archive()) {
 910     // No need to regenerate -- the lambda form invokers should have been regenerated
 911     // in the preimage archive (if allowed)
 912     return false;
 913   } else if (is_dumping_dynamic_archive() && is_using_aot_linked_classes()) {
 914     // The base archive has aot-linked classes that may have AOT-resolved CP references
 915     // that point to the lambda form invokers in the base archive. Such pointers will
 916     // be invalid if lambda form invokers are regenerated in the dynamic archive.
 917     return false;
 918   } else {
 919     return is_dumping_archive();
 920   }
 921 }
 922 
 923 void CDSConfig::stop_using_optimized_module_handling() {
 924   _is_using_optimized_module_handling = false;
 925   _is_dumping_full_module_graph = false; // This requires is_using_optimized_module_handling()

1086   }
1087 }
1088 
1089 bool CDSConfig::is_dumping_aot_linked_classes() {
1090   if (is_dumping_classic_static_archive() || is_dumping_final_static_archive()) {
1091     // FMG is required to guarantee that all cached boot/platform/app classes
1092     // are visible in the production run, so they can be unconditionally
1093     // loaded during VM bootstrap.
1094     return is_dumping_full_module_graph() && AOTClassLinking;
1095   } else {
1096     return false;
1097   }
1098 }
1099 
1100 bool CDSConfig::is_using_aot_linked_classes() {
1101   // Make sure we have the exact same module graph as in the assembly phase, or else
1102   // some aot-linked classes may not be visible so cannot be loaded.
1103   return is_using_full_module_graph() && _has_aot_linked_classes;
1104 }
1105 
1106 bool CDSConfig::is_dumping_dynamic_proxies() {
1107   return is_dumping_full_module_graph() && is_dumping_invokedynamic() && ArchiveDynamicProxies;
1108 }
1109 
1110 void CDSConfig::set_has_aot_linked_classes(bool has_aot_linked_classes) {
1111   _has_aot_linked_classes |= has_aot_linked_classes;
1112 }
1113 
1114 bool CDSConfig::is_initing_classes_at_dump_time() {
1115   return is_dumping_heap() && is_dumping_aot_linked_classes();
1116 }
1117 
1118 bool CDSConfig::is_dumping_invokedynamic() {
1119   // Requires is_dumping_aot_linked_classes(). Otherwise the classes of some archived heap
1120   // objects used by the archive indy callsites may be replaced at runtime.
1121   return AOTInvokeDynamicLinking && is_dumping_aot_linked_classes() && is_dumping_heap();
1122 }
1123 
1124 bool CDSConfig::is_dumping_reflection_data() {
1125   // reflection data use LambdaForm classes
1126   return ArchiveReflectionData && is_dumping_invokedynamic();
1127 }
1128 
1129 // When we are dumping aot-linked classes and we are able to write archived heap objects, we automatically
1130 // enable the archiving of MethodHandles. This will in turn enable the archiving of MethodTypes and hidden
1131 // classes that are used in the implementation of MethodHandles.
1132 // Archived MethodHandles are required for higher-level optimizations such as AOT resolution of invokedynamic
1133 // and dynamic proxies.
1134 bool CDSConfig::is_dumping_method_handles() {
1135   return is_initing_classes_at_dump_time();
1136 }
1137 
1138 #endif // INCLUDE_CDS_JAVA_HEAP
1139 
1140 // AOT code generation and its archiving is disabled by default.
1141 // We enable it only in the final image dump after the metadata and heap are dumped.
1142 // This affects only JITed code because it may have embedded oops and metadata pointers
1143 // which AOT code encodes as offsets in final CDS archive regions.
1144 
1145 static bool _is_dumping_aot_code = false;
1146 
1147 bool CDSConfig::is_dumping_aot_code() {
1148   return _is_dumping_aot_code;
< prev index next >