8214773: Replace use of thread unsafe strtok

Reviewed-by: thartmann, dholmes
This commit is contained in:
Nils Eliasson 2018-12-04 18:55:06 +01:00
parent a1c8528d3f
commit 4246096355
5 changed files with 17 additions and 9 deletions
src/hotspot

@ -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; }

@ -473,15 +473,16 @@ bool vmIntrinsics::is_intrinsic_disabled(vmIntrinsics::ID id) {
// 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);
}
}

@ -398,13 +398,14 @@ bool DirectiveSet::is_intrinsic_disabled(const methodHandle& method) {
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);
}
}

@ -44,10 +44,12 @@ void G1Arguments::initialize_verification_types() {
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);
}

@ -1118,8 +1118,9 @@ void Universe::initialize_verify_flags() {
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 @@ void Universe::initialize_verify_flags() {
} 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);
}