hotspot/src/share/vm/logging/log.cpp
author tschatzl
Fri, 01 Apr 2016 11:58:45 +0200
changeset 37229 fb86c6db7f7b
parent 37201 928cf689af1a
child 37242 91e5f98fff6f
child 37239 a6cda2376a19
permissions -rw-r--r--
8153182: GC ID prefix for gc, humongous log messages are missing Reviewed-by: mgerdin, brutisso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33766
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
     1
/*
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
33766
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
     4
 *
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
     8
 *
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    13
 * accompanied this code).
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    14
 *
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    18
 *
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    21
 * questions.
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    22
 *
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    23
 */
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    24
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    25
#include "precompiled.hpp"
37201
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    26
#include "logging/log.hpp"
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    27
#include "memory/allocation.inline.hpp"
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    28
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    29
void LogWriteHelper::write_large(LogTagSet& lts,
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    30
                                 LogLevelType level,
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    31
                                 const char* prefix,
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    32
                                 size_t prefix_len,
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    33
                                 size_t msg_len,
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    34
                                 const char* fmt,
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    35
                                 va_list args) {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    36
  size_t newbuf_len = prefix_len + msg_len + 1;
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    37
  char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    38
  memcpy(newbuf, prefix, prefix_len);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    39
  int ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, args);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    40
  assert(ret >= 0, "Log message buffer issue");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    41
  lts.log(level, newbuf);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    42
  FREE_C_HEAP_ARRAY(char, newbuf);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    43
}
33766
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    44
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    45
/////////////// Unit tests ///////////////
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    46
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    47
#ifndef PRODUCT
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    48
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    49
#include "logging/log.hpp"
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    50
#include "logging/logConfiguration.hpp"
35950
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
    51
#include "logging/logOutput.hpp"
33766
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    52
#include "memory/resourceArea.hpp"
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    53
35950
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
    54
#define assert_str_eq(s1, s2) \
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
    55
  assert(strcmp(s1, s2) == 0, "Expected '%s' to equal '%s'", s1, s2)
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
    56
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
    57
#define assert_char_in(c, s) \
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
    58
  assert(strchr(s, c) != NULL, "Expected '%s' to contain character '%c'", s, c)
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
    59
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
    60
#define assert_char_not_in(c, s) \
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
    61
  assert(strchr(s, c) == NULL, "Expected '%s' to *not* contain character '%c'", s, c)
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
    62
37201
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    63
class TestLogFile {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    64
 private:
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    65
  char file_name[256];
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    66
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    67
  void set_name(const char* test_name) {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    68
    const char* tmpdir = os::get_temp_directory();
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    69
    int pos = jio_snprintf(file_name, sizeof(file_name), "%s%svmtest.%s.%d.log", tmpdir, os::file_separator(), test_name, os::current_process_id());
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    70
    assert(pos > 0, "too small log file name buffer");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    71
    assert((size_t)pos < sizeof(file_name), "too small log file name buffer");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    72
  }
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    73
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    74
 public:
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    75
  TestLogFile(const char* test_name) {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    76
    set_name(test_name);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    77
    remove(name());
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    78
  }
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    79
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    80
  ~TestLogFile() {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    81
    remove(name());
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    82
  }
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    83
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    84
  const char* name() {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    85
    return file_name;
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    86
  }
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    87
};
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    88
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    89
class TestLogSavedConfig {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    90
 private:
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    91
  char* _saved_config;
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    92
  char* _new_output;
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    93
  LogHandle(logging) _log;
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    94
 public:
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    95
  TestLogSavedConfig(const char* apply_output = NULL, const char* apply_setting = NULL) : _new_output(0) {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    96
    _saved_config = os::strdup_check_oom(LogOutput::Stdout->config_string());
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    97
    bool success = LogConfiguration::parse_log_arguments("stdout", "all=off", NULL, NULL, _log.error_stream());
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    98
    assert(success, "test unable to turn all off");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
    99
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   100
    if (apply_output) {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   101
      _new_output = os::strdup_check_oom(apply_output);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   102
      bool success = LogConfiguration::parse_log_arguments(_new_output, apply_setting,  NULL, NULL, _log.error_stream());
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   103
      assert(success, "test unable to apply test log configuration");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   104
    }
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   105
  }
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   106
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   107
  ~TestLogSavedConfig() {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   108
    if (_new_output) {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   109
      bool success = LogConfiguration::parse_log_arguments(_new_output, "all=off", NULL, NULL, _log.error_stream());
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   110
      assert(success, "test unable to turn all off");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   111
      os::free(_new_output);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   112
    }
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   113
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   114
    bool success = LogConfiguration::parse_log_arguments("stdout", _saved_config, NULL, NULL, _log.error_stream());
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   115
    assert(success, "test unable to restore log configuration");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   116
    os::free(_saved_config);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   117
  }
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   118
};
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   119
35852
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
   120
void Test_configure_stdout() {
35950
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   121
  ResourceMark rm;
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   122
  LogOutput* stdoutput = LogOutput::Stdout;
37201
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   123
  TestLogSavedConfig tlsc;
35950
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   124
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   125
  // Enable 'logging=info', verifying it has been set
35852
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
   126
  LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(logging));
35950
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   127
  assert_str_eq("logging=info,", stdoutput->config_string());
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   128
  assert(log_is_enabled(Info, logging), "logging was not properly enabled");
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   129
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   130
  // Enable 'gc=debug' (no wildcard), verifying no other tags are enabled
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   131
  LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(gc));
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   132
  // No '+' character means only single tags are enabled, and no combinations
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   133
  assert_char_not_in('+', stdoutput->config_string());
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   134
  assert(log_is_enabled(Debug, gc), "logging was not properly enabled");
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   135
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   136
  // Enable 'gc*=trace' (with wildcard), verifying at least one tag combination is enabled (gc+...)
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   137
  LogConfiguration::configure_stdout(LogLevel::Trace, false, LOG_TAGS(gc));
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   138
  assert_char_in('+', stdoutput->config_string());
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   139
  assert(log_is_enabled(Trace, gc), "logging was not properly enabled");
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   140
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   141
  // Disable 'gc*' and 'logging', verifying all logging is properly disabled
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   142
  LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(gc));
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   143
  LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(logging));
c6142cb6bc4a 8149112: configure_stdout test depends on VM arguments
mlarsson
parents: 35852
diff changeset
   144
  assert_str_eq("all=off", stdoutput->config_string());
35852
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
   145
}
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   146
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   147
static int Test_logconfiguration_subscribe_triggered = 0;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   148
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   149
static void Test_logconfiguration_subscribe_helper() {
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   150
  Test_logconfiguration_subscribe_triggered++;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   151
}
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   152
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   153
void Test_logconfiguration_subscribe() {
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   154
  ResourceMark rm;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   155
  LogHandle(logging) log;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   156
37201
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   157
  TestLogSavedConfig log_cfg("stdout", "logging+test=trace");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   158
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   159
  LogConfiguration::register_update_listener(&Test_logconfiguration_subscribe_helper);
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   160
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   161
  LogConfiguration::parse_log_arguments("stdout", "logging=trace", NULL, NULL, log.error_stream());
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   162
  assert(Test_logconfiguration_subscribe_triggered == 1, "subscription not triggered (1)");
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   163
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   164
  LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(gc));
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   165
  assert(Test_logconfiguration_subscribe_triggered == 2, "subscription not triggered (2)");
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   166
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   167
  LogConfiguration::disable_logging();
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   168
  assert(Test_logconfiguration_subscribe_triggered == 3, "subscription not triggered (3)");
37201
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   169
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   170
  // We need to renable stderr error logging since "disable_logging" disable it all.
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   171
  // TestLogSavedConfig log_cfg will only renable stdout for us.
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   172
  LogConfiguration::parse_log_arguments("stderr", "all=warning", NULL, NULL, log.error_stream());
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   173
  assert(Test_logconfiguration_subscribe_triggered == 4, "subscription not triggered (3)");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   174
}
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   175
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   176
#define LOG_PREFIX_STR "THE_PREFIX "
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   177
#define LOG_LINE_STR "a log line"
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   178
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   179
size_t Test_log_prefix_prefixer(char* buf, size_t len) {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   180
  int ret = jio_snprintf(buf, len, LOG_PREFIX_STR);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   181
  assert(ret > 0, "Failed to print prefix. Log buffer too small?");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   182
  return (size_t) ret;
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   183
}
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   184
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   185
void Test_log_prefix() {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   186
  ResourceMark rm;
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   187
  TestLogFile log_file("log_prefix");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   188
  TestLogSavedConfig log_cfg(log_file.name(), "logging+test=trace");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   189
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   190
  log_trace(logging, test)(LOG_LINE_STR);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   191
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   192
  FILE* fp = fopen(log_file.name(), "r");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   193
  assert(fp, "File read error");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   194
  char output[1024];
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   195
  if (fgets(output, 1024, fp) != NULL) {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   196
    assert(strstr(output, LOG_PREFIX_STR LOG_LINE_STR), "logging prefix error");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   197
  }
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   198
  fclose(fp);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   199
}
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   200
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   201
void Test_log_big() {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   202
  char big_msg[4096] = {0};
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   203
  char Xchar = '~';
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   204
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   205
  ResourceMark rm;
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   206
  TestLogFile log_file("log_big");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   207
  TestLogSavedConfig log_cfg(log_file.name(), "logging+test=trace");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   208
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   209
  memset(big_msg, Xchar, sizeof(big_msg) - 1);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   210
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   211
  log_trace(logging, test)("%s", big_msg);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   212
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   213
  FILE* fp = fopen(log_file.name(), "r");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   214
  assert(fp, "File read error");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   215
  char output[sizeof(big_msg)+128 /*decorators*/ ];
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   216
  if (fgets(output, sizeof(output), fp) != NULL) {
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   217
    assert(strstr(output, LOG_PREFIX_STR), "logging prefix error");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   218
    size_t count = 0;
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   219
    for (size_t ps = 0 ; output[ps + count] != '\0'; output[ps + count] == Xchar ? count++ : ps++);
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   220
    assert(count == (sizeof(big_msg) - 1) , "logging msg error");
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   221
  }
928cf689af1a 8151993: Remove inclusion of inline.hpp in log.hpp
mlarsson
parents: 37200
diff changeset
   222
  fclose(fp);
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   223
}
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 35950
diff changeset
   224
37200
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   225
void Test_logtagset_duplicates() {
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   226
  for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   227
    char ts_name[512];
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   228
    ts->label(ts_name, sizeof(ts_name), ",");
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   229
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   230
    // verify that NO_TAG is never followed by a real tag
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   231
    for (size_t i = 0; i < LogTag::MaxTags; i++) {
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   232
      if (ts->tag(i) == LogTag::__NO_TAG) {
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   233
        for (i++; i < LogTag::MaxTags; i++) {
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   234
          assert(ts->tag(i) == LogTag::__NO_TAG,
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   235
                 "NO_TAG was followed by a real tag (%s) in tagset %s",
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   236
                 LogTag::name(ts->tag(i)), ts_name);
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   237
        }
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   238
      }
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   239
    }
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   240
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   241
    // verify that there are no duplicate tagsets (same tags in different order)
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   242
    for (LogTagSet* other = ts->next(); other != NULL; other = other->next()) {
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   243
      if (ts->ntags() != other->ntags()) {
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   244
        continue;
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   245
      }
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   246
      bool equal = true;
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   247
      for (size_t i = 0; i < ts->ntags(); i++) {
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   248
        LogTagType tag = ts->tag(i);
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   249
        if (!other->contains(tag)) {
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   250
          equal = false;
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   251
          break;
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   252
        }
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   253
      }
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   254
      // Since tagsets are implemented using template arguments, using both of
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   255
      // the (logically equivalent) tagsets (t1, t2) and (t2, t1) somewhere will
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   256
      // instantiate two different LogTagSetMappings. This causes multiple
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   257
      // tagset instances to be created for the same logical set. We want to
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   258
      // avoid this to save time, memory and prevent any confusion around it.
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   259
      if (equal) {
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   260
        char other_name[512];
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   261
        other->label(other_name, sizeof(other_name), ",");
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   262
        assert(false, "duplicate LogTagSets found: '%s' vs '%s' "
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   263
               "(tags must always be specified in the same order for each tagset)",
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   264
               ts_name, other_name);
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   265
      }
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   266
    }
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   267
  }
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   268
}
e601cf49b2d8 8151438: UL instantiates duplicate tag sets
mlarsson
parents: 37108
diff changeset
   269
33766
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
   270
#endif // PRODUCT