comparison src/os/windows/vm/os_windows.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 436b4a3231bf
children 4b18532913c7
comparison
equal deleted inserted replaced
4711:adedfbbf0360 4712:e7dead7e90af
819 GetSystemTimeAsFileTime(&wt); 819 GetSystemTimeAsFileTime(&wt);
820 return windows_to_java_time(wt); 820 return windows_to_java_time(wt);
821 } 821 }
822 } 822 }
823 823
824 #define NANOS_PER_SEC CONST64(1000000000)
825 #define NANOS_PER_MILLISEC 1000000
826 jlong os::javaTimeNanos() { 824 jlong os::javaTimeNanos() {
827 if (!has_performance_count) { 825 if (!has_performance_count) {
828 return javaTimeMillis() * NANOS_PER_MILLISEC; // the best we can do. 826 return javaTimeMillis() * NANOSECS_PER_MILLISEC; // the best we can do.
829 } else { 827 } else {
830 LARGE_INTEGER current_count; 828 LARGE_INTEGER current_count;
831 QueryPerformanceCounter(&current_count); 829 QueryPerformanceCounter(&current_count);
832 double current = as_long(current_count); 830 double current = as_long(current_count);
833 double freq = performance_frequency; 831 double freq = performance_frequency;
834 jlong time = (jlong)((current/freq) * NANOS_PER_SEC); 832 jlong time = (jlong)((current/freq) * NANOSECS_PER_SEC);
835 return time; 833 return time;
836 } 834 }
837 } 835 }
838 836
839 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) { 837 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
845 // this is a wall clock timer, so may skip 843 // this is a wall clock timer, so may skip
846 info_ptr->may_skip_backward = true; 844 info_ptr->may_skip_backward = true;
847 info_ptr->may_skip_forward = true; 845 info_ptr->may_skip_forward = true;
848 } else { 846 } else {
849 jlong freq = performance_frequency; 847 jlong freq = performance_frequency;
850 if (freq < NANOS_PER_SEC) { 848 if (freq < NANOSECS_PER_SEC) {
851 // the performance counter is 64 bits and we will 849 // the performance counter is 64 bits and we will
852 // be multiplying it -- so no wrap in 64 bits 850 // be multiplying it -- so no wrap in 64 bits
853 info_ptr->max_value = ALL_64_BITS; 851 info_ptr->max_value = ALL_64_BITS;
854 } else if (freq > NANOS_PER_SEC) { 852 } else if (freq > NANOSECS_PER_SEC) {
855 // use the max value the counter can reach to 853 // use the max value the counter can reach to
856 // determine the max value which could be returned 854 // determine the max value which could be returned
857 julong max_counter = (julong)ALL_64_BITS; 855 julong max_counter = (julong)ALL_64_BITS;
858 info_ptr->max_value = (jlong)(max_counter / (freq / NANOS_PER_SEC)); 856 info_ptr->max_value = (jlong)(max_counter / (freq / NANOSECS_PER_SEC));
859 } else { 857 } else {
860 // the performance counter is 64 bits and we will 858 // the performance counter is 64 bits and we will
861 // be using it directly -- so no wrap in 64 bits 859 // be using it directly -- so no wrap in 64 bits
862 info_ptr->max_value = ALL_64_BITS; 860 info_ptr->max_value = ALL_64_BITS;
863 } 861 }