Skip to content

Commit

Permalink
Backport 1c6fa113bd06585945e077f0d2004a291c27946d
Browse files Browse the repository at this point in the history
  • Loading branch information
duke committed Aug 28, 2024
1 parent 6f382d1 commit b879690
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 175 deletions.
58 changes: 1 addition & 57 deletions src/hotspot/os/aix/os_aix.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}

Expand Down
60 changes: 0 additions & 60 deletions src/hotspot/os/bsd/os_bsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -2045,7 +1986,6 @@ void os::init(void) {
Bsd::_main_thread = pthread_self();

Bsd::clock_init();
initial_time_count = javaTimeNanos();

os::Posix::init();
}
Expand Down
56 changes: 0 additions & 56 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -4505,8 +4451,6 @@ void os::init(void) {
check_pax();

os::Posix::init();

initial_time_count = javaTimeNanos();
}

// To install functions for atexit system call
Expand Down
66 changes: 64 additions & 2 deletions src/hotspot/os/posix/os_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/wait.h>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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().

Expand Down Expand Up @@ -1342,6 +1352,8 @@ void os::Posix::init(void) {
_use_clock_monotonic_condattr = true;
}
}

initial_time_count = javaTimeNanos();
}

void os::Posix::init_2(void) {
Expand Down Expand Up @@ -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.

Expand Down

0 comments on commit b879690

Please sign in to comment.