src/hotspot/share/logging/logTagSet.cpp
author coleenp
Tue, 31 Oct 2017 11:55:09 -0400
changeset 47765 b7c7428eaab9
parent 47216 71c04702a3d5
child 49177 eebf559c9e0d
permissions -rw-r--r--
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot Summary: Removed hotspot version of jvm*h and jni*h files. Reviewed-by: ihse, mchung, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     1
/*
46560
388aa8d67c80 8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents: 42067
diff changeset
     2
 * Copyright (c) 2015, 2017, 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
 */
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    24
#include "precompiled.hpp"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    25
#include "jvm.h"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    26
#include "logging/logDecorations.hpp"
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 38701
diff changeset
    27
#include "logging/logFileStreamOutput.hpp"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    28
#include "logging/logLevel.hpp"
38263
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37464
diff changeset
    29
#include "logging/logMessageBuffer.hpp"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    30
#include "logging/logOutput.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    31
#include "logging/logTag.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    32
#include "logging/logTagSet.hpp"
38292
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
    33
#include "logging/logTagSetDescriptions.hpp"
37247
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
    34
#include "memory/allocation.inline.hpp"
38292
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
    35
#include "utilities/ostream.hpp"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    36
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    37
LogTagSet*  LogTagSet::_list      = NULL;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    38
size_t      LogTagSet::_ntagsets  = 0;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    39
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    40
// This constructor is called only during static initialization.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    41
// See the declaration in logTagSet.hpp for more information.
37247
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
    42
