From 76168a85c979658f18075f53ff14770ff09e9eff Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 17 Jun 2019 16:41:38 +0100 Subject: [PATCH] 8202353: os::readdir should use readdir instead of readdir_r Summary: Summary: os::readdir uses POSIX readdir, drop buffer arg, fix JFR uses. Reviewed-by: coleenp, tschatzl, bsrbnd, shade, phh --- src/os/aix/vm/os_aix.cpp | 3 +- src/os/aix/vm/os_aix.inline.hpp | 35 ------------------------ src/os/aix/vm/perfMemory_aix.cpp | 13 ++------- src/os/bsd/vm/os_bsd.cpp | 3 +- src/os/bsd/vm/os_bsd.inline.hpp | 33 ---------------------- src/os/bsd/vm/perfMemory_bsd.cpp | 13 ++------- src/os/linux/vm/os_linux.cpp | 3 +- src/os/linux/vm/os_linux.inline.hpp | 33 ---------------------- src/os/linux/vm/perfMemory_linux.cpp | 14 ++-------- src/os/posix/vm/os_posix.cpp | 15 ++++++++++ src/os/solaris/vm/os_solaris.cpp | 4 +-- src/os/solaris/vm/os_solaris.inline.hpp | 31 --------------------- src/os/solaris/vm/perfMemory_solaris.cpp | 13 ++------- src/os/windows/vm/os_windows.cpp | 8 ++---- src/os/windows/vm/os_windows.inline.hpp | 8 ------ src/os/windows/vm/perfMemory_windows.cpp | 12 ++------ src/share/vm/runtime/arguments.cpp | 12 ++------ src/share/vm/runtime/os.hpp | 3 +- 18 files changed, 41 insertions(+), 215 deletions(-) diff --git a/src/os/aix/vm/os_aix.cpp b/src/os/aix/vm/os_aix.cpp index b03ce2458..717f692c2 100644 --- a/src/os/aix/vm/os_aix.cpp +++ b/src/os/aix/vm/os_aix.cpp @@ -4184,8 +4184,7 @@ bool os::dir_is_empty(const char* path) { /* Scan the directory */ bool result = true; - char buf[sizeof(struct dirent) + MAX_PATH]; - while (result && (ptr = ::readdir(dir)) != NULL) { + while (result && (ptr = readdir(dir)) != NULL) { if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) { result = false; } diff --git a/src/os/aix/vm/os_aix.inline.hpp b/src/os/aix/vm/os_aix.inline.hpp index a97c94c07..421ea342e 100644 --- a/src/os/aix/vm/os_aix.inline.hpp +++ b/src/os/aix/vm/os_aix.inline.hpp @@ -92,19 +92,6 @@ inline void os::dll_unload(void *lib) { inline const int os::default_file_open_flags() { return 0;} -inline DIR* os::opendir(const char* dirname) -{ - assert(dirname != NULL, "just checking"); - return ::opendir(dirname); -} - -inline int os::readdir_buf_size(const char *path) -{ - // according to aix sys/limits, NAME_MAX must be retrieved at runtime. */ - const long my_NAME_MAX = pathconf(path, _PC_NAME_MAX); - return my_NAME_MAX + sizeof(dirent) + 1; -} - inline jlong os::lseek(int fd, jlong offset, int whence) { return (jlong) ::lseek64(fd, offset, whence); } @@ -121,28 +108,6 @@ inline int os::ftruncate(int fd, jlong length) { return ::ftruncate64(fd, length); } -inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf) -{ - dirent* p; - int status; - assert(dirp != NULL, "just checking"); - - // NOTE: Linux readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX - // version. Here is the doc for this function: - // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html - - if((status = ::readdir_r(dirp, dbuf, &p)) != 0) { - errno = status; - return NULL; - } else - return p; -} - -inline int os::closedir(DIR *dirp) { - assert(dirp != NULL, "argument is NULL"); - return ::closedir(dirp); -} - // macros for restartable system calls #define RESTARTABLE(_cmd, _result) do { \ diff --git a/src/os/aix/vm/perfMemory_aix.cpp b/src/os/aix/vm/perfMemory_aix.cpp index 96f8451d2..80ae9e7a8 100644 --- a/src/os/aix/vm/perfMemory_aix.cpp +++ b/src/os/aix/vm/perfMemory_aix.cpp @@ -612,9 +612,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { // to determine the user name for the process id. // struct dirent* dentry; - char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal); errno = 0; - while ((dentry = os::readdir(tmpdirp, (struct dirent *)tdbuf)) != NULL) { + while ((dentry = os::readdir(tmpdirp)) != NULL) { // check if the directory entry is a hsperfdata file if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) { @@ -648,9 +647,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { } struct dirent* udentry; - char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal); errno = 0; - while ((udentry = os::readdir(subdirp, (struct dirent *)udbuf)) != NULL) { + while ((udentry = os::readdir(subdirp)) != NULL) { if (filename_to_pid(udentry->d_name) == vmid) { struct stat statbuf; @@ -694,11 +692,9 @@ static char* get_user_name_slow(int vmid, TRAPS) { } } os::closedir(subdirp); - FREE_C_HEAP_ARRAY(char, udbuf, mtInternal); FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); } os::closedir(tmpdirp); - FREE_C_HEAP_ARRAY(char, tdbuf, mtInternal); return(oldest_user); } @@ -774,10 +770,8 @@ static void cleanup_sharedmem_resources(const char* dirname) { // loop under these conditions is dependent upon the implementation of // opendir/readdir. struct dirent* entry; - char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal); - errno = 0; - while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) { + while ((entry = os::readdir(dirp)) != NULL) { pid_t pid = filename_to_pid(entry->d_name); @@ -816,7 +810,6 @@ static void cleanup_sharedmem_resources(const char* dirname) { // Close the directory and reset the current working directory. close_directory_secure_cwd(dirp, saved_cwd_fd); - FREE_C_HEAP_ARRAY(char, dbuf, mtInternal); } // Make the user specific temporary directory. Returns true if diff --git a/src/os/bsd/vm/os_bsd.cpp b/src/os/bsd/vm/os_bsd.cpp index 99a039988..1c0336edd 100644 --- a/src/os/bsd/vm/os_bsd.cpp +++ b/src/os/bsd/vm/os_bsd.cpp @@ -3957,8 +3957,7 @@ bool os::dir_is_empty(const char* path) { /* Scan the directory */ bool result = true; - char buf[sizeof(struct dirent) + MAX_PATH]; - while (result && (ptr = ::readdir(dir)) != NULL) { + while (result && (ptr = readdir(dir)) != NULL) { if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) { result = false; } diff --git a/src/os/bsd/vm/os_bsd.inline.hpp b/src/os/bsd/vm/os_bsd.inline.hpp index 10b39941d..c35abf486 100644 --- a/src/os/bsd/vm/os_bsd.inline.hpp +++ b/src/os/bsd/vm/os_bsd.inline.hpp @@ -95,17 +95,6 @@ inline void os::dll_unload(void *lib) { inline const int os::default_file_open_flags() { return 0;} -inline DIR* os::opendir(const char* dirname) -{ - assert(dirname != NULL, "just checking"); - return ::opendir(dirname); -} - -inline int os::readdir_buf_size(const char *path) -{ - return NAME_MAX + sizeof(dirent) + 1; -} - inline jlong os::lseek(int fd, jlong offset, int whence) { return (jlong) ::lseek(fd, offset, whence); } @@ -122,28 +111,6 @@ inline int os::ftruncate(int fd, jlong length) { return ::ftruncate(fd, length); } -inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf) -{ - dirent* p; - int status; - assert(dirp != NULL, "just checking"); - - // NOTE: Bsd readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX - // version. Here is the doc for this function: - // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html - - if((status = ::readdir_r(dirp, dbuf, &p)) != 0) { - errno = status; - return NULL; - } else - return p; -} - -inline int os::closedir(DIR *dirp) { - assert(dirp != NULL, "argument is NULL"); - return ::closedir(dirp); -} - // macros for restartable system calls #define RESTARTABLE(_cmd, _result) do { \ diff --git a/src/os/bsd/vm/perfMemory_bsd.cpp b/src/os/bsd/vm/perfMemory_bsd.cpp index df4fca613..802d0908f 100644 --- a/src/os/bsd/vm/perfMemory_bsd.cpp +++ b/src/os/bsd/vm/perfMemory_bsd.cpp @@ -533,9 +533,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { // to determine the user name for the process id. // struct dirent* dentry; - char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal); errno = 0; - while ((dentry = os::readdir(tmpdirp, (struct dirent *)tdbuf)) != NULL) { + while ((dentry = os::readdir(tmpdirp)) != NULL) { // check if the directory entry is a hsperfdata file if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) { @@ -557,9 +556,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { } struct dirent* udentry; - char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal); errno = 0; - while ((udentry = os::readdir(subdirp, (struct dirent *)udbuf)) != NULL) { + while ((udentry = os::readdir(subdirp)) != NULL) { if (filename_to_pid(udentry->d_name) == vmid) { struct stat statbuf; @@ -603,11 +601,9 @@ static char* get_user_name_slow(int vmid, TRAPS) { } } os::closedir(subdirp); - FREE_C_HEAP_ARRAY(char, udbuf, mtInternal); FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); } os::closedir(tmpdirp); - FREE_C_HEAP_ARRAY(char, tdbuf, mtInternal); return(oldest_user); } @@ -686,10 +682,8 @@ static void cleanup_sharedmem_resources(const char* dirname) { // opendir/readdir. // struct dirent* entry; - char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal); - errno = 0; - while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) { + while ((entry = os::readdir(dirp)) != NULL) { pid_t pid = filename_to_pid(entry->d_name); @@ -729,7 +723,6 @@ static void cleanup_sharedmem_resources(const char* dirname) { // close the directory and reset the current working directory close_directory_secure_cwd(dirp, saved_cwd_fd); - FREE_C_HEAP_ARRAY(char, dbuf, mtInternal); } // make the user specific temporary directory. Returns true if diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp index a499e499e..03cabfefb 100644 --- a/src/os/linux/vm/os_linux.cpp +++ b/src/os/linux/vm/os_linux.cpp @@ -5501,8 +5501,7 @@ bool os::dir_is_empty(const char* path) { /* Scan the directory */ bool result = true; - char buf[sizeof(struct dirent) + MAX_PATH]; - while (result && (ptr = ::readdir(dir)) != NULL) { + while (result && (ptr = readdir(dir)) != NULL) { if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) { result = false; } diff --git a/src/os/linux/vm/os_linux.inline.hpp b/src/os/linux/vm/os_linux.inline.hpp index 10d56d89f..a23bd5631 100644 --- a/src/os/linux/vm/os_linux.inline.hpp +++ b/src/os/linux/vm/os_linux.inline.hpp @@ -87,17 +87,6 @@ inline void os::dll_unload(void *lib) { inline const int os::default_file_open_flags() { return 0;} -inline DIR* os::opendir(const char* dirname) -{ - assert(dirname != NULL, "just checking"); - return ::opendir(dirname); -} - -inline int os::readdir_buf_size(const char *path) -{ - return NAME_MAX + sizeof(dirent) + 1; -} - inline jlong os::lseek(int fd, jlong offset, int whence) { return (jlong) ::lseek64(fd, offset, whence); } @@ -114,28 +103,6 @@ inline int os::ftruncate(int fd, jlong length) { return ::ftruncate64(fd, length); } -inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf) -{ - dirent* p; - int status; - assert(dirp != NULL, "just checking"); - - // NOTE: Linux readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX - // version. Here is the doc for this function: - // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html - - if((status = ::readdir_r(dirp, dbuf, &p)) != 0) { - errno = status; - return NULL; - } else - return p; -} - -inline int os::closedir(DIR *dirp) { - assert(dirp != NULL, "argument is NULL"); - return ::closedir(dirp); -} - // macros for restartable system calls #define RESTARTABLE(_cmd, _result) do { \ diff --git a/src/os/linux/vm/perfMemory_linux.cpp b/src/os/linux/vm/perfMemory_linux.cpp index 4143f655a..8293b7168 100644 --- a/src/os/linux/vm/perfMemory_linux.cpp +++ b/src/os/linux/vm/perfMemory_linux.cpp @@ -533,9 +533,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { // to determine the user name for the process id. // struct dirent* dentry; - char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal); errno = 0; - while ((dentry = os::readdir(tmpdirp, (struct dirent *)tdbuf)) != NULL) { + while ((dentry = os::readdir(tmpdirp)) != NULL) { // check if the directory entry is a hsperfdata file if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) { @@ -569,9 +568,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { } struct dirent* udentry; - char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal); errno = 0; - while ((udentry = os::readdir(subdirp, (struct dirent *)udbuf)) != NULL) { + while ((udentry = os::readdir(subdirp)) != NULL) { if (filename_to_pid(udentry->d_name) == vmid) { struct stat statbuf; @@ -615,11 +613,9 @@ static char* get_user_name_slow(int vmid, TRAPS) { } } os::closedir(subdirp); - FREE_C_HEAP_ARRAY(char, udbuf, mtInternal); FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); } os::closedir(tmpdirp); - FREE_C_HEAP_ARRAY(char, tdbuf, mtInternal); return(oldest_user); } @@ -698,10 +694,8 @@ static void cleanup_sharedmem_resources(const char* dirname) { // opendir/readdir. // struct dirent* entry; - char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal); - errno = 0; - while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) { + while ((entry = os::readdir(dirp)) != NULL) { pid_t pid = filename_to_pid(entry->d_name); @@ -738,8 +732,6 @@ static void cleanup_sharedmem_resources(const char* dirname) { // close the directory and reset the current working directory close_directory_secure_cwd(dirp, saved_cwd_fd); - - FREE_C_HEAP_ARRAY(char, dbuf, mtInternal); } // make the user specific temporary directory. Returns true if diff --git a/src/os/posix/vm/os_posix.cpp b/src/os/posix/vm/os_posix.cpp index 534b19258..a43a855b2 100644 --- a/src/os/posix/vm/os_posix.cpp +++ b/src/os/posix/vm/os_posix.cpp @@ -302,6 +302,21 @@ FILE* os::open(int fd, const char* mode) { return ::fdopen(fd, mode); } +DIR* os::opendir(const char* dirname) { + assert(dirname != NULL, "just checking"); + return ::opendir(dirname); +} + +struct dirent* os::readdir(DIR* dirp) { + assert(dirp != NULL, "just checking"); + return ::readdir(dirp); +} + +int os::closedir(DIR *dirp) { + assert(dirp != NULL, "just checking"); + return ::closedir(dirp); +} + // Builds a platform dependent Agent_OnLoad_ function name // which is used to find statically linked in agents. // Parameters: diff --git a/src/os/solaris/vm/os_solaris.cpp b/src/os/solaris/vm/os_solaris.cpp index 014a6d37a..6956f63d9 100644 --- a/src/os/solaris/vm/os_solaris.cpp +++ b/src/os/solaris/vm/os_solaris.cpp @@ -5163,9 +5163,7 @@ bool os::dir_is_empty(const char* path) { /* Scan the directory */ bool result = true; - char buf[sizeof(struct dirent) + MAX_PATH]; - struct dirent *dbuf = (struct dirent *) buf; - while (result && (ptr = readdir(dir, dbuf)) != NULL) { + while (result && (ptr = readdir(dir)) != NULL) { if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) { result = false; } diff --git a/src/os/solaris/vm/os_solaris.inline.hpp b/src/os/solaris/vm/os_solaris.inline.hpp index 921fcf7c0..8e095ab69 100644 --- a/src/os/solaris/vm/os_solaris.inline.hpp +++ b/src/os/solaris/vm/os_solaris.inline.hpp @@ -71,37 +71,6 @@ inline void os::bang_stack_shadow_pages() { } inline void os::dll_unload(void *lib) { ::dlclose(lib); } -inline DIR* os::opendir(const char* dirname) { - assert(dirname != NULL, "just checking"); - return ::opendir(dirname); -} - -inline int os::readdir_buf_size(const char *path) { - int size = pathconf(path, _PC_NAME_MAX); - return (size < 0 ? MAXPATHLEN : size) + sizeof(dirent) + 1; -} - -inline struct dirent* os::readdir(DIR* dirp, dirent* dbuf) { - assert(dirp != NULL, "just checking"); -#if defined(_LP64) || defined(_GNU_SOURCE) || _FILE_OFFSET_BITS==64 - dirent* p; - int status; - - if((status = ::readdir_r(dirp, dbuf, &p)) != 0) { - errno = status; - return NULL; - } else - return p; -#else // defined(_LP64) || defined(_GNU_SOURCE) || _FILE_OFFSET_BITS==64 - return ::readdir_r(dirp, dbuf); -#endif // defined(_LP64) || defined(_GNU_SOURCE) || _FILE_OFFSET_BITS==64 -} - -inline int os::closedir(DIR *dirp) { - assert(dirp != NULL, "argument is NULL"); - return ::closedir(dirp); -} - ////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// diff --git a/src/os/solaris/vm/perfMemory_solaris.cpp b/src/os/solaris/vm/perfMemory_solaris.cpp index 7c6f61604..8af1b2441 100644 --- a/src/os/solaris/vm/perfMemory_solaris.cpp +++ b/src/os/solaris/vm/perfMemory_solaris.cpp @@ -524,9 +524,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { // to determine the user name for the process id. // struct dirent* dentry; - char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal); errno = 0; - while ((dentry = os::readdir(tmpdirp, (struct dirent *)tdbuf)) != NULL) { + while ((dentry = os::readdir(tmpdirp)) != NULL) { // check if the directory entry is a hsperfdata file if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) { @@ -560,9 +559,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { } struct dirent* udentry; - char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal); errno = 0; - while ((udentry = os::readdir(subdirp, (struct dirent *)udbuf)) != NULL) { + while ((udentry = os::readdir(subdirp)) != NULL) { if (filename_to_pid(udentry->d_name) == vmid) { struct stat statbuf; @@ -606,11 +604,9 @@ static char* get_user_name_slow(int vmid, TRAPS) { } } os::closedir(subdirp); - FREE_C_HEAP_ARRAY(char, udbuf, mtInternal); FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); } os::closedir(tmpdirp); - FREE_C_HEAP_ARRAY(char, tdbuf, mtInternal); return(oldest_user); } @@ -737,10 +733,8 @@ static void cleanup_sharedmem_resources(const char* dirname) { // opendir/readdir. // struct dirent* entry; - char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal); - errno = 0; - while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) { + while ((entry = os::readdir(dirp)) != NULL) { pid_t pid = filename_to_pid(entry->d_name); @@ -780,7 +774,6 @@ static void cleanup_sharedmem_resources(const char* dirname) { // close the directory and reset the current working directory close_directory_secure_cwd(dirp, saved_cwd_fd); - FREE_C_HEAP_ARRAY(char, dbuf, mtInternal); } // make the user specific temporary directory. Returns true if diff --git a/src/os/windows/vm/os_windows.cpp b/src/os/windows/vm/os_windows.cpp index 2aca06d56..06eebde00 100644 --- a/src/os/windows/vm/os_windows.cpp +++ b/src/os/windows/vm/os_windows.cpp @@ -1172,14 +1172,12 @@ os::opendir(const char *dirname) return dirp; } -/* parameter dbuf unused on Windows */ - struct dirent * -os::readdir(DIR *dirp, dirent *dbuf) +os::readdir(DIR *dirp) { assert(dirp != NULL, "just checking"); // hotspot change if (dirp->handle == INVALID_HANDLE_VALUE) { - return 0; + return NULL; } strcpy(dirp->dirent.d_name, dirp->find_data.cFileName); @@ -1187,7 +1185,7 @@ os::readdir(DIR *dirp, dirent *dbuf) if (!FindNextFile(dirp->handle, &dirp->find_data)) { if (GetLastError() == ERROR_INVALID_HANDLE) { errno = EBADF; - return 0; + return NULL; } FindClose(dirp->handle); dirp->handle = INVALID_HANDLE_VALUE; diff --git a/src/os/windows/vm/os_windows.inline.hpp b/src/os/windows/vm/os_windows.inline.hpp index 30ce4682e..5dac11c90 100644 --- a/src/os/windows/vm/os_windows.inline.hpp +++ b/src/os/windows/vm/os_windows.inline.hpp @@ -65,14 +65,6 @@ inline bool os::allocate_stack_guard_pages() { return true; } -inline int os::readdir_buf_size(const char *path) -{ - /* As Windows doesn't use the directory entry buffer passed to - os::readdir() this can be as short as possible */ - - return 1; -} - // Bang the shadow pages if they need to be touched to be mapped. inline void os::bang_stack_shadow_pages() { // Write to each page of our new frame to force OS mapping. diff --git a/src/os/windows/vm/perfMemory_windows.cpp b/src/os/windows/vm/perfMemory_windows.cpp index b32fd9a15..c4cf8c1d5 100644 --- a/src/os/windows/vm/perfMemory_windows.cpp +++ b/src/os/windows/vm/perfMemory_windows.cpp @@ -316,9 +316,8 @@ static char* get_user_name_slow(int vmid) { // to determine the user name for the process id. // struct dirent* dentry; - char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal); errno = 0; - while ((dentry = os::readdir(tmpdirp, (struct dirent *)tdbuf)) != NULL) { + while ((dentry = os::readdir(tmpdirp)) != NULL) { // check if the directory entry is a hsperfdata file if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) { @@ -351,9 +350,8 @@ static char* get_user_name_slow(int vmid) { } struct dirent* udentry; - char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal); errno = 0; - while ((udentry = os::readdir(subdirp, (struct dirent *)udbuf)) != NULL) { + while ((udentry = os::readdir(subdirp)) != NULL) { if (filename_to_pid(udentry->d_name) == vmid) { struct stat statbuf; @@ -405,11 +403,9 @@ static char* get_user_name_slow(int vmid) { } } os::closedir(subdirp); - FREE_C_HEAP_ARRAY(char, udbuf, mtInternal); FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); } os::closedir(tmpdirp); - FREE_C_HEAP_ARRAY(char, tdbuf, mtInternal); return(latest_user); } @@ -639,9 +635,8 @@ static void cleanup_sharedmem_resources(const char* dirname) { // opendir/readdir. // struct dirent* entry; - char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal); errno = 0; - while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) { + while ((entry = os::readdir(dirp)) != NULL) { int pid = filename_to_pid(entry->d_name); @@ -682,7 +677,6 @@ static void cleanup_sharedmem_resources(const char* dirname) { errno = 0; } os::closedir(dirp); - FREE_C_HEAP_ARRAY(char, dbuf, mtInternal); } // create a file mapping object with the requested name, and size diff --git a/src/share/vm/runtime/arguments.cpp b/src/share/vm/runtime/arguments.cpp index 43e31d224..2665b6b8c 100644 --- a/src/share/vm/runtime/arguments.cpp +++ b/src/share/vm/runtime/arguments.cpp @@ -556,8 +556,7 @@ char* SysClassPath::add_jars_to_path(char* path, const char* directory) { /* Scan the directory for jars/zips, appending them to path. */ struct dirent *entry; - char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal); - while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) { + while ((entry = os::readdir(dir)) != NULL) { const char* name = entry->d_name; const char* ext = name + strlen(name) - 4; bool isJarOrZip = ext > name && @@ -571,7 +570,6 @@ char* SysClassPath::add_jars_to_path(char* path, const char* directory) { FREE_C_HEAP_ARRAY(char, jarpath, mtInternal); } } - FREE_C_HEAP_ARRAY(char, dbuf, mtInternal); os::closedir(dir); return path; } @@ -3485,14 +3483,12 @@ static bool has_jar_files(const char* directory) { if (dir == NULL) return false; struct dirent *entry; - char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal); bool hasJarFile = false; - while (!hasJarFile && (entry = os::readdir(dir, (dirent *) dbuf)) != NULL) { + while (!hasJarFile && (entry = os::readdir(dir)) != NULL) { const char* name = entry->d_name; const char* ext = name + strlen(name) - 4; hasJarFile = ext > name && (os::file_name_strcmp(ext, ".jar") == 0); } - FREE_C_HEAP_ARRAY(char, dbuf, mtInternal); os::closedir(dir); return hasJarFile ; } @@ -3574,8 +3570,7 @@ static bool check_endorsed_and_ext_dirs() { if (dir != NULL) { int num_ext_jars = 0; struct dirent *entry; - char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(extDir), mtInternal); - while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) { + while ((entry = os::readdir(dir)) != NULL) { const char* name = entry->d_name; const char* ext = name + strlen(name) - 4; if (ext > name && (os::file_name_strcmp(ext, ".jar") == 0)) { @@ -3594,7 +3589,6 @@ static bool check_endorsed_and_ext_dirs() { } } } - FREE_C_HEAP_ARRAY(char, dbuf, mtInternal); os::closedir(dir); if (num_ext_jars > 0) { nonEmptyDirs += 1; diff --git a/src/share/vm/runtime/os.hpp b/src/share/vm/runtime/os.hpp index 931f4cb5b..14cd94237 100644 --- a/src/share/vm/runtime/os.hpp +++ b/src/share/vm/runtime/os.hpp @@ -561,8 +561,7 @@ class os: AllStatic { // Reading directories. static DIR* opendir(const char* dirname); - static int readdir_buf_size(const char *path); - static struct dirent* readdir(DIR* dirp, dirent* dbuf); + static struct dirent* readdir(DIR* dirp); static int closedir(DIR* dirp); // Dynamic library extension -- GitLab