57 #include "runtime/os.hpp"
58 #include "runtime/safepoint.hpp"
59 #include "runtime/safepointMechanism.hpp"
60 #include "runtime/synchronizer.hpp"
61 #include "runtime/vm_version.hpp"
62 #include "services/management.hpp"
63 #include "utilities/align.hpp"
64 #include "utilities/checkedCast.hpp"
65 #include "utilities/debug.hpp"
66 #include "utilities/defaultStream.hpp"
67 #include "utilities/macros.hpp"
68 #include "utilities/parseInteger.hpp"
69 #include "utilities/powerOfTwo.hpp"
70 #include "utilities/stringUtils.hpp"
71 #include "utilities/systemMemoryBarrier.hpp"
72 #if INCLUDE_JFR
73 #include "jfr/jfr.hpp"
74 #endif
75
76 #include <limits>
77
78 static const char _default_java_launcher[] = "generic";
79
80 #define DEFAULT_JAVA_LAUNCHER _default_java_launcher
81
82 char* Arguments::_jvm_flags_file = nullptr;
83 char** Arguments::_jvm_flags_array = nullptr;
84 int Arguments::_num_jvm_flags = 0;
85 char** Arguments::_jvm_args_array = nullptr;
86 int Arguments::_num_jvm_args = 0;
87 char* Arguments::_java_command = nullptr;
88 SystemProperty* Arguments::_system_properties = nullptr;
89 size_t Arguments::_conservative_max_heap_alignment = 0;
90 Arguments::Mode Arguments::_mode = _mixed;
91 const char* Arguments::_java_vendor_url_bug = nullptr;
92 const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
93 bool Arguments::_sun_java_launcher_is_altjvm = false;
94
95 // These parameters are reset in method parse_vm_init_args()
96 bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
1770 }
1771 _sun_java_launcher = os::strdup_check_oom(launcher);
1772 }
1773
1774 bool Arguments::created_by_java_launcher() {
1775 assert(_sun_java_launcher != nullptr, "property must have value");
1776 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1777 }
1778
1779 bool Arguments::sun_java_launcher_is_altjvm() {
1780 return _sun_java_launcher_is_altjvm;
1781 }
1782
1783 //===========================================================================================================
1784 // Parsing of main arguments
1785
1786 unsigned int addreads_count = 0;
1787 unsigned int addexports_count = 0;
1788 unsigned int addopens_count = 0;
1789 unsigned int addmods_count = 0;
1790 unsigned int patch_mod_count = 0;
1791 unsigned int enable_native_access_count = 0;
1792
1793 // Check the consistency of vm_init_args
1794 bool Arguments::check_vm_args_consistency() {
1795 // Method for adding checks for flag consistency.
1796 // The intent is to warn the user of all possible conflicts,
1797 // before returning an error.
1798 // Note: Needs platform-dependent factoring.
1799 bool status = true;
1800
1801 if (TLABRefillWasteFraction == 0) {
1802 jio_fprintf(defaultStream::error_stream(),
1803 "TLABRefillWasteFraction should be a denominator, "
1804 "not " SIZE_FORMAT "\n",
1805 TLABRefillWasteFraction);
1806 status = false;
1807 }
1808
1809 status = CompilerConfig::check_args_consistency(status);
1810 #if INCLUDE_JVMCI
1817 }
1818 }
1819 }
1820 #endif
1821
1822 #if INCLUDE_JFR
1823 if (status && (FlightRecorderOptions || StartFlightRecording)) {
1824 if (!create_numbered_module_property("jdk.module.addmods", "jdk.jfr", addmods_count++)) {
1825 return false;
1826 }
1827 }
1828 #endif
1829
1830 #ifndef SUPPORT_RESERVED_STACK_AREA
1831 if (StackReservedPages != 0) {
1832 FLAG_SET_CMDLINE(StackReservedPages, 0);
1833 warning("Reserved Stack Area not supported on this platform");
1834 }
1835 #endif
1836
1837 #if !defined(X86) && !defined(AARCH64) && !defined(RISCV64) && !defined(ARM) && !defined(PPC64) && !defined(S390)
1838 if (LockingMode == LM_LIGHTWEIGHT) {
1839 FLAG_SET_CMDLINE(LockingMode, LM_LEGACY);
1840 warning("New lightweight locking not supported on this platform");
1841 }
1842 #endif
1843
1844 #if !defined(X86) && !defined(AARCH64) && !defined(PPC64) && !defined(RISCV64) && !defined(S390)
1845 if (LockingMode == LM_MONITOR) {
1846 jio_fprintf(defaultStream::error_stream(),
1847 "LockingMode == 0 (LM_MONITOR) is not fully implemented on this architecture\n");
1848 return false;
1849 }
1850 #endif
1851 #if defined(X86) && !defined(ZERO)
1852 if (LockingMode == LM_MONITOR && UseRTMForStackLocks) {
1853 jio_fprintf(defaultStream::error_stream(),
1854 "LockingMode == 0 (LM_MONITOR) and -XX:+UseRTMForStackLocks are mutually exclusive\n");
1855
1856 return false;
1945 }
1946
1947 jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
1948 return false;
1949 }
1950
1951 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
1952 julong* long_arg,
1953 julong min_size,
1954 julong max_size) {
1955 if (!parse_integer(s, long_arg)) return arg_unreadable;
1956 return check_memory_size(*long_arg, min_size, max_size);
1957 }
1958
1959 // Parse JavaVMInitArgs structure
1960
1961 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
1962 const JavaVMInitArgs *java_tool_options_args,
1963 const JavaVMInitArgs *java_options_args,
1964 const JavaVMInitArgs *cmd_line_args) {
1965 bool patch_mod_javabase = false;
1966
1967 // Save default settings for some mode flags
1968 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
1969 Arguments::_UseOnStackReplacement = UseOnStackReplacement;
1970 Arguments::_ClipInlining = ClipInlining;
1971 Arguments::_BackgroundCompilation = BackgroundCompilation;
1972
1973 // Remember the default value of SharedBaseAddress.
1974 Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1975
1976 // Setup flags for mixed which is the default
1977 set_mode_flags(_mixed);
1978
1979 // Parse args structure generated from java.base vm options resource
1980 jint result = parse_each_vm_init_arg(vm_options_args, &patch_mod_javabase, JVMFlagOrigin::JIMAGE_RESOURCE);
1981 if (result != JNI_OK) {
1982 return result;
1983 }
1984
1985 // Parse args structure generated from JAVA_TOOL_OPTIONS environment
1986 // variable (if present).
1987 result = parse_each_vm_init_arg(java_tool_options_args, &patch_mod_javabase, JVMFlagOrigin::ENVIRON_VAR);
1988 if (result != JNI_OK) {
1989 return result;
1990 }
1991
1992 // Parse args structure generated from the command line flags.
1993 result = parse_each_vm_init_arg(cmd_line_args, &patch_mod_javabase, JVMFlagOrigin::COMMAND_LINE);
1994 if (result != JNI_OK) {
1995 return result;
1996 }
1997
1998 // Parse args structure generated from the _JAVA_OPTIONS environment
1999 // variable (if present) (mimics classic VM)
2000 result = parse_each_vm_init_arg(java_options_args, &patch_mod_javabase, JVMFlagOrigin::ENVIRON_VAR);
2001 if (result != JNI_OK) {
2002 return result;
2003 }
2004
2005 // Disable CDS for exploded image
2006 if (!has_jimage()) {
2007 no_shared_spaces("CDS disabled on exploded JDK");
2008 }
2009
2010 // We need to ensure processor and memory resources have been properly
2011 // configured - which may rely on arguments we just processed - before
2012 // doing the final argument processing. Any argument processing that
2013 // needs to know about processor and memory resources must occur after
2014 // this point.
2015
2016 os::init_container_support();
2017
2018 SystemMemoryBarrier::initialize();
2019
2020 // Do final processing now that all arguments have been parsed
2021 result = finalize_vm_init_args(patch_mod_javabase);
2022 if (result != JNI_OK) {
2023 return result;
2024 }
2025
2026 return JNI_OK;
2027 }
2028
2029 #if !INCLUDE_JVMTI
2030 // Checks if name in command-line argument -agent{lib,path}:name[=options]
2031 // represents a valid JDWP agent. is_path==true denotes that we
2032 // are dealing with -agentpath (case where name is a path), otherwise with
2033 // -agentlib
2034 static bool valid_jdwp_agent(char *name, bool is_path) {
2035 char *_name;
2036 const char *_jdwp = "jdwp";
2037 size_t _len_jdwp, _len_prefix;
2038
2039 if (is_path) {
2040 if ((_name = strrchr(name, (int) *os::file_separator())) == nullptr) {
2041 return false;
2056 }
2057 else {
2058 return false;
2059 }
2060
2061 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) {
2062 return false;
2063 }
2064
2065 return true;
2066 }
2067
2068 if (strcmp(name, _jdwp) == 0) {
2069 return true;
2070 }
2071
2072 return false;
2073 }
2074 #endif
2075
2076 int Arguments::process_patch_mod_option(const char* patch_mod_tail, bool* patch_mod_javabase) {
2077 // --patch-module=<module>=<file>(<pathsep><file>)*
2078 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2079 // Find the equal sign between the module name and the path specification
2080 const char* module_equal = strchr(patch_mod_tail, '=');
2081 if (module_equal == nullptr) {
2082 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2083 return JNI_ERR;
2084 } else {
2085 // Pick out the module name
2086 size_t module_len = module_equal - patch_mod_tail;
2087 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2088 if (module_name != nullptr) {
2089 memcpy(module_name, patch_mod_tail, module_len);
2090 *(module_name + module_len) = '\0';
2091 // The path piece begins one past the module_equal sign
2092 add_patch_mod_prefix(module_name, module_equal + 1, patch_mod_javabase);
2093 FREE_C_HEAP_ARRAY(char, module_name);
2094 if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
2095 return JNI_ENOMEM;
2096 }
2097 } else {
2098 return JNI_ENOMEM;
2099 }
2100 }
2101 return JNI_OK;
2102 }
2103
2104 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2105 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2106 // The min and max sizes match the values in globals.hpp, but scaled
2107 // with K. The values have been chosen so that alignment with page
2108 // size doesn't change the max value, which makes the conversions
2109 // back and forth between Xss value and ThreadStackSize value easier.
2110 // The values have also been chosen to fit inside a 32-bit signed type.
2111 const julong min_ThreadStackSize = 0;
2112 const julong max_ThreadStackSize = 1 * M;
2113
2114 // Make sure the above values match the range set in globals.hpp
2115 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2116 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2117 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2118
2119 const julong min_size = min_ThreadStackSize * K;
2120 const julong max_size = max_ThreadStackSize * K;
2121
2122 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2123
2138 assert(size <= size_aligned,
2139 "Overflow: " JULONG_FORMAT " " JULONG_FORMAT,
2140 size, size_aligned);
2141
2142 const julong size_in_K = size_aligned / K;
2143 assert(size_in_K < (julong)max_intx,
2144 "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT,
2145 size_in_K);
2146
2147 // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow.
2148 const julong max_expanded = align_up(size_in_K * K, os::vm_page_size());
2149 assert(max_expanded < max_uintx && max_expanded >= size_in_K,
2150 "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT,
2151 max_expanded, size_in_K);
2152
2153 *out_ThreadStackSize = (intx)size_in_K;
2154
2155 return JNI_OK;
2156 }
2157
2158 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_mod_javabase, JVMFlagOrigin origin) {
2159 // For match_option to return remaining or value part of option string
2160 const char* tail;
2161
2162 // iterate over arguments
2163 for (int index = 0; index < args->nOptions; index++) {
2164 bool is_absolute_path = false; // for -agentpath vs -agentlib
2165
2166 const JavaVMOption* option = args->options + index;
2167
2168 if (!match_option(option, "-Djava.class.path", &tail) &&
2169 !match_option(option, "-Dsun.java.command", &tail) &&
2170 !match_option(option, "-Dsun.java.launcher", &tail)) {
2171
2172 // add all jvm options to the jvm_args string. This string
2173 // is used later to set the java.vm.args PerfData string constant.
2174 // the -Djava.class.path and the -Dsun.java.command options are
2175 // omitted from jvm_args string as each have their own PerfData
2176 // string constant object.
2177 build_jvm_args(option->optionString);
2178 }
2261 return JNI_ENOMEM;
2262 }
2263 } else if (match_option(option, "--enable-native-access=", &tail)) {
2264 if (!create_numbered_module_property("jdk.module.enable.native.access", tail, enable_native_access_count++)) {
2265 return JNI_ENOMEM;
2266 }
2267 } else if (match_option(option, "--limit-modules=", &tail)) {
2268 if (!create_module_property("jdk.module.limitmods", tail, InternalProperty)) {
2269 return JNI_ENOMEM;
2270 }
2271 } else if (match_option(option, "--module-path=", &tail)) {
2272 if (!create_module_property("jdk.module.path", tail, ExternalProperty)) {
2273 return JNI_ENOMEM;
2274 }
2275 } else if (match_option(option, "--upgrade-module-path=", &tail)) {
2276 if (!create_module_property("jdk.module.upgrade.path", tail, ExternalProperty)) {
2277 return JNI_ENOMEM;
2278 }
2279 } else if (match_option(option, "--patch-module=", &tail)) {
2280 // --patch-module=<module>=<file>(<pathsep><file>)*
2281 int res = process_patch_mod_option(tail, patch_mod_javabase);
2282 if (res != JNI_OK) {
2283 return res;
2284 }
2285 } else if (match_option(option, "--sun-misc-unsafe-memory-access=", &tail)) {
2286 if (strcmp(tail, "allow") == 0 || strcmp(tail, "warn") == 0 || strcmp(tail, "debug") == 0 || strcmp(tail, "deny") == 0) {
2287 PropertyList_unique_add(&_system_properties, "sun.misc.unsafe.memory.access", tail,
2288 AddProperty, WriteableProperty, InternalProperty);
2289 } else {
2290 jio_fprintf(defaultStream::error_stream(),
2291 "Value specified to --sun-misc-unsafe-memory-access not recognized: '%s'\n", tail);
2292 return JNI_ERR;
2293 }
2294 } else if (match_option(option, "--illegal-access=", &tail)) {
2295 char version[256];
2296 JDK_Version::jdk(17).to_string(version, sizeof(version));
2297 warning("Ignoring option %s; support was removed in %s", option->optionString, version);
2298 // -agentlib and -agentpath
2299 } else if (match_option(option, "-agentlib:", &tail) ||
2300 (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2301 if(tail != nullptr) {
2331 jio_fprintf(defaultStream::error_stream(),
2332 "Instrumentation agents are not supported in this VM\n");
2333 return JNI_ERR;
2334 #else
2335 if (tail != nullptr) {
2336 size_t length = strlen(tail) + 1;
2337 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2338 jio_snprintf(options, length, "%s", tail);
2339 JvmtiAgentList::add("instrument", options, false);
2340 FREE_C_HEAP_ARRAY(char, options);
2341
2342 // java agents need module java.instrument
2343 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", addmods_count++)) {
2344 return JNI_ENOMEM;
2345 }
2346 }
2347 #endif // !INCLUDE_JVMTI
2348 // --enable_preview
2349 } else if (match_option(option, "--enable-preview")) {
2350 set_enable_preview();
2351 // -Xnoclassgc
2352 } else if (match_option(option, "-Xnoclassgc")) {
2353 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2354 return JNI_EINVAL;
2355 }
2356 // -Xbatch
2357 } else if (match_option(option, "-Xbatch")) {
2358 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2359 return JNI_EINVAL;
2360 }
2361 // -Xmn for compatibility with other JVM vendors
2362 } else if (match_option(option, "-Xmn", &tail)) {
2363 julong long_initial_young_size = 0;
2364 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2365 if (errcode != arg_in_range) {
2366 jio_fprintf(defaultStream::error_stream(),
2367 "Invalid initial young generation size: %s\n", option->optionString);
2368 describe_range_error(errcode);
2369 return JNI_EINVAL;
2370 }
2806 // Unknown option
2807 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2808 return JNI_ERR;
2809 }
2810 }
2811
2812 // PrintSharedArchiveAndExit will turn on
2813 // -Xshare:on
2814 // -Xlog:class+path=info
2815 if (PrintSharedArchiveAndExit) {
2816 UseSharedSpaces = true;
2817 RequireSharedSpaces = true;
2818 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2819 }
2820
2821 fix_appclasspath();
2822
2823 return JNI_OK;
2824 }
2825
2826 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool* patch_mod_javabase) {
2827 // For java.base check for duplicate --patch-module options being specified on the command line.
2828 // This check is only required for java.base, all other duplicate module specifications
2829 // will be checked during module system initialization. The module system initialization
2830 // will throw an ExceptionInInitializerError if this situation occurs.
2831 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2832 if (*patch_mod_javabase) {
2833 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2834 } else {
2835 *patch_mod_javabase = true;
2836 }
2837 }
2838
2839 // Create GrowableArray lazily, only if --patch-module has been specified
2840 if (_patch_mod_prefix == nullptr) {
2841 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2842 }
2843
2844 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2845 }
2846
2847 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2848 //
2849 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2850 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2851 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2852 // path is treated as the current directory.
2853 //
2854 // This causes problems with CDS, which requires that all directories specified in the classpath
2855 // must be empty. In most cases, applications do NOT want to load classes from the current
2856 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2857 // scripts compatible with CDS.
2858 void Arguments::fix_appclasspath() {
2859 if (IgnoreEmptyClassPaths) {
2860 const char separator = *os::path_separator();
2861 const char* src = _java_class_path->value();
2862
2863 // skip over all the leading empty paths
2864 while (*src == separator) {
2867
2868 char* copy = os::strdup_check_oom(src, mtArguments);
2869
2870 // trim all trailing empty paths
2871 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
2872 *tail = '\0';
2873 }
2874
2875 char from[3] = {separator, separator, '\0'};
2876 char to [2] = {separator, '\0'};
2877 while (StringUtils::replace_no_expand(copy, from, to) > 0) {
2878 // Keep replacing "::" -> ":" until we have no more "::" (non-windows)
2879 // Keep replacing ";;" -> ";" until we have no more ";;" (windows)
2880 }
2881
2882 _java_class_path->set_writeable_value(copy);
2883 FreeHeap(copy); // a copy was made by set_value, so don't need this anymore
2884 }
2885 }
2886
2887 jint Arguments::finalize_vm_init_args(bool patch_mod_javabase) {
2888 // check if the default lib/endorsed directory exists; if so, error
2889 char path[JVM_MAXPATHLEN];
2890 const char* fileSep = os::file_separator();
2891 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
2892
2893 DIR* dir = os::opendir(path);
2894 if (dir != nullptr) {
2895 jio_fprintf(defaultStream::output_stream(),
2896 "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n"
2897 "in modular form will be supported via the concept of upgradeable modules.\n");
2898 os::closedir(dir);
2899 return JNI_ERR;
2900 }
2901
2902 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
2903 dir = os::opendir(path);
2904 if (dir != nullptr) {
2905 jio_fprintf(defaultStream::output_stream(),
2906 "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; "
2907 "Use -classpath instead.\n.");
2941 if (FLAG_IS_DEFAULT(UseLargePages) &&
2942 MaxHeapSize < LargePageHeapSizeThreshold) {
2943 // No need for large granularity pages w/small heaps.
2944 // Note that large pages are enabled/disabled for both the
2945 // Java heap and the code cache.
2946 FLAG_SET_DEFAULT(UseLargePages, false);
2947 }
2948
2949 UNSUPPORTED_OPTION(ProfileInterpreter);
2950 #endif
2951
2952 // Parse the CompilationMode flag
2953 if (!CompilationModeFlag::initialize()) {
2954 return JNI_ERR;
2955 }
2956
2957 if (!check_vm_args_consistency()) {
2958 return JNI_ERR;
2959 }
2960
2961 if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) {
2962 return JNI_ERR;
2963 }
2964
2965 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
2966 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
2967 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2968
2969 return JNI_OK;
2970 }
2971
2972 // Helper class for controlling the lifetime of JavaVMInitArgs
2973 // objects. The contents of the JavaVMInitArgs are guaranteed to be
2974 // deleted on the destruction of the ScopedVMInitArgs object.
2975 class ScopedVMInitArgs : public StackObj {
2976 private:
2977 JavaVMInitArgs _args;
2978 char* _container_name;
2979 bool _is_set;
2980 char* _vm_options_file_arg;
2981
3711 #ifdef ZERO
3712 // Clear flags not supported on zero.
3713 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3714 #endif // ZERO
3715
3716 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3717 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3718 DebugNonSafepoints = true;
3719 }
3720
3721 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3722 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3723 }
3724
3725 // Treat the odd case where local verification is enabled but remote
3726 // verification is not as if both were enabled.
3727 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3728 log_info(verification)("Turning on remote verification because local verification is on");
3729 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3730 }
3731
3732 #ifndef PRODUCT
3733 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3734 if (use_vm_log()) {
3735 LogVMOutput = true;
3736 }
3737 }
3738 #endif // PRODUCT
3739
3740 if (PrintCommandLineFlags) {
3741 JVMFlag::printSetFlags(tty);
3742 }
3743
3744 #if COMPILER2_OR_JVMCI
3745 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3746 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3747 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3748 }
3749 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3750
|
57 #include "runtime/os.hpp"
58 #include "runtime/safepoint.hpp"
59 #include "runtime/safepointMechanism.hpp"
60 #include "runtime/synchronizer.hpp"
61 #include "runtime/vm_version.hpp"
62 #include "services/management.hpp"
63 #include "utilities/align.hpp"
64 #include "utilities/checkedCast.hpp"
65 #include "utilities/debug.hpp"
66 #include "utilities/defaultStream.hpp"
67 #include "utilities/macros.hpp"
68 #include "utilities/parseInteger.hpp"
69 #include "utilities/powerOfTwo.hpp"
70 #include "utilities/stringUtils.hpp"
71 #include "utilities/systemMemoryBarrier.hpp"
72 #if INCLUDE_JFR
73 #include "jfr/jfr.hpp"
74 #endif
75
76 #include <limits>
77 #include <string.h>
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 char* Arguments::_java_command = nullptr;
89 SystemProperty* Arguments::_system_properties = nullptr;
90 size_t Arguments::_conservative_max_heap_alignment = 0;
91 Arguments::Mode Arguments::_mode = _mixed;
92 const char* Arguments::_java_vendor_url_bug = nullptr;
93 const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
94 bool Arguments::_sun_java_launcher_is_altjvm = false;
95
96 // These parameters are reset in method parse_vm_init_args()
97 bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
1771 }
1772 _sun_java_launcher = os::strdup_check_oom(launcher);
1773 }
1774
1775 bool Arguments::created_by_java_launcher() {
1776 assert(_sun_java_launcher != nullptr, "property must have value");
1777 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1778 }
1779
1780 bool Arguments::sun_java_launcher_is_altjvm() {
1781 return _sun_java_launcher_is_altjvm;
1782 }
1783
1784 //===========================================================================================================
1785 // Parsing of main arguments
1786
1787 unsigned int addreads_count = 0;
1788 unsigned int addexports_count = 0;
1789 unsigned int addopens_count = 0;
1790 unsigned int addmods_count = 0;
1791 unsigned int enable_native_access_count = 0;
1792
1793 // Check the consistency of vm_init_args
1794 bool Arguments::check_vm_args_consistency() {
1795 // Method for adding checks for flag consistency.
1796 // The intent is to warn the user of all possible conflicts,
1797 // before returning an error.
1798 // Note: Needs platform-dependent factoring.
1799 bool status = true;
1800
1801 if (TLABRefillWasteFraction == 0) {
1802 jio_fprintf(defaultStream::error_stream(),
1803 "TLABRefillWasteFraction should be a denominator, "
1804 "not " SIZE_FORMAT "\n",
1805 TLABRefillWasteFraction);
1806 status = false;
1807 }
1808
1809 status = CompilerConfig::check_args_consistency(status);
1810 #if INCLUDE_JVMCI
1817 }
1818 }
1819 }
1820 #endif
1821
1822 #if INCLUDE_JFR
1823 if (status && (FlightRecorderOptions || StartFlightRecording)) {
1824 if (!create_numbered_module_property("jdk.module.addmods", "jdk.jfr", addmods_count++)) {
1825 return false;
1826 }
1827 }
1828 #endif
1829
1830 #ifndef SUPPORT_RESERVED_STACK_AREA
1831 if (StackReservedPages != 0) {
1832 FLAG_SET_CMDLINE(StackReservedPages, 0);
1833 warning("Reserved Stack Area not supported on this platform");
1834 }
1835 #endif
1836
1837 if (AMD64_ONLY(false &&) AARCH64_ONLY(false &&) !FLAG_IS_DEFAULT(InlineTypePassFieldsAsArgs)) {
1838 FLAG_SET_CMDLINE(InlineTypePassFieldsAsArgs, false);
1839 warning("InlineTypePassFieldsAsArgs is not supported on this platform");
1840 }
1841
1842 if (AMD64_ONLY(false &&) AARCH64_ONLY(false &&) !FLAG_IS_DEFAULT(InlineTypeReturnedAsFields)) {
1843 FLAG_SET_CMDLINE(InlineTypeReturnedAsFields, false);
1844 warning("InlineTypeReturnedAsFields is not supported on this platform");
1845 }
1846
1847 #if !defined(X86) && !defined(AARCH64) && !defined(RISCV64) && !defined(ARM) && !defined(PPC64) && !defined(S390)
1848 if (LockingMode == LM_LIGHTWEIGHT) {
1849 FLAG_SET_CMDLINE(LockingMode, LM_LEGACY);
1850 warning("New lightweight locking not supported on this platform");
1851 }
1852 #endif
1853
1854 #if !defined(X86) && !defined(AARCH64) && !defined(PPC64) && !defined(RISCV64) && !defined(S390)
1855 if (LockingMode == LM_MONITOR) {
1856 jio_fprintf(defaultStream::error_stream(),
1857 "LockingMode == 0 (LM_MONITOR) is not fully implemented on this architecture\n");
1858 return false;
1859 }
1860 #endif
1861 #if defined(X86) && !defined(ZERO)
1862 if (LockingMode == LM_MONITOR && UseRTMForStackLocks) {
1863 jio_fprintf(defaultStream::error_stream(),
1864 "LockingMode == 0 (LM_MONITOR) and -XX:+UseRTMForStackLocks are mutually exclusive\n");
1865
1866 return false;
1955 }
1956
1957 jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
1958 return false;
1959 }
1960
1961 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
1962 julong* long_arg,
1963 julong min_size,
1964 julong max_size) {
1965 if (!parse_integer(s, long_arg)) return arg_unreadable;
1966 return check_memory_size(*long_arg, min_size, max_size);
1967 }
1968
1969 // Parse JavaVMInitArgs structure
1970
1971 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
1972 const JavaVMInitArgs *java_tool_options_args,
1973 const JavaVMInitArgs *java_options_args,
1974 const JavaVMInitArgs *cmd_line_args) {
1975 // Save default settings for some mode flags
1976 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
1977 Arguments::_UseOnStackReplacement = UseOnStackReplacement;
1978 Arguments::_ClipInlining = ClipInlining;
1979 Arguments::_BackgroundCompilation = BackgroundCompilation;
1980
1981 // Remember the default value of SharedBaseAddress.
1982 Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1983
1984 // Setup flags for mixed which is the default
1985 set_mode_flags(_mixed);
1986
1987 // Parse args structure generated from java.base vm options resource
1988 jint result = parse_each_vm_init_arg(vm_options_args, JVMFlagOrigin::JIMAGE_RESOURCE);
1989 if (result != JNI_OK) {
1990 return result;
1991 }
1992
1993 // Parse args structure generated from JAVA_TOOL_OPTIONS environment
1994 // variable (if present).
1995 result = parse_each_vm_init_arg(java_tool_options_args, JVMFlagOrigin::ENVIRON_VAR);
1996 if (result != JNI_OK) {
1997 return result;
1998 }
1999
2000 // Parse args structure generated from the command line flags.
2001 result = parse_each_vm_init_arg(cmd_line_args, JVMFlagOrigin::COMMAND_LINE);
2002 if (result != JNI_OK) {
2003 return result;
2004 }
2005
2006 // Parse args structure generated from the _JAVA_OPTIONS environment
2007 // variable (if present) (mimics classic VM)
2008 result = parse_each_vm_init_arg(java_options_args, JVMFlagOrigin::ENVIRON_VAR);
2009 if (result != JNI_OK) {
2010 return result;
2011 }
2012
2013 // Disable CDS for exploded image
2014 if (!has_jimage()) {
2015 no_shared_spaces("CDS disabled on exploded JDK");
2016 }
2017
2018 // We need to ensure processor and memory resources have been properly
2019 // configured - which may rely on arguments we just processed - before
2020 // doing the final argument processing. Any argument processing that
2021 // needs to know about processor and memory resources must occur after
2022 // this point.
2023
2024 os::init_container_support();
2025
2026 SystemMemoryBarrier::initialize();
2027
2028 // Do final processing now that all arguments have been parsed
2029 result = finalize_vm_init_args();
2030 if (result != JNI_OK) {
2031 return result;
2032 }
2033
2034 return JNI_OK;
2035 }
2036
2037 #if !INCLUDE_JVMTI
2038 // Checks if name in command-line argument -agent{lib,path}:name[=options]
2039 // represents a valid JDWP agent. is_path==true denotes that we
2040 // are dealing with -agentpath (case where name is a path), otherwise with
2041 // -agentlib
2042 static bool valid_jdwp_agent(char *name, bool is_path) {
2043 char *_name;
2044 const char *_jdwp = "jdwp";
2045 size_t _len_jdwp, _len_prefix;
2046
2047 if (is_path) {
2048 if ((_name = strrchr(name, (int) *os::file_separator())) == nullptr) {
2049 return false;
2064 }
2065 else {
2066 return false;
2067 }
2068
2069 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) {
2070 return false;
2071 }
2072
2073 return true;
2074 }
2075
2076 if (strcmp(name, _jdwp) == 0) {
2077 return true;
2078 }
2079
2080 return false;
2081 }
2082 #endif
2083
2084 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2085 // --patch-module=<module>=<file>(<pathsep><file>)*
2086 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2087 // Find the equal sign between the module name and the path specification
2088 const char* module_equal = strchr(patch_mod_tail, '=');
2089 if (module_equal == nullptr) {
2090 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2091 return JNI_ERR;
2092 } else {
2093 // Pick out the module name
2094 size_t module_len = module_equal - patch_mod_tail;
2095 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2096 if (module_name != nullptr) {
2097 memcpy(module_name, patch_mod_tail, module_len);
2098 *(module_name + module_len) = '\0';
2099 // The path piece begins one past the module_equal sign
2100 add_patch_mod_prefix(module_name, module_equal + 1, false /* no append */, false /* no cds */);
2101 FREE_C_HEAP_ARRAY(char, module_name);
2102 } else {
2103 return JNI_ENOMEM;
2104 }
2105 }
2106 return JNI_OK;
2107 }
2108
2109 // VALUECLASS_STR must match string used in the build
2110 #define VALUECLASS_STR "valueclasses"
2111 #define VALUECLASS_JAR "-" VALUECLASS_STR ".jar"
2112
2113 // Finalize --patch-module args and --enable-preview related to value class module patches.
2114 // Create all numbered properties passing module patches.
2115 int Arguments::finalize_patch_module() {
2116 // If --enable-preview and EnableValhalla is true, each module may have value classes that
2117 // are to be patched into the module.
2118 // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2119 // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2120 if (enable_preview() && EnableValhalla) {
2121 char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2122 const char * fileSep = os::file_separator();
2123
2124 jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s",
2125 Arguments::get_java_home(), fileSep, fileSep, fileSep);
2126 DIR* dir = os::opendir(valueclasses_dir);
2127 if (dir != nullptr) {
2128 char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2129 char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2130
2131 for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) {
2132 // Test if file ends-with "-valueclasses.jar"
2133 int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1);
2134 if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) {
2135 continue; // too short or not the expected suffix
2136 }
2137
2138 strcpy(module_name, entry->d_name);
2139 module_name[len] = '\0'; // truncate to just module-name
2140
2141 jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name);
2142 add_patch_mod_prefix(module_name, path, true /* append */, true /* cds OK*/);
2143 log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name);
2144 }
2145 FreeHeap(module_name);
2146 FreeHeap(path);
2147 os::closedir(dir);
2148 }
2149 FreeHeap(valueclasses_dir);
2150 }
2151
2152 // Create numbered properties for each module that has been patched either
2153 // by --patch-module or --enable-preview
2154 // Format is "jdk.module.patch.<n>=<module_name>=<path>"
2155 if (_patch_mod_prefix != nullptr) {
2156 char * prop_value = AllocateHeap(JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, mtArguments);
2157 unsigned int patch_mod_count = 0;
2158
2159 for (GrowableArrayIterator<ModulePatchPath *> it = _patch_mod_prefix->begin();
2160 it != _patch_mod_prefix->end(); ++it) {
2161 jio_snprintf(prop_value, JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, "%s=%s",
2162 (*it)->module_name(), (*it)->path_string());
2163 if (!create_numbered_module_property("jdk.module.patch", prop_value, patch_mod_count++)) {
2164 FreeHeap(prop_value);
2165 return JNI_ENOMEM;
2166 }
2167 }
2168 FreeHeap(prop_value);
2169 }
2170 return JNI_OK;
2171 }
2172
2173 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2174 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2175 // The min and max sizes match the values in globals.hpp, but scaled
2176 // with K. The values have been chosen so that alignment with page
2177 // size doesn't change the max value, which makes the conversions
2178 // back and forth between Xss value and ThreadStackSize value easier.
2179 // The values have also been chosen to fit inside a 32-bit signed type.
2180 const julong min_ThreadStackSize = 0;
2181 const julong max_ThreadStackSize = 1 * M;
2182
2183 // Make sure the above values match the range set in globals.hpp
2184 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2185 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2186 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2187
2188 const julong min_size = min_ThreadStackSize * K;
2189 const julong max_size = max_ThreadStackSize * K;
2190
2191 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2192
2207 assert(size <= size_aligned,
2208 "Overflow: " JULONG_FORMAT " " JULONG_FORMAT,
2209 size, size_aligned);
2210
2211 const julong size_in_K = size_aligned / K;
2212 assert(size_in_K < (julong)max_intx,
2213 "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT,
2214 size_in_K);
2215
2216 // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow.
2217 const julong max_expanded = align_up(size_in_K * K, os::vm_page_size());
2218 assert(max_expanded < max_uintx && max_expanded >= size_in_K,
2219 "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT,
2220 max_expanded, size_in_K);
2221
2222 *out_ThreadStackSize = (intx)size_in_K;
2223
2224 return JNI_OK;
2225 }
2226
2227 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, JVMFlagOrigin origin) {
2228 // For match_option to return remaining or value part of option string
2229 const char* tail;
2230
2231 // iterate over arguments
2232 for (int index = 0; index < args->nOptions; index++) {
2233 bool is_absolute_path = false; // for -agentpath vs -agentlib
2234
2235 const JavaVMOption* option = args->options + index;
2236
2237 if (!match_option(option, "-Djava.class.path", &tail) &&
2238 !match_option(option, "-Dsun.java.command", &tail) &&
2239 !match_option(option, "-Dsun.java.launcher", &tail)) {
2240
2241 // add all jvm options to the jvm_args string. This string
2242 // is used later to set the java.vm.args PerfData string constant.
2243 // the -Djava.class.path and the -Dsun.java.command options are
2244 // omitted from jvm_args string as each have their own PerfData
2245 // string constant object.
2246 build_jvm_args(option->optionString);
2247 }
2330 return JNI_ENOMEM;
2331 }
2332 } else if (match_option(option, "--enable-native-access=", &tail)) {
2333 if (!create_numbered_module_property("jdk.module.enable.native.access", tail, enable_native_access_count++)) {
2334 return JNI_ENOMEM;
2335 }
2336 } else if (match_option(option, "--limit-modules=", &tail)) {
2337 if (!create_module_property("jdk.module.limitmods", tail, InternalProperty)) {
2338 return JNI_ENOMEM;
2339 }
2340 } else if (match_option(option, "--module-path=", &tail)) {
2341 if (!create_module_property("jdk.module.path", tail, ExternalProperty)) {
2342 return JNI_ENOMEM;
2343 }
2344 } else if (match_option(option, "--upgrade-module-path=", &tail)) {
2345 if (!create_module_property("jdk.module.upgrade.path", tail, ExternalProperty)) {
2346 return JNI_ENOMEM;
2347 }
2348 } else if (match_option(option, "--patch-module=", &tail)) {
2349 // --patch-module=<module>=<file>(<pathsep><file>)*
2350 int res = process_patch_mod_option(tail);
2351 if (res != JNI_OK) {
2352 return res;
2353 }
2354 } else if (match_option(option, "--sun-misc-unsafe-memory-access=", &tail)) {
2355 if (strcmp(tail, "allow") == 0 || strcmp(tail, "warn") == 0 || strcmp(tail, "debug") == 0 || strcmp(tail, "deny") == 0) {
2356 PropertyList_unique_add(&_system_properties, "sun.misc.unsafe.memory.access", tail,
2357 AddProperty, WriteableProperty, InternalProperty);
2358 } else {
2359 jio_fprintf(defaultStream::error_stream(),
2360 "Value specified to --sun-misc-unsafe-memory-access not recognized: '%s'\n", tail);
2361 return JNI_ERR;
2362 }
2363 } else if (match_option(option, "--illegal-access=", &tail)) {
2364 char version[256];
2365 JDK_Version::jdk(17).to_string(version, sizeof(version));
2366 warning("Ignoring option %s; support was removed in %s", option->optionString, version);
2367 // -agentlib and -agentpath
2368 } else if (match_option(option, "-agentlib:", &tail) ||
2369 (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2370 if(tail != nullptr) {
2400 jio_fprintf(defaultStream::error_stream(),
2401 "Instrumentation agents are not supported in this VM\n");
2402 return JNI_ERR;
2403 #else
2404 if (tail != nullptr) {
2405 size_t length = strlen(tail) + 1;
2406 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2407 jio_snprintf(options, length, "%s", tail);
2408 JvmtiAgentList::add("instrument", options, false);
2409 FREE_C_HEAP_ARRAY(char, options);
2410
2411 // java agents need module java.instrument
2412 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", addmods_count++)) {
2413 return JNI_ENOMEM;
2414 }
2415 }
2416 #endif // !INCLUDE_JVMTI
2417 // --enable_preview
2418 } else if (match_option(option, "--enable-preview")) {
2419 set_enable_preview();
2420 // --enable-preview enables Valhalla, EnableValhalla VM option will eventually be removed before integration
2421 if (FLAG_SET_CMDLINE(EnableValhalla, true) != JVMFlag::SUCCESS) {
2422 return JNI_EINVAL;
2423 }
2424 // -Xnoclassgc
2425 } else if (match_option(option, "-Xnoclassgc")) {
2426 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2427 return JNI_EINVAL;
2428 }
2429 // -Xbatch
2430 } else if (match_option(option, "-Xbatch")) {
2431 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2432 return JNI_EINVAL;
2433 }
2434 // -Xmn for compatibility with other JVM vendors
2435 } else if (match_option(option, "-Xmn", &tail)) {
2436 julong long_initial_young_size = 0;
2437 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2438 if (errcode != arg_in_range) {
2439 jio_fprintf(defaultStream::error_stream(),
2440 "Invalid initial young generation size: %s\n", option->optionString);
2441 describe_range_error(errcode);
2442 return JNI_EINVAL;
2443 }
2879 // Unknown option
2880 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2881 return JNI_ERR;
2882 }
2883 }
2884
2885 // PrintSharedArchiveAndExit will turn on
2886 // -Xshare:on
2887 // -Xlog:class+path=info
2888 if (PrintSharedArchiveAndExit) {
2889 UseSharedSpaces = true;
2890 RequireSharedSpaces = true;
2891 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2892 }
2893
2894 fix_appclasspath();
2895
2896 return JNI_OK;
2897 }
2898
2899 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) {
2900 if (!allow_cds) {
2901 CDSConfig::set_module_patching_disables_cds();
2902 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2903 CDSConfig::set_java_base_module_patching_disables_cds();
2904 }
2905 }
2906
2907 // Create GrowableArray lazily, only if --patch-module has been specified
2908 if (_patch_mod_prefix == nullptr) {
2909 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2910 }
2911
2912 // Scan patches for matching module
2913 int i = _patch_mod_prefix->find_if([&](ModulePatchPath* patch) {
2914 return (strcmp(module_name, patch->module_name()) == 0);
2915 });
2916 if (i == -1) {
2917 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2918 } else {
2919 if (allow_append) {
2920 // append path to existing module entry
2921 _patch_mod_prefix->at(i)->append_path(path);
2922 } else {
2923 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2924 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2925 } else {
2926 vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
2927 }
2928 }
2929 }
2930 }
2931
2932 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2933 //
2934 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2935 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2936 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2937 // path is treated as the current directory.
2938 //
2939 // This causes problems with CDS, which requires that all directories specified in the classpath
2940 // must be empty. In most cases, applications do NOT want to load classes from the current
2941 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2942 // scripts compatible with CDS.
2943 void Arguments::fix_appclasspath() {
2944 if (IgnoreEmptyClassPaths) {
2945 const char separator = *os::path_separator();
2946 const char* src = _java_class_path->value();
2947
2948 // skip over all the leading empty paths
2949 while (*src == separator) {
2952
2953 char* copy = os::strdup_check_oom(src, mtArguments);
2954
2955 // trim all trailing empty paths
2956 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
2957 *tail = '\0';
2958 }
2959
2960 char from[3] = {separator, separator, '\0'};
2961 char to [2] = {separator, '\0'};
2962 while (StringUtils::replace_no_expand(copy, from, to) > 0) {
2963 // Keep replacing "::" -> ":" until we have no more "::" (non-windows)
2964 // Keep replacing ";;" -> ";" until we have no more ";;" (windows)
2965 }
2966
2967 _java_class_path->set_writeable_value(copy);
2968 FreeHeap(copy); // a copy was made by set_value, so don't need this anymore
2969 }
2970 }
2971
2972 jint Arguments::finalize_vm_init_args() {
2973 // check if the default lib/endorsed directory exists; if so, error
2974 char path[JVM_MAXPATHLEN];
2975 const char* fileSep = os::file_separator();
2976 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
2977
2978 DIR* dir = os::opendir(path);
2979 if (dir != nullptr) {
2980 jio_fprintf(defaultStream::output_stream(),
2981 "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n"
2982 "in modular form will be supported via the concept of upgradeable modules.\n");
2983 os::closedir(dir);
2984 return JNI_ERR;
2985 }
2986
2987 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
2988 dir = os::opendir(path);
2989 if (dir != nullptr) {
2990 jio_fprintf(defaultStream::output_stream(),
2991 "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; "
2992 "Use -classpath instead.\n.");
3026 if (FLAG_IS_DEFAULT(UseLargePages) &&
3027 MaxHeapSize < LargePageHeapSizeThreshold) {
3028 // No need for large granularity pages w/small heaps.
3029 // Note that large pages are enabled/disabled for both the
3030 // Java heap and the code cache.
3031 FLAG_SET_DEFAULT(UseLargePages, false);
3032 }
3033
3034 UNSUPPORTED_OPTION(ProfileInterpreter);
3035 #endif
3036
3037 // Parse the CompilationMode flag
3038 if (!CompilationModeFlag::initialize()) {
3039 return JNI_ERR;
3040 }
3041
3042 if (!check_vm_args_consistency()) {
3043 return JNI_ERR;
3044 }
3045
3046 // finalize --module-patch and related --enable-preview
3047 if (finalize_patch_module() != JNI_OK) {
3048 return JNI_ERR;
3049 }
3050
3051 if (!CDSConfig::check_vm_args_consistency(mode_flag_cmd_line)) {
3052 return JNI_ERR;
3053 }
3054
3055 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3056 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3057 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3058
3059 return JNI_OK;
3060 }
3061
3062 // Helper class for controlling the lifetime of JavaVMInitArgs
3063 // objects. The contents of the JavaVMInitArgs are guaranteed to be
3064 // deleted on the destruction of the ScopedVMInitArgs object.
3065 class ScopedVMInitArgs : public StackObj {
3066 private:
3067 JavaVMInitArgs _args;
3068 char* _container_name;
3069 bool _is_set;
3070 char* _vm_options_file_arg;
3071
3801 #ifdef ZERO
3802 // Clear flags not supported on zero.
3803 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3804 #endif // ZERO
3805
3806 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3807 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3808 DebugNonSafepoints = true;
3809 }
3810
3811 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3812 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3813 }
3814
3815 // Treat the odd case where local verification is enabled but remote
3816 // verification is not as if both were enabled.
3817 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3818 log_info(verification)("Turning on remote verification because local verification is on");
3819 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3820 }
3821 if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) {
3822 // Disable calling convention optimizations if inline types are not supported.
3823 // Also these aren't useful in -Xint. However, don't disable them when dumping or using
3824 // the CDS archive, as the values must match between dumptime and runtime.
3825 InlineTypePassFieldsAsArgs = false;
3826 InlineTypeReturnedAsFields = false;
3827 }
3828
3829 #ifndef PRODUCT
3830 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3831 if (use_vm_log()) {
3832 LogVMOutput = true;
3833 }
3834 }
3835 #endif // PRODUCT
3836
3837 if (PrintCommandLineFlags) {
3838 JVMFlag::printSetFlags(tty);
3839 }
3840
3841 #if COMPILER2_OR_JVMCI
3842 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3843 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3844 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3845 }
3846 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3847
|