src/hotspot/share/utilities/events.cpp
author pliden
Wed, 20 Nov 2019 10:37:46 +0100
changeset 59152 59272e9e0635
parent 55217 bb3359bcf534
permissions -rw-r--r--
8234383: Test TestBiasedLockRevocationEvents.java assumes -XX:UseBiasedLocking is enabled Reviewed-by: mgronlun, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53784
31e3aa9c0c71 8204551: Event descriptions are truncated in logs
ysuenaga
parents: 53738
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
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"
53738
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
    27
#include "oops/instanceKlass.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "runtime/mutexLocker.hpp"
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 24424
diff changeset
    29
#include "runtime/os.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/osThread.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 11788
diff changeset
    31
#include "runtime/thread.inline.hpp"
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    32
#include "runtime/threadCritical.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/timer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "utilities/events.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    37
EventLog* Events::_logs = NULL;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    38
StringEventLog* Events::_messages = NULL;
53874
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
    39
ExceptionsEventLog* Events::_exceptions = NULL;
31234
48000028382c 8081219: hs_err improvement: Add event logging for class redefinition to the hs_err file
coleenp
parents: 25468
diff changeset
    40
StringEventLog* Events::_redefinitions = NULL;
53738
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
    41
UnloadingEventLog* Events::_class_unloading = NULL;
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    42
StringEventLog* Events::_deopt_messages = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    44
EventLog::EventLog() {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    45
  // 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
    46
  // 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
    47
  // some are created slightly late.
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    48
  ThreadCritical tc;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    49
  _next = Events::_logs;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    50
  Events::_logs = this;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    51
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    53
// For each registered event logger, print out the current contents of
55217
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    54
// the buffer.
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    55
void Events::print_all(outputStream* out, int max) {
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    56
  EventLog* log = _logs;
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    57
  while (log != NULL) {
55217
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    58
    log->print_log_on(out, max);
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    59
    log = log->next();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
55217
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    63
// Print a single event log specified by name.
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    64
void Events::print_one(outputStream* out, const char* log_name, int max) {
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    65
  EventLog* log = _logs;
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    66
  int num_printed = 0;
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    67
  while (log != NULL) {
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    68
    if (log->matches_name_or_handle(log_name)) {
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    69
      log->print_log_on(out, max);
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    70
      num_printed ++;
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    71
    }
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    72
    log = log->next();
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    73
  }
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    74
  // Write a short error note if no name matched.
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    75
  if (num_printed == 0) {
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    76
    out->print_cr("The name \"%s\" did not match any known event log. "
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    77
                  "Valid event log names are:", log_name);
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    78
    EventLog* log = _logs;
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    79
    while (log != NULL) {
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    80
      log->print_names(out);
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    81
      out->cr();
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    82
      log = log->next();
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    83
    }
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    84
  }
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    85
}
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    86
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    87
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    88
void Events::print() {
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    89
  print_all(tty);
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    90
}
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11636
diff changeset
    91
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    92
void Events::init() {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    93
  if (LogEvents) {
55217
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    94
    _messages = new StringEventLog("Events", "events");
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    95
    _exceptions = new ExceptionsEventLog("Internal exceptions", "exc");
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    96
    _redefinitions = new StringEventLog("Classes redefined", "redef");
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    97
    _class_unloading = new UnloadingEventLog("Classes unloaded", "unload");
bb3359bcf534 8224600: Provide VM.events command
stuefe
parents: 55074
diff changeset
    98
    _deopt_messages = new StringEventLog("Deoptimization events", "deopt");
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
    99
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
   102
void eventlog_init() {
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
   103
  Events::init();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
///////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
// EventMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
EventMark::EventMark(const char* format, ...) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  if (LogEvents) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    va_list ap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    va_start(ap, format);
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
   113
    // 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
   114
    _buffer.printv(format, ap);
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 14583
diff changeset
   115
    Events::log(NULL, "%s", _buffer.buffer());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    va_end(ap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
EventMark::~EventMark() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  if (LogEvents) {
11636
3c07b54482a5 7141200: log some interesting information in ring buffers for crashes
never
parents: 10565
diff changeset
   122
    // 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
   123
    _buffer.append(" done");
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 14583
diff changeset
   124
    Events::log(NULL, "%s", _buffer.buffer());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
}
53738
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
   127
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
   128
void UnloadingEventLog::log(Thread* thread, InstanceKlass* ik) {
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
   129
  if (!should_log()) return;
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
   130
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
   131
  double timestamp = fetch_timestamp();
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
   132
  // Unloading events are single threaded.
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
   133
  int index = compute_log_index();
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
   134
  _records[index].thread = thread;
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
   135
  _records[index].timestamp = timestamp;
54973
0927d8c7296f 8224487: outputStream should not be copyable
stuefe
parents: 54623
diff changeset
   136
  stringStream st(_records[index].data.buffer(),
0927d8c7296f 8224487: outputStream should not be copyable
stuefe
parents: 54623
diff changeset
   137
                  _records[index].data.size());
53738
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
   138
  st.print("Unloading class " INTPTR_FORMAT " ", p2i(ik));
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
   139
  ik->name()->print_value_on(&st);
7f3b27d9c22d 8212988: add recent class unloading events to the hs_err log
coleenp
parents: 47216
diff changeset
   140
}
53874
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
   141
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
   142
void ExceptionsEventLog::log(Thread* thread, Handle h_exception, const char* message, const char* file, int line) {
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
   143
  if (!should_log()) return;
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
   144
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
   145
  double timestamp = fetch_timestamp();
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 53874
diff changeset
   146
  MutexLocker ml(&_mutex, Mutex::_no_safepoint_check_flag);
53874
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
   147
  int index = compute_log_index();
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
   148
  _records[index].thread = thread;
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
   149
  _records[index].timestamp = timestamp;
54973
0927d8c7296f 8224487: outputStream should not be copyable
stuefe
parents: 54623
diff changeset
   150
  stringStream st(_records[index].data.buffer(),
0927d8c7296f 8224487: outputStream should not be copyable
stuefe
parents: 54623
diff changeset
   151
                  _records[index].data.size());
53874
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
   152
  st.print("Exception <");
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
   153
  h_exception->print_value_on(&st);
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
   154
  st.print("%s%s> (" INTPTR_FORMAT ") \n"
55074
ea1e4a818785 8224750: Display thread once in Internal exceptions event log lines
mbaesken
parents: 54973
diff changeset
   155
           "thrown [%s, line %d]",
53874
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
   156
           message ? ": " : "", message ? message : "",
55074
ea1e4a818785 8224750: Display thread once in Internal exceptions event log lines
mbaesken
parents: 54973
diff changeset
   157
           p2i(h_exception()), file, line);
53874
b2fb6f782d84 8153413: Exceptions::_throw always logs exceptions, penalizing performance
coleenp
parents: 53784
diff changeset
   158
}