LogTagSet::LogTagSet(PrefixWriter prefix_writer, LogTagType t0, LogTagType t1, LogTagType t2, LogTagType t3, LogTagType t4)
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
    43
    : _next(_list), _write_prefix(prefix_writer) {
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    44
  _tag[0] = t0;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    45
  _tag[1] = t1;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    46
  _tag[2] = t2;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    47
  _tag[3] = t3;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    48
  _tag[4] = t4;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    49
  for (_ntags = 0; _ntags < LogTag::MaxTags && _tag[_ntags] != LogTag::__NO_TAG; _ntags++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    50
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    51
  _list = this;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    52
  _ntagsets++;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    53
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    54
  // Set the default output to warning and error level for all new tagsets.
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 38701
diff changeset
    55
  _output_list.set_output_level(&StdoutLog, LogLevel::Default);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    56
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    57
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    58
void LogTagSet::update_decorators(const LogDecorators& decorator) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    59
  LogDecorators new_decorators = decorator;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    60
  for (LogOutputList::Iterator it = _output_list.iterator(); it != _output_list.end(); it++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    61
    new_decorators.combine_with((*it)->decorators());
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    62
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    63
  _decorators = new_decorators;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    64
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    65
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    66
bool LogTagSet::has_output(const LogOutput* output) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    67
  for (LogOutputList::Iterator it = _output_list.iterator(); it != _output_list.end(); it++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    68
    if (*it == output) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    69
      return true;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    70
    }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    71
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    72
  return false;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    73
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    74
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    75
void LogTagSet::log(LogLevelType level, const char* msg) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    76
  LogDecorations decorations(level, *this, _decorators);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    77
  for (LogOutputList::Iterator it = _output_list.iterator(level); it != _output_list.end(); it++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    78
    (*it)->write(decorations, msg);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    79
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    80
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    81
38263
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37464
diff changeset
    82
void LogTagSet::log(const LogMessageBuffer& msg) {
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37464
diff changeset
    83
  LogDecorations decorations(LogLevel::Invalid, *this, _decorators);
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37464
diff changeset
    84
  for (LogOutputList::Iterator it = _output_list.iterator(msg.least_detailed_level()); it != _output_list.end(); it++) {
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37464
diff changeset
    85
    (*it)->write(msg.iterator(it.level(), decorations));
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37464
diff changeset
    86
  }
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37464
diff changeset
    87
}
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37464
diff changeset
    88
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 33097
diff changeset
    89
int LogTagSet::label(char* buf, size_t len, const char* separator) const {
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    90
  int tot_written = 0;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    91
  for (size_t i = 0; i < _ntags; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    92
    int written = jio_snprintf(buf + tot_written, len - tot_written, "%s%s",
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 33097
diff changeset
    93
                               (i == 0 ? "" : separator),
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    94
                               LogTag::name(_tag[i]));
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    95
    if (written < 0) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    96
      return -1;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    97
    }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    98
    tot_written += written;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    99
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   100
  return tot_written;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   101
}
37247
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   102
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   103
void LogTagSet::write(LogLevelType level, const char* fmt, ...) {
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   104
  va_list args;
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   105
  va_start(args, fmt);
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   106
  vwrite(level, fmt, args);
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   107
  va_end(args);
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   108
}
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   109
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   110
const size_t vwrite_buffer_size = 512;
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   111
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   112
void LogTagSet::vwrite(LogLevelType level, const char* fmt, va_list args) {
37464
5373bbadb433 8153845: UL log write method missing essential assert
rehn
parents: 37247
diff changeset
   113
  assert(level >= LogLevel::First && level <= LogLevel::Last, "Log level:%d is incorrect", level);
37247
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   114
  char buf[vwrite_buffer_size];
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   115
  va_list saved_args;           // For re-format on buf overflow.
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   116
  va_copy(saved_args, args);
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   117
  size_t prefix_len = _write_prefix(buf, sizeof(buf));
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   118
  // Check that string fits in buffer; resize buffer if necessary
38658
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37464
diff changeset
   119
  int ret;
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37464
diff changeset
   120
  if (prefix_len < vwrite_buffer_size) {
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37464
diff changeset
   121
    ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37464
diff changeset
   122
  } else {
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37464
diff changeset
   123
    // Buffer too small. Just call printf to find out the length for realloc below.
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37464
diff changeset
   124
    ret = os::log_vsnprintf(buf, sizeof(buf), fmt, args);
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37464
diff changeset
   125
  }
37247
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   126
  assert(ret >= 0, "Log message buffer issue");
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   127
  if ((size_t)ret >= sizeof(buf)) {
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   128
    size_t newbuf_len = prefix_len + ret + 1;
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   129
    char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging);
38658
34f9c45625d8 8140594: Various minor code improvements (compiler)
goetz
parents: 37464
diff changeset
   130
    prefix_len = _write_prefix(newbuf, newbuf_len);
37247
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   131
    ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, saved_args);
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   132
    assert(ret >= 0, "Log message buffer issue");
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   133
    log(level, newbuf);
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   134
    FREE_C_HEAP_ARRAY(char, newbuf);
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   135
  } else {
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   136
    log(level, buf);
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   137
  }
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   138
  va_end(saved_args);
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37241
diff changeset
   139
}
38292
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   140
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   141
static const size_t TagSetBufferSize = 128;
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   142
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   143
void LogTagSet::describe_tagsets(outputStream* out) {
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   144
  out->print_cr("Described tag combinations:");
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   145
  for (const LogTagSetDescription* d = tagset_descriptions; d->tagset != NULL; d++) {
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   146
    char buf[TagSetBufferSize];
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   147
    d->tagset->label(buf, sizeof(buf), "+");
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   148
    out->print_cr(" %s: %s", buf, d->descr);
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   149
  }
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   150
}
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   151
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   152
static int qsort_strcmp(const void* a, const void* b) {
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   153
  return strcmp((*(const char**)a), (*(const char**)b));
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   154
}
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   155
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   156
void LogTagSet::list_all_tagsets(outputStream* out) {
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   157
  char** tagset_labels = NEW_C_HEAP_ARRAY(char*, _ntagsets, mtLogging);
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   158
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   159
  // Generate the list of tagset labels
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   160
  size_t idx = 0;
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   161
  for (LogTagSet* ts = first(); ts != NULL; ts = ts->next()) {
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   162
    char buf[TagSetBufferSize];
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   163
    ts->label(buf, sizeof(buf), "+");
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   164
    tagset_labels[idx++] = os::strdup_check_oom(buf, mtLogging);
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   165
  }
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   166
  assert(idx == _ntagsets, "_ntagsets and list of tagsets not in sync");
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   167
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   168
  // Sort them lexicographically
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   169
  qsort(tagset_labels, _ntagsets, sizeof(*tagset_labels), qsort_strcmp);
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   170
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   171
  // Print and then free the labels
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   172
  out->print("All available tag sets: ");
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   173
  for (idx = 0; idx < _ntagsets; idx++) {
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   174
    out->print("%s%s", (idx == 0 ? "" : ", "), tagset_labels[idx]);
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   175
    os::free(tagset_labels[idx]);
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   176
  }
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   177
  out->cr();
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   178
  FREE_C_HEAP_ARRAY(char*, tagset_labels);
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   179
}
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38263
diff changeset
   180