< prev index next >

src/hotspot/share/runtime/arguments.cpp

Print this page

   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  *

  57 #include "runtime/os.hpp"
  58 #include "runtime/safepoint.hpp"
  59 #include "runtime/safepointMechanism.hpp"
  60 #include "runtime/synchronizer.hpp"
  61 #include "runtime/vm_version.hpp"
  62 #include "services/management.hpp"
  63 #include "utilities/align.hpp"
  64 #include "utilities/checkedCast.hpp"
  65 #include "utilities/debug.hpp"
  66 #include "utilities/defaultStream.hpp"
  67 #include "utilities/macros.hpp"
  68 #include "utilities/parseInteger.hpp"
  69 #include "utilities/powerOfTwo.hpp"
  70 #include "utilities/stringUtils.hpp"
  71 #include "utilities/systemMemoryBarrier.hpp"
  72 #if INCLUDE_JFR
  73 #include "jfr/jfr.hpp"
  74 #endif
  75 
  76 #include <limits>

  77 
  78 static const char _default_java_launcher[] = "generic";
  79 
  80 #define DEFAULT_JAVA_LAUNCHER _default_java_launcher
  81 
  82 char*  Arguments::_jvm_flags_file               = nullptr;
  83 char** Arguments::_jvm_flags_array              = nullptr;
  84 int    Arguments::_num_jvm_flags                = 0;
  85 char** Arguments::_jvm_args_array               = nullptr;
  86 int    Arguments::_num_jvm_args                 = 0;
  87 char*  Arguments::_java_command                 = nullptr;
  88 SystemProperty* Arguments::_system_properties   = nullptr;
  89 size_t Arguments::_conservative_max_heap_alignment = 0;
  90 Arguments::Mode Arguments::_mode                = _mixed;
  91 const char*  Arguments::_java_vendor_url_bug    = nullptr;
  92 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
  93 bool   Arguments::_sun_java_launcher_is_altjvm  = false;
  94 
  95 // These parameters are reset in method parse_vm_init_args()
  96 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;
  97 bool   Arguments::_UseOnStackReplacement        = UseOnStackReplacement;
  98 bool   Arguments::_BackgroundCompilation        = BackgroundCompilation;
  99 bool   Arguments::_ClipInlining                 = ClipInlining;
 100 size_t Arguments::_default_SharedBaseAddress    = SharedBaseAddress;
 101 
 102 bool   Arguments::_enable_preview               = false;

 103 
 104 char*  Arguments::_default_shared_archive_path  = nullptr;
 105 char*  Arguments::SharedArchivePath             = nullptr;
 106 char*  Arguments::SharedDynamicArchivePath      = nullptr;
 107 
 108 LegacyGCLogging Arguments::_legacyGCLogging     = { 0, 0 };
 109 
 110 // These are not set by the JDK's built-in launchers, but they can be set by
 111 // programs that embed the JVM using JNI_CreateJavaVM. See comments around
 112 // JavaVMOption in jni.h.
 113 abort_hook_t     Arguments::_abort_hook         = nullptr;
 114 exit_hook_t      Arguments::_exit_hook          = nullptr;
 115 vfprintf_hook_t  Arguments::_vfprintf_hook      = nullptr;
 116 
 117 
 118 SystemProperty *Arguments::_sun_boot_library_path = nullptr;
 119 SystemProperty *Arguments::_java_library_path = nullptr;
 120 SystemProperty *Arguments::_java_home = nullptr;
 121 SystemProperty *Arguments::_java_class_path = nullptr;
 122 SystemProperty *Arguments::_jdk_boot_class_path_append = nullptr;

1313       if (old_java_vendor_url_bug != nullptr) {
1314         os::free((void *)old_java_vendor_url_bug);
1315       }
1316     }
1317 
1318     // Create new property and add at the end of the list
1319     PropertyList_unique_add(&_system_properties, key, value, AddProperty, writeable, internal);
1320   }
1321 
1322   if (key != prop) {
1323     // SystemProperty copy passed value, thus free previously allocated
1324     // memory
1325     FreeHeap((void *)key);
1326   }
1327 
1328   return true;
1329 }
1330 
1331 #if INCLUDE_CDS
1332 const char* unsupported_properties[] = { "jdk.module.limitmods",
1333                                          "jdk.module.upgrade.path",
1334                                          "jdk.module.patch.0" };
1335 const char* unsupported_options[] = { "--limit-modules",
1336                                       "--upgrade-module-path",
1337                                       "--patch-module"
1338                                     };
1339 void Arguments::check_unsupported_dumping_properties() {
1340   assert(CDSConfig::is_dumping_archive(),
1341          "this function is only used with CDS dump time");
1342   assert(ARRAY_SIZE(unsupported_properties) == ARRAY_SIZE(unsupported_options), "must be");
1343   // If a vm option is found in the unsupported_options array, vm will exit with an error message.
1344   SystemProperty* sp = system_properties();
1345   while (sp != nullptr) {
1346     for (uint i = 0; i < ARRAY_SIZE(unsupported_properties); i++) {
1347       if (strcmp(sp->key(), unsupported_properties[i]) == 0) {
1348         vm_exit_during_initialization(
1349           "Cannot use the following option when dumping the shared archive", unsupported_options[i]);
1350       }
1351     }
1352     sp = sp->next();
1353   }
1354 





1355   // Check for an exploded module build in use with -Xshare:dump.
1356   if (!has_jimage()) {
1357     vm_exit_during_initialization("Dumping the shared archive is not supported with an exploded module build");
1358   }
1359 }
1360 
1361 bool Arguments::check_unsupported_cds_runtime_properties() {
1362   assert(UseSharedSpaces, "this function is only used with -Xshare:{on,auto}");
1363   assert(ARRAY_SIZE(unsupported_properties) == ARRAY_SIZE(unsupported_options), "must be");
1364   if (ArchiveClassesAtExit != nullptr) {
1365     // dynamic dumping, just return false for now.
1366     // check_unsupported_dumping_properties() will be called later to check the same set of
1367     // properties, and will exit the VM with the correct error message if the unsupported properties
1368     // are used.
1369     return false;
1370   }
1371   for (uint i = 0; i < ARRAY_SIZE(unsupported_properties); i++) {
1372     if (get_property(unsupported_properties[i]) != nullptr) {
1373       if (RequireSharedSpaces) {
1374         warning("CDS is disabled when the %s option is specified.", unsupported_options[i]);
1375       } else {
1376         log_info(cds)("CDS is disabled when the %s option is specified.", unsupported_options[i]);
1377       }
1378       return true;
1379     }
1380   }










1381   return false;
1382 }
1383 #endif
1384 
1385 //===========================================================================================================
1386 // Setting int/mixed/comp mode flags
1387 
1388 void Arguments::set_mode_flags(Mode mode) {
1389   // Set up default values for all flags.
1390   // If you add a flag to any of the branches below,
1391   // add a default value for it here.
1392   _mode                      = mode;
1393 
1394   // Ensure Agent_OnLoad has the correct initial values.
1395   // This may not be the final mode; mode may change later in onload phase.
1396   PropertyList_unique_add(&_system_properties, "java.vm.info",
1397                           VM_Version::vm_info_string(), AddProperty, UnwriteableProperty, ExternalProperty);
1398 
1399   UseInterpreter             = true;
1400   UseCompiler                = true;

1850   }
1851   _sun_java_launcher = os::strdup_check_oom(launcher);
1852 }
1853 
1854 bool Arguments::created_by_java_launcher() {
1855   assert(_sun_java_launcher != nullptr, "property must have value");
1856   return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1857 }
1858 
1859 bool Arguments::sun_java_launcher_is_altjvm() {
1860   return _sun_java_launcher_is_altjvm;
1861 }
1862 
1863 //===========================================================================================================
1864 // Parsing of main arguments
1865 
1866 unsigned int addreads_count = 0;
1867 unsigned int addexports_count = 0;
1868 unsigned int addopens_count = 0;
1869 unsigned int addmods_count = 0;
1870 unsigned int patch_mod_count = 0;
1871 unsigned int enable_native_access_count = 0;
1872 
1873 // Check the consistency of vm_init_args
1874 bool Arguments::check_vm_args_consistency() {
1875   // Method for adding checks for flag consistency.
1876   // The intent is to warn the user of all possible conflicts,
1877   // before returning an error.
1878   // Note: Needs platform-dependent factoring.
1879   bool status = true;
1880 
1881   if (TLABRefillWasteFraction == 0) {
1882     jio_fprintf(defaultStream::error_stream(),
1883                 "TLABRefillWasteFraction should be a denominator, "
1884                 "not " SIZE_FORMAT "\n",
1885                 TLABRefillWasteFraction);
1886     status = false;
1887   }
1888 
1889   status = CompilerConfig::check_args_consistency(status);
1890 #if INCLUDE_JVMCI

1897       }
1898     }
1899   }
1900 #endif
1901 
1902 #if INCLUDE_JFR
1903   if (status && (FlightRecorderOptions || StartFlightRecording)) {
1904     if (!create_numbered_module_property("jdk.module.addmods", "jdk.jfr", addmods_count++)) {
1905       return false;
1906     }
1907   }
1908 #endif
1909 
1910 #ifndef SUPPORT_RESERVED_STACK_AREA
1911   if (StackReservedPages != 0) {
1912     FLAG_SET_CMDLINE(StackReservedPages, 0);
1913     warning("Reserved Stack Area not supported on this platform");
1914   }
1915 #endif
1916 














