59 #include "runtime/os.hpp"
60 #include "runtime/safepoint.hpp"
61 #include "runtime/safepointMechanism.hpp"
62 #include "runtime/synchronizer.hpp"
63 #include "runtime/vm_version.hpp"
64 #include "services/management.hpp"
65 #include "utilities/align.hpp"
66 #include "utilities/checkedCast.hpp"
67 #include "utilities/debug.hpp"
68 #include "utilities/defaultStream.hpp"
69 #include "utilities/macros.hpp"
70 #include "utilities/parseInteger.hpp"
71 #include "utilities/powerOfTwo.hpp"
72 #include "utilities/stringUtils.hpp"
73 #include "utilities/systemMemoryBarrier.hpp"
74 #if INCLUDE_JFR
75 #include "jfr/jfr.hpp"
76 #endif
77
78 #include <limits>
79
80 static const char _default_java_launcher[] = "generic";
81
82 #define DEFAULT_JAVA_LAUNCHER _default_java_launcher
83
84 char* Arguments::_jvm_flags_file = nullptr;
85 char** Arguments::_jvm_flags_array = nullptr;
86 int Arguments::_num_jvm_flags = 0;
87 char** Arguments::_jvm_args_array = nullptr;
88 int Arguments::_num_jvm_args = 0;
89 unsigned int Arguments::_addmods_count = 0;
90 #if INCLUDE_JVMCI
91 bool Arguments::_jvmci_module_added = false;
92 #endif
93 char* Arguments::_java_command = nullptr;
94 SystemProperty* Arguments::_system_properties = nullptr;
95 size_t Arguments::_conservative_max_heap_alignment = 0;
96 Arguments::Mode Arguments::_mode = _mixed;
97 const char* Arguments::_java_vendor_url_bug = nullptr;
98 const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
346 matches_property_suffix(property_suffix, UPGRADE_PATH, UPGRADE_PATH_LEN) ||
347 matches_property_suffix(property_suffix, ILLEGAL_NATIVE_ACCESS, ILLEGAL_NATIVE_ACCESS_LEN)) {
348 return true;
349 }
350
351 if (!check_for_cds) {
352 // CDS notes: these properties are supported by CDS archived full module graph.
353 if (matches_property_suffix(property_suffix, ADDEXPORTS, ADDEXPORTS_LEN) ||
354 matches_property_suffix(property_suffix, ADDOPENS, ADDOPENS_LEN) ||
355 matches_property_suffix(property_suffix, ADDREADS, ADDREADS_LEN) ||
356 matches_property_suffix(property_suffix, PATH, PATH_LEN) ||
357 matches_property_suffix(property_suffix, ADDMODS, ADDMODS_LEN) ||
358 matches_property_suffix(property_suffix, ENABLE_NATIVE_ACCESS, ENABLE_NATIVE_ACCESS_LEN)) {
359 return true;
360 }
361 }
362 }
363 return false;
364 }
365
366 // Process java launcher properties.
367 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
368 // See if sun.java.launcher is defined.
369 // Must do this before setting up other system properties,
370 // as some of them may depend on launcher type.
371 for (int index = 0; index < args->nOptions; index++) {
372 const JavaVMOption* option = args->options + index;
373 const char* tail;
374
375 if (match_option(option, "-Dsun.java.launcher=", &tail)) {
376 process_java_launcher_argument(tail, option->extraInfo);
377 continue;
378 }
379 if (match_option(option, "-XX:+ExecutingUnitTests")) {
380 _executing_unit_tests = true;
381 continue;
382 }
383 }
384 }
385
1788 os::free(const_cast<char*>(_sun_java_launcher));
1789 }
1790 _sun_java_launcher = os::strdup_check_oom(launcher);
1791 }
1792
1793 bool Arguments::created_by_java_launcher() {
1794 assert(_sun_java_launcher != nullptr, "property must have value");
1795 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1796 }
1797
1798 bool Arguments::executing_unit_tests() {
1799 return _executing_unit_tests;
1800 }
1801
1802 //===========================================================================================================
1803 // Parsing of main arguments
1804
1805 static unsigned int addreads_count = 0;
1806 static unsigned int addexports_count = 0;
1807 static unsigned int addopens_count = 0;
1808 static unsigned int patch_mod_count = 0;
1809 static unsigned int enable_native_access_count = 0;
1810 static bool patch_mod_javabase = false;
1811
1812 // Check the consistency of vm_init_args
1813 bool Arguments::check_vm_args_consistency() {
1814 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1815 if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) {
1816 return false;
1817 }
1818
1819 // Method for adding checks for flag consistency.
1820 // The intent is to warn the user of all possible conflicts,
1821 // before returning an error.
1822 // Note: Needs platform-dependent factoring.
1823 bool status = true;
1824
1825 if (TLABRefillWasteFraction == 0) {
1826 jio_fprintf(defaultStream::error_stream(),
1827 "TLABRefillWasteFraction should be a denominator, "
1828 "not %zu\n",
1829 TLABRefillWasteFraction);
1830 status = false;
1831 }
1832
1833 status = CompilerConfig::check_args_consistency(status);
1834 #if INCLUDE_JVMCI
1835 if (status && EnableJVMCI) {
1962
1963 // Remember the default value of SharedBaseAddress.
1964 Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1965
1966 // Setup flags for mixed which is the default
1967 set_mode_flags(_mixed);
1968
1969 jint result;
1970 for (int i = 0; i < all_args->length(); i++) {
1971 result = parse_each_vm_init_arg(all_args->at(i)._args, all_args->at(i)._origin);
1972 if (result != JNI_OK) {
1973 return result;
1974 }
1975 }
1976
1977 // Disable CDS for exploded image
1978 if (!has_jimage()) {
1979 no_shared_spaces("CDS disabled on exploded JDK");
1980 }
1981
1982 // We need to ensure processor and memory resources have been properly
1983 // configured - which may rely on arguments we just processed - before
1984 // doing the final argument processing. Any argument processing that
1985 // needs to know about processor and memory resources must occur after
1986 // this point.
1987
1988 os::init_container_support();
1989
1990 SystemMemoryBarrier::initialize();
1991
1992 // Do final processing now that all arguments have been parsed
1993 result = finalize_vm_init_args();
1994 if (result != JNI_OK) {
1995 return result;
1996 }
1997
1998 return JNI_OK;
1999 }
2000
2001 #if !INCLUDE_JVMTI || INCLUDE_CDS
2044 return false;
2045 }
2046 #endif
2047
2048 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2049 // --patch-module=<module>=<file>(<pathsep><file>)*
2050 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2051 // Find the equal sign between the module name and the path specification
2052 const char* module_equal = strchr(patch_mod_tail, '=');
2053 if (module_equal == nullptr) {
2054 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2055 return JNI_ERR;
2056 } else {
2057 // Pick out the module name
2058 size_t module_len = module_equal - patch_mod_tail;
2059 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2060 if (module_name != nullptr) {
2061 memcpy(module_name, patch_mod_tail, module_len);
2062 *(module_name + module_len) = '\0';
2063 // The path piece begins one past the module_equal sign
2064 add_patch_mod_prefix(module_name, module_equal + 1);
2065 FREE_C_HEAP_ARRAY(char, module_name);
2066 if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
2067 return JNI_ENOMEM;
2068 }
2069 } else {
2070 return JNI_ENOMEM;
2071 }
2072 }
2073 return JNI_OK;
2074 }
2075
2076 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2077 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2078 // The min and max sizes match the values in globals.hpp, but scaled
2079 // with K. The values have been chosen so that alignment with page
2080 // size doesn't change the max value, which makes the conversions
2081 // back and forth between Xss value and ThreadStackSize value easier.
2082 // The values have also been chosen to fit inside a 32-bit signed type.
2083 const julong min_ThreadStackSize = 0;
2084 const julong max_ThreadStackSize = 1 * M;
2085
2086 // Make sure the above values match the range set in globals.hpp
2087 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2088 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2089 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2090
2091 const julong min_size = min_ThreadStackSize * K;
2092 const julong max_size = max_ThreadStackSize * K;
2093
2094 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2095
2324 jio_fprintf(defaultStream::error_stream(),
2325 "Instrumentation agents are not supported in this VM\n");
2326 return JNI_ERR;
2327 #else
2328 if (tail != nullptr) {
2329 size_t length = strlen(tail) + 1;
2330 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2331 jio_snprintf(options, length, "%s", tail);
2332 JvmtiAgentList::add("instrument", options, false);
2333 FREE_C_HEAP_ARRAY(char, options);
2334
2335 // java agents need module java.instrument
2336 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2337 return JNI_ENOMEM;
2338 }
2339 }
2340 #endif // !INCLUDE_JVMTI
2341 // --enable_preview
2342 } else if (match_option(option, "--enable-preview")) {
2343 set_enable_preview();
2344 // -Xnoclassgc
2345 } else if (match_option(option, "-Xnoclassgc")) {
2346 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2347 return JNI_EINVAL;
2348 }
2349 // -Xbatch
2350 } else if (match_option(option, "-Xbatch")) {
2351 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2352 return JNI_EINVAL;
2353 }
2354 // -Xmn for compatibility with other JVM vendors
2355 } else if (match_option(option, "-Xmn", &tail)) {
2356 julong long_initial_young_size = 0;
2357 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2358 if (errcode != arg_in_range) {
2359 jio_fprintf(defaultStream::error_stream(),
2360 "Invalid initial young generation size: %s\n", option->optionString);
2361 describe_range_error(errcode);
2362 return JNI_EINVAL;
2363 }
2827 // Unknown option
2828 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2829 return JNI_ERR;
2830 }
2831 }
2832
2833 // PrintSharedArchiveAndExit will turn on
2834 // -Xshare:on
2835 // -Xlog:class+path=info
2836 if (PrintSharedArchiveAndExit) {
2837 UseSharedSpaces = true;
2838 RequireSharedSpaces = true;
2839 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2840 }
2841
2842 fix_appclasspath();
2843
2844 return JNI_OK;
2845 }
2846
2847 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path) {
2848 // For java.base check for duplicate --patch-module options being specified on the command line.
2849 // This check is only required for java.base, all other duplicate module specifications
2850 // will be checked during module system initialization. The module system initialization
2851 // will throw an ExceptionInInitializerError if this situation occurs.
2852 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2853 if (patch_mod_javabase) {
2854 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2855 } else {
2856 patch_mod_javabase = true;
2857 }
2858 }
2859
2860 // Create GrowableArray lazily, only if --patch-module has been specified
2861 if (_patch_mod_prefix == nullptr) {
2862 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2863 }
2864
2865 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2866 }
2867
2868 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2869 //
2870 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2871 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2872 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2873 // path is treated as the current directory.
2874 //
2875 // This causes problems with CDS, which requires that all directories specified in the classpath
2876 // must be empty. In most cases, applications do NOT want to load classes from the current
2877 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2878 // scripts compatible with CDS.
2879 void Arguments::fix_appclasspath() {
2880 if (IgnoreEmptyClassPaths) {
2881 const char separator = *os::path_separator();
2882 const char* src = _java_class_path->value();
2883
2884 // skip over all the leading empty paths
2885 while (*src == separator) {
2958 }
2959
2960 #if !COMPILER2_OR_JVMCI
2961 // Don't degrade server performance for footprint
2962 if (FLAG_IS_DEFAULT(UseLargePages) &&
2963 MaxHeapSize < LargePageHeapSizeThreshold) {
2964 // No need for large granularity pages w/small heaps.
2965 // Note that large pages are enabled/disabled for both the
2966 // Java heap and the code cache.
2967 FLAG_SET_DEFAULT(UseLargePages, false);
2968 }
2969
2970 UNSUPPORTED_OPTION(ProfileInterpreter);
2971 #endif
2972
2973 // Parse the CompilationMode flag
2974 if (!CompilationModeFlag::initialize()) {
2975 return JNI_ERR;
2976 }
2977
2978 if (!check_vm_args_consistency()) {
2979 return JNI_ERR;
2980 }
2981
2982
2983 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
2984 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
2985 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2986
2987 return JNI_OK;
2988 }
2989
2990 // Helper class for controlling the lifetime of JavaVMInitArgs
2991 // objects. The contents of the JavaVMInitArgs are guaranteed to be
2992 // deleted on the destruction of the ScopedVMInitArgs object.
2993 class ScopedVMInitArgs : public StackObj {
2994 private:
2995 JavaVMInitArgs _args;
2996 char* _container_name;
2997 bool _is_set;
2998 char* _vm_options_file_arg;
2999
3000 public:
3001 ScopedVMInitArgs(const char *container_name) {
3847 #ifdef ZERO
3848 // Clear flags not supported on zero.
3849 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3850 #endif // ZERO
3851
3852 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3853 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3854 DebugNonSafepoints = true;
3855 }
3856
3857 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3858 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3859 }
3860
3861 // Treat the odd case where local verification is enabled but remote
3862 // verification is not as if both were enabled.
3863 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3864 log_info(verification)("Turning on remote verification because local verification is on");
3865 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3866 }
3867
3868 #ifndef PRODUCT
3869 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3870 if (use_vm_log()) {
3871 LogVMOutput = true;
3872 }
3873 }
3874 #endif // PRODUCT
3875
3876 if (PrintCommandLineFlags) {
3877 JVMFlag::printSetFlags(tty);
3878 }
3879
3880 #if COMPILER2_OR_JVMCI
3881 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3882 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3883 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3884 }
3885 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3886
|
59 #include "runtime/os.hpp"
60 #include "runtime/safepoint.hpp"
61 #include "runtime/safepointMechanism.hpp"
62 #include "runtime/synchronizer.hpp"
63 #include "runtime/vm_version.hpp"
64 #include "services/management.hpp"
65 #include "utilities/align.hpp"
66 #include "utilities/checkedCast.hpp"
67 #include "utilities/debug.hpp"
68 #include "utilities/defaultStream.hpp"
69 #include "utilities/macros.hpp"
70 #include "utilities/parseInteger.hpp"
71 #include "utilities/powerOfTwo.hpp"
72 #include "utilities/stringUtils.hpp"
73 #include "utilities/systemMemoryBarrier.hpp"
74 #if INCLUDE_JFR
75 #include "jfr/jfr.hpp"
76 #endif
77
78 #include <limits>
79 #include <string.h>
80
81 static const char _default_java_launcher[] = "generic";
82
83 #define DEFAULT_JAVA_LAUNCHER _default_java_launcher
84
85 char* Arguments::_jvm_flags_file = nullptr;
86 char** Arguments::_jvm_flags_array = nullptr;
87 int Arguments::_num_jvm_flags = 0;
88 char** Arguments::_jvm_args_array = nullptr;
89 int Arguments::_num_jvm_args = 0;
90 unsigned int Arguments::_addmods_count = 0;
91 #if INCLUDE_JVMCI
92 bool Arguments::_jvmci_module_added = false;
93 #endif
94 char* Arguments::_java_command = nullptr;
95 SystemProperty* Arguments::_system_properties = nullptr;
96 size_t Arguments::_conservative_max_heap_alignment = 0;
97 Arguments::Mode Arguments::_mode = _mixed;
98 const char* Arguments::_java_vendor_url_bug = nullptr;
99 const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
347 matches_property_suffix(property_suffix, UPGRADE_PATH, UPGRADE_PATH_LEN) ||
348 matches_property_suffix(property_suffix, ILLEGAL_NATIVE_ACCESS, ILLEGAL_NATIVE_ACCESS_LEN)) {
349 return true;
350 }
351
352 if (!check_for_cds) {
353 // CDS notes: these properties are supported by CDS archived full module graph.
354 if (matches_property_suffix(property_suffix, ADDEXPORTS, ADDEXPORTS_LEN) ||
355 matches_property_suffix(property_suffix, ADDOPENS, ADDOPENS_LEN) ||
356 matches_property_suffix(property_suffix, ADDREADS, ADDREADS_LEN) ||
357 matches_property_suffix(property_suffix, PATH, PATH_LEN) ||
358 matches_property_suffix(property_suffix, ADDMODS, ADDMODS_LEN) ||
359 matches_property_suffix(property_suffix, ENABLE_NATIVE_ACCESS, ENABLE_NATIVE_ACCESS_LEN)) {
360 return true;
361 }
362 }
363 }
364 return false;
365 }
366
367 bool Arguments::patching_migrated_classes(const char* property, const char* value) {
368 if (strncmp(property, MODULE_PROPERTY_PREFIX, MODULE_PROPERTY_PREFIX_LEN) == 0) {
369 const char* property_suffix = property + MODULE_PROPERTY_PREFIX_LEN;
370 if (matches_property_suffix(property_suffix, PATCH, PATCH_LEN)) {
371 if (strcmp(value, "java.base-valueclasses.jar")) {
372 return true;
373 }
374 }
375 }
376 return false;
377 }
378
379 // Process java launcher properties.
380 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
381 // See if sun.java.launcher is defined.
382 // Must do this before setting up other system properties,
383 // as some of them may depend on launcher type.
384 for (int index = 0; index < args->nOptions; index++) {
385 const JavaVMOption* option = args->options + index;
386 const char* tail;
387
388 if (match_option(option, "-Dsun.java.launcher=", &tail)) {
389 process_java_launcher_argument(tail, option->extraInfo);
390 continue;
391 }
392 if (match_option(option, "-XX:+ExecutingUnitTests")) {
393 _executing_unit_tests = true;
394 continue;
395 }
396 }
397 }
398
1801 os::free(const_cast<char*>(_sun_java_launcher));
1802 }
1803 _sun_java_launcher = os::strdup_check_oom(launcher);
1804 }
1805
1806 bool Arguments::created_by_java_launcher() {
1807 assert(_sun_java_launcher != nullptr, "property must have value");
1808 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1809 }
1810
1811 bool Arguments::executing_unit_tests() {
1812 return _executing_unit_tests;
1813 }
1814
1815 //===========================================================================================================
1816 // Parsing of main arguments
1817
1818 static unsigned int addreads_count = 0;
1819 static unsigned int addexports_count = 0;
1820 static unsigned int addopens_count = 0;
1821 static unsigned int enable_native_access_count = 0;
1822 static bool patch_mod_javabase = false;
1823
1824 // Check the consistency of vm_init_args
1825 bool Arguments::check_vm_args_consistency() {
1826 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1827 if (!CDSConfig::check_vm_args_consistency(mode_flag_cmd_line)) {
1828 return false;
1829 }
1830
1831 // Method for adding checks for flag consistency.
1832 // The intent is to warn the user of all possible conflicts,
1833 // before returning an error.
1834 // Note: Needs platform-dependent factoring.
1835 bool status = true;
1836
1837 if (TLABRefillWasteFraction == 0) {
1838 jio_fprintf(defaultStream::error_stream(),
1839 "TLABRefillWasteFraction should be a denominator, "
1840 "not %zu\n",
1841 TLABRefillWasteFraction);
1842 status = false;
1843 }
1844
1845 status = CompilerConfig::check_args_consistency(status);
1846 #if INCLUDE_JVMCI
1847 if (status && EnableJVMCI) {
1974
1975 // Remember the default value of SharedBaseAddress.
1976 Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1977
1978 // Setup flags for mixed which is the default
1979 set_mode_flags(_mixed);
1980
1981 jint result;
1982 for (int i = 0; i < all_args->length(); i++) {
1983 result = parse_each_vm_init_arg(all_args->at(i)._args, all_args->at(i)._origin);
1984 if (result != JNI_OK) {
1985 return result;
1986 }
1987 }
1988
1989 // Disable CDS for exploded image
1990 if (!has_jimage()) {
1991 no_shared_spaces("CDS disabled on exploded JDK");
1992 }
1993
1994 if (UseAltSubstitutabilityMethod) {
1995 no_shared_spaces("Alternate substitutability method doesn't work with CDS yet");
1996 }
1997
1998 // We need to ensure processor and memory resources have been properly
1999 // configured - which may rely on arguments we just processed - before
2000 // doing the final argument processing. Any argument processing that
2001 // needs to know about processor and memory resources must occur after
2002 // this point.
2003
2004 os::init_container_support();
2005
2006 SystemMemoryBarrier::initialize();
2007
2008 // Do final processing now that all arguments have been parsed
2009 result = finalize_vm_init_args();
2010 if (result != JNI_OK) {
2011 return result;
2012 }
2013
2014 return JNI_OK;
2015 }
2016
2017 #if !INCLUDE_JVMTI || INCLUDE_CDS
2060 return false;
2061 }
2062 #endif
2063
2064 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2065 // --patch-module=<module>=<file>(<pathsep><file>)*
2066 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2067 // Find the equal sign between the module name and the path specification
2068 const char* module_equal = strchr(patch_mod_tail, '=');
2069 if (module_equal == nullptr) {
2070 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2071 return JNI_ERR;
2072 } else {
2073 // Pick out the module name
2074 size_t module_len = module_equal - patch_mod_tail;
2075 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2076 if (module_name != nullptr) {
2077 memcpy(module_name, patch_mod_tail, module_len);
2078 *(module_name + module_len) = '\0';
2079 // The path piece begins one past the module_equal sign
2080 add_patch_mod_prefix(module_name, module_equal + 1, false /* no append */, false /* no cds */);
2081 FREE_C_HEAP_ARRAY(char, module_name);
2082 } else {
2083 return JNI_ENOMEM;
2084 }
2085 }
2086 return JNI_OK;
2087 }
2088
2089 // Temporary system property to disable preview patching and enable the new preview mode
2090 // feature for testing/development. Once the preview mode feature is finished, the value
2091 // will be always 'true' and this code, and all related dead-code can be removed.
2092 #define DISABLE_PREVIEW_PATCHING_DEFAULT false
2093
2094 bool Arguments::disable_preview_patching() {
2095 const char* prop = get_property("DISABLE_PREVIEW_PATCHING");
2096 return (prop != nullptr)
2097 ? strncmp(prop, "true", strlen("true")) == 0
2098 : DISABLE_PREVIEW_PATCHING_DEFAULT;
2099 }
2100
2101 // VALUECLASS_STR must match string used in the build
2102 #define VALUECLASS_STR "valueclasses"
2103 #define VALUECLASS_JAR "-" VALUECLASS_STR ".jar"
2104
2105 // Finalize --patch-module args and --enable-preview related to value class module patches.
2106 // Create all numbered properties passing module patches.
2107 int Arguments::finalize_patch_module() {
2108 // If --enable-preview and EnableValhalla is true, modules may have preview mode resources.
2109 bool enable_valhalla_preview = enable_preview() && EnableValhalla;
2110 // Whether to use module patching, or the new preview mode feature for preview resources.
2111 bool disable_patching = disable_preview_patching();
2112
2113 // This must be called, even with 'false', to enable resource lookup from JImage.
2114 ClassLoader::init_jimage(disable_patching && enable_valhalla_preview);
2115
2116 // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2117 // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2118 if (!disable_patching && enable_valhalla_preview) {
2119 char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2120 const char * fileSep = os::file_separator();
2121
2122 jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s",
2123 Arguments::get_java_home(), fileSep, fileSep, fileSep);
2124 DIR* dir = os::opendir(valueclasses_dir);
2125 if (dir != nullptr) {
2126 char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2127 char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2128
2129 for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) {
2130 // Test if file ends-with "-valueclasses.jar"
2131 int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1);
2132 if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) {
2133 continue; // too short or not the expected suffix
2134 }
2135
2136 strcpy(module_name, entry->d_name);
2137 module_name[len] = '\0'; // truncate to just module-name
2138
2139 jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name);
2140 add_patch_mod_prefix(module_name, path, true /* append */, true /* cds OK*/);
2141 log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name);
2142 }
2143 FreeHeap(module_name);
2144 FreeHeap(path);
2145 os::closedir(dir);
2146 }
2147 FreeHeap(valueclasses_dir);
2148 }
2149
2150 // Create numbered properties for each module that has been patched either
2151 // by --patch-module (or --enable-preview if disable_patching is false).
2152 // Format is "jdk.module.patch.<n>=<module_name>=<path>"
2153 if (_patch_mod_prefix != nullptr) {
2154 char * prop_value = AllocateHeap(JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, mtArguments);
2155 unsigned int patch_mod_count = 0;
2156
2157 for (GrowableArrayIterator<ModulePatchPath *> it = _patch_mod_prefix->begin();
2158 it != _patch_mod_prefix->end(); ++it) {
2159 jio_snprintf(prop_value, JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, "%s=%s",
2160 (*it)->module_name(), (*it)->path_string());
2161 if (!create_numbered_module_property("jdk.module.patch", prop_value, patch_mod_count++)) {
2162 FreeHeap(prop_value);
2163 return JNI_ENOMEM;
2164 }
2165 }
2166 FreeHeap(prop_value);
2167 }
2168 return JNI_OK;
2169 }
2170
2171 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2172 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2173 // The min and max sizes match the values in globals.hpp, but scaled
2174 // with K. The values have been chosen so that alignment with page
2175 // size doesn't change the max value, which makes the conversions
2176 // back and forth between Xss value and ThreadStackSize value easier.
2177 // The values have also been chosen to fit inside a 32-bit signed type.
2178 const julong min_ThreadStackSize = 0;
2179 const julong max_ThreadStackSize = 1 * M;
2180
2181 // Make sure the above values match the range set in globals.hpp
2182 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2183 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2184 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2185
2186 const julong min_size = min_ThreadStackSize * K;
2187 const julong max_size = max_ThreadStackSize * K;
2188
2189 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2190
2419 jio_fprintf(defaultStream::error_stream(),
2420 "Instrumentation agents are not supported in this VM\n");
2421 return JNI_ERR;
2422 #else
2423 if (tail != nullptr) {
2424 size_t length = strlen(tail) + 1;
2425 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2426 jio_snprintf(options, length, "%s", tail);
2427 JvmtiAgentList::add("instrument", options, false);
2428 FREE_C_HEAP_ARRAY(char, options);
2429
2430 // java agents need module java.instrument
2431 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2432 return JNI_ENOMEM;
2433 }
2434 }
2435 #endif // !INCLUDE_JVMTI
2436 // --enable_preview
2437 } else if (match_option(option, "--enable-preview")) {
2438 set_enable_preview();
2439 // --enable-preview enables Valhalla, EnableValhalla VM option will eventually be removed before integration
2440 if (FLAG_SET_CMDLINE(EnableValhalla, true) != JVMFlag::SUCCESS) {
2441 return JNI_EINVAL;
2442 }
2443 // -Xnoclassgc
2444 } else if (match_option(option, "-Xnoclassgc")) {
2445 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2446 return JNI_EINVAL;
2447 }
2448 // -Xbatch
2449 } else if (match_option(option, "-Xbatch")) {
2450 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2451 return JNI_EINVAL;
2452 }
2453 // -Xmn for compatibility with other JVM vendors
2454 } else if (match_option(option, "-Xmn", &tail)) {
2455 julong long_initial_young_size = 0;
2456 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2457 if (errcode != arg_in_range) {
2458 jio_fprintf(defaultStream::error_stream(),
2459 "Invalid initial young generation size: %s\n", option->optionString);
2460 describe_range_error(errcode);
2461 return JNI_EINVAL;
2462 }
2926 // Unknown option
2927 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2928 return JNI_ERR;
2929 }
2930 }
2931
2932 // PrintSharedArchiveAndExit will turn on
2933 // -Xshare:on
2934 // -Xlog:class+path=info
2935 if (PrintSharedArchiveAndExit) {
2936 UseSharedSpaces = true;
2937 RequireSharedSpaces = true;
2938 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2939 }
2940
2941 fix_appclasspath();
2942
2943 return JNI_OK;
2944 }
2945
2946 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) {
2947 if (!allow_cds) {
2948 CDSConfig::set_module_patching_disables_cds();
2949 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2950 CDSConfig::set_java_base_module_patching_disables_cds();
2951 }
2952 }
2953
2954 // Create GrowableArray lazily, only if --patch-module has been specified
2955 if (_patch_mod_prefix == nullptr) {
2956 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2957 }
2958
2959 // Scan patches for matching module
2960 int i = _patch_mod_prefix->find_if([&](ModulePatchPath* patch) {
2961 return (strcmp(module_name, patch->module_name()) == 0);
2962 });
2963 if (i == -1) {
2964 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2965 } else {
2966 if (allow_append) {
2967 // append path to existing module entry
2968 _patch_mod_prefix->at(i)->append_path(path);
2969 } else {
2970 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2971 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2972 } else {
2973 vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
2974 }
2975 }
2976 }
2977 }
2978
2979 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2980 //
2981 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2982 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2983 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2984 // path is treated as the current directory.
2985 //
2986 // This causes problems with CDS, which requires that all directories specified in the classpath
2987 // must be empty. In most cases, applications do NOT want to load classes from the current
2988 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2989 // scripts compatible with CDS.
2990 void Arguments::fix_appclasspath() {
2991 if (IgnoreEmptyClassPaths) {
2992 const char separator = *os::path_separator();
2993 const char* src = _java_class_path->value();
2994
2995 // skip over all the leading empty paths
2996 while (*src == separator) {
3069 }
3070
3071 #if !COMPILER2_OR_JVMCI
3072 // Don't degrade server performance for footprint
3073 if (FLAG_IS_DEFAULT(UseLargePages) &&
3074 MaxHeapSize < LargePageHeapSizeThreshold) {
3075 // No need for large granularity pages w/small heaps.
3076 // Note that large pages are enabled/disabled for both the
3077 // Java heap and the code cache.
3078 FLAG_SET_DEFAULT(UseLargePages, false);
3079 }
3080
3081 UNSUPPORTED_OPTION(ProfileInterpreter);
3082 #endif
3083
3084 // Parse the CompilationMode flag
3085 if (!CompilationModeFlag::initialize()) {
3086 return JNI_ERR;
3087 }
3088
3089 // finalize --module-patch and related --enable-preview
3090 if (finalize_patch_module() != JNI_OK) {
3091 return JNI_ERR;
3092 }
3093
3094 if (!check_vm_args_consistency()) {
3095 return JNI_ERR;
3096 }
3097
3098 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3099 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3100 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3101
3102 return JNI_OK;
3103 }
3104
3105 // Helper class for controlling the lifetime of JavaVMInitArgs
3106 // objects. The contents of the JavaVMInitArgs are guaranteed to be
3107 // deleted on the destruction of the ScopedVMInitArgs object.
3108 class ScopedVMInitArgs : public StackObj {
3109 private:
3110 JavaVMInitArgs _args;
3111 char* _container_name;
3112 bool _is_set;
3113 char* _vm_options_file_arg;
3114
3115 public:
3116 ScopedVMInitArgs(const char *container_name) {
3962 #ifdef ZERO
3963 // Clear flags not supported on zero.
3964 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3965 #endif // ZERO
3966
3967 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3968 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3969 DebugNonSafepoints = true;
3970 }
3971
3972 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3973 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3974 }
3975
3976 // Treat the odd case where local verification is enabled but remote
3977 // verification is not as if both were enabled.
3978 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3979 log_info(verification)("Turning on remote verification because local verification is on");
3980 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3981 }
3982 if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) {
3983 // Disable calling convention optimizations if inline types are not supported.
3984 // Also these aren't useful in -Xint. However, don't disable them when dumping or using
3985 // the CDS archive, as the values must match between dumptime and runtime.
3986 FLAG_SET_DEFAULT(InlineTypePassFieldsAsArgs, false);
3987 FLAG_SET_DEFAULT(InlineTypeReturnedAsFields, false);
3988 }
3989 if (!UseNonAtomicValueFlattening && !UseNullableValueFlattening && !UseAtomicValueFlattening) {
3990 // Flattening is disabled
3991 FLAG_SET_DEFAULT(UseArrayFlattening, false);
3992 FLAG_SET_DEFAULT(UseFieldFlattening, false);
3993 }
3994
3995 #ifndef PRODUCT
3996 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3997 if (use_vm_log()) {
3998 LogVMOutput = true;
3999 }
4000 }
4001 #endif // PRODUCT
4002
4003 if (PrintCommandLineFlags) {
4004 JVMFlag::printSetFlags(tty);
4005 }
4006
4007 #if COMPILER2_OR_JVMCI
4008 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
4009 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
4010 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
4011 }
4012 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
4013
|