src/hotspot/share/utilities/events.hpp
author ysuenaga
Sat, 16 Feb 2019 11:40:34 +0900
changeset 53784 31e3aa9c0c71
parent 53738 7f3b27d9c22d
child 53874 b2fb6f782d84
permissions -rw-r--r--
8204551: Event descriptions are truncated in logs Reviewed-by: coleenp, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51334
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51334
diff changeset
    25
#ifndef SHARE_UTILITIES_EVENTS_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51334
diff changeset
    26
#define SHARE_UTILITIES_EVENTS_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    29
#include "runtime/mutexLocker.hpp"
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    30
#include "runtime/thread.hpp"
46560
388aa8d67c80 8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents: 37466
diff changeset
    31
#include "utilities/formatBuffer.hpp"
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    32
#include "utilities/vmError.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// Events and EventMark provide interfaces to log events taking place in the vm.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// This facility is extremly useful for post-mortem debugging. The eventlog
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// often provides crucial information about events leading up to the crash.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    38
// Abstractly the logs can record whatever they way but normally they
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    39
// would record at least a timestamp and the current Thread, along
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    40
// with whatever data they need in a ring buffer.  Commonly fixed
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    41
// length text messages are recorded for simplicity but other
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    42
// strategies could be used.  Several logs are provided by default but
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    43
// new instances can be created as needed.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    45
// The base event log dumping class that is registered for dumping at
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    46
// crash time.  This is a very generic interface that is mainly here
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    47
// for completeness.  Normally the templated EventLogBase would be
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    48
// subclassed to provide different log types.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11795
diff changeset
    49
