提交 4385acc4 编写于 作者: Y ysr

6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function

Summary: replaced localtime() with localtime_r() on Solaris and Linux.
Reviewed-by: apetrusenko, dholmes, jmasa
上级 08c83944
...@@ -1432,6 +1432,10 @@ char * os::local_time_string(char *buf, size_t buflen) { ...@@ -1432,6 +1432,10 @@ char * os::local_time_string(char *buf, size_t buflen) {
return buf; return buf;
} }
struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
return localtime_r(clock, res);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// runtime exit support // runtime exit support
......
...@@ -323,6 +323,10 @@ size_t os::current_stack_size() { ...@@ -323,6 +323,10 @@ size_t os::current_stack_size() {
return (size_t)(base - bottom); return (size_t)(base - bottom);
} }
struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
return localtime_r(clock, res);
}
// interruptible infrastructure // interruptible infrastructure
// setup_interruptible saves the thread state before going into an // setup_interruptible saves the thread state before going into an
......
...@@ -327,6 +327,14 @@ size_t os::current_stack_size() { ...@@ -327,6 +327,14 @@ size_t os::current_stack_size() {
return sz; return sz;
} }
struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
const struct tm* time_struct_ptr = localtime(clock);
if (time_struct_ptr != NULL) {
*res = *time_struct_ptr;
return res;
}
return NULL;
}
LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo); LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo);
......
...@@ -74,13 +74,11 @@ char* os::iso8601_time(char* buffer, size_t buffer_length) { ...@@ -74,13 +74,11 @@ char* os::iso8601_time(char* buffer, size_t buffer_length) {
const int milliseconds_after_second = const int milliseconds_after_second =
milliseconds_since_19700101 % milliseconds_per_microsecond; milliseconds_since_19700101 % milliseconds_per_microsecond;
// Convert the time value to a tm and timezone variable // Convert the time value to a tm and timezone variable
const struct tm *time_struct_temp = localtime(&seconds_since_19700101); struct tm time_struct;
if (time_struct_temp == NULL) { if (localtime_pd(&seconds_since_19700101, &time_struct) == NULL) {
assert(false, "Failed localtime"); assert(false, "Failed localtime_pd");
return NULL; return NULL;
} }
// Save the results of localtime
const struct tm time_struct = *time_struct_temp;
const time_t zone = timezone; const time_t zone = timezone;
// If daylight savings time is in effect, // If daylight savings time is in effect,
...@@ -93,10 +91,10 @@ char* os::iso8601_time(char* buffer, size_t buffer_length) { ...@@ -93,10 +91,10 @@ char* os::iso8601_time(char* buffer, size_t buffer_length) {
UTC_to_local = UTC_to_local - seconds_per_hour; UTC_to_local = UTC_to_local - seconds_per_hour;
} }
// Compute the time zone offset. // Compute the time zone offset.
// localtime(3C) sets timezone to the difference (in seconds) // localtime_pd() sets timezone to the difference (in seconds)
// between UTC and and local time. // between UTC and and local time.
// ISO 8601 says we need the difference between local time and UTC, // ISO 8601 says we need the difference between local time and UTC,
// we change the sign of the localtime(3C) result. // we change the sign of the localtime_pd() result.
const time_t local_to_UTC = -(UTC_to_local); const time_t local_to_UTC = -(UTC_to_local);
// Then we have to figure out if if we are ahead (+) or behind (-) UTC. // Then we have to figure out if if we are ahead (+) or behind (-) UTC.
char sign_local_to_UTC = '+'; char sign_local_to_UTC = '+';
......
...@@ -120,7 +120,8 @@ class os: AllStatic { ...@@ -120,7 +120,8 @@ class os: AllStatic {
// Return current local time in a string (YYYY-MM-DD HH:MM:SS). // Return current local time in a string (YYYY-MM-DD HH:MM:SS).
// It is MT safe, but not async-safe, as reading time zone // It is MT safe, but not async-safe, as reading time zone
// information may require a lock on some platforms. // information may require a lock on some platforms.
static char* local_time_string(char *buf, size_t buflen); static char* local_time_string(char *buf, size_t buflen);
static struct tm* localtime_pd (const time_t* clock, struct tm* res);
// Fill in buffer with current local time as an ISO-8601 string. // Fill in buffer with current local time as an ISO-8601 string.
// E.g., YYYY-MM-DDThh:mm:ss.mmm+zzzz. // E.g., YYYY-MM-DDThh:mm:ss.mmm+zzzz.
// Returns buffer, or NULL if it failed. // Returns buffer, or NULL if it failed.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册