< prev index next >

src/hotspot/share/runtime/arguments.cpp

Print this page

  59 #include "runtime/java.hpp"
  60 #include "runtime/os.hpp"
  61 #include "runtime/safepoint.hpp"
  62 #include "runtime/safepointMechanism.hpp"
  63 #include "runtime/synchronizer.hpp"
  64 #include "runtime/vm_version.hpp"
  65 #include "services/management.hpp"
  66 #include "utilities/align.hpp"
  67 #include "utilities/checkedCast.hpp"
  68 #include "utilities/debug.hpp"
  69 #include "utilities/defaultStream.hpp"
  70 #include "utilities/macros.hpp"
  71 #include "utilities/parseInteger.hpp"
  72 #include "utilities/powerOfTwo.hpp"
  73 #include "utilities/stringUtils.hpp"
  74 #include "utilities/systemMemoryBarrier.hpp"
  75 #if INCLUDE_JFR
  76 #include "jfr/jfr.hpp"
  77 #endif
  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 #if INCLUDE_JVMCI
  90 bool   Arguments::_jvmci_module_added           = false;
  91 #endif
  92 char*  Arguments::_java_command                 = nullptr;
  93 SystemProperty* Arguments::_system_properties   = nullptr;
  94 size_t Arguments::_conservative_max_heap_alignment = 0;
  95 Arguments::Mode Arguments::_mode                = _mixed;
  96 const char*  Arguments::_java_vendor_url_bug    = nullptr;
  97 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
  98 bool   Arguments::_executing_unit_tests         = false;

 345         matches_property_suffix(property_suffix, UPGRADE_PATH, UPGRADE_PATH_LEN) ||
 346         matches_property_suffix(property_suffix, ILLEGAL_NATIVE_ACCESS, ILLEGAL_NATIVE_ACCESS_LEN)) {
 347       return true;
 348     }
 349 
 350     if (!check_for_cds) {
 351       // CDS notes: these properties are supported by CDS archived full module graph.
 352       if (matches_property_suffix(property_suffix, ADDEXPORTS, ADDEXPORTS_LEN) ||
 353           matches_property_suffix(property_suffix, ADDOPENS, ADDOPENS_LEN) ||
 354           matches_property_suffix(property_suffix, ADDREADS, ADDREADS_LEN) ||
 355           matches_property_suffix(property_suffix, PATH, PATH_LEN) ||
 356           matches_property_suffix(property_suffix, ADDMODS, ADDMODS_LEN) ||
 357           matches_property_suffix(property_suffix, ENABLE_NATIVE_ACCESS, ENABLE_NATIVE_ACCESS_LEN)) {
 358         return true;
 359       }
 360     }
 361   }
 362   return false;
 363 }
 364 












 365 // Process java launcher properties.
 366 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
 367   // See if sun.java.launcher is defined.
 368   // Must do this before setting up other system properties,
 369   // as some of them may depend on launcher type.
 370   for (int index = 0; index < args->nOptions; index++) {
 371     const JavaVMOption* option = args->options + index;
 372     const char* tail;
 373 
 374     if (match_option(option, "-Dsun.java.launcher=", &tail)) {
 375       process_java_launcher_argument(tail, option->extraInfo);
 376       continue;
 377     }
 378     if (match_option(option, "-XX:+ExecutingUnitTests")) {
 379       _executing_unit_tests = true;
 380       continue;
 381     }
 382   }
 383 }
 384 

