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;
1755 }
1756 _sun_java_launcher = os::strdup_check_oom(launcher);
1757 }
1758
1759 bool Arguments::created_by_java_launcher() {
1760 assert(_sun_java_launcher != nullptr, "property must have value");
1761 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1762 }
1763
1764 bool Arguments::sun_java_launcher_is_altjvm() {
1765 return _sun_java_launcher_is_altjvm;
1766 }
1767
1768 //===========================================================================================================
1769 // Parsing of main arguments
1770
1771 unsigned int addreads_count = 0;
1772 unsigned int addexports_count = 0;
1773 unsigned int addopens_count = 0;
1774 unsigned int addmods_count = 0;
1775 unsigned int patch_mod_count = 0;
1776 unsigned int enable_native_access_count = 0;
1777
1778 // Check the consistency of vm_init_args
1779 bool Arguments::check_vm_args_consistency() {
1780 // Method for adding checks for flag consistency.
1781 // The intent is to warn the user of all possible conflicts,
1782 // before returning an error.
1783 // Note: Needs platform-dependent factoring.
1784 bool status = true;
1785
1786 if (TLABRefillWasteFraction == 0) {
1787 jio_fprintf(defaultStream::error_stream(),
1788 "TLABRefillWasteFraction should be a denominator, "
1789 "not " SIZE_FORMAT "\n",
1790 TLABRefillWasteFraction);
1791 status = false;
1792 }
1793
1794 status = CompilerConfig::check_args_consistency(status);
1795 #if INCLUDE_JVMCI
1802 }
1803 }
1804 }
1805 #endif
1806
1807 #if INCLUDE_JFR
1808 if (status && (FlightRecorderOptions || StartFlightRecording)) {
1809 if (!create_numbered_module_property("jdk.module.addmods", "jdk.jfr", addmods_count++)) {
1810 return false;
1811 }
1812 }
1813 #endif
1814
1815 #ifndef SUPPORT_RESERVED_STACK_AREA
1816 if (StackReservedPages != 0) {
1817 FLAG_SET_CMDLINE(StackReservedPages, 0);
1818 warning("Reserved Stack Area not supported on this platform");
1819 }
1820 #endif
1821
1822 #if !defined(X86) && !defined(AARCH64) && !defined(RISCV64) && !defined(ARM) && !defined(PPC64) && !defined(S390)
1823 if (LockingMode == LM_LIGHTWEIGHT) {
1824 FLAG_SET_CMDLINE(LockingMode, LM_LEGACY);
1825 warning("New lightweight locking not supported on this platform");
1826 }
1827 #endif
1828
1829 #if !defined(X86) && !defined(AARCH64) && !defined(PPC64) && !defined(RISCV64) && !defined(S390)
1830 if (LockingMode == LM_MONITOR) {
1831 jio_fprintf(defaultStream::error_stream(),
1832 "LockingMode == 0 (LM_MONITOR) is not fully implemented on this architecture\n");
1833 return false;
1834 }
1835 #endif
1836 #if defined(X86) && !defined(ZERO)
1837 if (LockingMode == LM_MONITOR && UseRTMForStackLocks) {
1838 jio_fprintf(defaultStream::error_stream(),
1839 "LockingMode == 0 (LM_MONITOR) and -XX:+UseRTMForStackLocks are mutually exclusive\n");
1840
1841 return false;
1928 }
1929
1930 jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
1931 return false;
1932 }
1933
1934 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
1935 julong* long_arg,
1936 julong min_size,
1937 julong max_size) {
1938 if (!parse_integer(s, long_arg)) return arg_unreadable;
1939 return check_memory_size(*long_arg, min_size, max_size);
1940 }
1941
1942 // Parse JavaVMInitArgs structure
1943
1944 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
1945 const JavaVMInitArgs *java_tool_options_args,
1946 const JavaVMInitArgs *java_options_args,
1947 const JavaVMInitArgs *cmd_line_args) {
1948 bool patch_mod_javabase = false;
1949
1950 // Save default settings for some mode flags
1951 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
1952 Arguments::_UseOnStackReplacement = UseOnStackReplacement;
1953 Arguments::_ClipInlining = ClipInlining;
1954 Arguments::_BackgroundCompilation = BackgroundCompilation;
1955
1956 // Remember the default value of SharedBaseAddress.
1957 Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1958
1959 // Setup flags for mixed which is the default
1960 set_mode_flags(_mixed);
1961
1962 // Parse args structure generated from java.base vm options resource
1963 jint result = parse_each_vm_init_arg(vm_options_args, &patch_mod_javabase, JVMFlagOrigin::JIMAGE_RESOURCE);
1964 if (result != JNI_OK) {
1965 return result;
1966 }
1967
1968 // Parse args structure generated from JAVA_TOOL_OPTIONS environment
1969 // variable (if present).
1970 result = parse_each_vm_init_arg(java_tool_options_args, &patch_mod_javabase, JVMFlagOrigin::ENVIRON_VAR);
1971 if (result != JNI_OK) {
1972 return result;
1973 }
1974
1975 // Parse args structure generated from the command line flags.
1976 result = parse_each_vm_init_arg(cmd_line_args, &patch_mod_javabase, JVMFlagOrigin::COMMAND_LINE);
1977 if (result != JNI_OK) {
1978 return result;
1979 }
1980
1981 // Parse args structure generated from the _JAVA_OPTIONS environment
1982 // variable (if present) (mimics classic VM)
1983 result = parse_each_vm_init_arg(java_options_args, &patch_mod_javabase, JVMFlagOrigin::ENVIRON_VAR);
1984 if (result != JNI_OK) {
1985 return result;
1986 }
1987
1988 // Disable CDS for exploded image
1989 if (!has_jimage()) {
1990 no_shared_spaces("CDS disabled on exploded JDK");
1991 }
1992
1993 // We need to ensure processor and memory resources have been properly
1994 // configured - which may rely on arguments we just processed - before
1995 // doing the final argument processing. Any argument processing that
1996 // needs to know about processor and memory resources must occur after
1997 // this point.
1998
1999 os::init_container_support();
2000
2001 SystemMemoryBarrier::initialize();
2002
2003 // Do final processing now that all arguments have been parsed
2004 result = finalize_vm_init_args(patch_mod_javabase);
2005 if (result != JNI_OK) {
2006 return result;
2007 }
2008
2009 return JNI_OK;
2010 }
2011
2012 #if !INCLUDE_JVMTI
2013 // Checks if name in command-line argument -agent{lib,path}:name[=options]
2014 // represents a valid JDWP agent. is_path==true denotes that we
2015 // are dealing with -agentpath (case where name is a path), otherwise with
2016 // -agentlib
2017 static bool valid_jdwp_agent(char *name, bool is_path) {
2018 char *_name;
2019 const char *_jdwp = "jdwp";
2020 size_t _len_jdwp, _len_prefix;
2021
2022 if (is_path) {
2023 if ((_name = strrchr(name, (int) *os::file_separator())) == nullptr) {
2024 return false;
2039 }
2040 else {
2041 return false;
2042 }
2043
2044 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) {
2045 return false;
2046 }
2047
2048 return true;
2049 }
2050
2051 if (strcmp(name, _jdwp) == 0) {
2052 return true;
2053 }
2054
2055 return false;
2056 }
2057 #endif
2058
2059 int Arguments::process_patch_mod_option(const char* patch_mod_tail, bool* patch_mod_javabase) {
2060 // --patch-module=<module>=<file>(<pathsep><file>)*
2061 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2062 // Find the equal sign between the module name and the path specification
2063 const char* module_equal = strchr(patch_mod_tail, '=');
2064 if (module_equal == nullptr) {
2065 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2066 return JNI_ERR;
2067 } else {
2068 // Pick out the module name
2069 size_t module_len = module_equal - patch_mod_tail;
2070 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2071 if (module_name != nullptr) {
2072 memcpy(module_name, patch_mod_tail, module_len);
2073 *(module_name + module_len) = '\0';
2074 // The path piece begins one past the module_equal sign
2075 add_patch_mod_prefix(module_name, module_equal + 1, patch_mod_javabase);
2076 FREE_C_HEAP_ARRAY(char, module_name);
2077 if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
2078 return JNI_ENOMEM;
2079 }
2080 } else {
2081 return JNI_ENOMEM;
2082 }
2083 }
2084 return JNI_OK;
2085 }
2086
2087 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2088 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2089 // The min and max sizes match the values in globals.hpp, but scaled
2090 // with K. The values have been chosen so that alignment with page
2091 // size doesn't change the max value, which makes the conversions
2092 // back and forth between Xss value and ThreadStackSize value easier.
2093 // The values have also been chosen to fit inside a 32-bit signed type.
2094 const julong min_ThreadStackSize = 0;
2095 const julong max_ThreadStackSize = 1 * M;
2096
2097 // Make sure the above values match the range set in globals.hpp
2098 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2099 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2100 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2101
2102 const julong min_size = min_ThreadStackSize * K;
2103 const julong max_size = max_ThreadStackSize * K;
2104
2105 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2106
2121 assert(size <= size_aligned,
2122 "Overflow: " JULONG_FORMAT " " JULONG_FORMAT,
2123 size, size_aligned);
2124
2125 const julong size_in_K = size_aligned / K;
2126 assert(size_in_K < (julong)max_intx,
2127 "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT,
2128 size_in_K);
2129
2130 // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow.
2131 const julong max_expanded = align_up(size_in_K * K, os::vm_page_size());
2132 assert(max_expanded < max_uintx && max_expanded >= size_in_K,
2133 "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT,
2134 max_expanded, size_in_K);
2135
2136 *out_ThreadStackSize = (intx)size_in_K;
2137
2138 return JNI_OK;
2139 }
2140
2141 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_mod_javabase, JVMFlagOrigin origin) {
2142 // For match_option to return remaining or value part of option string
2143 const char* tail;
2144
2145 // iterate over arguments
2146 for (int index = 0; index < args->nOptions; index++) {
2147 bool is_absolute_path = false; // for -agentpath vs -agentlib
2148
2149 const JavaVMOption* option = args->options + index;
2150
2151 if (!match_option(option, "-Djava.class.path", &tail) &&
2152 !match_option(option, "-Dsun.java.command", &tail) &&
2153 !match_option(option, "-Dsun.java.launcher", &tail)) {
2154
2155 // add all jvm options to the jvm_args string. This string
2156 // is used later to set the java.vm.args PerfData string constant.
2157 // the -Djava.class.path and the -Dsun.java.command options are
2158 // omitted from jvm_args string as each have their own PerfData
2159 // string constant object.
2160 build_jvm_args(option->optionString);
2161 }
2244 return JNI_ENOMEM;
2245 }
2246 } else if (match_option(option, "--enable-native-access=", &tail)) {
2247 if (!create_numbered_module_property("jdk.module.enable.native.access", tail, enable_native_access_count++)) {
2248 return JNI_ENOMEM;
2249 }
2250 } else if (match_option(option, "--limit-modules=", &tail)) {
2251 if (!create_module_property("jdk.module.limitmods", tail, InternalProperty)) {
2252 return JNI_ENOMEM;
2253 }
2254 } else if (match_option(option, "--module-path=", &tail)) {
2255 if (!create_module_property("jdk.module.path", tail, ExternalProperty)) {
2256 return JNI_ENOMEM;
2257 }
2258 } else if (match_option(option, "--upgrade-module-path=", &tail)) {
2259 if (!create_module_property("jdk.module.upgrade.path", tail, ExternalProperty)) {
2260 return JNI_ENOMEM;
2261 }
2262 } else if (match_option(option, "--patch-module=", &tail)) {
2263 // --patch-module=<module>=<file>(<pathsep><file>)*
2264 int res = process_patch_mod_option(tail, patch_mod_javabase);
2265 if (res != JNI_OK) {
2266 return res;
2267 }
2268 } else if (match_option(option, "--illegal-access=", &tail)) {
2269 char version[256];
2270 JDK_Version::jdk(17).to_string(version, sizeof(version));
2271 warning("Ignoring option %s; support was removed in %s", option->optionString, version);
2272 // -agentlib and -agentpath
2273 } else if (match_option(option, "-agentlib:", &tail) ||
2274 (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2275 if(tail != nullptr) {
2276 const char* pos = strchr(tail, '=');
2277 char* name;
2278 if (pos == nullptr) {
2279 name = os::strdup_check_oom(tail, mtArguments);
2280 } else {
2281 size_t len = pos - tail;
2282 name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments);
2283 memcpy(name, tail, len);
2284 name[len] = '\0';
2305 jio_fprintf(defaultStream::error_stream(),
2306 "Instrumentation agents are not supported in this VM\n");
2307 return JNI_ERR;
2308 #else
2309 if (tail != nullptr) {
2310 size_t length = strlen(tail) + 1;
2311 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2312 jio_snprintf(options, length, "%s", tail);
2313 JvmtiAgentList::add("instrument", options, false);
2314 FREE_C_HEAP_ARRAY(char, options);
2315
2316 // java agents need module java.instrument
2317 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", addmods_count++)) {
2318 return JNI_ENOMEM;
2319 }
2320 }
2321 #endif // !INCLUDE_JVMTI
2322 // --enable_preview
2323 } else if (match_option(option, "--enable-preview")) {
2324 set_enable_preview();
2325 // -Xnoclassgc
2326 } else if (match_option(option, "-Xnoclassgc")) {
2327 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2328 return JNI_EINVAL;
2329 }
2330 // -Xbatch
2331 } else if (match_option(option, "-Xbatch")) {
2332 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2333 return JNI_EINVAL;
2334 }
2335 // -Xmn for compatibility with other JVM vendors
2336 } else if (match_option(option, "-Xmn", &tail)) {
2337 julong long_initial_young_size = 0;
2338 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2339 if (errcode != arg_in_range) {
2340 jio_fprintf(defaultStream::error_stream(),
2341 "Invalid initial young generation size: %s\n", option->optionString);
2342 describe_range_error(errcode);
2343 return JNI_EINVAL;
2344 }
2784 // Unknown option
2785 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2786 return JNI_ERR;
2787 }
2788 }
2789
2790 // PrintSharedArchiveAndExit will turn on
2791 // -Xshare:on
2792 // -Xlog:class+path=info
2793 if (PrintSharedArchiveAndExit) {
2794 UseSharedSpaces = true;
2795 RequireSharedSpaces = true;
2796 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2797 }
2798
2799 fix_appclasspath();
2800
2801 return JNI_OK;
2802 }
2803
2804 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool* patch_mod_javabase) {
2805 // For java.base check for duplicate --patch-module options being specified on the command line.
2806 // This check is only required for java.base, all other duplicate module specifications
2807 // will be checked during module system initialization. The module system initialization
2808 // will throw an ExceptionInInitializerError if this situation occurs.
2809 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2810 if (*patch_mod_javabase) {
2811 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2812 } else {
2813 *patch_mod_javabase = true;
2814 }
2815 }
2816
2817 // Create GrowableArray lazily, only if --patch-module has been specified
2818 if (_patch_mod_prefix == nullptr) {
2819 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2820 }
2821
2822 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2823 }
2824
2825 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2826 //
2827 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2828 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2829 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2830 // path is treated as the current directory.
2831 //
2832 // This causes problems with CDS, which requires that all directories specified in the classpath
2833 // must be empty. In most cases, applications do NOT want to load classes from the current
2834 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2835 // scripts compatible with CDS.
2836 void Arguments::fix_appclasspath() {
2837 if (IgnoreEmptyClassPaths) {
2838 const char separator = *os::path_separator();
2839 const char* src = _java_class_path->value();
2840
2841 // skip over all the leading empty paths
2842 while (*src == separator) {
2845
2846 char* copy = os::strdup_check_oom(src, mtArguments);
2847
2848 // trim all trailing empty paths
2849 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
2850 *tail = '\0';
2851 }
2852
2853 char from[3] = {separator, separator, '\0'};
2854 char to [2] = {separator, '\0'};
2855 while (StringUtils::replace_no_expand(copy, from, to) > 0) {
2856 // Keep replacing "::" -> ":" until we have no more "::" (non-windows)
2857 // Keep replacing ";;" -> ";" until we have no more ";;" (windows)
2858 }
2859
2860 _java_class_path->set_writeable_value(copy);
2861 FreeHeap(copy); // a copy was made by set_value, so don't need this anymore
2862 }
2863 }
2864
2865 jint Arguments::finalize_vm_init_args(bool patch_mod_javabase) {
2866 // check if the default lib/endorsed directory exists; if so, error
2867 char path[JVM_MAXPATHLEN];
2868 const char* fileSep = os::file_separator();
2869 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
2870
2871 DIR* dir = os::opendir(path);
2872 if (dir != nullptr) {
2873 jio_fprintf(defaultStream::output_stream(),
2874 "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n"
2875 "in modular form will be supported via the concept of upgradeable modules.\n");
2876 os::closedir(dir);
2877 return JNI_ERR;
2878 }
2879
2880 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
2881 dir = os::opendir(path);
2882 if (dir != nullptr) {
2883 jio_fprintf(defaultStream::output_stream(),
2884 "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; "
2885 "Use -classpath instead.\n.");
2919 if (FLAG_IS_DEFAULT(UseLargePages) &&
2920 MaxHeapSize < LargePageHeapSizeThreshold) {
2921 // No need for large granularity pages w/small heaps.
2922 // Note that large pages are enabled/disabled for both the
2923 // Java heap and the code cache.
2924 FLAG_SET_DEFAULT(UseLargePages, false);
2925 }
2926
2927 UNSUPPORTED_OPTION(ProfileInterpreter);
2928 #endif
2929
2930 // Parse the CompilationMode flag
2931 if (!CompilationModeFlag::initialize()) {
2932 return JNI_ERR;
2933 }
2934
2935 if (!check_vm_args_consistency()) {
2936 return JNI_ERR;
2937 }
2938
2939 if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) {
2940 return JNI_ERR;
2941 }
2942
2943 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
2944 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
2945 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2946
2947 return JNI_OK;
2948 }
2949
2950 // Helper class for controlling the lifetime of JavaVMInitArgs
2951 // objects. The contents of the JavaVMInitArgs are guaranteed to be
2952 // deleted on the destruction of the ScopedVMInitArgs object.
2953 class ScopedVMInitArgs : public StackObj {
2954 private:
2955 JavaVMInitArgs _args;
2956 char* _container_name;
2957 bool _is_set;
2958 char* _vm_options_file_arg;
2959
3676 #ifdef ZERO
3677 // Clear flags not supported on zero.
3678 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3679 #endif // ZERO
3680
3681 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3682 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3683 DebugNonSafepoints = true;
3684 }
3685
3686 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3687 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3688 }
3689
3690 // Treat the odd case where local verification is enabled but remote
3691 // verification is not as if both were enabled.
3692 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3693 log_info(verification)("Turning on remote verification because local verification is on");
3694 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3695 }
3696
3697 #ifndef PRODUCT
3698 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3699 if (use_vm_log()) {
3700 LogVMOutput = true;
3701 }
3702 }
3703 #endif // PRODUCT
3704
3705 if (PrintCommandLineFlags) {
3706 JVMFlag::printSetFlags(tty);
3707 }
3708
3709 #if COMPILER2_OR_JVMCI
3710 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3711 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3712 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3713 }
3714 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3715
|
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;
1756 }
1757 _sun_java_launcher = os::strdup_check_oom(launcher);
1758 }
1759
1760 bool Arguments::created_by_java_launcher() {
1761 assert(_sun_java_launcher != nullptr, "property must have value");
1762 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1763 }
1764
1765 bool Arguments::sun_java_launcher_is_altjvm() {
1766 return _sun_java_launcher_is_altjvm;
1767 }
1768
1769 //===========================================================================================================
1770 // Parsing of main arguments
1771
1772 unsigned int addreads_count = 0;
1773 unsigned int addexports_count = 0;
1774 unsigned int addopens_count = 0;
1775 unsigned int addmods_count = 0;
1776 unsigned int enable_native_access_count = 0;
1777
1778 // Check the consistency of vm_init_args
1779 bool Arguments::check_vm_args_consistency() {
1780 // Method for adding checks for flag consistency.
1781 // The intent is to warn the user of all possible conflicts,
1782 // before returning an error.
1783 // Note: Needs platform-dependent factoring.
1784 bool status = true;
1785
1786 if (TLABRefillWasteFraction == 0) {
1787 jio_fprintf(defaultStream::error_stream(),
1788 "TLABRefillWasteFraction should be a denominator, "
1789 "not " SIZE_FORMAT "\n",
1790 TLABRefillWasteFraction);
1791 status = false;
1792 }
1793
1794 status = CompilerConfig::check_args_consistency(status);
1795 #if INCLUDE_JVMCI
1802 }
1803 }
1804 }
1805 #endif
1806
1807 #if INCLUDE_JFR
1808 if (status && (FlightRecorderOptions || StartFlightRecording)) {
1809 if (!create_numbered_module_property("jdk.module.addmods", "jdk.jfr", addmods_count++)) {
1810 return false;
1811 }
1812 }
1813 #endif
1814
1815 #ifndef SUPPORT_RESERVED_STACK_AREA
1816 if (StackReservedPages != 0) {
1817 FLAG_SET_CMDLINE(StackReservedPages, 0);
1818 warning("Reserved Stack Area not supported on this platform");
1819 }
1820 #endif
1821
1822 if (AMD64_ONLY(false &&) AARCH64_ONLY(false &&) !FLAG_IS_DEFAULT(InlineTypePassFieldsAsArgs)) {
1823 FLAG_SET_CMDLINE(InlineTypePassFieldsAsArgs, false);
1824 warning("InlineTypePassFieldsAsArgs is not supported on this platform");
1825 }
1826
1827 if (AMD64_ONLY(false &&) AARCH64_ONLY(false &&) !FLAG_IS_DEFAULT(InlineTypeReturnedAsFields)) {
1828 FLAG_SET_CMDLINE(InlineTypeReturnedAsFields, false);
1829 warning("InlineTypeReturnedAsFields is not supported on this platform");
1830 }
1831
1832 #if !defined(X86) && !defined(AARCH64) && !defined(RISCV64) && !defined(ARM) && !defined(PPC64) && !defined(S390)
1833 if (LockingMode == LM_LIGHTWEIGHT) {
1834 FLAG_SET_CMDLINE(LockingMode, LM_LEGACY);
1835 warning("New lightweight locking not supported on this platform");
1836 }
1837 #endif
1838
1839 #if !defined(X86) && !defined(AARCH64) && !defined(PPC64) && !defined(RISCV64) && !defined(S390)
1840 if (LockingMode == LM_MONITOR) {
1841 jio_fprintf(defaultStream::error_stream(),
1842 "LockingMode == 0 (LM_MONITOR) is not fully implemented on this architecture\n");
1843 return false;
1844 }
1845 #endif
1846 #if defined(X86) && !defined(ZERO)
1847 if (LockingMode == LM_MONITOR && UseRTMForStackLocks) {
1848 jio_fprintf(defaultStream::error_stream(),
1849 "LockingMode == 0 (LM_MONITOR) and -XX:+UseRTMForStackLocks are mutually exclusive\n");
1850
1851 return false;
1938 }
1939
1940 jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
1941 return false;
1942 }
1943
1944 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
1945 julong* long_arg,
1946 julong min_size,
1947 julong max_size) {
1948 if (!parse_integer(s, long_arg)) return arg_unreadable;
1949 return check_memory_size(*long_arg, min_size, max_size);
1950 }
1951
1952 // Parse JavaVMInitArgs structure
1953
1954 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
1955 const JavaVMInitArgs *java_tool_options_args,
1956 const JavaVMInitArgs *java_options_args,
1957 const JavaVMInitArgs *cmd_line_args) {
1958 // Save default settings for some mode flags
1959 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
1960 Arguments::_UseOnStackReplacement = UseOnStackReplacement;
1961 Arguments::_ClipInlining = ClipInlining;
1962 Arguments::_BackgroundCompilation = BackgroundCompilation;
1963
1964 // Remember the default value of SharedBaseAddress.
1965 Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1966
1967 // Setup flags for mixed which is the default
1968 set_mode_flags(_mixed);
1969
1970 // Parse args structure generated from java.base vm options resource
1971 jint result = parse_each_vm_init_arg(vm_options_args, JVMFlagOrigin::JIMAGE_RESOURCE);
1972 if (result != JNI_OK) {
1973 return result;
1974 }
1975
1976 // Parse args structure generated from JAVA_TOOL_OPTIONS environment
1977 // variable (if present).
1978 result = parse_each_vm_init_arg(java_tool_options_args, JVMFlagOrigin::ENVIRON_VAR);
1979 if (result != JNI_OK) {
1980 return result;
1981 }
1982
1983 // Parse args structure generated from the command line flags.
1984 result = parse_each_vm_init_arg(cmd_line_args, JVMFlagOrigin::COMMAND_LINE);
1985 if (result != JNI_OK) {
1986 return result;
1987 }
1988
1989 // Parse args structure generated from the _JAVA_OPTIONS environment
1990 // variable (if present) (mimics classic VM)
1991 result = parse_each_vm_init_arg(java_options_args, JVMFlagOrigin::ENVIRON_VAR);
1992 if (result != JNI_OK) {
1993 return result;
1994 }
1995
1996 // Disable CDS for exploded image
1997 if (!has_jimage()) {
1998 no_shared_spaces("CDS disabled on exploded JDK");
1999 }
2000
2001 // We need to ensure processor and memory resources have been properly
2002 // configured - which may rely on arguments we just processed - before
2003 // doing the final argument processing. Any argument processing that
2004 // needs to know about processor and memory resources must occur after
2005 // this point.
2006
2007 os::init_container_support();
2008
2009 SystemMemoryBarrier::initialize();
2010
2011 // Do final processing now that all arguments have been parsed
2012 result = finalize_vm_init_args();
2013 if (result != JNI_OK) {
2014 return result;
2015 }
2016
2017 return JNI_OK;
2018 }
2019
2020 #if !INCLUDE_JVMTI
2021 // Checks if name in command-line argument -agent{lib,path}:name[=options]
2022 // represents a valid JDWP agent. is_path==true denotes that we
2023 // are dealing with -agentpath (case where name is a path), otherwise with
2024 // -agentlib
2025 static bool valid_jdwp_agent(char *name, bool is_path) {
2026 char *_name;
2027 const char *_jdwp = "jdwp";
2028 size_t _len_jdwp, _len_prefix;
2029
2030 if (is_path) {
2031 if ((_name = strrchr(name, (int) *os::file_separator())) == nullptr) {
2032 return false;
2047 }
2048 else {
2049 return false;
2050 }
2051
2052 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) {
2053 return false;
2054 }
2055
2056 return true;
2057 }
2058
2059 if (strcmp(name, _jdwp) == 0) {
2060 return true;
2061 }
2062
2063 return false;
2064 }
2065 #endif
2066
2067 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2068 // --patch-module=<module>=<file>(<pathsep><file>)*
2069 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2070 // Find the equal sign between the module name and the path specification
2071 const char* module_equal = strchr(patch_mod_tail, '=');
2072 if (module_equal == nullptr) {
2073 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2074 return JNI_ERR;
2075 } else {
2076 // Pick out the module name
2077 size_t module_len = module_equal - patch_mod_tail;
2078 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2079 if (module_name != nullptr) {
2080 memcpy(module_name, patch_mod_tail, module_len);
2081 *(module_name + module_len) = '\0';
2082 // The path piece begins one past the module_equal sign
2083 add_patch_mod_prefix(module_name, module_equal + 1, false /* no append */, false /* no cds */);
2084 FREE_C_HEAP_ARRAY(char, module_name);
2085 } else {
2086 return JNI_ENOMEM;
2087 }
2088 }
2089 return JNI_OK;
2090 }
2091
2092 // VALUECLASS_STR must match string used in the build
2093 #define VALUECLASS_STR "valueclasses"
2094 #define VALUECLASS_JAR "-" VALUECLASS_STR ".jar"
2095
2096 // Finalize --patch-module args and --enable-preview related to value class module patches.
2097 // Create all numbered properties passing module patches.
2098 int Arguments::finalize_patch_module() {
2099 // If --enable-preview and EnableValhalla is true, each module may have value classes that
2100 // are to be patched into the module.
2101 // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2102 // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2103 if (enable_preview() && EnableValhalla) {
2104 char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2105 const char * fileSep = os::file_separator();
2106
2107 jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s",
2108 Arguments::get_java_home(), fileSep, fileSep, fileSep);
2109 DIR* dir = os::opendir(valueclasses_dir);
2110 if (dir != nullptr) {
2111 char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2112 char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2113
2114 for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) {
2115 // Test if file ends-with "-valueclasses.jar"
2116 int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1);
2117 if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) {
2118 continue; // too short or not the expected suffix
2119 }
2120
2121 strcpy(module_name, entry->d_name);
2122 module_name[len] = '\0'; // truncate to just module-name
2123
2124 jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name);
2125 add_patch_mod_prefix(module_name, path, true /* append */, true /* cds OK*/);
2126 log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name);
2127 }
2128 FreeHeap(module_name);
2129 FreeHeap(path);
2130 os::closedir(dir);
2131 }
2132 FreeHeap(valueclasses_dir);
2133 }
2134
2135 // Create numbered properties for each module that has been patched either
2136 // by --patch-module or --enable-preview
2137 // Format is "jdk.module.patch.<n>=<module_name>=<path>"
2138 if (_patch_mod_prefix != nullptr) {
2139 char * prop_value = AllocateHeap(JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, mtArguments);
2140 unsigned int patch_mod_count = 0;
2141
2142 for (GrowableArrayIterator<ModulePatchPath *> it = _patch_mod_prefix->begin();
2143 it != _patch_mod_prefix->end(); ++it) {
2144 jio_snprintf(prop_value, JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, "%s=%s",
2145 (*it)->module_name(), (*it)->path_string());
2146 if (!create_numbered_module_property("jdk.module.patch", prop_value, patch_mod_count++)) {
2147 FreeHeap(prop_value);
2148 return JNI_ENOMEM;
2149 }
2150 }
2151 FreeHeap(prop_value);
2152 }
2153 return JNI_OK;
2154 }
2155
2156 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2157 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2158 // The min and max sizes match the values in globals.hpp, but scaled
2159 // with K. The values have been chosen so that alignment with page
2160 // size doesn't change the max value, which makes the conversions
2161 // back and forth between Xss value and ThreadStackSize value easier.
2162 // The values have also been chosen to fit inside a 32-bit signed type.
2163 const julong min_ThreadStackSize = 0;
2164 const julong max_ThreadStackSize = 1 * M;
2165
2166 // Make sure the above values match the range set in globals.hpp
2167 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2168 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2169 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2170
2171 const julong min_size = min_ThreadStackSize * K;
2172 const julong max_size = max_ThreadStackSize * K;
2173
2174 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2175
2190 assert(size <= size_aligned,
2191 "Overflow: " JULONG_FORMAT " " JULONG_FORMAT,
2192 size, size_aligned);
2193
2194 const julong size_in_K = size_aligned / K;
2195 assert(size_in_K < (julong)max_intx,
2196 "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT,
2197 size_in_K);
2198
2199 // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow.
2200 const julong max_expanded = align_up(size_in_K * K, os::vm_page_size());
2201 assert(max_expanded < max_uintx && max_expanded >= size_in_K,
2202 "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT,
2203 max_expanded, size_in_K);
2204
2205 *out_ThreadStackSize = (intx)size_in_K;
2206
2207 return JNI_OK;
2208 }
2209
2210 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, JVMFlagOrigin origin) {
2211 // For match_option to return remaining or value part of option string
2212 const char* tail;
2213
2214 // iterate over arguments
2215 for (int index = 0; index < args->nOptions; index++) {
2216 bool is_absolute_path = false; // for -agentpath vs -agentlib
2217
2218 const JavaVMOption* option = args->options + index;
2219
2220 if (!match_option(option, "-Djava.class.path", &tail) &&
2221 !match_option(option, "-Dsun.java.command", &tail) &&
2222 !match_option(option, "-Dsun.java.launcher", &tail)) {
2223
2224 // add all jvm options to the jvm_args string. This string
2225 // is used later to set the java.vm.args PerfData string constant.
2226 // the -Djava.class.path and the -Dsun.java.command options are
2227 // omitted from jvm_args string as each have their own PerfData
2228 // string constant object.
2229 build_jvm_args(option->optionString);
2230 }
2313 return JNI_ENOMEM;
2314 }
2315 } else if (match_option(option, "--enable-native-access=", &tail)) {
2316 if (!create_numbered_module_property("jdk.module.enable.native.access", tail, enable_native_access_count++)) {
2317 return JNI_ENOMEM;
2318 }
2319 } else if (match_option(option, "--limit-modules=", &tail)) {
2320 if (!create_module_property("jdk.module.limitmods", tail, InternalProperty)) {
2321 return JNI_ENOMEM;
2322 }
2323 } else if (match_option(option, "--module-path=", &tail)) {
2324 if (!create_module_property("jdk.module.path", tail, ExternalProperty)) {
2325 return JNI_ENOMEM;
2326 }
2327 } else if (match_option(option, "--upgrade-module-path=", &tail)) {
2328 if (!create_module_property("jdk.module.upgrade.path", tail, ExternalProperty)) {
2329 return JNI_ENOMEM;
2330 }
2331 } else if (match_option(option, "--patch-module=", &tail)) {
2332 // --patch-module=<module>=<file>(<pathsep><file>)*
2333 int res = process_patch_mod_option(tail);
2334 if (res != JNI_OK) {
2335 return res;
2336 }
2337 } else if (match_option(option, "--illegal-access=", &tail)) {
2338 char version[256];
2339 JDK_Version::jdk(17).to_string(version, sizeof(version));
2340 warning("Ignoring option %s; support was removed in %s", option->optionString, version);
2341 // -agentlib and -agentpath
2342 } else if (match_option(option, "-agentlib:", &tail) ||
2343 (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2344 if(tail != nullptr) {
2345 const char* pos = strchr(tail, '=');
2346 char* name;
2347 if (pos == nullptr) {
2348 name = os::strdup_check_oom(tail, mtArguments);
2349 } else {
2350 size_t len = pos - tail;
2351 name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments);
2352 memcpy(name, tail, len);
2353 name[len] = '\0';
2374 jio_fprintf(defaultStream::error_stream(),
2375 "Instrumentation agents are not supported in this VM\n");
2376 return JNI_ERR;
2377 #else
2378 if (tail != nullptr) {
2379 size_t length = strlen(tail) + 1;
2380 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2381 jio_snprintf(options, length, "%s", tail);
2382 JvmtiAgentList::add("instrument", options, false);
2383 FREE_C_HEAP_ARRAY(char, options);
2384
2385 // java agents need module java.instrument
2386 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", addmods_count++)) {
2387 return JNI_ENOMEM;
2388 }
2389 }
2390 #endif // !INCLUDE_JVMTI
2391 // --enable_preview
2392 } else if (match_option(option, "--enable-preview")) {
2393 set_enable_preview();
2394 // --enable-preview enables Valhalla, EnableValhalla VM option will eventually be removed before integration
2395 if (FLAG_SET_CMDLINE(EnableValhalla, true) != JVMFlag::SUCCESS) {
2396 return JNI_EINVAL;
2397 }
2398 // -Xnoclassgc
2399 } else if (match_option(option, "-Xnoclassgc")) {
2400 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2401 return JNI_EINVAL;
2402 }
2403 // -Xbatch
2404 } else if (match_option(option, "-Xbatch")) {
2405 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2406 return JNI_EINVAL;
2407 }
2408 // -Xmn for compatibility with other JVM vendors
2409 } else if (match_option(option, "-Xmn", &tail)) {
2410 julong long_initial_young_size = 0;
2411 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2412 if (errcode != arg_in_range) {
2413 jio_fprintf(defaultStream::error_stream(),
2414 "Invalid initial young generation size: %s\n", option->optionString);
2415 describe_range_error(errcode);
2416 return JNI_EINVAL;
2417 }
2857 // Unknown option
2858 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2859 return JNI_ERR;
2860 }
2861 }
2862
2863 // PrintSharedArchiveAndExit will turn on
2864 // -Xshare:on
2865 // -Xlog:class+path=info
2866 if (PrintSharedArchiveAndExit) {
2867 UseSharedSpaces = true;
2868 RequireSharedSpaces = true;
2869 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2870 }
2871
2872 fix_appclasspath();
2873
2874 return JNI_OK;
2875 }
2876
2877 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) {
2878 if (!allow_cds) {
2879 CDSConfig::set_module_patching_disables_cds();
2880 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2881 CDSConfig::set_java_base_module_patching_disables_cds();
2882 }
2883 }
2884
2885 // Create GrowableArray lazily, only if --patch-module has been specified
2886 if (_patch_mod_prefix == nullptr) {
2887 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2888 }
2889
2890 // Scan patches for matching module
2891 int i = _patch_mod_prefix->find_if([&](ModulePatchPath* patch) {
2892 return (strcmp(module_name, patch->module_name()) == 0);
2893 });
2894 if (i == -1) {
2895 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2896 } else {
2897 if (allow_append) {
2898 // append path to existing module entry
2899 _patch_mod_prefix->at(i)->append_path(path);
2900 } else {
2901 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2902 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2903 } else {
2904 vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
2905 }
2906 }
2907 }
2908 }
2909
2910 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2911 //
2912 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2913 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2914 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2915 // path is treated as the current directory.
2916 //
2917 // This causes problems with CDS, which requires that all directories specified in the classpath
2918 // must be empty. In most cases, applications do NOT want to load classes from the current
2919 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2920 // scripts compatible with CDS.
2921 void Arguments::fix_appclasspath() {
2922 if (IgnoreEmptyClassPaths) {
2923 const char separator = *os::path_separator();
2924 const char* src = _java_class_path->value();
2925
2926 // skip over all the leading empty paths
2927 while (*src == separator) {
2930
2931 char* copy = os::strdup_check_oom(src, mtArguments);
2932
2933 // trim all trailing empty paths
2934 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
2935 *tail = '\0';
2936 }
2937
2938 char from[3] = {separator, separator, '\0'};
2939 char to [2] = {separator, '\0'};
2940 while (StringUtils::replace_no_expand(copy, from, to) > 0) {
2941 // Keep replacing "::" -> ":" until we have no more "::" (non-windows)
2942 // Keep replacing ";;" -> ";" until we have no more ";;" (windows)
2943 }
2944
2945 _java_class_path->set_writeable_value(copy);
2946 FreeHeap(copy); // a copy was made by set_value, so don't need this anymore
2947 }
2948 }
2949
2950 jint Arguments::finalize_vm_init_args() {
2951 // check if the default lib/endorsed directory exists; if so, error
2952 char path[JVM_MAXPATHLEN];
2953 const char* fileSep = os::file_separator();
2954 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
2955
2956 DIR* dir = os::opendir(path);
2957 if (dir != nullptr) {
2958 jio_fprintf(defaultStream::output_stream(),
2959 "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n"
2960 "in modular form will be supported via the concept of upgradeable modules.\n");
2961 os::closedir(dir);
2962 return JNI_ERR;
2963 }
2964
2965 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
2966 dir = os::opendir(path);
2967 if (dir != nullptr) {
2968 jio_fprintf(defaultStream::output_stream(),
2969 "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; "
2970 "Use -classpath instead.\n.");
3004 if (FLAG_IS_DEFAULT(UseLargePages) &&
3005 MaxHeapSize < LargePageHeapSizeThreshold) {
3006 // No need for large granularity pages w/small heaps.
3007 // Note that large pages are enabled/disabled for both the
3008 // Java heap and the code cache.
3009 FLAG_SET_DEFAULT(UseLargePages, false);
3010 }
3011
3012 UNSUPPORTED_OPTION(ProfileInterpreter);
3013 #endif
3014
3015 // Parse the CompilationMode flag
3016 if (!CompilationModeFlag::initialize()) {
3017 return JNI_ERR;
3018 }
3019
3020 if (!check_vm_args_consistency()) {
3021 return JNI_ERR;
3022 }
3023
3024 // finalize --module-patch and related --enable-preview
3025 if (finalize_patch_module() != JNI_OK) {
3026 return JNI_ERR;
3027 }
3028
3029 if (!CDSConfig::check_vm_args_consistency(mode_flag_cmd_line)) {
3030 return JNI_ERR;
3031 }
3032
3033 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3034 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3035 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3036
3037 return JNI_OK;
3038 }
3039
3040 // Helper class for controlling the lifetime of JavaVMInitArgs
3041 // objects. The contents of the JavaVMInitArgs are guaranteed to be
3042 // deleted on the destruction of the ScopedVMInitArgs object.
3043 class ScopedVMInitArgs : public StackObj {
3044 private:
3045 JavaVMInitArgs _args;
3046 char* _container_name;
3047 bool _is_set;
3048 char* _vm_options_file_arg;
3049
3766 #ifdef ZERO
3767 // Clear flags not supported on zero.
3768 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3769 #endif // ZERO
3770
3771 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3772 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3773 DebugNonSafepoints = true;
3774 }
3775
3776 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3777 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3778 }
3779
3780 // Treat the odd case where local verification is enabled but remote
3781 // verification is not as if both were enabled.
3782 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3783 log_info(verification)("Turning on remote verification because local verification is on");
3784 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3785 }
3786 if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) {
3787 // Disable calling convention optimizations if inline types are not supported.
3788 // Also these aren't useful in -Xint. However, don't disable them when dumping or using
3789 // the CDS archive, as the values must match between dumptime and runtime.
3790 InlineTypePassFieldsAsArgs = false;
3791 InlineTypeReturnedAsFields = false;
3792 }
3793
3794 #ifndef PRODUCT
3795 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3796 if (use_vm_log()) {
3797 LogVMOutput = true;
3798 }
3799 }
3800 #endif // PRODUCT
3801
3802 if (PrintCommandLineFlags) {
3803 JVMFlag::printSetFlags(tty);
3804 }
3805
3806 #if COMPILER2_OR_JVMCI
3807 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3808 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3809 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3810 }
3811 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3812
|