1917 #if !defined(X86) && !defined(AARCH64) && !defined(RISCV64) && !defined(ARM) && !defined(PPC64) && !defined(S390)
1918   if (LockingMode == LM_LIGHTWEIGHT) {
1919     FLAG_SET_CMDLINE(LockingMode, LM_LEGACY);
1920     warning("New lightweight locking not supported on this platform");
1921   }
1922 #endif
1923 
1924 #if !defined(X86) && !defined(AARCH64) && !defined(PPC64) && !defined(RISCV64) && !defined(S390)
1925   if (LockingMode == LM_MONITOR) {
1926     jio_fprintf(defaultStream::error_stream(),
1927                 "LockingMode == 0 (LM_MONITOR) is not fully implemented on this architecture\n");
1928     return false;
1929   }
1930 #endif
1931 #if defined(X86) && !defined(ZERO)
1932   if (LockingMode == LM_MONITOR && UseRTMForStackLocks) {
1933     jio_fprintf(defaultStream::error_stream(),
1934                 "LockingMode == 0 (LM_MONITOR) and -XX:+UseRTMForStackLocks are mutually exclusive\n");
1935 
1936     return false;

2023   }
2024 
2025   jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
2026   return false;
2027 }
2028 
2029 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
2030                                                   julong* long_arg,
2031                                                   julong min_size,
2032                                                   julong max_size) {
2033   if (!parse_integer(s, long_arg)) return arg_unreadable;
2034   return check_memory_size(*long_arg, min_size, max_size);
2035 }
2036 
2037 // Parse JavaVMInitArgs structure
2038 
2039 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
2040                                    const JavaVMInitArgs *java_tool_options_args,
2041                                    const JavaVMInitArgs *java_options_args,
2042                                    const JavaVMInitArgs *cmd_line_args) {
2043   bool patch_mod_javabase = false;
2044 
2045   // Save default settings for some mode flags
2046   Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
2047   Arguments::_UseOnStackReplacement    = UseOnStackReplacement;
2048   Arguments::_ClipInlining             = ClipInlining;
2049   Arguments::_BackgroundCompilation    = BackgroundCompilation;
2050 
2051   // Remember the default value of SharedBaseAddress.
2052   Arguments::_default_SharedBaseAddress = SharedBaseAddress;
2053 
2054   // Setup flags for mixed which is the default
2055   set_mode_flags(_mixed);
2056 
2057   // Parse args structure generated from java.base vm options resource
2058   jint result = parse_each_vm_init_arg(vm_options_args, &patch_mod_javabase, JVMFlagOrigin::JIMAGE_RESOURCE);
2059   if (result != JNI_OK) {
2060     return result;
2061   }
2062 
2063   // Parse args structure generated from JAVA_TOOL_OPTIONS environment
2064   // variable (if present).
2065   result = parse_each_vm_init_arg(java_tool_options_args, &patch_mod_javabase, JVMFlagOrigin::ENVIRON_VAR);
2066   if (result != JNI_OK) {
2067     return result;
2068   }
2069 
2070   // Parse args structure generated from the command line flags.
2071   result = parse_each_vm_init_arg(cmd_line_args, &patch_mod_javabase, JVMFlagOrigin::COMMAND_LINE);
2072   if (result != JNI_OK) {
2073     return result;
2074   }
2075 
2076   // Parse args structure generated from the _JAVA_OPTIONS environment
2077   // variable (if present) (mimics classic VM)
2078   result = parse_each_vm_init_arg(java_options_args, &patch_mod_javabase, JVMFlagOrigin::ENVIRON_VAR);
2079   if (result != JNI_OK) {
2080     return result;
2081   }
2082 
2083   // Disable CDS for exploded image
2084   if (!has_jimage()) {
2085     no_shared_spaces("CDS disabled on exploded JDK");
2086   }
2087 
2088   // We need to ensure processor and memory resources have been properly
2089   // configured - which may rely on arguments we just processed - before
2090   // doing the final argument processing. Any argument processing that
2091   // needs to know about processor and memory resources must occur after
2092   // this point.
2093 
2094   os::init_container_support();
2095 
2096   SystemMemoryBarrier::initialize();
2097 
2098   // Do final processing now that all arguments have been parsed
2099   result = finalize_vm_init_args(patch_mod_javabase);
2100   if (result != JNI_OK) {
2101     return result;
2102   }
2103 
2104   return JNI_OK;
2105 }
2106 
2107 // Checks if name in command-line argument -agent{lib,path}:name[=options]
2108 // represents a valid JDWP agent.  is_path==true denotes that we
2109 // are dealing with -agentpath (case where name is a path), otherwise with
2110 // -agentlib
2111 bool valid_jdwp_agent(char *name, bool is_path) {
2112   char *_name;
2113   const char *_jdwp = "jdwp";
2114   size_t _len_jdwp, _len_prefix;
2115 
2116   if (is_path) {
2117     if ((_name = strrchr(name, (int) *os::file_separator())) == nullptr) {
2118       return false;
2119     }

2132       _name += _len_jdwp;
2133     }
2134     else {
2135       return false;
2136     }
2137 
2138     if (strcmp(_name, JNI_LIB_SUFFIX) != 0) {
2139       return false;
2140     }
2141 
2142     return true;
2143   }
2144 
2145   if (strcmp(name, _jdwp) == 0) {
2146     return true;
2147   }
2148 
2149   return false;
2150 }
2151 
2152 int Arguments::process_patch_mod_option(const char* patch_mod_tail, bool* patch_mod_javabase) {
2153   // --patch-module=<module>=<file>(<pathsep><file>)*
2154   assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2155   // Find the equal sign between the module name and the path specification
2156   const char* module_equal = strchr(patch_mod_tail, '=');
2157   if (module_equal == nullptr) {
2158     jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2159     return JNI_ERR;
2160   } else {
2161     // Pick out the module name
2162     size_t module_len = module_equal - patch_mod_tail;
2163     char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2164     if (module_name != nullptr) {
2165       memcpy(module_name, patch_mod_tail, module_len);
2166       *(module_name + module_len) = '\0';
2167       // The path piece begins one past the module_equal sign
2168       add_patch_mod_prefix(module_name, module_equal + 1, patch_mod_javabase);
2169       FREE_C_HEAP_ARRAY(char, module_name);
2170       if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
2171         return JNI_ENOMEM;
2172       }
2173     } else {
2174       return JNI_ENOMEM;
2175     }
2176   }
2177   return JNI_OK;
2178 }
2179 
































































2180 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2181 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2182   // The min and max sizes match the values in globals.hpp, but scaled
2183   // with K. The values have been chosen so that alignment with page
2184   // size doesn't change the max value, which makes the conversions
2185   // back and forth between Xss value and ThreadStackSize value easier.
2186   // The values have also been chosen to fit inside a 32-bit signed type.
2187   const julong min_ThreadStackSize = 0;
2188   const julong max_ThreadStackSize = 1 * M;
2189 
2190   // Make sure the above values match the range set in globals.hpp
2191   const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2192   assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2193   assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2194 
2195   const julong min_size = min_ThreadStackSize * K;
2196   const julong max_size = max_ThreadStackSize * K;
2197 
2198   assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2199 

