jdk

Форк
0
170 строк · 5.8 Кб
1
/*
2
 * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 *
23
 */
24

25
#include "precompiled.hpp"
26
#include "gc/shared/gc_globals.hpp"
27
#include "memory/allocation.inline.hpp"
28
#include "oops/instanceKlass.hpp"
29
#include "oops/symbol.hpp"
30
#include "runtime/javaThread.hpp"
31
#include "runtime/mutexLocker.hpp"
32
#include "runtime/osThread.hpp"
33
#include "runtime/threadCritical.hpp"
34
#include "runtime/timer.hpp"
35
#include "utilities/events.hpp"
36

37

38
EventLog* Events::_logs = nullptr;
39
StringEventLog* Events::_messages = nullptr;
40
StringEventLog* Events::_memprotect_messages = nullptr;
41
StringEventLog* Events::_nmethod_flush_messages = nullptr;
42
StringEventLog* Events::_vm_operations = nullptr;
43
StringEventLog* Events::_zgc_phase_switch = nullptr;
44
ExceptionsEventLog* Events::_exceptions = nullptr;
45
StringEventLog* Events::_redefinitions = nullptr;
46
UnloadingEventLog* Events::_class_unloading = nullptr;
47
StringEventLog* Events::_class_loading = nullptr;
48
StringEventLog* Events::_deopt_messages = nullptr;
49
StringEventLog* Events::_dll_messages = nullptr;
50

51
EventLog::EventLog() {
52
  // This normally done during bootstrap when we're only single
53
  // threaded but use a ThreadCritical to ensure inclusion in case
54
  // some are created slightly late.
55
  ThreadCritical tc;
56
  _next = Events::_logs;
57
  Events::_logs = this;
58
}
59

60
// For each registered event logger, print out the current contents of
61
// the buffer.
62
void Events::print_all(outputStream* out, int max) {
63
  EventLog* log = _logs;
64
  while (log != nullptr) {
65
    log->print_log_on(out, max);
66
    log = log->next();
67
  }
68
}
69

70
// Print a single event log specified by name.
71
void Events::print_one(outputStream* out, const char* log_name, int max) {
72
  EventLog* log = _logs;
73
  int num_printed = 0;
74
  while (log != nullptr) {
75
    if (log->matches_name_or_handle(log_name)) {
76
      log->print_log_on(out, max);
77
      num_printed ++;
78
    }
79
    log = log->next();
80
  }
81
  // Write a short error note if no name matched.
82
  if (num_printed == 0) {
83
    out->print_cr("The name \"%s\" did not match any known event log. "
84
                  "Valid event log names are:", log_name);
85
    EventLog* log = _logs;
86
    while (log != nullptr) {
87
      log->print_names(out);
88
      out->cr();
89
      log = log->next();
90
    }
91
  }
92
}
93

94

95
void Events::print() {
96
  print_all(tty);
97
}
98

99
void Events::init() {
100
  if (LogEvents) {
101
    _messages = new StringEventLog("Events", "events");
102
    _nmethod_flush_messages = new StringEventLog("Nmethod flushes", "nmethodflushes");
103
    _memprotect_messages = new StringEventLog("Memory protections", "memprotects");
104
    _vm_operations = new StringEventLog("VM Operations", "vmops");
105
    if (UseZGC) {
106
      _zgc_phase_switch = new StringEventLog("ZGC Phase Switch", "zgcps");
107
    }
108
    _exceptions = new ExceptionsEventLog("Internal exceptions", "exc");
109
    _redefinitions = new StringEventLog("Classes redefined", "redef");
110
    _class_unloading = new UnloadingEventLog("Classes unloaded", "unload");
111
    _class_loading = new StringEventLog("Classes loaded", "load");
112
    _deopt_messages = new StringEventLog("Deoptimization events", "deopt");
113
    _dll_messages = new StringEventLog("Dll operation events", "dll");
114
  }
115
}
116

117
void eventlog_init() {
118
  Events::init();
119
}
120

121
///////////////////////////////////////////////////////////////////////////
122
// EventMark
123

124
EventMarkBase::EventMarkBase(EventLogFunction log_function) :
125
    _log_function(log_function),
126
    _buffer() {}
127

128
void EventMarkBase::log_start(const char* format, va_list argp) {
129
  // Save a copy of begin message and log it.
130
  _buffer.printv(format, argp);
131
  _log_function(nullptr, "%s", _buffer.buffer());
132
}
133

134
void EventMarkBase::log_end() {
135
  // Append " done" to the begin message and log it
136
  _buffer.append(" done");
137
  _log_function(nullptr, "%s", _buffer.buffer());
138
}
139

140
void UnloadingEventLog::log(Thread* thread, InstanceKlass* ik) {
141
  if (!should_log()) return;
142

143
  double timestamp = fetch_timestamp();
144
  // Unloading events are single threaded.
145
  int index = compute_log_index();
146
  _records[index].thread = thread;
147
  _records[index].timestamp = timestamp;
148
  stringStream st(_records[index].data.buffer(),
149
                  _records[index].data.size());
150
  st.print("Unloading class " PTR_FORMAT " ", p2i(ik));
151
  ik->name()->print_value_on(&st);
152
}
153

154
void ExceptionsEventLog::log(Thread* thread, Handle h_exception, const char* message, const char* file, int line) {
155
  if (!should_log()) return;
156

157
  double timestamp = fetch_timestamp();
158
  MutexLocker ml(&_mutex, Mutex::_no_safepoint_check_flag);
159
  int index = compute_log_index();
160
  _records[index].thread = thread;
161
  _records[index].timestamp = timestamp;
162
  stringStream st(_records[index].data.buffer(),
163
                  _records[index].data.size());
164
  st.print("Exception <");
165
  h_exception->print_value_on(&st);
166
  st.print("%s%s> (" PTR_FORMAT ") \n"
167
           "thrown [%s, line %d]",
168
           message ? ": " : "", message ? message : "",
169
           p2i(h_exception()), file, line);
170
}
171

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.