diff src/os/linux/vm/os_linux.cpp @ 12997:e4f478e7781b

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
author jbachorik
date Fri, 25 Oct 2013 09:07:58 +0200
parents aa6f2ea19d8f
children 096c224171c4 c250880a6673 2b8e28fdf503 5656140324ed
line wrap: on
line diff
--- a/src/os/linux/vm/os_linux.cpp	Thu Oct 24 22:19:48 2013 -0700
+++ b/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;