2214   assert(size <= size_aligned,
2215          "Overflow: " JULONG_FORMAT " " JULONG_FORMAT,
2216          size, size_aligned);
2217 
2218   const julong size_in_K = size_aligned / K;
2219   assert(size_in_K < (julong)max_intx,
2220          "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT,
2221          size_in_K);
2222 
2223   // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow.
2224   const julong max_expanded = align_up(size_in_K * K, os::vm_page_size());
2225   assert(max_expanded < max_uintx && max_expanded >= size_in_K,
2226          "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT,
2227          max_expanded, size_in_K);
2228 
2229   *out_ThreadStackSize = (intx)size_in_K;
2230 
2231   return JNI_OK;
2232 }
2233 
2234 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_mod_javabase, JVMFlagOrigin origin) {
2235   // For match_option to return remaining or value part of option string
2236   const char* tail;
2237 
2238   // iterate over arguments
2239   for (int index = 0; index < args->nOptions; index++) {
2240     bool is_absolute_path = false;  // for -agentpath vs -agentlib
2241 
2242     const JavaVMOption* option = args->options + index;
2243 
2244     if (!match_option(option, "-Djava.class.path", &tail) &&
2245         !match_option(option, "-Dsun.java.command", &tail) &&
2246         !match_option(option, "-Dsun.java.launcher", &tail)) {
2247 
2248         // add all jvm options to the jvm_args string. This string
2249         // is used later to set the java.vm.args PerfData string constant.
2250         // the -Djava.class.path and the -Dsun.java.command options are
2251         // omitted from jvm_args string as each have their own PerfData
2252         // string constant object.
2253         build_jvm_args(option->optionString);
2254     }

2341         return JNI_ENOMEM;
2342       }
2343     } else if (match_option(option, "--enable-native-access=", &tail)) {
2344       if (!create_numbered_module_property("jdk.module.enable.native.access", tail, enable_native_access_count++)) {
2345         return JNI_ENOMEM;
2346       }
2347     } else if (match_option(option, "--limit-modules=", &tail)) {
2348       if (!create_module_property("jdk.module.limitmods", tail, InternalProperty)) {
2349         return JNI_ENOMEM;
2350       }
2351     } else if (match_option(option, "--module-path=", &tail)) {
2352       if (!create_module_property("jdk.module.path", tail, ExternalProperty)) {
2353         return JNI_ENOMEM;
2354       }
2355     } else if (match_option(option, "--upgrade-module-path=", &tail)) {
2356       if (!create_module_property("jdk.module.upgrade.path", tail, ExternalProperty)) {
2357         return JNI_ENOMEM;
2358       }
2359     } else if (match_option(option, "--patch-module=", &tail)) {
2360       // --patch-module=<module>=<file>(<pathsep><file>)*
2361       int res = process_patch_mod_option(tail, patch_mod_javabase);
2362       if (res != JNI_OK) {
2363         return res;
2364       }
2365     } else if (match_option(option, "--illegal-access=", &tail)) {
2366       char version[256];
2367       JDK_Version::jdk(17).to_string(version, sizeof(version));
2368       warning("Ignoring option %s; support was removed in %s", option->optionString, version);
2369     // -agentlib and -agentpath
2370     } else if (match_option(option, "-agentlib:", &tail) ||
2371           (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2372       if(tail != nullptr) {
2373         const char* pos = strchr(tail, '=');
2374         char* name;
2375         if (pos == nullptr) {
2376           name = os::strdup_check_oom(tail, mtArguments);
2377         } else {
2378           size_t len = pos - tail;
2379           name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments);
2380           memcpy(name, tail, len);
2381           name[len] = '\0';

2402       jio_fprintf(defaultStream::error_stream(),
2403         "Instrumentation agents are not supported in this VM\n");
2404       return JNI_ERR;
2405 #else
2406       if (tail != nullptr) {
2407         size_t length = strlen(tail) + 1;
2408         char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2409         jio_snprintf(options, length, "%s", tail);
2410         JvmtiAgentList::add("instrument", options, false);
2411         FREE_C_HEAP_ARRAY(char, options);
2412 
2413         // java agents need module java.instrument
2414         if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", addmods_count++)) {
2415           return JNI_ENOMEM;
2416         }
2417       }
2418 #endif // !INCLUDE_JVMTI
2419     // --enable_preview
2420     } else if (match_option(option, "--enable-preview")) {
2421       set_enable_preview();




2422     // -Xnoclassgc
2423     } else if (match_option(option, "-Xnoclassgc")) {
2424       if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2425         return JNI_EINVAL;
2426       }
2427     // -Xbatch
2428     } else if (match_option(option, "-Xbatch")) {
2429       if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2430         return JNI_EINVAL;
2431       }
2432     // -Xmn for compatibility with other JVM vendors
2433     } else if (match_option(option, "-Xmn", &tail)) {
2434       julong long_initial_young_size = 0;
2435       ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2436       if (errcode != arg_in_range) {
2437         jio_fprintf(defaultStream::error_stream(),
2438                     "Invalid initial young generation size: %s\n", option->optionString);
2439         describe_range_error(errcode);
2440         return JNI_EINVAL;
2441       }

2884     // Unknown option
2885     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2886       return JNI_ERR;
2887     }
2888   }
2889 
2890   // PrintSharedArchiveAndExit will turn on
2891   //   -Xshare:on
2892   //   -Xlog:class+path=info
2893   if (PrintSharedArchiveAndExit) {
2894     UseSharedSpaces = true;
2895     RequireSharedSpaces = true;
2896     LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2897   }
2898 
2899   fix_appclasspath();
2900 
2901   return JNI_OK;
2902 }
2903 
2904 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool* patch_mod_javabase) {
2905   // For java.base check for duplicate --patch-module options being specified on the command line.
2906   // This check is only required for java.base, all other duplicate module specifications
2907   // will be checked during module system initialization.  The module system initialization
2908   // will throw an ExceptionInInitializerError if this situation occurs.
2909   if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2910     if (*patch_mod_javabase) {
2911       vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2912     } else {
2913       *patch_mod_javabase = true;




2914     }
2915   }
2916 
2917   // Create GrowableArray lazily, only if --patch-module has been specified
2918   if (_patch_mod_prefix == nullptr) {
2919     _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2920   }
2921 
2922   _patch_mod_prefix->push(new ModulePatchPath(module_name, path));















