< prev index next >

src/hotspot/share/runtime/arguments.cpp

Print this page

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

  75 
  76 static const char _default_java_launcher[] = "generic";
  77 
  78 #define DEFAULT_JAVA_LAUNCHER _default_java_launcher
  79 
  80 char*  Arguments::_jvm_flags_file               = nullptr;
  81 char** Arguments::_jvm_flags_array              = nullptr;
  82 int    Arguments::_num_jvm_flags                = 0;
  83 char** Arguments::_jvm_args_array               = nullptr;
  84 int    Arguments::_num_jvm_args                 = 0;
  85 char*  Arguments::_java_command                 = nullptr;
  86 SystemProperty* Arguments::_system_properties   = nullptr;
  87 size_t Arguments::_conservative_max_heap_alignment = 0;
  88 Arguments::Mode Arguments::_mode                = _mixed;
  89 const char*  Arguments::_java_vendor_url_bug    = nullptr;
  90 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
  91 bool   Arguments::_sun_java_launcher_is_altjvm  = false;
  92 
  93 // These parameters are reset in method parse_vm_init_args()
  94 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;

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

1885       }
1886     }
1887   }
1888 #endif
1889 
1890 #if INCLUDE_JFR
1891   if (status && (FlightRecorderOptions || StartFlightRecording)) {
1892     if (!create_numbered_module_property("jdk.module.addmods", "jdk.jfr", addmods_count++)) {
1893       return false;
1894     }
1895   }
1896 #endif
1897 
1898 #ifndef SUPPORT_RESERVED_STACK_AREA
1899   if (StackReservedPages != 0) {
1900     FLAG_SET_CMDLINE(StackReservedPages, 0);
1901     warning("Reserved Stack Area not supported on this platform");
1902   }
1903 #endif
1904 










1905 
1906 #if !defined(X86) && !defined(AARCH64) && !defined(RISCV64) && !defined(ARM) && !defined(PPC64)
1907   if (LockingMode == LM_LIGHTWEIGHT) {
1908     FLAG_SET_CMDLINE(LockingMode, LM_LEGACY);
1909     warning("New lightweight locking not supported on this platform");
1910   }
1911 #endif
1912 
1913   if (UseHeavyMonitors) {
1914     if (FLAG_IS_CMDLINE(LockingMode) && LockingMode != LM_MONITOR) {
1915       jio_fprintf(defaultStream::error_stream(),
1916                   "Conflicting -XX:+UseHeavyMonitors and -XX:LockingMode=%d flags\n", LockingMode);
1917       return false;
1918     }
1919     FLAG_SET_CMDLINE(LockingMode, LM_MONITOR);
1920   }
1921 
1922 #if !defined(X86) && !defined(AARCH64) && !defined(PPC64) && !defined(RISCV64) && !defined(S390)
1923   if (LockingMode == LM_MONITOR) {
1924     jio_fprintf(defaultStream::error_stream(),

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

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
































































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

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

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

2865 #endif // INCLUDE_JVMCI
2866 #if INCLUDE_JFR
2867     } else if (match_jfr_option(&option)) {
2868       return JNI_EINVAL;
2869 #endif
2870     } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx
2871       // Skip -XX:Flags= and -XX:VMOptionsFile= since those cases have
2872       // already been handled
2873       if ((strncmp(tail, "Flags=", strlen("Flags=")) != 0) &&
2874           (strncmp(tail, "VMOptionsFile=", strlen("VMOptionsFile=")) != 0)) {
2875         if (!process_argument(tail, args->ignoreUnrecognized, origin)) {
2876           return JNI_EINVAL;
2877         }
2878       }
2879     // Unknown option
2880     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2881       return JNI_ERR;
2882     }
2883   }
2884 






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





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















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

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

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





