< prev index next >

src/hotspot/share/runtime/arguments.cpp

Print this page

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

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

1761     os::free(const_cast<char*>(_sun_java_launcher));
1762   }
1763   _sun_java_launcher = os::strdup_check_oom(launcher);
1764 }
1765 
1766 bool Arguments::created_by_java_launcher() {
1767   assert(_sun_java_launcher != nullptr, "property must have value");
1768   return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1769 }
1770 
1771 bool Arguments::sun_java_launcher_is_altjvm() {
1772   return _sun_java_launcher_is_altjvm;
1773 }
1774 
1775 //===========================================================================================================
1776 // Parsing of main arguments
1777 
1778 unsigned int addreads_count = 0;
1779 unsigned int addexports_count = 0;
1780 unsigned int addopens_count = 0;
1781 unsigned int patch_mod_count = 0;
1782 unsigned int enable_native_access_count = 0;
1783 
1784 // Check the consistency of vm_init_args
1785 bool Arguments::check_vm_args_consistency() {
1786   // Method for adding checks for flag consistency.
1787   // The intent is to warn the user of all possible conflicts,
1788   // before returning an error.
1789   // Note: Needs platform-dependent factoring.
1790   bool status = true;
1791 
1792   if (TLABRefillWasteFraction == 0) {
1793     jio_fprintf(defaultStream::error_stream(),
1794                 "TLABRefillWasteFraction should be a denominator, "
1795                 "not " SIZE_FORMAT "\n",
1796                 TLABRefillWasteFraction);
1797     status = false;
1798   }
1799 
1800   status = CompilerConfig::check_args_consistency(status);
1801 #if INCLUDE_JVMCI

1927   }
1928 
1929   jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
1930   return false;
1931 }
1932 
1933 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
1934                                                   julong* long_arg,
1935                                                   julong min_size,
1936                                                   julong max_size) {
1937   if (!parse_integer(s, long_arg)) return arg_unreadable;
1938   return check_memory_size(*long_arg, min_size, max_size);
1939 }
1940 
1941 // Parse JavaVMInitArgs structure
1942 
1943 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
1944                                    const JavaVMInitArgs *java_tool_options_args,
1945                                    const JavaVMInitArgs *java_options_args,
1946                                    const JavaVMInitArgs *cmd_line_args) {
1947   bool patch_mod_javabase = false;
1948 
1949   // Save default settings for some mode flags
1950   Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
1951   Arguments::_UseOnStackReplacement    = UseOnStackReplacement;
1952   Arguments::_ClipInlining             = ClipInlining;
1953   Arguments::_BackgroundCompilation    = BackgroundCompilation;
1954 
1955   // Remember the default value of SharedBaseAddress.
1956   Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1957 
1958   // Setup flags for mixed which is the default
1959   set_mode_flags(_mixed);
1960 
1961   // Parse args structure generated from java.base vm options resource
1962   jint result = parse_each_vm_init_arg(vm_options_args, &patch_mod_javabase, JVMFlagOrigin::JIMAGE_RESOURCE);
1963   if (result != JNI_OK) {
1964     return result;
1965   }
1966 
1967   // Parse args structure generated from JAVA_TOOL_OPTIONS environment
1968   // variable (if present).
1969   result = parse_each_vm_init_arg(java_tool_options_args, &patch_mod_javabase, JVMFlagOrigin::ENVIRON_VAR);
1970   if (result != JNI_OK) {
1971     return result;
1972   }
1973 
1974   // Parse args structure generated from the command line flags.
1975   result = parse_each_vm_init_arg(cmd_line_args, &patch_mod_javabase, JVMFlagOrigin::COMMAND_LINE);
1976   if (result != JNI_OK) {
1977     return result;
1978   }
1979 
1980   // Parse args structure generated from the _JAVA_OPTIONS environment
1981   // variable (if present) (mimics classic VM)
1982   result = parse_each_vm_init_arg(java_options_args, &patch_mod_javabase, JVMFlagOrigin::ENVIRON_VAR);
1983   if (result != JNI_OK) {
1984     return result;
1985   }
1986 
1987   // Disable CDS for exploded image
1988   if (!has_jimage()) {
1989     no_shared_spaces("CDS disabled on exploded JDK");
1990   }
1991 
1992   // We need to ensure processor and memory resources have been properly
1993   // configured - which may rely on arguments we just processed - before
1994   // doing the final argument processing. Any argument processing that
1995   // needs to know about processor and memory resources must occur after
1996   // this point.
1997 
1998   os::init_container_support();
1999 
2000   SystemMemoryBarrier::initialize();
2001 
2002   // Do final processing now that all arguments have been parsed
2003   result = finalize_vm_init_args(patch_mod_javabase);
2004   if (result != JNI_OK) {
2005     return result;
2006   }
2007 
2008   return JNI_OK;
2009 }
2010 
2011 #if !INCLUDE_JVMTI
2012 // Checks if name in command-line argument -agent{lib,path}:name[=options]
2013 // represents a valid JDWP agent.  is_path==true denotes that we
2014 // are dealing with -agentpath (case where name is a path), otherwise with
2015 // -agentlib
2016 static bool valid_jdwp_agent(char *name, bool is_path) {
2017   char *_name;
2018   const char *_jdwp = "jdwp";
2019   size_t _len_jdwp, _len_prefix;
2020 
2021   if (is_path) {
2022     if ((_name = strrchr(name, (int) *os::file_separator())) == nullptr) {
2023       return false;

2038     }
2039     else {
2040       return false;
2041     }
2042 
2043     if (strcmp(_name, JNI_LIB_SUFFIX) != 0) {
2044       return false;
2045     }
2046 
2047     return true;
2048   }
2049 
2050   if (strcmp(name, _jdwp) == 0) {
2051     return true;
2052   }
2053 
2054   return false;
2055 }
2056 #endif
2057 
2058 int Arguments::process_patch_mod_option(const char* patch_mod_tail, bool* patch_mod_javabase) {
2059   // --patch-module=<module>=<file>(<pathsep><file>)*
2060   assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2061   // Find the equal sign between the module name and the path specification
2062   const char* module_equal = strchr(patch_mod_tail, '=');
2063   if (module_equal == nullptr) {
2064     jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2065     return JNI_ERR;
2066   } else {
2067     // Pick out the module name
2068     size_t module_len = module_equal - patch_mod_tail;
2069     char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2070     if (module_name != nullptr) {
2071       memcpy(module_name, patch_mod_tail, module_len);
2072       *(module_name + module_len) = '\0';
2073       // The path piece begins one past the module_equal sign
2074       add_patch_mod_prefix(module_name, module_equal + 1, patch_mod_javabase);
2075       FREE_C_HEAP_ARRAY(char, module_name);
2076       if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
2077         return JNI_ENOMEM;
2078       }
2079     } else {
2080       return JNI_ENOMEM;
2081     }
2082   }
2083   return JNI_OK;
2084 }
2085 
































