1790     os::free(const_cast<char*>(_sun_java_launcher));
1791   }
1792   _sun_java_launcher = os::strdup_check_oom(launcher);
1793 }
1794 
1795 bool Arguments::created_by_java_launcher() {
1796   assert(_sun_java_launcher != nullptr, "property must have value");
1797   return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1798 }
1799 
1800 bool Arguments::executing_unit_tests() {
1801   return _executing_unit_tests;
1802 }
1803 
1804 //===========================================================================================================
1805 // Parsing of main arguments
1806 
1807 static unsigned int addreads_count = 0;
1808 static unsigned int addexports_count = 0;
1809 static unsigned int addopens_count = 0;
1810 static unsigned int patch_mod_count = 0;
1811 static unsigned int enable_native_access_count = 0;
1812 static bool patch_mod_javabase = false;
1813 
1814 // Check the consistency of vm_init_args
1815 bool Arguments::check_vm_args_consistency() {
1816   // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1817   if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) {
1818     return false;
1819   }
1820 
1821   // Method for adding checks for flag consistency.
1822   // The intent is to warn the user of all possible conflicts,
1823   // before returning an error.
1824   // Note: Needs platform-dependent factoring.
1825   bool status = true;
1826 
1827   if (TLABRefillWasteFraction == 0) {
1828     jio_fprintf(defaultStream::error_stream(),
1829                 "TLABRefillWasteFraction should be a denominator, "
1830                 "not %zu\n",
1831                 TLABRefillWasteFraction);
1832     status = false;
1833   }
1834 
1835   status = CompilerConfig::check_args_consistency(status);
1836 #if INCLUDE_JVMCI
1837   if (status && EnableJVMCI) {

1964 
1965   // Remember the default value of SharedBaseAddress.
1966   Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1967 
1968   // Setup flags for mixed which is the default
1969   set_mode_flags(_mixed);
1970 
1971   jint result;
1972   for (int i = 0; i < all_args->length(); i++) {
1973     result = parse_each_vm_init_arg(all_args->at(i)._args, all_args->at(i)._origin);
1974     if (result != JNI_OK) {
1975       return result;
1976     }
1977   }
1978 
1979   // Disable CDS for exploded image
1980   if (!has_jimage()) {
1981     no_shared_spaces("CDS disabled on exploded JDK");
1982   }
1983 




1984   // We need to ensure processor and memory resources have been properly
1985   // configured - which may rely on arguments we just processed - before
1986   // doing the final argument processing. Any argument processing that
1987   // needs to know about processor and memory resources must occur after
1988   // this point.
1989 
1990   os::init_container_support();
1991 
1992   SystemMemoryBarrier::initialize();
1993 
1994   // Do final processing now that all arguments have been parsed
1995   result = finalize_vm_init_args();
1996   if (result != JNI_OK) {
1997     return result;
1998   }
1999 
2000   return JNI_OK;
2001 }
2002 
2003 #if !INCLUDE_JVMTI || INCLUDE_CDS

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


















































































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

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




2346     // -Xnoclassgc
2347     } else if (match_option(option, "-Xnoclassgc")) {
2348       if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2349         return JNI_EINVAL;
2350       }
2351     // -Xbatch
2352     } else if (match_option(option, "-Xbatch")) {
2353       if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2354         return JNI_EINVAL;
2355       }
2356     // -Xmn for compatibility with other JVM vendors
2357     } else if (match_option(option, "-Xmn", &tail)) {
2358       julong long_initial_young_size = 0;
2359       ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2360       if (errcode != arg_in_range) {
2361         jio_fprintf(defaultStream::error_stream(),
2362                     "Invalid initial young generation size: %s\n", option->optionString);
2363         describe_range_error(errcode);
2364         return JNI_EINVAL;
2365       }

2829     // Unknown option
2830     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2831       return JNI_ERR;
2832     }
2833   }
2834 
2835   // PrintSharedArchiveAndExit will turn on
2836   //   -Xshare:on
2837   //   -Xlog:class+path=info
2838   if (PrintSharedArchiveAndExit) {
2839     UseSharedSpaces = true;
2840     RequireSharedSpaces = true;
2841     LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2842   }
2843 
2844   fix_appclasspath();
2845 
2846   return JNI_OK;
2847 }
2848 
2849 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path) {
2850   // For java.base check for duplicate --patch-module options being specified on the command line.
2851   // This check is only required for java.base, all other duplicate module specifications
2852   // will be checked during module system initialization.  The module system initialization
2853   // will throw an ExceptionInInitializerError if this situation occurs.
2854   if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2855     if (patch_mod_javabase) {
2856       vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2857     } else {
2858       patch_mod_javabase = true;
2859     }
2860   }
2861 
2862   // Create GrowableArray lazily, only if --patch-module has been specified
2863   if (_patch_mod_prefix == nullptr) {
2864     _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2865   }
2866 
2867   _patch_mod_prefix->push(new ModulePatchPath(module_name, path));

















