src/hotspot/share/logging/logSelectionList.cpp
author jwilhelm
Sun, 25 Feb 2018 04:59:43 +0100
changeset 49067 c153e9daadce
parent 47216 src/hotspot/share/logging/logTagLevelExpression.cpp@71c04702a3d5
parent 49016 src/hotspot/share/logging/logTagLevelExpression.cpp@ea85eed8b012
child 49186 b8bfadfacded
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     1
/*
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     4
 *
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     7
 * published by the Free Software Foundation.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     8
 *
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    13
 * accompanied this code).
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    14
 *
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    18
 *
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    21
 * questions.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    22
 *
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    23
 */
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    24
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    25
#include "precompiled.hpp"
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    26
#include "logging/logSelectionList.hpp"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    27
#include "logging/logTagSet.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    28
#include "runtime/arguments.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    29
#include "runtime/os.inline.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    30
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    31
static const char* DefaultExpressionString = "all";
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    32
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    33
bool LogSelectionList::verify_selections(outputStream* out) const {
40884
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    34
  bool valid = true;
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    35
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    36
  for (size_t i = 0; i < _nselections; i++) {
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    37
    if (_selections[i].tag_sets_selected() == 0) {
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    38
      // Return immediately unless all invalid selections should be listed
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    39
      if (out == NULL) {
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    40
        return false;
40884
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    41
      }
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    42
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    43
      if (valid) {
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    44
        out->print("No tag set matches selection(s):");
40884
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    45
      }
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    46
      valid = false;
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    47
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    48
      char buf[256];
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    49
      _selections[i].describe_tags(buf, sizeof(buf));
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    50
      out->print(" %s", buf);
40884
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    51
    }
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    52
  }
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    53
  if (!valid && out != NULL) {
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    54
    out->cr();
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    55
  }
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    56
  return valid;
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    57
}
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 35852
diff changeset
    58
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    59
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    60
bool LogSelectionList::parse(const char* str, outputStream* errstream) {
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    61
  bool success = true;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    62
  if (str == NULL || strcmp(str, "") == 0) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    63
    str = DefaultExpressionString;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    64
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    65
  char* copy = os::strdup_check_oom(str, mtLogging);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    66
  // Split string on commas
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    67
  for (char *comma_pos = copy, *cur = copy; success && comma_pos != NULL; cur = comma_pos + 1) {
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    68
    if (_nselections == MaxSelections) {
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    69
      if (errstream != NULL) {
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    70
        errstream->print_cr("Can not have more than " SIZE_FORMAT " log selections in a single configuration.",
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    71
                            MaxSelections);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    72
      }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    73
      success = false;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    74
      break;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    75
    }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    76
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    77
    comma_pos = strchr(cur, ',');
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    78
    if (comma_pos != NULL) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    79
      *comma_pos = '\0';
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    80
    }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    81
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    82
    LogSelection selection = LogSelection::parse(cur, errstream);
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    83
    if (selection == LogSelection::Invalid) {
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    84
      success = false;
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    85
      break;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    86
    }
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    87
    _selections[_nselections++] = selection;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    88
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    89
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 33097
diff changeset
    90
  os::free(copy);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    91
  return success;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    92
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    93
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    94
LogLevelType LogSelectionList::level_for(const LogTagSet& ts) const {
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 33097
diff changeset
    95
  // Return NotMentioned if the given tagset isn't covered by this expression.
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 33097
diff changeset
    96
  LogLevelType level = LogLevel::NotMentioned;
49016
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    97
  for (size_t i= 0; i < _nselections; i++) {
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    98
    if (_selections[i].selects(ts)) {
ea85eed8b012 8196783: Refactor LogTagLevelExpression into separate classes
mlarsson
parents: 47216
diff changeset
    99
      level = _selections[i].level();
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   100
    }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   101
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   102
  return level;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   103
}