aboutsummaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
authorjohnc <none@none>2011-12-19 10:02:05 -0800
committerjohnc <none@none>2011-12-19 10:02:05 -0800
commit748309fd92e55edf1d57546d137e0ec338e20b49 (patch)
treeb401c85334d209b8e8e4ba58f10f1cd026dbc728 /src/os
parent49748dff20f13432011df4fb34446a903deadcd2 (diff)
7117303: VM uses non-monotonic time source and complains that it is non-monotonic
Summary: Replaces calls to os::javaTimeMillis(), which does not (and cannot) guarantee monotonicity, in GC code to an equivalent expression that uses os::javaTimeNanos(). os::javaTimeNanos is guaranteed monotonically non-decreasing if the underlying platform provides a monotonic time source. Changes in OS files are to make use of the newly defined constants in globalDefinitions.hpp. Reviewed-by: dholmes, ysr
Diffstat (limited to 'src/os')
-rw-r--r--src/os/bsd/vm/os_bsd.cpp12
-rw-r--r--src/os/linux/vm/os_linux.cpp12
-rw-r--r--src/os/solaris/vm/os_solaris.cpp6
-rw-r--r--src/os/windows/vm/os_windows.cpp12
4 files changed, 12 insertions, 30 deletions
diff --git a/src/os/bsd/vm/os_bsd.cpp b/src/os/bsd/vm/os_bsd.cpp
index fd52f27ae..c4af904a3 100644
--- a/src/os/bsd/vm/os_bsd.cpp
+++ b/src/os/bsd/vm/os_bsd.cpp
@@ -150,7 +150,6 @@
// for timer info max values which include all bits
#define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
-#define SEC_IN_NANOSECS 1000000000LL
#define LARGEPAGES_BIT (1 << 6)
////////////////////////////////////////////////////////////////////////////////
@@ -3445,8 +3444,6 @@ size_t os::read(int fd, void *buf, unsigned int nBytes) {
// generates a SIGUSRx signal. Note that SIGUSR1 can interfere with
// SIGSEGV, see 4355769.
-const int NANOSECS_PER_MILLISECS = 1000000;
-
int os::sleep(Thread* thread, jlong millis, bool interruptible) {
assert(thread == Thread::current(), "thread consistency check");
@@ -3469,7 +3466,7 @@ int os::sleep(Thread* thread, jlong millis, bool interruptible) {
// not a guarantee() because JVM should not abort on kernel/glibc bugs
assert(!Bsd::supports_monotonic_clock(), "time moving backwards");
} else {
- millis -= (newtime - prevtime) / NANOSECS_PER_MILLISECS;
+ millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
}
if(millis <= 0) {
@@ -3508,7 +3505,7 @@ int os::sleep(Thread* thread, jlong millis, bool interruptible) {
// not a guarantee() because JVM should not abort on kernel/glibc bugs
assert(!Bsd::supports_monotonic_clock(), "time moving backwards");
} else {
- millis -= (newtime - prevtime) / NANOSECS_PER_MILLISECS;
+ millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
}
if(millis <= 0) break ;
@@ -4197,7 +4194,7 @@ jlong os::Bsd::fast_thread_cpu_time(clockid_t clockid) {
int rc = os::Bsd::clock_gettime(clockid, &tp);
assert(rc == 0, "clock_gettime is expected to return 0 code");
- return (tp.tv_sec * SEC_IN_NANOSECS) + tp.tv_nsec;
+ return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec;
}
#endif
@@ -5522,9 +5519,6 @@ void os::PlatformEvent::unpark() {
* is no need to track notifications.
*/
-
-#define NANOSECS_PER_SEC 1000000000
-#define NANOSECS_PER_MILLISEC 1000000
#define MAX_SECS 100000000
/*
* This code is common to bsd and solaris and will be moved to a
diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp
index 3aba51a77..a141f6a66 100644
--- a/src/os/linux/vm/os_linux.cpp
+++ b/src/os/linux/vm/os_linux.cpp
@@ -127,7 +127,6 @@
// for timer info max values which include all bits
#define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
-#define SEC_IN_NANOSECS 1000000000LL
#define LARGEPAGES_BIT (1 << 6)
////////////////////////////////////////////////////////////////////////////////
@@ -3259,8 +3258,6 @@ size_t os::read(int fd, void *buf, unsigned int nBytes) {
// generates a SIGUSRx signal. Note that SIGUSR1 can interfere with
// SIGSEGV, see 4355769.
-const int NANOSECS_PER_MILLISECS = 1000000;
-
int os::sleep(Thread* thread, jlong millis, bool interruptible) {
assert(thread == Thread::current(), "thread consistency check");
@@ -3283,7 +3280,7 @@ int os::sleep(Thread* thread, jlong millis, bool interruptible) {
// not a guarantee() because JVM should not abort on kernel/glibc bugs
assert(!Linux::supports_monotonic_clock(), "time moving backwards");
} else {
- millis -= (newtime - prevtime) / NANOSECS_PER_MILLISECS;
+ millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
}
if(millis <= 0) {
@@ -3322,7 +3319,7 @@ int os::sleep(Thread* thread, jlong millis, bool interruptible) {
// not a guarantee() because JVM should not abort on kernel/glibc bugs
assert(!Linux::supports_monotonic_clock(), "time moving backwards");
} else {
- millis -= (newtime - prevtime) / NANOSECS_PER_MILLISECS;
+ millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
}
if(millis <= 0) break ;
@@ -3924,7 +3921,7 @@ jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) {
int rc = os::Linux::clock_gettime(clockid, &tp);
assert(rc == 0, "clock_gettime is expected to return 0 code");
- return (tp.tv_sec * SEC_IN_NANOSECS) + tp.tv_nsec;
+ return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec;
}
/////
@@ -5165,9 +5162,6 @@ void os::PlatformEvent::unpark() {
* is no need to track notifications.
*/
-
-#define NANOSECS_PER_SEC 1000000000
-#define NANOSECS_PER_MILLISEC 1000000
#define MAX_SECS 100000000
/*
* This code is common to linux and solaris and will be moved to a
diff --git a/src/os/solaris/vm/os_solaris.cpp b/src/os/solaris/vm/os_solaris.cpp
index de9f88913..2a0f03eda 100644
--- a/src/os/solaris/vm/os_solaris.cpp
+++ b/src/os/solaris/vm/os_solaris.cpp
@@ -1674,7 +1674,6 @@ void* os::thread_local_storage_at(int index) {
}
-const int NANOSECS_PER_MILLISECS = 1000000;
// gethrtime can move backwards if read from one cpu and then a different cpu
// getTimeNanos is guaranteed to not move backward on Solaris
// local spinloop created as faster for a CAS on an int than
@@ -1803,7 +1802,7 @@ double os::elapsedVTime() {
// getTimeMillis guaranteed to not move backwards on Solaris
jlong getTimeMillis() {
jlong nanotime = getTimeNanos();
- return (jlong)(nanotime / NANOSECS_PER_MILLISECS);
+ return (jlong)(nanotime / NANOSECS_PER_MILLISEC);
}
// Must return millis since Jan 1 1970 for JVM_CurrentTimeMillis
@@ -6064,10 +6063,7 @@ void os::PlatformEvent::unpark() {
* is no need to track notifications.
*/
-#define NANOSECS_PER_SEC 1000000000
-#define NANOSECS_PER_MILLISEC 1000000
#define MAX_SECS 100000000
-
/*
* This code is common to linux and solaris and will be moved to a
* common place in dolphin.
diff --git a/src/os/windows/vm/os_windows.cpp b/src/os/windows/vm/os_windows.cpp
index e80ffb5b3..9fe70bdb0 100644
--- a/src/os/windows/vm/os_windows.cpp
+++ b/src/os/windows/vm/os_windows.cpp
@@ -821,17 +821,15 @@ jlong os::javaTimeMillis() {
}
}
-#define NANOS_PER_SEC CONST64(1000000000)
-#define NANOS_PER_MILLISEC 1000000
jlong os::javaTimeNanos() {
if (!has_performance_count) {
- return javaTimeMillis() * NANOS_PER_MILLISEC; // the best we can do.
+ return javaTimeMillis() * NANOSECS_PER_MILLISEC; // the best we can do.
} else {
LARGE_INTEGER current_count;
QueryPerformanceCounter(&current_count);
double current = as_long(current_count);
double freq = performance_frequency;
- jlong time = (jlong)((current/freq) * NANOS_PER_SEC);
+ jlong time = (jlong)((current/freq) * NANOSECS_PER_SEC);
return time;
}
}
@@ -847,15 +845,15 @@ void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
info_ptr->may_skip_forward = true;
} else {
jlong freq = performance_frequency;
- if (freq < NANOS_PER_SEC) {
+ if (freq < NANOSECS_PER_SEC) {
// the performance counter is 64 bits and we will
// be multiplying it -- so no wrap in 64 bits
info_ptr->max_value = ALL_64_BITS;
- } else if (freq > NANOS_PER_SEC) {
+ } else if (freq > NANOSECS_PER_SEC) {
// use the max value the counter can reach to
// determine the max value which could be returned
julong max_counter = (julong)ALL_64_BITS;
- info_ptr->max_value = (jlong)(max_counter / (freq / NANOS_PER_SEC));
+ info_ptr->max_value = (jlong)(max_counter / (freq / NANOSECS_PER_SEC));
} else {
// the performance counter is 64 bits and we will
// be using it directly -- so no wrap in 64 bits