2086 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2087 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2088   // The min and max sizes match the values in globals.hpp, but scaled
2089   // with K. The values have been chosen so that alignment with page
2090   // size doesn't change the max value, which makes the conversions
2091   // back and forth between Xss value and ThreadStackSize value easier.
2092   // The values have also been chosen to fit inside a 32-bit signed type.
2093   const julong min_ThreadStackSize = 0;
2094   const julong max_ThreadStackSize = 1 * M;
2095 
2096   // Make sure the above values match the range set in globals.hpp
2097   const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2098   assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2099   assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2100 
2101   const julong min_size = min_ThreadStackSize * K;
2102   const julong max_size = max_ThreadStackSize * K;
2103 
2104   assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2105 

2120   assert(size <= size_aligned,
2121          "Overflow: " JULONG_FORMAT " " JULONG_FORMAT,
2122          size, size_aligned);
2123 
2124   const julong size_in_K = size_aligned / K;
2125   assert(size_in_K < (julong)max_intx,
2126          "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT,
2127          size_in_K);
2128 
2129   // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow.
2130   const julong max_expanded = align_up(size_in_K * K, os::vm_page_size());
2131   assert(max_expanded < max_uintx && max_expanded >= size_in_K,
2132          "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT,
2133          max_expanded, size_in_K);
2134 
2135   *out_ThreadStackSize = (intx)size_in_K;
2136 
2137   return JNI_OK;
2138 }
2139 
2140 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_mod_javabase, JVMFlagOrigin origin) {
2141   // For match_option to return remaining or value part of option string
2142   const char* tail;
2143 
2144   // iterate over arguments
2145   for (int index = 0; index < args->nOptions; index++) {
2146     bool is_absolute_path = false;  // for -agentpath vs -agentlib
2147 
2148     const JavaVMOption* option = args->options + index;
2149 
2150     if (!match_option(option, "-Djava.class.path", &tail) &&
2151         !match_option(option, "-Dsun.java.command", &tail) &&
2152         !match_option(option, "-Dsun.java.launcher", &tail)) {
2153 
2154         // add all jvm options to the jvm_args string. This string
2155         // is used later to set the java.vm.args PerfData string constant.
2156         // the -Djava.class.path and the -Dsun.java.command options are
2157         // omitted from jvm_args string as each have their own PerfData
2158         // string constant object.
2159         build_jvm_args(option->optionString);
2160     }

2247         return JNI_ENOMEM;
2248       }
2249     } else if (match_option(option, "--illegal-native-access=", &tail)) {
2250       if (!create_module_property("jdk.module.illegal.native.access", tail, InternalProperty)) {
2251         return JNI_ENOMEM;
2252       }
2253     } else if (match_option(option, "--limit-modules=", &tail)) {
2254       if (!create_module_property("jdk.module.limitmods", tail, InternalProperty)) {
2255         return JNI_ENOMEM;
2256       }
2257     } else if (match_option(option, "--module-path=", &tail)) {
2258       if (!create_module_property("jdk.module.path", tail, ExternalProperty)) {
2259         return JNI_ENOMEM;
2260       }
2261     } else if (match_option(option, "--upgrade-module-path=", &tail)) {
2262       if (!create_module_property("jdk.module.upgrade.path", tail, ExternalProperty)) {
2263         return JNI_ENOMEM;
2264       }
2265     } else if (match_option(option, "--patch-module=", &tail)) {
2266       // --patch-module=<module>=<file>(<pathsep><file>)*
2267       int res = process_patch_mod_option(tail, patch_mod_javabase);
2268       if (res != JNI_OK) {
2269         return res;
2270       }
2271     } else if (match_option(option, "--sun-misc-unsafe-memory-access=", &tail)) {
2272       if (strcmp(tail, "allow") == 0 || strcmp(tail, "warn") == 0 || strcmp(tail, "debug") == 0 || strcmp(tail, "deny") == 0) {
2273         PropertyList_unique_add(&_system_properties, "sun.misc.unsafe.memory.access", tail,
2274                                 AddProperty, WriteableProperty, InternalProperty);
2275       } else {
2276         jio_fprintf(defaultStream::error_stream(),
2277                     "Value specified to --sun-misc-unsafe-memory-access not recognized: '%s'\n", tail);
2278         return JNI_ERR;
2279       }
2280     } else if (match_option(option, "--illegal-access=", &tail)) {
2281       char version[256];
2282       JDK_Version::jdk(17).to_string(version, sizeof(version));
2283       warning("Ignoring option %s; support was removed in %s", option->optionString, version);
2284     // -agentlib and -agentpath
2285     } else if (match_option(option, "-agentlib:", &tail) ||
2286           (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2287       if(tail != nullptr) {

2317       jio_fprintf(defaultStream::error_stream(),
2318         "Instrumentation agents are not supported in this VM\n");
2319       return JNI_ERR;
2320 #else
2321       if (tail != nullptr) {
2322         size_t length = strlen(tail) + 1;
2323         char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2324         jio_snprintf(options, length, "%s", tail);
2325         JvmtiAgentList::add("instrument", options, false);
2326         FREE_C_HEAP_ARRAY(char, options);
2327 
2328         // java agents need module java.instrument
2329         if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2330           return JNI_ENOMEM;
2331         }
2332       }
2333 #endif // !INCLUDE_JVMTI
2334     // --enable_preview
2335     } else if (match_option(option, "--enable-preview")) {
2336       set_enable_preview();




2337     // -Xnoclassgc
2338     } else if (match_option(option, "-Xnoclassgc")) {
2339       if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2340         return JNI_EINVAL;
2341       }
2342     // -Xbatch
2343     } else if (match_option(option, "-Xbatch")) {
2344       if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2345         return JNI_EINVAL;
2346       }
2347     // -Xmn for compatibility with other JVM vendors
2348     } else if (match_option(option, "-Xmn", &tail)) {
2349       julong long_initial_young_size = 0;
2350       ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2351       if (errcode != arg_in_range) {
2352         jio_fprintf(defaultStream::error_stream(),
2353                     "Invalid initial young generation size: %s\n", option->optionString);
2354         describe_range_error(errcode);
2355         return JNI_EINVAL;
2356       }

2792     // Unknown option
2793     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2794       return JNI_ERR;
2795     }
2796   }
2797 
2798   // PrintSharedArchiveAndExit will turn on
2799   //   -Xshare:on
2800   //   -Xlog:class+path=info
2801   if (PrintSharedArchiveAndExit) {
2802     UseSharedSpaces = true;
2803     RequireSharedSpaces = true;
2804     LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2805   }
2806 
2807   fix_appclasspath();
2808 
2809   return JNI_OK;
2810 }
2811 
2812 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool* patch_mod_javabase) {
2813   // For java.base check for duplicate --patch-module options being specified on the command line.
2814   // This check is only required for java.base, all other duplicate module specifications
2815   // will be checked during module system initialization.  The module system initialization
2816   // will throw an ExceptionInInitializerError if this situation occurs.
2817   if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2818     if (*patch_mod_javabase) {
2819       vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2820     } else {
2821       *patch_mod_javabase = true;
2822     }
2823   }
2824 
2825   // Create GrowableArray lazily, only if --patch-module has been specified
2826   if (_patch_mod_prefix == nullptr) {
2827     _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2828   }
2829 
2830   _patch_mod_prefix->push(new ModulePatchPath(module_name, path));

















