59 #include "runtime/java.hpp"
60 #include "runtime/os.hpp"
61 #include "runtime/safepoint.hpp"
62 #include "runtime/safepointMechanism.hpp"
63 #include "runtime/synchronizer.hpp"
64 #include "runtime/vm_version.hpp"
65 #include "services/management.hpp"
66 #include "utilities/align.hpp"
67 #include "utilities/checkedCast.hpp"
68 #include "utilities/debug.hpp"
69 #include "utilities/defaultStream.hpp"
70 #include "utilities/macros.hpp"
71 #include "utilities/parseInteger.hpp"
72 #include "utilities/powerOfTwo.hpp"
73 #include "utilities/stringUtils.hpp"
74 #include "utilities/systemMemoryBarrier.hpp"
75 #if INCLUDE_JFR
76 #include "jfr/jfr.hpp"
77 #endif
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;
98 bool Arguments::_executing_unit_tests = false;
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
1787 os::free(const_cast<char*>(_sun_java_launcher));
1788 }
1789 _sun_java_launcher = os::strdup_check_oom(launcher);
1790 }
1791
1792 bool Arguments::created_by_java_launcher() {
1793 assert(_sun_java_launcher != nullptr, "property must have value");
1794 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1795 }
1796
1797 bool Arguments::executing_unit_tests() {
1798 return _executing_unit_tests;
1799 }
1800
1801 //===========================================================================================================
1802 // Parsing of main arguments
1803
1804 static unsigned int addreads_count = 0;
1805 static unsigned int addexports_count = 0;
1806 static unsigned int addopens_count = 0;
1807 static unsigned int patch_mod_count = 0;
1808 static unsigned int enable_native_access_count = 0;
1809 static bool patch_mod_javabase = false;
1810
1811 // Check the consistency of vm_init_args
1812 bool Arguments::check_vm_args_consistency() {
1813 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1814 if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) {
1815 return false;
1816 }
1817
1818 // Method for adding checks for flag consistency.
1819 // The intent is to warn the user of all possible conflicts,
1820 // before returning an error.
1821 // Note: Needs platform-dependent factoring.
1822 bool status = true;
1823
1824 if (TLABRefillWasteFraction == 0) {
1825 jio_fprintf(defaultStream::error_stream(),
1826 "TLABRefillWasteFraction should be a denominator, "
1827 "not %zu\n",
1828 TLABRefillWasteFraction);
1829 status = false;
1830 }
1831
1832 status = CompilerConfig::check_args_consistency(status);
1833 #if INCLUDE_JVMCI
1834 if (status && EnableJVMCI) {
1961
1962 // Remember the default value of SharedBaseAddress.
1963 Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1964
1965 // Setup flags for mixed which is the default
1966 set_mode_flags(_mixed);
1967
1968 jint result;
1969 for (int i = 0; i < all_args->length(); i++) {
1970 result = parse_each_vm_init_arg(all_args->at(i)._args, all_args->at(i)._origin);
1971 if (result != JNI_OK) {
1972 return result;
1973 }
1974 }
1975
1976 // Disable CDS for exploded image
1977 if (!has_jimage()) {
1978 no_shared_spaces("CDS disabled on exploded JDK");
1979 }
1980
1981 // We need to ensure processor and memory resources have been properly
1982 // configured - which may rely on arguments we just processed - before
1983 // doing the final argument processing. Any argument processing that
1984 // needs to know about processor and memory resources must occur after
1985 // this point.
1986
1987 os::init_container_support();
1988
1989 SystemMemoryBarrier::initialize();
1990
1991 // Do final processing now that all arguments have been parsed
1992 result = finalize_vm_init_args();
1993 if (result != JNI_OK) {
1994 return result;
1995 }
1996
1997 return JNI_OK;
1998 }
1999
2000 #if !INCLUDE_JVMTI || INCLUDE_CDS
2043 return false;
2044 }
2045 #endif
2046
2047 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2048 // --patch-module=<module>=<file>(<pathsep><file>)*
2049 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2050 // Find the equal sign between the module name and the path specification
2051 const char* module_equal = strchr(patch_mod_tail, '=');
2052 if (module_equal == nullptr) {
2053 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2054 return JNI_ERR;
2055 } else {
2056 // Pick out the module name
2057 size_t module_len = module_equal - patch_mod_tail;
2058 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2059 if (module_name != nullptr) {
2060 memcpy(module_name, patch_mod_tail, module_len);
2061 *(module_name + module_len) = '\0';
2062 // The path piece begins one past the module_equal sign
2063 add_patch_mod_prefix(module_name, module_equal + 1);
2064 FREE_C_HEAP_ARRAY(char, module_name);
2065 if (!create_numbered_module_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) {
2066 return JNI_ENOMEM;
2067 }
2068 } else {
2069 return JNI_ENOMEM;
2070 }
2071 }
2072 return JNI_OK;
2073 }
2074
2075 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2076 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2077 // The min and max sizes match the values in globals.hpp, but scaled
2078 // with K. The values have been chosen so that alignment with page
2079 // size doesn't change the max value, which makes the conversions
2080 // back and forth between Xss value and ThreadStackSize value easier.
2081 // The values have also been chosen to fit inside a 32-bit signed type.
2082 const julong min_ThreadStackSize = 0;
2083 const julong max_ThreadStackSize = 1 * M;
2084
2085 // Make sure the above values match the range set in globals.hpp
2086 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2087 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2088 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2089
2090 const julong min_size = min_ThreadStackSize * K;
2091 const julong max_size = max_ThreadStackSize * K;
2092
2093 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2094
2323 jio_fprintf(defaultStream::error_stream(),
2324 "Instrumentation agents are not supported in this VM\n");
2325 return JNI_ERR;
2326 #else
2327 if (tail != nullptr) {
2328 size_t length = strlen(tail) + 1;
2329 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2330 jio_snprintf(options, length, "%s", tail);
2331 JvmtiAgentList::add("instrument", options, false);
2332 FREE_C_HEAP_ARRAY(char, options);
2333
2334 // java agents need module java.instrument
2335 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2336 return JNI_ENOMEM;
2337 }
2338 }
2339 #endif // !INCLUDE_JVMTI
2340 // --enable_preview
2341 } else if (match_option(option, "--enable-preview")) {
2342 set_enable_preview();
2343 // -Xnoclassgc
2344 } else if (match_option(option, "-Xnoclassgc")) {
2345 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2346 return JNI_EINVAL;
2347 }
2348 // -Xbatch
2349 } else if (match_option(option, "-Xbatch")) {
2350 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2351 return JNI_EINVAL;
2352 }
2353 // -Xmn for compatibility with other JVM vendors
2354 } else if (match_option(option, "-Xmn", &tail)) {
2355 julong long_initial_young_size = 0;
2356 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2357 if (errcode != arg_in_range) {
2358 jio_fprintf(defaultStream::error_stream(),
2359 "Invalid initial young generation size: %s\n", option->optionString);
2360 describe_range_error(errcode);
2361 return JNI_EINVAL;
2362 }
2826 // Unknown option
2827 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2828 return JNI_ERR;
2829 }
2830 }
2831
2832 // PrintSharedArchiveAndExit will turn on
2833 // -Xshare:on
2834 // -Xlog:class+path=info
2835 if (PrintSharedArchiveAndExit) {
2836 UseSharedSpaces = true;
2837 RequireSharedSpaces = true;
2838 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2839 }
2840
2841 fix_appclasspath();
2842
2843 return JNI_OK;
2844 }
2845
2846 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path) {
2847 // For java.base check for duplicate --patch-module options being specified on the command line.
2848 // This check is only required for java.base, all other duplicate module specifications
2849 // will be checked during module system initialization. The module system initialization
2850 // will throw an ExceptionInInitializerError if this situation occurs.
2851 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2852 if (patch_mod_javabase) {
2853 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2854 } else {
2855 patch_mod_javabase = true;
2856 }
2857 }
2858
2859 // Create GrowableArray lazily, only if --patch-module has been specified
2860 if (_patch_mod_prefix == nullptr) {
2861 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2862 }
2863
2864 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2865 }
2866
2867 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2868 //
2869 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2870 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2871 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2872 // path is treated as the current directory.
2873 //
2874 // This causes problems with CDS, which requires that all directories specified in the classpath
2875 // must be empty. In most cases, applications do NOT want to load classes from the current
2876 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2877 // scripts compatible with CDS.
2878 void Arguments::fix_appclasspath() {
2879 if (IgnoreEmptyClassPaths) {
2880 const char separator = *os::path_separator();
2881 const char* src = _java_class_path->value();
2882
2883 // skip over all the leading empty paths
2884 while (*src == separator) {
2957 }
2958
2959 #if !COMPILER2_OR_JVMCI
2960 // Don't degrade server performance for footprint
2961 if (FLAG_IS_DEFAULT(UseLargePages) &&
2962 MaxHeapSize < LargePageHeapSizeThreshold) {
2963 // No need for large granularity pages w/small heaps.
2964 // Note that large pages are enabled/disabled for both the
2965 // Java heap and the code cache.
2966 FLAG_SET_DEFAULT(UseLargePages, false);
2967 }
2968
2969 UNSUPPORTED_OPTION(ProfileInterpreter);
2970 #endif
2971
2972 // Parse the CompilationMode flag
2973 if (!CompilationModeFlag::initialize()) {
2974 return JNI_ERR;
2975 }
2976
2977 if (!check_vm_args_consistency()) {
2978 return JNI_ERR;
2979 }
2980
2981
2982 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
2983 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
2984 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2985
2986 return JNI_OK;
2987 }
2988
2989 // Helper class for controlling the lifetime of JavaVMInitArgs
2990 // objects. The contents of the JavaVMInitArgs are guaranteed to be
2991 // deleted on the destruction of the ScopedVMInitArgs object.
2992 class ScopedVMInitArgs : public StackObj {
2993 private:
2994 JavaVMInitArgs _args;
2995 char* _container_name;
2996 bool _is_set;
2997 char* _vm_options_file_arg;
2998
2999 public:
3000 ScopedVMInitArgs(const char *container_name) {
3846 #ifdef ZERO
3847 // Clear flags not supported on zero.
3848 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3849 #endif // ZERO
3850
3851 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3852 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3853 DebugNonSafepoints = true;
3854 }
3855
3856 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3857 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3858 }
3859
3860 // Treat the odd case where local verification is enabled but remote
3861 // verification is not as if both were enabled.
3862 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3863 log_info(verification)("Turning on remote verification because local verification is on");
3864 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3865 }
3866
3867 #ifndef PRODUCT
3868 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3869 if (use_vm_log()) {
3870 LogVMOutput = true;
3871 }
3872 }
3873 #endif // PRODUCT
3874
3875 if (PrintCommandLineFlags) {
3876 JVMFlag::printSetFlags(tty);
3877 }
3878
3879 #if COMPILER2_OR_JVMCI
3880 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
3881 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
3882 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
3883 }
3884 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
3885
|
59 #include "runtime/java.hpp"
60 #include "runtime/os.hpp"
61 #include "runtime/safepoint.hpp"
62 #include "runtime/safepointMechanism.hpp"
63 #include "runtime/synchronizer.hpp"
64 #include "runtime/vm_version.hpp"
65 #include "services/management.hpp"
66 #include "utilities/align.hpp"
67 #include "utilities/checkedCast.hpp"
68 #include "utilities/debug.hpp"
69 #include "utilities/defaultStream.hpp"
70 #include "utilities/macros.hpp"
71 #include "utilities/parseInteger.hpp"
72 #include "utilities/powerOfTwo.hpp"
73 #include "utilities/stringUtils.hpp"
74 #include "utilities/systemMemoryBarrier.hpp"
75 #if INCLUDE_JFR
76 #include "jfr/jfr.hpp"
77 #endif
78
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;
100 bool Arguments::_executing_unit_tests = false;
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
1801 os::free(const_cast<char*>(_sun_java_launcher));
1802 }
1803 _sun_java_launcher = os::strdup_check_oom(launcher);
1804 }
1805
1806 bool Arguments::created_by_java_launcher() {
1807 assert(_sun_java_launcher != nullptr, "property must have value");
1808 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1809 }
1810
1811 bool Arguments::executing_unit_tests() {
1812 return _executing_unit_tests;
1813 }
1814
1815 //===========================================================================================================
1816 // Parsing of main arguments
1817
1818 static unsigned int addreads_count = 0;
1819 static unsigned int addexports_count = 0;
1820 static unsigned int addopens_count = 0;
1821 static unsigned int enable_native_access_count = 0;
1822 static bool patch_mod_javabase = false;
1823
1824 // Check the consistency of vm_init_args
1825 bool Arguments::check_vm_args_consistency() {
1826 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1827 if (!CDSConfig::check_vm_args_consistency(mode_flag_cmd_line)) {
1828 return false;
1829 }
1830
1831 // Method for adding checks for flag consistency.
1832 // The intent is to warn the user of all possible conflicts,
1833 // before returning an error.
1834 // Note: Needs platform-dependent factoring.
1835 bool status = true;
1836
1837 if (TLABRefillWasteFraction == 0) {
1838 jio_fprintf(defaultStream::error_stream(),
1839 "TLABRefillWasteFraction should be a denominator, "
1840 "not %zu\n",
1841 TLABRefillWasteFraction);
1842 status = false;
1843 }
1844
1845 status = CompilerConfig::check_args_consistency(status);
1846 #if INCLUDE_JVMCI
1847 if (status && EnableJVMCI) {
1974
1975 // Remember the default value of SharedBaseAddress.
1976 Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1977
1978 // Setup flags for mixed which is the default
1979 set_mode_flags(_mixed);
1980
1981 jint result;
1982 for (int i = 0; i < all_args->length(); i++) {
1983 result = parse_each_vm_init_arg(all_args->at(i)._args, all_args->at(i)._origin);
1984 if (result != JNI_OK) {
1985 return result;
1986 }
1987 }
1988
1989 // Disable CDS for exploded image
1990 if (!has_jimage()) {
1991 no_shared_spaces("CDS disabled on exploded JDK");
1992 }
1993
1994 if (UseAltSubstitutabilityMethod) {
1995 no_shared_spaces("Alternate substitutability method doesn't work with CDS yet");
1996 }
1997
1998 // We need to ensure processor and memory resources have been properly
1999 // configured - which may rely on arguments we just processed - before
2000 // doing the final argument processing. Any argument processing that
2001 // needs to know about processor and memory resources must occur after
2002 // this point.
2003
2004 os::init_container_support();
2005
2006 SystemMemoryBarrier::initialize();
2007
2008 // Do final processing now that all arguments have been parsed
2009 result = finalize_vm_init_args();
2010 if (result != JNI_OK) {
2011 return result;
2012 }
2013
2014 return JNI_OK;
2015 }
2016
2017 #if !INCLUDE_JVMTI || INCLUDE_CDS
2060 return false;
2061 }
2062 #endif
2063
2064 int Arguments::process_patch_mod_option(const char* patch_mod_tail) {
2065 // --patch-module=<module>=<file>(<pathsep><file>)*
2066 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value");
2067 // Find the equal sign between the module name and the path specification
2068 const char* module_equal = strchr(patch_mod_tail, '=');
2069 if (module_equal == nullptr) {
2070 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n");
2071 return JNI_ERR;
2072 } else {
2073 // Pick out the module name
2074 size_t module_len = module_equal - patch_mod_tail;
2075 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments);
2076 if (module_name != nullptr) {
2077 memcpy(module_name, patch_mod_tail, module_len);
2078 *(module_name + module_len) = '\0';
2079 // The path piece begins one past the module_equal sign
2080 add_patch_mod_prefix(module_name, module_equal + 1, false /* no append */, false /* no cds */);
2081 FREE_C_HEAP_ARRAY(char, module_name);
2082 } else {
2083 return JNI_ENOMEM;
2084 }
2085 }
2086 return JNI_OK;
2087 }
2088
2089 // Temporary system property to disable preview patching and enable the new preview mode
2090 // feature for testing/development. Once the preview mode feature is finished, the value
2091 // will be always 'true' and this code, and all related dead-code can be removed.
2092 #define DISABLE_PREVIEW_PATCHING_DEFAULT false
2093
2094 bool Arguments::disable_preview_patching() {
2095 const char* prop = get_property("DISABLE_PREVIEW_PATCHING");
2096 return (prop != nullptr)
2097 ? strncmp(prop, "true", strlen("true")) == 0
2098 : DISABLE_PREVIEW_PATCHING_DEFAULT;
2099 }
2100
2101 // VALUECLASS_STR must match string used in the build
2102 #define VALUECLASS_STR "valueclasses"
2103 #define VALUECLASS_JAR "-" VALUECLASS_STR ".jar"
2104
2105 // Finalize --patch-module args and --enable-preview related to value class module patches.
2106 // Create all numbered properties passing module patches.
2107 int Arguments::finalize_patch_module() {
2108 // If --enable-preview and EnableValhalla is true, modules may have preview mode resources.
2109 bool enable_valhalla_preview = enable_preview() && EnableValhalla;
2110 // Whether to use module patching, or the new preview mode feature for preview resources.
2111 bool disable_patching = disable_preview_patching();
2112
2113 // This must be called, even with 'false', to enable resource lookup from JImage.
2114 ClassLoader::init_jimage(disable_patching && enable_valhalla_preview);
2115
2116 // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/
2117 // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar
2118 if (!disable_patching && enable_valhalla_preview) {
2119 char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2120 const char * fileSep = os::file_separator();
2121
2122 jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s",
2123 Arguments::get_java_home(), fileSep, fileSep, fileSep);
2124 DIR* dir = os::opendir(valueclasses_dir);
2125 if (dir != nullptr) {
2126 char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2127 char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments);
2128
2129 for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) {
2130 // Test if file ends-with "-valueclasses.jar"
2131 int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1);
2132 if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) {
2133 continue; // too short or not the expected suffix
2134 }
2135
2136 strcpy(module_name, entry->d_name);
2137 module_name[len] = '\0'; // truncate to just module-name
2138
2139 jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name);
2140 add_patch_mod_prefix(module_name, path, true /* append */, true /* cds OK*/);
2141 log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name);
2142 }
2143 FreeHeap(module_name);
2144 FreeHeap(path);
2145 os::closedir(dir);
2146 }
2147 FreeHeap(valueclasses_dir);
2148 }
2149
2150 // Create numbered properties for each module that has been patched either
2151 // by --patch-module (or --enable-preview if disable_patching is false).
2152 // Format is "jdk.module.patch.<n>=<module_name>=<path>"
2153 if (_patch_mod_prefix != nullptr) {
2154 char * prop_value = AllocateHeap(JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, mtArguments);
2155 unsigned int patch_mod_count = 0;
2156
2157 for (GrowableArrayIterator<ModulePatchPath *> it = _patch_mod_prefix->begin();
2158 it != _patch_mod_prefix->end(); ++it) {
2159 jio_snprintf(prop_value, JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, "%s=%s",
2160 (*it)->module_name(), (*it)->path_string());
2161 if (!create_numbered_module_property("jdk.module.patch", prop_value, patch_mod_count++)) {
2162 FreeHeap(prop_value);
2163 return JNI_ENOMEM;
2164 }
2165 }
2166 FreeHeap(prop_value);
2167 }
2168 return JNI_OK;
2169 }
2170
2171 // Parse -Xss memory string parameter and convert to ThreadStackSize in K.
2172 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) {
2173 // The min and max sizes match the values in globals.hpp, but scaled
2174 // with K. The values have been chosen so that alignment with page
2175 // size doesn't change the max value, which makes the conversions
2176 // back and forth between Xss value and ThreadStackSize value easier.
2177 // The values have also been chosen to fit inside a 32-bit signed type.
2178 const julong min_ThreadStackSize = 0;
2179 const julong max_ThreadStackSize = 1 * M;
2180
2181 // Make sure the above values match the range set in globals.hpp
2182 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>();
2183 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be");
2184 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be");
2185
2186 const julong min_size = min_ThreadStackSize * K;
2187 const julong max_size = max_ThreadStackSize * K;
2188
2189 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption");
2190
2419 jio_fprintf(defaultStream::error_stream(),
2420 "Instrumentation agents are not supported in this VM\n");
2421 return JNI_ERR;
2422 #else
2423 if (tail != nullptr) {
2424 size_t length = strlen(tail) + 1;
2425 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments);
2426 jio_snprintf(options, length, "%s", tail);
2427 JvmtiAgentList::add("instrument", options, false);
2428 FREE_C_HEAP_ARRAY(char, options);
2429
2430 // java agents need module java.instrument
2431 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) {
2432 return JNI_ENOMEM;
2433 }
2434 }
2435 #endif // !INCLUDE_JVMTI
2436 // --enable_preview
2437 } else if (match_option(option, "--enable-preview")) {
2438 set_enable_preview();
2439 // --enable-preview enables Valhalla, EnableValhalla VM option will eventually be removed before integration
2440 if (FLAG_SET_CMDLINE(EnableValhalla, true) != JVMFlag::SUCCESS) {
2441 return JNI_EINVAL;
2442 }
2443 // -Xnoclassgc
2444 } else if (match_option(option, "-Xnoclassgc")) {
2445 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) {
2446 return JNI_EINVAL;
2447 }
2448 // -Xbatch
2449 } else if (match_option(option, "-Xbatch")) {
2450 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) {
2451 return JNI_EINVAL;
2452 }
2453 // -Xmn for compatibility with other JVM vendors
2454 } else if (match_option(option, "-Xmn", &tail)) {
2455 julong long_initial_young_size = 0;
2456 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1);
2457 if (errcode != arg_in_range) {
2458 jio_fprintf(defaultStream::error_stream(),
2459 "Invalid initial young generation size: %s\n", option->optionString);
2460 describe_range_error(errcode);
2461 return JNI_EINVAL;
2462 }
2926 // Unknown option
2927 } else if (is_bad_option(option, args->ignoreUnrecognized)) {
2928 return JNI_ERR;
2929 }
2930 }
2931
2932 // PrintSharedArchiveAndExit will turn on
2933 // -Xshare:on
2934 // -Xlog:class+path=info
2935 if (PrintSharedArchiveAndExit) {
2936 UseSharedSpaces = true;
2937 RequireSharedSpaces = true;
2938 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path));
2939 }
2940
2941 fix_appclasspath();
2942
2943 return JNI_OK;
2944 }
2945
2946 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) {
2947 if (!allow_cds) {
2948 CDSConfig::set_module_patching_disables_cds();
2949 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2950 CDSConfig::set_java_base_module_patching_disables_cds();
2951 }
2952 }
2953
2954 // Create GrowableArray lazily, only if --patch-module has been specified
2955 if (_patch_mod_prefix == nullptr) {
2956 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments);
2957 }
2958
2959 // Scan patches for matching module
2960 int i = _patch_mod_prefix->find_if([&](ModulePatchPath* patch) {
2961 return (strcmp(module_name, patch->module_name()) == 0);
2962 });
2963 if (i == -1) {
2964 _patch_mod_prefix->push(new ModulePatchPath(module_name, path));
2965 } else {
2966 if (allow_append) {
2967 // append path to existing module entry
2968 _patch_mod_prefix->at(i)->append_path(path);
2969 } else {
2970 if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
2971 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module");
2972 } else {
2973 vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name);
2974 }
2975 }
2976 }
2977 }
2978
2979 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
2980 //
2981 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
2982 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar".
2983 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty
2984 // path is treated as the current directory.
2985 //
2986 // This causes problems with CDS, which requires that all directories specified in the classpath
2987 // must be empty. In most cases, applications do NOT want to load classes from the current
2988 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up
2989 // scripts compatible with CDS.
2990 void Arguments::fix_appclasspath() {
2991 if (IgnoreEmptyClassPaths) {
2992 const char separator = *os::path_separator();
2993 const char* src = _java_class_path->value();
2994
2995 // skip over all the leading empty paths
2996 while (*src == separator) {
3069 }
3070
3071 #if !COMPILER2_OR_JVMCI
3072 // Don't degrade server performance for footprint
3073 if (FLAG_IS_DEFAULT(UseLargePages) &&
3074 MaxHeapSize < LargePageHeapSizeThreshold) {
3075 // No need for large granularity pages w/small heaps.
3076 // Note that large pages are enabled/disabled for both the
3077 // Java heap and the code cache.
3078 FLAG_SET_DEFAULT(UseLargePages, false);
3079 }
3080
3081 UNSUPPORTED_OPTION(ProfileInterpreter);
3082 #endif
3083
3084 // Parse the CompilationMode flag
3085 if (!CompilationModeFlag::initialize()) {
3086 return JNI_ERR;
3087 }
3088
3089 // finalize --module-patch and related --enable-preview
3090 if (finalize_patch_module() != JNI_OK) {
3091 return JNI_ERR;
3092 }
3093
3094 if (!check_vm_args_consistency()) {
3095 return JNI_ERR;
3096 }
3097
3098 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
3099 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
3100 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
3101
3102 return JNI_OK;
3103 }
3104
3105 // Helper class for controlling the lifetime of JavaVMInitArgs
3106 // objects. The contents of the JavaVMInitArgs are guaranteed to be
3107 // deleted on the destruction of the ScopedVMInitArgs object.
3108 class ScopedVMInitArgs : public StackObj {
3109 private:
3110 JavaVMInitArgs _args;
3111 char* _container_name;
3112 bool _is_set;
3113 char* _vm_options_file_arg;
3114
3115 public:
3116 ScopedVMInitArgs(const char *container_name) {
3962 #ifdef ZERO
3963 // Clear flags not supported on zero.
3964 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3965 #endif // ZERO
3966
3967 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3968 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3969 DebugNonSafepoints = true;
3970 }
3971
3972 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3973 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3974 }
3975
3976 // Treat the odd case where local verification is enabled but remote
3977 // verification is not as if both were enabled.
3978 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) {
3979 log_info(verification)("Turning on remote verification because local verification is on");
3980 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true);
3981 }
3982 if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) {
3983 // Disable calling convention optimizations if inline types are not supported.
3984 // Also these aren't useful in -Xint. However, don't disable them when dumping or using
3985 // the CDS archive, as the values must match between dumptime and runtime.
3986 FLAG_SET_DEFAULT(InlineTypePassFieldsAsArgs, false);
3987 FLAG_SET_DEFAULT(InlineTypeReturnedAsFields, false);
3988 }
3989 if (!UseNonAtomicValueFlattening && !UseNullableValueFlattening && !UseAtomicValueFlattening) {
3990 // Flattening is disabled
3991 FLAG_SET_DEFAULT(UseArrayFlattening, false);
3992 FLAG_SET_DEFAULT(UseFieldFlattening, false);
3993 }
3994
3995 #ifndef PRODUCT
3996 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
3997 if (use_vm_log()) {
3998 LogVMOutput = true;
3999 }
4000 }
4001 #endif // PRODUCT
4002
4003 if (PrintCommandLineFlags) {
4004 JVMFlag::printSetFlags(tty);
4005 }
4006
4007 #if COMPILER2_OR_JVMCI
4008 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) {
4009 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) {
4010 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off.");
4011 }
4012 FLAG_SET_DEFAULT(EnableVectorReboxing, false);
4013
|