hotspot/src/share/vm/utilities/events.hpp
author drchase
Fri, 09 May 2014 16:50:54 -0400
changeset 24424 2658d7834c6e
parent 17376 4ee999c3c007
child 28163 322d55d167be
permissions -rw-r--r--
8037816: Fix for 8036122 breaks build with Xcode5/clang Summary: Repaired or selectively disabled offending formats; future-proofed with additional checking Reviewed-by: kvn, jrose, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17376
diff changeset
     2
 * Copyright (c) 1997, 2014, 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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_UTILITIES_EVENTS_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_UTILITIES_EVENTS_HPP
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"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "utilities/top.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):
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    89
    _name(name),
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    90
    _length(length),
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    91
    _count(0),
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    92
    _index(0),
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
    93
    _mutex(Mutex::event, name) {
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.
14620
45167d2bc15a 8001538: hs_err file does not list anymore compiled methods in compilation events
vlivanov
parents: 13195
diff changeset
   138
class StringLogMessage : public FormatBuffer<256> {
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   139
 public:
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   140
  // Wrap this buffer in a stringStream.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   141
  stringStream stream() {
14620
45167d2bc15a 8001538: hs_err file does not list anymore compiled methods in compilation events
vlivanov
parents: 13195
diff changeset
   142
    return stringStream(_buf, size());
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   143
  }
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
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   146
// A simple ring buffer of fixed size text messages.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   147
class StringEventLog : public EventLogBase<StringLogMessage> {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   148
 public:
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   149
  StringEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase<StringLogMessage>(name, count) {}
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   150
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17376
diff changeset
   151
  void logv(Thread* thread, const char* format, va_list ap) ATTRIBUTE_PRINTF(3, 0) {
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   152
    if (!should_log()) return;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   153
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
   154
    double timestamp = fetch_timestamp();
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   155
    MutexLockerEx ml(&_mutex, Mutex::_no_safepoint_check_flag);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   156
    int index = compute_log_index();
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   157
    _records[index].thread = thread;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   158
    _records[index].timestamp = timestamp;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   159
    _records[index].data.printv(format, ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   160
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   161
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17376
diff changeset
   162
  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
   163
    va_list ap;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   164
    va_start(ap, format);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   165
    logv(thread, format, ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   166
    va_end(ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   167
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   168
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   171
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   172
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   173
class Events : AllStatic {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   174
  friend class EventLog;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   175
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   176
 private:
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   177
  static EventLog* _logs;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   178
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   179
  // 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
   180
  static StringEventLog* _messages;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   181
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   182
  // 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
   183
  // throws and implicit exceptions.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   184
  static StringEventLog* _exceptions;
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
  // Deoptization related messages
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   187
  static StringEventLog* _deopt_messages;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   188
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   189
 public:
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   190
  static void print_all(outputStream* out);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   191
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
   192
  // Dump all events to the tty
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
   193
  static void print();
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   194
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   195
  // 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
   196
  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
   197
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   198
  // Log exception related message
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17376
diff changeset
   199
  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
   200
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17376
diff changeset
   201
  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
   202
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   203
  // Register default loggers
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   204
  static void init();
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   205
};
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   206
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   207
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
   208
  if (LogEvents) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   209
    va_list ap;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   210
    va_start(ap, format);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   211
    _messages->logv(thread, format, ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   212
    va_end(ap);
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
}
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   215
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   216
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
   217
  if (LogEvents) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   218
    va_list ap;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   219
    va_start(ap, format);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   220
    _exceptions->logv(thread, format, ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   221
    va_end(ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   222
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   223
}
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   224
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   225
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
   226
  if (LogEvents) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   227
    va_list ap;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   228
    va_start(ap, format);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   229
    _deopt_messages->logv(thread, format, ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   230
    va_end(ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   231
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   232
}
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   233
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   234
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   235
template <class T>
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   236
inline void EventLogBase<T>::print_log_on(outputStream* out) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   237
  if (ThreadLocalStorage::get_thread_slow() == NULL) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   238
    // Not a regular Java thread so don't bother locking
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   239
    print_log_impl(out);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   240
  } else {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   241
    MutexLockerEx ml(&_mutex, Mutex::_no_safepoint_check_flag);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   242
    print_log_impl(out);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   243
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   244
}
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
// 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
   247
template <class T>
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   248
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
   249
  out->print_cr("%s (%d events):", _name, _count);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   250
  if (_count == 0) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   251
    out->print_cr("No events");
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
   252
    out->cr();
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   253
    return;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   254
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   255
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   256
  if (_count < _length) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   257
    for (int i = 0; i < _count; i++) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   258
      print(out, _records[i]);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   259
    }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   260
  } else {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   261
    for (int i = _index; i < _length; i++) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   262
      print(out, _records[i]);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   263
    }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   264
    for (int i = 0; i < _index; i++) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   265
      print(out, _records[i]);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   266
    }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   267
  }
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   268
  out->cr();
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
// Implement a printing routine for the StringLogMessage
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   272
template <>
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   273
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
   274
  out->print_raw(lm);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   275
  out->cr();
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   276
}
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   277
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   278
// 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
   279
// These end up in the default log.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
class EventMark : public StackObj {
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   281
  StringLogMessage _buffer;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   282
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  // log a begin event, format as printf
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17376
diff changeset
   285
  EventMark(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  // log an end event
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 7397
diff changeset
   287
  ~EventMark();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   290
#endif // SHARE_VM_UTILITIES_EVENTS_HPP