2831 }
2832 
2833 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2834 //
2835 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2836 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2837 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2838 // path is treated as the current directory.
2839 //
2840 // This causes problems with CDS, which requires that all directories specified in the classpath
2841 // must be empty. In most cases, applications do NOT want to load classes from the current
2842 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2843 // scripts compatible with CDS.
2844 void Arguments::fix_appclasspath() {
2845   if (IgnoreEmptyClassPaths) {
2846     const char separator = *os::path_separator();
2847     const char* src = _java_class_path->value();
2848 
2849     // skip over all the leading empty paths
2850     while (*src == separator) {

2853 
2854     char* copy = os::strdup_check_oom(src, mtArguments);
2855 
2856     // trim all trailing empty paths
2857     for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
2858       *tail = '\0';
2859     }
2860 
2861     char from[3] = {separator, separator, '\0'};
2862     char to  [2] = {separator, '\0'};
2863     while (StringUtils::replace_no_expand(copy, from, to) > 0) {
2864       // Keep replacing "::" -> ":" until we have no more "::" (non-windows)
2865       // Keep replacing ";;" -> ";" until we have no more ";;" (windows)
2866     }
2867 
2868     _java_class_path->set_writeable_value(copy);
2869     FreeHeap(copy); // a copy was made by set_value, so don't need this anymore
2870   }
2871 }
2872 
2873 jint Arguments::finalize_vm_init_args(bool patch_mod_javabase) {
2874   // check if the default lib/endorsed directory exists; if so, error
2875   char path[JVM_MAXPATHLEN];
2876   const char* fileSep = os::file_separator();
2877   jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep);
2878 
2879   DIR* dir = os::opendir(path);
2880   if (dir != nullptr) {
2881     jio_fprintf(defaultStream::output_stream(),
2882       "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n"
2883       "in modular form will be supported via the concept of upgradeable modules.\n");
2884     os::closedir(dir);
2885     return JNI_ERR;
2886   }
2887 
2888   jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep);
2889   dir = os::opendir(path);
2890   if (dir != nullptr) {
2891     jio_fprintf(defaultStream::output_stream(),
2892       "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; "
2893       "Use -classpath instead.\n.");

2927   if (FLAG_IS_DEFAULT(UseLargePages) &&
2928       MaxHeapSize < LargePageHeapSizeThreshold) {
2929     // No need for large granularity pages w/small heaps.
2930     // Note that large pages are enabled/disabled for both the
2931     // Java heap and the code cache.
2932     FLAG_SET_DEFAULT(UseLargePages, false);
2933   }
2934 
2935   UNSUPPORTED_OPTION(ProfileInterpreter);
2936 #endif
2937 
2938   // Parse the CompilationMode flag
2939   if (!CompilationModeFlag::initialize()) {
2940     return JNI_ERR;
2941   }
2942 
2943   if (!check_vm_args_consistency()) {
2944     return JNI_ERR;
2945   }
2946 
2947   if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) {





2948     return JNI_ERR;
2949   }
2950 
2951 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
2952   UNSUPPORTED_OPTION(ShowRegistersOnAssert);
2953 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2954 
2955   return JNI_OK;
2956 }
2957 
2958 // Helper class for controlling the lifetime of JavaVMInitArgs
2959 // objects.  The contents of the JavaVMInitArgs are guaranteed to be
2960 // deleted on the destruction of the ScopedVMInitArgs object.
2961 class ScopedVMInitArgs : public StackObj {
2962  private:
2963   JavaVMInitArgs _args;
2964   char*          _container_name;
2965   bool           _is_set;
2966   char*          _vm_options_file_arg;
2967 

3697 #ifdef ZERO
3698   // Clear flags not supported on zero.
3699   FLAG_SET_DEFAULT(ProfileInterpreter, false);
3700 #endif // ZERO
3701 
3702   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3703     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3704     DebugNonSafepoints = true;
3705   }
3706 
3707   if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3708     warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3709   }
3710 
3711   // Treat the odd case where local verification is enabled but remote
3712   // verification is not as if both were enabled.
3713   if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3714     log_info(verification)("Turning on remote verification because local verification is on");
3715     FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3716   }