2923 }
2924 
2925 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2926 //
2927 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2928 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2929 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2930 // path is treated as the current directory.
2931 //
2932 // This causes problems with CDS, which requires that all directories specified in the classpath
2933 // must be empty. In most cases, applications do NOT want to load classes from the current
2934 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2935 // scripts compatible with CDS.
2936 void Arguments::fix_appclasspath() {
2937   if (IgnoreEmptyClassPaths) {
2938     const char separator = *os::path_separator();
2939     const char* src = _java_class_path->value();
2940 
2941     // skip over all the leading empty paths
2942     while (*src == separator) {

2945 
2946     char* copy = os::strdup_check_oom(src, mtArguments);
2947 
2948     // trim all trailing empty paths
2949     for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
2950       *tail = '\0';
2951     }
2952 
2953     char from[3] = {separator, separator, '\0'};
2954     char to  [2] = {separator, '\0'};
2955     while (StringUtils::replace_no_expand(copy, from, to) > 0) {
2956       // Keep replacing "::" -> ":" until we have no more "::" (non-windows)
2957       // Keep replacing ";;" -> ";" until we have no more ";;" (windows)
2958     }
2959 
2960     _java_class_path->set_writeable_value(copy);
2961     FreeHeap(copy); // a copy was made by set_value, so don't need this anymore
2962   }
2963 }
2964 
2965 jint Arguments::finalize_vm_init_args(bool patch_mod_javabase) {
2966   // check if the default lib/endorsed directory exists; if so, error
2967   char path[JVM_MAXPATHLEN];
2968   const char* fileSep = os::file_separator();
2969   jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
2970 
2971   DIR* dir = os::opendir(path);
2972   if (dir != nullptr) {
2973     jio_fprintf(defaultStream::output_stream(),
2974       "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n"
2975       "in modular form will be supported via the concept of upgradeable modules.\n");
2976     os::closedir(dir);
2977     return JNI_ERR;
2978   }
2979 
2980   jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
2981   dir = os::opendir(path);
2982   if (dir != nullptr) {
2983     jio_fprintf(defaultStream::output_stream(),
2984       "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; "
2985       "Use -classpath instead.\n.");

3019   if (FLAG_IS_DEFAULT(UseLargePages) &&
3020       MaxHeapSize < LargePageHeapSizeThreshold) {
3021     // No need for large granularity pages w/small heaps.
3022     // Note that large pages are enabled/disabled for both the
3023     // Java heap and the code cache.
3024     FLAG_SET_DEFAULT(UseLargePages, false);
3025   }
3026 
3027   UNSUPPORTED_OPTION(ProfileInterpreter);
3028 #endif
3029 
3030   // Parse the CompilationMode flag
3031   if (!CompilationModeFlag::initialize()) {
3032     return JNI_ERR;
3033   }
3034 
3035   if (!check_vm_args_consistency()) {
3036     return JNI_ERR;
3037   }
3038 





3039 #if INCLUDE_CDS
3040   if (CDSConfig::is_dumping_static_archive()) {
3041     if (!mode_flag_cmd_line) {
3042       // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
3043       //
3044       // If your classlist is large and you don't care about deterministic dumping, you can use
3045       // -Xshare:dump -Xmixed to improve dumping speed.
3046       set_mode_flags(_int);
3047     } else if (_mode == _comp) {
3048       // -Xcomp may use excessive CPU for the test tiers. Also, -Xshare:dump runs a small and fixed set of
3049       // Java code, so there's not much benefit in running -Xcomp.
3050       log_info(cds)("reduced -Xcomp to -Xmixed for static dumping");
3051       set_mode_flags(_mixed);
3052     }
3053 
3054     // String deduplication may cause CDS to iterate the strings in different order from one
3055     // run to another which resulting in non-determinstic CDS archives.
3056     // Disable UseStringDeduplication while dumping CDS archive.
3057     UseStringDeduplication = false;
3058   }

3064     return JNI_ERR;
3065   }
3066 
3067   if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
3068     CDSConfig::disable_dumping_dynamic_archive();
3069   } else {
3070     CDSConfig::enable_dumping_dynamic_archive();
3071   }
3072 
3073   if (AutoCreateSharedArchive) {
3074     if (SharedArchiveFile == nullptr) {
3075       log_warning(cds)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
3076       return JNI_ERR;
3077     }
3078     if (ArchiveClassesAtExit != nullptr) {
3079       log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
3080       return JNI_ERR;
3081     }
3082   }
3083 
3084   if (UseSharedSpaces && patch_mod_javabase) {
3085     no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
3086   }
3087   if (UseSharedSpaces && check_unsupported_cds_runtime_properties()) {
3088     UseSharedSpaces = false;
3089   }
3090 
3091   if (CDSConfig::is_dumping_archive()) {
3092     // Always verify non-system classes during CDS dump
3093     if (!BytecodeVerificationRemote) {
3094       BytecodeVerificationRemote = true;
3095       log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
3096     }
3097   }
3098 #endif
3099 
3100 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3101   UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3102 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3103 
3104   return JNI_OK;

3376   // This must be after set_ergonomics_flags() called so flag UseCompressedOops is set properly.
3377   //
3378   // UseSharedSpaces may be disabled if -XX:SharedArchiveFile is invalid.
3379   if (CDSConfig::is_dumping_static_archive() || UseSharedSpaces) {
3380     init_shared_archive_paths();
3381   }
3382 #endif  // INCLUDE_CDS
3383 }
3384 
3385 #if INCLUDE_CDS
3386 // Sharing support
3387 // Construct the path to the archive
3388 char* Arguments::get_default_shared_archive_path() {
3389   if (_default_shared_archive_path == nullptr) {
3390     char jvm_path[JVM_MAXPATHLEN];
3391     os::jvm_path(jvm_path, sizeof(jvm_path));
3392     char *end = strrchr(jvm_path, *os::file_separator());
3393     if (end != nullptr) *end = '\0';
3394     size_t jvm_path_len = strlen(jvm_path);
3395     size_t file_sep_len = strlen(os::file_separator());
3396     const size_t len = jvm_path_len + file_sep_len + 20;
3397     _default_shared_archive_path = NEW_C_HEAP_ARRAY(char, len, mtArguments);
3398     jio_snprintf(_default_shared_archive_path, len,
3399                 LP64_ONLY(!UseCompressedOops ? "%s%sclasses_nocoops.jsa":) "%s%sclasses.jsa",
3400                 jvm_path, os::file_separator());




3401   }
3402   return _default_shared_archive_path;
3403 }
3404 
3405 int Arguments::num_archives(const char* archive_path) {
3406   if (archive_path == nullptr) {
3407     return 0;
3408   }
3409   int npaths = 1;
3410   char* p = (char*)archive_path;
3411   while (*p != '\0') {
3412     if (*p == os::path_separator()[0]) {
3413       npaths++;
3414     }
3415     p++;
3416   }
3417   return npaths;
3418 }
3419 
3420 void Arguments::extract_shared_archive_paths(const char* archive_path,

4014 #ifdef ZERO
4015   // Clear flags not supported on zero.
4016   FLAG_SET_DEFAULT(ProfileInterpreter, false);
4017 #endif // ZERO
4018 
4019   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
4020     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
4021     DebugNonSafepoints = true;
4022   }
4023 
4024   if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
4025     warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
4026   }
4027 
4028   // Treat the odd case where local verification is enabled but remote
4029   // verification is not as if both were enabled.
4030   if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
4031     log_info(verification)("Turning on remote verification because local verification is on");
4032     FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
4033   }







