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