3717 
3718 #ifndef PRODUCT
3719   if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3720     if (use_vm_log()) {
3721       LogVMOutput = true;
3722     }
3723   }
3724 #endif // PRODUCT
3725 
3726   if (PrintCommandLineFlags) {
3727     JVMFlag::printSetFlags(tty);
3728   }
3729 
3730 #if COMPILER2_OR_JVMCI
3731   if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3732     if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3733       warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3734     }
3735     FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3736 

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

1762     os::free(const_cast<char*>(_sun_java_launcher));
1763   }
1764   _sun_java_launcher = os::strdup_check_oom(launcher);
1765 }
1766 
1767 bool Arguments::created_by_java_launcher() {
1768   assert(_sun_java_launcher != nullptr, "property must have value");
1769   return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1770 }
1771 
1772 bool Arguments::sun_java_launcher_is_altjvm() {
1773   return _sun_java_launcher_is_altjvm;
1774 }
1775 
1776 //===========================================================================================================
1777 // Parsing of main arguments
1778 
1779 unsigned int addreads_count = 0;
1780 unsigned int addexports_count = 0;
1781 unsigned int addopens_count = 0;

1782 unsigned int enable_native_access_count = 0;
1783 
1784 // Check the consistency of vm_init_args
1785 bool Arguments::check_vm_args_consistency() {
1786   // Method for adding checks for flag consistency.
1787   // The intent is to warn the user of all possible conflicts,
1788   // before returning an error.
1789   // Note: Needs platform-dependent factoring.
1790   bool status = true;
1791 
1792   if (TLABRefillWasteFraction == 0) {
1793     jio_fprintf(defaultStream::error_stream(),
1794                 "TLABRefillWasteFraction should be a denominator, "
1795                 "not " SIZE_FORMAT "\n",
1796                 TLABRefillWasteFraction);
1797     status = false;
1798   }
1799 
1800   status = CompilerConfig::check_args_consistency(status);
1801 #if INCLUDE_JVMCI

1927   }
1928 
1929   jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
1930   return false;
1931 }
1932 
1933 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
1934                                                   julong* long_arg,
1935                                                   julong min_size,
1936                                                   julong max_size) {
1937   if (!parse_integer(s, long_arg)) return arg_unreadable;
1938   return check_memory_size(*long_arg, min_size, max_size);
1939 }
1940 
1941 // Parse JavaVMInitArgs structure
1942 
1943 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
1944                                    const JavaVMInitArgs *java_tool_options_args,
1945                                    const JavaVMInitArgs *java_options_args,
1946                                    const JavaVMInitArgs *cmd_line_args) {


1947   // Save default settings for some mode flags
1948   Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
1949   Arguments::_UseOnStackReplacement    = UseOnStackReplacement;
1950   Arguments::_ClipInlining             = ClipInlining;
1951   Arguments::_BackgroundCompilation    = BackgroundCompilation;
1952 
1953   // Remember the default value of SharedBaseAddress.
1954   Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1955 
1956   // Setup flags for mixed which is the default
1957   set_mode_flags(_mixed);
1958 
1959   // Parse args structure generated from java.base vm options resource
1960   jint result = parse_each_vm_init_arg(vm_options_args, JVMFlagOrigin::JIMAGE_RESOURCE);
1961   if (result != JNI_OK) {
1962     return result;
1963   }
1964 
1965   // Parse args structure generated from JAVA_TOOL_OPTIONS environment
1966   // variable (if present).
1967   result = parse_each_vm_init_arg(java_tool_options_args, JVMFlagOrigin::ENVIRON_VAR);
1968   if (result != JNI_OK) {
1969     return result;
1970   }
1971 
1972   // Parse args structure generated from the command line flags.
1973   result = parse_each_vm_init_arg(cmd_line_args, JVMFlagOrigin::COMMAND_LINE);
1974   if (result != JNI_OK) {
1975     return result;
1976   }
1977 
1978   // Parse args structure generated from the _JAVA_OPTIONS environment
1979   // variable (if present) (mimics classic VM)
1980   result = parse_each_vm_init_arg(java_options_args, JVMFlagOrigin::ENVIRON_VAR);
1981   if (result != JNI_OK) {
1982     return result;
1983   }
1984 
1985   // Disable CDS for exploded image
1986   if (!has_jimage()) {
1987     no_shared_spaces("CDS disabled on exploded JDK");
1988   }
1989 
1990   // We need to ensure processor and memory resources have been properly
1991   // configured - which may rely on arguments we just processed - before
1992   // doing the final argument processing. Any argument processing that
1993   // needs to know about processor and memory resources must occur after
1994   // this point.
1995 
1996   os::init_container_support();
1997 
1998   SystemMemoryBarrier::initialize();
1999 
2000   // Do final processing now that all arguments have been parsed
2001   result = finalize_vm_init_args();
2002   if (result != JNI_OK) {
2003     return result;
2004   }
2005 
2006   return JNI_OK;
2007 }
2008 
2009 #if !INCLUDE_JVMTI
2010 // Checks if name in command-line argument -agent{lib,path}:name[=options]
2011 // represents a valid JDWP agent.  is_path==true denotes that we
2012 // are dealing with -agentpath (case where name is a path), otherwise with
2013 // -agentlib
2014 static bool valid_jdwp_agent(char *name, bool is_path) {
2015   char *_name;
2016   const char *_jdwp = "jdwp";
2017   size_t _len_jdwp, _len_prefix;
2018 
2019   if (is_path) {
2020     if ((_name = strrchr(name, (int) *os::file_separator())) == nullptr) {
2021       return false;

2036     }
2037     else {
2038       return false;
2039     }
2040 
2041     if (strcmp(_name, JNI_LIB_SUFFIX) != 0) {
2042       return false;
2043     }
2044 
2045     return true;
2046   }
2047 
2048   if (strcmp(name, _jdwp) == 0) {
2049     return true;
2050   }
2051 
2052   return false;
2053 }
2054 #endif
2055 
2056 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2057   // --patch-module=<module>=<file>(<pathsep><file>)*
2058   assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2059   // Find the equal sign between the module name and the path specification
2060   const char* module_equal = strchr(patch_mod_tail, '=');
2061   if (module_equal == nullptr) {
2062     jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2063     return JNI_ERR;
2064   } else {
2065     // Pick out the module name
2066     size_t module_len = module_equal - patch_mod_tail;
2067     char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2068     if (module_name != nullptr) {
2069       memcpy(module_name, patch_mod_tail, module_len);
2070       *(module_name + module_len) = '\0';
2071       // The path piece begins one past the module_equal sign
2072       add_patch_mod_prefix(module_name, module_equal + 1, false /* no append */, false /* no cds */);
2073       FREE_C_HEAP_ARRAY(char, module_name);



2074     } else {
2075       return JNI_ENOMEM;
2076     }
2077   }
2078   return JNI_OK;
2079 }
2080 
2081 // VALUECLASS_STR must match string used in the build
2082 #define VALUECLASS_STR "valueclasses"
2083 #define VALUECLASS_JAR "-" VALUECLASS_STR ".jar"
2084 
2085 // Finalize --patch-module args and --enable-preview related to value class module patches.
2086 // Create all numbered properties passing module patches.
2087 int Arguments::finalize_patch_module() {
2088   // If --enable-preview and EnableValhalla is true, each module may have value classes that
2089   // are to be patched into the module.
2090   // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2091   // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2092   if (enable_preview() && EnableValhalla) {
2093     char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2094     const char * fileSep = os::file_separator();
2095 
2096     jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s",
2097                  Arguments::get_java_home(), fileSep, fileSep, fileSep);
2098     DIR* dir = os::opendir(valueclasses_dir);
2099     if (dir != nullptr) {
2100       char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2101       char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2102 
2103       for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) {
2104         // Test if file ends-with "-valueclasses.jar"
2105         int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1);
2106         if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) {
2107           continue;         // too short or not the expected suffix
2108         }
2109 
2110         strcpy(module_name, entry->d_name);
2111         module_name[len] = '\0';     // truncate to just module-name
2112 
2113         jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name);
2114         add_patch_mod_prefix(module_name, path, true /* append */, true /* cds OK*/);
2115         log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name);
2116       }
2117       FreeHeap(module_name);
2118       FreeHeap(path);
2119       os::closedir(dir);
2120     }
2121     FreeHeap(valueclasses_dir);
2122   }
2123 
2124   // Create numbered properties for each module that has been patched either
2125   // by --patch-module or --enable-preview
2126   // Format is "jdk.module.patch.<n>=<module_name>=<path>"
2127   if (_patch_mod_prefix != nullptr) {
2128     char * prop_value = AllocateHeap(JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, mtArguments);
2129     unsigned int patch_mod_count = 0;
2130 
2131     for (GrowableArrayIterator<ModulePatchPath *> it = _patch_mod_prefix->begin();
2132             it != _patch_mod_prefix->end(); ++it) {
2133       jio_snprintf(prop_value, JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, "%s=%s",
2134                    (*it)->module_name(), (*it)->path_string());
2135       if (!create_numbered_module_property("jdk.module.patch", prop_value, patch_mod_count++)) {
2136         FreeHeap(prop_value);
2137         return JNI_ENOMEM;
2138       }
2139     }
2140     FreeHeap(prop_value);
2141   }
2142   return JNI_OK;
2143 }
2144 
2145 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2146 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2147   // The min and max sizes match the values in globals.hpp, but scaled
2148   // with K. The values have been chosen so that alignment with page
2149   // size doesn't change the max value, which makes the conversions
2150   // back and forth between Xss value and ThreadStackSize value easier.
2151   // The values have also been chosen to fit inside a 32-bit signed type.
2152   const julong min_ThreadStackSize = 0;
2153   const julong max_ThreadStackSize = 1 * M;
2154 
2155   // Make sure the above values match the range set in globals.hpp
2156   const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2157   assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2158   assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2159 
2160   const julong min_size = min_ThreadStackSize * K;
2161   const julong max_size = max_ThreadStackSize * K;
2162 
2163   assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2164 

