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

Mon, 09 Feb 2009 12:26:05 -0800

author
ysr
date
Mon, 09 Feb 2009 12:26:05 -0800
changeset 983
773234c55e8c
parent 982
1e458753107d
child 984
fe3d7c11b4b7

6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
Summary: replaced localtime() with localtime_r() on Solaris and Linux.
Reviewed-by: apetrusenko, dholmes, jmasa

src/os/linux/vm/os_linux.cpp file | annotate | diff | comparison | revisions
src/os/solaris/vm/os_solaris.cpp file | annotate | diff | comparison | revisions
src/os/windows/vm/os_windows.cpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/os.cpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/os.hpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/os/linux/vm/os_linux.cpp	Mon Feb 09 17:33:06 2009 +0300
     1.2 +++ b/src/os/linux/vm/os_linux.cpp	Mon Feb 09 12:26:05 2009 -0800
     1.3 @@ -1432,6 +1432,10 @@
     1.4    return buf;
     1.5  }
     1.6  
     1.7 +struct tm* os::localtime_pd(const time_t* clock, struct tm*  res) {
     1.8 +  return localtime_r(clock, res);
     1.9 +}
    1.10 +
    1.11  ////////////////////////////////////////////////////////////////////////////////
    1.12  // runtime exit support
    1.13  
     2.1 --- a/src/os/solaris/vm/os_solaris.cpp	Mon Feb 09 17:33:06 2009 +0300
     2.2 +++ b/src/os/solaris/vm/os_solaris.cpp	Mon Feb 09 12:26:05 2009 -0800
     2.3 @@ -323,6 +323,10 @@
     2.4    return (size_t)(base - bottom);
     2.5  }
     2.6  
     2.7 +struct tm* os::localtime_pd(const time_t* clock, struct tm*  res) {
     2.8 +  return localtime_r(clock, res);
     2.9 +}
    2.10 +
    2.11  // interruptible infrastructure
    2.12  
    2.13  // setup_interruptible saves the thread state before going into an
     3.1 --- a/src/os/windows/vm/os_windows.cpp	Mon Feb 09 17:33:06 2009 +0300
     3.2 +++ b/src/os/windows/vm/os_windows.cpp	Mon Feb 09 12:26:05 2009 -0800
     3.3 @@ -327,6 +327,14 @@
     3.4    return sz;
     3.5  }
     3.6  
     3.7 +struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
     3.8 +  const struct tm* time_struct_ptr = localtime(clock);
     3.9 +  if (time_struct_ptr != NULL) {
    3.10 +    *res = *time_struct_ptr;
    3.11 +    return res;
    3.12 +  }
    3.13 +  return NULL;
    3.14 +}
    3.15  
    3.16  LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo);
    3.17  
     4.1 --- a/src/share/vm/runtime/os.cpp	Mon Feb 09 17:33:06 2009 +0300
     4.2 +++ b/src/share/vm/runtime/os.cpp	Mon Feb 09 12:26:05 2009 -0800
     4.3 @@ -74,13 +74,11 @@
     4.4    const int milliseconds_after_second =
     4.5      milliseconds_since_19700101 % milliseconds_per_microsecond;
     4.6    // Convert the time value to a tm and timezone variable
     4.7 -  const struct tm *time_struct_temp = localtime(&seconds_since_19700101);
     4.8 -  if (time_struct_temp == NULL) {
     4.9 -    assert(false, "Failed localtime");
    4.10 +  struct tm time_struct;
    4.11 +  if (localtime_pd(&seconds_since_19700101, &time_struct) == NULL) {
    4.12 +    assert(false, "Failed localtime_pd");
    4.13      return NULL;
    4.14    }
    4.15 -  // Save the results of localtime
    4.16 -  const struct tm time_struct = *time_struct_temp;
    4.17    const time_t zone = timezone;
    4.18  
    4.19    // If daylight savings time is in effect,
    4.20 @@ -93,10 +91,10 @@
    4.21      UTC_to_local = UTC_to_local - seconds_per_hour;
    4.22    }
    4.23    // Compute the time zone offset.
    4.24 -  //    localtime(3C) sets timezone to the difference (in seconds)
    4.25 +  //    localtime_pd() sets timezone to the difference (in seconds)
    4.26    //    between UTC and and local time.
    4.27    //    ISO 8601 says we need the difference between local time and UTC,
    4.28 -  //    we change the sign of the localtime(3C) result.
    4.29 +  //    we change the sign of the localtime_pd() result.
    4.30    const time_t local_to_UTC = -(UTC_to_local);
    4.31    // Then we have to figure out if if we are ahead (+) or behind (-) UTC.
    4.32    char sign_local_to_UTC = '+';
     5.1 --- a/src/share/vm/runtime/os.hpp	Mon Feb 09 17:33:06 2009 +0300
     5.2 +++ b/src/share/vm/runtime/os.hpp	Mon Feb 09 12:26:05 2009 -0800
     5.3 @@ -120,7 +120,8 @@
     5.4    // Return current local time in a string (YYYY-MM-DD HH:MM:SS).
     5.5    // It is MT safe, but not async-safe, as reading time zone
     5.6    // information may require a lock on some platforms.
     5.7 -  static char* local_time_string(char *buf, size_t buflen);
     5.8 +  static char*      local_time_string(char *buf, size_t buflen);
     5.9 +  static struct tm* localtime_pd     (const time_t* clock, struct tm*  res);
    5.10    // Fill in buffer with current local time as an ISO-8601 string.
    5.11    // E.g., YYYY-MM-DDThh:mm:ss.mmm+zzzz.
    5.12    // Returns buffer, or NULL if it failed.

mercurial