8147348: LogTagLevelExpression not properly initialized in configure_stdout
authormlarsson
Wed, 27 Jan 2016 09:07:10 +0100
changeset 35852 15ca44d4ae0c
parent 35850 34c2f89c8ebb
child 35853 9cffac525e28
8147348: LogTagLevelExpression not properly initialized in configure_stdout Reviewed-by: brutisso, sla
hotspot/src/share/vm/logging/log.cpp
hotspot/src/share/vm/logging/logTagLevelExpression.cpp
hotspot/src/share/vm/logging/logTagLevelExpression.hpp
hotspot/src/share/vm/utilities/internalVMTests.cpp
--- a/hotspot/src/share/vm/logging/log.cpp	Wed Jan 27 05:59:31 2016 +0100
+++ b/hotspot/src/share/vm/logging/log.cpp	Wed Jan 27 09:07:10 2016 +0100
@@ -36,52 +36,54 @@
   remove("loglengthoutput.txt");
 
   // Write long message to output file
-  LogConfiguration::parse_log_arguments("loglengthoutput.txt", "logging=trace",
-    NULL, NULL, NULL);
   ResourceMark rm;
-  outputStream* logstream = LogHandle(logging)::trace_stream();
-  logstream->print_cr("01:1234567890-"
-                      "02:1234567890-"
-                      "03:1234567890-"
-                      "04:1234567890-"
-                      "05:1234567890-"
-                      "06:1234567890-"
-                      "07:1234567890-"
-                      "08:1234567890-"
-                      "09:1234567890-"
-                      "10:1234567890-"
-                      "11:1234567890-"
-                      "12:1234567890-"
-                      "13:1234567890-"
-                      "14:1234567890-"
-                      "15:1234567890-"
-                      "16:1234567890-"
-                      "17:1234567890-"
-                      "18:1234567890-"
-                      "19:1234567890-"
-                      "20:1234567890-"
-                      "21:1234567890-"
-                      "22:1234567890-"
-                      "23:1234567890-"
-                      "24:1234567890-"
-                      "25:1234567890-"
-                      "26:1234567890-"
-                      "27:1234567890-"
-                      "28:1234567890-"
-                      "29:1234567890-"
-                      "30:1234567890-"
-                      "31:1234567890-"
-                      "32:1234567890-"
-                      "33:1234567890-"
-                      "34:1234567890-"
-                      "35:1234567890-"
-                      "36:1234567890-"
-                      "37:1234567890-");
+  LogHandle(logging) log;
+  bool success = LogConfiguration::parse_log_arguments("loglengthoutput.txt", "logging=trace",
+    NULL, NULL, log.error_stream());
+  assert(success, "test unable to configure logging");
+  log.trace("01:1234567890-"
+            "02:1234567890-"
+            "03:1234567890-"
+            "04:1234567890-"
+            "05:1234567890-"
+            "06:1234567890-"
+            "07:1234567890-"
+            "08:1234567890-"
+            "09:1234567890-"
+            "10:1234567890-"
+            "11:1234567890-"
+            "12:1234567890-"
+            "13:1234567890-"
+            "14:1234567890-"
+            "15:1234567890-"
+            "16:1234567890-"
+            "17:1234567890-"
+            "18:1234567890-"
+            "19:1234567890-"
+            "20:1234567890-"
+            "21:1234567890-"
+            "22:1234567890-"
+            "23:1234567890-"
+            "24:1234567890-"
+            "25:1234567890-"
+            "26:1234567890-"
+            "27:1234567890-"
+            "28:1234567890-"
+            "29:1234567890-"
+            "30:1234567890-"
+            "31:1234567890-"
+            "32:1234567890-"
+            "33:1234567890-"
+            "34:1234567890-"
+            "35:1234567890-"
+            "36:1234567890-"
+            "37:1234567890-");
+  LogConfiguration::parse_log_arguments("loglengthoutput.txt", "all=off",
+    NULL, NULL, log.error_stream());
 
   // Look for end of message in output file
