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

@ -1268,10 +1268,6 @@ void os::Linux::capture_initial_stack(size_t max_size) {
////////////////////////////////////////////////////////////////////////////////
// time support
#ifndef SUPPORTS_CLOCK_MONOTONIC
#error "Build platform doesn't support clock_gettime and related functionality"
#endif
// Time since start-up in seconds to a fine granularity.
// Used by VMSelfDestructTimer and the MemProfiler.
double os::elapsedTime() {
@ -1300,38 +1296,6 @@ double os::elapsedVTime() {
}
}
jlong os::javaTimeMillis() {
if (os::Posix::supports_clock_gettime()) {
struct timespec ts;
int status = os::Posix::clock_gettime(CLOCK_REALTIME, &ts);
assert_status(status == 0, status, "gettime error");
return jlong(ts.tv_sec) * MILLIUNITS +
jlong(ts.tv_nsec) / NANOUNITS_PER_MILLIUNIT;
} else {
timeval time;
int status = gettimeofday(&time, NULL);
assert(status != -1, "linux error");
return jlong(time.tv_sec) * MILLIUNITS +
jlong(time.tv_usec) / (MICROUNITS / MILLIUNITS);
}
}
void os::javaTimeSystemUTC(jlong &seconds, jlong &nanos) {
if (os::Posix::supports_clock_gettime()) {
struct timespec ts;
int status = os::Posix::clock_gettime(CLOCK_REALTIME, &ts);
assert_status(status == 0, status, "gettime error");
seconds = jlong(ts.tv_sec);
nanos = jlong(ts.tv_nsec);
} else {
timeval time;
int status = gettimeofday(&time, NULL);
assert(status != -1, "linux error");
seconds = jlong(time.tv_sec);
nanos = jlong(time.tv_usec) * (NANOUNITS / MICROUNITS);
}
}
void os::Linux::fast_thread_clock_init() {
if (!UseLinuxPosixThreadCPUClocks) {
return;
@ -1352,47 +1316,12 @@ void os::Linux::fast_thread_clock_init() {
if (pthread_getcpuclockid_func &&
pthread_getcpuclockid_func(_main_thread, &clockid) == 0 &&
os::Posix::clock_getres(clockid, &tp) == 0 && tp.tv_sec == 0) {
clock_getres(clockid, &tp) == 0 && tp.tv_sec == 0) {
_supports_fast_thread_cpu_time = true;
_pthread_getcpuclockid = pthread_getcpuclockid_func;
}
}
jlong os::javaTimeNanos() {
if (os::supports_monotonic_clock()) {
struct timespec tp;
int status = os::Posix::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, "linux error");
jlong usecs = jlong(time.tv_sec) * (1000 * 1000) + jlong(time.tv_usec);
return 1000 * usecs;
}
}
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,
@ -4344,9 +4273,8 @@ OSReturn os::get_native_priority(const Thread* const thread,
jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) {
struct timespec tp;
int rc = os::Posix::clock_gettime(clockid, &tp);
assert(rc == 0, "clock_gettime is expected to return 0 code");
int status = clock_gettime(clockid, &tp);
assert(status == 0, "clock_gettime error: %s", os::strerror(errno));
return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec;
}
@ -4454,12 +4382,6 @@ void os::init(void) {
os::Posix::init();
initial_time_count = javaTimeNanos();
// Always warn if no monotonic clock available
if (!os::Posix::supports_monotonic_clock()) {
warning("No monotonic clock was available - timed services may " \
"be adversely affected if the time-of-day clock changes");
}
}
// To install functions for atexit system call