4034 
4035 #ifndef PRODUCT
4036   if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
4037     if (use_vm_log()) {
4038       LogVMOutput = true;
4039     }
4040   }
4041 #endif // PRODUCT
4042 
4043   if (PrintCommandLineFlags) {
4044     JVMFlag::printSetFlags(tty);
4045   }
4046 
4047 #if COMPILER2_OR_JVMCI
4048   if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
4049     if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
4050       warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
4051     }
4052     FLAG_SET_DEFAULT(EnableVectorReboxing, false);
4053 

   1 /*
   2  * Copyright (c) 1997, 2024, 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  *

  57 #include "runtime/os.hpp"
  58 #include "runtime/safepoint.hpp"
  59 #include "runtime/safepointMechanism.hpp"
  60 #include "runtime/synchronizer.hpp"
  61 #include "runtime/vm_version.hpp"
  62 #include "services/management.hpp"
  63 #include "utilities/align.hpp"
  64 #include "utilities/checkedCast.hpp"
  65 #include "utilities/debug.hpp"
  66 #include "utilities/defaultStream.hpp"
  67 #include "utilities/macros.hpp"
  68 #include "utilities/parseInteger.hpp"
  69 #include "utilities/powerOfTwo.hpp"
  70 #include "utilities/stringUtils.hpp"
  71 #include "utilities/systemMemoryBarrier.hpp"
  72 #if INCLUDE_JFR
  73 #include "jfr/jfr.hpp"
  74 #endif
  75 
  76 #include <limits>
  77 #include <string.h>
  78 
  79 static const char _default_java_launcher[] = "generic";
  80 
  81 #define DEFAULT_JAVA_LAUNCHER _default_java_launcher
  82 
  83 char*  Arguments::_jvm_flags_file               = nullptr;
  84 char** Arguments::_jvm_flags_array              = nullptr;
  85 int    Arguments::_num_jvm_flags                = 0;
  86 char** Arguments::_jvm_args_array               = nullptr;
  87 int    Arguments::_num_jvm_args                 = 0;
  88 char*  Arguments::_java_command                 = nullptr;
  89 SystemProperty* Arguments::_system_properties   = nullptr;
  90 size_t Arguments::_conservative_max_heap_alignment = 0;
  91 Arguments::Mode Arguments::_mode                = _mixed;
  92 const char*  Arguments::_java_vendor_url_bug    = nullptr;
  93 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
  94 bool   Arguments::_sun_java_launcher_is_altjvm  = false;
  95 
  96 // These parameters are reset in method parse_vm_init_args()
  97 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;
  98 bool   Arguments::_UseOnStackReplacement        = UseOnStackReplacement;
  99 bool   Arguments::_BackgroundCompilation        = BackgroundCompilation;
 100 bool   Arguments::_ClipInlining                 = ClipInlining;
 101 size_t Arguments::_default_SharedBaseAddress    = SharedBaseAddress;
 102 
 103 bool   Arguments::_enable_preview               = false;
 104 bool   Arguments::_module_patching_disables_cds = false;
 105 
 106 char*  Arguments::_default_shared_archive_path  = nullptr;
 107 char*  Arguments::SharedArchivePath             = nullptr;
 108 char*  Arguments::SharedDynamicArchivePath      = nullptr;
 109 
 110 LegacyGCLogging Arguments::_legacyGCLogging     = { 0, 0 };
 111 
 112 // These are not set by the JDK's built-in launchers, but they can be set by
 113 // programs that embed the JVM using JNI_CreateJavaVM. See comments around
 114 // JavaVMOption in jni.h.
 115 abort_hook_t     Arguments::_abort_hook         = nullptr;
 116 exit_hook_t      Arguments::_exit_hook          = nullptr;
 117 vfprintf_hook_t  Arguments::_vfprintf_hook      = nullptr;
 118 
 119 
 120 SystemProperty *Arguments::_sun_boot_library_path = nullptr;
 121 SystemProperty *Arguments::_java_library_path = nullptr;
 122 SystemProperty *Arguments::_java_home = nullptr;
 123 SystemProperty *Arguments::_java_class_path = nullptr;
 124 SystemProperty *Arguments::_jdk_boot_class_path_append = nullptr;

1315       if (old_java_vendor_url_bug != nullptr) {
1316         os::free((void *)old_java_vendor_url_bug);
1317       }
1318     }
1319 
1320     // Create new property and add at the end of the list
1321     PropertyList_unique_add(&_system_properties, key, value, AddProperty, writeable, internal);
1322   }
1323 
1324   if (key != prop) {
1325     // SystemProperty copy passed value, thus free previously allocated
1326     // memory
1327     FreeHeap((void *)key);
1328   }
1329 
1330   return true;
1331 }
1332 
1333 #if INCLUDE_CDS
1334 const char* unsupported_properties[] = { "jdk.module.limitmods",
1335                                          "jdk.module.upgrade.path"};

1336 const char* unsupported_options[] = { "--limit-modules",
1337                                       "--upgrade-module-path"};


1338 void Arguments::check_unsupported_dumping_properties() {
1339   assert(CDSConfig::is_dumping_archive(),
1340          "this function is only used with CDS dump time");
1341   assert(ARRAY_SIZE(unsupported_properties) == ARRAY_SIZE(unsupported_options), "must be");
1342   // If a vm option is found in the unsupported_options array, vm will exit with an error message.
1343   SystemProperty* sp = system_properties();
1344   while (sp != nullptr) {
1345     for (uint i = 0; i < ARRAY_SIZE(unsupported_properties); i++) {
1346       if (strcmp(sp->key(), unsupported_properties[i]) == 0) {
1347         vm_exit_during_initialization(
1348           "Cannot use the following option when dumping the shared archive", unsupported_options[i]);
1349       }
1350     }
1351     sp = sp->next();
1352   }
1353 
1354   if (_module_patching_disables_cds) {
1355     vm_exit_during_initialization(
1356             "Cannot use the following option when dumping the shared archive", "--patch-module");
1357   }
1358 
1359   // Check for an exploded module build in use with -Xshare:dump.
1360   if (!has_jimage()) {
1361     vm_exit_during_initialization("Dumping the shared archive is not supported with an exploded module build");
1362   }
1363 }
1364 
1365 bool Arguments::check_unsupported_cds_runtime_properties() {
1366   assert(UseSharedSpaces, "this function is only used with -Xshare:{on,auto}");
1367   assert(ARRAY_SIZE(unsupported_properties) == ARRAY_SIZE(unsupported_options), "must be");
1368   if (ArchiveClassesAtExit != nullptr) {
1369     // dynamic dumping, just return false for now.
1370     // check_unsupported_dumping_properties() will be called later to check the same set of
1371     // properties, and will exit the VM with the correct error message if the unsupported properties
1372     // are used.
1373     return false;
1374   }
1375   for (uint i = 0; i < ARRAY_SIZE(unsupported_properties); i++) {
1376     if (get_property(unsupported_properties[i]) != nullptr) {
1377       if (RequireSharedSpaces) {
1378         warning("CDS is disabled when the %s option is specified.", unsupported_options[i]);
1379       } else {
1380         log_info(cds)("CDS is disabled when the %s option is specified.", unsupported_options[i]);
1381       }
1382       return true;
1383     }
1384   }
1385 
1386   if (_module_patching_disables_cds) {
1387     if (RequireSharedSpaces) {
1388       warning("CDS is disabled when the %s option is specified.", "--patch-module");
1389     } else {
1390       log_info(cds)("CDS is disabled when the %s option is specified.", "--patch-module");
1391     }
1392     return true;
1393   }
1394 
1395   return false;
1396 }
1397 #endif
1398 
1399 //===========================================================================================================
1400 // Setting int/mixed/comp mode flags
1401 
1402 void Arguments::set_mode_flags(Mode mode) {
1403   // Set up default values for all flags.
1404   // If you add a flag to any of the branches below,
1405   // add a default value for it here.
1406   _mode                      = mode;
1407 
1408   // Ensure Agent_OnLoad has the correct initial values.
1409   // This may not be the final mode; mode may change later in onload phase.
1410   PropertyList_unique_add(&_system_properties, "java.vm.info",
1411                           VM_Version::vm_info_string(), AddProperty, UnwriteableProperty, ExternalProperty);
1412 
1413   UseInterpreter             = true;
1414   UseCompiler                = true;

1864   }
1865   _sun_java_launcher = os::strdup_check_oom(launcher);
1866 }
1867 
1868 bool Arguments::created_by_java_launcher() {
1869   assert(_sun_java_launcher != nullptr, "property must have value");
1870   return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1871 }
1872 
1873 bool Arguments::sun_java_launcher_is_altjvm() {
1874   return _sun_java_launcher_is_altjvm;
1875 }
1876 
1877 //===========================================================================================================
1878 // Parsing of main arguments
1879 
1880 unsigned int addreads_count = 0;
1881 unsigned int addexports_count = 0;
1882 unsigned int addopens_count = 0;
1883 unsigned int addmods_count = 0;

1884 unsigned int enable_native_access_count = 0;
1885 
1886 // Check the consistency of vm_init_args
1887 bool Arguments::check_vm_args_consistency() {
1888   // Method for adding checks for flag consistency.
1889   // The intent is to warn the user of all possible conflicts,
1890   // before returning an error.
1891   // Note: Needs platform-dependent factoring.
1892   bool status = true;
1893 
1894   if (TLABRefillWasteFraction == 0) {
1895     jio_fprintf(defaultStream::error_stream(),
1896                 "TLABRefillWasteFraction should be a denominator, "
1897                 "not " SIZE_FORMAT "\n",
1898                 TLABRefillWasteFraction);
1899     status = false;
1900   }
1901 
1902   status = CompilerConfig::check_args_consistency(status);
1903 #if INCLUDE_JVMCI

1910       }
1911     }
1912   }
1913 #endif
1914 
1915 #if INCLUDE_JFR
1916   if (status && (FlightRecorderOptions || StartFlightRecording)) {
1917     if (!create_numbered_module_property("jdk.module.addmods", "jdk.jfr", addmods_count++)) {
1918       return false;
1919     }
1920   }
1921 #endif
1922 
1923 #ifndef SUPPORT_RESERVED_STACK_AREA
1924   if (StackReservedPages != 0) {
1925     FLAG_SET_CMDLINE(StackReservedPages, 0);
1926     warning("Reserved Stack Area not supported on this platform");
1927   }
1928 #endif
1929 
1930   if (AMD64_ONLY(false &&) AARCH64_ONLY(false &&) !FLAG_IS_DEFAULT(InlineTypePassFieldsAsArgs)) {
1931     FLAG_SET_CMDLINE(InlineTypePassFieldsAsArgs, false);
1932     warning("InlineTypePassFieldsAsArgs is not supported on this platform");
1933   }
1934 
1935   if (AMD64_ONLY(false &&) AARCH64_ONLY(false &&) !FLAG_IS_DEFAULT(InlineTypeReturnedAsFields)) {
1936     FLAG_SET_CMDLINE(InlineTypeReturnedAsFields, false);
1937     warning("InlineTypeReturnedAsFields is not supported on this platform");
1938   }
1939 
1940   // Valhalla missing LM_LIGHTWEIGHT support just now
1941   if (EnableValhalla && LockingMode != LM_LEGACY) {
1942     FLAG_SET_CMDLINE(LockingMode, LM_LEGACY);
1943   }
1944 #if !defined(X86) && !defined(AARCH64) && !defined(RISCV64) && !defined(ARM) && !defined(PPC64) && !defined(S390)
1945   if (LockingMode == LM_LIGHTWEIGHT) {
1946     FLAG_SET_CMDLINE(LockingMode, LM_LEGACY);
1947     warning("New lightweight locking not supported on this platform");
1948   }
1949 #endif
1950 
1951 #if !defined(X86) && !defined(AARCH64) && !defined(PPC64) && !defined(RISCV64) && !defined(S390)
1952   if (LockingMode == LM_MONITOR) {
1953     jio_fprintf(defaultStream::error_stream(),
1954                 "LockingMode == 0 (LM_MONITOR) is not fully implemented on this architecture\n");
1955     return false;
1956   }
1957 #endif
1958 #if defined(X86) && !defined(ZERO)
1959   if (LockingMode == LM_MONITOR && UseRTMForStackLocks) {
1960     jio_fprintf(defaultStream::error_stream(),
1961                 "LockingMode == 0 (LM_MONITOR) and -XX:+UseRTMForStackLocks are mutually exclusive\n");
1962 
1963     return false;

2050   }
2051 
2052   jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
2053   return false;
2054 }
2055 
2056 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
2057                                                   julong* long_arg,
2058                                                   julong min_size,
2059                                                   julong max_size) {
2060   if (!parse_integer(s, long_arg)) return arg_unreadable;
2061   return check_memory_size(*long_arg, min_size, max_size);
2062 }
2063 
2064 // Parse JavaVMInitArgs structure
2065 
2066 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
2067                                    const JavaVMInitArgs *java_tool_options_args,
2068                                    const JavaVMInitArgs *java_options_args,
2069                                    const JavaVMInitArgs *cmd_line_args) {


2070   // Save default settings for some mode flags
2071   Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
2072   Arguments::_UseOnStackReplacement    = UseOnStackReplacement;
2073   Arguments::_ClipInlining             = ClipInlining;
2074   Arguments::_BackgroundCompilation    = BackgroundCompilation;
2075 
2076   // Remember the default value of SharedBaseAddress.
2077   Arguments::_default_SharedBaseAddress = SharedBaseAddress;
2078 
2079   // Setup flags for mixed which is the default
2080   set_mode_flags(_mixed);
2081 
2082   // Parse args structure generated from java.base vm options resource
2083   jint result = parse_each_vm_init_arg(vm_options_args, JVMFlagOrigin::JIMAGE_RESOURCE);
2084   if (result != JNI_OK) {
2085     return result;
2086   }
2087 
2088   // Parse args structure generated from JAVA_TOOL_OPTIONS environment
2089   // variable (if present).
2090   result = parse_each_vm_init_arg(java_tool_options_args, JVMFlagOrigin::ENVIRON_VAR);
2091   if (result != JNI_OK) {
2092     return result;
2093   }
2094 
2095   // Parse args structure generated from the command line flags.
2096   result = parse_each_vm_init_arg(cmd_line_args, JVMFlagOrigin::COMMAND_LINE);
2097   if (result != JNI_OK) {
2098     return result;
2099   }
2100 
2101   // Parse args structure generated from the _JAVA_OPTIONS environment
2102   // variable (if present) (mimics classic VM)
2103   result = parse_each_vm_init_arg(java_options_args, JVMFlagOrigin::ENVIRON_VAR);
2104   if (result != JNI_OK) {
2105     return result;
2106   }
2107 
2108   // Disable CDS for exploded image
2109   if (!has_jimage()) {
2110     no_shared_spaces("CDS disabled on exploded JDK");
2111   }
2112 
2113   // We need to ensure processor and memory resources have been properly
2114   // configured - which may rely on arguments we just processed - before
2115   // doing the final argument processing. Any argument processing that
2116   // needs to know about processor and memory resources must occur after
2117   // this point.
2118 
2119   os::init_container_support();
2120 
2121   SystemMemoryBarrier::initialize();
2122 
2123   // Do final processing now that all arguments have been parsed
2124   result = finalize_vm_init_args();
2125   if (result != JNI_OK) {
2126     return result;
2127   }
2128 
2129   return JNI_OK;
2130 }
2131 
2132 // Checks if name in command-line argument -agent{lib,path}:name[=options]
2133 // represents a valid JDWP agent.  is_path==true denotes that we
2134 // are dealing with -agentpath (case where name is a path), otherwise with
2135 // -agentlib
2136 bool valid_jdwp_agent(char *name, bool is_path) {
2137   char *_name;
2138   const char *_jdwp = "jdwp";
2139   size_t _len_jdwp, _len_prefix;
2140 
2141   if (is_path) {
2142     if ((_name = strrchr(name, (int) *os::file_separator())) == nullptr) {
2143       return false;
2144     }

2157       _name += _len_jdwp;
2158     }
2159     else {
2160       return false;
2161     }
2162 
2163     if (strcmp(_name, JNI_LIB_SUFFIX) != 0) {
2164       return false;
2165     }
2166 
2167     return true;
2168   }
2169 
2170   if (strcmp(name, _jdwp) == 0) {
2171     return true;
2172   }
2173 
2174   return false;
2175 }
2176 
2177 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2178   // --patch-module=<module>=<file>(<pathsep><file>)*
2179   assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2180   // Find the equal sign between the module name and the path specification
2181   const char* module_equal = strchr(patch_mod_tail, '=');
2182   if (module_equal == nullptr) {
2183     jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2184     return JNI_ERR;
2185   } else {
2186     // Pick out the module name
2187     size_t module_len = module_equal - patch_mod_tail;
2188     char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2189     if (module_name != nullptr) {
2190       memcpy(module_name, patch_mod_tail, module_len);
2191       *(module_name + module_len) = '\0';
2192       // The path piece begins one past the module_equal sign
2193       add_patch_mod_prefix(module_name, module_equal + 1, false /* no append */, false /* no cds */);
2194       FREE_C_HEAP_ARRAY(char, module_name);