2179   assert(size <= size_aligned,
2180          "Overflow: " JULONG_FORMAT " " JULONG_FORMAT,
2181          size, size_aligned);
2182 
2183   const julong size_in_K = size_aligned / K;
2184   assert(size_in_K < (julong)max_intx,
2185          "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT,
2186          size_in_K);
2187 
2188   // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow.
2189   const julong max_expanded = align_up(size_in_K * K, os::vm_page_size());
2190   assert(max_expanded < max_uintx && max_expanded >= size_in_K,
2191          "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT,
2192          max_expanded, size_in_K);
2193 
2194   *out_ThreadStackSize = (intx)size_in_K;
2195 
2196   return JNI_OK;
2197 }
2198 
2199 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, JVMFlagOrigin origin) {
2200   // For match_option to return remaining or value part of option string
2201   const char* tail;
2202 
2203   // iterate over arguments
2204   for (int index = 0; index < args->nOptions; index++) {
2205     bool is_absolute_path = false;  // for -agentpath vs -agentlib
2206 
2207     const JavaVMOption* option = args->options + index;
2208 
2209     if (!match_option(option, "-Djava.class.path", &tail) &&
2210         !match_option(option, "-Dsun.java.command", &tail) &&
2211         !match_option(option, "-Dsun.java.launcher", &tail)) {
2212 
2213         // add all jvm options to the jvm_args string. This string
2214         // is used later to set the java.vm.args PerfData string constant.
2215         // the -Djava.class.path and the -Dsun.java.command options are
2216         // omitted from jvm_args string as each have their own PerfData
2217         // string constant object.
2218         build_jvm_args(option->optionString);
2219     }

2306         return JNI_ENOMEM;
2307       }
2308     } else if (match_option(option, "--illegal-native-access=", &tail)) {
2309       if (!create_module_property("jdk.module.illegal.native.access", tail, InternalProperty)) {
2310         return JNI_ENOMEM;
2311       }
2312     } else if (match_option(option, "--limit-modules=", &tail)) {
2313       if (!create_module_property("jdk.module.limitmods", tail, InternalProperty)) {
2314         return JNI_ENOMEM;
2315       }
2316     } else if (match_option(option, "--module-path=", &tail)) {
2317       if (!create_module_property("jdk.module.path", tail, ExternalProperty)) {
2318         return JNI_ENOMEM;
2319       }
2320     } else if (match_option(option, "--upgrade-module-path=", &tail)) {
2321       if (!create_module_property("jdk.module.upgrade.path", tail, ExternalProperty)) {
2322         return JNI_ENOMEM;
2323       }
2324     } else if (match_option(option, "--patch-module=", &tail)) {
2325       // --patch-module=<module>=<file>(<pathsep><file>)*
2326       int res = process_patch_mod_option(tail);
2327       if (res != JNI_OK) {
2328         return res;
2329       }
2330     } else if (match_option(option, "--sun-misc-unsafe-memory-access=", &tail)) {
2331       if (strcmp(tail, "allow") == 0 || strcmp(tail, "warn") == 0 || strcmp(tail, "debug") == 0 || strcmp(tail, "deny") == 0) {
2332         PropertyList_unique_add(&_system_properties, "sun.misc.unsafe.memory.access", tail,
2333                                 AddProperty, WriteableProperty, InternalProperty);
2334       } else {
2335         jio_fprintf(defaultStream::error_stream(),
2336                     "Value specified to --sun-misc-unsafe-memory-access not recognized: '%s'\n", tail);
2337         return JNI_ERR;
2338       }
2339     } else if (match_option(option, "--illegal-access=", &tail)) {
2340       char version[256];
2341       JDK_Version::jdk(17).to_string(version, sizeof(version));
2342       warning("Ignoring option %s; support was removed in %s", option->optionString, version);
2343     // -agentlib and -agentpath
2344     } else if (match_option(option, "-agentlib:", &tail) ||
2345           (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
2346       if(tail != nullptr) {

2376       jio_fprintf(defaultStream::error_stream(),
2377         "Instrumentation agents are not supported in this VM\n");
2378       return JNI_ERR;
2379 #else
2380       if (tail != nullptr) {
2381         size_t length = strlen(tail) + 1;
2382         char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2383         jio_snprintf(options, length, "%s", tail);
2384         JvmtiAgentList::add("instrument", options, false);
2385         FREE_C_HEAP_ARRAY(char, options);
2386 
2387         // java agents need module java.instrument
2388         if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2389           return JNI_ENOMEM;
2390         }
2391       }
2392 #endif // !INCLUDE_JVMTI
2393     // --enable_preview
2394     } else if (match_option(option, "--enable-preview")) {
2395       set_enable_preview();
2396       // --enable-preview enables Valhalla, EnableValhalla VM option will eventually be removed before integration
2397       if (FLAG_SET_CMDLINE(EnableValhalla, true) != JVMFlag::SUCCESS) {
2398         return JNI_EINVAL;
2399       }
2400     // -Xnoclassgc
2401     } else if (match_option(option, "-Xnoclassgc")) {
2402       if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2403         return JNI_EINVAL;
2404       }
2405     // -Xbatch
2406     } else if (match_option(option, "-Xbatch")) {
2407       if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2408         return JNI_EINVAL;
2409       }
2410     // -Xmn for compatibility with other JVM vendors
2411     } else if (match_option(option, "-Xmn", &tail)) {
2412       julong long_initial_young_size = 0;
2413       ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2414       if (errcode != arg_in_range) {
2415         jio_fprintf(defaultStream::error_stream(),
2416                     "Invalid initial young generation size: %s\n", option->optionString);
2417         describe_range_error(errcode);
2418         return JNI_EINVAL;
2419       }

2855     // Unknown option
2856     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2857       return JNI_ERR;
2858     }
2859   }
2860 
2861   // PrintSharedArchiveAndExit will turn on
2862   //   -Xshare:on
2863   //   -Xlog:class+path=info
2864   if (PrintSharedArchiveAndExit) {
2865     UseSharedSpaces = true;
2866     RequireSharedSpaces = true;
2867     LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2868   }
2869 
2870   fix_appclasspath();
2871 
2872   return JNI_OK;
2873 }
2874 
2875 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) {
2876   if (!allow_cds) {
2877     CDSConfig::set_module_patching_disables_cds();
2878     if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2879       CDSConfig::set_java_base_module_patching_disables_cds();





2880     }
2881   }
2882 
2883   // Create GrowableArray lazily, only if --patch-module has been specified
2884   if (_patch_mod_prefix == nullptr) {
2885     _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2886   }
2887 
2888   // Scan patches for matching module
2889   int i = _patch_mod_prefix->find_if([&](ModulePatchPath* patch) {
2890     return (strcmp(module_name, patch->module_name()) == 0);
2891   });
2892   if (i == -1) {
2893     _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2894   } else {
2895     if (allow_append) {
2896       // append path to existing module entry
2897       _patch_mod_prefix->at(i)->append_path(path);
2898     } else {
2899       if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2900         vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2901       } else {
2902         vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
2903       }
2904     }
2905   }
2906 }
2907 
2908 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2909 //
2910 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2911 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2912 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2913 // path is treated as the current directory.
2914 //
2915 // This causes problems with CDS, which requires that all directories specified in the classpath
2916 // must be empty. In most cases, applications do NOT want to load classes from the current
2917 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2918 // scripts compatible with CDS.
2919 void Arguments::fix_appclasspath() {
2920   if (IgnoreEmptyClassPaths) {
2921     const char separator = *os::path_separator();
2922     const char* src = _java_class_path->value();
2923 
2924     // skip over all the leading empty paths
2925     while (*src == separator) {

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

3002   if (FLAG_IS_DEFAULT(UseLargePages) &&
3003       MaxHeapSize < LargePageHeapSizeThreshold) {
3004     // No need for large granularity pages w/small heaps.
3005     // Note that large pages are enabled/disabled for both the
3006     // Java heap and the code cache.
3007     FLAG_SET_DEFAULT(UseLargePages, false);
3008   }
3009 
3010   UNSUPPORTED_OPTION(ProfileInterpreter);
3011 #endif
3012 
3013   // Parse the CompilationMode flag
3014   if (!CompilationModeFlag::initialize()) {
3015     return JNI_ERR;
3016   }
3017 
3018   if (!check_vm_args_consistency()) {
3019     return JNI_ERR;
3020   }
3021 
3022   // finalize --module-patch and related --enable-preview
3023   if (finalize_patch_module() != JNI_OK) {
3024     return JNI_ERR;
3025   }
3026 
3027   if (!CDSConfig::check_vm_args_consistency(mode_flag_cmd_line)) {
3028     return JNI_ERR;
3029   }
3030 
3031 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3032   UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3033 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3034 
3035   return JNI_OK;
3036 }
3037 
3038 // Helper class for controlling the lifetime of JavaVMInitArgs
3039 // objects.  The contents of the JavaVMInitArgs are guaranteed to be
3040 // deleted on the destruction of the ScopedVMInitArgs object.
3041 class ScopedVMInitArgs : public StackObj {
3042  private:
3043   JavaVMInitArgs _args;
3044   char*          _container_name;
3045   bool           _is_set;
3046   char*          _vm_options_file_arg;
3047 

3777 #ifdef ZERO
3778   // Clear flags not supported on zero.
3779   FLAG_SET_DEFAULT(ProfileInterpreter, false);
3780 #endif // ZERO
3781 
3782   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3783     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3784     DebugNonSafepoints = true;
3785   }
3786 
3787   if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3788     warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3789   }
3790 
3791   // Treat the odd case where local verification is enabled but remote
3792   // verification is not as if both were enabled.
3793   if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3794     log_info(verification)("Turning on remote verification because local verification is on");
3795     FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3796   }
3797   if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) {
3798     // Disable calling convention optimizations if inline types are not supported.
3799     // Also these aren't useful in -Xint. However, don't disable them when dumping or using
3800     // the CDS archive, as the values must match between dumptime and runtime.
3801     InlineTypePassFieldsAsArgs = false;
3802     InlineTypeReturnedAsFields = false;
3803   }
3804 
3805 #ifndef PRODUCT
3806   if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3807     if (use_vm_log()) {
3808       LogVMOutput = true;
3809     }
3810   }
3811 #endif // PRODUCT
3812 
3813   if (PrintCommandLineFlags) {
3814     JVMFlag::printSetFlags(tty);
3815   }
3816 
3817 #if COMPILER2_OR_JVMCI
3818   if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3819     if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3820       warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3821     }
3822     FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3823 
< prev index next >