changeset 54143:7054249afee5

8217843: Performance regression related to os::supports_monotonic_clock() on linux Reviewed-by: redestad, stuefe
author dholmes
date Tue, 05 Feb 2019 20:18:00 -0500
parents 868611f0adc3
children c6e8196e4b54
files src/hotspot/os/linux/os_linux.inline.hpp src/hotspot/os/posix/os_posix.cpp src/hotspot/os/posix/os_posix.hpp src/hotspot/os/posix/os_posix.inline.hpp
diffstat 4 files changed, 59 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/os/linux/os_linux.inline.hpp	Tue Feb 05 17:05:40 2019 -0800
+++ b/src/hotspot/os/linux/os_linux.inline.hpp	Tue Feb 05 20:18:00 2019 -0500
@@ -26,6 +26,7 @@
 #define OS_LINUX_OS_LINUX_INLINE_HPP
 
 #include "runtime/os.hpp"
+#include "os_posix.inline.hpp"
 
 // System includes
 
--- a/src/hotspot/os/posix/os_posix.cpp	Tue Feb 05 17:05:40 2019 -0800
+++ b/src/hotspot/os/posix/os_posix.cpp	Tue Feb 05 20:18:00 2019 -0500
@@ -25,10 +25,10 @@
 #include "jvm.h"
 #include "logging/log.hpp"
 #include "memory/allocation.inline.hpp"
+#include "os_posix.inline.hpp"
 #include "utilities/globalDefinitions.hpp"
 #include "runtime/frame.inline.hpp"
 #include "runtime/interfaceSupport.inline.hpp"
-#include "runtime/os.hpp"
 #include "services/memTracker.hpp"
 #include "utilities/align.hpp"
 #include "utilities/formatBuffer.hpp"
@@ -1659,26 +1659,13 @@
 
 // This means we have clockid_t, clock_gettime et al and CLOCK_MONOTONIC
 
-static int (*_clock_gettime)(clockid_t, struct timespec *) = NULL;
-static int (*_clock_getres)(clockid_t, struct timespec *) = NULL;
+int (*os::Posix::_clock_gettime)(clockid_t, struct timespec *) = NULL;
+int (*os::Posix::_clock_getres)(clockid_t, struct timespec *) = NULL;
+
 static int (*_pthread_condattr_setclock)(pthread_condattr_t *, clockid_t) = NULL;
 
 static bool _use_clock_monotonic_condattr = false;
 
-// Exported clock functionality
-
-int os::Posix::clock_gettime(clockid_t clock_id, struct timespec *tp) {
-  return _clock_gettime != NULL ? _clock_gettime(clock_id, tp) : -1;
-}
-
-int os::Posix::clock_getres(clockid_t clock_id, struct timespec *tp) {
-  return _clock_getres != NULL ? _clock_getres(clock_id, tp) : -1;
-}
-
-bool os::Posix::supports_monotonic_clock() {
-  return _clock_gettime != NULL;
-}
-
 // Determine what POSIX API's are present and do appropriate
 // configuration.
 void os::Posix::init(void) {
@@ -1879,12 +1866,12 @@
 
   clockid_t clock = CLOCK_MONOTONIC;
   // need to ensure we have a runtime check for clock_gettime support
-  if (!isAbsolute && _clock_gettime != NULL) {
+  if (!isAbsolute && os::Posix::supports_monotonic_clock()) {
     if (!_use_clock_monotonic_condattr || isRealtime) {
       clock = CLOCK_REALTIME;
     }
     struct timespec now;
-    int status = _clock_gettime(clock, &now);
+    int status = os::Posix::clock_gettime(clock, &now);
     assert_status(status == 0, status, "clock_gettime");
     calc_rel_time(abstime, timeout, now.tv_sec, now.tv_nsec, NANOUNITS);
     DEBUG_ONLY(max_secs += now.tv_sec;)
--- a/src/hotspot/os/posix/os_posix.hpp	Tue Feb 05 17:05:40 2019 -0800
+++ b/src/hotspot/os/posix/os_posix.hpp	Tue Feb 05 20:18:00 2019 -0500
@@ -123,6 +123,11 @@
 
 #ifdef SUPPORTS_CLOCK_MONOTONIC
 
+private:
+  // These need to be members so we can access them from inline functions
+  static int (*_clock_gettime)(clockid_t, struct timespec *);
+  static int (*_clock_getres)(clockid_t, struct timespec *);
+public:
   static bool supports_monotonic_clock();
   static int clock_gettime(clockid_t clock_id, struct timespec *tp);
   static int clock_getres(clockid_t clock_id, struct timespec *tp);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/os/posix/os_posix.inline.hpp	Tue Feb 05 20:18:00 2019 -0500
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 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_POSIX_OS_POSIX_INLINE_HPP
+#define OS_POSIX_OS_POSIX_INLINE_HPP
+
+#include "runtime/os.hpp"
+
+#ifdef SUPPORTS_CLOCK_MONOTONIC
+
+// Exported clock functionality
+
+inline bool os::Posix::supports_monotonic_clock() {
+  return _clock_gettime != NULL;
+}
+
+inline int os::Posix::clock_gettime(clockid_t clock_id, struct timespec *tp) {
+  return _clock_gettime != NULL ? _clock_gettime(clock_id, tp) : -1;
+}
+
+inline int os::Posix::clock_getres(clockid_t clock_id, struct timespec *tp) {
+  return _clock_getres != NULL ? _clock_getres(clock_id, tp) : -1;
+}
+#endif // SUPPORTS_CLOCK_MONOTONIC
+
+#endif // OS_POSIX_OS_POSIX_INLINE_HPP