-  FILE* fp;
-  fp = fopen("loglengthoutput.txt", "r");
-  assert (fp, "File read error");
+  FILE* fp = fopen("loglengthoutput.txt", "r");
+  assert(fp, "File read error");
   char output[600];
   if (fgets(output, 600, fp) != NULL) {
     assert(strstr(output, "37:1234567890-"), "logging print size error");
@@ -89,5 +91,12 @@
   fclose(fp);
   remove("loglengthoutput.txt");
 }
+
+void Test_configure_stdout() {
+  LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(logging));
+  assert(log_is_enabled(Info, logging), "configure_stdout did not enable requested logging");
+  assert(!log_is_enabled(Info, logging, gc), "configure_stdout enabled too much logging");
+  LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(logging));
+  assert(!log_is_enabled(Info, logging), "configure_stdout did not disable requested logging");
+}
 #endif // PRODUCT
-
--- a/hotspot/src/share/vm/logging/logTagLevelExpression.cpp	Wed Jan 27 05:59:31 2016 +0100
+++ b/hotspot/src/share/vm/logging/logTagLevelExpression.cpp	Wed Jan 27 09:07:10 2016 +0100
@@ -29,21 +29,8 @@
 
 const char* LogTagLevelExpression::DefaultExpressionString = "all";
 
-void LogTagLevelExpression::clear() {
-  _ntags = 0;
-  _ncombinations = 0;
-  for (size_t combination = 0; combination < MaxCombinations; combination++) {
-    _level[combination] = LogLevel::Invalid;
-    _allow_other_tags[combination] = false;
-    for (size_t tag = 0; tag < LogTag::MaxTags; tag++) {
-      _tags[combination][tag] = LogTag::__NO_TAG;
-    }
-  }
-}
-
 bool LogTagLevelExpression::parse(const char* str, outputStream* errstream) {
   bool success = true;
-  clear();
   if (str == NULL || strcmp(str, "") == 0) {
     str = DefaultExpressionString;
   }
--- a/hotspot/src/share/vm/logging/logTagLevelExpression.hpp	Wed Jan 27 05:59:31 2016 +0100
+++ b/hotspot/src/share/vm/logging/logTagLevelExpression.hpp	Wed Jan 27 09:07:10 2016 +0100
@@ -47,6 +47,11 @@
   bool          _allow_other_tags[MaxCombinations];
 
   void new_combination() {
+    // Make sure either all tags are set or the last tag is __NO_TAG
+    if (_ntags < LogTag::MaxTags) {
+      _tags[_ncombinations][_ntags] = LogTag::__NO_TAG;
+    }
+
     _ncombinations++;
     _ntags = 0;
   }
@@ -64,10 +69,13 @@
     _allow_other_tags[_ncombinations] = true;
   }
 
-  void clear();
-
  public:
   LogTagLevelExpression() : _ntags(0), _ncombinations(0) {
+    for (size_t combination = 0; combination < MaxCombinations; combination++) {
+      _level[combination] = LogLevel::Invalid;
+      _allow_other_tags[combination] = false;
+      _tags[combination][0] = LogTag::__NO_TAG;
+    }
   }
 
   bool parse(const char* str, outputStream* errstream = NULL);
--- a/hotspot/src/share/vm/utilities/internalVMTests.cpp	Wed Jan 27 05:59:31 2016 +0100
+++ b/hotspot/src/share/vm/utilities/internalVMTests.cpp	Wed Jan 27 09:07:10 2016 +0100
@@ -53,6 +53,7 @@
 void TestResourcehash_test();
 void TestChunkedList_test();
 void Test_log_length();
+void Test_configure_stdout();
 void Test_TempNewSymbol();
 void GlobalDefinitions_test();
 void GCTimer_test();
@@ -110,6 +111,7 @@
   run_unit_test(TestChunkedList_test());
   run_unit_test(JSON_test());
   run_unit_test(Test_log_length());
+  run_unit_test(Test_configure_stdout());
   run_unit_test(DirectivesParser_test());
   run_unit_test(Test_TempNewSymbol());
 #if INCLUDE_VM_STRUCTS