< prev index next >

src/hotspot/share/cds/cdsConfig.cpp

Print this page

  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/heapShared.hpp"

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

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

 33 #include "runtime/arguments.hpp"

 34 #include "runtime/java.hpp"
 35 #include "utilities/defaultStream.hpp"
 36 
 37 bool CDSConfig::_is_dumping_static_archive = false;
 38 bool CDSConfig::_is_dumping_dynamic_archive = false;
 39 
 40 // The ability to dump the FMG depends on many factors checked by
 41 // is_dumping_full_module_graph(), but can be unconditionally disabled by
 42 // _dumping_full_module_graph_disabled. (Ditto for loading the FMG).
 43 bool CDSConfig::_dumping_full_module_graph_disabled = false;
 44 bool CDSConfig::_loading_full_module_graph_disabled = false;


 45 
 46 char* CDSConfig::_default_archive_path = nullptr;
 47 char* CDSConfig::_static_archive_path = nullptr;
 48 char* CDSConfig::_dynamic_archive_path = nullptr;
 49 
 50 void CDSConfig::initialize() {
 51   if (is_dumping_static_archive()) {
 52     if (RequireSharedSpaces) {
 53       warning("Cannot dump shared archive while using shared archive");
 54     }
 55     UseSharedSpaces = false;
 56   }
 57 
 58   // Initialize shared archive paths which could include both base and dynamic archive paths
 59   // This must be after set_ergonomics_flags() called so flag UseCompressedOops is set properly.
 60   //
 61   // UseSharedSpaces may be disabled if -XX:SharedArchiveFile is invalid.
 62   if (is_dumping_static_archive() || UseSharedSpaces) {
 63     init_shared_archive_paths();
 64   }
 65 }
 66 
 67 char* CDSConfig::default_archive_path() {
 68   if (_default_archive_path == nullptr) {
 69     char jvm_path[JVM_MAXPATHLEN];
 70     os::jvm_path(jvm_path, sizeof(jvm_path));
 71     char *end = strrchr(jvm_path, *os::file_separator());

105     vm_exit_during_initialization("Base archive was not specified", archive_path);
106   }
107   size_t len = end_ptr - begin_ptr;
108   char* cur_path = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
109   strncpy(cur_path, begin_ptr, len);
110   cur_path[len] = '\0';
111   *base_archive_path = cur_path;
112 
113   begin_ptr = ++end_ptr;
114   if (*begin_ptr == '\0') {
115     vm_exit_during_initialization("Top archive was not specified", archive_path);
116   }
117   end_ptr = strchr(begin_ptr, '\0');
118   assert(end_ptr != nullptr, "sanity");
119   len = end_ptr - begin_ptr;
120   cur_path = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
121   strncpy(cur_path, begin_ptr, len + 1);
122   *top_archive_path = cur_path;
123 }
124 