2868 }
2869 
2870 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2871 //
2872 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2873 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2874 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2875 // path is treated as the current directory.
2876 //
2877 // This causes problems with CDS, which requires that all directories specified in the classpath
2878 // must be empty. In most cases, applications do NOT want to load classes from the current
2879 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2880 // scripts compatible with CDS.
2881 void Arguments::fix_appclasspath() {
2882   if (IgnoreEmptyClassPaths) {
2883     const char separator = *os::path_separator();
2884     const char* src = _java_class_path->value();
2885 
2886     // skip over all the leading empty paths
2887     while (*src == separator) {

2960   }
2961 
2962 #if !COMPILER2_OR_JVMCI
2963   // Don't degrade server performance for footprint
2964   if (FLAG_IS_DEFAULT(UseLargePages) &&
2965       MaxHeapSize < LargePageHeapSizeThreshold) {
2966     // No need for large granularity pages w/small heaps.
2967     // Note that large pages are enabled/disabled for both the
2968     // Java heap and the code cache.
2969     FLAG_SET_DEFAULT(UseLargePages, false);
2970   }
2971 
2972   UNSUPPORTED_OPTION(ProfileInterpreter);
2973 #endif
2974 
2975   // Parse the CompilationMode flag
2976   if (!CompilationModeFlag::initialize()) {
2977     return JNI_ERR;
2978   }
2979 
2980   if (!check_vm_args_consistency()) {

2981     return JNI_ERR;
2982   }
2983 



2984 
2985 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
2986   UNSUPPORTED_OPTION(ShowRegistersOnAssert);
2987 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2988 
2989   return JNI_OK;
2990 }
2991 
2992 // Helper class for controlling the lifetime of JavaVMInitArgs
2993 // objects.  The contents of the JavaVMInitArgs are guaranteed to be
2994 // deleted on the destruction of the ScopedVMInitArgs object.
2995 class ScopedVMInitArgs : public StackObj {
2996  private:
2997   JavaVMInitArgs _args;
2998   char*          _container_name;
2999   bool           _is_set;
3000   char*          _vm_options_file_arg;
3001 
3002  public:
3003   ScopedVMInitArgs(const char *container_name) {

3849 #ifdef ZERO
3850   // Clear flags not supported on zero.
3851   FLAG_SET_DEFAULT(ProfileInterpreter, false);
3852 #endif // ZERO
3853 
3854   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3855     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3856     DebugNonSafepoints = true;
3857   }
3858 
3859   if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3860     warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3861   }
3862 
3863   // Treat the odd case where local verification is enabled but remote
3864   // verification is not as if both were enabled.
3865   if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3866     log_info(verification)("Turning on remote verification because local verification is on");
3867     FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3868   }












3869 
3870 #ifndef PRODUCT
3871   if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3872     if (use_vm_log()) {
3873       LogVMOutput = true;
3874     }
3875   }
3876 #endif // PRODUCT
3877 
3878   if (PrintCommandLineFlags) {
3879     JVMFlag::printSetFlags(tty);
3880   }
3881 
3882 #if COMPILER2_OR_JVMCI
3883   if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3884     if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3885       warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3886     }
3887     FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3888 

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

 347         matches_property_suffix(property_suffix, UPGRADE_PATH, UPGRADE_PATH_LEN) ||
 348         matches_property_suffix(property_suffix, ILLEGAL_NATIVE_ACCESS, ILLEGAL_NATIVE_ACCESS_LEN)) {
 349       return true;
 350     }
 351 
 352     if (!check_for_cds) {
 353       // CDS notes: these properties are supported by CDS archived full module graph.
 354       if (matches_property_suffix(property_suffix, ADDEXPORTS, ADDEXPORTS_LEN) ||
 355           matches_property_suffix(property_suffix, ADDOPENS, ADDOPENS_LEN) ||
 356           matches_property_suffix(property_suffix, ADDREADS, ADDREADS_LEN) ||
 357           matches_property_suffix(property_suffix, PATH, PATH_LEN) ||
 358           matches_property_suffix(property_suffix, ADDMODS, ADDMODS_LEN) ||
 359           matches_property_suffix(property_suffix, ENABLE_NATIVE_ACCESS, ENABLE_NATIVE_ACCESS_LEN)) {
 360         return true;
 361       }
 362     }
 363   }
 364   return false;
 365 }
 366 
 367 bool Arguments::patching_migrated_classes(const char* property, const char* value) {
 368   if (strncmp(property, MODULE_PROPERTY_PREFIX, MODULE_PROPERTY_PREFIX_LEN) == 0) {
 369     const char* property_suffix = property + MODULE_PROPERTY_PREFIX_LEN;
 370     if (matches_property_suffix(property_suffix, PATCH, PATCH_LEN)) {
 371       if (strcmp(value, "java.base-valueclasses.jar")) {
 372         return true;
 373       }
 374     }
 375   }
 376   return false;
 377 }
 378 
 379 // Process java launcher properties.
 380 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
 381   // See if sun.java.launcher is defined.
 382   // Must do this before setting up other system properties,
 383   // as some of them may depend on launcher type.
 384   for (int index = 0; index < args->nOptions; index++) {
 385     const JavaVMOption* option = args->options + index;
 386     const char* tail;
 387 
 388     if (match_option(option, "-Dsun.java.launcher=", &tail)) {
 389       process_java_launcher_argument(tail, option->extraInfo);
 390       continue;
 391     }
 392     if (match_option(option, "-XX:+ExecutingUnitTests")) {
 393       _executing_unit_tests = true;
 394       continue;
 395     }
 396   }
 397 }
 398 