2195     } else {
2196       return JNI_ENOMEM;
2197     }
2198   }
2199   return JNI_OK;
2200 }
2201 
2202 // VALUECLASS_STR must match string used in the build
2203 #define VALUECLASS_STR "valueclasses"
2204 #define VALUECLASS_JAR "-" VALUECLASS_STR ".jar"
2205 
2206 // Finalize --patch-module args and --enable-preview related to value class module patches.
2207 // Create all numbered properties passing module patches.
2208 int Arguments::finalize_patch_module() {
2209   // If --enable-preview and EnableValhalla is true, each module may have value classes that
2210   // are to be patched into the module.
2211   // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2212   // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2213   if (enable_preview() && EnableValhalla) {
2214     char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2215     const char * fileSep = os::file_separator();
2216 
2217     jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s",
2218                  Arguments::get_java_home(), fileSep, fileSep, fileSep);
2219     DIR* dir = os::opendir(valueclasses_dir);
2220     if (dir != nullptr) {
2221       char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2222       char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2223 
2224       for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) {
2225         // Test if file ends-with "-valueclasses.jar"
2226         int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1);
2227         if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) {
2228           continue;         // too short or not the expected suffix
2229         }
2230 
2231         strcpy(module_name, entry->d_name);
2232         module_name[len] = '\0';     // truncate to just module-name
2233 
2234         jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name);
2235         add_patch_mod_prefix(module_name, path, true /* append */, true /* cds OK*/);
2236         log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name);
2237       }
2238       FreeHeap(module_name);
2239       FreeHeap(path);
2240       os::closedir(dir);
2241     }
2242     FreeHeap(valueclasses_dir);
2243   }
2244 
2245   // Create numbered properties for each module that has been patched either
2246   // by --patch-module or --enable-preview
2247   // Format is "jdk.module.patch.<n>=<module_name>=<path>"
2248   if (_patch_mod_prefix != nullptr) {
2249     char * prop_value = AllocateHeap(JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, mtArguments);
2250     unsigned int patch_mod_count = 0;
2251 
2252     for (GrowableArrayIterator<ModulePatchPath *> it = _patch_mod_prefix->begin();
2253             it != _patch_mod_prefix->end(); ++it) {
2254       jio_snprintf(prop_value, JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, "%s=%s",
2255                    (*it)->module_name(), (*it)->path_string());
2256       if (!create_numbered_module_property("jdk.module.patch", prop_value, patch_mod_count++)) {
2257         FreeHeap(prop_value);
2258         return JNI_ENOMEM;
2259       }
2260     }
2261     FreeHeap(prop_value);
2262   }
2263   return JNI_OK;
2264 }
2265 
2266 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2267 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2268   // The min and max sizes match the values in globals.hpp, but scaled
2269   // with K. The values have been chosen so that alignment with page
2270   // size doesn't change the max value, which makes the conversions
2271   // back and forth between Xss value and ThreadStackSize value easier.
2272   // The values have also been chosen to fit inside a 32-bit signed type.
2273   const julong min_ThreadStackSize = 0;
2274   const julong max_ThreadStackSize = 1 * M;
2275 
2276   // Make sure the above values match the range set in globals.hpp
2277   const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2278   assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2279   assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2280 
2281   const julong min_size = min_ThreadStackSize * K;
2282   const julong max_size = max_ThreadStackSize * K;
2283 
2284   assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2285 

