A DESCRIPTION OF THE PROBLEM :
On error reporting, Hotspot calls the ctime() function to transform date and time. However, this function is not thread-safe function.
Other functions that transform date and time were replaced to thread-safe functions (e.g. localtime_r()). In additional, ctime() is marked as obsolete, and recommended to the use of strftime() instead. And strftime() is already called to transform time zone.
Therefore, to print time information, there should be used strftime() only at first, and should be used ctime_r() only if localtime_pd() returns null..
src/hotspot/share/runtime/os.cpp
---------- BEGIN SOURCE ----------
void os::print_date_and_time(outputStream *st, char* buf, size_t buflen) {
const int secs_per_day = 86400;
const int secs_per_hour = 3600;
const int secs_per_min = 60;
time_t tloc;
(void)time(&tloc);
char* timestring = ctime(&tloc); // ctime adds newline.
// edit out the newline
char* nl = strchr(timestring, '\n');
if (nl != NULL) {
*nl = '\0';
}
struct tm tz;
if (localtime_pd(&tloc, &tz) != NULL) {
::strftime(buf, buflen, "%Z", &tz);
st->print("Time: %s %s", timestring, buf);
} else {
st->print("Time: %s", timestring);
}
---------- END SOURCE ----------
FREQUENCY : always
On error reporting, Hotspot calls the ctime() function to transform date and time. However, this function is not thread-safe function.
Other functions that transform date and time were replaced to thread-safe functions (e.g. localtime_r()). In additional, ctime() is marked as obsolete, and recommended to the use of strftime() instead. And strftime() is already called to transform time zone.
Therefore, to print time information, there should be used strftime() only at first, and should be used ctime_r() only if localtime_pd() returns null..
src/hotspot/share/runtime/os.cpp
---------- BEGIN SOURCE ----------
void os::print_date_and_time(outputStream *st, char* buf, size_t buflen) {
const int secs_per_day = 86400;
const int secs_per_hour = 3600;
const int secs_per_min = 60;
time_t tloc;
(void)time(&tloc);
char* timestring = ctime(&tloc); // ctime adds newline.
// edit out the newline
char* nl = strchr(timestring, '\n');
if (nl != NULL) {
*nl = '\0';
}
struct tm tz;
if (localtime_pd(&tloc, &tz) != NULL) {
::strftime(buf, buflen, "%Z", &tz);
st->print("Time: %s %s", timestring, buf);
} else {
st->print("Time: %s", timestring);
}
---------- END SOURCE ----------
FREQUENCY : always