comparison src/os/linux/vm/os_linux.cpp @ 4712:e7dead7e90af

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
author johnc
date Mon, 19 Dec 2011 10:02:05 -0800
parents 36b057451829
children 20bfb6d15a94
comparison
equal deleted inserted replaced
4711:adedfbbf0360 4712:e7dead7e90af
125 125
126 #define MAX_PATH (2 * K) 126 #define MAX_PATH (2 * K)
127 127
128 // for timer info max values which include all bits 128 // for timer info max values which include all bits
129 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) 129 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
130 #define SEC_IN_NANOSECS 1000000000LL
131 130
132 #define LARGEPAGES_BIT (1 << 6) 131 #define LARGEPAGES_BIT (1 << 6)
133 //////////////////////////////////////////////////////////////////////////////// 132 ////////////////////////////////////////////////////////////////////////////////
134 // global variables 133 // global variables
135 julong os::Linux::_physical_memory = 0; 134 julong os::Linux::_physical_memory = 0;
3257 // Solaris uses poll(), linux uses park(). 3256 // Solaris uses poll(), linux uses park().
3258 // Poll() is likely a better choice, assuming that Thread.interrupt() 3257 // Poll() is likely a better choice, assuming that Thread.interrupt()
3259 // generates a SIGUSRx signal. Note that SIGUSR1 can interfere with 3258 // generates a SIGUSRx signal. Note that SIGUSR1 can interfere with
3260 // SIGSEGV, see 4355769. 3259 // SIGSEGV, see 4355769.
3261 3260
3262 const int NANOSECS_PER_MILLISECS = 1000000;
3263
3264 int os::sleep(Thread* thread, jlong millis, bool interruptible) { 3261 int os::sleep(Thread* thread, jlong millis, bool interruptible) {
3265 assert(thread == Thread::current(), "thread consistency check"); 3262 assert(thread == Thread::current(), "thread consistency check");
3266 3263
3267 ParkEvent * const slp = thread->_SleepEvent ; 3264 ParkEvent * const slp = thread->_SleepEvent ;
3268 slp->reset() ; 3265 slp->reset() ;
3281 if (newtime - prevtime < 0) { 3278 if (newtime - prevtime < 0) {
3282 // time moving backwards, should only happen if no monotonic clock 3279 // time moving backwards, should only happen if no monotonic clock
3283 // not a guarantee() because JVM should not abort on kernel/glibc bugs 3280 // not a guarantee() because JVM should not abort on kernel/glibc bugs
3284 assert(!Linux::supports_monotonic_clock(), "time moving backwards"); 3281 assert(!Linux::supports_monotonic_clock(), "time moving backwards");
3285 } else { 3282 } else {
3286 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISECS; 3283 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
3287 } 3284 }
3288 3285
3289 if(millis <= 0) { 3286 if(millis <= 0) {
3290 return OS_OK; 3287 return OS_OK;
3291 } 3288 }
3320 if (newtime - prevtime < 0) { 3317 if (newtime - prevtime < 0) {
3321 // time moving backwards, should only happen if no monotonic clock 3318 // time moving backwards, should only happen if no monotonic clock
3322 // not a guarantee() because JVM should not abort on kernel/glibc bugs 3319 // not a guarantee() because JVM should not abort on kernel/glibc bugs
3323 assert(!Linux::supports_monotonic_clock(), "time moving backwards"); 3320 assert(!Linux::supports_monotonic_clock(), "time moving backwards");
3324 } else { 3321 } else {
3325 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISECS; 3322 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
3326 } 3323 }
3327 3324
3328 if(millis <= 0) break ; 3325 if(millis <= 0) break ;
3329 3326
3330 prevtime = newtime; 3327 prevtime = newtime;
3922 jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) { 3919 jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) {
3923 struct timespec tp; 3920 struct timespec tp;
3924 int rc = os::Linux::clock_gettime(clockid, &tp); 3921 int rc = os::Linux::clock_gettime(clockid, &tp);
3925 assert(rc == 0, "clock_gettime is expected to return 0 code"); 3922 assert(rc == 0, "clock_gettime is expected to return 0 code");
3926 3923
3927 return (tp.tv_sec * SEC_IN_NANOSECS) + tp.tv_nsec; 3924 return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec;
3928 } 3925 }
3929 3926
3930 ///// 3927 /////
3931 // glibc on Linux platform uses non-documented flag 3928 // glibc on Linux platform uses non-documented flag
3932 // to indicate, that some special sort of signal 3929 // to indicate, that some special sort of signal
5163 * on the condvar. Contention seen when trying to park implies that someone 5160 * on the condvar. Contention seen when trying to park implies that someone
5164 * is unparking you, so don't wait. And spurious returns are fine, so there 5161 * is unparking you, so don't wait. And spurious returns are fine, so there
5165 * is no need to track notifications. 5162 * is no need to track notifications.
5166 */ 5163 */
5167 5164
5168
5169 #define NANOSECS_PER_SEC 1000000000
5170 #define NANOSECS_PER_MILLISEC 1000000
5171 #define MAX_SECS 100000000 5165 #define MAX_SECS 100000000
5172 /* 5166 /*
5173 * This code is common to linux and solaris and will be moved to a 5167 * This code is common to linux and solaris and will be moved to a
5174 * common place in dolphin. 5168 * common place in dolphin.
5175 * 5169 *