2300   assert(size <= size_aligned,
2301          "Overflow: " JULONG_FORMAT " " JULONG_FORMAT,
2302          size, size_aligned);
2303 
2304   const julong size_in_K = size_aligned / K;
2305   assert(size_in_K < (julong)max_intx,
2306          "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT,
2307          size_in_K);
2308 
2309   // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow.
2310   const julong max_expanded = align_up(size_in_K * K, os::vm_page_size());
2311   assert(max_expanded < max_uintx && max_expanded >= size_in_K,
2312          "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT,
2313          max_expanded, size_in_K);
2314 
2315   *out_ThreadStackSize = (intx)size_in_K;
2316 
2317   return JNI_OK;
2318 }
2319 
2320 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, JVMFlagOrigin origin) {
2321   // For match_option to return remaining or value part of option string
2322   const char* tail;
2323 
2324   // iterate over arguments
2325   for (int index = 0; index < args->nOptions; index++) {
2326     bool is_absolute_path = false;  // for -agentpath vs -agentlib
2327 
2328     const JavaVMOption* option = args->options + index;
2329 
2330     if (!match_option(option, "-Djava.class.path", &tail) &&
2331         !match_option(option, "-Dsun.java.command", &tail) &&
2332         !match_option(option, "-Dsun.java.launcher", &tail)) {
2333 
2334         // add all jvm options to the jvm_args string. This string
2335         // is used later to set the java.vm.args PerfData string constant.
2336         // the -Djava.class.path and the -Dsun.java.command options are
2337         // omitted from jvm_args string as each have their own PerfData
2338         // string constant object.
2339         build_jvm_args(option->optionString);
2340     }

2427         return JNI_ENOMEM;
2428       }
2429     } else if (match_option(option, "--enable-native-access=", &tail)) {
2430       if (!create_numbered_module_property("jdk.module.enable.native.access", tail, enable_native_access_count++)) {
2431         return JNI_ENOMEM;
2432       }
2433     } else if (match_option(option, "--limit-modules=", &tail)) {
2434       if (!create_module_property("jdk.module.limitmods", tail, InternalProperty)) {
2435         return JNI_ENOMEM;
2436       }
2437     } else if (match_option(option, "--module-path=", &tail)) {
2438       if (!create_module_property("jdk.module.path", tail, ExternalProperty)) {
2439         return JNI_ENOMEM;
2440       }
2441     } else if (match_option(option, "--upgrade-module-path=", &tail)) {
2442       if (!create_module_property("jdk.module.upgrade.path", tail, ExternalProperty)) {
2443         return JNI_ENOMEM;
2444       }
2445     } else if (match_option(option, "--patch-module=", &tail)) {
2446       // --patch-module=<module>=<file>(<pathsep><file>)*
2447       int res = process_patch_mod_option(tail);
2448       if (res != JNI_OK) {
2449         return res;
2450       }
2451     } else if (match_option(option, "--illegal-access=", &tail)) {
2452       char version[256];
2453       JDK_Version::jdk(17).to_string(version, sizeof(version));
2454       warning("Ignoring option %s; support was removed in %s", option->optionString, version);
2455     // -agentlib and -agentpath
2456     } else if (match_option(option, "-agentlib:", &tail) ||
2457           (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2458       if(tail != nullptr) {
2459         const char* pos = strchr(tail, '=');
2460         char* name;
2461         if (pos == nullptr) {
2462           name = os::strdup_check_oom(tail, mtArguments);
2463         } else {
2464           size_t len = pos - tail;
2465           name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments);
2466           memcpy(name, tail, len);
2467           name[len] = '\0';

2488       jio_fprintf(defaultStream::error_stream(),
2489         "Instrumentation agents are not supported in this VM\n");
2490       return JNI_ERR;
2491 #else
2492       if (tail != nullptr) {
2493         size_t length = strlen(tail) + 1;
2494         char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2495         jio_snprintf(options, length, "%s", tail);
2496         JvmtiAgentList::add("instrument", options, false);
2497         FREE_C_HEAP_ARRAY(char, options);
2498 
2499         // java agents need module java.instrument
2500         if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", addmods_count++)) {
2501           return JNI_ENOMEM;
2502         }
2503       }
2504 #endif // !INCLUDE_JVMTI
2505     // --enable_preview
2506     } else if (match_option(option, "--enable-preview")) {
2507       set_enable_preview();
2508       // --enable-preview enables Valhalla, EnableValhalla VM option will eventually be removed before integration
2509       if (FLAG_SET_CMDLINE(EnableValhalla, true) != JVMFlag::SUCCESS) {
2510         return JNI_EINVAL;
2511       }
2512     // -Xnoclassgc
2513     } else if (match_option(option, "-Xnoclassgc")) {
2514       if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2515         return JNI_EINVAL;
2516       }
2517     // -Xbatch
2518     } else if (match_option(option, "-Xbatch")) {
2519       if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2520         return JNI_EINVAL;
2521       }
2522     // -Xmn for compatibility with other JVM vendors
2523     } else if (match_option(option, "-Xmn", &tail)) {
2524       julong long_initial_young_size = 0;
2525       ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2526       if (errcode != arg_in_range) {
2527         jio_fprintf(defaultStream::error_stream(),
2528                     "Invalid initial young generation size: %s\n", option->optionString);
2529         describe_range_error(errcode);
2530         return JNI_EINVAL;
2531       }

2974     // Unknown option
2975     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2976       return JNI_ERR;
2977     }
2978   }
2979 
2980   // PrintSharedArchiveAndExit will turn on
2981   //   -Xshare:on
2982   //   -Xlog:class+path=info
2983   if (PrintSharedArchiveAndExit) {
2984     UseSharedSpaces = true;
2985     RequireSharedSpaces = true;
2986     LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2987   }
2988 
2989   fix_appclasspath();
2990 
2991   return JNI_OK;
2992 }
2993 
2994 bool match_module(void *module_name, ModulePatchPath *patch) {
2995   return (strcmp((char *)module_name, patch->module_name()) == 0);
2996 }
2997 
2998 static bool _java_base_module_patching_disables_cds = false;
2999 bool Arguments::patch_mod_javabase() {
3000   return _java_base_module_patching_disables_cds;
3001 }
3002 
3003 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) {
3004   if (!allow_cds) {
3005     _module_patching_disables_cds = true;
3006     if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
3007       _java_base_module_patching_disables_cds = true;
3008     }
3009   }
3010 
3011   // Create GrowableArray lazily, only if --patch-module has been specified
3012   if (_patch_mod_prefix == nullptr) {
3013     _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
3014   }
3015 
3016   // Scan patches for matching module
3017   int i = _patch_mod_prefix->find((void*)module_name, match_module);
3018   if (i == -1) {
3019     _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
3020   } else {
3021     if (allow_append) {
3022       // append path to existing module entry
3023       _patch_mod_prefix->at(i)->append_path(path);
3024     } else {
3025       if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
3026         vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
3027       } else {
3028         vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
3029       }
3030     }
3031   }
3032 }
3033 
3034 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
3035 //
3036 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
3037 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
3038 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
3039 // path is treated as the current directory.
3040 //
3041 // This causes problems with CDS, which requires that all directories specified in the classpath
3042 // must be empty. In most cases, applications do NOT want to load classes from the current
3043 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
3044 // scripts compatible with CDS.
3045 void Arguments::fix_appclasspath() {
3046   if (IgnoreEmptyClassPaths) {
3047     const char separator = *os::path_separator();
3048     const char* src = _java_class_path->value();
3049 
3050     // skip over all the leading empty paths
3051     while (*src == separator) {

3054 
3055     char* copy = os::strdup_check_oom(src, mtArguments);
3056 
3057     // trim all trailing empty paths
3058     for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
3059       *tail = '\0';
3060     }
3061 
3062     char from[3] = {separator, separator, '\0'};
3063     char to  [2] = {separator, '\0'};
3064     while (StringUtils::replace_no_expand(copy, from, to) > 0) {
3065       // Keep replacing "::" -> ":" until we have no more "::" (non-windows)
3066       // Keep replacing ";;" -> ";" until we have no more ";;" (windows)
3067     }
3068 
3069     _java_class_path->set_writeable_value(copy);
3070     FreeHeap(copy); // a copy was made by set_value, so don't need this anymore
3071   }
3072 }
3073 
3074 jint Arguments::finalize_vm_init_args() {
3075   // check if the default lib/endorsed directory exists; if so, error
3076   char path[JVM_MAXPATHLEN];
3077   const char* fileSep = os::file_separator();
3078   jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
3079 
3080   DIR* dir = os::opendir(path);
3081   if (dir != nullptr) {
3082     jio_fprintf(defaultStream::output_stream(),
3083       "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n"
3084       "in modular form will be supported via the concept of upgradeable modules.\n");
3085     os::closedir(dir);
3086     return JNI_ERR;
3087   }
3088 
3089   jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
3090   dir = os::opendir(path);
3091   if (dir != nullptr) {
3092     jio_fprintf(defaultStream::output_stream(),
3093       "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; "
3094       "Use -classpath instead.\n.");

3128   if (FLAG_IS_DEFAULT(UseLargePages) &&
3129       MaxHeapSize < LargePageHeapSizeThreshold) {
3130     // No need for large granularity pages w/small heaps.
3131     // Note that large pages are enabled/disabled for both the
3132     // Java heap and the code cache.
3133     FLAG_SET_DEFAULT(UseLargePages, false);
3134   }
3135 
3136   UNSUPPORTED_OPTION(ProfileInterpreter);
3137 #endif
3138 
3139   // Parse the CompilationMode flag
3140   if (!CompilationModeFlag::initialize()) {
3141     return JNI_ERR;
3142   }
3143 
3144   if (!check_vm_args_consistency()) {
3145     return JNI_ERR;
3146   }
3147 
3148   // finalize --module-patch and related --enable-preview
3149   if (finalize_patch_module() != JNI_OK) {
3150     return JNI_ERR;
3151   }
3152 
3153 #if INCLUDE_CDS
3154   if (CDSConfig::is_dumping_static_archive()) {
3155     if (!mode_flag_cmd_line) {
3156       // By default, -Xshare:dump runs in interpreter-only mode, which is required for deterministic archive.
3157       //
3158       // If your classlist is large and you don't care about deterministic dumping, you can use
3159       // -Xshare:dump -Xmixed to improve dumping speed.
3160       set_mode_flags(_int);
3161     } else if (_mode == _comp) {
3162       // -Xcomp may use excessive CPU for the test tiers. Also, -Xshare:dump runs a small and fixed set of
3163       // Java code, so there's not much benefit in running -Xcomp.
3164       log_info(cds)("reduced -Xcomp to -Xmixed for static dumping");
3165       set_mode_flags(_mixed);
3166     }
3167 
3168     // String deduplication may cause CDS to iterate the strings in different order from one
3169     // run to another which resulting in non-determinstic CDS archives.
3170     // Disable UseStringDeduplication while dumping CDS archive.
3171     UseStringDeduplication = false;
3172   }

3178     return JNI_ERR;
3179   }
3180 
3181   if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
3182     CDSConfig::disable_dumping_dynamic_archive();
3183   } else {
3184     CDSConfig::enable_dumping_dynamic_archive();
3185   }
3186 
3187   if (AutoCreateSharedArchive) {
3188     if (SharedArchiveFile == nullptr) {
3189       log_warning(cds)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
3190       return JNI_ERR;
3191     }
3192     if (ArchiveClassesAtExit != nullptr) {
3193       log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
3194       return JNI_ERR;
3195     }
3196   }
3197 
3198   if (UseSharedSpaces && patch_mod_javabase() && _module_patching_disables_cds) {
3199     no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
3200   }
3201   if (UseSharedSpaces && check_unsupported_cds_runtime_properties()) {
3202     UseSharedSpaces = false;
3203   }
3204 
3205   if (CDSConfig::is_dumping_archive()) {
3206     // Always verify non-system classes during CDS dump
3207     if (!BytecodeVerificationRemote) {
3208       BytecodeVerificationRemote = true;
3209       log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
3210     }
3211   }
3212 #endif
3213 
3214 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3215   UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3216 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3217 
3218   return JNI_OK;

