--- old/src/share/vm/runtime/arguments.cpp 2015-05-04 13:42:23.981887000 -0700 +++ new/src/share/vm/runtime/arguments.cpp 2015-05-04 13:42:23.881882000 -0700 @@ -87,7 +87,7 @@ int Arguments::_sun_java_launcher_pid = -1; bool Arguments::_sun_java_launcher_is_altjvm = false; -// These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*) +// These parameters are reset in method parse_vm_init_args() bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods; bool Arguments::_UseOnStackReplacement = UseOnStackReplacement; bool Arguments::_BackgroundCompilation = BackgroundCompilation; @@ -2526,7 +2526,9 @@ // Parse JavaVMInitArgs structure -jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) { +jint Arguments::parse_vm_init_args(const JavaVMInitArgs *java_tool_options_args, + const JavaVMInitArgs *java_options_args, + const JavaVMInitArgs *cmd_line_args) { // For components of the system classpath. SysClassPath scp(Arguments::get_sysclasspath()); bool scp_assembly_required = false; @@ -2544,20 +2546,25 @@ // Setup flags for mixed which is the default set_mode_flags(_mixed); - // Parse JAVA_TOOL_OPTIONS environment variable (if present) - jint result = parse_java_tool_options_environment_variable(&scp, &scp_assembly_required); + // Parse args structure generated from JAVA_TOOL_OPTIONS environment + // variable (if present). + jint result = parse_each_vm_init_arg( + java_tool_options_args, &scp, &scp_assembly_required, Flag::ENVIRON_VAR); if (result != JNI_OK) { return result; } - // Parse JavaVMInitArgs structure passed in - result = parse_each_vm_init_arg(args, &scp, &scp_assembly_required, Flag::COMMAND_LINE); + // Parse args structure generated from the command line flags. + result = parse_each_vm_init_arg(cmd_line_args, &scp, &scp_assembly_required, + Flag::COMMAND_LINE); if (result != JNI_OK) { return result; } - // Parse _JAVA_OPTIONS environment variable (if present) (mimics classic VM) - result = parse_java_options_environment_variable(&scp, &scp_assembly_required); + // Parse args structure generated from the _JAVA_OPTIONS environment + // variable (if present) (mimics classic VM) + result = parse_each_vm_init_arg( + java_options_args, &scp, &scp_assembly_required, Flag::ENVIRON_VAR); if (result != JNI_OK) { return result; } @@ -3500,20 +3507,23 @@ return JNI_OK; } -jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) { - return parse_options_environment_variable("_JAVA_OPTIONS", scp_p, - scp_assembly_required_p); +jint Arguments::parse_java_options_environment_variable(JavaVMInitArgs* args) { + return parse_options_environment_variable("_JAVA_OPTIONS", args); } -jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) { - return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p, - scp_assembly_required_p); +jint Arguments::parse_java_tool_options_environment_variable(JavaVMInitArgs* args) { + return parse_options_environment_variable("JAVA_TOOL_OPTIONS", args); } -jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) { +jint Arguments::parse_options_environment_variable(const char* name, JavaVMInitArgs* vm_args) { char *buffer = ::getenv(name); - // Don't check this variable if user has special privileges + vm_args->version = JNI_VERSION_1_2; + vm_args->options = NULL; + vm_args->nOptions = 0; + vm_args->ignoreUnrecognized = false; + + // Don't check this environment variable if user has special privileges // (e.g. unix su command). if (buffer == NULL || os::have_special_privileges()) { return JNI_OK; @@ -3558,14 +3568,15 @@ *wrt++ = *rd++; // copy to option string } } - // Need to check if we're done before writing a NULL, - // because the write could be to the byte that rd is pointing to. - if (*rd++ == 0) { - *wrt = 0; - break; + if (*rd != 0) { + // In this case, the assignment to wrt below will make *rd nul, + // which will interfere with the next loop iteration. + rd++; } *wrt = 0; // Zero terminate option } + + // Fill out JavaVMInitArgs structure. JavaVMOption* options_arr = NEW_C_HEAP_ARRAY_RETURN_NULL(JavaVMOption, options->length(), mtInternal); if (options_arr == NULL) { @@ -3577,29 +3588,12 @@ options_arr[i] = options->at(i); } - // Construct JavaVMInitArgs structure and parse as if it was part of the command line - JavaVMInitArgs vm_args; - vm_args.version = JNI_VERSION_1_2; - vm_args.options = options_arr; - vm_args.nOptions = options->length(); - vm_args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions; - - if (PrintVMOptions) { - const char* tail; - for (int i = 0; i < vm_args.nOptions; i++) { - const JavaVMOption *option = vm_args.options + i; - if (match_option(option, "-XX:", &tail)) { - logOption(tail); - } - } - } + vm_args->options = options_arr; + vm_args->nOptions = options->length(); + vm_args->ignoreUnrecognized = IgnoreUnrecognizedVMOptions; - jint result = parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, - Flag::ENVIRON_VAR); - FREE_C_HEAP_ARRAY(JavaVMOption, options_arr); delete options; - os::free(buffer); - return result; + return JNI_OK; } void Arguments::set_shared_spaces_flags() { @@ -3682,28 +3676,18 @@ } #endif // PRODUCT -// Parse entry point called from JNI_CreateJavaVM - -jint Arguments::parse(const JavaVMInitArgs* args) { - +static int match_special_option_and_act(const JavaVMInitArgs* args, + char** flags_file) { // Remaining part of option string const char* tail; - // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed. - const char* hotspotrc = ".hotspotrc"; - bool settings_file_specified = false; - bool needs_hotspotrc_warning = false; - - const char* flags_file; - int index; - for (index = 0; index < args->nOptions; index++) { - const JavaVMOption *option = args->options + index; + 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 = tail; - settings_file_specified = true; + *flags_file = (char *) tail; continue; } if (match_option(option, "-XX:+PrintVMOptions")) { @@ -3757,10 +3741,51 @@ } #endif } + return JNI_OK; +} + +static void print_options(const JavaVMInitArgs *args) { + const char* tail; + for (int index = 0; index < args->nOptions; index++) { + const JavaVMOption *option = args->options + index; + if (match_option(option, "-XX:", &tail)) { + logOption(tail); + } + } +} + +// Parse entry point called from JNI_CreateJavaVM + +jint Arguments::parse(const JavaVMInitArgs* args) { + // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed. + const char* hotspotrc = ".hotspotrc"; + char* flags_file = NULL; + bool settings_file_specified = false; + bool needs_hotspotrc_warning = false; + JavaVMInitArgs java_tool_options_args; + JavaVMInitArgs java_options_args; + + int code = + parse_java_tool_options_environment_variable(&java_tool_options_args); + if (code != JNI_OK) { + return code; + } + + code = parse_java_options_environment_variable(&java_options_args); + if (code != JNI_OK) { + return code; + } + + match_special_option_and_act(args, &flags_file); + match_special_option_and_act(&java_tool_options_args, &flags_file); + match_special_option_and_act(&java_options_args, &flags_file); + settings_file_specified = (flags_file != NULL); if (IgnoreUnrecognizedVMOptions) { // uncast const to modify the flag args->ignoreUnrecognized *(jboolean*)(&args->ignoreUnrecognized) = true; + java_tool_options_args.ignoreUnrecognized = true; + java_options_args.ignoreUnrecognized = true; } // Parse specified settings file @@ -3783,16 +3808,18 @@ } if (PrintVMOptions) { - for (index = 0; index < args->nOptions; index++) { - const JavaVMOption *option = args->options + index; - if (match_option(option, "-XX:", &tail)) { - logOption(tail); - } - } + print_options(args); + print_options(&java_tool_options_args); + print_options(&java_options_args); } // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS - jint result = parse_vm_init_args(args); + jint result = + parse_vm_init_args(&java_tool_options_args, &java_options_args, args); + + // Done with the envvars + FREE_C_HEAP_ARRAY(JavaVMOption, java_tool_options_args.options); + FREE_C_HEAP_ARRAY(JavaVMOption, java_options_args.options); if (result != JNI_OK) { return result; }