1 /*
2 * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
52 #include "runtime/java.hpp"
53 #include "runtime/os.hpp"
54 #include "runtime/safepoint.hpp"
55 #include "runtime/safepointMechanism.hpp"
56 #include "runtime/synchronizer.hpp"
57 #include "runtime/vm_version.hpp"
58 #include "services/management.hpp"
59 #include "services/nmtCommon.hpp"
60 #include "utilities/align.hpp"
61 #include "utilities/debug.hpp"
62 #include "utilities/defaultStream.hpp"
63 #include "utilities/macros.hpp"
64 #include "utilities/parseInteger.hpp"
65 #include "utilities/powerOfTwo.hpp"
66 #include "utilities/stringUtils.hpp"
67 #if INCLUDE_JFR
68 #include "jfr/jfr.hpp"
69 #endif
70
71 #include <limits>
72
73 #define DEFAULT_JAVA_LAUNCHER "generic"
74
75 char* Arguments::_jvm_flags_file = NULL;
76 char** Arguments::_jvm_flags_array = NULL;
77 int Arguments::_num_jvm_flags = 0;
78 char** Arguments::_jvm_args_array = NULL;
79 int Arguments::_num_jvm_args = 0;
80 char* Arguments::_java_command = NULL;
81 SystemProperty* Arguments::_system_properties = NULL;
82 size_t Arguments::_conservative_max_heap_alignment = 0;
83 Arguments::Mode Arguments::_mode = _mixed;
84 bool Arguments::_java_compiler = false;
85 bool Arguments::_xdebug_mode = false;
86 const char* Arguments::_java_vendor_url_bug = NULL;
87 const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
88 bool Arguments::_sun_java_launcher_is_altjvm = false;
89
90 // These parameters are reset in method parse_vm_init_args()
91 bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
1906 void Arguments::process_java_launcher_argument(const char* launcher, void* extra_info) {
1907 _sun_java_launcher = os::strdup_check_oom(launcher);
1908 }
1909
1910 bool Arguments::created_by_java_launcher() {
1911 assert(_sun_java_launcher != NULL, "property must have value");
1912 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1913 }
1914
1915 bool Arguments::sun_java_launcher_is_altjvm() {
1916 return _sun_java_launcher_is_altjvm;
1917 }
1918
1919 //===========================================================================================================
1920 // Parsing of main arguments
1921
1922 unsigned int addreads_count = 0;
1923 unsigned int addexports_count = 0;
1924 unsigned int addopens_count = 0;
1925 unsigned int addmods_count = 0;
1926 unsigned int patch_mod_count = 0;
1927 unsigned int enable_native_access_count = 0;
1928
1929 // Check the consistency of vm_init_args
1930 bool Arguments::check_vm_args_consistency() {
1931 // Method for adding checks for flag consistency.
1932 // The intent is to warn the user of all possible conflicts,
1933 // before returning an error.
1934 // Note: Needs platform-dependent factoring.
1935 bool status = true;
1936
1937 if (TLABRefillWasteFraction == 0) {
1938 jio_fprintf(defaultStream::error_stream(),
1939 "TLABRefillWasteFraction should be a denominator, "
1940 "not " SIZE_FORMAT "\n",
1941 TLABRefillWasteFraction);
1942 status = false;
1943 }
1944
1945 status = CompilerConfig::check_args_consistency(status);
1946 #if INCLUDE_JVMCI
1953 }
1954 }
1955 }
1956 #endif
1957
1958 #if INCLUDE_JFR
1959 if (status && (FlightRecorderOptions || StartFlightRecording)) {
1960 if (!create_numbered_module_property("jdk.module.addmods", "jdk.jfr", addmods_count++)) {
1961 return false;
1962 }
1963 }
1964 #endif
1965
1966 #ifndef SUPPORT_RESERVED_STACK_AREA
1967 if (StackReservedPages != 0) {
1968 FLAG_SET_CMDLINE(StackReservedPages, 0);
1969 warning("Reserved Stack Area not supported on this platform");
1970 }
1971 #endif
1972
1973 #if !defined(X86) && !defined(AARCH64) && !defined(PPC64) && !defined(RISCV64)
1974 if (UseHeavyMonitors) {
1975 jio_fprintf(defaultStream::error_stream(),
1976 "UseHeavyMonitors is not fully implemented on this architecture");
1977 return false;
1978 }
1979 #endif
1980 #if (defined(X86) || defined(PPC64)) && !defined(ZERO)
1981 if (UseHeavyMonitors && UseRTMForStackLocks) {
1982 jio_fprintf(defaultStream::error_stream(),
1983 "-XX:+UseHeavyMonitors and -XX:+UseRTMForStackLocks are mutually exclusive");
1984
1985 return false;
1986 }
1987 #endif
1988 if (VerifyHeavyMonitors && !UseHeavyMonitors) {
1989 jio_fprintf(defaultStream::error_stream(),
1990 "-XX:+VerifyHeavyMonitors requires -XX:+UseHeavyMonitors");
1991 return false;
1992 }
2073 }
2074
2075 jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
2076 return false;
2077 }
2078
2079 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
2080 julong* long_arg,
2081 julong min_size,
2082 julong max_size) {
2083 if (!parse_integer(s, long_arg)) return arg_unreadable;
2084 return check_memory_size(*long_arg, min_size, max_size);
2085 }
2086
2087 // Parse JavaVMInitArgs structure
2088
2089 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
2090 const JavaVMInitArgs *java_tool_options_args,
2091 const JavaVMInitArgs *java_options_args,
2092 const JavaVMInitArgs *cmd_line_args) {
2093 bool patch_mod_javabase = false;
2094
2095 // Save default settings for some mode flags
2096 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
2097 Arguments::_UseOnStackReplacement = UseOnStackReplacement;
2098 Arguments::_ClipInlining = ClipInlining;
2099 Arguments::_BackgroundCompilation = BackgroundCompilation;
2100
2101 // Remember the default value of SharedBaseAddress.
2102 Arguments::_default_SharedBaseAddress = SharedBaseAddress;
2103
2104 // Setup flags for mixed which is the default
2105 set_mode_flags(_mixed);
2106
2107 // Parse args structure generated from java.base vm options resource
2108 jint result = parse_each_vm_init_arg(vm_options_args, &patch_mod_javabase, JVMFlagOrigin::JIMAGE_RESOURCE);
2109 if (result != JNI_OK) {
2110 return result;
2111 }
2112
2113 // Parse args structure generated from JAVA_TOOL_OPTIONS environment
2114 // variable (if present).
2115 result = parse_each_vm_init_arg(java_tool_options_args, &patch_mod_javabase, JVMFlagOrigin::ENVIRON_VAR);
2116 if (result != JNI_OK) {
2117 return result;
2118 }
2119
2120 // Parse args structure generated from the command line flags.
2121 result = parse_each_vm_init_arg(cmd_line_args, &patch_mod_javabase, JVMFlagOrigin::COMMAND_LINE);
2122 if (result != JNI_OK) {
2123 return result;
2124 }
2125
2126 // Parse args structure generated from the _JAVA_OPTIONS environment
2127 // variable (if present) (mimics classic VM)
2128 result = parse_each_vm_init_arg(java_options_args, &patch_mod_javabase, JVMFlagOrigin::ENVIRON_VAR);
2129 if (result != JNI_OK) {
2130 return result;
2131 }
2132
2133 // We need to ensure processor and memory resources have been properly
2134 // configured - which may rely on arguments we just processed - before
2135 // doing the final argument processing. Any argument processing that
2136 // needs to know about processor and memory resources must occur after
2137 // this point.
2138
2139 os::init_container_support();
2140
2141 // Do final processing now that all arguments have been parsed
2142 result = finalize_vm_init_args(patch_mod_javabase);
2143 if (result != JNI_OK) {
2144 return result;
2145 }
2146
2147 return JNI_OK;
2148 }
2149
2150 // Checks if name in command-line argument -agent{lib,path}:name[=options]
2151 // represents a valid JDWP agent. is_path==true denotes that we
2152 // are dealing with -agentpath (case where name is a path), otherwise with
2153 // -agentlib
2154 bool valid_jdwp_agent(char *name, bool is_path) {
2155 char *_name;
2156 const char *_jdwp = "jdwp";
2157 size_t _len_jdwp, _len_prefix;
2158
2159 if (is_path) {
2160 if ((_name = strrchr(name, (int) *os::file_separator())) == NULL) {
2161 return false;
2162 }
2175 _name += _len_jdwp;
2176 }
2177 else {
2178 return false;
2179 }
2180
2181 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) {
2182 return false;
2183 }
2184
2185 return true;
2186 }
2187
2188 if (strcmp(name, _jdwp) == 0) {
2189 return true;
2190 }
2191
2192 return false;
2193 }
2194
2195 int Arguments::process_patch_mod_option(const char* patch_mod_tail, bool* patch_mod_javabase) {
2196 // --patch-module=<module>=<file>(<pathsep><file>)*
2197 assert(patch_mod_tail != NULL, "Unexpected NULL patch-module value");
2198 // Find the equal sign between the module name and the path specification
2199 const char* module_equal = strchr(patch_mod_tail, '=');
2200 if (module_equal == NULL) {
2201 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2202 return JNI_ERR;
2203 } else {
2204 // Pick out the module name
2205 size_t module_len = module_equal - patch_mod_tail;
2206 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2207 if (module_name != NULL) {
2208 memcpy(module_name, patch_mod_tail, module_len);
2209 *(module_name + module_len) = '\0';
2210 // The path piece begins one past the module_equal sign
2211 add_patch_mod_prefix(module_name, module_equal + 1, patch_mod_javabase);
2212 FREE_C_HEAP_ARRAY(char, module_name);
2213 if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
2214 return JNI_ENOMEM;
2215 }
2216 } else {
2217 return JNI_ENOMEM;
2218 }
2219 }
2220 return JNI_OK;
2221 }
2222
2223 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2224 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2225 // The min and max sizes match the values in globals.hpp, but scaled
2226 // with K. The values have been chosen so that alignment with page
2227 // size doesn't change the max value, which makes the conversions
2228 // back and forth between Xss value and ThreadStackSize value easier.
2229 // The values have also been chosen to fit inside a 32-bit signed type.
2230 const julong min_ThreadStackSize = 0;
2231 const julong max_ThreadStackSize = 1 * M;
2232
2233 // Make sure the above values match the range set in globals.hpp
2234 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2235 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2236 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2237
2238 const julong min_size = min_ThreadStackSize * K;
2239 const julong max_size = max_ThreadStackSize * K;
2240
2241 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2242
2257 assert(size <= size_aligned,
2258 "Overflow: " JULONG_FORMAT " " JULONG_FORMAT,
2259 size, size_aligned);
2260
2261 const julong size_in_K = size_aligned / K;
2262 assert(size_in_K < (julong)max_intx,
2263 "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT,
2264 size_in_K);
2265
2266 // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow.
2267 const julong max_expanded = align_up(size_in_K * K, os::vm_page_size());
2268 assert(max_expanded < max_uintx && max_expanded >= size_in_K,
2269 "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT,
2270 max_expanded, size_in_K);
2271
2272 *out_ThreadStackSize = (intx)size_in_K;
2273
2274 return JNI_OK;
2275 }
2276
2277 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_mod_javabase, JVMFlagOrigin origin) {
2278 // For match_option to return remaining or value part of option string
2279 const char* tail;
2280
2281 // iterate over arguments
2282 for (int index = 0; index < args->nOptions; index++) {
2283 bool is_absolute_path = false; // for -agentpath vs -agentlib
2284
2285 const JavaVMOption* option = args->options + index;
2286
2287 if (!match_option(option, "-Djava.class.path", &tail) &&
2288 !match_option(option, "-Dsun.java.command", &tail) &&
2289 !match_option(option, "-Dsun.java.launcher", &tail)) {
2290
2291 // add all jvm options to the jvm_args string. This string
2292 // is used later to set the java.vm.args PerfData string constant.
2293 // the -Djava.class.path and the -Dsun.java.command options are
2294 // omitted from jvm_args string as each have their own PerfData
2295 // string constant object.
2296 build_jvm_args(option->optionString);
2297 }
2382 return JNI_ENOMEM;
2383 }
2384 } else if (match_option(option, "--enable-native-access=", &tail)) {
2385 if (!create_numbered_module_property("jdk.module.enable.native.access", tail, enable_native_access_count++)) {
2386 return JNI_ENOMEM;
2387 }
2388 } else if (match_option(option, "--limit-modules=", &tail)) {
2389 if (!create_module_property("jdk.module.limitmods", tail, InternalProperty)) {
2390 return JNI_ENOMEM;
2391 }
2392 } else if (match_option(option, "--module-path=", &tail)) {
2393 if (!create_module_property("jdk.module.path", tail, ExternalProperty)) {
2394 return JNI_ENOMEM;
2395 }
2396 } else if (match_option(option, "--upgrade-module-path=", &tail)) {
2397 if (!create_module_property("jdk.module.upgrade.path", tail, ExternalProperty)) {
2398 return JNI_ENOMEM;
2399 }
2400 } else if (match_option(option, "--patch-module=", &tail)) {
2401 // --patch-module=<module>=<file>(<pathsep><file>)*
2402 int res = process_patch_mod_option(tail, patch_mod_javabase);
2403 if (res != JNI_OK) {
2404 return res;
2405 }
2406 } else if (match_option(option, "--illegal-access=", &tail)) {
2407 char version[256];
2408 JDK_Version::jdk(17).to_string(version, sizeof(version));
2409 warning("Ignoring option %s; support was removed in %s", option->optionString, version);
2410 // -agentlib and -agentpath
2411 } else if (match_option(option, "-agentlib:", &tail) ||
2412 (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2413 if(tail != NULL) {
2414 const char* pos = strchr(tail, '=');
2415 char* name;
2416 if (pos == NULL) {
2417 name = os::strdup_check_oom(tail, mtArguments);
2418 } else {
2419 size_t len = pos - tail;
2420 name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments);
2421 memcpy(name, tail, len);
2422 name[len] = '\0';
2891 #endif // INCLUDE_JVMCI
2892 #if INCLUDE_JFR
2893 } else if (match_jfr_option(&option)) {
2894 return JNI_EINVAL;
2895 #endif
2896 } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx
2897 // Skip -XX:Flags= and -XX:VMOptionsFile= since those cases have
2898 // already been handled
2899 if ((strncmp(tail, "Flags=", strlen("Flags=")) != 0) &&
2900 (strncmp(tail, "VMOptionsFile=", strlen("VMOptionsFile=")) != 0)) {
2901 if (!process_argument(tail, args->ignoreUnrecognized, origin)) {
2902 return JNI_EINVAL;
2903 }
2904 }
2905 // Unknown option
2906 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2907 return JNI_ERR;
2908 }
2909 }
2910
2911 // PrintSharedArchiveAndExit will turn on
2912 // -Xshare:on
2913 // -Xlog:class+path=info
2914 if (PrintSharedArchiveAndExit) {
2915 UseSharedSpaces = true;
2916 RequireSharedSpaces = true;
2917 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2918 }
2919
2920 fix_appclasspath();
2921
2922 return JNI_OK;
2923 }
2924
2925 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool* patch_mod_javabase) {
2926 // For java.base check for duplicate --patch-module options being specified on the command line.
2927 // This check is only required for java.base, all other duplicate module specifications
2928 // will be checked during module system initialization. The module system initialization
2929 // will throw an ExceptionInInitializerError if this situation occurs.
2930 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2931 if (*patch_mod_javabase) {
2932 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2933 } else {
2934 *patch_mod_javabase = true;
2935 }
2936 }
2937
2938 // Create GrowableArray lazily, only if --patch-module has been specified
2939 if (_patch_mod_prefix == NULL) {
2940 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2941 }
2942
2943 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2944 }
2945
2946 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2947 //
2948 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2949 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2950 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2951 // path is treated as the current directory.
2952 //
2953 // This causes problems with CDS, which requires that all directories specified in the classpath
2954 // must be empty. In most cases, applications do NOT want to load classes from the current
2955 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2956 // scripts compatible with CDS.
2957 void Arguments::fix_appclasspath() {
2958 if (IgnoreEmptyClassPaths) {
2959 const char separator = *os::path_separator();
2960 const char* src = _java_class_path->value();
2961
2962 // skip over all the leading empty paths
2963 while (*src == separator) {
2966
2967 char* copy = os::strdup_check_oom(src, mtArguments);
2968
2969 // trim all trailing empty paths
2970 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
2971 *tail = '\0';
2972 }
2973
2974 char from[3] = {separator, separator, '\0'};
2975 char to [2] = {separator, '\0'};
2976 while (StringUtils::replace_no_expand(copy, from, to) > 0) {
2977 // Keep replacing "::" -> ":" until we have no more "::" (non-windows)
2978 // Keep replacing ";;" -> ";" until we have no more ";;" (windows)
2979 }
2980
2981 _java_class_path->set_writeable_value(copy);
2982 FreeHeap(copy); // a copy was made by set_value, so don't need this anymore
2983 }
2984 }
2985
2986 jint Arguments::finalize_vm_init_args(bool patch_mod_javabase) {
2987 // check if the default lib/endorsed directory exists; if so, error
2988 char path[JVM_MAXPATHLEN];
2989 const char* fileSep = os::file_separator();
2990 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
2991
2992 DIR* dir = os::opendir(path);
2993 if (dir != NULL) {
2994 jio_fprintf(defaultStream::output_stream(),
2995 "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n"
2996 "in modular form will be supported via the concept of upgradeable modules.\n");
2997 os::closedir(dir);
2998 return JNI_ERR;
2999 }
3000
3001 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
3002 dir = os::opendir(path);
3003 if (dir != NULL) {
3004 jio_fprintf(defaultStream::output_stream(),
3005 "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; "
3006 "Use -classpath instead.\n.");
3049 if (FLAG_IS_DEFAULT(UseLargePages) &&
3050 MaxHeapSize < LargePageHeapSizeThreshold) {
3051 // No need for large granularity pages w/small heaps.
3052 // Note that large pages are enabled/disabled for both the
3053 // Java heap and the code cache.
3054 FLAG_SET_DEFAULT(UseLargePages, false);
3055 }
3056
3057 UNSUPPORTED_OPTION(ProfileInterpreter);
3058 #endif
3059
3060 // Parse the CompilationMode flag
3061 if (!CompilationModeFlag::initialize()) {
3062 return JNI_ERR;
3063 }
3064
3065 if (!check_vm_args_consistency()) {
3066 return JNI_ERR;
3067 }
3068
3069 #if INCLUDE_CDS
3070 if (DumpSharedSpaces) {
3071 // Compiler threads may concurrently update the class metadata (such as method entries), so it's
3072 // unsafe with -Xshare:dump (which modifies the class metadata in place). Let's disable
3073 // compiler just to be safe.
3074 //
3075 // Note: this is not a concern for dynamically dumping shared spaces, which makes a copy of the
3076 // class metadata instead of modifying them in place. The copy is inaccessible to the compiler.
3077 // TODO: revisit the following for the static archive case.
3078 set_mode_flags(_int);
3079 }
3080
3081 // RecordDynamicDumpInfo is not compatible with ArchiveClassesAtExit
3082 if (ArchiveClassesAtExit != NULL && RecordDynamicDumpInfo) {
3083 jio_fprintf(defaultStream::output_stream(),
3084 "-XX:+RecordDynamicDumpInfo cannot be used with -XX:ArchiveClassesAtExit.\n");
3085 return JNI_ERR;
3086 }
3087
3088 if (ArchiveClassesAtExit == NULL && !RecordDynamicDumpInfo) {
3089 DynamicDumpSharedSpaces = false;
3090 } else {
3091 DynamicDumpSharedSpaces = true;
3092 }
3093
3094 if (AutoCreateSharedArchive) {
3095 if (SharedArchiveFile == NULL) {
3096 log_warning(cds)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
3097 return JNI_ERR;
3098 }
3099 if (ArchiveClassesAtExit != NULL) {
3100 log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
3101 return JNI_ERR;
3102 }
3103 }
3104
3105 if (UseSharedSpaces && patch_mod_javabase) {
3106 no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
3107 }
3108 if (UseSharedSpaces && !DumpSharedSpaces && check_unsupported_cds_runtime_properties()) {
3109 UseSharedSpaces = false;
3110 }
3111
3112 if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
3113 // Always verify non-system classes during CDS dump
3114 if (!BytecodeVerificationRemote) {
3115 BytecodeVerificationRemote = true;
3116 log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
3117 }
3118 }
3119 #endif
3120
3121 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3122 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3123 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3124
3125 return JNI_OK;
4035 #ifdef ZERO
4036 // Clear flags not supported on zero.
4037 FLAG_SET_DEFAULT(ProfileInterpreter, false);
4038 #endif // ZERO
4039
4040 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
4041 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
4042 DebugNonSafepoints = true;
4043 }
4044
4045 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
4046 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
4047 }
4048
4049 // Treat the odd case where local verification is enabled but remote
4050 // verification is not as if both were enabled.
4051 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
4052 log_info(verification)("Turning on remote verification because local verification is on");
4053 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
4054 }
4055
4056 #ifndef PRODUCT
4057 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
4058 if (use_vm_log()) {
4059 LogVMOutput = true;
4060 }
4061 }
4062 #endif // PRODUCT
4063
4064 if (PrintCommandLineFlags) {
4065 JVMFlag::printSetFlags(tty);
4066 }
4067
4068 #ifdef COMPILER2
4069 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
4070 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
4071 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
4072 }
4073 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
4074
|
1 /*
2 * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
52 #include "runtime/java.hpp"
53 #include "runtime/os.hpp"
54 #include "runtime/safepoint.hpp"
55 #include "runtime/safepointMechanism.hpp"
56 #include "runtime/synchronizer.hpp"
57 #include "runtime/vm_version.hpp"
58 #include "services/management.hpp"
59 #include "services/nmtCommon.hpp"
60 #include "utilities/align.hpp"
61 #include "utilities/debug.hpp"
62 #include "utilities/defaultStream.hpp"
63 #include "utilities/macros.hpp"
64 #include "utilities/parseInteger.hpp"
65 #include "utilities/powerOfTwo.hpp"
66 #include "utilities/stringUtils.hpp"
67 #if INCLUDE_JFR
68 #include "jfr/jfr.hpp"
69 #endif
70
71 #include <limits>
72 #include <string.h>
73
74 #define DEFAULT_JAVA_LAUNCHER "generic"
75
76 char* Arguments::_jvm_flags_file = NULL;
77 char** Arguments::_jvm_flags_array = NULL;
78 int Arguments::_num_jvm_flags = 0;
79 char** Arguments::_jvm_args_array = NULL;
80 int Arguments::_num_jvm_args = 0;
81 char* Arguments::_java_command = NULL;
82 SystemProperty* Arguments::_system_properties = NULL;
83 size_t Arguments::_conservative_max_heap_alignment = 0;
84 Arguments::Mode Arguments::_mode = _mixed;
85 bool Arguments::_java_compiler = false;
86 bool Arguments::_xdebug_mode = false;
87 const char* Arguments::_java_vendor_url_bug = NULL;
88 const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
89 bool Arguments::_sun_java_launcher_is_altjvm = false;
90
91 // These parameters are reset in method parse_vm_init_args()
92 bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
1907 void Arguments::process_java_launcher_argument(const char* launcher, void* extra_info) {
1908 _sun_java_launcher = os::strdup_check_oom(launcher);
1909 }
1910
1911 bool Arguments::created_by_java_launcher() {
1912 assert(_sun_java_launcher != NULL, "property must have value");
1913 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1914 }
1915
1916 bool Arguments::sun_java_launcher_is_altjvm() {
1917 return _sun_java_launcher_is_altjvm;
1918 }
1919
1920 //===========================================================================================================
1921 // Parsing of main arguments
1922
1923 unsigned int addreads_count = 0;
1924 unsigned int addexports_count = 0;
1925 unsigned int addopens_count = 0;
1926 unsigned int addmods_count = 0;
1927 unsigned int enable_native_access_count = 0;
1928
1929 // Check the consistency of vm_init_args
1930 bool Arguments::check_vm_args_consistency() {
1931 // Method for adding checks for flag consistency.
1932 // The intent is to warn the user of all possible conflicts,
1933 // before returning an error.
1934 // Note: Needs platform-dependent factoring.
1935 bool status = true;
1936
1937 if (TLABRefillWasteFraction == 0) {
1938 jio_fprintf(defaultStream::error_stream(),
1939 "TLABRefillWasteFraction should be a denominator, "
1940 "not " SIZE_FORMAT "\n",
1941 TLABRefillWasteFraction);
1942 status = false;
1943 }
1944
1945 status = CompilerConfig::check_args_consistency(status);
1946 #if INCLUDE_JVMCI
1953 }
1954 }
1955 }
1956 #endif
1957
1958 #if INCLUDE_JFR
1959 if (status && (FlightRecorderOptions || StartFlightRecording)) {
1960 if (!create_numbered_module_property("jdk.module.addmods", "jdk.jfr", addmods_count++)) {
1961 return false;
1962 }
1963 }
1964 #endif
1965
1966 #ifndef SUPPORT_RESERVED_STACK_AREA
1967 if (StackReservedPages != 0) {
1968 FLAG_SET_CMDLINE(StackReservedPages, 0);
1969 warning("Reserved Stack Area not supported on this platform");
1970 }
1971 #endif
1972
1973 if (AMD64_ONLY(false &&) AARCH64_ONLY(false &&) !FLAG_IS_DEFAULT(InlineTypePassFieldsAsArgs)) {
1974 FLAG_SET_CMDLINE(InlineTypePassFieldsAsArgs, false);
1975 warning("InlineTypePassFieldsAsArgs is not supported on this platform");
1976 }
1977
1978 if (AMD64_ONLY(false &&) AARCH64_ONLY(false &&) !FLAG_IS_DEFAULT(InlineTypeReturnedAsFields)) {
1979 FLAG_SET_CMDLINE(InlineTypeReturnedAsFields, false);
1980 warning("InlineTypeReturnedAsFields is not supported on this platform");
1981 }
1982
1983 #if !defined(X86) && !defined(AARCH64) && !defined(PPC64) && !defined(RISCV64)
1984 if (UseHeavyMonitors) {
1985 jio_fprintf(defaultStream::error_stream(),
1986 "UseHeavyMonitors is not fully implemented on this architecture");
1987 return false;
1988 }
1989 #endif
1990 #if (defined(X86) || defined(PPC64)) && !defined(ZERO)
1991 if (UseHeavyMonitors && UseRTMForStackLocks) {
1992 jio_fprintf(defaultStream::error_stream(),
1993 "-XX:+UseHeavyMonitors and -XX:+UseRTMForStackLocks are mutually exclusive");
1994
1995 return false;
1996 }
1997 #endif
1998 if (VerifyHeavyMonitors && !UseHeavyMonitors) {
1999 jio_fprintf(defaultStream::error_stream(),
2000 "-XX:+VerifyHeavyMonitors requires -XX:+UseHeavyMonitors");
2001 return false;
2002 }
2083 }
2084
2085 jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
2086 return false;
2087 }
2088
2089 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
2090 julong* long_arg,
2091 julong min_size,
2092 julong max_size) {
2093 if (!parse_integer(s, long_arg)) return arg_unreadable;
2094 return check_memory_size(*long_arg, min_size, max_size);
2095 }
2096
2097 // Parse JavaVMInitArgs structure
2098
2099 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
2100 const JavaVMInitArgs *java_tool_options_args,
2101 const JavaVMInitArgs *java_options_args,
2102 const JavaVMInitArgs *cmd_line_args) {
2103 // Save default settings for some mode flags
2104 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
2105 Arguments::_UseOnStackReplacement = UseOnStackReplacement;
2106 Arguments::_ClipInlining = ClipInlining;
2107 Arguments::_BackgroundCompilation = BackgroundCompilation;
2108
2109 // Remember the default value of SharedBaseAddress.
2110 Arguments::_default_SharedBaseAddress = SharedBaseAddress;
2111
2112 // Setup flags for mixed which is the default
2113 set_mode_flags(_mixed);
2114
2115 // Parse args structure generated from java.base vm options resource
2116 jint result = parse_each_vm_init_arg(vm_options_args, JVMFlagOrigin::JIMAGE_RESOURCE);
2117 if (result != JNI_OK) {
2118 return result;
2119 }
2120
2121 // Parse args structure generated from JAVA_TOOL_OPTIONS environment
2122 // variable (if present).
2123 result = parse_each_vm_init_arg(java_tool_options_args, JVMFlagOrigin::ENVIRON_VAR);
2124 if (result != JNI_OK) {
2125 return result;
2126 }
2127
2128 // Parse args structure generated from the command line flags.
2129 result = parse_each_vm_init_arg(cmd_line_args, JVMFlagOrigin::COMMAND_LINE);
2130 if (result != JNI_OK) {
2131 return result;
2132 }
2133
2134 // Parse args structure generated from the _JAVA_OPTIONS environment
2135 // variable (if present) (mimics classic VM)
2136 result = parse_each_vm_init_arg(java_options_args, JVMFlagOrigin::ENVIRON_VAR);
2137 if (result != JNI_OK) {
2138 return result;
2139 }
2140
2141 // We need to ensure processor and memory resources have been properly
2142 // configured - which may rely on arguments we just processed - before
2143 // doing the final argument processing. Any argument processing that
2144 // needs to know about processor and memory resources must occur after
2145 // this point.
2146
2147 os::init_container_support();
2148
2149 // Do final processing now that all arguments have been parsed
2150 result = finalize_vm_init_args();
2151 if (result != JNI_OK) {
2152 return result;
2153 }
2154
2155 return JNI_OK;
2156 }
2157
2158 // Checks if name in command-line argument -agent{lib,path}:name[=options]
2159 // represents a valid JDWP agent. is_path==true denotes that we
2160 // are dealing with -agentpath (case where name is a path), otherwise with
2161 // -agentlib
2162 bool valid_jdwp_agent(char *name, bool is_path) {
2163 char *_name;
2164 const char *_jdwp = "jdwp";
2165 size_t _len_jdwp, _len_prefix;
2166
2167 if (is_path) {
2168 if ((_name = strrchr(name, (int) *os::file_separator())) == NULL) {
2169 return false;
2170 }
2183 _name += _len_jdwp;
2184 }
2185 else {
2186 return false;
2187 }
2188
2189 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) {
2190 return false;
2191 }
2192
2193 return true;
2194 }
2195
2196 if (strcmp(name, _jdwp) == 0) {
2197 return true;
2198 }
2199
2200 return false;
2201 }
2202
2203 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2204 // --patch-module=<module>=<file>(<pathsep><file>)*
2205 assert(patch_mod_tail != NULL, "Unexpected NULL patch-module value");
2206 // Find the equal sign between the module name and the path specification
2207 const char* module_equal = strchr(patch_mod_tail, '=');
2208 if (module_equal == NULL) {
2209 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2210 return JNI_ERR;
2211 } else {
2212 // Pick out the module name
2213 size_t module_len = module_equal - patch_mod_tail;
2214 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2215 if (module_name != NULL) {
2216 memcpy(module_name, patch_mod_tail, module_len);
2217 *(module_name + module_len) = '\0';
2218 // The path piece begins one past the module_equal sign
2219 add_patch_mod_prefix(module_name, module_equal + 1, false /* no append */);
2220 FREE_C_HEAP_ARRAY(char, module_name);
2221 } else {
2222 return JNI_ENOMEM;
2223 }
2224 }
2225 return JNI_OK;
2226 }
2227
2228 // VALUECLASS_STR must match string used in the build
2229 #define VALUECLASS_STR "valueclasses"
2230 #define VALUECLASS_JAR "-" VALUECLASS_STR ".jar"
2231
2232 // Finalize --patch-module args and --enable-preview related to value class module patches.
2233 // Create all numbered properties passing module patches.
2234 int Arguments::finalize_patch_module() {
2235 // If --enable-preview and EnableValhalla is true, each module may have value classes that
2236 // are to be patched into the module.
2237 // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2238 // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2239 if (enable_preview() && EnableValhalla) {
2240 char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2241 const char * fileSep = os::file_separator();
2242
2243 jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s",
2244 Arguments::get_java_home(), fileSep, fileSep, fileSep);
2245 DIR* dir = os::opendir(valueclasses_dir);
2246 if (dir != nullptr) {
2247 char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2248 char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2249
2250 for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) {
2251 // Test if file ends-with "-valueclasses.jar"
2252 int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1);
2253 if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) {
2254 continue; // too short or not the expected suffix
2255 }
2256
2257 strcpy(module_name, entry->d_name);
2258 module_name[len] = '\0'; // truncate to just module-name
2259
2260 jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name);
2261 add_patch_mod_prefix(module_name, path, true /* append */);
2262 log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name);
2263 }
2264 FreeHeap(module_name);
2265 FreeHeap(path);
2266 os::closedir(dir);
2267 }
2268 FreeHeap(valueclasses_dir);
2269 }
2270
2271 // Create numbered properties for each module that has been patched either
2272 // by --patch-module or --enable-preview
2273 // Format is "jdk.module.patch.<n>=<module_name>=<path>"
2274 if (_patch_mod_prefix != nullptr) {
2275 char * prop_value = AllocateHeap(JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, mtArguments);
2276 unsigned int patch_mod_count = 0;
2277
2278 for (GrowableArrayIterator<ModulePatchPath *> it = _patch_mod_prefix->begin();
2279 it != _patch_mod_prefix->end(); ++it) {
2280 jio_snprintf(prop_value, JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, "%s=%s",
2281 (*it)->module_name(), (*it)->path_string());
2282 if (!create_numbered_module_property("jdk.module.patch", prop_value, patch_mod_count++)) {
2283 FreeHeap(prop_value);
2284 return JNI_ENOMEM;
2285 }
2286 }
2287 FreeHeap(prop_value);
2288 }
2289 return JNI_OK;
2290 }
2291
2292 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2293 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2294 // The min and max sizes match the values in globals.hpp, but scaled
2295 // with K. The values have been chosen so that alignment with page
2296 // size doesn't change the max value, which makes the conversions
2297 // back and forth between Xss value and ThreadStackSize value easier.
2298 // The values have also been chosen to fit inside a 32-bit signed type.
2299 const julong min_ThreadStackSize = 0;
2300 const julong max_ThreadStackSize = 1 * M;
2301
2302 // Make sure the above values match the range set in globals.hpp
2303 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2304 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2305 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2306
2307 const julong min_size = min_ThreadStackSize * K;
2308 const julong max_size = max_ThreadStackSize * K;
2309
2310 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2311
2326 assert(size <= size_aligned,
2327 "Overflow: " JULONG_FORMAT " " JULONG_FORMAT,
2328 size, size_aligned);
2329
2330 const julong size_in_K = size_aligned / K;
2331 assert(size_in_K < (julong)max_intx,
2332 "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT,
2333 size_in_K);
2334
2335 // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow.
2336 const julong max_expanded = align_up(size_in_K * K, os::vm_page_size());
2337 assert(max_expanded < max_uintx && max_expanded >= size_in_K,
2338 "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT,
2339 max_expanded, size_in_K);
2340
2341 *out_ThreadStackSize = (intx)size_in_K;
2342
2343 return JNI_OK;
2344 }
2345
2346 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, JVMFlagOrigin origin) {
2347 // For match_option to return remaining or value part of option string
2348 const char* tail;
2349
2350 // iterate over arguments
2351 for (int index = 0; index < args->nOptions; index++) {
2352 bool is_absolute_path = false; // for -agentpath vs -agentlib
2353
2354 const JavaVMOption* option = args->options + index;
2355
2356 if (!match_option(option, "-Djava.class.path", &tail) &&
2357 !match_option(option, "-Dsun.java.command", &tail) &&
2358 !match_option(option, "-Dsun.java.launcher", &tail)) {
2359
2360 // add all jvm options to the jvm_args string. This string
2361 // is used later to set the java.vm.args PerfData string constant.
2362 // the -Djava.class.path and the -Dsun.java.command options are
2363 // omitted from jvm_args string as each have their own PerfData
2364 // string constant object.
2365 build_jvm_args(option->optionString);
2366 }
2451 return JNI_ENOMEM;
2452 }
2453 } else if (match_option(option, "--enable-native-access=", &tail)) {
2454 if (!create_numbered_module_property("jdk.module.enable.native.access", tail, enable_native_access_count++)) {
2455 return JNI_ENOMEM;
2456 }
2457 } else if (match_option(option, "--limit-modules=", &tail)) {
2458 if (!create_module_property("jdk.module.limitmods", tail, InternalProperty)) {
2459 return JNI_ENOMEM;
2460 }
2461 } else if (match_option(option, "--module-path=", &tail)) {
2462 if (!create_module_property("jdk.module.path", tail, ExternalProperty)) {
2463 return JNI_ENOMEM;
2464 }
2465 } else if (match_option(option, "--upgrade-module-path=", &tail)) {
2466 if (!create_module_property("jdk.module.upgrade.path", tail, ExternalProperty)) {
2467 return JNI_ENOMEM;
2468 }
2469 } else if (match_option(option, "--patch-module=", &tail)) {
2470 // --patch-module=<module>=<file>(<pathsep><file>)*
2471 int res = process_patch_mod_option(tail);
2472 if (res != JNI_OK) {
2473 return res;
2474 }
2475 } else if (match_option(option, "--illegal-access=", &tail)) {
2476 char version[256];
2477 JDK_Version::jdk(17).to_string(version, sizeof(version));
2478 warning("Ignoring option %s; support was removed in %s", option->optionString, version);
2479 // -agentlib and -agentpath
2480 } else if (match_option(option, "-agentlib:", &tail) ||
2481 (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2482 if(tail != NULL) {
2483 const char* pos = strchr(tail, '=');
2484 char* name;
2485 if (pos == NULL) {
2486 name = os::strdup_check_oom(tail, mtArguments);
2487 } else {
2488 size_t len = pos - tail;
2489 name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments);
2490 memcpy(name, tail, len);
2491 name[len] = '\0';
2960 #endif // INCLUDE_JVMCI
2961 #if INCLUDE_JFR
2962 } else if (match_jfr_option(&option)) {
2963 return JNI_EINVAL;
2964 #endif
2965 } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx
2966 // Skip -XX:Flags= and -XX:VMOptionsFile= since those cases have
2967 // already been handled
2968 if ((strncmp(tail, "Flags=", strlen("Flags=")) != 0) &&
2969 (strncmp(tail, "VMOptionsFile=", strlen("VMOptionsFile=")) != 0)) {
2970 if (!process_argument(tail, args->ignoreUnrecognized, origin)) {
2971 return JNI_EINVAL;
2972 }
2973 }
2974 // Unknown option
2975 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2976 return JNI_ERR;
2977 }
2978 }
2979
2980 if (!EnableValhalla && EnablePrimitiveClasses) {
2981 jio_fprintf(defaultStream::error_stream(),
2982 "Cannot specify -XX:+EnablePrimitiveClasses without -XX:+EnableValhalla");
2983 return JNI_EINVAL;
2984 }
2985
2986 // PrintSharedArchiveAndExit will turn on
2987 // -Xshare:on
2988 // -Xlog:class+path=info
2989 if (PrintSharedArchiveAndExit) {
2990 UseSharedSpaces = true;
2991 RequireSharedSpaces = true;
2992 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2993 }
2994
2995 fix_appclasspath();
2996
2997 return JNI_OK;
2998 }
2999
3000 bool match_module(void *module_name, ModulePatchPath *patch) {
3001 return (strcmp((char *)module_name, patch->module_name()) == 0);
3002 }
3003
3004 bool Arguments::patch_mod_javabase() {
3005 return _patch_mod_prefix != nullptr && _patch_mod_prefix->find((void*)JAVA_BASE_NAME, match_module) >= 0;
3006 }
3007
3008 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append) {
3009 // Create GrowableArray lazily, only if --patch-module has been specified
3010 if (_patch_mod_prefix == nullptr) {
3011 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
3012 }
3013
3014 // Scan patches for matching module
3015 int i = _patch_mod_prefix->find((void*)module_name, match_module);
3016 if (i == -1) {
3017 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
3018 } else {
3019 if (allow_append) {
3020 // append path to existing module entry
3021 _patch_mod_prefix->at(i)->append_path(path);
3022 } else {
3023 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
3024 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
3025 } else {
3026 vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
3027 }
3028 }
3029 }
3030 }
3031
3032 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
3033 //
3034 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
3035 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
3036 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
3037 // path is treated as the current directory.
3038 //
3039 // This causes problems with CDS, which requires that all directories specified in the classpath
3040 // must be empty. In most cases, applications do NOT want to load classes from the current
3041 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
3042 // scripts compatible with CDS.
3043 void Arguments::fix_appclasspath() {
3044 if (IgnoreEmptyClassPaths) {
3045 const char separator = *os::path_separator();
3046 const char* src = _java_class_path->value();
3047
3048 // skip over all the leading empty paths
3049 while (*src == separator) {
3052
3053 char* copy = os::strdup_check_oom(src, mtArguments);
3054
3055 // trim all trailing empty paths
3056 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
3057 *tail = '\0';
3058 }
3059
3060 char from[3] = {separator, separator, '\0'};
3061 char to [2] = {separator, '\0'};
3062 while (StringUtils::replace_no_expand(copy, from, to) > 0) {
3063 // Keep replacing "::" -> ":" until we have no more "::" (non-windows)
3064 // Keep replacing ";;" -> ";" until we have no more ";;" (windows)
3065 }
3066
3067 _java_class_path->set_writeable_value(copy);
3068 FreeHeap(copy); // a copy was made by set_value, so don't need this anymore
3069 }
3070 }
3071
3072 jint Arguments::finalize_vm_init_args() {
3073 // check if the default lib/endorsed directory exists; if so, error
3074 char path[JVM_MAXPATHLEN];
3075 const char* fileSep = os::file_separator();
3076 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
3077
3078 DIR* dir = os::opendir(path);
3079 if (dir != NULL) {
3080 jio_fprintf(defaultStream::output_stream(),
3081 "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n"
3082 "in modular form will be supported via the concept of upgradeable modules.\n");
3083 os::closedir(dir);
3084 return JNI_ERR;
3085 }
3086
3087 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
3088 dir = os::opendir(path);
3089 if (dir != NULL) {
3090 jio_fprintf(defaultStream::output_stream(),
3091 "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; "
3092 "Use -classpath instead.\n.");
3135 if (FLAG_IS_DEFAULT(UseLargePages) &&
3136 MaxHeapSize < LargePageHeapSizeThreshold) {
3137 // No need for large granularity pages w/small heaps.
3138 // Note that large pages are enabled/disabled for both the
3139 // Java heap and the code cache.
3140 FLAG_SET_DEFAULT(UseLargePages, false);
3141 }
3142
3143 UNSUPPORTED_OPTION(ProfileInterpreter);
3144 #endif
3145
3146 // Parse the CompilationMode flag
3147 if (!CompilationModeFlag::initialize()) {
3148 return JNI_ERR;
3149 }
3150
3151 if (!check_vm_args_consistency()) {
3152 return JNI_ERR;
3153 }
3154
3155 // finalize --module-patch and related --enable-preview
3156 if (finalize_patch_module() != JNI_OK) {
3157 return JNI_ERR;
3158 }
3159
3160 #if INCLUDE_CDS
3161 if (DumpSharedSpaces) {
3162 // Compiler threads may concurrently update the class metadata (such as method entries), so it's
3163 // unsafe with -Xshare:dump (which modifies the class metadata in place). Let's disable
3164 // compiler just to be safe.
3165 //
3166 // Note: this is not a concern for dynamically dumping shared spaces, which makes a copy of the
3167 // class metadata instead of modifying them in place. The copy is inaccessible to the compiler.
3168 // TODO: revisit the following for the static archive case.
3169 set_mode_flags(_int);
3170 }
3171
3172 // RecordDynamicDumpInfo is not compatible with ArchiveClassesAtExit
3173 if (ArchiveClassesAtExit != NULL && RecordDynamicDumpInfo) {
3174 jio_fprintf(defaultStream::output_stream(),
3175 "-XX:+RecordDynamicDumpInfo cannot be used with -XX:ArchiveClassesAtExit.\n");
3176 return JNI_ERR;
3177 }
3178
3179 if (ArchiveClassesAtExit == NULL && !RecordDynamicDumpInfo) {
3180 DynamicDumpSharedSpaces = false;
3181 } else {
3182 DynamicDumpSharedSpaces = true;
3183 }
3184
3185 if (AutoCreateSharedArchive) {
3186 if (SharedArchiveFile == NULL) {
3187 log_warning(cds)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
3188 return JNI_ERR;
3189 }
3190 if (ArchiveClassesAtExit != NULL) {
3191 log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
3192 return JNI_ERR;
3193 }
3194 }
3195
3196 if (UseSharedSpaces && patch_mod_javabase()) {
3197 no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
3198 }
3199 if (UseSharedSpaces && !DumpSharedSpaces && check_unsupported_cds_runtime_properties()) {
3200 UseSharedSpaces = false;
3201 }
3202
3203 if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
3204 // Always verify non-system classes during CDS dump
3205 if (!BytecodeVerificationRemote) {
3206 BytecodeVerificationRemote = true;
3207 log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
3208 }
3209 }
3210 #endif
3211
3212 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3213 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3214 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3215
3216 return JNI_OK;
4126 #ifdef ZERO
4127 // Clear flags not supported on zero.
4128 FLAG_SET_DEFAULT(ProfileInterpreter, false);
4129 #endif // ZERO
4130
4131 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
4132 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
4133 DebugNonSafepoints = true;
4134 }
4135
4136 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
4137 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
4138 }
4139
4140 // Treat the odd case where local verification is enabled but remote
4141 // verification is not as if both were enabled.
4142 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
4143 log_info(verification)("Turning on remote verification because local verification is on");
4144 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
4145 }
4146 if (!EnableValhalla || (is_interpreter_only() && !is_dumping_archive() && !UseSharedSpaces)) {
4147 // Disable calling convention optimizations if inline types are not supported.
4148 // Also these aren't useful in -Xint. However, don't disable them when dumping or using
4149 // the CDS archive, as the values must match between dumptime and runtime.
4150 InlineTypePassFieldsAsArgs = false;
4151 InlineTypeReturnedAsFields = false;
4152 }
4153
4154 #ifndef PRODUCT
4155 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
4156 if (use_vm_log()) {
4157 LogVMOutput = true;
4158 }
4159 }
4160 #endif // PRODUCT
4161
4162 if (PrintCommandLineFlags) {
4163 JVMFlag::printSetFlags(tty);
4164 }
4165
4166 #ifdef COMPILER2
4167 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
4168 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
4169 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
4170 }
4171 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
4172
|