3490   // This must be after set_ergonomics_flags() called so flag UseCompressedOops is set properly.
3491   //
3492   // UseSharedSpaces may be disabled if -XX:SharedArchiveFile is invalid.
3493   if (CDSConfig::is_dumping_static_archive() || UseSharedSpaces) {
3494     init_shared_archive_paths();
3495   }
3496 #endif  // INCLUDE_CDS
3497 }
3498 
3499 #if INCLUDE_CDS
3500 // Sharing support
3501 // Construct the path to the archive
3502 char* Arguments::get_default_shared_archive_path() {
3503   if (_default_shared_archive_path == nullptr) {
3504     char jvm_path[JVM_MAXPATHLEN];
3505     os::jvm_path(jvm_path, sizeof(jvm_path));
3506     char *end = strrchr(jvm_path, *os::file_separator());
3507     if (end != nullptr) *end = '\0';
3508     size_t jvm_path_len = strlen(jvm_path);
3509     size_t file_sep_len = strlen(os::file_separator());
3510     const size_t len = jvm_path_len + file_sep_len + strlen("classes_nocoops_valhalla.jsa") + 1;
3511     _default_shared_archive_path = NEW_C_HEAP_ARRAY(char, len, mtArguments);
3512     LP64_ONLY(bool nocoops = !UseCompressedOops);
3513     NOT_LP64(bool nocoops = false);
3514     bool valhalla = CDSConfig::is_valhalla_preview();
3515     jio_snprintf(_default_shared_archive_path, len, "%s%sclasses%s%s.jsa",
3516                 jvm_path, os::file_separator(),
3517                  nocoops ? "_nocoops" : "",
3518                  valhalla ? "_valhalla" : "");
3519   }
3520   return _default_shared_archive_path;
3521 }
3522 
3523 int Arguments::num_archives(const char* archive_path) {
3524   if (archive_path == nullptr) {
3525     return 0;
3526   }
3527   int npaths = 1;
3528   char* p = (char*)archive_path;
3529   while (*p != '\0') {
3530     if (*p == os::path_separator()[0]) {
3531       npaths++;
3532     }
3533     p++;
3534   }
3535   return npaths;
3536 }
3537 
3538 void Arguments::extract_shared_archive_paths(const char* archive_path,

4132 #ifdef ZERO
4133   // Clear flags not supported on zero.
4134   FLAG_SET_DEFAULT(ProfileInterpreter, false);
4135 #endif // ZERO
4136 
4137   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
4138     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
4139     DebugNonSafepoints = true;
4140   }
4141 
4142   if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
4143     warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
4144   }
4145 
4146   // Treat the odd case where local verification is enabled but remote
4147   // verification is not as if both were enabled.
4148   if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
4149     log_info(verification)("Turning on remote verification because local verification is on");
4150     FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
4151   }
4152   if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) {
4153     // Disable calling convention optimizations if inline types are not supported.
4154     // Also these aren't useful in -Xint. However, don't disable them when dumping or using
4155     // the CDS archive, as the values must match between dumptime and runtime.
4156     InlineTypePassFieldsAsArgs = false;
4157     InlineTypeReturnedAsFields = false;
4158   }
4159 
4160 #ifndef PRODUCT
4161   if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
4162     if (use_vm_log()) {
4163       LogVMOutput = true;
4164     }
4165   }
4166 #endif // PRODUCT
4167 
4168   if (PrintCommandLineFlags) {
4169     JVMFlag::printSetFlags(tty);
4170   }
4171 
4172 #if COMPILER2_OR_JVMCI
4173   if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
4174     if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
4175       warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
4176     }
4177     FLAG_SET_DEFAULT(EnableVectorReboxing, false);
4178 
< prev index next >