hotspot/src/share/vm/utilities/events.cpp
author never
Wed, 15 Feb 2012 10:12:55 -0800
changeset 11788 bef6166c683c
parent 11636 3c07b54482a5
child 14583 d70ee55535f4
permissions -rw-r--r--
7145537: minor tweaks to LogEvents Reviewed-by: kvn, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
     2
 * Copyright (c) 1997, 2012, 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
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "runtime/mutexLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "runtime/osThread.hpp"
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    29
#include "runtime/threadCritical.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/threadLocalStorage.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "runtime/timer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "utilities/events.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#ifdef TARGET_OS_FAMILY_linux
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
# include "thread_linux.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#ifdef TARGET_OS_FAMILY_solaris
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
# include "thread_solaris.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    38
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    39
#ifdef TARGET_OS_FAMILY_windows
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
# include "thread_windows.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    41
#endif
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7397
diff changeset
    42
#ifdef TARGET_OS_FAMILY_bsd
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7397
diff changeset
    43
# include "thread_bsd.inline.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7397
diff changeset
    44
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    47
EventLog* Events::_logs = NULL;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    48
StringEventLog* Events::_messages = NULL;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    49
StringEventLog* Events::_exceptions = NULL;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    50
StringEventLog* Events::_deopt_messages = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    52
EventLog::EventLog() {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    53
  // This normally done during bootstrap when we're only single
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    54
  // threaded but use a ThreadCritical to ensure inclusion in case
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    55
  // some are created slightly late.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    56
  ThreadCritical tc;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    57
  _next = Events::_logs;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    58
  Events::_logs = this;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    59
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    61
// For each registered event logger, print out the current contents of
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    62
// the buffer.  This is normally called when the JVM is crashing.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    63
void Events::print_all(outputStream* out) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    64
  EventLog* log = _logs;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    65
  while (log != NULL) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    66
    log->print_log_on(out);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    67
    log = log->next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    71
void Events::print() {
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    72
  print_all(tty);
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    73
}
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    74
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    75
void Events::init() {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    76
  if (LogEvents) {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    77
    _messages = new StringEventLog("Events");
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    78
    _exceptions = new StringEventLog("Internal exceptions");
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    79
    _deopt_messages = new StringEventLog("Deoptimization events");
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    80
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    83
void eventlog_init() {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    84
  Events::init();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
///////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
// EventMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
EventMark::EventMark(const char* format, ...) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  if (LogEvents) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    va_list ap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    va_start(ap, format);
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    94
    // Save a copy of begin message and log it.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    95
    _buffer.printv(format, ap);
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    96
    Events::log(NULL, _buffer);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    va_end(ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
EventMark::~EventMark() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  if (LogEvents) {
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
   103
    // Append " done" to the begin message and log it
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
   104
    _buffer.append(" done");
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
   105
    Events::log(NULL, _buffer);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
}