< 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 #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;

1757     os::free(const_cast<char*>(_sun_java_launcher));
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::executing_unit_tests() {
1768   return _executing_unit_tests;
1769 }
1770 
1771 //===========================================================================================================
1772 // Parsing of main arguments
1773 
1774 static unsigned int addreads_count = 0;
1775 static unsigned int addexports_count = 0;
1776 static unsigned int addopens_count = 0;
1777 static unsigned int patch_mod_count = 0;
1778 static unsigned int enable_native_access_count = 0;
1779 static bool patch_mod_javabase = false;
1780 
1781 // Check the consistency of vm_init_args
1782 bool Arguments::check_vm_args_consistency() {
1783   // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1784   if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) {
1785     return false;
1786   }
1787 
1788   // Method for adding checks for flag consistency.
1789   // The intent is to warn the user of all possible conflicts,
1790   // before returning an error.
1791   // Note: Needs platform-dependent factoring.
1792   bool status = true;
1793 
1794   if (TLABRefillWasteFraction == 0) {
1795     jio_fprintf(defaultStream::error_stream(),
1796                 "TLABRefillWasteFraction should be a denominator, "
1797                 "not %zu\n",
1798                 TLABRefillWasteFraction);
1799     status = false;
1800   }
1801 
1802   status = CompilerConfig::check_args_consistency(status);
1803 #if INCLUDE_JVMCI
1804   if (status && EnableJVMCI) {

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);
2084       FREE_C_HEAP_ARRAY(char, module_name);
2085       if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
2086         return JNI_ENOMEM;
2087       }
2088     } else {
2089       return JNI_ENOMEM;
2090     }
2091   }
2092   return JNI_OK;
2093 }
2094 
































































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

2343       jio_fprintf(defaultStream::error_stream(),
2344         "Instrumentation agents are not supported in this VM\n");
2345       return JNI_ERR;
2346 #else
2347       if (tail != nullptr) {
2348         size_t length = strlen(tail) + 1;
2349         char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2350         jio_snprintf(options, length, "%s", tail);
2351         JvmtiAgentList::add("instrument", options, false);
2352         FREE_C_HEAP_ARRAY(char, options);
2353 
2354         // java agents need module java.instrument
2355         if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2356           return JNI_ENOMEM;
2357         }
2358       }
2359 #endif // !INCLUDE_JVMTI
2360     // --enable_preview
2361     } else if (match_option(option, "--enable-preview")) {
2362       set_enable_preview();




2363     // -Xnoclassgc
2364     } else if (match_option(option, "-Xnoclassgc")) {
2365       if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2366         return JNI_EINVAL;
2367       }
2368     // -Xbatch
2369     } else if (match_option(option, "-Xbatch")) {
2370       if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2371         return JNI_EINVAL;
2372       }
2373     // -Xmn for compatibility with other JVM vendors
2374     } else if (match_option(option, "-Xmn", &tail)) {
2375       julong long_initial_young_size = 0;
2376       ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2377       if (errcode != arg_in_range) {
2378         jio_fprintf(defaultStream::error_stream(),
2379                     "Invalid initial young generation size: %s\n", option->optionString);
2380         describe_range_error(errcode);
2381         return JNI_EINVAL;
2382       }

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

















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

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

2974     return JNI_ERR;
2975   }
2976 



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

3759 #ifdef ZERO
3760   // Clear flags not supported on zero.
3761   FLAG_SET_DEFAULT(ProfileInterpreter, false);
3762 #endif // ZERO
3763 
3764   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3765     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3766     DebugNonSafepoints = true;
3767   }
3768 
3769   if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3770     warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3771   }
3772 
3773   // Treat the odd case where local verification is enabled but remote
3774   // verification is not as if both were enabled.
3775   if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3776     log_info(verification)("Turning on remote verification because local verification is on");
3777     FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3778   }












3779 
3780 #ifndef PRODUCT
3781   if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3782     if (use_vm_log()) {
3783       LogVMOutput = true;
3784     }
3785   }
3786 #endif // PRODUCT
3787 
3788   if (PrintCommandLineFlags) {
3789     JVMFlag::printSetFlags(tty);
3790   }
3791 
3792 #if COMPILER2_OR_JVMCI
3793   if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3794     if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3795       warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3796     }
3797     FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3798 

  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 #if INCLUDE_JVMCI
  91 bool   Arguments::_jvmci_module_added           = false;
  92 #endif
  93 char*  Arguments::_java_command                 = nullptr;
  94 SystemProperty* Arguments::_system_properties   = nullptr;
  95 size_t Arguments::_conservative_max_heap_alignment = 0;
  96 Arguments::Mode Arguments::_mode                = _mixed;
  97 const char*  Arguments::_java_vendor_url_bug    = nullptr;
  98 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;