1804     os::free(const_cast<char*>(_sun_java_launcher));
1805   }
1806   _sun_java_launcher = os::strdup_check_oom(launcher);
1807 }
1808 
1809 bool Arguments::created_by_java_launcher() {
1810   assert(_sun_java_launcher != nullptr, "property must have value");
1811   return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1812 }
1813 
1814 bool Arguments::executing_unit_tests() {
1815   return _executing_unit_tests;
1816 }
1817 
1818 //===========================================================================================================
1819 // Parsing of main arguments
1820 
1821 static unsigned int addreads_count = 0;
1822 static unsigned int addexports_count = 0;
1823 static unsigned int addopens_count = 0;

1824 static unsigned int enable_native_access_count = 0;
1825 static bool patch_mod_javabase = false;
1826 
1827 // Check the consistency of vm_init_args
1828 bool Arguments::check_vm_args_consistency() {
1829   // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1830   if (!CDSConfig::check_vm_args_consistency(mode_flag_cmd_line)) {
1831     return false;
1832   }
1833 
1834   // Method for adding checks for flag consistency.
1835   // The intent is to warn the user of all possible conflicts,
1836   // before returning an error.
1837   // Note: Needs platform-dependent factoring.
1838   bool status = true;
1839 
1840   if (TLABRefillWasteFraction == 0) {
1841     jio_fprintf(defaultStream::error_stream(),
1842                 "TLABRefillWasteFraction should be a denominator, "
1843                 "not %zu\n",
1844                 TLABRefillWasteFraction);
1845     status = false;
1846   }
1847 
1848   status = CompilerConfig::check_args_consistency(status);
1849 #if INCLUDE_JVMCI
1850   if (status && EnableJVMCI) {

1977 
1978   // Remember the default value of SharedBaseAddress.
1979   Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1980 
1981   // Setup flags for mixed which is the default
1982   set_mode_flags(_mixed);
1983 
1984   jint result;
1985   for (int i = 0; i < all_args->length(); i++) {
1986     result = parse_each_vm_init_arg(all_args->at(i)._args, all_args->at(i)._origin);
1987     if (result != JNI_OK) {
1988       return result;
1989     }
1990   }
1991 
1992   // Disable CDS for exploded image
1993   if (!has_jimage()) {
1994     no_shared_spaces("CDS disabled on exploded JDK");
1995   }
1996 
1997   if (UseAltSubstitutabilityMethod) {
1998     no_shared_spaces("Alternate substitutability method doesn't work with CDS yet");
1999   }
2000 
2001   // We need to ensure processor and memory resources have been properly
2002   // configured - which may rely on arguments we just processed - before
2003   // doing the final argument processing. Any argument processing that
2004   // needs to know about processor and memory resources must occur after
2005   // this point.
2006 
2007   os::init_container_support();
2008 
2009   SystemMemoryBarrier::initialize();
2010 
2011   // Do final processing now that all arguments have been parsed
2012   result = finalize_vm_init_args();
2013   if (result != JNI_OK) {
2014     return result;
2015   }
2016 
2017   return JNI_OK;
2018 }
2019 
2020 #if !INCLUDE_JVMTI || INCLUDE_CDS

