< prev index next >

src/hotspot/share/cds/cdsConfig.cpp

Print this page

 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/java.hpp"
 37 #include "utilities/defaultStream.hpp"
 38 
 39 bool CDSConfig::_is_dumping_static_archive = false;
 40 bool CDSConfig::_is_dumping_dynamic_archive = false;
 41 bool CDSConfig::_is_using_optimized_module_handling = true;
 42 bool CDSConfig::_is_dumping_full_module_graph = true;
 43 bool CDSConfig::_is_using_full_module_graph = true;
 44 








 45 char* CDSConfig::_default_archive_path = nullptr;
 46 char* CDSConfig::_static_archive_path = nullptr;
 47 char* CDSConfig::_dynamic_archive_path = nullptr;
 48 
 49 int CDSConfig::get_status() {
 50   assert(Universe::is_fully_initialized(), "status is finalized only after Universe is initialized");
 51   return (is_dumping_archive()              ? IS_DUMPING_ARCHIVE : 0) |
 52          (is_dumping_static_archive()       ? IS_DUMPING_STATIC_ARCHIVE : 0) |
 53          (is_logging_lambda_form_invokers() ? IS_LOGGING_LAMBDA_FORM_INVOKERS : 0) |
 54          (is_using_archive()                ? IS_USING_ARCHIVE : 0);
 55 }
 56 
 57 
 58 void CDSConfig::initialize() {
 59   if (is_dumping_static_archive()) {
 60     if (RequireSharedSpaces) {
 61       warning("Cannot dump shared archive while using shared archive");
 62     }
 63     UseSharedSpaces = false;
 64   }

 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() || is_using_archive()) {
 71     init_shared_archive_paths();
 72   }
 73 
 74   if (!is_dumping_heap()) {
 75     _is_dumping_full_module_graph = false;
 76   }
 77 }
 78 
 79 char* CDSConfig::default_archive_path() {
 80   if (_default_archive_path == nullptr) {
 81     char jvm_path[JVM_MAXPATHLEN];
 82     os::jvm_path(jvm_path, sizeof(jvm_path));
 83     char *end = strrchr(jvm_path, *os::file_separator());
 84     if (end != nullptr) *end = '\0';
 85     size_t jvm_path_len = strlen(jvm_path);
 86     size_t file_sep_len = strlen(os::file_separator());
 87     const size_t len = jvm_path_len + file_sep_len + 20;
 88     _default_archive_path = NEW_C_HEAP_ARRAY(char, len, mtArguments);
 89     jio_snprintf(_default_archive_path, len,
 90                 LP64_ONLY(!UseCompressedOops ? "%s%sclasses_nocoops.jsa":) "%s%sclasses.jsa",
 91                 jvm_path, os::file_separator());




 92   }
 93   return _default_archive_path;
 94 }
 95 
 96 int CDSConfig::num_archives(const char* archive_path) {
 97   if (archive_path == nullptr) {
 98     return 0;
 99   }
100   int npaths = 1;
101   char* p = (char*)archive_path;
102   while (*p != '\0') {
103     if (*p == os::path_separator()[0]) {
104       npaths++;
105     }
106     p++;
107   }
108   return npaths;
109 }
110 
111 void CDSConfig::extract_shared_archive_paths(const char* archive_path,

254   for (const char* property : incompatible_properties) {
255     if (strcmp(key, property) == 0) {
256       stop_dumping_full_module_graph();
257       stop_using_full_module_graph();
258       log_info(cds)("full module graph: disabled due to incompatible property: %s=%s", key, value);
259       break;
260     }
261   }
262 
263 }
264 
265 // Returns any JVM command-line option, such as "--patch-module", that's not supported by CDS.
266 static const char* find_any_unsupported_module_option() {
267   // Note that arguments.cpp has translated the command-line options into properties. If we find an
268   // unsupported property, translate it back to its command-line option for better error reporting.
269 
270   // The following properties are checked by Arguments::is_internal_module_property() and cannot be
271   // directly specified in the command-line.
272   static const char* unsupported_module_properties[] = {
273     "jdk.module.limitmods",
274     "jdk.module.upgrade.path",
275     "jdk.module.patch.0"
276   };
277   static const char* unsupported_module_options[] = {
278     "--limit-modules",
279     "--upgrade-module-path",
280     "--patch-module"
281   };
282 
283   assert(ARRAY_SIZE(unsupported_module_properties) == ARRAY_SIZE(unsupported_module_options), "must be");
284   SystemProperty* sp = Arguments::system_properties();
285   while (sp != nullptr) {
286     for (uint i = 0; i < ARRAY_SIZE(unsupported_module_properties); i++) {
287       if (strcmp(sp->key(), unsupported_module_properties[i]) == 0) {
288         return unsupported_module_options[i];
289       }
290     }
291     sp = sp->next();
292   }
293 
294   return nullptr; // not found
295 }
296 
297 void CDSConfig::check_unsupported_dumping_module_options() {
298   assert(is_dumping_archive(), "this function is only used with CDS dump time");
299   const char* option = find_any_unsupported_module_option();
300   if (option != nullptr) {
301     vm_exit_during_initialization("Cannot use the following option when dumping the shared archive", option);
302   }






303   // Check for an exploded module build in use with -Xshare:dump.
304   if (!Arguments::has_jimage()) {
305     vm_exit_during_initialization("Dumping the shared archive is not supported with an exploded module build");
306   }
307 }
308 
309 bool CDSConfig::has_unsupported_runtime_module_options() {
310   assert(is_using_archive(), "this function is only used with -Xshare:{on,auto}");
311   if (ArchiveClassesAtExit != nullptr) {
312     // dynamic dumping, just return false for now.
313     // check_unsupported_dumping_properties() will be called later to check the same set of
314     // properties, and will exit the VM with the correct error message if the unsupported properties
315     // are used.
316     return false;
317   }
318   const char* option = find_any_unsupported_module_option();
319   if (option != nullptr) {
320     if (RequireSharedSpaces) {
321       warning("CDS is disabled when the %s option is specified.", option);
322     } else {
323       log_info(cds)("CDS is disabled when the %s option is specified.", option);
324     }
325     return true;
326   }










327   return false;
328 }
329 
330 bool CDSConfig::check_vm_args_consistency(bool patch_mod_javabase, bool mode_flag_cmd_line) {
331   if (is_dumping_static_archive()) {
332     if (!mode_flag_cmd_line) {
333       // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
334       //
335       // If your classlist is large and you don't care about deterministic dumping, you can use
336       // -Xshare:dump -Xmixed to improve dumping speed.
337       Arguments::set_mode_flags(Arguments::_int);
338     } else if (Arguments::mode() == Arguments::_comp) {
339       // -Xcomp may use excessive CPU for the test tiers. Also, -Xshare:dump runs a small and fixed set of
340       // Java code, so there's not much benefit in running -Xcomp.
341       log_info(cds)("reduced -Xcomp to -Xmixed for static dumping");
342       Arguments::set_mode_flags(Arguments::_mixed);
343     }
344 
345     // String deduplication may cause CDS to iterate the strings in different order from one
346     // run to another which resulting in non-determinstic CDS archives.
347     // Disable UseStringDeduplication while dumping CDS archive.
348     UseStringDeduplication = false;
349   }
350 

355     return false;
356   }
357 
358   if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
359     disable_dumping_dynamic_archive();
360   } else {
361     enable_dumping_dynamic_archive();
362   }
363 
364   if (AutoCreateSharedArchive) {
365     if (SharedArchiveFile == nullptr) {
366       log_warning(cds)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
367       return false;
368     }
369     if (ArchiveClassesAtExit != nullptr) {
370       log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
371       return false;
372     }
373   }
374 
375   if (is_using_archive() && patch_mod_javabase) {
376     Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
377   }
378   if (is_using_archive() && has_unsupported_runtime_module_options()) {
379     UseSharedSpaces = false;
380   }
381 
382   if (is_dumping_archive()) {
383     // Always verify non-system classes during CDS dump
384     if (!BytecodeVerificationRemote) {
385       BytecodeVerificationRemote = true;
386       log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
387     }
388   }
389 
390   return true;
391 }
392 
393 bool CDSConfig::is_using_archive() {
394   return UseSharedSpaces;
395 }
396 
397 bool CDSConfig::is_logging_lambda_form_invokers() {
398   return ClassListWriter::is_enabled() || is_dumping_dynamic_archive();
399 }
400 
401 void CDSConfig::stop_using_optimized_module_handling() {
402   _is_using_optimized_module_handling = false;
403   _is_dumping_full_module_graph = false; // This requires is_using_optimized_module_handling()
404   _is_using_full_module_graph = false; // This requires is_using_optimized_module_handling()
405 }
406 
407 #if INCLUDE_CDS_JAVA_HEAP
408 bool CDSConfig::is_dumping_heap() {




409   // heap dump is not supported in dynamic dump
410   return is_dumping_static_archive() && HeapShared::can_write();
411 }
412 
413 bool CDSConfig::is_using_full_module_graph() {
414   if (ClassLoaderDataShared::is_full_module_graph_loaded()) {
415     return true;
416   }
417 
418   if (!_is_using_full_module_graph) {
419     return false;
420   }
421 
422   if (is_using_archive() && ArchiveHeapLoader::can_use()) {
423     // Classes used by the archived full module graph are loaded in JVMTI early phase.
424     assert(!(JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()),
425            "CDS should be disabled if early class hooks are enabled");
426     return true;
427   } else {
428     _is_using_full_module_graph = false;

 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.hpp"
 37 #include "runtime/java.hpp"
 38 #include "utilities/defaultStream.hpp"
 39 
 40 bool CDSConfig::_is_dumping_static_archive = false;
 41 bool CDSConfig::_is_dumping_dynamic_archive = false;
 42 bool CDSConfig::_is_using_optimized_module_handling = true;
 43 bool CDSConfig::_is_dumping_full_module_graph = true;
 44 bool CDSConfig::_is_using_full_module_graph = true;
 45 
 46 bool CDSConfig::_module_patching_disables_cds = false;
 47 bool CDSConfig::_java_base_module_patching_disables_cds = false;
 48 
 49 bool CDSConfig::is_valhalla_preview() {
 50   return Arguments::enable_preview() && EnableValhalla;
 51 }
 52 
 53 
 54 char* CDSConfig::_default_archive_path = nullptr;
 55 char* CDSConfig::_static_archive_path = nullptr;
 56 char* CDSConfig::_dynamic_archive_path = nullptr;
 57 
 58 int CDSConfig::get_status() {
 59   assert(Universe::is_fully_initialized(), "status is finalized only after Universe is initialized");
 60   return (is_dumping_archive()              ? IS_DUMPING_ARCHIVE : 0) |
 61          (is_dumping_static_archive()       ? IS_DUMPING_STATIC_ARCHIVE : 0) |
 62          (is_logging_lambda_form_invokers() ? IS_LOGGING_LAMBDA_FORM_INVOKERS : 0) |
 63          (is_using_archive()                ? IS_USING_ARCHIVE : 0);
 64 }
 65 
 66 
 67 void CDSConfig::initialize() {
 68   if (is_dumping_static_archive()) {
 69     if (RequireSharedSpaces) {
 70       warning("Cannot dump shared archive while using shared archive");
 71     }
 72     UseSharedSpaces = false;
 73   }

 76   // This must be after set_ergonomics_flags() called so flag UseCompressedOops is set properly.
 77   //
 78   // UseSharedSpaces may be disabled if -XX:SharedArchiveFile is invalid.
 79   if (is_dumping_static_archive() || is_using_archive()) {
 80     init_shared_archive_paths();
 81   }
 82 
 83   if (!is_dumping_heap()) {
 84     _is_dumping_full_module_graph = false;
 85   }
 86 }
 87 
 88 char* CDSConfig::default_archive_path() {
 89   if (_default_archive_path == nullptr) {
 90     char jvm_path[JVM_MAXPATHLEN];
 91     os::jvm_path(jvm_path, sizeof(jvm_path));
 92     char *end = strrchr(jvm_path, *os::file_separator());
 93     if (end != nullptr) *end = '\0';
 94     size_t jvm_path_len = strlen(jvm_path);
 95     size_t file_sep_len = strlen(os::file_separator());
 96     const size_t len = jvm_path_len + file_sep_len + strlen("classes_nocoops_valhalla.jsa") + 1;
 97     _default_archive_path = NEW_C_HEAP_ARRAY(char, len, mtArguments);
 98     LP64_ONLY(bool nocoops = !UseCompressedOops);
 99     NOT_LP64(bool nocoops = false);
100     bool valhalla = is_valhalla_preview();
101     jio_snprintf(_default_archive_path, len, "%s%sclasses%s%s.jsa",
102                 jvm_path, os::file_separator(),
103                  nocoops ? "_nocoops" : "",
104                  valhalla ? "_valhalla" : "");
105   }
106   return _default_archive_path;
107 }
108 
109 int CDSConfig::num_archives(const char* archive_path) {
110   if (archive_path == nullptr) {
111     return 0;
112   }
113   int npaths = 1;
114   char* p = (char*)archive_path;
115   while (*p != '\0') {
116     if (*p == os::path_separator()[0]) {
117       npaths++;
118     }
119     p++;
120   }
121   return npaths;
122 }
123 
124 void CDSConfig::extract_shared_archive_paths(const char* archive_path,

267   for (const char* property : incompatible_properties) {
268     if (strcmp(key, property) == 0) {
269       stop_dumping_full_module_graph();
270       stop_using_full_module_graph();
271       log_info(cds)("full module graph: disabled due to incompatible property: %s=%s", key, value);
272       break;
273     }
274   }
275 
276 }
277 
278 // Returns any JVM command-line option, such as "--patch-module", that's not supported by CDS.
279 static const char* find_any_unsupported_module_option() {
280   // Note that arguments.cpp has translated the command-line options into properties. If we find an
281   // unsupported property, translate it back to its command-line option for better error reporting.
282 
283   // The following properties are checked by Arguments::is_internal_module_property() and cannot be
284   // directly specified in the command-line.
285   static const char* unsupported_module_properties[] = {
286     "jdk.module.limitmods",
287     "jdk.module.upgrade.path"

288   };
289   static const char* unsupported_module_options[] = {
290     "--limit-modules",
291     "--upgrade-module-path"

292   };
293 
294   assert(ARRAY_SIZE(unsupported_module_properties) == ARRAY_SIZE(unsupported_module_options), "must be");
295   SystemProperty* sp = Arguments::system_properties();
296   while (sp != nullptr) {
297     for (uint i = 0; i < ARRAY_SIZE(unsupported_module_properties); i++) {
298       if (strcmp(sp->key(), unsupported_module_properties[i]) == 0) {
299         return unsupported_module_options[i];
300       }
301     }
302     sp = sp->next();
303   }
304 
305   return nullptr; // not found
306 }
307 
308 void CDSConfig::check_unsupported_dumping_module_options() {
309   assert(is_dumping_archive(), "this function is only used with CDS dump time");
310   const char* option = find_any_unsupported_module_option();
311   if (option != nullptr) {
312     vm_exit_during_initialization("Cannot use the following option when dumping the shared archive", option);
313   }
314 
315   if (module_patching_disables_cds()) {
316     vm_exit_during_initialization(
317             "Cannot use the following option when dumping the shared archive", "--patch-module");
318   }
319 
320   // Check for an exploded module build in use with -Xshare:dump.
321   if (!Arguments::has_jimage()) {
322     vm_exit_during_initialization("Dumping the shared archive is not supported with an exploded module build");
323   }
324 }
325 
326 bool CDSConfig::has_unsupported_runtime_module_options() {
327   assert(is_using_archive(), "this function is only used with -Xshare:{on,auto}");
328   if (ArchiveClassesAtExit != nullptr) {
329     // dynamic dumping, just return false for now.
330     // check_unsupported_dumping_properties() will be called later to check the same set of
331     // properties, and will exit the VM with the correct error message if the unsupported properties
332     // are used.
333     return false;
334   }
335   const char* option = find_any_unsupported_module_option();
336   if (option != nullptr) {
337     if (RequireSharedSpaces) {
338       warning("CDS is disabled when the %s option is specified.", option);
339     } else {
340       log_info(cds)("CDS is disabled when the %s option is specified.", option);
341     }
342     return true;
343   }
344 
345   if (module_patching_disables_cds()) {
346     if (RequireSharedSpaces) {
347       warning("CDS is disabled when the %s option is specified.", "--patch-module");
348     } else {
349       log_info(cds)("CDS is disabled when the %s option is specified.", "--patch-module");
350     }
351     return true;
352   }
353 
354   return false;
355 }
356 
357 bool CDSConfig::check_vm_args_consistency(bool mode_flag_cmd_line) {
358   if (is_dumping_static_archive()) {
359     if (!mode_flag_cmd_line) {
360       // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
361       //
362       // If your classlist is large and you don't care about deterministic dumping, you can use
363       // -Xshare:dump -Xmixed to improve dumping speed.
364       Arguments::set_mode_flags(Arguments::_int);
365     } else if (Arguments::mode() == Arguments::_comp) {
366       // -Xcomp may use excessive CPU for the test tiers. Also, -Xshare:dump runs a small and fixed set of
367       // Java code, so there's not much benefit in running -Xcomp.
368       log_info(cds)("reduced -Xcomp to -Xmixed for static dumping");
369       Arguments::set_mode_flags(Arguments::_mixed);
370     }
371 
372     // String deduplication may cause CDS to iterate the strings in different order from one
373     // run to another which resulting in non-determinstic CDS archives.
374     // Disable UseStringDeduplication while dumping CDS archive.
375     UseStringDeduplication = false;
376   }
377 

382     return false;
383   }
384 
385   if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
386     disable_dumping_dynamic_archive();
387   } else {
388     enable_dumping_dynamic_archive();
389   }
390 
391   if (AutoCreateSharedArchive) {
392     if (SharedArchiveFile == nullptr) {
393       log_warning(cds)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
394       return false;
395     }
396     if (ArchiveClassesAtExit != nullptr) {
397       log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
398       return false;
399     }
400   }
401 
402   if (is_using_archive() && java_base_module_patching_disables_cds() && module_patching_disables_cds()) {
403     Arguments::no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
404   }
405   if (is_using_archive() && has_unsupported_runtime_module_options()) {
406     UseSharedSpaces = false;
407   }
408 
409   if (is_dumping_archive()) {
410     // Always verify non-system classes during CDS dump
411     if (!BytecodeVerificationRemote) {
412       BytecodeVerificationRemote = true;
413       log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
414     }
415   }
416 
417   return true;
418 }
419 
420 bool CDSConfig::is_using_archive() {
421   return UseSharedSpaces;
422 }
423 
424 bool CDSConfig::is_logging_lambda_form_invokers() {
425   return ClassListWriter::is_enabled() || is_dumping_dynamic_archive();
426 }
427 
428 void CDSConfig::stop_using_optimized_module_handling() {
429   _is_using_optimized_module_handling = false;
430   _is_dumping_full_module_graph = false; // This requires is_using_optimized_module_handling()
431   _is_using_full_module_graph = false; // This requires is_using_optimized_module_handling()
432 }
433 
434 #if INCLUDE_CDS_JAVA_HEAP
435 bool CDSConfig::is_dumping_heap() {
436   if (is_valhalla_preview()) {
437     // Not working yet -- e.g., HeapShared::oop_hash() needs to be implemented for value oops
438     return false;
439   }
440   // heap dump is not supported in dynamic dump
441   return is_dumping_static_archive() && HeapShared::can_write();
442 }
443 
444 bool CDSConfig::is_using_full_module_graph() {
445   if (ClassLoaderDataShared::is_full_module_graph_loaded()) {
446     return true;
447   }
448 
449   if (!_is_using_full_module_graph) {
450     return false;
451   }
452 
453   if (is_using_archive() && ArchiveHeapLoader::can_use()) {
454     // Classes used by the archived full module graph are loaded in JVMTI early phase.
455     assert(!(JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()),
456            "CDS should be disabled if early class hooks are enabled");
457     return true;
458   } else {
459     _is_using_full_module_graph = false;
< prev index next >