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;
345 matches_property_suffix(property_suffix, UPGRADE_PATH, UPGRADE_PATH_LEN) ||
346 matches_property_suffix(property_suffix, ILLEGAL_NATIVE_ACCESS, ILLEGAL_NATIVE_ACCESS_LEN)) {
347 return true;
348 }
349
350 if (!check_for_cds) {
351 // CDS notes: these properties are supported by CDS archived full module graph.
352 if (matches_property_suffix(property_suffix, ADDEXPORTS, ADDEXPORTS_LEN) ||
353 matches_property_suffix(property_suffix, ADDOPENS, ADDOPENS_LEN) ||
354 matches_property_suffix(property_suffix, ADDREADS, ADDREADS_LEN) ||
355 matches_property_suffix(property_suffix, PATH, PATH_LEN) ||
356 matches_property_suffix(property_suffix, ADDMODS, ADDMODS_LEN) ||
357 matches_property_suffix(property_suffix, ENABLE_NATIVE_ACCESS, ENABLE_NATIVE_ACCESS_LEN)) {
358 return true;
359 }
360 }
361 }
362 return false;
363 }
364
365 // Process java launcher properties.
366 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
367 // See if sun.java.launcher is defined.
368 // Must do this before setting up other system properties,
369 // as some of them may depend on launcher type.
370 for (int index = 0; index < args->nOptions; index++) {
371 const JavaVMOption* option = args->options + index;
372 const char* tail;
373
374 if (match_option(option, "-Dsun.java.launcher=", &tail)) {
375 process_java_launcher_argument(tail, option->extraInfo);
376 continue;
377 }
378 if (match_option(option, "-XX:+ExecutingUnitTests")) {
379 _executing_unit_tests = true;
380 continue;
381 }
382 }
383 }
384
1767 os::free(const_cast<char*>(_sun_java_launcher));
1768 }
1769 _sun_java_launcher = os::strdup_check_oom(launcher);
1770 }
1771
1772 bool Arguments::created_by_java_launcher() {
1773 assert(_sun_java_launcher != nullptr, "property must have value");
1774 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1775 }
1776
1777 bool Arguments::executing_unit_tests() {
1778 return _executing_unit_tests;
1779 }
1780
1781 //===========================================================================================================
1782 // Parsing of main arguments
1783
1784 static unsigned int addreads_count = 0;
1785 static unsigned int addexports_count = 0;
1786 static unsigned int addopens_count = 0;
1787 static unsigned int patch_mod_count = 0;
1788 static unsigned int enable_native_access_count = 0;
1789 static bool patch_mod_javabase = false;
1790
1791 // Check the consistency of vm_init_args
1792 bool Arguments::check_vm_args_consistency() {
1793 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1794 if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) {
1795 return false;
1796 }
1797
1798 // Method for adding checks for flag consistency.
1799 // The intent is to warn the user of all possible conflicts,
1800 // before returning an error.
1801 // Note: Needs platform-dependent factoring.
1802 bool status = true;
1803
1804 if (TLABRefillWasteFraction == 0) {
1805 jio_fprintf(defaultStream::error_stream(),
1806 "TLABRefillWasteFraction should be a denominator, "
1807 "not %zu\n",
1808 TLABRefillWasteFraction);
1809 status = false;
1810 }
1811
1812 status = CompilerConfig::check_args_consistency(status);
1813 #if INCLUDE_JVMCI
1814 if (status && EnableJVMCI) {
2041 return false;
2042 }
2043 #endif
2044
2045 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2046 // --patch-module=<module>=<file>(<pathsep><file>)*
2047 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2048 // Find the equal sign between the module name and the path specification
2049 const char* module_equal = strchr(patch_mod_tail, '=');
2050 if (module_equal == nullptr) {
2051 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2052 return JNI_ERR;
2053 } else {
2054 // Pick out the module name
2055 size_t module_len = module_equal - patch_mod_tail;
2056 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2057 if (module_name != nullptr) {
2058 memcpy(module_name, patch_mod_tail, module_len);
2059 *(module_name + module_len) = '\0';
2060 // The path piece begins one past the module_equal sign
2061 add_patch_mod_prefix(module_name, module_equal + 1);
2062 FREE_C_HEAP_ARRAY(char, module_name);
2063 if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
2064 return JNI_ENOMEM;
2065 }
2066 } else {
2067 return JNI_ENOMEM;
2068 }
2069 }
2070 return JNI_OK;
2071 }
2072
2073 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2074 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2075 // The min and max sizes match the values in globals.hpp, but scaled
2076 // with K. The values have been chosen so that alignment with page
2077 // size doesn't change the max value, which makes the conversions
2078 // back and forth between Xss value and ThreadStackSize value easier.
2079 // The values have also been chosen to fit inside a 32-bit signed type.
2080 const julong min_ThreadStackSize = 0;
2081 const julong max_ThreadStackSize = 1 * M;
2082
2083 // Make sure the above values match the range set in globals.hpp
2084 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2085 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2086 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2087
2088 const julong min_size = min_ThreadStackSize * K;
2089 const julong max_size = max_ThreadStackSize * K;
2090
2091 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2092
2321 jio_fprintf(defaultStream::error_stream(),
2322 "Instrumentation agents are not supported in this VM\n");
2323 return JNI_ERR;
2324 #else
2325 if (tail != nullptr) {
2326 size_t length = strlen(tail) + 1;
2327 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2328 jio_snprintf(options, length, "%s", tail);
2329 JvmtiAgentList::add("instrument", options, false);
2330 FREE_C_HEAP_ARRAY(char, options);
2331
2332 // java agents need module java.instrument
2333 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2334 return JNI_ENOMEM;
2335 }
2336 }
2337 #endif // !INCLUDE_JVMTI
2338 // --enable_preview
2339 } else if (match_option(option, "--enable-preview")) {
2340 set_enable_preview();
2341 // -Xnoclassgc
2342 } else if (match_option(option, "-Xnoclassgc")) {
2343 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2344 return JNI_EINVAL;
2345 }
2346 // -Xbatch
2347 } else if (match_option(option, "-Xbatch")) {
2348 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2349 return JNI_EINVAL;
2350 }
2351 // -Xmn for compatibility with other JVM vendors
2352 } else if (match_option(option, "-Xmn", &tail)) {
2353 julong long_initial_young_size = 0;
2354 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2355 if (errcode != arg_in_range) {
2356 jio_fprintf(defaultStream::error_stream(),
2357 "Invalid initial young generation size: %s\n", option->optionString);
2358 describe_range_error(errcode);
2359 return JNI_EINVAL;
2360 }
2800 // Unknown option
2801 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2802 return JNI_ERR;
2803 }
2804 }
2805
2806 // PrintSharedArchiveAndExit will turn on
2807 // -Xshare:on
2808 // -Xlog:class+path=info
2809 if (PrintSharedArchiveAndExit) {
2810 UseSharedSpaces = true;
2811 RequireSharedSpaces = true;
2812 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2813 }
2814
2815 fix_appclasspath();
2816
2817 return JNI_OK;
2818 }
2819
2820 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path) {
2821 // For java.base check for duplicate --patch-module options being specified on the command line.
2822 // This check is only required for java.base, all other duplicate module specifications
2823 // will be checked during module system initialization. The module system initialization
2824 // will throw an ExceptionInInitializerError if this situation occurs.
2825 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2826 if (patch_mod_javabase) {
2827 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2828 } else {
2829 patch_mod_javabase = true;
2830 }
2831 }
2832
2833 // Create GrowableArray lazily, only if --patch-module has been specified
2834 if (_patch_mod_prefix == nullptr) {
2835 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2836 }
2837
2838 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2839 }
2840
2841 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2842 //
2843 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2844 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2845 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2846 // path is treated as the current directory.
2847 //
2848 // This causes problems with CDS, which requires that all directories specified in the classpath
2849 // must be empty. In most cases, applications do NOT want to load classes from the current
2850 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2851 // scripts compatible with CDS.
2852 void Arguments::fix_appclasspath() {
2853 if (IgnoreEmptyClassPaths) {
2854 const char separator = *os::path_separator();
2855 const char* src = _java_class_path->value();
2856
2857 // skip over all the leading empty paths
2858 while (*src == separator) {
2931 }
2932
2933 #if !COMPILER2_OR_JVMCI
2934 // Don't degrade server performance for footprint
2935 if (FLAG_IS_DEFAULT(UseLargePages) &&
2936 MaxHeapSize < LargePageHeapSizeThreshold) {
2937 // No need for large granularity pages w/small heaps.
2938 // Note that large pages are enabled/disabled for both the
2939 // Java heap and the code cache.
2940 FLAG_SET_DEFAULT(UseLargePages, false);
2941 }
2942
2943 UNSUPPORTED_OPTION(ProfileInterpreter);
2944 #endif
2945
2946 // Parse the CompilationMode flag
2947 if (!CompilationModeFlag::initialize()) {
2948 return JNI_ERR;
2949 }
2950
2951 if (!check_vm_args_consistency()) {
2952 return JNI_ERR;
2953 }
2954
2955
2956 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
2957 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
2958 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2959
2960 return JNI_OK;
2961 }
2962
2963 // Helper class for controlling the lifetime of JavaVMInitArgs
2964 // objects. The contents of the JavaVMInitArgs are guaranteed to be
2965 // deleted on the destruction of the ScopedVMInitArgs object.
2966 class ScopedVMInitArgs : public StackObj {
2967 private:
2968 JavaVMInitArgs _args;
2969 char* _container_name;
2970 bool _is_set;
2971 char* _vm_options_file_arg;
2972
2973 public:
2974 ScopedVMInitArgs(const char *container_name) {
3820 #ifdef ZERO
3821 // Clear flags not supported on zero.
3822 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3823 #endif // ZERO
3824
3825 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3826 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3827 DebugNonSafepoints = true;
3828 }
3829
3830 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3831 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3832 }
3833
3834 // Treat the odd case where local verification is enabled but remote
3835 // verification is not as if both were enabled.
3836 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3837 log_info(verification)("Turning on remote verification because local verification is on");
3838 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3839 }
3840
3841 #ifndef PRODUCT
3842 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3843 if (use_vm_log()) {
3844 LogVMOutput = true;
3845 }
3846 }
3847 #endif // PRODUCT
3848
3849 if (PrintCommandLineFlags) {
3850 JVMFlag::printSetFlags(tty);
3851 }
3852
3853 #if COMPILER2_OR_JVMCI
3854 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3855 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3856 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3857 }
3858 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3859
|
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;
346 matches_property_suffix(property_suffix, UPGRADE_PATH, UPGRADE_PATH_LEN) ||
347 matches_property_suffix(property_suffix, ILLEGAL_NATIVE_ACCESS, ILLEGAL_NATIVE_ACCESS_LEN)) {
348 return true;
349 }
350
351 if (!check_for_cds) {
352 // CDS notes: these properties are supported by CDS archived full module graph.
353 if (matches_property_suffix(property_suffix, ADDEXPORTS, ADDEXPORTS_LEN) ||
354 matches_property_suffix(property_suffix, ADDOPENS, ADDOPENS_LEN) ||
355 matches_property_suffix(property_suffix, ADDREADS, ADDREADS_LEN) ||
356 matches_property_suffix(property_suffix, PATH, PATH_LEN) ||
357 matches_property_suffix(property_suffix, ADDMODS, ADDMODS_LEN) ||
358 matches_property_suffix(property_suffix, ENABLE_NATIVE_ACCESS, ENABLE_NATIVE_ACCESS_LEN)) {
359 return true;
360 }
361 }
362 }
363 return false;
364 }
365
366 bool Arguments::patching_migrated_classes(const char* property, const char* value) {
367 if (strncmp(property, MODULE_PROPERTY_PREFIX, MODULE_PROPERTY_PREFIX_LEN) == 0) {
368 const char* property_suffix = property + MODULE_PROPERTY_PREFIX_LEN;
369 if (matches_property_suffix(property_suffix, PATCH, PATCH_LEN)) {
370 if (strcmp(value, "java.base-valueclasses.jar")) {
371 return true;
372 }
373 }
374 }
375 return false;
376 }
377
378 // Process java launcher properties.
379 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
380 // See if sun.java.launcher is defined.
381 // Must do this before setting up other system properties,
382 // as some of them may depend on launcher type.
383 for (int index = 0; index < args->nOptions; index++) {
384 const JavaVMOption* option = args->options + index;
385 const char* tail;
386
387 if (match_option(option, "-Dsun.java.launcher=", &tail)) {
388 process_java_launcher_argument(tail, option->extraInfo);
389 continue;
390 }
391 if (match_option(option, "-XX:+ExecutingUnitTests")) {
392 _executing_unit_tests = true;
393 continue;
394 }
395 }
396 }
397
1780 os::free(const_cast<char*>(_sun_java_launcher));
1781 }
1782 _sun_java_launcher = os::strdup_check_oom(launcher);
1783 }
1784
1785 bool Arguments::created_by_java_launcher() {
1786 assert(_sun_java_launcher != nullptr, "property must have value");
1787 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1788 }
1789
1790 bool Arguments::executing_unit_tests() {
1791 return _executing_unit_tests;
1792 }
1793
1794 //===========================================================================================================
1795 // Parsing of main arguments
1796
1797 static unsigned int addreads_count = 0;
1798 static unsigned int addexports_count = 0;
1799 static unsigned int addopens_count = 0;
1800 static unsigned int enable_native_access_count = 0;
1801 static bool patch_mod_javabase = false;
1802
1803 // Check the consistency of vm_init_args
1804 bool Arguments::check_vm_args_consistency() {
1805 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1806 if (!CDSConfig::check_vm_args_consistency(mode_flag_cmd_line)) {
1807 return false;
1808 }
1809
1810 // Method for adding checks for flag consistency.
1811 // The intent is to warn the user of all possible conflicts,
1812 // before returning an error.
1813 // Note: Needs platform-dependent factoring.
1814 bool status = true;
1815
1816 if (TLABRefillWasteFraction == 0) {
1817 jio_fprintf(defaultStream::error_stream(),
1818 "TLABRefillWasteFraction should be a denominator, "
1819 "not %zu\n",
1820 TLABRefillWasteFraction);
1821 status = false;
1822 }
1823
1824 status = CompilerConfig::check_args_consistency(status);
1825 #if INCLUDE_JVMCI
1826 if (status && EnableJVMCI) {
2053 return false;
2054 }
2055 #endif
2056
2057 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2058 // --patch-module=<module>=<file>(<pathsep><file>)*
2059 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2060 // Find the equal sign between the module name and the path specification
2061 const char* module_equal = strchr(patch_mod_tail, '=');
2062 if (module_equal == nullptr) {
2063 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2064 return JNI_ERR;
2065 } else {
2066 // Pick out the module name
2067 size_t module_len = module_equal - patch_mod_tail;
2068 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2069 if (module_name != nullptr) {
2070 memcpy(module_name, patch_mod_tail, module_len);
2071 *(module_name + module_len) = '\0';
2072 // The path piece begins one past the module_equal sign
2073 add_patch_mod_prefix(module_name, module_equal + 1, false /* no append */, false /* no cds */);
2074 FREE_C_HEAP_ARRAY(char, module_name);
2075 } else {
2076 return JNI_ENOMEM;
2077 }
2078 }
2079 return JNI_OK;
2080 }
2081
2082 // VALUECLASS_STR must match string used in the build
2083 #define VALUECLASS_STR "valueclasses"
2084 #define VALUECLASS_JAR "-" VALUECLASS_STR ".jar"
2085
2086 // Finalize --patch-module args and --enable-preview related to value class module patches.
2087 // Create all numbered properties passing module patches.
2088 int Arguments::finalize_patch_module() {
2089 // If --enable-preview and EnableValhalla is true, each module may have value classes that
2090 // are to be patched into the module.
2091 // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2092 // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2093 if (enable_preview() && EnableValhalla) {
2094 char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2095 const char * fileSep = os::file_separator();
2096
2097 jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s",
2098 Arguments::get_java_home(), fileSep, fileSep, fileSep);
2099 DIR* dir = os::opendir(valueclasses_dir);
2100 if (dir != nullptr) {
2101 char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2102 char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2103
2104 for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) {
2105 // Test if file ends-with "-valueclasses.jar"
2106 int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1);
2107 if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) {
2108 continue; // too short or not the expected suffix
2109 }
2110
2111 strcpy(module_name, entry->d_name);
2112 module_name[len] = '\0'; // truncate to just module-name
2113
2114 jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name);
2115 add_patch_mod_prefix(module_name, path, true /* append */, true /* cds OK*/);
2116 log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name);
2117 }
2118 FreeHeap(module_name);
2119 FreeHeap(path);
2120 os::closedir(dir);
2121 }
2122 FreeHeap(valueclasses_dir);
2123 }
2124
2125 // Create numbered properties for each module that has been patched either
2126 // by --patch-module or --enable-preview
2127 // Format is "jdk.module.patch.<n>=<module_name>=<path>"
2128 if (_patch_mod_prefix != nullptr) {
2129 char * prop_value = AllocateHeap(JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, mtArguments);
2130 unsigned int patch_mod_count = 0;
2131
2132 for (GrowableArrayIterator<ModulePatchPath *> it = _patch_mod_prefix->begin();
2133 it != _patch_mod_prefix->end(); ++it) {
2134 jio_snprintf(prop_value, JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, "%s=%s",
2135 (*it)->module_name(), (*it)->path_string());
2136 if (!create_numbered_module_property("jdk.module.patch", prop_value, patch_mod_count++)) {
2137 FreeHeap(prop_value);
2138 return JNI_ENOMEM;
2139 }
2140 }
2141 FreeHeap(prop_value);
2142 }
2143 return JNI_OK;
2144 }
2145
2146 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2147 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2148 // The min and max sizes match the values in globals.hpp, but scaled
2149 // with K. The values have been chosen so that alignment with page
2150 // size doesn't change the max value, which makes the conversions
2151 // back and forth between Xss value and ThreadStackSize value easier.
2152 // The values have also been chosen to fit inside a 32-bit signed type.
2153 const julong min_ThreadStackSize = 0;
2154 const julong max_ThreadStackSize = 1 * M;
2155
2156 // Make sure the above values match the range set in globals.hpp
2157 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2158 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2159 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2160
2161 const julong min_size = min_ThreadStackSize * K;
2162 const julong max_size = max_ThreadStackSize * K;
2163
2164 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2165
2394 jio_fprintf(defaultStream::error_stream(),
2395 "Instrumentation agents are not supported in this VM\n");
2396 return JNI_ERR;
2397 #else
2398 if (tail != nullptr) {
2399 size_t length = strlen(tail) + 1;
2400 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2401 jio_snprintf(options, length, "%s", tail);
2402 JvmtiAgentList::add("instrument", options, false);
2403 FREE_C_HEAP_ARRAY(char, options);
2404
2405 // java agents need module java.instrument
2406 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2407 return JNI_ENOMEM;
2408 }
2409 }
2410 #endif // !INCLUDE_JVMTI
2411 // --enable_preview
2412 } else if (match_option(option, "--enable-preview")) {
2413 set_enable_preview();
2414 // --enable-preview enables Valhalla, EnableValhalla VM option will eventually be removed before integration
2415 if (FLAG_SET_CMDLINE(EnableValhalla, true) != JVMFlag::SUCCESS) {
2416 return JNI_EINVAL;
2417 }
2418 // -Xnoclassgc
2419 } else if (match_option(option, "-Xnoclassgc")) {
2420 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2421 return JNI_EINVAL;
2422 }
2423 // -Xbatch
2424 } else if (match_option(option, "-Xbatch")) {
2425 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2426 return JNI_EINVAL;
2427 }
2428 // -Xmn for compatibility with other JVM vendors
2429 } else if (match_option(option, "-Xmn", &tail)) {
2430 julong long_initial_young_size = 0;
2431 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2432 if (errcode != arg_in_range) {
2433 jio_fprintf(defaultStream::error_stream(),
2434 "Invalid initial young generation size: %s\n", option->optionString);
2435 describe_range_error(errcode);
2436 return JNI_EINVAL;
2437 }
2877 // Unknown option
2878 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2879 return JNI_ERR;
2880 }
2881 }
2882
2883 // PrintSharedArchiveAndExit will turn on
2884 // -Xshare:on
2885 // -Xlog:class+path=info
2886 if (PrintSharedArchiveAndExit) {
2887 UseSharedSpaces = true;
2888 RequireSharedSpaces = true;
2889 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2890 }
2891
2892 fix_appclasspath();
2893
2894 return JNI_OK;
2895 }
2896
2897 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) {
2898 if (!allow_cds) {
2899 CDSConfig::set_module_patching_disables_cds();
2900 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2901 CDSConfig::set_java_base_module_patching_disables_cds();
2902 }
2903 }
2904
2905 // Create GrowableArray lazily, only if --patch-module has been specified
2906 if (_patch_mod_prefix == nullptr) {
2907 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2908 }
2909
2910 // Scan patches for matching module
2911 int i = _patch_mod_prefix->find_if([&](ModulePatchPath* patch) {
2912 return (strcmp(module_name, patch->module_name()) == 0);
2913 });
2914 if (i == -1) {
2915 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2916 } else {
2917 if (allow_append) {
2918 // append path to existing module entry
2919 _patch_mod_prefix->at(i)->append_path(path);
2920 } else {
2921 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2922 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2923 } else {
2924 vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
2925 }
2926 }
2927 }
2928 }
2929
2930 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2931 //
2932 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2933 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2934 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2935 // path is treated as the current directory.
2936 //
2937 // This causes problems with CDS, which requires that all directories specified in the classpath
2938 // must be empty. In most cases, applications do NOT want to load classes from the current
2939 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2940 // scripts compatible with CDS.
2941 void Arguments::fix_appclasspath() {
2942 if (IgnoreEmptyClassPaths) {
2943 const char separator = *os::path_separator();
2944 const char* src = _java_class_path->value();
2945
2946 // skip over all the leading empty paths
2947 while (*src == separator) {
3020 }
3021
3022 #if !COMPILER2_OR_JVMCI
3023 // Don't degrade server performance for footprint
3024 if (FLAG_IS_DEFAULT(UseLargePages) &&
3025 MaxHeapSize < LargePageHeapSizeThreshold) {
3026 // No need for large granularity pages w/small heaps.
3027 // Note that large pages are enabled/disabled for both the
3028 // Java heap and the code cache.
3029 FLAG_SET_DEFAULT(UseLargePages, false);
3030 }
3031
3032 UNSUPPORTED_OPTION(ProfileInterpreter);
3033 #endif
3034
3035 // Parse the CompilationMode flag
3036 if (!CompilationModeFlag::initialize()) {
3037 return JNI_ERR;
3038 }
3039
3040 // finalize --module-patch and related --enable-preview
3041 if (finalize_patch_module() != JNI_OK) {
3042 return JNI_ERR;
3043 }
3044
3045 if (!check_vm_args_consistency()) {
3046 return JNI_ERR;
3047 }
3048
3049 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3050 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3051 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3052
3053 return JNI_OK;
3054 }
3055
3056 // Helper class for controlling the lifetime of JavaVMInitArgs
3057 // objects. The contents of the JavaVMInitArgs are guaranteed to be
3058 // deleted on the destruction of the ScopedVMInitArgs object.
3059 class ScopedVMInitArgs : public StackObj {
3060 private:
3061 JavaVMInitArgs _args;
3062 char* _container_name;
3063 bool _is_set;
3064 char* _vm_options_file_arg;
3065
3066 public:
3067 ScopedVMInitArgs(const char *container_name) {
3913 #ifdef ZERO
3914 // Clear flags not supported on zero.
3915 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3916 #endif // ZERO
3917
3918 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3919 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3920 DebugNonSafepoints = true;
3921 }
3922
3923 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3924 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3925 }
3926
3927 // Treat the odd case where local verification is enabled but remote
3928 // verification is not as if both were enabled.
3929 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3930 log_info(verification)("Turning on remote verification because local verification is on");
3931 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3932 }
3933 if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) {
3934 // Disable calling convention optimizations if inline types are not supported.
3935 // Also these aren't useful in -Xint. However, don't disable them when dumping or using
3936 // the CDS archive, as the values must match between dumptime and runtime.
3937 FLAG_SET_DEFAULT(InlineTypePassFieldsAsArgs, false);
3938 FLAG_SET_DEFAULT(InlineTypeReturnedAsFields, false);
3939 }
3940 if (!UseNonAtomicValueFlattening && !UseNullableValueFlattening && !UseAtomicValueFlattening) {
3941 // Flattening is disabled
3942 FLAG_SET_DEFAULT(UseArrayFlattening, false);
3943 FLAG_SET_DEFAULT(UseFieldFlattening, false);
3944 }
3945
3946 #ifndef PRODUCT
3947 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3948 if (use_vm_log()) {
3949 LogVMOutput = true;
3950 }
3951 }
3952 #endif // PRODUCT
3953
3954 if (PrintCommandLineFlags) {
3955 JVMFlag::printSetFlags(tty);
3956 }
3957
3958 #if COMPILER2_OR_JVMCI
3959 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3960 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3961 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3962 }
3963 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3964
|