1.1 --- a/src/share/vm/runtime/arguments.cpp Wed Oct 14 16:43:13 2020 +0800 1.2 +++ b/src/share/vm/runtime/arguments.cpp Wed Oct 14 17:44:48 2020 +0800 1.3 @@ -44,6 +44,9 @@ 1.4 #include "utilities/macros.hpp" 1.5 #include "utilities/stringUtils.hpp" 1.6 #include "utilities/taskqueue.hpp" 1.7 +#if INCLUDE_JFR 1.8 +#include "jfr/jfr.hpp" 1.9 +#endif 1.10 #ifdef TARGET_OS_FAMILY_linux 1.11 # include "os_linux.inline.hpp" 1.12 #endif 1.13 @@ -155,6 +158,20 @@ 1.14 } 1.15 } 1.16 1.17 +#if INCLUDE_JFR 1.18 +// return true on failure 1.19 +static bool match_jfr_option(const JavaVMOption** option) { 1.20 + assert((*option)->optionString != NULL, "invariant"); 1.21 + char* tail = NULL; 1.22 + if (match_option(*option, "-XX:StartFlightRecording", (const char**)&tail)) { 1.23 + return Jfr::on_start_flight_recording_option(option, tail); 1.24 + } else if (match_option(*option, "-XX:FlightRecorderOptions", (const char**)&tail)) { 1.25 + return Jfr::on_flight_recorder_option(option, tail); 1.26 + } 1.27 + return false; 1.28 +} 1.29 +#endif 1.30 + 1.31 static void logOption(const char* opt) { 1.32 if (PrintVMOptions) { 1.33 jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt); 1.34 @@ -3400,6 +3417,10 @@ 1.35 "ManagementServer is not supported in this VM.\n"); 1.36 return JNI_ERR; 1.37 #endif // INCLUDE_MANAGEMENT 1.38 +#if INCLUDE_JFR 1.39 + } else if (match_jfr_option(&option)) { 1.40 + return JNI_EINVAL; 1.41 +#endif 1.42 } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx 1.43 // Skip -XX:Flags= since that case has already been handled 1.44 if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) { 1.45 @@ -3455,8 +3476,7 @@ 1.46 src ++; 1.47 } 1.48 1.49 - char* copy = AllocateHeap(strlen(src) + 1, mtInternal); 1.50 - strncpy(copy, src, strlen(src) + 1); 1.51 + char* copy = os::strdup(src, mtInternal); 1.52 1.53 // trim all trailing empty paths 1.54 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) { 1.55 @@ -3835,18 +3855,14 @@ 1.56 if (end != NULL) *end = '\0'; 1.57 size_t jvm_path_len = strlen(jvm_path); 1.58 size_t file_sep_len = strlen(os::file_separator()); 1.59 - shared_archive_path = NEW_C_HEAP_ARRAY(char, jvm_path_len + 1.60 - file_sep_len + 20, mtInternal); 1.61 + const size_t len = jvm_path_len + file_sep_len + 20; 1.62 + shared_archive_path = NEW_C_HEAP_ARRAY(char, len, mtInternal); 1.63 if (shared_archive_path != NULL) { 1.64 - strncpy(shared_archive_path, jvm_path, jvm_path_len + 1); 1.65 - strncat(shared_archive_path, os::file_separator(), file_sep_len); 1.66 - strncat(shared_archive_path, "classes.jsa", 11); 1.67 + jio_snprintf(shared_archive_path, len, "%s%sclasses.jsa", 1.68 + jvm_path, os::file_separator()); 1.69 } 1.70 } else { 1.71 - shared_archive_path = NEW_C_HEAP_ARRAY(char, strlen(SharedArchiveFile) + 1, mtInternal); 1.72 - if (shared_archive_path != NULL) { 1.73 - strncpy(shared_archive_path, SharedArchiveFile, strlen(SharedArchiveFile) + 1); 1.74 - } 1.75 + shared_archive_path = os::strdup(SharedArchiveFile, mtInternal); 1.76 } 1.77 return shared_archive_path; 1.78 }