2063   return false;
2064 }
2065 #endif
2066 
2067 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2068   // --patch-module=<module>=<file>(<pathsep><file>)*
2069   assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2070   // Find the equal sign between the module name and the path specification
2071   const char* module_equal = strchr(patch_mod_tail, '=');
2072   if (module_equal == nullptr) {
2073     jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2074     return JNI_ERR;
2075   } else {
2076     // Pick out the module name
2077     size_t module_len = module_equal - patch_mod_tail;
2078     char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2079     if (module_name != nullptr) {
2080       memcpy(module_name, patch_mod_tail, module_len);
2081       *(module_name + module_len) = '\0';
2082       // The path piece begins one past the module_equal sign
2083       add_patch_mod_prefix(module_name, module_equal + 1, false /* no append */, false /* no cds */);
2084       FREE_C_HEAP_ARRAY(char, module_name);



2085     } else {
2086       return JNI_ENOMEM;
2087     }
2088   }
2089   return JNI_OK;
2090 }
2091 
2092 // Temporary system property to disable preview patching and enable the new preview mode
2093 // feature for testing/development. Once the preview mode feature is finished, the value
2094 // will be always 'true' and this code, and all related dead-code can be removed.
2095 #define DISABLE_PREVIEW_PATCHING_DEFAULT false
2096 
2097 bool Arguments::disable_preview_patching() {
2098   const char* prop = get_property("DISABLE_PREVIEW_PATCHING");
2099   return (prop != nullptr)
2100       ? strncmp(prop, "true", strlen("true")) == 0
2101       : DISABLE_PREVIEW_PATCHING_DEFAULT;
2102 }
2103 
2104 // VALUECLASS_STR must match string used in the build
2105 #define VALUECLASS_STR "valueclasses"
2106 #define VALUECLASS_JAR "-" VALUECLASS_STR ".jar"
2107 
2108 // Finalize --patch-module args and --enable-preview related to value class module patches.
2109 // Create all numbered properties passing module patches.
2110 int Arguments::finalize_patch_module() {
2111   // If --enable-preview and EnableValhalla is true, modules may have preview mode resources.
2112   bool enable_valhalla_preview = enable_preview() && EnableValhalla;
2113   // Whether to use module patching, or the new preview mode feature for preview resources.
2114   bool disable_patching = disable_preview_patching();
2115 
2116   // This must be called, even with 'false', to enable resource lookup from JImage.
2117   ClassLoader::init_jimage(disable_patching && enable_valhalla_preview);
2118 
2119   // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2120   // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2121   if (!disable_patching && enable_valhalla_preview) {
2122     char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2123     const char * fileSep = os::file_separator();
2124 
2125     jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s",
2126                  Arguments::get_java_home(), fileSep, fileSep, fileSep);
2127     DIR* dir = os::opendir(valueclasses_dir);
2128     if (dir != nullptr) {
2129       char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2130       char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2131 
2132       for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) {
2133         // Test if file ends-with "-valueclasses.jar"
2134         int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1);
2135         if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) {
2136           continue;         // too short or not the expected suffix
2137         }
2138 
2139         strcpy(module_name, entry->d_name);
2140         module_name[len] = '\0';     // truncate to just module-name
2141 
2142         jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name);
2143         add_patch_mod_prefix(module_name, path, true /* append */, true /* cds OK*/);
2144         log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name);
2145       }
2146       FreeHeap(module_name);
2147       FreeHeap(path);
2148       os::closedir(dir);
2149     }
2150     FreeHeap(valueclasses_dir);
2151   }
2152 
2153   // Create numbered properties for each module that has been patched either
2154   // by --patch-module (or --enable-preview if disable_patching is false).
2155   // Format is "jdk.module.patch.<n>=<module_name>=<path>"
2156   if (_patch_mod_prefix != nullptr) {
2157     char * prop_value = AllocateHeap(JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, mtArguments);
2158     unsigned int patch_mod_count = 0;
2159 
2160     for (GrowableArrayIterator<ModulePatchPath *> it = _patch_mod_prefix->begin();
2161             it != _patch_mod_prefix->end(); ++it) {
2162       jio_snprintf(prop_value, JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, "%s=%s",
2163                    (*it)->module_name(), (*it)->path_string());
2164       if (!create_numbered_module_property("jdk.module.patch", prop_value, patch_mod_count++)) {
2165         FreeHeap(prop_value);
2166         return JNI_ENOMEM;
2167       }
2168     }
2169     FreeHeap(prop_value);
2170   }
2171   return JNI_OK;
2172 }
2173 
2174 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2175 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2176   // The min and max sizes match the values in globals.hpp, but scaled
2177   // with K. The values have been chosen so that alignment with page
2178   // size doesn't change the max value, which makes the conversions
2179   // back and forth between Xss value and ThreadStackSize value easier.
2180   // The values have also been chosen to fit inside a 32-bit signed type.
2181   const julong min_ThreadStackSize = 0;
2182   const julong max_ThreadStackSize = 1 * M;
2183 
2184   // Make sure the above values match the range set in globals.hpp
2185   const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2186   assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2187   assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2188 
2189   const julong min_size = min_ThreadStackSize * K;
2190   const julong max_size = max_ThreadStackSize * K;
2191 
2192   assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2193 

