< 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/archiveHeapLoader.hpp"
  26 #include "cds/cdsConfig.hpp"

  27 #include "cds/classListWriter.hpp"
  28 #include "cds/filemap.hpp"
  29 #include "cds/heapShared.hpp"

  30 #include "classfile/classLoaderDataShared.hpp"
  31 #include "classfile/moduleEntry.hpp"


  32 #include "include/jvm_io.h"
  33 #include "logging/log.hpp"

  34 #include "memory/universe.hpp"
  35 #include "runtime/arguments.hpp"
  36 #include "runtime/globals_extension.hpp"
  37 #include "runtime/java.hpp"
  38 #include "runtime/vmThread.hpp"
  39 #include "utilities/defaultStream.hpp"
  40 #include "utilities/formatBuffer.hpp"
  41 
  42 bool CDSConfig::_is_dumping_static_archive = false;
  43 bool CDSConfig::_is_dumping_preimage_static_archive = false;
  44 bool CDSConfig::_is_dumping_final_static_archive = false;
  45 bool CDSConfig::_is_dumping_dynamic_archive = false;
  46 bool CDSConfig::_is_using_optimized_module_handling = true;
  47 bool CDSConfig::_is_dumping_full_module_graph = true;
  48 bool CDSConfig::_is_using_full_module_graph = true;
  49 bool CDSConfig::_has_aot_linked_classes = false;
  50 bool CDSConfig::_has_archived_invokedynamic = false;



  51 bool CDSConfig::_old_cds_flags_used = false;
  52 bool CDSConfig::_new_aot_flags_used = false;
  53 bool CDSConfig::_disable_heap_dumping = false;
  54 
  55 char* CDSConfig::_default_archive_path = nullptr;
  56 char* CDSConfig::_static_archive_path = nullptr;
  57 char* CDSConfig::_dynamic_archive_path = nullptr;
  58 
  59 JavaThread* CDSConfig::_dumper_thread = nullptr;
  60 
  61 int CDSConfig::get_status() {
  62   assert(Universe::is_fully_initialized(), "status is finalized only after Universe is initialized");
  63   return (is_dumping_archive()              ? IS_DUMPING_ARCHIVE : 0) |
  64          (is_dumping_static_archive()       ? IS_DUMPING_STATIC_ARCHIVE : 0) |
  65          (is_logging_lambda_form_invokers() ? IS_LOGGING_LAMBDA_FORM_INVOKERS : 0) |
  66          (is_using_archive()                ? IS_USING_ARCHIVE : 0);




  67 }
  68 
  69 void CDSConfig::initialize() {
  70   if (is_dumping_static_archive() && !is_dumping_final_static_archive()) {




  71     if (RequireSharedSpaces) {
  72       warning("Cannot dump shared archive while using shared archive");







  73     }
  74     UseSharedSpaces = false;
  75   }
  76 
  77   // Initialize shared archive paths which could include both base and dynamic archive paths
  78   // This must be after set_ergonomics_flags() called so flag UseCompressedOops is set properly.
  79   //
  80   // UseSharedSpaces may be disabled if -XX:SharedArchiveFile is invalid.
  81   if (is_dumping_static_archive() || is_using_archive()) {
  82     init_shared_archive_paths();
  83   }
  84 
  85   if (!is_dumping_heap()) {
  86     _is_dumping_full_module_graph = false;
  87   }
  88 }
  89 
  90 char* CDSConfig::default_archive_path() {
  91   if (_default_archive_path == nullptr) {
  92     char jvm_path[JVM_MAXPATHLEN];

 160     }
 161     check_unsupported_dumping_module_options();
 162 
 163     if (os::same_files(default_archive_path(), ArchiveClassesAtExit)) {
 164       vm_exit_during_initialization(
 165         "Cannot specify the default CDS archive for -XX:ArchiveClassesAtExit", default_archive_path());
 166     }
 167   }
 168 
 169   if (SharedArchiveFile == nullptr) {
 170     _static_archive_path = default_archive_path();
 171   } else {
 172     int archives = num_archives(SharedArchiveFile);
 173     assert(archives > 0, "must be");
 174 
 175     if (is_dumping_archive() && archives > 1) {
 176       vm_exit_during_initialization(
 177         "Cannot have more than 1 archive file specified in -XX:SharedArchiveFile during CDS dumping");
 178     }
 179 




 180     if (is_dumping_static_archive()) {
 181       assert(archives == 1, "must be");
 182       // Static dump is simple: only one archive is allowed in SharedArchiveFile. This file
 183       // will be overwritten no matter regardless of its contents
 184       _static_archive_path = os::strdup_check_oom(SharedArchiveFile, mtArguments);
 185     } else {
 186       // SharedArchiveFile may specify one or two files. In case (c), the path for base.jsa
 187       // is read from top.jsa
 188       //    (a) 1 file:  -XX:SharedArchiveFile=base.jsa
 189       //    (b) 2 files: -XX:SharedArchiveFile=base.jsa:top.jsa
 190       //    (c) 2 files: -XX:SharedArchiveFile=top.jsa
 191       //
 192       // However, if either RecordDynamicDumpInfo or ArchiveClassesAtExit is used, we do not
 193       // allow cases (b) and (c). Case (b) is already checked above.
 194 
 195       if (archives > 2) {
 196         vm_exit_during_initialization(
 197           "Cannot have more than 2 archive files specified in the -XX:SharedArchiveFile option");
 198       }
 199       if (archives == 1) {
 200         char* base_archive_path = nullptr;
 201         bool success =
 202           FileMapInfo::get_base_archive_name_from_header(SharedArchiveFile, &base_archive_path);
 203         if (!success) {




 204           // If +AutoCreateSharedArchive and the specified shared archive does not exist,
 205           // regenerate the dynamic archive base on default archive.
 206           if (AutoCreateSharedArchive && !os::file_exists(SharedArchiveFile)) {
 207             enable_dumping_dynamic_archive();
 208             ArchiveClassesAtExit = const_cast<char *>(SharedArchiveFile);
 209             _static_archive_path = default_archive_path();
 210             SharedArchiveFile = nullptr;
 211           } else {
 212             if (AutoCreateSharedArchive) {
 213               warning("-XX:+AutoCreateSharedArchive is unsupported when base CDS archive is not loaded. Run with -Xlog:cds for more info.");
 214               AutoCreateSharedArchive = false;
 215             }
 216             log_error(cds)("Not a valid %s (%s)", new_aot_flags_used() ? "AOT cache" : "archive", SharedArchiveFile);
 217             Arguments::no_shared_spaces("invalid archive");
 218           }
 219         } else if (base_archive_path == nullptr) {
 220           // User has specified a single archive, which is a static archive.
 221           _static_archive_path = const_cast<char *>(SharedArchiveFile);
 222         } else {
 223           // User has specified a single archive, which is a dynamic archive.

 237         // Check for case (c)
 238         if (RecordDynamicDumpInfo) {
 239           vm_exit_during_initialization("-XX:+RecordDynamicDumpInfo is unsupported when a dynamic CDS archive is specified in -XX:SharedArchiveFile",
 240                                         SharedArchiveFile);
 241         }
 242         if (ArchiveClassesAtExit != nullptr) {
 243           vm_exit_during_initialization("-XX:ArchiveClassesAtExit is unsupported when a dynamic CDS archive is specified in -XX:SharedArchiveFile",
 244                                         SharedArchiveFile);
 245         }
 246       }
 247 
 248       if (ArchiveClassesAtExit != nullptr && os::same_files(SharedArchiveFile, ArchiveClassesAtExit)) {
 249           vm_exit_during_initialization(
 250             "Cannot have the same archive file specified for -XX:SharedArchiveFile and -XX:ArchiveClassesAtExit",
 251             SharedArchiveFile);
 252       }
 253     }
 254   }
 255 }
 256 



 257 void CDSConfig::check_internal_module_property(const char* key, const char* value) {
 258   if (Arguments::is_incompatible_cds_internal_module_property(key)) {
 259     stop_using_optimized_module_handling();
 260     log_info(cds)("optimized module handling: disabled due to incompatible property: %s=%s", key, value);









 261   }
 262 }
 263 
 264 void CDSConfig::check_incompatible_property(const char* key, const char* value) {
 265   static const char* incompatible_properties[] = {
 266     "java.system.class.loader",
 267     "jdk.module.showModuleResolution",
 268     "jdk.module.validation"
 269   };
 270 
 271   for (const char* property : incompatible_properties) {
 272     if (strcmp(key, property) == 0) {
 273       stop_dumping_full_module_graph();
 274       stop_using_full_module_graph();
 275       log_info(cds)("full module graph: disabled due to incompatible property: %s=%s", key, value);
 276       break;
 277     }
 278   }
 279 






 280 }
 281 
 282 // Returns any JVM command-line option, such as "--patch-module", that's not supported by CDS.
 283 static const char* find_any_unsupported_module_option() {
 284   // Note that arguments.cpp has translated the command-line options into properties. If we find an
 285   // unsupported property, translate it back to its command-line option for better error reporting.
 286 
 287   // The following properties are checked by Arguments::is_internal_module_property() and cannot be
 288   // directly specified in the command-line.
 289   static const char* unsupported_module_properties[] = {
 290     "jdk.module.limitmods",
 291     "jdk.module.upgrade.path",
 292     "jdk.module.patch.0"
 293   };
 294   static const char* unsupported_module_options[] = {
 295     "--limit-modules",
 296     "--upgrade-module-path",
 297     "--patch-module"
 298   };
 299 

 441 
 442 void CDSConfig::check_aotmode_create() {
 443   if (FLAG_IS_DEFAULT(AOTCache)) {
 444     vm_exit_during_initialization("AOTCache must be specified when using -XX:AOTMode=create");
 445   }
 446 
 447   assert(FLAG_IS_DEFAULT(SharedArchiveFile), "already checked");
 448 
 449   _is_dumping_final_static_archive = true;
 450   FLAG_SET_ERGO(SharedArchiveFile, AOTConfiguration);
 451   UseSharedSpaces = true;
 452   RequireSharedSpaces = true;
 453 
 454   if (!FileMapInfo::is_preimage_static_archive(AOTConfiguration)) {
 455     vm_exit_during_initialization("Must be a valid AOT configuration generated by the current JVM", AOTConfiguration);
 456   }
 457 
 458   CDSConfig::enable_dumping_static_archive();
 459 }
 460 
 461 bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) {
 462   check_aot_flags();
 463 
 464   if (!FLAG_IS_DEFAULT(AOTMode)) {
 465     // Using any form of the new AOTMode switch enables enhanced optimizations.
 466     FLAG_SET_ERGO_IF_DEFAULT(AOTClassLinking, true);
 467   }
 468 












 469   if (AOTClassLinking) {
 470     // If AOTClassLinking is specified, enable all AOT optimizations by default.
 471     FLAG_SET_ERGO_IF_DEFAULT(AOTInvokeDynamicLinking, true);





 472   } else {
 473     // AOTInvokeDynamicLinking depends on AOTClassLinking.
 474     FLAG_SET_ERGO(AOTInvokeDynamicLinking, false);












 475   }
 476 










 477   if (is_dumping_static_archive()) {
 478     if (is_dumping_preimage_static_archive()) {
 479       // Don't tweak execution mode
 480     } else if (!mode_flag_cmd_line) {
 481       // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
 482       //
 483       // If your classlist is large and you don't care about deterministic dumping, you can use
 484       // -Xshare:dump -Xmixed to improve dumping speed.
 485       Arguments::set_mode_flags(Arguments::_int);
 486     } else if (Arguments::mode() == Arguments::_comp) {
 487       // -Xcomp may use excessive CPU for the test tiers. Also, -Xshare:dump runs a small and fixed set of
 488       // Java code, so there's not much benefit in running -Xcomp.
 489       log_info(cds)("reduced -Xcomp to -Xmixed for static dumping");
 490       Arguments::set_mode_flags(Arguments::_mixed);
 491     }
 492 
 493     // String deduplication may cause CDS to iterate the strings in different order from one
 494     // run to another which resulting in non-determinstic CDS archives.
 495     // Disable UseStringDeduplication while dumping CDS archive.
 496     UseStringDeduplication = false;
 497 
 498     // Don't use SoftReferences so that objects used by java.lang.invoke tables can be archived.
 499     Arguments::PropertyList_add(new SystemProperty("java.lang.invoke.MethodHandleNatives.USE_SOFT_CACHE", "false", false));
 500   }
 501 
 502   // RecordDynamicDumpInfo is not compatible with ArchiveClassesAtExit
 503   if (ArchiveClassesAtExit != nullptr && RecordDynamicDumpInfo) {
 504     jio_fprintf(defaultStream::output_stream(),
 505                 "-XX:+RecordDynamicDumpInfo cannot be used with -XX:ArchiveClassesAtExit.\n");
 506     return false;
 507   }
 508 
 509   if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
 510     disable_dumping_dynamic_archive();
 511   } else {
 512     enable_dumping_dynamic_archive();
 513   }
 514 
 515   if (AutoCreateSharedArchive) {
 516     if (SharedArchiveFile == nullptr) {
 517       log_warning(cds)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
 518       return false;
 519     }

 521       log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
 522       return false;
 523     }
 524   }
 525 
 526   if (is_using_archive() && patch_mod_javabase) {
 527     Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
 528   }
 529   if (is_using_archive() && has_unsupported_runtime_module_options()) {
 530     UseSharedSpaces = false;
 531   }
 532 
 533   if (is_dumping_archive()) {
 534     // Always verify non-system classes during CDS dump
 535     if (!BytecodeVerificationRemote) {
 536       BytecodeVerificationRemote = true;
 537       log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
 538     }
 539   }
 540 











































































































































 541   return true;
 542 }
 543 
 544 bool CDSConfig::is_dumping_classic_static_archive() {
 545   return _is_dumping_static_archive &&
 546     !is_dumping_preimage_static_archive() &&
 547     !is_dumping_final_static_archive();
 548 }
 549 
 550 bool CDSConfig::is_dumping_preimage_static_archive() {
 551   return _is_dumping_preimage_static_archive;
 552 }
 553 




 554 bool CDSConfig::is_dumping_final_static_archive() {
 555   return _is_dumping_final_static_archive;
 556 }
 557 
 558 bool CDSConfig::allow_only_single_java_thread() {
 559   // See comments in JVM_StartThread()
 560   return is_dumping_static_archive();
































 561 }
 562 
 563 bool CDSConfig::is_using_archive() {
 564   return UseSharedSpaces;
 565 }
 566 
 567 bool CDSConfig::is_logging_lambda_form_invokers() {
 568   return ClassListWriter::is_enabled() || is_dumping_dynamic_archive();
 569 }
 570 
 571 void CDSConfig::stop_using_optimized_module_handling() {
 572   _is_using_optimized_module_handling = false;
 573   _is_dumping_full_module_graph = false; // This requires is_using_optimized_module_handling()
 574   _is_using_full_module_graph = false; // This requires is_using_optimized_module_handling()
 575 }
 576 
 577 
 578 CDSConfig::DumperThreadMark::DumperThreadMark(JavaThread* current) {
 579   assert(_dumper_thread == nullptr, "sanity");
 580   _dumper_thread = current;
 581 }
 582 
 583 CDSConfig::DumperThreadMark::~DumperThreadMark() {
 584   assert(_dumper_thread != nullptr, "sanity");
 585   _dumper_thread = nullptr;
 586 }
 587 
 588 bool CDSConfig::current_thread_is_vm_or_dumper() {

 697     _is_using_full_module_graph = false;
 698     if (reason != nullptr) {
 699       log_info(cds)("full module graph cannot be loaded: %s", reason);
 700     }
 701   }
 702 }
 703 
 704 bool CDSConfig::is_dumping_aot_linked_classes() {
 705   if (is_dumping_preimage_static_archive()) {
 706     return false;
 707   } else if (is_dumping_dynamic_archive()) {
 708     return is_using_full_module_graph() && AOTClassLinking;
 709   } else if (is_dumping_static_archive()) {
 710     return is_dumping_full_module_graph() && AOTClassLinking;
 711   } else {
 712     return false;
 713   }
 714 }
 715 
 716 bool CDSConfig::is_using_aot_linked_classes() {





 717   // Make sure we have the exact same module graph as in the assembly phase, or else
 718   // some aot-linked classes may not be visible so cannot be loaded.
 719   return is_using_full_module_graph() && _has_aot_linked_classes;
 720 }
 721 




 722 void CDSConfig::set_has_aot_linked_classes(bool has_aot_linked_classes) {
 723   _has_aot_linked_classes |= has_aot_linked_classes;
 724 }
 725 
 726 bool CDSConfig::is_initing_classes_at_dump_time() {
 727   return is_dumping_heap() && is_dumping_aot_linked_classes();
 728 }
 729 
 730 bool CDSConfig::is_dumping_invokedynamic() {
 731   // Requires is_dumping_aot_linked_classes(). Otherwise the classes of some archived heap
 732   // objects used by the archive indy callsites may be replaced at runtime.
 733   return AOTInvokeDynamicLinking && is_dumping_aot_linked_classes() && is_dumping_heap();
 734 }
 735 































 736 bool CDSConfig::is_loading_invokedynamic() {
 737   return UseSharedSpaces && is_using_full_module_graph() && _has_archived_invokedynamic;
 738 }
 739 
 740 #endif // INCLUDE_CDS_JAVA_HEAP

























   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/archiveHeapLoader.hpp"
  26 #include "cds/cdsConfig.hpp"
  27 #include "cds/cds_globals.hpp"
  28 #include "cds/classListWriter.hpp"
  29 #include "cds/filemap.hpp"
  30 #include "cds/heapShared.hpp"
  31 #include "cds/metaspaceShared.hpp"
  32 #include "classfile/classLoaderDataShared.hpp"
  33 #include "classfile/moduleEntry.hpp"
  34 #include "classfile/systemDictionaryShared.hpp"
  35 #include "code/SCCache.hpp"
  36 #include "include/jvm_io.h"
  37 #include "logging/log.hpp"
  38 #include "prims/jvmtiExport.hpp"
  39 #include "memory/universe.hpp"
  40 #include "runtime/arguments.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::_has_archived_invokedynamic = false;
  56 bool CDSConfig::_is_loading_packages = false;
  57 bool CDSConfig::_is_loading_protection_domains = false;
  58 bool CDSConfig::_is_security_manager_allowed = false;
  59 bool CDSConfig::_old_cds_flags_used = false;
  60 bool CDSConfig::_new_aot_flags_used = false;
  61 bool CDSConfig::_disable_heap_dumping = false;
  62 
  63 char* CDSConfig::_default_archive_path = nullptr;
  64 char* CDSConfig::_static_archive_path = nullptr;
  65 char* CDSConfig::_dynamic_archive_path = nullptr;
  66 
  67 JavaThread* CDSConfig::_dumper_thread = nullptr;
  68 
  69 int CDSConfig::get_status() {
  70   assert(Universe::is_fully_initialized(), "status is finalized only after Universe is initialized");
  71   return (is_dumping_archive()              ? IS_DUMPING_ARCHIVE : 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          (is_dumping_heap()                 ? IS_DUMPING_HEAP : 0) |
  76          (is_logging_dynamic_proxies()      ? IS_LOGGING_DYNAMIC_PROXIES : 0) |
  77          (is_dumping_packages()             ? IS_DUMPING_PACKAGES : 0) |
  78          (is_dumping_protection_domains()   ? IS_DUMPING_PROTECTION_DOMAINS : 0);
  79 }
  80 
  81 void CDSConfig::initialize() {
  82   if (is_dumping_static_archive() && !is_dumping_final_static_archive()) {
  83     // If dumping the classic archive, or making an AOT training run (dumping a preimage archive),
  84     // for sanity, parse all classes from classfiles.
  85     // TODO: in the future, if we want to support re-training on top of an existing AOT cache, this
  86     // needs to be changed.
  87     if (RequireSharedSpaces) {
  88       if (is_experimental_leyden_workflow()) {
  89         log_info(cds)("-Xshare:on flag is ignored when creating a CacheDataStore");
  90       } else {
  91         // -Xshare and -XX:AOTMode flags are mutually exclusive:
  92         //   Class workflow: -Xshare:on and -Xshare:dump cannot take effect at the same time.
  93         //   JEP 483 workflow: -XX:AOTMode:record and -XX:AOTMode=on cannot take effect at the same time.
  94         ShouldNotReachHere();
  95       }
  96     }
  97     UseSharedSpaces = false;
  98   }
  99 
 100   // Initialize shared archive paths which could include both base and dynamic archive paths
 101   // This must be after set_ergonomics_flags() called so flag UseCompressedOops is set properly.
 102   //
 103   // UseSharedSpaces may be disabled if -XX:SharedArchiveFile is invalid.
 104   if (is_dumping_static_archive() || is_using_archive()) {
 105     init_shared_archive_paths();
 106   }
 107 
 108   if (!is_dumping_heap()) {
 109     _is_dumping_full_module_graph = false;
 110   }
 111 }
 112 
 113 char* CDSConfig::default_archive_path() {
 114   if (_default_archive_path == nullptr) {
 115     char jvm_path[JVM_MAXPATHLEN];

 183     }
 184     check_unsupported_dumping_module_options();
 185 
 186     if (os::same_files(default_archive_path(), ArchiveClassesAtExit)) {
 187       vm_exit_during_initialization(
 188         "Cannot specify the default CDS archive for -XX:ArchiveClassesAtExit", default_archive_path());
 189     }
 190   }
 191 
 192   if (SharedArchiveFile == nullptr) {
 193     _static_archive_path = default_archive_path();
 194   } else {
 195     int archives = num_archives(SharedArchiveFile);
 196     assert(archives > 0, "must be");
 197 
 198     if (is_dumping_archive() && archives > 1) {
 199       vm_exit_during_initialization(
 200         "Cannot have more than 1 archive file specified in -XX:SharedArchiveFile during CDS dumping");
 201     }
 202 
 203     if (CDSPreimage != nullptr && archives > 1) {
 204       vm_exit_during_initialization("CDSPreimage must point to a single file", CDSPreimage);
 205     }
 206 
 207     if (is_dumping_static_archive()) {
 208       assert(archives == 1, "must be");
 209       // Static dump is simple: only one archive is allowed in SharedArchiveFile. This file
 210       // will be overwritten no matter regardless of its contents
 211       _static_archive_path = os::strdup_check_oom(SharedArchiveFile, mtArguments);
 212     } else {
 213       // SharedArchiveFile may specify one or two files. In case (c), the path for base.jsa
 214       // is read from top.jsa
 215       //    (a) 1 file:  -XX:SharedArchiveFile=base.jsa
 216       //    (b) 2 files: -XX:SharedArchiveFile=base.jsa:top.jsa
 217       //    (c) 2 files: -XX:SharedArchiveFile=top.jsa
 218       //
 219       // However, if either RecordDynamicDumpInfo or ArchiveClassesAtExit is used, we do not
 220       // allow cases (b) and (c). Case (b) is already checked above.
 221 
 222       if (archives > 2) {
 223         vm_exit_during_initialization(
 224           "Cannot have more than 2 archive files specified in the -XX:SharedArchiveFile option");
 225       }
 226       if (archives == 1) {
 227         char* base_archive_path = nullptr;
 228         bool success =
 229           FileMapInfo::get_base_archive_name_from_header(SharedArchiveFile, &base_archive_path);
 230         if (!success) {
 231           if (CDSPreimage != nullptr) {
 232             vm_exit_during_initialization("Unable to map shared spaces from CDSPreimage", CDSPreimage);
 233           }
 234 
 235           // If +AutoCreateSharedArchive and the specified shared archive does not exist,
 236           // regenerate the dynamic archive base on default archive.
 237           if (AutoCreateSharedArchive && !os::file_exists(SharedArchiveFile)) {
 238             enable_dumping_dynamic_archive();
 239             ArchiveClassesAtExit = const_cast<char *>(SharedArchiveFile);
 240             _static_archive_path = default_archive_path();
 241             SharedArchiveFile = nullptr;
 242           } else {
 243             if (AutoCreateSharedArchive) {
 244               warning("-XX:+AutoCreateSharedArchive is unsupported when base CDS archive is not loaded. Run with -Xlog:cds for more info.");
 245               AutoCreateSharedArchive = false;
 246             }
 247             log_error(cds)("Not a valid %s (%s)", new_aot_flags_used() ? "AOT cache" : "archive", SharedArchiveFile);
 248             Arguments::no_shared_spaces("invalid archive");
 249           }
 250         } else if (base_archive_path == nullptr) {
 251           // User has specified a single archive, which is a static archive.
 252           _static_archive_path = const_cast<char *>(SharedArchiveFile);
 253         } else {
 254           // User has specified a single archive, which is a dynamic archive.

 268         // Check for case (c)
 269         if (RecordDynamicDumpInfo) {
 270           vm_exit_during_initialization("-XX:+RecordDynamicDumpInfo is unsupported when a dynamic CDS archive is specified in -XX:SharedArchiveFile",
 271                                         SharedArchiveFile);
 272         }
 273         if (ArchiveClassesAtExit != nullptr) {
 274           vm_exit_during_initialization("-XX:ArchiveClassesAtExit is unsupported when a dynamic CDS archive is specified in -XX:SharedArchiveFile",
 275                                         SharedArchiveFile);
 276         }
 277       }
 278 
 279       if (ArchiveClassesAtExit != nullptr && os::same_files(SharedArchiveFile, ArchiveClassesAtExit)) {
 280           vm_exit_during_initialization(
 281             "Cannot have the same archive file specified for -XX:SharedArchiveFile and -XX:ArchiveClassesAtExit",
 282             SharedArchiveFile);
 283       }
 284     }
 285   }
 286 }
 287 
 288 static char* bad_module_prop_key   = nullptr;
 289 static char* bad_module_prop_value = nullptr;
 290 
 291 void CDSConfig::check_internal_module_property(const char* key, const char* value) {
 292   if (Arguments::is_incompatible_cds_internal_module_property(key)) {
 293     stop_using_optimized_module_handling();
 294     if (bad_module_prop_key == nullptr) {
 295       // We don't want to print an unconditional warning here, as we are still processing the command line.
 296       // A later argument may specify something like -Xshare:off, which makes such a warning irrelevant.
 297       //
 298       // Instead, we save the info so we can warn when necessary: we are doing it only during CacheDataStore
 299       // creation for now, but could add it to other places.
 300       bad_module_prop_key   = os::strdup(key);
 301       bad_module_prop_value = os::strdup(value);
 302     }
 303     log_info(cds)("optimized module handling/full module graph: 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       log_info(cds)("full module graph: disabled due to incompatible property: %s=%s", key, value);
 319       break;
 320     }
 321   }
 322 
 323   // Match the logic in java/lang/System.java, but we need to know this before the System class is initialized.
 324   if (strcmp(key, "java.security.manager") == 0) {
 325     if (strcmp(value, "disallowed") != 0) {
 326       _is_security_manager_allowed = true;
 327     }
 328   }
 329 }
 330 
 331 // Returns any JVM command-line option, such as "--patch-module", that's not supported by CDS.
 332 static const char* find_any_unsupported_module_option() {
 333   // Note that arguments.cpp has translated the command-line options into properties. If we find an
 334   // unsupported property, translate it back to its command-line option for better error reporting.
 335 
 336   // The following properties are checked by Arguments::is_internal_module_property() and cannot be
 337   // directly specified in the command-line.
 338   static const char* unsupported_module_properties[] = {
 339     "jdk.module.limitmods",
 340     "jdk.module.upgrade.path",
 341     "jdk.module.patch.0"
 342   };
 343   static const char* unsupported_module_options[] = {
 344     "--limit-modules",
 345     "--upgrade-module-path",
 346     "--patch-module"
 347   };
 348 

 490 
 491 void CDSConfig::check_aotmode_create() {
 492   if (FLAG_IS_DEFAULT(AOTCache)) {
 493     vm_exit_during_initialization("AOTCache must be specified when using -XX:AOTMode=create");
 494   }
 495 
 496   assert(FLAG_IS_DEFAULT(SharedArchiveFile), "already checked");
 497 
 498   _is_dumping_final_static_archive = true;
 499   FLAG_SET_ERGO(SharedArchiveFile, AOTConfiguration);
 500   UseSharedSpaces = true;
 501   RequireSharedSpaces = true;
 502 
 503   if (!FileMapInfo::is_preimage_static_archive(AOTConfiguration)) {
 504     vm_exit_during_initialization("Must be a valid AOT configuration generated by the current JVM", AOTConfiguration);
 505   }
 506 
 507   CDSConfig::enable_dumping_static_archive();
 508 }
 509 
 510 bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line, bool xshare_auto_cmd_line) {
 511   check_aot_flags();
 512 
 513   if (!FLAG_IS_DEFAULT(AOTMode)) {
 514     // Using any form of the new AOTMode switch enables enhanced optimizations.
 515     FLAG_SET_ERGO_IF_DEFAULT(AOTClassLinking, true);
 516   }
 517 
 518   if (CacheDataStore != nullptr) {
 519     if (!setup_experimental_leyden_workflow(xshare_auto_cmd_line)) {
 520       return false;
 521     }
 522   } else {
 523     if (CDSPreimage != nullptr) {
 524       vm_exit_during_initialization("CDSPreimage must be specified only when CacheDataStore is specified");
 525     }
 526 
 527     setup_compiler_args();
 528   }
 529 
 530   if (AOTClassLinking) {
 531     // If AOTClassLinking is specified, enable all these optimizations by default.
 532     FLAG_SET_ERGO_IF_DEFAULT(AOTInvokeDynamicLinking, true);
 533     FLAG_SET_ERGO_IF_DEFAULT(ArchiveDynamicProxies, true);
 534     FLAG_SET_ERGO_IF_DEFAULT(ArchiveLoaderLookupCache, true);
 535     FLAG_SET_ERGO_IF_DEFAULT(ArchivePackages, true);
 536     FLAG_SET_ERGO_IF_DEFAULT(ArchiveProtectionDomains, true);
 537     FLAG_SET_ERGO_IF_DEFAULT(ArchiveReflectionData, true);
 538   } else {
 539     // All of these *might* depend on AOTClassLinking. Better be safe than sorry.
 540     FLAG_SET_ERGO(AOTInvokeDynamicLinking, false);
 541     FLAG_SET_ERGO(ArchiveDynamicProxies, false);
 542     FLAG_SET_ERGO(ArchiveLoaderLookupCache, false);
 543     FLAG_SET_ERGO(ArchivePackages, false);
 544     FLAG_SET_ERGO(ArchiveProtectionDomains, false);
 545     FLAG_SET_ERGO(ArchiveReflectionData, false);
 546 
 547     if (CDSConfig::is_dumping_archive()) {
 548       FLAG_SET_ERGO(RecordTraining, false);
 549       FLAG_SET_ERGO(ReplayTraining, false);
 550       FLAG_SET_ERGO(StoreCachedCode, false);
 551       FLAG_SET_ERGO(LoadCachedCode, false);
 552     }
 553   }
 554 
 555   if (StoreCachedCode) {
 556     log_info(cds)("ArchiveAdapters is enabled");
 557     FLAG_SET_ERGO_IF_DEFAULT(ArchiveAdapters, true);
 558   }
 559 
 560 #ifdef _WINDOWS
 561   // This optimization is not working on Windows for some reason. See JDK-8338604.
 562   FLAG_SET_ERGO(ArchiveReflectionData, false);
 563 #endif
 564 
 565   if (is_dumping_static_archive()) {
 566     if (is_dumping_preimage_static_archive() || is_dumping_final_static_archive()) {
 567       // Don't tweak execution mode
 568     } else if (!mode_flag_cmd_line) {
 569       // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
 570       //
 571       // If your classlist is large and you don't care about deterministic dumping, you can use
 572       // -Xshare:dump -Xmixed to improve dumping speed.
 573       Arguments::set_mode_flags(Arguments::_int);
 574     } else if (Arguments::mode() == Arguments::_comp) {
 575       // -Xcomp may use excessive CPU for the test tiers. Also, -Xshare:dump runs a small and fixed set of
 576       // Java code, so there's not much benefit in running -Xcomp.
 577       log_info(cds)("reduced -Xcomp to -Xmixed for static dumping");
 578       Arguments::set_mode_flags(Arguments::_mixed);
 579     }
 580 
 581     // String deduplication may cause CDS to iterate the strings in different order from one
 582     // run to another which resulting in non-determinstic CDS archives.
 583     // Disable UseStringDeduplication while dumping CDS archive.
 584     UseStringDeduplication = false;



 585   }
 586 
 587   // RecordDynamicDumpInfo is not compatible with ArchiveClassesAtExit
 588   if (ArchiveClassesAtExit != nullptr && RecordDynamicDumpInfo) {
 589     jio_fprintf(defaultStream::output_stream(),
 590                 "-XX:+RecordDynamicDumpInfo cannot be used with -XX:ArchiveClassesAtExit.\n");
 591     return false;
 592   }
 593 
 594   if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
 595     disable_dumping_dynamic_archive();
 596   } else {
 597     enable_dumping_dynamic_archive();
 598   }
 599 
 600   if (AutoCreateSharedArchive) {
 601     if (SharedArchiveFile == nullptr) {
 602       log_warning(cds)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
 603       return false;
 604     }

 606       log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
 607       return false;
 608     }
 609   }
 610 
 611   if (is_using_archive() && patch_mod_javabase) {
 612     Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
 613   }
 614   if (is_using_archive() && has_unsupported_runtime_module_options()) {
 615     UseSharedSpaces = false;
 616   }
 617 
 618   if (is_dumping_archive()) {
 619     // Always verify non-system classes during CDS dump
 620     if (!BytecodeVerificationRemote) {
 621       BytecodeVerificationRemote = true;
 622       log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
 623     }
 624   }
 625 
 626   if (AOTClassLinking) {
 627     if (is_dumping_final_static_archive() && !is_dumping_full_module_graph()) {
 628       if (bad_module_prop_key != nullptr) {
 629         log_warning(cds)("optimized module handling/full module graph: disabled due to incompatible property: %s=%s",
 630                          bad_module_prop_key, bad_module_prop_value);
 631       }
 632       if (is_experimental_leyden_workflow()) {
 633         vm_exit_during_initialization("CacheDataStore cannot be created because AOTClassLinking is enabled but full module graph is disabled");
 634       } else {
 635         vm_exit_during_initialization("AOT cache cannot be created because AOTClassLinking is enabled but full module graph is disabled");
 636       }
 637     }
 638   }
 639 
 640   return true;
 641 }
 642 
 643 void CDSConfig::setup_compiler_args() {
 644   // AOT profiles and AOT-compiled methods are supported only in the JEP 483 workflow.
 645   bool can_dump_profile_and_compiled_code = AOTClassLinking && new_aot_flags_used();
 646 
 647   if (is_dumping_preimage_static_archive() && can_dump_profile_and_compiled_code) {
 648     // JEP 483 workflow -- training
 649     FLAG_SET_ERGO_IF_DEFAULT(RecordTraining, true);
 650     FLAG_SET_ERGO(ReplayTraining, false);
 651     FLAG_SET_ERGO(StoreCachedCode, false);
 652     FLAG_SET_ERGO(LoadCachedCode, false);
 653   } else if (is_dumping_final_static_archive() && can_dump_profile_and_compiled_code) {
 654     // JEP 483 workflow -- assembly
 655     FLAG_SET_ERGO(RecordTraining, false); // This will be updated inside MetaspaceShared::preload_and_dump()
 656     FLAG_SET_ERGO_IF_DEFAULT(ReplayTraining, true);
 657     FLAG_SET_ERGO_IF_DEFAULT(StoreCachedCode, true);
 658     FLAG_SET_ERGO(LoadCachedCode, false);
 659     disable_dumping_cached_code(); // Cannot dump cached code until metadata and heap are dumped.
 660   } else if (is_using_archive() && new_aot_flags_used()) {
 661     // JEP 483 workflow -- production
 662     FLAG_SET_ERGO(RecordTraining, false);
 663     FLAG_SET_ERGO_IF_DEFAULT(ReplayTraining, true);
 664     FLAG_SET_ERGO(StoreCachedCode, false);
 665     FLAG_SET_ERGO_IF_DEFAULT(LoadCachedCode, true);
 666 
 667     if (UseSharedSpaces && FLAG_IS_DEFAULT(AOTMode)) {
 668       log_info(cds)("Enabled -XX:AOTMode=on by default for troubleshooting Leyden prototype");
 669       RequireSharedSpaces = true;
 670     }
 671   } else {
 672     FLAG_SET_ERGO(ReplayTraining, false);
 673     FLAG_SET_ERGO(RecordTraining, false);
 674     FLAG_SET_ERGO(StoreCachedCode, false);
 675     FLAG_SET_ERGO(LoadCachedCode, false);
 676   }
 677 }
 678 
 679 // Ergo set-up of various flags used by the experimental workflow that uses -XX:CacheDataStore. This workflow
 680 // is deprecated and will be removed from Leyden.
 681 bool CDSConfig::setup_experimental_leyden_workflow(bool xshare_auto_cmd_line) {
 682   // Leyden temp work-around:
 683   //
 684   // By default, when using CacheDataStore, use the HeapBasedNarrowOop mode so that
 685   // AOT code can be always work regardless of runtime heap range.
 686   //
 687   // If you are *absolutely sure* that the CompressedOops::mode() will be the same
 688   // between training and production runs (e.g., if you specify -Xmx128m
 689   // for both training and production runs, and you know the OS will always reserve
 690   // the heap under 4GB), you can explicitly disable this with:
 691   //     java -XX:-UseCompatibleCompressedOops -XX:CacheDataStore=...
 692   // However, this is risky and there's a chance that the production run will be slower
 693   // because it is unable to load the AOT code cache.
 694 #ifdef _LP64
 695   // FLAG_SET_ERGO_IF_DEFAULT(UseCompatibleCompressedOops, true); // FIXME @iklam - merge with mainline - UseCompatibleCompressedOops
 696 #endif
 697 
 698   if (FLAG_IS_DEFAULT(AOTClassLinking)) {
 699     FLAG_SET_ERGO(AOTClassLinking, true);
 700   }
 701 
 702   if (SharedArchiveFile != nullptr) {
 703     vm_exit_during_initialization("CacheDataStore and SharedArchiveFile cannot be both specified");
 704   }
 705   if (!AOTClassLinking) {
 706     vm_exit_during_initialization("CacheDataStore requires AOTClassLinking");
 707   }
 708 
 709   if (CDSPreimage == nullptr) {
 710     if (os::file_exists(CacheDataStore) /* && TODO: Need to check if CDS file is valid*/) {
 711       // The CacheDataStore is already up to date. Use it. Also turn on cached code by default.
 712       SharedArchiveFile = CacheDataStore;
 713       FLAG_SET_ERGO_IF_DEFAULT(ReplayTraining, true);
 714       FLAG_SET_ERGO_IF_DEFAULT(LoadCachedCode, true);
 715 
 716       // Leyden temp: make sure the user knows if CDS archive somehow fails to load.
 717       if (UseSharedSpaces && !xshare_auto_cmd_line) {
 718         log_info(cds)("Enabled -Xshare:on by default for troubleshooting Leyden prototype");
 719         RequireSharedSpaces = true;
 720       }
 721     } else {
 722       // The preimage dumping phase -- run the app and write the preimage file
 723       size_t len = strlen(CacheDataStore) + 10;
 724       char* preimage = AllocateHeap(len, mtArguments);
 725       jio_snprintf(preimage, len, "%s.preimage", CacheDataStore);
 726 
 727       UseSharedSpaces = false;
 728       enable_dumping_static_archive();
 729       SharedArchiveFile = preimage;
 730       log_info(cds)("CacheDataStore needs to be updated. Writing %s file", SharedArchiveFile);
 731 
 732       // At VM exit, the module graph may be contaminated with program states. We should rebuild the
 733       // module graph when dumping the CDS final image.
 734       log_info(cds)("full module graph: disabled when writing CDS preimage");
 735       disable_heap_dumping();
 736       stop_dumping_full_module_graph();
 737       FLAG_SET_ERGO(ArchivePackages, false);
 738       FLAG_SET_ERGO(ArchiveProtectionDomains, false);
 739       FLAG_SET_ERGO_IF_DEFAULT(RecordTraining, true);
 740       _is_dumping_static_archive = true;
 741       _is_dumping_preimage_static_archive = true;
 742     }
 743   } else {
 744     // The final image dumping phase -- load the preimage and write the final image file
 745     SharedArchiveFile = CDSPreimage;
 746     UseSharedSpaces = true;
 747     log_info(cds)("Generate CacheDataStore %s from CDSPreimage %s", CacheDataStore, CDSPreimage);
 748     // Force -Xbatch for AOT compilation.
 749     if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
 750       return false;
 751     }
 752     RecordTraining = false; // This will be updated inside MetaspaceShared::preload_and_dump()
 753 
 754     FLAG_SET_ERGO_IF_DEFAULT(ReplayTraining, true);
 755     // Settings for AOT
 756     FLAG_SET_ERGO_IF_DEFAULT(StoreCachedCode, true);
 757     if (StoreCachedCode) {
 758       // Cannot dump cached code until metadata and heap are dumped.
 759       disable_dumping_cached_code();
 760     }
 761     _is_dumping_static_archive = true;
 762     _is_dumping_final_static_archive = true;
 763   }
 764 
 765   return true;
 766 }
 767 
 768 bool CDSConfig::is_dumping_classic_static_archive() {
 769   return _is_dumping_static_archive &&
 770     !is_dumping_preimage_static_archive() &&
 771     !is_dumping_final_static_archive();
 772 }
 773 
 774 bool CDSConfig::is_dumping_preimage_static_archive() {
 775   return _is_dumping_preimage_static_archive;
 776 }
 777 
 778 bool CDSConfig::is_dumping_preimage_static_archive_with_triggers() {
 779   return (!FLAG_IS_DEFAULT(AOTEndTrainingOnMethodEntry)) && is_dumping_preimage_static_archive();
 780 }
 781 
 782 bool CDSConfig::is_dumping_final_static_archive() {
 783   return _is_dumping_final_static_archive;
 784 }
 785 
 786 bool CDSConfig::allow_only_single_java_thread() {
 787   // See comments in JVM_StartThread()
 788   return is_dumping_classic_static_archive() || is_dumping_final_static_archive();
 789 }
 790 
 791 bool CDSConfig::is_dumping_regenerated_lambdaform_invokers() {
 792   if (is_dumping_final_static_archive()) {
 793     // No need to regenerate -- the lambda form invokers should have been regenerated
 794     // in the preimage archive (if allowed)
 795     return false;
 796   } else if (is_dumping_dynamic_archive() && is_using_aot_linked_classes()) {
 797     // The base archive has aot-linked classes that may have AOT-resolved CP references
 798     // that point to the lambda form invokers in the base archive. Such pointers will
 799     // be invalid if lambda form invokers are regenerated in the dynamic archive.
 800     return false;
 801   } else if (CDSConfig::is_dumping_invokedynamic()) {
 802     // Work around JDK-8310831, as some methods in lambda form holder classes may not get generated.
 803     return false;
 804   } else {
 805     return is_dumping_archive();
 806   }
 807 }
 808 
 809 bool CDSConfig::is_logging_dynamic_proxies() {
 810   return ClassListWriter::is_enabled() || is_dumping_preimage_static_archive();
 811 }
 812 
 813 // Preserve all states that were examined used during dumptime verification, such
 814 // that the verification result (pass or fail) cannot be changed at runtime.
 815 //
 816 // For example, if the verification of ik requires that class A must be a subtype of B,
 817 // then this relationship between A and B cannot be changed at runtime. I.e., the app
 818 // cannot load alternative versions of A and B such that A is not a subtype of B.
 819 bool CDSConfig::preserve_all_dumptime_verification_states(const InstanceKlass* ik) {
 820   return is_dumping_aot_linked_classes() && SystemDictionaryShared::is_builtin(ik);
 821 }
 822 
 823 bool CDSConfig::is_using_archive() {
 824   return UseSharedSpaces;
 825 }
 826 
 827 bool CDSConfig::is_logging_lambda_form_invokers() {
 828   return ClassListWriter::is_enabled() || is_dumping_dynamic_archive() || is_dumping_preimage_static_archive();
 829 }
 830 
 831 void CDSConfig::stop_using_optimized_module_handling() {
 832   _is_using_optimized_module_handling = false;
 833   _is_dumping_full_module_graph = false; // This requires is_using_optimized_module_handling()
 834   _is_using_full_module_graph = false; // This requires is_using_optimized_module_handling()
 835 }
 836 
 837 
 838 CDSConfig::DumperThreadMark::DumperThreadMark(JavaThread* current) {
 839   assert(_dumper_thread == nullptr, "sanity");
 840   _dumper_thread = current;
 841 }
 842 
 843 CDSConfig::DumperThreadMark::~DumperThreadMark() {
 844   assert(_dumper_thread != nullptr, "sanity");
 845   _dumper_thread = nullptr;
 846 }
 847 
 848 bool CDSConfig::current_thread_is_vm_or_dumper() {

 957     _is_using_full_module_graph = false;
 958     if (reason != nullptr) {
 959       log_info(cds)("full module graph cannot be loaded: %s", reason);
 960     }
 961   }
 962 }
 963 
 964 bool CDSConfig::is_dumping_aot_linked_classes() {
 965   if (is_dumping_preimage_static_archive()) {
 966     return false;
 967   } else if (is_dumping_dynamic_archive()) {
 968     return is_using_full_module_graph() && AOTClassLinking;
 969   } else if (is_dumping_static_archive()) {
 970     return is_dumping_full_module_graph() && AOTClassLinking;
 971   } else {
 972     return false;
 973   }
 974 }
 975 
 976 bool CDSConfig::is_using_aot_linked_classes() {
 977   if (is_dumping_final_static_archive()) {
 978     // We assume that the final image is being dumped with the exact same module graph as the training run,
 979     // so all aot-linked classes can be loaded.
 980     return _has_aot_linked_classes;
 981   }
 982   // Make sure we have the exact same module graph as in the assembly phase, or else
 983   // some aot-linked classes may not be visible so cannot be loaded.
 984   return is_using_full_module_graph() && _has_aot_linked_classes;
 985 }
 986 
 987 bool CDSConfig::is_dumping_dynamic_proxies() {
 988   return is_dumping_full_module_graph() && is_dumping_invokedynamic() && ArchiveDynamicProxies;
 989 }
 990 
 991 void CDSConfig::set_has_aot_linked_classes(bool has_aot_linked_classes) {
 992   _has_aot_linked_classes |= has_aot_linked_classes;
 993 }
 994 
 995 bool CDSConfig::is_initing_classes_at_dump_time() {
 996   return is_dumping_heap() && is_dumping_aot_linked_classes();
 997 }
 998 
 999 bool CDSConfig::is_dumping_invokedynamic() {
1000   // Requires is_dumping_aot_linked_classes(). Otherwise the classes of some archived heap
1001   // objects used by the archive indy callsites may be replaced at runtime.
1002   return AOTInvokeDynamicLinking && is_dumping_aot_linked_classes() && is_dumping_heap();
1003 }
1004 
1005 bool CDSConfig::is_dumping_packages() {
1006   return ArchivePackages && is_dumping_heap();
1007 }
1008 
1009 bool CDSConfig::is_loading_packages() {
1010   return UseSharedSpaces && is_using_full_module_graph() && _is_loading_packages;
1011 }
1012 
1013 bool CDSConfig::is_dumping_protection_domains() {
1014   if (_is_security_manager_allowed) {
1015     // For sanity, don't archive PDs. TODO: can this be relaxed?
1016     return false;
1017   }
1018   // Archived PDs for the modules will reference their java.lang.Module, which must
1019   // also be archived.
1020   return ArchiveProtectionDomains && is_dumping_full_module_graph();
1021 }
1022 
1023 bool CDSConfig::is_loading_protection_domains() {
1024   if (_is_security_manager_allowed) {
1025     // For sanity, don't used any archived PDs. TODO: can this be relaxed?
1026     return false;
1027   }
1028   return UseSharedSpaces && is_using_full_module_graph() && _is_loading_protection_domains;
1029 }
1030 
1031 bool CDSConfig::is_dumping_reflection_data() {
1032   // reflection data use LambdaForm classes
1033   return ArchiveReflectionData && is_dumping_invokedynamic();
1034 }
1035 
1036 bool CDSConfig::is_loading_invokedynamic() {
1037   return UseSharedSpaces && is_using_full_module_graph() && _has_archived_invokedynamic;
1038 }
1039 
1040 #endif // INCLUDE_CDS_JAVA_HEAP
1041 
1042 // This is allowed by default. We disable it only in the final image dump before the
1043 // metadata and heap are dumped.
1044 static bool _is_dumping_cached_code = true;
1045 
1046 bool CDSConfig::is_dumping_cached_code() {
1047   return _is_dumping_cached_code;
1048 }
1049 
1050 void CDSConfig::disable_dumping_cached_code() {
1051   _is_dumping_cached_code = false;
1052 }
1053 
1054 void CDSConfig::enable_dumping_cached_code() {
1055   _is_dumping_cached_code = true;
1056 }
1057 
1058 bool CDSConfig::is_dumping_adapters() {
1059   return (ArchiveAdapters && is_dumping_final_static_archive());
1060 }
1061 
1062 bool CDSConfig::is_experimental_leyden_workflow() {
1063   return CacheDataStore != nullptr || CDSPreimage != nullptr;
1064 }
< prev index next >