diff --git a/src/hotspot/os/aix/os_aix.cpp b/src/hotspot/os/aix/os_aix.cpp index 3744f49a65e..917fe4d841d 100644 --- a/src/hotspot/os/aix/os_aix.cpp +++ b/src/hotspot/os/aix/os_aix.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, 2020 SAP SE. All rights reserved. + * Copyright (c) 2012, 2021 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -182,8 +182,6 @@ int os::Aix::_extshm = -1; // local variables static volatile jlong max_real_time = 0; -static jlong initial_time_count = 0; -static int clock_tics_per_sec = 100; // Process break recorded at startup. static address g_brk_at_startup = NULL; @@ -936,21 +934,6 @@ void os::free_thread(OSThread* osthread) { //////////////////////////////////////////////////////////////////////////////// // time support -// Time since start-up in seconds to a fine granularity. -double os::elapsedTime() { - return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution -} - -jlong os::elapsed_counter() { - return javaTimeNanos() - initial_time_count; -} - -jlong os::elapsed_frequency() { - return NANOSECS_PER_SEC; // nanosecond resolution -} - -bool os::supports_vtime() { return true; } - double os::elapsedVTime() { struct rusage usage; int retval = getrusage(RUSAGE_THREAD, &usage); @@ -1017,41 +1000,6 @@ void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) { 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, - double* process_user_time, - double* process_system_time) { - struct tms ticks; - clock_t real_ticks = times(&ticks); - - if (real_ticks == (clock_t) (-1)) { - return false; - } else { - double ticks_per_second = (double) clock_tics_per_sec; - *process_user_time = ((double) ticks.tms_utime) / ticks_per_second; - *process_system_time = ((double) ticks.tms_stime) / ticks_per_second; - *process_real_time = ((double) real_ticks) / ticks_per_second; - - return true; - } -} - -char * os::local_time_string(char *buf, size_t buflen) { - struct tm t; - time_t long_time; - time(&long_time); - localtime_r(&long_time, &t); - jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d", - t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, - t.tm_hour, t.tm_min, t.tm_sec); - return buf; -} - -struct tm* os::localtime_pd(const time_t* clock, struct tm* res) { - return localtime_r(clock, res); -} - intx os::current_thread_id() { return (intx)pthread_self(); } @@ -2417,13 +2365,9 @@ void os::init(void) { // need libperfstat etc. os::Aix::initialize_system_info(); - clock_tics_per_sec = sysconf(_SC_CLK_TCK); - // _main_thread points to the thread that created/loaded the JVM. Aix::_main_thread = pthread_self(); - initial_time_count = javaTimeNanos(); - os::Posix::init(); } diff --git a/src/hotspot/os/bsd/os_bsd.cpp b/src/hotspot/os/bsd/os_bsd.cpp index 65101650372..f32db7ae56a 100644 --- a/src/hotspot/os/bsd/os_bsd.cpp +++ b/src/hotspot/os/bsd/os_bsd.cpp @@ -123,10 +123,6 @@ volatile uint64_t os::Bsd::_max_abstime = 0; pthread_t os::Bsd::_main_thread; int os::Bsd::_page_size = -1; -static jlong initial_time_count=0; - -static int clock_tics_per_sec = 100; - #if defined(__APPLE__) && defined(__x86_64__) static const int processor_id_unassigned = -1; static const int processor_id_assigning = -2; @@ -758,22 +754,6 @@ void os::free_thread(OSThread* osthread) { //////////////////////////////////////////////////////////////////////////////// // time support - -// Time since start-up in seconds to a fine granularity. -double os::elapsedTime() { - return ((double)os::elapsed_counter()) / os::elapsed_frequency(); -} - -jlong os::elapsed_counter() { - return javaTimeNanos() - initial_time_count; -} - -jlong os::elapsed_frequency() { - return NANOSECS_PER_SEC; // nanosecond resolution -} - -bool os::supports_vtime() { return true; } - double os::elapsedVTime() { // better than nothing, but not much return elapsedTime(); @@ -823,45 +803,8 @@ void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) { info_ptr->may_skip_forward = false; // not subject to resetting or drifting info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time } - #endif // __APPLE__ -// Return the real, user, and system times in seconds from an -// arbitrary fixed point in the past. -bool os::getTimesSecs(double* process_real_time, - double* process_user_time, - double* process_system_time) { - struct tms ticks; - clock_t real_ticks = times(&ticks); - - if (real_ticks == (clock_t) (-1)) { - return false; - } else { - double ticks_per_second = (double) clock_tics_per_sec; - *process_user_time = ((double) ticks.tms_utime) / ticks_per_second; - *process_system_time = ((double) ticks.tms_stime) / ticks_per_second; - *process_real_time = ((double) real_ticks) / ticks_per_second; - - return true; - } -} - - -char * os::local_time_string(char *buf, size_t buflen) { - struct tm t; - time_t long_time; - time(&long_time); - localtime_r(&long_time, &t); - jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d", - t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, - t.tm_hour, t.tm_min, t.tm_sec); - return buf; -} - -struct tm* os::localtime_pd(const time_t* clock, struct tm* res) { - return localtime_r(clock, res); -} - // Information of current thread in variety of formats pid_t os::Bsd::gettid() { int retval = -1; @@ -2031,8 +1974,6 @@ extern void report_error(char* file_name, int line_no, char* title, void os::init(void) { char dummy; // used to get a guess on initial stack address - clock_tics_per_sec = CLK_TCK; - Bsd::set_page_size(getpagesize()); if (Bsd::page_size() == -1) { fatal("os_bsd.cpp: os::init: sysconf failed (%s)", os::strerror(errno)); @@ -2045,7 +1986,6 @@ void os::init(void) { Bsd::_main_thread = pthread_self(); Bsd::clock_init(); - initial_time_count = javaTimeNanos(); os::Posix::init(); } diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index 7c951cee51c..c8f75a66a48 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -173,8 +173,6 @@ os::Linux::mallinfo_func_t os::Linux::_mallinfo = NULL; os::Linux::mallinfo2_func_t os::Linux::_mallinfo2 = NULL; #endif // __GLIBC__ -static jlong initial_time_count=0; - static int clock_tics_per_sec = 100; // If the VM might have been created on the primordial thread, we need to resolve the @@ -1336,22 +1334,6 @@ void os::Linux::capture_initial_stack(size_t max_size) { //////////////////////////////////////////////////////////////////////////////// // time support - -// Time since start-up in seconds to a fine granularity. -double os::elapsedTime() { - return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution -} - -jlong os::elapsed_counter() { - return javaTimeNanos() - initial_time_count; -} - -jlong os::elapsed_frequency() { - return NANOSECS_PER_SEC; // nanosecond resolution -} - -bool os::supports_vtime() { return true; } - double os::elapsedVTime() { struct rusage usage; int retval = getrusage(RUSAGE_THREAD, &usage); @@ -1389,42 +1371,6 @@ void os::Linux::fast_thread_clock_init() { } } -// Return the real, user, and system times in seconds from an -// arbitrary fixed point in the past. -bool os::getTimesSecs(double* process_real_time, - double* process_user_time, - double* process_system_time) { - struct tms ticks; - clock_t real_ticks = times(&ticks); - - if (real_ticks == (clock_t) (-1)) { - return false; - } else { - double ticks_per_second = (double) clock_tics_per_sec; - *process_user_time = ((double) ticks.tms_utime) / ticks_per_second; - *process_system_time = ((double) ticks.tms_stime) / ticks_per_second; - *process_real_time = ((double) real_ticks) / ticks_per_second; - - return true; - } -} - - -char * os::local_time_string(char *buf, size_t buflen) { - struct tm t; - time_t long_time; - time(&long_time); - localtime_r(&long_time, &t); - jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d", - t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, - t.tm_hour, t.tm_min, t.tm_sec); - return buf; -} - -struct tm* os::localtime_pd(const time_t* clock, struct tm* res) { - return localtime_r(clock, res); -} - // thread_id is kernel thread id (similar to Solaris LWP id) intx os::current_thread_id() { return os::Linux::gettid(); } int os::current_process_id() { @@ -4505,8 +4451,6 @@ void os::init(void) { check_pax(); os::Posix::init(); - - initial_time_count = javaTimeNanos(); } // To install functions for atexit system call diff --git a/src/hotspot/os/posix/os_posix.cpp b/src/hotspot/os/posix/os_posix.cpp index 4307a189edf..5aec8fc75f7 100644 --- a/src/hotspot/os/posix/os_posix.cpp +++ b/src/hotspot/os/posix/os_posix.cpp @@ -62,6 +62,8 @@ #include #include #include +#include +#include #include #include #include @@ -89,6 +91,10 @@ #define assert_with_errno(cond, msg) check_with_errno(assert, cond, msg) #define guarantee_with_errno(cond, msg) check_with_errno(guarantee, cond, msg) +static jlong initial_time_count = 0; + +static int clock_tics_per_sec = 100; + // Check core dump limit and report possible place where core can be found void os::check_dump_limit(char* buffer, size_t bufferSize) { if (!FLAG_IS_DEFAULT(CreateCoredumpOnCrash) && !CreateCoredumpOnCrash) { @@ -1310,7 +1316,11 @@ static bool _use_clock_monotonic_condattr = false; // Determine what POSIX API's are present and do appropriate // configuration. void os::Posix::init(void) { - +#if defined(_ALLBSD_SOURCE) + clock_tics_per_sec = CLK_TCK; +#else + clock_tics_per_sec = sysconf(_SC_CLK_TCK); +#endif // NOTE: no logging available when this is called. Put logging // statements in init_2(). @@ -1342,6 +1352,8 @@ void os::Posix::init(void) { _use_clock_monotonic_condattr = true; } } + + initial_time_count = javaTimeNanos(); } void os::Posix::init_2(void) { @@ -1509,9 +1521,59 @@ void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) { info_ptr->may_skip_forward = false; // not subject to resetting or drifting info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time } - #endif // ! APPLE && !AIX +// Time since start-up in seconds to a fine granularity. +double os::elapsedTime() { + return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution +} + +jlong os::elapsed_counter() { + return os::javaTimeNanos() - initial_time_count; +} + +jlong os::elapsed_frequency() { + return NANOSECS_PER_SEC; // nanosecond resolution +} + +bool os::supports_vtime() { return true; } + +// Return the real, user, and system times in seconds from an +// arbitrary fixed point in the past. +bool os::getTimesSecs(double* process_real_time, + double* process_user_time, + double* process_system_time) { + struct tms ticks; + clock_t real_ticks = times(&ticks); + + if (real_ticks == (clock_t) (-1)) { + return false; + } else { + double ticks_per_second = (double) clock_tics_per_sec; + *process_user_time = ((double) ticks.tms_utime) / ticks_per_second; + *process_system_time = ((double) ticks.tms_stime) / ticks_per_second; + *process_real_time = ((double) real_ticks) / ticks_per_second; + + return true; + } +} + +char * os::local_time_string(char *buf, size_t buflen) { + struct tm t; + time_t long_time; + time(&long_time); + localtime_r(&long_time, &t); + jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d", + t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, + t.tm_hour, t.tm_min, t.tm_sec); + return buf; +} + +struct tm* os::localtime_pd(const time_t* clock, struct tm* res) { + return localtime_r(clock, res); +} + + // Shared pthread_mutex/cond based PlatformEvent implementation. // Not currently usable by Solaris.