8246112: Remove build-time and run-time checks for clock_gettime and CLOCK_MONOTONIC

Reviewed-by: ihse, erikj, gziemski, hseigel
This commit is contained in:
David Holmes 2021-01-27 01:18:52 +00:00
parent 19b6f61bd2
commit 6f2be9c608
16 changed files with 90 additions and 359 deletions

View file

@ -123,8 +123,6 @@ julong os::Bsd::_physical_memory = 0;
#ifdef __APPLE__
mach_timebase_info_data_t os::Bsd::_timebase_info = {0, 0};
volatile uint64_t os::Bsd::_max_abstime = 0;
#else
int (*os::Bsd::_clock_gettime)(clockid_t, struct timespec *) = NULL;
#endif
pthread_t os::Bsd::_main_thread;
int os::Bsd::_page_size = -1;
@ -789,40 +787,13 @@ double os::elapsedVTime() {
return elapsedTime();
}
jlong os::javaTimeMillis() {
timeval time;
int status = gettimeofday(&time, NULL);
assert(status != -1, "bsd error");
return jlong(time.tv_sec) * 1000 + jlong(time.tv_usec / 1000);
}
void os::javaTimeSystemUTC(jlong &seconds, jlong &nanos) {
timeval time;
int status = gettimeofday(&time, NULL);
assert(status != -1, "bsd error");
seconds = jlong(time.tv_sec);
nanos = jlong(time.tv_usec) * 1000;
}
#ifndef __APPLE__
#ifndef CLOCK_MONOTONIC
#define CLOCK_MONOTONIC (1)
#endif
#endif
#ifdef __APPLE__
void os::Bsd::clock_init() {
mach_timebase_info(&_timebase_info);
}
#else
void os::Bsd::clock_init() {
struct timespec res;
struct timespec tp;
if (::clock_getres(CLOCK_MONOTONIC, &res) == 0 &&
::clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
// yes, monotonic clock is supported
_clock_gettime = ::clock_gettime;
}
// Nothing to do
}
#endif
@ -854,45 +825,15 @@ jlong os::javaTimeNanos() {
return (prev == obsv) ? now : obsv;
}
#else // __APPLE__
jlong os::javaTimeNanos() {
if (os::supports_monotonic_clock()) {
struct timespec tp;
int status = Bsd::_clock_gettime(CLOCK_MONOTONIC, &tp);
assert(status == 0, "gettime error");
jlong result = jlong(tp.tv_sec) * (1000 * 1000 * 1000) + jlong(tp.tv_nsec);
return result;
} else {
timeval time;
int status = gettimeofday(&time, NULL);
assert(status != -1, "bsd error");
jlong usecs = jlong(time.tv_sec) * (1000 * 1000) + jlong(time.tv_usec);
return 1000 * usecs;
}
void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
info_ptr->max_value = ALL_64_BITS;
info_ptr->may_skip_backward = false; // not subject to resetting or drifting
info_ptr->may_skip_forward = false; // not subject to resetting or drifting
info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time
}
#endif // __APPLE__
void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
if (os::supports_monotonic_clock()) {
info_ptr->max_value = ALL_64_BITS;
// CLOCK_MONOTONIC - amount of time since some arbitrary point in the past
info_ptr->may_skip_backward = false; // not subject to resetting or drifting
info_ptr->may_skip_forward = false; // not subject to resetting or drifting
} else {
// gettimeofday - based on time in seconds since the Epoch thus does not wrap
info_ptr->max_value = ALL_64_BITS;
// gettimeofday is a real time clock so it skips
info_ptr->may_skip_backward = true;
info_ptr->may_skip_forward = true;
}
info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time
}
// Return the real, user, and system times in seconds from an
// arbitrary fixed point in the past.
bool os::getTimesSecs(double* process_real_time,
@ -2812,4 +2753,3 @@ bool os::start_debugging(char *buf, int buflen) {
}
void os::print_memory_mappings(char* addr, size_t bytes, outputStream* st) {}