3034 #if INCLUDE_CDS
3035   if (DumpSharedSpaces) {
3036     // Compiler threads may concurrently update the class metadata (such as method entries), so it's
3037     // unsafe with -Xshare:dump (which modifies the class metadata in place). Let's disable
3038     // compiler just to be safe.
3039     //
3040     // Note: this is not a concern for dynamically dumping shared spaces, which makes a copy of the
3041     // class metadata instead of modifying them in place. The copy is inaccessible to the compiler.
3042     // TODO: revisit the following for the static archive case.
3043     set_mode_flags(_int);
3044 
3045     // String deduplication may cause CDS to iterate the strings in different order from one
3046     // run to another which resulting in non-determinstic CDS archives.
3047     // Disable UseStringDeduplication while dumping CDS archive.
3048     UseStringDeduplication = false;
3049   }
3050 
3051   // RecordDynamicDumpInfo is not compatible with ArchiveClassesAtExit
3052   if (ArchiveClassesAtExit != nullptr && RecordDynamicDumpInfo) {
3053     jio_fprintf(defaultStream::output_stream(),

3055     return JNI_ERR;
3056   }
3057 
3058   if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
3059     DynamicDumpSharedSpaces = false;
3060   } else {
3061     DynamicDumpSharedSpaces = true;
3062   }
3063 
3064   if (AutoCreateSharedArchive) {
3065     if (SharedArchiveFile == nullptr) {
3066       log_warning(cds)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
3067       return JNI_ERR;
3068     }
3069     if (ArchiveClassesAtExit != nullptr) {
3070       log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
3071       return JNI_ERR;
3072     }
3073   }
3074 
3075   if (UseSharedSpaces && patch_mod_javabase) {
3076     no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
3077   }
3078   if (UseSharedSpaces && !DumpSharedSpaces && check_unsupported_cds_runtime_properties()) {
3079     UseSharedSpaces = false;
3080   }
3081 
3082   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
3083     // Always verify non-system classes during CDS dump
3084     if (!BytecodeVerificationRemote) {
3085       BytecodeVerificationRemote = true;
3086       log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
3087     }
3088   }
3089 #endif
3090 
3091 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3092   UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3093 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3094 
3095   return JNI_OK;

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







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

  55 #include "runtime/os.hpp"
  56 #include "runtime/safepoint.hpp"
  57 #include "runtime/safepointMechanism.hpp"
  58 #include "runtime/synchronizer.hpp"
  59 #include "runtime/vm_version.hpp"
  60 #include "services/management.hpp"
  61 #include "services/nmtCommon.hpp"
  62 #include "utilities/align.hpp"
  63 #include "utilities/debug.hpp"
  64 #include "utilities/defaultStream.hpp"
  65 #include "utilities/macros.hpp"
  66 #include "utilities/parseInteger.hpp"
  67 #include "utilities/powerOfTwo.hpp"
  68 #include "utilities/stringUtils.hpp"
  69 #include "utilities/systemMemoryBarrier.hpp"
  70 #if INCLUDE_JFR
  71 #include "jfr/jfr.hpp"
  72 #endif
  73 
  74 #include <limits>
  75 #include <string.h>
  76 
  77 static const char _default_java_launcher[] = "generic";
  78 
  79 #define DEFAULT_JAVA_LAUNCHER _default_java_launcher
  80 
  81 char*  Arguments::_jvm_flags_file               = nullptr;
  82 char** Arguments::_jvm_flags_array              = nullptr;
  83 int    Arguments::_num_jvm_flags                = 0;
  84 char** Arguments::_jvm_args_array               = nullptr;
  85 int    Arguments::_num_jvm_args                 = 0;
  86 char*  Arguments::_java_command                 = nullptr;
  87 SystemProperty* Arguments::_system_properties   = nullptr;
  88 size_t Arguments::_conservative_max_heap_alignment = 0;
  89 Arguments::Mode Arguments::_mode                = _mixed;
  90 const char*  Arguments::_java_vendor_url_bug    = nullptr;
  91 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
  92 bool   Arguments::_sun_java_launcher_is_altjvm  = false;
  93 
  94 // These parameters are reset in method parse_vm_init_args()
  95 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;

1839   }
1840   _sun_java_launcher = os::strdup_check_oom(launcher);
1841 }
1842 
1843 bool Arguments::created_by_java_launcher() {
1844   assert(_sun_java_launcher != nullptr, "property must have value");
1845   return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1846 }
1847 
1848 bool Arguments::sun_java_launcher_is_altjvm() {
1849   return _sun_java_launcher_is_altjvm;
1850 }
1851 
1852 //===========================================================================================================
1853 // Parsing of main arguments
1854 
1855 unsigned int addreads_count = 0;
1856 unsigned int addexports_count = 0;
1857 unsigned int addopens_count = 0;
1858 unsigned int addmods_count = 0;

