Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/hotspot/share/utilities/events.cpp
64441 views
1
/*
2
* Copyright (c) 1997, 2022, 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 "memory/allocation.inline.hpp"
27
#include "oops/instanceKlass.hpp"
28
#include "runtime/mutexLocker.hpp"
29
#include "runtime/osThread.hpp"
30
#include "runtime/thread.inline.hpp"
31
#include "runtime/threadCritical.hpp"
32
#include "runtime/timer.hpp"
33
#include "utilities/events.hpp"
34
35
36
EventLog* Events::_logs = NULL;
37
StringEventLog* Events::_messages = NULL;
38
StringEventLog* Events::_vm_operations = NULL;
39
ExceptionsEventLog* Events::_exceptions = NULL;
40
StringEventLog* Events::_redefinitions = NULL;
41
UnloadingEventLog* Events::_class_unloading = NULL;
42
StringEventLog* Events::_deopt_messages = NULL;
43
StringEventLog* Events::_dll_messages = NULL;
44
45
EventLog::EventLog() {
46
// This normally done during bootstrap when we're only single
47
// threaded but use a ThreadCritical to ensure inclusion in case
48
// some are created slightly late.
49
ThreadCritical tc;
50
_next = Events::_logs;
51
Events::_logs = this;
52
}
53
54
// For each registered event logger, print out the current contents of
55
// the buffer.
56
void Events::print_all(outputStream* out, int max) {
57
EventLog* log = _logs;
58
while (log != NULL) {
59
log->print_log_on(out, max);
60
log = log->next();
61
}
62
}
63
64
// Print a single event log specified by name.
65
void Events::print_one(outputStream* out, const char* log_name, int max) {
66
EventLog* log = _logs;
67
int num_printed = 0;
68
while (log != NULL) {
69
if (log->matches_name_or_handle(log_name)) {
70
log->print_log_on(out, max);
71
num_printed ++;
72
}
73
log = log->next();
74
}
75
// Write a short error note if no name matched.
76
if (num_printed == 0) {
77
out->print_cr("The name \"%s\" did not match any known event log. "
78
"Valid event log names are:", log_name);
79
EventLog* log = _logs;
80
while (log != NULL) {
81
log->print_names(out);
82
out->cr();
83
log = log->next();
84
}
85
}
86
}
87
88
89
void Events::print() {
90
print_all(tty);
91
}
92
93
void Events::init() {
94
if (LogEvents) {
95
_messages = new StringEventLog("Events", "events");
96
_vm_operations = new StringEventLog("VM Operations", "vmops");
97
_exceptions = new ExceptionsEventLog("Internal exceptions", "exc");
98
_redefinitions = new StringEventLog("Classes redefined", "redef");
99
_class_unloading = new UnloadingEventLog("Classes unloaded", "unload");
100
_deopt_messages = new StringEventLog("Deoptimization events", "deopt");
101
_dll_messages = new StringEventLog("Dll operation events", "dll");
102
}
103
}
104
105
void eventlog_init() {
106
Events::init();
107
}
108
109
///////////////////////////////////////////////////////////////////////////
110
// EventMark
111
112
EventMarkBase::EventMarkBase(EventLogFunction log_function) :
113
_log_function(log_function),
114
_buffer() {}
115
116
void EventMarkBase::log_start(const char* format, va_list argp) {
117
// Save a copy of begin message and log it.
118
_buffer.printv(format, argp);
119
_log_function(NULL, "%s", _buffer.buffer());
120
}
121
122
void EventMarkBase::log_end() {
123
// Append " done" to the begin message and log it
124
_buffer.append(" done");
125
_log_function(NULL, "%s", _buffer.buffer());
126
}
127
128
void UnloadingEventLog::log(Thread* thread, InstanceKlass* ik) {
129
if (!should_log()) return;
130
131
double timestamp = fetch_timestamp();
132
// Unloading events are single threaded.
133
int index = compute_log_index();
134
_records[index].thread = thread;
135
_records[index].timestamp = timestamp;
136
stringStream st(_records[index].data.buffer(),
137
_records[index].data.size());
138
st.print("Unloading class " INTPTR_FORMAT " ", p2i(ik));
139
ik->name()->print_value_on(&st);
140
}
141
142
void ExceptionsEventLog::log(Thread* thread, Handle h_exception, const char* message, const char* file, int line) {
143
if (!should_log()) return;
144
145
double timestamp = fetch_timestamp();
146
MutexLocker ml(&_mutex, Mutex::_no_safepoint_check_flag);
147
int index = compute_log_index();
148
_records[index].thread = thread;
149
_records[index].timestamp = timestamp;
150
stringStream st(_records[index].data.buffer(),
151
_records[index].data.size());
152
st.print("Exception <");
153
h_exception->print_value_on(&st);
154
st.print("%s%s> (" INTPTR_FORMAT ") \n"
155
"thrown [%s, line %d]",
156
message ? ": " : "", message ? message : "",
157
p2i(h_exception()), file, line);
158
}
159
160