8203680: os::stat() on Posix platform does not need to copy input path
authorstuefe
Tue, 19 Jun 2018 09:34:41 +0200
changeset 50667 cc58f1fa0438
parent 50666 3e66d204af9b
child 50668 11c7290b85ff
8203680: os::stat() on Posix platform does not need to copy input path Reviewed-by: hseigel, dholmes
src/hotspot/os/aix/os_aix.cpp
src/hotspot/os/aix/os_aix.inline.hpp
src/hotspot/os/bsd/os_bsd.cpp
src/hotspot/os/bsd/os_bsd.inline.hpp
src/hotspot/os/linux/os_linux.cpp
src/hotspot/os/linux/os_linux.inline.hpp
src/hotspot/os/posix/os_posix.cpp
src/hotspot/os/solaris/os_solaris.cpp
src/hotspot/share/runtime/os.hpp
--- a/src/hotspot/os/aix/os_aix.cpp	Fri Jun 15 13:57:32 2018 -0400
+++ b/src/hotspot/os/aix/os_aix.cpp	Tue Jun 19 09:34:41 2018 +0200
@@ -3737,16 +3737,6 @@
   return buf[0] == 'y' || buf[0] == 'Y';
 }
 
-int os::stat(const char *path, struct stat *sbuf) {
-  char pathbuf[MAX_PATH];
-  if (strlen(path) > MAX_PATH - 1) {
-    errno = ENAMETOOLONG;
-    return -1;
-  }
-  os::native_path(strcpy(pathbuf, path));
-  return ::stat(pathbuf, sbuf);
-}
-
 // Is a (classpath) directory empty?
 bool os::dir_is_empty(const char* path) {
   DIR *dir = NULL;
--- a/src/hotspot/os/aix/os_aix.inline.hpp	Fri Jun 15 13:57:32 2018 -0400
+++ b/src/hotspot/os/aix/os_aix.inline.hpp	Tue Jun 19 09:34:41 2018 +0200
@@ -93,10 +93,6 @@
   return ::fsync(fd);
 }
 
-inline char* os::native_path(char *path) {
-  return path;
-}
-
 inline int os::ftruncate(int fd, jlong length) {
   return ::ftruncate64(fd, length);
 }
--- a/src/hotspot/os/bsd/os_bsd.cpp	Fri Jun 15 13:57:32 2018 -0400
+++ b/src/hotspot/os/bsd/os_bsd.cpp	Tue Jun 19 09:34:41 2018 +0200
@@ -3489,16 +3489,6 @@
   return buf[0] == 'y' || buf[0] == 'Y';
 }
 
-int os::stat(const char *path, struct stat *sbuf) {
-  char pathbuf[MAX_PATH];
-  if (strlen(path) > MAX_PATH - 1) {
-    errno = ENAMETOOLONG;
-    return -1;
-  }
-  os::native_path(strcpy(pathbuf, path));
-  return ::stat(pathbuf, sbuf);
-}
-
 static inline struct timespec get_mtime(const char* filename) {
   struct stat st;
   int ret = os::stat(filename, &st);
--- a/src/hotspot/os/bsd/os_bsd.inline.hpp	Fri Jun 15 13:57:32 2018 -0400
+++ b/src/hotspot/os/bsd/os_bsd.inline.hpp	Tue Jun 19 09:34:41 2018 +0200
@@ -96,10 +96,6 @@
   return ::fsync(fd);
 }
 
-inline char* os::native_path(char *path) {
-  return path;
-}
-
 inline int os::ftruncate(int fd, jlong length) {
   return ::ftruncate(fd, length);
 }
--- a/src/hotspot/os/linux/os_linux.cpp	Fri Jun 15 13:57:32 2018 -0400
+++ b/src/hotspot/os/linux/os_linux.cpp	Tue Jun 19 09:34:41 2018 +0200
@@ -5378,16 +5378,6 @@
   return buf[0] == 'y' || buf[0] == 'Y';
 }
 
-int os::stat(const char *path, struct stat *sbuf) {
-  char pathbuf[MAX_PATH];
-  if (strlen(path) > MAX_PATH - 1) {
-    errno = ENAMETOOLONG;
-    return -1;
-  }
-  os::native_path(strcpy(pathbuf, path));
-  return ::stat(pathbuf, sbuf);
-}
-
 // Is a (classpath) directory empty?
 bool os::dir_is_empty(const char* path) {
   DIR *dir = NULL;
--- a/src/hotspot/os/linux/os_linux.inline.hpp	Fri Jun 15 13:57:32 2018 -0400
+++ b/src/hotspot/os/linux/os_linux.inline.hpp	Tue Jun 19 09:34:41 2018 +0200
@@ -88,10 +88,6 @@
   return ::fsync(fd);
 }
 
-inline char* os::native_path(char *path) {
-  return path;
-}
-
 inline int os::ftruncate(int fd, jlong length) {
   return ::ftruncate64(fd, length);
 }
--- a/src/hotspot/os/posix/os_posix.cpp	Fri Jun 15 13:57:32 2018 -0400
+++ b/src/hotspot/os/posix/os_posix.cpp	Tue Jun 19 09:34:41 2018 +0200
@@ -1334,6 +1334,13 @@
 
 }
 
+int os::stat(const char *path, struct stat *sbuf) {
+  return ::stat(path, sbuf);
+}
+
+char * os::native_path(char *path) {
+  return path;
+}
 
 // Check minimum allowable stack sizes for thread creation and to initialize
 // the java system classes, including StackOverflowError - depends on page
--- a/src/hotspot/os/solaris/os_solaris.cpp	Fri Jun 15 13:57:32 2018 -0400
+++ b/src/hotspot/os/solaris/os_solaris.cpp	Tue Jun 19 09:34:41 2018 +0200
@@ -1667,16 +1667,6 @@
   return (void*)::dlopen(NULL, RTLD_LAZY);
 }
 
-int os::stat(const char *path, struct stat *sbuf) {
-  char pathbuf[MAX_PATH];
-  if (strlen(path) > MAX_PATH - 1) {
-    errno = ENAMETOOLONG;
-    return -1;
-  }
-  os::native_path(strcpy(pathbuf, path));
-  return ::stat(pathbuf, sbuf);
-}
-
 static inline time_t get_mtime(const char* filename) {
   struct stat st;
   int ret = os::stat(filename, &st);
@@ -4474,10 +4464,6 @@
   return (jlong) ::lseek64(fd, offset, whence);
 }
 
-char * os::native_path(char *path) {
-  return path;
-}
-
 int os::ftruncate(int fd, jlong length) {
   return ::ftruncate64(fd, length);
 }
--- a/src/hotspot/share/runtime/os.hpp	Fri Jun 15 13:57:32 2018 -0400
+++ b/src/hotspot/share/runtime/os.hpp	Tue Jun 19 09:34:41 2018 +0200
@@ -558,6 +558,9 @@
   static FILE* fopen(const char* path, const char* mode);
   static int close(int fd);
   static jlong lseek(int fd, jlong offset, int whence);
+  // This function, on Windows, canonicalizes a given path (see os_windows.cpp for details).
+  // On Posix, this function is a noop: it does not change anything and just returns
+  // the input pointer.
   static char* native_path(char *path);
   static int ftruncate(int fd, jlong length);
   static int fsync(int fd);