59 #include "runtime/os.hpp"
60 #include "runtime/safepoint.hpp"
61 #include "runtime/safepointMechanism.hpp"
62 #include "runtime/synchronizer.hpp"
63 #include "runtime/vm_version.hpp"
64 #include "services/management.hpp"
65 #include "utilities/align.hpp"
66 #include "utilities/checkedCast.hpp"
67 #include "utilities/debug.hpp"
68 #include "utilities/defaultStream.hpp"
69 #include "utilities/macros.hpp"
70 #include "utilities/parseInteger.hpp"
71 #include "utilities/powerOfTwo.hpp"
72 #include "utilities/stringUtils.hpp"
73 #include "utilities/systemMemoryBarrier.hpp"
74 #if INCLUDE_JFR
75 #include "jfr/jfr.hpp"
76 #endif
77
78 #include <limits>
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 // Process java launcher properties.
367 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
368 // See if sun.java.launcher is defined.
369 // Must do this before setting up other system properties,
370 // as some of them may depend on launcher type.
371 for (int index = 0; index < args->nOptions; index++) {
372 const JavaVMOption* option = args->options + index;
373 const char* tail;
374
375 if (match_option(option, "-Dsun.java.launcher=", &tail)) {
376 process_java_launcher_argument(tail, option->extraInfo);
377 continue;
378 }
379 if (match_option(option, "-XX:+ExecutingUnitTests")) {
380 _executing_unit_tests = true;
381 continue;
382 }
383 }
384 }
385
1799 os::free(const_cast<char*>(_sun_java_launcher));
1800 }
1801 _sun_java_launcher = os::strdup_check_oom(launcher);
1802 }
1803
1804 bool Arguments::created_by_java_launcher() {
1805 assert(_sun_java_launcher != nullptr, "property must have value");
1806 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1807 }
1808
1809 bool Arguments::executing_unit_tests() {
1810 return _executing_unit_tests;
1811 }
1812
1813 //===========================================================================================================
1814 // Parsing of main arguments
1815
1816 static unsigned int addreads_count = 0;
1817 static unsigned int addexports_count = 0;
1818 static unsigned int addopens_count = 0;
1819 static unsigned int patch_mod_count = 0;
1820 static unsigned int enable_native_access_count = 0;
1821 static bool patch_mod_javabase = false;
1822
1823 // Check the consistency of vm_init_args
1824 bool Arguments::check_vm_args_consistency() {
1825 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1826 if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) {
1827 return false;
1828 }
1829
1830 // Method for adding checks for flag consistency.
1831 // The intent is to warn the user of all possible conflicts,
1832 // before returning an error.
1833 // Note: Needs platform-dependent factoring.
1834 bool status = true;
1835
1836 if (TLABRefillWasteFraction == 0) {
1837 jio_fprintf(defaultStream::error_stream(),
1838 "TLABRefillWasteFraction should be a denominator, "
1839 "not %zu\n",
1840 TLABRefillWasteFraction);
1841 status = false;
1842 }
1843
1844 status = CompilerConfig::check_args_consistency(status);
1845 #if INCLUDE_JVMCI
1846 if (status && EnableJVMCI) {
2055 return false;
2056 }
2057 #endif
2058
2059 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2060 // --patch-module=<module>=<file>(<pathsep><file>)*
2061 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2062 // Find the equal sign between the module name and the path specification
2063 const char* module_equal = strchr(patch_mod_tail, '=');
2064 if (module_equal == nullptr) {
2065 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2066 return JNI_ERR;
2067 } else {
2068 // Pick out the module name
2069 size_t module_len = module_equal - patch_mod_tail;
2070 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2071 if (module_name != nullptr) {
2072 memcpy(module_name, patch_mod_tail, module_len);
2073 *(module_name + module_len) = '\0';
2074 // The path piece begins one past the module_equal sign
2075 add_patch_mod_prefix(module_name, module_equal + 1);
2076 FREE_C_HEAP_ARRAY(char, module_name);
2077 if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
2078 return JNI_ENOMEM;
2079 }
2080 } else {
2081 return JNI_ENOMEM;
2082 }
2083 }
2084 return JNI_OK;
2085 }
2086
2087 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2088 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2089 // The min and max sizes match the values in globals.hpp, but scaled
2090 // with K. The values have been chosen so that alignment with page
2091 // size doesn't change the max value, which makes the conversions
2092 // back and forth between Xss value and ThreadStackSize value easier.
2093 // The values have also been chosen to fit inside a 32-bit signed type.
2094 const julong min_ThreadStackSize = 0;
2095 const julong max_ThreadStackSize = 1 * M;
2096
2097 // Make sure the above values match the range set in globals.hpp
2098 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2099 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2100 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2101
2102 const julong min_size = min_ThreadStackSize * K;
2103 const julong max_size = max_ThreadStackSize * K;
2104
2105 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2106
2335 jio_fprintf(defaultStream::error_stream(),
2336 "Instrumentation agents are not supported in this VM\n");
2337 return JNI_ERR;
2338 #else
2339 if (tail != nullptr) {
2340 size_t length = strlen(tail) + 1;
2341 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2342 jio_snprintf(options, length, "%s", tail);
2343 JvmtiAgentList::add("instrument", options, false);
2344 FREE_C_HEAP_ARRAY(char, options);
2345
2346 // java agents need module java.instrument
2347 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2348 return JNI_ENOMEM;
2349 }
2350 }
2351 #endif // !INCLUDE_JVMTI
2352 // --enable_preview
2353 } else if (match_option(option, "--enable-preview")) {
2354 set_enable_preview();
2355 // -Xnoclassgc
2356 } else if (match_option(option, "-Xnoclassgc")) {
2357 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2358 return JNI_EINVAL;
2359 }
2360 // -Xbatch
2361 } else if (match_option(option, "-Xbatch")) {
2362 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2363 return JNI_EINVAL;
2364 }
2365 // -Xmn for compatibility with other JVM vendors
2366 } else if (match_option(option, "-Xmn", &tail)) {
2367 julong long_initial_young_size = 0;
2368 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2369 if (errcode != arg_in_range) {
2370 jio_fprintf(defaultStream::error_stream(),
2371 "Invalid initial young generation size: %s\n", option->optionString);
2372 describe_range_error(errcode);
2373 return JNI_EINVAL;
2374 }
2838 // Unknown option
2839 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2840 return JNI_ERR;
2841 }
2842 }
2843
2844 // PrintSharedArchiveAndExit will turn on
2845 // -Xshare:on
2846 // -Xlog:class+path=info
2847 if (PrintSharedArchiveAndExit) {
2848 UseSharedSpaces = true;
2849 RequireSharedSpaces = true;
2850 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2851 }
2852
2853 fix_appclasspath();
2854
2855 return JNI_OK;
2856 }
2857
2858 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path) {
2859 // For java.base check for duplicate --patch-module options being specified on the command line.
2860 // This check is only required for java.base, all other duplicate module specifications
2861 // will be checked during module system initialization. The module system initialization
2862 // will throw an ExceptionInInitializerError if this situation occurs.
2863 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2864 if (patch_mod_javabase) {
2865 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2866 } else {
2867 patch_mod_javabase = true;
2868 }
2869 }
2870
2871 // Create GrowableArray lazily, only if --patch-module has been specified
2872 if (_patch_mod_prefix == nullptr) {
2873 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2874 }
2875
2876 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2877 }
2878
2879 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2880 //
2881 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2882 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2883 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2884 // path is treated as the current directory.
2885 //
2886 // This causes problems with CDS, which requires that all directories specified in the classpath
2887 // must be empty. In most cases, applications do NOT want to load classes from the current
2888 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2889 // scripts compatible with CDS.
2890 void Arguments::fix_appclasspath() {
2891 if (IgnoreEmptyClassPaths) {
2892 const char separator = *os::path_separator();
2893 const char* src = _java_class_path->value();
2894
2895 // skip over all the leading empty paths
2896 while (*src == separator) {
2969 }
2970
2971 #if !COMPILER2_OR_JVMCI
2972 // Don't degrade server performance for footprint
2973 if (FLAG_IS_DEFAULT(UseLargePages) &&
2974 MaxHeapSize < LargePageHeapSizeThreshold) {
2975 // No need for large granularity pages w/small heaps.
2976 // Note that large pages are enabled/disabled for both the
2977 // Java heap and the code cache.
2978 FLAG_SET_DEFAULT(UseLargePages, false);
2979 }
2980
2981 UNSUPPORTED_OPTION(ProfileInterpreter);
2982 #endif
2983
2984 // Parse the CompilationMode flag
2985 if (!CompilationModeFlag::initialize()) {
2986 return JNI_ERR;
2987 }
2988
2989 if (!check_vm_args_consistency()) {
2990 return JNI_ERR;
2991 }
2992
2993
2994 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
2995 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
2996 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2997
2998 return JNI_OK;
2999 }
3000
3001 // Helper class for controlling the lifetime of JavaVMInitArgs
3002 // objects. The contents of the JavaVMInitArgs are guaranteed to be
3003 // deleted on the destruction of the ScopedVMInitArgs object.
3004 class ScopedVMInitArgs : public StackObj {
3005 private:
3006 JavaVMInitArgs _args;
3007 char* _container_name;
3008 bool _is_set;
3009 char* _vm_options_file_arg;
3010
3011 public:
3012 ScopedVMInitArgs(const char *container_name) {
3858 #ifdef ZERO
3859 // Clear flags not supported on zero.
3860 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3861 #endif // ZERO
3862
3863 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3864 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3865 DebugNonSafepoints = true;
3866 }
3867
3868 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3869 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3870 }
3871
3872 // Treat the odd case where local verification is enabled but remote
3873 // verification is not as if both were enabled.
3874 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3875 log_info(verification)("Turning on remote verification because local verification is on");
3876 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3877 }
3878
3879 #ifndef PRODUCT
3880 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3881 if (use_vm_log()) {
3882 LogVMOutput = true;
3883 }
3884 }
3885 #endif // PRODUCT
3886
3887 if (PrintCommandLineFlags) {
3888 JVMFlag::printSetFlags(tty);
3889 }
3890
3891 #if COMPILER2_OR_JVMCI
3892 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3893 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3894 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3895 }
3896 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3897
|
59 #include "runtime/os.hpp"
60 #include "runtime/safepoint.hpp"
61 #include "runtime/safepointMechanism.hpp"
62 #include "runtime/synchronizer.hpp"
63 #include "runtime/vm_version.hpp"
64 #include "services/management.hpp"
65 #include "utilities/align.hpp"
66 #include "utilities/checkedCast.hpp"
67 #include "utilities/debug.hpp"
68 #include "utilities/defaultStream.hpp"
69 #include "utilities/macros.hpp"
70 #include "utilities/parseInteger.hpp"
71 #include "utilities/powerOfTwo.hpp"
72 #include "utilities/stringUtils.hpp"
73 #include "utilities/systemMemoryBarrier.hpp"
74 #if INCLUDE_JFR
75 #include "jfr/jfr.hpp"
76 #endif
77
78 #include <limits>
79 #include <string.h>
80
81 static const char _default_java_launcher[] = "generic";
82
83 #define DEFAULT_JAVA_LAUNCHER _default_java_launcher
84
85 char* Arguments::_jvm_flags_file = nullptr;
86 char** Arguments::_jvm_flags_array = nullptr;
87 int Arguments::_num_jvm_flags = 0;
88 char** Arguments::_jvm_args_array = nullptr;
89 int Arguments::_num_jvm_args = 0;
90 unsigned int Arguments::_addmods_count = 0;
91 #if INCLUDE_JVMCI
92 bool Arguments::_jvmci_module_added = false;
93 #endif
94 char* Arguments::_java_command = nullptr;
95 SystemProperty* Arguments::_system_properties = nullptr;
96 size_t Arguments::_conservative_max_heap_alignment = 0;
97 Arguments::Mode Arguments::_mode = _mixed;
98 const char* Arguments::_java_vendor_url_bug = nullptr;
99 const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
347 matches_property_suffix(property_suffix, UPGRADE_PATH, UPGRADE_PATH_LEN) ||
348 matches_property_suffix(property_suffix, ILLEGAL_NATIVE_ACCESS, ILLEGAL_NATIVE_ACCESS_LEN)) {
349 return true;
350 }
351
352 if (!check_for_cds) {
353 // CDS notes: these properties are supported by CDS archived full module graph.
354 if (matches_property_suffix(property_suffix, ADDEXPORTS, ADDEXPORTS_LEN) ||
355 matches_property_suffix(property_suffix, ADDOPENS, ADDOPENS_LEN) ||
356 matches_property_suffix(property_suffix, ADDREADS, ADDREADS_LEN) ||
357 matches_property_suffix(property_suffix, PATH, PATH_LEN) ||
358 matches_property_suffix(property_suffix, ADDMODS, ADDMODS_LEN) ||
359 matches_property_suffix(property_suffix, ENABLE_NATIVE_ACCESS, ENABLE_NATIVE_ACCESS_LEN)) {
360 return true;
361 }
362 }
363 }
364 return false;
365 }
366
367 bool Arguments::patching_migrated_classes(const char* property, const char* value) {
368 if (strncmp(property, MODULE_PROPERTY_PREFIX, MODULE_PROPERTY_PREFIX_LEN) == 0) {
369 const char* property_suffix = property + MODULE_PROPERTY_PREFIX_LEN;
370 if (matches_property_suffix(property_suffix, PATCH, PATCH_LEN)) {
371 if (strcmp(value, "java.base-valueclasses.jar")) {
372 return true;
373 }
374 }
375 }
376 return false;
377 }
378
379 // Process java launcher properties.
380 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
381 // See if sun.java.launcher is defined.
382 // Must do this before setting up other system properties,
383 // as some of them may depend on launcher type.
384 for (int index = 0; index < args->nOptions; index++) {
385 const JavaVMOption* option = args->options + index;
386 const char* tail;
387
388 if (match_option(option, "-Dsun.java.launcher=", &tail)) {
389 process_java_launcher_argument(tail, option->extraInfo);
390 continue;
391 }
392 if (match_option(option, "-XX:+ExecutingUnitTests")) {
393 _executing_unit_tests = true;
394 continue;
395 }
396 }
397 }
398
1812 os::free(const_cast<char*>(_sun_java_launcher));
1813 }
1814 _sun_java_launcher = os::strdup_check_oom(launcher);
1815 }
1816
1817 bool Arguments::created_by_java_launcher() {
1818 assert(_sun_java_launcher != nullptr, "property must have value");
1819 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1820 }
1821
1822 bool Arguments::executing_unit_tests() {
1823 return _executing_unit_tests;
1824 }
1825
1826 //===========================================================================================================
1827 // Parsing of main arguments
1828
1829 static unsigned int addreads_count = 0;
1830 static unsigned int addexports_count = 0;
1831 static unsigned int addopens_count = 0;
1832 static unsigned int enable_native_access_count = 0;
1833 static bool patch_mod_javabase = false;
1834
1835 // Check the consistency of vm_init_args
1836 bool Arguments::check_vm_args_consistency() {
1837 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1838 if (!CDSConfig::check_vm_args_consistency(mode_flag_cmd_line)) {
1839 return false;
1840 }
1841
1842 // Method for adding checks for flag consistency.
1843 // The intent is to warn the user of all possible conflicts,
1844 // before returning an error.
1845 // Note: Needs platform-dependent factoring.
1846 bool status = true;
1847
1848 if (TLABRefillWasteFraction == 0) {
1849 jio_fprintf(defaultStream::error_stream(),
1850 "TLABRefillWasteFraction should be a denominator, "
1851 "not %zu\n",
1852 TLABRefillWasteFraction);
1853 status = false;
1854 }
1855
1856 status = CompilerConfig::check_args_consistency(status);
1857 #if INCLUDE_JVMCI
1858 if (status && EnableJVMCI) {
2067 return false;
2068 }
2069 #endif
2070
2071 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2072 // --patch-module=<module>=<file>(<pathsep><file>)*
2073 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2074 // Find the equal sign between the module name and the path specification
2075 const char* module_equal = strchr(patch_mod_tail, '=');
2076 if (module_equal == nullptr) {
2077 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2078 return JNI_ERR;
2079 } else {
2080 // Pick out the module name
2081 size_t module_len = module_equal - patch_mod_tail;
2082 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2083 if (module_name != nullptr) {
2084 memcpy(module_name, patch_mod_tail, module_len);
2085 *(module_name + module_len) = '\0';
2086 // The path piece begins one past the module_equal sign
2087 add_patch_mod_prefix(module_name, module_equal + 1, false /* no append */, false /* no cds */);
2088 FREE_C_HEAP_ARRAY(char, module_name);
2089 } else {
2090 return JNI_ENOMEM;
2091 }
2092 }
2093 return JNI_OK;
2094 }
2095
2096 // Temporary system property to disable preview patching and enable the new preview mode
2097 // feature for testing/development. Once the preview mode feature is finished, the value
2098 // will be always 'true' and this code, and all related dead-code can be removed.
2099 #define DISABLE_PREVIEW_PATCHING_DEFAULT false
2100
2101 bool Arguments::disable_preview_patching() {
2102 const char* prop = get_property("DISABLE_PREVIEW_PATCHING");
2103 return (prop != nullptr)
2104 ? strncmp(prop, "true", strlen("true")) == 0
2105 : DISABLE_PREVIEW_PATCHING_DEFAULT;
2106 }
2107
2108 // VALUECLASS_STR must match string used in the build
2109 #define VALUECLASS_STR "valueclasses"
2110 #define VALUECLASS_JAR "-" VALUECLASS_STR ".jar"
2111
2112 // Finalize --patch-module args and --enable-preview related to value class module patches.
2113 // Create all numbered properties passing module patches.
2114 int Arguments::finalize_patch_module() {
2115 // If --enable-preview and EnableValhalla is true, modules may have preview mode resources.
2116 bool enable_valhalla_preview = enable_preview() && EnableValhalla;
2117 // Whether to use module patching, or the new preview mode feature for preview resources.
2118 bool disable_patching = disable_preview_patching();
2119
2120 // This must be called, even with 'false', to enable resource lookup from JImage.
2121 ClassLoader::init_jimage(disable_patching && enable_valhalla_preview);
2122
2123 // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2124 // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2125 if (!disable_patching && enable_valhalla_preview) {
2126 char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2127 const char * fileSep = os::file_separator();
2128
2129 jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s",
2130 Arguments::get_java_home(), fileSep, fileSep, fileSep);
2131 DIR* dir = os::opendir(valueclasses_dir);
2132 if (dir != nullptr) {
2133 char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2134 char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2135
2136 for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) {
2137 // Test if file ends-with "-valueclasses.jar"
2138 int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1);
2139 if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) {
2140 continue; // too short or not the expected suffix
2141 }
2142
2143 strcpy(module_name, entry->d_name);
2144 module_name[len] = '\0'; // truncate to just module-name
2145
2146 jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name);
2147 add_patch_mod_prefix(module_name, path, true /* append */, true /* cds OK*/);
2148 log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name);
2149 }
2150 FreeHeap(module_name);
2151 FreeHeap(path);
2152 os::closedir(dir);
2153 }
2154 FreeHeap(valueclasses_dir);
2155 }
2156
2157 // Create numbered properties for each module that has been patched either
2158 // by --patch-module (or --enable-preview if disable_patching is false).
2159 // Format is "jdk.module.patch.<n>=<module_name>=<path>"
2160 if (_patch_mod_prefix != nullptr) {
2161 char * prop_value = AllocateHeap(JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, mtArguments);
2162 unsigned int patch_mod_count = 0;
2163
2164 for (GrowableArrayIterator<ModulePatchPath *> it = _patch_mod_prefix->begin();
2165 it != _patch_mod_prefix->end(); ++it) {
2166 jio_snprintf(prop_value, JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, "%s=%s",
2167 (*it)->module_name(), (*it)->path_string());
2168 if (!create_numbered_module_property("jdk.module.patch", prop_value, patch_mod_count++)) {
2169 FreeHeap(prop_value);
2170 return JNI_ENOMEM;
2171 }
2172 }
2173 FreeHeap(prop_value);
2174 }
2175 return JNI_OK;
2176 }
2177
2178 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2179 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2180 // The min and max sizes match the values in globals.hpp, but scaled
2181 // with K. The values have been chosen so that alignment with page
2182 // size doesn't change the max value, which makes the conversions
2183 // back and forth between Xss value and ThreadStackSize value easier.
2184 // The values have also been chosen to fit inside a 32-bit signed type.
2185 const julong min_ThreadStackSize = 0;
2186 const julong max_ThreadStackSize = 1 * M;
2187
2188 // Make sure the above values match the range set in globals.hpp
2189 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2190 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2191 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2192
2193 const julong min_size = min_ThreadStackSize * K;
2194 const julong max_size = max_ThreadStackSize * K;
2195
2196 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2197
2426 jio_fprintf(defaultStream::error_stream(),
2427 "Instrumentation agents are not supported in this VM\n");
2428 return JNI_ERR;
2429 #else
2430 if (tail != nullptr) {
2431 size_t length = strlen(tail) + 1;
2432 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2433 jio_snprintf(options, length, "%s", tail);
2434 JvmtiAgentList::add("instrument", options, false);
2435 FREE_C_HEAP_ARRAY(char, options);
2436
2437 // java agents need module java.instrument
2438 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2439 return JNI_ENOMEM;
2440 }
2441 }
2442 #endif // !INCLUDE_JVMTI
2443 // --enable_preview
2444 } else if (match_option(option, "--enable-preview")) {
2445 set_enable_preview();
2446 // --enable-preview enables Valhalla, EnableValhalla VM option will eventually be removed before integration
2447 if (FLAG_SET_CMDLINE(EnableValhalla, true) != JVMFlag::SUCCESS) {
2448 return JNI_EINVAL;
2449 }
2450 // -Xnoclassgc
2451 } else if (match_option(option, "-Xnoclassgc")) {
2452 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2453 return JNI_EINVAL;
2454 }
2455 // -Xbatch
2456 } else if (match_option(option, "-Xbatch")) {
2457 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2458 return JNI_EINVAL;
2459 }
2460 // -Xmn for compatibility with other JVM vendors
2461 } else if (match_option(option, "-Xmn", &tail)) {
2462 julong long_initial_young_size = 0;
2463 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2464 if (errcode != arg_in_range) {
2465 jio_fprintf(defaultStream::error_stream(),
2466 "Invalid initial young generation size: %s\n", option->optionString);
2467 describe_range_error(errcode);
2468 return JNI_EINVAL;
2469 }
2933 // Unknown option
2934 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2935 return JNI_ERR;
2936 }
2937 }
2938
2939 // PrintSharedArchiveAndExit will turn on
2940 // -Xshare:on
2941 // -Xlog:class+path=info
2942 if (PrintSharedArchiveAndExit) {
2943 UseSharedSpaces = true;
2944 RequireSharedSpaces = true;
2945 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2946 }
2947
2948 fix_appclasspath();
2949
2950 return JNI_OK;
2951 }
2952
2953 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) {
2954 if (!allow_cds) {
2955 CDSConfig::set_module_patching_disables_cds();
2956 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2957 CDSConfig::set_java_base_module_patching_disables_cds();
2958 }
2959 }
2960
2961 // Create GrowableArray lazily, only if --patch-module has been specified
2962 if (_patch_mod_prefix == nullptr) {
2963 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2964 }
2965
2966 // Scan patches for matching module
2967 int i = _patch_mod_prefix->find_if([&](ModulePatchPath* patch) {
2968 return (strcmp(module_name, patch->module_name()) == 0);
2969 });
2970 if (i == -1) {
2971 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2972 } else {
2973 if (allow_append) {
2974 // append path to existing module entry
2975 _patch_mod_prefix->at(i)->append_path(path);
2976 } else {
2977 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2978 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2979 } else {
2980 vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
2981 }
2982 }
2983 }
2984 }
2985
2986 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2987 //
2988 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2989 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2990 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2991 // path is treated as the current directory.
2992 //
2993 // This causes problems with CDS, which requires that all directories specified in the classpath
2994 // must be empty. In most cases, applications do NOT want to load classes from the current
2995 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2996 // scripts compatible with CDS.
2997 void Arguments::fix_appclasspath() {
2998 if (IgnoreEmptyClassPaths) {
2999 const char separator = *os::path_separator();
3000 const char* src = _java_class_path->value();
3001
3002 // skip over all the leading empty paths
3003 while (*src == separator) {
3076 }
3077
3078 #if !COMPILER2_OR_JVMCI
3079 // Don't degrade server performance for footprint
3080 if (FLAG_IS_DEFAULT(UseLargePages) &&
3081 MaxHeapSize < LargePageHeapSizeThreshold) {
3082 // No need for large granularity pages w/small heaps.
3083 // Note that large pages are enabled/disabled for both the
3084 // Java heap and the code cache.
3085 FLAG_SET_DEFAULT(UseLargePages, false);
3086 }
3087
3088 UNSUPPORTED_OPTION(ProfileInterpreter);
3089 #endif
3090
3091 // Parse the CompilationMode flag
3092 if (!CompilationModeFlag::initialize()) {
3093 return JNI_ERR;
3094 }
3095
3096 // finalize --module-patch and related --enable-preview
3097 if (finalize_patch_module() != JNI_OK) {
3098 return JNI_ERR;
3099 }
3100
3101 if (!check_vm_args_consistency()) {
3102 return JNI_ERR;
3103 }
3104
3105 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3106 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3107 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3108
3109 return JNI_OK;
3110 }
3111
3112 // Helper class for controlling the lifetime of JavaVMInitArgs
3113 // objects. The contents of the JavaVMInitArgs are guaranteed to be
3114 // deleted on the destruction of the ScopedVMInitArgs object.
3115 class ScopedVMInitArgs : public StackObj {
3116 private:
3117 JavaVMInitArgs _args;
3118 char* _container_name;
3119 bool _is_set;
3120 char* _vm_options_file_arg;
3121
3122 public:
3123 ScopedVMInitArgs(const char *container_name) {
3969 #ifdef ZERO
3970 // Clear flags not supported on zero.
3971 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3972 #endif // ZERO
3973
3974 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3975 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3976 DebugNonSafepoints = true;
3977 }
3978
3979 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3980 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3981 }
3982
3983 // Treat the odd case where local verification is enabled but remote
3984 // verification is not as if both were enabled.
3985 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3986 log_info(verification)("Turning on remote verification because local verification is on");
3987 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3988 }
3989 if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) {
3990 // Disable calling convention optimizations if inline types are not supported.
3991 // Also these aren't useful in -Xint. However, don't disable them when dumping or using
3992 // the CDS archive, as the values must match between dumptime and runtime.
3993 FLAG_SET_DEFAULT(InlineTypePassFieldsAsArgs, false);
3994 FLAG_SET_DEFAULT(InlineTypeReturnedAsFields, false);
3995 }
3996 if (!UseNonAtomicValueFlattening && !UseNullableValueFlattening && !UseAtomicValueFlattening) {
3997 // Flattening is disabled
3998 FLAG_SET_DEFAULT(UseArrayFlattening, false);
3999 FLAG_SET_DEFAULT(UseFieldFlattening, false);
4000 }
4001
4002 #ifndef PRODUCT
4003 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
4004 if (use_vm_log()) {
4005 LogVMOutput = true;
4006 }
4007 }
4008 #endif // PRODUCT
4009
4010 if (PrintCommandLineFlags) {
4011 JVMFlag::printSetFlags(tty);
4012 }
4013
4014 #if COMPILER2_OR_JVMCI
4015 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
4016 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
4017 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
4018 }
4019 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
4020
|