1859 unsigned int enable_native_access_count = 0;
1860 
1861 // Check the consistency of vm_init_args
1862 bool Arguments::check_vm_args_consistency() {
1863   // Method for adding checks for flag consistency.
1864   // The intent is to warn the user of all possible conflicts,
1865   // before returning an error.
1866   // Note: Needs platform-dependent factoring.
1867   bool status = true;
1868 
1869   if (TLABRefillWasteFraction == 0) {
1870     jio_fprintf(defaultStream::error_stream(),
1871                 "TLABRefillWasteFraction should be a denominator, "
1872                 "not " SIZE_FORMAT "\n",
1873                 TLABRefillWasteFraction);
1874     status = false;
1875   }
1876 
1877   status = CompilerConfig::check_args_consistency(status);
1878 #if INCLUDE_JVMCI

1885       }
1886     }
1887   }
1888 #endif
1889 
1890 #if INCLUDE_JFR
1891   if (status && (FlightRecorderOptions || StartFlightRecording)) {
1892     if (!create_numbered_module_property("jdk.module.addmods", "jdk.jfr", addmods_count++)) {
1893       return false;
1894     }
1895   }
1896 #endif
1897 
1898 #ifndef SUPPORT_RESERVED_STACK_AREA
1899   if (StackReservedPages != 0) {
1900     FLAG_SET_CMDLINE(StackReservedPages, 0);
1901     warning("Reserved Stack Area not supported on this platform");
1902   }
1903 #endif
1904 
1905   if (AMD64_ONLY(false &&) AARCH64_ONLY(false &&) !FLAG_IS_DEFAULT(InlineTypePassFieldsAsArgs)) {
1906     FLAG_SET_CMDLINE(InlineTypePassFieldsAsArgs, false);
1907     warning("InlineTypePassFieldsAsArgs is not supported on this platform");
1908   }
1909 
1910   if (AMD64_ONLY(false &&) AARCH64_ONLY(false &&) !FLAG_IS_DEFAULT(InlineTypeReturnedAsFields)) {
1911     FLAG_SET_CMDLINE(InlineTypeReturnedAsFields, false);
1912     warning("InlineTypeReturnedAsFields is not supported on this platform");
1913   }
1914 
1915 
1916 #if !defined(X86) && !defined(AARCH64) && !defined(RISCV64) && !defined(ARM) && !defined(PPC64)
1917   if (LockingMode == LM_LIGHTWEIGHT) {
1918     FLAG_SET_CMDLINE(LockingMode, LM_LEGACY);
1919     warning("New lightweight locking not supported on this platform");
1920   }
1921 #endif
1922 
1923   if (UseHeavyMonitors) {
1924     if (FLAG_IS_CMDLINE(LockingMode) && LockingMode != LM_MONITOR) {
1925       jio_fprintf(defaultStream::error_stream(),
1926                   "Conflicting -XX:+UseHeavyMonitors and -XX:LockingMode=%d flags\n", LockingMode);
1927       return false;
1928     }
1929     FLAG_SET_CMDLINE(LockingMode, LM_MONITOR);
1930   }
1931 
1932 #if !defined(X86) && !defined(AARCH64) && !defined(PPC64) && !defined(RISCV64) && !defined(S390)
1933   if (LockingMode == LM_MONITOR) {
1934     jio_fprintf(defaultStream::error_stream(),

2031   }
2032 
2033   jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
2034   return false;
2035 }
2036 
2037 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
2038                                                   julong* long_arg,
2039                                                   julong min_size,
2040                                                   julong max_size) {
2041   if (!parse_integer(s, long_arg)) return arg_unreadable;
2042   return check_memory_size(*long_arg, min_size, max_size);
2043 }
2044 
2045 // Parse JavaVMInitArgs structure
2046 
2047 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
2048                                    const JavaVMInitArgs *java_tool_options_args,
2049                                    const JavaVMInitArgs *java_options_args,
2050                                    const JavaVMInitArgs *cmd_line_args) {


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

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



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

2281   assert(size <= size_aligned,
2282          "Overflow: " JULONG_FORMAT " " JULONG_FORMAT,
2283          size, size_aligned);
2284 
2285   const julong size_in_K = size_aligned / K;
2286   assert(size_in_K < (julong)max_intx,
2287          "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT,
2288          size_in_K);
2289 
2290   // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow.
2291   const julong max_expanded = align_up(size_in_K * K, os::vm_page_size());
2292   assert(max_expanded < max_uintx && max_expanded >= size_in_K,
2293          "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT,
2294          max_expanded, size_in_K);
2295 
2296   *out_ThreadStackSize = (intx)size_in_K;
2297 
2298   return JNI_OK;
2299 }
2300 
2301 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, JVMFlagOrigin origin) {
2302   // For match_option to return remaining or value part of option string
2303   const char* tail;
2304 
2305   // iterate over arguments
2306   for (int index = 0; index < args->nOptions; index++) {
2307     bool is_absolute_path = false;  // for -agentpath vs -agentlib
2308 
2309     const JavaVMOption* option = args->options + index;
2310 
2311     if (!match_option(option, "-Djava.class.path", &tail) &&
2312         !match_option(option, "-Dsun.java.command", &tail) &&
2313         !match_option(option, "-Dsun.java.launcher", &tail)) {
2314 
2315         // add all jvm options to the jvm_args string. This string
2316         // is used later to set the java.vm.args PerfData string constant.
2317         // the -Djava.class.path and the -Dsun.java.command options are
2318         // omitted from jvm_args string as each have their own PerfData
2319         // string constant object.
2320         build_jvm_args(option->optionString);
2321     }

2408         return JNI_ENOMEM;
2409       }
2410     } else if (match_option(option, "--enable-native-access=", &tail)) {
2411       if (!create_numbered_module_property("jdk.module.enable.native.access", tail, enable_native_access_count++)) {
2412         return JNI_ENOMEM;
2413       }
2414     } else if (match_option(option, "--limit-modules=", &tail)) {
2415       if (!create_module_property("jdk.module.limitmods", tail, InternalProperty)) {
2416         return JNI_ENOMEM;
2417       }
2418     } else if (match_option(option, "--module-path=", &tail)) {
2419       if (!create_module_property("jdk.module.path", tail, ExternalProperty)) {
2420         return JNI_ENOMEM;
2421       }
2422     } else if (match_option(option, "--upgrade-module-path=", &tail)) {
2423       if (!create_module_property("jdk.module.upgrade.path", tail, ExternalProperty)) {
2424         return JNI_ENOMEM;
2425       }
2426     } else if (match_option(option, "--patch-module=", &tail)) {
2427       // --patch-module=<module>=<file>(<pathsep><file>)*
2428       int res = process_patch_mod_option(tail);
2429       if (res != JNI_OK) {
2430         return res;
2431       }
2432     } else if (match_option(option, "--illegal-access=", &tail)) {
2433       char version[256];
2434       JDK_Version::jdk(17).to_string(version, sizeof(version));
2435       warning("Ignoring option %s; support was removed in %s", option->optionString, version);
2436     // -agentlib and -agentpath
2437     } else if (match_option(option, "-agentlib:", &tail) ||
2438           (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2439       if(tail != nullptr) {
2440         const char* pos = strchr(tail, '=');
2441         char* name;
2442         if (pos == nullptr) {
2443           name = os::strdup_check_oom(tail, mtArguments);
2444         } else {
2445           size_t len = pos - tail;
2446           name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments);
2447           memcpy(name, tail, len);
2448           name[len] = '\0';

2934 #endif // INCLUDE_JVMCI
2935 #if INCLUDE_JFR
2936     } else if (match_jfr_option(&option)) {
2937       return JNI_EINVAL;
2938 #endif
2939     } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx
2940       // Skip -XX:Flags= and -XX:VMOptionsFile= since those cases have
2941       // already been handled
2942       if ((strncmp(tail, "Flags=", strlen("Flags=")) != 0) &&
2943           (strncmp(tail, "VMOptionsFile=", strlen("VMOptionsFile=")) != 0)) {
2944         if (!process_argument(tail, args->ignoreUnrecognized, origin)) {
2945           return JNI_EINVAL;
2946         }
2947       }
2948     // Unknown option
2949     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2950       return JNI_ERR;
2951     }
2952   }
2953 
2954   if (!EnableValhalla && EnablePrimitiveClasses) {
2955     jio_fprintf(defaultStream::error_stream(),
2956                 "Cannot specify -XX:+EnablePrimitiveClasses without -XX:+EnableValhalla");
2957     return JNI_EINVAL;
2958   }
2959 
2960   // PrintSharedArchiveAndExit will turn on
2961   //   -Xshare:on
2962   //   -Xlog:class+path=info
2963   if (PrintSharedArchiveAndExit) {
2964     UseSharedSpaces = true;
2965     RequireSharedSpaces = true;
2966     LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2967   }
2968 
2969   fix_appclasspath();
2970 
2971   return JNI_OK;
2972 }
2973 
2974 bool match_module(void *module_name, ModulePatchPath *patch) {
2975   return (strcmp((char *)module_name, patch->module_name()) == 0);
2976 }









