1763 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1764 }
1765
1766 bool Arguments::sun_java_launcher_is_altjvm() {
1767 return _sun_java_launcher_is_altjvm;
1768 }
1769
1770 //===========================================================================================================
1771 // Parsing of main arguments
1772
1773 static unsigned int addreads_count = 0;
1774 static unsigned int addexports_count = 0;
1775 static unsigned int addopens_count = 0;
1776 static unsigned int patch_mod_count = 0;
1777 static unsigned int enable_native_access_count = 0;
1778 static bool patch_mod_javabase = false;
1779
1780 // Check the consistency of vm_init_args
1781 bool Arguments::check_vm_args_consistency() {
1782 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1783 if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line)) {
1784 return false;
1785 }
1786
1787 // Method for adding checks for flag consistency.
1788 // The intent is to warn the user of all possible conflicts,
1789 // before returning an error.
1790 // Note: Needs platform-dependent factoring.
1791 bool status = true;
1792
1793 if (TLABRefillWasteFraction == 0) {
1794 jio_fprintf(defaultStream::error_stream(),
1795 "TLABRefillWasteFraction should be a denominator, "
1796 "not %zu\n",
1797 TLABRefillWasteFraction);
1798 status = false;
1799 }
1800
1801 status = CompilerConfig::check_args_consistency(status);
1802 #if INCLUDE_JVMCI
1803 if (status && EnableJVMCI) {
1931 jio_fprintf(defaultStream::error_stream(), "Failed to create property %s.%d=%s\n", prop_base_name, count, prop_value);
1932 return false;
1933 }
1934 bool added = add_property(property, UnwriteableProperty, InternalProperty);
1935 FreeHeap(property);
1936 return added;
1937 }
1938
1939 jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
1940 return false;
1941 }
1942
1943 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
1944 julong* long_arg,
1945 julong min_size,
1946 julong max_size) {
1947 if (!parse_integer(s, long_arg)) return arg_unreadable;
1948 return check_memory_size(*long_arg, min_size, max_size);
1949 }
1950
1951 // Parse JavaVMInitArgs structure
1952
1953 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
1954 const JavaVMInitArgs *java_tool_options_args,
1955 const JavaVMInitArgs *java_options_args,
1956 const JavaVMInitArgs *cmd_line_args) {
1957 // Save default settings for some mode flags
1958 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
1959 Arguments::_UseOnStackReplacement = UseOnStackReplacement;
1960 Arguments::_ClipInlining = ClipInlining;
1961 Arguments::_BackgroundCompilation = BackgroundCompilation;
1962
1963 // Remember the default value of SharedBaseAddress.
1964 Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1965
1966 // Setup flags for mixed which is the default
1967 set_mode_flags(_mixed);
1968
1969 // Parse args structure generated from java.base vm options resource
1970 jint result = parse_each_vm_init_arg(vm_options_args, JVMFlagOrigin::JIMAGE_RESOURCE);
1971 if (result != JNI_OK) {
1972 return result;
1973 }
1974
1975 // Parse args structure generated from JAVA_TOOL_OPTIONS environment
1976 // variable (if present).
1977 result = parse_each_vm_init_arg(java_tool_options_args, JVMFlagOrigin::ENVIRON_VAR);
1978 if (result != JNI_OK) {
1979 return result;
1980 }
1981
1982 // Parse args structure generated from the command line flags.
1983 result = parse_each_vm_init_arg(cmd_line_args, JVMFlagOrigin::COMMAND_LINE);
1984 if (result != JNI_OK) {
1985 return result;
1986 }
1987
1988 // Parse args structure generated from the _JAVA_OPTIONS environment
1989 // variable (if present) (mimics classic VM)
1990 result = parse_each_vm_init_arg(java_options_args, JVMFlagOrigin::ENVIRON_VAR);
1991 if (result != JNI_OK) {
1992 return result;
1993 }
1994
1995 // Disable CDS for exploded image
1996 if (!has_jimage()) {
1997 no_shared_spaces("CDS disabled on exploded JDK");
1998 }
1999
2000 // We need to ensure processor and memory resources have been properly
2001 // configured - which may rely on arguments we just processed - before
2002 // doing the final argument processing. Any argument processing that
2003 // needs to know about processor and memory resources must occur after
2004 // this point.
2005
2006 os::init_container_support();
2007
2008 SystemMemoryBarrier::initialize();
2009
2010 // Do final processing now that all arguments have been parsed
2011 result = finalize_vm_init_args();
2012 if (result != JNI_OK) {
2013 return result;
2014 }
2943 if (FLAG_IS_DEFAULT(UseLargePages) &&
2944 MaxHeapSize < LargePageHeapSizeThreshold) {
2945 // No need for large granularity pages w/small heaps.
2946 // Note that large pages are enabled/disabled for both the
2947 // Java heap and the code cache.
2948 FLAG_SET_DEFAULT(UseLargePages, false);
2949 }
2950
2951 UNSUPPORTED_OPTION(ProfileInterpreter);
2952 #endif
2953
2954 // Parse the CompilationMode flag
2955 if (!CompilationModeFlag::initialize()) {
2956 return JNI_ERR;
2957 }
2958
2959 if (!check_vm_args_consistency()) {
2960 return JNI_ERR;
2961 }
2962
2963
2964 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
2965 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
2966 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2967
2968 return JNI_OK;
2969 }
2970
2971 // Helper class for controlling the lifetime of JavaVMInitArgs
2972 // objects. The contents of the JavaVMInitArgs are guaranteed to be
2973 // deleted on the destruction of the ScopedVMInitArgs object.
2974 class ScopedVMInitArgs : public StackObj {
2975 private:
2976 JavaVMInitArgs _args;
2977 char* _container_name;
2978 bool _is_set;
2979 char* _vm_options_file_arg;
2980
2981 public:
2982 ScopedVMInitArgs(const char *container_name) {
3061 for (int j = 0; j < args_to_insert->nOptions; j++) {
3062 options.push(args_to_insert->options[j]);
3063 }
3064 } else {
3065 options.push(args->options[i]);
3066 }
3067 }
3068 // make into options array
3069 return set_args(&options);
3070 }
3071 };
3072
3073 jint Arguments::parse_java_options_environment_variable(ScopedVMInitArgs* args) {
3074 return parse_options_environment_variable("_JAVA_OPTIONS", args);
3075 }
3076
3077 jint Arguments::parse_java_tool_options_environment_variable(ScopedVMInitArgs* args) {
3078 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", args);
3079 }
3080
3081 jint Arguments::parse_options_environment_variable(const char* name,
3082 ScopedVMInitArgs* vm_args) {
3083 char *buffer = ::getenv(name);
3084
3085 // Don't check this environment variable if user has special privileges
3086 // (e.g. unix su command).
3087 if (buffer == nullptr || os::have_special_privileges()) {
3088 return JNI_OK;
3089 }
3090
3091 if ((buffer = os::strdup(buffer)) == nullptr) {
3092 return JNI_ENOMEM;
3093 }
3094
3095 jio_fprintf(defaultStream::error_stream(),
3096 "Picked up %s: %s\n", name, buffer);
3097
3098 int retcode = parse_options_buffer(name, buffer, strlen(buffer), vm_args);
3099
3100 os::free(buffer);
3439 FLAG_SET_ERGO_IF_DEFAULT(ConcGCThreads, 1);
3440 FLAG_SET_ERGO_IF_DEFAULT(ParallelGCThreads, 1);
3441 FLAG_SET_ERGO_IF_DEFAULT(CICompilerCount, 2);
3442 }
3443 #endif // ASSERT
3444 }
3445
3446 // Parse entry point called from JNI_CreateJavaVM
3447
3448 jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) {
3449 assert(verify_special_jvm_flags(false), "deprecated and obsolete flag table inconsistent");
3450 JVMFlag::check_all_flag_declarations();
3451
3452 // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
3453 const char* hotspotrc = ".hotspotrc";
3454 bool settings_file_specified = false;
3455 bool needs_hotspotrc_warning = false;
3456 ScopedVMInitArgs initial_vm_options_args("");
3457 ScopedVMInitArgs initial_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'");
3458 ScopedVMInitArgs initial_java_options_args("env_var='_JAVA_OPTIONS'");
3459
3460 // Pointers to current working set of containers
3461 JavaVMInitArgs* cur_cmd_args;
3462 JavaVMInitArgs* cur_vm_options_args;
3463 JavaVMInitArgs* cur_java_options_args;
3464 JavaVMInitArgs* cur_java_tool_options_args;
3465
3466 // Containers for modified/expanded options
3467 ScopedVMInitArgs mod_cmd_args("cmd_line_args");
3468 ScopedVMInitArgs mod_vm_options_args("vm_options_args");
3469 ScopedVMInitArgs mod_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'");
3470 ScopedVMInitArgs mod_java_options_args("env_var='_JAVA_OPTIONS'");
3471
3472
3473 jint code =
3474 parse_java_tool_options_environment_variable(&initial_java_tool_options_args);
3475 if (code != JNI_OK) {
3476 return code;
3477 }
3478
3479 code = parse_java_options_environment_variable(&initial_java_options_args);
3480 if (code != JNI_OK) {
3481 return code;
3482 }
3483
3484 // Parse the options in the /java.base/jdk/internal/vm/options resource, if present
3485 char *vmoptions = ClassLoader::lookup_vm_options();
3486 if (vmoptions != nullptr) {
3487 code = parse_options_buffer("vm options resource", vmoptions, strlen(vmoptions), &initial_vm_options_args);
3488 FREE_C_HEAP_ARRAY(char, vmoptions);
3489 if (code != JNI_OK) {
3490 return code;
3491 }
3511 if (code != JNI_OK) {
3512 return code;
3513 }
3514
3515 code = expand_vm_options_as_needed(initial_vm_options_args.get(),
3516 &mod_vm_options_args,
3517 &cur_vm_options_args);
3518 if (code != JNI_OK) {
3519 return code;
3520 }
3521
3522 const char* flags_file = Arguments::get_jvm_flags_file();
3523 settings_file_specified = (flags_file != nullptr);
3524
3525 if (IgnoreUnrecognizedVMOptions) {
3526 cur_cmd_args->ignoreUnrecognized = true;
3527 cur_java_tool_options_args->ignoreUnrecognized = true;
3528 cur_java_options_args->ignoreUnrecognized = true;
3529 }
3530
3531 // Parse specified settings file
3532 if (settings_file_specified) {
3533 if (!process_settings_file(flags_file, true,
3534 cur_cmd_args->ignoreUnrecognized)) {
3535 return JNI_EINVAL;
3536 }
3537 } else {
3538 #ifdef ASSERT
3539 // Parse default .hotspotrc settings file
3540 if (!process_settings_file(".hotspotrc", false,
3541 cur_cmd_args->ignoreUnrecognized)) {
3542 return JNI_EINVAL;
3543 }
3544 #else
3545 struct stat buf;
3546 if (os::stat(hotspotrc, &buf) == 0) {
3547 needs_hotspotrc_warning = true;
3548 }
3549 #endif
3550 }
3551
3552 if (PrintVMOptions) {
3553 print_options(cur_java_tool_options_args);
3554 print_options(cur_cmd_args);
3555 print_options(cur_java_options_args);
3556 }
3557
3558 // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS
3559 jint result = parse_vm_init_args(cur_vm_options_args,
3560 cur_java_tool_options_args,
3561 cur_java_options_args,
3562 cur_cmd_args);
3563
3564 if (result != JNI_OK) {
3565 return result;
3566 }
3567
3568 // Delay warning until here so that we've had a chance to process
3569 // the -XX:-PrintWarnings flag
3570 if (needs_hotspotrc_warning) {
3571 warning("%s file is present but has been ignored. "
3572 "Run with -XX:Flags=%s to load the file.",
3573 hotspotrc, hotspotrc);
3574 }
3575
3576 if (needs_module_property_warning) {
3577 warning("Ignoring system property options whose names match the '-Djdk.module.*'."
3578 " names that are reserved for internal use.");
3579 }
3580
3581 #if defined(_ALLBSD_SOURCE) || defined(AIX) // UseLargePages is not yet supported on BSD and AIX.
3582 UNSUPPORTED_OPTION(UseLargePages);
3719
3720 // Set compiler flags after GC is selected and GC specific
3721 // flags (LoopStripMiningIter) are set.
3722 CompilerConfig::ergo_initialize();
3723
3724 // Set bytecode rewriting flags
3725 set_bytecode_flags();
3726
3727 // Set flags if aggressive optimization flags are enabled
3728 jint code = set_aggressive_opts_flags();
3729 if (code != JNI_OK) {
3730 return code;
3731 }
3732
3733 if (FLAG_IS_DEFAULT(UseSecondarySupersTable)) {
3734 FLAG_SET_DEFAULT(UseSecondarySupersTable, VM_Version::supports_secondary_supers_table());
3735 } else if (UseSecondarySupersTable && !VM_Version::supports_secondary_supers_table()) {
3736 warning("UseSecondarySupersTable is not supported");
3737 FLAG_SET_DEFAULT(UseSecondarySupersTable, false);
3738 }
3739 if (!UseSecondarySupersTable) {
3740 FLAG_SET_DEFAULT(StressSecondarySupers, false);
3741 FLAG_SET_DEFAULT(VerifySecondarySupers, false);
3742 }
3743
3744 #ifdef ZERO
3745 // Clear flags not supported on zero.
3746 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3747 #endif // ZERO
3748
3749 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3750 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3751 DebugNonSafepoints = true;
3752 }
3753
3754 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3755 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3756 }
3757
3758 // Treat the odd case where local verification is enabled but remote
3787 } else {
3788 warning("Disabling EnableVectorAggressiveReboxing since EnableVectorSupport is turned off.");
3789 }
3790 }
3791 FLAG_SET_DEFAULT(EnableVectorAggressiveReboxing, false);
3792
3793 if (!FLAG_IS_DEFAULT(UseVectorStubs) && UseVectorStubs) {
3794 warning("Disabling UseVectorStubs since EnableVectorSupport is turned off.");
3795 }
3796 FLAG_SET_DEFAULT(UseVectorStubs, false);
3797 }
3798 #endif // COMPILER2_OR_JVMCI
3799
3800 #ifdef COMPILER2
3801 if (!FLAG_IS_DEFAULT(UseLoopPredicate) && !UseLoopPredicate && UseProfiledLoopPredicate) {
3802 warning("Disabling UseProfiledLoopPredicate since UseLoopPredicate is turned off.");
3803 FLAG_SET_ERGO(UseProfiledLoopPredicate, false);
3804 }
3805 #endif // COMPILER2
3806
3807 if (log_is_enabled(Info, perf, class, link)) {
3808 if (!UsePerfData) {
3809 warning("Disabling -Xlog:perf+class+link since UsePerfData is turned off.");
3810 LogConfiguration::disable_tags(false, LOG_TAGS(perf, class, link));
3811 assert(!log_is_enabled(Info, perf, class, link), "sanity");
3812 }
3813 }
3814
3815 if (FLAG_IS_CMDLINE(DiagnoseSyncOnValueBasedClasses)) {
3816 if (DiagnoseSyncOnValueBasedClasses == ObjectSynchronizer::LOG_WARNING && !log_is_enabled(Info, valuebasedclasses)) {
3817 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(valuebasedclasses));
3818 }
3819 }
3820 return JNI_OK;
3821 }
3822
3823 jint Arguments::adjust_after_os() {
3824 if (UseNUMA) {
3825 if (UseParallelGC) {
3826 if (FLAG_IS_DEFAULT(MinHeapDeltaBytes)) {
3827 FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64*M);
3828 }
3829 }
3830 }
3831 return JNI_OK;
3832 }
3833
|
1763 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
1764 }
1765
1766 bool Arguments::sun_java_launcher_is_altjvm() {
1767 return _sun_java_launcher_is_altjvm;
1768 }
1769
1770 //===========================================================================================================
1771 // Parsing of main arguments
1772
1773 static unsigned int addreads_count = 0;
1774 static unsigned int addexports_count = 0;
1775 static unsigned int addopens_count = 0;
1776 static unsigned int patch_mod_count = 0;
1777 static unsigned int enable_native_access_count = 0;
1778 static bool patch_mod_javabase = false;
1779
1780 // Check the consistency of vm_init_args
1781 bool Arguments::check_vm_args_consistency() {
1782 // This may modify compiler flags. Must be called before CompilerConfig::check_args_consistency()
1783 if (!CDSConfig::check_vm_args_consistency(patch_mod_javabase, mode_flag_cmd_line, xshare_auto_cmd_line)) {
1784 return false;
1785 }
1786
1787 // Method for adding checks for flag consistency.
1788 // The intent is to warn the user of all possible conflicts,
1789 // before returning an error.
1790 // Note: Needs platform-dependent factoring.
1791 bool status = true;
1792
1793 if (TLABRefillWasteFraction == 0) {
1794 jio_fprintf(defaultStream::error_stream(),
1795 "TLABRefillWasteFraction should be a denominator, "
1796 "not %zu\n",
1797 TLABRefillWasteFraction);
1798 status = false;
1799 }
1800
1801 status = CompilerConfig::check_args_consistency(status);
1802 #if INCLUDE_JVMCI
1803 if (status && EnableJVMCI) {
1931 jio_fprintf(defaultStream::error_stream(), "Failed to create property %s.%d=%s\n", prop_base_name, count, prop_value);
1932 return false;
1933 }
1934 bool added = add_property(property, UnwriteableProperty, InternalProperty);
1935 FreeHeap(property);
1936 return added;
1937 }
1938
1939 jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
1940 return false;
1941 }
1942
1943 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
1944 julong* long_arg,
1945 julong min_size,
1946 julong max_size) {
1947 if (!parse_integer(s, long_arg)) return arg_unreadable;
1948 return check_memory_size(*long_arg, min_size, max_size);
1949 }
1950
1951 // Parse JavaVMInitArgs (in the order of the parameters to this function)
1952 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args,
1953 const JavaVMInitArgs *java_tool_options_args,
1954 const JavaVMInitArgs *cmd_line_args,
1955 const JavaVMInitArgs *java_options_args,
1956 const JavaVMInitArgs *aot_tool_options_args) {
1957 // Save default settings for some mode flags
1958 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
1959 Arguments::_UseOnStackReplacement = UseOnStackReplacement;
1960 Arguments::_ClipInlining = ClipInlining;
1961 Arguments::_BackgroundCompilation = BackgroundCompilation;
1962
1963 // Remember the default value of SharedBaseAddress.
1964 Arguments::_default_SharedBaseAddress = SharedBaseAddress;
1965
1966 // Setup flags for mixed which is the default
1967 set_mode_flags(_mixed);
1968
1969 // Parse args generated from java.base vm options resource
1970 jint result = parse_each_vm_init_arg(vm_options_args, JVMFlagOrigin::JIMAGE_RESOURCE);
1971 if (result != JNI_OK) {
1972 return result;
1973 }
1974
1975 // Parse args generated from JAVA_TOOL_OPTIONS environment
1976 // variable (if present).
1977 result = parse_each_vm_init_arg(java_tool_options_args, JVMFlagOrigin::ENVIRON_VAR);
1978 if (result != JNI_OK) {
1979 return result;
1980 }
1981
1982 // Parse args generated from the command line flags.
1983 result = parse_each_vm_init_arg(cmd_line_args, JVMFlagOrigin::COMMAND_LINE);
1984 if (result != JNI_OK) {
1985 return result;
1986 }
1987
1988 // Parse args generated from the _JAVA_OPTIONS environment
1989 // variable (if present) (mimics classic VM)
1990 result = parse_each_vm_init_arg(java_options_args, JVMFlagOrigin::ENVIRON_VAR);
1991 if (result != JNI_OK) {
1992 return result;
1993 }
1994
1995 // Parse args generated from the AOT_TOOL_OPTIONS environment variable -- only if AOTMode is "create"
1996 if (aot_tool_options_args->nOptions > 0) {
1997 assert(AOTMode != nullptr && strcmp(AOTMode, "create") == 0, "Required for parsing AOT_TOOL_OPTIONS");
1998 for (int index = 0; index < aot_tool_options_args->nOptions; index++) {
1999 JavaVMOption* option = aot_tool_options_args->options + index;
2000 const char* optionString = option->optionString;
2001 if (strncmp(optionString, "-XX:AOTMode=", 12) == 0 &&
2002 strcmp(optionString, "-XX:AOTMode=create") != 0) {
2003 jio_fprintf(defaultStream::error_stream(),
2004 "Option %s cannot be specified in AOT_TOOL_OPTIONS\n", optionString);
2005 return JNI_ERR;
2006 }
2007 }
2008 result = parse_each_vm_init_arg(aot_tool_options_args, JVMFlagOrigin::ENVIRON_VAR);
2009 if (result != JNI_OK) {
2010 return result;
2011 }
2012 }
2013
2014 // Disable CDS for exploded image
2015 if (!has_jimage()) {
2016 no_shared_spaces("CDS disabled on exploded JDK");
2017 }
2018
2019 // We need to ensure processor and memory resources have been properly
2020 // configured - which may rely on arguments we just processed - before
2021 // doing the final argument processing. Any argument processing that
2022 // needs to know about processor and memory resources must occur after
2023 // this point.
2024
2025 os::init_container_support();
2026
2027 SystemMemoryBarrier::initialize();
2028
2029 // Do final processing now that all arguments have been parsed
2030 result = finalize_vm_init_args();
2031 if (result != JNI_OK) {
2032 return result;
2033 }
2962 if (FLAG_IS_DEFAULT(UseLargePages) &&
2963 MaxHeapSize < LargePageHeapSizeThreshold) {
2964 // No need for large granularity pages w/small heaps.
2965 // Note that large pages are enabled/disabled for both the
2966 // Java heap and the code cache.
2967 FLAG_SET_DEFAULT(UseLargePages, false);
2968 }
2969
2970 UNSUPPORTED_OPTION(ProfileInterpreter);
2971 #endif
2972
2973 // Parse the CompilationMode flag
2974 if (!CompilationModeFlag::initialize()) {
2975 return JNI_ERR;
2976 }
2977
2978 if (!check_vm_args_consistency()) {
2979 return JNI_ERR;
2980 }
2981
2982 if (StoreCachedCode) {
2983 FLAG_SET_ERGO_IF_DEFAULT(CachedCodeMaxSize, 512*M);
2984 }
2985
2986 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT
2987 UNSUPPORTED_OPTION(ShowRegistersOnAssert);
2988 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
2989
2990 return JNI_OK;
2991 }
2992
2993 // Helper class for controlling the lifetime of JavaVMInitArgs
2994 // objects. The contents of the JavaVMInitArgs are guaranteed to be
2995 // deleted on the destruction of the ScopedVMInitArgs object.
2996 class ScopedVMInitArgs : public StackObj {
2997 private:
2998 JavaVMInitArgs _args;
2999 char* _container_name;
3000 bool _is_set;
3001 char* _vm_options_file_arg;
3002
3003 public:
3004 ScopedVMInitArgs(const char *container_name) {
3083 for (int j = 0; j < args_to_insert->nOptions; j++) {
3084 options.push(args_to_insert->options[j]);
3085 }
3086 } else {
3087 options.push(args->options[i]);
3088 }
3089 }
3090 // make into options array
3091 return set_args(&options);
3092 }
3093 };
3094
3095 jint Arguments::parse_java_options_environment_variable(ScopedVMInitArgs* args) {
3096 return parse_options_environment_variable("_JAVA_OPTIONS", args);
3097 }
3098
3099 jint Arguments::parse_java_tool_options_environment_variable(ScopedVMInitArgs* args) {
3100 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", args);
3101 }
3102
3103 static JavaVMOption* get_last_aotmode_arg(const JavaVMInitArgs* args) {
3104 for (int index = args->nOptions - 1; index >= 0; index--) {
3105 JavaVMOption* option = args->options + index;
3106 if (strncmp(option->optionString, "-XX:AOTMode=", 12) == 0) {
3107 return option;
3108 }
3109 }
3110
3111 return nullptr;
3112 }
3113
3114 jint Arguments::parse_aot_tool_options_environment_variable(const JavaVMInitArgs* vm_options_args,
3115 const JavaVMInitArgs* java_tool_options_args,
3116 const JavaVMInitArgs* cmd_line_args,
3117 const JavaVMInitArgs* java_options_args,
3118 ScopedVMInitArgs* aot_tool_options_args) {
3119 // Don't bother scanning all the args if this env variable is not set
3120 if (::getenv("AOT_TOOL_OPTIONS") == nullptr) {
3121 return JNI_OK;
3122 }
3123
3124 // The JavaVMInitArgs will be parsed by parse_vm_init_args() in the order of the
3125 // parameters to this function, so let's look backwards and find the last occurrence
3126 // of -XX:AOTMode=xxx, which will decide the value of AOTMode.
3127 JavaVMOption* option;
3128 if ((option = get_last_aotmode_arg(java_options_args)) != nullptr ||
3129 (option = get_last_aotmode_arg(cmd_line_args)) != nullptr ||
3130 (option = get_last_aotmode_arg(java_tool_options_args)) != nullptr ||
3131 (option = get_last_aotmode_arg(vm_options_args)) != nullptr) {
3132 // We have found the last -XX:AOTMode=xxx in the above 4 set of args. At this point
3133 // <option> has NOT been parsed yet, so its value is not reflected inside the global
3134 // variable AOTMode.
3135 if (strcmp(option->optionString, "-XX:AOTMode=create") != 0) {
3136 return JNI_OK; // Do not parse AOT_TOOL_OPTIONS
3137 }
3138 } else {
3139 // -XX:AOTMode is not specified in any of 4 options_args, let's check AOTMode,
3140 // which would have been set inside process_settings_file();
3141 if (AOTMode == nullptr || strcmp(AOTMode, "create") != 0) {
3142 return JNI_OK; // Do not parse AOT_TOOL_OPTIONS
3143 }
3144 }
3145
3146 return parse_options_environment_variable("AOT_TOOL_OPTIONS", aot_tool_options_args);
3147 }
3148
3149 jint Arguments::parse_options_environment_variable(const char* name,
3150 ScopedVMInitArgs* vm_args) {
3151 char *buffer = ::getenv(name);
3152
3153 // Don't check this environment variable if user has special privileges
3154 // (e.g. unix su command).
3155 if (buffer == nullptr || os::have_special_privileges()) {
3156 return JNI_OK;
3157 }
3158
3159 if ((buffer = os::strdup(buffer)) == nullptr) {
3160 return JNI_ENOMEM;
3161 }
3162
3163 jio_fprintf(defaultStream::error_stream(),
3164 "Picked up %s: %s\n", name, buffer);
3165
3166 int retcode = parse_options_buffer(name, buffer, strlen(buffer), vm_args);
3167
3168 os::free(buffer);
3507 FLAG_SET_ERGO_IF_DEFAULT(ConcGCThreads, 1);
3508 FLAG_SET_ERGO_IF_DEFAULT(ParallelGCThreads, 1);
3509 FLAG_SET_ERGO_IF_DEFAULT(CICompilerCount, 2);
3510 }
3511 #endif // ASSERT
3512 }
3513
3514 // Parse entry point called from JNI_CreateJavaVM
3515
3516 jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) {
3517 assert(verify_special_jvm_flags(false), "deprecated and obsolete flag table inconsistent");
3518 JVMFlag::check_all_flag_declarations();
3519
3520 // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
3521 const char* hotspotrc = ".hotspotrc";
3522 bool settings_file_specified = false;
3523 bool needs_hotspotrc_warning = false;
3524 ScopedVMInitArgs initial_vm_options_args("");
3525 ScopedVMInitArgs initial_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'");
3526 ScopedVMInitArgs initial_java_options_args("env_var='_JAVA_OPTIONS'");
3527 ScopedVMInitArgs initial_aot_tool_options_args("env_var='AOT_TOOL_OPTIONS'");
3528
3529 // Pointers to current working set of containers
3530 JavaVMInitArgs* cur_cmd_args;
3531 JavaVMInitArgs* cur_vm_options_args;
3532 JavaVMInitArgs* cur_java_options_args;
3533 JavaVMInitArgs* cur_java_tool_options_args;
3534 JavaVMInitArgs* cur_aot_tool_options_args;
3535
3536 // Containers for modified/expanded options
3537 ScopedVMInitArgs mod_cmd_args("cmd_line_args");
3538 ScopedVMInitArgs mod_vm_options_args("vm_options_args");
3539 ScopedVMInitArgs mod_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'");
3540 ScopedVMInitArgs mod_java_options_args("env_var='_JAVA_OPTIONS'");
3541 ScopedVMInitArgs mod_aot_tool_options_args("env_var='_AOT_TOOL_OPTIONS'");
3542
3543 jint code =
3544 parse_java_tool_options_environment_variable(&initial_java_tool_options_args);
3545 if (code != JNI_OK) {
3546 return code;
3547 }
3548
3549 code = parse_java_options_environment_variable(&initial_java_options_args);
3550 if (code != JNI_OK) {
3551 return code;
3552 }
3553
3554 // Parse the options in the /java.base/jdk/internal/vm/options resource, if present
3555 char *vmoptions = ClassLoader::lookup_vm_options();
3556 if (vmoptions != nullptr) {
3557 code = parse_options_buffer("vm options resource", vmoptions, strlen(vmoptions), &initial_vm_options_args);
3558 FREE_C_HEAP_ARRAY(char, vmoptions);
3559 if (code != JNI_OK) {
3560 return code;
3561 }
3581 if (code != JNI_OK) {
3582 return code;
3583 }
3584
3585 code = expand_vm_options_as_needed(initial_vm_options_args.get(),
3586 &mod_vm_options_args,
3587 &cur_vm_options_args);
3588 if (code != JNI_OK) {
3589 return code;
3590 }
3591
3592 const char* flags_file = Arguments::get_jvm_flags_file();
3593 settings_file_specified = (flags_file != nullptr);
3594
3595 if (IgnoreUnrecognizedVMOptions) {
3596 cur_cmd_args->ignoreUnrecognized = true;
3597 cur_java_tool_options_args->ignoreUnrecognized = true;
3598 cur_java_options_args->ignoreUnrecognized = true;
3599 }
3600
3601 // Parse specified settings file (s) -- the effects are applied immediately into the JVM global flags.
3602 if (settings_file_specified) {
3603 if (!process_settings_file(flags_file, true,
3604 cur_cmd_args->ignoreUnrecognized)) {
3605 return JNI_EINVAL;
3606 }
3607 } else {
3608 #ifdef ASSERT
3609 // Parse default .hotspotrc settings file
3610 if (!process_settings_file(".hotspotrc", false,
3611 cur_cmd_args->ignoreUnrecognized)) {
3612 return JNI_EINVAL;
3613 }
3614 #else
3615 struct stat buf;
3616 if (os::stat(hotspotrc, &buf) == 0) {
3617 needs_hotspotrc_warning = true;
3618 }
3619 #endif
3620 }
3621
3622 // AOT_TOOL_OPTIONS are parsed only if -XX:AOTMode=create has been detected from all
3623 // the options that have been gathered above.
3624 code = parse_aot_tool_options_environment_variable(cur_vm_options_args,
3625 cur_java_tool_options_args,
3626 cur_cmd_args,
3627 cur_java_options_args,
3628 &initial_aot_tool_options_args);
3629 if (code != JNI_OK) {
3630 return code;
3631 }
3632 code = expand_vm_options_as_needed(initial_aot_tool_options_args.get(),
3633 &mod_aot_tool_options_args,
3634 &cur_aot_tool_options_args);
3635 if (code != JNI_OK) {
3636 return code;
3637 }
3638
3639
3640 if (PrintVMOptions) {
3641 print_options(cur_java_tool_options_args);
3642 print_options(cur_cmd_args);
3643 print_options(cur_java_options_args);
3644 print_options(cur_aot_tool_options_args);
3645 }
3646
3647 // Apply the settings in these args into the JVM global flags, in the order
3648 // of the parameters to parse_vm_init_args()
3649 jint result = parse_vm_init_args(cur_vm_options_args,
3650 cur_java_tool_options_args,
3651 cur_cmd_args,
3652 cur_java_options_args,
3653 cur_aot_tool_options_args);
3654
3655 if (result != JNI_OK) {
3656 return result;
3657 }
3658
3659 // Delay warning until here so that we've had a chance to process
3660 // the -XX:-PrintWarnings flag
3661 if (needs_hotspotrc_warning) {
3662 warning("%s file is present but has been ignored. "
3663 "Run with -XX:Flags=%s to load the file.",
3664 hotspotrc, hotspotrc);
3665 }
3666
3667 if (needs_module_property_warning) {
3668 warning("Ignoring system property options whose names match the '-Djdk.module.*'."
3669 " names that are reserved for internal use.");
3670 }
3671
3672 #if defined(_ALLBSD_SOURCE) || defined(AIX) // UseLargePages is not yet supported on BSD and AIX.
3673 UNSUPPORTED_OPTION(UseLargePages);
3810
3811 // Set compiler flags after GC is selected and GC specific
3812 // flags (LoopStripMiningIter) are set.
3813 CompilerConfig::ergo_initialize();
3814
3815 // Set bytecode rewriting flags
3816 set_bytecode_flags();
3817
3818 // Set flags if aggressive optimization flags are enabled
3819 jint code = set_aggressive_opts_flags();
3820 if (code != JNI_OK) {
3821 return code;
3822 }
3823
3824 if (FLAG_IS_DEFAULT(UseSecondarySupersTable)) {
3825 FLAG_SET_DEFAULT(UseSecondarySupersTable, VM_Version::supports_secondary_supers_table());
3826 } else if (UseSecondarySupersTable && !VM_Version::supports_secondary_supers_table()) {
3827 warning("UseSecondarySupersTable is not supported");
3828 FLAG_SET_DEFAULT(UseSecondarySupersTable, false);
3829 }
3830 UseSecondarySupersTable = false; // FIXME: Disabled for Leyden. Neet to fix AOTCodeAddressTable::id_for_address()
3831 if (!UseSecondarySupersTable) {
3832 FLAG_SET_DEFAULT(StressSecondarySupers, false);
3833 FLAG_SET_DEFAULT(VerifySecondarySupers, false);
3834 }
3835
3836 #ifdef ZERO
3837 // Clear flags not supported on zero.
3838 FLAG_SET_DEFAULT(ProfileInterpreter, false);
3839 #endif // ZERO
3840
3841 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
3842 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
3843 DebugNonSafepoints = true;
3844 }
3845
3846 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) {
3847 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
3848 }
3849
3850 // Treat the odd case where local verification is enabled but remote
3879 } else {
3880 warning("Disabling EnableVectorAggressiveReboxing since EnableVectorSupport is turned off.");
3881 }
3882 }
3883 FLAG_SET_DEFAULT(EnableVectorAggressiveReboxing, false);
3884
3885 if (!FLAG_IS_DEFAULT(UseVectorStubs) && UseVectorStubs) {
3886 warning("Disabling UseVectorStubs since EnableVectorSupport is turned off.");
3887 }
3888 FLAG_SET_DEFAULT(UseVectorStubs, false);
3889 }
3890 #endif // COMPILER2_OR_JVMCI
3891
3892 #ifdef COMPILER2
3893 if (!FLAG_IS_DEFAULT(UseLoopPredicate) && !UseLoopPredicate && UseProfiledLoopPredicate) {
3894 warning("Disabling UseProfiledLoopPredicate since UseLoopPredicate is turned off.");
3895 FLAG_SET_ERGO(UseProfiledLoopPredicate, false);
3896 }
3897 #endif // COMPILER2
3898
3899 if (log_is_enabled(Info, init)) {
3900 if (FLAG_IS_DEFAULT(ProfileVMLocks)) {
3901 FLAG_SET_DEFAULT(ProfileVMLocks, true);
3902 }
3903 if (UsePerfData && !log_is_enabled(Info, perf, class, link)) {
3904 // automatically enable -Xlog:perf+class+link
3905 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(perf, class, link));
3906 }
3907 // Don't turn on ProfileVMCalls and ProfileRuntimeCalls by default.
3908 } else {
3909 if (!FLAG_IS_DEFAULT(ProfileVMLocks) && ProfileVMLocks) {
3910 warning("Disabling ProfileVMLocks since logging is turned off.");
3911 FLAG_SET_DEFAULT(ProfileVMLocks, false);
3912 }
3913 if (!FLAG_IS_DEFAULT(ProfileVMCalls) && ProfileVMCalls) {
3914 warning("Disabling ProfileVMCalls since logging is turned off.");
3915 FLAG_SET_DEFAULT(ProfileVMCalls, false);
3916 }
3917 if (!FLAG_IS_DEFAULT(ProfileRuntimeCalls) && ProfileRuntimeCalls) {
3918 warning("Disabling ProfileRuntimeCalls since logging is turned off.");
3919 FLAG_SET_DEFAULT(ProfileRuntimeCalls, false);
3920 }
3921 if (log_is_enabled(Info, perf, class, link)) {
3922 warning("Disabling -Xlog:perf+class+link since logging is turned off.");
3923 LogConfiguration::disable_tags(false, LOG_TAGS(perf, class, link));
3924 assert(!log_is_enabled(Info, perf, class, link), "sanity");
3925 }
3926 }
3927 if (FLAG_IS_DEFAULT(PerfDataMemorySize)) {
3928 if (ProfileVMLocks || ProfileVMCalls || ProfileRuntimeCalls) {
3929 FLAG_SET_DEFAULT(PerfDataMemorySize, 128*K); // reserve more space for extra perf counters
3930 }
3931 }
3932
3933 if (FLAG_IS_CMDLINE(DiagnoseSyncOnValueBasedClasses)) {
3934 if (DiagnoseSyncOnValueBasedClasses == ObjectSynchronizer::LOG_WARNING && !log_is_enabled(Info, valuebasedclasses)) {
3935 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(valuebasedclasses));
3936 }
3937 }
3938 return JNI_OK;
3939 }
3940
3941 jint Arguments::adjust_after_os() {
3942 if (UseNUMA) {
3943 if (UseParallelGC) {
3944 if (FLAG_IS_DEFAULT(MinHeapDeltaBytes)) {
3945 FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64*M);
3946 }
3947 }
3948 }
3949 return JNI_OK;
3950 }
3951
|