changeset 57727:d06f42327c32

8237200: ZGC: Rename ZBackingPath to ZMountPoint Reviewed-by: stefank, eosterlund, smonteith
author pliden
date Fri, 17 Jan 2020 10:20:38 +0100
parents 58c756dc0f20
children f30115dede77
files src/hotspot/os/linux/gc/z/zBackingPath_linux.cpp src/hotspot/os/linux/gc/z/zBackingPath_linux.hpp src/hotspot/os/linux/gc/z/zMountPoint_linux.cpp src/hotspot/os/linux/gc/z/zMountPoint_linux.hpp src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp
diffstat 5 files changed, 208 insertions(+), 208 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/os/linux/gc/z/zBackingPath_linux.cpp	Fri Jan 17 10:20:38 2020 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +0,0 @@
-/*
- * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#include "precompiled.hpp"
-#include "gc/z/zArray.inline.hpp"
-#include "gc/z/zBackingPath_linux.hpp"
-#include "gc/z/zErrno.hpp"
-#include "logging/log.hpp"
-
-#include <stdio.h>
-#include <unistd.h>
-
-// Mount information, see proc(5) for more details.
-#define PROC_SELF_MOUNTINFO        "/proc/self/mountinfo"
-
-ZBackingPath::ZBackingPath(const char* filesystem, const char** preferred_mountpoints) {
-  if (ZPath != NULL) {
-    // Use specified path
-    _path = strdup(ZPath);
-  } else {
-    // Find suitable path
-    _path = find_mountpoint(filesystem, preferred_mountpoints);
-  }
-}
-
-ZBackingPath::~ZBackingPath() {
-  free(_path);
-  _path = NULL;
-}
-
-char* ZBackingPath::get_mountpoint(const char* line, const char* filesystem) const {
-  char* line_mountpoint = NULL;
-  char* line_filesystem = NULL;
-
-  // Parse line and return a newly allocated string containing the mount point if
-  // the line contains a matching filesystem and the mount point is accessible by
-  // the current user.
-  if (sscanf(line, "%*u %*u %*u:%*u %*s %ms %*[^-]- %ms", &line_mountpoint, &line_filesystem) != 2 ||
-      strcmp(line_filesystem, filesystem) != 0 ||
-      access(line_mountpoint, R_OK|W_OK|X_OK) != 0) {
-    // Not a matching or accessible filesystem
-    free(line_mountpoint);
-    line_mountpoint = NULL;
-  }
-
-  free(line_filesystem);
-
-  return line_mountpoint;
-}
-
-void ZBackingPath::get_mountpoints(const char* filesystem, ZArray<char*>* mountpoints) const {
-  FILE* fd = fopen(PROC_SELF_MOUNTINFO, "r");
-  if (fd == NULL) {
-    ZErrno err;
-    log_error(gc)("Failed to open %s: %s", PROC_SELF_MOUNTINFO, err.to_string());
-    return;
-  }
-
-  char* line = NULL;
-  size_t length = 0;
-
-  while (getline(&line, &length, fd) != -1) {
-    char* const mountpoint = get_mountpoint(line, filesystem);
-    if (mountpoint != NULL) {
-      mountpoints->add(mountpoint);
-    }
-  }
-
-  free(line);
-  fclose(fd);
-}
-
-void ZBackingPath::free_mountpoints(ZArray<char*>* mountpoints) const {
-  ZArrayIterator<char*> iter(mountpoints);
-  for (char* mountpoint; iter.next(&mountpoint);) {
-    free(mountpoint);
-  }
-  mountpoints->clear();
-}
-
-char* ZBackingPath::find_preferred_mountpoint(const char* filesystem,
-                                              ZArray<char*>* mountpoints,
-                                              const char** preferred_mountpoints) const {
-  // Find preferred mount point
-  ZArrayIterator<char*> iter1(mountpoints);
-  for (char* mountpoint; iter1.next(&mountpoint);) {
-    for (const char** preferred = preferred_mountpoints; *preferred != NULL; preferred++) {
-      if (!strcmp(mountpoint, *preferred)) {
-        // Preferred mount point found
-        return strdup(mountpoint);
-      }
-    }
-  }
-
-  // Preferred mount point not found
-  log_error(gc)("More than one %s filesystem found:", filesystem);
-  ZArrayIterator<char*> iter2(mountpoints);
-  for (char* mountpoint; iter2.next(&mountpoint);) {
-    log_error(gc)("  %s", mountpoint);
-  }
-
-  return NULL;
-}
-
-char* ZBackingPath::find_mountpoint(const char* filesystem, const char** preferred_mountpoints) const {
-  char* path = NULL;
-  ZArray<char*> mountpoints;
-
-  get_mountpoints(filesystem, &mountpoints);
-
-  if (mountpoints.size() == 0) {
-    // No mount point found
-    log_error(gc)("Failed to find an accessible %s filesystem", filesystem);
-  } else if (mountpoints.size() == 1) {
-    // One mount point found
-    path = strdup(mountpoints.at(0));
-  } else {
-    // More than one mount point found
-    path = find_preferred_mountpoint(filesystem, &mountpoints, preferred_mountpoints);
-  }
-
-  free_mountpoints(&mountpoints);
-
-  return path;
-}
-
-const char* ZBackingPath::get() const {
-  return _path;
-}
--- a/src/hotspot/os/linux/gc/z/zBackingPath_linux.hpp	Fri Jan 17 10:20:38 2020 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#ifndef OS_LINUX_GC_Z_ZBACKINGPATH_LINUX_HPP
-#define OS_LINUX_GC_Z_ZBACKINGPATH_LINUX_HPP
-
-#include "gc/z/zArray.hpp"
-#include "memory/allocation.hpp"
-
-class ZBackingPath : public StackObj {
-private:
-  char* _path;
-
-  char* get_mountpoint(const char* line,
-                       const char* filesystem) const;
-  void get_mountpoints(const char* filesystem,
-                       ZArray<char*>* mountpoints) const;
-  void free_mountpoints(ZArray<char*>* mountpoints) const;
-  char* find_preferred_mountpoint(const char* filesystem,
-                                  ZArray<char*>* mountpoints,
-                                  const char** preferred_mountpoints) const;
-  char* find_mountpoint(const char* filesystem,
-                        const char** preferred_mountpoints) const;
-
-public:
-  ZBackingPath(const char* filesystem, const char** preferred_mountpoints);
-  ~ZBackingPath();
-
-  const char* get() const;
-};
-
-#endif // OS_LINUX_GC_Z_ZBACKINGPATH_LINUX_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/linux/gc/z/zMountPoint_linux.cpp	Fri Jan 17 10:20:38 2020 +0100
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "precompiled.hpp"
+#include "gc/z/zArray.inline.hpp"
+#include "gc/z/zErrno.hpp"
+#include "gc/z/zMountPoint_linux.hpp"
+#include "logging/log.hpp"
+
+#include <stdio.h>
+#include <unistd.h>
+
+// Mount information, see proc(5) for more details.
+#define PROC_SELF_MOUNTINFO        "/proc/self/mountinfo"
+
+ZMountPoint::ZMountPoint(const char* filesystem, const char** preferred_mountpoints) {
+  if (ZPath != NULL) {
+    // Use specified path
+    _path = strdup(ZPath);
+  } else {
+    // Find suitable path
+    _path = find_mountpoint(filesystem, preferred_mountpoints);
+  }
+}
+
+ZMountPoint::~ZMountPoint() {
+  free(_path);
+  _path = NULL;
+}
+
+char* ZMountPoint::get_mountpoint(const char* line, const char* filesystem) const {
+  char* line_mountpoint = NULL;
+  char* line_filesystem = NULL;
+
+  // Parse line and return a newly allocated string containing the mount point if
+  // the line contains a matching filesystem and the mount point is accessible by
+  // the current user.
+  if (sscanf(line, "%*u %*u %*u:%*u %*s %ms %*[^-]- %ms", &line_mountpoint, &line_filesystem) != 2 ||
+      strcmp(line_filesystem, filesystem) != 0 ||
+      access(line_mountpoint, R_OK|W_OK|X_OK) != 0) {
+    // Not a matching or accessible filesystem
+    free(line_mountpoint);
+    line_mountpoint = NULL;
+  }
+
+  free(line_filesystem);
+
+  return line_mountpoint;
+}
+
+void ZMountPoint::get_mountpoints(const char* filesystem, ZArray<char*>* mountpoints) const {
+  FILE* fd = fopen(PROC_SELF_MOUNTINFO, "r");
+  if (fd == NULL) {
+    ZErrno err;
+    log_error(gc)("Failed to open %s: %s", PROC_SELF_MOUNTINFO, err.to_string());
+    return;
+  }
+
+  char* line = NULL;
+  size_t length = 0;
+
+  while (getline(&line, &length, fd) != -1) {
+    char* const mountpoint = get_mountpoint(line, filesystem);
+    if (mountpoint != NULL) {
+      mountpoints->add(mountpoint);
+    }
+  }
+
+  free(line);
+  fclose(fd);
+}
+
+void ZMountPoint::free_mountpoints(ZArray<char*>* mountpoints) const {
+  ZArrayIterator<char*> iter(mountpoints);
+  for (char* mountpoint; iter.next(&mountpoint);) {
+    free(mountpoint);
+  }
+  mountpoints->clear();
+}
+
+char* ZMountPoint::find_preferred_mountpoint(const char* filesystem,
+                                              ZArray<char*>* mountpoints,
+                                              const char** preferred_mountpoints) const {
+  // Find preferred mount point
+  ZArrayIterator<char*> iter1(mountpoints);
+  for (char* mountpoint; iter1.next(&mountpoint);) {
+    for (const char** preferred = preferred_mountpoints; *preferred != NULL; preferred++) {
+      if (!strcmp(mountpoint, *preferred)) {
+        // Preferred mount point found
+        return strdup(mountpoint);
+      }
+    }
+  }
+
+  // Preferred mount point not found
+  log_error(gc)("More than one %s filesystem found:", filesystem);
+  ZArrayIterator<char*> iter2(mountpoints);
+  for (char* mountpoint; iter2.next(&mountpoint);) {
+    log_error(gc)("  %s", mountpoint);
+  }
+
+  return NULL;
+}
+
+char* ZMountPoint::find_mountpoint(const char* filesystem, const char** preferred_mountpoints) const {
+  char* path = NULL;
+  ZArray<char*> mountpoints;
+
+  get_mountpoints(filesystem, &mountpoints);
+
+  if (mountpoints.size() == 0) {
+    // No mount point found
+    log_error(gc)("Failed to find an accessible %s filesystem", filesystem);
+  } else if (mountpoints.size() == 1) {
+    // One mount point found
+    path = strdup(mountpoints.at(0));
+  } else {
+    // More than one mount point found
+    path = find_preferred_mountpoint(filesystem, &mountpoints, preferred_mountpoints);
+  }
+
+  free_mountpoints(&mountpoints);
+
+  return path;
+}
+
+const char* ZMountPoint::get() const {
+  return _path;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/linux/gc/z/zMountPoint_linux.hpp	Fri Jan 17 10:20:38 2020 +0100
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef OS_LINUX_GC_Z_ZMOUNTPOINT_LINUX_HPP
+#define OS_LINUX_GC_Z_ZMOUNTPOINT_LINUX_HPP
+
+#include "gc/z/zArray.hpp"
+#include "memory/allocation.hpp"
+
+class ZMountPoint : public StackObj {
+private:
+  char* _path;
+
+  char* get_mountpoint(const char* line,
+                       const char* filesystem) const;
+  void get_mountpoints(const char* filesystem,
+                       ZArray<char*>* mountpoints) const;
+  void free_mountpoints(ZArray<char*>* mountpoints) const;
+  char* find_preferred_mountpoint(const char* filesystem,
+                                  ZArray<char*>* mountpoints,
+                                  const char** preferred_mountpoints) const;
+  char* find_mountpoint(const char* filesystem,
+                        const char** preferred_mountpoints) const;
+
+public:
+  ZMountPoint(const char* filesystem, const char** preferred_mountpoints);
+  ~ZMountPoint();
+
+  const char* get() const;
+};
+
+#endif // OS_LINUX_GC_Z_ZMOUNTPOINT_LINUX_HPP
--- a/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp	Fri Jan 17 10:20:38 2020 +0100
+++ b/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp	Fri Jan 17 10:20:38 2020 +0100
@@ -23,10 +23,10 @@
 
 #include "precompiled.hpp"
 #include "gc/z/zArray.inline.hpp"
-#include "gc/z/zBackingPath_linux.hpp"
 #include "gc/z/zErrno.hpp"
 #include "gc/z/zGlobals.hpp"
 #include "gc/z/zLargePages.inline.hpp"
+#include "gc/z/zMountPoint_linux.hpp"
 #include "gc/z/zPhysicalMemoryBacking_linux.hpp"
 #include "gc/z/zSyscall_linux.hpp"
 #include "logging/log.hpp"
@@ -207,18 +207,18 @@
                                              : z_preferred_tmpfs_mountpoints;
 
   // Find mountpoint
-  ZBackingPath path(filesystem, preferred_mountpoints);
-  if (path.get() == NULL) {
+  ZMountPoint mountpoint(filesystem, preferred_mountpoints);
+  if (mountpoint.get() == NULL) {
     log_error(gc)("Use -XX:ZPath to specify the path to a %s filesystem", filesystem);
     return -1;
   }
 
   // Try to create an anonymous file using the O_TMPFILE flag. Note that this
   // flag requires kernel >= 3.11. If this fails we fall back to open/unlink.
-  const int fd_anon = os::open(path.get(), O_TMPFILE|O_EXCL|O_RDWR|O_CLOEXEC, S_IRUSR|S_IWUSR);
+  const int fd_anon = os::open(mountpoint.get(), O_TMPFILE|O_EXCL|O_RDWR|O_CLOEXEC, S_IRUSR|S_IWUSR);
   if (fd_anon == -1) {
     ZErrno err;
-    log_debug(gc, init)("Failed to create anonymous file in %s (%s)", path.get(),
+    log_debug(gc, init)("Failed to create anonymous file in %s (%s)", mountpoint.get(),
                         (err == EINVAL ? "Not supported" : err.to_string()));
   } else {
     // Get inode number for anonymous file
@@ -229,7 +229,7 @@
       return -1;
     }
 
-    log_info(gc, init)("Heap backed by file: %s/#" UINT64_FORMAT, path.get(), (uint64_t)stat_buf.st_ino);
+    log_info(gc, init)("Heap backed by file: %s/#" UINT64_FORMAT, mountpoint.get(), (uint64_t)stat_buf.st_ino);
 
     return fd_anon;
   }
@@ -238,7 +238,7 @@
 
   // Create file name
   char filename[PATH_MAX];
-  snprintf(filename, sizeof(filename), "%s/%s.%d", path.get(), name, os::current_process_id());
+  snprintf(filename, sizeof(filename), "%s/%s.%d", mountpoint.get(), name, os::current_process_id());
 
   // Create file
   const int fd = os::open(filename, O_CREAT|O_EXCL|O_RDWR|O_CLOEXEC, S_IRUSR|S_IWUSR);