Skip to content

Commit 1c6fa11

Browse files
committed
8273979: move some os time related functions to os_posix for POSIX platforms
Reviewed-by: dholmes, lucy
1 parent 45adc92 commit 1c6fa11

File tree

4 files changed

+65
-175
lines changed

4 files changed

+65
-175
lines changed

src/hotspot/os/aix/os_aix.cpp

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2012, 2020 SAP SE. All rights reserved.
3+
* Copyright (c) 2012, 2021 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -182,8 +182,6 @@ int os::Aix::_extshm = -1;
182182
// local variables
183183

184184
static volatile jlong max_real_time = 0;
185-
static jlong initial_time_count = 0;
186-
static int clock_tics_per_sec = 100;
187185

188186
// Process break recorded at startup.
189187
static address g_brk_at_startup = NULL;
@@ -921,21 +919,6 @@ void os::free_thread(OSThread* osthread) {
921919
////////////////////////////////////////////////////////////////////////////////
922920
// time support
923921

924-
// Time since start-up in seconds to a fine granularity.
925-
double os::elapsedTime() {
926-
return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution
927-
}
928-
929-
jlong os::elapsed_counter() {
930-
return javaTimeNanos() - initial_time_count;
931-
}
932-
933-
jlong os::elapsed_frequency() {
934-
return NANOSECS_PER_SEC; // nanosecond resolution
935-
}
936-
937-
bool os::supports_vtime() { return true; }
938-
939922
double os::elapsedVTime() {
940923
struct rusage usage;
941924
int retval = getrusage(RUSAGE_THREAD, &usage);
@@ -1002,41 +985,6 @@ void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
1002985
info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time
1003986
}
1004987

1005-
// Return the real, user, and system times in seconds from an
1006-
// arbitrary fixed point in the past.
1007-
bool os::getTimesSecs(double* process_real_time,
1008-
double* process_user_time,
1009-
double* process_system_time) {
1010-
struct tms ticks;
1011-
clock_t real_ticks = times(&ticks);
1012-
1013-
if (real_ticks == (clock_t) (-1)) {
1014-
return false;
1015-
} else {
1016-
double ticks_per_second = (double) clock_tics_per_sec;
1017-
*process_user_time = ((double) ticks.tms_utime) / ticks_per_second;
1018-
*process_system_time = ((double) ticks.tms_stime) / ticks_per_second;
1019-
*process_real_time = ((double) real_ticks) / ticks_per_second;
1020-
1021-
return true;
1022-
}
1023-
}
1024-
1025-
char * os::local_time_string(char *buf, size_t buflen) {
1026-
struct tm t;
1027-
time_t long_time;
1028-
time(&long_time);
1029-
localtime_r(&long_time, &t);
1030-
jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d",
1031-
t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
1032-
t.tm_hour, t.tm_min, t.tm_sec);
1033-
return buf;
1034-
}
1035-
1036-
struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
1037-
return localtime_r(clock, res);
1038-
}
1039-
1040988
intx os::current_thread_id() {
1041989
return (intx)pthread_self();
1042990
}
@@ -2402,13 +2350,9 @@ void os::init(void) {
24022350
// need libperfstat etc.
24032351
os::Aix::initialize_system_info();
24042352

2405-
clock_tics_per_sec = sysconf(_SC_CLK_TCK);
2406-
24072353
// _main_thread points to the thread that created/loaded the JVM.
24082354
Aix::_main_thread = pthread_self();
24092355

2410-
initial_time_count = javaTimeNanos();
2411-
24122356
os::Posix::init();
24132357
}
24142358

src/hotspot/os/bsd/os_bsd.cpp

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ volatile uint64_t os::Bsd::_max_abstime = 0;
123123
pthread_t os::Bsd::_main_thread;
124124
int os::Bsd::_page_size = -1;
125125