2977 
2978 bool Arguments::patch_mod_javabase() {
2979     return _patch_mod_prefix != nullptr && _patch_mod_prefix->find((void*)JAVA_BASE_NAME, match_module) >= 0;
2980 }
2981 
2982 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append) {
2983   // Create GrowableArray lazily, only if --patch-module has been specified
2984   if (_patch_mod_prefix == nullptr) {
2985     _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2986   }
2987 
2988   // Scan patches for matching module
2989   int i = _patch_mod_prefix->find((void*)module_name, match_module);
2990   if (i == -1) {
2991     _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2992   } else {
2993     if (allow_append) {
2994       // append path to existing module entry
2995       _patch_mod_prefix->at(i)->append_path(path);
2996     } else {
2997       if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2998         vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2999       } else {
3000         vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
3001       }
3002     }
3003   }
3004 }
3005 
3006 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
3007 //
3008 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
3009 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
3010 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
3011 // path is treated as the current directory.
3012 //
3013 // This causes problems with CDS, which requires that all directories specified in the classpath
3014 // must be empty. In most cases, applications do NOT want to load classes from the current
3015 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
3016 // scripts compatible with CDS.
3017 void Arguments::fix_appclasspath() {
3018   if (IgnoreEmptyClassPaths) {
3019     const char separator = *os::path_separator();
3020     const char* src = _java_class_path->value();
3021 
3022     // skip over all the leading empty paths
3023     while (*src == separator) {

3026 
3027     char* copy = os::strdup_check_oom(src, mtArguments);
3028 
3029     // trim all trailing empty paths
3030     for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
3031       *tail = '\0';
3032     }
3033 
3034     char from[3] = {separator, separator, '\0'};
3035     char to  [2] = {separator, '\0'};
3036     while (StringUtils::replace_no_expand(copy, from, to) > 0) {
3037       // Keep replacing "::" -> ":" until we have no more "::" (non-windows)
3038       // Keep replacing ";;" -> ";" until we have no more ";;" (windows)
3039     }
3040 
3041     _java_class_path->set_writeable_value(copy);
3042     FreeHeap(copy); // a copy was made by set_value, so don't need this anymore
3043   }
3044 }
3045 
3046 jint Arguments::finalize_vm_init_args() {
3047   // check if the default lib/endorsed directory exists; if so, error
3048   char path[JVM_MAXPATHLEN];
3049   const char* fileSep = os::file_separator();
3050   jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
3051 
3052   DIR* dir = os::opendir(path);
3053   if (dir != nullptr) {
3054     jio_fprintf(defaultStream::output_stream(),
3055       "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n"
3056       "in modular form will be supported via the concept of upgradeable modules.\n");
3057     os::closedir(dir);
3058     return JNI_ERR;
3059   }
3060 
3061   jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
3062   dir = os::opendir(path);
3063   if (dir != nullptr) {
3064     jio_fprintf(defaultStream::output_stream(),
3065       "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; "
3066       "Use -classpath instead.\n.");

3100   if (FLAG_IS_DEFAULT(UseLargePages) &&
3101       MaxHeapSize < LargePageHeapSizeThreshold) {
3102     // No need for large granularity pages w/small heaps.
3103     // Note that large pages are enabled/disabled for both the
3104     // Java heap and the code cache.
3105     FLAG_SET_DEFAULT(UseLargePages, false);
3106   }
3107 
3108   UNSUPPORTED_OPTION(ProfileInterpreter);
3109 #endif
3110 
3111   // Parse the CompilationMode flag
3112   if (!CompilationModeFlag::initialize()) {
3113     return JNI_ERR;
3114   }
3115 
3116   if (!check_vm_args_consistency()) {
3117     return JNI_ERR;
3118   }
3119 
3120   // finalize --module-patch and related --enable-preview
3121   if (finalize_patch_module() != JNI_OK) {
3122     return JNI_ERR;
3123   }
3124 
3125 #if INCLUDE_CDS
3126   if (DumpSharedSpaces) {
3127     // Compiler threads may concurrently update the class metadata (such as method entries), so it's
3128     // unsafe with -Xshare:dump (which modifies the class metadata in place). Let's disable
3129     // compiler just to be safe.
3130     //
3131     // Note: this is not a concern for dynamically dumping shared spaces, which makes a copy of the
3132     // class metadata instead of modifying them in place. The copy is inaccessible to the compiler.
3133     // TODO: revisit the following for the static archive case.
3134     set_mode_flags(_int);
3135 
3136     // String deduplication may cause CDS to iterate the strings in different order from one
3137     // run to another which resulting in non-determinstic CDS archives.
3138     // Disable UseStringDeduplication while dumping CDS archive.
3139     UseStringDeduplication = false;
3140   }
3141 
3142   // RecordDynamicDumpInfo is not compatible with ArchiveClassesAtExit
3143   if (ArchiveClassesAtExit != nullptr && RecordDynamicDumpInfo) {
3144     jio_fprintf(defaultStream::output_stream(),

3146     return JNI_ERR;
3147   }
3148 
3149   if (ArchiveClassesAtExit == nullptr && !RecordDynamicDumpInfo) {
3150     DynamicDumpSharedSpaces = false;
3151   } else {
3152     DynamicDumpSharedSpaces = true;
3153   }
3154 
3155   if (AutoCreateSharedArchive) {
3156     if (SharedArchiveFile == nullptr) {
3157       log_warning(cds)("-XX:+AutoCreateSharedArchive requires -XX:SharedArchiveFile");
3158       return JNI_ERR;
3159     }
3160     if (ArchiveClassesAtExit != nullptr) {
3161       log_warning(cds)("-XX:+AutoCreateSharedArchive does not work with ArchiveClassesAtExit");
3162       return JNI_ERR;
3163     }
3164   }
3165 
3166   if (UseSharedSpaces && patch_mod_javabase()) {
3167     no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched.");
3168   }
3169   if (UseSharedSpaces && !DumpSharedSpaces && check_unsupported_cds_runtime_properties()) {
3170     UseSharedSpaces = false;
3171   }
3172 
3173   if (DumpSharedSpaces || DynamicDumpSharedSpaces) {
3174     // Always verify non-system classes during CDS dump
3175     if (!BytecodeVerificationRemote) {
3176       BytecodeVerificationRemote = true;
3177       log_info(cds)("All non-system classes will be verified (-Xverify:remote) during CDS dump time.");
3178     }
3179   }
3180 #endif
3181 
3182 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3183   UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3184 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3185 
3186   return JNI_OK;

4102 #ifdef ZERO
4103   // Clear flags not supported on zero.
4104   FLAG_SET_DEFAULT(ProfileInterpreter, false);
4105 #endif // ZERO
4106 
4107   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
4108     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
4109     DebugNonSafepoints = true;
4110   }
4111 
4112   if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
4113     warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
4114   }
4115 
4116   // Treat the odd case where local verification is enabled but remote
4117   // verification is not as if both were enabled.
4118   if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
4119     log_info(verification)("Turning on remote verification because local verification is on");
4120     FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
4121   }
4122   if (!EnableValhalla || (is_interpreter_only() && !is_dumping_archive() && !UseSharedSpaces)) {
4123     // Disable calling convention optimizations if inline types are not supported.
4124     // Also these aren't useful in -Xint. However, don't disable them when dumping or using
4125     // the CDS archive, as the values must match between dumptime and runtime.
4126     InlineTypePassFieldsAsArgs = false;
4127     InlineTypeReturnedAsFields = false;
4128   }
4129 
4130 #ifndef PRODUCT
4131   if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
4132     if (use_vm_log()) {
4133       LogVMOutput = true;
4134     }
4135   }
4136 #endif // PRODUCT
4137 
4138   if (PrintCommandLineFlags) {
4139     JVMFlag::printSetFlags(tty);
4140   }
4141 
4142 #ifdef COMPILER2
4143   if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
4144     if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
4145       warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
4146     }
4147     FLAG_SET_DEFAULT(EnableVectorReboxing, false);
4148 
< prev index next >