8027294: Prepare hotspot for non TOD based uptime counter
authorjbachorik
Fri, 25 Oct 2013 09:07:58 +0200
changeset 21185 9d53434b1ef5
parent 21184 f7cc37a4ea4d
child 21187 8b35dcf13513
8027294: Prepare hotspot for non TOD based uptime counter Summary: Use HR timer when available for os::elapsed_counter() on linux/bsd. Add a new counter for the JVM uptime. Reviewed-by: dholmes, sla
hotspot/src/os/bsd/vm/os_bsd.cpp
hotspot/src/os/linux/vm/os_linux.cpp
hotspot/src/share/vm/services/jmm.h
hotspot/src/share/vm/services/management.cpp
--- a/hotspot/src/os/bsd/vm/os_bsd.cpp	Thu Oct 24 22:19:48 2013 -0700
+++ b/hotspot/src/os/bsd/vm/os_bsd.cpp	Fri Oct 25 09:07:58 2013 +0200
@@ -945,17 +945,15 @@
 // Used by VMSelfDestructTimer and the MemProfiler.
 double os::elapsedTime() {
 
-  return (double)(os::elapsed_counter()) * 0.000001;
+  return ((double)os::elapsed_counter()) / os::elapsed_frequency();
 }
 
 jlong os::elapsed_counter() {
-  timeval time;
-  int status = gettimeofday(&time, NULL);
-  return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count;
+  return javaTimeNanos() - initial_time_count;
 }
 
 jlong os::elapsed_frequency() {
-  return (1000 * 1000);
+  return NANOSECS_PER_SEC; // nanosecond resolution
 }
 
 bool os::supports_vtime() { return true; }
@@ -3582,7 +3580,7 @@
   Bsd::_main_thread = pthread_self();
 
   Bsd::clock_init();
-  initial_time_count = os::elapsed_counter();
+  initial_time_count = javaTimeNanos();
 
 #ifdef __APPLE__
   // XXXDARWIN
--- a/hotspot/src/os/linux/vm/os_linux.cpp	Thu Oct 24 22:19:48 2013 -0700
+++ b/hotspot/src/os/linux/vm/os_linux.cpp	Fri Oct 25 09:07:58 2013 +0200
@@ -1333,17 +1333,15 @@
 // Used by VMSelfDestructTimer and the MemProfiler.
 double os::elapsedTime() {
 
-  return (double)(os::elapsed_counter()) * 0.000001;
+  return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution
 }
 
 jlong os::elapsed_counter() {
-  timeval time;
-  int status = gettimeofday(&time, NULL);
-  return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count;
+  return javaTimeNanos() - initial_time_count;
 }
 
 jlong os::elapsed_frequency() {
-  return (1000 * 1000);
+  return NANOSECS_PER_SEC; // nanosecond resolution
 }
 
 bool os::supports_vtime() { return true; }
@@ -4750,7 +4748,7 @@
   Linux::_main_thread = pthread_self();
 
   Linux::clock_init();
-  initial_time_count = os::elapsed_counter();
+  initial_time_count = javaTimeNanos();
 
   // pthread_condattr initialization for monotonic clock
   int status;
--- a/hotspot/src/share/vm/services/jmm.h	Thu Oct 24 22:19:48 2013 -0700
+++ b/hotspot/src/share/vm/services/jmm.h	Fri Oct 25 09:07:58 2013 +0200
@@ -78,6 +78,7 @@
   JMM_COMPILE_TOTAL_TIME_MS          = 8,    /* Total accumulated time spent in compilation */
   JMM_GC_TIME_MS                     = 9,    /* Total accumulated time spent in collection */
   JMM_GC_COUNT                       = 10,   /* Total number of collections */
+  JMM_JVM_UPTIME_MS                  = 11,   /* The JVM uptime in milliseconds */
 
   JMM_INTERNAL_ATTRIBUTE_INDEX       = 100,
   JMM_CLASS_LOADED_BYTES             = 101,  /* Number of bytes loaded instance classes */
--- a/hotspot/src/share/vm/services/management.cpp	Thu Oct 24 22:19:48 2013 -0700
+++ b/hotspot/src/share/vm/services/management.cpp	Fri Oct 25 09:07:58 2013 +0200
@@ -1032,6 +1032,9 @@
   case JMM_JVM_INIT_DONE_TIME_MS:
     return Management::vm_init_done_time();
 
+  case JMM_JVM_UPTIME_MS:
+    return Management::ticks_to_ms(os::elapsed_counter());
+
   case JMM_COMPILE_TOTAL_TIME_MS:
     return Management::ticks_to_ms(CompileBroker::total_compilation_ticks());