126-
static jlong initial_time_count=0;
127-
128-
static int clock_tics_per_sec = 100;
129-
130126
#if defined(__APPLE__) && defined(__x86_64__)
131127
static const int processor_id_unassigned = -1;
132128
static const int processor_id_assigning = -2;
@@ -746,22 +742,6 @@ void os::free_thread(OSThread* osthread) {
746742

747743
////////////////////////////////////////////////////////////////////////////////
748744
// time support
749-
750-
// Time since start-up in seconds to a fine granularity.
751-
double os::elapsedTime() {
752-
return ((double)os::elapsed_counter()) / os::elapsed_frequency();
753-
}
754-
755-
jlong os::elapsed_counter() {
756-
return javaTimeNanos() - initial_time_count;
757-
}
758-
759-
jlong os::elapsed_frequency() {
760-
return NANOSECS_PER_SEC; // nanosecond resolution
761-
}
762-
763-
bool os::supports_vtime() { return true; }
764-
765745
double os::elapsedVTime() {
766746
// better than nothing, but not much
767747
return elapsedTime();
@@ -811,45 +791,8 @@ void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
811791
info_ptr->may_skip_forward = false; // not subject to resetting or drifting
812792
info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time
813793
}
814-
815794
#endif // __APPLE__
816795

817-
// Return the real, user, and system times in seconds from an
818-
// arbitrary fixed point in the past.
819-
bool os::getTimesSecs(double* process_real_time,
820-
double* process_user_time,
821-
double* process_system_time) {
822-
struct tms ticks;
823-
clock_t real_ticks = times(&ticks);
824-
825-
if (real_ticks == (clock_t) (-1)) {
826-
return false;
827-
} else {
828-
double ticks_per_second = (double) clock_tics_per_sec;
829-
*process_user_time = ((double) ticks.tms_utime) / ticks_per_second;
830-
*process_system_time = ((double) ticks.tms_stime) / ticks_per_second;
831-
*process_real_time = ((double) real_ticks) / ticks_per_second;
832-
833-
return true;
834-
}
835-
}
836-
837-
838-
char * os::local_time_string(char *buf, size_t buflen) {
839-
struct tm t;
840-
time_t long_time;
841-
time(&long_time);
842-
localtime_r(&long_time, &t);
843-
jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d",
844-
t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
845-
t.tm_hour, t.tm_min, t.tm_sec);
846-
return buf;
847-
}
848-
849-
struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
850-
return localtime_r(clock, res);
851-
}
852-
853796
// Information of current thread in variety of formats
854797
pid_t os::Bsd::gettid() {
855798
int retval = -1;
@@ -1990,8 +1933,6 @@ extern void report_error(char* file_name, int line_no, char* title,
19901933
void os::init(void) {
19911934
char dummy; // used to get a guess on initial stack address
19921935

1993-
clock_tics_per_sec = CLK_TCK;
1994-
19951936
Bsd::set_page_size(getpagesize());
19961937
if (Bsd::page_size() == -1) {
19971938
fatal("os_bsd.cpp: os::init: sysconf failed (%s)", os::strerror(errno));
@@ -2004,7 +1945,6 @@ void os::init(void) {
20041945
Bsd::_main_thread = pthread_self();
20051946

20061947
Bsd::clock_init();
2007-
initial_time_count = javaTimeNanos();
20081948

20091949
os::Posix::init();
20101950
}

src/hotspot/os/linux/os_linux.cpp

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ os::Linux::mallinfo_func_t os::Linux::_mallinfo = NULL;
171171
os::Linux::mallinfo2_func_t os::Linux::_mallinfo2 = NULL;
172172
#endif // __GLIBC__
173173

174-
static jlong initial_time_count=0;
175-
176174
static int clock_tics_per_sec = 100;
177175

178176
// If the VM might have been created on the primordial thread, we need to resolve the
@@ -1266,22 +1264,6 @@ void os::Linux::capture_initial_stack(size_t max_size) {
12661264

12671265
////////////////////////////////////////////////////////////////////////////////
12681266
// time support
1269-
1270-
// Time since start-up in seconds to a fine granularity.
1271-
double os::elapsedTime() {
1272-
return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution
1273-
}
1274-
1275-
jlong os::elapsed_counter() {
1276-
return javaTimeNanos() - initial_time_count;
1277-
}
1278-
1279-
jlong os::elapsed_frequency() {
1280-
return NANOSECS_PER_SEC; // nanosecond resolution
1281-
}
1282-
1283-
bool os::supports_vtime() { return true; }
1284-
12851267
double os::elapsedVTime() {
12861268
struct rusage usage;
12871269
int retval = getrusage(RUSAGE_THREAD, &usage);
@@ -1319,42 +1301,6 @@ void os::Linux::fast_thread_clock_init() {
13191301
}
13201302
}
13211303

1322-
// Return the real, user, and system times in seconds from an
1323-
// arbitrary fixed point in the past.
1324-
bool os::getTimesSecs(double* process_real_time,
1325-
double* process_user_time,
1326-
double* process_system_time) {
1327-
struct tms ticks;
1328-
clock_t real_ticks = times(&ticks);
1329-
1330-
if (real_ticks == (clock_t) (-1)) {
1331-
return false;
1332-
} else {
1333-
double ticks_per_second = (double) clock_tics_per_sec;
1334-
*process_user_time = ((double) ticks.tms_utime) / ticks_per_second;
1335-
*process_system_time = ((double) ticks.tms_stime) / ticks_per_second;
1336-
*process_real_time = ((double) real_ticks) / ticks_per_second;
1337-
1338-
return true;
1339-
}
1340-
}
1341-
1342-
1343-
char * os::local_time_string(char *buf, size_t buflen) {
1344-
struct tm t;
1345-
time_t long_time;
1346-
time(&long_time);
1347-
localtime_r(&long_time, &t);
1348-
jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d",
1349-
t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
1350-
t.tm_hour, t.tm_min, t.tm_sec);
1351-
return buf;
1352-
}
1353-
1354-
struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
1355-
return localtime_r(clock, res);
1356-
}
1357-
13581304
// thread_id is kernel thread id (similar to Solaris LWP id)
13591305
intx os::current_thread_id() { return os::Linux::gettid(); }
13601306
int os::current_process_id() {
@@ -4431,8 +4377,6 @@ void os::init(void) {
44314377
check_pax();
44324378

44334379
os::Posix::init();
4434-
4435-
initial_time_count = javaTimeNanos();
44364380
}
44374381

44384382
// To install functions for atexit system call

src/hotspot/os/posix/os_posix.cpp

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
#include <sys/mman.h>
6161
#include <sys/resource.h>
6262
#include <sys/socket.h>
63+
#include <sys/time.h>
64+
#include <sys/times.h>
6365
#include <sys/types.h>
6466
#include <sys/utsname.h>
6567
#include <sys/wait.h>
@@ -87,6 +89,10 @@
8789
#define assert_with_errno(cond, msg) check_with_errno(assert, cond, msg)
8890
#define guarantee_with_errno(cond, msg) check_with_errno(guarantee, cond, msg)
8991

92+
static jlong initial_time_count = 0;
93+
94+
static int clock_tics_per_sec = 100;
95+
9096
// Check core dump limit and report possible place where core can be found
9197
void os::check_dump_limit(char* buffer, size_t bufferSize) {
9298
if (!FLAG_IS_DEFAULT(CreateCoredumpOnCrash) && !CreateCoredumpOnCrash) {
@@ -1224,7 +1230,11 @@ static bool _use_clock_monotonic_condattr = false;
12241230
// Determine what POSIX API's are present and do appropriate
12251231
// configuration.
12261232
void os::Posix::init(void) {
1227-
1233+
#if defined(_ALLBSD_SOURCE)
1234+
clock_tics_per_sec = CLK_TCK;
1235+
#else
1236+
clock_tics_per_sec = sysconf(_SC_CLK_TCK);
1237+
#endif
12281238
// NOTE: no logging available when this is called. Put logging
12291239
// statements in init_2().
12301240

@@ -1256,6 +1266,8 @@ void os::Posix::init(void) {
12561266
_use_clock_monotonic_condattr = true;
12571267
}
12581268
}
1269+
1270+
initial_time_count = javaTimeNanos();
12591271
}
12601272

12611273
void os::Posix::init_2(void) {
@@ -1423,9 +1435,59 @@ void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
14231435
info_ptr->may_skip_forward = false; // not subject to resetting or drifting
14241436
info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time
14251437
}
1426-
14271438
#endif // ! APPLE && !AIX
14281439

1440+
// Time since start-up in seconds to a fine granularity.
1441+
double os::elapsedTime() {
1442+
return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution
1443+
}
1444+
1445+
jlong os::elapsed_counter() {
1446+
return os::javaTimeNanos() - initial_time_count;
1447+
}
1448+
1449+
jlong os::elapsed_frequency() {
1450+
return NANOSECS_PER_SEC; // nanosecond resolution
1451+
}
1452+
1453+
bool os::supports_vtime() { return true; }
1454+
1455+
// Return the real, user, and system times in seconds from an
1456+
// arbitrary fixed point in the past.
1457+
bool os::getTimesSecs(double* process_real_time,
1458+
double* process_user_time,
1459+
double* process_system_time) {
1460+
struct tms ticks;
1461+
clock_t real_ticks = times(&ticks);
1462+
1463+
if (real_ticks == (clock_t) (-1)) {
1464+
return false;
1465+
} else {
1466+
double ticks_per_second = (double) clock_tics_per_sec;
1467+
*process_user_time = ((double) ticks.tms_utime) / ticks_per_second;
1468+
*process_system_time = ((double) ticks.tms_stime) / ticks_per_second;
1469+
*process_real_time = ((double) real_ticks) / ticks_per_second;
1470+
1471+
return true;
1472+
}
1473+
}
1474+
1475+
char * os::local_time_string(char *buf, size_t buflen) {
1476+
struct tm t;
1477+
time_t long_time;
1478+
time(&long_time);
1479+
localtime_r(&long_time, &t);
1480+
jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d",
1481+
t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
1482+
t.tm_hour, t.tm_min, t.tm_sec);
1483+
return buf;
1484+
}
1485+
1486+
struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
1487+
return localtime_r(clock, res);
1488+
}
1489+
1490+
14291491
// Shared pthread_mutex/cond based PlatformEvent implementation.
14301492
// Not currently usable by Solaris.
14311493

0 commit comments

Comments
 (0)