提交 76168a85 编写于 作者: A andrew

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
上级 8519ccef
...@@ -4184,8 +4184,7 @@ bool os::dir_is_empty(const char* path) { ...@@ -4184,8 +4184,7 @@ bool os::dir_is_empty(const char* path) {
/* Scan the directory */ /* Scan the directory */
bool result = true; 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) { if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
result = false; result = false;
} }
......
...@@ -92,19 +92,6 @@ inline void os::dll_unload(void *lib) { ...@@ -92,19 +92,6 @@ inline void os::dll_unload(void *lib) {
inline const int os::default_file_open_flags() { return 0;} 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) { inline jlong os::lseek(int fd, jlong offset, int whence) {
return (jlong) ::lseek64(fd, offset, whence); return (jlong) ::lseek64(fd, offset, whence);
} }
...@@ -121,28 +108,6 @@ inline int os::ftruncate(int fd, jlong length) { ...@@ -121,28 +108,6 @@ inline int os::ftruncate(int fd, jlong length) {
return ::ftruncate64(fd, 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 // macros for restartable system calls
#define RESTARTABLE(_cmd, _result) do { \ #define RESTARTABLE(_cmd, _result) do { \
......
...@@ -612,9 +612,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -612,9 +612,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
// to determine the user name for the process id. // to determine the user name for the process id.
// //
struct dirent* dentry; struct dirent* dentry;
char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal);
errno = 0; 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 // check if the directory entry is a hsperfdata file
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) { if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
...@@ -648,9 +647,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -648,9 +647,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
} }
struct dirent* udentry; struct dirent* udentry;
char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal);
errno = 0; 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) { if (filename_to_pid(udentry->d_name) == vmid) {
struct stat statbuf; struct stat statbuf;
...@@ -694,11 +692,9 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -694,11 +692,9 @@ static char* get_user_name_slow(int vmid, TRAPS) {
} }
} }
os::closedir(subdirp); os::closedir(subdirp);
FREE_C_HEAP_ARRAY(char, udbuf, mtInternal);
FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal);
} }
os::closedir(tmpdirp); os::closedir(tmpdirp);
FREE_C_HEAP_ARRAY(char, tdbuf, mtInternal);
return(oldest_user); return(oldest_user);
} }
...@@ -774,10 +770,8 @@ static void cleanup_sharedmem_resources(const char* dirname) { ...@@ -774,10 +770,8 @@ static void cleanup_sharedmem_resources(const char* dirname) {
// loop under these conditions is dependent upon the implementation of // loop under these conditions is dependent upon the implementation of
// opendir/readdir. // opendir/readdir.
struct dirent* entry; struct dirent* entry;
char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal);
errno = 0; 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); pid_t pid = filename_to_pid(entry->d_name);
...@@ -816,7 +810,6 @@ static void cleanup_sharedmem_resources(const char* dirname) { ...@@ -816,7 +810,6 @@ static void cleanup_sharedmem_resources(const char* dirname) {
// Close the directory and reset the current working directory. // Close the directory and reset the current working directory.
close_directory_secure_cwd(dirp, saved_cwd_fd); close_directory_secure_cwd(dirp, saved_cwd_fd);
FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
} }
// Make the user specific temporary directory. Returns true if // Make the user specific temporary directory. Returns true if
......
...@@ -3957,8 +3957,7 @@ bool os::dir_is_empty(const char* path) { ...@@ -3957,8 +3957,7 @@ bool os::dir_is_empty(const char* path) {
/* Scan the directory */ /* Scan the directory */
bool result = true; 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) { if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
result = false; result = false;
} }
......
...@@ -95,17 +95,6 @@ inline void os::dll_unload(void *lib) { ...@@ -95,17 +95,6 @@ inline void os::dll_unload(void *lib) {
inline const int os::default_file_open_flags() { return 0;} 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) { inline jlong os::lseek(int fd, jlong offset, int whence) {
return (jlong) ::lseek(fd, offset, whence); return (jlong) ::lseek(fd, offset, whence);
} }
...@@ -122,28 +111,6 @@ inline int os::ftruncate(int fd, jlong length) { ...@@ -122,28 +111,6 @@ inline int os::ftruncate(int fd, jlong length) {
return ::ftruncate(fd, 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 // macros for restartable system calls
#define RESTARTABLE(_cmd, _result) do { \ #define RESTARTABLE(_cmd, _result) do { \
......
...@@ -533,9 +533,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -533,9 +533,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
// to determine the user name for the process id. // to determine the user name for the process id.
// //
struct dirent* dentry; struct dirent* dentry;
char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal);
errno = 0; 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 // check if the directory entry is a hsperfdata file
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) { if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
...@@ -557,9 +556,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -557,9 +556,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
} }
struct dirent* udentry; struct dirent* udentry;
char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal);
errno = 0; 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) { if (filename_to_pid(udentry->d_name) == vmid) {
struct stat statbuf; struct stat statbuf;
...@@ -603,11 +601,9 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -603,11 +601,9 @@ static char* get_user_name_slow(int vmid, TRAPS) {
} }
} }
os::closedir(subdirp); os::closedir(subdirp);
FREE_C_HEAP_ARRAY(char, udbuf, mtInternal);
FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal);
} }
os::closedir(tmpdirp); os::closedir(tmpdirp);
FREE_C_HEAP_ARRAY(char, tdbuf, mtInternal);
return(oldest_user); return(oldest_user);
} }
...@@ -686,10 +682,8 @@ static void cleanup_sharedmem_resources(const char* dirname) { ...@@ -686,10 +682,8 @@ static void cleanup_sharedmem_resources(const char* dirname) {
// opendir/readdir. // opendir/readdir.
// //
struct dirent* entry; struct dirent* entry;
char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal);
errno = 0; 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); pid_t pid = filename_to_pid(entry->d_name);
...@@ -729,7 +723,6 @@ static void cleanup_sharedmem_resources(const char* dirname) { ...@@ -729,7 +723,6 @@ static void cleanup_sharedmem_resources(const char* dirname) {
// close the directory and reset the current working directory // close the directory and reset the current working directory
close_directory_secure_cwd(dirp, saved_cwd_fd); close_directory_secure_cwd(dirp, saved_cwd_fd);
FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
} }
// make the user specific temporary directory. Returns true if // make the user specific temporary directory. Returns true if
......
...@@ -5501,8 +5501,7 @@ bool os::dir_is_empty(const char* path) { ...@@ -5501,8 +5501,7 @@ bool os::dir_is_empty(const char* path) {
/* Scan the directory */ /* Scan the directory */
bool result = true; 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) { if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
result = false; result = false;
} }
......
...@@ -87,17 +87,6 @@ inline void os::dll_unload(void *lib) { ...@@ -87,17 +87,6 @@ inline void os::dll_unload(void *lib) {
inline const int os::default_file_open_flags() { return 0;} 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) { inline jlong os::lseek(int fd, jlong offset, int whence) {
return (jlong) ::lseek64(fd, offset, whence); return (jlong) ::lseek64(fd, offset, whence);
} }
...@@ -114,28 +103,6 @@ inline int os::ftruncate(int fd, jlong length) { ...@@ -114,28 +103,6 @@ inline int os::ftruncate(int fd, jlong length) {
return ::ftruncate64(fd, 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 // macros for restartable system calls
#define RESTARTABLE(_cmd, _result) do { \ #define RESTARTABLE(_cmd, _result) do { \
......
...@@ -533,9 +533,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -533,9 +533,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
// to determine the user name for the process id. // to determine the user name for the process id.
// //
struct dirent* dentry; struct dirent* dentry;
char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal);
errno = 0; 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 // check if the directory entry is a hsperfdata file
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) { if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
...@@ -569,9 +568,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -569,9 +568,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
} }
struct dirent* udentry; struct dirent* udentry;
char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal);
errno = 0; 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) { if (filename_to_pid(udentry->d_name) == vmid) {
struct stat statbuf; struct stat statbuf;
...@@ -615,11 +613,9 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -615,11 +613,9 @@ static char* get_user_name_slow(int vmid, TRAPS) {
} }
} }
os::closedir(subdirp); os::closedir(subdirp);
FREE_C_HEAP_ARRAY(char, udbuf, mtInternal);
FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal);
} }
os::closedir(tmpdirp); os::closedir(tmpdirp);
FREE_C_HEAP_ARRAY(char, tdbuf, mtInternal);
return(oldest_user); return(oldest_user);
} }
...@@ -698,10 +694,8 @@ static void cleanup_sharedmem_resources(const char* dirname) { ...@@ -698,10 +694,8 @@ static void cleanup_sharedmem_resources(const char* dirname) {
// opendir/readdir. // opendir/readdir.
// //
struct dirent* entry; struct dirent* entry;
char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal);
errno = 0; 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); pid_t pid = filename_to_pid(entry->d_name);
...@@ -738,8 +732,6 @@ static void cleanup_sharedmem_resources(const char* dirname) { ...@@ -738,8 +732,6 @@ static void cleanup_sharedmem_resources(const char* dirname) {
// close the directory and reset the current working directory // close the directory and reset the current working directory
close_directory_secure_cwd(dirp, saved_cwd_fd); close_directory_secure_cwd(dirp, saved_cwd_fd);
FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
} }
// make the user specific temporary directory. Returns true if // make the user specific temporary directory. Returns true if
......
...@@ -302,6 +302,21 @@ FILE* os::open(int fd, const char* mode) { ...@@ -302,6 +302,21 @@ FILE* os::open(int fd, const char* mode) {
return ::fdopen(fd, 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_<lib_name> function name // Builds a platform dependent Agent_OnLoad_<lib_name> function name
// which is used to find statically linked in agents. // which is used to find statically linked in agents.
// Parameters: // Parameters:
......
...@@ -5163,9 +5163,7 @@ bool os::dir_is_empty(const char* path) { ...@@ -5163,9 +5163,7 @@ bool os::dir_is_empty(const char* path) {
/* Scan the directory */ /* Scan the directory */
bool result = true; bool result = true;
char buf[sizeof(struct dirent) + MAX_PATH]; while (result && (ptr = readdir(dir)) != NULL) {
struct dirent *dbuf = (struct dirent *) buf;
while (result && (ptr = readdir(dir, dbuf)) != NULL) {
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) { if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
result = false; result = false;
} }
......
...@@ -71,37 +71,6 @@ inline void os::bang_stack_shadow_pages() { ...@@ -71,37 +71,6 @@ inline void os::bang_stack_shadow_pages() {
} }
inline void os::dll_unload(void *lib) { ::dlclose(lib); } 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);
}
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
...@@ -524,9 +524,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -524,9 +524,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
// to determine the user name for the process id. // to determine the user name for the process id.
// //
struct dirent* dentry; struct dirent* dentry;
char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal);
errno = 0; 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 // check if the directory entry is a hsperfdata file
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) { if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
...@@ -560,9 +559,8 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -560,9 +559,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
} }
struct dirent* udentry; struct dirent* udentry;
char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal);
errno = 0; 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) { if (filename_to_pid(udentry->d_name) == vmid) {
struct stat statbuf; struct stat statbuf;
...@@ -606,11 +604,9 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -606,11 +604,9 @@ static char* get_user_name_slow(int vmid, TRAPS) {
} }
} }
os::closedir(subdirp); os::closedir(subdirp);
FREE_C_HEAP_ARRAY(char, udbuf, mtInternal);
FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal);
} }
os::closedir(tmpdirp); os::closedir(tmpdirp);
FREE_C_HEAP_ARRAY(char, tdbuf, mtInternal);
return(oldest_user); return(oldest_user);
} }
...@@ -737,10 +733,8 @@ static void cleanup_sharedmem_resources(const char* dirname) { ...@@ -737,10 +733,8 @@ static void cleanup_sharedmem_resources(const char* dirname) {
// opendir/readdir. // opendir/readdir.
// //
struct dirent* entry; struct dirent* entry;
char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal);
errno = 0; 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); pid_t pid = filename_to_pid(entry->d_name);
...@@ -780,7 +774,6 @@ static void cleanup_sharedmem_resources(const char* dirname) { ...@@ -780,7 +774,6 @@ static void cleanup_sharedmem_resources(const char* dirname) {
// close the directory and reset the current working directory // close the directory and reset the current working directory
close_directory_secure_cwd(dirp, saved_cwd_fd); close_directory_secure_cwd(dirp, saved_cwd_fd);
FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
} }
// make the user specific temporary directory. Returns true if // make the user specific temporary directory. Returns true if
......
...@@ -1172,14 +1172,12 @@ os::opendir(const char *dirname) ...@@ -1172,14 +1172,12 @@ os::opendir(const char *dirname)
return dirp; return dirp;
} }
/* parameter dbuf unused on Windows */
struct dirent * struct dirent *
os::readdir(DIR *dirp, dirent *dbuf) os::readdir(DIR *dirp)
{ {
assert(dirp != NULL, "just checking"); // hotspot change assert(dirp != NULL, "just checking"); // hotspot change
if (dirp->handle == INVALID_HANDLE_VALUE) { if (dirp->handle == INVALID_HANDLE_VALUE) {
return 0; return NULL;
} }
strcpy(dirp->dirent.d_name, dirp->find_data.cFileName); strcpy(dirp->dirent.d_name, dirp->find_data.cFileName);
...@@ -1187,7 +1185,7 @@ os::readdir(DIR *dirp, dirent *dbuf) ...@@ -1187,7 +1185,7 @@ os::readdir(DIR *dirp, dirent *dbuf)
if (!FindNextFile(dirp->handle, &dirp->find_data)) { if (!FindNextFile(dirp->handle, &dirp->find_data)) {
if (GetLastError() == ERROR_INVALID_HANDLE) { if (GetLastError() == ERROR_INVALID_HANDLE) {
errno = EBADF; errno = EBADF;
return 0; return NULL;
} }
FindClose(dirp->handle); FindClose(dirp->handle);
dirp->handle = INVALID_HANDLE_VALUE; dirp->handle = INVALID_HANDLE_VALUE;
......
...@@ -65,14 +65,6 @@ inline bool os::allocate_stack_guard_pages() { ...@@ -65,14 +65,6 @@ inline bool os::allocate_stack_guard_pages() {
return true; 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. // Bang the shadow pages if they need to be touched to be mapped.
inline void os::bang_stack_shadow_pages() { inline void os::bang_stack_shadow_pages() {
// Write to each page of our new frame to force OS mapping. // Write to each page of our new frame to force OS mapping.
......
...@@ -316,9 +316,8 @@ static char* get_user_name_slow(int vmid) { ...@@ -316,9 +316,8 @@ static char* get_user_name_slow(int vmid) {
// to determine the user name for the process id. // to determine the user name for the process id.
// //
struct dirent* dentry; struct dirent* dentry;
char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal);
errno = 0; 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 // check if the directory entry is a hsperfdata file
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) { if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
...@@ -351,9 +350,8 @@ static char* get_user_name_slow(int vmid) { ...@@ -351,9 +350,8 @@ static char* get_user_name_slow(int vmid) {
} }
struct dirent* udentry; struct dirent* udentry;
char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal);
errno = 0; 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) { if (filename_to_pid(udentry->d_name) == vmid) {
struct stat statbuf; struct stat statbuf;
...@@ -405,11 +403,9 @@ static char* get_user_name_slow(int vmid) { ...@@ -405,11 +403,9 @@ static char* get_user_name_slow(int vmid) {
} }
} }
os::closedir(subdirp); os::closedir(subdirp);
FREE_C_HEAP_ARRAY(char, udbuf, mtInternal);
FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal);
} }
os::closedir(tmpdirp); os::closedir(tmpdirp);
FREE_C_HEAP_ARRAY(char, tdbuf, mtInternal);
return(latest_user); return(latest_user);
} }
...@@ -639,9 +635,8 @@ static void cleanup_sharedmem_resources(const char* dirname) { ...@@ -639,9 +635,8 @@ static void cleanup_sharedmem_resources(const char* dirname) {
// opendir/readdir. // opendir/readdir.
// //
struct dirent* entry; struct dirent* entry;
char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal);
errno = 0; 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); int pid = filename_to_pid(entry->d_name);
...@@ -682,7 +677,6 @@ static void cleanup_sharedmem_resources(const char* dirname) { ...@@ -682,7 +677,6 @@ static void cleanup_sharedmem_resources(const char* dirname) {
errno = 0; errno = 0;
} }
os::closedir(dirp); os::closedir(dirp);
FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
} }
// create a file mapping object with the requested name, and size // create a file mapping object with the requested name, and size
......
...@@ -556,8 +556,7 @@ char* SysClassPath::add_jars_to_path(char* path, const char* directory) { ...@@ -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. */ /* Scan the directory for jars/zips, appending them to path. */
struct dirent *entry; struct dirent *entry;
char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal); while ((entry = os::readdir(dir)) != NULL) {
while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
const char* name = entry->d_name; const char* name = entry->d_name;
const char* ext = name + strlen(name) - 4; const char* ext = name + strlen(name) - 4;
bool isJarOrZip = ext > name && bool isJarOrZip = ext > name &&
...@@ -571,7 +570,6 @@ char* SysClassPath::add_jars_to_path(char* path, const char* directory) { ...@@ -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, jarpath, mtInternal);
} }
} }
FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
os::closedir(dir); os::closedir(dir);
return path; return path;
} }
...@@ -3485,14 +3483,12 @@ static bool has_jar_files(const char* directory) { ...@@ -3485,14 +3483,12 @@ static bool has_jar_files(const char* directory) {
if (dir == NULL) return false; if (dir == NULL) return false;
struct dirent *entry; struct dirent *entry;
char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal);
bool hasJarFile = false; 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* name = entry->d_name;
const char* ext = name + strlen(name) - 4; const char* ext = name + strlen(name) - 4;
hasJarFile = ext > name && (os::file_name_strcmp(ext, ".jar") == 0); hasJarFile = ext > name && (os::file_name_strcmp(ext, ".jar") == 0);
} }
FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
os::closedir(dir); os::closedir(dir);
return hasJarFile ; return hasJarFile ;
} }
...@@ -3574,8 +3570,7 @@ static bool check_endorsed_and_ext_dirs() { ...@@ -3574,8 +3570,7 @@ static bool check_endorsed_and_ext_dirs() {
if (dir != NULL) { if (dir != NULL) {
int num_ext_jars = 0; int num_ext_jars = 0;
struct dirent *entry; struct dirent *entry;
char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(extDir), mtInternal); while ((entry = os::readdir(dir)) != NULL) {
while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
const char* name = entry->d_name; const char* name = entry->d_name;
const char* ext = name + strlen(name) - 4; const char* ext = name + strlen(name) - 4;
if (ext > name && (os::file_name_strcmp(ext, ".jar") == 0)) { if (ext > name && (os::file_name_strcmp(ext, ".jar") == 0)) {
...@@ -3594,7 +3589,6 @@ static bool check_endorsed_and_ext_dirs() { ...@@ -3594,7 +3589,6 @@ static bool check_endorsed_and_ext_dirs() {
} }
} }
} }
FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
os::closedir(dir); os::closedir(dir);
if (num_ext_jars > 0) { if (num_ext_jars > 0) {
nonEmptyDirs += 1; nonEmptyDirs += 1;
......
...@@ -561,8 +561,7 @@ class os: AllStatic { ...@@ -561,8 +561,7 @@ class os: AllStatic {
// Reading directories. // Reading directories.
static DIR* opendir(const char* dirname); static DIR* opendir(const char* dirname);
static int readdir_buf_size(const char *path); static struct dirent* readdir(DIR* dirp);
static struct dirent* readdir(DIR* dirp, dirent* dbuf);
static int closedir(DIR* dirp); static int closedir(DIR* dirp);
// Dynamic library extension // Dynamic library extension
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册