2422       jio_fprintf(defaultStream::error_stream(),
2423         "Instrumentation agents are not supported in this VM\n");
2424       return JNI_ERR;
2425 #else
2426       if (tail != nullptr) {
2427         size_t length = strlen(tail) + 1;
2428         char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2429         jio_snprintf(options, length, "%s", tail);
2430         JvmtiAgentList::add("instrument", options, false);
2431         FREE_C_HEAP_ARRAY(char, options);
2432 
2433         // java agents need module java.instrument
2434         if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2435           return JNI_ENOMEM;
2436         }
2437       }
2438 #endif // !INCLUDE_JVMTI
2439     // --enable_preview
2440     } else if (match_option(option, "--enable-preview")) {
2441       set_enable_preview();
2442       // --enable-preview enables Valhalla, EnableValhalla VM option will eventually be removed before integration
2443       if (FLAG_SET_CMDLINE(EnableValhalla, true) != JVMFlag::SUCCESS) {
2444         return JNI_EINVAL;
2445       }
2446     // -Xnoclassgc
2447     } else if (match_option(option, "-Xnoclassgc")) {
2448       if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2449         return JNI_EINVAL;
2450       }
2451     // -Xbatch
2452     } else if (match_option(option, "-Xbatch")) {
2453       if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2454         return JNI_EINVAL;
2455       }
2456     // -Xmn for compatibility with other JVM vendors
2457     } else if (match_option(option, "-Xmn", &tail)) {
2458       julong long_initial_young_size = 0;
2459       ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2460       if (errcode != arg_in_range) {
2461         jio_fprintf(defaultStream::error_stream(),
2462                     "Invalid initial young generation size: %s\n", option->optionString);
2463         describe_range_error(errcode);
2464         return JNI_EINVAL;
2465       }

2929     // Unknown option
2930     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2931       return JNI_ERR;
2932     }
2933   }
2934 
2935   // PrintSharedArchiveAndExit will turn on
2936   //   -Xshare:on
2937   //   -Xlog:class+path=info
2938   if (PrintSharedArchiveAndExit) {
2939     UseSharedSpaces = true;
2940     RequireSharedSpaces = true;
2941     LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2942   }
2943 
2944   fix_appclasspath();
2945 
2946   return JNI_OK;
2947 }
2948 
2949 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) {
2950   if (!allow_cds) {
2951     CDSConfig::set_module_patching_disables_cds();
2952     if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2953       CDSConfig::set_java_base_module_patching_disables_cds();





2954     }
2955   }
2956 
2957   // Create GrowableArray lazily, only if --patch-module has been specified
2958   if (_patch_mod_prefix == nullptr) {
2959     _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2960   }
2961 
2962   // Scan patches for matching module
2963   int i = _patch_mod_prefix->find_if([&](ModulePatchPath* patch) {
2964     return (strcmp(module_name, patch->module_name()) == 0);
2965   });
2966   if (i == -1) {
2967     _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2968   } else {
2969     if (allow_append) {
2970       // append path to existing module entry
2971       _patch_mod_prefix->at(i)->append_path(path);
2972     } else {
2973       if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2974         vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2975       } else {
2976         vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
2977       }
2978     }
2979   }
2980 }
2981 
2982 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2983 //
2984 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2985 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2986 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2987 // path is treated as the current directory.
2988 //
2989 // This causes problems with CDS, which requires that all directories specified in the classpath
2990 // must be empty. In most cases, applications do NOT want to load classes from the current
2991 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2992 // scripts compatible with CDS.
2993 void Arguments::fix_appclasspath() {
2994   if (IgnoreEmptyClassPaths) {
2995     const char separator = *os::path_separator();
2996     const char* src = _java_class_path->value();
2997 
2998     // skip over all the leading empty paths
2999     while (*src == separator) {

3072   }
3073 
3074 #if !COMPILER2_OR_JVMCI
3075   // Don't degrade server performance for footprint
3076   if (FLAG_IS_DEFAULT(UseLargePages) &&
3077       MaxHeapSize < LargePageHeapSizeThreshold) {
3078     // No need for large granularity pages w/small heaps.
3079     // Note that large pages are enabled/disabled for both the
3080     // Java heap and the code cache.
3081     FLAG_SET_DEFAULT(UseLargePages, false);
3082   }
3083 
3084   UNSUPPORTED_OPTION(ProfileInterpreter);
3085 #endif
3086 
3087   // Parse the CompilationMode flag
3088   if (!CompilationModeFlag::initialize()) {
3089     return JNI_ERR;
3090   }
3091 
3092   // finalize --module-patch and related --enable-preview
3093   if (finalize_patch_module() != JNI_OK) {
3094     return JNI_ERR;
3095   }
3096 
3097   if (!check_vm_args_consistency()) {
3098     return JNI_ERR;
3099   }
3100 
3101 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3102   UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3103 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3104 
3105   return JNI_OK;
3106 }
3107 
3108 // Helper class for controlling the lifetime of JavaVMInitArgs
3109 // objects.  The contents of the JavaVMInitArgs are guaranteed to be
3110 // deleted on the destruction of the ScopedVMInitArgs object.
3111 class ScopedVMInitArgs : public StackObj {
3112  private:
3113   JavaVMInitArgs _args;
3114   char*          _container_name;
3115   bool           _is_set;
3116   char*          _vm_options_file_arg;
3117 
3118  public:
3119   ScopedVMInitArgs(const char *container_name) {

3965 #ifdef ZERO
3966   // Clear flags not supported on zero.
3967   FLAG_SET_DEFAULT(ProfileInterpreter, false);
3968 #endif // ZERO
3969 
3970   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3971     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3972     DebugNonSafepoints = true;
3973   }
3974 
3975   if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3976     warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3977   }
3978 
3979   // Treat the odd case where local verification is enabled but remote
3980   // verification is not as if both were enabled.
3981   if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3982     log_info(verification)("Turning on remote verification because local verification is on");
3983     FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3984   }
3985   if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) {
3986     // Disable calling convention optimizations if inline types are not supported.
3987     // Also these aren't useful in -Xint. However, don't disable them when dumping or using
3988     // the CDS archive, as the values must match between dumptime and runtime.
3989     FLAG_SET_DEFAULT(InlineTypePassFieldsAsArgs, false);
3990     FLAG_SET_DEFAULT(InlineTypeReturnedAsFields, false);
3991   }
3992   if (!UseNonAtomicValueFlattening && !UseNullableValueFlattening && !UseAtomicValueFlattening) {
3993     // Flattening is disabled
3994     FLAG_SET_DEFAULT(UseArrayFlattening, false);
3995     FLAG_SET_DEFAULT(UseFieldFlattening, false);
3996   }
3997 
3998 #ifndef PRODUCT
3999   if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
4000     if (use_vm_log()) {
4001       LogVMOutput = true;
4002     }
4003   }
4004 #endif // PRODUCT
4005 
4006   if (PrintCommandLineFlags) {
4007     JVMFlag::printSetFlags(tty);
4008   }
4009 
4010 #if COMPILER2_OR_JVMCI
4011   if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
4012     if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
4013       warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
4014     }
4015     FLAG_SET_DEFAULT(EnableVectorReboxing, false);
4016 
< prev index next >