125 void CDSConfig::init_shared_archive_paths() {
126   if (ArchiveClassesAtExit != nullptr) {
127     assert(!RecordDynamicDumpInfo, "already checked");
128     if (is_dumping_static_archive()) {
129       vm_exit_during_initialization("-XX:ArchiveClassesAtExit cannot be used with -Xshare:dump");
130     }
131     check_unsupported_dumping_properties();
132 
133     if (os::same_files(default_archive_path(), ArchiveClassesAtExit)) {
134       vm_exit_during_initialization(
135         "Cannot specify the default CDS archive for -XX:ArchiveClassesAtExit", default_archive_path());
136     }
137   }
138 
139   if (SharedArchiveFile == nullptr) {
140     _static_archive_path = default_archive_path();
141   } else {
142     int archives = num_archives(SharedArchiveFile);
143     assert(archives > 0, "must be");
144 
145     if (is_dumping_archive() && archives > 1) {
146       vm_exit_during_initialization(
147         "Cannot have more than 1 archive file specified in -XX:SharedArchiveFile during CDS dumping");
148     }
149 




150     if (is_dumping_static_archive()) {
151       assert(archives == 1, "must be");
152       // Static dump is simple: only one archive is allowed in SharedArchiveFile. This file
153       // will be overwritten no matter regardless of its contents
154       _static_archive_path = os::strdup_check_oom(SharedArchiveFile, mtArguments);
155     } else {
156       // SharedArchiveFile may specify one or two files. In case (c), the path for base.jsa
157       // is read from top.jsa
158       //    (a) 1 file:  -XX:SharedArchiveFile=base.jsa
159       //    (b) 2 files: -XX:SharedArchiveFile=base.jsa:top.jsa
160       //    (c) 2 files: -XX:SharedArchiveFile=top.jsa
161       //
162       // However, if either RecordDynamicDumpInfo or ArchiveClassesAtExit is used, we do not
163       // allow cases (b) and (c). Case (b) is already checked above.
164 
165       if (archives > 2) {
166         vm_exit_during_initialization(
167           "Cannot have more than 2 archive files specified in the -XX:SharedArchiveFile option");
168       }
169       if (archives == 1) {
170         char* base_archive_path = nullptr;
171         bool success =
172           FileMapInfo::get_base_archive_name_from_header(SharedArchiveFile, &base_archive_path);
173         if (!success) {




174           // If +AutoCreateSharedArchive and the specified shared archive does not exist,
175           // regenerate the dynamic archive base on default archive.
176           if (AutoCreateSharedArchive && !os::file_exists(SharedArchiveFile)) {
177             enable_dumping_dynamic_archive();
178             ArchiveClassesAtExit = const_cast<char *>(SharedArchiveFile);
179             _static_archive_path = default_archive_path();
180             SharedArchiveFile = nullptr;
181           } else {
182             if (AutoCreateSharedArchive) {
183               warning("-XX:+AutoCreateSharedArchive is unsupported when base CDS archive is not loaded. Run with -Xlog:cds for more info.");
184               AutoCreateSharedArchive = false;
185             }
186             Arguments::no_shared_spaces("invalid archive");
187           }
188         } else if (base_archive_path == nullptr) {
189           // User has specified a single archive, which is a static archive.
190           _static_archive_path = const_cast<char *>(SharedArchiveFile);
191         } else {
192           // User has specified a single archive, which is a dynamic archive.
193           _dynamic_archive_path = const_cast<char *>(SharedArchiveFile);

276     // dynamic dumping, just return false for now.
277     // check_unsupported_dumping_properties() will be called later to check the same set of
278     // properties, and will exit the VM with the correct error message if the unsupported properties
279     // are used.
280     return false;
281   }
282   for (uint i = 0; i < ARRAY_SIZE(unsupported_properties); i++) {
283     if (Arguments::get_property(unsupported_properties[i]) != nullptr) {
284       if (RequireSharedSpaces) {
285         warning("CDS is disabled when the %s option is specified.", unsupported_options[i]);
286       } else {
287         log_info(cds)("CDS is disabled when the %s option is specified.", unsupported_options[i]);
288       }
289       return true;
290     }
291   }
292   return false;
293 }
294 
295 bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase,  bool mode_flag_cmd_line) {



































































296   if (is_dumping_static_archive()) {
297     if (!mode_flag_cmd_line) {


298       // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
299       //
300       // If your classlist is large and you don't care about deterministic dumping, you can use
301       // -Xshare:dump -Xmixed to improve dumping speed.
302       Arguments::set_mode_flags(Arguments::_int);
303     } else if (Arguments::mode() == Arguments::_comp) {
304       // -Xcomp may use excessive CPU for the test tiers. Also, -Xshare:dump runs a small and fixed set of
305       // Java code, so there's not much benefit in running -Xcomp.
306       log_info(cds)("reduced -Xcomp to -Xmixed for static dumping");
307       Arguments::set_mode_flags(Arguments::_mixed);
308     }
309 
310     // String deduplication may cause CDS to iterate the strings in different order from one
311     // run to another which resulting in non-determinstic CDS archives.
312     // Disable UseStringDeduplication while dumping CDS archive.
313     UseStringDeduplication = false;





314   }
315 
316   // RecordDynamicDumpInfo is not compatible with ArchiveClassesAtExit
317   if (ArchiveClassesAtExit != nullptr && RecordDynamicDumpInfo) {
318     jio_fprintf(defaultStream::output_stream(),
319                 "-XX:+RecordDynamicDumpInfo cannot be used with -XX:ArchiveClassesAtExit.\n");
320     return false;
321   }
322 
323   if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
324     disable_dumping_dynamic_archive();
325   } else {
326     enable_dumping_dynamic_archive();
327   }
328 
329   if (AutoCreateSharedArchive) {
330     if (SharedArchiveFile == nullptr) {
331       log_warning(cds)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
332       return false;
333     }

335       log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
336       return false;
337     }
338   }
339 
340   if (UseSharedSpaces && patch_mod_javabase) {
341     Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
342   }
343   if (UseSharedSpaces && check_unsupported_cds_runtime_properties()) {
344     UseSharedSpaces = false;
345   }
346 
347   if (is_dumping_archive()) {
348     // Always verify non-system classes during CDS dump
349     if (!BytecodeVerificationRemote) {
350       BytecodeVerificationRemote = true;
351       log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
352     }
353   }
354 












355   return true;
356 }









































