< prev index next >

src/hotspot/share/runtime/arguments.cpp

Print this page

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

  77 
  78 static const char _default_java_launcher[] = "generic";
  79 
  80 #define DEFAULT_JAVA_LAUNCHER _default_java_launcher
  81 
  82 char*  Arguments::_jvm_flags_file               = nullptr;
  83 char** Arguments::_jvm_flags_array              = nullptr;
  84 int    Arguments::_num_jvm_flags                = 0;
  85 char** Arguments::_jvm_args_array               = nullptr;
  86 int    Arguments::_num_jvm_args                 = 0;
  87 unsigned int Arguments::_addmods_count          = 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()

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

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
































































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

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




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

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

















2847 }
2848 
2849 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2850 //
2851 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2852 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2853 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2854 // path is treated as the current directory.
2855 //
2856 // This causes problems with CDS, which requires that all directories specified in the classpath
2857 // must be empty. In most cases, applications do NOT want to load classes from the current
2858 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2859 // scripts compatible with CDS.
2860 void Arguments::fix_appclasspath() {
2861   if (IgnoreEmptyClassPaths) {
2862     const char separator = *os::path_separator();
2863     const char* src = _java_class_path->value();
2864 
2865     // skip over all the leading empty paths
2866     while (*src == separator) {

2939   }
2940 
2941 #if !COMPILER2_OR_JVMCI
2942   // Don't degrade server performance for footprint
2943   if (FLAG_IS_DEFAULT(UseLargePages) &&
2944       MaxHeapSize < LargePageHeapSizeThreshold) {
2945     // No need for large granularity pages w/small heaps.
2946     // Note that large pages are enabled/disabled for both the
2947     // Java heap and the code cache.
2948     FLAG_SET_DEFAULT(UseLargePages, false);
2949   }
2950 
2951   UNSUPPORTED_OPTION(ProfileInterpreter);
2952 #endif
2953 
2954   // Parse the CompilationMode flag
2955   if (!CompilationModeFlag::initialize()) {
2956     return JNI_ERR;
2957   }
2958 
2959   if (!check_vm_args_consistency()) {

2960     return JNI_ERR;
2961   }
2962 



2963 
2964 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
2965   UNSUPPORTED_OPTION(ShowRegistersOnAssert);
2966 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2967 
2968   return JNI_OK;
2969 }
2970 
2971 // Helper class for controlling the lifetime of JavaVMInitArgs
2972 // objects.  The contents of the JavaVMInitArgs are guaranteed to be
2973 // deleted on the destruction of the ScopedVMInitArgs object.
2974 class ScopedVMInitArgs : public StackObj {
2975  private:
2976   JavaVMInitArgs _args;
2977   char*          _container_name;
2978   bool           _is_set;
2979   char*          _vm_options_file_arg;
2980 
2981  public:
2982   ScopedVMInitArgs(const char *container_name) {

3744 #ifdef ZERO
3745   // Clear flags not supported on zero.
3746   FLAG_SET_DEFAULT(ProfileInterpreter, false);
3747 #endif // ZERO
3748 
3749   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3750     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3751     DebugNonSafepoints = true;
3752   }
3753 
3754   if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3755     warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3756   }
3757 
3758   // Treat the odd case where local verification is enabled but remote
3759   // verification is not as if both were enabled.
3760   if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3761     log_info(verification)("Turning on remote verification because local verification is on");
3762     FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3763   }







3764 
3765 #ifndef PRODUCT
3766   if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3767     if (use_vm_log()) {
3768       LogVMOutput = true;
3769     }
3770   }
3771 #endif // PRODUCT
3772 
3773   if (PrintCommandLineFlags) {
3774     JVMFlag::printSetFlags(tty);
3775   }
3776 
3777 #if COMPILER2_OR_JVMCI
3778   if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3779     if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3780       warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3781     }
3782     FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3783 

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

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

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



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

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

2873     // Unknown option
2874     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2875       return JNI_ERR;
2876     }
2877   }
2878 
2879   // PrintSharedArchiveAndExit will turn on
2880   //   -Xshare:on
2881   //   -Xlog:class+path=info
2882   if (PrintSharedArchiveAndExit) {
2883     UseSharedSpaces = true;
2884     RequireSharedSpaces = true;
2885     LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2886   }
2887 
2888   fix_appclasspath();
2889 
2890   return JNI_OK;
2891 }
2892 
2893 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) {
2894   if (!allow_cds) {
2895     CDSConfig::set_module_patching_disables_cds();
2896     if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2897       CDSConfig::set_java_base_module_patching_disables_cds();





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

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

3825 #ifdef ZERO
3826   // Clear flags not supported on zero.
3827   FLAG_SET_DEFAULT(ProfileInterpreter, false);
3828 #endif // ZERO
3829 
3830   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3831     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3832     DebugNonSafepoints = true;
3833   }
3834 
3835   if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3836     warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3837   }
3838 
3839   // Treat the odd case where local verification is enabled but remote
3840   // verification is not as if both were enabled.
3841   if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3842     log_info(verification)("Turning on remote verification because local verification is on");
3843     FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3844   }
3845   if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) {
3846     // Disable calling convention optimizations if inline types are not supported.
3847     // Also these aren't useful in -Xint. However, don't disable them when dumping or using
3848     // the CDS archive, as the values must match between dumptime and runtime.
3849     InlineTypePassFieldsAsArgs = false;
3850     InlineTypeReturnedAsFields = false;
3851   }
3852 
3853 #ifndef PRODUCT
3854   if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3855     if (use_vm_log()) {
3856       LogVMOutput = true;
3857     }
3858   }
3859 #endif // PRODUCT
3860 
3861   if (PrintCommandLineFlags) {
3862     JVMFlag::printSetFlags(tty);
3863   }
3864 
3865 #if COMPILER2_OR_JVMCI
3866   if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3867     if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3868       warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3869     }
3870     FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3871 
< prev index next >