58 #include "runtime/os.hpp"
59 #include "runtime/safepoint.hpp"
60 #include "runtime/safepointMechanism.hpp"
61 #include "runtime/synchronizer.hpp"
62 #include "runtime/vm_version.hpp"
63 #include "services/management.hpp"
64 #include "utilities/align.hpp"
65 #include "utilities/checkedCast.hpp"
66 #include "utilities/debug.hpp"
67 #include "utilities/defaultStream.hpp"
68 #include "utilities/macros.hpp"
69 #include "utilities/parseInteger.hpp"
70 #include "utilities/powerOfTwo.hpp"
71 #include "utilities/stringUtils.hpp"
72 #include "utilities/systemMemoryBarrier.hpp"
73 #if INCLUDE_JFR
74 #include "jfr/jfr.hpp"
75 #endif
76
77 #include <limits>
78
79 static const char _default_java_launcher[] = "generic";
80
81 #define DEFAULT_JAVA_LAUNCHER _default_java_launcher
82
83 char* Arguments::_jvm_flags_file = nullptr;
84 char** Arguments::_jvm_flags_array = nullptr;
85 int Arguments::_num_jvm_flags = 0;
86 char** Arguments::_jvm_args_array = nullptr;
87 int Arguments::_num_jvm_args = 0;
88 unsigned int Arguments::_addmods_count = 0;
89 #if INCLUDE_JVMCI
90 bool Arguments::_jvmci_module_added = false;
91 #endif
92 char* Arguments::_java_command = nullptr;
93 SystemProperty* Arguments::_system_properties = nullptr;
94 size_t Arguments::_conservative_max_heap_alignment = 0;
95 Arguments::Mode Arguments::_mode = _mixed;
96 const char* Arguments::_java_vendor_url_bug = nullptr;
97 const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
345 matches_property_suffix(property_suffix, UPGRADE_PATH, UPGRADE_PATH_LEN) ||
346 matches_property_suffix(property_suffix, ILLEGAL_NATIVE_ACCESS, ILLEGAL_NATIVE_ACCESS_LEN)) {
347 return true;
348 }
349
350 if (!check_for_cds) {
351 // CDS notes: these properties are supported by CDS archived full module graph.
352 if (matches_property_suffix(property_suffix, ADDEXPORTS, ADDEXPORTS_LEN) ||
353 matches_property_suffix(property_suffix, ADDOPENS, ADDOPENS_LEN) ||
354 matches_property_suffix(property_suffix, ADDREADS, ADDREADS_LEN) ||
355 matches_property_suffix(property_suffix, PATH, PATH_LEN) ||
356 matches_property_suffix(property_suffix, ADDMODS, ADDMODS_LEN) ||
357 matches_property_suffix(property_suffix, ENABLE_NATIVE_ACCESS, ENABLE_NATIVE_ACCESS_LEN)) {
358 return true;
359 }
360 }
361 }
362 return false;
363 }
364
365 // Process java launcher properties.
366 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
367 // See if sun.java.launcher is defined.
368 // Must do this before setting up other system properties,
369 // as some of them may depend on launcher type.
370 for (int index = 0; index < args->nOptions; index++) {
371 const JavaVMOption* option = args->options + index;
372 const char* tail;
373
374 if (match_option(option, "-Dsun.java.launcher=", &tail)) {
375 process_java_launcher_argument(tail, option->extraInfo);
376 continue;
377 }
378 if (match_option(option, "-XX:+ExecutingUnitTests")) {
379 _executing_unit_tests = true;
380 continue;
381 }
382 }
383 }
384
1784 os::free(const_cast<char*>(_sun_java_launcher));
1785 }
1786 _sun_java_launcher = os::strdup_check_oom(launcher);
1787 }
1788
1789 bool Arguments::created_by_java_launcher() {
1790 assert(_sun_java_launcher != nullptr, "property must have value");
1791 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1792 }
1793
1794 bool Arguments::executing_unit_tests() {
1795 return _executing_unit_tests;
1796 }
1797
1798 //===========================================================================================================
1799 // Parsing of main arguments
1800
1801 static unsigned int addreads_count = 0;
1802 static unsigned int addexports_count = 0;
1803 static unsigned int addopens_count = 0;
1804 static unsigned int patch_mod_count = 0;
1805 static unsigned int enable_native_access_count = 0;
1806 static bool patch_mod_javabase = false;
1807
1808 // Check the consistency of vm_init_args
1809 bool Arguments::check_vm_args_consistency() {
1810 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1811 if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) {
1812 return false;
1813 }
1814
1815 // Method for adding checks for flag consistency.
1816 // The intent is to warn the user of all possible conflicts,
1817 // before returning an error.
1818 // Note: Needs platform-dependent factoring.
1819 bool status = true;
1820
1821 if (TLABRefillWasteFraction == 0) {
1822 jio_fprintf(defaultStream::error_stream(),
1823 "TLABRefillWasteFraction should be a denominator, "
1824 "not %zu\n",
1825 TLABRefillWasteFraction);
1826 status = false;
1827 }
1828
1829 status = CompilerConfig::check_args_consistency(status);
1830 #if INCLUDE_JVMCI
1831 if (status && EnableJVMCI) {
2058 return false;
2059 }
2060 #endif
2061
2062 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2063 // --patch-module=<module>=<file>(<pathsep><file>)*
2064 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2065 // Find the equal sign between the module name and the path specification
2066 const char* module_equal = strchr(patch_mod_tail, '=');
2067 if (module_equal == nullptr) {
2068 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2069 return JNI_ERR;
2070 } else {
2071 // Pick out the module name
2072 size_t module_len = module_equal - patch_mod_tail;
2073 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2074 if (module_name != nullptr) {
2075 memcpy(module_name, patch_mod_tail, module_len);
2076 *(module_name + module_len) = '\0';
2077 // The path piece begins one past the module_equal sign
2078 add_patch_mod_prefix(module_name, module_equal + 1);
2079 FREE_C_HEAP_ARRAY(char, module_name);
2080 if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
2081 return JNI_ENOMEM;
2082 }
2083 } else {
2084 return JNI_ENOMEM;
2085 }
2086 }
2087 return JNI_OK;
2088 }
2089
2090 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2091 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2092 // The min and max sizes match the values in globals.hpp, but scaled
2093 // with K. The values have been chosen so that alignment with page
2094 // size doesn't change the max value, which makes the conversions
2095 // back and forth between Xss value and ThreadStackSize value easier.
2096 // The values have also been chosen to fit inside a 32-bit signed type.
2097 const julong min_ThreadStackSize = 0;
2098 const julong max_ThreadStackSize = 1 * M;
2099
2100 // Make sure the above values match the range set in globals.hpp
2101 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2102 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2103 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2104
2105 const julong min_size = min_ThreadStackSize * K;
2106 const julong max_size = max_ThreadStackSize * K;
2107
2108 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2109
2338 jio_fprintf(defaultStream::error_stream(),
2339 "Instrumentation agents are not supported in this VM\n");
2340 return JNI_ERR;
2341 #else
2342 if (tail != nullptr) {
2343 size_t length = strlen(tail) + 1;
2344 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2345 jio_snprintf(options, length, "%s", tail);
2346 JvmtiAgentList::add("instrument", options, false);
2347 FREE_C_HEAP_ARRAY(char, options);
2348
2349 // java agents need module java.instrument
2350 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2351 return JNI_ENOMEM;
2352 }
2353 }
2354 #endif // !INCLUDE_JVMTI
2355 // --enable_preview
2356 } else if (match_option(option, "--enable-preview")) {
2357 set_enable_preview();
2358 // -Xnoclassgc
2359 } else if (match_option(option, "-Xnoclassgc")) {
2360 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2361 return JNI_EINVAL;
2362 }
2363 // -Xbatch
2364 } else if (match_option(option, "-Xbatch")) {
2365 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2366 return JNI_EINVAL;
2367 }
2368 // -Xmn for compatibility with other JVM vendors
2369 } else if (match_option(option, "-Xmn", &tail)) {
2370 julong long_initial_young_size = 0;
2371 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2372 if (errcode != arg_in_range) {
2373 jio_fprintf(defaultStream::error_stream(),
2374 "Invalid initial young generation size: %s\n", option->optionString);
2375 describe_range_error(errcode);
2376 return JNI_EINVAL;
2377 }
2817 // Unknown option
2818 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2819 return JNI_ERR;
2820 }
2821 }
2822
2823 // PrintSharedArchiveAndExit will turn on
2824 // -Xshare:on
2825 // -Xlog:class+path=info
2826 if (PrintSharedArchiveAndExit) {
2827 UseSharedSpaces = true;
2828 RequireSharedSpaces = true;
2829 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2830 }
2831
2832 fix_appclasspath();
2833
2834 return JNI_OK;
2835 }
2836
2837 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path) {
2838 // For java.base check for duplicate --patch-module options being specified on the command line.
2839 // This check is only required for java.base, all other duplicate module specifications
2840 // will be checked during module system initialization. The module system initialization
2841 // will throw an ExceptionInInitializerError if this situation occurs.
2842 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2843 if (patch_mod_javabase) {
2844 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2845 } else {
2846 patch_mod_javabase = true;
2847 }
2848 }
2849
2850 // Create GrowableArray lazily, only if --patch-module has been specified
2851 if (_patch_mod_prefix == nullptr) {
2852 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2853 }
2854
2855 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2856 }
2857
2858 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2859 //
2860 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2861 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2862 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2863 // path is treated as the current directory.
2864 //
2865 // This causes problems with CDS, which requires that all directories specified in the classpath
2866 // must be empty. In most cases, applications do NOT want to load classes from the current
2867 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2868 // scripts compatible with CDS.
2869 void Arguments::fix_appclasspath() {
2870 if (IgnoreEmptyClassPaths) {
2871 const char separator = *os::path_separator();
2872 const char* src = _java_class_path->value();
2873
2874 // skip over all the leading empty paths
2875 while (*src == separator) {
2948 }
2949
2950 #if !COMPILER2_OR_JVMCI
2951 // Don't degrade server performance for footprint
2952 if (FLAG_IS_DEFAULT(UseLargePages) &&
2953 MaxHeapSize < LargePageHeapSizeThreshold) {
2954 // No need for large granularity pages w/small heaps.
2955 // Note that large pages are enabled/disabled for both the
2956 // Java heap and the code cache.
2957 FLAG_SET_DEFAULT(UseLargePages, false);
2958 }
2959
2960 UNSUPPORTED_OPTION(ProfileInterpreter);
2961 #endif
2962
2963 // Parse the CompilationMode flag
2964 if (!CompilationModeFlag::initialize()) {
2965 return JNI_ERR;
2966 }
2967
2968 if (!check_vm_args_consistency()) {
2969 return JNI_ERR;
2970 }
2971
2972
2973 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
2974 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
2975 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2976
2977 return JNI_OK;
2978 }
2979
2980 // Helper class for controlling the lifetime of JavaVMInitArgs
2981 // objects. The contents of the JavaVMInitArgs are guaranteed to be
2982 // deleted on the destruction of the ScopedVMInitArgs object.
2983 class ScopedVMInitArgs : public StackObj {
2984 private:
2985 JavaVMInitArgs _args;
2986 char* _container_name;
2987 bool _is_set;
2988 char* _vm_options_file_arg;
2989
2990 public:
2991 ScopedVMInitArgs(const char *container_name) {
3837 #ifdef ZERO
3838 // Clear flags not supported on zero.
3839 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3840 #endif // ZERO
3841
3842 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3843 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3844 DebugNonSafepoints = true;
3845 }
3846
3847 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3848 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3849 }
3850
3851 // Treat the odd case where local verification is enabled but remote
3852 // verification is not as if both were enabled.
3853 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3854 log_info(verification)("Turning on remote verification because local verification is on");
3855 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3856 }
3857
3858 #ifndef PRODUCT
3859 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3860 if (use_vm_log()) {
3861 LogVMOutput = true;
3862 }
3863 }
3864 #endif // PRODUCT
3865
3866 if (PrintCommandLineFlags) {
3867 JVMFlag::printSetFlags(tty);
3868 }
3869
3870 #if COMPILER2_OR_JVMCI
3871 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3872 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3873 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3874 }
3875 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3876
|
58 #include "runtime/os.hpp"
59 #include "runtime/safepoint.hpp"
60 #include "runtime/safepointMechanism.hpp"
61 #include "runtime/synchronizer.hpp"
62 #include "runtime/vm_version.hpp"
63 #include "services/management.hpp"
64 #include "utilities/align.hpp"
65 #include "utilities/checkedCast.hpp"
66 #include "utilities/debug.hpp"
67 #include "utilities/defaultStream.hpp"
68 #include "utilities/macros.hpp"
69 #include "utilities/parseInteger.hpp"
70 #include "utilities/powerOfTwo.hpp"
71 #include "utilities/stringUtils.hpp"
72 #include "utilities/systemMemoryBarrier.hpp"
73 #if INCLUDE_JFR
74 #include "jfr/jfr.hpp"
75 #endif
76
77 #include <limits>
78 #include <string.h>
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 bool Arguments::patching_migrated_classes(const char* property, const char* value) {
367 if (strncmp(property, MODULE_PROPERTY_PREFIX, MODULE_PROPERTY_PREFIX_LEN) == 0) {
368 const char* property_suffix = property + MODULE_PROPERTY_PREFIX_LEN;
369 if (matches_property_suffix(property_suffix, PATCH, PATCH_LEN)) {
370 if (strcmp(value, "java.base-valueclasses.jar")) {
371 return true;
372 }
373 }
374 }
375 return false;
376 }
377
378 // Process java launcher properties.
379 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
380 // See if sun.java.launcher is defined.
381 // Must do this before setting up other system properties,
382 // as some of them may depend on launcher type.
383 for (int index = 0; index < args->nOptions; index++) {
384 const JavaVMOption* option = args->options + index;
385 const char* tail;
386
387 if (match_option(option, "-Dsun.java.launcher=", &tail)) {
388 process_java_launcher_argument(tail, option->extraInfo);
389 continue;
390 }
391 if (match_option(option, "-XX:+ExecutingUnitTests")) {
392 _executing_unit_tests = true;
393 continue;
394 }
395 }
396 }
397
1797 os::free(const_cast<char*>(_sun_java_launcher));
1798 }
1799 _sun_java_launcher = os::strdup_check_oom(launcher);
1800 }
1801
1802 bool Arguments::created_by_java_launcher() {
1803 assert(_sun_java_launcher != nullptr, "property must have value");
1804 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1805 }
1806
1807 bool Arguments::executing_unit_tests() {
1808 return _executing_unit_tests;
1809 }
1810
1811 //===========================================================================================================
1812 // Parsing of main arguments
1813
1814 static unsigned int addreads_count = 0;
1815 static unsigned int addexports_count = 0;
1816 static unsigned int addopens_count = 0;
1817 static unsigned int enable_native_access_count = 0;
1818 static bool patch_mod_javabase = false;
1819
1820 // Check the consistency of vm_init_args
1821 bool Arguments::check_vm_args_consistency() {
1822 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1823 if (!CDSConfig::check_vm_args_consistency(mode_flag_cmd_line)) {
1824 return false;
1825 }
1826
1827 // Method for adding checks for flag consistency.
1828 // The intent is to warn the user of all possible conflicts,
1829 // before returning an error.
1830 // Note: Needs platform-dependent factoring.
1831 bool status = true;
1832
1833 if (TLABRefillWasteFraction == 0) {
1834 jio_fprintf(defaultStream::error_stream(),
1835 "TLABRefillWasteFraction should be a denominator, "
1836 "not %zu\n",
1837 TLABRefillWasteFraction);
1838 status = false;
1839 }
1840
1841 status = CompilerConfig::check_args_consistency(status);
1842 #if INCLUDE_JVMCI
1843 if (status && EnableJVMCI) {
2070 return false;
2071 }
2072 #endif
2073
2074 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2075 // --patch-module=<module>=<file>(<pathsep><file>)*
2076 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2077 // Find the equal sign between the module name and the path specification
2078 const char* module_equal = strchr(patch_mod_tail, '=');
2079 if (module_equal == nullptr) {
2080 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2081 return JNI_ERR;
2082 } else {
2083 // Pick out the module name
2084 size_t module_len = module_equal - patch_mod_tail;
2085 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2086 if (module_name != nullptr) {
2087 memcpy(module_name, patch_mod_tail, module_len);
2088 *(module_name + module_len) = '\0';
2089 // The path piece begins one past the module_equal sign
2090 add_patch_mod_prefix(module_name, module_equal + 1, false /* no append */, false /* no cds */);
2091 FREE_C_HEAP_ARRAY(char, module_name);
2092 } else {
2093 return JNI_ENOMEM;
2094 }
2095 }
2096 return JNI_OK;
2097 }
2098
2099 // VALUECLASS_STR must match string used in the build
2100 #define VALUECLASS_STR "valueclasses"
2101 #define VALUECLASS_JAR "-" VALUECLASS_STR ".jar"
2102
2103 // Finalize --patch-module args and --enable-preview related to value class module patches.
2104 // Create all numbered properties passing module patches.
2105 int Arguments::finalize_patch_module() {
2106 // If --enable-preview and EnableValhalla is true, each module may have value classes that
2107 // are to be patched into the module.
2108 // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2109 // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2110 if (enable_preview() && EnableValhalla) {
2111 char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2112 const char * fileSep = os::file_separator();
2113
2114 jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s",
2115 Arguments::get_java_home(), fileSep, fileSep, fileSep);
2116 DIR* dir = os::opendir(valueclasses_dir);
2117 if (dir != nullptr) {
2118 char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2119 char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2120
2121 for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) {
2122 // Test if file ends-with "-valueclasses.jar"
2123 int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1);
2124 if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) {
2125 continue; // too short or not the expected suffix
2126 }
2127
2128 strcpy(module_name, entry->d_name);
2129 module_name[len] = '\0'; // truncate to just module-name
2130
2131 jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name);
2132 add_patch_mod_prefix(module_name, path, true /* append */, true /* cds OK*/);
2133 log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name);
2134 }
2135 FreeHeap(module_name);
2136 FreeHeap(path);
2137 os::closedir(dir);
2138 }
2139 FreeHeap(valueclasses_dir);
2140 }
2141
2142 // Create numbered properties for each module that has been patched either
2143 // by --patch-module or --enable-preview
2144 // Format is "jdk.module.patch.<n>=<module_name>=<path>"
2145 if (_patch_mod_prefix != nullptr) {
2146 char * prop_value = AllocateHeap(JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, mtArguments);
2147 unsigned int patch_mod_count = 0;
2148
2149 for (GrowableArrayIterator<ModulePatchPath *> it = _patch_mod_prefix->begin();
2150 it != _patch_mod_prefix->end(); ++it) {
2151 jio_snprintf(prop_value, JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, "%s=%s",
2152 (*it)->module_name(), (*it)->path_string());
2153 if (!create_numbered_module_property("jdk.module.patch", prop_value, patch_mod_count++)) {
2154 FreeHeap(prop_value);
2155 return JNI_ENOMEM;
2156 }
2157 }
2158 FreeHeap(prop_value);
2159 }
2160 return JNI_OK;
2161 }
2162
2163 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2164 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2165 // The min and max sizes match the values in globals.hpp, but scaled
2166 // with K. The values have been chosen so that alignment with page
2167 // size doesn't change the max value, which makes the conversions
2168 // back and forth between Xss value and ThreadStackSize value easier.
2169 // The values have also been chosen to fit inside a 32-bit signed type.
2170 const julong min_ThreadStackSize = 0;
2171 const julong max_ThreadStackSize = 1 * M;
2172
2173 // Make sure the above values match the range set in globals.hpp
2174 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2175 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2176 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2177
2178 const julong min_size = min_ThreadStackSize * K;
2179 const julong max_size = max_ThreadStackSize * K;
2180
2181 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2182
2411 jio_fprintf(defaultStream::error_stream(),
2412 "Instrumentation agents are not supported in this VM\n");
2413 return JNI_ERR;
2414 #else
2415 if (tail != nullptr) {
2416 size_t length = strlen(tail) + 1;
2417 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2418 jio_snprintf(options, length, "%s", tail);
2419 JvmtiAgentList::add("instrument", options, false);
2420 FREE_C_HEAP_ARRAY(char, options);
2421
2422 // java agents need module java.instrument
2423 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2424 return JNI_ENOMEM;
2425 }
2426 }
2427 #endif // !INCLUDE_JVMTI
2428 // --enable_preview
2429 } else if (match_option(option, "--enable-preview")) {
2430 set_enable_preview();
2431 // --enable-preview enables Valhalla, EnableValhalla VM option will eventually be removed before integration
2432 if (FLAG_SET_CMDLINE(EnableValhalla, true) != JVMFlag::SUCCESS) {
2433 return JNI_EINVAL;
2434 }
2435 // -Xnoclassgc
2436 } else if (match_option(option, "-Xnoclassgc")) {
2437 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2438 return JNI_EINVAL;
2439 }
2440 // -Xbatch
2441 } else if (match_option(option, "-Xbatch")) {
2442 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2443 return JNI_EINVAL;
2444 }
2445 // -Xmn for compatibility with other JVM vendors
2446 } else if (match_option(option, "-Xmn", &tail)) {
2447 julong long_initial_young_size = 0;
2448 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2449 if (errcode != arg_in_range) {
2450 jio_fprintf(defaultStream::error_stream(),
2451 "Invalid initial young generation size: %s\n", option->optionString);
2452 describe_range_error(errcode);
2453 return JNI_EINVAL;
2454 }
2894 // Unknown option
2895 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2896 return JNI_ERR;
2897 }
2898 }
2899
2900 // PrintSharedArchiveAndExit will turn on
2901 // -Xshare:on
2902 // -Xlog:class+path=info
2903 if (PrintSharedArchiveAndExit) {
2904 UseSharedSpaces = true;
2905 RequireSharedSpaces = true;
2906 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2907 }
2908
2909 fix_appclasspath();
2910
2911 return JNI_OK;
2912 }
2913
2914 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) {
2915 if (!allow_cds) {
2916 CDSConfig::set_module_patching_disables_cds();
2917 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2918 CDSConfig::set_java_base_module_patching_disables_cds();
2919 }
2920 }
2921
2922 // Create GrowableArray lazily, only if --patch-module has been specified
2923 if (_patch_mod_prefix == nullptr) {
2924 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2925 }
2926
2927 // Scan patches for matching module
2928 int i = _patch_mod_prefix->find_if([&](ModulePatchPath* patch) {
2929 return (strcmp(module_name, patch->module_name()) == 0);
2930 });
2931 if (i == -1) {
2932 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2933 } else {
2934 if (allow_append) {
2935 // append path to existing module entry
2936 _patch_mod_prefix->at(i)->append_path(path);
2937 } else {
2938 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2939 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2940 } else {
2941 vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
2942 }
2943 }
2944 }
2945 }
2946
2947 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2948 //
2949 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2950 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2951 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2952 // path is treated as the current directory.
2953 //
2954 // This causes problems with CDS, which requires that all directories specified in the classpath
2955 // must be empty. In most cases, applications do NOT want to load classes from the current
2956 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2957 // scripts compatible with CDS.
2958 void Arguments::fix_appclasspath() {
2959 if (IgnoreEmptyClassPaths) {
2960 const char separator = *os::path_separator();
2961 const char* src = _java_class_path->value();
2962
2963 // skip over all the leading empty paths
2964 while (*src == separator) {
3037 }
3038
3039 #if !COMPILER2_OR_JVMCI
3040 // Don't degrade server performance for footprint
3041 if (FLAG_IS_DEFAULT(UseLargePages) &&
3042 MaxHeapSize < LargePageHeapSizeThreshold) {
3043 // No need for large granularity pages w/small heaps.
3044 // Note that large pages are enabled/disabled for both the
3045 // Java heap and the code cache.
3046 FLAG_SET_DEFAULT(UseLargePages, false);
3047 }
3048
3049 UNSUPPORTED_OPTION(ProfileInterpreter);
3050 #endif
3051
3052 // Parse the CompilationMode flag
3053 if (!CompilationModeFlag::initialize()) {
3054 return JNI_ERR;
3055 }
3056
3057 // finalize --module-patch and related --enable-preview
3058 if (finalize_patch_module() != JNI_OK) {
3059 return JNI_ERR;
3060 }
3061
3062 if (!check_vm_args_consistency()) {
3063 return JNI_ERR;
3064 }
3065
3066 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3067 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3068 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3069
3070 return JNI_OK;
3071 }
3072
3073 // Helper class for controlling the lifetime of JavaVMInitArgs
3074 // objects. The contents of the JavaVMInitArgs are guaranteed to be
3075 // deleted on the destruction of the ScopedVMInitArgs object.
3076 class ScopedVMInitArgs : public StackObj {
3077 private:
3078 JavaVMInitArgs _args;
3079 char* _container_name;
3080 bool _is_set;
3081 char* _vm_options_file_arg;
3082
3083 public:
3084 ScopedVMInitArgs(const char *container_name) {
3930 #ifdef ZERO
3931 // Clear flags not supported on zero.
3932 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3933 #endif // ZERO
3934
3935 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3936 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3937 DebugNonSafepoints = true;
3938 }
3939
3940 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3941 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3942 }
3943
3944 // Treat the odd case where local verification is enabled but remote
3945 // verification is not as if both were enabled.
3946 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3947 log_info(verification)("Turning on remote verification because local verification is on");
3948 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3949 }
3950 if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) {
3951 // Disable calling convention optimizations if inline types are not supported.
3952 // Also these aren't useful in -Xint. However, don't disable them when dumping or using
3953 // the CDS archive, as the values must match between dumptime and runtime.
3954 FLAG_SET_DEFAULT(InlineTypePassFieldsAsArgs, false);
3955 FLAG_SET_DEFAULT(InlineTypeReturnedAsFields, false);
3956 }
3957 if (!UseNonAtomicValueFlattening && !UseNullableValueFlattening && !UseAtomicValueFlattening) {
3958 // Flattening is disabled
3959 FLAG_SET_DEFAULT(UseArrayFlattening, false);
3960 FLAG_SET_DEFAULT(UseFieldFlattening, false);
3961 }
3962
3963 #ifndef PRODUCT
3964 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3965 if (use_vm_log()) {
3966 LogVMOutput = true;
3967 }
3968 }
3969 #endif // PRODUCT
3970
3971 if (PrintCommandLineFlags) {
3972 JVMFlag::printSetFlags(tty);
3973 }
3974
3975 #if COMPILER2_OR_JVMCI
3976 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3977 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3978 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3979 }
3980 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3981
|