< 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 char*  Arguments::_java_command                 = nullptr;
  89 SystemProperty* Arguments::_system_properties   = nullptr;
  90 size_t Arguments::_conservative_max_heap_alignment = 0;
  91 Arguments::Mode Arguments::_mode                = _mixed;
  92 const char*  Arguments::_java_vendor_url_bug    = nullptr;
  93 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
  94 bool   Arguments::_sun_java_launcher_is_altjvm  = false;
  95 
  96 // These parameters are reset in method parse_vm_init_args()
  97 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;

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

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

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
































































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

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

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

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




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

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

















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

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

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





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

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







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

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

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

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

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


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

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



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

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

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

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

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





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

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

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

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