357 
358 #if INCLUDE_CDS_JAVA_HEAP
359 bool CDSConfig::is_dumping_heap() {
360   // heap dump is not supported in dynamic dump
361   return is_dumping_static_archive() && HeapShared::can_write();




362 }
363 
364 bool CDSConfig::is_dumping_full_module_graph() {
365   if (!_dumping_full_module_graph_disabled &&
366       is_dumping_heap() &&
367       MetaspaceShared::use_optimized_module_handling()) {
368     return true;
369   } else {
370     return false;
371   }
372 }
373 
374 bool CDSConfig::is_loading_full_module_graph() {
375   if (ClassLoaderDataShared::is_full_module_graph_loaded()) {
376     return true;
377   }
378 
379   if (!_loading_full_module_graph_disabled &&
380       UseSharedSpaces &&
381       ArchiveHeapLoader::can_use() &&

390 }
391 
392 void CDSConfig::disable_dumping_full_module_graph(const char* reason) {
393   if (!_dumping_full_module_graph_disabled) {
394     _dumping_full_module_graph_disabled = true;
395     if (reason != nullptr) {
396       log_info(cds)("full module graph cannot be dumped: %s", reason);
397     }
398   }
399 }
400 
401 void CDSConfig::disable_loading_full_module_graph(const char* reason) {
402   assert(!ClassLoaderDataShared::is_full_module_graph_loaded(), "you call this function too late!");
403   if (!_loading_full_module_graph_disabled) {
404     _loading_full_module_graph_disabled = true;
405     if (reason != nullptr) {
406       log_info(cds)("full module graph cannot be loaded: %s", reason);
407     }
408   }
409 }








410 #endif // INCLUDE_CDS_JAVA_HEAP

























  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 "runtime/arguments.hpp"
 39 #include "runtime/globals_extension.hpp"
 40 #include "runtime/java.hpp"
 41 #include "utilities/defaultStream.hpp"
 42 
 43 bool CDSConfig::_is_dumping_static_archive = false;
 44 bool CDSConfig::_is_dumping_dynamic_archive = false;
 45 
 46 // The ability to dump the FMG depends on many factors checked by
 47 // is_dumping_full_module_graph(), but can be unconditionally disabled by
 48 // _dumping_full_module_graph_disabled. (Ditto for loading the FMG).
 49 bool CDSConfig::_dumping_full_module_graph_disabled = false;
 50 bool CDSConfig::_loading_full_module_graph_disabled = false;
 51 bool CDSConfig::_has_preloaded_classes;
 52 bool CDSConfig::_is_loading_invokedynamic = false;
 53 
 54 char* CDSConfig::_default_archive_path = nullptr;
 55 char* CDSConfig::_static_archive_path = nullptr;
 56 char* CDSConfig::_dynamic_archive_path = nullptr;
 57 
 58 void CDSConfig::initialize() {
 59   if (is_dumping_static_archive() && !CDSConfig::is_dumping_final_static_archive()) {
 60     if (RequireSharedSpaces) {
 61       warning("Cannot dump shared archive while using shared archive");
 62     }
 63     UseSharedSpaces = false;
 64   }
 65 
 66   // Initialize shared archive paths which could include both base and dynamic archive paths
 67   // This must be after set_ergonomics_flags() called so flag UseCompressedOops is set properly.
 68   //
 69   // UseSharedSpaces may be disabled if -XX:SharedArchiveFile is invalid.
 70   if (is_dumping_static_archive() || UseSharedSpaces) {
 71     init_shared_archive_paths();
 72   }
 73 }
 74 
 75 char* CDSConfig::default_archive_path() {
 76   if (_default_archive_path == nullptr) {
 77     char jvm_path[JVM_MAXPATHLEN];
 78     os::jvm_path(jvm_path, sizeof(jvm_path));
 79     char *end = strrchr(jvm_path, *os::file_separator());

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

299     // dynamic dumping, just return false for now.
300     // check_unsupported_dumping_properties() will be called later to check the same set of
301     // properties, and will exit the VM with the correct error message if the unsupported properties
302     // are used.
303     return false;
304   }
305   for (uint i = 0; i < ARRAY_SIZE(unsupported_properties); i++) {
306     if (Arguments::get_property(unsupported_properties[i]) != nullptr) {
307       if (RequireSharedSpaces) {
308         warning("CDS is disabled when the %s option is specified.", unsupported_options[i]);
309       } else {
310         log_info(cds)("CDS is disabled when the %s option is specified.", unsupported_options[i]);
311       }
312       return true;
313     }
314   }
315   return false;
316 }
317 
318 bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase,  bool mode_flag_cmd_line) {
319   if (CacheDataStore != nullptr) {
320     if (SharedArchiveFile != nullptr) {
321       vm_exit_during_initialization("CacheDataStore and SharedArchiveFile cannot be both specified");
322     }
323     if (!PreloadSharedClasses) {
324       // TODO: in the forked JVM, we should ensure all classes are loaded from the hotspot.cds.preimage.
325       // PreloadSharedClasses only loads the classes for built-in loaders. We need to load the classes
326       // for custom loaders as well.
327       vm_exit_during_initialization("CacheDataStore requires PreloadSharedClasses");
328     }
329 
330     if (CDSPreimage == nullptr) {
331       if (os::file_exists(CacheDataStore) /* && TODO: CDS file is valid*/) {
332         // The CacheDataStore is already up to date. Use it. Also turn on cached code by default.
333         SharedArchiveFile = CacheDataStore;
334         FLAG_SET_ERGO_IF_DEFAULT(ReplayTraining, true);
335         FLAG_SET_ERGO_IF_DEFAULT(LoadCachedCode, true);
336         if (LoadCachedCode && FLAG_IS_DEFAULT(CachedCodeFile)) {
337           set_new_workflow_default_CachedCodeFile();
338         }
339       } else {
340         // The preimage dumping phase -- run the app and write the preimage file
341         size_t len = strlen(CacheDataStore) + 10;
342         char* preimage = AllocateHeap(len, mtArguments);
343         jio_snprintf(preimage, len, "%s.preimage", CacheDataStore);
344 
345         UseSharedSpaces = false;
346         CDSConfig::enable_dumping_static_archive();
347         SharedArchiveFile = preimage;
348         log_info(cds)("CacheDataStore needs to be updated. Writing %s file", SharedArchiveFile);
349 
350         // At VM exit, the module graph may be contaminated with program states. We should rebuild the
351         // module graph when dumping the CDS final image.
352         log_info(cds)("full module graph: disabled when writing CDS preimage");
353         HeapShared::disable_writing();
354         CDSConfig::disable_dumping_full_module_graph();
355         ArchiveInvokeDynamic = false;
356 
357         FLAG_SET_ERGO_IF_DEFAULT(RecordTraining, true);
358       }
359     } else {
360       // The final image dumping phase -- load the preimage and write the final image file
361       SharedArchiveFile = CDSPreimage;
362       UseSharedSpaces = true;
363       log_info(cds)("Generate CacheDataStore %s from CDSPreimage %s", CacheDataStore, CDSPreimage);
364       // Force -Xbatch for AOT compilation.
365       if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
366         return JNI_EINVAL;
367       }
368       Inline = false; // FIXME: this is just for temp debugging.
369       RecordTraining = false; // This will be updated inside MetaspaceShared::preload_and_dump()
370 
371       FLAG_SET_ERGO_IF_DEFAULT(ReplayTraining, true);
372       // Settings for AOT
373       FLAG_SET_ERGO_IF_DEFAULT(StoreCachedCode, true);
374       if (StoreCachedCode && FLAG_IS_DEFAULT(CachedCodeFile)) {
375         set_new_workflow_default_CachedCodeFile();
376         // Cannot dump cached code until metadata and heap are dumped.
377         CDSConfig::disable_dumping_cached_code();
378       }
379     }
380   } else {
381     if (CDSPreimage != nullptr) {
382       vm_exit_during_initialization("CDSPreimage must be specified only when CacheDataStore is specified");
383     }
384   }
385 
386   if (is_dumping_static_archive()) {
387     if (is_dumping_preimage_static_archive() || is_dumping_final_static_archive()) {
388       // Don't tweak execution mode
389     } else if (!mode_flag_cmd_line) {
390       // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
391       //
392       // If your classlist is large and you don't care about deterministic dumping, you can use
393       // -Xshare:dump -Xmixed to improve dumping speed.
394       Arguments::set_mode_flags(Arguments::_int);
395     } else if (Arguments::mode() == Arguments::_comp) {
396       // -Xcomp may use excessive CPU for the test tiers. Also, -Xshare:dump runs a small and fixed set of
397       // Java code, so there's not much benefit in running -Xcomp.
398       log_info(cds)("reduced -Xcomp to -Xmixed for static dumping");
399       Arguments::set_mode_flags(Arguments::_mixed);
400     }
401 
402     // String deduplication may cause CDS to iterate the strings in different order from one
403     // run to another which resulting in non-determinstic CDS archives.
404     // Disable UseStringDeduplication while dumping CDS archive.
405     UseStringDeduplication = false;
406 
407     Arguments::PropertyList_add(new SystemProperty("java.lang.invoke.MethodHandle.NO_SOFT_CACHE", "true", false));
408   } else {
409     // This flag is useful only when dumping static archive
410     ArchiveInvokeDynamic = false;
411   }
412 
413   // RecordDynamicDumpInfo is not compatible with ArchiveClassesAtExit
414   if (ArchiveClassesAtExit != nullptr && RecordDynamicDumpInfo) {
415     jio_fprintf(defaultStream::output_stream(),
416                 "-XX:+RecordDynamicDumpInfo cannot be used with -XX:ArchiveClassesAtExit.\n");
417     return false;
418   }
419 
420   if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
421     disable_dumping_dynamic_archive();
422   } else {
423     enable_dumping_dynamic_archive();
424   }
425 
426   if (AutoCreateSharedArchive) {
427     if (SharedArchiveFile == nullptr) {
428       log_warning(cds)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
429       return false;
430     }

432       log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
433       return false;
434     }
435   }
436 
437   if (UseSharedSpaces && patch_mod_javabase) {
438     Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
439   }
440   if (UseSharedSpaces && check_unsupported_cds_runtime_properties()) {
441     UseSharedSpaces = false;
442   }
443 
444   if (is_dumping_archive()) {
445     // Always verify non-system classes during CDS dump
446     if (!BytecodeVerificationRemote) {
447       BytecodeVerificationRemote = true;
448       log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
449     }
450   }
451 
452   if (!CDSConfig::is_dumping_static_archive() || !PreloadSharedClasses) {
453     // FIXME -- CDSConfig::is_dumping_heap() is not yet callable from here, as UseG1GC is not yet set by ergo!
454     //
455     // These optimizations require heap dumping and PreloadSharedClasses, or else
456     // the classes of some archived heap objects may be replaced at runtime.
457     ArchiveInvokeDynamic = false;
458   }
459 
460   if (!ArchiveInvokeDynamic) {
461     ArchiveReflectionData = false; // reflection data use LambdaForm classes
462   }
463 
464   return true;
465 }
466 bool CDSConfig::is_dumping_classic_static_archive() {
467   return _is_dumping_static_archive && CacheDataStore == nullptr && CDSPreimage == nullptr;
468 }
469 
470 bool CDSConfig::is_dumping_preimage_static_archive() {
471   return _is_dumping_static_archive && CacheDataStore != nullptr && CDSPreimage == nullptr;
472 }
473 
474 bool CDSConfig::is_dumping_final_static_archive() {
475   if (CDSPreimage != nullptr) {
476     assert(CacheDataStore != nullptr, "must be"); // should have been properly initialized by arguments.cpp
477   }
478 
479   // Note: _is_dumping_static_archive is false! // FIXME -- refactor this so it makes more sense!
480   return CacheDataStore != nullptr && CDSPreimage != nullptr;
481 }
482 
483 bool CDSConfig::is_dumping_regenerated_lambdaform_invokers() {
484   if (is_dumping_final_static_archive()) {
485     // Not yet supported in new workflow -- the training data may point
486     // to a method in a lambdaform holder class that was not regenerated
487     // due to JDK-8318064.
488     return false;
489   } else {
490     return is_dumping_archive();
491   }
492 }
493 
494 bool CDSConfig::is_tracing_dynamic_proxy() {
495   return ClassListWriter::is_enabled() || is_dumping_preimage_static_archive();
496 }
497 
498 // Preserve all states that were examined used during dumptime verification, such
499 // that the verification result (pass or fail) cannot be changed at runtime.
500 //
501 // For example, if the verification of ik requires that class A must be a subtype of B,
502 // then this relationship between A and B cannot be changed at runtime. I.e., the app
503 // cannot load alternative versions of A and B such that A is not a subtype of B.
504 bool CDSConfig::preserve_all_dumptime_verification_states(const InstanceKlass* ik) {
505   return PreloadSharedClasses && SystemDictionaryShared::is_builtin(ik);
506 }
507 
508 #if INCLUDE_CDS_JAVA_HEAP
509 bool CDSConfig::is_dumping_heap() {
510   return is_dumping_static_archive() && !is_dumping_preimage_static_archive()
511     && HeapShared::can_write();
512 }
513 
514 bool CDSConfig::is_loading_heap() {
515   return ArchiveHeapLoader::is_in_use();
516 }
517 
518 bool CDSConfig::is_dumping_full_module_graph() {
519   if (!_dumping_full_module_graph_disabled &&
520       is_dumping_heap() &&
521       MetaspaceShared::use_optimized_module_handling()) {
522     return true;
523   } else {
524     return false;
525   }
526 }
527 
528 bool CDSConfig::is_loading_full_module_graph() {
529   if (ClassLoaderDataShared::is_full_module_graph_loaded()) {
530     return true;
531   }
532 
533   if (!_loading_full_module_graph_disabled &&
534       UseSharedSpaces &&
535       ArchiveHeapLoader::can_use() &&

544 }
545 
546 void CDSConfig::disable_dumping_full_module_graph(const char* reason) {
547   if (!_dumping_full_module_graph_disabled) {
548     _dumping_full_module_graph_disabled = true;
549     if (reason != nullptr) {
550       log_info(cds)("full module graph cannot be dumped: %s", reason);
551     }
552   }
553 }
554 
555 void CDSConfig::disable_loading_full_module_graph(const char* reason) {
556   assert(!ClassLoaderDataShared::is_full_module_graph_loaded(), "you call this function too late!");
557   if (!_loading_full_module_graph_disabled) {
558     _loading_full_module_graph_disabled = true;
559     if (reason != nullptr) {
560       log_info(cds)("full module graph cannot be loaded: %s", reason);
561     }
562   }
563 }
564 
565 bool CDSConfig::is_loading_invokedynamic() {
566   return UseSharedSpaces && is_loading_heap() && _is_loading_invokedynamic;
567 }
568 
569 bool CDSConfig::is_dumping_dynamic_proxy() {
570   return is_dumping_full_module_graph() && is_dumping_invokedynamic();
571 }
572 #endif // INCLUDE_CDS_JAVA_HEAP
573 
574 // This is allowed by default. We disable it only in the final image dump before the
575 // metadata and heap are dumped.
576 static bool _is_dumping_cached_code = true;
577 
578 bool CDSConfig::is_dumping_cached_code() {
579   return _is_dumping_cached_code;
580 }
581 
582 void CDSConfig::disable_dumping_cached_code() {
583   _is_dumping_cached_code = false;
584 }
585 
586 void CDSConfig::enable_dumping_cached_code() {
587   _is_dumping_cached_code = true;
588 }
589 
590 bool CDSConfig::is_initing_classes_at_dump_time() {
591   return is_dumping_heap() && PreloadSharedClasses;
592 }
593 
594 bool CDSConfig::is_dumping_invokedynamic() {
595   return ArchiveInvokeDynamic && is_dumping_heap();
596 }
< prev index next >