8214773: Replace use of thread unsafe strtok
Reviewed-by: thartmann, dholmes
diff --git a/src/hotspot/os/windows/os_windows.hpp b/src/hotspot/os/windows/os_windows.hpp
index 9d58e74..644582d 100644
--- a/src/hotspot/os/windows/os_windows.hpp
+++ b/src/hotspot/os/windows/os_windows.hpp
@@ -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 --git a/src/hotspot/share/classfile/vmSymbols.cpp b/src/hotspot/share/classfile/vmSymbols.cpp
index f453885..1def05a 100644
--- a/src/hotspot/share/classfile/vmSymbols.cpp
+++ b/src/hotspot/share/classfile/vmSymbols.cpp
@@ -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 --git a/src/hotspot/share/compiler/compilerDirectives.cpp b/src/hotspot/share/compiler/compilerDirectives.cpp
index 6488463..5040a3a 100644
--- a/src/hotspot/share/compiler/compilerDirectives.cpp
+++ b/src/hotspot/share/compiler/compilerDirectives.cpp
@@ -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 --git a/src/hotspot/share/gc/g1/g1Arguments.cpp b/src/hotspot/share/gc/g1/g1Arguments.cpp
index af3d0b8..93799b0 100644
--- a/src/hotspot/share/gc/g1/g1Arguments.cpp
+++ b/src/hotspot/share/gc/g1/g1Arguments.cpp
@@ -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 --git a/src/hotspot/share/memory/universe.cpp b/src/hotspot/share/memory/universe.cpp
index b24a95b..49aadd1 100644
--- a/src/hotspot/share/memory/universe.cpp
+++ b/src/hotspot/share/memory/universe.cpp
@@ -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);
}