Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8142722 | emb-9 | Daniel Daugherty | P3 | Resolved | Fixed | team |
If we have option file(name it "optionfile") with option which have special behavior("-XX:+PrintVMOptions") and ran java with following options:
./java -XX:VMOptionsFile=optionfile -XX:-PrintVMOptions -version
We expect that special PrintVMOption will be disabled since "last argument wins", because "-XX:-PrintVMOptions" is specified after VM Options file. But in current implementation we see:
java -XX:VMOptionsFile=optionfile -XX:-PrintVMOptions -version
VM option '+PrintVMOptions'
VM option '-PrintVMOptions'
That means that special option got value from VM Options file. This applied to the all special options("-XX:Flags", "-XX:+IgnoreUnrecognizedVMOptions" etc.). The problem is that in Arguments::match_special_option_and_act function "match specail option and act" mechanism is applied to the VM Options file only after all options from command line are compared with special options:
jint Arguments::match_special_option_and_act(const JavaVMInitArgs* args,
char ** flags_file,
char ** vm_options_file,
ScopedVMInitArgs* vm_options_file_args,
ScopedVMInitArgs* args_out) {
// Remaining part of option string
const char* tail;
int vm_options_file_pos = -1;
for (int index = 0; index < args->nOptions; index++) {
const JavaVMOption* option = args->options + index;
if (ArgumentsExt::process_options(option)) {
continue;
}
if (match_option(option, "-XX:Flags=", &tail)) {
*flags_file = (char *) tail;
if (*flags_file == NULL) {
jio_fprintf(defaultStream::error_stream(),
"Cannot copy flags_file name.\n");
return JNI_ENOMEM;
}
continue;
}
if (match_option(option, "-XX:VMOptionsFile=", &tail)) {
...
}
if (match_option(option, "-XX:+PrintVMOptions")) {
PrintVMOptions = true;
continue;
}
...
}
// If there's a VMOptionsFile, parse that (also can set flags_file)
if ((vm_options_file != NULL) && (*vm_options_file != NULL)) {
return insert_vm_options_file(args, flags_file, vm_options_file,
vm_options_file_pos, vm_options_file_args, args_out);
}
return JNI_OK;
}
./java -XX:VMOptionsFile=optionfile -XX:-PrintVMOptions -version
We expect that special PrintVMOption will be disabled since "last argument wins", because "-XX:-PrintVMOptions" is specified after VM Options file. But in current implementation we see:
java -XX:VMOptionsFile=optionfile -XX:-PrintVMOptions -version
VM option '+PrintVMOptions'
VM option '-PrintVMOptions'
That means that special option got value from VM Options file. This applied to the all special options("-XX:Flags", "-XX:+IgnoreUnrecognizedVMOptions" etc.). The problem is that in Arguments::match_special_option_and_act function "match specail option and act" mechanism is applied to the VM Options file only after all options from command line are compared with special options:
jint Arguments::match_special_option_and_act(const JavaVMInitArgs* args,
char ** flags_file,
char ** vm_options_file,
ScopedVMInitArgs* vm_options_file_args,
ScopedVMInitArgs* args_out) {
// Remaining part of option string
const char* tail;
int vm_options_file_pos = -1;
for (int index = 0; index < args->nOptions; index++) {
const JavaVMOption* option = args->options + index;
if (ArgumentsExt::process_options(option)) {
continue;
}
if (match_option(option, "-XX:Flags=", &tail)) {
*flags_file = (char *) tail;
if (*flags_file == NULL) {
jio_fprintf(defaultStream::error_stream(),
"Cannot copy flags_file name.\n");
return JNI_ENOMEM;
}
continue;
}
if (match_option(option, "-XX:VMOptionsFile=", &tail)) {
...
}
if (match_option(option, "-XX:+PrintVMOptions")) {
PrintVMOptions = true;
continue;
}
...
}
// If there's a VMOptionsFile, parse that (also can set flags_file)
if ((vm_options_file != NULL) && (*vm_options_file != NULL)) {
return insert_vm_options_file(args, flags_file, vm_options_file,
vm_options_file_pos, vm_options_file_args, args_out);
}
return JNI_OK;
}
- backported by
-
JDK-8142722 Last argument wins does not work for special options with "-XX:VMOptionsFile" option
-
- Resolved
-
- relates to
-
JDK-8061999 Enhance VM option parsing to allow options to be specified in a file
-
- Resolved
-