< prev index next >

src/hotspot/share/cds/cdsConfig.cpp

Print this page

  1 /*
  2  * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  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 "precompiled.hpp"
 26 #include "cds/archiveHeapLoader.hpp"
 27 #include "cds/cdsConfig.hpp"

 28 #include "cds/classListWriter.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_dynamic_archive = false;
 44 bool CDSConfig::_is_using_optimized_module_handling = true;
 45 bool CDSConfig::_is_dumping_full_module_graph = true;
 46 bool CDSConfig::_is_using_full_module_graph = true;
 47 bool CDSConfig::_has_aot_linked_classes = false;
 48 bool CDSConfig::_has_archived_invokedynamic = false;



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




 63 }
 64 
 65 void CDSConfig::initialize() {
 66   if (is_dumping_static_archive()) {
 67     if (RequireSharedSpaces) {
 68       warning("Cannot dump shared archive while using shared archive");
 69     }
 70     UseSharedSpaces = false;
 71   }
 72 
 73   // Initialize shared archive paths which could include both base and dynamic archive paths
 74   // This must be after set_ergonomics_flags() called so flag UseCompressedOops is set properly.
 75   //
 76   // UseSharedSpaces may be disabled if -XX:SharedArchiveFile is invalid.
 77   if (is_dumping_static_archive() || is_using_archive()) {
 78     init_shared_archive_paths();
 79   }
 80 
 81   if (!is_dumping_heap()) {
 82     _is_dumping_full_module_graph = false;
 83   }
 84 }
 85 
 86 char* CDSConfig::default_archive_path() {
 87   if (_default_archive_path == nullptr) {
 88     char jvm_path[JVM_MAXPATHLEN];
 89     os::jvm_path(jvm_path, sizeof(jvm_path));

131     vm_exit_during_initialization("Base archive was not specified", archive_path);
132   }
133   size_t len = end_ptr - begin_ptr;
134   char* cur_path = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
135   strncpy(cur_path, begin_ptr, len);
136   cur_path[len] = '\0';
137   *base_archive_path = cur_path;
138 
139   begin_ptr = ++end_ptr;
140   if (*begin_ptr == '\0') {
141     vm_exit_during_initialization("Top archive was not specified", archive_path);
142   }
143   end_ptr = strchr(begin_ptr, '\0');
144   assert(end_ptr != nullptr, "sanity");
145   len = end_ptr - begin_ptr;
146   cur_path = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
147   strncpy(cur_path, begin_ptr, len + 1);
148   *top_archive_path = cur_path;
149 }
150 







151 void CDSConfig::init_shared_archive_paths() {
152   if (ArchiveClassesAtExit != nullptr) {
153     assert(!RecordDynamicDumpInfo, "already checked");
154     if (is_dumping_static_archive()) {
155       vm_exit_during_initialization("-XX:ArchiveClassesAtExit cannot be used with -Xshare:dump");
156     }
157     check_unsupported_dumping_module_options();
158 
159     if (os::same_files(default_archive_path(), ArchiveClassesAtExit)) {
160       vm_exit_during_initialization(
161         "Cannot specify the default CDS archive for -XX:ArchiveClassesAtExit", default_archive_path());
162     }
163   }
164 
165   if (SharedArchiveFile == nullptr) {
166     _static_archive_path = default_archive_path();
167   } else {
168     int archives = num_archives(SharedArchiveFile);
169     assert(archives > 0, "must be");
170 
171     if (is_dumping_archive() && archives > 1) {
172       vm_exit_during_initialization(
173         "Cannot have more than 1 archive file specified in -XX:SharedArchiveFile during CDS dumping");
174     }
175 




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




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

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



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









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






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

400       assert(FLAG_IS_DEFAULT(DumpLoadedClassList), "already checked");
401       FLAG_SET_ERGO(DumpLoadedClassList, AOTConfiguration);
402       UseSharedSpaces = false;
403       RequireSharedSpaces = false;
404     } else {
405       assert(strcmp(AOTMode, "create") == 0, "checked by AOTModeConstraintFunc");
406       if (FLAG_IS_DEFAULT(AOTCache)) {
407         vm_exit_during_initialization("AOTCache must be specified when using -XX:AOTMode=create");
408       }
409 
410       assert(FLAG_IS_DEFAULT(SharedClassListFile), "already checked");
411       FLAG_SET_ERGO(SharedClassListFile, AOTConfiguration);
412       assert(FLAG_IS_DEFAULT(SharedArchiveFile), "already checked");
413       FLAG_SET_ERGO(SharedArchiveFile, AOTCache);
414 
415       CDSConfig::enable_dumping_static_archive();
416     }
417   }
418 }
419 
420 bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) {
421   check_flag_aliases();
422 














































































































423   if (AOTClassLinking) {
424     // If AOTClassLinking is specified, enable all AOT optimizations by default.
425     FLAG_SET_ERGO_IF_DEFAULT(AOTInvokeDynamicLinking, true);







426   } else {
427     // AOTInvokeDynamicLinking depends on AOTClassLinking.

428     FLAG_SET_ERGO(AOTInvokeDynamicLinking, false);





429   }
430 





431   if (is_dumping_static_archive()) {
432     if (!mode_flag_cmd_line) {


433       // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
434       //
435       // If your classlist is large and you don't care about deterministic dumping, you can use
436       // -Xshare:dump -Xmixed to improve dumping speed.
437       Arguments::set_mode_flags(Arguments::_int);
438     } else if (Arguments::mode() == Arguments::_comp) {
439       // -Xcomp may use excessive CPU for the test tiers. Also, -Xshare:dump runs a small and fixed set of
440       // Java code, so there's not much benefit in running -Xcomp.
441       log_info(cds)("reduced -Xcomp to -Xmixed for static dumping");
442       Arguments::set_mode_flags(Arguments::_mixed);
443     }
444 
445     // String deduplication may cause CDS to iterate the strings in different order from one
446     // run to another which resulting in non-determinstic CDS archives.
447     // Disable UseStringDeduplication while dumping CDS archive.
448     UseStringDeduplication = false;
449 
450     // Don't use SoftReferences so that objects used by java.lang.invoke tables can be archived.
451     Arguments::PropertyList_add(new SystemProperty("java.lang.invoke.MethodHandleNatives.USE_SOFT_CACHE", "false", false));
452   }

473       log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
474       return false;
475     }
476   }
477 
478   if (is_using_archive() && patch_mod_javabase) {
479     Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
480   }
481   if (is_using_archive() && has_unsupported_runtime_module_options()) {
482     UseSharedSpaces = false;
483   }
484 
485   if (is_dumping_archive()) {
486     // Always verify non-system classes during CDS dump
487     if (!BytecodeVerificationRemote) {
488       BytecodeVerificationRemote = true;
489       log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
490     }
491   }
492 











493   return true;
494 }
495 





















496 bool CDSConfig::allow_only_single_java_thread() {
497   // See comments in JVM_StartThread()
498   return is_dumping_static_archive();

























499 }
500 
501 bool CDSConfig::is_using_archive() {
502   return UseSharedSpaces;
503 }
504 
505 bool CDSConfig::is_logging_lambda_form_invokers() {
506   return ClassListWriter::is_enabled() || is_dumping_dynamic_archive();
507 }
508 
509 void CDSConfig::stop_using_optimized_module_handling() {
510   _is_using_optimized_module_handling = false;
511   _is_dumping_full_module_graph = false; // This requires is_using_optimized_module_handling()
512   _is_using_full_module_graph = false; // This requires is_using_optimized_module_handling()
513 }
514 
515 
516 CDSConfig::DumperThreadMark::DumperThreadMark(JavaThread* current) {
517   assert(_dumper_thread == nullptr, "sanity");
518   _dumper_thread = current;
519 }
520 
521 CDSConfig::DumperThreadMark::~DumperThreadMark() {
522   assert(_dumper_thread != nullptr, "sanity");
523   _dumper_thread = nullptr;
524 }
525 
526 bool CDSConfig::current_thread_is_vm_or_dumper() {
527   Thread* t = Thread::current();
528   return t != nullptr && (t->is_VM_thread() || t == _dumper_thread);
529 }
530 
531 #if INCLUDE_CDS_JAVA_HEAP
532 bool CDSConfig::is_dumping_heap() {
533   // heap dump is not supported in dynamic dump
534   return is_dumping_static_archive() && HeapShared::can_write();
535 }
536 
537 bool CDSConfig::is_loading_heap() {
538   return ArchiveHeapLoader::is_in_use();
539 }
540 
541 bool CDSConfig::is_using_full_module_graph() {
542   if (ClassLoaderDataShared::is_full_module_graph_loaded()) {
543     return true;
544   }
545 
546   if (!_is_using_full_module_graph) {
547     return false;
548   }
549 
550   if (is_using_archive() && ArchiveHeapLoader::can_use()) {
551     // Classes used by the archived full module graph are loaded in JVMTI early phase.
552     assert(!(JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()),
553            "CDS should be disabled if early class hooks are enabled");
554     return true;

561 void CDSConfig::stop_dumping_full_module_graph(const char* reason) {
562   if (_is_dumping_full_module_graph) {
563     _is_dumping_full_module_graph = false;
564     if (reason != nullptr) {
565       log_info(cds)("full module graph cannot be dumped: %s", reason);
566     }
567   }
568 }
569 
570 void CDSConfig::stop_using_full_module_graph(const char* reason) {
571   assert(!ClassLoaderDataShared::is_full_module_graph_loaded(), "you call this function too late!");
572   if (_is_using_full_module_graph) {
573     _is_using_full_module_graph = false;
574     if (reason != nullptr) {
575       log_info(cds)("full module graph cannot be loaded: %s", reason);
576     }
577   }
578 }
579 
580 bool CDSConfig::is_dumping_aot_linked_classes() {
581   if (is_dumping_dynamic_archive()) {


582     return is_using_full_module_graph() && AOTClassLinking;
583   } else if (is_dumping_static_archive()) {
584     return is_dumping_full_module_graph() && AOTClassLinking;
585   } else {
586     return false;
587   }
588 }
589 
590 bool CDSConfig::is_using_aot_linked_classes() {





591   // Make sure we have the exact same module graph as in the assembly phase, or else
592   // some aot-linked classes may not be visible so cannot be loaded.
593   return is_using_full_module_graph() && _has_aot_linked_classes;
594 }
595 




596 void CDSConfig::set_has_aot_linked_classes(bool has_aot_linked_classes) {
597   _has_aot_linked_classes |= has_aot_linked_classes;
598 }
599 
600 bool CDSConfig::is_initing_classes_at_dump_time() {
601   return is_dumping_heap() && is_dumping_aot_linked_classes();
602 }
603 
604 bool CDSConfig::is_dumping_invokedynamic() {
605   // Requires is_dumping_aot_linked_classes(). Otherwise the classes of some archived heap
606   // objects used by the archive indy callsites may be replaced at runtime.
607   return AOTInvokeDynamicLinking && is_dumping_aot_linked_classes() && is_dumping_heap();
608 }
609 































610 bool CDSConfig::is_loading_invokedynamic() {
611   return UseSharedSpaces && is_using_full_module_graph() && _has_archived_invokedynamic;
612 }
613 
614 #endif // INCLUDE_CDS_JAVA_HEAP

















  1 /*
  2  * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  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 "precompiled.hpp"
 26 #include "cds/archiveHeapLoader.hpp"
 27 #include "cds/cdsConfig.hpp"
 28 #include "cds/cds_globals.hpp"
 29 #include "cds/classListWriter.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 "include/jvm_io.h"
 36 #include "logging/log.hpp"
 37 #include "prims/jvmtiExport.hpp"
 38 #include "memory/universe.hpp"
 39 #include "runtime/arguments.hpp"
 40 #include "runtime/globals_extension.hpp"
 41 #include "runtime/java.hpp"
 42 #include "runtime/vmThread.hpp"
 43 #include "utilities/defaultStream.hpp"
 44 #include "utilities/formatBuffer.hpp"
 45 
 46 bool CDSConfig::_is_dumping_static_archive = false;
 47 bool CDSConfig::_is_dumping_dynamic_archive = false;
 48 bool CDSConfig::_is_using_optimized_module_handling = true;
 49 bool CDSConfig::_is_dumping_full_module_graph = true;
 50 bool CDSConfig::_is_using_full_module_graph = true;
 51 bool CDSConfig::_has_aot_linked_classes = false;
 52 bool CDSConfig::_has_archived_invokedynamic = false;
 53 bool CDSConfig::_is_loading_packages = false;
 54 bool CDSConfig::_is_loading_protection_domains = false;
 55 bool CDSConfig::_is_security_manager_allowed = false;
 56 bool CDSConfig::_old_cds_flags_used = false;
 57 
 58 char* CDSConfig::_default_archive_path = nullptr;
 59 char* CDSConfig::_static_archive_path = nullptr;
 60 char* CDSConfig::_dynamic_archive_path = nullptr;
 61 
 62 JavaThread* CDSConfig::_dumper_thread = nullptr;
 63 
 64 int CDSConfig::get_status() {
 65   assert(Universe::is_fully_initialized(), "status is finalized only after Universe is initialized");
 66   return (is_dumping_archive()              ? IS_DUMPING_ARCHIVE : 0) |
 67          (is_dumping_static_archive()       ? IS_DUMPING_STATIC_ARCHIVE : 0) |
 68          (is_logging_lambda_form_invokers() ? IS_LOGGING_LAMBDA_FORM_INVOKERS : 0) |
 69          (is_using_archive()                ? IS_USING_ARCHIVE : 0) |
 70          (is_dumping_heap()                 ? IS_DUMPING_HEAP : 0) |
 71          (is_logging_dynamic_proxies()      ? IS_LOGGING_DYNAMIC_PROXIES : 0) |
 72          (is_dumping_packages()             ? IS_DUMPING_PACKAGES : 0) |
 73          (is_dumping_protection_domains()   ? IS_DUMPING_PROTECTION_DOMAINS : 0);
 74 }
 75 
 76 void CDSConfig::initialize() {
 77   if (is_dumping_static_archive() && !is_dumping_final_static_archive()) {



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

139     vm_exit_during_initialization("Base archive was not specified", archive_path);
140   }
141   size_t len = end_ptr - begin_ptr;
142   char* cur_path = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
143   strncpy(cur_path, begin_ptr, len);
144   cur_path[len] = '\0';
145   *base_archive_path = cur_path;
146 
147   begin_ptr = ++end_ptr;
148   if (*begin_ptr == '\0') {
149     vm_exit_during_initialization("Top archive was not specified", archive_path);
150   }
151   end_ptr = strchr(begin_ptr, '\0');
152   assert(end_ptr != nullptr, "sanity");
153   len = end_ptr - begin_ptr;
154   cur_path = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
155   strncpy(cur_path, begin_ptr, len + 1);
156   *top_archive_path = cur_path;
157 }
158 
159 static void set_new_workflow_default_CachedCodeFile() {
160   size_t len = strlen(CacheDataStore) + 6;
161   char* file = AllocateHeap(len, mtArguments);
162   jio_snprintf(file, len, "%s.code", CacheDataStore);
163   FLAG_SET_ERGO(CachedCodeFile, file);
164 }
165 
166 void CDSConfig::init_shared_archive_paths() {
167   if (ArchiveClassesAtExit != nullptr) {
168     assert(!RecordDynamicDumpInfo, "already checked");
169     if (is_dumping_static_archive()) {
170       vm_exit_during_initialization("-XX:ArchiveClassesAtExit cannot be used with -Xshare:dump");
171     }
172     check_unsupported_dumping_module_options();
173 
174     if (os::same_files(default_archive_path(), ArchiveClassesAtExit)) {
175       vm_exit_during_initialization(
176         "Cannot specify the default CDS archive for -XX:ArchiveClassesAtExit", default_archive_path());
177     }
178   }
179 
180   if (SharedArchiveFile == nullptr) {
181     _static_archive_path = default_archive_path();
182   } else {
183     int archives = num_archives(SharedArchiveFile);
184     assert(archives > 0, "must be");
185 
186     if (is_dumping_archive() && archives > 1) {
187       vm_exit_during_initialization(
188         "Cannot have more than 1 archive file specified in -XX:SharedArchiveFile during CDS dumping");
189     }
190 
191     if (CDSPreimage != nullptr && archives > 1) {
192       vm_exit_during_initialization("CDSPreimage must point to a single file", CDSPreimage);
193     }
194 
195     if (is_dumping_static_archive()) {
196       assert(archives == 1, "must be");
197       // Static dump is simple: only one archive is allowed in SharedArchiveFile. This file
198       // will be overwritten no matter regardless of its contents
199       _static_archive_path = os::strdup_check_oom(SharedArchiveFile, mtArguments);
200     } else {
201       // SharedArchiveFile may specify one or two files. In case (c), the path for base.jsa
202       // is read from top.jsa
203       //    (a) 1 file:  -XX:SharedArchiveFile=base.jsa
204       //    (b) 2 files: -XX:SharedArchiveFile=base.jsa:top.jsa
205       //    (c) 2 files: -XX:SharedArchiveFile=top.jsa
206       //
207       // However, if either RecordDynamicDumpInfo or ArchiveClassesAtExit is used, we do not
208       // allow cases (b) and (c). Case (b) is already checked above.
209 
210       if (archives > 2) {
211         vm_exit_during_initialization(
212           "Cannot have more than 2 archive files specified in the -XX:SharedArchiveFile option");
213       }
214       if (archives == 1) {
215         char* base_archive_path = nullptr;
216         bool success =
217           FileMapInfo::get_base_archive_name_from_header(SharedArchiveFile, &base_archive_path);
218         if (!success) {
219           if (CDSPreimage != nullptr) {
220             vm_exit_during_initialization("Unable to map shared spaces from CDSPreimage", CDSPreimage);
221           }
222 
223           // If +AutoCreateSharedArchive and the specified shared archive does not exist,
224           // regenerate the dynamic archive base on default archive.
225           if (AutoCreateSharedArchive && !os::file_exists(SharedArchiveFile)) {
226             enable_dumping_dynamic_archive();
227             ArchiveClassesAtExit = const_cast<char *>(SharedArchiveFile);
228             _static_archive_path = default_archive_path();
229             SharedArchiveFile = nullptr;
230           } else {
231             if (AutoCreateSharedArchive) {
232               warning("-XX:+AutoCreateSharedArchive is unsupported when base CDS archive is not loaded. Run with -Xlog:cds for more info.");
233               AutoCreateSharedArchive = false;
234             }
235             Arguments::no_shared_spaces("invalid archive");
236           }
237         } else if (base_archive_path == nullptr) {
238           // User has specified a single archive, which is a static archive.
239           _static_archive_path = const_cast<char *>(SharedArchiveFile);
240         } else {
241           // User has specified a single archive, which is a dynamic archive.
242           _dynamic_archive_path = const_cast<char *>(SharedArchiveFile);

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

441       assert(FLAG_IS_DEFAULT(DumpLoadedClassList), "already checked");
442       FLAG_SET_ERGO(DumpLoadedClassList, AOTConfiguration);
443       UseSharedSpaces = false;
444       RequireSharedSpaces = false;
445     } else {
446       assert(strcmp(AOTMode, "create") == 0, "checked by AOTModeConstraintFunc");
447       if (FLAG_IS_DEFAULT(AOTCache)) {
448         vm_exit_during_initialization("AOTCache must be specified when using -XX:AOTMode=create");
449       }
450 
451       assert(FLAG_IS_DEFAULT(SharedClassListFile), "already checked");
452       FLAG_SET_ERGO(SharedClassListFile, AOTConfiguration);
453       assert(FLAG_IS_DEFAULT(SharedArchiveFile), "already checked");
454       FLAG_SET_ERGO(SharedArchiveFile, AOTCache);
455 
456       CDSConfig::enable_dumping_static_archive();
457     }
458   }
459 }
460 
461 bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line, bool xshare_auto_cmd_line) {
462   check_flag_aliases();
463 
464   if (CacheDataStore != nullptr) {
465     // Leyden temp work-around:
466     //
467     // By default, when using CacheDataStore, use the HeapBasedNarrowOop mode so that
468     // AOT code can be always work regardless of runtime heap range.
469     //
470     // If you are *absolutely sure* that the CompressedOops::mode() will be the same
471     // between training and production runs (e.g., if you specify -Xmx128m
472     // for both training and production runs, and you know the OS will always reserve
473     // the heap under 4GB), you can explicitly disable this with:
474     //     java -XX:-UseCompatibleCompressedOops -XX:CacheDataStore=...
475     // However, this is risky and there's a chance that the production run will be slower
476     // because it is unable to load the AOT code cache.
477 #ifdef _LP64
478     // FLAG_SET_ERGO_IF_DEFAULT(UseCompatibleCompressedOops, true); // FIXME @iklam - merge with mainline - UseCompatibleCompressedOops
479 #endif
480 
481     // Leyden temp: make sure the user knows if CDS archive somehow fails to load.
482     if (UseSharedSpaces && !xshare_auto_cmd_line) {
483       log_info(cds)("Enabled -Xshare:on by default for troubleshooting Leyden prototype");
484       RequireSharedSpaces = true;
485     }
486 
487     if (FLAG_IS_DEFAULT(AOTClassLinking)) {
488       // New workflow - enable AOTClassLinking by default.
489       // TODO: make new workflow work, even when AOTClassLinking is false.
490       //
491       // NOTE: in old workflow, we cannot enable AOTClassLinking by default. That
492       // should be an opt-in option, per JEP nnn.
493       FLAG_SET_ERGO(AOTClassLinking, true);
494     }
495 
496     if (SharedArchiveFile != nullptr) {
497       vm_exit_during_initialization("CacheDataStore and SharedArchiveFile cannot be both specified");
498     }
499     if (!AOTClassLinking) {
500       // TODO: in the forked JVM, we should ensure all classes are loaded from the hotspot.cds.preimage.
501       // AOTClassLinking only loads the classes for built-in loaders. We need to load the classes
502       // for custom loaders as well.
503       vm_exit_during_initialization("CacheDataStore requires AOTClassLinking");
504     }
505 
506     if (CDSPreimage == nullptr) {
507       if (os::file_exists(CacheDataStore) /* && TODO: CDS file is valid*/) {
508         // The CacheDataStore is already up to date. Use it. Also turn on cached code by default.
509         SharedArchiveFile = CacheDataStore;
510         FLAG_SET_ERGO_IF_DEFAULT(ReplayTraining, true);
511         FLAG_SET_ERGO_IF_DEFAULT(LoadCachedCode, true);
512         if (LoadCachedCode && FLAG_IS_DEFAULT(CachedCodeFile)) {
513           set_new_workflow_default_CachedCodeFile();
514         }
515       } else {
516         // The preimage dumping phase -- run the app and write the preimage file
517         size_t len = strlen(CacheDataStore) + 10;
518         char* preimage = AllocateHeap(len, mtArguments);
519         jio_snprintf(preimage, len, "%s.preimage", CacheDataStore);
520 
521         UseSharedSpaces = false;
522         enable_dumping_static_archive();
523         SharedArchiveFile = preimage;
524         log_info(cds)("CacheDataStore needs to be updated. Writing %s file", SharedArchiveFile);
525 
526         // At VM exit, the module graph may be contaminated with program states. We should rebuild the
527         // module graph when dumping the CDS final image.
528         log_info(cds)("full module graph: disabled when writing CDS preimage");
529         HeapShared::disable_writing();
530         stop_dumping_full_module_graph();
531         FLAG_SET_ERGO(ArchivePackages, false);
532         FLAG_SET_ERGO(ArchiveProtectionDomains, false);
533 
534         FLAG_SET_ERGO_IF_DEFAULT(RecordTraining, true);
535       }
536     } else {
537       // The final image dumping phase -- load the preimage and write the final image file
538       SharedArchiveFile = CDSPreimage;
539       UseSharedSpaces = true;
540       log_info(cds)("Generate CacheDataStore %s from CDSPreimage %s", CacheDataStore, CDSPreimage);
541       // Force -Xbatch for AOT compilation.
542       if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
543         return false;
544       }
545       RecordTraining = false; // This will be updated inside MetaspaceShared::preload_and_dump()
546 
547       FLAG_SET_ERGO_IF_DEFAULT(ReplayTraining, true);
548       // Settings for AOT
549       FLAG_SET_ERGO_IF_DEFAULT(StoreCachedCode, true);
550       if (StoreCachedCode && FLAG_IS_DEFAULT(CachedCodeFile)) {
551         set_new_workflow_default_CachedCodeFile();
552         // Cannot dump cached code until metadata and heap are dumped.
553         disable_dumping_cached_code();
554       }
555     }
556   } else {
557     // Old workflow
558     if (CDSPreimage != nullptr) {
559       vm_exit_during_initialization("CDSPreimage must be specified only when CacheDataStore is specified");
560     }
561   }
562 
563   if (FLAG_IS_DEFAULT(UsePermanentHeapObjects)) {
564     if (StoreCachedCode || AOTClassLinking) {
565       FLAG_SET_ERGO(UsePermanentHeapObjects, true);
566     }
567   }
568 
569   if (LoadCachedCode) {
570     // This must be true. Cached code is hard-wired to use permanent objects.
571     UsePermanentHeapObjects = true;
572   }
573 
574   if (AOTClassLinking) {
575     // If AOTClassLinking is specified, enable all these optimizations by default.
576     FLAG_SET_ERGO_IF_DEFAULT(AOTInvokeDynamicLinking, true);
577     FLAG_SET_ERGO_IF_DEFAULT(ArchiveDynamicProxies, true);
578     FLAG_SET_ERGO_IF_DEFAULT(ArchiveLoaderLookupCache, true);
579     FLAG_SET_ERGO_IF_DEFAULT(ArchivePackages, true);
580     FLAG_SET_ERGO_IF_DEFAULT(ArchiveProtectionDomains, true);
581     FLAG_SET_ERGO_IF_DEFAULT(ArchiveReflectionData, true);
582 
583     FLAG_SET_ERGO(ArchiveLoaderLookupCache, false);  // FIXME -- leyden+JEP483 merge
584   } else {
585     // All of these *might* depend on AOTClassLinking. Better be safe than sorry.
586     // TODO: more fine-grained handling.
587     FLAG_SET_ERGO(AOTInvokeDynamicLinking, false);
588     FLAG_SET_ERGO(ArchiveDynamicProxies, false);
589     FLAG_SET_ERGO(ArchiveLoaderLookupCache, false);
590     FLAG_SET_ERGO(ArchivePackages, false);
591     FLAG_SET_ERGO(ArchiveProtectionDomains, false);
592     FLAG_SET_ERGO(ArchiveReflectionData, false);
593   }
594 
595 #ifdef _WINDOWS
596   // This optimization is not working on Windows for some reason. See JDK-8338604.
597   FLAG_SET_ERGO(ArchiveReflectionData, false);
598 #endif
599 
600   if (is_dumping_static_archive()) {
601     if (is_dumping_preimage_static_archive() || is_dumping_final_static_archive()) {
602       // Don't tweak execution mode
603     } else if (!mode_flag_cmd_line) {
604       // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
605       //
606       // If your classlist is large and you don't care about deterministic dumping, you can use
607       // -Xshare:dump -Xmixed to improve dumping speed.
608       Arguments::set_mode_flags(Arguments::_int);
609     } else if (Arguments::mode() == Arguments::_comp) {
610       // -Xcomp may use excessive CPU for the test tiers. Also, -Xshare:dump runs a small and fixed set of
611       // Java code, so there's not much benefit in running -Xcomp.
612       log_info(cds)("reduced -Xcomp to -Xmixed for static dumping");
613       Arguments::set_mode_flags(Arguments::_mixed);
614     }
615 
616     // String deduplication may cause CDS to iterate the strings in different order from one
617     // run to another which resulting in non-determinstic CDS archives.
618     // Disable UseStringDeduplication while dumping CDS archive.
619     UseStringDeduplication = false;
620 
621     // Don't use SoftReferences so that objects used by java.lang.invoke tables can be archived.
622     Arguments::PropertyList_add(new SystemProperty("java.lang.invoke.MethodHandleNatives.USE_SOFT_CACHE", "false", false));
623   }

644       log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
645       return false;
646     }
647   }
648 
649   if (is_using_archive() && patch_mod_javabase) {
650     Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
651   }
652   if (is_using_archive() && has_unsupported_runtime_module_options()) {
653     UseSharedSpaces = false;
654   }
655 
656   if (is_dumping_archive()) {
657     // Always verify non-system classes during CDS dump
658     if (!BytecodeVerificationRemote) {
659       BytecodeVerificationRemote = true;
660       log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
661     }
662   }
663 
664   if (AOTClassLinking) {
665     if ((is_dumping_preimage_static_archive() && !is_using_optimized_module_handling()) ||
666         (is_dumping_final_static_archive()    && !is_dumping_full_module_graph())) {
667       if (bad_module_prop_key != nullptr) {
668         log_warning(cds)("optimized module handling/full module graph: disabled due to incompatible property: %s=%s",
669                          bad_module_prop_key, bad_module_prop_value);
670       }
671       vm_exit_during_initialization("CacheDataStore cannot be created because AOTClassLinking is enabled but full module graph is disabled");
672     }
673   }
674 
675   return true;
676 }
677 
678 bool CDSConfig::is_dumping_classic_static_archive() {
679   return _is_dumping_static_archive && CacheDataStore == nullptr && CDSPreimage == nullptr;
680 }
681 
682 bool CDSConfig::is_dumping_preimage_static_archive() {
683   return _is_dumping_static_archive && CacheDataStore != nullptr && CDSPreimage == nullptr;
684 }
685 
686 bool CDSConfig::is_dumping_preimage_static_archive_with_triggers() {
687   return (!FLAG_IS_DEFAULT(AOTEndTrainingOnMethodEntry)) && is_dumping_preimage_static_archive();
688 }
689 
690 bool CDSConfig::is_dumping_final_static_archive() {
691   if (CDSPreimage != nullptr) {
692     assert(CacheDataStore != nullptr, "must be"); // should have been properly initialized by arguments.cpp
693   }
694 
695   // Note: _is_dumping_static_archive is false! // FIXME -- refactor this so it makes more sense!
696   return CacheDataStore != nullptr && CDSPreimage != nullptr;
697 }
698 
699 bool CDSConfig::allow_only_single_java_thread() {
700   // See comments in JVM_StartThread()
701   return is_dumping_classic_static_archive() || is_dumping_final_static_archive();
702 }
703 
704 bool CDSConfig::is_dumping_regenerated_lambdaform_invokers() {
705   if (is_dumping_final_static_archive()) {
706     // Not yet supported in new workflow -- the training data may point
707     // to a method in a lambdaform holder class that was not regenerated
708     // due to JDK-8318064.
709     return false;
710   } else {
711     return is_dumping_archive();
712   }
713 }
714 
715 bool CDSConfig::is_logging_dynamic_proxies() {
716   return ClassListWriter::is_enabled() || is_dumping_preimage_static_archive();
717 }
718 
719 // Preserve all states that were examined used during dumptime verification, such
720 // that the verification result (pass or fail) cannot be changed at runtime.
721 //
722 // For example, if the verification of ik requires that class A must be a subtype of B,
723 // then this relationship between A and B cannot be changed at runtime. I.e., the app
724 // cannot load alternative versions of A and B such that A is not a subtype of B.
725 bool CDSConfig::preserve_all_dumptime_verification_states(const InstanceKlass* ik) {
726   return is_dumping_aot_linked_classes() && SystemDictionaryShared::is_builtin(ik);
727 }
728 
729 bool CDSConfig::is_using_archive() {
730   return UseSharedSpaces;
731 }
732 
733 bool CDSConfig::is_logging_lambda_form_invokers() {
734   return ClassListWriter::is_enabled() || is_dumping_dynamic_archive() || is_dumping_preimage_static_archive();
735 }
736 
737 void CDSConfig::stop_using_optimized_module_handling() {
738   _is_using_optimized_module_handling = false;
739   _is_dumping_full_module_graph = false; // This requires is_using_optimized_module_handling()
740   _is_using_full_module_graph = false; // This requires is_using_optimized_module_handling()
741 }
742 
743 
744 CDSConfig::DumperThreadMark::DumperThreadMark(JavaThread* current) {
745   assert(_dumper_thread == nullptr, "sanity");
746   _dumper_thread = current;
747 }
748 
749 CDSConfig::DumperThreadMark::~DumperThreadMark() {
750   assert(_dumper_thread != nullptr, "sanity");
751   _dumper_thread = nullptr;
752 }
753 
754 bool CDSConfig::current_thread_is_vm_or_dumper() {
755   Thread* t = Thread::current();
756   return t != nullptr && (t->is_VM_thread() || t == _dumper_thread);
757 }
758 
759 #if INCLUDE_CDS_JAVA_HEAP
760 bool CDSConfig::is_dumping_heap() {
761   return is_dumping_static_archive() && !is_dumping_preimage_static_archive()
762     && HeapShared::can_write();
763 }
764 
765 bool CDSConfig::is_loading_heap() {
766   return ArchiveHeapLoader::is_in_use();
767 }
768 
769 bool CDSConfig::is_using_full_module_graph() {
770   if (ClassLoaderDataShared::is_full_module_graph_loaded()) {
771     return true;
772   }
773 
774   if (!_is_using_full_module_graph) {
775     return false;
776   }
777 
778   if (is_using_archive() && ArchiveHeapLoader::can_use()) {
779     // Classes used by the archived full module graph are loaded in JVMTI early phase.
780     assert(!(JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()),
781            "CDS should be disabled if early class hooks are enabled");
782     return true;

789 void CDSConfig::stop_dumping_full_module_graph(const char* reason) {
790   if (_is_dumping_full_module_graph) {
791     _is_dumping_full_module_graph = false;
792     if (reason != nullptr) {
793       log_info(cds)("full module graph cannot be dumped: %s", reason);
794     }
795   }
796 }
797 
798 void CDSConfig::stop_using_full_module_graph(const char* reason) {
799   assert(!ClassLoaderDataShared::is_full_module_graph_loaded(), "you call this function too late!");
800   if (_is_using_full_module_graph) {
801     _is_using_full_module_graph = false;
802     if (reason != nullptr) {
803       log_info(cds)("full module graph cannot be loaded: %s", reason);
804     }
805   }
806 }
807 
808 bool CDSConfig::is_dumping_aot_linked_classes() {
809   if (is_dumping_preimage_static_archive()) {
810     return AOTClassLinking;
811   } else if (is_dumping_dynamic_archive()) {
812     return is_using_full_module_graph() && AOTClassLinking;
813   } else if (is_dumping_static_archive()) {
814     return is_dumping_full_module_graph() && AOTClassLinking;
815   } else {
816     return false;
817   }
818 }
819 
820 bool CDSConfig::is_using_aot_linked_classes() {
821   if (is_dumping_final_static_archive()) {
822     // We assume that the final image is being dumped with the exact same module graph as the training run,
823     // so all aot-linked classes can be loaded.
824     return _has_aot_linked_classes;
825   }
826   // Make sure we have the exact same module graph as in the assembly phase, or else
827   // some aot-linked classes may not be visible so cannot be loaded.
828   return is_using_full_module_graph() && _has_aot_linked_classes;
829 }
830 
831 bool CDSConfig::is_dumping_dynamic_proxies() {
832   return is_dumping_full_module_graph() && is_dumping_invokedynamic() && ArchiveDynamicProxies;
833 }
834 
835 void CDSConfig::set_has_aot_linked_classes(bool has_aot_linked_classes) {
836   _has_aot_linked_classes |= has_aot_linked_classes;
837 }
838 
839 bool CDSConfig::is_initing_classes_at_dump_time() {
840   return is_dumping_heap() && is_dumping_aot_linked_classes();
841 }
842 
843 bool CDSConfig::is_dumping_invokedynamic() {
844   // Requires is_dumping_aot_linked_classes(). Otherwise the classes of some archived heap
845   // objects used by the archive indy callsites may be replaced at runtime.
846   return AOTInvokeDynamicLinking && is_dumping_aot_linked_classes() && is_dumping_heap();
847 }
848 
849 bool CDSConfig::is_dumping_packages() {
850   return ArchivePackages && is_dumping_heap();
851 }
852 
853 bool CDSConfig::is_loading_packages() {
854   return UseSharedSpaces && is_using_full_module_graph() && _is_loading_packages;
855 }
856 
857 bool CDSConfig::is_dumping_protection_domains() {
858   if (_is_security_manager_allowed) {
859     // For sanity, don't archive PDs. TODO: can this be relaxed?
860     return false;
861   }
862   // Archived PDs for the modules will reference their java.lang.Module, which must
863   // also be archived.
864   return ArchiveProtectionDomains && is_dumping_full_module_graph();
865 }
866 
867 bool CDSConfig::is_loading_protection_domains() {
868   if (_is_security_manager_allowed) {
869     // For sanity, don't used any archived PDs. TODO: can this be relaxed?
870     return false;
871   }
872   return UseSharedSpaces && is_using_full_module_graph() && _is_loading_protection_domains;
873 }
874 
875 bool CDSConfig::is_dumping_reflection_data() {
876   // reflection data use LambdaForm classes
877   return ArchiveReflectionData && is_dumping_invokedynamic();
878 }
879 
880 bool CDSConfig::is_loading_invokedynamic() {
881   return UseSharedSpaces && is_using_full_module_graph() && _has_archived_invokedynamic;
882 }
883 
884 #endif // INCLUDE_CDS_JAVA_HEAP
885 
886 // This is allowed by default. We disable it only in the final image dump before the
887 // metadata and heap are dumped.
888 static bool _is_dumping_cached_code = true;
889 
890 bool CDSConfig::is_dumping_cached_code() {
891   return _is_dumping_cached_code;
892 }
893 
894 void CDSConfig::disable_dumping_cached_code() {
895   _is_dumping_cached_code = false;
896 }
897 
898 void CDSConfig::enable_dumping_cached_code() {
899   _is_dumping_cached_code = true;
900 }
< prev index next >