changeset 58821:74ecb602ffb0

8237857: LogDecorations::uptimenanos is implemented incorrectly Reviewed-by: dcubed, kbarrett
author dholmes
date Wed, 29 Jan 2020 23:53:16 -0500
parents d20418cfe16e
children 68181ac4ce7d
files src/hotspot/share/logging/logConfiguration.cpp src/hotspot/share/logging/logDecorations.cpp src/hotspot/share/logging/logDecorations.hpp test/hotspot/gtest/logging/test_logDecorations.cpp
diffstat 4 files changed, 20 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/logging/logConfiguration.cpp	Thu Jan 30 05:05:04 2020 +0100
+++ b/src/hotspot/share/logging/logConfiguration.cpp	Wed Jan 29 23:53:16 2020 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2020, Oracle and/or its affiliates. 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
@@ -102,7 +102,6 @@
 
 void LogConfiguration::initialize(jlong vm_start_time) {
   LogFileOutput::set_file_name_parameters(vm_start_time);
-  LogDecorations::initialize(vm_start_time);
   assert(_outputs == NULL, "Should not initialize _outputs before this function, initialize called twice?");
   _outputs = NEW_C_HEAP_ARRAY(LogOutput*, 2, mtLogging);
   _outputs[0] = &StdoutLog;
--- a/src/hotspot/share/logging/logDecorations.cpp	Thu Jan 30 05:05:04 2020 +0100
+++ b/src/hotspot/share/logging/logDecorations.cpp	Wed Jan 29 23:53:16 2020 -0500
@@ -30,7 +30,6 @@
 #include "runtime/thread.inline.hpp"
 #include "services/management.hpp"
 
-jlong LogDecorations::_vm_start_time_millis = 0;
 const char* volatile LogDecorations::_host_name = NULL;
 
 LogDecorations::LogDecorations(LogLevelType level, const LogTagSet &tagset, const LogDecorators &decorators)
@@ -38,10 +37,6 @@
   create_decorations(decorators);
 }
 
-void LogDecorations::initialize(jlong vm_start_time) {
-  _vm_start_time_millis = vm_start_time;
-}
-
 const char* LogDecorations::host_name() {
   const char* host_name = Atomic::load_acquire(&_host_name);
   if (host_name == NULL) {
@@ -97,9 +92,14 @@
   ASSERT_AND_RETURN(written, pos)
 }
 
+// Small helper for uptime conversion
+static jlong elapsed_time(int unit_multiplier) {
+  return (jlong)(os::elapsedTime() * unit_multiplier);
+}
+
 char * LogDecorations::create_uptimemillis_decoration(char* pos) {
   int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer),
-                             INT64_FORMAT "ms", nanos_to_millis(os::elapsed_counter()));
+                             INT64_FORMAT "ms", elapsed_time(MILLIUNITS));
   ASSERT_AND_RETURN(written, pos)
 }
 
@@ -109,7 +109,7 @@
 }
 
 char * LogDecorations::create_uptimenanos_decoration(char* pos) {
-  int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer), INT64_FORMAT "ns", os::elapsed_counter());
+  int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer), INT64_FORMAT "ns", elapsed_time(NANOUNITS));
   ASSERT_AND_RETURN(written, pos)
 }
 
--- a/src/hotspot/share/logging/logDecorations.hpp	Thu Jan 30 05:05:04 2020 +0100
+++ b/src/hotspot/share/logging/logDecorations.hpp	Wed Jan 29 23:53:16 2020 -0500
@@ -36,7 +36,6 @@
   char* _decoration_offset[LogDecorators::Count];
   LogLevelType _level;
   const LogTagSet& _tagset;
-  static jlong _vm_start_time_millis;
   static const char* volatile _host_name;
 
   const char* host_name();
@@ -47,8 +46,6 @@
 #undef DECORATOR
 
  public:
-  static void initialize(jlong vm_start_time);
-
   LogDecorations(LogLevelType level, const LogTagSet& tagset, const LogDecorators& decorators);
 
   void set_level(LogLevelType level) {
--- a/test/hotspot/gtest/logging/test_logDecorations.cpp	Thu Jan 30 05:05:04 2020 +0100
+++ b/test/hotspot/gtest/logging/test_logDecorations.cpp	Wed Jan 29 23:53:16 2020 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2020, Oracle and/or its affiliates. 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
@@ -86,14 +86,16 @@
   struct {
     const LogDecorators::Decorator decorator;
     const char* suffix;
+    const char* desc;
   } test_decorator[] = {
-    { LogDecorators::timemillis_decorator, "ms" },
-    { LogDecorators::uptimemillis_decorator, "ms" },
-    { LogDecorators::timenanos_decorator, "ns" },
-    { LogDecorators::uptimenanos_decorator, "ns" }
+    { LogDecorators::timemillis_decorator, "ms", "timemillis" },
+    { LogDecorators::uptimemillis_decorator, "ms", "uptimemillis" },
+    { LogDecorators::timenanos_decorator, "ns", "timenanos" },
+    { LogDecorators::uptimenanos_decorator, "ns", "uptimenanos" }
   };
 
   for (uint i = 0; i < ARRAY_SIZE(test_decorator); i++) {
+    tty->print_cr("Processing Decorator %s", test_decorator[i].desc);
     LogDecorators::Decorator decorator = test_decorator[i].decorator;
     LogDecorators decorator_selection;
     ASSERT_TRUE(decorator_selection.parse(LogDecorators::name(decorator)));
@@ -112,9 +114,13 @@
     // Verify timestamp values
     julong prev = 0;
     for (int i = 0; i < 3; i++) {
-      os::naked_short_sleep(5);
+      // The sleep needs to be longer than the timer resolution to ensure
+      // we see updates to 'timemillis'. Windows has the lowest resolution
+      // at 15-16ms, so we use 20.
+      os::naked_short_sleep(20);
       LogDecorations d(LogLevel::Info, tagset, decorator_selection);
       julong val = strtoull(d.decoration(decorator), NULL, 10);
+      tty->print_cr("Read value: " UINT64_FORMAT, val);
       ASSERT_LT(prev, val);
       prev = val;
     }