# HG changeset patch # User neliasso # Date 1543946106 -3600 # Node ID 8df9cf767f79129ef0b3ab50aae4198295b36729 # Parent f14aa990b3301b91b60918015c7f3a55be4301af 8214773: Replace use of thread unsafe strtok Reviewed-by: thartmann, dholmes diff -r f14aa990b330 -r 8df9cf767f79 src/hotspot/os/windows/os_windows.hpp --- a/src/hotspot/os/windows/os_windows.hpp Fri Dec 07 14:36:43 2018 +0530 +++ b/src/hotspot/os/windows/os_windows.hpp Tue Dec 04 18:55:06 2018 +0100 @@ -26,6 +26,9 @@ #define OS_WINDOWS_VM_OS_WINDOWS_HPP // Win32_OS defines the interface to windows operating systems +// strtok_s is the Windows thread-safe equivalent of POSIX strtok_r +#define strtok_r strtok_s + // Information about the protection of the page at address '0' on this os. static bool zero_page_read_protected() { return true; } diff -r f14aa990b330 -r 8df9cf767f79 src/hotspot/share/classfile/vmSymbols.cpp --- a/src/hotspot/share/classfile/vmSymbols.cpp Fri Dec 07 14:36:43 2018 +0530 +++ b/src/hotspot/share/classfile/vmSymbols.cpp Tue Dec 04 18:55:06 2018 +0100 @@ -473,15 +473,16 @@ // Note, DirectiveSet may not be created at this point yet since this code // is called from initial stub geenration code. char* local_list = (char*)DirectiveSet::canonicalize_disableintrinsic(DisableIntrinsic); - + char* save_ptr; bool found = false; - char* token = strtok(local_list, ","); + + char* token = strtok_r(local_list, ",", &save_ptr); while (token != NULL) { if (strcmp(token, vmIntrinsics::name_at(id)) == 0) { found = true; break; } else { - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &save_ptr); } } diff -r f14aa990b330 -r 8df9cf767f79 src/hotspot/share/compiler/compilerDirectives.cpp --- a/src/hotspot/share/compiler/compilerDirectives.cpp Fri Dec 07 14:36:43 2018 +0530 +++ b/src/hotspot/share/compiler/compilerDirectives.cpp Tue Dec 04 18:55:06 2018 +0100 @@ -398,13 +398,14 @@ size_t length = strlen(DisableIntrinsicOption); char* local_list = NEW_RESOURCE_ARRAY(char, length + 1); strncpy(local_list, DisableIntrinsicOption, length + 1); + char* save_ptr; - char* token = strtok(local_list, ","); + char* token = strtok_r(local_list, ",", &save_ptr); while (token != NULL) { if (strcmp(token, vmIntrinsics::name_at(id)) == 0) { return true; } else { - token = strtok(NULL, ","); + token = strtok_r(NULL, ",", &save_ptr); } } diff -r f14aa990b330 -r 8df9cf767f79 src/hotspot/share/gc/g1/g1Arguments.cpp --- a/src/hotspot/share/gc/g1/g1Arguments.cpp Fri Dec 07 14:36:43 2018 +0530 +++ b/src/hotspot/share/gc/g1/g1Arguments.cpp Tue Dec 04 18:55:06 2018 +0100 @@ -44,10 +44,12 @@ size_t length = strlen(VerifyGCType); char* type_list = NEW_C_HEAP_ARRAY(char, length + 1, mtInternal); strncpy(type_list, VerifyGCType, length + 1); - char* token = strtok(type_list, delimiter); + char* save_ptr; + + char* token = strtok_r(type_list, delimiter, &save_ptr); while (token != NULL) { parse_verification_type(token); - token = strtok(NULL, delimiter); + token = strtok_r(NULL, delimiter, &save_ptr); } FREE_C_HEAP_ARRAY(char, type_list); } diff -r f14aa990b330 -r 8df9cf767f79 src/hotspot/share/memory/universe.cpp --- a/src/hotspot/share/memory/universe.cpp Fri Dec 07 14:36:43 2018 +0530 +++ b/src/hotspot/share/memory/universe.cpp Tue Dec 04 18:55:06 2018 +0100 @@ -1118,8 +1118,9 @@ size_t length = strlen(VerifySubSet); char* subset_list = NEW_C_HEAP_ARRAY(char, length + 1, mtInternal); strncpy(subset_list, VerifySubSet, length + 1); + char* save_ptr; - char* token = strtok(subset_list, delimiter); + char* token = strtok_r(subset_list, delimiter, &save_ptr); while (token != NULL) { if (strcmp(token, "threads") == 0) { verify_flags |= Verify_Threads; @@ -1144,7 +1145,7 @@ } else { vm_exit_during_initialization(err_msg("VerifySubSet: \'%s\' memory sub-system is unknown, please correct it", token)); } - token = strtok(NULL, delimiter); + token = strtok_r(NULL, delimiter, &save_ptr); } FREE_C_HEAP_ARRAY(char, subset_list); }