1758     os::free(const_cast<char*>(_sun_java_launcher));
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::executing_unit_tests() {
1769   return _executing_unit_tests;
1770 }
1771 
1772 //===========================================================================================================
1773 // Parsing of main arguments
1774 
1775 static unsigned int addreads_count = 0;
1776 static unsigned int addexports_count = 0;
1777 static unsigned int addopens_count = 0;

1778 static unsigned int enable_native_access_count = 0;
1779 static bool patch_mod_javabase = false;
1780 
1781 // Check the consistency of vm_init_args
1782 bool Arguments::check_vm_args_consistency() {
1783   // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1784   if (!CDSConfig::check_vm_args_consistency(mode_flag_cmd_line)) {
1785     return false;
1786   }
1787 
1788   // Method for adding checks for flag consistency.
1789   // The intent is to warn the user of all possible conflicts,
1790   // before returning an error.
1791   // Note: Needs platform-dependent factoring.
1792   bool status = true;
1793 
1794   if (TLABRefillWasteFraction == 0) {
1795     jio_fprintf(defaultStream::error_stream(),
1796                 "TLABRefillWasteFraction should be a denominator, "
1797                 "not %zu\n",
1798                 TLABRefillWasteFraction);
1799     status = false;
1800   }
1801 
1802   status = CompilerConfig::check_args_consistency(status);
1803 #if INCLUDE_JVMCI
1804   if (status && EnableJVMCI) {

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

2404       jio_fprintf(defaultStream::error_stream(),
2405         "Instrumentation agents are not supported in this VM\n");
2406       return JNI_ERR;
2407 #else
2408       if (tail != nullptr) {
2409         size_t length = strlen(tail) + 1;
2410         char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2411         jio_snprintf(options, length, "%s", tail);
2412         JvmtiAgentList::add("instrument", options, false);
2413         FREE_C_HEAP_ARRAY(char, options);
2414 
2415         // java agents need module java.instrument
2416         if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2417           return JNI_ENOMEM;
2418         }
2419       }
2420 #endif // !INCLUDE_JVMTI
2421     // --enable_preview
2422     } else if (match_option(option, "--enable-preview")) {
2423       set_enable_preview();
2424       // --enable-preview enables Valhalla, EnableValhalla VM option will eventually be removed before integration
2425       if (FLAG_SET_CMDLINE(EnableValhalla, true) != JVMFlag::SUCCESS) {
2426         return JNI_EINVAL;
2427       }
2428     // -Xnoclassgc
2429     } else if (match_option(option, "-Xnoclassgc")) {
2430       if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2431         return JNI_EINVAL;
2432       }
2433     // -Xbatch
2434     } else if (match_option(option, "-Xbatch")) {
2435       if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2436         return JNI_EINVAL;
2437       }
2438     // -Xmn for compatibility with other JVM vendors
2439     } else if (match_option(option, "-Xmn", &tail)) {
2440       julong long_initial_young_size = 0;
2441       ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2442       if (errcode != arg_in_range) {
2443         jio_fprintf(defaultStream::error_stream(),
2444                     "Invalid initial young generation size: %s\n", option->optionString);
2445         describe_range_error(errcode);
2446         return JNI_EINVAL;
2447       }

2887     // Unknown option
2888     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2889       return JNI_ERR;
2890     }
2891   }
2892 
2893   // PrintSharedArchiveAndExit will turn on
2894   //   -Xshare:on
2895   //   -Xlog:class+path=info
2896   if (PrintSharedArchiveAndExit) {
2897     UseSharedSpaces = true;
2898     RequireSharedSpaces = true;
2899     LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2900   }
2901 
2902   fix_appclasspath();
2903 
2904   return JNI_OK;
2905 }
2906 
2907 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) {
2908   if (!allow_cds) {
2909     CDSConfig::set_module_patching_disables_cds();
2910     if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2911       CDSConfig::set_java_base_module_patching_disables_cds();





2912     }
2913   }
2914 
2915   // Create GrowableArray lazily, only if --patch-module has been specified
2916   if (_patch_mod_prefix == nullptr) {
2917     _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2918   }
2919 
2920   // Scan patches for matching module
2921   int i = _patch_mod_prefix->find_if([&](ModulePatchPath* patch) {
2922     return (strcmp(module_name, patch->module_name()) == 0);
2923   });
2924   if (i == -1) {
2925     _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2926   } else {
2927     if (allow_append) {
2928       // append path to existing module entry
2929       _patch_mod_prefix->at(i)->append_path(path);
2930     } else {
2931       if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2932         vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2933       } else {
2934         vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
2935       }
2936     }
2937   }
2938 }
2939 
2940 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2941 //
2942 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2943 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2944 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2945 // path is treated as the current directory.
2946 //
2947 // This causes problems with CDS, which requires that all directories specified in the classpath
2948 // must be empty. In most cases, applications do NOT want to load classes from the current
2949 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2950 // scripts compatible with CDS.
2951 void Arguments::fix_appclasspath() {
2952   if (IgnoreEmptyClassPaths) {
2953     const char separator = *os::path_separator();
2954     const char* src = _java_class_path->value();
2955 
2956     // skip over all the leading empty paths
2957     while (*src == separator) {

3030   }
3031 
3032 #if !COMPILER2_OR_JVMCI
3033   // Don't degrade server performance for footprint
3034   if (FLAG_IS_DEFAULT(UseLargePages) &&
3035       MaxHeapSize < LargePageHeapSizeThreshold) {
3036     // No need for large granularity pages w/small heaps.
3037     // Note that large pages are enabled/disabled for both the
3038     // Java heap and the code cache.
3039     FLAG_SET_DEFAULT(UseLargePages, false);
3040   }
3041 
3042   UNSUPPORTED_OPTION(ProfileInterpreter);
3043 #endif
3044 
3045   // Parse the CompilationMode flag
3046   if (!CompilationModeFlag::initialize()) {
3047     return JNI_ERR;
3048   }
3049 
3050   // finalize --module-patch and related --enable-preview
3051   if (finalize_patch_module() != JNI_OK) {
3052     return JNI_ERR;
3053   }
3054 
3055   if (!check_vm_args_consistency()) {
3056     return JNI_ERR;
3057   }
3058 
3059 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3060   UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3061 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3062 
3063   return JNI_OK;
3064 }
3065 
3066 // Helper class for controlling the lifetime of JavaVMInitArgs
3067 // objects.  The contents of the JavaVMInitArgs are guaranteed to be
3068 // deleted on the destruction of the ScopedVMInitArgs object.
3069 class ScopedVMInitArgs : public StackObj {
3070  private:
3071   JavaVMInitArgs _args;
3072   char*          _container_name;
3073   bool           _is_set;
3074   char*          _vm_options_file_arg;
3075 
3076  public:
3077   ScopedVMInitArgs(const char *container_name) {

3840 #ifdef ZERO
3841   // Clear flags not supported on zero.
3842   FLAG_SET_DEFAULT(ProfileInterpreter, false);
3843 #endif // ZERO
3844 
3845   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3846     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3847     DebugNonSafepoints = true;
3848   }
3849 
3850   if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3851     warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3852   }
3853 
3854   // Treat the odd case where local verification is enabled but remote
3855   // verification is not as if both were enabled.
3856   if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3857     log_info(verification)("Turning on remote verification because local verification is on");
3858     FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3859   }
3860   if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) {
3861     // Disable calling convention optimizations if inline types are not supported.
3862     // Also these aren't useful in -Xint. However, don't disable them when dumping or using
3863     // the CDS archive, as the values must match between dumptime and runtime.
3864     FLAG_SET_DEFAULT(InlineTypePassFieldsAsArgs, false);
3865     FLAG_SET_DEFAULT(InlineTypeReturnedAsFields, false);
3866   }
3867   if (!UseNonAtomicValueFlattening && !UseNullableValueFlattening && !UseAtomicValueFlattening) {
3868     // Flattening is disabled
3869     FLAG_SET_DEFAULT(UseArrayFlattening, false);
3870     FLAG_SET_DEFAULT(UseFieldFlattening, false);
3871   }
3872 
3873 #ifndef PRODUCT
3874   if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3875     if (use_vm_log()) {
3876       LogVMOutput = true;
3877     }
3878   }
3879 #endif // PRODUCT
3880 
3881   if (PrintCommandLineFlags) {
3882     JVMFlag::printSetFlags(tty);
3883   }
3884 
3885 #if COMPILER2_OR_JVMCI
3886   if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3887     if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3888       warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3889     }
3890     FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3891 
< prev index next >