class EventLog : public CHeapObj<mtInternal> {
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    50
  friend class Events;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    51
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    52
 private:
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    53
  EventLog* _next;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    54
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    55
  EventLog* next() const { return _next; }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    56
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
 public:
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    58
  // Automatically registers the log so that it will be printed during
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    59
  // crashes.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    60
  EventLog();
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    61
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    62
  virtual void print_log_on(outputStream* out) = 0;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    63
};
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    64
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    65
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    66
// A templated subclass of EventLog that provides basic ring buffer
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    67
// functionality.  Most event loggers should subclass this, possibly
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    68
// providing a more featureful log function if the existing copy
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    69
// semantics aren't appropriate.  The name is used as the label of the
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    70
// log when it is dumped during a crash.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    71
template <class T> class EventLogBase : public EventLog {
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17031
diff changeset
    72
  template <class X> class EventRecord : public CHeapObj<mtInternal> {
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    73
   public:
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    74
    double  timestamp;
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    75
    Thread* thread;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    76
    X       data;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    77
  };
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    78
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    79
 protected:
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    80
  Mutex           _mutex;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    81
  const char*     _name;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    82
  int             _length;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    83
  int             _index;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    84
  int             _count;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    85
  EventRecord<T>* _records;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    86
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    87
 public:
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    88
  EventLogBase<T>(const char* name, int length = LogEventsBufferEntries):
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    89
    _mutex(Mutex::event, name, false, Monitor::_safepoint_check_never),
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    90
    _name(name),
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    91
    _length(length),
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    92
    _index(0),
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    93
    _count(0) {
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    94
    _records = new EventRecord<T>[length];
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    95
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    97
  double fetch_timestamp() {
11795
0c892974d26c 7146729: nightly failure after 7141200: tty is sometimes null during shutdown of main thread
never
parents: 11788
diff changeset
    98
    return os::elapsedTime();
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    99
  }
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
   100
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   101
  // move the ring buffer to next open slot and return the index of
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   102
  // the slot to use for the current message.  Should only be called
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   103
  // while mutex is held.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   104
  int compute_log_index() {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   105
    int index = _index;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   106
    if (_count < _length) _count++;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   107
    _index++;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   108
    if (_index >= _length) _index = 0;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   109
    return index;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   110
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   111
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   112
  bool should_log() {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   113
    // Don't bother adding new entries when we're crashing.  This also
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   114
    // avoids mutating the ring buffer when printing the log.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   115
    return !VMError::fatal_error_in_progress();
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   116
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   117
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   118
  // Print the contents of the log
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   119
  void print_log_on(outputStream* out);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   120
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   121
 private:
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   122
  void print_log_impl(outputStream* out);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   123
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   124
  // Print a single element.  A templated implementation might need to
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   125
  // be declared by subclasses.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   126
  void print(outputStream* out, T& e);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   128
  void print(outputStream* out, EventRecord<T>& e) {
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
   129
    out->print("Event: %.3f ", e.timestamp);
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   130
    if (e.thread != NULL) {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17376
diff changeset
   131
      out->print("Thread " INTPTR_FORMAT " ", p2i(e.thread));
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   132
    }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   133
    print(out, e.data);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   134
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   135
};
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   136
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   137
// A simple wrapper class for fixed size text messages.
53784
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   138
template <size_t bufsz>
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   139
class FormatStringLogMessage : public FormatBuffer<bufsz> {
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   140
 public:
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   141
  // Wrap this buffer in a stringStream.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   142
  stringStream stream() {
53784
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   143
    return stringStream(this->_buf, this->size());
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   144
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   145
};
53784
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   146
typedef FormatStringLogMessage<256> StringLogMessage;
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   147
typedef FormatStringLogMessage<512> ExtendedStringLogMessage;
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   148
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   149
// A simple ring buffer of fixed size text messages.
53784
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   150
template <size_t bufsz>
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   151
class FormatStringEventLog : public EventLogBase< FormatStringLogMessage<bufsz> > {
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   152
 public:
53784
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   153
  FormatStringEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase< FormatStringLogMessage<bufsz> >(name, count) {}
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   154
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17376
diff changeset
   155
  void logv(Thread* thread, const char* format, va_list ap) ATTRIBUTE_PRINTF(3, 0) {
53784
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   156
    if (!this->should_log()) return;
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   157
53784
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   158
    double timestamp = this->fetch_timestamp();
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   159
    MutexLockerEx ml(&this->_mutex, Mutex::_no_safepoint_check_flag);
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   160
    int index = this->compute_log_index();
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   161
    this->_records[index].thread = thread;
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   162
    this->_records[index].timestamp = timestamp;
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   163
    this->_records[index].data.printv(format, ap);
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   164
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   165
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17376
diff changeset
   166
  void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(3, 4) {
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   167
    va_list ap;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   168
    va_start(ap, format);
53784
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   169
    this->logv(thread, format, ap);
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   170
    va_end(ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   171
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
};
53784
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   173
typedef FormatStringEventLog<256> StringEventLog;
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   174
typedef FormatStringEventLog<512> ExtendedStringEventLog;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
53738
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   176
class InstanceKlass;
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   177
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   178
// Event log for class unloading events to materialize the class name in place in the log stream.
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   179
class UnloadingEventLog : public EventLogBase<StringLogMessage> {
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   180
 public:
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   181
  UnloadingEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase<StringLogMessage>(name, count) {}
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   182
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   183
  void log(Thread* thread, InstanceKlass* ik);
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   184
};
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   185
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   186
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   187
class Events : AllStatic {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   188
  friend class EventLog;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   189
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   190
 private:
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   191
  static EventLog* _logs;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   192
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   193
  // A log for generic messages that aren't well categorized.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   194
  static StringEventLog* _messages;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   195
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   196
  // A log for internal exception related messages, like internal
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   197
  // throws and implicit exceptions.
53784
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   198
  static ExtendedStringEventLog* _exceptions;
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   199
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   200
  // Deoptization related messages
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   201
  static StringEventLog* _deopt_messages;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   202
31234
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   203
  // Redefinition related messages
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   204
  static StringEventLog* _redefinitions;
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   205
53738
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   206
  // Class unloading events
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   207
  static UnloadingEventLog* _class_unloading;
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   208
 public:
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   209
  static void print_all(outputStream* out);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   210
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
   211
  // Dump all events to the tty
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
   212
  static void print();
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   213
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   214
  // Logs a generic message with timestamp and format as printf.
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17376
diff changeset
   215
  static void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   216
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   217
  // Log exception related message
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17376
diff changeset
   218
  static void log_exception(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   219
31234
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   220
  static void log_redefinition(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   221
53738
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   222
  static void log_class_unloading(Thread* thread, InstanceKlass* ik);
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   223
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17376
diff changeset
   224
  static void log_deopt_message(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   225
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   226
  // Register default loggers
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   227
  static void init();
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   228
};
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   229
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   230
inline void Events::log(Thread* thread, const char* format, ...) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   231
  if (LogEvents) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   232
    va_list ap;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   233
    va_start(ap, format);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   234
    _messages->logv(thread, format, ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   235
    va_end(ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   236
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   237
}
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   238
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   239
inline void Events::log_exception(Thread* thread, const char* format, ...) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   240
  if (LogEvents) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   241
    va_list ap;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   242
    va_start(ap, format);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   243
    _exceptions->logv(thread, format, ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   244
    va_end(ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   245
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   246
}
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   247
31234
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   248
inline void Events::log_redefinition(Thread* thread, const char* format, ...) {
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   249
  if (LogEvents) {
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   250
    va_list ap;
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   251
    va_start(ap, format);
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   252
    _redefinitions->logv(thread, format, ap);
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   253
    va_end(ap);
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   254
  }
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   255
}
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 28163
diff changeset
   256
53738
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   257
inline void Events::log_class_unloading(Thread* thread, InstanceKlass* ik) {
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   258
  if (LogEvents) {
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   259
    _class_unloading->log(thread, ik);
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   260
  }
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   261
}
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 53244
diff changeset
   262
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   263
inline void Events::log_deopt_message(Thread* thread, const char* format, ...) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   264
  if (LogEvents) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   265
    va_list ap;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   266
    va_start(ap, format);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   267
    _deopt_messages->logv(thread, format, ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   268
    va_end(ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   269
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   270
}
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   271
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   272
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   273
template <class T>
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   274
inline void EventLogBase<T>::print_log_on(outputStream* out) {
34633
2a6c7c7b30a7 8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents: 31234
diff changeset
   275
  if (Thread::current_or_null() == NULL) {
2a6c7c7b30a7 8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents: 31234
diff changeset
   276
    // Not yet attached? Don't try to use locking
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   277
    print_log_impl(out);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   278
  } else {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   279
    MutexLockerEx ml(&_mutex, Mutex::_no_safepoint_check_flag);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   280
    print_log_impl(out);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   281
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   282
}
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   283
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   284
// Dump the ring buffer entries that current have entries.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   285
template <class T>
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   286
inline void EventLogBase<T>::print_log_impl(outputStream* out) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   287
  out->print_cr("%s (%d events):", _name, _count);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   288
  if (_count == 0) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   289
    out->print_cr("No events");
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
   290
    out->cr();
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   291
    return;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   292
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   293
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   294
  if (_count < _length) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   295
    for (int i = 0; i < _count; i++) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   296
      print(out, _records[i]);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   297
    }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   298
  } else {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   299
    for (int i = _index; i < _length; i++) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   300
      print(out, _records[i]);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   301
    }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   302
    for (int i = 0; i < _index; i++) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   303
      print(out, _records[i]);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   304
    }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   305
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   306
  out->cr();
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   307
}
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   308
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   309
// Implement a printing routine for the StringLogMessage
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   310
template <>
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   311
inline void EventLogBase<StringLogMessage>::print(outputStream* out, StringLogMessage& lm) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   312
  out->print_raw(lm);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   313
  out->cr();
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   314
}
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   315
53784
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   316
// Implement a printing routine for the ExtendedStringLogMessage
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   317
template <>
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   318
inline void EventLogBase<ExtendedStringLogMessage>::print(outputStream* out, ExtendedStringLogMessage& lm) {
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   319
  out->print_raw(lm);
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   320
  out->cr();
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   321
}
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
diff changeset
   322
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   323
// Place markers for the beginning and end up of a set of events.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   324
// These end up in the default log.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
class EventMark : public StackObj {
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   326
  StringLogMessage _buffer;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   327
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  // log a begin event, format as printf
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17376
diff changeset
   330
  EventMark(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  // log an end event
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   332
  ~EventMark();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51334
diff changeset
   335
#endif // SHARE_UTILITIES_EVENTS_HPP