mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-17 09:34:38 +02:00
6522873: Java not print "Unrecognized option" when it is invalid option
Introduced a new version of match_option() that don't allow a tail after the flag name and used it for flags without extra arguments Reviewed-by: dholmes, dcubed
This commit is contained in:
parent
bdb2636f9e
commit
f101b30199
1 changed files with 79 additions and 68 deletions
|
@ -125,8 +125,8 @@ char* Arguments::_meta_index_path = NULL;
|
|||
char* Arguments::_meta_index_dir = NULL;
|
||||
char* Arguments::_ext_dirs = NULL;
|
||||
|
||||
// Check if head of 'option' matches 'name', and sets 'tail' remaining part of option string
|
||||
|
||||
// Check if head of 'option' matches 'name', and sets 'tail' to the remaining
|
||||
// part of the option string.
|
||||
static bool match_option(const JavaVMOption *option, const char* name,
|
||||
const char** tail) {
|
||||
int len = (int)strlen(name);
|
||||
|
@ -138,6 +138,32 @@ static bool match_option(const JavaVMOption *option, const char* name,
|
|||
}
|
||||
}
|
||||
|
||||
// Check if 'option' matches 'name'. No "tail" is allowed.
|
||||
static bool match_option(const JavaVMOption *option, const char* name) {
|
||||
const char* tail = NULL;
|
||||
bool result = match_option(option, name, &tail);
|
||||
if (tail != NULL && *tail == '\0') {
|
||||
return result;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Return true if any of the strings in null-terminated array 'names' matches.
|
||||
// If tail_allowed is true, then the tail must begin with a colon; otherwise,
|
||||
// the option must match exactly.
|
||||
static bool match_option(const JavaVMOption* option, const char** names, const char** tail,
|
||||
bool tail_allowed) {
|
||||
for (/* empty */; *names != NULL; ++names) {
|
||||
if (match_option(option, *names, tail)) {
|
||||
if (**tail == '\0' || tail_allowed && **tail == ':') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void logOption(const char* opt) {
|
||||
if (PrintVMOptions) {
|
||||
jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt);
|
||||
|
@ -2526,21 +2552,6 @@ static const char* system_assertion_options[] = {
|
|||
"-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0
|
||||
};
|
||||
|
||||
// Return true if any of the strings in null-terminated array 'names' matches.
|
||||
// If tail_allowed is true, then the tail must begin with a colon; otherwise,
|
||||
// the option must match exactly.
|
||||
static bool match_option(const JavaVMOption* option, const char** names, const char** tail,
|
||||
bool tail_allowed) {
|
||||
for (/* empty */; *names != NULL; ++names) {
|
||||
if (match_option(option, *names, tail)) {
|
||||
if (**tail == '\0' || tail_allowed && **tail == ':') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Arguments::parse_uintx(const char* value,
|
||||
uintx* uintx_arg,
|
||||
uintx min_size) {
|
||||
|
@ -2782,16 +2793,16 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
}
|
||||
#endif // !INCLUDE_JVMTI
|
||||
// -Xnoclassgc
|
||||
} else if (match_option(option, "-Xnoclassgc", &tail)) {
|
||||
} else if (match_option(option, "-Xnoclassgc")) {
|
||||
FLAG_SET_CMDLINE(bool, ClassUnloading, false);
|
||||
// -Xconcgc
|
||||
} else if (match_option(option, "-Xconcgc", &tail)) {
|
||||
} else if (match_option(option, "-Xconcgc")) {
|
||||
FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
|
||||
// -Xnoconcgc
|
||||
} else if (match_option(option, "-Xnoconcgc", &tail)) {
|
||||
} else if (match_option(option, "-Xnoconcgc")) {
|
||||
FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
|
||||
// -Xbatch
|
||||
} else if (match_option(option, "-Xbatch", &tail)) {
|
||||
} else if (match_option(option, "-Xbatch")) {
|
||||
FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
|
||||
// -Xmn for compatibility with other JVM vendors
|
||||
} else if (match_option(option, "-Xmn", &tail)) {
|
||||
|
@ -2936,28 +2947,28 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
}
|
||||
FLAG_SET_CMDLINE(uintx, IncreaseFirstTierCompileThresholdAt, (uintx)uint_IncreaseFirstTierCompileThresholdAt);
|
||||
// -green
|
||||
} else if (match_option(option, "-green", &tail)) {
|
||||
} else if (match_option(option, "-green")) {
|
||||
jio_fprintf(defaultStream::error_stream(),
|
||||
"Green threads support not available\n");
|
||||
return JNI_EINVAL;
|
||||
// -native
|
||||
} else if (match_option(option, "-native", &tail)) {
|
||||
} else if (match_option(option, "-native")) {
|
||||
// HotSpot always uses native threads, ignore silently for compatibility
|
||||
// -Xsqnopause
|
||||
} else if (match_option(option, "-Xsqnopause", &tail)) {
|
||||
} else if (match_option(option, "-Xsqnopause")) {
|
||||
// EVM option, ignore silently for compatibility
|
||||
// -Xrs
|
||||
} else if (match_option(option, "-Xrs", &tail)) {
|
||||
} else if (match_option(option, "-Xrs")) {
|
||||
// Classic/EVM option, new functionality
|
||||
FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true);
|
||||
} else if (match_option(option, "-Xusealtsigs", &tail)) {
|
||||
} else if (match_option(option, "-Xusealtsigs")) {
|
||||
// change default internal VM signals used - lower case for back compat
|
||||
FLAG_SET_CMDLINE(bool, UseAltSigs, true);
|
||||
// -Xoptimize
|
||||
} else if (match_option(option, "-Xoptimize", &tail)) {
|
||||
} else if (match_option(option, "-Xoptimize")) {
|
||||
// EVM option, ignore silently for compatibility
|
||||
// -Xprof
|
||||
} else if (match_option(option, "-Xprof", &tail)) {
|
||||
} else if (match_option(option, "-Xprof")) {
|
||||
#if INCLUDE_FPROF
|
||||
_has_profile = true;
|
||||
#else // INCLUDE_FPROF
|
||||
|
@ -2966,7 +2977,7 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
return JNI_ERR;
|
||||
#endif // INCLUDE_FPROF
|
||||
// -Xconcurrentio
|
||||
} else if (match_option(option, "-Xconcurrentio", &tail)) {
|
||||
} else if (match_option(option, "-Xconcurrentio")) {
|
||||
FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true);
|
||||
FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
|
||||
FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1);
|
||||
|
@ -2974,13 +2985,13 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
FLAG_SET_CMDLINE(uintx, NewSizeThreadIncrease, 16 * K); // 20Kb per thread added to new generation
|
||||
|
||||
// -Xinternalversion
|
||||
} else if (match_option(option, "-Xinternalversion", &tail)) {
|
||||
} else if (match_option(option, "-Xinternalversion")) {
|
||||
jio_fprintf(defaultStream::output_stream(), "%s\n",
|
||||
VM_Version::internal_vm_info_string());
|
||||
vm_exit(0);
|
||||
#ifndef PRODUCT
|
||||
// -Xprintflags
|
||||
} else if (match_option(option, "-Xprintflags", &tail)) {
|
||||
} else if (match_option(option, "-Xprintflags")) {
|
||||
CommandLineFlags::printFlags(tty, false);
|
||||
vm_exit(0);
|
||||
#endif
|
||||
|
@ -3014,29 +3025,29 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
#endif
|
||||
}
|
||||
// -Xint
|
||||
} else if (match_option(option, "-Xint", &tail)) {
|
||||
} else if (match_option(option, "-Xint")) {
|
||||
set_mode_flags(_int);
|
||||
// -Xmixed
|
||||
} else if (match_option(option, "-Xmixed", &tail)) {
|
||||
} else if (match_option(option, "-Xmixed")) {
|
||||
set_mode_flags(_mixed);
|
||||
// -Xcomp
|
||||
} else if (match_option(option, "-Xcomp", &tail)) {
|
||||
} else if (match_option(option, "-Xcomp")) {
|
||||
// for testing the compiler; turn off all flags that inhibit compilation
|
||||
set_mode_flags(_comp);
|
||||
// -Xshare:dump
|
||||
} else if (match_option(option, "-Xshare:dump", &tail)) {
|
||||
} else if (match_option(option, "-Xshare:dump")) {
|
||||
FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true);
|
||||
set_mode_flags(_int); // Prevent compilation, which creates objects
|
||||
// -Xshare:on
|
||||
} else if (match_option(option, "-Xshare:on", &tail)) {
|
||||
} else if (match_option(option, "-Xshare:on")) {
|
||||
FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
|
||||
FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true);
|
||||
// -Xshare:auto
|
||||
} else if (match_option(option, "-Xshare:auto", &tail)) {
|
||||
} else if (match_option(option, "-Xshare:auto")) {
|
||||
FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
|
||||
FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
|
||||
// -Xshare:off
|
||||
} else if (match_option(option, "-Xshare:off", &tail)) {
|
||||
} else if (match_option(option, "-Xshare:off")) {
|
||||
FLAG_SET_CMDLINE(bool, UseSharedSpaces, false);
|
||||
FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
|
||||
// -Xverify
|
||||
|
@ -3054,13 +3065,13 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
return JNI_EINVAL;
|
||||
}
|
||||
// -Xdebug
|
||||
} else if (match_option(option, "-Xdebug", &tail)) {
|
||||
} else if (match_option(option, "-Xdebug")) {
|
||||
// note this flag has been used, then ignore
|
||||
set_xdebug_mode(true);
|
||||
// -Xnoagent
|
||||
} else if (match_option(option, "-Xnoagent", &tail)) {
|
||||
} else if (match_option(option, "-Xnoagent")) {
|
||||
// For compatibility with classic. HotSpot refuses to load the old style agent.dll.
|
||||
} else if (match_option(option, "-Xboundthreads", &tail)) {
|
||||
} else if (match_option(option, "-Xboundthreads")) {
|
||||
// Bind user level threads to kernel threads (Solaris only)
|
||||
FLAG_SET_CMDLINE(bool, UseBoundThreads, true);
|
||||
} else if (match_option(option, "-Xloggc:", &tail)) {
|
||||
|
@ -3090,14 +3101,14 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
"check")) {
|
||||
return JNI_EINVAL;
|
||||
}
|
||||
} else if (match_option(option, "vfprintf", &tail)) {
|
||||
} else if (match_option(option, "vfprintf")) {
|
||||
_vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo);
|
||||
} else if (match_option(option, "exit", &tail)) {
|
||||
} else if (match_option(option, "exit")) {
|
||||
_exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo);
|
||||
} else if (match_option(option, "abort", &tail)) {
|
||||
} else if (match_option(option, "abort")) {
|
||||
_abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo);
|
||||
// -XX:+AggressiveHeap
|
||||
} else if (match_option(option, "-XX:+AggressiveHeap", &tail)) {
|
||||
} else if (match_option(option, "-XX:+AggressiveHeap")) {
|
||||
|
||||
// This option inspects the machine and attempts to set various
|
||||
// parameters to be optimal for long-running, memory allocation
|
||||
|
@ -3188,11 +3199,11 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
|
||||
// Need to keep consistency of MaxTenuringThreshold and AlwaysTenure/NeverTenure;
|
||||
// and the last option wins.
|
||||
} else if (match_option(option, "-XX:+NeverTenure", &tail)) {
|
||||
} else if (match_option(option, "-XX:+NeverTenure")) {
|
||||
FLAG_SET_CMDLINE(bool, NeverTenure, true);
|
||||
FLAG_SET_CMDLINE(bool, AlwaysTenure, false);
|
||||
FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, markOopDesc::max_age + 1);
|
||||
} else if (match_option(option, "-XX:+AlwaysTenure", &tail)) {
|
||||
} else if (match_option(option, "-XX:+AlwaysTenure")) {
|
||||
FLAG_SET_CMDLINE(bool, NeverTenure, false);
|
||||
FLAG_SET_CMDLINE(bool, AlwaysTenure, true);
|
||||
FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0);
|
||||
|
@ -3211,17 +3222,17 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
FLAG_SET_CMDLINE(bool, NeverTenure, false);
|
||||
FLAG_SET_CMDLINE(bool, AlwaysTenure, false);
|
||||
}
|
||||
} else if (match_option(option, "-XX:+CMSPermGenSweepingEnabled", &tail) ||
|
||||
match_option(option, "-XX:-CMSPermGenSweepingEnabled", &tail)) {
|
||||
} else if (match_option(option, "-XX:+CMSPermGenSweepingEnabled") ||
|
||||
match_option(option, "-XX:-CMSPermGenSweepingEnabled")) {
|
||||
jio_fprintf(defaultStream::error_stream(),
|
||||
"Please use CMSClassUnloadingEnabled in place of "
|
||||
"CMSPermGenSweepingEnabled in the future\n");
|
||||
} else if (match_option(option, "-XX:+UseGCTimeLimit", &tail)) {
|
||||
} else if (match_option(option, "-XX:+UseGCTimeLimit")) {
|
||||
FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, true);
|
||||
jio_fprintf(defaultStream::error_stream(),
|
||||
"Please use -XX:+UseGCOverheadLimit in place of "
|
||||
"-XX:+UseGCTimeLimit in the future\n");
|
||||
} else if (match_option(option, "-XX:-UseGCTimeLimit", &tail)) {
|
||||
} else if (match_option(option, "-XX:-UseGCTimeLimit")) {
|
||||
FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, false);
|
||||
jio_fprintf(defaultStream::error_stream(),
|
||||
"Please use -XX:-UseGCOverheadLimit in place of "
|
||||
|
@ -3231,13 +3242,13 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
// are not to be documented.
|
||||
} else if (match_option(option, "-XX:MaxTLERatio=", &tail)) {
|
||||
// No longer used.
|
||||
} else if (match_option(option, "-XX:+ResizeTLE", &tail)) {
|
||||
} else if (match_option(option, "-XX:+ResizeTLE")) {
|
||||
FLAG_SET_CMDLINE(bool, ResizeTLAB, true);
|
||||
} else if (match_option(option, "-XX:-ResizeTLE", &tail)) {
|
||||
} else if (match_option(option, "-XX:-ResizeTLE")) {
|
||||
FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
|
||||
} else if (match_option(option, "-XX:+PrintTLE", &tail)) {
|
||||
} else if (match_option(option, "-XX:+PrintTLE")) {
|
||||
FLAG_SET_CMDLINE(bool, PrintTLAB, true);
|
||||
} else if (match_option(option, "-XX:-PrintTLE", &tail)) {
|
||||
} else if (match_option(option, "-XX:-PrintTLE")) {
|
||||
FLAG_SET_CMDLINE(bool, PrintTLAB, false);
|
||||
} else if (match_option(option, "-XX:TLEFragmentationRatio=", &tail)) {
|
||||
// No longer used.
|
||||
|
@ -3253,17 +3264,17 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
FLAG_SET_CMDLINE(uintx, TLABSize, long_tlab_size);
|
||||
} else if (match_option(option, "-XX:TLEThreadRatio=", &tail)) {
|
||||
// No longer used.
|
||||
} else if (match_option(option, "-XX:+UseTLE", &tail)) {
|
||||
} else if (match_option(option, "-XX:+UseTLE")) {
|
||||
FLAG_SET_CMDLINE(bool, UseTLAB, true);
|
||||
} else if (match_option(option, "-XX:-UseTLE", &tail)) {
|
||||
} else if (match_option(option, "-XX:-UseTLE")) {
|
||||
FLAG_SET_CMDLINE(bool, UseTLAB, false);
|
||||
} else if (match_option(option, "-XX:+DisplayVMOutputToStderr", &tail)) {
|
||||
} else if (match_option(option, "-XX:+DisplayVMOutputToStderr")) {
|
||||
FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false);
|
||||
FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true);
|
||||
} else if (match_option(option, "-XX:+DisplayVMOutputToStdout", &tail)) {
|
||||
} else if (match_option(option, "-XX:+DisplayVMOutputToStdout")) {
|
||||
FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false);
|
||||
FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true);
|
||||
} else if (match_option(option, "-XX:+ExtendedDTraceProbes", &tail)) {
|
||||
} else if (match_option(option, "-XX:+ExtendedDTraceProbes")) {
|
||||
#if defined(DTRACE_ENABLED)
|
||||
FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true);
|
||||
FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true);
|
||||
|
@ -3275,7 +3286,7 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
return JNI_EINVAL;
|
||||
#endif // defined(DTRACE_ENABLED)
|
||||
#ifdef ASSERT
|
||||
} else if (match_option(option, "-XX:+FullGCALot", &tail)) {
|
||||
} else if (match_option(option, "-XX:+FullGCALot")) {
|
||||
FLAG_SET_CMDLINE(bool, FullGCALot, true);
|
||||
// disable scavenge before parallel mark-compact
|
||||
FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
|
||||
|
@ -3361,7 +3372,7 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
}
|
||||
FLAG_SET_CMDLINE(uintx, MaxDirectMemorySize, max_direct_memory_size);
|
||||
#if !INCLUDE_MANAGEMENT
|
||||
} else if (match_option(option, "-XX:+ManagementServer", &tail)) {
|
||||
} else if (match_option(option, "-XX:+ManagementServer")) {
|
||||
jio_fprintf(defaultStream::error_stream(),
|
||||
"ManagementServer is not supported in this VM.\n");
|
||||
return JNI_ERR;
|
||||
|
@ -3796,23 +3807,23 @@ jint Arguments::parse(const JavaVMInitArgs* args) {
|
|||
settings_file_specified = true;
|
||||
continue;
|
||||
}
|
||||
if (match_option(option, "-XX:+PrintVMOptions", &tail)) {
|
||||
if (match_option(option, "-XX:+PrintVMOptions")) {
|
||||
PrintVMOptions = true;
|
||||
continue;
|
||||
}
|
||||
if (match_option(option, "-XX:-PrintVMOptions", &tail)) {
|
||||
if (match_option(option, "-XX:-PrintVMOptions")) {
|
||||
PrintVMOptions = false;
|
||||
continue;
|
||||
}
|
||||
if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions", &tail)) {
|
||||
if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions")) {
|
||||
IgnoreUnrecognizedVMOptions = true;
|
||||
continue;
|
||||
}
|
||||
if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions", &tail)) {
|
||||
if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions")) {
|
||||
IgnoreUnrecognizedVMOptions = false;
|
||||
continue;
|
||||
}
|
||||
if (match_option(option, "-XX:+PrintFlagsInitial", &tail)) {
|
||||
if (match_option(option, "-XX:+PrintFlagsInitial")) {
|
||||
CommandLineFlags::printFlags(tty, false);
|
||||
vm_exit(0);
|
||||
}
|
||||
|
@ -3838,7 +3849,7 @@ jint Arguments::parse(const JavaVMInitArgs* args) {
|
|||
|
||||
|
||||
#ifndef PRODUCT
|
||||
if (match_option(option, "-XX:+PrintFlagsWithComments", &tail)) {
|
||||
if (match_option(option, "-XX:+PrintFlagsWithComments")) {
|
||||
CommandLineFlags::printFlags(tty, true);
|
||||
vm_exit(0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue