hotspot/src/share/vm/logging/log.cpp
author mockner
Wed, 03 Feb 2016 11:40:30 -0500
changeset 35917 463d67f86eaa
parent 35852 15ca44d4ae0c
child 35950 c6142cb6bc4a
permissions -rw-r--r--
8079408: Reimplement TraceClassLoading, TraceClassUnloading, and TraceClassLoaderData with Unified Logging. Summary: TraceClassLoading, TraceClassUnloading, and TraceClassLoaderData have been reimplemented using Unified logging. Reviewed-by: iklam, coleenp, dholmes, jiangli, hseigel, rprotacio Contributed-by: max.ockner@oracle.com, ioi.lam@oracle.com
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
/*
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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"
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    26
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    27
/////////////// Unit tests ///////////////
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    28
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    29
#ifndef PRODUCT
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    30
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    31
#include "logging/log.hpp"
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    32
#include "logging/logConfiguration.hpp"
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    33
#include "memory/resourceArea.hpp"
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    34
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    35
void Test_log_length() {
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    36
  remove("loglengthoutput.txt");
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    37
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    38
  // Write long message to output file
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    39
  ResourceMark rm;
35852
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    40
  LogHandle(logging) log;
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    41
  bool success = LogConfiguration::parse_log_arguments("loglengthoutput.txt", "logging=trace",
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    42
    NULL, NULL, log.error_stream());
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    43
  assert(success, "test unable to configure logging");
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    44
  log.trace("01:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    45
            "02:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    46
            "03:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    47
            "04:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    48
            "05:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    49
            "06:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    50
            "07:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    51
            "08:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    52
            "09:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    53
            "10:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    54
            "11:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    55
            "12:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    56
            "13:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    57
            "14:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    58
            "15:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    59
            "16:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    60
            "17:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    61
            "18:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    62
            "19:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    63
            "20:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    64
            "21:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    65
            "22:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    66
            "23:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    67
            "24:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    68
            "25:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    69
            "26:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    70
            "27:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    71
            "28:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    72
            "29:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    73
            "30:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    74
            "31:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    75
            "32:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    76
            "33:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    77
            "34:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    78
            "35:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    79
            "36:1234567890-"
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    80
            "37:1234567890-");
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    81
  LogConfiguration::parse_log_arguments("loglengthoutput.txt", "all=off",
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    82
    NULL, NULL, log.error_stream());
33766
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    83
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    84
  // Look for end of message in output file
35852
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    85
  FILE* fp = fopen("loglengthoutput.txt", "r");
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    86
  assert(fp, "File read error");
33766
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    87
  char output[600];
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    88
  if (fgets(output, 600, fp) != NULL) {
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    89
    assert(strstr(output, "37:1234567890-"), "logging print size error");
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    90
  }
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    91
  fclose(fp);
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    92
  remove("loglengthoutput.txt");
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
    93
}
35852
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    94
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    95
void Test_configure_stdout() {
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    96
  LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(logging));
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    97
  assert(log_is_enabled(Info, logging), "configure_stdout did not enable requested logging");
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    98
  assert(!log_is_enabled(Info, logging, gc), "configure_stdout enabled too much logging");
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
    99
  LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(logging));
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
   100
  assert(!log_is_enabled(Info, logging), "configure_stdout did not disable requested logging");
15ca44d4ae0c 8147348: LogTagLevelExpression not properly initialized in configure_stdout
mlarsson
parents: 35228
diff changeset
   101
}
33766
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents:
diff changeset
   102
#endif // PRODUCT