--- old/src/os/aix/vm/os_aix.cpp 2015-03-26 02:34:04.726149025 -0400 +++ new/src/os/aix/vm/os_aix.cpp 2015-03-26 02:34:03.674089837 -0400 @@ -257,19 +257,6 @@ return Aix::physical_memory(); } -//////////////////////////////////////////////////////////////////////////////// -// environment support - -bool os::getenv(const char* name, char* buf, int len) { - const char* val = ::getenv(name); - if (val != NULL && strlen(val) < (size_t)len) { - strcpy(buf, val); - return true; - } - if (len > 0) buf[0] = 0; // return a null string - return false; -} - // Return true if user is running as root. bool os::have_special_privileges() { --- old/src/os/bsd/vm/os_bsd.cpp 2015-03-26 02:34:08.070337166 -0400 +++ new/src/os/bsd/vm/os_bsd.cpp 2015-03-26 02:34:07.026278428 -0400 @@ -190,20 +190,6 @@ return Bsd::physical_memory(); } -//////////////////////////////////////////////////////////////////////////////// -// environment support - -bool os::getenv(const char* name, char* buf, int len) { - const char* val = ::getenv(name); - if (val != NULL && strlen(val) < (size_t)len) { - strcpy(buf, val); - return true; - } - if (len > 0) buf[0] = 0; // return a null string - return false; -} - - // Return true if user is running as root. bool os::have_special_privileges() { --- old/src/os/linux/vm/os_linux.cpp 2015-03-26 02:34:11.594535434 -0400 +++ new/src/os/linux/vm/os_linux.cpp 2015-03-26 02:34:10.506474220 -0400 @@ -184,20 +184,6 @@ return Linux::physical_memory(); } -//////////////////////////////////////////////////////////////////////////////// -// environment support - -bool os::getenv(const char* name, char* buf, int len) { - const char* val = ::getenv(name); - if (val != NULL && strlen(val) < (size_t)len) { - strcpy(buf, val); - return true; - } - if (len > 0) buf[0] = 0; // return a null string - return false; -} - - // Return true if user is running as root. bool os::have_special_privileges() { --- old/src/os/solaris/vm/os_solaris.cpp 2015-03-26 02:34:15.118733702 -0400 +++ new/src/os/solaris/vm/os_solaris.cpp 2015-03-26 02:34:13.974669338 -0400 @@ -555,17 +555,6 @@ return (bind_result == 0); } -bool os::getenv(const char* name, char* buffer, int len) { - char* val = ::getenv(name); - if (val == NULL || strlen(val) + 1 > len) { - if (len > 0) buffer[0] = 0; // return a null string - return false; - } - strcpy(buffer, val); - return true; -} - - // Return true if user is running as root. bool os::have_special_privileges() { --- old/src/os/windows/vm/os_windows.cpp 2015-03-26 02:34:18.578928372 -0400 +++ new/src/os/windows/vm/os_windows.cpp 2015-03-26 02:34:17.510868279 -0400 @@ -153,11 +153,6 @@ // Implementation of os -bool os::getenv(const char* name, char* buffer, int len) { - int result = GetEnvironmentVariable(name, buffer, len); - return result > 0 && result < len; -} - bool os::unsetenv(const char* name) { assert(name != NULL, "Null pointer"); return (SetEnvironmentVariable(name, NULL) == TRUE); @@ -188,9 +183,13 @@ char *dll_path; char *pslash; char *bin = "\\bin"; - char home_dir[MAX_PATH]; + char home_dir[MAX_PATH + 1]; + char *alt_home_dir = ::getenv("_ALT_JAVA_HOME_DIR"); - if (!getenv("_ALT_JAVA_HOME_DIR", home_dir, MAX_PATH)) { + if (alt_home_dir != NULL) { + strncpy(home_dir, alt_home_dir, MAX_PATH + 1); + home_dir[MAX_PATH] = '\0'; + } else { os::jvm_path(home_dir, sizeof(home_dir)); // Found the full path to jvm.dll. // Now cut the path to /jre if we can. @@ -5930,4 +5929,3 @@ UseNUMAInterleaving = old_use_numa_interleaving; } #endif // PRODUCT - --- old/src/share/vm/runtime/arguments.cpp 2015-03-26 02:34:22.223133388 -0400 +++ new/src/share/vm/runtime/arguments.cpp 2015-03-26 02:34:21.051067449 -0400 @@ -3462,15 +3462,16 @@ if (os::is_headless_jre()) { const char* headless = Arguments::get_property("java.awt.headless"); if (headless == NULL) { - char envbuffer[128]; - if (!os::getenv("JAVA_AWT_HEADLESS", envbuffer, sizeof(envbuffer))) { + const char *headless_env = ::getenv("JAVA_AWT_HEADLESS"); + if (headless_env == NULL) { if (!add_property("java.awt.headless=true")) { return JNI_ENOMEM; } } else { char buffer[256]; - strcpy(buffer, "java.awt.headless="); - strcat(buffer, envbuffer); + const char *key = "java.awt.headless="; + strcpy(buffer, key); + strncat(buffer, headless_env, 256 - strlen(key) - 1); if (!add_property(buffer)) { return JNI_ENOMEM; } @@ -3501,75 +3502,91 @@ } jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) { - const int N_MAX_OPTIONS = 64; - const int OPTION_BUFFER_SIZE = 1024; - char buffer[OPTION_BUFFER_SIZE]; + char *buffer = ::getenv(name); - // The variable will be ignored if it exceeds the length of the buffer. // Don't check this variable if user has special privileges // (e.g. unix su command). - if (os::getenv(name, buffer, sizeof(buffer)) && - !os::have_special_privileges()) { - JavaVMOption options[N_MAX_OPTIONS]; // Construct option array - jio_fprintf(defaultStream::error_stream(), - "Picked up %s: %s\n", name, buffer); - char* rd = buffer; // pointer to the input string (rd) - int i; - for (i = 0; i < N_MAX_OPTIONS;) { // repeat for all options in the input string - while (isspace(*rd)) rd++; // skip whitespace - if (*rd == 0) break; // we re done when the input string is read completely - - // The output, option string, overwrites the input string. - // Because of quoting, the pointer to the option string (wrt) may lag the pointer to - // input string (rd). - char* wrt = rd; - - options[i++].optionString = wrt; // Fill in option - while (*rd != 0 && !isspace(*rd)) { // unquoted strings terminate with a space or NULL - if (*rd == '\'' || *rd == '"') { // handle a quoted string - int quote = *rd; // matching quote to look for - rd++; // don't copy open quote - while (*rd != quote) { // include everything (even spaces) up until quote - if (*rd == 0) { // string termination means unmatched string - jio_fprintf(defaultStream::error_stream(), - "Unmatched quote in %s\n", name); - return JNI_ERR; - } - *wrt++ = *rd++; // copy to option string + if (buffer == NULL || os::have_special_privileges()) { + return JNI_OK; + } + + if ((buffer = os::strdup(buffer)) == NULL) { + return JNI_ENOMEM; + } + + GrowableArray options(2, true); // Construct option array + jio_fprintf(defaultStream::error_stream(), + "Picked up %s: %s\n", name, buffer); + char* rd = buffer; // pointer to the input string (rd) + while (true) { // repeat for all options in the input string + while (isspace(*rd)) rd++; // skip whitespace + if (*rd == 0) break; // we re done when the input string is read completely + + // The output, option string, overwrites the input string. + // Because of quoting, the pointer to the option string (wrt) may lag the pointer to + // input string (rd). + char* wrt = rd; + + JavaVMOption option; + option.optionString = wrt; + options.append(option); // Fill in option + while (*rd != 0 && !isspace(*rd)) { // unquoted strings terminate with a space or NULL + if (*rd == '\'' || *rd == '"') { // handle a quoted string + int quote = *rd; // matching quote to look for + rd++; // don't copy open quote + while (*rd != quote) { // include everything (even spaces) up until quote + if (*rd == 0) { // string termination means unmatched string + jio_fprintf(defaultStream::error_stream(), + "Unmatched quote in %s\n", name); + os::free(buffer); + return JNI_ERR; } - rd++; // don't copy close quote - } else { - *wrt++ = *rd++; // copy to option string + *wrt++ = *rd++; // copy to option string } + rd++; // don't copy close quote + } else { + *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; - } - *wrt = 0; // Zero terminate option } - // 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; - vm_args.nOptions = i; - 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); - } - } + // 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; } + *wrt = 0; // Zero terminate option + } + JavaVMOption* options_arr = + NEW_C_HEAP_ARRAY_RETURN_NULL(JavaVMOption, options.length(), mtInternal); + if (options_arr == NULL) { + return JNI_ENOMEM; + } + for (int i = 0; i < options.length(); i++) { + options_arr[i] = options.at(i); + } - return(parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, Flag::ENVIRON_VAR)); + // 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); + } + } } - return JNI_OK; + + 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); + os::free(buffer); + return result; } void Arguments::set_shared_spaces_flags() { --- old/src/share/vm/runtime/os.cpp 2015-03-26 02:34:25.663326930 -0400 +++ new/src/share/vm/runtime/os.cpp 2015-03-26 02:34:24.611267742 -0400 @@ -813,16 +813,16 @@ st->cr(); } -void os::print_environment_variables(outputStream* st, const char** env_list, - char* buffer, int len) { +void os::print_environment_variables(outputStream* st, const char** env_list) { if (env_list) { st->print_cr("Environment Variables:"); for (int i = 0; env_list[i] != NULL; i++) { - if (getenv(env_list[i], buffer, len)) { + char *envvar = ::getenv(env_list[i]); + if (envvar != NULL) { st->print("%s", env_list[i]); st->print("="); - st->print_cr("%s", buffer); + st->print_cr("%s", envvar); } } } --- old/src/share/vm/runtime/os.hpp 2015-03-26 02:34:29.019515745 -0400 +++ new/src/share/vm/runtime/os.hpp 2015-03-26 02:34:27.975457008 -0400 @@ -164,8 +164,7 @@ // Override me as needed static int file_name_strcmp(const char* s1, const char* s2); - // get/unset environment variable - static bool getenv(const char* name, char* buffer, int len); + // unset environment variable static bool unsetenv(const char* name); static bool have_special_privileges(); @@ -591,7 +590,7 @@ static void pd_print_cpu_info(outputStream* st); static void print_memory_info(outputStream* st); static void print_dll_info(outputStream* st); - static void print_environment_variables(outputStream* st, const char** env_list, char* buffer, int len); + static void print_environment_variables(outputStream* st, const char** env_list); static void print_context(outputStream* st, void* context); static void print_register_info(outputStream* st, void* context); static void print_siginfo(outputStream* st, void* siginfo); --- old/src/share/vm/services/memTracker.cpp 2015-03-26 02:34:32.387705236 -0400 +++ new/src/share/vm/services/memTracker.cpp 2015-03-26 02:34:31.335646048 -0400 @@ -47,9 +47,9 @@ NMT_TrackingLevel MemTracker::init_tracking_level() { NMT_TrackingLevel level = NMT_off; char buf[64]; - char nmt_option[64]; jio_snprintf(buf, sizeof(buf), "NMT_LEVEL_%d", os::current_process_id()); - if (os::getenv(buf, nmt_option, sizeof(nmt_option))) { + const char *nmt_option = ::getenv(buf); + if (nmt_option != NULL) { if (strcmp(nmt_option, "summary") == 0) { level = NMT_summary; } else if (strcmp(nmt_option, "detail") == 0) { @@ -311,4 +311,3 @@ out->print_cr(" "); walker.report_statistics(out); } - --- old/src/share/vm/utilities/growableArray.hpp 2015-03-26 02:34:35.715892476 -0400 +++ new/src/share/vm/utilities/growableArray.hpp 2015-03-26 02:34:34.663833288 -0400 @@ -168,6 +168,8 @@ GrowableArray(int initial_size, bool C_heap = false, MEMFLAGS F = mtInternal) : GenericGrowableArray(initial_size, 0, C_heap, F) { _data = (E*)raw_allocate(sizeof(E)); +// Needed for Visual Studio 2012 and older +#pragma warning(suppress: 4345) for (int i = 0; i < _max; i++) ::new ((void*)&_data[i]) E(); } @@ -385,6 +387,8 @@ E* newData = (E*)raw_allocate(sizeof(E)); int i = 0; for ( ; i < _len; i++) ::new ((void*)&newData[i]) E(_data[i]); +// Needed for Visual Studio 2012 and older +#pragma warning(suppress: 4345) for ( ; i < _max; i++) ::new ((void*)&newData[i]) E(); for (i = 0; i < old_max; i++) _data[i].~E(); if (on_C_heap() && _data != NULL) { --- old/src/share/vm/utilities/vmError.cpp 2015-03-26 02:34:39.048079940 -0400 +++ new/src/share/vm/utilities/vmError.cpp 2015-03-26 02:34:37.992020528 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -768,7 +768,7 @@ STEP(220, "(printing environment variables)" ) if (_verbose) { - os::print_environment_variables(st, env_list, buf, sizeof(buf)); + os::print_environment_variables(st, env_list); st->cr(); }