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::_executing_unit_tests = false;
95
96 // These parameters are reset in method parse_vm_init_args()
1753 os::free(const_cast<char*>(_sun_java_launcher));
1754 }
1755 _sun_java_launcher = os::strdup_check_oom(launcher);
1756 }
1757
1758 bool Arguments::created_by_java_launcher() {
1759 assert(_sun_java_launcher != nullptr, "property must have value");
1760 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1761 }
1762
1763 bool Arguments::executing_unit_tests() {
1764 return _executing_unit_tests;
1765 }
1766
1767 //===========================================================================================================
1768 // Parsing of main arguments
1769
1770 static unsigned int addreads_count = 0;
1771 static unsigned int addexports_count = 0;
1772 static unsigned int addopens_count = 0;
1773 static unsigned int patch_mod_count = 0;
1774 static unsigned int enable_native_access_count = 0;
1775 static bool patch_mod_javabase = false;
1776
1777 // Check the consistency of vm_init_args
1778 bool Arguments::check_vm_args_consistency() {
1779 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1780 if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) {
1781 return false;
1782 }
1783
1784 // Method for adding checks for flag consistency.
1785 // The intent is to warn the user of all possible conflicts,
1786 // before returning an error.
1787 // Note: Needs platform-dependent factoring.
1788 bool status = true;
1789
1790 if (TLABRefillWasteFraction == 0) {
1791 jio_fprintf(defaultStream::error_stream(),
1792 "TLABRefillWasteFraction should be a denominator, "
1793 "not %zu\n",
1794 TLABRefillWasteFraction);
1795 status = false;
1796 }
1797
1798 status = CompilerConfig::check_args_consistency(status);
1799 #if INCLUDE_JVMCI
1800 if (status && EnableJVMCI) {
2059 return false;
2060 }
2061 #endif
2062
2063 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2064 // --patch-module=<module>=<file>(<pathsep><file>)*
2065 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2066 // Find the equal sign between the module name and the path specification
2067 const char* module_equal = strchr(patch_mod_tail, '=');
2068 if (module_equal == nullptr) {
2069 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2070 return JNI_ERR;
2071 } else {
2072 // Pick out the module name
2073 size_t module_len = module_equal - patch_mod_tail;
2074 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2075 if (module_name != nullptr) {
2076 memcpy(module_name, patch_mod_tail, module_len);
2077 *(module_name + module_len) = '\0';
2078 // The path piece begins one past the module_equal sign
2079 add_patch_mod_prefix(module_name, module_equal + 1);
2080 FREE_C_HEAP_ARRAY(char, module_name);
2081 if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
2082 return JNI_ENOMEM;
2083 }
2084 } else {
2085 return JNI_ENOMEM;
2086 }
2087 }
2088 return JNI_OK;
2089 }
2090
2091 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2092 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2093 // The min and max sizes match the values in globals.hpp, but scaled
2094 // with K. The values have been chosen so that alignment with page
2095 // size doesn't change the max value, which makes the conversions
2096 // back and forth between Xss value and ThreadStackSize value easier.
2097 // The values have also been chosen to fit inside a 32-bit signed type.
2098 const julong min_ThreadStackSize = 0;
2099 const julong max_ThreadStackSize = 1 * M;
2100
2101 // Make sure the above values match the range set in globals.hpp
2102 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2103 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2104 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2105
2106 const julong min_size = min_ThreadStackSize * K;
2107 const julong max_size = max_ThreadStackSize * K;
2108
2109 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2110
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 }
2805 // Unknown option
2806 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2807 return JNI_ERR;
2808 }
2809 }
2810
2811 // PrintSharedArchiveAndExit will turn on
2812 // -Xshare:on
2813 // -Xlog:class+path=info
2814 if (PrintSharedArchiveAndExit) {
2815 UseSharedSpaces = true;
2816 RequireSharedSpaces = true;
2817 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2818 }
2819
2820 fix_appclasspath();
2821
2822 return JNI_OK;
2823 }
2824
2825 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path) {
2826 // For java.base check for duplicate --patch-module options being specified on the command line.
2827 // This check is only required for java.base, all other duplicate module specifications
2828 // will be checked during module system initialization. The module system initialization
2829 // will throw an ExceptionInInitializerError if this situation occurs.
2830 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2831 if (patch_mod_javabase) {
2832 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2833 } else {
2834 patch_mod_javabase = true;
2835 }
2836 }
2837
2838 // Create GrowableArray lazily, only if --patch-module has been specified
2839 if (_patch_mod_prefix == nullptr) {
2840 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2841 }
2842
2843 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2844 }
2845
2846 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2847 //
2848 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2849 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2850 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2851 // path is treated as the current directory.
2852 //
2853 // This causes problems with CDS, which requires that all directories specified in the classpath
2854 // must be empty. In most cases, applications do NOT want to load classes from the current
2855 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2856 // scripts compatible with CDS.
2857 void Arguments::fix_appclasspath() {
2858 if (IgnoreEmptyClassPaths) {
2859 const char separator = *os::path_separator();
2860 const char* src = _java_class_path->value();
2861
2862 // skip over all the leading empty paths
2863 while (*src == separator) {
2936 }
2937
2938 #if !COMPILER2_OR_JVMCI
2939 // Don't degrade server performance for footprint
2940 if (FLAG_IS_DEFAULT(UseLargePages) &&
2941 MaxHeapSize < LargePageHeapSizeThreshold) {
2942 // No need for large granularity pages w/small heaps.
2943 // Note that large pages are enabled/disabled for both the
2944 // Java heap and the code cache.
2945 FLAG_SET_DEFAULT(UseLargePages, false);
2946 }
2947
2948 UNSUPPORTED_OPTION(ProfileInterpreter);
2949 #endif
2950
2951 // Parse the CompilationMode flag
2952 if (!CompilationModeFlag::initialize()) {
2953 return JNI_ERR;
2954 }
2955
2956 if (!check_vm_args_consistency()) {
2957 return JNI_ERR;
2958 }
2959
2960
2961 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
2962 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
2963 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2964
2965 return JNI_OK;
2966 }
2967
2968 // Helper class for controlling the lifetime of JavaVMInitArgs
2969 // objects. The contents of the JavaVMInitArgs are guaranteed to be
2970 // deleted on the destruction of the ScopedVMInitArgs object.
2971 class ScopedVMInitArgs : public StackObj {
2972 private:
2973 JavaVMInitArgs _args;
2974 char* _container_name;
2975 bool _is_set;
2976 char* _vm_options_file_arg;
2977
2978 public:
2979 ScopedVMInitArgs(const char *container_name) {
3741 #ifdef ZERO
3742 // Clear flags not supported on zero.
3743 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3744 #endif // ZERO
3745
3746 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3747 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3748 DebugNonSafepoints = true;
3749 }
3750
3751 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3752 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3753 }
3754
3755 // Treat the odd case where local verification is enabled but remote
3756 // verification is not as if both were enabled.
3757 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3758 log_info(verification)("Turning on remote verification because local verification is on");
3759 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3760 }
3761
3762 #ifndef PRODUCT
3763 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3764 if (use_vm_log()) {
3765 LogVMOutput = true;
3766 }
3767 }
3768 #endif // PRODUCT
3769
3770 if (PrintCommandLineFlags) {
3771 JVMFlag::printSetFlags(tty);
3772 }
3773
3774 #if COMPILER2_OR_JVMCI
3775 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3776 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3777 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3778 }
3779 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3780
|
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::_executing_unit_tests = false;
96
97 // These parameters are reset in method parse_vm_init_args()
1754 os::free(const_cast<char*>(_sun_java_launcher));
1755 }
1756 _sun_java_launcher = os::strdup_check_oom(launcher);
1757 }
1758
1759 bool Arguments::created_by_java_launcher() {
1760 assert(_sun_java_launcher != nullptr, "property must have value");
1761 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1762 }
1763
1764 bool Arguments::executing_unit_tests() {
1765 return _executing_unit_tests;
1766 }
1767
1768 //===========================================================================================================
1769 // Parsing of main arguments
1770
1771 static unsigned int addreads_count = 0;
1772 static unsigned int addexports_count = 0;
1773 static unsigned int addopens_count = 0;
1774 static unsigned int enable_native_access_count = 0;
1775 static bool patch_mod_javabase = false;
1776
1777 // Check the consistency of vm_init_args
1778 bool Arguments::check_vm_args_consistency() {
1779 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1780 if (!CDSConfig::check_vm_args_consistency(mode_flag_cmd_line)) {
1781 return false;
1782 }
1783
1784 // Method for adding checks for flag consistency.
1785 // The intent is to warn the user of all possible conflicts,
1786 // before returning an error.
1787 // Note: Needs platform-dependent factoring.
1788 bool status = true;
1789
1790 if (TLABRefillWasteFraction == 0) {
1791 jio_fprintf(defaultStream::error_stream(),
1792 "TLABRefillWasteFraction should be a denominator, "
1793 "not %zu\n",
1794 TLABRefillWasteFraction);
1795 status = false;
1796 }
1797
1798 status = CompilerConfig::check_args_consistency(status);
1799 #if INCLUDE_JVMCI
1800 if (status && EnableJVMCI) {
2059 return false;
2060 }
2061 #endif
2062
2063 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2064 // --patch-module=<module>=<file>(<pathsep><file>)*
2065 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2066 // Find the equal sign between the module name and the path specification
2067 const char* module_equal = strchr(patch_mod_tail, '=');
2068 if (module_equal == nullptr) {
2069 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2070 return JNI_ERR;
2071 } else {
2072 // Pick out the module name
2073 size_t module_len = module_equal - patch_mod_tail;
2074 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2075 if (module_name != nullptr) {
2076 memcpy(module_name, patch_mod_tail, module_len);
2077 *(module_name + module_len) = '\0';
2078 // The path piece begins one past the module_equal sign
2079 add_patch_mod_prefix(module_name, module_equal + 1, false /* no append */, false /* no cds */);
2080 FREE_C_HEAP_ARRAY(char, module_name);
2081 } else {
2082 return JNI_ENOMEM;
2083 }
2084 }
2085 return JNI_OK;
2086 }
2087
2088 // VALUECLASS_STR must match string used in the build
2089 #define VALUECLASS_STR "valueclasses"
2090 #define VALUECLASS_JAR "-" VALUECLASS_STR ".jar"
2091
2092 // Finalize --patch-module args and --enable-preview related to value class module patches.
2093 // Create all numbered properties passing module patches.
2094 int Arguments::finalize_patch_module() {
2095 // If --enable-preview and EnableValhalla is true, each module may have value classes that
2096 // are to be patched into the module.
2097 // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2098 // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2099 if (enable_preview() && EnableValhalla) {
2100 char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2101 const char * fileSep = os::file_separator();
2102
2103 jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s",
2104 Arguments::get_java_home(), fileSep, fileSep, fileSep);
2105 DIR* dir = os::opendir(valueclasses_dir);
2106 if (dir != nullptr) {
2107 char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2108 char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2109
2110 for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) {
2111 // Test if file ends-with "-valueclasses.jar"
2112 int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1);
2113 if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) {
2114 continue; // too short or not the expected suffix
2115 }
2116
2117 strcpy(module_name, entry->d_name);
2118 module_name[len] = '\0'; // truncate to just module-name
2119
2120 jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name);
2121 add_patch_mod_prefix(module_name, path, true /* append */, true /* cds OK*/);
2122 log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name);
2123 }
2124 FreeHeap(module_name);
2125 FreeHeap(path);
2126 os::closedir(dir);
2127 }
2128 FreeHeap(valueclasses_dir);
2129 }
2130
2131 // Create numbered properties for each module that has been patched either
2132 // by --patch-module or --enable-preview
2133 // Format is "jdk.module.patch.<n>=<module_name>=<path>"
2134 if (_patch_mod_prefix != nullptr) {
2135 char * prop_value = AllocateHeap(JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, mtArguments);
2136 unsigned int patch_mod_count = 0;
2137
2138 for (GrowableArrayIterator<ModulePatchPath *> it = _patch_mod_prefix->begin();
2139 it != _patch_mod_prefix->end(); ++it) {
2140 jio_snprintf(prop_value, JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, "%s=%s",
2141 (*it)->module_name(), (*it)->path_string());
2142 if (!create_numbered_module_property("jdk.module.patch", prop_value, patch_mod_count++)) {
2143 FreeHeap(prop_value);
2144 return JNI_ENOMEM;
2145 }
2146 }
2147 FreeHeap(prop_value);
2148 }
2149 return JNI_OK;
2150 }
2151
2152 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2153 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2154 // The min and max sizes match the values in globals.hpp, but scaled
2155 // with K. The values have been chosen so that alignment with page
2156 // size doesn't change the max value, which makes the conversions
2157 // back and forth between Xss value and ThreadStackSize value easier.
2158 // The values have also been chosen to fit inside a 32-bit signed type.
2159 const julong min_ThreadStackSize = 0;
2160 const julong max_ThreadStackSize = 1 * M;
2161
2162 // Make sure the above values match the range set in globals.hpp
2163 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2164 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2165 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2166
2167 const julong min_size = min_ThreadStackSize * K;
2168 const julong max_size = max_ThreadStackSize * K;
2169
2170 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2171
2387 jio_fprintf(defaultStream::error_stream(),
2388 "Instrumentation agents are not supported in this VM\n");
2389 return JNI_ERR;
2390 #else
2391 if (tail != nullptr) {
2392 size_t length = strlen(tail) + 1;
2393 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2394 jio_snprintf(options, length, "%s", tail);
2395 JvmtiAgentList::add("instrument", options, false);
2396 FREE_C_HEAP_ARRAY(char, options);
2397
2398 // java agents need module java.instrument
2399 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2400 return JNI_ENOMEM;
2401 }
2402 }
2403 #endif // !INCLUDE_JVMTI
2404 // --enable_preview
2405 } else if (match_option(option, "--enable-preview")) {
2406 set_enable_preview();
2407 // --enable-preview enables Valhalla, EnableValhalla VM option will eventually be removed before integration
2408 if (FLAG_SET_CMDLINE(EnableValhalla, true) != JVMFlag::SUCCESS) {
2409 return JNI_EINVAL;
2410 }
2411 // -Xnoclassgc
2412 } else if (match_option(option, "-Xnoclassgc")) {
2413 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2414 return JNI_EINVAL;
2415 }
2416 // -Xbatch
2417 } else if (match_option(option, "-Xbatch")) {
2418 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2419 return JNI_EINVAL;
2420 }
2421 // -Xmn for compatibility with other JVM vendors
2422 } else if (match_option(option, "-Xmn", &tail)) {
2423 julong long_initial_young_size = 0;
2424 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2425 if (errcode != arg_in_range) {
2426 jio_fprintf(defaultStream::error_stream(),
2427 "Invalid initial young generation size: %s\n", option->optionString);
2428 describe_range_error(errcode);
2429 return JNI_EINVAL;
2430 }
2870 // Unknown option
2871 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2872 return JNI_ERR;
2873 }
2874 }
2875
2876 // PrintSharedArchiveAndExit will turn on
2877 // -Xshare:on
2878 // -Xlog:class+path=info
2879 if (PrintSharedArchiveAndExit) {
2880 UseSharedSpaces = true;
2881 RequireSharedSpaces = true;
2882 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2883 }
2884
2885 fix_appclasspath();
2886
2887 return JNI_OK;
2888 }
2889
2890 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) {
2891 if (!allow_cds) {
2892 CDSConfig::set_module_patching_disables_cds();
2893 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2894 CDSConfig::set_java_base_module_patching_disables_cds();
2895 }
2896 }
2897
2898 // Create GrowableArray lazily, only if --patch-module has been specified
2899 if (_patch_mod_prefix == nullptr) {
2900 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2901 }
2902
2903 // Scan patches for matching module
2904 int i = _patch_mod_prefix->find_if([&](ModulePatchPath* patch) {
2905 return (strcmp(module_name, patch->module_name()) == 0);
2906 });
2907 if (i == -1) {
2908 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2909 } else {
2910 if (allow_append) {
2911 // append path to existing module entry
2912 _patch_mod_prefix->at(i)->append_path(path);
2913 } else {
2914 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2915 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2916 } else {
2917 vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
2918 }
2919 }
2920 }
2921 }
2922
2923 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2924 //
2925 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2926 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2927 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2928 // path is treated as the current directory.
2929 //
2930 // This causes problems with CDS, which requires that all directories specified in the classpath
2931 // must be empty. In most cases, applications do NOT want to load classes from the current
2932 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2933 // scripts compatible with CDS.
2934 void Arguments::fix_appclasspath() {
2935 if (IgnoreEmptyClassPaths) {
2936 const char separator = *os::path_separator();
2937 const char* src = _java_class_path->value();
2938
2939 // skip over all the leading empty paths
2940 while (*src == separator) {
3013 }
3014
3015 #if !COMPILER2_OR_JVMCI
3016 // Don't degrade server performance for footprint
3017 if (FLAG_IS_DEFAULT(UseLargePages) &&
3018 MaxHeapSize < LargePageHeapSizeThreshold) {
3019 // No need for large granularity pages w/small heaps.
3020 // Note that large pages are enabled/disabled for both the
3021 // Java heap and the code cache.
3022 FLAG_SET_DEFAULT(UseLargePages, false);
3023 }
3024
3025 UNSUPPORTED_OPTION(ProfileInterpreter);
3026 #endif
3027
3028 // Parse the CompilationMode flag
3029 if (!CompilationModeFlag::initialize()) {
3030 return JNI_ERR;
3031 }
3032
3033 // finalize --module-patch and related --enable-preview
3034 if (finalize_patch_module() != JNI_OK) {
3035 return JNI_ERR;
3036 }
3037
3038 if (!check_vm_args_consistency()) {
3039 return JNI_ERR;
3040 }
3041
3042 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3043 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3044 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3045
3046 return JNI_OK;
3047 }
3048
3049 // Helper class for controlling the lifetime of JavaVMInitArgs
3050 // objects. The contents of the JavaVMInitArgs are guaranteed to be
3051 // deleted on the destruction of the ScopedVMInitArgs object.
3052 class ScopedVMInitArgs : public StackObj {
3053 private:
3054 JavaVMInitArgs _args;
3055 char* _container_name;
3056 bool _is_set;
3057 char* _vm_options_file_arg;
3058
3059 public:
3060 ScopedVMInitArgs(const char *container_name) {
3822 #ifdef ZERO
3823 // Clear flags not supported on zero.
3824 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3825 #endif // ZERO
3826
3827 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3828 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3829 DebugNonSafepoints = true;
3830 }
3831
3832 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3833 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3834 }
3835
3836 // Treat the odd case where local verification is enabled but remote
3837 // verification is not as if both were enabled.
3838 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3839 log_info(verification)("Turning on remote verification because local verification is on");
3840 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3841 }
3842 if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) {
3843 // Disable calling convention optimizations if inline types are not supported.
3844 // Also these aren't useful in -Xint. However, don't disable them when dumping or using
3845 // the CDS archive, as the values must match between dumptime and runtime.
3846 FLAG_SET_DEFAULT(InlineTypePassFieldsAsArgs, false);
3847 FLAG_SET_DEFAULT(InlineTypeReturnedAsFields, false);
3848 }
3849 if (!UseNonAtomicValueFlattening && !UseNullableValueFlattening && !UseAtomicValueFlattening) {
3850 // Flattening is disabled
3851 FLAG_SET_DEFAULT(UseArrayFlattening, false);
3852 FLAG_SET_DEFAULT(UseFieldFlattening, false);
3853 }
3854
3855 #ifndef PRODUCT
3856 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3857 if (use_vm_log()) {
3858 LogVMOutput = true;
3859 }
3860 }
3861 #endif // PRODUCT
3862
3863 if (PrintCommandLineFlags) {
3864 JVMFlag::printSetFlags(tty);
3865 }
3866
3867 #if COMPILER2_OR_JVMCI
3868 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3869 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3870 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3871 }
3872 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3873
|